CMS 3D CMS Logo

MaterialBudgetHcal.cc
Go to the documentation of this file.
2 
6 
9 
10 #include "G4Step.hh"
11 #include "G4Track.hh"
12 
13 #include <iostream>
14 #include <memory>
15 
17  edm::ParameterSet m_p = p.getParameter<edm::ParameterSet>("MaterialBudgetHcal");
18  rMax_ = m_p.getUntrackedParameter<double>("RMax", 4.5) * CLHEP::m;
19  zMax_ = m_p.getUntrackedParameter<double>("ZMax", 13.0) * CLHEP::m;
20  fromdd4hep_ = m_p.getUntrackedParameter<bool>("Fromdd4hep", false);
21  bool doHcal = m_p.getUntrackedParameter<bool>("DoHCAL", true);
22  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetHcal initialized with rMax " << rMax_ << " mm and zMax " << zMax_
23  << " mm doHcal is set to " << doHcal << " and Fromdd4hep to " << fromdd4hep_;
24  if (doHcal) {
25  theHistoHcal_ = std::make_unique<MaterialBudgetHcalHistos>(m_p);
26  theHistoCastor_.reset(nullptr);
27  } else {
28  theHistoHcal_.reset(nullptr);
29  theHistoCastor_ = std::make_unique<MaterialBudgetCastorHistos>(m_p);
30  }
31 }
32 
34  if (fromdd4hep_)
36  else
38  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetHcal: Initialize the token for CompactView";
39 }
40 
42  //----- Check that selected volumes are indeed part of the geometry
43  // Numbering From DDD
44  if (fromdd4hep_) {
45  const auto& pDD = es.getHandle(cpvTokenDD4hep_);
46  if (theHistoHcal_)
47  theHistoHcal_->fillBeginJob((*pDD));
48  } else {
49  const auto& pDD = es.getHandle(cpvTokenDDD_);
50  if (theHistoHcal_)
51  theHistoHcal_->fillBeginJob((*pDD));
52  }
53 }
54 
56  const G4Track* aTrack = (*trk)(); // recover G4 pointer if wanted
57  if (theHistoHcal_)
58  theHistoHcal_->fillStartTrack(aTrack);
59  if (theHistoCastor_)
60  theHistoCastor_->fillStartTrack(aTrack);
61 }
62 
63 void MaterialBudgetHcal::update(const G4Step* aStep) {
64  //---------- each step
65  if (theHistoHcal_)
66  theHistoHcal_->fillPerStep(aStep);
67  if (theHistoCastor_)
68  theHistoCastor_->fillPerStep(aStep);
69 
70  //----- Stop tracking after selected position
71  if (stopAfter(aStep)) {
72  G4Track* track = aStep->GetTrack();
73  track->SetTrackStatus(fStopAndKill);
74  }
75 }
76 
78  if (theHistoHcal_)
79  theHistoHcal_->fillEndTrack();
80  if (theHistoCastor_)
81  theHistoCastor_->fillEndTrack();
82 }
83 
84 bool MaterialBudgetHcal::stopAfter(const G4Step* aStep) {
85  G4ThreeVector hitPoint = aStep->GetPreStepPoint()->GetPosition();
86  double rr = hitPoint.perp();
87  double zz = std::abs(hitPoint.z());
88 
89  if (rr > rMax_ || zz > zMax_) {
90  edm::LogVerbatim("MaterialBudget") << " MaterialBudgetHcal::StopAfter R = " << rr << " and Z = " << zz;
91  return true;
92  } else {
93  return false;
94  }
95 }
Log< level::Info, true > LogVerbatim
void update(const BeginOfTrack *) override
This routine will be called when the appropriate signal arrives.
std::unique_ptr< MaterialBudgetHcalHistos > theHistoHcal_
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > cpvTokenDD4hep_
void beginRun(edm::EventSetup const &) override
void registerConsumes(edm::ConsumesCollector) override
T getUntrackedParameter(std::string const &, T const &) const
bool stopAfter(const G4Step *)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::ESGetToken< DDCompactView, IdealGeometryRecord > cpvTokenDDD_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
MaterialBudgetHcal(const edm::ParameterSet &)
std::unique_ptr< MaterialBudgetCastorHistos > theHistoCastor_