CMS 3D CMS Logo

SimG4HcalValidation.cc
Go to the documentation of this file.
1 // File: SimG4Validation.cc
3 // Description: Main analysis class for Hcal Validation of G4 Hits
11 
12 // to retreive hits
18 
23 
28 
32 
35 
36 #include <CLHEP/Units/SystemOfUnits.h>
37 
38 #include "G4HCofThisEvent.hh"
39 #include "G4SDManager.hh"
40 #include "G4Step.hh"
41 #include "G4Track.hh"
42 #include "G4VProcess.hh"
43 
44 #include <iostream>
45 #include <memory>
46 #include <string>
47 #include <vector>
48 
49 using namespace geant_units::operators;
50 using CLHEP::GeV;
51 using CLHEP::MeV;
52 
54  public Observer<const BeginOfRun *>,
55  public Observer<const BeginOfEvent *>,
56  public Observer<const EndOfEvent *>,
57  public Observer<const G4Step *> {
58 public:
60  SimG4HcalValidation(const SimG4HcalValidation &) = delete; // stop default
61  const SimG4HcalValidation &operator=(const SimG4HcalValidation &) = delete;
62  ~SimG4HcalValidation() override;
63 
64  void registerConsumes(edm::ConsumesCollector) override;
65  void produce(edm::Event &, const edm::EventSetup &) override;
66  void beginRun(edm::EventSetup const &) override;
67 
68 private:
69  void init();
70 
71  // observer classes
72  void update(const BeginOfRun *run) override;
73  void update(const BeginOfEvent *evt) override;
74  void update(const G4Step *step) override;
75  void update(const EndOfEvent *evt) override;
76 
77  // jetfinding and analysis-related stuff
78  void fill(const EndOfEvent *ev);
79  void layerAnalysis(PHcalValidInfoLayer &);
80  void nxNAnalysis(PHcalValidInfoNxN &);
82  void fetchHits(PHcalValidInfoLayer &);
83  void clear();
84  void collectEnergyRdir(const double, const double);
85  double getHcalScale(std::string, int) const;
86 
87 private:
89 
90  // Keep parameters to instantiate Jet finder later
91  std::unique_ptr<SimG4HcalHitJetFinder> jetf;
92 
93  // Keep reference to instantiate HcalNumberingFromDDD later
94  std::unique_ptr<HcalNumberingFromDDD> numberingFromDDD;
95 
96  // Keep parameters to instantiate HcalTestNumberingScheme later
97  std::unique_ptr<HcalTestNumberingScheme> org;
98 
99  // Hit cache for cluster analysis
100  std::vector<CaloHit> hitcache; // e, eta, phi, time, layer, calo type
101 
102  // scale factors :
103  std::vector<float> scaleHB;
104  std::vector<float> scaleHE;
105  std::vector<float> scaleHF;
106 
107  // to read from parameter set
108  std::vector<std::string> names;
109  double coneSize, ehitThreshold, hhitThreshold;
110  float timeLowlim, timeUplim, eta0, phi0, jetThreshold;
111  bool applySampling, hcalOnly;
113  std::string labelLayer, labelNxN, labelJets;
114 
115  // eta and phi size of windows around eta0, phi0
116  std::vector<double> dEta;
117  std::vector<double> dPhi;
118 
119  // some private members for ananlysis
120  unsigned int count;
121  double edepEB, edepEE, edepHB, edepHE, edepHO;
122  double edepd[5], edepl[20];
123  double een, hen, hoen; // Energy sum in ECAL, HCAL, HO
124  double vhitec, vhithc, enEcal, enHcal;
125 };
126 
128  edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("SimG4HcalValidation");
129  infolevel = m_Anal.getParameter<int>("InfoLevel");
130  hcalOnly = m_Anal.getParameter<bool>("HcalClusterOnly");
131  applySampling = m_Anal.getParameter<bool>("HcalSampling");
132  coneSize = m_Anal.getParameter<double>("ConeSize");
133  ehitThreshold = m_Anal.getParameter<double>("EcalHitThreshold");
134  hhitThreshold = m_Anal.getParameter<double>("HcalHitThreshold");
135  timeLowlim = m_Anal.getParameter<double>("TimeLowLimit");
136  timeUplim = m_Anal.getParameter<double>("TimeUpLimit");
137  jetThreshold = m_Anal.getParameter<double>("JetThreshold");
138  eta0 = m_Anal.getParameter<double>("Eta0");
139  phi0 = m_Anal.getParameter<double>("Phi0");
140  names = m_Anal.getParameter<std::vector<std::string>>("Names");
141  labelLayer = m_Anal.getUntrackedParameter<std::string>("LabelLayerInfo", "HcalInfoLayer");
142  labelNxN = m_Anal.getUntrackedParameter<std::string>("LabelNxNInfo", "HcalInfoNxN");
143  labelJets = m_Anal.getUntrackedParameter<std::string>("LabelJetsInfo", "HcalInfoJets");
144 
145  produces<PHcalValidInfoLayer>(labelLayer);
146  if (infolevel > 0)
147  produces<PHcalValidInfoNxN>(labelNxN);
148  if (infolevel > 1)
149  produces<PHcalValidInfoJets>(labelJets);
150 
151  edm::LogVerbatim("ValidHcal") << "HcalTestAnalysis:: Initialized as observer of begin/end events and "
152  << "of G4step with Parameter values: \n\tInfoLevel = " << infolevel
153  << "\n\thcalOnly = " << hcalOnly << "\n\tapplySampling = " << applySampling
154  << "\n\tconeSize = " << coneSize << "\n\tehitThreshold = " << ehitThreshold
155  << "\n\thhitThreshold = " << hhitThreshold << "\n\tttimeLowlim = " << timeLowlim
156  << "\n\tttimeUplim = " << timeUplim << "\n\teta0 = " << eta0
157  << "\n\tphi0 = " << phi0 << "\nLabels (Layer): " << labelLayer
158  << " (NxN): " << labelNxN << " (Jets): " << labelJets;
159 
160  init();
161 }
162 
164  edm::LogVerbatim("ValidHcal") << "\n --------> Total number of selected entries"
165  << " : " << count;
166 }
167 
170  edm::LogVerbatim("ValidHcal") << "SimG4HcalValidation::Initialize ESGetToken for HcalDDDSimConstants";
171 }
172 
174  std::unique_ptr<PHcalValidInfoLayer> productLayer(new PHcalValidInfoLayer);
175  layerAnalysis(*productLayer);
176  e.put(std::move(productLayer), labelLayer);
177 
178  if (infolevel > 0) {
179  std::unique_ptr<PHcalValidInfoNxN> productNxN(new PHcalValidInfoNxN);
180  nxNAnalysis(*productNxN);
181  e.put(std::move(productNxN), labelNxN);
182  }
183 
184  if (infolevel > 1) {
185  std::unique_ptr<PHcalValidInfoJets> productJets(new PHcalValidInfoJets);
186  jetAnalysis(*productJets);
187  e.put(std::move(productJets), labelJets);
188  }
189 }
190 
191 //==================================================================== per RUN
193  float sHB[4] = {117., 117., 178., 217.};
194  float sHE[3] = {178., 178., 178.};
195  float sHF[3] = {2.84, 2.09, 0.}; //
196 
197  float deta[4] = {0.0435, 0.1305, 0.2175, 0.3045};
198  float dphi[4] = {0.0436, 0.1309, 0.2182, 0.3054};
199 
200  int i = 0;
201  for (i = 0; i < 4; i++) {
202  scaleHB.push_back(sHB[i]);
203  }
204  for (i = 0; i < 3; i++) {
205  scaleHE.push_back(sHE[i]);
206  }
207  for (i = 0; i < 3; i++) {
208  scaleHF.push_back(sHF[i]);
209  }
210 
211  // window steps;
212  for (i = 0; i < 4; i++) {
213  dEta.push_back(deta[i]);
214  dPhi.push_back(dphi[i]);
215  }
216 
217  // jetfinder conse size setting
218  jetf = std::make_unique<SimG4HcalHitJetFinder>(coneSize);
219 
220  // counter
221  count = 0;
222 }
223 
225  // Numbering From DDD
226  const HcalDDDSimConstants *hcons = &es.getData(ddconsToken_);
227  edm::LogVerbatim("ValidHcal") << "HcalTestAnalysis:: Initialise HcalNumberingFromDDD";
228  numberingFromDDD = std::make_unique<HcalNumberingFromDDD>(hcons);
229 
230  // Numbering scheme
231  org = std::make_unique<HcalTestNumberingScheme>(false);
232 }
233 
235  int irun = (*run)()->GetRunID();
236 
237  edm::LogVerbatim("ValidHcal") << " =====> Begin of Run = " << irun;
238 
239  std::string sdname = names[0];
240  G4SDManager *sd = G4SDManager::GetSDMpointerIfExist();
241  if (sd != nullptr) {
242  G4VSensitiveDetector *aSD = sd->FindSensitiveDetector(sdname);
243  if (aSD == nullptr) {
244  edm::LogWarning("ValidHcal") << "SimG4HcalValidation::beginOfRun: No SD"
245  << " with name " << sdname << " in this "
246  << "Setup";
247  } else {
248  HCalSD *theCaloSD = dynamic_cast<HCalSD *>(aSD);
249  edm::LogVerbatim("ValidHcal") << "SimG4HcalValidation::beginOfRun: Finds SD with name " << theCaloSD->GetName()
250  << " in this Setup";
251  if (org.get()) {
252  theCaloSD->setNumberingScheme(org.get());
253  edm::LogVerbatim("ValidHcal") << "SimG4HcalValidation::beginOfRun: set a new numbering scheme";
254  }
255  }
256  } else {
257  edm::LogWarning("ValidHcal") << "SimG4HcalValidation::beginOfRun: Could "
258  << "not get SD Manager!";
259  }
260 }
261 
262 //=================================================================== per EVENT
264  int i = 0;
265  edepEB = edepEE = edepHB = edepHE = edepHO = 0.;
266  for (i = 0; i < 5; i++)
267  edepd[i] = 0.;
268  for (i = 0; i < 20; i++)
269  edepl[i] = 0.;
270  vhitec = vhithc = enEcal = enHcal = 0;
271  // Cache reset
272  clear();
273 
274  LogDebug("ValidHcal") << "SimG4HcalValidation: =====> Begin of event = " << (*evt)()->GetEventID();
275 }
276 
277 //=================================================================== each STEP
278 void SimG4HcalValidation::update(const G4Step *aStep) {
279  if (aStep != nullptr) {
280  G4VPhysicalVolume *curPV = aStep->GetPreStepPoint()->GetPhysicalVolume();
281  G4String name = curPV->GetName();
282  name.assign(name, 0, 3);
283  double edeposit = aStep->GetTotalEnergyDeposit();
284  int layer = -1, depth = -1;
285  if (name == "EBR") {
286  depth = 0;
287  edepEB += edeposit;
288  } else if (name == "EFR") {
289  depth = 0;
290  edepEE += edeposit;
291  } else if (name == "HBS") {
292  layer = (curPV->GetCopyNo() / 10) % 100;
293  depth = (curPV->GetCopyNo()) % 10 + 1;
294  if (depth > 0 && depth < 4 && layer >= 0 && layer < 17) {
295  edepHB += edeposit;
296  } else {
297  edm::LogWarning("ValidHcal") << "SimG4HcalValidation:Error " << curPV->GetName() << curPV->GetCopyNo();
298  depth = -1;
299  layer = -1;
300  }
301  } else if (name == "HES") {
302  layer = (curPV->GetCopyNo() / 10) % 100;
303  depth = (curPV->GetCopyNo()) % 10 + 1;
304  if (depth > 0 && depth < 3 && layer >= 0 && layer < 19) {
305  edepHE += edeposit;
306  } else {
307  edm::LogWarning("ValidHcal") << "SimG4HcalValidation:Error " << curPV->GetName() << curPV->GetCopyNo();
308  depth = -1;
309  layer = -1;
310  }
311  } else if (name == "HTS") {
312  layer = (curPV->GetCopyNo() / 10) % 100;
313  depth = (curPV->GetCopyNo()) % 10 + 1;
314  if (depth > 3 && depth < 5 && layer >= 17 && layer < 20) {
315  edepHO += edeposit;
316  } else {
317  edm::LogWarning("ValidHcal") << "SimG4HcalValidation:Error " << curPV->GetName() << curPV->GetCopyNo();
318  depth = -1;
319  layer = -1;
320  }
321  }
322  if (depth >= 0 && depth < 5)
323  edepd[depth] += edeposit;
324  if (layer >= 0 && layer < 20)
325  edepl[layer] += edeposit;
326 
327  if (layer >= 0 && layer < 20) {
328  LogDebug("ValidHcal") << "SimG4HcalValidation:: G4Step: " << name << " Layer " << std::setw(3) << layer
329  << " Depth " << std::setw(2) << depth << " Edep " << std::setw(6) << edeposit / MeV
330  << " MeV";
331  }
332  }
333 }
334 
335 //================================================================ End of EVENT
337  count++;
338 
339  // Fill hits cache for jetfinding etc.
340  fill(evt);
341  LogDebug("ValidHcal") << "SimG4HcalValidation:: --- after Fill ";
342 }
343 
344 //---------------------------------------------------
346  LogDebug("ValidHcal") << "SimG4HcalValidation:Fill event " << (*evt)()->GetEventID();
347 
348  // access to the G4 hit collections
349  G4HCofThisEvent *allHC = (*evt)()->GetHCofThisEvent();
350 
351  int nhc = 0, j = 0;
352 
353  // Hcal
354  int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(names[0]);
355  CaloG4HitCollection *theHCHC = (CaloG4HitCollection *)allHC->GetHC(HCHCid);
356  LogDebug("ValidHcal") << "SimG4HcalValidation :: Hit Collection for " << names[0] << " of ID " << HCHCid
357  << " is obtained at " << theHCHC;
358  if (HCHCid >= 0 && theHCHC != nullptr) {
359  int nhits = theHCHC->entries();
360  for (j = 0; j < nhits; j++) {
361  CaloG4Hit *aHit = (*theHCHC)[j];
362 
363  double e = aHit->getEnergyDeposit() / GeV;
364  double time = aHit->getTimeSlice();
365 
366  math::XYZPoint pos = aHit->getPosition();
367  double theta = pos.theta();
368  double eta = -log(tan(theta * 0.5));
369  double phi = pos.phi();
370 
371  uint32_t unitID = aHit->getUnitID();
372  int subdet, zside, layer, etaIndex, phiIndex, lay;
373  org->unpackHcalIndex(unitID, subdet, zside, layer, etaIndex, phiIndex, lay);
374 
375  // some logic to separate HO ...
376  layer--;
377  std::string det = "HB";
378  if (subdet == static_cast<int>(HcalForward)) {
379  det = "HF";
380  uint16_t depth = aHit->getDepth();
381  if (depth != 0) {
382  layer += 2;
383  lay += 2;
384  }
385  if (layer == 1)
386  vhithc += e;
387  else if (layer == 0)
388  vhitec += e;
389  else
390  edm::LogVerbatim("ValidHcal") << "SimG4HcalValidation::HitPMT " << subdet << " " << (2 * zside - 1) * etaIndex
391  << " " << phiIndex << " " << layer + 1 << " R " << pos.rho() << " Phi "
392  << convertRadToDeg(phi) << " Edep " << e << " Time " << time;
393  } else if (subdet == static_cast<int>(HcalEndcap)) {
394  if (etaIndex <= 20) {
395  det = "HES";
396  } else {
397  det = "HED";
398  }
399  }
400  LogDebug("ValidHcal") << "SimG4HcalValidation::debugFill Hcal " << det << " layer " << std::setw(2) << layer
401  << " lay " << std::setw(2) << lay << " time " << std::setw(6) << time << " theta "
402  << std::setw(8) << theta << " eta " << std::setw(8) << eta << " phi " << std::setw(8) << phi
403  << " e " << std::setw(8) << e << " ID 0x" << std::hex << unitID << " ID dec " << std::dec
404  << (int)unitID;
405 
406  // if desired, apply sampling factors in HCAL !!!
407  if (applySampling)
408  e *= getHcalScale(det, layer);
409 
410  // filter on time & energy
411  if (time >= timeLowlim && time <= timeUplim && e > hhitThreshold) {
412  enHcal += e;
413  CaloHit ahit(subdet, lay, e, eta, phi, time, unitID);
414  hitcache.push_back(ahit); // fill cache
415  ++nhc;
416  }
417  }
418  }
419  LogDebug("ValidHcal") << "SimG4HcalValidation:: HCAL hits : " << nhc;
420 
421  if (!hcalOnly) { //-------------------------- ECAL hits --------------------
422  int ndets = names.size();
423  if (ndets > 3)
424  ndets = 3;
425  for (int idty = 1; idty < ndets; idty++) {
426  std::string det = "EB";
427  if (idty == 2)
428  det = "EE";
429  else if (idty > 2)
430  det = "ES";
431 
432  int nec = 0;
433  int ECHCid = G4SDManager::GetSDMpointer()->GetCollectionID(names[idty]);
434  CaloG4HitCollection *theECHC = (CaloG4HitCollection *)allHC->GetHC(ECHCid);
435  LogDebug("ValidHcal") << "SimG4HcalValidation:: Hit Collection for " << names[idty] << " of ID " << ECHCid
436  << " is obtained at " << theECHC;
437  int theechc_entries = theECHC->entries();
438  if (ECHCid >= 0 && theECHC != nullptr) {
439  for (j = 0; j < theechc_entries; j++) {
440  CaloG4Hit *aHit = (*theECHC)[j];
441 
442  double e = aHit->getEnergyDeposit() / GeV;
443  double time = aHit->getTimeSlice();
444 
445  math::XYZPoint pos = aHit->getPosition();
446  double theta = pos.theta();
447  double eta = -log(tan(theta / 2.));
448  double phi = pos.phi();
449  HcalNumberingFromDDD::HcalID id = numberingFromDDD->unitID(eta, phi, 1, 1);
450  uint32_t unitID = org->getUnitID(id);
451  int subdet, zside, layer, ieta, iphi, lay;
452  org->unpackHcalIndex(unitID, subdet, zside, layer, ieta, iphi, lay);
453  subdet = idty + 9;
454  layer = 0;
455  unitID = org->packHcalIndex(subdet, zside, layer, ieta, iphi, lay);
456 
457  // filter on time & energy
458  if (time >= timeLowlim && time <= timeUplim && e > ehitThreshold) {
459  enEcal += e;
460  CaloHit ahit(subdet, lay, e, eta, phi, time, unitID);
461  hitcache.push_back(ahit); // fill cache
462  ++nec;
463  }
464 
465  LogDebug("ValidHcal") << "SimG4HcalValidation::debugFill Ecal " << det << " layer " << std::setw(2) << layer
466  << " lay " << std::setw(2) << lay << " time " << std::setw(6) << time << " theta "
467  << std::setw(8) << theta << " eta " << std::setw(8) << eta << " phi " << std::setw(8)
468  << phi << " e " << std::setw(8) << e << " ID 0x" << std::hex << unitID << " ID dec "
469  << std::dec << (int)unitID;
470  }
471  }
472 
473  LogDebug("ValidHcal") << "SimG4HcalValidation:: " << det << " hits : " << nec;
474  }
475  } // end of if(!hcalOnly)
476 }
477 
479  int i = 0;
480  LogDebug("ValidHcal") << "\n ===>>> SimG4HcalValidation: Energy deposit "
481  << "in MeV\n at EB : " << std::setw(6) << edepEB / MeV << "\n at EE : " << std::setw(6)
482  << edepEE / MeV << "\n at HB : " << std::setw(6) << edepHB / MeV
483  << "\n at HE : " << std::setw(6) << edepHE / MeV << "\n at HO : " << std::setw(6)
484  << edepHO / MeV << "\n ---- SimG4HcalValidation: Energy deposit in";
485  for (i = 0; i < 5; i++)
486  LogDebug("ValidHcal") << " Depth " << std::setw(2) << i << " E " << std::setw(8) << edepd[i] / MeV << " MeV";
487  LogDebug("ValidHcal") << " ---- SimG4HcalValidation: Energy deposit in"
488  << "layers";
489  for (i = 0; i < 20; i++)
490  LogDebug("ValidHcal") << " Layer " << std::setw(2) << i << " E " << std::setw(8) << edepl[i] / MeV << " MeV";
491 
492  product.fillLayers(edepl, edepd, edepHO, edepHB + edepHE, edepEB + edepEE);
493 
494  // Hits in HF
495  product.fillHF(vhitec, vhithc, enEcal, enHcal);
496  LogDebug("ValidHcal") << "SimG4HcalValidation::HF hits " << vhitec << " in EC and " << vhithc << " in HC\n"
497  << " HB/HE " << enEcal << " in EC and " << enHcal << " in HC";
498 
499  // Another HCAL hist to porcess and store separately (a bit more complicated)
500  fetchHits(product);
501 
502  LogDebug("ValidHcal") << " layerAnalysis ===> after fetchHits";
503 }
504 
505 //-----------------------------------------------------------------------------
507  std::vector<CaloHit> *hits = &hitcache;
508  std::vector<CaloHit>::iterator hit_itr;
509 
510  LogDebug("ValidHcal") << "SimG4HcalValidation::NxNAnalysis : entrance ";
511 
512  collectEnergyRdir(eta0, phi0); // HCAL and ECAL energy in SimHitCache
513  // around (eta0,phi0)
514 
515  LogDebug("ValidHcal") << " NxNAnalysis : coolectEnergyRdir - Ecal " << een << " Hcal " << hen;
516 
517  double etot = 0.; // total e deposited in "cluster"
518  double ee = 0.; // ECAL e deposited in "cluster"
519  double he = 0.; // HCAL e deposited in "cluster"
520  double hoe = 0.; // HO e deposited in "cluster"
521 
522  int max = dEta.size(); // 4
523 
524  for (hit_itr = hits->begin(); hit_itr < hits->end(); hit_itr++) {
525  double e = hit_itr->e();
526  double t = hit_itr->t();
527  double eta = hit_itr->eta();
528  double phi = hit_itr->phi();
529  int type = hit_itr->det();
530  int layer = hit_itr->layer();
531 
532  // NxN calulation
533 
534  if (fabs(eta0 - eta) <= dEta[max - 1] && fabs(phi0 - phi) <= dPhi[max - 1]) {
535  etot += e;
536  if (type == 10 || type == 11 || type == 12)
537  ee += e;
538  if (type == static_cast<int>(HcalBarrel) || type == static_cast<int>(HcalEndcap) ||
539  type == static_cast<int>(HcalForward)) {
540  he += e;
541  if (type == static_cast<int>(HcalBarrel) && layer > 17)
542  hoe += e;
543 
544  // which concrete i-th square ?
545  for (int i = 0; i < max; i++) {
546  if ((eta0 - eta) <= dEta[i] && (eta0 - eta) >= -dEta[i] && (phi0 - phi) <= dPhi[i] &&
547  (phi0 - phi) >= -dPhi[i]) {
548  LogDebug("ValidHcal") << "SimG4HcalValidation:: nxNAnalysis eta0,"
549  << " phi0 = " << eta0 << " " << phi0 << " type, layer = " << type << "," << layer
550  << " eta, phi = " << eta << " " << phi;
551 
552  product.fillTProfileNxN(e, i, t);
553  break;
554  }
555  }
556  // here comes break ...
557  }
558  }
559  }
560 
561  product.fillEcollectNxN(ee, he, hoe, etot);
562  product.fillHvsE(een, hen, hoen, een + hen);
563 
564  LogDebug("ValidHcal") << " nxNAnalysis ===> after fillHvsE";
565 }
566 
567 //-----------------------------------------------------------------------------
569  std::vector<CaloHit> *hhit = &hitcache;
570 
571  jetf->setInput(hhit);
572 
573  // zeroing cluster list, perfom clustering, fill cluster list & return pntr
574  std::vector<SimG4HcalHitCluster> *result = jetf->getClusters(hcalOnly);
575 
576  std::vector<SimG4HcalHitCluster>::iterator clus_itr;
577 
578  LogDebug("ValidHcal") << "\n ---------- Final list of " << (*result).size() << " clusters ---------------";
579  for (clus_itr = result->begin(); clus_itr < result->end(); clus_itr++)
580  LogDebug("ValidHcal") << (*clus_itr);
581 
582  std::vector<double> enevec, etavec, phivec;
583 
584  if (!(*result).empty()) {
585  sort((*result).begin(), (*result).end());
586 
587  clus_itr = result->begin(); // first cluster only
588  double etac = clus_itr->eta();
589  double phic = clus_itr->phi();
590 
591  double ecal_collect = 0.; // collect Ecal energy in the cone
592  if (!hcalOnly) {
593  [[clang::suppress]] ecal_collect = clus_itr->collectEcalEnergyR();
594  } else {
595  collectEnergyRdir(etac, phic);
596  [[clang::suppress]] ecal_collect = een;
597  }
598  LogDebug("ValidHcal") << " JetAnalysis ===> ecal_collect = " << ecal_collect;
599 
600  // eta-phi deviation of the cluster from nominal (eta0, phi0) values
601  double dist = jetf->rDist(eta0, phi0, etac, phic);
602  LogDebug("ValidHcal") << " JetAnalysis ===> eta phi deviation = " << dist;
603  product.fillEtaPhiProfileJet(eta0, phi0, etac, phic, dist);
604 
605  LogDebug("ValidHcal") << " JetAnalysis ===> after fillEtaPhiProfileJet";
606 
607  std::vector<CaloHit> *hits = clus_itr->getHits();
608  std::vector<CaloHit>::iterator hit_itr;
609 
610  double ee = 0., he = 0., hoe = 0., etot = 0.;
611 
612  // cycle over all hits in the FIRST cluster
613  for (hit_itr = hits->begin(); hit_itr < hits->end(); hit_itr++) {
614  double e = hit_itr->e();
615  double t = hit_itr->t();
616  double r = jetf->rDist(&(*clus_itr), &(*hit_itr));
617 
618  // energy collection
619  etot += e;
620  if (hit_itr->det() == 10 || hit_itr->det() == 11 || hit_itr->det() == 12)
621  ee += e;
622  if (hit_itr->det() == static_cast<int>(HcalBarrel) || hit_itr->det() == static_cast<int>(HcalEndcap) ||
623  hit_itr->det() == static_cast<int>(HcalForward)) {
624  he += e;
625  if (hit_itr->det() == static_cast<int>(HcalBarrel) && hit_itr->layer() > 17)
626  hoe += e;
627  }
628 
629  if (hit_itr->det() == static_cast<int>(HcalBarrel) || hit_itr->det() == static_cast<int>(HcalEndcap) ||
630  hit_itr->det() == static_cast<int>(HcalForward)) {
631  product.fillTProfileJet(he, r, t);
632  }
633  }
634 
635  product.fillEcollectJet(ee, he, hoe, etot);
636 
637  LogDebug("ValidHcal") << " JetAnalysis ===> after fillEcollectJet: "
638  << "ee/he/hoe/etot " << ee << "/" << he << "/" << hoe << "/" << etot;
639 
640  // Loop over clusters
641  for (clus_itr = result->begin(); clus_itr < result->end(); clus_itr++) {
642  if (clus_itr->e() > jetThreshold) {
643  enevec.push_back(clus_itr->e());
644  etavec.push_back(clus_itr->eta());
645  phivec.push_back(clus_itr->phi());
646  }
647  }
648  product.fillJets(enevec, etavec, phivec);
649 
650  LogDebug("ValidHcal") << " JetAnalysis ===> after fillJets\n"
651  << " JetAnalysis ===> (*result).size() " << (*result).size();
652 
653  // Di-jet mass
654  if (etavec.size() > 1) {
655  if (etavec[0] > -2.5 && etavec[0] < 2.5 && etavec[1] > -2.5 && etavec[1] < 2.5) {
656  LogDebug("ValidHcal") << " JetAnalysis ===> Di-jet mass enter\n"
657  << " JetAnalysis ===> Di-jet vectors ";
658  for (unsigned int i = 0; i < enevec.size(); i++)
659  LogDebug("ValidHcal") << " e, eta, phi = " << enevec[i] << " " << etavec[i] << " " << phivec[i];
660 
661  double et0 = enevec[0] / cosh(etavec[0]);
662  double px0 = et0 * cos(phivec[0]);
663  double py0 = et0 * sin(phivec[0]);
664  double pz0 = et0 * sinh(etavec[0]);
665  double et1 = enevec[1] / cosh(etavec[1]);
666  double px1 = et1 * cos(phivec[1]);
667  double py1 = et1 * sin(phivec[1]);
668  double pz1 = et1 * sinh(etavec[1]);
669 
670  double dijetmass2 = (enevec[0] + enevec[1]) * (enevec[0] + enevec[1]) - (px1 + px0) * (px1 + px0) -
671  (py1 + py0) * (py1 + py0) - (pz1 + pz0) * (pz1 + pz0);
672 
673  LogDebug("ValidHcal") << " JetAnalysis ===> Di-jet massSQ " << dijetmass2;
674 
675  double dijetmass;
676  if (dijetmass2 >= 0.)
677  dijetmass = sqrt(dijetmass2);
678  else
679  dijetmass = -sqrt(-1. * dijetmass2);
680 
681  product.fillDiJets(dijetmass);
682 
683  LogDebug("ValidHcal") << " JetAnalysis ===> after fillDiJets";
684  }
685  }
686  }
687 }
688 
689 //---------------------------------------------------
691  LogDebug("ValidHcal") << "Enter SimG4HcalValidation::fetchHits with " << hitcache.size() << " hits";
692  int nHit = hitcache.size();
693  int hit = 0;
694  int i;
695  std::vector<CaloHit>::iterator itr;
696  std::vector<CaloHit *> lhits(nHit);
697  for (i = 0, itr = hitcache.begin(); itr != hitcache.end(); i++, itr++) {
698  uint32_t unitID = itr->id();
699  int subdet, zside, group, ieta, iphi, lay;
700  HcalTestNumbering::unpackHcalIndex(unitID, subdet, zside, group, ieta, iphi, lay);
701  subdet = itr->det();
702  lay = itr->layer();
703  group = (subdet & 15) << 20;
704  group += ((lay - 1) & 31) << 15;
705  group += (zside & 1) << 14;
706  group += (ieta & 127) << 7;
707  group += (iphi & 127);
708  itr->setId(group);
709  lhits[i] = &hitcache[i];
710  LogDebug("ValidHcal") << "SimG4HcalValidation::fetchHits:Original " << i << " " << hitcache[i] << "\n"
711  << "SimG4HcalValidation::fetchHits:Copied " << i << " " << *lhits[i];
712  }
713  sort(lhits.begin(), lhits.end(), CaloHitIdMore());
714  std::vector<CaloHit *>::iterator k1, k2;
715  for (i = 0, k1 = lhits.begin(); k1 != lhits.end(); i++, k1++)
716  LogDebug("ValidHcal") << "SimG4HcalValidation::fetchHits:Sorted " << i << " " << **k1;
717  int nHits = 0;
718  for (i = 0, k1 = lhits.begin(); k1 != lhits.end(); i++, k1++) {
719  double ehit = (**k1).e();
720  double t = (**k1).t();
721  uint32_t unitID = (**k1).id();
722  int jump = 0;
723  LogDebug("ValidHcal") << "SimG4HcalValidation::fetchHits:Start " << i << " U/T/E"
724  << " 0x" << std::hex << unitID << std::dec << " " << t << " " << ehit;
725  for (k2 = k1 + 1; k2 != lhits.end() && (t - (**k2).t()) < 1 && (t - (**k2).t()) > -1 && unitID == (**k2).id();
726  k2++) {
727  ehit += (**k2).e();
728  LogDebug("ValidHcal") << "\t + " << (**k2).e();
729  jump++;
730  }
731  LogDebug("ValidHcal") << "\t = " << ehit << " in " << jump;
732 
733  double eta = (*k1)->eta();
734  double phi = (*k1)->phi();
735  int lay = ((unitID >> 15) & 31) + 1;
736  int subdet = (unitID >> 20) & 15;
737 
738  // All hits in cache
739  product.fillHits(nHits, lay, subdet, eta, phi, ehit, t);
740  nHits++;
741 
742  LogDebug("ValidHcal") << "SimG4HcalValidation::fetchHits:Hit " << nHits << " " << i << " ID 0x" << std::hex
743  << unitID << " det " << std::dec << subdet << " " << lay << " " << ((unitID >> 14) & 1)
744  << " " << ((unitID >> 7) & 127) << " " << ((unitID) & 127) << " Time " << t << " E " << ehit;
745 
746  i += jump;
747  k1 += jump;
748  }
749 
750  LogDebug("ValidHcal") << "SimG4HcalValidation::fetchHits called with " << nHit << " hits"
751  << " and writes out " << nHits << '(' << hit << ") hits";
752 }
753 //---------------------------------------------------
754 void SimG4HcalValidation::clear() { hitcache.erase(hitcache.begin(), hitcache.end()); }
755 
756 //---------------------------------------------------
757 void SimG4HcalValidation::collectEnergyRdir(const double eta0, const double phi0) {
758  std::vector<CaloHit> *hits = &hitcache;
759  std::vector<CaloHit>::iterator hit_itr;
760 
761  double sume = 0., sumh = 0., sumho = 0.;
762 
763  for (hit_itr = hits->begin(); hit_itr < hits->end(); hit_itr++) {
764  double e = hit_itr->e();
765  double eta = hit_itr->eta();
766  double phi = hit_itr->phi();
767 
768  int type = hit_itr->det();
769 
770  double r = jetf->rDist(eta0, phi0, eta, phi);
771  if (r < coneSize) {
772  if (type == 10 || type == 11 || type == 12) {
773  sume += e;
774  } else {
775  sumh += e;
776  if (type == static_cast<int>(HcalBarrel) && hit_itr->layer() > 17)
777  sumho += e;
778  }
779  }
780  }
781 
782  een = sume;
783  hen = sumh;
784  hoen = sumho;
785 }
786 
787 //---------------------------------------------------
788 double SimG4HcalValidation::getHcalScale(std::string det, int layer) const {
789  double tmp = 0.;
790 
791  if (det == "HB") {
792  tmp = scaleHB[layer];
793  } else if (det == "HES" || det == "HED") {
794  tmp = scaleHE[layer];
795  } else if (det == "HF") {
796  tmp = scaleHF[layer];
797  }
798 
799  return tmp;
800 }
801 
805 
void fillJets(const std::vector< double > &enj, const std::vector< double > &etaj, const std::vector< double > &phij)
Log< level::Info, true > LogVerbatim
double getHcalScale(std::string, int) const
#define DEFINE_SIMWATCHER(type)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
Basic3DVector & operator=(const Basic3DVector &)=default
Assignment operator.
std::unique_ptr< HcalNumberingFromDDD > numberingFromDDD
void fillHvsE(double ee, double he, double hoe, double etot)
void fillTProfileJet(double e, double r, double t)
void beginRun(edm::EventSetup const &) override
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void fill(const EndOfEvent *ev)
void fillLayers(double el[], double ed[], double ho, double hbhe, double ebee)
std::vector< float > scaleHF
void registerConsumes(edm::ConsumesCollector) override
void fillEcollectJet(double ee, double he, double hoe, double etot)
void collectEnergyRdir(const double, const double)
std::vector< std::string > names
void fillEtaPhiProfileJet(double eta0, double phi0, double eta, double phi, double dist)
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
std::vector< CaloHit > hitcache
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
void produce(edm::Event &, const edm::EventSetup &) override
int init
Definition: HydjetWrapper.h:66
void fillDiJets(double mass)
std::vector< double > dEta
uint16_t getDepth() const
Definition: CaloG4Hit.h:69
int zside(DetId const &)
void setNumberingScheme(HcalNumberingScheme *)
Definition: HCalSD.cc:564
const std::string names[nVars_]
void fillHits(int Nhits, int lay, int unitID, double eta, double phi, double ehit, double t)
T getUntrackedParameter(std::string const &, T const &) const
Definition: HCalSD.h:38
void jetAnalysis(PHcalValidInfoJets &)
math::XYZPoint getPosition() const
Definition: CaloG4Hit.h:52
void nxNAnalysis(PHcalValidInfoNxN &)
std::vector< double > dPhi
void fetchHits(PHcalValidInfoLayer &)
T sqrt(T t)
Definition: SSEVec.h:23
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
edm::ESGetToken< HcalDDDSimConstants, HcalSimNumberingRecord > ddconsToken_
std::vector< float > scaleHB
void fillEcollectNxN(double een, double hen, double hoen, double etotn)
void update(const BeginOfRun *run) override
This routine will be called when the appropriate signal arrives.
std::unique_ptr< SimG4HcalHitJetFinder > jetf
void fillTProfileNxN(double e, int i, double t)
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
double getEnergyDeposit() const
Definition: CaloG4Hit.h:79
uint32_t getUnitID() const
Definition: CaloG4Hit.h:66
std::vector< float > scaleHE
std::unique_ptr< HcalTestNumberingScheme > org
#define update(a, b)
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
double getTimeSlice() const
Definition: CaloG4Hit.h:67
SimG4HcalValidation(const edm::ParameterSet &p)
step
Definition: StallMonitor.cc:83
void clear(EGIsoObj &c)
Definition: egamma.h:82
Log< level::Warning, false > LogWarning
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
tmp
align.sh
Definition: createJobs.py:716
void layerAnalysis(PHcalValidInfoLayer &)
def move(src, dest)
Definition: eostools.py:511
void fillHF(double fibl, double fibs, double enec, double enhc)
#define LogDebug(id)