CMS 3D CMS Logo

HGCalTBMB.cc
Go to the documentation of this file.
6 
11 
12 #include "G4LogicalVolumeStore.hh"
13 #include "G4Step.hh"
14 #include "G4Track.hh"
15 
16 #include <TH1F.h>
17 
18 #include <iostream>
19 #include <string>
20 #include <vector>
21 
22 //#define EDM_ML_DEBUG
23 
24 class HGCalTBMB : public SimWatcher,
25  public Observer<const BeginOfTrack*>,
26  public Observer<const G4Step*>,
27  public Observer<const EndOfTrack*> {
28 public:
30  ~HGCalTBMB() override;
31 
32 private:
33  HGCalTBMB(const HGCalTBMB&) = delete; // stop default
34  const HGCalTBMB& operator=(const HGCalTBMB&) = delete; // ...
35 
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_;
47  std::vector<double> radLen_, intLen_, stepLen_;
48  std::vector<TH1D*> me100_, me200_, me300_;
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") << "HGCalTBMB 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 
63  if (!tfile.isAvailable())
64  throw cms::Exception("BadConfig") << "TFileService unavailable: "
65  << "please add it to config file";
66  char name[20], title[80];
67  TH1D* hist;
68  for (unsigned int i = 0; i <= nList_; i++) {
69  std::string named = (i == nList_) ? "Total" : listNames_[i];
70  sprintf(name, "RadL%d", i);
71  sprintf(title, "MB(X0) for (%s)", named.c_str());
72  hist = tfile->make<TH1D>(name, title, 100000, 0.0, 100.0);
73  hist->Sumw2(true);
74  me100_.push_back(hist);
75  sprintf(name, "IntL%d", i);
76  sprintf(title, "MB(L0) for (%s)", named.c_str());
77  hist = tfile->make<TH1D>(name, title, 100000, 0.0, 10.0);
78  hist->Sumw2(true);
79  me200_.push_back(hist);
80  sprintf(name, "StepL%d", i);
81  sprintf(title, "MB(Step) for (%s)", named.c_str());
82  hist = tfile->make<TH1D>(name, title, 100000, 0.0, 50000.0);
83  hist->Sumw2(true);
84  me300_.push_back(hist);
85  }
86  edm::LogVerbatim("HGCSim") << "HGCalTBMB: Booking user histos done ===";
87 }
88 
90 
91 void HGCalTBMB::update(const BeginOfTrack* trk) {
92  radLen_ = std::vector<double>(nList_ + 1, 0);
93  intLen_ = std::vector<double>(nList_ + 1, 0);
94  stepLen_ = std::vector<double>(nList_ + 1, 0);
95 
96 #ifdef EDM_ML_DEBUG
97  const G4Track* aTrack = (*trk)(); // recover G4 pointer if wanted
98  const G4ThreeVector& mom = aTrack->GetMomentum();
99  double theEnergy = aTrack->GetTotalEnergy();
100  int theID = (int)(aTrack->GetDefinition()->GetPDGEncoding());
101  edm::LogVerbatim("HGCSim") << "MaterialBudgetHcalHistos: Track " << aTrack->GetTrackID() << " Code " << theID
102  << " Energy " << theEnergy / CLHEP::GeV << " GeV; Momentum " << mom;
103 #endif
104 }
105 
106 void HGCalTBMB::update(const G4Step* aStep) {
107  G4Material* material = aStep->GetPreStepPoint()->GetMaterial();
108  double step = aStep->GetStepLength();
109  double radl = material->GetRadlen();
110  double intl = material->GetNuclearInterLength();
111 
112  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
113  int indx = findVolume(touch, false);
114 
115  if (indx >= 0) {
116  stepLen_[indx] += step;
117  radLen_[indx] += (step / radl);
118  intLen_[indx] += (step / intl);
119  }
120  stepLen_[nList_] += step;
121  radLen_[nList_] += (step / radl);
122  intLen_[nList_] += (step / intl);
123 #ifdef EDM_ML_DEBUG
124  edm::LogVerbatim("HGCSim") << "HGCalTBMB::Step in " << touch->GetVolume(0)->GetLogicalVolume()->GetName() << " Index "
125  << indx << " Step " << step << " RadL " << step / radl << " IntL " << step / intl;
126 #endif
127 
128  if (stopAfter(aStep)) {
129  G4Track* track = aStep->GetTrack();
130  track->SetTrackStatus(fStopAndKill);
131  }
132 }
133 
134 void HGCalTBMB::update(const EndOfTrack* trk) {
135  for (unsigned int ii = 0; ii <= nList_; ++ii) {
136  me100_[ii]->Fill(radLen_[ii]);
137  me200_[ii]->Fill(intLen_[ii]);
138  me300_[ii]->Fill(stepLen_[ii]);
139 #ifdef EDM_ML_DEBUG
140  std::string name("Total");
141  if (ii < nList_)
142  name = listNames_[ii];
143  edm::LogVerbatim("HGCSim") << "HGCalTBMB::Volume[" << ii << "]: " << name << " == Step " << stepLen_[ii] << " RadL "
144  << radLen_[ii] << " IntL " << intLen_[ii];
145 #endif
146  }
147 }
148 
149 bool HGCalTBMB::stopAfter(const G4Step* aStep) {
150  bool flag(false);
151  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
152  G4ThreeVector hitPoint = aStep->GetPreStepPoint()->GetPosition();
153  if (aStep->GetPostStepPoint() != nullptr)
154  hitPoint = aStep->GetPostStepPoint()->GetPosition();
155  double zz = hitPoint.z();
156 
157  if ((findVolume(touch, true) == 0) || (zz > stopZ_))
158  flag = true;
159 #ifdef EDM_ML_DEBUG
160  edm::LogVerbatim("HGCSim") << " HGCalTBMB::Name " << touch->GetVolume(0)->GetName() << " z " << zz << " Flag" << flag;
161 #endif
162  return flag;
163 }
164 
165 int HGCalTBMB::findVolume(const G4VTouchable* touch, bool stop) const {
166  int ivol = -1;
167  int level = (touch->GetHistoryDepth()) + 1;
168  for (int ii = 0; ii < level; ii++) {
169  std::string name = touch->GetVolume(ii)->GetName();
170  if (stop) {
171  if (strcmp(name.c_str(), stopName_.c_str()) == 0)
172  ivol = 0;
173  } else {
174  for (unsigned int k = 0; k < nList_; ++k) {
175  if (strcmp(name.c_str(), listNames_[k].c_str()) == 0) {
176  ivol = k;
177  break;
178  }
179  }
180  }
181  if (ivol >= 0)
182  break;
183  }
184  return ivol;
185 }
186 
190 
personalPlayback.level
level
Definition: personalPlayback.py:22
HGCalTBMB::HGCalTBMB
HGCalTBMB(const edm::ParameterSet &)
Definition: HGCalTBMB.cc:51
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
mps_fire.i
i
Definition: mps_fire.py:428
geometryCSVtoXML.zz
zz
Definition: geometryCSVtoXML.py:19
HGCalTBMB::listNames_
std::vector< std::string > listNames_
Definition: HGCalTBMB.cc:43
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
Observer
Definition: Observer.h:23
MessageLogger.h
HGCalTBMB::stepLen_
std::vector< double > stepLen_
Definition: HGCalTBMB.cc:47
step
step
Definition: StallMonitor.cc:94
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
HGCalTBMB::operator=
const HGCalTBMB & operator=(const HGCalTBMB &)=delete
EndOfTrack.h
HGCalTBMB::~HGCalTBMB
~HGCalTBMB() override
Definition: HGCalTBMB.cc:89
EndOfTrack
Definition: EndOfTrack.h:6
Observer.h
BeginOfTrack.h
DEFINE_SIMWATCHER
#define DEFINE_SIMWATCHER(type)
Definition: SimWatcherFactory.h:13
MakerMacros.h
HGCalTBMB::me100_
std::vector< TH1D * > me100_
Definition: HGCalTBMB.cc:48
compare.hist
hist
Definition: compare.py:376
SimWatcher.h
Service.h
tfile
Definition: tfile.py:1
HGCalTBMB::nList_
unsigned int nList_
Definition: HGCalTBMB.cc:46
HGCalTBMB::stopZ_
double stopZ_
Definition: HGCalTBMB.cc:45
BeginOfTrack
Definition: BeginOfTrack.h:6
HGCalTBMB::me200_
std::vector< TH1D * > me200_
Definition: HGCalTBMB.cc:48
dqmdumpme.k
k
Definition: dqmdumpme.py:60
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TFileService.h
edm::ParameterSet
Definition: ParameterSet.h:47
HGCalTBMB::radLen_
std::vector< double > radLen_
Definition: HGCalTBMB.cc:47
SimWatcherFactory.h
GeV
const double GeV
Definition: MathUtil.h:16
ModuleDef.h
edm::Service< TFileService >
createfilelist.int
int
Definition: createfilelist.py:10
SimWatcher
Definition: SimWatcher.h:33
HGCalTBMB::intLen_
std::vector< double > intLen_
Definition: HGCalTBMB.cc:47
HGCalTBMB::stopName_
std::string stopName_
Definition: HGCalTBMB.cc:44
compare.tfile
tfile
Definition: compare.py:325
HGCalTBMB::me300_
std::vector< TH1D * > me300_
Definition: HGCalTBMB.cc:48
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
HGCalTBMB::update
void update(const BeginOfTrack *) override
This routine will be called when the appropriate signal arrives.
Definition: HGCalTBMB.cc:91
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
HGCalTBMB::findVolume
int findVolume(const G4VTouchable *touch, bool stop) const
Definition: HGCalTBMB.cc:165
cms::Exception
Definition: Exception.h:70
ParameterSet.h
HGCalTBMB
Definition: HGCalTBMB.cc:24
edm::Log
Definition: MessageLogger.h:70
HGCalTBMB::stopAfter
bool stopAfter(const G4Step *)
Definition: HGCalTBMB.cc:149
cuy.ii
ii
Definition: cuy.py:590
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116