CMS 3D CMS Logo

CaloSD.cc
Go to the documentation of this file.
1 // File: CaloSD.cc
3 // Description: Sensitive Detector class for calorimeters
5 
13 
14 #include "G4EventManager.hh"
15 #include "G4LogicalVolumeStore.hh"
16 #include "G4LogicalVolume.hh"
17 #include "G4SDManager.hh"
18 #include "G4Step.hh"
19 #include "G4Track.hh"
20 #include "G4VProcess.hh"
21 #include "G4GFlashSpot.hh"
22 #include "G4ParticleTable.hh"
23 #include "G4SystemOfUnits.hh"
24 #include "G4PhysicalConstants.hh"
25 #include "DD4hep/Filter.h"
26 
27 #include <fstream>
28 #include <memory>
29 #include <sstream>
30 
31 // #define EDM_ML_DEBUG
32 
34  const SensitiveDetectorCatalog& clg,
35  edm::ParameterSet const& p,
36  const SimTrackManager* manager,
37  float timeSliceUnit,
38  bool ignoreTkID)
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 }
157 
159 
160 G4bool CaloSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
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 }
249 
250 bool CaloSD::ProcessHits(G4GFlashSpot* aSpot, G4TouchableHistory*) {
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 }
314 
315 double CaloSD::getEnergyDeposit(const G4Step* aStep) { return aStep->GetTotalEnergyDeposit(); }
316 
317 double CaloSD::EnergyCorrected(const G4Step& aStep, const G4Track*) { return aStep.GetTotalEnergyDeposit(); }
318 
319 bool CaloSD::getFromLibrary(const G4Step*) { return false; }
320 
321 bool CaloSD::isItFineCalo(const G4VTouchable* touch) {
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 }
340 
341 void CaloSD::Initialize(G4HCofThisEvent* HCE) {
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 }
358 
359 void CaloSD::EndOfEvent(G4HCofThisEvent*) {
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 }
371 
372 void CaloSD::clear() {}
373 
375 
377 #ifdef EDM_ML_DEBUG
378  edm::LogVerbatim("CaloSim") << "CaloSD: Collection " << theHC->GetName();
379 #endif
380  theHC->PrintAllHits();
381 }
382 
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 }
393 
394 G4ThreeVector CaloSD::setToLocal(const G4ThreeVector& global, const G4VTouchable* touch) const {
395  return touch->GetHistory()->GetTopTransform().TransformPoint(global);
396 }
397 
398 G4ThreeVector CaloSD::setToGlobal(const G4ThreeVector& local, const G4VTouchable* touch) const {
399  return touch->GetHistory()->GetTopTransform().Inverse().TransformPoint(local);
400 }
401 
402 bool CaloSD::hitExists(const G4Step* aStep) {
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 }
422 
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 }
451 
452 int CaloSD::getNumberOfHits() { return theHC->entries(); }
453 
454 /*
455 Takes a vector of ints (representing trackIDs), and returns a formatted string
456 for debugging purposes
457 */
458 std::string CaloSD::printableDecayChain(const std::vector<unsigned int>& decayChain) {
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 }
467 
468 /* Very short representation of a CaloHitID */
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 }
476 
477 /* As above, but with a hit as input */
479 
480 /*
481 Finds the boundary-crossing parent of a track, and stores it in the CaloSD's map
482 */
483 unsigned int CaloSD::findBoundaryCrossingParent(const G4Track* track, bool markAsSaveable) {
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 }
554 
555 CaloG4Hit* CaloSD::createNewHit(const G4Step* aStep, const G4Track* theTrack) {
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 }
632 
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 }
643 
644 void CaloSD::resetForNewPrimary(const G4Step* aStep) {
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 }
656 
657 double CaloSD::getAttenuation(const G4Step* aStep, double birk1, double birk2, double birk3) const {
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 }
678 
679 void CaloSD::update(const BeginOfRun*) { initRun(); }
680 
681 void CaloSD::update(const BeginOfEvent* g4Event) {
682 #ifdef EDM_ML_DEBUG
683  edm::LogVerbatim("CaloSim") << "CaloSD: Dispatched BeginOfEvent for " << GetName() << " !";
684 #endif
685  clearHits();
686  initEvent(g4Event);
687 }
688 
689 void CaloSD::update(const EndOfTrack* trk) {
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 }
714 
715 void CaloSD::update(const ::EndOfEvent*) {
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 }
772 
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 }
783 
785  if (fpCaloG4HitAllocator) {
786  fpCaloG4HitAllocator->ResetStorage();
787  }
788 }
789 
791 
793 
795 
796 int CaloSD::getTrackID(const G4Track* aTrack) {
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 }
813 
814 int CaloSD::setTrackID(const G4Step* aStep) {
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 }
835 
836 uint16_t CaloSD::getDepth(const G4Step*) { return 0; }
837 
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 }
848 
849 double CaloSD::getResponseWt(const G4Track* aTrack) {
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 }
857 
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 }
869 
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 }
932 
933 void CaloSD::update(const BeginOfTrack* trk) {
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 }
955 
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 }
1071 
1072 void CaloSD::printDetectorLevels(const G4VTouchable* touch) const {
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 }
float edepositEM
Definition: CaloSD.h:140
bool storeTrack() const
double genParticleP() const
Int_t getEntry(TBranch *branch, EntryNumber entryNumber)
Definition: RootTree.cc:527
double energyCut
Definition: CaloSD.h:144
Log< level::Info, true > LogVerbatim
int getTrackID() const
Definition: CaloG4Hit.h:64
bool isPrimary() const
bool ignoreReject
Definition: CaloSD.h:170
bool crossedBoundary() const
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
virtual bool getFromLibrary(const G4Step *step)
Definition: CaloSD.cc:319
std::vector< PCaloHit > PCaloHitContainer
double kmaxNeutron
Definition: CaloSD.h:149
bool doFineCaloThisStep_
Definition: CaloSD.h:192
G4ThreadLocal G4Allocator< CaloG4Hit > * fpCaloG4HitAllocator
Definition: CaloG4Hit.cc:11
void updateHit(CaloG4Hit *)
Definition: CaloSD.cc:633
virtual uint16_t getDepth(const G4Step *)
Definition: CaloSD.cc:836
virtual double getEnergyDeposit(const G4Step *step)
Definition: CaloSD.cc:315
virtual double EnergyCorrected(const G4Step &step, const G4Track *)
Definition: CaloSD.cc:317
int parentID() const
unsigned int findBoundaryCrossingParent(const G4Track *track, bool markParentAsSaveable=true)
Definition: CaloSD.cc:483
double eMinFine_
Definition: CaloSD.h:185
bool corrTOFBeam
Definition: CaloSD.h:172
int totalHits
Definition: CaloSD.h:177
double getEM() const
Definition: CaloG4Hit.h:55
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
void DrawAll() override
Definition: CaloSD.cc:374
uint32_t ID
Definition: Definitions.h:24
void clear() override
Definition: CaloSD.cc:372
uint32_t setDetUnitId(const G4Step *step) override=0
bool useMap
Definition: CaloSD.h:171
TrackWithHistory * getTrackByID(unsigned int trackID, bool strict=false) const
int hcID
Definition: CaloSD.h:174
double eminHitD
Definition: CaloSD.h:182
uint16_t getDepth() const
Definition: CaloG4Hit.h:69
G4ThreeVector setToLocal(const G4ThreeVector &, const G4VTouchable *) const
Definition: CaloSD.cc:394
Definition: weight.py:1
G4ThreeVector posGlobal
Definition: CaloSD.h:138
virtual int getTrackID(const G4Track *)
Definition: CaloSD.cc:796
int primIDSaved
Definition: CaloSD.h:178
void Initialize(G4HCofThisEvent *HCE) override
Definition: CaloSD.cc:341
int primAncestor
Definition: CaloSD.h:175
void reset() override
Definition: CaloSD.cc:784
double kmaxProton
Definition: CaloSD.h:149
void fillHits(edm::PCaloHitContainer &, const std::string &) override
Definition: CaloSD.cc:383
std::vector< Detector > fineDetectors_
Definition: CaloSD.h:191
double eminHit
Definition: CaloSD.h:144
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
double getHadr() const
Definition: CaloG4Hit.h:58
bool equal(const T &first, const T &second)
Definition: Equal.h:32
virtual void initEvent(const BeginOfEvent *)
Definition: CaloSD.cc:792
std::unordered_map< unsigned int, unsigned int > boundaryCrossingParentMap_
Definition: CaloSD.h:189
void cleanHitCollection()
Definition: CaloSD.cc:956
void reset()
Definition: CaloHitID.cc:49
T getUntrackedParameter(std::string const &, T const &) const
bool forceSave
Definition: CaloSD.h:151
int timeSliceID() const
Definition: CaloHitID.h:21
bool isItFineCalo(const G4VTouchable *touch)
Definition: CaloSD.cc:321
void addEnergyDeposit(double em, double hd)
Definition: CaloG4Hit.cc:45
float timeSlice
Definition: CaloSD.h:181
bool trackExists(unsigned int i) const
bool isFinecaloTrackID() const
Definition: CaloG4Hit.h:70
bool checkHit()
Definition: CaloSD.cc:423
static std::string printableDecayChain(const std::vector< unsigned int > &decayChain)
Definition: CaloSD.cc:458
double kmaxIon
Definition: CaloSD.h:149
bool suppressHeavy
Definition: CaloSD.h:148
std::unique_ptr< CaloSlaveSD > slave
Definition: CaloSD.h:163
std::vector< TrackWithHistory * > TrackContainer
Definition: TrackContainer.h:8
float edepositHAD
Definition: CaloSD.h:140
T sqrt(T t)
Definition: SSEVec.h:19
void resetForNewPrimary(const G4Step *)
Definition: CaloSD.cc:644
void setEM(double e)
Definition: CaloG4Hit.h:56
bool doFineCalo_
Definition: CaloSD.h:184
void setID(uint32_t i, double d, int j, uint16_t k=0)
Definition: CaloG4Hit.h:73
def pv(vc)
Definition: MetAnalyzer.py:7
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
G4bool ProcessHits(G4Step *step, G4TouchableHistory *) override
Definition: CaloSD.cc:160
double f[11][100]
int getNumberOfHits()
Definition: CaloSD.cc:452
CaloG4Hit * createNewHit(const G4Step *, const G4Track *)
Definition: CaloSD.cc:555
CaloHitID previousID
Definition: CaloSD.h:142
~CaloSD() override
Definition: CaloSD.cc:158
CaloG4Hit * currentHit
Definition: CaloSD.h:146
uint32_t unitID() const
Definition: CaloHitID.h:20
void storeHit(CaloG4Hit *)
Definition: CaloSD.cc:858
G4ThreeVector setToGlobal(const G4ThreeVector &, const G4VTouchable *) const
Definition: CaloSD.cc:398
TrackInformation * cmsTrackInformation(const G4Track *aTrack)
virtual bool filterHit(CaloG4Hit *, double)
Definition: CaloSD.cc:838
int getIDonCaloSurface() const
ii
Definition: cuy.py:589
double tmaxHit
Definition: CaloSD.h:144
void setID(uint32_t unitID, double timeSlice, int trackID, uint16_t depth=0)
Definition: CaloHitID.cc:41
int genParticlePID() const
bool hitExists(const G4Step *)
Definition: CaloSD.cc:402
const TrackContainer * trackContainer() const
std::unique_ptr< CaloMeanResponse > meanResponse
Definition: CaloSD.h:164
CaloHitID currentID
Definition: CaloSD.h:142
virtual void initRun()
Definition: CaloSD.cc:790
double correctT
Definition: CaloSD.h:183
std::map< CaloHitID, CaloG4Hit * > hitMap
Definition: CaloSD.h:187
double getAttenuation(const G4Step *aStep, double birk1, double birk2, double birk3) const
Definition: CaloSD.cc:657
void EndOfEvent(G4HCofThisEvent *eventHC) override
Definition: CaloSD.cc:359
CSCCFEBTimeSlice const *const timeSlice(T const &data, int nCFEB, int nSample)
uint32_t getUnitID() const
Definition: CaloG4Hit.h:66
int nCheckedHits
Definition: CaloSD.h:179
virtual void endEvent()
Definition: CaloSD.cc:794
CaloG4HitCollection * theHC
Definition: CaloSD.h:166
CaloSD(const std::string &aSDname, const SensitiveDetectorCatalog &clg, edm::ParameterSet const &p, const SimTrackManager *, float timeSlice=1., bool ignoreTkID=false)
Definition: CaloSD.cc:33
void printDetectorLevels(const G4VTouchable *) const
Definition: CaloSD.cc:1072
void setHadr(double e)
Definition: CaloG4Hit.h:59
float incidentEnergy
Definition: CaloSD.h:139
virtual int setTrackID(const G4Step *)
Definition: CaloSD.cc:814
void markAsFinecaloTrackID(bool flag=true)
Definition: CaloHitID.h:29
void setPosition(double x, double y, double z)
Definition: CaloG4Hit.h:53
void setEntry(double x, double y, double z)
Definition: CaloG4Hit.h:47
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
static bool isGammaElectronPositron(int pdgCode)
bool isParameterized
Definition: CaloSD.h:169
double getTimeSlice() const
Definition: CaloG4Hit.h:67
std::map< int, TrackWithHistory * > tkMap
Definition: CaloSD.h:188
int giveMotherNeeded(int i) const
std::vector< std::unique_ptr< CaloG4Hit > > reusehit
Definition: CaloSD.h:190
const SimTrackManager * m_trackManager
Definition: CaloSD.h:161
std::string shortreprID(const CaloHitID &ID)
Definition: CaloSD.cc:469
Log< level::Warning, false > LogWarning
void clearHits() override
Definition: CaloSD.cc:773
double getResponseWt(const G4Track *)
Definition: CaloSD.cc:849
int trackID() const
Definition: CaloHitID.h:23
bool saveHit(CaloG4Hit *)
Definition: CaloSD.cc:870
void PrintAll() override
Definition: CaloSD.cc:376
void NaNTrap(const G4Step *step) const
G4ThreeVector entrancePoint
Definition: CaloSD.h:136
G4ThreeVector entranceLocal
Definition: CaloSD.h:137
void update(const BeginOfRun *) override
This routine will be called when the appropriate signal arrives.
Definition: CaloSD.cc:679
int cleanIndex
Definition: CaloSD.h:176
unsigned int trackID() const
bool ignoreTrackID
Definition: CaloSD.h:168
uint16_t depth() const
Definition: CaloHitID.h:24