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