CMS 3D CMS Logo

MaterialBudgetHcalHistos.cc
Go to the documentation of this file.
2 
11 
12 #include "CLHEP/Units/GlobalPhysicalConstants.h"
13 #include "CLHEP/Units/GlobalSystemOfUnits.h"
14 
15 #include <string>
16 
18  binEta = p.getUntrackedParameter<int>("NBinEta", 260);
19  binPhi = p.getUntrackedParameter<int>("NBinPhi", 180);
20  maxEta = p.getUntrackedParameter<double>("MaxEta", 5.2);
21  etaLow = p.getUntrackedParameter<double>("EtaLow", -5.2);
22  etaHigh = p.getUntrackedParameter<double>("EtaHigh", 5.2);
23  fillHistos = p.getUntrackedParameter<bool>("FillHisto", true);
24  printSum = p.getUntrackedParameter<bool>("PrintSummary", false);
25  edm::LogInfo("MaterialBudget") << "MaterialBudgetHcalHistos: FillHisto : " << fillHistos << " PrintSummary "
26  << printSum << " == Eta plot: NX " << binEta << " Range " << -maxEta << ":" << maxEta
27  << " Phi plot: NX " << binPhi << " Range " << -pi << ":" << pi << " (Eta limit "
28  << etaLow << ":" << etaHigh << ")";
29  if (fillHistos)
30  book();
31 }
32 
34  if (fillHistos) {
35  std::string attribute = "ReadOutName";
36  std::string value = "HcalHits";
37  DDSpecificsMatchesValueFilter filter1{DDValue(attribute, value, 0)};
38  DDFilteredView fv1(cpv, filter1);
39  sensitives = getNames(fv1);
40  edm::LogInfo("MaterialBudget") << "MaterialBudgetHcalHistos: Names to be "
41  << "tested for " << attribute << " = " << value << " has " << sensitives.size()
42  << " elements";
43  for (unsigned int i = 0; i < sensitives.size(); i++)
44  edm::LogInfo("MaterialBudget") << "MaterialBudgetHcalHistos: sensitives[" << i << "] = " << sensitives[i];
45 
46  attribute = "Volume";
47  value = "HF";
48  DDSpecificsMatchesValueFilter filter2{DDValue(attribute, value, 0)};
49  DDFilteredView fv2(cpv, filter2);
50  hfNames = getNames(fv2);
51  fv2.firstChild();
53  std::vector<double> temp = getDDDArray("Levels", sv);
54  edm::LogInfo("MaterialBudget") << "MaterialBudgetHcalHistos: Names to be "
55  << "tested for " << attribute << " = " << value << " has " << hfNames.size()
56  << " elements";
57  for (unsigned int i = 0; i < hfNames.size(); i++) {
58  int level = static_cast<int>(temp[i]);
59  hfLevels.push_back(level);
60  edm::LogInfo("MaterialBudget") << "MaterialBudgetHcalHistos: HF[" << i << "] = " << hfNames[i] << " at level "
61  << hfLevels[i];
62  }
63 
64  std::string ecalRO[2] = {"EcalHitsEB", "EcalHitsEE"};
65  attribute = "ReadOutName";
66  for (int k = 0; k < 2; k++) {
67  value = ecalRO[k];
68  DDSpecificsMatchesValueFilter filter3{DDValue(attribute, value, 0)};
69  DDFilteredView fv3(cpv, filter3);
70  std::vector<std::string> senstmp = getNames(fv3);
71  edm::LogInfo("MaterialBudget") << "MaterialBudgetHcalHistos: Names to be"
72  << " tested for " << attribute << " = " << value << " has " << senstmp.size()
73  << " elements";
74  for (unsigned int i = 0; i < senstmp.size(); i++)
75  sensitiveEC.push_back(senstmp[i]);
76  }
77  for (unsigned int i = 0; i < sensitiveEC.size(); i++)
78  edm::LogInfo("MaterialBudget") << "MaterialBudgetHcalHistos:sensitiveEC[" << i << "] = " << sensitiveEC[i];
79  }
80 }
81 
82 void MaterialBudgetHcalHistos::fillStartTrack(const G4Track* aTrack) {
83  id = layer = steps = 0;
84  radLen = intLen = stepLen = 0;
85  nlayHB = nlayHE = nlayHF = nlayHO = 0;
86 
87  const G4ThreeVector& dir = aTrack->GetMomentum();
88  if (dir.theta() != 0) {
89  eta = dir.eta();
90  } else {
91  eta = -99;
92  }
93  phi = dir.phi();
94  double theEnergy = aTrack->GetTotalEnergy();
95  int theID = (int)(aTrack->GetDefinition()->GetPDGEncoding());
96 
97  if (printSum) {
98  matList.clear();
99  stepLength.clear();
100  radLength.clear();
101  intLength.clear();
102  }
103 
104  edm::LogInfo("MaterialBudget") << "MaterialBudgetHcalHistos: Track " << aTrack->GetTrackID() << " Code " << theID
105  << " Energy " << theEnergy / GeV << " GeV; Eta " << eta << " Phi " << phi / deg
106  << " PT " << dir.perp() / GeV << " GeV *****";
107 }
108 
109 void MaterialBudgetHcalHistos::fillPerStep(const G4Step* aStep) {
110  G4Material* material = aStep->GetPreStepPoint()->GetMaterial();
111  double step = aStep->GetStepLength();
112  double radl = material->GetRadlen();
113  double intl = material->GetNuclearInterLength();
114  double density = material->GetDensity() / (g / cm3);
115 
116  int idOld = id;
117  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
118  std::string name = touch->GetVolume(0)->GetName();
119  const std::string& matName = material->GetName();
120  if (printSum) {
121  bool found = false;
122  for (unsigned int ii = 0; ii < matList.size(); ii++) {
123  if (matList[ii] == matName) {
124  stepLength[ii] += step;
125  radLength[ii] += (step / radl);
126  intLength[ii] += (step / intl);
127  found = true;
128  break;
129  }
130  }
131  if (!found) {
132  matList.push_back(matName);
133  stepLength.push_back(step);
134  radLength.push_back(step / radl);
135  intLength.push_back(step / intl);
136  }
137  edm::LogInfo("MaterialBudget") << name << " " << step << " " << matName << " " << stepLen << " " << step / radl
138  << " " << radLen << " " << step / intl << " " << intLen;
139  } else {
140  edm::LogInfo("MaterialBudget") << "MaterialBudgetHcalHistos: Step at " << name << " Length " << step << " in "
141  << matName << " of density " << density << " g/cc; Radiation Length " << radl
142  << " mm;"
143  << " Interaction Length " << intl << " mm\n"
144  << " Position " << aStep->GetPreStepPoint()->GetPosition()
145  << " Cylindrical R " << aStep->GetPreStepPoint()->GetPosition().perp()
146  << " Length (so far) " << stepLen << " L/X0 " << step / radl << "/" << radLen
147  << " L/Lambda " << step / intl << "/" << intLen;
148  }
149 
150  int det = 0, lay = 0;
151  if (fillHistos) {
152  if (isItEC(name)) {
153  det = 1;
154  lay = 1;
155  } else {
156  if (isSensitive(name)) {
157  if (isItHF(touch)) {
158  det = 5;
159  lay = 21;
160  if (lay != layer)
161  nlayHF++;
162  } else {
163  det = (touch->GetReplicaNumber(1)) / 1000;
164  lay = (touch->GetReplicaNumber(0) / 10) % 100 + 3;
165  if (det == 4) {
166  double abeta = std::abs(eta);
167  if (abeta < 1.479)
168  lay = layer + 1;
169  else
170  lay--;
171  if (lay < 3)
172  lay = 3;
173  if (lay == layer)
174  lay++;
175  if (lay > 20)
176  lay = 20;
177  if (lay != layer)
178  nlayHE++;
179  } else if (lay != layer) {
180  if (lay >= 20)
181  nlayHO++;
182  else
183  nlayHB++;
184  }
185  }
186  LogDebug("MaterialBudget") << "MaterialBudgetHcalHistos: Det " << det << " Layer " << lay << " Eta " << eta
187  << " Phi " << phi / deg;
188  } else if (layer == 1) {
189  det = -1;
190  lay = 2;
191  }
192  }
193  if (det != 0) {
194  if (lay != layer) {
195  id = lay;
196  layer = lay;
197  }
198  }
199 
200  if (id > idOld) {
201  // edm::LogInfo("MaterialBudget") << "MaterialBudgetHcalHistos: Step at " << name;
202  fillHisto(id - 1);
203  }
204  }
205 
206  stepLen += step;
207  radLen += step / radl;
208  intLen += step / intl;
209  if (fillHistos) {
210  if (layer == 21 && det == 5) {
211  if (!isItHF(aStep->GetPostStepPoint()->GetTouchable())) {
212  LogDebug("MaterialBudget") << "MaterialBudgetHcalHistos: After HF in "
213  << aStep->GetPostStepPoint()->GetTouchable()->GetVolume(0)->GetName();
214  fillHisto(id);
215  id++;
216  layer = 0;
217  }
218  }
219  }
220 }
221 
223  edm::LogInfo("MaterialBudget") << "Number of layers hit in HB:" << nlayHB << " HE:" << nlayHE << " HO:" << nlayHO
224  << " HF:" << nlayHF;
225  if (fillHistos) {
226  fillHisto(maxSet - 1);
227  fillLayer();
228  }
229  if (printSum) {
230  for (unsigned int ii = 0; ii < matList.size(); ii++) {
231  edm::LogInfo("MaterialBudget") << matList[ii] << "\t" << stepLength[ii] << "\t" << radLength[ii] << "\t"
232  << intLength[ii];
233  }
234  }
235 }
236 
238  // Book histograms
240 
241  if (!tfile.isAvailable())
242  throw cms::Exception("BadConfig") << "TFileService unavailable: "
243  << "please add it to config file";
244 
245  double maxPhi = pi;
246  edm::LogInfo("MaterialBudget") << "MaterialBudgetHcalHistos: Booking user "
247  << "histos === with " << binEta << " bins "
248  << "in eta from " << -maxEta << " to " << maxEta << " and " << binPhi << " bins "
249  << "in phi from " << -maxPhi << " to " << maxPhi;
250 
251  std::string iter;
252  // total X0
253  for (int i = 0; i < maxSet; i++) {
254  iter = std::to_string(i);
255  me100[i] = tfile->make<TProfile>(
256  std::to_string(i + 100).c_str(), ("MB(X0) prof Eta in region " + iter).c_str(), binEta, -maxEta, maxEta);
257  me200[i] = tfile->make<TProfile>(
258  std::to_string(i + 200).c_str(), ("MB(L0) prof Eta in region " + iter).c_str(), binEta, -maxEta, maxEta);
259  me300[i] = tfile->make<TProfile>(
260  std::to_string(i + 300).c_str(), ("MB(Step) prof Eta in region " + iter).c_str(), binEta, -maxEta, maxEta);
261  me400[i] =
262  tfile->make<TH1F>(std::to_string(i + 400).c_str(), ("Eta in region " + iter).c_str(), binEta, -maxEta, maxEta);
263  me500[i] = tfile->make<TProfile>(
264  std::to_string(i + 500).c_str(), ("MB(X0) prof Ph in region " + iter).c_str(), binPhi, -maxPhi, maxPhi);
265  me600[i] = tfile->make<TProfile>(
266  std::to_string(i + 600).c_str(), ("MB(L0) prof Ph in region " + iter).c_str(), binPhi, -maxPhi, maxPhi);
267  me700[i] = tfile->make<TProfile>(
268  std::to_string(i + 700).c_str(), ("MB(Step) prof Ph in region " + iter).c_str(), binPhi, -maxPhi, maxPhi);
269  me800[i] =
270  tfile->make<TH1F>(std::to_string(i + 800).c_str(), ("Phi in region " + iter).c_str(), binPhi, -maxPhi, maxPhi);
271  me900[i] = tfile->make<TProfile2D>(std::to_string(i + 900).c_str(),
272  ("MB(X0) prof Eta Phi in region " + iter).c_str(),
273  binEta / 2,
274  -maxEta,
275  maxEta,
276  binPhi / 2,
277  -maxPhi,
278  maxPhi);
279  me1000[i] = tfile->make<TProfile2D>(std::to_string(i + 1000).c_str(),
280  ("MB(L0) prof Eta Phi in region " + iter).c_str(),
281  binEta / 2,
282  -maxEta,
283  maxEta,
284  binPhi / 2,
285  -maxPhi,
286  maxPhi);
287  me1100[i] = tfile->make<TProfile2D>(std::to_string(i + 1100).c_str(),
288  ("MB(Step) prof Eta Phi in region " + iter).c_str(),
289  binEta / 2,
290  -maxEta,
291  maxEta,
292  binPhi / 2,
293  -maxPhi,
294  maxPhi);
295  me1200[i] = tfile->make<TH2F>(std::to_string(i + 1200).c_str(),
296  ("Eta vs Phi in region " + iter).c_str(),
297  binEta / 2,
298  -maxEta,
299  maxEta,
300  binPhi / 2,
301  -maxPhi,
302  maxPhi);
303  }
304  for (int i = 0; i < maxSet2; i++) {
305  iter = std::to_string(i);
306  me1300[i] = tfile->make<TH1F>(std::to_string(i + 1300).c_str(),
307  ("Events with layers Hit (0 all, 1 HB, ..) for " + iter).c_str(),
308  binEta,
309  -maxEta,
310  maxEta);
311  me1400[i] = tfile->make<TH2F>(std::to_string(i + 1400).c_str(),
312  ("Eta vs Phi for layers hit in " + iter).c_str(),
313  binEta / 2,
314  -maxEta,
315  maxEta,
316  binPhi / 2,
317  -maxPhi,
318  maxPhi);
319  me1500[i] = tfile->make<TProfile>(std::to_string(i + 1500).c_str(),
320  ("Number of layers crossed (0 all, 1 HB, ..) for " + iter).c_str(),
321  binEta,
322  -maxEta,
323  maxEta);
324  }
325 
326  edm::LogInfo("MaterialBudget") << "MaterialBudgetHcalHistos: Booking user "
327  << "histos done ===";
328 }
329 
331  LogDebug("MaterialBudget") << "MaterialBudgetHcalHistos:FillHisto called "
332  << "with index " << ii << " integrated step " << stepLen << " X0 " << radLen << " Lamda "
333  << intLen;
334 
335  if (ii >= 0 && ii < maxSet) {
336  me100[ii]->Fill(eta, radLen);
337  me200[ii]->Fill(eta, intLen);
338  me300[ii]->Fill(eta, stepLen);
339  me400[ii]->Fill(eta);
340 
341  if (eta >= etaLow && eta <= etaHigh) {
342  me500[ii]->Fill(phi, radLen);
343  me600[ii]->Fill(phi, intLen);
344  me700[ii]->Fill(phi, stepLen);
345  me800[ii]->Fill(phi);
346  }
347 
348  me900[ii]->Fill(eta, phi, radLen);
349  me1000[ii]->Fill(eta, phi, intLen);
350  me1100[ii]->Fill(eta, phi, stepLen);
351  me1200[ii]->Fill(eta, phi);
352  }
353 }
354 
356  me1300[0]->Fill(eta);
357  me1400[0]->Fill(eta, phi);
358  if (nlayHB > 0) {
359  me1300[1]->Fill(eta);
360  me1400[1]->Fill(eta, phi);
361  }
362  if (nlayHB >= 16) {
363  me1300[2]->Fill(eta);
364  me1400[2]->Fill(eta, phi);
365  }
366  if (nlayHE > 0) {
367  me1300[3]->Fill(eta);
368  me1400[3]->Fill(eta, phi);
369  }
370  if (nlayHE >= 16) {
371  me1300[4]->Fill(eta);
372  me1400[4]->Fill(eta, phi);
373  }
374  if (nlayHO > 0) {
375  me1300[5]->Fill(eta);
376  me1400[5]->Fill(eta, phi);
377  }
378  if (nlayHO >= 2) {
379  me1300[6]->Fill(eta);
380  me1400[6]->Fill(eta, phi);
381  }
382  if (nlayHF > 0) {
383  me1300[7]->Fill(eta);
384  me1400[7]->Fill(eta, phi);
385  }
386  if (nlayHB > 0 || nlayHE > 0 || (nlayHF > 0 && std::abs(eta) > 3.0)) {
387  me1300[8]->Fill(eta);
388  me1400[8]->Fill(eta, phi);
389  }
390  me1500[0]->Fill(eta, (double)(nlayHB + nlayHO + nlayHE + nlayHF));
391  me1500[1]->Fill(eta, (double)(nlayHB));
392  me1500[2]->Fill(eta, (double)(nlayHE));
393  me1500[4]->Fill(eta, (double)(nlayHF));
394 }
395 
397  edm::LogInfo("MaterialBudget") << "MaterialBudgetHcalHistos: Save user "
398  << "histos ===";
399 }
400 
401 std::vector<std::string> MaterialBudgetHcalHistos::getNames(DDFilteredView& fv) {
402  std::vector<std::string> tmp;
403  bool dodet = fv.firstChild();
404  while (dodet) {
405  const DDLogicalPart& log = fv.logicalPart();
406  std::string namx = log.name().name();
407  bool ok = true;
408  for (unsigned int i = 0; i < tmp.size(); i++)
409  if (namx == tmp[i])
410  ok = false;
411  if (ok)
412  tmp.push_back(namx);
413  dodet = fv.next();
414  }
415  return tmp;
416 }
417 
419  LogDebug("MaterialBudget") << "MaterialBudgetHcalHistos:getDDDArray called "
420  << "for " << str;
421  DDValue value(str);
422  if (DDfetch(&sv, value)) {
423  LogDebug("MaterialBudget") << value;
424  const std::vector<double>& fvec = value.doubles();
425  int nval = fvec.size();
426  if (nval < 1) {
427  edm::LogError("MaterialBudget") << "MaterialBudgetHcalHistos : # of " << str << " bins " << nval
428  << " < 1 ==> illegal";
429  throw cms::Exception("Unknown", "MaterialBudgetHcalHistos") << "nval < 1 for array " << str << "\n";
430  }
431 
432  return fvec;
433  } else {
434  edm::LogError("MaterialBudget") << "MaterialBudgetHcalHistos : cannot get "
435  << "array " << str;
436  throw cms::Exception("Unknown", "MaterialBudgetHcalHistos") << "cannot get array " << str << "\n";
437  }
438 }
439 
441  std::vector<std::string>::const_iterator it = sensitives.begin();
442  std::vector<std::string>::const_iterator itEnd = sensitives.end();
443  for (; it != itEnd; ++it)
444  if (name == *it)
445  return true;
446  return false;
447 }
448 
449 bool MaterialBudgetHcalHistos::isItHF(const G4VTouchable* touch) {
450  // std::vector<std::string>::const_iterator it = hfNames.begin();
451  int levels = ((touch->GetHistoryDepth()) + 1);
452  for (unsigned int it = 0; it < hfNames.size(); it++) {
453  if (levels >= hfLevels[it]) {
454  std::string name = touch->GetVolume(levels - hfLevels[it])->GetName();
455  if (name == hfNames[it])
456  return true;
457  }
458  }
459  return false;
460 }
461 
463  std::vector<std::string>::const_iterator it = sensitiveEC.begin();
464  std::vector<std::string>::const_iterator itEnd = sensitiveEC.end();
465  for (; it != itEnd; ++it)
466  if (name == *it)
467  return true;
468  return false;
469 }
#define LogDebug(id)
T getUntrackedParameter(std::string const &, T const &) const
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:111
const double GeV
Definition: MathUtil.h:16
const N & name() const
Definition: DDBase.h:59
std::vector< double > stepLength
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
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
const Double_t pi
std::vector< std::string > getNames(DDFilteredView &fv)
std::vector< std::string > hfNames
void fillBeginJob(const DDCompactView &)
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12
std::vector< std::string > matList
void fillStartTrack(const G4Track *)
bool next()
set current node to the next node in the filtered tree
std::vector< double > radLength
bool isAvailable() const
Definition: Service.h:40
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
std::vector< std::string > sensitiveEC
Definition: value.py:1
ii
Definition: cuy.py:590
DDsvalues_type mergedSpecifics() const
bool firstChild()
set the current node to the first child ...
MaterialBudgetHcalHistos(const edm::ParameterSet &p)
std::vector< std::string > sensitives
step
Definition: StallMonitor.cc:94
#define str(s)
tmp
align.sh
Definition: createJobs.py:716
std::vector< double > getDDDArray(const std::string &str, const DDsvalues_type &sv)
const std::string & name() const
Returns the name.
Definition: DDName.cc:40
std::vector< double > intLength
bool isItHF(const G4VTouchable *)