15 #include "G4SDManager.hh"
18 #include "G4VProcess.hh"
21 #include "G4Cerenkov.hh"
22 #include "G4LogicalVolumeStore.hh"
24 #include "CLHEP/Units/GlobalSystemOfUnits.h"
25 #include "CLHEP/Units/GlobalPhysicalConstants.h"
26 #include "Randomize.hh"
27 #include "G4Poisson.hh"
36 lvC3HF(0), lvC4EF(0), lvC4HF(0), lvCAST(0) {
41 energyThresholdSL = energyThresholdSL*
GeV;
50 <<
"***************************************************\n"
52 <<
"* Constructing a CastorSD with name " << GetName() <<
"\n"
54 <<
"***************************************************";
56 const G4LogicalVolumeStore * lvs = G4LogicalVolumeStore::GetInstance();
57 std::vector<G4LogicalVolume*>::const_iterator lvcite;
58 for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
59 if (strcmp(((*lvcite)->GetName()).c_str(),
"C3EF") == 0)
lvC3EF = (*lvcite);
60 if (strcmp(((*lvcite)->GetName()).c_str(),
"C3HF") == 0)
lvC3HF = (*lvcite);
61 if (strcmp(((*lvcite)->GetName()).c_str(),
"C4EF") == 0)
lvC4EF = (*lvcite);
62 if (strcmp(((*lvcite)->GetName()).c_str(),
"C4HF") == 0)
lvC4HF = (*lvcite);
63 if (strcmp(((*lvcite)->GetName()).c_str(),
"CAST") == 0)
lvCAST = (*lvcite);
66 edm::LogInfo(
"ForwardSim") <<
"CastorSD:: LogicalVolume pointers\n"
68 <<
" for C3HF; " <<
lvC4EF <<
" for C4EF; "
70 <<
lvCAST <<
" for CAST. " << std::endl;
87 G4ParticleTable * theParticleTable = G4ParticleTable::GetParticleTable();
89 edm::LogInfo(
"ForwardSim") <<
"CastorSD::initRun: Using Castor Shower Library \n";
105 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
106 G4LogicalVolume* currentLV = currentPV->GetLogicalVolume();
107 G4String
name = currentPV->GetName();
109 nameVolume.assign(name,0,4);
112 G4SteppingControl stepControlFlag = aStep->GetControlFlag();
113 if (aStep->IsFirstStepInVolume())
114 LogDebug(
"ForwardSim") <<
"CastorSD::getEnergyDeposit:"
115 <<
"\n IsFirstStepInVolume " ;
119 G4Track*
theTrack = aStep->GetTrack();
123 LogDebug(
"ForwardSim") <<
"CastorSD::getEnergyDeposit:"
124 <<
"\n TrackID , ParentID , ParticleName ,"
125 <<
" eta , phi , z , time ,"
128 << theTrack->GetTrackID()
130 << theTrack->GetParentID()
132 << theTrack->GetDefinition()->GetParticleName()
134 << theTrack->GetPosition().eta()
136 << theTrack->GetPosition().phi()
138 << theTrack->GetPosition().z()
140 << theTrack->GetGlobalTime()
142 << theTrack->GetKineticEnergy()
144 << theTrack->GetTotalEnergy()
146 << theTrack->GetMomentum().mag() ;
147 if(theTrack->GetTrackID() != 1)
148 LogDebug(
"ForwardSim") <<
"CastorSD::getEnergyDeposit:"
149 <<
"\n CurrentStepNumber , TrackID , Particle , VertexPosition ,"
150 <<
" LogicalVolumeAtVertex , CreatorProcess"
152 << theTrack->GetCurrentStepNumber()
154 << theTrack->GetTrackID()
156 << theTrack->GetDefinition()->GetParticleName()
158 << theTrack->GetVertexPosition()
160 << theTrack->GetLogicalVolumeAtVertex()->GetName()
162 << theTrack->GetCreatorProcess()->GetProcessName() ;
167 bool backward =
false;
168 G4ThreeVector hitPoint = preStepPoint->GetPosition();
169 G4ThreeVector hit_mom = preStepPoint->GetMomentumDirection();
170 double zint = hitPoint.z();
171 double pz = hit_mom.z();
174 if (pz * zint < 0.) backward =
true;
177 bool aboveThreshold =
false;
181 bool notaMuon =
true;
184 G4int parCode = theTrack->GetDefinition()->GetPDGEncoding();
185 if (parCode == mupPDG || parCode == mumPDG ) notaMuon =
false;
188 double theta_max =
M_PI - 3.1305;
189 double R_mom=
sqrt(hit_mom.x()*hit_mom.x() + hit_mom.y()*hit_mom.y());
191 bool angleok =
false;
192 if ( theta < theta_max) angleok =
true;
195 double R =
sqrt(hitPoint.x()*hitPoint.x() + hitPoint.y()*hitPoint.y());
197 if ( zint < -14450. && R < 45.) dot =
true;
199 if ( zint < -14700. || R > 193.) inRange =
false;
200 bool OkToUse =
false;
201 if ( inRange && !dot) OkToUse =
true;
203 if (
useShowerLibrary && aboveThreshold && notaMuon && (!backward) && OkToUse && angleok && currentLV ==
lvCAST ) {
209 LogDebug(
"ForwardSim") <<
" Current logical volume is " << nameVolume ;
216 G4double stepl = aStep->GetStepLength()/cm;
217 G4double
beta = preStepPoint->GetBeta();
218 G4double charge = preStepPoint->GetCharge();
230 G4StepPoint* postStepPoint= aStep->GetPostStepPoint();
231 G4VPhysicalVolume* postPV = postStepPoint->GetPhysicalVolume();
232 G4String postname = postPV->GetName();
234 postnameVolume.assign(postname,0,4);
239 G4ThreeVector vert_mom = theTrack->GetVertexMomentumDirection();
241 G4ThreeVector localPoint = theTrack->GetTouchable()->GetHistory()->
242 GetTopTransform().TransformPoint(hitPoint);
246 if (vert_mom.x() != 0) phi = atan2(vert_mom.y(),vert_mom.x());
247 if (phi < 0.) phi += twopi;
248 G4String
particleType = theTrack->GetDefinition()->GetParticleName();
250 float costheta =vert_mom.z()/
sqrt(vert_mom.x()*vert_mom.x()+
251 vert_mom.y()*vert_mom.y()+
252 vert_mom.z()*vert_mom.z());
255 G4int primaryID = theTrack->GetTrackID();
260 double edep = aStep->GetTotalEnergyDeposit();
282 double meanNCherPhot=0;
288 float bThreshold = 0.67;
289 float nMedium = 1.4925;
293 float photEnSpectrDE = 1.24;
302 float thFullRefl = 23.;
303 float thFullReflRad = thFullRefl*
pi/180.;
306 float thFibDir = 45.;
312 float thFibDirRad = thFibDir*
pi/180.;
320 float costh =hit_mom.z()/
sqrt(hit_mom.x()*hit_mom.x()+
321 hit_mom.y()*hit_mom.y()+
322 hit_mom.z()*hit_mom.z());
323 if (zint < 0) costh = -costh;
327 if (th < 0.) th += twopi;
332 float costhcher =1./(nMedium*
beta);
336 float DelFibPart = fabs(th - thFibDirRad);
339 float d = fabs(
tan(th)-
tan(thFibDirRad));
344 float a =
tan(thFibDirRad)+
tan(fabs(thFibDirRad-thFullReflRad));
345 float r =
tan(th)+
tan(fabs(th-thcher));
353 if(DelFibPart > (thFullReflRad + thcher) ) {
361 if((th + thcher) < (thFibDirRad+thFullReflRad) &&
362 (th - thcher) > (thFibDirRad-thFullReflRad)) {
371 if((thFibDirRad + thFullReflRad) < (th + thcher) &&
372 (thFibDirRad - thFullReflRad) > (th - thcher) ) {
390 float arg_arcos = 0.;
391 float tan_arcos = 2.*a*d;
392 if(tan_arcos != 0.) arg_arcos =(r*r-a*a-d*d)/tan_arcos;
393 arg_arcos = fabs(arg_arcos);
395 d_qz = th_arcos/
pi/2.;
417 if(charge != 0. && beta > bThreshold ) {
419 meanNCherPhot = 370.*charge*charge*
420 ( 1. - 1./(nMedium*nMedium*beta*
beta) )*
421 photEnSpectrDE*stepl;
423 G4int poissNCherPhot = (G4int) G4Poisson(meanNCherPhot);
425 if(poissNCherPhot < 0) poissNCherPhot = 0;
427 float effPMTandTransport = 0.19;
428 double ReflPower = 0.1;
429 double proba = d_qz + (1-d_qz)*ReflPower;
430 NCherPhot = poissNCherPhot*effPMTandTransport*proba*0.307;
434 float thgrad = th*180./
pi;
435 float thchergrad = thcher*180./
pi;
436 float DelFibPartgrad = DelFibPart*180./
pi;
437 LogDebug(
"ForwardSim") <<
" ==============================> start all "
438 <<
"information:<========= \n" <<
" =====> for "
439 <<
"test:<=== \n" <<
" variant = " << variant
440 <<
"\n thgrad = " << thgrad <<
"\n thchergrad "
441 <<
"= " << thchergrad <<
"\n DelFibPartgrad = "
442 << DelFibPartgrad <<
"\n d_qz = " << d_qz
443 <<
"\n =====> Start Step Information <=== \n"
444 <<
" ===> calo preStepPoint info <=== \n"
445 <<
" hitPoint = " << hitPoint <<
"\n"
446 <<
" hitMom = " << hit_mom <<
"\n"
447 <<
" stepControlFlag = " << stepControlFlag
450 <<
"\n charge = " << charge <<
"\n"
451 <<
" beta = " << beta <<
"\n"
452 <<
" bThreshold = " << bThreshold <<
"\n"
453 <<
" thgrad =" << thgrad <<
"\n"
454 <<
" effPMTandTransport=" << effPMTandTransport
456 <<
"\n nameVolume = " << nameVolume <<
"\n"
457 <<
" nMedium = " << nMedium <<
"\n"
460 <<
" stepl = " << stepl <<
"\n"
461 <<
" photEnSpectrDE = " << photEnSpectrDE <<
"\n"
462 <<
" edep = " << edep <<
"\n"
463 <<
" ===> calo theTrack info <=== " <<
"\n"
464 <<
" particleType = " << particleType <<
"\n"
465 <<
" primaryID = " << primaryID <<
"\n"
466 <<
" entot= " << theTrack->GetTotalEnergy() <<
"\n"
467 <<
" vert_eta= " << eta <<
"\n"
468 <<
" vert_phi= " << phi <<
"\n"
469 <<
" vert_mom= " << vert_mom <<
"\n"
470 <<
" ===> calo hit preStepPointinfo <=== "<<
"\n"
471 <<
" local point = " << localPoint <<
"\n"
472 <<
" ==============================> final info"
474 <<
" meanNCherPhot = " << meanNCherPhot <<
"\n"
475 <<
" poissNCherPhot = " << poissNCherPhot <<
"\n"
476 <<
" NCherPhot = " << NCherPhot;
492 LogDebug(
"ForwardSim") <<
"CastorSD:: " << nameVolume
494 <<
" Weighted Energy Deposit " << edep/
MeV
518 edm::LogInfo(
"ForwardSim") <<
"CastorSD: updates numbering scheme for "
534 if (primaryID == 0) {
536 edm::LogWarning(
"ForwardSim") <<
"CastorSD: Problem with primaryID **** set by force "
537 <<
"to TkID **** " <<
theTrack->GetTrackID();
559 float trackPhi = track->GetPosition().phi();
560 if(trackPhi<0) trackPhi += 2*
M_PI ;
563 if(showerPhi<0) showerPhi += 2*
M_PI ;
567 int trackOctSector = (int) ( trackPhi / (
M_PI/4) ) ;
568 int showerOctSector = (int) ( showerPhi / (
M_PI/4) ) ;
571 uint32_t sec = ( ( unitID>>4 ) & 0xF ) ;
572 uint32_t complement = ( unitID & 0xFFFFFF0F ) ;
580 float trackZ = track->GetPosition().z();
583 int dSec = 2*(trackOctSector - showerOctSector) ;
589 if(sec1<0) sec1 += 16;
590 if(sec1>15) sec1 -= 16;
591 sec = (uint32_t)(sec1);
593 if( dSec<0 ) sec += 16 ;
595 aux = (int) (sec/16) ;
599 newUnitID = complement | sec ;
602 if(newUnitID != unitID) {
603 LogDebug(
"ForwardSim") <<
"\n CastorSD::rotateUnitID: "
604 <<
"\n unitID = " << unitID
605 <<
"\n newUnitID = " << newUnitID ;
644 G4int particleCode =
theTrack->GetDefinition()->GetPDGEncoding();
647 isEM =
true ; isHAD =
false;
649 isEM =
false; isHAD =
true ;
654 LogDebug(
"ForwardSim") <<
"\n CastorSD::getFromLibrary: "
655 << hits.
getNhit() <<
" hits for " << GetName() <<
" from "
656 <<
theTrack->GetDefinition()->GetParticleName() <<
" of "
664 double scale = E_track/E_SLhit ;
691 for (
unsigned int i=0;
i<hits.
getNhit();
i++) {
696 nPhotoElectrons *=
scale ;
731 theTrack->SetTrackStatus(fStopAndKill);
733 LogDebug(
"ForwardSim") <<
"CastorSD::getFromLibrary:"
734 <<
"\n \"theTrack\" with TrackID() = "
736 <<
" and with energy "
738 <<
" has been set to be killed" ;
740 G4TrackVector tv = *(aStep->GetSecondary());
741 for (
unsigned int kk=0;
kk<tv.size();
kk++) {
743 tv[
kk]->SetTrackStatus(fStopAndKill);
745 LogDebug(
"ForwardSim") <<
"CastorSD::getFromLibrary:"
746 <<
"\n tv[" <<
kk <<
"]->GetTrackID() = "
747 << tv[
kk]->GetTrackID()
749 << tv[
kk]->GetTotalEnergy()
750 <<
" has been set to be killed" ;
T getParameter(std::string const &) const
void initParticleTable(G4ParticleTable *)
void updateHit(CaloG4Hit *)
virtual double getEnergyDeposit(G4Step *)
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(G4String, const DDCompactView &, const SensitiveDetectorCatalog &clg, edm::ParameterSet const &, const SimTrackManager *)
CastorShowerLibrary * showerLibrary
CastorShowerEvent getShowerHits(G4Step *, bool &)
virtual uint32_t setDetUnitId(G4Step *step)
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()