CMS 3D CMS Logo

CaloSteppingAction.cc
Go to the documentation of this file.
1 //#define EDM_ML_DEBUG
2 //#define HcalNumberingTest
3 
4 // to make hits in EB/EE/HC
5 
9 
16 
20 #ifdef HcalNumberingTest
24 #endif
25 
30 
34 
42 
43 #include "G4LogicalVolume.hh"
44 #include "G4LogicalVolumeStore.hh"
45 #include "G4NavigationHistory.hh"
46 #include "G4ParticleTable.hh"
47 #include "G4PhysicalVolumeStore.hh"
48 #include "G4Region.hh"
49 #include "G4RegionStore.hh"
50 #include "G4Step.hh"
51 #include "G4Track.hh"
52 #include "G4Trap.hh"
53 #include "G4UnitsTable.hh"
54 #include "G4UserSteppingAction.hh"
55 #include "G4VPhysicalVolume.hh"
56 #include "G4VTouchable.hh"
57 
58 #include <CLHEP/Units/SystemOfUnits.h>
59 
60 #include <algorithm>
61 #include <cmath>
62 #include <iostream>
63 #include <iomanip>
64 #include <string>
65 #include <utility>
66 #include <vector>
67 
69  public Observer<const BeginOfRun*>,
70  public Observer<const BeginOfEvent*>,
71  public Observer<const EndOfEvent*>,
72  public Observer<const G4Step*> {
73 public:
75  ~CaloSteppingAction() override;
76 
78  void produce(edm::Event&, const edm::EventSetup&) override;
79  void beginRun(edm::EventSetup const&) override;
80 
81 private:
84  // observer classes
85  void update(const BeginOfRun* run) override;
86  void update(const BeginOfEvent* evt) override;
87  void update(const G4Step* step) override;
88  void update(const EndOfEvent* evt) override;
89 
90  void NaNTrap(const G4Step*) const;
91  uint32_t getDetIDHC(int det, int lay, int depth, const math::XYZVectorD& pos) const;
92  void fillHit(uint32_t id, double dE, double time, int primID, uint16_t depth, double em, int flag);
93  uint16_t getDepth(bool flag, double crystalDepth, double radl) const;
94  double curve_LY(double crystalLength, double crystalDepth) const;
95  double getBirkL3(double dE, double step, double chg, double dens) const;
96  double getBirkHC(double dE, double step, double chg, double dens) const;
97  void saveHits(int flag);
98 
99  static const int nSD_ = 3;
100  std::unique_ptr<EcalBarrelNumberingScheme> ebNumberingScheme_;
101  std::unique_ptr<EcalEndcapNumberingScheme> eeNumberingScheme_;
102  std::unique_ptr<HcalNumberingFromPS> hcNumberingPS_;
103 #ifdef HcalNumberingTest
105  std::unique_ptr<HcalNumberingFromDDD> hcNumbering_;
106 #endif
107  std::unique_ptr<HcalNumberingScheme> hcNumberingScheme_;
108  std::unique_ptr<CaloSlaveSD> slave_[nSD_];
109 
111  const std::vector<std::string> nameEBSD_, nameEESD_, nameHCSD_;
112  const std::vector<std::string> nameHitC_;
113  std::vector<const G4LogicalVolume*> volEBSD_, volEESD_, volHCSD_;
114  std::map<const G4LogicalVolume*, double> xtalMap_;
115  std::map<const G4LogicalVolume*, std::string> mapLV_;
116  const int allSteps_;
119  const double birkC3HC_, timeSliceUnit_;
121  std::map<std::pair<int, CaloHitID>, CaloGVHit> hitMap_[nSD_];
122  typedef std::tuple<const G4LogicalVolume*, uint32_t, int, int, double, double, double, double, double, double, double>
124  std::vector<PassiveData> store_;
125 };
126 
128  : iC_(p.getParameter<edm::ParameterSet>("CaloSteppingAction")),
129  nameEBSD_(iC_.getParameter<std::vector<std::string> >("EBSDNames")),
130  nameEESD_(iC_.getParameter<std::vector<std::string> >("EESDNames")),
131  nameHCSD_(iC_.getParameter<std::vector<std::string> >("HCSDNames")),
132  nameHitC_(iC_.getParameter<std::vector<std::string> >("HitCollNames")),
133  allSteps_(iC_.getParameter<int>("AllSteps")),
134  slopeLY_(iC_.getParameter<double>("SlopeLightYield")),
135  birkC1EC_(iC_.getParameter<double>("BirkC1EC")),
136  birkSlopeEC_(iC_.getParameter<double>("BirkSlopeEC")),
137  birkCutEC_(iC_.getParameter<double>("BirkCutEC")),
138  birkC1HC_(iC_.getParameter<double>("BirkC1HC")),
139  birkC2HC_(iC_.getParameter<double>("BirkC2HC")),
140  birkC3HC_(iC_.getParameter<double>("BirkC3HC")),
141  timeSliceUnit_(iC_.getUntrackedParameter<double>("TimeSliceUnit", 1.0)),
142  count_(0) {
143  edm::ParameterSet iC = p.getParameter<edm::ParameterSet>("CaloSteppingAction");
144 
145  edm::LogVerbatim("Step") << "CaloSteppingAction:: " << nameEBSD_.size() << " names for EB SD's";
146  for (unsigned int k = 0; k < nameEBSD_.size(); ++k)
147  edm::LogVerbatim("Step") << "[" << k << "] " << nameEBSD_[k];
148  edm::LogVerbatim("Step") << "CaloSteppingAction:: " << nameEESD_.size() << " names for EE SD's";
149  for (unsigned int k = 0; k < nameEESD_.size(); ++k)
150  edm::LogVerbatim("Step") << "[" << k << "] " << nameEESD_[k];
151  edm::LogVerbatim("Step") << "CaloSteppingAction:: " << nameHCSD_.size() << " names for HC SD's";
152  for (unsigned int k = 0; k < nameHCSD_.size(); ++k)
153  edm::LogVerbatim("Step") << "[" << k << "] " << nameHCSD_[k];
154  edm::LogVerbatim("Step") << "CaloSteppingAction::Constants for ECAL: slope " << slopeLY_ << " Birk constants "
155  << birkC1EC_ << ":" << birkSlopeEC_ << ":" << birkCutEC_;
156  edm::LogVerbatim("Step") << "CaloSteppingAction::Constants for HCAL: Birk "
157  << "constants " << birkC1HC_ << ":" << birkC2HC_ << ":" << birkC3HC_;
158  edm::LogVerbatim("Step") << "CaloSteppingAction::Constant for time slice " << timeSliceUnit_;
159  edm::LogVerbatim("Step") << "CaloSteppingAction:: " << nameHitC_.size() << " hit collections";
160  for (unsigned int k = 0; k < nameHitC_.size(); ++k)
161  edm::LogVerbatim("Step") << "[" << k << "] " << nameHitC_[k];
162 
163  ebNumberingScheme_ = std::make_unique<EcalBarrelNumberingScheme>();
164  eeNumberingScheme_ = std::make_unique<EcalEndcapNumberingScheme>();
165  hcNumberingPS_ = std::make_unique<HcalNumberingFromPS>(iC);
166  hcNumberingScheme_ = std::make_unique<HcalNumberingScheme>();
167 #ifdef HcalNumberingTest
168  hcNumbering_.reset(nullptr);
169 #endif
170  for (int k = 0; k < CaloSteppingAction::nSD_; ++k) {
171  slave_[k] = std::make_unique<CaloSlaveSD>(nameHitC_[k]);
172  produces<edm::PCaloHitContainer>(nameHitC_[k]);
173  }
174  if (allSteps_ != 0)
175  produces<edm::PassiveHitContainer>("AllPassiveHits");
176  edm::LogVerbatim("Step") << "CaloSteppingAction:: All Steps Flag " << allSteps_ << " for passive hits";
177 }
178 
180  edm::LogVerbatim("Step") << "CaloSteppingAction: --------> Total number of "
181  << "selected entries : " << count_;
182 }
183 
185 #ifdef HcalNumberingTest
187  edm::LogVerbatim("Step") << "CaloSteppingAction::Initialize ESGetToken for HcalDDDSimConstants";
188 #endif
189 }
190 
192  for (int k = 0; k < CaloSteppingAction::nSD_; ++k) {
193  saveHits(k);
194  auto product = std::make_unique<edm::PCaloHitContainer>();
195  fillHits(*product, k);
196  e.put(std::move(product), nameHitC_[k]);
197  }
198  if (allSteps_ != 0) {
199  std::unique_ptr<edm::PassiveHitContainer> hgcPH(new edm::PassiveHitContainer);
200  fillPassiveHits(*hgcPH);
201  e.put(std::move(hgcPH), "AllPassiveHits");
202  }
203 }
204 
206  edm::LogVerbatim("Step") << "CaloSteppingAction::fillHits for type " << type << " with "
207  << slave_[type].get()->hits().size() << " hits";
208  cc = slave_[type].get()->hits();
209  slave_[type].get()->Clean();
210 }
211 
213  edm::LogVerbatim("Step") << "CaloSteppingAction::fillPassiveHits with " << store_.size() << " hits";
214  for (const auto& element : store_) {
215  auto lv = std::get<0>(element);
216  auto it = mapLV_.find(lv);
217  if (it != mapLV_.end()) {
218  PassiveHit hit(it->second,
219  std::get<1>(element),
220  std::get<5>(element),
221  std::get<6>(element),
222  std::get<4>(element),
223  std::get<2>(element),
224  std::get<3>(element),
225  std::get<7>(element),
226  std::get<8>(element),
227  std::get<9>(element),
228  std::get<10>(element));
229  cc.emplace_back(hit);
230  }
231  }
232 }
233 
235  edm::LogVerbatim("Step") << "CaloSteppingAction:: Enter BeginOfRun";
236 
237 #ifdef HcalNumberingTest
238  // Numbering From DDD
239  const HcalDDDSimConstants* hcons_ = &es.getData(ddconsToken_);
240  edm::LogVerbatim("Step") << "CaloSteppingAction:: Initialise "
241  << "HcalNumberingFromDDD";
242  hcNumbering_ = std::make_unique<HcalNumberingFromDDD>(hcons_);
243 #endif
244 }
245 
246 //==================================================================== per RUN
248  int irun = (*run)()->GetRunID();
249  edm::LogVerbatim("Step") << "CaloSteppingAction:: Begin of Run = " << irun;
250 
251  const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
252  if (lvs) {
253  std::map<const std::string, const G4LogicalVolume*> nameMap;
254  std::map<const std::string, const G4LogicalVolume*>::const_iterator itr;
255  for (auto lvi = lvs->begin(), lve = lvs->end(); lvi != lve; ++lvi) {
256  nameMap.emplace((*lvi)->GetName(), *lvi);
257  if (allSteps_ < 0)
258  mapLV_[*lvi] = (*lvi)->GetName();
259  }
260 
261  for (auto const& name : nameEBSD_) {
262  for (itr = nameMap.begin(); itr != nameMap.end(); ++itr) {
263  const std::string& lvname = itr->first;
264  if (lvname.find(name) != std::string::npos) {
265  volEBSD_.emplace_back(itr->second);
266  int type = (lvname.find("refl") == std::string::npos) ? -1 : 1;
267  G4Trap* solid = static_cast<G4Trap*>(itr->second->GetSolid());
268  double dz = 2 * solid->GetZHalfLength() / CLHEP::mm;
269  xtalMap_.insert(std::pair<const G4LogicalVolume*, double>(itr->second, dz * type));
270  if ((allSteps_ > 0) && ((allSteps_ % 10) > 0))
271  mapLV_[itr->second] = itr->first;
272  }
273  }
274  }
275  for (auto const& name : nameEESD_) {
276  for (itr = nameMap.begin(); itr != nameMap.end(); ++itr) {
277  const std::string& lvname = itr->first;
278  if (lvname.find(name) != std::string::npos) {
279  volEESD_.emplace_back(itr->second);
280  int type = (lvname.find("refl") == std::string::npos) ? 1 : -1;
281  G4Trap* solid = static_cast<G4Trap*>(itr->second->GetSolid());
282  double dz = 2 * solid->GetZHalfLength() / CLHEP::mm;
283  xtalMap_.insert(std::pair<const G4LogicalVolume*, double>(itr->second, dz * type));
284  if ((allSteps_ > 0) && (((allSteps_ / 10) % 10) > 0))
285  mapLV_[itr->second] = itr->first;
286  }
287  }
288  }
289 
290  for (auto const& name : nameHCSD_) {
291  for (itr = nameMap.begin(); itr != nameMap.end(); ++itr) {
292  const std::string& lvname = itr->first;
293  if (lvname.find(name) != std::string::npos) {
294  volHCSD_.emplace_back(itr->second);
295  if ((allSteps_ > 0) && (((allSteps_ / 100) % 10) > 0))
296  mapLV_[itr->second] = itr->first;
297  }
298  }
299  }
300  }
301 #ifdef EDM_ML_DEBUG
302  edm::LogVerbatim("Step") << volEBSD_.size() << " logical volumes for EB SD";
303  for (unsigned int k = 0; k < volEBSD_.size(); ++k)
304  edm::LogVerbatim("Step") << "[" << k << "] " << volEBSD_[k];
305  edm::LogVerbatim("Step") << volEESD_.size() << " logical volumes for EE SD";
306  for (unsigned int k = 0; k < volEESD_.size(); ++k)
307  edm::LogVerbatim("Step") << "[" << k << "] " << volEESD_[k];
308  edm::LogVerbatim("Step") << volHCSD_.size() << " logical volumes for HC SD";
309  for (unsigned int k = 0; k < volHCSD_.size(); ++k)
310  edm::LogVerbatim("Step") << "[" << k << "] " << volHCSD_[k];
311  edm::LogVerbatim("Step") << mapLV_.size() << " logical volumes for Passive hits";
312  unsigned int k(0);
313  for (auto itr = mapLV_.begin(); itr != mapLV_.end(); ++itr) {
314  edm::LogVerbatim("Step") << "[" << k << "] " << itr->second << ":" << itr->first;
315  ++k;
316  }
317 #endif
318 }
319 
320 //=================================================================== per EVENT
322  eventID_ = (*evt)()->GetEventID();
323  edm::LogVerbatim("Step") << "CaloSteppingAction: Begin of event = " << eventID_;
324  for (int k = 0; k < CaloSteppingAction::nSD_; ++k) {
325  hitMap_[k].erase(hitMap_[k].begin(), hitMap_[k].end());
326  slave_[k].get()->Initialize();
327  }
328  if (allSteps_ != 0)
329  store_.clear();
330 }
331 
332 //=================================================================== each STEP
333 void CaloSteppingAction::update(const G4Step* aStep) {
334  // edm::LogVerbatim("Step") <<"CaloSteppingAction: At each Step";
335  NaNTrap(aStep);
336  auto lv = aStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume();
337  bool hc = (std::find(volHCSD_.begin(), volHCSD_.end(), lv) != volHCSD_.end());
338  bool eb = (std::find(volEBSD_.begin(), volEBSD_.end(), lv) != volEBSD_.end());
339  bool ee = (std::find(volEESD_.begin(), volEESD_.end(), lv) != volEESD_.end());
340  uint32_t unitID(0);
341  if (hc || eb || ee) {
342  double dEStep = aStep->GetTotalEnergyDeposit() / CLHEP::MeV;
343  auto const theTrack = aStep->GetTrack();
344  double time = theTrack->GetGlobalTime() / CLHEP::nanosecond;
345  int primID = theTrack->GetTrackID();
347  auto const touch = aStep->GetPreStepPoint()->GetTouchable();
348  auto const& hitPoint = aStep->GetPreStepPoint()->GetPosition();
349  if (hc) {
350  int depth = (touch->GetReplicaNumber(0)) % 10 + 1;
351  int lay = (touch->GetReplicaNumber(0) / 10) % 100 + 1;
352  int det = (touch->GetReplicaNumber(1)) / 1000;
353  unitID = getDetIDHC(det, lay, depth, math::XYZVectorD(hitPoint.x(), hitPoint.y(), hitPoint.z()));
354  if (unitID > 0 && dEStep > 0.0) {
355  dEStep *= getBirkHC(dEStep,
356  (aStep->GetStepLength() / CLHEP::cm),
357  aStep->GetPreStepPoint()->GetCharge(),
358  (aStep->GetPreStepPoint()->GetMaterial()->GetDensity() / (CLHEP::g / CLHEP::cm3)));
359  fillHit(unitID, dEStep, time, primID, 0, em, 2);
360  }
361  } else {
362  EcalBaseNumber theBaseNumber;
363  int size = touch->GetHistoryDepth() + 1;
364  if (theBaseNumber.getCapacity() < size)
365  theBaseNumber.setSize(size);
366  //Get name and copy numbers
367  if (size > 1) {
368  for (int ii = 0; ii < size; ii++) {
369  theBaseNumber.addLevel(touch->GetVolume(ii)->GetName(), touch->GetReplicaNumber(ii));
370  }
371  }
372  unitID = (eb ? (ebNumberingScheme_->getUnitID(theBaseNumber)) : (eeNumberingScheme_->getUnitID(theBaseNumber)));
373  if (unitID > 0 && dEStep > 0.0) {
374  auto local = touch->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
375  auto ite = xtalMap_.find(lv);
376  double crystalLength = ((ite == xtalMap_.end()) ? 230.0 : std::abs(ite->second));
377  double crystalDepth =
378  ((ite == xtalMap_.end()) ? 0.0 : (std::abs(0.5 * (ite->second) + (local.z() / CLHEP::mm))));
379  double radl = aStep->GetPreStepPoint()->GetMaterial()->GetRadlen() / CLHEP::mm;
380  bool flag = ((ite == xtalMap_.end()) ? true : (((ite->second) >= 0) ? true : false));
381  auto depth = getDepth(flag, crystalDepth, radl);
382  dEStep *= (getBirkL3(dEStep,
383  (aStep->GetStepLength() / CLHEP::cm),
384  aStep->GetPreStepPoint()->GetCharge(),
385  (aStep->GetPreStepPoint()->GetMaterial()->GetDensity() / (CLHEP::g / CLHEP::cm3))) *
386  curve_LY(crystalLength, crystalDepth));
387  fillHit(unitID, dEStep, time, primID, depth, em, (eb ? 0 : 1));
388  }
389  }
390  }
391 
392  if (allSteps_ != 0) {
393  auto it = mapLV_.find(lv);
394  if (it != mapLV_.end()) {
395  double energy = aStep->GetTotalEnergyDeposit() / CLHEP::MeV;
396  auto const touch = aStep->GetPreStepPoint()->GetTouchable();
397  double time = aStep->GetTrack()->GetGlobalTime() / CLHEP::nanosecond;
398  int trackId = aStep->GetTrack()->GetTrackID();
399  int pdg = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
400  double stepl = (aStep->GetStepLength() / CLHEP::cm);
401  double xp = aStep->GetPreStepPoint()->GetPosition().x() / CLHEP::cm;
402  double yp = aStep->GetPreStepPoint()->GetPosition().y() / CLHEP::cm;
403  double zp = aStep->GetPreStepPoint()->GetPosition().z() / CLHEP::cm;
404 #ifdef EDM_ML_DEBUG
405  edm::LogVerbatim("Step") << "CaloSteppingAction: Volume " << lv->GetName() << " History "
406  << touch->GetHistoryDepth() << " Pointers " << aStep->GetPostStepPoint() << ":"
407  << aStep->GetTrack()->GetNextVolume() << ":" << aStep->IsLastStepInVolume() << " E "
408  << energy << " T " << time << " PDG " << pdg << " step " << stepl << " Position (" << xp
409  << ", " << yp << ", " << zp << ")";
410 #endif
411  uint32_t copy = (allSteps_ < 0) ? 0 : unitID;
412  if (((aStep->GetPostStepPoint() == nullptr) || (aStep->GetTrack()->GetNextVolume() == nullptr)) &&
413  (aStep->IsLastStepInVolume())) {
414  energy += (aStep->GetPreStepPoint()->GetKineticEnergy() / CLHEP::MeV);
415  } else {
416  time = aStep->GetPostStepPoint()->GetGlobalTime() / CLHEP::nanosecond;
417  if (copy == 0)
418  copy = (touch->GetHistoryDepth() < 1)
419  ? static_cast<uint32_t>(touch->GetReplicaNumber(0))
420  : static_cast<uint32_t>(touch->GetReplicaNumber(0) + 1000 * touch->GetReplicaNumber(1));
421  }
422  PassiveData key(std::make_tuple(lv, copy, trackId, pdg, time, energy, energy, stepl, xp, yp, zp));
423  store_.push_back(key);
424  }
425  }
426 }
427 
428 //================================================================ End of EVENT
430  ++count_;
431  // Fill event input
432  edm::LogVerbatim("Step") << "CaloSteppingAction: EndOfEvent " << (*evt)()->GetEventID();
433 }
434 
435 void CaloSteppingAction::NaNTrap(const G4Step* aStep) const {
436  auto currentPos = aStep->GetTrack()->GetPosition();
437  double xyz = currentPos.x() + currentPos.y() + currentPos.z();
438  auto currentMom = aStep->GetTrack()->GetMomentum();
439  xyz += currentMom.x() + currentMom.y() + currentMom.z();
440 
441  if (edm::isNotFinite(xyz)) {
442  auto pCurrentVol = aStep->GetPreStepPoint()->GetPhysicalVolume();
443  auto& nameOfVol = pCurrentVol->GetName();
444  throw cms::Exception("Unknown", "CaloSteppingAction")
445  << " Corrupted Event - NaN detected in volume " << nameOfVol << "\n";
446  }
447 }
448 
449 uint32_t CaloSteppingAction::getDetIDHC(int det, int lay, int depth, const math::XYZVectorD& pos) const {
450  HcalNumberingFromDDD::HcalID tmp = hcNumberingPS_.get()->unitID(det, lay, depth, pos);
451 #ifdef HcalNumberingTest
452  auto id0 = hcNumberingScheme_.get()->getUnitID(tmp);
453  HcalNumberingFromDDD::HcalID tmpO = hcNumbering_.get()->unitID(det, pos, depth, lay);
454  auto idO = hcNumberingScheme_.get()->getUnitID(tmpO);
455  std::string error = (id0 == idO) ? " ** OK **" : " ** ERROR **";
456  edm::LogVerbatim("Step") << "Det ID " << HcalDetId(id0) << " Original " << HcalDetId(idO) << error;
457 #endif
458  return (hcNumberingScheme_.get()->getUnitID(tmp));
459 }
460 
461 void CaloSteppingAction::fillHit(uint32_t id, double dE, double time, int primID, uint16_t depth, double em, int flag) {
462  CaloHitID currentID(id, time, primID, depth, timeSliceUnit_);
463  double edepEM = (em ? dE : 0);
464  double edepHAD = (em ? 0 : dE);
465  std::pair<int, CaloHitID> evID = std::make_pair(eventID_, currentID);
466  auto it = hitMap_[flag].find(evID);
467  if (it != hitMap_[flag].end()) {
468  (it->second).addEnergyDeposit(edepEM, edepHAD);
469  } else {
470  CaloGVHit aHit;
471  aHit.setEventID(eventID_);
472  aHit.setID(currentID);
473  aHit.addEnergyDeposit(edepEM, edepHAD);
474  hitMap_[flag][evID] = aHit;
475  }
476 }
477 
478 uint16_t CaloSteppingAction::getDepth(bool flag, double crystalDepth, double radl) const {
479  uint16_t depth1 = (flag ? 0 : PCaloHit::kEcalDepthRefz);
480  uint16_t depth2 = (uint16_t)floor(crystalDepth / radl);
481  uint16_t depth = (((depth2 & PCaloHit::kEcalDepthMask) << PCaloHit::kEcalDepthOffset) | depth1);
482 #ifdef EDM_ML_DEBUG
483  edm::LogVerbatim("Step") << "CaloSteppingAction::getDepth radl " << radl << ":" << crystalDepth << " depth " << depth;
484 #endif
485  return depth;
486 }
487 
488 double CaloSteppingAction::curve_LY(double crystalLength, double crystalDepth) const {
489  double weight = 1.;
490  double dapd = crystalLength - crystalDepth;
491  if (dapd >= -0.1 || dapd <= crystalLength + 0.1) {
492  if (dapd <= 100.)
493  weight = 1.0 + slopeLY_ - dapd * 0.01 * slopeLY_;
494 #ifdef EDM_ML_DEBUG
495  edm::LogVerbatim("Step") << "CaloSteppingAction::curve_LY " << crystalDepth << ":" << crystalLength << ":" << dapd
496  << ":" << weight;
497 #endif
498  } else {
499  edm::LogWarning("Step") << "CaloSteppingAction: light coll curve : wrong "
500  << "distance to APD " << dapd << " crlength = " << crystalLength
501  << " crystal Depth = " << crystalDepth << " weight = " << weight;
502  }
503  return weight;
504 }
505 
506 double CaloSteppingAction::getBirkL3(double dEStep, double step, double charge, double density) const {
507  double weight = 1.;
508  if (charge != 0. && step > 0.) {
509  double dedx = dEStep / step;
510  double rkb = birkC1EC_ / density;
511  if (dedx > 0) {
512  weight = 1. - birkSlopeEC_ * log(rkb * dedx);
513  if (weight < birkCutEC_)
514  weight = birkCutEC_;
515  else if (weight > 1.)
516  weight = 1.;
517  }
518 #ifdef EDM_ML_DEBUG
519  edm::LogVerbatim("Step") << "CaloSteppingAction::getBirkL3 Charge " << charge << " dE/dx " << dedx << " Birk Const "
520  << rkb << " Weight = " << weight << " dE " << dEStep << " step " << step;
521 #endif
522  }
523  return weight;
524 }
525 
526 double CaloSteppingAction::getBirkHC(double dEStep, double step, double charge, double density) const {
527  double weight = 1.;
528  if (charge != 0. && step > 0.) {
529  double dedx = dEStep / step;
530  double rkb = birkC1HC_ / density;
531  double c = birkC2HC_ * rkb * rkb;
532  if (std::abs(charge) >= 2.)
533  rkb /= birkC3HC_;
534  weight = 1. / (1. + rkb * dedx + c * dedx * dedx);
535 #ifdef EDM_ML_DEBUG
536  edm::LogVerbatim("Step") << "CaloSteppingAction::getBirkHC Charge " << charge << " dE/dx " << dedx << " Birk Const "
537  << rkb << ", " << c << " Weight = " << weight << " dE " << dEStep;
538 #endif
539  }
540  return weight;
541 }
542 
544  edm::LogVerbatim("Step") << "CaloSteppingAction:: saveHits for type " << type << " with " << hitMap_[type].size()
545  << " hits";
546  slave_[type].get()->ReserveMemory(hitMap_[type].size());
547  for (auto const& hit : hitMap_[type]) {
548  slave_[type].get()->processHits(hit.second.getUnitID(),
549  0.001 * hit.second.getEM(),
550  0.001 * hit.second.getHadr(),
551  hit.second.getTimeSlice(),
552  hit.second.getTrackID(),
553  hit.second.getDepth());
554  }
555 }
556 
559 
size
Write out results.
std::map< std::pair< int, CaloHitID >, CaloGVHit > hitMap_[nSD_]
Log< level::Info, true > LogVerbatim
#define DEFINE_SIMWATCHER(type)
std::vector< const G4LogicalVolume * > volEBSD_
void setID(uint32_t i, double d, int j, uint16_t k=0)
Definition: CaloGVHit.h:55
std::vector< PCaloHit > PCaloHitContainer
const std::vector< std::string > nameHitC_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const std::vector< std::string > nameEESD_
static const int kEcalDepthRefz
Definition: PCaloHit.h:63
const float chg[109]
Definition: CoreSimTrack.cc:5
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
void produce(edm::Event &, const edm::EventSetup &) override
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
void registerConsumes(edm::ConsumesCollector) override
std::map< const G4LogicalVolume *, double > xtalMap_
std::vector< const G4LogicalVolume * > volHCSD_
const std::vector< std::string > nameEBSD_
Definition: weight.py:1
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void setEventID(int id)
Definition: CaloGVHit.h:46
uint16_t getDepth(bool flag, double crystalDepth, double radl) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
void fillHits(edm::PCaloHitContainer &cc, int type)
void NaNTrap(const G4Step *) const
void addLevel(const std::string &name, const int &copyNumber)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
Definition: Vector3D.h:8
CaloSteppingAction(const edm::ParameterSet &p)
void update(const BeginOfRun *run) override
This routine will be called when the appropriate signal arrives.
static const int kEcalDepthMask
Definition: PCaloHit.h:61
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
key
prepare the HTCondor submission files and eventually submit them
static const int kEcalDepthOffset
Definition: PCaloHit.h:62
std::map< const G4LogicalVolume *, std::string > mapLV_
const edm::ParameterSet iC_
uint32_t getDetIDHC(int det, int lay, int depth, const math::XYZVectorD &pos) const
void fillPassiveHits(edm::PassiveHitContainer &cc)
std::vector< PassiveHit > PassiveHitContainer
Definition: PassiveHit.h:100
void addEnergyDeposit(double em, double hd)
Definition: CaloGVHit.cc:29
std::unique_ptr< CaloSlaveSD > slave_[nSD_]
ii
Definition: cuy.py:589
void fillHit(uint32_t id, double dE, double time, int primID, uint16_t depth, double em, int flag)
double getBirkHC(double dE, double step, double chg, double dens) const
std::unique_ptr< HcalNumberingFromPS > hcNumberingPS_
std::unique_ptr< HcalNumberingScheme > hcNumberingScheme_
void beginRun(edm::EventSetup const &) override
std::vector< const G4LogicalVolume * > volEESD_
std::unique_ptr< EcalBarrelNumberingScheme > ebNumberingScheme_
HLT enums.
std::tuple< const G4LogicalVolume *, uint32_t, int, int, double, double, double, double, double, double, double > PassiveData
static bool isGammaElectronPositron(int pdgCode)
std::unique_ptr< EcalEndcapNumberingScheme > eeNumberingScheme_
double getBirkL3(double dE, double step, double chg, double dens) const
std::vector< PassiveData > store_
step
Definition: StallMonitor.cc:83
const std::vector< std::string > nameHCSD_
Log< level::Warning, false > LogWarning
static const int nSD_
void setSize(const int &size)
tmp
align.sh
Definition: createJobs.py:716
double curve_LY(double crystalLength, double crystalDepth) const
def move(src, dest)
Definition: eostools.py:511