8 #include "cetlib_except/exception.h" 14 #include "TGeoMaterial.h" 19 #include "Geant4/G4Event.hh" 20 #include "Geant4/G4Track.hh" 21 #include "Geant4/G4ThreeVector.hh" 22 #include "Geant4/G4ParticleDefinition.hh" 23 #include "Geant4/G4PrimaryParticle.hh" 24 #include "Geant4/G4DynamicParticle.hh" 25 #include "Geant4/G4VUserPrimaryParticleInformation.hh" 26 #include "Geant4/G4Step.hh" 27 #include "Geant4/G4StepPoint.hh" 28 #include "Geant4/G4VProcess.hh" 29 #include "Geant4/G4MaterialCutsCouple.hh" 30 #include "Geant4/G4NavigationHistory.hh" 31 #include "Geant4/G4EmSaturation.hh" 32 #include "Geant4/G4Version.hh" 37 #include "CoreUtils/ServiceUtil.h" 48 fGeo = gar::providerFrom<geo::GeometryGAr>();
49 fDetProp = gar::providerFrom<detinfo::DetectorPropertiesService>();
120 <<
"AuxDetAction::SteppingAction";
163 <<
"AuxDetAction::LArSteppingAction";
166 G4Track *track = step->GetTrack();
168 const CLHEP::Hep3Vector &start = step->GetPreStepPoint()->GetPosition();
169 const CLHEP::Hep3Vector &stop = track->GetPosition();
172 if(start == stop)
return;
173 if(step->GetTotalEnergyDeposit() == 0)
return;
181 auto pos = 0.5 * (start + stop);
186 <<
"Node not found in " 193 std::string volmaterial = node->GetMedium()->GetMaterial()->GetName();
194 if ( ! std::regex_match(volmaterial, std::regex(
fLArMaterial)) )
return;
206 <<
" cm and deposited " 207 << step->GetTotalEnergyDeposit()
208 <<
" MeV of energy with a minimum of " 213 auto midPoint = 0.5 * (step->GetPreStepPoint()->GetPosition() +
214 step->GetPostStepPoint()->GetPosition() );
218 float time = step->GetPreStepPoint()->GetGlobalTime();
236 <<
"AuxDetAction::ECALSteppingAction";
239 G4Track *track = step->GetTrack();
241 const CLHEP::Hep3Vector &start = step->GetPreStepPoint()->GetPosition();
242 const CLHEP::Hep3Vector &stop = track->GetPosition();
245 if(start == stop)
return;
246 if(step->GetTotalEnergyDeposit() == 0)
return;
255 auto pos = 0.5 * (start + stop);
260 <<
"Node not found in " 267 std::string volmaterial = node->GetMedium()->GetMaterial()->GetName();
268 if ( ! std::regex_match(volmaterial, std::regex(
fECALMaterial)) )
return;
278 <<
" cm and deposited " 279 << step->GetTotalEnergyDeposit()
283 G4ThreeVector G4Global = 0.5 * (step->GetPreStepPoint()->GetPosition() + step->GetPostStepPoint()->GetPosition() );
293 <<
"det_id " << det_id
294 <<
" stave " << stave
295 <<
" module " << module
296 <<
" layer " << layer
297 <<
" slice " << slice;
307 double G4Pos[3] = {0., 0., 0.};
314 float time = step->GetPreStepPoint()->GetGlobalTime();
319 <<
"Energy deposited " 332 std::vector<gar::sdp::CaloDeposit> vechit;
333 vechit.push_back(hit);
342 <<
"AuxDetAction::TrackerScSteppingAction";
345 G4Track *track = step->GetTrack();
347 const CLHEP::Hep3Vector &start = step->GetPreStepPoint()->GetPosition();
348 const CLHEP::Hep3Vector &stop = track->GetPosition();
351 if(start == stop)
return;
352 if(step->GetTotalEnergyDeposit() == 0)
return;
360 auto pos = 0.5 * (start + stop);
366 <<
"Node not found in " 374 std::string volmaterial = node->GetMedium()->GetMaterial()->GetName();
385 <<
" cm and deposited " 386 << step->GetTotalEnergyDeposit()
390 G4ThreeVector G4Global = 0.5 * (step->GetPreStepPoint()->GetPosition() + step->GetPostStepPoint()->GetPosition() );
395 unsigned int det_id = 3;
398 <<
"det_id " << det_id
399 <<
" layer " << layer
400 <<
" slice " << slice;
410 double G4Pos[3] = {0., 0., 0.};
417 float time = step->GetPreStepPoint()->GetGlobalTime();
421 <<
"Energy deposited " 434 std::vector<gar::sdp::CaloDeposit> vechit;
435 vechit.push_back(hit);
444 <<
"AuxDetAction::MuIDSteppingAction";
447 G4Track *track = step->GetTrack();
449 const CLHEP::Hep3Vector &start = step->GetPreStepPoint()->GetPosition();
450 const CLHEP::Hep3Vector &stop = track->GetPosition();
453 if(start == stop)
return;
454 if(step->GetTotalEnergyDeposit() == 0)
return;
463 auto pos = 0.5 * (start + stop);
469 <<
"Node not found in " 476 std::string volmaterial = node->GetMedium()->GetMaterial()->GetName();
477 if ( ! std::regex_match(volmaterial, std::regex(
fMuIDMaterial)) )
return;
487 <<
" cm and deposited " 488 << step->GetTotalEnergyDeposit()
492 G4ThreeVector G4Global = 0.5 * (step->GetPreStepPoint()->GetPosition() + step->GetPostStepPoint()->GetPosition() );
502 <<
"det_id " << det_id
503 <<
" stave " << stave
504 <<
" module " << module
505 <<
" layer " << layer
506 <<
" slice " << slice;
516 double G4Pos[3] = {0., 0., 0.};
523 float time = step->GetPreStepPoint()->GetGlobalTime();
528 <<
"Energy deposited " 541 std::vector<gar::sdp::CaloDeposit> vechit;
542 vechit.push_back(hit);
550 std::string VolName = track->GetVolume()->GetName();
551 VolName.erase(VolName.length()-3, 3);
558 return std::atoi( (volname.substr( volname.find(
"layer_") + 6, 2)).c_str() );
564 return std::atoi( (volname.substr( volname.find(
"slice") + 5, 1)).c_str() );
570 unsigned int det_id = 0;
572 if( volname.find(
"ECal") != std::string::npos )
574 if( volname.find(
"Barrel") != std::string::npos )
576 if( volname.find(
"Endcap") != std::string::npos )
580 if( volname.find(
"Yoke") != std::string::npos )
582 if( volname.find(
"Barrel") != std::string::npos )
584 if( volname.find(
"Endcap") != std::string::npos )
594 return std::atoi( (volname.substr( volname.find(
"_stave") + 6, 2)).c_str() );
600 return std::atoi( (volname.substr( volname.find(
"_module") + 7, 2)).c_str() );
606 return step->GetPreStepPoint()->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(glob);
612 return step->GetPreStepPoint()->GetTouchable()->GetHistory()->GetTopTransform().Inverse().TransformPoint(loc);
622 return step->GetTotalEnergyDeposit();
629 #if G4VERSION_NUMBER >= 1001 630 static G4EmSaturation s_emSaturation(1);
632 static G4EmSaturation s_emSaturation();
633 s_emSaturation.SetVerbose(1);
636 #if G4VERSION_NUMBER >= 1030 637 static bool s_initialised =
false;
638 if(not s_initialised) {
639 s_emSaturation.InitialiseG4Saturation();
640 s_initialised =
true;
644 double energyDeposition = step->GetTotalEnergyDeposit();
645 double length = step->GetStepLength();
646 double niel = step->GetNonIonizingEnergyDeposit();
647 const G4Track*
trk = step->GetTrack();
648 const G4ParticleDefinition* particle = trk->GetDefinition();
649 const G4MaterialCutsCouple* couple = trk->GetMaterialCutsCouple();
650 double engyVis = s_emSaturation.VisibleEnergyDeposition(particle,
662 for(
auto const &it : m_hits) {
665 std::vector<gar::sdp::CaloDeposit> vechit = it.second;
666 std::sort(vechit.begin(), vechit.end());
669 float time = vechit.at(0).Time();
670 int trackID = vechit.at(0).TrackID();
671 double pos[3] = { vechit.at(0).X(), vechit.at(0).Y(), vechit.at(0).Z() };
673 for(
auto const &
hit : vechit) {
674 esum +=
hit.Energy();
677 fDeposits.emplace_back( trackID, time, esum, pos, cellID );
static constexpr double cm
TGeoNode * FindNode(T const &x, T const &y, T const &z) const
float GetStepEnergy(const G4Step *step, bool birks)
unsigned int GetDetNumber(std::string volname)
const gar::geo::GeometryCore * fGeo
geometry information
bool HasLArTPCDetector() const
std::string fLArMaterial
Material for the LArTPC.
std::vector< std::string > fECALVolumeName
volume we will record energy depositions in
std::vector< std::string > fMuIDVolumeName
volume we will record energy depositions in
std::string fTrackerScMaterial
Material for the TrackerSc (GArLite)
AuxDetAction(CLHEP::HepRandomEngine *engine, fhicl::ParameterSet const &pset)
gar::raw::CellID_t GetCellID(const TGeoNode *node, const unsigned int &det_id, const unsigned int &stave, const unsigned int &module, const unsigned int &layer, const unsigned int &slice, const std::array< double, 3 > &localPosition) const
static constexpr double MeV
void AddHitsMinerva(std::map< gar::raw::CellID_t, std::vector< gar::sdp::CaloDeposit > > &m_Deposits, std::vector< gar::sdp::CaloDeposit > &fDeposits) const
void LArSteppingAction(const G4Step *)
std::map< gar::raw::CellID_t, std::vector< gar::sdp::CaloDeposit > > m_ECALDeposits
unsigned int GetSliceNumber(std::string volname)
const detinfo::DetectorProperties * fDetProp
detector properties
std::map< gar::raw::CellID_t, std::vector< gar::sdp::CaloDeposit > > m_TrackerScDeposits
G4ThreeVector globalToLocal(const G4Step *step, const G4ThreeVector &glob)
void reconfigure(fhicl::ParameterSet const &pset)
void BeginOfEventAction(const G4Event *)
double fLArEnergyCut
The minimum energy in GeV for a particle to be included in the list.
fInnerVessel push_back(Point(-578.400000, 0.000000, 0.000000))
std::map< gar::raw::CellID_t, std::vector< gar::sdp::CaloDeposit > > m_MuIDDeposits
unsigned int GetModuleNumber(std::string volname)
std::string fMuIDMaterial
Material for the MuID.
static constexpr double GeV
T get(std::string const &key) const
unsigned int GetLayerNumber(std::string volname)
std::string GetVolumeName(const G4Track *track)
bool HasTrackerScDetector() const
const gar::geo::seg::MinervaSegmentationAlg * fMinervaSegAlg
std::vector< gar::sdp::CaloDeposit > fMuIDDeposits
energy fDeposits for the MuID
gar::geo::seg::SegmentationAlg const * MinervaSegmentationAlg() const
Returns the object handling the Sc Tracker segmentation.
Detector simulation of raw signals on wires.
std::vector< gar::sdp::LArDeposit > fLArDeposits
energy fDeposits for the LArTPC
void AddHits(const std::map< gar::raw::CellID_t, std::vector< gar::sdp::CaloDeposit > > m_hits, std::vector< gar::sdp::CaloDeposit > &fDeposits)
General GArSoft Utilities.
bool HasECALDetector() const
std::string fECALMaterial
Material for the ECAL.
std::vector< std::string > fTrackerScVolumeName
volume we will record energy depositions in
void SteppingAction(const G4Step *)
bool HasMuonDetector() const
void ECALSteppingAction(const G4Step *)
std::vector< gar::sdp::CaloDeposit > fTrackerScDeposits
energy fDeposits for the TrackerSc
void MuIDSteppingAction(const G4Step *)
std::vector< std::string > fLArVolumeName
volume we will record energy depositions in
G4ThreeVector localToGlobal(const G4Step *step, const G4ThreeVector &loc)
void EndOfEventAction(const G4Event *)
float birksAttenuation(const G4Step *step)
unsigned int GetStaveNumber(std::string volname)
void TrackerScSteppingAction(const G4Step *)
void PreTrackingAction(const G4Track *)
std::vector< gar::sdp::CaloDeposit > fECALDeposits
energy fDeposits for the ECAL
void PostTrackingAction(const G4Track *)
static int GetCurrentTrackID()