CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HGCalTBMBProducer.cc
Go to the documentation of this file.
6 
12 
13 #include "G4LogicalVolumeStore.hh"
14 #include "G4Step.hh"
15 #include "G4Track.hh"
16 
17 #include <iostream>
18 #include <string>
19 #include <vector>
20 
21 //#define EDM_ML_DEBUG
22 
24  public Observer<const BeginOfTrack*>,
25  public Observer<const G4Step*>,
26  public Observer<const EndOfTrack*> {
27 public:
29  HGCalTBMBProducer(const HGCalTBMBProducer&) = delete; // stop default
30  const HGCalTBMBProducer& operator=(const HGCalTBMBProducer&) = delete; // ...
31  ~HGCalTBMBProducer() override = default;
32 
33  void produce(edm::Event&, const edm::EventSetup&) override;
34 
35 private:
36  void update(const BeginOfTrack*) override;
37  void update(const G4Step*) override;
38  void update(const EndOfTrack*) override;
39 
40  bool stopAfter(const G4Step*);
41  int findVolume(const G4VTouchable* touch, bool stop) const;
42 
43  std::vector<std::string> listNames_;
45  double stopZ_;
46  unsigned int nList_;
48  std::vector<double> radLen_, intLen_, stepLen_;
49 };
50 
52  edm::ParameterSet m_p = p.getParameter<edm::ParameterSet>("HGCalTBMB");
53  listNames_ = m_p.getParameter<std::vector<std::string> >("DetectorNames");
54  stopName_ = m_p.getParameter<std::string>("StopName");
55  stopZ_ = m_p.getParameter<double>("MaximumZ");
56  nList_ = listNames_.size();
57  edm::LogVerbatim("HGCSim") << "HGCalTBMBProducer initialized for " << nList_ << " volumes";
58  for (unsigned int k = 0; k < nList_; ++k)
59  edm::LogVerbatim("HGCSim") << " [" << k << "] " << listNames_[k];
60  edm::LogVerbatim("HGCSim") << "Stop after " << stopZ_ << " or reaching volume " << stopName_;
61 
62  produces<MaterialAccountingCaloCollection>("HGCalTBMB");
63 }
64 
66  std::unique_ptr<MaterialAccountingCaloCollection> hgc(new MaterialAccountingCaloCollection);
67  for (auto const& mbc : matcoll_) {
68  hgc->emplace_back(mbc);
69  }
70  e.put(std::move(hgc), "HGCalTBMB");
71 }
72 
74  radLen_ = std::vector<double>(nList_ + 1, 0);
75  intLen_ = std::vector<double>(nList_ + 1, 0);
76  stepLen_ = std::vector<double>(nList_ + 1, 0);
77 
78 #ifdef EDM_ML_DEBUG
79  const G4Track* aTrack = (*trk)(); // recover G4 pointer if wanted
80  const G4ThreeVector& mom = aTrack->GetMomentum();
81  double theEnergy = aTrack->GetTotalEnergy();
82  int theID = (int)(aTrack->GetDefinition()->GetPDGEncoding());
83  edm::LogVerbatim("HGCSim") << "HGCalTBMBProducer: Track " << aTrack->GetTrackID() << " Code " << theID << " Energy "
84  << theEnergy / CLHEP::GeV << " GeV; Momentum " << mom;
85 #endif
86 }
87 
88 void HGCalTBMBProducer::update(const G4Step* aStep) {
89  G4Material* material = aStep->GetPreStepPoint()->GetMaterial();
90  double step = aStep->GetStepLength();
91  double radl = material->GetRadlen();
92  double intl = material->GetNuclearInterLength();
93 
94  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
95  int indx = findVolume(touch, false);
96 
97  if (indx >= 0) {
98  stepLen_[indx] += step;
99  radLen_[indx] += (step / radl);
100  intLen_[indx] += (step / intl);
101  }
102  stepLen_[nList_] += step;
103  radLen_[nList_] += (step / radl);
104  intLen_[nList_] += (step / intl);
105 #ifdef EDM_ML_DEBUG
106  edm::LogVerbatim("HGCSim") << "HGCalTBMBProducer::Step in " << touch->GetVolume(0)->GetLogicalVolume()->GetName()
107  << " Index " << indx << " Step " << step << " RadL " << step / radl << " IntL "
108  << step / intl;
109 #endif
110 
111  if (stopAfter(aStep)) {
112  G4Track* track = aStep->GetTrack();
113  track->SetTrackStatus(fStopAndKill);
114  }
115 }
116 
118  MaterialAccountingCalo matCalo;
119  matCalo.m_eta = 0;
120  matCalo.m_phi = 0;
121  for (unsigned int ii = 0; ii <= nList_; ++ii) {
122  matCalo.m_stepLen.emplace_back(stepLen_[ii]);
123  matCalo.m_radLen.emplace_back(radLen_[ii]);
124  matCalo.m_intLen.emplace_back(intLen_[ii]);
125 #ifdef EDM_ML_DEBUG
126  std::string name("Total");
127  if (ii < nList_)
128  name = listNames_[ii];
129  edm::LogVerbatim("HGCSim") << "HGCalTBMBProducer::Volume[" << ii << "]: " << name << " == Step " << stepLen_[ii]
130  << " RadL " << radLen_[ii] << " IntL " << intLen_[ii];
131 #endif
132  }
133  matcoll_.emplace_back(matCalo);
134 }
135 
136 bool HGCalTBMBProducer::stopAfter(const G4Step* aStep) {
137  bool flag(false);
138  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
139  G4ThreeVector hitPoint = aStep->GetPreStepPoint()->GetPosition();
140  if (aStep->GetPostStepPoint() != nullptr)
141  hitPoint = aStep->GetPostStepPoint()->GetPosition();
142  double zz = hitPoint.z();
143 
144  if ((findVolume(touch, true) == 0) || (zz > stopZ_))
145  flag = true;
146 #ifdef EDM_ML_DEBUG
147  edm::LogVerbatim("HGCSim") << " HGCalTBMBProducer::Name " << touch->GetVolume(0)->GetName() << " z " << zz << " Flag"
148  << flag;
149 #endif
150  return flag;
151 }
152 
153 int HGCalTBMBProducer::findVolume(const G4VTouchable* touch, bool stop) const {
154  int ivol = -1;
155  int level = (touch->GetHistoryDepth()) + 1;
156  for (int ii = 0; ii < level; ii++) {
157  std::string name = touch->GetVolume(ii)->GetName();
158  if (stop) {
159  if (strcmp(name.c_str(), stopName_.c_str()) == 0)
160  ivol = 0;
161  } else {
162  for (unsigned int k = 0; k < nList_; ++k) {
163  if (strcmp(name.c_str(), listNames_[k].c_str()) == 0) {
164  ivol = k;
165  break;
166  }
167  }
168  }
169  if (ivol >= 0)
170  break;
171  }
172  return ivol;
173 }
174 
178 
Log< level::Info, true > LogVerbatim
#define DEFINE_SIMWATCHER(type)
MaterialAccountingCaloCollection matcoll_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const double GeV
Definition: MathUtil.h:16
const HGCalTBMBProducer & operator=(const HGCalTBMBProducer &)=delete
std::vector< MaterialAccountingCalo > MaterialAccountingCaloCollection
HGCalTBMBProducer(const edm::ParameterSet &)
std::vector< std::string > listNames_
std::vector< double > m_radLen
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< double > radLen_
int ii
Definition: cuy.py:589
void update(const BeginOfTrack *) override
This routine will be called when the appropriate signal arrives.
def move
Definition: eostools.py:511
int findVolume(const G4VTouchable *touch, bool stop) const
std::vector< double > stepLen_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< double > m_intLen
~HGCalTBMBProducer() override=default
std::vector< double > intLen_
step
Definition: StallMonitor.cc:94
tuple level
Definition: testEve_cfg.py:47
std::vector< double > m_stepLen
bool stopAfter(const G4Step *)