CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ValidIsoTrkCalib.cc
Go to the documentation of this file.
1 //
2 // Package: ValidIsoTrkCalib
3 // Class: ValidIsoTrkCalib
4 //
5 
6 /*
7  Description: Validation for Isolated tracks Calibration
8 
9  Implementation:
10 See the twiki page for details:
11 https://twiki.cern.ch/twiki/bin/view/CMS/ValidIsoTrkCalib
12 
13 */
14 
15 //
16 // Original Author: Andrey Pozdnyakov
17 // Created: Tue Nov 4 01:16:05 CET 2008
18 //
19 
20 // system include files
21 
22 #include <memory>
23 
24 // user include files
32 
41 
51 
53 
54 #include "TROOT.h"
55 #include "TFile.h"
56 #include "TTree.h"
57 #include "TH1F.h"
58 
59 #include <fstream>
60 #include <map>
61 
62 //#define EDM_ML_DEBUG
63 
64 class ValidIsoTrkCalib : public edm::one::EDAnalyzer<edm::one::SharedResources> {
65 public:
66  explicit ValidIsoTrkCalib(const edm::ParameterSet&);
67 
68  // double getDistInPlaneSimple(const GlobalPoint caloPoint, const GlobalPoint rechitPoint);
69 
70 private:
71  void beginJob() override;
72  void analyze(const edm::Event&, const edm::EventSetup&) override;
73 
74  // ----------member data ---------------------------
75 
76  //Variables from HcalIsotrackAnalyzer
77 
80  double taECALCone_;
81  double taHCALCone_;
82 
83  const CaloGeometry* geo;
84  // nothing is done with these tags, so I leave it - cowden
87  std::vector<edm::InputTag> genecalLabel_;
88 
94 
97 
98  //std::string m_inputTrackLabel;
99  //std::string m_hcalLabel;
100 
102  string AxB_;
104 
107  //string calibFactorsFileName_;
108  // string corrfile;
109 
111  //bool takeAllRecHits_, takeGenTracks_;
112  int gen, iso, pix;
113  float genPt[500], genPhi[500], genEta[500];
114  float isoPt[500], isoPhi[500], isoEta[500];
115  float pixPt[500], pixPhi[500], pixEta[500];
116  //int hbheiEta[5000],hbheiPhi[5000],hbheDepth[5000];
117  //float hbheEnergy[5000];
118 
119  int NisoTrk;
121  float ptNear;
122  float ptrack, rvert;
123  //float eecal, ehcal;
124 
128 
129  Float_t emEnergy;
130  Float_t targetE;
131 
132  //TFile* rootFile;
133  // TTree* tree;
134  TTree *tTree, *fTree;
135 
136  Float_t xTrkEcal;
137  Float_t yTrkEcal;
138  Float_t zTrkEcal;
139 
140  Float_t xTrkHcal;
141  Float_t yTrkHcal;
142  Float_t zTrkHcal;
143 
144  int Nhits;
145  float eClustBefore; //Calo energy before calibration
146  float eClustAfter; //After calibration
147  float eTrack; //Track energy
148  float etaTrack;
149  float phiTrack;
150  float eECAL; // Energy deposited in ECAL
151  int numHits; //number of rechits
152  //float e3x3;
153 
161  int iEta;
162  int iPhi;
163  int iEtaTr;
164  int iPhiTr;
165  float iDr, delR;
166  int dietatr;
167  int diphitr;
168 
169  float iTime;
170  float HTime[100];
171  float e3x3Before;
172  float e3x3After;
173  float e5x5Before;
174  float e5x5After;
177  float PtNearBy;
179 
181  // map<UInt_t, Float_t> CalibFactors;
182  // Bool_t ReadCalibFactors(string);
183 
184  TH1F* nTracks;
185 
187  // int Lumi_n;
188 };
189 
191  usesResource(TFileService::kSharedResource);
192 
193  //takeAllRecHits_=iConfig.getUntrackedParameter<bool>("takeAllRecHits");
194  takeGenTracks_ = iConfig.getUntrackedParameter<bool>("takeGenTracks");
195 
196  tok_genTrack_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("genTracksLabel"));
197  genhbheLabel_ = iConfig.getParameter<edm::InputTag>("genHBHE");
198  //genhoLabel_=iConfig.getParameter<edm::InputTag>("genHO");
199  //genecalLabel_=iConfig.getParameter<std::vector<edm::InputTag> >("genECAL");
200 
201  // m_hcalLabel = iConfig.getUntrackedParameter<std::string> ("hcalRecHitsLabel","hbhereco");
202 
203  tok_hbhe_ = consumes<HBHERecHitCollection>(iConfig.getParameter<edm::InputTag>("hbheInput"));
204  tok_ho_ = consumes<HORecHitCollection>(iConfig.getParameter<edm::InputTag>("hoInput"));
205  //eLabel_=iConfig.getParameter<edm::InputTag>("eInput");
206  tok_track_ =
207  consumes<reco::IsolatedPixelTrackCandidateCollection>(iConfig.getParameter<edm::InputTag>("HcalIsolTrackInput"));
208  tok_track1_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("trackInput"));
209 
210  tok_recalibCorrs_ = esConsumes(edm::ESInputTag("", "recalibrate"));
211  tok_geom_ = esConsumes();
212 
213  associationConeSize_ = iConfig.getParameter<double>("associationConeSize");
214  allowMissingInputs_ = iConfig.getUntrackedParameter<bool>("allowMissingInputs", true);
215  // outputFileName_=iConfig.getParameter<std::string>("outputFileName");
216  // calibFactorsFileName_=iConfig.getParameter<std::string>("calibFactorsFileName");
217 
218  AxB_ = iConfig.getParameter<std::string>("AxB");
219  calibrationConeSize_ = iConfig.getParameter<double>("calibrationConeSize");
220 
221  MinNTrackHitsBarrel = iConfig.getParameter<int>("MinNTrackHitsBarrel");
222  MinNTECHitsEndcap = iConfig.getParameter<int>("MinNTECHitsEndcap");
223  energyECALmip = iConfig.getParameter<double>("energyECALmip");
224  energyMinIso = iConfig.getParameter<double>("energyMinIso");
225  energyMaxIso = iConfig.getParameter<double>("energyMaxIso");
226  maxPNear = iConfig.getParameter<double>("maxPNear");
227 
228  edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
230  parameters_.loadParameters(parameters, iC);
232 
233  // taECALCone_=iConfig.getUntrackedParameter<double>("TrackAssociatorECALCone",0.5);
234  //taHCALCone_=iConfig.getUntrackedParameter<double>("TrackAssociatorHCALCone",0.6);
235 }
236 
237 // ------------ method called to for each event ------------
239  try {
241 
242  edm::LogVerbatim("CalibConstants") << " Loaded: OK ";
243 
244  } catch (const cms::Exception& e) {
245  edm::LogWarning("CalibConstants") << " Not Found!! ";
246  }
247 
249  iEvent.getByToken(tok_genTrack_, generalTracks);
250 
252  iEvent.getByToken(tok_track1_, isoProdTracks);
253 
255  //edm::Handle<reco::TrackCollection> isoPixelTracks;
256  iEvent.getByToken(tok_track_, isoPixelTracks);
257 
258  /*
259  edm::Handle<EcalRecHitCollection> ecal;
260  iEvent.getByLabel(eLabel_,ecal);
261  const EcalRecHitCollection Hitecal = *(ecal.product());
262  */
263 
265  iEvent.getByToken(tok_hbhe_, hbhe);
266  const HBHERecHitCollection Hithbhe = *(hbhe.product());
267 
268  geo = &iSetup.getData(tok_geom_);
269 
270  const HcalGeometry* gHcal = static_cast<const HcalGeometry*>(geo->getSubdetectorGeometry(DetId::Hcal, HcalBarrel));
271  //Note: even though it says HcalBarrel, we actually get the whole Hcal detector geometry!
272 
273  // Lumi_n=iEvent.luminosityBlock();
274  parameters_.useEcal = true;
275  parameters_.useHcal = true;
276  parameters_.useCalo = false;
277  parameters_.useMuon = false;
278  //parameters_.dREcal = taECALCone_;
279  //parameters_.dRHcal = taHCALCone_;
280 #ifdef EDM_ML_DEBUG
281  edm::LogVerbatim("HcalIsoTrack") << "Hello World. TrackCollectionSize: " << isoPixelTracks->size();
282 #endif
283  if (isoPixelTracks->empty())
284  return;
285 
286  for (reco::TrackCollection::const_iterator trit = isoProdTracks->begin(); trit != isoProdTracks->end(); trit++) {
287  reco::IsolatedPixelTrackCandidateCollection::const_iterator isoMatched = isoPixelTracks->begin();
288  //reco::TrackCollection::const_iterator isoMatched=isoPixelTracks->begin();
289  bool matched = false;
290 
291  //for (reco::IsolatedPixelTrackCandidateCollection::const_iterator trit = isoPixelTracks->begin(); trit!=isoPixelTracks->end(); trit++)
292  for (reco::IsolatedPixelTrackCandidateCollection::const_iterator it = isoPixelTracks->begin();
293  it != isoPixelTracks->end();
294  it++)
295  //for (reco::TrackCollection::const_iterator it = isoPixelTracks->begin(); it!=isoPixelTracks->end(); it++)
296  {
297  if (abs((trit->pt() - it->pt()) / it->pt()) < 0.005 && abs(trit->eta() - it->eta()) < 0.01) {
298  isoMatched = it;
299  matched = true;
300  break;
301  }
302  }
303  // CUT
304 
305  if (!matched)
306  continue;
307  if (isoMatched->maxPtPxl() > maxPNear)
308  continue;
309 
310  ptNear = isoMatched->maxPtPxl();
311 #ifdef EDM_ML_DEBUG
312  edm::LogVerbatim("HcalIsoTrack") << "Point 0.1 isoMatch. ptnear: " << ptNear;
313 #endif
314  // CUT
315  if (trit->hitPattern().numberOfValidHits() < MinNTrackHitsBarrel)
316  continue;
317  if (fabs(trit->eta()) > 1.47 && trit->hitPattern().numberOfValidStripTECHits() < MinNTECHitsEndcap)
318  continue;
319 
320 #ifdef EDM_ML_DEBUG
321  edm::LogVerbatim("HcalIsoTrack") << "Point 0.2.1 after numofvalidhits HB: "
322  << trit->hitPattern().numberOfValidHits();
323  edm::LogVerbatim("HcalIsoTrack") << "Point 0.2.2 after numofvalidstrips HE: "
324  << trit->hitPattern().numberOfValidStripTECHits();
325 #endif
326  numVH = trit->hitPattern().numberOfValidHits();
327  numVS = trit->hitPattern().numberOfValidStripTECHits();
328 
329  trackE = sqrt(trit->px() * trit->px() + trit->py() * trit->py() + trit->pz() * trit->pz() + 0.14 * 0.14);
330  trackPt = trit->pt();
331  trackEta = trit->eta();
332  trackPhi = trit->phi();
333 
334  emEnergy = isoMatched->energyIn();
335 
336 #ifdef EDM_ML_DEBUG
337  edm::LogVerbatim("HcalIsoTrack") << "Point 0.3. Matched :: pt: " << trit->pt() << " wholeEnergy: " << trackE
338  << " emEnergy: " << emEnergy << " eta: " << trackEta << " phi: " << trackPhi;
339  edm::LogVerbatim("HcalIsoTrack") << "Point 0.4. EM energy in cone: " << emEnergy;
340 #endif
342  iEvent,
343  iSetup,
345  parameters_);
346 
347  //float etaecal=info.trkGlobPosAtEcal.eta();
348  //float phiecal=info.trkGlobPosAtEcal.phi();
349  // float etahcal=info.trkGlobPosAtHcal.eta();
350  // float phihcal=info.trkGlobPosAtHcal.phi();
351 
352  xTrkEcal = info.trkGlobPosAtEcal.x();
353  yTrkEcal = info.trkGlobPosAtEcal.y();
354  zTrkEcal = info.trkGlobPosAtEcal.z();
355 
356  xTrkHcal = info.trkGlobPosAtHcal.x();
357  yTrkHcal = info.trkGlobPosAtHcal.y();
358  zTrkHcal = info.trkGlobPosAtHcal.z();
359 
360  if (xTrkEcal == 0 && yTrkEcal == 0 && zTrkEcal == 0) {
361  edm::LogVerbatim("HcalIsoTrack") << "zero point at Ecal";
362  continue;
363  }
364  if (xTrkHcal == 0 && yTrkHcal == 0 && zTrkHcal == 0) {
365  edm::LogVerbatim("HcalIsoTrack") << "zero point at Hcal";
366  continue;
367  }
368 
369  /*GlobalVector trackMomAtEcal = info.trkMomAtEcal;
370  GlobalVector trackMomAtHcal = info.trkMomAtHcal;
371 
372  PxTrkHcal = trackMomAtHcal.x();
373  PyTrkHcal = trackMomAtHcal.y();
374  PzTrkHcal = trackMomAtHcal.z();
375  */
376 
377  GlobalPoint gPointEcal(xTrkEcal, yTrkEcal, zTrkEcal);
378  GlobalPoint gPointHcal(xTrkHcal, yTrkHcal, zTrkHcal);
379 
380  int iphitrue = -10;
381  int ietatrue = 100;
382  const HcalDetId tempId = gHcal->getClosestCell(gPointHcal);
383  ietatrue = tempId.ieta();
384  iphitrue = tempId.iphi();
385 
386  MaxHit_struct MaxHit;
387 
388  MaxHit.hitenergy = -100.;
389 
390  //container for used recHits
391  std::vector<DetId> usedHits;
392  //
393  usedHits.clear();
394 #ifdef EDM_ML_DEBUG
395  edm::LogVerbatim("HcalIsoTrack") << "Point 1. Entrance to HBHECollection";
396 #endif
397  //float dddeta = 1000.;
398  //float dddphi = 1000.;
399  //int iphitrue = 1234;
400  //int ietatrue = 1234;
401 
402  GlobalPoint gPhot;
403 
404  for (HBHERecHitCollection::const_iterator hhit = Hithbhe.begin(); hhit != Hithbhe.end(); hhit++) {
405  //check that this hit was not considered before and push it into usedHits
406  bool hitIsUsed = false;
407  for (uint32_t i = 0; i < usedHits.size(); i++) {
408  if (usedHits[i] == hhit->id())
409  hitIsUsed = true;
410  }
411  if (hitIsUsed)
412  continue;
413  usedHits.push_back(hhit->id());
414  //
415 
416  // rof 16.05.2008 start: include the possibility for recalibration
417  float recal = 1;
418  // rof end
419 
420  GlobalPoint pos = geo->getPosition(hhit->detid());
421  //float phihit = pos.phi();
422  //float etahit = pos.eta();
423 
424  int iphihitm = (hhit->id()).iphi();
425  int ietahitm = (hhit->id()).ieta();
426  int depthhit = (hhit->id()).depth();
427  float enehit = hhit->energy() * recal;
428 
429  if (depthhit != 1)
430  continue;
431 
432 #ifdef EDM_ML_DEBUG
433  float dphi = fabs(info.trkGlobPosAtHcal.phi() - pos.phi());
434  if (dphi > 4. * atan(1.))
435  dphi = 8. * atan(1.) - dphi;
436  float deta = fabs(info.trkGlobPosAtHcal.eta() - pos.eta());
437  float dr = sqrt(dphi * dphi + deta * deta);
438 #endif
439 
440  //double distAtHcal = getDistInPlaneTrackDir(gPointHcal, trackMomAtHcal, pos);
441  double distAtHcal = getDistInPlaneSimple(gPointHcal, pos);
442 
443  if (distAtHcal < associationConeSize_) {
444  for (HBHERecHitCollection::const_iterator hhit2 = Hithbhe.begin(); hhit2 != Hithbhe.end(); hhit2++) {
445  int iphihitm2 = (hhit2->id()).iphi();
446  int ietahitm2 = (hhit2->id()).ieta();
447  int depthhit2 = (hhit2->id()).depth();
448  float enehit2 = hhit2->energy() * recal;
449 
450  if (iphihitm == iphihitm2 && ietahitm == ietahitm2 && depthhit != depthhit2)
451  enehit = enehit + enehit2;
452  }
453 
454 #ifdef EDM_ML_DEBUG
455  edm::LogVerbatim("HcalIsoTrack") << "IN CONE ieta: " << ietahitm << " iphi: " << iphihitm
456  << " depthhit: " << depthhit << " dr: " << dr << " energy: " << enehit;
457 #endif
458  //Find a Hit with Maximum Energy
459 
460  if (enehit > MaxHit.hitenergy) {
461  MaxHit.hitenergy = enehit;
462  MaxHit.ietahitm = (hhit->id()).ieta();
463  MaxHit.iphihitm = (hhit->id()).iphi();
464  MaxHit.dr = distAtHcal;
465  //MaxHit.depthhit = (hhit->id()).depth();
466  MaxHit.depthhit = 1;
467 
468  //gPhot = geo->getPosition(hhit->detid());
469  }
470  }
471  } //end of all HBHE hits cycle
472 
473  usedHits.clear();
474 
475 #ifdef EDM_ML_DEBUG
476  edm::LogVerbatim("HcalIsoTrack") << "Hottest ieta: " << MaxHit.ietahitm << " iphi: " << MaxHit.iphihitm
477  << " dr: " << MaxHit.dr;
478  edm::LogVerbatim("HcalIsoTrack") << "Track ieta: " << ietatrue << " iphi: " << iphitrue;
479  edm::LogVerbatim("HcalIsoTrack") << "Point 3. MaxHit :::En " << MaxHit.hitenergy << " ieta: " << MaxHit.ietahitm
480  << " iphi: " << MaxHit.iphihitm;
481 #endif
482 
483  Bool_t passCuts = kFALSE;
484  if (trackE > energyMinIso && trackE < energyMaxIso && emEnergy < energyECALmip && MaxHit.hitenergy > 0. &&
485  abs(MaxHit.ietahitm) < 29)
486  passCuts = kTRUE;
487 
488 #ifdef EDM_ML_DEBUG
489  edm::LogVerbatim("HcalIsoTrack") << "Pont 0.1.1. trackE:" << trackE << " emEn: " << emEnergy;
490 #endif
491  numHits = 0;
492 
493  eClustBefore = 0.0;
494  eClustAfter = 0.0;
495  eBeforeDepth1 = 0.0;
496  eAfterDepth1 = 0.0;
497  eBeforeDepth2 = 0.0;
498  eAfterDepth2 = 0.0;
499  CentHitFactor = 0.0;
500  e3x3After = 0.0;
501  e3x3Before = 0.0;
502  e5x5After = 0.0;
503  e5x5Before = 0.0;
504 
505  for (HBHERecHitCollection::const_iterator hhit = Hithbhe.begin(); hhit != Hithbhe.end(); hhit++) {
506  //check that this hit was not considered before and push it into usedHits
507  bool hitIsUsed = false;
508  for (uint32_t i = 0; i < usedHits.size(); i++) {
509  if (usedHits[i] == hhit->id())
510  hitIsUsed = true;
511  }
512  if (hitIsUsed)
513  continue;
514  usedHits.push_back(hhit->id());
515 
516  int DIETA = 100;
517  if (MaxHit.ietahitm * (hhit->id()).ieta() > 0) {
518  DIETA = MaxHit.ietahitm - (hhit->id()).ieta();
519  }
520  if (MaxHit.ietahitm * (hhit->id()).ieta() < 0) {
521  DIETA = MaxHit.ietahitm - (hhit->id()).ieta();
522  DIETA = DIETA > 0 ? DIETA - 1 : DIETA + 1;
523  }
524 
525  int DIPHI = abs(MaxHit.iphihitm - (hhit->id()).iphi());
526  DIPHI = DIPHI > 36 ? 72 - DIPHI : DIPHI;
527 
528  int numbercell = 100; //always collect Wide clastor!
529 
530  //if(AxB_=="5x5" || AxB_=="3x3" || AxB_=="7x7"|| AxB_=="Cone")
531 
532  //if(AxB_=="3x3") numbercell = 1;
533  //if(AxB_=="5x5") numbercell = 2;
534  //if(AxB_=="Cone") numbercell = 1000;
535 
536  if (abs(DIETA) <= numbercell &&
537  (abs(DIPHI) <= numbercell || (abs(MaxHit.ietahitm) >= 20 && abs(DIPHI) <= numbercell + 1))) {
538  const GlobalPoint pos2 = geo->getPosition(hhit->detid());
539 
540  if (passCuts && hhit->energy() > 0) {
541  float factor = 0.0;
542  // factor = CalibFactors[hhit->id()];
543  factor = respRecalib->getValues(hhit->id())->getValue();
544 
545 #ifdef EDM_ML_DEBUG
546  edm::LogVerbatim("HcalIsoTrack") << " calib factors: " << factor;
547 #endif
548 
549  if (hhit->id().ieta() == MaxHit.ietahitm && hhit->id().iphi() == MaxHit.iphihitm)
550  CentHitFactor = factor;
551 
552  if (hhit->id().ieta() == MaxHit.ietahitm && hhit->id().iphi() == MaxHit.iphihitm)
553  iTime = hhit->time();
554 
555  if (AxB_ != "3x3" && AxB_ != "5x5" && AxB_ != "Cone")
556  edm::LogWarning(" AxB ") << " Not supported: " << AxB_;
557 
558  if (abs(DIETA) <= 2 && (abs(DIPHI) <= 2 || ((abs(MaxHit.ietahitm) > 20 && abs(DIPHI) <= 4) &&
559  !((abs(MaxHit.ietahitm) == 21 || abs(MaxHit.ietahitm) == 22) &&
560  abs((hhit->id()).ieta()) <= 20 && abs(DIPHI) > 2)))) {
561  e5x5Before += hhit->energy();
562  e5x5After += hhit->energy() * factor;
563  }
564 
565  if (abs(DIETA) <= 1 && (abs(DIPHI) <= 1 || ((abs(MaxHit.ietahitm) > 20 && abs(DIPHI) <= 2) &&
566  !(abs(MaxHit.ietahitm) == 21 && abs((hhit->id()).ieta()) <= 20 &&
567  abs(DIPHI) > 1)))) {
568  e3x3Before += hhit->energy();
569  e3x3After += hhit->energy() * factor;
570  }
571 
572  if (AxB_ == "5x5") {
573  if (abs(DIETA) <= 2 && (abs(DIPHI) <= 2 || (abs(MaxHit.ietahitm) > 20 && abs(DIPHI) <= 4))) {
574  if (abs(MaxHit.ietahitm) == 21 && abs((hhit->id()).ieta()) <= 20 && abs(DIPHI) > 3)
575  continue;
576 
577  HTime[numHits] = hhit->time();
578  numHits++;
579 
580  eClustBefore += hhit->energy();
581  eClustAfter += hhit->energy() * factor;
582 
583  if ((hhit->id().depth() == 1) && (abs(hhit->id().ieta()) > 17) && (abs(hhit->id().ieta()) < 29)) {
584  eBeforeDepth1 += hhit->energy();
585  eAfterDepth1 += hhit->energy() * factor;
586  } else if ((hhit->id().depth() == 2) && (abs(hhit->id().ieta()) > 17) && (abs(hhit->id().ieta()) < 29)) {
587  eBeforeDepth2 += hhit->energy();
588  eAfterDepth2 += hhit->energy() * factor;
589  }
590  }
591  } //end of 5x5
592 
593  if (AxB_ == "3x3") {
594  if (abs(DIETA) <= 1 && (abs(DIPHI) <= 1 || (abs(MaxHit.ietahitm) > 20 && abs(DIPHI) <= 2))) {
595  if (abs(MaxHit.ietahitm) == 21 && abs((hhit->id()).ieta()) <= 20 && abs(DIPHI) > 2)
596  continue;
597 
598  HTime[numHits] = hhit->time();
599  numHits++;
600 
601  eClustBefore += hhit->energy();
602  eClustAfter += hhit->energy() * factor;
603 
604  if ((hhit->id().depth() == 1) && (abs(hhit->id().ieta()) > 17) && (abs(hhit->id().ieta()) < 29)) {
605  eBeforeDepth1 += hhit->energy();
606  eAfterDepth1 += hhit->energy() * factor;
607  } else if ((hhit->id().depth() == 2) && (abs(hhit->id().ieta()) > 17) && (abs(hhit->id().ieta()) < 29)) {
608  eBeforeDepth2 += hhit->energy();
609  eAfterDepth2 += hhit->energy() * factor;
610  }
611  }
612  } //end of 3x3
613 
614  if (AxB_ == "Cone" && getDistInPlaneSimple(gPointHcal, pos2) < calibrationConeSize_) {
615  HTime[numHits] = hhit->time();
616  numHits++;
617 
618  eClustBefore += hhit->energy();
619  eClustAfter += hhit->energy() * factor;
620 
621  if ((hhit->id().depth() == 1) && (abs(hhit->id().ieta()) > 17) && (abs(hhit->id().ieta()) < 29)) {
622  eBeforeDepth1 += hhit->energy();
623  eAfterDepth1 += hhit->energy() * factor;
624  } else if ((hhit->id().depth() == 2) && (abs(hhit->id().ieta()) > 17) && (abs(hhit->id().ieta()) < 29)) {
625  eBeforeDepth2 += hhit->energy();
626  eAfterDepth2 += hhit->energy() * factor;
627  }
628 
629  } //end of Cone
630 
631  } //end of passCuts
632 
633  } //end of DIETA DIPHI
634 
635  } //end of associatedcone HBHE hits cycle
636 
637  int dieta_M_P = 100;
638  int diphi_M_P = 100;
639  if (MaxHit.ietahitm * ietatrue > 0) {
640  dieta_M_P = abs(MaxHit.ietahitm - ietatrue);
641  }
642  if (MaxHit.ietahitm * ietatrue < 0) {
643  dieta_M_P = abs(MaxHit.ietahitm - ietatrue) - 1;
644  }
645  diphi_M_P = abs(MaxHit.iphihitm - iphitrue);
646  diphi_M_P = diphi_M_P > 36 ? 72 - diphi_M_P : diphi_M_P;
647 
648  if (passCuts)
649 
650  {
651  eventNumber = iEvent.id().event();
652  runNumber = iEvent.id().run();
653 
654  eCentHitBefore = MaxHit.hitenergy;
656  eECAL = emEnergy;
659  PtNearBy = ptNear;
660 
661  eTrack = trackE;
662  phiTrack = trackPhi;
663  etaTrack = trackEta;
664 
665  iEta = MaxHit.ietahitm;
666  iPhi = MaxHit.iphihitm;
667 
668  iEtaTr = ietatrue;
669  iPhiTr = iphitrue;
670  iDr = sqrt(diphi_M_P * diphi_M_P + dieta_M_P * dieta_M_P);
671  delR = MaxHit.dr;
672  dietatr = dieta_M_P;
673  diphitr = diphi_M_P;
674 
675  fTree->Fill();
676  }
677 
678  } //end of isoProdTracks cycle
679 
680  /* ------------------ Some stuff for general tracks ---------- ----*/
681 #ifdef EDM_ML_DEBUG
682  edm::LogVerbatim("HcalIsoTrack") << " generalTracks Size: " << generalTracks->size();
683 #endif
684  int n = generalTracks->size();
685  nTracks->Fill(n);
686 
687  if (takeGenTracks_ && iEvent.id().event() % 10 == 1) {
688  gen = generalTracks->size();
689  iso = isoProdTracks->size();
690  pix = isoPixelTracks->size();
691 
692  genPt[0] = -33;
693  genPhi[0] = -33;
694  genEta[0] = -33;
695 
696  isoPt[0] = -33;
697  isoPhi[0] = -33;
698  isoEta[0] = -33;
699 
700  pixPt[0] = -33;
701  pixPhi[0] = -33;
702  pixEta[0] = -33;
703 
704  Int_t gencount = 0, isocount = 0, pixcount = 0;
705  for (reco::TrackCollection::const_iterator gentr = generalTracks->begin(); gentr != generalTracks->end(); gentr++) {
706  genPt[gencount] = gentr->pt();
707  genPhi[gencount] = gentr->phi();
708  genEta[gencount] = gentr->eta();
709  gencount++;
710  }
711 
712  for (reco::TrackCollection::const_iterator isotr = isoProdTracks->begin(); isotr != isoProdTracks->end(); isotr++) {
713  isoPt[isocount] = isotr->pt();
714  isoPhi[isocount] = isotr->phi();
715  isoEta[isocount] = isotr->eta();
716  isocount++;
717  }
718 
719  for (reco::IsolatedPixelTrackCandidateCollection::const_iterator pixtr = isoPixelTracks->begin();
720  pixtr != isoPixelTracks->end();
721  pixtr++) {
722  pixPt[pixcount] = pixtr->pt();
723  pixPhi[pixcount] = pixtr->phi();
724  pixEta[pixcount] = pixtr->eta();
725  pixcount++;
726  }
727  }
728 
729  tTree->Fill();
730 }
731 
732 // ------------ method called once each job just before starting event loop ------------
734 #ifdef EDM_ML_DEBUG
735 // if (!ReadCalibFactors(calibFactorsFileName_.c_str() ))
736 // edm::LogVerbatim("HcalIsoTrack")<<"Cant read file with cailib coefficients!! ---";
737 #endif
738  // rootFile = new TFile(outputFileName_.c_str(),"RECREATE");
739 
740  //@@@@@@@@@@@@@
741  //TFileDirectory ValDir = fs->mkdir("Validation");
742 
743  nTracks = fs->make<TH1F>("nTracks", "general;number of general tracks", 11, -0.5, 10.5);
744 
745  tTree = fs->make<TTree>("tTree", "Tree for gen info");
746 
747  fTree = fs->make<TTree>("fTree", "Tree for IsoTrack Calibration");
748 
749  fTree->Branch("eventNumber", &eventNumber, "eventNumber/I");
750  fTree->Branch("runNumber", &runNumber, "runNumber/I");
751 
752  fTree->Branch("eClustBefore", &eClustBefore, "eClustBefore/F");
753  fTree->Branch("eClustAfter", &eClustAfter, "eClustAfter/F");
754  fTree->Branch("eTrack", &eTrack, "eTrack/F");
755  fTree->Branch("etaTrack", &etaTrack, "etaTrack/F");
756  fTree->Branch("phiTrack", &phiTrack, "phiTrack/F");
757 
758  fTree->Branch("numHits", &numHits, "numHits/I");
759  fTree->Branch("eECAL", &eECAL, "eECAL/F");
760  fTree->Branch("PtNearBy", &PtNearBy, "PtNearBy/F");
761  fTree->Branch("numValidTrkHits", &numValidTrkHits, "numValidTrkHits/F");
762  fTree->Branch("numValidTrkStrips", &numValidTrkStrips, "numValidTrkStrips/F");
763 
764  fTree->Branch("eBeforeDepth1", &eBeforeDepth1, "eBeforeDepth1/F");
765  fTree->Branch("eBeforeDepth2", &eBeforeDepth2, "eBeforeDepth2/F");
766  fTree->Branch("eAfterDepth1", &eAfterDepth1, "eAfterDepth1/F");
767  fTree->Branch("eAfterDepth2", &eAfterDepth2, "eAfterDepth2/F");
768 
769  fTree->Branch("e3x3Before", &e3x3Before, "e3x3Before/F");
770  fTree->Branch("e3x3After", &e3x3After, "e3x3After/F");
771  fTree->Branch("e5x5Before", &e5x5Before, "e5x5Before/F");
772  fTree->Branch("e5x5After", &e5x5After, "e5x5After/F");
773 
774  fTree->Branch("eCentHitAfter", &eCentHitAfter, "eCentHitAfter/F");
775  fTree->Branch("eCentHitBefore", &eCentHitBefore, "eCentHitBefore/F");
776  fTree->Branch("iEta", &iEta, "iEta/I");
777  fTree->Branch("iPhi", &iPhi, "iPhi/I");
778 
779  fTree->Branch("iEtaTr", &iEtaTr, "iEtaTr/I");
780  fTree->Branch("iPhiTr", &iPhiTr, "iPhiTr/I");
781  fTree->Branch("dietatr", &dietatr, "dietatr/I");
782  fTree->Branch("diphitr", &diphitr, "diphitr/I");
783  fTree->Branch("iDr", &iDr, "iDr/F");
784  fTree->Branch("delR", &delR, "delR/F");
785 
786  fTree->Branch("iTime", &iTime, "iTime/F");
787  fTree->Branch("HTime", HTime, "HTime[numHits]/F");
788 
789  fTree->Branch("xTrkEcal", &xTrkEcal, "xTrkEcal/F");
790  fTree->Branch("yTrkEcal", &yTrkEcal, "yTrkEcal/F");
791  fTree->Branch("zTrkEcal", &zTrkEcal, "zTrkEcal/F");
792  fTree->Branch("xTrkHcal", &xTrkHcal, "xTrkHcal/F");
793  fTree->Branch("yTrkHcal", &yTrkHcal, "yTrkHcal/F");
794  fTree->Branch("zTrkHcal", &zTrkHcal, "zTrkHcal/F");
795 
796  if (takeGenTracks_) {
797  tTree->Branch("gen", &gen, "gen/I");
798  tTree->Branch("iso", &iso, "iso/I");
799  tTree->Branch("pix", &pix, "pix/I");
800  tTree->Branch("genPt", genPt, "genPt[gen]/F");
801  tTree->Branch("genPhi", genPhi, "genPhi[gen]/F");
802  tTree->Branch("genEta", genEta, "genEta[gen]/F");
803 
804  tTree->Branch("isoPt", isoPt, "isoPt[iso]/F");
805  tTree->Branch("isoPhi", isoPhi, "isoPhi[iso]/F");
806  tTree->Branch("isoEta", isoEta, "isoEta[iso]/F");
807 
808  tTree->Branch("pixPt", pixPt, "pixPt[pix]/F");
809  tTree->Branch("pixPhi", pixPhi, "pixPhi[pix]/F");
810  tTree->Branch("pixEta", pixEta, "pixEta[pix]/F");
811  }
812 }
813 
814 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:38
static const std::string kSharedResource
Definition: TFileService.h:76
edm::EDGetTokenT< reco::TrackCollection > tok_genTrack_
Log< level::Info, true > LogVerbatim
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
EventNumber_t event() const
Definition: EventID.h:40
T getUntrackedParameter(std::string const &, T const &) const
static const TGPicture * info(bool iBackgroundIsBlack)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
void analyze(const edm::Event &, const edm::EventSetup &) override
DetId getClosestCell(const GlobalPoint &r) const override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void useDefaultPropagator()
use the default propagator
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
std::vector< T >::const_iterator const_iterator
void loadParameters(const edm::ParameterSet &, edm::ConsumesCollector &)
TrackAssociatorParameters parameters_
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
const Item * getValues(DetId fId, bool throwOnFail=true) const
math::XYZPoint trkGlobPosAtHcal
edm::EDGetTokenT< reco::IsolatedPixelTrackCandidateCollection > tok_track_
bool getData(T &iHolder) const
Definition: EventSetup.h:128
int iEvent
Definition: GenABIO.cc:224
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
const CaloGeometry * geo
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
T sqrt(T t)
Definition: SSEVec.h:19
void beginJob() override
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > bFieldToken
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:50
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TrackDetectorAssociator trackAssociator_
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
edm::EDGetTokenT< HBHERecHitCollection > tok_hbhe_
edm::ESGetToken< HcalRespCorrs, HcalRespCorrsRcd > tok_recalibCorrs_
const HcalRespCorrs * respRecalib
edm::InputTag genhbheLabel_
ValidIsoTrkCalib(const edm::ParameterSet &)
std::vector< edm::InputTag > genecalLabel_
const_iterator end() const
T const * product() const
Definition: Handle.h:70
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > tok_geom_
edm::Service< TFileService > fs
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
static FreeTrajectoryState getFreeTrajectoryState(const MagneticField *, const reco::Track &)
get FreeTrajectoryState from different track representations
T eta() const
Definition: PV3DBase.h:73
edm::EventID id() const
Definition: EventBase.h:59
edm::EDGetTokenT< HORecHitCollection > tok_ho_
edm::InputTag genhoLabel_
TrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const AssociatorParameters &)
math::XYZPoint trkGlobPosAtEcal
Track position at different parts of the calorimeter.
const JetExtendedData & getValue(const Container &, const reco::JetBaseRef &)
get value for the association. Throw exception if no association found
double getDistInPlaneSimple(const GlobalPoint caloPoint, const GlobalPoint rechitPoint)
Definition: ConeDefinition.h:9
Log< level::Warning, false > LogWarning
edm::EDGetTokenT< reco::TrackCollection > tok_track1_
const_iterator begin() const