14 #include "G4SDManager.hh" 17 #include "G4VProcess.hh" 20 #include "G4Cerenkov.hh" 21 #include "G4LogicalVolumeStore.hh" 23 #include "CLHEP/Units/GlobalSystemOfUnits.h" 24 #include "CLHEP/Units/GlobalPhysicalConstants.h" 25 #include "Randomize.hh" 26 #include "G4Poisson.hh" 40 energyThresholdSL = energyThresholdSL*
GeV;
49 <<
"***************************************************\n" 51 <<
"* Constructing a CastorSD with name " << GetName() <<
"\n" 53 <<
"***************************************************";
55 const G4LogicalVolumeStore * lvs = G4LogicalVolumeStore::GetInstance();
56 std::vector<G4LogicalVolume*>::const_iterator lvcite;
57 for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
58 if (strcmp(((*lvcite)->GetName()).c_str(),
"C3EF") == 0)
lvC3EF = (*lvcite);
59 if (strcmp(((*lvcite)->GetName()).c_str(),
"C3HF") == 0)
lvC3HF = (*lvcite);
60 if (strcmp(((*lvcite)->GetName()).c_str(),
"C4EF") == 0)
lvC4EF = (*lvcite);
61 if (strcmp(((*lvcite)->GetName()).c_str(),
"C4HF") == 0)
lvC4HF = (*lvcite);
62 if (strcmp(((*lvcite)->GetName()).c_str(),
"CAST") == 0)
lvCAST = (*lvcite);
65 edm::LogInfo(
"ForwardSim") <<
"CastorSD:: LogicalVolume pointers\n" 67 <<
" for C3HF; " <<
lvC4EF <<
" for C4EF; " 69 <<
lvCAST <<
" for CAST. " << std::endl;
86 G4ParticleTable * theParticleTable = G4ParticleTable::GetParticleTable();
88 edm::LogInfo(
"ForwardSim") <<
"CastorSD::initRun: Using Castor Shower Library \n";
96 double NCherPhot = 0.;
99 G4Track*
theTrack = aStep->GetTrack();
104 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
105 G4LogicalVolume* currentLV = currentPV->GetLogicalVolume();
108 G4String
name = currentPV->GetName();
110 nameVolume.assign(name,0,4);
112 G4SteppingControl stepControlFlag = aStep->GetControlFlag();
113 if (aStep->IsFirstStepInVolume())
114 LogDebug(
"ForwardSim") <<
"CastorSD::getEnergyDeposit:" 115 <<
"\n IsFirstStepInVolume " ;
122 LogDebug(
"ForwardSim") <<
"CastorSD::getEnergyDeposit:" 123 <<
"\n TrackID , ParentID , ParticleName ," 124 <<
" eta , phi , z , time ," 127 << theTrack->GetTrackID()
129 << theTrack->GetParentID()
131 << theTrack->GetDefinition()->GetParticleName()
133 << theTrack->GetPosition().eta()
135 << theTrack->GetPosition().phi()
137 << theTrack->GetPosition().z()
139 << theTrack->GetGlobalTime()
141 << theTrack->GetKineticEnergy()
143 << theTrack->GetTotalEnergy()
145 << theTrack->GetMomentum().mag() ;
146 if(theTrack->GetTrackID() != 1)
147 LogDebug(
"ForwardSim") <<
"CastorSD::getEnergyDeposit:" 148 <<
"\n CurrentStepNumber , TrackID , Particle , VertexPosition ," 149 <<
" LogicalVolumeAtVertex , CreatorProcess" 151 << theTrack->GetCurrentStepNumber()
153 << theTrack->GetTrackID()
155 << theTrack->GetDefinition()->GetParticleName()
157 << theTrack->GetVertexPosition()
159 << theTrack->GetLogicalVolumeAtVertex()->GetName()
161 << theTrack->GetCreatorProcess()->GetProcessName() ;
166 bool backward =
false;
167 const G4ThreeVector& hitPoint = preStepPoint->GetPosition();
168 const G4ThreeVector& hit_mom = preStepPoint->GetMomentumDirection();
169 double zint = hitPoint.z();
170 double pz = hit_mom.z();
173 if (pz * zint < 0.) backward =
true;
176 bool aboveThreshold =
false;
180 bool notaMuon =
true;
183 G4int parCode = theTrack->GetDefinition()->GetPDGEncoding();
184 if (parCode == mupPDG || parCode == mumPDG ) notaMuon =
false;
187 double theta_max =
M_PI - 3.1305;
188 double R_mom=
sqrt(hit_mom.x()*hit_mom.x() + hit_mom.y()*hit_mom.y());
190 bool angleok =
false;
191 if ( theta < theta_max) angleok =
true;
194 double R =
sqrt(hitPoint.x()*hitPoint.x() + hitPoint.y()*hitPoint.y());
196 if ( zint < -14450. && R < 45.) dot =
true;
198 if ( zint < -14700. || R > 193.) inRange =
false;
199 bool OkToUse =
false;
200 if ( inRange && !dot) OkToUse =
true;
202 const bool particleWithinShowerLibrary = aboveThreshold &&
203 notaMuon && (!backward) && OkToUse && angleok && currentLV ==
lvCAST;
211 LogDebug(
"ForwardSim") <<
" Current logical volume is " << nameVolume ;
222 double meanNCherPhot=0;
234 const bool isHad = !(castorHitPID==
emPDG || castorHitPID==
epPDG || castorHitPID==
gammaPDG || castorHitPID == mupPDG || castorHitPID == mumPDG);
240 G4double stepl = aStep->GetStepLength()/cm;
241 G4double
beta = preStepPoint->GetBeta();
242 G4double
charge = preStepPoint->GetCharge();
255 G4StepPoint* postStepPoint= aStep->GetPostStepPoint();
256 G4VPhysicalVolume* postPV= postStepPoint->GetPhysicalVolume();
258 G4String postname = postPV->GetName();
260 postnameVolume.assign(postname,0,4);
265 G4ThreeVector vert_mom = theTrack->GetVertexMomentumDirection();
267 G4ThreeVector localPoint = theTrack->GetTouchable()->GetHistory()->
268 GetTopTransform().TransformPoint(hitPoint);
270 G4String
particleType = theTrack->GetDefinition()->GetParticleName();
274 if (vert_mom.x() != 0) phi = atan2(vert_mom.y(),vert_mom.x());
275 if (phi < 0.) phi += twopi;
278 double costheta =vert_mom.z()/
sqrt(vert_mom.x()*vert_mom.x()+
279 vert_mom.y()*vert_mom.y()+
280 vert_mom.z()*vert_mom.z());
283 G4int primaryID = theTrack->GetTrackID();
288 double edep = aStep->GetTotalEnergyDeposit();
314 double bThreshold = 0.67;
315 double nMedium = 1.4925;
319 double photEnSpectrDE = 1.24;
328 double thFullRefl = 23.;
329 double thFullReflRad = thFullRefl*
pi/180.;
332 double thFibDir = 45.;
338 double thFibDirRad = thFibDir*
pi/180.;
346 double costh =hit_mom.z()/
sqrt(hit_mom.x()*hit_mom.x()+
347 hit_mom.y()*hit_mom.y()+
348 hit_mom.z()*hit_mom.z());
349 if (zint < 0) costh = -costh;
353 if (th < 0.) th += twopi;
358 double costhcher =1./(nMedium*
beta);
362 double DelFibPart = fabs(th - thFibDirRad);
365 double d = fabs(
tan(th)-
tan(thFibDirRad));
370 double a =
tan(thFibDirRad)+
tan(fabs(thFibDirRad-thFullReflRad));
371 double r =
tan(th)+
tan(fabs(th-thcher));
379 if(DelFibPart > (thFullReflRad + thcher) ) {
387 if((th + thcher) < (thFibDirRad+thFullReflRad) &&
388 (th - thcher) > (thFibDirRad-thFullReflRad)) {
397 if((thFibDirRad + thFullReflRad) < (th + thcher) &&
398 (thFibDirRad - thFullReflRad) > (th - thcher) ) {
415 double arg_arcos = 0.;
416 double tan_arcos = 2.*a*
d;
417 if(tan_arcos != 0.) arg_arcos =(r*r-a*a-d*
d)/tan_arcos;
418 arg_arcos = fabs(arg_arcos);
419 double th_arcos = acos(
std::min(
std::max(arg_arcos,
double(-1.)),
double(1.)));
420 d_qz = fabs(th_arcos/
pi/2.);
439 if(charge != 0. && beta > bThreshold ) {
441 meanNCherPhot = 370.*charge*charge*
442 ( 1. - 1./(nMedium*nMedium*beta*
beta) )*
443 photEnSpectrDE*stepl;
446 G4int poissNCherPhot = (G4int) G4Poisson(meanNCherPhot * scale);
448 if(poissNCherPhot < 0) poissNCherPhot = 0;
450 double effPMTandTransport = 0.19;
451 double ReflPower = 0.1;
452 double proba = d_qz + (1-d_qz)*ReflPower;
453 NCherPhot = poissNCherPhot*effPMTandTransport*proba*0.307;
457 double thgrad = th*180./
pi;
458 double thchergrad = thcher*180./
pi;
459 double DelFibPartgrad = DelFibPart*180./
pi;
460 LogDebug(
"ForwardSim") <<
" ==============================> start all " 461 <<
"information:<========= \n" <<
" =====> for " 462 <<
"test:<=== \n" <<
" variant = " << variant
463 <<
"\n thgrad = " << thgrad <<
"\n thchergrad " 464 <<
"= " << thchergrad <<
"\n DelFibPartgrad = " 465 << DelFibPartgrad <<
"\n d_qz = " << d_qz
466 <<
"\n =====> Start Step Information <=== \n" 467 <<
" ===> calo preStepPoint info <=== \n" 468 <<
" hitPoint = " << hitPoint <<
"\n" 469 <<
" hitMom = " << hit_mom <<
"\n" 470 <<
" stepControlFlag = " << stepControlFlag
473 <<
"\n charge = " << charge <<
"\n" 474 <<
" beta = " << beta <<
"\n" 475 <<
" bThreshold = " << bThreshold <<
"\n" 476 <<
" thgrad =" << thgrad <<
"\n" 477 <<
" effPMTandTransport=" << effPMTandTransport
479 <<
"\n nameVolume = " << nameVolume <<
"\n" 480 <<
" nMedium = " << nMedium <<
"\n" 483 <<
" stepl = " << stepl <<
"\n" 484 <<
" photEnSpectrDE = " << photEnSpectrDE <<
"\n" 485 <<
" edep = " << edep <<
"\n" 486 <<
" ===> calo theTrack info <=== " <<
"\n" 487 <<
" particleType = " << particleType <<
"\n" 488 <<
" primaryID = " << primaryID <<
"\n" 489 <<
" entot= " << theTrack->GetTotalEnergy() <<
"\n" 490 <<
" vert_eta= " << eta <<
"\n" 491 <<
" vert_phi= " << phi <<
"\n" 492 <<
" vert_mom= " << vert_mom <<
"\n" 493 <<
" ===> calo hit preStepPointinfo <=== "<<
"\n" 494 <<
" local point = " << localPoint <<
"\n" 495 <<
" ==============================> final info" 497 <<
" meanNCherPhot = " << meanNCherPhot <<
"\n" 498 <<
" poissNCherPhot = " << poissNCherPhot <<
"\n" 499 <<
" NCherPhot = " << NCherPhot;
515 LogDebug(
"ForwardSim") <<
"CastorSD:: " << nameVolume
517 <<
" Weighted Energy Deposit " << edep/
MeV 537 if (scheme !=
nullptr) {
538 edm::LogInfo(
"ForwardSim") <<
"CastorSD: updates numbering scheme for " 553 if (primaryID == 0) {
555 edm::LogWarning(
"ForwardSim") <<
"CastorSD: Problem with primaryID **** set by force " 556 <<
"to TkID **** " <<
theTrack->GetTrackID();
580 double trackPhi = track->GetPosition().phi();
581 if(trackPhi<0) trackPhi += 2*
M_PI ;
584 if(showerPhi<0) showerPhi += 2*
M_PI ;
588 int trackOctSector = (
int) ( trackPhi / (
M_PI/4) ) ;
589 int showerOctSector = (
int) ( showerPhi / (
M_PI/4) ) ;
592 uint32_t sec = ( ( unitID>>4 ) & 0xF ) ;
593 uint32_t complement = ( unitID & 0xFFFFFF0F ) ;
601 double trackZ = track->GetPosition().z();
604 int dSec = 2*(trackOctSector - showerOctSector) ;
610 if(sec1<0) sec1 += 16;
611 if(sec1>15) sec1 -= 16;
612 sec = (uint32_t)(sec1);
614 if( dSec<0 ) sec += 16 ;
616 aux = (
int) (sec/16) ;
620 newUnitID = complement | sec ;
623 if(newUnitID != unitID) {
624 LogDebug(
"ForwardSim") <<
"\n CastorSD::rotateUnitID: " 625 <<
"\n unitID = " << unitID
626 <<
"\n newUnitID = " << newUnitID ;
665 G4int particleCode =
theTrack->GetDefinition()->GetPDGEncoding();
668 isEM =
true ; isHAD =
false;
670 isEM =
false; isHAD =
true ;
675 LogDebug(
"ForwardSim") <<
"\n CastorSD::getFromLibrary: " 676 << hits.
getNhit() <<
" hits for " << GetName() <<
" from " 677 <<
theTrack->GetDefinition()->GetParticleName() <<
" of " 685 double scale = E_track/E_SLhit ;
712 for (
unsigned int i=0;
i<hits.
getNhit();
i++) {
717 nPhotoElectrons *=
scale ;
752 theTrack->SetTrackStatus(fStopAndKill);
754 LogDebug(
"ForwardSim") <<
"CastorSD::getFromLibrary:" 755 <<
"\n \"theTrack\" with TrackID() = " 757 <<
" and with energy " 759 <<
" has been set to be killed" ;
761 G4TrackVector tv = *(aStep->GetSecondary());
762 for (
unsigned int kk=0;
kk<tv.size();
kk++) {
764 tv[
kk]->SetTrackStatus(fStopAndKill);
766 LogDebug(
"ForwardSim") <<
"CastorSD::getFromLibrary:" 767 <<
"\n tv[" <<
kk <<
"]->GetTrackID() = " 768 << tv[
kk]->GetTrackID()
770 << tv[
kk]->GetTotalEnergy()
771 <<
" has been set to be killed" ;
T getParameter(std::string const &) const
void initParticleTable(G4ParticleTable *)
void updateHit(CaloG4Hit *)
double getEnergyDeposit(G4Step *) override
uint32_t setDetUnitId(const G4Step *step) override
Geom::Theta< T > theta() const
double non_compensation_factor
CastorNumberingScheme * numberingScheme
uint32_t rotateUnitID(uint32_t, G4Track *, const CastorShowerEvent &)
type of data representation of DDCompactView
void getFromLibrary(G4Step *)
unsigned int getDetID(int i)
static TrackerG4SimHitNumberingScheme & numberingScheme(const DDCompactView &cpv, const GeometricDet &det)
void resetForNewPrimary(const G4ThreeVector &, double)
Tan< T >::type tan(const T &t)
Abs< T >::type abs(const T &t)
void setID(uint32_t unitID, double timeSlice, int trackID, uint16_t depth=0)
G4StepPoint * preStepPoint
static const G4LogicalVolume * GetVolume(const std::string &name)
CastorSD(const std::string &, const DDCompactView &, const SensitiveDetectorCatalog &clg, edm::ParameterSet const &, const SimTrackManager *)
CastorShowerLibrary * showerLibrary
CastorShowerEvent getShowerHits(G4Step *, bool &)
void setNumberingScheme(CastorNumberingScheme *scheme)
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
virtual uint32_t getUnitID(const G4Step *aStep) const
CaloG4Hit * createNewHit()