CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
CaloSD Class Referenceabstract

#include <CaloSD.h>

Inheritance diagram for CaloSD:
SensitiveCaloDetector Observer< const BeginOfRun *> Observer< const BeginOfEvent *> Observer< const BeginOfTrack *> Observer< const EndOfTrack *> Observer< const EndOfEvent *> SensitiveDetector AHCalSD CastorSD DreamSD ECalSD EcalTBH4BeamSD HCalSD HcalTB02SD HcalTB06BeamSD HFNoseSD HGCalSD HGCalTB16SD01 HGCScintSD HGCSD TotemT2ScintSD ZdcSD

Classes

struct  Detector
 

Public Member Functions

 CaloSD (const std::string &aSDname, const SensitiveDetectorCatalog &clg, edm::ParameterSet const &p, const SimTrackManager *, float timeSlice=1., bool ignoreTkID=false)
 
void clear () override
 
void clearHits () override
 
void DrawAll () override
 
void EndOfEvent (G4HCofThisEvent *eventHC) override
 
void fillHits (edm::PCaloHitContainer &, const std::string &) override
 
void Initialize (G4HCofThisEvent *HCE) override
 
bool isItFineCalo (const G4VTouchable *touch)
 
void PrintAll () override
 
G4bool ProcessHits (G4Step *step, G4TouchableHistory *) override
 
bool ProcessHits (G4GFlashSpot *aSpot, G4TouchableHistory *) override
 
void reset () override
 
uint32_t setDetUnitId (const G4Step *step) override=0
 
 ~CaloSD () override
 
- Public Member Functions inherited from SensitiveCaloDetector
 SensitiveCaloDetector (const std::string &iname, const SensitiveDetectorCatalog &clg)
 
- Public Member Functions inherited from SensitiveDetector
void EndOfEvent (G4HCofThisEvent *eventHC) override
 
const std::vector< std::string > & getNames () const
 
void Initialize (G4HCofThisEvent *eventHC) override
 
bool isCaloSD () const
 
 SensitiveDetector (const std::string &iname, const SensitiveDetectorCatalog &, bool calo)
 
 ~SensitiveDetector () override
 
- Public Member Functions inherited from Observer< const BeginOfRun *>
 Observer ()
 
void slotForUpdate (const BeginOfRun * iT)
 
virtual ~Observer ()
 
- Public Member Functions inherited from Observer< const BeginOfEvent *>
 Observer ()
 
void slotForUpdate (const BeginOfEvent * iT)
 
virtual ~Observer ()
 
- Public Member Functions inherited from Observer< const BeginOfTrack *>
 Observer ()
 
void slotForUpdate (const BeginOfTrack * iT)
 
virtual ~Observer ()
 
- Public Member Functions inherited from Observer< const EndOfTrack *>
 Observer ()
 
void slotForUpdate (const EndOfTrack * iT)
 
virtual ~Observer ()
 
- Public Member Functions inherited from Observer< const EndOfEvent *>
 Observer ()
 
void slotForUpdate (const EndOfEvent * iT)
 
virtual ~Observer ()
 

Protected Member Functions

bool checkHit ()
 
CaloG4HitcreateNewHit (const G4Step *, const G4Track *)
 
virtual void endEvent ()
 
virtual double EnergyCorrected (const G4Step &step, const G4Track *)
 
virtual bool filterHit (CaloG4Hit *, double)
 
unsigned int findBoundaryCrossingParent (const G4Track *track, bool markParentAsSaveable=true)
 
double getAttenuation (const G4Step *aStep, double birk1, double birk2, double birk3) const
 
virtual uint16_t getDepth (const G4Step *)
 
virtual double getEnergyDeposit (const G4Step *step)
 
virtual bool getFromLibrary (const G4Step *step)
 
int getNumberOfHits ()
 
double getResponseWt (const G4Track *)
 
virtual int getTrackID (const G4Track *)
 
bool hitExists (const G4Step *)
 
void ignoreRejection ()
 
virtual void initEvent (const BeginOfEvent *)
 
virtual void initRun ()
 
void printDetectorLevels (const G4VTouchable *) const
 
void processHit (const G4Step *step)
 
void resetForNewPrimary (const G4Step *)
 
void setNumberCheckedHits (int val)
 
void setParameterized (bool val)
 
G4ThreeVector setToGlobal (const G4ThreeVector &, const G4VTouchable *) const
 
G4ThreeVector setToLocal (const G4ThreeVector &, const G4VTouchable *) const
 
virtual int setTrackID (const G4Step *)
 
void setUseMap (bool val)
 
std::string shortreprID (const CaloHitID &ID)
 
std::string shortreprID (const CaloG4Hit *hit)
 
void update (const BeginOfRun *) override
 This routine will be called when the appropriate signal arrives. More...
 
void update (const BeginOfEvent *) override
 This routine will be called when the appropriate signal arrives. More...
 
void update (const BeginOfTrack *trk) override
 This routine will be called when the appropriate signal arrives. More...
 
void update (const EndOfTrack *trk) override
 This routine will be called when the appropriate signal arrives. More...
 
void update (const ::EndOfEvent *) override
 
void updateHit (CaloG4Hit *)
 
- Protected Member Functions inherited from SensitiveDetector
TrackInformationcmsTrackInformation (const G4Track *aTrack)
 
Local3DPoint ConvertToLocal3DPoint (const G4ThreeVector &point) const
 
Local3DPoint FinalStepPosition (const G4Step *step, coordinates) const
 
Local3DPoint InitialStepPosition (const G4Step *step, coordinates) const
 
Local3DPoint LocalPostStepPosition (const G4Step *step) const
 
Local3DPoint LocalPreStepPosition (const G4Step *step) const
 
void NaNTrap (const G4Step *step) const
 
void setNames (const std::vector< std::string > &)
 
- Protected Member Functions inherited from Observer< const EndOfEvent *>
virtual void update (const EndOfEvent *)=0
 This routine will be called when the appropriate signal arrives. More...
 

Static Protected Member Functions

static std::string printableDecayChain (const std::vector< unsigned int > &decayChain)
 

Protected Attributes

CaloG4HitcurrentHit
 
CaloHitID currentID
 
float edepositEM
 
float edepositHAD
 
double eminHit
 
double energyCut
 
G4ThreeVector entranceLocal
 
G4ThreeVector entrancePoint
 
bool forceSave
 
float incidentEnergy
 
double kmaxIon
 
double kmaxNeutron
 
double kmaxProton
 
G4ThreeVector posGlobal
 
CaloHitID previousID
 
bool suppressHeavy
 
double tmaxHit
 

Private Member Functions

void cleanHitCollection ()
 
bool saveHit (CaloG4Hit *)
 
void storeHit (CaloG4Hit *)
 

Private Attributes

std::unordered_map< unsigned int, unsigned int > boundaryCrossingParentMap_
 
int cleanIndex
 
double correctT
 
bool corrTOFBeam
 
bool doFineCalo_
 
bool doFineCaloThisStep_
 
double eMinFine_
 
double eminHitD
 
std::vector< DetectorfineDetectors_
 
int hcID
 
std::map< CaloHitID, CaloG4Hit * > hitMap
 
bool ignoreReject
 
bool ignoreTrackID
 
bool isParameterized
 
const SimTrackManagerm_trackManager
 
std::unique_ptr< CaloMeanResponsemeanResponse
 
int nCheckedHits
 
int primAncestor
 
int primIDSaved
 
std::vector< std::unique_ptr< CaloG4Hit > > reusehit
 
std::unique_ptr< CaloSlaveSDslave
 
CaloG4HitCollectiontheHC
 
float timeSlice
 
std::map< int, TrackWithHistory * > tkMap
 
int totalHits
 
bool useMap
 

Additional Inherited Members

- Protected Types inherited from SensitiveDetector
enum  coordinates { WorldCoordinates, LocalCoordinates }
 

Detailed Description

Definition at line 40 of file CaloSD.h.

Constructor & Destructor Documentation

◆ CaloSD()

CaloSD::CaloSD ( const std::string &  aSDname,
const SensitiveDetectorCatalog clg,
edm::ParameterSet const &  p,
const SimTrackManager manager,
float  timeSlice = 1.,
bool  ignoreTkID = false 
)

Definition at line 33 of file CaloSD.cc.

References cleanIndex, correctT, corrTOFBeam, currentID, hgcalTestNeighbor_cfi::detector, doFineCalo_, edepositEM, edepositHAD, eMinFine_, eminHit, eminHitD, energyCut, entranceLocal, entrancePoint, fineDetectors_, forceSave, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), mps_fire::i, ignoreTrackID, incidentEnergy, isParameterized, dqmdumpme::k, kmaxIon, kmaxNeutron, kmaxProton, personalPlayback::level, meanResponse, Skims_PA_cff::name, nCheckedHits, AlCaHLTBitMon_ParallelJobs::p, posGlobal, previousID, primAncestor, primIDSaved, slave, suppressHeavy, timeSlice, tmaxHit, totalHits, and useMap.

40  G4VGFlashSensitiveDetector(),
41  eminHit(0.),
42  currentHit(nullptr),
43  m_trackManager(manager),
44  theHC(nullptr),
45  ignoreTrackID(ignoreTkID),
46  hcID(-1),
47  timeSlice(timeSliceUnit),
48  eminHitD(0.) {
49  //Parameters
50  bool dd4hep = p.getParameter<bool>("g4GeometryDD4hepSource");
51  int addlevel = dd4hep ? 1 : 0;
52  edm::ParameterSet m_CaloSD = p.getParameter<edm::ParameterSet>("CaloSD");
53  energyCut = m_CaloSD.getParameter<double>("EminTrack") * CLHEP::GeV;
54  tmaxHit = m_CaloSD.getParameter<double>("TmaxHit") * CLHEP::ns;
55  std::vector<double> eminHits = m_CaloSD.getParameter<std::vector<double>>("EminHits");
56  std::vector<double> tmaxHits = m_CaloSD.getParameter<std::vector<double>>("TmaxHits");
57  std::vector<std::string> hcn = m_CaloSD.getParameter<std::vector<std::string>>("HCNames");
58  std::vector<int> useResMap = m_CaloSD.getParameter<std::vector<int>>("UseResponseTables");
59  std::vector<double> eminHitX = m_CaloSD.getParameter<std::vector<double>>("EminHitsDepth");
60  suppressHeavy = m_CaloSD.getParameter<bool>("SuppressHeavy");
61  kmaxIon = m_CaloSD.getParameter<double>("IonThreshold") * CLHEP::MeV;
62  kmaxProton = m_CaloSD.getParameter<double>("ProtonThreshold") * CLHEP::MeV;
63  kmaxNeutron = m_CaloSD.getParameter<double>("NeutronThreshold") * CLHEP::MeV;
64  nCheckedHits = m_CaloSD.getUntrackedParameter<int>("CheckHits", 25);
65  useMap = m_CaloSD.getUntrackedParameter<bool>("UseMap", true);
66  int verbn = m_CaloSD.getUntrackedParameter<int>("Verbosity", 0);
67  corrTOFBeam = m_CaloSD.getParameter<bool>("CorrectTOFBeam");
68  double beamZ = m_CaloSD.getParameter<double>("BeamPosition") * CLHEP::cm;
69  correctT = beamZ / CLHEP::c_light / CLHEP::nanosecond;
70  doFineCalo_ = m_CaloSD.getParameter<bool>("DoFineCalo");
71  eMinFine_ = m_CaloSD.getParameter<double>("EminFineTrack") * CLHEP::MeV;
72  std::vector<std::string> fineNames = m_CaloSD.getParameter<std::vector<std::string>>("FineCaloNames");
73  std::vector<int> fineLevels = m_CaloSD.getParameter<std::vector<int>>("FineCaloLevels");
74  std::vector<int> useFines = m_CaloSD.getParameter<std::vector<int>>("UseFineCalo");
75  for (auto& level : fineLevels)
76  level += addlevel;
77 
78  SetVerboseLevel(verbn);
79  meanResponse.reset(nullptr);
80  for (unsigned int k = 0; k < hcn.size(); ++k) {
81  if (name == hcn[k]) {
82  if (k < eminHits.size())
83  eminHit = eminHits[k] * CLHEP::MeV;
84  if (k < eminHitX.size())
85  eminHitD = eminHitX[k] * CLHEP::MeV;
86  if (k < tmaxHits.size())
87  tmaxHit = tmaxHits[k] * CLHEP::ns;
88  if (k < useResMap.size() && useResMap[k] > 0) {
89  meanResponse = std::make_unique<CaloMeanResponse>(p);
90  break;
91  }
92  }
93  }
94  slave = std::make_unique<CaloSlaveSD>(name);
95 
98  isParameterized = false;
99 
100  entrancePoint.set(0., 0., 0.);
101  entranceLocal.set(0., 0., 0.);
102  posGlobal.set(0., 0., 0.);
104 
106  forceSave = false;
107 
108  edm::LogVerbatim("CaloSim") << "CaloSD: Minimum energy of track for saving it " << energyCut / CLHEP::GeV
109  << " GeV\n Use of HitID Map " << useMap << "\n Check last " << nCheckedHits
110  << " before saving the hit\n Correct TOF globally by " << correctT
111  << " ns (Flag =" << corrTOFBeam << ")\n Save hits recorded before " << tmaxHit
112  << " ns and if energy is above " << eminHit / CLHEP::MeV << " MeV (for depth 0) or "
113  << eminHitD / CLHEP::MeV << " MeV (for nonzero depths);\n Time Slice Unit "
114  << timeSlice << "\nIgnore TrackID Flag " << ignoreTrackID << " doFineCalo flag "
115  << doFineCalo_ << "\nBeam Position " << beamZ / CLHEP::cm << " cm";
116  if (doFineCalo_)
117  edm::LogVerbatim("DoFineCalo") << "Using finecalo v2";
118 
119  // Treat fine calorimeters
120  edm::LogVerbatim("CaloSim") << "CaloSD: Have a possibility of " << fineNames.size() << " fine calorimeters of which "
121  << useFines.size() << " are selected";
122  for (unsigned int k = 0; k < fineNames.size(); ++k)
123  edm::LogVerbatim("CaloSim") << "[" << k << "] " << fineNames[k] << " at " << fineLevels[k];
124  std::ostringstream st1;
125  for (unsigned int k = 0; k < useFines.size(); ++k)
126  st1 << " [" << k << "] " << useFines[k] << ":" << fineNames[useFines[k]];
127  edm::LogVerbatim("CaloSim") << "CaloSD used calorimeters" << st1.str();
128  const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
129  std::vector<G4LogicalVolume*>::const_iterator lvcite;
130  for (unsigned int i = 0; i < useFines.size(); i++) {
131  G4LogicalVolume* lv = nullptr;
132  G4String name = static_cast<G4String>(fineNames[useFines[i]]);
133  for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
134  G4String namx(static_cast<std::string>(dd4hep::dd::noNamespace((*lvcite)->GetName())));
135  if (namx == name) {
136  lv = (*lvcite);
137  break;
138  }
139  }
140  if (lv != nullptr) {
142  detector.name = name;
143  detector.lv = lv;
144  detector.level = fineLevels[useFines[i]];
145  fineDetectors_.emplace_back(detector);
146  }
147  }
148 #ifdef EDM_ML_DEBUG
149  edm::LogVerbatim("CaloSim") << "CaloSD::Loads information for " << fineDetectors_.size() << " fine detectors";
150  unsigned int k(0);
151  for (const auto& detector : fineDetectors_) {
152  edm::LogVerbatim("CaloSim") << "Detector[" << k << "] " << detector.name << " at level " << detector.level
153  << " pointer to LV: " << detector.lv;
154  }
155 #endif
156 }
float edepositEM
Definition: CaloSD.h:140
double energyCut
Definition: CaloSD.h:144
Log< level::Info, true > LogVerbatim
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
double kmaxNeutron
Definition: CaloSD.h:149
double eMinFine_
Definition: CaloSD.h:185
bool corrTOFBeam
Definition: CaloSD.h:172
int totalHits
Definition: CaloSD.h:177
bool useMap
Definition: CaloSD.h:171
int hcID
Definition: CaloSD.h:174
double eminHitD
Definition: CaloSD.h:182
G4ThreeVector posGlobal
Definition: CaloSD.h:138
int primIDSaved
Definition: CaloSD.h:178
int primAncestor
Definition: CaloSD.h:175
double kmaxProton
Definition: CaloSD.h:149
std::vector< Detector > fineDetectors_
Definition: CaloSD.h:191
double eminHit
Definition: CaloSD.h:144
T getUntrackedParameter(std::string const &, T const &) const
bool forceSave
Definition: CaloSD.h:151
float timeSlice
Definition: CaloSD.h:181
double kmaxIon
Definition: CaloSD.h:149
bool suppressHeavy
Definition: CaloSD.h:148
std::unique_ptr< CaloSlaveSD > slave
Definition: CaloSD.h:163
float edepositHAD
Definition: CaloSD.h:140
bool doFineCalo_
Definition: CaloSD.h:184
SensitiveCaloDetector(const std::string &iname, const SensitiveDetectorCatalog &clg)
CaloHitID previousID
Definition: CaloSD.h:142
CaloG4Hit * currentHit
Definition: CaloSD.h:146
double tmaxHit
Definition: CaloSD.h:144
std::unique_ptr< CaloMeanResponse > meanResponse
Definition: CaloSD.h:164
CaloHitID currentID
Definition: CaloSD.h:142
double correctT
Definition: CaloSD.h:183
int nCheckedHits
Definition: CaloSD.h:179
CaloG4HitCollection * theHC
Definition: CaloSD.h:166
float incidentEnergy
Definition: CaloSD.h:139
bool isParameterized
Definition: CaloSD.h:169
const SimTrackManager * m_trackManager
Definition: CaloSD.h:161
G4ThreeVector entrancePoint
Definition: CaloSD.h:136
G4ThreeVector entranceLocal
Definition: CaloSD.h:137
int cleanIndex
Definition: CaloSD.h:176
bool ignoreTrackID
Definition: CaloSD.h:168

◆ ~CaloSD()

CaloSD::~CaloSD ( )
override

Definition at line 158 of file CaloSD.cc.

158 {}

Member Function Documentation

◆ checkHit()

bool CaloSD::checkHit ( )
protected

Definition at line 423 of file CaloSD.cc.

References currentHit, currentID, newFWLiteAna::found, hitMap, dqmiolumiharvest::j, SiStripPI::max, nCheckedHits, nhits, theHC, updateHit(), and useMap.

Referenced by hitExists(), processHit(), and ProcessHits().

423  {
424  //look in the HitContainer whether a hit with the same ID already exists:
425  bool found = false;
426  if (useMap) {
427  std::map<CaloHitID, CaloG4Hit*>::const_iterator it = hitMap.find(currentID);
428  if (it != hitMap.end()) {
429  currentHit = it->second;
430  found = true;
431  }
432  } else if (nCheckedHits > 0) {
433  int nhits = theHC->entries();
434  int minhit = std::max(nhits - nCheckedHits, 0);
435  int maxhit = nhits - 1;
436 
437  for (int j = maxhit; j > minhit; --j) {
438  if ((*theHC)[j]->getID() == currentID) {
439  currentHit = (*theHC)[j];
440  found = true;
441  break;
442  }
443  }
444  }
445 
446  if (found) {
448  }
449  return found;
450 }
void updateHit(CaloG4Hit *)
Definition: CaloSD.cc:633
bool useMap
Definition: CaloSD.h:171
CaloG4Hit * currentHit
Definition: CaloSD.h:146
CaloHitID currentID
Definition: CaloSD.h:142
std::map< CaloHitID, CaloG4Hit * > hitMap
Definition: CaloSD.h:187
int nCheckedHits
Definition: CaloSD.h:179
CaloG4HitCollection * theHC
Definition: CaloSD.h:166

◆ cleanHitCollection()

void CaloSD::cleanHitCollection ( )
private

Definition at line 956 of file CaloSD.cc.

References cleanIndex, correctT, corrTOFBeam, cond::serialization::equal(), filterHit(), CaloG4Hit::getTimeSlice(), hitMap, mps_fire::i, cuy::ii, dqmiolumiharvest::j, hltrates_dqm_sourceclient-live_cfg::offset, AlCaHLTBitMon_ParallelJobs::p, reusehit, jetUpdater_cfi::sort, theHC, protons_cff::time, totalHits, and useMap.

Referenced by EndOfEvent(), and update().

956  {
957  std::vector<CaloG4Hit*>* theCollection = theHC->GetVector();
958 
959 #ifdef EDM_ML_DEBUG
960  edm::LogVerbatim("CaloSim") << "CaloSD: collection before merging, size = " << theHC->entries();
961 #endif
962  if (reusehit.empty())
963  reusehit.reserve(theHC->entries() - cleanIndex);
964 
965  // if no map used, merge before hits to have the save situation as a map
966  if (!useMap) {
967  std::vector<CaloG4Hit*> hitvec;
968 
969  hitvec.swap(*theCollection);
970  sort((hitvec.begin() + cleanIndex), hitvec.end(), CaloG4HitLess());
971 #ifdef EDM_ML_DEBUG
972  edm::LogVerbatim("CaloSim") << "CaloSD::cleanHitCollection: sort hits in buffer starting from "
973  << "element = " << cleanIndex;
974  for (unsigned int i = 0; i < hitvec.size(); ++i) {
975  if (hitvec[i] == nullptr)
976  edm::LogVerbatim("CaloSim") << i << " has a null pointer";
977  else
978  edm::LogVerbatim("CaloSim") << i << " " << *hitvec[i];
979  }
980 #endif
982  for (unsigned int i = cleanIndex; i < hitvec.size(); ++i) {
983  int jump = 0;
984  for (unsigned int j = i + 1; j < hitvec.size() && equal(hitvec[i], hitvec[j]); ++j) {
985  ++jump;
986  // merge j to i
987  (*hitvec[i]).addEnergyDeposit(*hitvec[j]);
988  (*hitvec[j]).setEM(0.);
989  (*hitvec[j]).setHadr(0.);
990  reusehit.emplace_back(hitvec[j]);
991  hitvec[j] = nullptr;
992  }
993  i += jump;
994  }
995 #ifdef EDM_ML_DEBUG
996  edm::LogVerbatim("CaloSim") << "CaloSD: cleanHitCollection merge the hits in buffer ";
997  for (unsigned int i = 0; i < hitvec.size(); ++i) {
998  if (hitvec[i] == nullptr)
999  edm::LogVerbatim("CaloSim") << i << " has a null pointer";
1000  else
1001  edm::LogVerbatim("CaloSim") << i << " " << *hitvec[i];
1002  }
1003 #endif
1004  //move all nullptr to end of list and then remove them
1005  hitvec.erase(
1006  std::stable_partition(hitvec.begin() + cleanIndex, hitvec.end(), [](CaloG4Hit* p) { return p != nullptr; }),
1007  hitvec.end());
1008 #ifdef EDM_ML_DEBUG
1009  edm::LogVerbatim("CaloSim") << "CaloSD::cleanHitCollection: remove the merged hits in buffer,"
1010  << " new size = " << hitvec.size();
1011 #endif
1012  hitvec.swap(*theCollection);
1013  totalHits = theHC->entries();
1014  }
1015 
1016 #ifdef EDM_ML_DEBUG
1017  edm::LogVerbatim("CaloSim") << "CaloSD: collection after merging, size= " << theHC->entries()
1018  << " Size of reusehit= " << reusehit.size()
1019  << "\n starting hit selection from index = " << cleanIndex;
1020 #endif
1021 
1022  int addhit = 0;
1023  for (unsigned int i = cleanIndex; i < theCollection->size(); ++i) {
1024  CaloG4Hit* aHit((*theCollection)[i]);
1025 
1026  // selection
1027 
1028  double time = aHit->getTimeSlice();
1029  if (corrTOFBeam)
1030  time += correctT;
1031  if (!filterHit(aHit, time)) {
1032 #ifdef EDM_ML_DEBUG
1033  edm::LogVerbatim("CaloSim") << "CaloSD: dropped CaloG4Hit "
1034  << " " << *aHit;
1035 #endif
1036 
1037  // create the list of hits to be reused
1038 
1039  reusehit.emplace_back((*theCollection)[i]);
1040  (*theCollection)[i] = nullptr;
1041  ++addhit;
1042  }
1043  }
1044 
1045 #ifdef EDM_ML_DEBUG
1046  edm::LogVerbatim("CaloSim") << "CaloSD: Size of reusehit after selection = " << reusehit.size()
1047  << " Number of added hit = " << addhit;
1048 #endif
1049  if (useMap) {
1050  if (addhit > 0) {
1051  int offset = reusehit.size() - addhit;
1052  for (int ii = addhit - 1; ii >= 0; --ii) {
1053  CaloHitID theID = reusehit[offset + ii]->getID();
1054  hitMap.erase(theID);
1055  }
1056  }
1057  }
1058 
1059  //move all nullptr to end of list and then remove them
1060  theCollection->erase(
1061  std::stable_partition(
1062  theCollection->begin() + cleanIndex, theCollection->end(), [](CaloG4Hit* p) { return p != nullptr; }),
1063  theCollection->end());
1064 #ifdef EDM_ML_DEBUG
1065  edm::LogVerbatim("CaloSim") << "CaloSD: hit collection after selection, size = " << theHC->entries();
1066  theHC->PrintAllHits();
1067 #endif
1068 
1069  cleanIndex = theHC->entries();
1070 }
Log< level::Info, true > LogVerbatim
bool corrTOFBeam
Definition: CaloSD.h:172
int totalHits
Definition: CaloSD.h:177
bool useMap
Definition: CaloSD.h:171
bool equal(const T &first, const T &second)
Definition: Equal.h:32
virtual bool filterHit(CaloG4Hit *, double)
Definition: CaloSD.cc:838
ii
Definition: cuy.py:589
double correctT
Definition: CaloSD.h:183
std::map< CaloHitID, CaloG4Hit * > hitMap
Definition: CaloSD.h:187
CaloG4HitCollection * theHC
Definition: CaloSD.h:166
std::vector< std::unique_ptr< CaloG4Hit > > reusehit
Definition: CaloSD.h:190
int cleanIndex
Definition: CaloSD.h:176

◆ clear()

void CaloSD::clear ( void  )
override

Definition at line 372 of file CaloSD.cc.

372 {}

◆ clearHits()

void CaloSD::clearHits ( )
overridevirtual

Implements SensitiveDetector.

Definition at line 773 of file CaloSD.cc.

References cleanIndex, previousID, primIDSaved, CaloHitID::reset(), and slave.

Referenced by update().

773  {
774  cleanIndex = 0;
775  previousID.reset();
776  primIDSaved = -99;
777 #ifdef EDM_ML_DEBUG
778  edm::LogVerbatim("CaloSim") << "CaloSD: Clears hit vector for " << GetName()
779  << " and initialise slave: " << slave.get()->name();
780 #endif
781  slave.get()->Initialize();
782 }
Log< level::Info, true > LogVerbatim
int primIDSaved
Definition: CaloSD.h:178
void reset()
Definition: CaloHitID.cc:49
std::unique_ptr< CaloSlaveSD > slave
Definition: CaloSD.h:163
CaloHitID previousID
Definition: CaloSD.h:142
int cleanIndex
Definition: CaloSD.h:176

◆ createNewHit()

CaloG4Hit * CaloSD::createNewHit ( const G4Step *  aStep,
const G4Track *  theTrack 
)
protected

Definition at line 555 of file CaloSD.cc.

References SensitiveDetector::cmsTrackInformation(), currentID, CaloHitID::depth(), doFineCaloThisStep_, edepositEM, edepositHAD, energyCut, entranceLocal, entrancePoint, f, forceSave, getNumberOfHits(), incidentEnergy, isItFineCalo(), TrackWithHistory::momentum(), posGlobal, primIDSaved, TrackInformation::putInHistory(), reusehit, TrackWithHistory::save(), CaloG4Hit::setEM(), CaloG4Hit::setEntry(), CaloG4Hit::setEntryLocal(), CaloG4Hit::setHadr(), CaloG4Hit::setID(), CaloG4Hit::setIncidentEnergy(), CaloG4Hit::setPosition(), shortreprID(), mathSSE::sqrt(), storeHit(), TrackInformation::storeTrack(), CaloHitID::timeSliceID(), tkMap, totalHits, CaloHitID::trackID(), CaloHitID::unitID(), updateHit(), and useMap.

Referenced by processHit(), and ProcessHits().

555  {
556 #ifdef EDM_ML_DEBUG
557  edm::LogVerbatim("CaloSim") << "CaloSD::CreateNewHit " << getNumberOfHits() << " for " << GetName()
558  << " Unit:" << currentID.unitID() << " " << currentID.depth() << " Edep= " << edepositEM
559  << " " << edepositHAD << " primaryID= " << currentID.trackID()
560  << " timeSlice= " << currentID.timeSliceID() << " ID= " << theTrack->GetTrackID() << " "
561  << theTrack->GetDefinition()->GetParticleName()
562  << " E(GeV)= " << theTrack->GetKineticEnergy() / CLHEP::GeV
563  << " parentID= " << theTrack->GetParentID() << "\n Ein= " << incidentEnergy
564  << " entranceGlobal: " << entrancePoint << " entranceLocal: " << entranceLocal
565  << " posGlobal: " << posGlobal;
566 #endif
567 
568  CaloG4Hit* aHit;
569  if (!reusehit.empty()) {
570  aHit = reusehit.back().release();
571  aHit->setEM(0.f);
572  aHit->setHadr(0.f);
573  reusehit.pop_back();
574  } else {
575  aHit = new CaloG4Hit;
576  }
577 
578  aHit->setID(currentID);
579  aHit->setEntry(entrancePoint.x(), entrancePoint.y(), entrancePoint.z());
581  aHit->setPosition(posGlobal.x(), posGlobal.y(), posGlobal.z());
583  updateHit(aHit);
584 
585  storeHit(aHit);
586  TrackInformation* trkInfo = cmsTrackInformation(theTrack);
587 
588 #ifdef EDM_ML_DEBUG
590  edm::LogVerbatim("DoFineCalo") << "New hit " << shortreprID(aHit) << " using finecalo;"
591  << " isItFineCalo(post)=" << isItFineCalo(aStep->GetPostStepPoint()->GetTouchable())
592  << " isItFineCalo(pre)=" << isItFineCalo(aStep->GetPreStepPoint()->GetTouchable());
593 #endif
594 
595  // 'Traditional', non-fine history bookkeeping
596  if (!doFineCaloThisStep_) {
597  double etrack = 0;
598  if (currentID.trackID() == primIDSaved) { // The track is saved; nothing to be done
599  } else if (currentID.trackID() == theTrack->GetTrackID()) {
600  etrack = theTrack->GetKineticEnergy();
601 #ifdef EDM_ML_DEBUG
602  edm::LogVerbatim("CaloSim") << "CaloSD: set save the track " << currentID.trackID() << " etrack " << etrack
603  << " eCut " << energyCut << " force: " << forceSave
604  << " save: " << (etrack >= energyCut || forceSave);
605 #endif
606  if (etrack >= energyCut || forceSave) {
607  trkInfo->storeTrack(true);
608  trkInfo->putInHistory();
609  }
610  } else {
612 #ifdef EDM_ML_DEBUG
613  edm::LogVerbatim("CaloSim") << "CaloSD : TrackWithHistory pointer for " << currentID.trackID() << " is " << trkh;
614 #endif
615  if (trkh != nullptr) {
616  etrack = sqrt(trkh->momentum().Mag2());
617  if (etrack >= energyCut) {
618  trkh->save();
619 #ifdef EDM_ML_DEBUG
620  edm::LogVerbatim("CaloSim") << "CaloSD: set save the track " << currentID.trackID() << " with Hit";
621 #endif
622  }
623  }
624  }
626  }
627 
628  if (useMap)
629  ++totalHits;
630  return aHit;
631 }
float edepositEM
Definition: CaloSD.h:140
bool storeTrack() const
double energyCut
Definition: CaloSD.h:144
Log< level::Info, true > LogVerbatim
bool doFineCaloThisStep_
Definition: CaloSD.h:192
void updateHit(CaloG4Hit *)
Definition: CaloSD.cc:633
int totalHits
Definition: CaloSD.h:177
void setIncidentEnergy(double e)
Definition: CaloG4Hit.h:62
const math::XYZVectorD & momentum() const
void setEntryLocal(double x, double y, double z)
Definition: CaloG4Hit.h:50
bool useMap
Definition: CaloSD.h:171
G4ThreeVector posGlobal
Definition: CaloSD.h:138
int primIDSaved
Definition: CaloSD.h:178
bool forceSave
Definition: CaloSD.h:151
int timeSliceID() const
Definition: CaloHitID.h:21
bool isItFineCalo(const G4VTouchable *touch)
Definition: CaloSD.cc:321
float edepositHAD
Definition: CaloSD.h:140
T sqrt(T t)
Definition: SSEVec.h:19
void setEM(double e)
Definition: CaloG4Hit.h:56
void setID(uint32_t i, double d, int j, uint16_t k=0)
Definition: CaloG4Hit.h:73
double f[11][100]
int getNumberOfHits()
Definition: CaloSD.cc:452
uint32_t unitID() const
Definition: CaloHitID.h:20
void storeHit(CaloG4Hit *)
Definition: CaloSD.cc:858
TrackInformation * cmsTrackInformation(const G4Track *aTrack)
CaloHitID currentID
Definition: CaloSD.h:142
void setHadr(double e)
Definition: CaloG4Hit.h:59
float incidentEnergy
Definition: CaloSD.h:139
void setPosition(double x, double y, double z)
Definition: CaloG4Hit.h:53
void setEntry(double x, double y, double z)
Definition: CaloG4Hit.h:47
std::map< int, TrackWithHistory * > tkMap
Definition: CaloSD.h:188
std::vector< std::unique_ptr< CaloG4Hit > > reusehit
Definition: CaloSD.h:190
std::string shortreprID(const CaloHitID &ID)
Definition: CaloSD.cc:469
int trackID() const
Definition: CaloHitID.h:23
G4ThreeVector entrancePoint
Definition: CaloSD.h:136
G4ThreeVector entranceLocal
Definition: CaloSD.h:137
uint16_t depth() const
Definition: CaloHitID.h:24

◆ DrawAll()

void CaloSD::DrawAll ( )
override

Definition at line 374 of file CaloSD.cc.

374 {}

◆ endEvent()

void CaloSD::endEvent ( )
protectedvirtual

Reimplemented in HGCSD.

Definition at line 794 of file CaloSD.cc.

Referenced by update().

794 {}

◆ EndOfEvent()

void CaloSD::EndOfEvent ( G4HCofThisEvent *  eventHC)
override

Definition at line 359 of file CaloSD.cc.

References cleanHitCollection(), and theHC.

359  {
360  // clean the hits for the last tracks
361 
363 
364 #ifdef EDM_ML_DEBUG
365  if (theHC == nullptr)
366  edm::LogVerbatim("CaloSim") << "CaloSD: EndofEvent entered with no entries";
367  else
368  edm::LogVerbatim("CaloSim") << "CaloSD: EndofEvent entered with " << theHC->entries() << " entries";
369 #endif
370 }
Log< level::Info, true > LogVerbatim
void cleanHitCollection()
Definition: CaloSD.cc:956
CaloG4HitCollection * theHC
Definition: CaloSD.h:166

◆ EnergyCorrected()

double CaloSD::EnergyCorrected ( const G4Step &  step,
const G4Track *   
)
protectedvirtual

Reimplemented in ECalSD.

Definition at line 317 of file CaloSD.cc.

Referenced by ProcessHits().

317 { return aStep.GetTotalEnergyDeposit(); }

◆ fillHits()

void CaloSD::fillHits ( edm::PCaloHitContainer cc,
const std::string &  hname 
)
overridevirtual

Implements SensitiveCaloDetector.

Definition at line 383 of file CaloSD.cc.

References slave.

383  {
384 #ifdef EDM_ML_DEBUG
385  edm::LogVerbatim("CaloSim") << "CaloSD: Tries to transfer " << slave.get()->hits().size() << " hits for "
386  << slave.get()->name() << " " << hname;
387 #endif
388  if (slave.get()->name() == hname) {
389  cc = slave.get()->hits();
390  }
391  slave.get()->Clean();
392 }
Log< level::Info, true > LogVerbatim
std::unique_ptr< CaloSlaveSD > slave
Definition: CaloSD.h:163

◆ filterHit()

bool CaloSD::filterHit ( CaloG4Hit hit,
double  time 
)
protectedvirtual

Reimplemented in HCalSD, HGCSD, HFNoseSD, HGCalSD, HGCScintSD, and AHCalSD.

Definition at line 838 of file CaloSD.cc.

References eminHit, eminHitD, protons_cff::time, and tmaxHit.

Referenced by cleanHitCollection().

838  {
839  double emin(eminHit);
840  if (hit->getDepth() > 0)
841  emin = eminHitD;
842 #ifdef EDM_ML_DEBUG
843  edm::LogVerbatim("CaloSim") << "CaloSD::filterHit(..) Depth " << hit->getDepth() << " Emin = " << emin << " ("
844  << eminHit << ", " << eminHitD << ")";
845 #endif
846  return ((time <= tmaxHit) && (hit->getEnergyDeposit() > emin));
847 }
Log< level::Info, true > LogVerbatim
double eminHitD
Definition: CaloSD.h:182
double eminHit
Definition: CaloSD.h:144
double tmaxHit
Definition: CaloSD.h:144

◆ findBoundaryCrossingParent()

unsigned int CaloSD::findBoundaryCrossingParent ( const G4Track *  track,
bool  markParentAsSaveable = true 
)
protected

Definition at line 483 of file CaloSD.cc.

References boundaryCrossingParentMap_, SensitiveDetector::cmsTrackInformation(), TrackInformation::crossedBoundary(), Exception, SimTrackManager::getTrackByID(), triggerObjects_cff::id, m_trackManager, TrackWithHistory::parentID(), cosmicMuonLinks_cfi::parentTrack, printableDecayChain(), TrackInformation::storeTrack(), and HLT_2022v12_cff::track.

Referenced by ProcessHits().

483  {
485  unsigned int id = track->GetTrackID();
486  // First see if this track is already in the map
487  auto it = boundaryCrossingParentMap_.find(id);
488  if (it != boundaryCrossingParentMap_.end()) {
489 #ifdef EDM_ML_DEBUG
490  edm::LogVerbatim("DoFineCalo") << "Track " << id << " parent already cached: " << it->second;
491 #endif
492  return it->second;
493  }
494  // Then see if the track itself crosses the boundary
495  else if (trkInfo->crossedBoundary()) {
496 #ifdef EDM_ML_DEBUG
497  edm::LogVerbatim("DoFineCalo") << "Track " << id << " crosses boundary itself";
498 #endif
500  trkInfo->storeTrack(true);
501  return id;
502  }
503  // Else, traverse the history of the track
504  std::vector<unsigned int> decayChain{id};
505 #ifdef EDM_ML_DEBUG
506  edm::LogVerbatim("DoFineCalo") << "Track " << id << ": Traversing history to find boundary-crossing parent";
507 #endif
508  unsigned int parentID = track->GetParentID();
509  while (true) {
510  if (parentID == 0)
511  throw cms::Exception("Unknown", "CaloSD")
512  << "Hit end of parentage for track " << id << " without finding a boundary-crossing parent";
513  // First check if this ancestor is already in the map
514  auto it = boundaryCrossingParentMap_.find(parentID);
515  if (it != boundaryCrossingParentMap_.end()) {
516 #ifdef EDM_ML_DEBUG
517  edm::LogVerbatim("DoFineCalo") << " Track " << parentID
518  << " boundary-crossing parent already cached: " << it->second;
519 #endif
520  // Store this parent also for the rest of the traversed decay chain
521  for (auto ancestorID : decayChain)
522  boundaryCrossingParentMap_[ancestorID] = it->second;
523 #ifdef EDM_ML_DEBUG
524  // In debug mode, still build the rest of the decay chain for debugging
525  decayChain.push_back(parentID);
526  while (parentID != it->second) {
527  parentID = m_trackManager->getTrackByID(parentID, true)->parentID();
528  decayChain.push_back(parentID);
529  }
530  edm::LogVerbatim("DoFineCalo") << " Full decay chain: " << printableDecayChain(decayChain);
531 #endif
532  return it->second;
533  }
534  // If not, get this parent from the track manager (expensive)
536  if (parentTrack->crossedBoundary()) {
537  if (markAsSaveable)
538  parentTrack->save();
539  decayChain.push_back(parentID);
540  // Record this boundary crossing parent for all traversed ancestors
541  for (auto ancestorID : decayChain)
542  boundaryCrossingParentMap_[ancestorID] = parentID;
543 #ifdef EDM_ML_DEBUG
544  edm::LogVerbatim("DoFineCalo") << " Found boundary-crossing ancestor " << parentID << " for track " << id
545  << "; decay chain: " << printableDecayChain(decayChain);
546 #endif
547  return parentID;
548  }
549  // Next iteration
550  decayChain.push_back(parentID);
551  parentID = parentTrack->parentID();
552  }
553 }
bool storeTrack() const
Log< level::Info, true > LogVerbatim
bool crossedBoundary() const
int parentID() const
TrackWithHistory * getTrackByID(unsigned int trackID, bool strict=false) const
std::unordered_map< unsigned int, unsigned int > boundaryCrossingParentMap_
Definition: CaloSD.h:189
static std::string printableDecayChain(const std::vector< unsigned int > &decayChain)
Definition: CaloSD.cc:458
TrackInformation * cmsTrackInformation(const G4Track *aTrack)
const SimTrackManager * m_trackManager
Definition: CaloSD.h:161

◆ getAttenuation()

double CaloSD::getAttenuation ( const G4Step *  aStep,
double  birk1,
double  birk2,
double  birk3 
) const
protected

Definition at line 657 of file CaloSD.cc.

References funct::abs(), c, ALCARECOTkAlJpsiMuMu_cff::charge, fastSimProducer_cff::density, and mps_merge::weight.

Referenced by TotemT2ScintSD::getEnergyDeposit(), AHCalSD::getEnergyDeposit(), HGCalTB16SD01::getEnergyDeposit(), HcalTB06BeamSD::getEnergyDeposit(), HGCScintSD::getEnergyDeposit(), EcalTBH4BeamSD::getEnergyDeposit(), DreamSD::getEnergyDeposit(), ECalSD::getEnergyDeposit(), HcalTB02SD::getEnergyDeposit(), and HCalSD::getEnergyDeposit().

657  {
658  double weight = 1.;
659  double charge = aStep->GetPreStepPoint()->GetCharge();
660  double length = aStep->GetStepLength();
661 
662  if (charge != 0. && length > 0.) {
663  double density = aStep->GetPreStepPoint()->GetMaterial()->GetDensity();
664  double dedx = aStep->GetTotalEnergyDeposit() / length;
665  double rkb = birk1 / density;
666  double c = birk2 * rkb * rkb;
667  if (std::abs(charge) >= 2.)
668  rkb /= birk3; // based on alpha particle data
669  weight = 1. / (1. + rkb * dedx + c * dedx * dedx);
670 #ifdef EDM_ML_DEBUG
671  edm::LogVerbatim("CaloSim") << "CaloSD::getAttenuation in " << aStep->GetPreStepPoint()->GetMaterial()->GetName()
672  << " Charge " << charge << " dE/dx " << dedx << " Birk Const " << rkb << ", " << c
673  << " Weight = " << weight << " dE " << aStep->GetTotalEnergyDeposit();
674 #endif
675  }
676  return weight;
677 }
Log< level::Info, true > LogVerbatim
Definition: weight.py:1
Abs< T >::type abs(const T &t)
Definition: Abs.h:22

◆ getDepth()

uint16_t CaloSD::getDepth ( const G4Step *  )
protectedvirtual

Reimplemented in ECalSD.

Definition at line 836 of file CaloSD.cc.

Referenced by ProcessHits().

836 { return 0; }

◆ getEnergyDeposit()

double CaloSD::getEnergyDeposit ( const G4Step *  step)
protectedvirtual

Reimplemented in HCalSD, ECalSD, HcalTB02SD, CastorSD, DreamSD, HGCSD, HFNoseSD, HGCalSD, EcalTBH4BeamSD, HGCScintSD, HcalTB06BeamSD, ZdcSD, HGCalTB16SD01, AHCalSD, and TotemT2ScintSD.

Definition at line 315 of file CaloSD.cc.

Referenced by ProcessHits().

315 { return aStep->GetTotalEnergyDeposit(); }

◆ getFromLibrary()

bool CaloSD::getFromLibrary ( const G4Step *  step)
protectedvirtual

Reimplemented in HCalSD, CastorSD, and ZdcSD.

Definition at line 319 of file CaloSD.cc.

Referenced by ProcessHits().

319 { return false; }

◆ getNumberOfHits()

int CaloSD::getNumberOfHits ( )
protected

Definition at line 452 of file CaloSD.cc.

References theHC.

Referenced by createNewHit(), and HCalSD::getFromLibrary().

452 { return theHC->entries(); }
CaloG4HitCollection * theHC
Definition: CaloSD.h:166

◆ getResponseWt()

double CaloSD::getResponseWt ( const G4Track *  aTrack)
protected

Definition at line 849 of file CaloSD.cc.

References SensitiveDetector::cmsTrackInformation(), TrackInformation::genParticleP(), TrackInformation::genParticlePID(), and meanResponse.

Referenced by ECalSD::EnergyCorrected(), HGCScintSD::getEnergyDeposit(), HFNoseSD::getEnergyDeposit(), HGCalSD::getEnergyDeposit(), HGCSD::getEnergyDeposit(), ECalSD::getEnergyDeposit(), and HCalSD::getEnergyDeposit().

849  {
850  double wt = 1.0;
851  if (meanResponse.get()) {
852  TrackInformation* trkInfo = cmsTrackInformation(aTrack);
853  wt = meanResponse.get()->getWeight(trkInfo->genParticlePID(), trkInfo->genParticleP());
854  }
855  return wt;
856 }
double genParticleP() const
TrackInformation * cmsTrackInformation(const G4Track *aTrack)
int genParticlePID() const
std::unique_ptr< CaloMeanResponse > meanResponse
Definition: CaloSD.h:164

◆ getTrackID()

int CaloSD::getTrackID ( const G4Track *  aTrack)
protectedvirtual

Reimplemented in ECalSD.

Definition at line 796 of file CaloSD.cc.

References SensitiveDetector::cmsTrackInformation(), and TrackInformation::getIDonCaloSurface().

Referenced by ECalSD::getTrackID(), and ProcessHits().

796  {
797  int primaryID = 0;
798  TrackInformation* trkInfo = cmsTrackInformation(aTrack);
799  if (trkInfo) {
800  primaryID = trkInfo->getIDonCaloSurface();
801 #ifdef EDM_ML_DEBUG
802  edm::LogVerbatim("CaloSim") << "Track ID: " << trkInfo->getIDonCaloSurface() << ":" << aTrack->GetTrackID() << ":"
803  << primaryID;
804 #endif
805  } else {
806  primaryID = aTrack->GetTrackID();
807 #ifdef EDM_ML_DEBUG
808  edm::LogWarning("CaloSim") << "CaloSD: Problem with primaryID **** set by force to TkID **** " << primaryID;
809 #endif
810  }
811  return primaryID;
812 }
Log< level::Info, true > LogVerbatim
TrackInformation * cmsTrackInformation(const G4Track *aTrack)
int getIDonCaloSurface() const
Log< level::Warning, false > LogWarning

◆ hitExists()

bool CaloSD::hitExists ( const G4Step *  aStep)
protected

Definition at line 402 of file CaloSD.cc.

References checkHit(), currentHit, currentID, posGlobal, previousID, resetForNewPrimary(), CaloHitID::trackID(), and updateHit().

Referenced by ProcessHits().

402  {
403  // Update if in the same detector, time-slice and for same track
404  if (currentID == previousID) {
406  return true;
407  }
408 
409  // Note T. Klijnsma:
410  // This is a rather strange place to set these class variables.
411  // The code would be much more readable if all logic for determining
412  // whether to update a hit or create a new hit is done in one place,
413  // and only then perform the actual updating or creating of the hit.
414 
415  // Reset entry point for new primary
416  posGlobal = aStep->GetPreStepPoint()->GetPosition();
417  if (currentID.trackID() != previousID.trackID()) {
418  resetForNewPrimary(aStep);
419  }
420  return checkHit();
421 }
void updateHit(CaloG4Hit *)
Definition: CaloSD.cc:633
G4ThreeVector posGlobal
Definition: CaloSD.h:138
bool checkHit()
Definition: CaloSD.cc:423
void resetForNewPrimary(const G4Step *)
Definition: CaloSD.cc:644
CaloHitID previousID
Definition: CaloSD.h:142
CaloG4Hit * currentHit
Definition: CaloSD.h:146
CaloHitID currentID
Definition: CaloSD.h:142
int trackID() const
Definition: CaloHitID.h:23

◆ ignoreRejection()

void CaloSD::ignoreRejection ( )
inlineprotected

Definition at line 108 of file CaloSD.h.

References ignoreReject.

Referenced by HGCalSD::setDetUnitId().

108 { ignoreReject = true; }
bool ignoreReject
Definition: CaloSD.h:170

◆ initEvent()

void CaloSD::initEvent ( const BeginOfEvent )
protectedvirtual

Reimplemented in HGCSD.

Definition at line 792 of file CaloSD.cc.

Referenced by update().

792 {}

◆ Initialize()

void CaloSD::Initialize ( G4HCofThisEvent *  HCE)
override

Definition at line 341 of file CaloSD.cc.

References bysipixelclustmulteventfilter_cfi::collectionName, hcID, theHC, and totalHits.

341  {
342  totalHits = 0;
343 
344 #ifdef EDM_ML_DEBUG
345  edm::LogVerbatim("CaloSim") << "CaloSD : Initialize called for " << GetName();
346 #endif
347 
348  //This initialization is performed at the beginning of an event
349  //------------------------------------------------------------
350  theHC = new CaloG4HitCollection(GetName(), collectionName[0]);
351 
352  if (hcID < 0) {
353  hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
354  }
355  //theHC ownership is transfered here to HCE
356  HCE->AddHitsCollection(hcID, theHC);
357 }
Log< level::Info, true > LogVerbatim
int totalHits
Definition: CaloSD.h:177
int hcID
Definition: CaloSD.h:174
CaloG4HitCollection * theHC
Definition: CaloSD.h:166
G4THitsCollection< CaloG4Hit > CaloG4HitCollection

◆ initRun()

void CaloSD::initRun ( )
protectedvirtual

Reimplemented in HCalSD, HGCSD, DreamSD, HFNoseSD, HGCalSD, HGCScintSD, and ZdcSD.

Definition at line 790 of file CaloSD.cc.

Referenced by update().

790 {}

◆ isItFineCalo()

bool CaloSD::isItFineCalo ( const G4VTouchable *  touch)

Definition at line 321 of file CaloSD.cc.

References hgcalTestNeighbor_cfi::detector, fineDetectors_, cuy::ii, personalPlayback::level, convertSQLiteXML::ok, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by createNewHit(), and ProcessHits().

321  {
322  bool ok(false);
323  int level = ((touch->GetHistoryDepth()) + 1);
324  for (const auto& detector : fineDetectors_) {
325  if (level > 0 && level >= detector.level) {
326  int ii = level - detector.level;
327  G4LogicalVolume* lv = touch->GetVolume(ii)->GetLogicalVolume();
328  ok = (lv == detector.lv);
329 #ifdef EDM_ML_DEBUG
330  std::string name1 = (lv == 0) ? "Unknown" : lv->GetName();
331  edm::LogVerbatim("CaloSim") << "CaloSD: volume " << name1 << ":" << detector.name << " at Level "
332  << detector.level << " Flag " << ok;
333 #endif
334  if (ok)
335  break;
336  }
337  }
338  return ok;
339 }
Log< level::Info, true > LogVerbatim
std::vector< Detector > fineDetectors_
Definition: CaloSD.h:191
ii
Definition: cuy.py:589

◆ printableDecayChain()

std::string CaloSD::printableDecayChain ( const std::vector< unsigned int > &  decayChain)
staticprotected

Definition at line 458 of file CaloSD.cc.

References mps_fire::i, and contentValuesCheck::ss.

Referenced by findBoundaryCrossingParent().

458  {
459  std::stringstream ss;
460  for (long unsigned int i = 0; i < decayChain.size(); i++) {
461  if (i > 0)
462  ss << " <- ";
463  ss << decayChain[i];
464  }
465  return ss.str();
466 }

◆ PrintAll()

void CaloSD::PrintAll ( )
override

Definition at line 376 of file CaloSD.cc.

References theHC.

376  {
377 #ifdef EDM_ML_DEBUG
378  edm::LogVerbatim("CaloSim") << "CaloSD: Collection " << theHC->GetName();
379 #endif
380  theHC->PrintAllHits();
381 }
Log< level::Info, true > LogVerbatim
CaloG4HitCollection * theHC
Definition: CaloSD.h:166

◆ printDetectorLevels()

void CaloSD::printDetectorLevels ( const G4VTouchable *  touch) const
protected

Definition at line 1072 of file CaloSD.cc.

References mps_fire::i, cuy::ii, personalPlayback::level, Skims_PA_cff::name, MetAnalyzer::pv(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by HGCScintSD::setDetUnitId(), and HGCalSD::setDetUnitId().

1072  {
1073  //Print name and copy numbers
1074  int level = ((touch->GetHistoryDepth()) + 1);
1075  std::ostringstream st1;
1076  st1 << level << " Levels:";
1077  if (level > 0) {
1078  for (int ii = 0; ii < level; ii++) {
1079  int i = level - ii - 1;
1080  G4VPhysicalVolume* pv = touch->GetVolume(i);
1081  std::string name = (pv != nullptr) ? pv->GetName() : "Unknown";
1082  st1 << " " << name << ":" << touch->GetReplicaNumber(i);
1083  }
1084  }
1085  edm::LogVerbatim("CaloSim") << st1.str();
1086 }
Log< level::Info, true > LogVerbatim
def pv(vc)
Definition: MetAnalyzer.py:7
ii
Definition: cuy.py:589

◆ processHit()

void CaloSD::processHit ( const G4Step *  step)
inlineprotected

Definition at line 113 of file CaloSD.h.

References checkHit(), createNewHit(), currentHit, currentID, previousID, and updateHit().

Referenced by HCalSD::getFromHFLibrary(), ZdcSD::getFromLibrary(), CastorSD::getFromLibrary(), HCalSD::getFromParam(), HCalSD::getHitFibreBundle(), HCalSD::getHitPMT(), and HCalSD::hitForFibre().

113  {
114  // check if it is in the same unit and timeslice as the previous one
115  if (currentID == previousID) {
117  } else if (!checkHit()) {
118  currentHit = createNewHit(step, step->GetTrack());
119  }
120  }
void updateHit(CaloG4Hit *)
Definition: CaloSD.cc:633
bool checkHit()
Definition: CaloSD.cc:423
CaloG4Hit * createNewHit(const G4Step *, const G4Track *)
Definition: CaloSD.cc:555
CaloHitID previousID
Definition: CaloSD.h:142
CaloG4Hit * currentHit
Definition: CaloSD.h:146
CaloHitID currentID
Definition: CaloSD.h:142
step
Definition: StallMonitor.cc:98

◆ ProcessHits() [1/2]

G4bool CaloSD::ProcessHits ( G4Step *  step,
G4TouchableHistory *   
)
overridevirtual

Implements SensitiveDetector.

Definition at line 160 of file CaloSD.cc.

References createNewHit(), currentHit, currentID, TauDecayModes::dec, LEDCalibrationChannels::depth, doFineCalo_, doFineCaloThisStep_, edepositEM, edepositHAD, HCALHighEnergyHPDFilter_cfi::energy, findBoundaryCrossingParent(), getDepth(), getEnergyDeposit(), getFromLibrary(), getTrackID(), hitExists(), ignoreReject, G4TrackToParticleID::isGammaElectronPositron(), isItFineCalo(), isParameterized, CaloHitID::markAsFinecaloTrackID(), SensitiveDetector::NaNTrap(), previousID, setDetUnitId(), CaloHitID::setID(), shortreprID(), protons_cff::time, and CaloHitID::unitID().

160  {
161  NaNTrap(aStep);
162  ignoreReject = false;
163 
164 #ifdef EDM_ML_DEBUG
165  edm::LogVerbatim("CaloSim") << "CaloSD::" << GetName() << " ID= " << aStep->GetTrack()->GetTrackID()
166  << " prID= " << aStep->GetTrack()->GetParentID()
167  << " Eprestep= " << aStep->GetPreStepPoint()->GetKineticEnergy()
168  << " step= " << aStep->GetStepLength() << " Edep= " << aStep->GetTotalEnergyDeposit();
169 #endif
170 
171  // Class variable to determine whether finecalo rules should apply for this step
172  doFineCaloThisStep_ = (doFineCalo_ && isItFineCalo(aStep->GetPreStepPoint()->GetTouchable()));
173 
174  // apply shower library or parameterisation
175  if (isParameterized) {
176  if (getFromLibrary(aStep)) {
177  // for parameterized showers the primary track should be killed
178  aStep->GetTrack()->SetTrackStatus(fStopAndKill);
179  auto tv = aStep->GetSecondary();
180  auto vol = aStep->GetPreStepPoint()->GetPhysicalVolume();
181  for (auto& tk : *tv) {
182  if (tk->GetVolume() == vol) {
183  tk->SetTrackStatus(fStopAndKill);
184  }
185  }
186  return true;
187  }
188  }
189 
190  // ignore steps without energy deposit
191  edepositEM = edepositHAD = 0.f;
192  unsigned int unitID = setDetUnitId(aStep);
193  auto const theTrack = aStep->GetTrack();
194  uint16_t depth = getDepth(aStep);
195 
196  double time = theTrack->GetGlobalTime() / nanosecond;
197  int primaryID = getTrackID(theTrack);
198  if (unitID > 0) {
199  currentID.setID(unitID, time, primaryID, depth);
200  } else {
201  if (aStep->GetTotalEnergyDeposit() > 0.0 && (!ignoreReject)) {
202  const G4TouchableHistory* touch = static_cast<const G4TouchableHistory*>(theTrack->GetTouchable());
203  edm::LogVerbatim("CaloSim") << "CaloSD::ProcessHits: unitID= " << unitID << " currUnit= " << currentID.unitID()
204  << " Detector: " << GetName() << " trackID= " << theTrack->GetTrackID() << " "
205  << theTrack->GetDefinition()->GetParticleName()
206  << "\n Edep= " << aStep->GetTotalEnergyDeposit()
207  << " PV: " << touch->GetVolume(0)->GetName()
208  << " PVid= " << touch->GetReplicaNumber(0) << " MVid= " << touch->GetReplicaNumber(1);
209  }
210  return false;
211  }
212 
213  if (aStep->GetTotalEnergyDeposit() == 0.0) {
214  return false;
215  }
216 
217  double energy = getEnergyDeposit(aStep);
218  if (energy > 0.0) {
219  if (doFineCaloThisStep_) {
220  currentID.setID(unitID, time, findBoundaryCrossingParent(theTrack), depth);
222  }
224  edepositEM = energy;
225  } else {
227  }
228 #ifdef EDM_ML_DEBUG
229  G4TouchableHistory* touch = (G4TouchableHistory*)(theTrack->GetTouchable());
230  edm::LogVerbatim("CaloSim") << "CaloSD::" << GetName() << " PV:" << touch->GetVolume(0)->GetName()
231  << " PVid=" << touch->GetReplicaNumber(0) << " MVid=" << touch->GetReplicaNumber(1)
232  << " Unit:" << std::hex << unitID << std::dec << " Edep=" << edepositEM << " "
233  << edepositHAD << " ID=" << theTrack->GetTrackID() << " pID=" << theTrack->GetParentID()
234  << " E=" << theTrack->GetKineticEnergy() << " S=" << aStep->GetStepLength() << "\n "
235  << theTrack->GetDefinition()->GetParticleName() << " primaryID= " << primaryID
236  << " currentID= (" << currentID << ") previousID= (" << previousID << ")";
237 #endif
238  if (!hitExists(aStep)) {
239  currentHit = createNewHit(aStep, aStep->GetTrack());
240  } else {
241 #ifdef EDM_ML_DEBUG
242  edm::LogVerbatim("DoFineCalo") << "Not creating new hit, only updating " << shortreprID(currentHit);
243 #endif
244  }
245  return true;
246  }
247  return false;
248 }
float edepositEM
Definition: CaloSD.h:140
Log< level::Info, true > LogVerbatim
bool ignoreReject
Definition: CaloSD.h:170
virtual bool getFromLibrary(const G4Step *step)
Definition: CaloSD.cc:319
bool doFineCaloThisStep_
Definition: CaloSD.h:192
virtual uint16_t getDepth(const G4Step *)
Definition: CaloSD.cc:836
virtual double getEnergyDeposit(const G4Step *step)
Definition: CaloSD.cc:315
unsigned int findBoundaryCrossingParent(const G4Track *track, bool markParentAsSaveable=true)
Definition: CaloSD.cc:483
uint32_t setDetUnitId(const G4Step *step) override=0
virtual int getTrackID(const G4Track *)
Definition: CaloSD.cc:796
bool isItFineCalo(const G4VTouchable *touch)
Definition: CaloSD.cc:321
float edepositHAD
Definition: CaloSD.h:140
bool doFineCalo_
Definition: CaloSD.h:184
CaloG4Hit * createNewHit(const G4Step *, const G4Track *)
Definition: CaloSD.cc:555
CaloHitID previousID
Definition: CaloSD.h:142
CaloG4Hit * currentHit
Definition: CaloSD.h:146
uint32_t unitID() const
Definition: CaloHitID.h:20
void setID(uint32_t unitID, double timeSlice, int trackID, uint16_t depth=0)
Definition: CaloHitID.cc:41
bool hitExists(const G4Step *)
Definition: CaloSD.cc:402
CaloHitID currentID
Definition: CaloSD.h:142
void markAsFinecaloTrackID(bool flag=true)
Definition: CaloHitID.h:29
static bool isGammaElectronPositron(int pdgCode)
bool isParameterized
Definition: CaloSD.h:169
std::string shortreprID(const CaloHitID &ID)
Definition: CaloSD.cc:469
void NaNTrap(const G4Step *step) const

◆ ProcessHits() [2/2]

bool CaloSD::ProcessHits ( G4GFlashSpot *  aSpot,
G4TouchableHistory *   
)
override

Definition at line 250 of file CaloSD.cc.

References checkHit(), createNewHit(), currentHit, currentID, TauDecayModes::dec, LEDCalibrationChannels::depth, edepositEM, edepositHAD, EnergyCorrected(), entranceLocal, entrancePoint, getDepth(), getTrackID(), incidentEnergy, G4TrackToParticleID::isGammaElectronPositron(), posGlobal, previousID, setDetUnitId(), CaloHitID::setID(), protons_cff::time, HLT_2022v12_cff::track, CaloHitID::trackID(), CaloHitID::unitID(), and updateHit().

250  {
251  edepositEM = edepositHAD = 0.f;
252  const G4Track* track = aSpot->GetOriginatorTrack()->GetPrimaryTrack();
253 
254  double edep = aSpot->GetEnergySpot()->GetEnergy();
255  if (edep <= 0.0) {
256  return false;
257  }
258 
259  G4Step fFakeStep;
260  G4StepPoint* fFakePreStepPoint = fFakeStep.GetPreStepPoint();
261  G4StepPoint* fFakePostStepPoint = fFakeStep.GetPostStepPoint();
262  fFakePreStepPoint->SetPosition(aSpot->GetPosition());
263  fFakePostStepPoint->SetPosition(aSpot->GetPosition());
264 
265  G4TouchableHandle fTouchableHandle = aSpot->GetTouchableHandle();
266  fFakePreStepPoint->SetTouchableHandle(fTouchableHandle);
267  fFakeStep.SetTotalEnergyDeposit(edep);
268  edep = EnergyCorrected(fFakeStep, track);
269  if (edep <= 0.0) {
270  return false;
271  }
272 
274  edepositEM = edep;
275  } else {
276  edepositHAD = edep;
277  }
278 
279  unsigned int unitID = setDetUnitId(&fFakeStep);
280 
281  if (unitID > 0) {
282  double time = 0;
283  int primaryID = getTrackID(track);
284  uint16_t depth = getDepth(&fFakeStep);
285  currentID.setID(unitID, time, primaryID, depth);
286 #ifdef EDM_ML_DEBUG
287  edm::LogVerbatim("CaloSim") << "CaloSD:: GetSpotInfo for Unit 0x" << std::hex << currentID.unitID() << std::dec
288  << " Edeposit = " << edepositEM << " " << edepositHAD;
289 #endif
290  // Update if in the same detector, time-slice and for same track
291  if (currentID == previousID) {
293  } else {
294  posGlobal = aSpot->GetEnergySpot()->GetPosition();
295  // Reset entry point for new primary
296  if (currentID.trackID() != previousID.trackID()) {
297  entrancePoint = aSpot->GetPosition();
298  entranceLocal = aSpot->GetTouchableHandle()->GetHistory()->GetTopTransform().TransformPoint(entrancePoint);
299  incidentEnergy = track->GetKineticEnergy();
300 #ifdef EDM_ML_DEBUG
301  edm::LogVerbatim("CaloSim") << "CaloSD: Incident energy " << incidentEnergy / CLHEP::GeV << " GeV and"
302  << " entrance point " << entrancePoint << " (Global) " << entranceLocal
303  << " (Local)";
304 #endif
305  }
306  if (!checkHit()) {
307  currentHit = createNewHit(&fFakeStep, track);
308  }
309  }
310  return true;
311  }
312  return false;
313 }
float edepositEM
Definition: CaloSD.h:140
Log< level::Info, true > LogVerbatim
void updateHit(CaloG4Hit *)
Definition: CaloSD.cc:633
virtual uint16_t getDepth(const G4Step *)
Definition: CaloSD.cc:836
virtual double EnergyCorrected(const G4Step &step, const G4Track *)
Definition: CaloSD.cc:317
uint32_t setDetUnitId(const G4Step *step) override=0
G4ThreeVector posGlobal
Definition: CaloSD.h:138
virtual int getTrackID(const G4Track *)
Definition: CaloSD.cc:796
bool checkHit()
Definition: CaloSD.cc:423
float edepositHAD
Definition: CaloSD.h:140
CaloG4Hit * createNewHit(const G4Step *, const G4Track *)
Definition: CaloSD.cc:555
CaloHitID previousID
Definition: CaloSD.h:142
CaloG4Hit * currentHit
Definition: CaloSD.h:146
uint32_t unitID() const
Definition: CaloHitID.h:20
void setID(uint32_t unitID, double timeSlice, int trackID, uint16_t depth=0)
Definition: CaloHitID.cc:41
CaloHitID currentID
Definition: CaloSD.h:142
float incidentEnergy
Definition: CaloSD.h:139
static bool isGammaElectronPositron(int pdgCode)
int trackID() const
Definition: CaloHitID.h:23
G4ThreeVector entrancePoint
Definition: CaloSD.h:136
G4ThreeVector entranceLocal
Definition: CaloSD.h:137

◆ reset()

void CaloSD::reset ( void  )
overridevirtual

Reimplemented from SensitiveCaloDetector.

Definition at line 784 of file CaloSD.cc.

References fpCaloG4HitAllocator.

784  {
785  if (fpCaloG4HitAllocator) {
786  fpCaloG4HitAllocator->ResetStorage();
787  }
788 }
G4ThreadLocal G4Allocator< CaloG4Hit > * fpCaloG4HitAllocator
Definition: CaloG4Hit.cc:11

◆ resetForNewPrimary()

void CaloSD::resetForNewPrimary ( const G4Step *  aStep)
protected

Definition at line 644 of file CaloSD.cc.

References entranceLocal, entrancePoint, incidentEnergy, and setToLocal().

Referenced by HCalSD::getFromHFLibrary(), ZdcSD::getFromLibrary(), CastorSD::getFromLibrary(), HCalSD::getHitFibreBundle(), HCalSD::getHitPMT(), hitExists(), and setTrackID().

644  {
645  auto const preStepPoint = aStep->GetPreStepPoint();
646  entrancePoint = preStepPoint->GetPosition();
647  entranceLocal = setToLocal(entrancePoint, preStepPoint->GetTouchable());
648  incidentEnergy = preStepPoint->GetKineticEnergy();
649 #ifdef EDM_ML_DEBUG
650  edm::LogVerbatim("CaloSim") << "CaloSD::resetForNewPrimary for " << GetName()
651  << " ID= " << aStep->GetTrack()->GetTrackID() << " Ein= " << incidentEnergy / CLHEP::GeV
652  << " GeV and"
653  << " entrance point global: " << entrancePoint << " local: " << entranceLocal;
654 #endif
655 }
Log< level::Info, true > LogVerbatim
G4ThreeVector setToLocal(const G4ThreeVector &, const G4VTouchable *) const
Definition: CaloSD.cc:394
float incidentEnergy
Definition: CaloSD.h:139
G4ThreeVector entrancePoint
Definition: CaloSD.h:136
G4ThreeVector entranceLocal
Definition: CaloSD.h:137

◆ saveHit()

bool CaloSD::saveHit ( CaloG4Hit aHit)
private

Definition at line 870 of file CaloSD.cc.

References correctT, corrTOFBeam, TauDecayModes::dec, doFineCalo_, Exception, CaloG4Hit::getDepth(), CaloG4Hit::getEM(), CaloG4Hit::getHadr(), CaloG4Hit::getTimeSlice(), CaloG4Hit::getTrackID(), CaloG4Hit::getUnitID(), SimTrackManager::giveMotherNeeded(), CaloG4Hit::isFinecaloTrackID(), m_trackManager, convertSQLiteXML::ok, shortreprID(), slave, protons_cff::time, and SimTrackManager::trackExists().

Referenced by update().

870  {
871  int tkID;
872  bool ok = true;
873 
874  double time = aHit->getTimeSlice();
875  if (corrTOFBeam)
876  time += correctT;
877 
878  // More strict bookkeeping for finecalo
879  if (doFineCalo_ && aHit->isFinecaloTrackID()) {
880 #ifdef EDM_ML_DEBUG
881  edm::LogVerbatim("DoFineCalo") << "Saving hit " << shortreprID(aHit);
882 #endif
883  if (!m_trackManager)
884  throw cms::Exception("Unknown", "CaloSD") << "m_trackManager not set, needed for finecalo!";
885  if (!m_trackManager->trackExists(aHit->getTrackID()))
886  throw cms::Exception("Unknown", "CaloSD")
887  << "Error on hit " << shortreprID(aHit) << ": Parent track not in track manager";
888  slave.get()->processHits(aHit->getUnitID(),
889  aHit->getEM() / CLHEP::GeV,
890  aHit->getHadr() / CLHEP::GeV,
891  time,
892  aHit->getTrackID(),
893  aHit->getDepth());
894  }
895  // Regular, not-fine way:
896  else {
897  if (m_trackManager) {
898  tkID = m_trackManager->giveMotherNeeded(aHit->getTrackID());
899  if (tkID == 0) {
900  if (m_trackManager->trackExists(aHit->getTrackID()))
901  tkID = (aHit->getTrackID());
902  else {
903  ok = false;
904  }
905  }
906  } else {
907  tkID = aHit->getTrackID();
908  ok = false;
909  }
910 #ifdef EDM_ML_DEBUG
911  edm::LogVerbatim("DoFineCalo") << "Saving hit " << shortreprID(aHit) << " with trackID=" << tkID;
912 #endif
913  slave.get()->processHits(
914  aHit->getUnitID(), aHit->getEM() / CLHEP::GeV, aHit->getHadr() / CLHEP::GeV, time, tkID, aHit->getDepth());
915  }
916 
917 #ifdef EDM_ML_DEBUG
918  if (!ok)
919  edm::LogWarning("CaloSim") << "CaloSD:Cannot find track ID for " << aHit->getTrackID();
920  edm::LogVerbatim("CaloSim") << "CalosD: Track ID " << aHit->getTrackID() << " changed to " << tkID
921  << " by SimTrackManager Status " << ok;
922 #endif
923 
924 #ifdef EDM_ML_DEBUG
925  edm::LogVerbatim("CaloSim") << "CaloSD: Store Hit at " << std::hex << aHit->getUnitID() << std::dec << " "
926  << aHit->getDepth() << " due to " << tkID << " in time " << time << " of energy "
927  << aHit->getEM() / CLHEP::GeV << " GeV (EM) and " << aHit->getHadr() / CLHEP::GeV
928  << " GeV (Hadr)";
929 #endif
930  return ok;
931 }
Log< level::Info, true > LogVerbatim
int getTrackID() const
Definition: CaloG4Hit.h:64
bool corrTOFBeam
Definition: CaloSD.h:172
double getEM() const
Definition: CaloG4Hit.h:55
uint16_t getDepth() const
Definition: CaloG4Hit.h:69
double getHadr() const
Definition: CaloG4Hit.h:58
bool trackExists(unsigned int i) const
bool isFinecaloTrackID() const
Definition: CaloG4Hit.h:70
std::unique_ptr< CaloSlaveSD > slave
Definition: CaloSD.h:163
bool doFineCalo_
Definition: CaloSD.h:184
double correctT
Definition: CaloSD.h:183
uint32_t getUnitID() const
Definition: CaloG4Hit.h:66
double getTimeSlice() const
Definition: CaloG4Hit.h:67
int giveMotherNeeded(int i) const
const SimTrackManager * m_trackManager
Definition: CaloSD.h:161
std::string shortreprID(const CaloHitID &ID)
Definition: CaloSD.cc:469
Log< level::Warning, false > LogWarning

◆ setDetUnitId()

uint32_t CaloSD::setDetUnitId ( const G4Step *  step)
overridepure virtual

◆ setNumberCheckedHits()

void CaloSD::setNumberCheckedHits ( int  val)
inlineprotected

Definition at line 122 of file CaloSD.h.

References nCheckedHits, and heppy_batch::val.

Referenced by HFNoseSD::HFNoseSD(), HGCalSD::HGCalSD(), HGCScintSD::HGCScintSD(), and HGCSD::HGCSD().

122 { nCheckedHits = val; }
int nCheckedHits
Definition: CaloSD.h:179

◆ setParameterized()

void CaloSD::setParameterized ( bool  val)
inlineprotected

Definition at line 110 of file CaloSD.h.

References isParameterized, and heppy_batch::val.

Referenced by CastorSD::CastorSD(), HCalSD::HCalSD(), and ZdcSD::ZdcSD().

110 { isParameterized = val; }
bool isParameterized
Definition: CaloSD.h:169

◆ setToGlobal()

G4ThreeVector CaloSD::setToGlobal ( const G4ThreeVector &  local,
const G4VTouchable *  touch 
) const
protected

Definition at line 398 of file CaloSD.cc.

References DTRecHitClients_cfi::local.

398  {
399  return touch->GetHistory()->GetTopTransform().Inverse().TransformPoint(local);
400 }

◆ setToLocal()

G4ThreeVector CaloSD::setToLocal ( const G4ThreeVector &  global,
const G4VTouchable *  touch 
) const
protected

Definition at line 394 of file CaloSD.cc.

Referenced by DreamSD::curve_LY(), HcalTB02SD::curve_LY(), ECalSD::EnergyCorrected(), ECalSD::getDepth(), ECalSD::getRadiationLength(), resetForNewPrimary(), and HcalTB06BeamSD::setDetUnitId().

394  {
395  return touch->GetHistory()->GetTopTransform().TransformPoint(global);
396 }

◆ setTrackID()

int CaloSD::setTrackID ( const G4Step *  aStep)
protectedvirtual

Definition at line 814 of file CaloSD.cc.

References SensitiveDetector::cmsTrackInformation(), TrackInformation::getIDonCaloSurface(), previousID, resetForNewPrimary(), and CaloHitID::trackID().

Referenced by HCalSD::getFromHFLibrary(), ZdcSD::getFromLibrary(), CastorSD::getFromLibrary(), HCalSD::getFromParam(), and HCalSD::hitForFibre().

814  {
815  auto const theTrack = aStep->GetTrack();
816  TrackInformation* trkInfo = cmsTrackInformation(theTrack);
817  int primaryID = trkInfo->getIDonCaloSurface();
818  if (primaryID <= 0) {
819  primaryID = theTrack->GetTrackID();
820  }
821 #ifdef EDM_ML_DEBUG
822  edm::LogVerbatim("CaloSim") << "Track ID: " << trkInfo->getIDonCaloSurface() << ":" << theTrack->GetTrackID() << ":"
823  << primaryID;
824 #endif
825 
826  if (primaryID != previousID.trackID()) {
827  resetForNewPrimary(aStep);
828  }
829 #ifdef EDM_ML_DEBUG
830  edm::LogVerbatim("CaloSim") << "CaloSD::setTrackID for " << GetName()
831  << " trackID= " << aStep->GetTrack()->GetTrackID() << " primaryID= " << primaryID;
832 #endif
833  return primaryID;
834 }
Log< level::Info, true > LogVerbatim
void resetForNewPrimary(const G4Step *)
Definition: CaloSD.cc:644
CaloHitID previousID
Definition: CaloSD.h:142
TrackInformation * cmsTrackInformation(const G4Track *aTrack)
int getIDonCaloSurface() const
int trackID() const
Definition: CaloHitID.h:23

◆ setUseMap()

void CaloSD::setUseMap ( bool  val)
inlineprotected

Definition at line 111 of file CaloSD.h.

References useMap, and heppy_batch::val.

Referenced by HFNoseSD::HFNoseSD(), HGCalSD::HGCalSD(), HGCScintSD::HGCScintSD(), and HGCSD::HGCSD().

111 { useMap = val; }
bool useMap
Definition: CaloSD.h:171

◆ shortreprID() [1/2]

std::string CaloSD::shortreprID ( const CaloHitID ID)
protected

Definition at line 469 of file CaloSD.cc.

References contentValuesCheck::ss.

Referenced by createNewHit(), ProcessHits(), saveHit(), and shortreprID().

469  {
470  std::stringstream ss;
471  ss << GetName() << "/" << ID.unitID() << "/trk" << ID.trackID() << "/d" << ID.depth() << "/time" << ID.timeSliceID();
472  if (ID.isFinecaloTrackID())
473  ss << "/FC";
474  return ss.str();
475 }
uint32_t ID
Definition: Definitions.h:24

◆ shortreprID() [2/2]

std::string CaloSD::shortreprID ( const CaloG4Hit hit)
protected

Definition at line 478 of file CaloSD.cc.

References shortreprID().

478 { return shortreprID(hit->getID()); }
std::string shortreprID(const CaloHitID &ID)
Definition: CaloSD.cc:469

◆ storeHit()

void CaloSD::storeHit ( CaloG4Hit hit)
private

Definition at line 858 of file CaloSD.cc.

References hitMap, previousID, theHC, CaloHitID::trackID(), and useMap.

Referenced by createNewHit().

858  {
859  if (hit == nullptr || previousID.trackID() < 0) {
860  edm::LogWarning("CaloSim") << "CaloSD: hit to be stored is nullptr !!"
861  << " previousID.trackID()= " << previousID.trackID();
862  return;
863  }
864 
865  theHC->insert(hit);
866  if (useMap)
867  hitMap.insert(std::pair<CaloHitID, CaloG4Hit*>(previousID, hit));
868 }
bool useMap
Definition: CaloSD.h:171
CaloHitID previousID
Definition: CaloSD.h:142
std::map< CaloHitID, CaloG4Hit * > hitMap
Definition: CaloSD.h:187
CaloG4HitCollection * theHC
Definition: CaloSD.h:166
Log< level::Warning, false > LogWarning
int trackID() const
Definition: CaloHitID.h:23

◆ update() [1/5]

void CaloSD::update ( const BeginOfRun )
overrideprotectedvirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfRun *>.

Definition at line 679 of file CaloSD.cc.

References initRun().

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), progressbar.ProgressBar::finish(), and MatrixUtil.Steps::overwrite().

679 { initRun(); }
virtual void initRun()
Definition: CaloSD.cc:790

◆ update() [2/5]

void CaloSD::update ( const BeginOfEvent )
overrideprotectedvirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfEvent *>.

Definition at line 681 of file CaloSD.cc.

References clearHits(), and initEvent().

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), progressbar.ProgressBar::finish(), and MatrixUtil.Steps::overwrite().

681  {
682 #ifdef EDM_ML_DEBUG
683  edm::LogVerbatim("CaloSim") << "CaloSD: Dispatched BeginOfEvent for " << GetName() << " !";
684 #endif
685  clearHits();
686  initEvent(g4Event);
687 }
Log< level::Info, true > LogVerbatim
virtual void initEvent(const BeginOfEvent *)
Definition: CaloSD.cc:792
void clearHits() override
Definition: CaloSD.cc:773

◆ update() [3/5]

void CaloSD::update ( const BeginOfTrack )
overrideprotectedvirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfTrack *>.

Definition at line 933 of file CaloSD.cc.

References cleanHitCollection(), SensitiveDetector::cmsTrackInformation(), TrackInformation::isPrimary(), primAncestor, and theHC.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), progressbar.ProgressBar::finish(), and MatrixUtil.Steps::overwrite().

933  {
934  int primary = -1;
935  TrackInformation* trkInfo = cmsTrackInformation((*trk)());
936  if (trkInfo->isPrimary())
937  primary = (*trk)()->GetTrackID();
938 
939 #ifdef EDM_ML_DEBUG
940  edm::LogVerbatim("CaloSim") << "New track: isPrimary " << trkInfo->isPrimary() << " primary ID = " << primary
941  << " primary ancestor ID " << primAncestor;
942 #endif
943 
944  // update the information if a different primary track ID
945 
946  if (primary > 0 && primary != primAncestor) {
947  primAncestor = primary;
948 
949  // clean the hits information
950 
951  if (theHC->entries() > 0)
953  }
954 }
Log< level::Info, true > LogVerbatim
bool isPrimary() const
int primAncestor
Definition: CaloSD.h:175
void cleanHitCollection()
Definition: CaloSD.cc:956
TrackInformation * cmsTrackInformation(const G4Track *aTrack)
CaloG4HitCollection * theHC
Definition: CaloSD.h:166

◆ update() [4/5]

void CaloSD::update ( const EndOfTrack )
overrideprotectedvirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const EndOfTrack *>.

Definition at line 689 of file CaloSD.cc.

References SensitiveDetector::cmsTrackInformation(), TrackInformation::getIDonCaloSurface(), createfilelist::int, m_trackManager, tkMap, SimTrackManager::trackContainer(), and TrackWithHistory::trackID().

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), progressbar.ProgressBar::finish(), and MatrixUtil.Steps::overwrite().

689  {
690  int id = (*trk)()->GetTrackID();
691  TrackInformation* trkI = cmsTrackInformation((*trk)());
692  int lastTrackID = -1;
693  if (trkI)
694  lastTrackID = trkI->getIDonCaloSurface();
695  if (id == lastTrackID) {
696  const TrackContainer* trksForThisEvent = m_trackManager->trackContainer();
697  if (trksForThisEvent != nullptr) {
698  int it = (int)(trksForThisEvent->size()) - 1;
699  if (it >= 0) {
700  TrackWithHistory* trkH = (*trksForThisEvent)[it];
701  if (trkH->trackID() == (unsigned int)(id))
702  tkMap[id] = trkH;
703 #ifdef EDM_ML_DEBUG
704  edm::LogVerbatim("CaloSim") << "CaloSD: get track " << it << " from Container of size "
705  << trksForThisEvent->size() << " with ID " << trkH->trackID();
706  } else {
707  edm::LogVerbatim("CaloSim") << "CaloSD: get track " << it << " from Container of size "
708  << trksForThisEvent->size() << " with no ID";
709 #endif
710  }
711  }
712  }
713 }
Log< level::Info, true > LogVerbatim
std::vector< TrackWithHistory * > TrackContainer
Definition: TrackContainer.h:8
TrackInformation * cmsTrackInformation(const G4Track *aTrack)
int getIDonCaloSurface() const
const TrackContainer * trackContainer() const
std::map< int, TrackWithHistory * > tkMap
Definition: CaloSD.h:188
const SimTrackManager * m_trackManager
Definition: CaloSD.h:161
unsigned int trackID() const

◆ update() [5/5]

void CaloSD::update ( const ::EndOfEvent )
overrideprotected

Definition at line 715 of file CaloSD.cc.

References funct::abs(), boundaryCrossingParentMap_, submitPVResolutionJobs::count, endEvent(), edm::roottree::getEntry(), hitMap, mps_fire::i, reusehit, saveHit(), slave, mathSSE::sqrt(), edm::swap(), theHC, tkMap, totalHits, groupFilesInBlocks::tt, useMap, x, and z.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), progressbar.ProgressBar::finish(), and MatrixUtil.Steps::overwrite().

715  {
716  endEvent();
717  slave.get()->ReserveMemory(theHC->entries());
718 
719  int count(0);
720  int wrong(0);
721  double eEM(0.0);
722  double eHAD(0.0);
723  double eEM2(0.0);
724  double eHAD2(0.0);
725  double tt(0.0);
726  double zloc(0.0);
727  double zglob(0.0);
728  double ee(0.0);
729  int hc_entries = theHC->entries();
730  for (int i = 0; i < hc_entries; ++i) {
731  if (!saveHit((*theHC)[i])) {
732  ++wrong;
733  }
734  ++count;
735  double x = (*theHC)[i]->getEM();
736  eEM += x;
737  eEM2 += x * x;
738  x = (*theHC)[i]->getHadr();
739  eHAD += x;
740  eHAD2 += x * x;
741  tt += (*theHC)[i]->getTimeSlice();
742  ee += (*theHC)[i]->getIncidentEnergy();
743  zglob += std::abs((*theHC)[i]->getEntry().z());
744  zloc += std::abs((*theHC)[i]->getEntryLocal().z());
745  }
746 
747  double norm = (count > 0) ? 1.0 / count : 0.0;
748  eEM *= norm;
749  eEM2 *= norm;
750  eHAD *= norm;
751  eHAD2 *= norm;
752  eEM2 = std::sqrt(eEM2 - eEM * eEM);
753  eHAD2 = std::sqrt(eHAD2 - eHAD * eHAD);
754  tt *= norm;
755  ee *= norm;
756  zglob *= norm;
757  zloc *= norm;
758 
759 #ifdef EDM_ML_DEBUG
760  edm::LogVerbatim("CaloSim") << "CaloSD: " << GetName() << " store " << count << " hits; " << wrong
761  << " track IDs not given properly and " << totalHits - count
762  << " hits not passing cuts\n EmeanEM= " << eEM << " ErmsEM= " << eEM2
763  << "\n EmeanHAD= " << eHAD << " ErmsHAD= " << eHAD2 << " TimeMean= " << tt
764  << " E0mean= " << ee << " Zglob= " << zglob << " Zloc= " << zloc << " ";
765 #endif
766  tkMap.erase(tkMap.begin(), tkMap.end());
767  std::vector<std::unique_ptr<CaloG4Hit>>().swap(reusehit);
768  if (useMap)
769  hitMap.erase(hitMap.begin(), hitMap.end());
771 }
Int_t getEntry(TBranch *branch, EntryNumber entryNumber)
Definition: RootTree.cc:527
Log< level::Info, true > LogVerbatim
int totalHits
Definition: CaloSD.h:177
bool useMap
Definition: CaloSD.h:171
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
std::unordered_map< unsigned int, unsigned int > boundaryCrossingParentMap_
Definition: CaloSD.h:189
std::unique_ptr< CaloSlaveSD > slave
Definition: CaloSD.h:163
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::map< CaloHitID, CaloG4Hit * > hitMap
Definition: CaloSD.h:187
virtual void endEvent()
Definition: CaloSD.cc:794
CaloG4HitCollection * theHC
Definition: CaloSD.h:166
std::map< int, TrackWithHistory * > tkMap
Definition: CaloSD.h:188
std::vector< std::unique_ptr< CaloG4Hit > > reusehit
Definition: CaloSD.h:190
bool saveHit(CaloG4Hit *)
Definition: CaloSD.cc:870

◆ updateHit()

void CaloSD::updateHit ( CaloG4Hit aHit)
protected

Definition at line 633 of file CaloSD.cc.

References CaloG4Hit::addEnergyDeposit(), currentID, edepositEM, edepositHAD, and previousID.

Referenced by checkHit(), createNewHit(), hitExists(), processHit(), and ProcessHits().

633  {
635 #ifdef EDM_ML_DEBUG
636  edm::LogVerbatim("CaloSim") << "CaloSD:" << GetName() << " Add energy deposit in " << currentID
637  << " Edep_em(MeV)= " << edepositEM << " Edep_had(MeV)= " << edepositHAD;
638 #endif
639 
640  // buffer for next steps:
642 }
float edepositEM
Definition: CaloSD.h:140
Log< level::Info, true > LogVerbatim
void addEnergyDeposit(double em, double hd)
Definition: CaloG4Hit.cc:45
float edepositHAD
Definition: CaloSD.h:140
CaloHitID previousID
Definition: CaloSD.h:142
CaloHitID currentID
Definition: CaloSD.h:142

Member Data Documentation

◆ boundaryCrossingParentMap_

std::unordered_map<unsigned int, unsigned int> CaloSD::boundaryCrossingParentMap_
private

Definition at line 189 of file CaloSD.h.

Referenced by findBoundaryCrossingParent(), and update().

◆ cleanIndex

int CaloSD::cleanIndex
private

Definition at line 176 of file CaloSD.h.

Referenced by CaloSD(), cleanHitCollection(), and clearHits().

◆ correctT

double CaloSD::correctT
private

Definition at line 183 of file CaloSD.h.

Referenced by CaloSD(), cleanHitCollection(), and saveHit().

◆ corrTOFBeam

bool CaloSD::corrTOFBeam
private

Definition at line 172 of file CaloSD.h.

Referenced by CaloSD(), cleanHitCollection(), and saveHit().

◆ currentHit

CaloG4Hit* CaloSD::currentHit
protected

Definition at line 146 of file CaloSD.h.

Referenced by checkHit(), ZdcSD::getFromLibrary(), hitExists(), processHit(), and ProcessHits().

◆ currentID

CaloHitID CaloSD::currentID
protected

◆ doFineCalo_

bool CaloSD::doFineCalo_
private

Definition at line 184 of file CaloSD.h.

Referenced by CaloSD(), ProcessHits(), and saveHit().

◆ doFineCaloThisStep_

bool CaloSD::doFineCaloThisStep_
private

Definition at line 192 of file CaloSD.h.

Referenced by createNewHit(), and ProcessHits().

◆ edepositEM

float CaloSD::edepositEM
protected

◆ edepositHAD

float CaloSD::edepositHAD
protected

◆ eMinFine_

double CaloSD::eMinFine_
private

Definition at line 185 of file CaloSD.h.

Referenced by CaloSD().

◆ eminHit

double CaloSD::eminHit
protected

Definition at line 144 of file CaloSD.h.

Referenced by CaloSD(), filterHit(), and HGCSD::HGCSD().

◆ eminHitD

double CaloSD::eminHitD
private

Definition at line 182 of file CaloSD.h.

Referenced by CaloSD(), and filterHit().

◆ energyCut

double CaloSD::energyCut
protected

Definition at line 144 of file CaloSD.h.

Referenced by CaloSD(), createNewHit(), HCalSD::getHitFibreBundle(), and HCalSD::getHitPMT().

◆ entranceLocal

G4ThreeVector CaloSD::entranceLocal
protected

◆ entrancePoint

G4ThreeVector CaloSD::entrancePoint
protected

◆ fineDetectors_

std::vector<Detector> CaloSD::fineDetectors_
private

Definition at line 191 of file CaloSD.h.

Referenced by CaloSD(), and isItFineCalo().

◆ forceSave

bool CaloSD::forceSave
protected

Definition at line 151 of file CaloSD.h.

Referenced by CaloSD(), createNewHit(), and ECalSD::getTrackID().

◆ hcID

int CaloSD::hcID
private

Definition at line 174 of file CaloSD.h.

Referenced by Initialize().

◆ hitMap

std::map<CaloHitID, CaloG4Hit*> CaloSD::hitMap
private

Definition at line 187 of file CaloSD.h.

Referenced by checkHit(), cleanHitCollection(), storeHit(), and update().

◆ ignoreReject

bool CaloSD::ignoreReject
private

Definition at line 170 of file CaloSD.h.

Referenced by ignoreRejection(), and ProcessHits().

◆ ignoreTrackID

bool CaloSD::ignoreTrackID
private

Definition at line 168 of file CaloSD.h.

Referenced by CaloSD().

◆ incidentEnergy

float CaloSD::incidentEnergy
protected

◆ isParameterized

bool CaloSD::isParameterized
private

Definition at line 169 of file CaloSD.h.

Referenced by CaloSD(), ProcessHits(), and setParameterized().

◆ kmaxIon

double CaloSD::kmaxIon
protected

◆ kmaxNeutron

double CaloSD::kmaxNeutron
protected

◆ kmaxProton

double CaloSD::kmaxProton
protected

◆ m_trackManager

const SimTrackManager* CaloSD::m_trackManager
private

Definition at line 161 of file CaloSD.h.

Referenced by findBoundaryCrossingParent(), saveHit(), and update().

◆ meanResponse

std::unique_ptr<CaloMeanResponse> CaloSD::meanResponse
private

Definition at line 164 of file CaloSD.h.

Referenced by CaloSD(), and getResponseWt().

◆ nCheckedHits

int CaloSD::nCheckedHits
private

Definition at line 179 of file CaloSD.h.

Referenced by CaloSD(), checkHit(), and setNumberCheckedHits().

◆ posGlobal

G4ThreeVector CaloSD::posGlobal
protected

Definition at line 138 of file CaloSD.h.

Referenced by CaloSD(), createNewHit(), ZdcSD::getFromLibrary(), hitExists(), and ProcessHits().

◆ previousID

CaloHitID CaloSD::previousID
protected

◆ primAncestor

int CaloSD::primAncestor
private

Definition at line 175 of file CaloSD.h.

Referenced by CaloSD(), and update().

◆ primIDSaved

int CaloSD::primIDSaved
private

Definition at line 178 of file CaloSD.h.

Referenced by CaloSD(), clearHits(), and createNewHit().

◆ reusehit

std::vector<std::unique_ptr<CaloG4Hit> > CaloSD::reusehit
private

Definition at line 190 of file CaloSD.h.

Referenced by cleanHitCollection(), createNewHit(), and update().

◆ slave

std::unique_ptr<CaloSlaveSD> CaloSD::slave
private

Definition at line 163 of file CaloSD.h.

Referenced by CaloSD(), clearHits(), fillHits(), saveHit(), and update().

◆ suppressHeavy

bool CaloSD::suppressHeavy
protected

◆ theHC

CaloG4HitCollection* CaloSD::theHC
private

◆ timeSlice

float CaloSD::timeSlice
private

Definition at line 181 of file CaloSD.h.

Referenced by CaloSD().

◆ tkMap

std::map<int, TrackWithHistory*> CaloSD::tkMap
private

Definition at line 188 of file CaloSD.h.

Referenced by createNewHit(), and update().

◆ tmaxHit

double CaloSD::tmaxHit
protected

◆ totalHits

int CaloSD::totalHits
private

Definition at line 177 of file CaloSD.h.

Referenced by CaloSD(), cleanHitCollection(), createNewHit(), Initialize(), and update().

◆ useMap

bool CaloSD::useMap
private

Definition at line 171 of file CaloSD.h.

Referenced by CaloSD(), checkHit(), cleanHitCollection(), createNewHit(), setUseMap(), storeHit(), and update().