CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HcalTestAnalysis.cc
Go to the documentation of this file.
6 
7 // to retreive hits
12 
15 
19 
25 
26 #include "G4SDManager.hh"
27 #include "G4Step.hh"
28 #include "G4Track.hh"
29 #include "G4VProcess.hh"
30 #include "G4HCofThisEvent.hh"
31 
32 #include <CLHEP/Random/Randomize.h>
33 #include <CLHEP/Units/GlobalSystemOfUnits.h>
34 #include <CLHEP/Units/GlobalPhysicalConstants.h>
35 
36 #include <cmath>
37 #include <iomanip>
38 #include <iostream>
39 #include <string>
40 #include <vector>
41 
43  public Observer<const BeginOfRun*>,
44  public Observer<const BeginOfEvent*>,
45  public Observer<const EndOfEvent*>,
46  public Observer<const G4Step*> {
47 public:
49  ~HcalTestAnalysis() override;
50 
52  void produce(edm::Event&, const edm::EventSetup&) override;
53  void beginRun(edm::EventSetup const&) override;
54 
55 private:
56  // observer classes
57  void update(const BeginOfRun* run) override;
58  void update(const BeginOfEvent* evt) override;
59  void update(const EndOfEvent* evt) override;
60  void update(const G4Step* step) override;
61 
62  // analysis-related stuff
63  std::vector<int> layerGrouping(int);
64  std::vector<int> towersToAdd(int centre, int nadd);
65  void fill(const EndOfEvent* ev);
66  void qieAnalysis(CLHEP::HepRandomEngine*);
67  void layerAnalysis();
68  double timeOfFlight(int det, int layer, double eta);
69 
70 private:
71  //Keep parameters to instantiate HcalTestHistoClass later
73 
74  // Qie Analysis
75  std::unique_ptr<HcalQie> myqie_;
76  int addTower_;
77 
78  // Private Tuples
79  std::unique_ptr<HcalTestHistoClass> tuples_;
80 
81  // Numbering scheme
83  std::unique_ptr<HcalNumberingFromDDD> numberingFromDDD_;
85  std::unique_ptr<HcalTestNumberingScheme> org_;
86 
87  // Hits for qie analysis
88  std::vector<CaloHit> caloHitCache_;
89  std::vector<int> group_, tower_;
91 
92  // to read from ParameterSet
93  std::vector<std::string> names_;
94  double eta0_, phi0_;
96 
97  // some private members for ananlysis
98  unsigned int count_;
100  double edepHO_, edepl_[20];
101  double mudist_[20]; // Distance of muon from central part
102 };
103 
104 HcalTestAnalysis::HcalTestAnalysis(const edm::ParameterSet& p) : addTower_(3), hcons_(nullptr) {
105  org_.reset(nullptr);
106  edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("HcalTestAnalysis");
107  eta0_ = m_Anal.getParameter<double>("Eta0");
108  phi0_ = m_Anal.getParameter<double>("Phi0");
109  int laygroup = m_Anal.getParameter<int>("LayerGrouping");
110  centralTower_ = m_Anal.getParameter<int>("CentralTower");
111  names_ = m_Anal.getParameter<std::vector<std::string> >("Names");
112  fileName_ = m_Anal.getParameter<std::string>("FileName");
113 
114  tuples_.reset(nullptr);
115  numberingFromDDD_.reset(nullptr);
116  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis:: Initialised as observer of begin/end events"
117  << " and of G4step";
118 
119  count_ = 0;
120  group_ = layerGrouping(laygroup);
121  nGroup_ = 0;
122  for (unsigned int i = 0; i < group_.size(); i++)
123  if (group_[i] > nGroup_)
124  nGroup_ = group_[i];
125  tower_ = towersToAdd(centralTower_, addTower_);
126  nTower_ = tower_.size() / 2;
127 
128  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis:: initialised for " << nGroup_ << " Longitudinal groups and "
129  << nTower_ << " towers";
130 
131  // qie
132  myqie_ = std::make_unique<HcalQie>(p);
133 
134  produces<HcalTestHistoClass>();
135 }
136 
138  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis: --------> Total number of selected entries : " << count_;
139  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis: Pointers:: Numbering Scheme " << org_.get();
140 }
141 
144  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis::Initialize ESGetToken for HcalDDDSimConstants";
145 }
146 
148  e.put(std::move(tuples_));
149  tuples_.reset(nullptr);
150 }
151 
152 std::vector<int> HcalTestAnalysis::layerGrouping(int group) {
153  std::vector<int> temp(19);
154  if (group <= 1) {
155  int grp[19] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
156  for (int i = 0; i < 19; i++)
157  temp[i] = grp[i];
158  } else if (group == 2) {
159  int grp[19] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
160  for (int i = 0; i < 19; i++)
161  temp[i] = grp[i];
162  } else if (group == 3) {
163  int grp[19] = {1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7};
164  for (int i = 0; i < 19; i++)
165  temp[i] = grp[i];
166  } else if (group == 4) {
167  int grp[19] = {1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7};
168  for (int i = 0; i < 19; i++)
169  temp[i] = grp[i];
170  } else {
171  int grp[19] = {1, 1, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7};
172  for (int i = 0; i < 19; i++)
173  temp[i] = grp[i];
174  }
175 
176  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis:: Layer Grouping ";
177  for (int i = 0; i < 19; i++)
178  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis: Group[" << i << "] = " << temp[i];
179  return temp;
180 }
181 
182 std::vector<int> HcalTestAnalysis::towersToAdd(int centre, int nadd) {
183  int etac = (centre / 100) % 100;
184  int phic = (centre % 100);
185  int etamin, etamax, phimin, phimax;
186  if (etac > 0) {
187  etamin = etac - nadd;
188  etamax = etac + nadd;
189  } else {
190  etamin = etac;
191  etamax = etac;
192  }
193  if (phic > 0) {
194  phimin = phic - nadd;
195  phimax = phic + nadd;
196  } else {
197  phimin = phic;
198  phimax = phic;
199  }
200 
201  int nbuf, kount = 0;
202  nbuf = (etamax - etamin + 1) * (phimax - phimin + 1);
203  std::vector<int> temp(2 * nbuf);
204  for (int eta = etamin; eta <= etamax; eta++) {
205  for (int phi = phimin; phi <= phimax; phi++) {
206  temp[kount] = (eta * 100 + phi);
207  temp[kount + nbuf] = std::max(abs(eta - etac), abs(phi - phic));
208  kount++;
209  }
210  }
211 
212  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis:: Towers to be considered for Central " << centre << " and " << nadd
213  << " on either side";
214  for (int i = 0; i < nbuf; i++)
215  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis: Tower[" << std::setw(3) << i << "] " << temp[i] << " "
216  << temp[nbuf + i];
217  return temp;
218 }
219 
220 //==================================================================== per JOB
221 
223  // Numbering From DDD
224  hcons_ = &es.getData(ddconsToken_);
225  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis:: Initialise HcalNumberingFromDDD for " << names_[0];
226  numberingFromDDD_ = std::make_unique<HcalNumberingFromDDD>(hcons_);
227 
228  // Numbering scheme
229  org_ = std::make_unique<HcalTestNumberingScheme>(false);
230 }
231 
232 //==================================================================== per RUN
234  int irun = (*run)()->GetRunID();
235  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis:: Begin of Run = " << irun;
236 
237  bool loop = true, eta = true, phi = true;
238  int etac = (centralTower_ / 100) % 100;
239  if (etac == 0) {
240  etac = 1;
241  eta = false;
242  }
243  int phic = (centralTower_ % 100);
244  if (phic == 0) {
245  phic = 1;
246  phi = false;
247  }
248  int idet = static_cast<int>(HcalBarrel);
249  while (loop) {
250  HcalCellType::HcalCell tmp = hcons_->cell(idet, 1, 1, etac, phic);
251  if (tmp.ok) {
252  if (eta)
253  eta0_ = tmp.eta;
254  if (phi)
255  phi0_ = tmp.phi;
256  loop = false;
257  } else if (idet == static_cast<int>(HcalBarrel)) {
258  idet = static_cast<int>(HcalEndcap);
259  } else if (idet == static_cast<int>(HcalEndcap)) {
260  idet = static_cast<int>(HcalForward);
261  } else {
262  loop = false;
263  }
264  }
265 
266  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis:: Central Tower " << centralTower_
267  << " corresponds to eta0 = " << eta0_ << " phi0 = " << phi0_;
268 
269  std::string sdname = names_[0];
270  G4SDManager* sd = G4SDManager::GetSDMpointerIfExist();
271  if (sd != nullptr) {
272  G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(sdname);
273  if (aSD == nullptr) {
274  edm::LogWarning("HcalSim") << "HcalTestAnalysis::beginOfRun: No SD with "
275  << "name " << sdname << " in this Setup";
276  } else {
277  HCalSD* theCaloSD = dynamic_cast<HCalSD*>(aSD);
278  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis::beginOfRun: Finds SD with name " << theCaloSD->GetName()
279  << " in this Setup";
280  if (org_.get()) {
281  theCaloSD->setNumberingScheme(org_.get());
282  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis::beginOfRun: set a new numbering scheme";
283  }
284  }
285  } else {
286  edm::LogWarning("HcalSim") << "HcalTestAnalysis::beginOfRun: Could not get"
287  << " SD Manager!";
288  }
289 }
290 
291 //=================================================================== per EVENT
293  // create tuple object
294  tuples_ = std::make_unique<HcalTestHistoClass>();
295  // Reset counters
296  tuples_->setCounters();
297 
298  int i = 0;
299  edepEB_ = edepEE_ = edepHB_ = edepHE_ = edepHO_ = 0.;
300  for (i = 0; i < 20; i++)
301  edepl_[i] = 0.;
302  for (i = 0; i < 20; i++)
303  mudist_[i] = -1.;
304 
305  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis: Begin of event = " << (*evt)()->GetEventID();
306 }
307 
308 //=================================================================== each STEP
309 void HcalTestAnalysis::update(const G4Step* aStep) {
310  if (aStep != nullptr) {
311  G4VPhysicalVolume* curPV = aStep->GetPreStepPoint()->GetPhysicalVolume();
312  G4String name = curPV->GetName();
313  name.assign(name, 0, 3);
314  double edeposit = aStep->GetTotalEnergyDeposit();
315  int layer = -1;
316  if (name == "EBR") {
317  edepEB_ += edeposit;
318  } else if (name == "EFR") {
319  edepEE_ += edeposit;
320  } else if (name == "HBS") {
321  layer = (curPV->GetCopyNo() / 10) % 100;
322  if (layer >= 0 && layer < 17) {
323  edepHB_ += edeposit;
324  } else {
325  edm::LogWarning("HcalSim") << "HcalTestAnalysis::Error in HB " << curPV->GetName() << curPV->GetCopyNo();
326  layer = -1;
327  }
328  } else if (name == "HES") {
329  layer = (curPV->GetCopyNo() / 10) % 100;
330  if (layer >= 0 && layer < 19) {
331  edepHE_ += edeposit;
332  } else {
333  edm::LogWarning("HcalSim") << "HcalTestAnalysis::Error in HE " << curPV->GetName() << curPV->GetCopyNo();
334  layer = -1;
335  }
336  } else if (name == "HTS") {
337  layer = (curPV->GetCopyNo() / 10) % 100;
338  if (layer >= 17 && layer < 20) {
339  edepHO_ += edeposit;
340  } else {
341  edm::LogWarning("HcalSim") << "HcalTestAnalysis::Error in HO " << curPV->GetName() << curPV->GetCopyNo();
342  layer = -1;
343  }
344  }
345  if (layer >= 0 && layer < 20) {
346  edepl_[layer] += edeposit;
347 
348  // Calculate the distance if it is a muon
349  G4String part = aStep->GetTrack()->GetDefinition()->GetParticleName();
350  if ((part == "mu-" || part == "mu+") && mudist_[layer] < 0) {
351  math::XYZPoint pos(aStep->GetPreStepPoint()->GetPosition().x(),
352  aStep->GetPreStepPoint()->GetPosition().y(),
353  aStep->GetPreStepPoint()->GetPosition().z());
354  double theta = pos.theta();
355  double eta = -log(tan(theta * 0.5));
356  double phi = pos.phi();
357  double dist = sqrt((eta - eta0_) * (eta - eta0_) + (phi - phi0_) * (phi - phi0_));
358  mudist_[layer] = dist * std::sqrt(pos.perp2());
359  }
360  }
361 
362  if (layer >= 0 && layer < 20) {
363  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis:: G4Step: " << name << " Layer " << std::setw(3) << layer
364  << " Edep " << std::setw(6) << edeposit / MeV << " MeV";
365  }
366  } else {
367  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis:: G4Step: Null Step";
368  }
369 }
370 
371 //================================================================ End of EVENT
373  ++count_;
374  // Fill event input
375  fill(evt);
376  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis:: --- after Fill";
377 
378  // Qie analysis
379  CLHEP::HepRandomEngine* engine = G4Random::getTheEngine();
380  qieAnalysis(engine);
381  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis:: --- after QieAnalysis";
382 
383  // Layers tuples filling
384  layerAnalysis();
385  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis:: --- after LayerAnalysis";
386 }
387 
388 //---------------------------------------------------
390  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis: Fill event " << (*evt)()->GetEventID();
391 
392  // access to the G4 hit collections
393  G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
394 
395  int nhc = 0, neb = 0, nef = 0, j = 0;
396  caloHitCache_.erase(caloHitCache_.begin(), caloHitCache_.end());
397 
398  // Hcal
399  int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(names_[0]);
400  CaloG4HitCollection* theHCHC = (CaloG4HitCollection*)allHC->GetHC(HCHCid);
401  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis :: Hit Collection for " << names_[0] << " of ID " << HCHCid
402  << " is obtained at " << theHCHC;
403  int hchc_entries = theHCHC->entries();
404  if (HCHCid >= 0 && theHCHC != nullptr) {
405  for (j = 0; j < hchc_entries; j++) {
406  CaloG4Hit* aHit = (*theHCHC)[j];
407 
408  double e = aHit->getEnergyDeposit() / GeV;
409  double time = aHit->getTimeSlice();
410 
411  math::XYZPoint pos = aHit->getPosition();
412  double theta = pos.theta();
413  double eta = -log(tan(theta * 0.5));
414  double phi = pos.phi();
415 
416  uint32_t unitID = aHit->getUnitID();
417  int subdet, zside, layer, etaIndex, phiIndex, lay;
418  org_->unpackHcalIndex(unitID, subdet, zside, layer, etaIndex, phiIndex, lay);
419  double jitter = time - timeOfFlight(subdet, lay, eta);
420  if (jitter < 0)
421  jitter = 0;
422  CaloHit hit(subdet, lay, e, eta, phi, jitter, unitID);
423  caloHitCache_.push_back(hit);
424  nhc++;
425 
426  std::string det = "HB";
427  if (subdet == static_cast<int>(HcalForward)) {
428  det = "HF";
429  } else if (subdet == static_cast<int>(HcalEndcap)) {
430  if (etaIndex <= 20) {
431  det = "HES";
432  } else {
433  det = "HED";
434  }
435  }
436 
437  edm::LogVerbatim("HcalSim") << "HcalTest: " << det << " layer " << std::setw(2) << layer << " time "
438  << std::setw(6) << time << " theta " << std::setw(8) << theta << " eta "
439  << std::setw(8) << eta << " phi " << std::setw(8) << phi << " e " << std::setw(8)
440  << e;
441  }
442  }
443  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis::HCAL hits : " << nhc;
444 
445  // EB
446  int EBHCid = G4SDManager::GetSDMpointer()->GetCollectionID(names_[1]);
447  CaloG4HitCollection* theEBHC = (CaloG4HitCollection*)allHC->GetHC(EBHCid);
448  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis :: Hit Collection for " << names_[1] << " of ID " << EBHCid
449  << " is obtained at " << theEBHC;
450  int ebhc_entries = theEBHC->entries();
451  if (EBHCid >= 0 && theEBHC != nullptr) {
452  for (j = 0; j < ebhc_entries; j++) {
453  CaloG4Hit* aHit = (*theEBHC)[j];
454 
455  double e = aHit->getEnergyDeposit() / GeV;
456  double time = aHit->getTimeSlice();
457  std::string det = "EB";
458 
459  math::XYZPoint pos = aHit->getPosition();
460  double theta = pos.theta();
461  double eta = -log(tan(theta / 2.));
462  double phi = pos.phi();
463 
464  HcalNumberingFromDDD::HcalID id = numberingFromDDD_->unitID(eta, phi, 1, 1);
465  uint32_t unitID = org_->getUnitID(id);
466  int subdet, zside, layer, ieta, iphi, lay;
467  org_->unpackHcalIndex(unitID, subdet, zside, layer, ieta, iphi, lay);
468  subdet = 10;
469  layer = 0;
470  unitID = org_->packHcalIndex(subdet, zside, layer, ieta, iphi, lay);
471  CaloHit hit(subdet, lay, e, eta, phi, time, unitID);
472  caloHitCache_.push_back(hit);
473  neb++;
474  edm::LogVerbatim("HcalSim") << "HcalTest: " << det << " layer " << std::setw(2) << layer << " time "
475  << std::setw(6) << time << " theta " << std::setw(8) << theta << " eta "
476  << std::setw(8) << eta << " phi " << std::setw(8) << phi << " e " << std::setw(8)
477  << e;
478  }
479  }
480  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis::EB hits : " << neb;
481 
482  // EE
483  int EEHCid = G4SDManager::GetSDMpointer()->GetCollectionID(names_[2]);
484  CaloG4HitCollection* theEEHC = (CaloG4HitCollection*)allHC->GetHC(EEHCid);
485  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis :: Hit Collection for " << names_[2] << " of ID " << EEHCid
486  << " is obtained at " << theEEHC;
487  int eehc_entries = theEEHC->entries();
488  if (EEHCid >= 0 && theEEHC != nullptr) {
489  for (j = 0; j < eehc_entries; j++) {
490  CaloG4Hit* aHit = (*theEEHC)[j];
491 
492  double e = aHit->getEnergyDeposit() / GeV;
493  double time = aHit->getTimeSlice();
494  std::string det = "EE";
495 
496  math::XYZPoint pos = aHit->getPosition();
497  double theta = pos.theta();
498  double eta = -log(tan(theta / 2.));
499  double phi = pos.phi();
500 
501  HcalNumberingFromDDD::HcalID id = numberingFromDDD_->unitID(eta, phi, 1, 1);
502  uint32_t unitID = org_->getUnitID(id);
503  int subdet, zside, layer, ieta, iphi, lay;
504  org_->unpackHcalIndex(unitID, subdet, zside, layer, ieta, iphi, lay);
505  subdet = 11;
506  layer = 0;
507  unitID = org_->packHcalIndex(subdet, zside, layer, ieta, iphi, lay);
508  CaloHit hit(subdet, lay, e, eta, phi, time, unitID);
509  caloHitCache_.push_back(hit);
510  nef++;
511  edm::LogVerbatim("HcalSim") << "HcalTest: " << det << " layer " << std::setw(2) << layer << " time "
512  << std::setw(6) << time << " theta " << std::setw(8) << theta << " eta "
513  << std::setw(8) << eta << " phi " << std::setw(8) << phi << " e " << std::setw(8)
514  << e;
515  }
516  }
517  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis::EE hits : " << nef;
518 }
519 
520 //-----------------------------------------------------------------------------
521 void HcalTestAnalysis::qieAnalysis(CLHEP::HepRandomEngine* engine) {
522  //Fill tuple with hit information
523  int hittot = caloHitCache_.size();
524  tuples_->fillHits(caloHitCache_);
525 
526  //Get the index of the central tower
528  uint32_t unitID = org_->getUnitID(id);
529  int subdet, zside, layer, ieta, iphi, lay;
530  org_->unpackHcalIndex(unitID, subdet, zside, layer, ieta, iphi, lay);
531  int laymax = 0;
532  std::string det = "Unknown";
533  if (subdet == static_cast<int>(HcalBarrel)) {
534  laymax = 4;
535  det = "HB";
536  } else if (subdet == static_cast<int>(HcalEndcap)) {
537  laymax = 2;
538  det = "HES";
539  }
540  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis::Qie: " << det << " Eta " << ieta << " Phi " << iphi << " Laymax "
541  << laymax << " Hits " << hittot;
542 
543  if (laymax > 0 && hittot > 0) {
544  std::vector<CaloHit> hits(hittot);
545  std::vector<double> eqielay(80, 0.0), esimlay(80, 0.0), esimtot(4, 0.0);
546  std::vector<double> eqietow(200, 0.0), esimtow(200, 0.0), eqietot(4, 0.0);
547  int etac = (centralTower_ / 100) % 100;
548  int phic = (centralTower_ % 100);
549 
550  for (int layr = 0; layr < nGroup_; layr++) {
551  /*
552  int layx, layy=20;
553  for (int i=0; i<20; i++)
554  if (group_[i] == layr+1 && i < layy) layy = i+1;
555  if (subdet == static_cast<int>(HcalBarrel)) {
556  if (layy < 2) layx = 0;
557  else if (layy < 17) layx = 1;
558  else if (layy == 17) layx = 2;
559  else layx = 3;
560  } else {
561  if (layy < 2) layx = 0;
562  else layx = 1;
563  }
564  */
565  for (int it = 0; it < nTower_; it++) {
566  int nhit = 0;
567  double esim = 0;
568  for (int k1 = 0; k1 < hittot; k1++) {
569  CaloHit hit = caloHitCache_[k1];
570  int subdetc = hit.det();
571  int layer = hit.layer();
572  int group = 0;
573  if (layer > 0 && layer < 20)
574  group = group_[layer];
575  if (subdetc == subdet && group == layr + 1) {
576  int zsidec, ietac, iphic, idx;
577  unitID = hit.id();
578  org_->unpackHcalIndex(unitID, subdetc, zsidec, layer, ietac, iphic, lay);
579  if (etac > 0 && phic > 0) {
580  idx = ietac * 100 + iphic;
581  } else if (etac > 0) {
582  idx = ietac * 100;
583  } else if (phic > 0) {
584  idx = iphic;
585  } else {
586  idx = 0;
587  }
588  if (zsidec == zside && idx == tower_[it]) {
589  hits[nhit] = hit;
590  edm::LogVerbatim("HcalSim") << "HcalTest: Hit " << nhit << " " << hit;
591  nhit++;
592  esim += hit.e();
593  }
594  }
595  }
596 
597  std::vector<int> cd = myqie_->getCode(nhit, hits, engine);
598  double eqie = myqie_->getEnergy(cd);
599 
600  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis::Qie: Energy in layer " << layr << " Sim " << esim
601  << " After QIE " << eqie;
602  for (int i = 0; i < 4; i++) {
603  if (tower_[nTower_ + it] <= i) {
604  esimtot[i] += esim;
605  eqietot[i] += eqie;
606  esimlay[20 * i + layr] += esim;
607  eqielay[20 * i + layr] += eqie;
608  esimtow[50 * i + it] += esim;
609  eqietow[50 * i + it] += eqie;
610  }
611  }
612  }
613  }
614  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis::Qie: Total energy " << esimtot[3] << " (SimHit) " << eqietot[3]
615  << " (After QIE)";
616 
617  std::vector<double> latphi(10);
618  int nt = 2 * addTower_ + 1;
619  for (int it = 0; it < nt; it++)
620  latphi[it] = it - addTower_;
621  for (int i = 0; i < 4; i++) {
622  double scals = 1, scalq = 1;
623  std::vector<double> latfs(10, 0.), latfq(10, 0.), longs(20), longq(20);
624  if (esimtot[i] > 0)
625  scals = 1. / esimtot[i];
626  if (eqietot[i] > 0)
627  scalq = 1. / eqietot[i];
628  for (int it = 0; it < nTower_; it++) {
629  int phib = it % nt;
630  latfs[phib] += scals * esimtow[50 * i + it];
631  latfq[phib] += scalq * eqietow[50 * i + it];
632  }
633  for (int layr = 0; layr <= nGroup_; layr++) {
634  longs[layr] = scals * esimlay[20 * i + layr];
635  longq[layr] = scalq * eqielay[20 * i + layr];
636  }
637  tuples_->fillQie(i, esimtot[i], eqietot[i], nGroup_, longs, longq, nt, latphi, latfs, latfq);
638  }
639  }
640 }
641 
642 //---------------------------------------------------
644  int i = 0;
645  edm::LogVerbatim("HcalSim") << "\n ===>>> HcalTestAnalysis: Energy deposit "
646  << "\n at EB : " << std::setw(6) << edepEB_ / MeV << "\n at EE : " << std::setw(6)
647  << edepEE_ / MeV << "\n at HB : " << std::setw(6) << edepHB_ / MeV
648  << "\n at HE : " << std::setw(6) << edepHE_ / MeV << "\n at HO : " << std::setw(6)
649  << edepHO_ / MeV << "\n ---- HcalTestAnalysis: Energy deposit in Layers";
650  for (i = 0; i < 20; i++)
651  edm::LogVerbatim("HcalSim") << " Layer " << std::setw(2) << i << " E " << std::setw(8) << edepl_[i] / MeV << " MeV";
652 
653  tuples_->fillLayers(edepl_, edepHO_, edepHB_ + edepHE_, mudist_);
654 }
655 
656 //---------------------------------------------------
657 double HcalTestAnalysis::timeOfFlight(int det, int layer, double eta) {
658  double theta = 2.0 * atan(exp(-eta));
659  double dist = 0.;
660  if (det == static_cast<int>(HcalBarrel)) {
661  const double rLay[19] = {1836.0,
662  1902.0,
663  1962.0,
664  2022.0,
665  2082.0,
666  2142.0,
667  2202.0,
668  2262.0,
669  2322.0,
670  2382.0,
671  2448.0,
672  2514.0,
673  2580.0,
674  2646.0,
675  2712.0,
676  2776.0,
677  2862.5,
678  3847.0,
679  4052.0};
680  if (layer > 0 && layer < 20)
681  dist += rLay[layer - 1] * mm / sin(theta);
682  } else {
683  const double zLay[19] = {4034.0,
684  4032.0,
685  4123.0,
686  4210.0,
687  4297.0,
688  4384.0,
689  4471.0,
690  4558.0,
691  4645.0,
692  4732.0,
693  4819.0,
694  4906.0,
695  4993.0,
696  5080.0,
697  5167.0,
698  5254.0,
699  5341.0,
700  5428.0,
701  5515.0};
702  if (layer > 0 && layer < 20)
703  dist += zLay[layer - 1] * mm / cos(theta);
704  }
705  double tmp = dist / c_light / ns;
706  edm::LogVerbatim("HcalSim") << "HcalTestAnalysis::timeOfFlight " << tmp << " for det/lay " << det << " " << layer
707  << " eta/theta " << eta << " " << theta / deg << " dist " << dist;
708  return tmp;
709 }
710 
713 
Log< level::Info, true > LogVerbatim
#define DEFINE_SIMWATCHER(type)
math::XYZPoint getPosition() const
Definition: CaloG4Hit.h:52
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const double GeV
Definition: MathUtil.h:16
static std::vector< std::string > checklist log
int det() const
Definition: CaloHit.h:19
std::unique_ptr< HcalTestHistoClass > tuples_
std::vector< int > layerGrouping(int)
std::unique_ptr< HcalNumberingFromDDD > numberingFromDDD_
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
std::vector< std::string > names_
bool ev
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
int zside(DetId const &)
void beginRun(edm::EventSetup const &) override
HcalCellType::HcalCell cell(const int &det, const int &zside, const int &depth, const int &etaR, const int &iphi) const
void setNumberingScheme(HcalNumberingScheme *)
Definition: HCalSD.cc:544
std::vector< int > towersToAdd(int centre, int nadd)
constexpr std::array< uint8_t, layerIndexSize > layer
void produce(edm::Event &, const edm::EventSetup &) override
bool getData(T &iHolder) const
Definition: EventSetup.h:128
const double MeV
double timeOfFlight(int det, int layer, double eta)
Definition: HCalSD.h:38
uint32_t id() const
Definition: CaloHit.h:25
void fill(const EndOfEvent *ev)
std::vector< int > tower_
HcalTestAnalysis(const edm::ParameterSet &p)
T sqrt(T t)
Definition: SSEVec.h:19
const HcalDDDSimConstants * hcons_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
def move
Definition: eostools.py:511
unsigned int count_
~HcalTestAnalysis() override
std::unique_ptr< HcalQie > myqie_
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
int layer() const
Definition: CaloHit.h:20
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int nt
Definition: AMPTWrapper.h:42
tuple group
Definition: watchdog.py:82
void registerConsumes(edm::ConsumesCollector) override
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
double sd
std::unique_ptr< HcalTestNumberingScheme > org_
part
Definition: HCALResponse.h:20
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
double e() const
Definition: CaloHit.h:21
std::vector< CaloHit > caloHitCache_
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
std::string fileName_
double getTimeSlice() const
Definition: CaloG4Hit.h:67
edm::ESGetToken< HcalDDDSimConstants, HcalSimNumberingRecord > ddconsToken_
step
Definition: StallMonitor.cc:94
void update(const BeginOfRun *run) override
This routine will be called when the appropriate signal arrives.
void qieAnalysis(CLHEP::HepRandomEngine *)
uint32_t getUnitID() const
Definition: CaloG4Hit.h:66
Log< level::Warning, false > LogWarning
tmp
align.sh
Definition: createJobs.py:716
std::vector< int > group_
double getEnergyDeposit() const
Definition: CaloG4Hit.h:79