ATLAS Offline Software
FCALDistEtaEnergyShowerLib.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 // this header file
8 
10 #include "AtlasHepMC/GenVertex.h"
11 
12 #include <sstream>
13 #include <fstream>
14 
15 #include <iostream>
16 #include <iomanip>
17 
18 // G4 includes
19 #include "G4Track.hh"
20 
21 #include "LArG4Code/EnergySpot.h"
23 
24 #include "TTree.h"
25 #include "TFile.h"
26 #include "TParameter.h"
27 
28 #define LIB_VERSION 5
29 #ifndef __FSLIB_NO_BACKWARD_COMPAT__
30 #define LIB_VERSION_OLD 3
31 #endif
32 
33 namespace ShowerLib {
34 
35  inline int calcKey(float eta, float dist) {
36  return (int)(eta*1000000)+(int)(dist*1000);
37  }
38 
39  float FCALDistEtaEnergyShowerLib::distance (double x, double y) const
40  {
41  double stepy = m_step * sqrt(3.)/2.;
42  double dy = fmod(y-m_yrodcent,stepy);
43  int ny = int( (y-m_yrodcent)/stepy );
44  //additional half shift:
45  double dx0 = (ny % 2 )*m_step/2.;
46  double dx = fmod(x-m_xrodcent-dx0,m_step);
47  double d1 = sqrt(dx*dx+dy*dy);
48  double d2 = sqrt((m_step-dx)*(m_step-dx)+dy*dy);
49  double d3 = sqrt((m_step/2.-dx)*(m_step/2.-dx)+(stepy-dy)*(stepy-dy));
50  float dd = d1;
51  if (dd > d2) dd = d2;
52  if (dd > d3) dd = d3;
53  return dd;
54  }
55 
57  {
58 
59 
60  TParameter<int>* ver;
61  ver = (TParameter<int>*)source->Get("version");
62 
63  if ((ver == nullptr) || (ver->GetVal() != LIB_VERSION))
64 #ifndef __FSLIB_NO_BACKWARD_COMPAT__
65  if ((ver == nullptr) || (ver->GetVal() != LIB_VERSION_OLD))
66 #endif
67  return nullptr;
68 
69  TTree* TTreeMeta = (TTree*)source->Get("meta");
70  TTree* TTreeLib = (TTree*)source->Get("library");
71 
72  if ((TTreeMeta == nullptr) || (TTreeLib == nullptr)) return nullptr;
73 
74  std::cout << "FCALDistEtaEnergyShowerLib header found." << std::endl;
75 
77 #ifndef __FSLIB_NO_BACKWARD_COMPAT__
78  if (ver->GetVal() == LIB_VERSION_OLD)
79  newlib->m_compat=true;
80  else
81  newlib->m_compat=false;
82 #endif
83 
84  if (!(newlib->readMeta(TTreeMeta)) || !(newlib->read(TTreeLib))) {
85  delete newlib;
86  std::cout << "FCALDistEtaEnergyShowerLib read unsuccessful." << std::endl;
87  return nullptr;
88  }
89 
90  return newlib;
91 
92  }
93 
95  {
96  /*
97  * Eta Energy Structure format:
98  *
99  * VER PART DET
100  * XRODCENT YRODCENT STEP
101  * ETA1 DIST1 DIST2 ...
102  * ETA2 DIST1 DIST2 ...
103  * ...
104  * END
105  * COMMENT
106  *
107  * where
108  *
109  * VER == 5
110  * DIST(N+1) > DIST(N)
111  * DIST(N) >= 0
112  * First DIST is the beginning of the lib. If not zero, zero will be added
113  * Last DIST is the end of the lib. If less then 4.5, 4.5 will be added
114  */
115  std::ifstream filestr(inputFile.c_str(),std::ios::in);
116 
117 
118  if (!filestr.is_open()) {
119  std::cout << "FCALDistEtaEnergyShowerLib " << inputFile << ": bad file!" << std::endl;
120  return nullptr;
121  }
122 
123  std::string instr;
124  std::getline(filestr,instr);
125 
126  int ver;
127  int part;
128  std::string det;
129 
130  {
131  std::stringstream ss(instr);
132 
133  ss >> ver;
134 
135 #ifndef __FSLIB_NO_BACKWARD_COMPAT__
136  if (ver == LIB_VERSION_OLD) {
137  std::cout << "FCALDistEtaEnergyShowerLib: you are trying to create the old version of this library. Use the new one." << std::endl;
138  return nullptr;
139  }
140 #endif
141  if (ver != LIB_VERSION) {
142  return nullptr;
143  }
144 
145  ss >> part >> det;
146  }
147 
148  std::getline(filestr,instr);
149  double xrodcent, yrodcent,step;
150  {
151  std::stringstream ss(instr);
152  ss >> xrodcent >> yrodcent >> step;
153  }
154 
155  std::map<float,std::vector<float> > libstruct;
156 
157  float etaold = 0;
158  std::getline(filestr,instr);
159  while (instr != "END") {
160 
161  std::stringstream ss(instr);
162 
163  float eta;
164  ss >> eta;
165 
166  if (etaold == 0) {
167  if (eta > 3.0001) {
168  std::cout << "First eta should be 3.0 (have " << eta << ")" << std::endl;
169  return nullptr;
170  }
171  eta = 3.0;
172  } else if (eta <= etaold) {
173  std::cout << "eta is not correct: " << eta << "<=" << etaold << std::endl;
174  return nullptr;
175  }
176  etaold = eta;
177 
178  std::vector<float> * distlist = &(libstruct[eta]);
179 
180  float dist;
181  float distold;
182 
183  ss >> dist;
184 
185  if (ss.fail()) {
186  std::cout << "file reading failed! (not enough data)" << std::endl;
187  return nullptr;
188  }
189 
190  if (dist != 0.) {
191  if (dist < 0) {
192  std::cout << "no negative dists allowed (" << eta << ")" << std::endl;
193  return nullptr;
194  }
195  distlist->push_back(0.);
196  }
197 
198  distlist->push_back(dist);
199  distold = dist;
200 
201  float maxdist = step/sqrt(3);
202 
203  while (!ss.eof()) {
204  ss >> dist;
205  if ((ss.fail()) || (dist <= distold)) {
206  std::cout << "screwed dists! (" << dist << "<=" << distold << ")" << std::endl;
207  return nullptr;
208  }
209  if (dist < maxdist) {
210  distlist->push_back(dist);
211  } else if (dist >= maxdist) {
212  std::cout << "dist can't be bigger than " << maxdist << " (" << dist << "). ignored" << std::endl;
213  }
214  distold = dist;
215  }
216  std::getline(filestr,instr);
217  if (filestr.fail()) {
218  std::cout << "file reading failed! (not enough data)" << std::endl;
219  return nullptr;
220  }
221  }
222 
223  //if (etalist.back() < 4.5) etalist.push_back(4.5);
224 
226  if (!newlib->readStructure(libstruct)) {
227  std::cout << "this structure is not valid" << std::endl;
228  delete newlib;
229  return nullptr;
230  }
231 
232  newlib->m_detector = det;
233  newlib->m_particle = part;
234 
235  newlib->m_xrodcent = xrodcent;
236  newlib->m_yrodcent = yrodcent;
237  newlib->m_step = step;
238 
239  newlib->m_filled = false;
240 
241  std::getline(filestr,instr);
242  newlib->m_comment = instr;
243 
244  return newlib;
245  }
246 
247  std::vector<EnergySpot>* FCALDistEtaEnergyShowerLib::getShower(const G4Track* track, ShowerLibStatistics* stats, int randomShift) const
248  {
249  if (!m_filled) {
250  std::cout << "Library is not created for production use" << std::endl;
251  return nullptr;
252  }
253 
254  //std::cout << "Starting getShower()" << std::endl;
255 
256  double x = track->GetPosition().getX();
257  double y = track->GetPosition().getY();
258 
259  float dist = this->distance(x,y);
260  double eta = track->GetPosition().eta();
261  if (eta < 0) {
262  eta = -eta;
263  }
264 
265  G4int particleCode = track->GetDefinition()->GetPDGEncoding();
266  if ( particleCode < 0 ) particleCode = -particleCode; // hack for positrons.
267 
268  if ( particleCode != m_particle ) {
269  std::cout << "wrong particle: " << particleCode << "!=" << m_particle << std::endl;
270  return nullptr;
271  }
272  if (eta < 3.0) {
273  std::cout << "wrong eta: |eta|=" << eta << " is not inside FCAL" << std::endl;
274  return nullptr;
275  }
276 
277  //std::cout << "Extracted particle parameters: " << eta << std::endl;
278 
279  library::const_iterator libit = m_libData.upper_bound(eta);
280  if (libit == m_libData.begin()) {
281  //this is really weird
282  std::cout << "Something is wrong with eta: |eta|=" << eta << std::endl;
283  } else {
284  --libit;
285  }
286 
287  etabin::const_iterator etait = (*libit).second.upper_bound(dist);
288 
289  if (etait == (*libit).second.begin()) {
290  //this is really weird
291  std::cout << "Something is wrong with dist: x=" << x << " y=" << y << " dist=" << dist << std::endl;
292  } else {
293  --etait;
294  }
295 
296  //std::cout << "Found eta bin" << std::endl;
297 
298  if ((*etait).second.empty()) {
299  std::cout << "The bin corresponding to the eta/dist pair is empty" << std::endl;
300  return nullptr;
301  }
302  double trenergy = track->GetKineticEnergy();
303  //std::cout << "Energy: " << trenergy << std::endl;
304  distbin::const_iterator distit = (*etait).second.lower_bound(trenergy);
305  if (distit == (*etait).second.end()) --distit; //if it points to the end, repoint it to the last shower in bin
306  else if (distit != (*etait).second.begin()) { //find the closest energy. it's either found item or previous (if there is a previous)
307  distbin::const_iterator distitch = distit;
308  --distitch;
309  if (((*distit).first - trenergy) > (trenergy - (*distitch).first)) { // the closest is the previous
310  --distit;
311  }
312  }
313  //std::cout << "Found closest energy:" << (*distit).first << std::endl;
314  if (randomShift > 0) {
315  double upperEnergy = (*distit).first * 1.01; //we allow 1% off
316  for (int i = 0; i < randomShift; i++) {
317  ++distit;
318  if (distit == (*etait).second.end()) {
319  --distit;
320  break;
321  }
322  if ((*distit).first > upperEnergy) break; //energy diff too high
323  }
324  }
325  if ((randomShift < 0)&&(distit != (*etait).second.begin())) {
326  double lowerEnergy = (*distit).first * 0.99; //we allow 1% off
327  for (int i = 0; i > randomShift; i--) {
328  --distit;
329  if (distit == (*etait).second.begin()) {
330  //distit++;
331  break;
332  }
333  if (lowerEnergy > (*distit).first) break; //energy diff too high
334  }
335  }
336  //std::cout << "Found out energy" << std::endl;
337  //std::cout << "Shower with num hits:" << (*etait).second.size() << std::endl;
338  std::vector<EnergySpot>* outshower = new std::vector<EnergySpot>();//((*etait).second);
339  Shower::const_iterator iter;
340  //std::cout << "Created out shower" << std::endl;
341 
342  float energyScale = track->GetKineticEnergy() / (*distit).first;
343  //std::cout << "Scale: " << energyScale << std::endl;
344 
345  for (iter = (*distit).second.begin() /*outshower->begin()*/; iter != (*distit).second.end() /*outshower->end()*/; ++iter) {
346  EnergySpot tmp( (*iter)->GetPosition(), (*iter)->GetEnergy(), (*iter)->GetTime() );
347  tmp.SetEnergy(tmp.GetEnergy() * energyScale);
348  outshower->push_back(tmp);
349  //(*iter).SetEnergy((*iter).GetEnergy() * energyScale);
350  }
351  //std::cout << "Scaled" << std::endl;
352  if (stats != nullptr) {
353  stats->recordShowerLibUse(calcKey((*libit).first,(*etait).first));
354  }
355  //std::cout << "Done" << std::endl;
356  return outshower;
357  }
358 
360  {
361  if (!m_filled) {
362  std::cout << "Library is not created for production use" << std::endl;
363  return 0;
364  }
365 
366  //std::cout << "Starting getShower()" << std::endl;
367 
368  double x = track->GetPosition().getX();
369  double y = track->GetPosition().getY();
370 
371  float dist = this->distance(x,y);
372  double eta = track->GetPosition().eta();
373  if (eta < 0) {
374  eta = -eta;
375  }
376 
377  G4int particleCode = track->GetDefinition()->GetPDGEncoding();
378  if ( particleCode < 0 ) particleCode = -particleCode; // hack for positrons.
379 
380  if ( particleCode != m_particle ) {
381  std::cout << "wrong particle: " << particleCode << "!=" << m_particle << std::endl;
382  return 0;
383  }
384  if (eta < 3.0) {
385  std::cout << "wrong eta: |eta|=" << eta << " is not inside FCAL" << std::endl;
386  return 0;
387  }
388 
389  library::const_iterator libit = m_libData.upper_bound(eta);
390  if (libit == m_libData.begin()) {
391  //this is really weird
392  std::cout << "Something is wrong with eta: |eta|=" << eta << std::endl;
393  } else {
394  --libit;
395  }
396 
397  etabin::const_iterator etait = (*libit).second.upper_bound(dist);
398  if (etait == (*libit).second.begin()) {
399  //this is really weird
400  std::cout << "Something is wrong with dist: x=" << x << " y=" << y << " dist=" << dist << std::endl;
401  } else {
402  --etait;
403  }
404 
405  //std::cout << "Found eta bin" << std::endl;
406 
407  if ((*etait).second.empty()) {
408  std::cout << "The etabin corresponding to the eta is empty" << std::endl;
409  return 0;
410  }
411  double trenergy = track->GetKineticEnergy();
412  //std::cout << "Energy: " << trenergy << std::endl;
413  distbin::const_iterator distit = (*etait).second.lower_bound(trenergy);
414  if (distit == (*etait).second.end()) --distit; //if it points to the end, repoint it to the last shower in bin
415  else if (distit != (*etait).second.begin()) { //find the closest energy. it's either found item or previous (if there is a previous)
416  distbin::const_iterator distitch = distit;
417  --distitch;
418  if (((*distit).first - trenergy) > (trenergy - (*distitch).first)) { // the closest is the previous
419  --distit;
420  }
421  }
422  //std::cout << "Found closest energy:" << (*etait).first << std::endl;
423  double rezZ = (*distit).second.getZSize();
424  distbin::const_iterator distiter = distit;
425  int actualNumFS = 1;
426  int spread = 2; //will calculate average Z for 5 showers max ( -2 .. 0 .. +2 )
427  double upperEnergy = (*distit).first * 1.01; //we allow 1% off
428  for (int i = 0; i < spread; i++) {
429  ++distiter;
430  if (distiter == (*etait).second.end()) {
431  break;
432  }
433  if (upperEnergy < (*distiter).first) break; //energy diff too high
434  //the shower is OK, including it to the average
435  rezZ += (*distiter).second.getZSize();
436  actualNumFS++;
437  }
438  distiter = distit;
439  if (distiter != (*etait).second.begin()) {
440  double lowerEnergy = (*distit).first * 0.99; //we allow 1% off
441  for (int i = 0; i < spread; i++) {
442  --distiter;
443  if (lowerEnergy > (*distiter).first) break; //energy diff too high
444  //the shower is OK, including it to the average
445  rezZ += (*distiter).second.getZSize();
446  actualNumFS++;
447  if (distiter == (*etait).second.begin()) {
448  break;
449  }
450  }
451  }
452  return rezZ/actualNumFS; //average Z size
453  }
454 
456  {
457  if (!m_filled) {
458  std::cout << "Library is not created for production use" << std::endl;
459  return 0;
460  }
461 
462  //std::cout << "Starting getShower()" << std::endl;
463 
464  double x = track->GetPosition().getX();
465  double y = track->GetPosition().getY();
466 
467  float dist = this->distance(x,y);
468  double eta = track->GetPosition().eta();
469  if (eta < 0) {
470  eta = -eta;
471  }
472 
473  G4int particleCode = track->GetDefinition()->GetPDGEncoding();
474  if ( particleCode < 0 ) particleCode = -particleCode; // hack for positrons.
475 
476  if ( particleCode != m_particle ) {
477  std::cout << "wrong particle: " << particleCode << "!=" << m_particle << std::endl;
478  return 0;
479  }
480  if (eta < 3.0) {
481  std::cout << "wrong eta: |eta|=" << eta << " is not inside FCAL" << std::endl;
482  return 0;
483  }
484 
485  library::const_iterator libit = m_libData.upper_bound(eta);
486  if (libit == m_libData.begin()) {
487  //this is really weird
488  std::cout << "Something is wrong with eta: |eta|=" << eta << std::endl;
489  } else {
490  --libit;
491  }
492 
493  etabin::const_iterator etait = (*libit).second.upper_bound(dist);
494  if (etait == (*libit).second.begin()) {
495  //this is really weird
496  std::cout << "Something is wrong with dist: x=" << x << " y=" << y << " dist=" << dist << std::endl;
497  } else {
498  --etait;
499  }
500 
501  //std::cout << "Found eta bin" << std::endl;
502 
503  if ((*etait).second.empty()) {
504  std::cout << "The etabin corresponding to the eta is empty" << std::endl;
505  return 0;
506  }
507  double trenergy = track->GetKineticEnergy();
508  //std::cout << "Energy: " << trenergy << std::endl;
509  distbin::const_iterator distit = (*etait).second.lower_bound(trenergy);
510  if (distit == (*etait).second.end()) --distit; //if it points to the end, repoint it to the last shower in bin
511  else if (distit != (*etait).second.begin()) { //find the closest energy. it's either found item or previous (if there is a previous)
512  distbin::const_iterator distitch = distit;
513  --distitch;
514  if (((*distit).first - trenergy) > (trenergy - (*distitch).first)) { // the closest is the previous
515  --distit;
516  }
517  }
518  //std::cout << "Found closest energy:" << (*etait).first << std::endl;
519  double rezR = (*distit).second.getRSize();
520  distbin::const_iterator distiter = distit;
521  int actualNumFS = 1;
522  int spread = 2; //will calculate average Z for 5 showers max ( -2 .. 0 .. +2 )
523  double upperEnergy = (*distit).first * 1.01; //we allow 1% off
524  for (int i = 0; i < spread; i++) {
525  ++distiter;
526  if (distiter == (*etait).second.end()) {
527  break;
528  }
529  if (upperEnergy < (*distiter).first) break; //energy diff too high
530  //the shower is OK, including it to the average
531  rezR += (*distiter).second.getRSize();
532  actualNumFS++;
533  }
534  distiter = distit;
535  if (distiter != (*etait).second.begin()) {
536  double lowerEnergy = (*distit).first * 0.99; //we allow 1% off
537  for (int i = 0; i < spread; i++) {
538  --distiter;
539  if (lowerEnergy > (*distiter).first) break; //energy diff too high
540  //the shower is OK, including it to the average
541  rezR += (*distiter).second.getRSize();
542  actualNumFS++;
543  if (distiter == (*etait).second.begin()) {
544  break;
545  }
546  }
547  }
548  return rezR/actualNumFS; //average Z size
549  }
550 
552  {
553  if (m_filled) {
554  std::cout << "ERROR: filled" << std::endl;
555  return false;
556  }
557 
558  double x = genParticle->production_vertex()->position().x();
559  double y = genParticle->production_vertex()->position().y();
560 
561  float dist = this->distance(x,y);
562  double eta = genParticle->production_vertex()->position().eta();//momentum().eta();
563  if (eta < 0) {
564  eta = -eta;
565  }
566 
567  if ( genParticle->pdg_id() != m_particle ) {
568  std::cout << "ERROR: wrong pdgcode: " << m_particle << " != " << genParticle->pdg_id() << std::endl;
569  return false;
570  }
571  if (eta < 3.0) {
572  std::cout << "wrong eta: |eta|=" << eta << " is not inside FCAL" << std::endl;
573  return 0;
574  }
575 
576  library::iterator libit = m_libData.upper_bound(eta);
577  if (libit == m_libData.begin()) {
578  //this is really weird
579  std::cout << "Something is wrong with eta: |eta|=" << eta << std::endl;
580  } else {
581  --libit;
582  }
583 
584  etabin::iterator etait = (*libit).second.upper_bound(dist);
585  if (etait == (*libit).second.begin()) {
586  //this is really weird
587  std::cout << "Something is wrong with dist: x=" << x << " y=" << y << " dist=" << dist << std::endl;
588  } else {
589  --etait;
590  }
591  (*etait).second.insert(distbin::value_type(genParticle->momentum().e(),(*shower)));
592  return true;
593  }
594 
596  {
597  if (m_libData.empty()) return false;
598  TParameter<int> ver("version",LIB_VERSION);
599 
600  dest->WriteObject(&ver,"version");
601 
602  TTree TTreeMeta;
603  TTree TTreeLib;
604 
605  write(&TTreeLib);
606  writeMeta(&TTreeMeta);
607 
608  dest->WriteObject(&TTreeLib,"library");
609  dest->WriteObject(&TTreeMeta,"meta");
610 
611  return true;
612  }
613 
614 
616  {
617  /*
618  * Dist Energy library format:
619  * | x | y | z | e | time | - name of branch in TTree
620  * ------------------------------------------------------------------
621  * | xrod cent | yrod cent |step (roddist)| not | not | - library header
622  * | (parameter) | (parameter) | (parameter) | used | used |
623  * ------------------------------------------------------------------
624  * |num of distbin| min eta for | not | not | not | - eta bin header
625  * | in eta bin | cur eta bin | used | used | used |
626  * ------------------------------------------------------------------
627  * |num of showers| min dist for | not | not | not | - dist bin header
628  * | in dist bin | cur dist bin | used | used | used |
629  * ------------------------------------------------------------------
630  * | num of hits |shower r-size |shower z-size | truth | not | - shower header
631  * | in shower |for cont.check|for cont.check| energy | used |
632  * ------------------------------------------------------------------
633  * |x-coord of hit|y-coord of hit|z-coord of hit|dep.energy|hit time| - hit
634  */
635  int nentr = source->GetEntriesFast();
636  if (nentr < 3) return false;
637  Float_t x,y,z,e,time;
638  source->SetBranchAddress("x",&x);
639  source->SetBranchAddress("y",&y);
640  source->SetBranchAddress("z",&z);
641  source->SetBranchAddress("e",&e);
642  source->SetBranchAddress("time",&time);
643  int entr = 0;
644 
645 #ifndef __FSLIB_NO_BACKWARD_COMPAT__
646  if (m_compat == false) {
647 #endif
648  source->GetEntry(entr++);
649  m_xrodcent = x;
650  m_yrodcent = y;
651  m_step = z;
652 #ifndef __FSLIB_NO_BACKWARD_COMPAT__
653  } else {
654  m_xrodcent = -748.12;
655  m_yrodcent = -717.719;
656  m_step = 7.5;
657  }
658 #endif
659 
660 
661  do {
662  //read eta bin header
663  source->GetEntry(entr++); //x - ndistbins, y - min eta in the current eta bin
664  int ndists = (int)(x+0.1); // +0.1 just in case - c++ has low round
665  float curEta = y;
666  etabin * curetabin = &(m_libData[curEta]); //creating a new eta bin
667 
668  for (int i = 0; i < ndists; i++) {
669  source->GetEntry(entr++); //x - nshowers, y - min dist in the current dist bin
670  int nsh = (int)(x+0.1); // +0.1 just in case - c++ has low round
671  float curDist = y;
672  distbin * curbin = &((*curetabin)[curDist]); //creating a new dist bin
673  for(int j = 0; j < nsh; j++) {
674  //read shower header
675  source->GetEntry(entr++); //x - nhits, y - r size, z - z size, e - gen energy
676  int nhits = (int)(x+0.1);
677  float curEnergy = e;
678  Shower * shower = &((*curbin)[curEnergy]);
679  shower->setRSize(y);
680  shower->setZSize(z);
681  for(int k = 0; k < nhits; k++) {
682  source->GetEntry(entr++); //variables mean what the name suggests
683  shower->push_back(new ShowerEnergySpot(G4ThreeVector(x,y,z),e,time));
684  }
685  }
686  }
687  } while (entr < nentr);
688 
689  if (entr != nentr) {
690  return false;
691  }
692 
693  m_filled = true;
694  return true;
695  }
696 
698  {
699  /*
700  * Dist Energy library format:
701  * | x | y | z | e | time | - name of branch in TTree
702  * ------------------------------------------------------------------
703  * | xrod cent | yrod cent |step (roddist)| not | not | - library header
704  * | (parameter) | (parameter) | (parameter) | used | used |
705  * ------------------------------------------------------------------
706  * |num of distbin| min eta for | not | not | not | - eta bin header
707  * | in eta bin | cur eta bin | used | used | used |
708  * ------------------------------------------------------------------
709  * |num of showers| min dist for | not | not | not | - dist bin header
710  * | in dist bin | cur dist bin | used | used | used |
711  * ------------------------------------------------------------------
712  * | num of hits |shower r-size |shower z-size | truth | not | - shower header
713  * | in shower |for cont.check|for cont.check| energy | used |
714  * ------------------------------------------------------------------
715  * |x-coord of hit|y-coord of hit|z-coord of hit|dep.energy|hit time| - hit
716  */
717  Float_t x,y,z,e,time;
718  dest->Branch("x",&x);
719  dest->Branch("y",&y);
720  dest->Branch("z",&z);
721  dest->Branch("e",&e);
722  dest->Branch("time",&time);
723 
724  x = m_xrodcent;
725  y = m_yrodcent;
726  z = m_step;
727  e = 0;
728  time = 0;
729  dest->Fill();
730 
731  library::const_iterator libit;
732  for (libit = m_libData.begin(); libit != m_libData.end(); ++libit) {
733  x = (*libit).second.size();
734  y = (*libit).first;
735  z = 0;
736  e = 0;
737  time = 0;
738  dest->Fill(); //eta bin header
739  etabin::const_iterator etait;
740  for (etait = (*libit).second.begin(); etait != (*libit).second.end(); ++etait) {
741  x = (*etait).second.size();
742  y = (*etait).first;
743  z = 0;
744  e = 0;
745  time = 0;
746  dest->Fill(); //eta bin header
747  distbin::const_iterator distit;
748  for (distit = (*etait).second.begin(); distit != (*etait).second.end(); ++distit) {
749  x = (*distit).second.size();
750  y = (*distit).second.getRSize();
751  z = (*distit).second.getZSize();
752  e = (*distit).first;
753  time = 0;
754  dest->Fill(); //shower header
755  Shower::const_iterator iter;
756  for (iter = (*distit).second.begin(); iter != (*distit).second.end(); ++iter) {
757  x = (*iter)->GetPosition().x();
758  y = (*iter)->GetPosition().y();
759  z = (*iter)->GetPosition().z();
760  e = (*iter)->GetEnergy();
761  time = (*iter)->GetTime();
762  dest->Fill();
763  }
764  }
765  }
766  }
767  //dest->Write();
768  return true;
769  }
770 
772  {
773  std::stringstream ss;
774  ss << std::fixed << std::setprecision(3);
775  ss << "Distance calculator parameters: xrod_cent=" << m_xrodcent << " yrod_cent=" << m_yrodcent << " step=" << m_step;
776  return ss.str();
777  }
778 
779  bool FCALDistEtaEnergyShowerLib::readStructure(std::map<float, std::vector<float> >& structure)
780  {
781  std::map<float, std::vector<float> >::const_iterator iter;
782 
783  for (iter = structure.begin(); iter != structure.end(); ++iter) {
784  m_libData[(*iter).first];
785  std::vector<float>::const_iterator inneriter;
786  for (inneriter = (*iter).second.begin(); inneriter != (*iter).second.end(); ++inneriter) {
787  (m_libData[(*iter).first])[(*inneriter)];
788  }
789  }
790 
791  return true;
792  }
793 
795  {
796  std::map<int, std::string> names;
797  std::map<int, int> sizes;
798  for(library::const_iterator it = m_libData.begin(); it != m_libData.end(); ++it) {
799  for(etabin::const_iterator etait = (*it).second.begin(); etait != (*it).second.end(); ++etait) {
800  sizes[calcKey(it->first, etait->first)]=etait->second.size();
801  float etalow = it->first;
802  float distlow = etait->first;
803  float etahigh;
804  float disthigh;
805  library::const_iterator it_copy = it;
806  ++it_copy;
807  if (it_copy == m_libData.end()) {
808  etahigh = 9.99;
809  } else {
810  etahigh = it_copy->first;
811  }
812  etabin::const_iterator etait_copy = etait;
813  ++etait_copy;
814  if (etait_copy == (*it).second.end()) {
815  disthigh = 4.5;
816  } else {
817  disthigh = etait_copy->first;
818  }
819  std::stringstream ss;
820  ss << std::showpos << std::fixed << std::setprecision(2);
821  ss << "ETA: " << etalow << " .. " << etahigh << " DIST: " << distlow << " .. " << disthigh;
822  names[calcKey(it->first, etait->first)]= ss.str();
823  }
824  }
825  return new ShowerLibStatistics(names, sizes);
826  }
827 
828 } // namespace ShowerLib
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
ShowerLib::Shower::setZSize
void setZSize(const float zsize)
Definition: Shower.h:64
ShowerLib::IShowerLib::m_detector
std::string m_detector
name of the detector
Definition: IShowerLib.h:106
ShowerLib::Shower
Class for shower library shower.
Definition: Shower.h:36
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
ShowerLib::ShowerLibStatistics
Definition: ShowerLibStatistics.h:20
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
EnergySpot
Definition: EnergySpot.h:18
GenVertex.h
ShowerLib::FCALDistEtaEnergyShowerLib::readStructure
bool readStructure(std::map< float, std::vector< float > > &structure)
Definition: FCALDistEtaEnergyShowerLib.cxx:779
ShowerLib::ShowerEnergySpot
Definition: ShowerEnergySpot.h:13
ShowerLib::IShowerLib::m_comment
std::string m_comment
comment
Definition: IShowerLib.h:112
skel.it
it
Definition: skel.GENtoEVGEN.py:423
dq_defect_virtual_defect_validation.d1
d1
Definition: dq_defect_virtual_defect_validation.py:79
ShowerLib::FCALDistEtaEnergyShowerLib::printParameters
virtual const std::string printParameters() const
Definition: FCALDistEtaEnergyShowerLib.cxx:771
perfmonmt-printer.dest
dest
Definition: perfmonmt-printer.py:189
ShowerLib::IShowerLib::m_filled
bool m_filled
is the library read from ROOT or from structure file
Definition: IShowerLib.h:114
trigbs_dumpHLTContentInBS.stats
stats
Definition: trigbs_dumpHLTContentInBS.py:91
ShowerLib::FCALDistEtaEnergyShowerLib::distance
float distance(double x, double y) const
Definition: FCALDistEtaEnergyShowerLib.cxx:39
x
#define x
GenParticle.h
ShowerLib::IShowerLib::writeMeta
bool writeMeta(TTree *dest) const
write metadata to the given TTree
Definition: IShowerLib.cxx:40
ShowerLib::FCALDistEtaEnergyShowerLib::getContainmentZ
virtual double getContainmentZ(const G4Track *track) const
get average length of showers for the given energy
Definition: FCALDistEtaEnergyShowerLib.cxx:359
ShowerLib::FCALDistEtaEnergyShowerLib::distbin
std::map< float, Shower > distbin
Definition: FCALDistEtaEnergyShowerLib.h:101
ShowerLib::FCALDistEtaEnergyShowerLib::m_xrodcent
double m_xrodcent
Definition: FCALDistEtaEnergyShowerLib.h:108
ShowerLib::FCALDistEtaEnergyShowerLib::write
bool write(TTree *dest) const
write library to given TTree
Definition: FCALDistEtaEnergyShowerLib.cxx:697
Pythia8_A14_NNPDF23LO_Var1Down_Common.ver
ver
Definition: Pythia8_A14_NNPDF23LO_Var1Down_Common.py:26
ShowerEnergySpot.h
CaloCondBlobAlgs_fillNoiseFromASCII.inputFile
string inputFile
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:17
ShowerLib::FCALDistEtaEnergyShowerLib::read
bool read(TTree *source)
read library from given TTree
Definition: FCALDistEtaEnergyShowerLib.cxx:615
lumiFormat.i
int i
Definition: lumiFormat.py:92
z
#define z
ShowerLib::FCALDistEtaEnergyShowerLib::createEmptyLib
static IShowerLib * createEmptyLib(const std::string &inputFile)
factory method. create empty library with the given structure. returns NULL if file is invalid.
Definition: FCALDistEtaEnergyShowerLib.cxx:94
ShowerLib::IShowerLib::m_particle
int m_particle
ID of the generated particles.
Definition: IShowerLib.h:107
python.subdetectors.mmg.names
names
Definition: mmg.py:8
ShowerLib::FCALDistEtaEnergyShowerLib::storeShower
virtual bool storeShower(HepMC::ConstGenParticlePtr genParticle, const Shower *shower)
store shower in the library
Definition: FCALDistEtaEnergyShowerLib.cxx:551
WritePulseShapeToCool.det
det
Definition: WritePulseShapeToCool.py:204
ShowerLib::FCALDistEtaEnergyShowerLib::m_yrodcent
double m_yrodcent
Definition: FCALDistEtaEnergyShowerLib.h:109
ShowerLib::FCALDistEtaEnergyShowerLib::m_compat
bool m_compat
Definition: FCALDistEtaEnergyShowerLib.h:113
ShowerLib::IShowerLib
Class for shower library shower lib interface.
Definition: IShowerLib.h:40
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
ShowerLib::FCALDistEtaEnergyShowerLib::m_libData
library m_libData
Definition: FCALDistEtaEnergyShowerLib.h:105
ShowerLib::IShowerLib::readMeta
bool readMeta(TTree *source)
read metadata from the given TTree
Definition: IShowerLib.cxx:16
ShowerLib::FCALDistEtaEnergyShowerLib::etabin
std::map< float, distbin > etabin
Definition: FCALDistEtaEnergyShowerLib.h:102
ShowerLib::FCALDistEtaEnergyShowerLib::m_step
double m_step
Definition: FCALDistEtaEnergyShowerLib.h:110
ShowerLib::FCALDistEtaEnergyShowerLib::FCALDistEtaEnergyShowerLib
FCALDistEtaEnergyShowerLib()
Definition: FCALDistEtaEnergyShowerLib.h:84
ShowerLib::FCALDistEtaEnergyShowerLib::readFromROOTFile
static IShowerLib * readFromROOTFile(TFile *source)
factory method. create a library from root file. returns NULL if file is invalid.
Definition: FCALDistEtaEnergyShowerLib.cxx:56
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
ShowerLib::FCALDistEtaEnergyShowerLib::writeToROOT
virtual bool writeToROOT(TFile *dest)
write library to ROOT file
Definition: FCALDistEtaEnergyShowerLib.cxx:595
library_scraper.dd
list dd
Definition: library_scraper.py:46
ShowerLib::FCALDistEtaEnergyShowerLib::getShower
virtual std::vector< EnergySpot > * getShower(const G4Track *track, ShowerLibStatistics *stats, int randomShift) const
get shower for given G4 track
Definition: FCALDistEtaEnergyShowerLib.cxx:247
LIB_VERSION
#define LIB_VERSION
Definition: FCALDistEtaEnergyShowerLib.cxx:28
EnergySpot.h
ShowerLib::FCALDistEtaEnergyShowerLib
Class for shower library shower lib.
Definition: FCALDistEtaEnergyShowerLib.h:35
makeTRTBarrelCans.dy
tuple dy
Definition: makeTRTBarrelCans.py:21
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
y
#define y
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
ShowerLib::Shower::setRSize
void setRSize(const float rsize)
Definition: Shower.h:65
dq_defect_virtual_defect_validation.d2
d2
Definition: dq_defect_virtual_defect_validation.py:81
ShowerLib::FCALDistEtaEnergyShowerLib::getContainmentR
virtual double getContainmentR(const G4Track *track) const
get average lateral spread of the showers for the given energy
Definition: FCALDistEtaEnergyShowerLib.cxx:455
ShowerLib::FCALDistEtaEnergyShowerLib::createStatistics
virtual ShowerLibStatistics * createStatistics() const
Definition: FCALDistEtaEnergyShowerLib.cxx:794
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
FCALDistEtaEnergyShowerLib.h
LArCellBinning.step
step
Definition: LArCellBinning.py:158
ShowerLib
Namespace for the ShowerLib related classes.
Definition: LArG4GenShowerLib.h:19
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
ShowerLib::calcKey
int calcKey(float eta)
Definition: EtaEnergyShowerLib.cxx:32
LIB_VERSION_OLD
#define LIB_VERSION_OLD
Definition: FCALDistEtaEnergyShowerLib.cxx:30
fitman.k
k
Definition: fitman.py:528