CMS 3D CMS Logo

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