Skip to content

Commit

Permalink
Simpler dr crystal hits for SCEPCal
Browse files Browse the repository at this point in the history
  • Loading branch information
wonyongc committed Dec 11, 2024
1 parent a6d10af commit 5bead95
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 199 deletions.
54 changes: 27 additions & 27 deletions detector/calorimeter/SCEPCalConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Princeton University
//===============================

#include "detectorSegmentations/SCEPCalSegmentationHandle.h"
#include "detectorSegmentations/SCEPCalSegmentationHandle_k4geo.h"
#include "DD4hep/DetFactoryHelper.h"
#include "DD4hep/DetectorTools.h"
#include "DD4hep/Printout.h"
Expand Down Expand Up @@ -34,7 +34,7 @@ create_detector_SCEPCal(dd4hep::Detector &theDetector,xml_h xmlElement,dd4hep::S
xml_comp_t timingLgXML =detectorXML.child(_Unicode(timingLayerLg));
xml_comp_t sipmLgXML =detectorXML.child(_Unicode(sipmLg));
xml_comp_t sipmTrXML =detectorXML.child(_Unicode(sipmTr));
xml_comp_t instXML =detectorXML.child(_Unicode(inst));
// xml_comp_t instXML =detectorXML.child(_Unicode(inst));
xml_comp_t timingAssemblyGlobalVisXML =detectorXML.child(_Unicode(timingAssemblyGlobalVis));
xml_comp_t barrelAssemblyGlobalVisXML =detectorXML.child(_Unicode(barrelAssemblyGlobalVis));
xml_comp_t endcapAssemblyGlobalVisXML =detectorXML.child(_Unicode(endcapAssemblyGlobalVis));
Expand All @@ -45,7 +45,7 @@ create_detector_SCEPCal(dd4hep::Detector &theDetector,xml_h xmlElement,dd4hep::S
dd4hep::Material timingLgMat =theDetector.material(timingLgXML.materialStr());
dd4hep::Material sipmLgMat =theDetector.material(sipmLgXML.materialStr());
dd4hep::Material sipmTrMat =theDetector.material(sipmTrXML.materialStr());
dd4hep::Material instMat =theDetector.material(instXML.materialStr());
// dd4hep::Material instMat =theDetector.material(instXML.materialStr());
const double EBz =dimXML.attr<double>(_Unicode(barrelHalfZ));
const double Rin =dimXML.attr<double>(_Unicode(barrelInnerR));
const double nomfw =dimXML.attr<double>(_Unicode(crystalFaceWidthNominal));
Expand All @@ -56,8 +56,8 @@ create_detector_SCEPCal(dd4hep::Detector &theDetector,xml_h xmlElement,dd4hep::S
const int PHI_SEGMENTS =dimXML.attr<int>(_Unicode(phiSegments));
const int N_PROJECTIVE_FILL =dimXML.attr<int>(_Unicode(projectiveFill));
const bool CONSTRUCT_TIMING =timingXML.attr<bool>(_Unicode(construct));
const int TIMING_PHI_START =timingXML.attr<int>(_Unicode(phistart));
const int TIMING_PHI_END =timingXML.attr<int>(_Unicode(phiend));
// const int TIMING_PHI_START =timingXML.attr<int>(_Unicode(phistart));
// const int TIMING_PHI_END =timingXML.attr<int>(_Unicode(phiend));
const bool CONSTRUCT_BARREL =barrelXML.attr<bool>(_Unicode(construct));
const int BARREL_PHI_START =barrelXML.attr<int>(_Unicode(phistart));
const int BARREL_PHI_END =barrelXML.attr<int>(_Unicode(phiend));
Expand Down Expand Up @@ -93,30 +93,30 @@ create_detector_SCEPCal(dd4hep::Detector &theDetector,xml_h xmlElement,dd4hep::S
int nCy =floor(lT/nomth);
double actY =lT/nCy;
double actX =2*wT/nCy;
double r2slice_end =r0slice_end+Fdz+Rdz;
double z2slice_end =r2slice_end*cos(thC_end)+PROJECTIVE_GAP;
double Rin2slice_end =r2slice_end*sin(thC_end);
double y2slice_end =r2slice_end*tan(D_THETA_BARREL/2.);
double slice_front_jut2 =y2slice_end*sin(M_PI/2-thC_end);
double slice_side_jut2 =y2slice_end*cos(M_PI/2-thC_end);
// double r2slice_end =r0slice_end+Fdz+Rdz;
// double z2slice_end =r2slice_end*cos(thC_end)+PROJECTIVE_GAP;
// double Rin2slice_end =r2slice_end*sin(thC_end);
// double y2slice_end =r2slice_end*tan(D_THETA_BARREL/2.);
// double slice_front_jut2 =y2slice_end*sin(M_PI/2-thC_end);
// double slice_side_jut2 =y2slice_end*cos(M_PI/2-thC_end);
double barrelSlice_z1 =z0slice_end+slice_side_jut;
double barrelSlice_z2 =y2slice;
double barrelSlice_rmin2 =Rin2slice_end-slice_front_jut2;
// double barrelSlice_rmin2 =Rin2slice_end-slice_front_jut2;
double thCEnd =THETA_SIZE_ENDCAP-D_THETA_ENDCAP/2;
double thCBeg =D_THETA_ENDCAP/2+ENDCAP_THETA_START*D_THETA_ENDCAP;
double r0eEnd =EBz/cos(thCEnd);
double r2eEnd =r0eEnd+Fdz+Rdz;
double y2eEnd =r2eEnd*tan(D_THETA_ENDCAP/2.);
// double r2eEnd =r0eEnd+Fdz+Rdz;
// double y2eEnd =r2eEnd*tan(D_THETA_ENDCAP/2.);
double r0eBeg =EBz/cos(thCBeg);
double r2eBeg =r0eBeg+Fdz+Rdz;
double y2eBeg =r2eBeg*tan(D_THETA_ENDCAP/2.);
double aEnd =r0eEnd/cos(D_THETA_ENDCAP/2);
double bEnd =sqrt(r2eEnd*r2eEnd+y2eEnd*y2eEnd);
// double bEnd =sqrt(r2eEnd*r2eEnd+y2eEnd*y2eEnd);
double z1End =aEnd*cos(thCEnd+D_THETA_ENDCAP/2);
double z2End =bEnd*cos(thCEnd-D_THETA_ENDCAP/2);
double aBeg =r0eBeg/cos(D_THETA_ENDCAP/2);
// double z2End =bEnd*cos(thCEnd-D_THETA_ENDCAP/2);
// double aBeg =r0eBeg/cos(D_THETA_ENDCAP/2);
double bBeg =sqrt(r2eBeg*r2eBeg+y2eBeg*y2eBeg);
double z1Beg =aBeg*cos(thCBeg+D_THETA_ENDCAP/2);
// double z1Beg =aBeg*cos(thCBeg+D_THETA_ENDCAP/2);
double z2Beg =bBeg*cos(thCBeg-D_THETA_ENDCAP/2);
double z1rmaxE =z1End*tan(thCEnd+D_THETA_ENDCAP/2);
double z2rmaxE =z2Beg*tan(thCEnd+D_THETA_ENDCAP/2);
Expand Down Expand Up @@ -175,7 +175,7 @@ create_detector_SCEPCal(dd4hep::Detector &theDetector,xml_h xmlElement,dd4hep::S
dd4hep::Readout readout=sens.readout();
dd4hep::Segmentation geomseg=readout.segmentation();
dd4hep::Segmentation* _geoSeg=&geomseg;
auto segmentation=dynamic_cast<dd4hep::DDSegmentation::SCEPCalSegmentation *>(_geoSeg->segmentation());
auto segmentation=dynamic_cast<dd4hep::DDSegmentation::SCEPCalSegmentation_k4geo *>(_geoSeg->segmentation());
segmentation->setGeomParams(Fdz,Rdz,nomfw,nomth,EBz,Rin,sipmth,PHI_SEGMENTS,N_PROJECTIVE_FILL);

std::vector<double> zTimingPolyhedra ={-barrelSlice_z1,barrelSlice_z1};
Expand Down Expand Up @@ -211,10 +211,10 @@ create_detector_SCEPCal(dd4hep::Detector &theDetector,xml_h xmlElement,dd4hep::S
int endcapAssemblyVolId32=segmentation->getFirst32bits(endcapAssemblyVolId);
auto endcap1AssemblyVolId =segmentation->setVolumeID(2,1,0,0);
int endcap1AssemblyVolId32=segmentation->getFirst32bits(endcap1AssemblyVolId);
dd4hep::PlacedVolume timingPlacedVol =experimentalHall.placeVolume(timingAssemblyVol,timingAssemblyVolId32);
experimentalHall.placeVolume(timingAssemblyVol,timingAssemblyVolId32);
dd4hep::PlacedVolume barrelPlacedVol =experimentalHall.placeVolume(barrelAssemblyVol,barrelAssemblyVolId32);
dd4hep::PlacedVolume endcapPlacedVol =experimentalHall.placeVolume(endcapAssemblyVol,endcapAssemblyVolId32);
dd4hep::PlacedVolume endcap1PlacedVol=experimentalHall.placeVolume(endcap1AssemblyVol,endcap1AssemblyVolId32);
experimentalHall.placeVolume(endcapAssemblyVol,endcapAssemblyVolId32);
experimentalHall.placeVolume(endcap1AssemblyVol,endcap1AssemblyVolId32);

ScepcalDetElement.setPlacement(barrelPlacedVol);

Expand All @@ -231,7 +231,7 @@ create_detector_SCEPCal(dd4hep::Detector &theDetector,xml_h xmlElement,dd4hep::S
RotationZ rotZPhi(phiEnvBarrel);
double rTimingAssembly=rT+nomth;
Position dispTimingAssembly(rTimingAssembly*cos(phiEnvBarrel),rTimingAssembly*sin(phiEnvBarrel),0);
dd4hep::PlacedVolume timingPhiAssemblyPlacedVol=timingAssemblyVol.placeVolume(timingPhiAssemblyVolume,Transform3D(rotZPhi,dispTimingAssembly));
timingAssemblyVol.placeVolume(timingPhiAssemblyVolume,Transform3D(rotZPhi,dispTimingAssembly));

dd4hep::Box timingCrystalLg(nomth/2,actX/2,lT/2-sipmth);
dd4hep::Box timingCrystalTr(nomth/2,wT-sipmth,actY/2);
Expand All @@ -255,7 +255,7 @@ create_detector_SCEPCal(dd4hep::Detector &theDetector,xml_h xmlElement,dd4hep::S
dd4hep::Volume tileAssemblyVolume("tileAssembly",tileAssemblyShape,theDetector.material("Vacuum"));
tileAssemblyVolume.setVisAttributes(theDetector,scepcalAssemblyXML.visStr());
Position dispTileAssembly(0,0,-y1slice+nTile*lT+lT/2);
dd4hep::PlacedVolume tileAssemblyPlacedVol=timingPhiAssemblyVolume.placeVolume(tileAssemblyVolume,dispTileAssembly);
timingPhiAssemblyVolume.placeVolume(tileAssemblyVolume,dispTileAssembly);

for (int nC=0;nC<nCy;nC++) {
int phiEnvBarrelSign=iPhi%2==0? 1:-1;
Expand Down Expand Up @@ -327,7 +327,7 @@ create_detector_SCEPCal(dd4hep::Detector &theDetector,xml_h xmlElement,dd4hep::S
dd4hep::EightPointSolid barrelPhiAssemblyShape(zheight_slice,verticesS);
dd4hep::Volume barrelPhiAssemblyVolume("barrelPhiAssembly",barrelPhiAssemblyShape,theDetector.material("Vacuum"));
barrelPhiAssemblyVolume.setVisAttributes(theDetector,scepcalAssemblyXML.visStr());
dd4hep::PlacedVolume barrelPhiAssemblyPlacedVol=barrelAssemblyVol.placeVolume(barrelPhiAssemblyVolume,Transform3D(rotSlice,dispSlice));
barrelAssemblyVol.placeVolume(barrelPhiAssemblyVolume,Transform3D(rotSlice,dispSlice));

for (int iTheta=0; iTheta<N_THETA_BARREL; iTheta++) {
double thC =THETA_SIZE_ENDCAP+D_THETA_BARREL/2+(iTheta*D_THETA_BARREL);
Expand Down Expand Up @@ -486,8 +486,8 @@ create_detector_SCEPCal(dd4hep::Detector &theDetector,xml_h xmlElement,dd4hep::S
dd4hep::Volume endcap1RingAssemblyVolume("endcapRingAssembly",endcapRingAssemblyShape,theDetector.material("Vacuum"));
endcap1RingAssemblyVolume.setVisAttributes(theDetector,scepcalAssemblyXML.visStr());
RotationY rotMirror(M_PI);
dd4hep::PlacedVolume endcapRingAssemblyPlacedVol=endcapAssemblyVol.placeVolume(endcapRingAssemblyVolume);
dd4hep::PlacedVolume endcap1RingAssemblyPlacedVol=endcap1AssemblyVol.placeVolume(endcap1RingAssemblyVolume,Transform3D(rotMirror));
endcapAssemblyVol.placeVolume(endcapRingAssemblyVolume);
endcap1AssemblyVol.placeVolume(endcap1RingAssemblyVolume,Transform3D(rotMirror));

for (int iPhi=ENDCAP_PHI_START;iPhi<ENDCAP_PHI_END;iPhi++) {
double phiEnvEndcap=iPhi*D_PHI_GLOBAL;
Expand Down
54 changes: 13 additions & 41 deletions detectorSegmentations/include/detectorSegmentations/DRCrystalHit.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@
//===============================
#ifndef DRCrystalHit_h
#define DRCrystalHit_h 1
#include "G4VHit.hh"
#include "G4THitsCollection.hh"
#include "G4Allocator.hh"
#include "G4ThreeVector.hh"
// #include "G4VHit.hh"
// #include "G4THitsCollection.hh"
// #include "G4Allocator.hh"
// #include "G4ThreeVector.hh"
#include "DDG4/Geant4Data.h"
#include "G4OpticalPhoton.hh"
#include "G4VProcess.hh"
#include "DD4hep/Objects.h"
#include "DD4hep/Segmentations.h"
#include "CLHEP/Vector/ThreeVector.h"
// #include "G4OpticalPhoton.hh"
// #include "G4VProcess.hh"
// #include "DD4hep/Objects.h"
// #include "DD4hep/Segmentations.h"
// #include "CLHEP/Vector/ThreeVector.h"

namespace SCEPCal {

typedef ROOT::Math::XYZVector Position;

const int nsipmbins=6000;

class DRCrystalHit : public dd4hep::sim::Geant4HitData {

public:
Expand All @@ -29,28 +27,11 @@ namespace SCEPCal {
Position position;
Contributions truth;
double energyDeposit;

int eta;
int phi;
int depth;
int system;

int ncerenkov;
int nscintillator;

int nbins=nsipmbins;

float wavelen_min=300;
float wavelen_max=1000;

float time_min=0;
float time_max=300;

std::array<int,nsipmbins> nwavelen_cer;
std::array<int,nsipmbins> nwavelen_scint;

std::array<int,nsipmbins> ntime_cer;
std::array<int,nsipmbins> ntime_scint;
int nCerenkovProd;
int nScintillationProd;
double tAvgC;
double tAvgS;

public:
DRCrystalHit();
Expand All @@ -63,13 +44,4 @@ namespace SCEPCal {
};
};

#if defined(__CINT__) || defined(__MAKECINT__) || defined(__CLING__) || defined(__ROOTCLING__)
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ namespace dd4hep;
#pragma link C++ namespace dd4hep::sim;
#pragma link C++ namespace SCEPCal;
#pragma link C++ class SCEPCal::DRCrystalHit+;
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Author: Wonyong Chung
// Princeton University
//===============================
#ifndef SCEPCalSegmentationHandle_h
#define SCEPCalSegmentationHandle_h 1
#include "detectorSegmentations/SCEPCalSegmentation.h"
#ifndef SCEPCalSegmentationHandle_k4geo_h
#define SCEPCalSegmentationHandle_k4geo_h 1
#include "detectorSegmentations/SCEPCalSegmentation_k4geo.h"
#include "DD4hep/Segmentations.h"
#include "DD4hep/detail/SegmentationsInterna.h"

Expand All @@ -14,21 +14,21 @@ class Segmentation;
template <typename T>
class SegmentationWrapper;

typedef Handle<SegmentationWrapper<DDSegmentation::SCEPCalSegmentation>> SCEPCalSegmentationHandle;
typedef Handle<SegmentationWrapper<DDSegmentation::SCEPCalSegmentation_k4geo>> SCEPCalSegmentationHandle_k4geo;

class SCEPCalSegmentation : public SCEPCalSegmentationHandle {
class SCEPCalSegmentation_k4geo : public SCEPCalSegmentationHandle_k4geo {
public:
typedef SCEPCalSegmentationHandle::Object Object;
typedef SCEPCalSegmentationHandle_k4geo::Object Object;

public:
SCEPCalSegmentation() = default;
SCEPCalSegmentation(const SCEPCalSegmentation& e) = default;
SCEPCalSegmentation(const Segmentation& e) : Handle<Object>(e) {}
SCEPCalSegmentation(const Handle<Object>& e) : Handle<Object>(e) {}
SCEPCalSegmentation_k4geo() = default;
SCEPCalSegmentation_k4geo(const SCEPCalSegmentation_k4geo& e) = default;
SCEPCalSegmentation_k4geo(const Segmentation& e) : Handle<Object>(e) {}
SCEPCalSegmentation_k4geo(const Handle<Object>& e) : Handle<Object>(e) {}
template <typename Q>
SCEPCalSegmentation(const Handle<Q>& e) : Handle<Object>(e) {}
SCEPCalSegmentation& operator=(const SCEPCalSegmentation& seg) = default;
bool operator==(const SCEPCalSegmentation& seg) const { return m_element == seg.m_element; }
SCEPCalSegmentation_k4geo(const Handle<Q>& e) : Handle<Object>(e) {}
SCEPCalSegmentation_k4geo& operator=(const SCEPCalSegmentation_k4geo& seg) = default;
bool operator==(const SCEPCalSegmentation_k4geo& seg) const { return m_element == seg.m_element; }

inline Position position(const CellID& id) const {
return Position(access()->implementation->position(id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Author: Wonyong Chung
// Princeton University
//===============================
#ifndef SCEPCalSegmentation_h
#define SCEPCalSegmentation_h 1
#ifndef SCEPCalSegmentation_k4geo_h
#define SCEPCalSegmentation_k4geo_h 1
#include "DDSegmentation/Segmentation.h"
#include "TVector3.h"
#include "DD4hep/DetFactoryHelper.h"
Expand All @@ -13,15 +13,15 @@
namespace dd4hep {
namespace DDSegmentation {

class SCEPCalSegmentation : public Segmentation {
class SCEPCalSegmentation_k4geo : public Segmentation {
public:
SCEPCalSegmentation(const std::string& aCellEncoding);
SCEPCalSegmentation(const BitFieldCoder* decoder);
virtual ~SCEPCalSegmentation() override;
SCEPCalSegmentation_k4geo(const std::string& aCellEncoding);
SCEPCalSegmentation_k4geo(const BitFieldCoder* decoder);
virtual ~SCEPCalSegmentation_k4geo() override;

virtual Vector3D position(const CellID& aCellID) const;

virtual Vector3D myPosition(const CellID& aCellID) ;
virtual Vector3D myPosition(const CellID& aCellID) const;

virtual CellID cellID(const Vector3D& aLocalPosition,
const Vector3D& aGlobalPosition,
Expand Down
45 changes: 14 additions & 31 deletions detectorSegmentations/src/DRCrystalHit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,28 @@
#include <DD4hep/Printout.h>
#include <DD4hep/InstanceCount.h>
#include <DDG4/Geant4Data.h>
#include <DDG4/Geant4StepHandler.h>
#include <DDG4/Geant4FastSimHandler.h>
#include <G4Step.hh>
#include <G4Allocator.hh>
#include <G4OpticalPhoton.hh>
// #include <DDG4/Geant4StepHandler.h>
// #include <DDG4/Geant4FastSimHandler.h>
// #include <G4Step.hh>
// #include <G4Allocator.hh>
// #include <G4OpticalPhoton.hh>
#include "detectorSegmentations/DRCrystalHit.h"
#include "G4Track.hh"
// #include "G4Track.hh"

using namespace dd4hep::sim;
using namespace dd4hep;
using namespace std;
using namespace SCEPCal;
SCEPCal::DRCrystalHit::DRCrystalHit()
: dd4hep::sim::Geant4HitData(), position(), truth(), energyDeposit(0), nCerenkovProd(0), nScintillationProd(0), tAvgC(0), tAvgS(0) {

DRCrystalHit::DRCrystalHit()
: Geant4HitData(), position(), truth(), energyDeposit(0), eta(0), phi(0), depth(0), system(0), ncerenkov(0), nscintillator(0) {
dd4hep::InstanceCount::increment(this);

InstanceCount::increment(this);

for( int i=0; i<nsipmbins; i++) {
nwavelen_cer[i]=0;
nwavelen_scint[i]=0;
ntime_cer[i]=0;
ntime_scint[i]=0;
}
}

DRCrystalHit::DRCrystalHit(const Position& pos)
: Geant4HitData(), position(pos), truth(), energyDeposit(0), eta(0), phi(0), depth(0), system(0), ncerenkov(0), nscintillator(0) {
SCEPCal::DRCrystalHit::DRCrystalHit(const Position& pos)
: dd4hep::sim::Geant4HitData(), position(pos), truth(), energyDeposit(0), nCerenkovProd(0), nScintillationProd(0), tAvgC(0), tAvgS(0) {

InstanceCount::increment(this);
dd4hep::InstanceCount::increment(this);

for( int i=0; i<nsipmbins; i++) {
nwavelen_cer[i]=0;
nwavelen_scint[i]=0;
ntime_cer[i]=0;
ntime_scint[i]=0;
}
}

DRCrystalHit::~DRCrystalHit() {
InstanceCount::decrement(this);
SCEPCal::DRCrystalHit::~DRCrystalHit() {
dd4hep::InstanceCount::decrement(this);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "detectorSegmentations/SCEPCalSegmentationHandle.h"
#include "detectorSegmentations/SCEPCalSegmentationHandle_k4geo.h"
#include "DD4hep/detail/Handle.inl"

DD4HEP_INSTANTIATE_HANDLE_UNNAMED(dd4hep::DDSegmentation::SCEPCalSegmentation);
DD4HEP_INSTANTIATE_HANDLE_UNNAMED(dd4hep::DDSegmentation::SCEPCalSegmentation_k4geo);
Loading

0 comments on commit 5bead95

Please sign in to comment.