10 #include <phparameter/PHParameters.h>
33 #include <Geant4/G4Field.hh>
34 #include <Geant4/G4FieldManager.hh>
35 #include <Geant4/G4ParticleDefinition.hh>
36 #include <Geant4/G4PropagatorInField.hh>
37 #include <Geant4/G4ReferenceCountedHandle.hh>
38 #include <Geant4/G4Step.hh>
39 #include <Geant4/G4StepPoint.hh>
40 #include <Geant4/G4StepStatus.hh>
41 #include <Geant4/G4String.hh>
42 #include <Geant4/G4SystemOfUnits.hh>
43 #include <Geant4/G4ThreeVector.hh>
44 #include <Geant4/G4TouchableHandle.hh>
45 #include <Geant4/G4Track.hh>
46 #include <Geant4/G4TrackStatus.hh>
47 #include <Geant4/G4TransportationManager.hh>
48 #include <Geant4/G4Types.hh>
49 #include <Geant4/G4VPhysicalVolume.hh>
50 #include <Geant4/G4VTouchable.hh>
51 #include <Geant4/G4VUserTrackInformation.hh>
52 #include <Geant4/G4Transform3D.hh>
70 , m_Detector(detector)
72 , m_AbsorberHits(nullptr)
74 , m_Params(parameters)
75 , m_SaveHitContainer(nullptr)
76 , m_SaveShower(nullptr)
77 , m_SaveVolPre(nullptr)
78 , m_SaveVolPost(nullptr)
80 , m_SavePreStepStatus(-1)
81 , m_SavePostStepStatus(-1)
82 , m_EnableFieldCheckerFlag(m_Params->get_int_param(
"field_check"))
83 , m_IsActiveFlag(m_Params->get_int_param(
"active"))
84 , m_IsBlackHoleFlag(m_Params->get_int_param(
"blackhole"))
85 , m_NScintiPlates(m_Params->get_int_param(PHG4HcalDefs::
scipertwr) * m_Params->get_int_param(
"n_towers"))
86 , m_LightScintModelFlag(m_Params->get_int_param(
"light_scint_model"))
111 std::ostringstream mappingfilename;
112 const char* calibroot = getenv(
"CALIBRATIONROOT");
115 mappingfilename << calibroot;
119 std::cout <<
"no CALIBRATIONROOT environment variable" << std::endl;
123 mappingfilename <<
"/HCALOUT/tilemap/oHCALMaps092021.root";
124 TFile *f =
new TFile(mappingfilename.str().data());
125 MapCorr = (TH2F *)f->Get(
"hCombinedMap");
127 std::cout <<
"ERROR: MapCorr is NULL" << std::endl;
137 G4TouchableHandle touch = aStep->GetPreStepPoint()->GetTouchableHandle();
138 G4TouchableHandle touchpost = aStep->GetPostStepPoint()->GetTouchableHandle();
140 G4VPhysicalVolume*
volume = touch->GetVolume();
165 layer_id = layer_tower.first;
166 tower_id = layer_tower.second;
170 layer_id = touch->GetCopyNumber();
173 G4double edep = aStep->GetTotalEnergyDeposit() /
GeV;
174 G4double eion = (aStep->GetTotalEnergyDeposit() - aStep->GetNonIonizingEnergyDeposit()) /
GeV;
175 G4double light_yield = 0;
177 const G4Track* aTrack = aStep->GetTrack();
182 edep = aTrack->GetKineticEnergy() /
GeV;
183 G4Track* killtrack =
const_cast<G4Track*
>(aTrack);
184 killtrack->SetTrackStatus(fStopAndKill);
190 bool geantino =
false;
195 if (aTrack->GetParticleDefinition()->GetPDGEncoding() == 0 &&
196 aTrack->GetParticleDefinition()->GetParticleName().find(
"geantino") != string::npos)
200 G4StepPoint* prePoint = aStep->GetPreStepPoint();
201 G4StepPoint* postPoint = aStep->GetPostStepPoint();
206 switch (prePoint->GetStepStatus())
208 case fPostStepDoItProc:
215 cout <<
GetName() <<
": New Hit for " << endl;
221 <<
", current trackid: " << aTrack->GetTrackID() << endl;
222 cout <<
"phys pre vol: " << volume->GetName()
223 <<
" post vol : " << touchpost->GetVolume()->GetName() << endl;
224 cout <<
" previous phys pre vol: " <<
m_SaveVolPre->GetName()
225 <<
" previous phys post vol: " <<
m_SaveVolPost->GetName() << endl;
256 m_Hit->
set_t(0, prePoint->GetGlobalTime() / nanosecond);
274 if (G4VUserTrackInformation*
p = aTrack->GetUserInformation())
291 cout <<
GetName() <<
": hit was not created" << endl;
297 <<
", current trackid: " << aTrack->GetTrackID() << endl;
298 cout <<
"phys pre vol: " << volume->GetName()
299 <<
" post vol : " << touchpost->GetVolume()->GetName() << endl;
300 cout <<
" previous phys pre vol: " <<
m_SaveVolPre->GetName()
301 <<
" previous phys post vol: " <<
m_SaveVolPost->GetName() << endl;
308 cout <<
GetName() <<
": hits do not belong to the same track" << endl;
310 <<
", current trackid: " << aTrack->GetTrackID()
325 m_Hit->
set_t(1, postPoint->GetGlobalTime() / nanosecond);
334 G4TouchableHandle theTouchable = prePoint->GetTouchableHandle();
335 G4ThreeVector worldPosition = postPoint->GetPosition();
336 G4ThreeVector localPosition = theTouchable->GetHistory()->GetTopTransform().TransformPoint(worldPosition);
351 float lx = (localPosition.x()/
cm);
352 float lz = fabs(localPosition.z()/
cm);
356 int lcz = (int)(2.0*lz) + 1;
357 int lcx = (int)(2.0*(lx+42.75)) + 1;
359 if( (lcx>=1) && (lcx<=
MapCorr->GetNbinsY()) &&
360 (lcz>=1) && (lcz<=
MapCorr->GetNbinsX()) ){
362 light_yield *= (double) (
MapCorr->GetBinContent(lcz, lcx));
379 double cor =
GetLightCorrection(postPoint->GetPosition().x() , (postPoint->GetPosition().y() ));
380 cout <<
"applying cor: " << cor << endl;
381 light_yield = light_yield *
GetLightCorrection(postPoint->GetPosition().x() , (postPoint->GetPosition().y() ));
399 if (G4VUserTrackInformation*
p = aTrack->GetUserInformation())
416 if (postPoint->GetStepStatus() == fGeomBoundary ||
417 postPoint->GetStepStatus() == fWorldBoundary ||
418 postPoint->GetStepStatus() == fAtRestDoItProc ||
419 aTrack->GetTrackStatus() == fStopAndKill)
454 string absorbernodename;
467 m_Hits = findNode::getClass<PHG4HitContainer>(topNode, hitnodename.c_str());
468 m_AbsorberHits = findNode::getClass<PHG4HitContainer>(topNode, absorbernodename.c_str());
473 std::cout <<
"PHG4OuterHcalSteppingAction::SetTopNode - unable to find " << hitnodename << std::endl;
479 cout <<
"PHG4HcalSteppingAction::SetTopNode - unable to find " << absorbernodename << endl;
489 static const string h_field_name =
"hOuterHcalField";
493 TH2F*
h =
new TH2F(h_field_name.c_str(),
"Magnetic field (Tesla) in HCal;X (cm);Y (cm)", 2400,
494 -300, 300, 2400, -300, 300);
498 cout <<
"PHG4OuterHcalSteppingAction::FieldChecker - make a histograme to check outer Hcal field map."
499 <<
" Saved to Fun4AllServer Histo with name " << h_field_name << endl;
502 TH2F*
h =
dynamic_cast<TH2F*
>(se->
getHisto(h_field_name));
506 G4TouchableHandle touch = aStep->GetPreStepPoint()->GetTouchableHandle();
509 G4VPhysicalVolume*
volume = touch->GetVolume();
512 G4ThreeVector globPosition = aStep->GetPreStepPoint()->GetPosition();
514 G4double globPosVec[4] = {0};
515 G4double FieldValueVec[6] = {0};
517 globPosVec[0] = globPosition.x();
518 globPosVec[1] = globPosition.y();
519 globPosVec[2] = globPosition.z();
520 globPosVec[3] = aStep->GetPreStepPoint()->GetGlobalTime();
522 const Int_t binx = h->GetXaxis()->FindBin(globPosVec[0] /
cm);
523 const Int_t biny = h->GetYaxis()->FindBin(globPosVec[1] /
cm);
525 if (h->GetBinContent(binx, binx) == 0)
528 G4TransportationManager* transportMgr =
529 G4TransportationManager::GetTransportationManager();
530 assert(transportMgr);
532 G4PropagatorInField* fFieldPropagator =
533 transportMgr->GetPropagatorInField();
534 assert(fFieldPropagator);
536 G4FieldManager* fieldMgr = fFieldPropagator->FindAndSetFieldManager(volume);
539 const G4Field* pField = fieldMgr->GetDetectorField();
542 pField->GetFieldValue(globPosVec, FieldValueVec);
544 G4ThreeVector FieldValue = G4ThreeVector(FieldValueVec[0],
545 FieldValueVec[1], FieldValueVec[2]);
547 const double B = FieldValue.mag() / tesla;
549 h->SetBinContent(binx, biny, B);
551 cout <<
"PHG4OuterHcalSteppingAction::FieldChecker - "
553 <<
", " << biny <<
" := " << B <<
" Tesla @ x,y = " << globPosVec[0] /
cm
554 <<
"," << globPosVec[1] /
cm <<
" cm" << endl;