CMS 3D CMS Logo

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