test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IsoTrackCalibration.cc
Go to the documentation of this file.
1 //#define DebugLog
2 // system include files
3 #include <memory>
4 #include <string>
5 #include <vector>
6 
7 // Root objects
8 #include "TROOT.h"
9 #include "TSystem.h"
10 #include "TFile.h"
11 #include "TProfile.h"
12 #include "TDirectory.h"
13 #include "TTree.h"
14 #include "TLorentzVector.h"
15 #include "TInterpreter.h"
16 
17 //Tracks
22 
23 // Vertices
27 // Jets
30 
31 //Triggers
39 
43 
51 
57 
72 
74 
75 public:
76  explicit IsoTrackCalibration(const edm::ParameterSet&);
78 
79  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
80 
81 private:
82  virtual void beginJob() ;
83  virtual void analyze(const edm::Event&, const edm::EventSetup&);
84  virtual void endJob() ;
85  virtual void beginRun(edm::Run const&, edm::EventSetup const&);
86  virtual void endRun(edm::Run const&, edm::EventSetup const&);
87  virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
88  virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
89 
91 
92  bool changed;
95  std::vector<std::string> trigNames, HLTNames;
96  std::vector<int> trigKount, trigPass;
97  int verbosity;
103  bool qcdMC;
104  int nRun, nAll, nGood;
108 
118 
119  TTree *tree;
126  std::vector<bool> *t_trgbits;
127  std::vector<unsigned int> *t_DetIds;
128  std::vector<double> *t_HitEnergies, pbin, vbin;
130  TH1I *h_iEta, *h_tketa0[5], *h_tketa1[5], *h_tketa2[5];
131  TH1I *h_tketa3[5], *h_tketa4[5], *h_tketa5[5];
133  TH1F *h_jetpt[4];
134  TH1I *h_tketav1[5][6], *h_tketav2[5][6];
135 };
136 
138  changed(false), nRun(0), nAll(0), nGood(0),
139  t_trgbits(0), t_DetIds(0), t_HitEnergies(0) {
140  //now do whatever initialization is needed
141  verbosity = iConfig.getUntrackedParameter<int>("Verbosity",0);
142  trigNames = iConfig.getUntrackedParameter<std::vector<std::string> >("Triggers");
143  theTrackQuality = iConfig.getUntrackedParameter<std::string>("TrackQuality","highPurity");
144  processName = iConfig.getUntrackedParameter<std::string>("ProcessName","HLT");
145  l1Filter = iConfig.getUntrackedParameter<std::string>("L1Filter", "hltL1sL1SingleJet");
146  l2Filter = iConfig.getUntrackedParameter<std::string>("L2Filter", "L2Filter");
147  l3Filter = iConfig.getUntrackedParameter<std::string>("L3Filter", "Filter");
148  reco::TrackBase::TrackQuality trackQuality_=reco::TrackBase::qualityByName(theTrackQuality);
149  selectionParameters.minPt = iConfig.getUntrackedParameter<double>("MinTrackPt", 10.0);
150  selectionParameters.minQuality = trackQuality_;
151  selectionParameters.maxDxyPV = iConfig.getUntrackedParameter<double>("MaxDxyPV", 0.2);
152  selectionParameters.maxDzPV = iConfig.getUntrackedParameter<double>("MaxDzPV", 5.0);
153  selectionParameters.maxChi2 = iConfig.getUntrackedParameter<double>("MaxChi2", 5.0);
154  selectionParameters.maxDpOverP = iConfig.getUntrackedParameter<double>("MaxDpOverP", 0.1);
155  selectionParameters.minOuterHit = iConfig.getUntrackedParameter<int>("MinOuterHit", 4);
156  selectionParameters.minLayerCrossed = iConfig.getUntrackedParameter<int>("MinLayerCrossed", 8);
157  selectionParameters.maxInMiss = iConfig.getUntrackedParameter<int>("MaxInMiss", 0);
158  selectionParameters.maxOutMiss = iConfig.getUntrackedParameter<int>("MaxOutMiss", 0);
159  a_coneR = iConfig.getUntrackedParameter<double>("ConeRadius",34.98);
160  a_charIsoR = a_coneR + 28.9;
161  a_mipR = iConfig.getUntrackedParameter<double>("ConeRadiusMIP",14.0);
162  pTrackMin_ = iConfig.getUntrackedParameter<double>("MinimumTrackP",20.0);
163  eEcalMax_ = iConfig.getUntrackedParameter<double>("MaximumEcalEnergy",2.0);
164  eIsolation_ = iConfig.getUntrackedParameter<double>("IsolationEnergy",2.0);
165  qcdMC = iConfig.getUntrackedParameter<bool>("IsItQCDMC", true);
166  bool isItAOD = iConfig.getUntrackedParameter<bool>("IsItAOD", false);
167  triggerEvent_ = edm::InputTag("hltTriggerSummaryAOD","",processName);
168  theTriggerResultsLabel = edm::InputTag("TriggerResults","",processName);
169 
170  // define tokens for access
171  tok_trigEvt = consumes<trigger::TriggerEvent>(triggerEvent_);
172  tok_trigRes = consumes<edm::TriggerResults>(theTriggerResultsLabel);
173  tok_genTrack_ = consumes<reco::TrackCollection>(edm::InputTag("generalTracks"));
174  tok_recVtx_ = consumes<reco::VertexCollection>(edm::InputTag("offlinePrimaryVertices"));
175  tok_bs_ = consumes<reco::BeamSpot>(edm::InputTag("offlineBeamSpot"));
176  tok_ew_ = consumes<GenEventInfoProduct>(edm::InputTag("generator"));
177  tok_pu_ = consumes<std::vector<PileupSummaryInfo>>(iConfig.getParameter<edm::InputTag>("PUinfo"));
178 
179  if (isItAOD) {
180  tok_EB_ = consumes<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEB"));
181  tok_EE_ = consumes<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEE"));
182  tok_hbhe_ = consumes<HBHERecHitCollection>(edm::InputTag("reducedHcalRecHits", "hbhereco"));
183  } else {
184  tok_EB_ = consumes<EcalRecHitCollection>(edm::InputTag("ecalRecHit","EcalRecHitsEB"));
185  tok_EE_ = consumes<EcalRecHitCollection>(edm::InputTag("ecalRecHit","EcalRecHitsEE"));
186  tok_hbhe_ = consumes<HBHERecHitCollection>(edm::InputTag("hbhereco"));
187  }
188  tok_jets_ = consumes<reco::GenJetCollection>(iConfig.getParameter<edm::InputTag>("JetSource"));
189 
190  std::vector<int>dummy(trigNames.size(),0);
191  trigKount = trigPass = dummy;
192 #ifdef DebugLog
193  if (verbosity>=0) {
194  std::cout <<"Parameters read from config file \n"
195  <<"\t minPt " << selectionParameters.minPt
196  <<"\t theTrackQuality " << theTrackQuality
197  <<"\t minQuality " << selectionParameters.minQuality
198  <<"\t maxDxyPV " << selectionParameters.maxDxyPV
199  <<"\t maxDzPV " << selectionParameters.maxDzPV
200  <<"\t maxChi2 " << selectionParameters.maxChi2
201  <<"\t maxDpOverP " << selectionParameters.maxDpOverP
202  <<"\t minOuterHit " << selectionParameters.minOuterHit
203  <<"\t minLayerCrossed " << selectionParameters.minLayerCrossed
204  <<"\t maxInMiss " << selectionParameters.maxInMiss
205  <<"\t maxOutMiss " << selectionParameters.maxOutMiss
206  <<"\t a_coneR " << a_coneR
207  <<"\t a_charIsoR " << a_charIsoR
208  <<"\t a_mipR " << a_mipR
209  <<"\t qcdMC " << qcdMC
210  << std::endl;
211  std::cout << "Process " << processName << " L1Filter:" << l1Filter
212  << " L2Filter:" << l2Filter << " L3Filter:" << l3Filter
213  << std::endl;
214  std::cout << trigNames.size() << " triggers to be studied";
215  for (unsigned int k=0; k<trigNames.size(); ++k)
216  std::cout << ": " << trigNames[k];
217  std::cout << std::endl;
218  }
219 #endif
220 }
221 
223  // do anything here that needs to be done at desctruction time
224  // (e.g. close files, deallocate resources etc.)
225  if (t_trgbits) delete t_trgbits;
226  if (t_DetIds) delete t_DetIds;
227  if (t_HitEnergies) delete t_HitEnergies;
228 
229 }
230 
232  const edm::EventSetup& iSetup) {
233 
234  t_Run = iEvent.id().run();
235  t_Event = iEvent.id().event();
236  nAll++;
237 #ifdef DebugLog
238  if (verbosity%10 > 0)
239  std::cout << "Run " << t_Run << " Event " << t_Event << " Luminosity "
240  << iEvent.luminosityBlock() << " Bunch " << iEvent.bunchCrossing()
241  << " starts ==========" << std::endl;
242 #endif
243  //Get magnetic field and ECAL channel status
245  iSetup.get<IdealMagneticFieldRecord>().get(bFieldH);
246  const MagneticField *bField = bFieldH.product();
247 
249  iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
250 
251  // get handles to calogeometry and calotopology
253  iSetup.get<CaloGeometryRecord>().get(pG);
254  const CaloGeometry* geo = pG.product();
255 
256  //Get track collection
258  iEvent.getByToken(tok_genTrack_, trkCollection);
259  reco::TrackCollection::const_iterator trkItr;
260 
261  //event weight for FLAT sample and PU information
262  t_EventWeight = 1.0;
264  iEvent.getByToken(tok_ew_, genEventInfo);
265  if (genEventInfo.isValid()) t_EventWeight = genEventInfo->weight();
266  t_npvtruth = t_npvObserved = 999;
268  iEvent.getByToken(tok_pu_, PupInfo);
269  if (PupInfo.isValid()) {
270  std::vector<PileupSummaryInfo>::const_iterator PVI;
271  for (PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
272  int BX = PVI->getBunchCrossing();
273  if (BX==0) {
274  t_npvtruth = PVI->getTrueNumInteractions();
275  t_npvObserved = PVI->getPU_NumInteractions();
276  break;
277  }
278  }
279  }
280  int ivtx = (int)(vbin.size()-2);
281  for (unsigned int iv=1; iv<vbin.size(); ++iv) {
282 #ifdef DebugLog
283  std::cout << "Bin " << iv << " " << vbin[iv-1] << ":" << vbin[iv] << std::endl;
284 #endif
285  if (t_npvtruth <= vbin[iv]) {
286  ivtx = iv-1; break;
287  }
288  }
289 #ifdef DebugLog
290  if (verbosity == 0)
291  std::cout << "PU Vertex " << t_npvtruth << "/" << t_npvObserved << " IV "
292  << ivtx << ":" << vbin.size() << std::endl;
293 #endif
294  //=== genJet information
296  iEvent.getByToken(tok_jets_, genJets);
297  if (genJets.isValid()) {
298  for (unsigned iGenJet = 0; iGenJet < genJets->size(); ++iGenJet) {
299  const reco::GenJet& genJet = (*genJets) [iGenJet];
300  double genJetPt = genJet.pt();
301  double genJetEta = genJet.eta();
302  h_jetpt[0]->Fill(genJetPt);
303  h_jetpt[1]->Fill(genJetPt,t_EventWeight);
304  if (genJetEta>-2.5 && genJetEta<2.5) {
305  h_jetpt[2]->Fill(genJetPt);
306  h_jetpt[3]->Fill(genJetPt,t_EventWeight);
307  }
308  }
309  }
310 
311  //Define the best vertex and the beamspot
313  iEvent.getByToken(tok_recVtx_, recVtxs);
314  edm::Handle<reco::BeamSpot> beamSpotH;
315  iEvent.getByToken(tok_bs_, beamSpotH);
316  math::XYZPoint leadPV(0,0,0);
317  if (recVtxs->size()>0 && !((*recVtxs)[0].isFake())) {
318  leadPV = math::XYZPoint( (*recVtxs)[0].x(),(*recVtxs)[0].y(), (*recVtxs)[0].z() );
319  } else if (beamSpotH.isValid()) {
320  leadPV = beamSpotH->position();
321  }
322 #ifdef DebugLog
323  if ((verbosity/100)%10>0) {
324  std::cout << "Primary Vertex " << leadPV;
325  if (beamSpotH.isValid()) std::cout << " Beam Spot "
326  << beamSpotH->position();
327  std::cout << std::endl;
328  }
329 #endif
330  // RecHits
331  edm::Handle<EcalRecHitCollection> barrelRecHitsHandle;
332  edm::Handle<EcalRecHitCollection> endcapRecHitsHandle;
333  iEvent.getByToken(tok_EB_, barrelRecHitsHandle);
334  iEvent.getByToken(tok_EE_, endcapRecHitsHandle);
336  iEvent.getByToken(tok_hbhe_, hbhe);
338 
339  for (rhitItr=hbhe->begin();rhitItr!=hbhe->end();rhitItr++) {
340  double rec_energy = rhitItr->energy();
341  int rec_ieta = rhitItr->id().ieta();
342  int rec_depth = rhitItr->id().depth();
343  int rec_zside = rhitItr->id().zside();
344  double num1_1 = rec_zside*(rec_ieta+0.2*(rec_depth-1));
345 #ifdef DebugLog
346  if (verbosity%10>0)
347  std::cout << "detid/rechit/ieta/zside/depth/num = " << rhitItr->id()
348  << "/" << rec_energy << "/" << rec_ieta << "/" << rec_zside
349  << "/" << rec_depth << "/" << num1_1 << std::endl;
350 #endif
351  h_iEta->Fill(rec_ieta);
352  h_Rechit_E->Fill(rec_energy);
353  h_RecHit_iEta->Fill(rec_ieta,rec_energy);
354  h_RecHit_num->Fill(num1_1,rec_energy);
355  }
356 
357  //Propagate tracks to calorimeter surface)
358  std::vector<spr::propagatedTrackDirection> trkCaloDirections;
359  spr::propagateCALO(trkCollection, geo, bField, theTrackQuality,
360  trkCaloDirections, ((verbosity/100)%10>2));
361  std::vector<spr::propagatedTrackDirection>::const_iterator trkDetItr;
362  for (trkDetItr = trkCaloDirections.begin();
363  trkDetItr != trkCaloDirections.end(); trkDetItr++) {
364  if (trkDetItr->okHCAL) {
365  HcalDetId detId = (HcalDetId)(trkDetItr->detIdHCAL);
366  int tk_ieta = detId.ieta();
367  const reco::Track* pTrack = &(*(trkDetItr->trkItr));
368  double tk_p = pTrack->p();
369  h_tketa0[0]->Fill(tk_ieta);
370  h_tketav1[ivtx][0]->Fill(tk_ieta);
371 #ifdef DebugLog
372  std::cout << "Fill for " << tk_ieta << " in " << ivtx << ":"
373  << h_tketav1[ivtx][0]->GetName() << std::endl;
374 #endif
375  for (unsigned int k=1; k<pbin.size(); ++k) {
376  if (tk_p >= pbin[k-1] && tk_p < pbin[k]) {
377  h_tketa0[k]->Fill(tk_ieta);
378  h_tketav1[ivtx][k]->Fill(tk_ieta);
379 #ifdef DebugLog
380  std::cout << "Fill for " << tk_ieta << ":" << tk_p << " in " << ivtx
381  << ":" << h_tketav1[ivtx][k]->GetName() << std::endl;
382 #endif
383  break;
384  }
385  }
386  }
387  }
388 
389  //Trigger
390  t_trgbits->clear();
391  for (unsigned int i=0; i<trigNames.size(); ++i) t_trgbits->push_back(false);
392 
393  trigger::TriggerEvent triggerEvent;
394  edm::Handle<trigger::TriggerEvent> triggerEventHandle;
395  iEvent.getByToken(tok_trigEvt, triggerEventHandle);
396  if (!triggerEventHandle.isValid()) {
397 #ifdef DebugLog
398  std::cout << "Error! Can't get the product "<< triggerEvent_.label()
399  << std::endl;
400 #endif
401  } else {
402  triggerEvent = *(triggerEventHandle.product());
403 
404  const trigger::TriggerObjectCollection& TOC(triggerEvent.getObjects());
407  iEvent.getByToken(tok_trigRes, triggerResults);
408  if (triggerResults.isValid()) {
409  std::vector<std::string> modules;
410  const edm::TriggerNames & triggerNames = iEvent.triggerNames(*triggerResults);
411  const std::vector<std::string> & triggerNames_ = triggerNames.triggerNames();
412  for (unsigned int iHLT=0; iHLT<triggerResults->size(); iHLT++) {
413  bool ok(false);
414  int hlt = triggerResults->accept(iHLT);
415  for (unsigned int i=0; i<trigNames.size(); ++i) {
416  if (triggerNames_[iHLT].find(trigNames[i].c_str())!=std::string::npos) {
417  t_trgbits->at(i) = (hlt>0);
418  trigKount[i]++;
419  if (hlt > 0) {
420  ok = true;
421  trigPass[i]++;
422  }
423 #ifdef DebugLog
424  if (verbosity%10 > 0)
425  std::cout << "This is the trigger we are looking for "
426  << triggerNames_[iHLT] << " Flag " << hlt << ":"
427  << ok << std::endl;
428 #endif
429  }
430  }
431 
432  if (ok) {
433  unsigned int triggerindx = hltConfig_.triggerIndex(triggerNames_[iHLT]);
434  const std::vector<std::string>& moduleLabels(hltConfig_.moduleLabels(triggerindx));
435  std::vector<math::XYZTLorentzVector> vec[3];
436  //loop over all trigger filters in event (i.e. filters passed)
437  for (unsigned int ifilter=0; ifilter<triggerEvent.sizeFilters();
438  ++ifilter) {
439  std::vector<int> Keys;
440  std::string label = triggerEvent.filterTag(ifilter).label();
441  //loop over keys to objects passing this filter
442  for (unsigned int imodule=0; imodule<moduleLabels.size();
443  imodule++) {
444  if (label.find(moduleLabels[imodule]) != std::string::npos) {
445 #ifdef DebugLog
446  if (verbosity%10 > 0) std::cout << "FilterName " << label << std::endl;
447 #endif
448  for (unsigned int ifiltrKey=0; ifiltrKey<triggerEvent.filterKeys(ifilter).size(); ++ifiltrKey) {
449  Keys.push_back(triggerEvent.filterKeys(ifilter)[ifiltrKey]);
450  const trigger::TriggerObject& TO(TOC[Keys[ifiltrKey]]);
451  math::XYZTLorentzVector v4(TO.px(), TO.py(), TO.pz(), TO.energy());
452  if (qcdMC) {
453  if (label.find("hltL1s") != std::string::npos) {
454  vec[0].push_back(v4);
455  } else if (label.find("PFJet") != std::string::npos) {
456  vec[2].push_back(v4);
457  } else {
458  vec[1].push_back(v4);
459  }
460  } else {
461  if (label.find(l2Filter) != std::string::npos) {
462  vec[1].push_back(v4);
463  } else if (label.find(l3Filter) != std::string::npos) {
464  vec[2].push_back(v4);
465  } else if (label.find(l1Filter) != std::string::npos ||
466  l1Filter == "") {
467  vec[0].push_back(v4);
468  }
469  }
470 #ifdef DebugLog
471  if (verbosity%10 > 2)
472  std::cout << "key " << ifiltrKey << " : pt " << TO.pt()
473  << " eta " << TO.eta() << " phi " << TO.phi()
474  << " mass " << TO.mass() << " Id " << TO.id()
475  << std::endl;
476 #endif
477  }
478 #ifdef DebugLog
479  if (verbosity%10 > 0) std::cout << "sizes " << vec[0].size()
480  << ":" << vec[1].size() << ":"
481  << vec[2].size() << std::endl;
482 #endif
483  }
484  }
485  }
486  double dr;
488  math::XYZTLorentzVector mindRvec1;
489  double mindR1(999);
490  for (int lvl=1; lvl<3; lvl++) {
491  for (unsigned int i=0; i<vec[lvl].size(); i++) {
492  dr = dR(vec[0][0],vec[lvl][i]);
493 #ifdef DebugLog
494  if (verbosity%10 > 2) std::cout << "lvl " <<lvl << " i " << i
495  << " dR " << dr << std::endl;
496 #endif
497  if (dr<mindR1) {
498  mindR1 = dr;
499  mindRvec1 = vec[lvl][i];
500  }
501  }
502  }
503 
504  t_l1pt = vec[0][0].pt();
505  t_l1eta = vec[0][0].eta();
506  t_l1phi = vec[0][0].phi();
507  if (vec[2].size()>0) {
508  t_l3pt = vec[2][0].pt();
509  t_l3eta = vec[2][0].eta();
510  t_l3phi = vec[2][0].phi();
511  }
512  //Loop over tracks
513  std::vector<spr::propagatedTrackDirection>::const_iterator trkDetItr;
514  unsigned int nTracks(0), nselTracks(0);
515  for (trkDetItr = trkCaloDirections.begin(),nTracks=0;
516  trkDetItr != trkCaloDirections.end(); trkDetItr++,nTracks++) {
517  const reco::Track* pTrack = &(*(trkDetItr->trkItr));
518  math::XYZTLorentzVector v4(pTrack->px(), pTrack->py(),
519  pTrack->pz(), pTrack->p());
520 #ifdef DebugLog
521  if (verbosity%10> 0)
522  std::cout << "This track : " << nTracks << " (pt/eta/phi/p) :"
523  << pTrack->pt() << "/" << pTrack->eta() << "/"
524  << pTrack->phi() << "/" << pTrack->p() << std::endl;
525 #endif
526  math::XYZTLorentzVector mindRvec2;
527  t_mindR2 = 999;
528 
529  for (unsigned int k=0; k<vec[2].size(); ++k) {
530  dr = dR(vec[2][k],v4); //changed 1 to 2
531  if (dr<t_mindR2) {
532  t_mindR2 = dr;
533  mindRvec2 = vec[2][k];
534  }
535  }
536  t_mindR1 = dR(vec[0][0],v4);
537 #ifdef DebugLog
538  if (verbosity%10> 2)
539  std::cout << "Closest L3 object at mindr :" << t_mindR2 << " is "
540  << mindRvec2 << " and from L1 " << t_mindR1 <<std::endl;
541 #endif
542 
543  //Selection of good track
544  t_selectTk = spr::goodTrack(pTrack,leadPV,selectionParameters,((verbosity/100)%10>2));
546  oneCutParameters.maxDxyPV = 10;
547  oneCutParameters.maxDzPV = 100;
548  oneCutParameters.maxInMiss = 2;
549  oneCutParameters.maxOutMiss= 2;
550  bool qltyFlag = spr::goodTrack(pTrack,leadPV,oneCutParameters,((verbosity/100)%10>2));
551  oneCutParameters = selectionParameters;
552  oneCutParameters.maxDxyPV = 10;
553  oneCutParameters.maxDzPV = 100;
554  t_qltyMissFlag = spr::goodTrack(pTrack,leadPV,oneCutParameters,((verbosity/100)%10>2));
555  oneCutParameters = selectionParameters;
556  oneCutParameters.maxInMiss = 2;
557  oneCutParameters.maxOutMiss= 2;
558  t_qltyPVFlag = spr::goodTrack(pTrack,leadPV,oneCutParameters,((verbosity/100)%10>2));
559  t_ieta = 0;
560  if (trkDetItr->okHCAL) {
561  HcalDetId detId = (HcalDetId)(trkDetItr->detIdHCAL);
562  t_ieta = detId.ieta();
563  }
564 #ifdef DebugLog
565  if (verbosity%10 > 0)
566  std::cout << "qltyFlag|okECAL|okHCAL : " << qltyFlag << "|"
567  << trkDetItr->okECAL << "/" << trkDetItr->okHCAL
568  << std::endl;
569 #endif
570  t_qltyFlag = (qltyFlag && trkDetItr->okECAL && trkDetItr->okHCAL);
571  t_p = pTrack->p();
572  h_tketa1[0]->Fill(t_ieta);
573  for (unsigned int k=1; k<pbin.size(); ++k) {
574  if (t_p >= pbin[k-1] && t_p < pbin[k]) {
575  h_tketa1[k]->Fill(t_ieta);
576  break;
577  }
578  }
579  if (t_qltyFlag) {
580  nselTracks++;
581  h_tketa2[0]->Fill(t_ieta);
582  for (unsigned int k=1; k<pbin.size(); ++k) {
583  if (t_p >= pbin[k-1] && t_p < pbin[k]) {
584  h_tketa2[k]->Fill(t_ieta);
585  break;
586  }
587  }
588  int nRH_eMipDR(0), nNearTRKs(0), nRecHits(-999);
589  t_eMipDR = spr::eCone_ecal(geo, barrelRecHitsHandle,
590  endcapRecHitsHandle,
591  trkDetItr->pointHCAL,
592  trkDetItr->pointECAL,
593  a_mipR, trkDetItr->directionECAL,
594  nRH_eMipDR);
595  t_DetIds->clear(); t_HitEnergies->clear();
596  std::vector<DetId> ids;
597  t_eHcal = spr::eCone_hcal(geo, hbhe, trkDetItr->pointHCAL,
598  trkDetItr->pointECAL, a_coneR,
599  trkDetItr->directionHCAL,nRecHits,
600  ids, *t_HitEnergies);
601  for (unsigned int k=0; k<ids.size(); ++k) {
602  t_DetIds->push_back(ids[k].rawId());
603  }
604  t_hmaxNearP = spr::chargeIsolationCone(nTracks,trkCaloDirections,
605  a_charIsoR, nNearTRKs,
606  ((verbosity/100)%10>2));
607  if (t_hmaxNearP < 2) {
608  h_tketa3[0]->Fill(t_ieta);
609  for (unsigned int k=1; k<pbin.size(); ++k) {
610  if (t_p >= pbin[k-1] && t_p < pbin[k]) {
611  h_tketa3[k]->Fill(t_ieta);
612  break;
613  }
614  }
615  if (t_eMipDR < 1) {
616  h_tketa4[0]->Fill(t_ieta);
617  for (unsigned int k=1; k<pbin.size(); ++k) {
618  if (t_p >= pbin[k-1] && t_p < pbin[k]) {
619  h_tketa4[k]->Fill(t_ieta);
620  break;
621  }
622  }
623  if (t_mindR1 > 1) {
624  h_tketa5[0]->Fill(t_ieta);
625  h_tketav2[ivtx][0]->Fill(t_ieta);
626  for (unsigned int k=1; k<pbin.size(); ++k) {
627  if (t_p >= pbin[k-1] && t_p < pbin[k]) {
628  h_tketa5[k]->Fill(t_ieta);
629  h_tketav2[ivtx][k]->Fill(t_ieta);
630  break;
631  }
632  }
633  }
634  }
635  }
636 #ifdef DebugLog
637  if (verbosity%10 > 0) {
638  std::cout << "This track : " << nTracks << " (pt/eta/phi/p) :"
639  << pTrack->pt() << "/" << pTrack->eta() << "/"
640  << pTrack->phi() << "/" << t_p << std::endl;
641  std::cout << "e_MIP " << t_eMipDR << " Chg Isolation "
642  << t_hmaxNearP << " eHcal" << t_eHcal << " ieta "
643  << t_ieta << " Quality " << t_qltyMissFlag
644  << ":" << t_qltyPVFlag << ":" << t_selectTk
645  << std::endl;
646  for (unsigned int lll=0;lll<t_DetIds->size();lll++) {
647  std::cout << "det id is = " << t_DetIds->at(lll) << " "
648  << " hit enery is = " << t_HitEnergies->at(lll)
649  << std::endl;
650  }
651  }
652 #endif
653  if (t_p>pTrackMin_ && t_eMipDR<eEcalMax_ &&
655 #ifdef DebugLog
656  if (verbosity%10> 2) {
657  for (unsigned int k=0; k<t_trgbits->size(); k++)
658  std::cout <<"trigger bit is = " << t_trgbits->at(k)
659  << std::endl;
660  }
661 #endif
662  tree->Fill();
663  nGood++;
664  }
665  }
666  }
667  }
668  }
669  t_trgbits->clear(); t_DetIds->clear(); t_HitEnergies->clear();
670  // check if trigger names in (new) config
671  if (changed) {
672  changed = false;
673 #ifdef DebugLog
674  if (verbosity%10> 1) {
675  std::cout<<"New trigger menu found !!!" << std::endl;
676  const unsigned int n(hltConfig_.size());
677  for (unsigned itrig=0; itrig<triggerNames_.size(); itrig++) {
678  unsigned int triggerindx = hltConfig_.triggerIndex(triggerNames_[itrig]);
679  std::cout << triggerNames_[itrig] << " " << triggerindx << " ";
680  if (triggerindx >= n)
681  std::cout << "does not exist in the current menu" << std::endl;
682  else
683  std::cout << "exists" << std::endl;
684  }
685  }
686 #endif
687  }
688  }
689  }
690 }
691 
693  h_RecHit_iEta = fs->make<TProfile>("rechit_ieta","Rec hit vs. ieta",60,-30,30,0,1000);
694  h_RecHit_num = fs->make<TProfile>("rechit_num","Rec hit vs. num",100,0,20,0,1000);
695  h_iEta = fs->make<TH1I>("iEta","iEta",60,-30,30);
696  h_Rechit_E = fs->make<TH1F>("Rechit_E","Rechit_E",100,0,1000);
697 
698  double prange[5] = {20,30,40,60,100};
699  for (int k=0; k<5; ++k) pbin.push_back(prange[k]);
700  std::string type[6] = {"All", "Trigger OK", "Tree Selected",
701  "Charge Isolation", "MIP Cut", "L1 Cut"};
702  double vrange[6] = {0, 10, 20, 30, 40, 1000};
703  for (int k=0; k<6; ++k) vbin.push_back(vrange[k]);
704  char name[20], namp[20], title[100];
705  for (unsigned int k=0; k<pbin.size(); ++k) {
706  if (k == 0) sprintf (namp, "all momentum");
707  else sprintf (namp, "p = %4.0f:%4.0f GeV", pbin[k-1], pbin[k]);
708  sprintf (name, "TrackEta0%d", k);
709  sprintf (title, "Track #eta for tracks with %s (%s)",namp,type[0].c_str());
710  h_tketa0[k] = fs->make<TH1I>(name, title, 60, -30, 30);
711  sprintf (name, "TrackEta1%d", k);
712  sprintf (title, "Track #eta for tracks with %s (%s)",namp,type[1].c_str());
713  h_tketa1[k] = fs->make<TH1I>(name, title, 60, -30, 30);
714  sprintf (name, "TrackEta2%d", k);
715  sprintf (title, "Track #eta for tracks with %s (%s)",namp,type[2].c_str());
716  h_tketa2[k] = fs->make<TH1I>(name, title, 60, -30, 30);
717  sprintf (name, "TrackEta3%d", k);
718  sprintf (title, "Track #eta for tracks with %s (%s)",namp,type[3].c_str());
719  h_tketa3[k] = fs->make<TH1I>(name, title, 60, -30, 30);
720  sprintf (name, "TrackEta4%d", k);
721  sprintf (title, "Track #eta for tracks with %s (%s)",namp,type[4].c_str());
722  h_tketa4[k] = fs->make<TH1I>(name, title, 60, -30, 30);
723  sprintf (name, "TrackEta5%d", k);
724  sprintf (title, "Track #eta for tracks with %s (%s)",namp,type[5].c_str());
725  h_tketa5[k] = fs->make<TH1I>(name, title, 60, -30, 30);
726  for (unsigned int l=0; l<vbin.size()-1; ++l) {
727  int v1 = (int)(vbin[l]);
728  int v2 = (int)(vbin[l+1]);
729  sprintf (name, "TrackEta1%dVtx%d", k, l);
730  sprintf (title, "Track #eta for tracks with %s (%s and PU %d:%d)",namp,type[0].c_str(),v1,v2);
731  h_tketav1[l][k] = fs->make<TH1I>(name, title, 60, -30, 30);
732  sprintf (name, "TrackEta2%dVtx%d", k, l);
733  sprintf (title, "Track #eta for tracks with %s (%s and PU %d:%d)",namp,type[5].c_str(),v1,v2);
734  h_tketav2[l][k] = fs->make<TH1I>(name, title, 60, -30, 30);
735  }
736  }
737  h_jetpt[0] = fs->make<TH1F>("Jetpt0","Jet p_T (All)", 500,0.,2500.);
738  h_jetpt[1] = fs->make<TH1F>("Jetpt1","Jet p_T (All Weighted)", 500,0.,2500.);
739  h_jetpt[2] = fs->make<TH1F>("Jetpt2","Jet p_T (|#eta| < 2.5)", 500,0.,2500.);
740  h_jetpt[3] = fs->make<TH1F>("Jetpt3","Jet p_T (|#eta| < 2.5 Weighted)", 500,0.,2500.);
741  tree = fs->make<TTree>("CalibTree", "CalibTree");
742 
743 
744  tree->Branch("t_Run", &t_Run, "t_Run/I");
745  tree->Branch("t_Event", &t_Event, "t_Event/I");
746  tree->Branch("t_ieta", &t_ieta, "t_ieta/I");
747  tree->Branch("t_EventWeight", &t_EventWeight, "t_EventWeight/D");
748  tree->Branch("t_npvtruth", &t_npvtruth, "t_npvtruth/D");
749  tree->Branch("t_npvObserved", &t_npvObserved, "t_npvObserved/D");
750  tree->Branch("t_l1pt", &t_l1pt, "t_l1pt/D");
751  tree->Branch("t_l1eta", &t_l1eta, "t_l1eta/D");
752  tree->Branch("t_l1phi", &t_l1phi, "t_l1phi/D");
753  tree->Branch("t_l3pt", &t_l3pt, "t_l3pt/D");
754  tree->Branch("t_l3eta", &t_l3eta, "t_l3eta/D");
755  tree->Branch("t_l3phi", &t_l3phi, "t_l3phi/D");
756  tree->Branch("t_p", &t_p, "t_p/D");
757  tree->Branch("t_mindR1", &t_mindR1, "t_mindR1/D");
758  tree->Branch("t_mindR2", &t_mindR2, "t_mindR2/D");
759  tree->Branch("t_eMipDR", &t_eMipDR, "t_eMipDR/D");
760  tree->Branch("t_eHcal", &t_eHcal, "t_eHcal/D");
761  tree->Branch("t_hmaxNearP", &t_hmaxNearP, "t_hmaxNearP/D");
762  tree->Branch("t_selectTk", &t_selectTk, "t_selectTk/O");
763  tree->Branch("t_qltyFlag", &t_qltyFlag, "t_qltyFlag/O");
764  tree->Branch("t_qltyMissFlag",&t_qltyMissFlag,"t_qltyMissFlag/O");
765  tree->Branch("t_qltyPVFlag", &t_qltyPVFlag, "t_qltyPVFlag/O)");
766 
767  t_DetIds = new std::vector<unsigned int>();
768  t_HitEnergies = new std::vector<double>();
769  t_trgbits = new std::vector<bool>();
770  tree->Branch("t_DetIds", "std::vector<unsigned int>", &t_DetIds);
771  tree->Branch("t_HitEnergies", "std::vector<double>", &t_HitEnergies);
772  tree->Branch("t_trgbits", "std::vector<bool>", &t_trgbits);
773 }
774 
775 // ------------ method called once each job just after ending the event loop ------------
777  edm::LogWarning("IsoTrack") << "Finds " << nGood << " good tracks in "
778  << nAll << " events from " << nRun << " runs";
779  for (unsigned int k=0; k<trigNames.size(); ++k)
780  edm::LogWarning("IsoTrack") << "Trigger[" << k << "]: " << trigNames[k]
781  << " Events " << trigKount[k] << " Passed "
782  << trigPass[k];
783 }
784 
785 // ------------ method called when starting to processes a run ------------
786 void IsoTrackCalibration::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
787  edm::LogWarning("IsoTrack") << "Run[" << nRun <<"] " << iRun.run()
788  << " hltconfig.init " << hltConfig_.init(iRun,iSetup,processName,changed);
789 }
790 
791 // ------------ method called when ending the processing of a run ------------
793  nRun++;
794  edm::LogWarning("IsoTrack") << "endRun[" << nRun << "] " << iRun.run();
795 }
796 
797 // ------------ method called when starting to processes a luminosity block ------------
799 // ------------ method called when ending the processing of a luminosity block ------------
801 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
803  //The following says we do not know what parameters are allowed so do no validation
804  // Please change this to state exactly what you do use, even if it is no parameters
806  desc.setUnknown();
807  descriptions.addDefault(desc);
808 }
809 
811  return reco::deltaR(vec1.eta(),vec1.phi(),vec2.eta(),vec2.phi());
812 }
813 
814 //define this as a plug-in
816 
RunNumber_t run() const
Definition: EventID.h:39
std::vector< int > trigPass
unsigned int size() const
number of trigger paths in trigger table
double p() const
momentum vector magnitude
Definition: TrackBase.h:602
type
Definition: HCALResponse.h:21
std::vector< bool > * t_trgbits
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
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:220
std::vector< spr::propagatedTrackID > propagateCALO(edm::Handle< reco::TrackCollection > &trkCollection, const CaloGeometry *geo, const MagneticField *bField, std::string &theTrackQuality, bool debug=false)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
edm::EDGetTokenT< reco::BeamSpot > tok_bs_
int id() const
getters
Definition: TriggerObject.h:55
RunNumber_t run() const
Definition: RunBase.h:42
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:25
trigger::size_type sizeFilters() const
Definition: TriggerEvent.h:135
edm::EDGetTokenT< reco::TrackCollection > tok_genTrack_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
float phi() const
Definition: TriggerObject.h:58
TrackQuality
track quality
Definition: TrackBase.h:149
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:111
std::vector< HBHERecHit >::const_iterator const_iterator
virtual void beginRun(edm::Run const &, edm::EventSetup const &)
int bunchCrossing() const
Definition: EventBase.h:66
std::vector< int > trigKount
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
std::vector< std::string > trigNames
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:632
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
float energy() const
Definition: TriggerObject.h:65
double chargeIsolationCone(unsigned int trkIndex, std::vector< spr::propagatedTrackDirection > &trkDirs, double dR, int &nNearTRKs, bool debug=false)
double deltaR(const T1 &t1, const T2 &t2)
Definition: deltaR.h:48
float eta() const
Definition: TriggerObject.h:57
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:614
virtual void endRun(edm::Run const &, edm::EventSetup const &)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
edm::InputTag theTriggerResultsLabel
Strings const & triggerNames() const
Definition: TriggerNames.cc:24
std::vector< double > vbin
edm::EDGetTokenT< EcalRecHitCollection > tok_EE_
virtual double eta() const
momentum pseudorapidity
virtual double pt() const
transverse momentum
unsigned int triggerIndex(const std::string &triggerName) const
slot position of trigger path in trigger table (0 to size-1)
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:22
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
edm::EDGetTokenT< edm::TriggerResults > tok_trigRes
int iEvent
Definition: GenABIO.cc:230
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:638
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< std::string > HLTNames
edm::EDGetTokenT< GenEventInfoProduct > tok_ew_
bool goodTrack(const reco::Track *pTrack, math::XYZPoint leadPV, trackSelectionParameters parameters, bool debug=false)
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:98
std::vector< double > vec1
Definition: HCALResponse.h:15
double pt() const
track transverse momentum
Definition: TrackBase.h:608
int ieta() const
get the cell ieta
Definition: HcalDetId.h:51
Jets made from MC generator particles.
Definition: GenJet.h:24
double eCone_ecal(const CaloGeometry *geo, edm::Handle< T > &barrelhits, edm::Handle< T > &endcaphits, const GlobalPoint &hpoint1, const GlobalPoint &point1, double dR, const GlobalVector &trackMom, int &nRecHits, double ebThr=-100, double eeThr=-100, double tMin=-500, double tMax=500, bool debug=false)
edm::Service< TFileService > fs
static std::string const triggerResults
Definition: EdmProvDump.cc:40
IsoTrackCalibration(const edm::ParameterSet &)
bool isValid() const
Definition: HandleBase.h:75
std::vector< double > * t_HitEnergies
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:626
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:81
edm::EDGetTokenT< HBHERecHitCollection > tok_hbhe_
const edm::InputTag filterTag(trigger::size_type index) const
Definition: TriggerEvent.h:103
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:123
T const * product() const
Definition: Handle.h:81
double eCone_hcal(const CaloGeometry *geo, edm::Handle< T > &hits, const GlobalPoint &hpoint1, const GlobalPoint &point1, double dR, const GlobalVector &trackMom, int &nRecHits, double hbThr=-100, double heThr=-100, double hfThr=-100, double hoThr=-100, double tMin=-500, double tMax=500, int detOnly=-1, bool debug=false)
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > tok_pu_
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
std::vector< size_type > Keys
double dR(math::XYZTLorentzVector &, math::XYZTLorentzVector &)
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
const T & get() const
Definition: EventSetup.h:56
std::vector< double > pbin
T const * product() const
Definition: ESHandle.h:86
edm::EDGetTokenT< EcalRecHitCollection > tok_EB_
std::string const & label() const
Definition: InputTag.h:43
edm::EDGetTokenT< trigger::TriggerEvent > tok_trigEvt
edm::EventID id() const
Definition: EventBase.h:60
spr::trackSelectionParameters selectionParameters
reco::TrackBase::TrackQuality minQuality
edm::EDGetTokenT< reco::GenJetCollection > tok_jets_
tuple cout
Definition: gather_cfg.py:121
volatile std::atomic< bool > shutdown_flag false
float mass() const
Definition: TriggerObject.h:59
std::vector< vec1 > vec2
Definition: HCALResponse.h:16
std::vector< unsigned int > * t_DetIds
HLTConfigProvider hltConfig_
tuple size
Write out results.
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:620
Definition: Run.h:43
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
edm::EDGetTokenT< reco::VertexCollection > tok_recVtx_