CMS 3D CMS Logo

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