CMS 3D CMS Logo

IsoTrackCalib.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // Root objects
5 #include "TROOT.h"
6 #include "TSystem.h"
7 #include "TFile.h"
8 #include "TProfile.h"
9 #include "TDirectory.h"
10 #include "TTree.h"
11 #include "TLorentzVector.h"
12 #include "TInterpreter.h"
13 
19 
20  //L1 trigger Menus etc
26 
30 
31 //Tracks
36 // Vertices
40 // Jets
44 
45 //Triggers
52 
62 
65 
74 
77 
81 
82 class IsoTrackCalib : public edm::one::EDAnalyzer<edm::one::WatchRuns,edm::one::SharedResources> {
83 
84 public:
85  explicit IsoTrackCalib(const edm::ParameterSet&);
86  ~IsoTrackCalib() override;
87 
88  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
89 
90 private:
91  void beginJob() override ;
92  void analyze(const edm::Event&, const edm::EventSetup&) override;
93  void endJob() override {}
94  void beginRun(edm::Run const&, edm::EventSetup const&) override;
95  void endRun(edm::Run const&, edm::EventSetup const&) override;
96 
100  double deltaR(double eta1,double eta2,double phi1,double phi2);
101 
105  std::vector<std::string> l1Names_;
111  std::vector<bool> *t_l1bits;
115 
128 
129  TTree *tree;
134 
136  std::vector<unsigned int> *t_DetIds;
137  std::vector<double> *t_HitEnergies, pbin;
139  TH1I *h_iEta, *h_tkEta0[5], *h_tkEta1[5], *h_tkEta2[5];
140  TH1I *h_tkEta3[5], *h_tkEta4[5], *h_tkEta5[5];
142  TH1F *h_jetpt[4];
143  TH1I *h_tketa0[6], *h_tketa1[6], *h_tketa2[6];
144  TH1I *h_tketa3[6], *h_tketa4[6],*h_tketa5[6];
145  std::map< std::pair<unsigned int,std::string>, int> l1AlgoMap_;
146 };
147 
148 static const bool useL1GtTriggerMenuLite(true);
151 
152  usesResource("TFileService");
153 
154  //now do whatever initialization is needed
155  verbosity_ = iConfig.getUntrackedParameter<int>("Verbosity",0);
156  l1Names_ = iConfig.getUntrackedParameter<std::vector<std::string> >("L1Seed");
157  theTrackQuality_ = iConfig.getUntrackedParameter<std::string>("TrackQuality","highPurity");
158  reco::TrackBase::TrackQuality trackQuality_=reco::TrackBase::qualityByName(theTrackQuality_);
159  selectionParameters_.minPt = iConfig.getUntrackedParameter<double>("MinTrackPt", 10.0);
160  selectionParameters_.minQuality = trackQuality_;
161  selectionParameters_.maxDxyPV = iConfig.getUntrackedParameter<double>("MaxDxyPV", 0.2);
162  selectionParameters_.maxDzPV = iConfig.getUntrackedParameter<double>("MaxDzPV", 5.0);
163  selectionParameters_.maxChi2 = iConfig.getUntrackedParameter<double>("MaxChi2", 5.0);
164  selectionParameters_.maxDpOverP = iConfig.getUntrackedParameter<double>("MaxDpOverP", 0.1);
165  selectionParameters_.minOuterHit = iConfig.getUntrackedParameter<int>("MinOuterHit", 4);
166  selectionParameters_.minLayerCrossed= iConfig.getUntrackedParameter<int>("MinLayerCrossed", 8);
167  selectionParameters_.maxInMiss = iConfig.getUntrackedParameter<int>("MaxInMiss", 0);
168  selectionParameters_.maxOutMiss = iConfig.getUntrackedParameter<int>("MaxOutMiss", 0);
169  a_coneR_ = iConfig.getUntrackedParameter<double>("ConeRadius",34.98);
170  a_charIsoR_ = a_coneR_ + 28.9;
171  a_mipR_ = iConfig.getUntrackedParameter<double>("ConeRadiusMIP",14.0);
172  bool isItAOD = iConfig.getUntrackedParameter<bool>("IsItAOD", false);
173  triggerEvent_ = edm::InputTag("hltTriggerSummaryAOD","","HLT");
174  theTriggerResultsLabel_ = edm::InputTag("TriggerResults","","HLT");
175  edm::InputTag L1extraTauJetSource_ = iConfig.getParameter<edm::InputTag> ("L1extraTauJetSource" );
176  edm::InputTag L1extraCenJetSource_ = iConfig.getParameter<edm::InputTag> ("L1extraCenJetSource" );
177  edm::InputTag L1extraFwdJetSource_ = iConfig.getParameter<edm::InputTag> ("L1extraFwdJetSource" );
178 
179  // define tokens for access
180  tok_trigEvt = consumes<trigger::TriggerEvent>(triggerEvent_);
181  tok_trigRes = consumes<edm::TriggerResults>(theTriggerResultsLabel_);
182  tok_genTrack_ = consumes<reco::TrackCollection>(edm::InputTag("generalTracks"));
183  tok_recVtx_ = consumes<reco::VertexCollection>(edm::InputTag("offlinePrimaryVertices"));
184  tok_bs_ = consumes<reco::BeamSpot>(edm::InputTag("offlineBeamSpot"));
185  tok_ew_ = consumes<GenEventInfoProduct>(edm::InputTag("generatorSmeared"));
186  tok_L1extTauJet_ = consumes<l1extra::L1JetParticleCollection>(L1extraTauJetSource_);
187  tok_L1extCenJet_ = consumes<l1extra::L1JetParticleCollection>(L1extraCenJetSource_);
188  tok_L1extFwdJet_ = consumes<l1extra::L1JetParticleCollection>(L1extraFwdJetSource_);
189  if (isItAOD) {
190  tok_EB_ = consumes<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEB"));
191  tok_EE_ = consumes<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEE"));
192  tok_hbhe_ = consumes<HBHERecHitCollection>(edm::InputTag("reducedHcalRecHits", "hbhereco"));
193  } else {
194  tok_EB_ = consumes<EcalRecHitCollection>(edm::InputTag("ecalRecHit","EcalRecHitsEB"));
195  tok_EE_ = consumes<EcalRecHitCollection>(edm::InputTag("ecalRecHit","EcalRecHitsEE"));
196  tok_hbhe_ = consumes<HBHERecHitCollection>(edm::InputTag("hbhereco"));
197  }
198  tok_jets_ = consumes<reco::GenJetCollection>(iConfig.getParameter<edm::InputTag>("JetSource"));
199  tok_pfjets_ = consumes<reco::PFJetCollection>(edm::InputTag("ak5PFJets"));
200  if (verbosity_>=0) {
201  edm::LogInfo("IsoTrack")
202  <<"Parameters read from config file \n"
203  <<"\t minPt " << selectionParameters_.minPt
204  <<"\t theTrackQuality " << theTrackQuality_
205  <<"\t minQuality " << selectionParameters_.minQuality
206  <<"\t maxDxyPV " << selectionParameters_.maxDxyPV
207  <<"\t maxDzPV " << selectionParameters_.maxDzPV
208  <<"\t maxChi2 " << selectionParameters_.maxChi2
209  <<"\t maxDpOverP " << selectionParameters_.maxDpOverP
210  <<"\t minOuterHit " << selectionParameters_.minOuterHit
211  <<"\t minLayerCrossed " << selectionParameters_.minLayerCrossed
212  <<"\t maxInMiss " << selectionParameters_.maxInMiss
213  <<"\t maxOutMiss " << selectionParameters_.maxOutMiss
214  <<"\t a_coneR " << a_coneR_
215  <<"\t a_charIsoR " << a_charIsoR_
216  <<"\t a_mipR " << a_mipR_
217  <<"\t isItAOD " << isItAOD;
218  edm::LogInfo("IsoTrack") << l1Names_.size() << " triggers to be studied";
219  for (unsigned int k=0; k<l1Names_.size(); ++k)
220  edm::LogInfo("IsoTrack") << "[" << k << "]: " << l1Names_[k];
221  }
222 
223 }
224 
226  // do anything here that needs to be done at desctruction time
227  // (e.g. close files, deallocate resources etc.)
228 
229 }
230 
231 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
233 
234  std::vector<std::string> seeds = {"L1_SingleJet36","L1_SingleJet52",
235  "L1_SingleJet68","L1_SingleJet92",
236  "L1_SingleJet128"};
238  desc.addUntracked<int>("Verbosity", 0);
239  desc.addUntracked<std::vector<std::string> >("L1Seed", seeds);
240  desc.addUntracked<std::string>("TrackQuality", "highPurity");
241  desc.addUntracked<double>("MinTrackPt", 10.0);
242  desc.addUntracked<double>("MaxDxyPV", 0.02);
243  desc.addUntracked<double>("MaxDzPV", 0.02);
244  desc.addUntracked<double>("MaxChi2", 5.0);
245  desc.addUntracked<double>("MaxDpOverP", 0.1);
246  desc.addUntracked<int>("MinOuterHit", 4);
247  desc.addUntracked<int>("MinLayerCrossed", 8);
248  desc.addUntracked<int>("MaxInMiss", 0);
249  desc.addUntracked<int>("MaxOutMiss", 0);
250  desc.addUntracked<double>("ConeRadius", 34.98);
251  desc.addUntracked<double>("ConeRadiusMIP",14.0);
252  desc.addUntracked<bool>("IsItAOD", false);
253  descriptions.add("isoTrackCalib",desc);
254 }
255 
257  const edm::EventSetup& iSetup) {
258 
259  t_Run = iEvent.id().run();
260  t_Event = iEvent.id().event();
261  if (verbosity_%10 > 0)
262  edm::LogInfo("IsoTrack")
263  << "Run " << t_Run << " Event " << t_Event << " Luminosity "
264  << iEvent.luminosityBlock() << " Bunch " << iEvent.bunchCrossing()
265  << " starts ==========";
266 
267  //Get magnetic field and ECAL channel status
269  iSetup.get<IdealMagneticFieldRecord>().get(bFieldH);
270  const MagneticField *bField = bFieldH.product();
271 
273  iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
274 
275  // get handles to calogeometry and calotopology
277  iSetup.get<CaloGeometryRecord>().get(pG);
278  const CaloGeometry* geo = pG.product();
279 
280  //Get track collection
282  iEvent.getByToken(tok_genTrack_, trkCollection);
283  reco::TrackCollection::const_iterator trkItr;
284 
285  //event weight for FLAT sample
286  t_EventWeight = 1.0;
288  iEvent.getByToken(tok_ew_, genEventInfo);
289  if (genEventInfo.isValid()) t_EventWeight = genEventInfo->weight();
290 
291  // genJet information
293  iEvent.getByToken(tok_jets_, genJets);
294  if (genJets.isValid()) {
295  for (unsigned iGenJet = 0; iGenJet < genJets->size(); ++iGenJet) {
296  const reco::GenJet& genJet = (*genJets) [iGenJet];
297  double genJetPt = genJet.pt();
298  double genJetEta = genJet.eta();
299  h_jetpt[0]->Fill(genJetPt);
300  h_jetpt[1]->Fill(genJetPt,t_EventWeight);
301  if (genJetEta>-2.5 && genJetEta<2.5) {
302  h_jetpt[2]->Fill(genJetPt);
303  h_jetpt[3]->Fill(genJetPt,t_EventWeight);
304  }
305  break;
306  }
307  }
308 
309  //pf jets
311  iEvent.getByToken(tok_pfjets_, pfJets);
312  reco::PFJetCollection::const_iterator pfItr;
313 
314  //Define the best vertex and the beamspot
316  iEvent.getByToken(tok_recVtx_, recVtxs);
317  edm::Handle<reco::BeamSpot> beamSpotH;
318  iEvent.getByToken(tok_bs_, beamSpotH);
319  math::XYZPoint leadPV(0,0,0);
320  if (!recVtxs->empty() && !((*recVtxs)[0].isFake())) {
321  leadPV = math::XYZPoint( (*recVtxs)[0].x(),(*recVtxs)[0].y(), (*recVtxs)[0].z() );
322  } else if (beamSpotH.isValid()) {
323  leadPV = beamSpotH->position();
324  }
325  if (verbosity_>10) {
326  if ((verbosity_%100)/10>2)
327  edm::LogInfo("IsoTrack") << "Primary Vertex " << leadPV;
328  if (beamSpotH.isValid()) edm::LogInfo("IsoTrack") << " Beam Spot "
329  << beamSpotH->position();
330  }
331 
332  // RecHits
333  edm::Handle<EcalRecHitCollection> barrelRecHitsHandle;
334  edm::Handle<EcalRecHitCollection> endcapRecHitsHandle;
335  iEvent.getByToken(tok_EB_, barrelRecHitsHandle);
336  iEvent.getByToken(tok_EE_, endcapRecHitsHandle);
338  iEvent.getByToken(tok_hbhe_, hbhe);
340 
341  for (rhitItr=hbhe->begin();rhitItr!=hbhe->end();rhitItr++) {
342  double rec_energy = rhitItr->energy();
343  int rec_ieta = rhitItr->id().ieta();
344  int rec_depth = rhitItr->id().depth();
345  int rec_zside = rhitItr->id().zside();
346  double num1_1 = rec_zside*(rec_ieta+0.2*(rec_depth-1));
347  if (verbosity_%10>0)
348  edm::LogInfo("IsoTrack") << "detid/rechit/ieta/zside/depth/num " << " = "
349  << rhitItr->id() << "/" << rec_energy << "/"
350  << rec_ieta << "/" << rec_zside << "/"
351  << rec_depth << "/" << num1_1;
352  h_iEta->Fill(rec_ieta);
353  h_Rechit_E->Fill(rec_energy);
354  h_RecHit_iEta->Fill(rec_ieta,rec_energy);
355  h_RecHit_num->Fill(num1_1,rec_energy);
356  }
357 
358  //Propagate tracks to calorimeter surface)
359  std::vector<spr::propagatedTrackDirection> trkCaloDirections;
360  spr::propagateCALO(trkCollection, geo, bField, theTrackQuality_,
361  trkCaloDirections, ((verbosity_/100)%10>2));
362  std::vector<spr::propagatedTrackDirection>::const_iterator trkDetItr;
363  for (trkDetItr = trkCaloDirections.begin();
364  trkDetItr != trkCaloDirections.end(); trkDetItr++) {
365  if (trkDetItr->okHCAL) {
366  HcalDetId detId = (HcalDetId)(trkDetItr->detIdHCAL);
367  int tk_ieta = detId.ieta();
368  const reco::Track* pTrack = &(*(trkDetItr->trkItr));
369  double tk_p = pTrack->p();
370  h_tketa0[0]->Fill(tk_ieta);
371  for (unsigned int k=1; k<pbin.size(); ++k) {
372  if (tk_p >= pbin[k-1] && tk_p < pbin[k]) {
373  h_tketa0[k]->Fill(tk_ieta);
374  break;
375  }
376  }
377  }
378  }
380  t_l1bits->clear();
381  for (unsigned int i=0; i<l1Names_.size(); ++i) t_l1bits->push_back(false);
382  bool useL1EventSetup = true;
383  bool useL1GtTriggerMenuLite = true;
384 
385  m_l1GtUtils.getL1GtRunCache(iEvent, iSetup, useL1EventSetup, useL1GtTriggerMenuLite);
386  int iErrorCode = -1;
387  int l1ConfCode = -1;
388  const bool l1Conf = m_l1GtUtils.availableL1Configuration(iErrorCode, l1ConfCode);
389  if( !l1Conf) {
390  edm::LogInfo("IsoTrack") << "\nL1 configuration code:" << l1ConfCode
391  << "\nNo valid L1 trigger configuration available."
392  << "\nSee text above for error code interpretation"
393  << "\nNo return here, in order to test each method"
394  << ", protected against configuration error.";
395  }
396 
397  const AlgorithmMap& algorithmMap = m_l1GtMenu->gtAlgorithmMap();
398  const std::string& menuName = m_l1GtMenu->gtTriggerMenuName();
399  if (verbosity_%10>0)
400  edm::LogInfo("IsoTrack") << "menuName " << menuName << std::endl;
401 
402  std::vector<int> algbits;
403  for (CItAlgo itAlgo = algorithmMap.begin(); itAlgo != algorithmMap.end();
404  itAlgo++) {
405  std::string algName = itAlgo->first;
406  int algBitNumber = ( itAlgo->second ).algoBitNumber();
407  bool decision = m_l1GtUtils.decision(iEvent, itAlgo->first, iErrorCode);
408 
409  bool l1ok(false);
410  if (verbosity_%10>0)
411  edm::LogInfo("IsoTrack") << algName <<" "<< algBitNumber << " "
412  << decision;
413  for (unsigned int i=0; i<l1Names_.size(); ++i) {
414  if (algName.find(l1Names_[i])!=std::string::npos){
415  if (verbosity_%10>0)
416  edm::LogInfo("IsoTrack") << "match found" << " " << algName << " "
417  << decision;
418  t_l1bits->at(i) = (decision>0);
419  if (decision > 0) l1ok = true;
420  }
421  }
422  if (verbosity_%10>0) edm::LogInfo("IsoTrack") << "l1 ok =" << l1ok;
423 
424  if(l1ok){
426  iEvent.getByToken(tok_L1extTauJet_,l1TauHandle);
427  l1extra::L1JetParticleCollection::const_iterator itr;
428  double ptTriggered = -10;
429  double etaTriggered = -100;
430  double phiTriggered = -100;
431 
432  for(itr = l1TauHandle->begin(); itr != l1TauHandle->end(); ++itr) {
433  if(itr->pt()>ptTriggered){
434  ptTriggered = itr->pt();
435  etaTriggered = itr->eta();
436  phiTriggered = itr->phi() ;
437  }
438  if (verbosity_%10>0)
439  edm::LogInfo("IsoTrack") << "tauJ pt " << itr->pt() << " eta/phi "
440  << itr->eta() << " " << itr->phi();
441  }
443  iEvent.getByToken(tok_L1extCenJet_,l1CenJetHandle);
444  for (itr = l1CenJetHandle->begin(); itr != l1CenJetHandle->end(); ++itr){
445  if (itr->pt()>ptTriggered) {
446  ptTriggered = itr->pt();
447  etaTriggered = itr->eta();
448  phiTriggered = itr->phi() ;
449  }
450  if (verbosity_%10>0)
451  edm::LogInfo("IsoTrack") << "cenJ pt " << itr->pt()
452  << " eta/phi " << itr->eta() << " "
453  << itr->phi();
454  }
456  iEvent.getByToken(tok_L1extFwdJet_,l1FwdJetHandle);
457  for (itr = l1FwdJetHandle->begin(); itr != l1FwdJetHandle->end(); ++itr) {
458  if (itr->pt()>ptTriggered) {
459  ptTriggered = itr->pt();
460  etaTriggered = itr->eta();
461  phiTriggered = itr->phi() ;
462  }
463  if (verbosity_%10>0)
464  edm::LogInfo("IsoTrack") << "forJ pt " << itr->pt() << " eta/phi "
465  << itr->eta() << " " << itr->phi();
466  }
467  if (verbosity_%10>0)
468  edm::LogInfo("IsoTrack") << "jets pt/eta/phi = " << ptTriggered << "/"
469  << etaTriggered << "/" <<phiTriggered;
471  unsigned int nTracks(0),nselTracks(0);
472  for (trkDetItr = trkCaloDirections.begin(),nTracks=0;
473  trkDetItr != trkCaloDirections.end(); trkDetItr++,nTracks++) {
474  const reco::Track* pTrack = &(*(trkDetItr->trkItr));
475  math::XYZTLorentzVector v4(pTrack->px(), pTrack->py(),
476  pTrack->pz(), pTrack->p());
477 
478  t_mindR1 = deltaR(etaTriggered,v4.eta(),phiTriggered,v4.phi());
479  t_mindR2 = -999;
480  if (verbosity_%10>0)
481  edm::LogInfo("IsoTrack") << "This track : " << nTracks << " (pt/eta/phi/p) :"
482  << pTrack->pt() << "/" << pTrack->eta() << "/"
483  << pTrack->phi() << "/" << pTrack->p();
484 
485  if (verbosity_%10>0) edm::LogInfo("IsoTrack") << "dr values are = " << t_mindR1;
486 
487  t_l1pt = ptTriggered;
488  t_l1eta = etaTriggered;
489  t_l1phi = phiTriggered;
490  t_l3pt = -999;
491  t_l3eta = -999;
492  t_l3phi = -999;
493 
494  //Selection of good track
495  t_selectTk = spr::goodTrack(pTrack,leadPV,selectionParameters_,((verbosity_/100)%10>2));
497  oneCutParameters.maxDxyPV = 10;
498  oneCutParameters.maxDzPV = 100;
499  oneCutParameters.maxInMiss = 2;
500  oneCutParameters.maxOutMiss= 2;
501  bool qltyFlag = spr::goodTrack(pTrack,leadPV,oneCutParameters,((verbosity_/100)%10>2));
502  oneCutParameters = selectionParameters_;
503  oneCutParameters.maxDxyPV = 10;
504  oneCutParameters.maxDzPV = 100;
505  t_qltyMissFlag = spr::goodTrack(pTrack,leadPV,oneCutParameters,((verbosity_/100)%10>2));
506  oneCutParameters = selectionParameters_;
507  oneCutParameters.maxInMiss = 2;
508  oneCutParameters.maxOutMiss= 2;
509  t_qltyPVFlag = spr::goodTrack(pTrack,leadPV,oneCutParameters,((verbosity_/100)%10>2));
510  t_ieta = 0;
511  if (trkDetItr->okHCAL) {
512  HcalDetId detId = (HcalDetId)(trkDetItr->detIdHCAL);
513  t_ieta = detId.ieta();
514  }
515  if (verbosity_%10 > 0)
516  edm::LogInfo("IsoTrack") << "qltyFlag|okECAL|okHCAL : " << qltyFlag << "|"
517  << trkDetItr->okECAL << "/" << trkDetItr->okHCAL;
518  t_qltyFlag = (qltyFlag && trkDetItr->okECAL && trkDetItr->okHCAL);
519  t_p = pTrack->p();
520  h_tketa1[0]->Fill(t_ieta);
521  for (unsigned int k=1; k<pbin.size(); ++k) {
522  if (t_p >= pbin[k-1] && t_p < pbin[k]) {
523  h_tketa1[k]->Fill(t_ieta);
524  break;
525  }
526  }
527  if (t_qltyFlag) {
528  nselTracks++;
529  h_tketa2[0]->Fill(t_ieta);
530  for (unsigned int k=1; k<pbin.size(); ++k) {
531  if (t_p >= pbin[k-1] && t_p < pbin[k]) {
532  h_tketa2[k]->Fill(t_ieta);
533  break;
534  }
535  }
536  int nRH_eMipDR(0), nNearTRKs(0), nRecHits(-999);
537  t_eMipDR = spr::eCone_ecal(geo, barrelRecHitsHandle,
538  endcapRecHitsHandle,
539  trkDetItr->pointHCAL,
540  trkDetItr->pointECAL,
541  a_mipR_, trkDetItr->directionECAL,
542  nRH_eMipDR);
543  t_DetIds->clear(); t_HitEnergies->clear();
544  std::vector<DetId> ids;
545  t_eHcal = spr::eCone_hcal(geo, hbhe, trkDetItr->pointHCAL,
546  trkDetItr->pointECAL, a_coneR_,
547  trkDetItr->directionHCAL,nRecHits,
548  ids, *t_HitEnergies);
549  for (unsigned int k=0; k<ids.size(); ++k) {
550  t_DetIds->push_back(ids[k].rawId());
551  }
552  t_hmaxNearP = spr::chargeIsolationCone(nTracks,trkCaloDirections,
553  a_charIsoR_, nNearTRKs,
554  ((verbosity_/100)%10>2));
555  if (t_hmaxNearP < 2) {
556  h_tketa3[0]->Fill(t_ieta);
557  for (unsigned int k=1; k<pbin.size(); ++k) {
558  if (t_p >= pbin[k-1] && t_p < pbin[k]) {
559  h_tketa3[k]->Fill(t_ieta);
560  break;
561  }
562  }
563  if (t_eMipDR < 1) {
564  h_tketa4[0]->Fill(t_ieta);
565  for (unsigned int k=1; k<pbin.size(); ++k) {
566  if (t_p >= pbin[k-1] && t_p < pbin[k]) {
567  h_tketa4[k]->Fill(t_ieta);
568  break;
569  }
570  }
571  if (t_mindR1 > 1) {
572  h_tketa5[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_tketa5[k]->Fill(t_ieta);
576  break;
577  }
578  }
579  }
580  }
581  }
582  if (verbosity_%10 > 0) {
583  edm::LogInfo("IsoTrack") << "This track : " << nTracks << " (pt/eta/phi/p) :"
584  << pTrack->pt() << "/" << pTrack->eta() << "/"
585  << pTrack->phi() << "/" << t_p;
586  edm::LogInfo("IsoTrack") << "e_MIP " << t_eMipDR << " Chg Isolation "
587  << t_hmaxNearP << " eHcal" << t_eHcal << " ieta "
588  << t_ieta << " Quality " << t_qltyMissFlag
589  << ":" << t_qltyPVFlag << ":" << t_selectTk;
590  for (unsigned int lll=0;lll<t_DetIds->size();lll++) {
591  edm::LogInfo("IsoTrack") << "det id is = " << t_DetIds->at(lll) << " "
592  << " hit enery is = " << t_HitEnergies->at(lll);
593  }
594  }
595  if (t_p>20.0 && t_eMipDR<2.0 && t_hmaxNearP<10.0) {
596  tree->Fill();
597  }
598  }
599  }
600  }
601  }
602 }
603 
605  h_RecHit_iEta = fs_->make<TProfile>("rechit_ieta","Rec hit vs. ieta",60,-30,30,0,1000);
606  h_RecHit_num = fs_->make<TProfile>("rechit_num","Rec hit vs. num",100,0,20,0,1000);
607  h_iEta = fs_->make<TH1I>("iEta","iEta",60,-30,30);
608  h_Rechit_E = fs_->make<TH1F>("Rechit_E","Rechit_E",100,0,1000);
609 
610  double prange[5] = {20,30,40,60,100};
611  for (int k=0; k<5; ++k) pbin.push_back(prange[k]);
612  std::string type[6] = {"All", "Trigger OK", "Tree Selected",
613  "Charge Isolation", "MIP Cut", "L1 Cut"};
614  for (unsigned int k=0; k<pbin.size(); ++k) {
615  char name[20], namp[20], title[100];
616  if (k == 0) sprintf (namp, "all momentum");
617  else sprintf (namp, "p = %4.0f:%4.0f GeV", pbin[k-1], pbin[k]);
618  sprintf (name, "TrackEta0%d", k);
619  sprintf (title, "Track #eta for tracks with %s (%s)",namp,type[0].c_str());
620  h_tketa0[k] = fs_->make<TH1I>(name, title, 60, -30, 30);
621  sprintf (name, "TrackEta1%d", k);
622  sprintf (title, "Track #eta for tracks with %s (%s)",namp,type[1].c_str());
623  h_tketa1[k] = fs_->make<TH1I>(name, title, 60, -30, 30);
624  sprintf (name, "TrackEta2%d", k);
625  sprintf (title, "Track #eta for tracks with %s (%s)",namp,type[2].c_str());
626  h_tketa2[k] = fs_->make<TH1I>(name, title, 60, -30, 30);
627  sprintf (name, "TrackEta3%d", k);
628  sprintf (title, "Track #eta for tracks with %s (%s)",namp,type[3].c_str());
629  h_tketa3[k] = fs_->make<TH1I>(name, title, 60, -30, 30);
630  sprintf (name, "TrackEta4%d", k);
631  sprintf (title, "Track #eta for tracks with %s (%s)",namp,type[4].c_str());
632  h_tketa4[k] = fs_->make<TH1I>(name, title, 60, -30, 30);
633  sprintf (name, "TrackEta5%d", k);
634  sprintf (title, "Track #eta for tracks with %s (%s)",namp,type[5].c_str());
635  h_tketa5[k] = fs_->make<TH1I>(name, title, 60, -30, 30);
636  }
637  h_jetpt[0] = fs_->make<TH1F>("Jetpt0","Jet p_T (All)", 500,0.,2500.);
638  h_jetpt[1] = fs_->make<TH1F>("Jetpt1","Jet p_T (All Weighted)", 500,0.,2500.);
639  h_jetpt[2] = fs_->make<TH1F>("Jetpt2","Jet p_T (|#eta| < 2.5)", 500,0.,2500.);
640  h_jetpt[3] = fs_->make<TH1F>("Jetpt3","Jet p_T (|#eta| < 2.5 Weighted)", 500,0.,2500.);
641 
642  tree = fs_->make<TTree>("CalibTree", "CalibTree");
643 
644  tree->Branch("t_Run", &t_Run, "t_Run/I");
645  tree->Branch("t_Event", &t_Event, "t_Event/I");
646  tree->Branch("t_ieta", &t_ieta, "t_ieta/I");
647  tree->Branch("t_EventWeight", &t_EventWeight, "t_EventWeight/D");
648  tree->Branch("t_l1pt", &t_l1pt, "t_l1pt/D");
649  tree->Branch("t_l1eta", &t_l1eta, "t_l1eta/D");
650  tree->Branch("t_l1phi", &t_l1phi, "t_l1phi/D");
651  tree->Branch("t_l3pt", &t_l3pt, "t_l3pt/D");
652  tree->Branch("t_l3eta", &t_l3eta, "t_l3eta/D");
653  tree->Branch("t_l3phi", &t_l3phi, "t_l3phi/D");
654  tree->Branch("t_p", &t_p, "t_p/D");
655  tree->Branch("t_mindR1", &t_mindR1, "t_mindR1/D");
656  tree->Branch("t_mindR2", &t_mindR2, "t_mindR2/D");
657  tree->Branch("t_eMipDR", &t_eMipDR, "t_eMipDR/D");
658  tree->Branch("t_eHcal", &t_eHcal, "t_eHcal/D");
659  tree->Branch("t_hmaxNearP", &t_hmaxNearP, "t_hmaxNearP/D");
660  tree->Branch("t_selectTk", &t_selectTk, "t_selectTk/O");
661  tree->Branch("t_qltyFlag", &t_qltyFlag, "t_qltyFlag/O");
662  tree->Branch("t_qltyMissFlag",&t_qltyMissFlag,"t_qltyMissFlag/O");
663  tree->Branch("t_qltyPVFlag", &t_qltyPVFlag, "t_qltyPVFlag/O)");
664 
665  t_DetIds = new std::vector<unsigned int>();
666  t_HitEnergies = new std::vector<double>();
667  t_l1bits = new std::vector<bool>();
668  tree->Branch("t_DetIds", "std::vector<unsigned int>", &t_DetIds);
669  tree->Branch("t_HitEnergies", "std::vector<double>", &t_HitEnergies);
670  tree->Branch("t_l1bits","std::vector<bool>", &t_l1bits);
671 }
672 
673 // ------------ method called when starting to processes a run ------------
674 void IsoTrackCalib::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
675  bool changed = false;
676  bool ok = hltConfig_.init(iRun,iSetup,"HLT",changed);
677  edm::LogInfo("IsoTrack") << "Run " << iRun.run() << " hltconfig.init " << ok;
678 
679  int iErrorCode = -1;
681  const AlgorithmMap& algorithmMap = m_l1GtMenu->gtAlgorithmMap();
682  const std::string& menuName = m_l1GtMenu->gtTriggerMenuName();
683 
684  if (verbosity_%10>0) edm::LogInfo("IsoTrack") << "menuName " << menuName;
685  for (CItAlgo itAlgo = algorithmMap.begin(); itAlgo != algorithmMap.end();
686  itAlgo++) {
687  std::string algName = itAlgo->first;
688  int algBitNumber = ( itAlgo->second ).algoBitNumber();
689  l1AlgoMap_.insert( std::pair<std::pair<unsigned int,std::string>,int>( std::pair<unsigned int,std::string>(algBitNumber, algName) , 0) ) ;
690  }
691  std::map< std::pair<unsigned int,std::string>, int>::iterator itr;
692  for (itr=l1AlgoMap_.begin(); itr!=l1AlgoMap_.end(); itr++) {
693  if (verbosity_%10>0)
694  edm::LogInfo("IsoTrack") << " ********** " << (itr->first).first << " "
695  << (itr->first).second <<" "<<itr->second;
696  }
697 }
698 
699 // ------------ method called when ending the processing of a run ------------
700 void IsoTrackCalib::endRun(edm::Run const& iRun, edm::EventSetup const&) {
701  edm::LogInfo("IsoTrack") << "endRun " << iRun.run() << std::endl;
702 }
703 
705  return (vec1.eta()-vec2.eta());
706 }
707 
709 
710  double phi1 = vec1.phi();
711  if (phi1 < 0) phi1 += 2.0*M_PI;
712  double phi2 = vec2.phi();
713  if (phi2 < 0) phi2 += 2.0*M_PI;
714  double dphi = phi1-phi2;
715  if (dphi > M_PI) dphi -= 2.*M_PI;
716  else if (dphi < -M_PI) dphi += 2.*M_PI;
717  return dphi;
718 }
719 
721  double deta = dEta(vec1,vec2);
722  double dphi = dPhi(vec1,vec2);
723  return std::sqrt(deta*deta + dphi*dphi);
724 }
725 
726 double IsoTrackCalib::deltaR(double eta1,double eta2,double phi1,double phi2){
727  double deta = eta1-eta2;
728  if (phi1 < 0) phi1 += 2.0*M_PI;
729  if (phi2 < 0) phi2 += 2.0*M_PI;
730  double dphi = phi1-phi2;
731  if (dphi > M_PI) dphi -= 2.*M_PI;
732  else if (dphi < -M_PI) dphi += 2.*M_PI;
733  return std::sqrt(deta*deta + dphi*dphi);
734 }
735 
736 
737 
738 //define this as a plug-in
740 
RunNumber_t run() const
Definition: EventID.h:39
double p() const
momentum vector magnitude
Definition: TrackBase.h:615
void beginRun(edm::Run const &, edm::EventSetup const &) override
type
Definition: HCALResponse.h:21
const std::string & gtTriggerMenuName() const
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
spr::trackSelectionParameters selectionParameters_
std::vector< double > * t_HitEnergies
T getUntrackedParameter(std::string const &, T const &) const
void beginJob() override
TH1I * h_tkEta0[5]
const unsigned int nTracks(const reco::Vertex &sv)
const L1GtTriggerMenu * m_l1GtMenu
std::vector< unsigned int > * t_DetIds
double eta() const final
momentum pseudorapidity
std::vector< spr::propagatedTrackID > propagateCALO(edm::Handle< reco::TrackCollection > &trkCollection, const CaloGeometry *geo, const MagneticField *bField, std::string &theTrackQuality, bool debug=false)
edm::EDGetTokenT< EcalRecHitCollection > tok_EE_
RunNumber_t run() const
Definition: RunBase.h:40
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
TProfile * h_RecHit_num
HLTConfigProvider hltConfig_
edm::EDGetTokenT< l1extra::L1JetParticleCollection > tok_L1extCenJet_
edm::EDGetTokenT< reco::GenJetCollection > tok_jets_
std::map< std::pair< unsigned int, std::string >, int > l1AlgoMap_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
edm::InputTag triggerEvent_
TrackQuality
track quality
Definition: TrackBase.h:151
void endJob() override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::map< std::string, L1GtAlgorithm > AlgorithmMap
map containing the algorithms
const bool availableL1Configuration(int &errorCode, int &l1ConfCode) const
Definition: L1GtUtils.cc:1948
TH1I * h_tketa0[6]
edm::EDGetTokenT< reco::VertexCollection > tok_recVtx_
std::vector< HBHERecHit >::const_iterator const_iterator
int bunchCrossing() const
Definition: EventBase.h:66
TH1I * h_tketa3[6]
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:645
double pt() const final
transverse momentum
const bool decision(const edm::Event &iEvent, const std::string &nameAlgoTechTrig, int &errorCode) const
Definition: L1GtUtils.cc:1208
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
edm::InputTag theTriggerResultsLabel_
edm::EDGetTokenT< reco::TrackCollection > tok_genTrack_
edm::EDGetTokenT< reco::PFJetCollection > tok_pfjets_
double chargeIsolationCone(unsigned int trkIndex, std::vector< spr::propagatedTrackDirection > &trkDirs, double dR, int &nNearTRKs, bool debug=false)
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:627
double weight() const
edm::EDGetTokenT< l1extra::L1JetParticleCollection > tok_L1extTauJet_
edm::EDGetTokenT< HBHERecHitCollection > tok_hbhe_
edm::EDGetTokenT< edm::TriggerResults > tok_trigRes
TH1I * h_tketa5[6]
TH1I * h_tketa1[6]
AlgorithmMap::const_iterator CItAlgo
iterators through map containing the algorithms
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
edm::EDGetTokenT< trigger::TriggerEvent > tok_trigEvt
TH1I * h_tketa4[6]
int iEvent
Definition: GenABIO.cc:230
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:651
std::vector< double > pbin
TH1I * h_tkEta2[5]
TH1I * h_tkEta4[5]
static const bool useL1GtTriggerMenuLite(true)
edm::Service< TFileService > fs_
double deltaR(double eta1, double eta2, double phi1, double phi2)
edm::EDGetTokenT< reco::BeamSpot > tok_bs_
bool goodTrack(const reco::Track *pTrack, math::XYZPoint leadPV, trackSelectionParameters parameters, bool debug=false)
std::vector< bool > * t_l1bits
std::vector< double > vec1
Definition: HCALResponse.h:15
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
T sqrt(T t)
Definition: SSEVec.h:18
double pt() const
track transverse momentum
Definition: TrackBase.h:621
TH1I * h_tketa2[6]
std::string theTrackQuality_
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
edm::EDGetTokenT< EcalRecHitCollection > tok_EB_
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)
~IsoTrackCalib() override
edm::EDGetTokenT< l1extra::L1JetParticleCollection > tok_L1extFwdJet_
bool isValid() const
Definition: HandleBase.h:74
#define M_PI
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:639
int k[5][pyjets_maxn]
const_iterator end() const
double t_EventWeight
double dEta(math::XYZTLorentzVector &, math::XYZTLorentzVector &)
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:125
L1GtUtils m_l1GtUtils
TH1I * h_tkEta3[5]
TProfile * h_RecHit_iEta
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
edm::EDGetTokenT< GenEventInfoProduct > tok_ew_
const T & get() const
Definition: EventSetup.h:58
std::vector< std::string > l1Names_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
TH1I * h_tkEta5[5]
TH1I * h_tkEta1[5]
edm::EventID id() const
Definition: EventBase.h:60
void getL1GtRunCache(const edm::Run &, const edm::EventSetup &, const bool, const bool)
get all the run-constant quantities for L1 trigger and cache them
Definition: L1GtUtils.cc:319
reco::TrackBase::TrackQuality minQuality
void endRun(edm::Run const &, edm::EventSetup const &) override
const AlgorithmMap & gtAlgorithmMap() const
get / set the algorithm map (by name)
void analyze(const edm::Event &, const edm::EventSetup &) override
const Point & position() const
position
Definition: BeamSpot.h:62
double dR(math::XYZTLorentzVector &, math::XYZTLorentzVector &)
double dPhi(math::XYZTLorentzVector &, math::XYZTLorentzVector &)
Definition: tree.py:1
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const L1GtTriggerMenu * ptrL1TriggerMenuEventSetup(int &errorCode)
return a pointer to the L1 trigger menu from event setup
Definition: L1GtUtils.cc:1883
std::vector< vec1 > vec2
Definition: HCALResponse.h:16
TH1F * h_jetpt[4]
T const * product() const
Definition: ESHandle.h:86
const_iterator begin() const
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:633
static const bool useL1EventSetup(true)
Definition: Run.h:43
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 useRaw=false, bool debug=false)
IsoTrackCalib(const edm::ParameterSet &)