CMS 3D CMS Logo

HcalIsoTrkAnalyzer.cc
Go to the documentation of this file.
1 // system include files
2 #include <atomic>
3 #include <cmath>
4 #include <memory>
5 #include <string>
6 #include <vector>
7 
8 // Root objects
9 #include "TROOT.h"
10 #include "TSystem.h"
11 #include "TFile.h"
12 #include "TProfile.h"
13 #include "TDirectory.h"
14 #include "TTree.h"
15 #include "TLorentzVector.h"
16 #include "TInterpreter.h"
17 
21 
22 //Tracks
27 // Vertices
31 
32 //Triggers
39 
44 
47 
48 //Generator information
52 
55 
63 
69 
83 
84 //#define EDM_ML_DEBUG
85 
86 class HcalIsoTrkAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns,edm::one::SharedResources> {
87 
88 public:
89  explicit HcalIsoTrkAnalyzer(edm::ParameterSet const&);
91 
92  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
93 
94 private:
95  virtual void analyze(edm::Event const&, edm::EventSetup const&) override;
96  virtual void beginJob() override;
97  virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
98  virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
99 
100  std::array<int,3> fillTree(std::vector< math::XYZTLorentzVector>& vecL1,
101  std::vector< math::XYZTLorentzVector>& vecL3,
102  math::XYZPoint& leadPV,
103  std::vector<spr::propagatedTrackDirection>& trkCaloDirections,
104  const CaloGeometry* geo,
105  edm::Handle<EcalRecHitCollection>& barrelRecHitsHandle,
106  edm::Handle<EcalRecHitCollection>& endcapRecHitsHandle,
110  const HcalRespCorrs* respCorrs);
112  double trackP(const reco::Track* ,
114  double rhoh(const edm::Handle<CaloTowerCollection>&);
115  void storeEnergy(int indx, const HcalRespCorrs* respCorrs,
116  const std::vector<DetId>& ids,
117  std::vector<double>& edet, double & eHcal,
118  std::vector<unsigned int> *detIds,
119  std::vector<double> *hitEnergies);
120 
124  const std::vector<std::string> trigNames_;
132  const int useRaw_, dataType_, mode_;
136  const double hitEthrEE2_, hitEthrEE3_;
140  unsigned int nRun_;
143  std::vector<double> etabins_, phibins_;
157 
158  TTree *tree, *tree2;
159  unsigned int t_RunNo, t_EventNo;
170  std::vector<unsigned int> *t_DetIds, *t_DetIds1, *t_DetIds3;
171  std::vector<double> *t_HitEnergies, *t_HitEnergies1, *t_HitEnergies3;
172  std::vector<bool> *t_trgbits, *t_hltbits;
173  bool t_L1Bit;
176  std::vector<int> *t_ietaAll, *t_ietaGood, *t_trackType;
177 };
178 
179 static const bool useL1EventSetup(false);
180 static const bool useL1GtTriggerMenuLite(true);
181 
183  trigNames_(iConfig.getParameter<std::vector<std::string> >("triggers")),
184  theTrackQuality_(iConfig.getParameter<std::string>("trackQuality")),
185  processName_(iConfig.getParameter<std::string>("processName")),
186  l1Filter_(iConfig.getParameter<std::string>("l1Filter")),
187  l2Filter_(iConfig.getParameter<std::string>("l2Filter")),
188  l3Filter_(iConfig.getParameter<std::string>("l3Filter")),
189  a_coneR_(iConfig.getParameter<double>("coneRadius")),
190  a_mipR_(iConfig.getParameter<double>("coneRadiusMIP")),
191  pTrackMin_(iConfig.getParameter<double>("minimumTrackP")),
192  eEcalMax_(iConfig.getParameter<double>("maximumEcalEnergy")),
193  maxRestrictionP_(iConfig.getParameter<double>("maxTrackP")),
194  slopeRestrictionP_(iConfig.getParameter<double>("slopeTrackP")),
195  hcalScale_(iConfig.getUntrackedParameter<double>("hHcalScale",1.0)),
196  eIsolate1_(iConfig.getParameter<double>("isolationEnergyTight")),
197  eIsolate2_(iConfig.getParameter<double>("isolationEnergyLoose")),
198  useRaw_(iConfig.getUntrackedParameter<int>("useRaw",0)),
199  dataType_(iConfig.getUntrackedParameter<int>("dataType",0)),
200  mode_(iConfig.getUntrackedParameter<int>("outMode",11)),
201  ignoreTrigger_(iConfig.getUntrackedParameter<bool>("ignoreTriggers",false)),
202  useL1Trigger_(iConfig.getUntrackedParameter<bool>("useL1Trigger",false)),
203  unCorrect_(iConfig.getUntrackedParameter<bool>("unCorrect",false)),
204  collapseDepth_(iConfig.getUntrackedParameter<bool>("collapseDepth",false)),
205  hitEthrEB_(iConfig.getParameter<double>("EBHitEnergyThreshold") ),
206  hitEthrEE0_(iConfig.getParameter<double>("EEHitEnergyThreshold0") ),
207  hitEthrEE1_(iConfig.getParameter<double>("EEHitEnergyThreshold1") ),
208  hitEthrEE2_(iConfig.getParameter<double>("EEHitEnergyThreshold2") ),
209  hitEthrEE3_(iConfig.getParameter<double>("EEHitEnergyThreshold3") ),
210  triggerEvent_(iConfig.getParameter<edm::InputTag>("labelTriggerEvent")),
211  theTriggerResultsLabel_(iConfig.getParameter<edm::InputTag>("labelTriggerResult")),
212  labelGenTrack_(iConfig.getParameter<std::string>("labelTrack")),
213  labelRecVtx_(iConfig.getParameter<std::string>("labelVertex")),
214  labelEB_(iConfig.getParameter<std::string>("labelEBRecHit")),
215  labelEE_(iConfig.getParameter<std::string>("labelEERecHit")),
216  labelHBHE_(iConfig.getParameter<std::string>("labelHBHERecHit")),
217  labelTower_(iConfig.getParameter<std::string>("labelCaloTower")),
218  l1TrigName_(iConfig.getUntrackedParameter<std::string>("l1TrigName","L1_SingleJet60")),
219  nRun_(0), hdc_(nullptr) {
220 
221  usesResource(TFileService::kSharedResource);
222 
223  //now do whatever initialization is needed
224  const double isolationRadius(28.9), innerR(10.0), outerR(30.0);
226  selectionParameter_.minPt = iConfig.getParameter<double>("minTrackPt");;
227  selectionParameter_.minQuality = trackQuality_;
228  selectionParameter_.maxDxyPV = iConfig.getParameter<double>("maxDxyPV");
229  selectionParameter_.maxDzPV = iConfig.getParameter<double>("maxDzPV");
230  selectionParameter_.maxChi2 = iConfig.getParameter<double>("maxChi2");
231  selectionParameter_.maxDpOverP = iConfig.getParameter<double>("maxDpOverP");
232  selectionParameter_.minOuterHit = iConfig.getParameter<int>("minOuterHit");
233  selectionParameter_.minLayerCrossed = iConfig.getParameter<int>("minLayerCrossed");
234  selectionParameter_.maxInMiss = iConfig.getParameter<int>("maxInMiss");
235  selectionParameter_.maxOutMiss = iConfig.getParameter<int>("maxOutMiss");
236  a_charIsoR_ = a_coneR_ + isolationRadius;
237  a_coneR1_ = a_coneR_ + innerR;
238  a_coneR2_ = a_coneR_ + outerR;
239  // Different isolation cuts are described in DN-2016/029
240  // Tight cut uses 2 GeV; Loose cut uses 10 GeV
241  // Eta dependent cut uses (maxRestrictionP_ * exp(|ieta|*log(2.5)/18))
242  // with the factor for exponential slopeRestrictionP_ = log(2.5)/18
243  // maxRestrictionP_ = 8 GeV as came from a study
244  std::string labelBS = iConfig.getParameter<std::string>("labelBeamSpot");
245  std::string modnam = iConfig.getUntrackedParameter<std::string>("moduleName","");
246  std::string prdnam = iConfig.getUntrackedParameter<std::string>("producerName","");
247  edm::InputTag algTag = iConfig.getParameter<edm::InputTag>("algInputTag");
248  edm::InputTag extTag = iConfig.getParameter<edm::InputTag>("extInputTag");
249  l1GtUtils_ = new l1t::L1TGlobalUtil(iConfig, consumesCollector(), *this, algTag, extTag);
250  // define tokens for access
251  tok_trigEvt_ = consumes<trigger::TriggerEvent>(triggerEvent_);
252  tok_trigRes_ = consumes<edm::TriggerResults>(theTriggerResultsLabel_);
253  tok_bs_ = consumes<reco::BeamSpot>(labelBS);
254  tok_genTrack_ = consumes<reco::TrackCollection>(labelGenTrack_);
255  tok_ew_ = consumes<GenEventInfoProduct>(edm::InputTag("generator"));
256  tok_parts_ = consumes<reco::GenParticleCollection>(edm::InputTag("genParticles"));
257  tok_cala_ = consumes<CaloTowerCollection>(labelTower_);
258  tok_alg_ = consumes<BXVector<GlobalAlgBlk>>(algTag);
259 
260  if (modnam == "") {
261  tok_recVtx_ = consumes<reco::VertexCollection>(labelRecVtx_);
262  tok_EB_ = consumes<EcalRecHitCollection>(edm::InputTag("ecalRecHit",labelEB_));
263  tok_EE_ = consumes<EcalRecHitCollection>(edm::InputTag("ecalRecHit",labelEE_));
264  tok_hbhe_ = consumes<HBHERecHitCollection>(labelHBHE_);
265  edm::LogVerbatim("HcalIsoTrack") << "Labels used " << triggerEvent_ << " "
266  << theTriggerResultsLabel_ << " "
267  << labelBS << " " << labelRecVtx_ << " "
268  << labelGenTrack_ << " "
269  << edm::InputTag("ecalRecHit",labelEB_)
270  << " "
271  << edm::InputTag("ecalRecHit",labelEE_)
272  << " " << labelHBHE_ << " " << labelTower_;
273  } else {
274  tok_recVtx_ = consumes<reco::VertexCollection>(edm::InputTag(modnam,labelRecVtx_,prdnam));
275  tok_EB_ = consumes<EcalRecHitCollection>(edm::InputTag(modnam,labelEB_,prdnam));
276  tok_EE_ = consumes<EcalRecHitCollection>(edm::InputTag(modnam,labelEE_,prdnam));
277  tok_hbhe_ = consumes<HBHERecHitCollection>(edm::InputTag(modnam,labelHBHE_,prdnam));
278  edm::LogVerbatim("HcalIsoTrack") << "Labels used " << triggerEvent_ << " "
279  << theTriggerResultsLabel_ << " "
280  << labelBS << " "
281  << edm::InputTag(modnam,labelRecVtx_,prdnam)
282  << " " << labelGenTrack_ << " "
283  << edm::InputTag(modnam,labelEB_,prdnam)
284  << " "
285  << edm::InputTag(modnam,labelEE_,prdnam)
286  << " "
287  << edm::InputTag(modnam,labelHBHE_,prdnam)
288  << " " << labelTower_;
289  }
290 
291  edm::LogVerbatim("HcalIsoTrack") <<"Parameters read from config file \n"
292  <<"\t minPt " << selectionParameter_.minPt
293  <<"\t theTrackQuality " << theTrackQuality_
294  <<"\t minQuality " << selectionParameter_.minQuality
295  <<"\t maxDxyPV " << selectionParameter_.maxDxyPV
296  <<"\t maxDzPV " << selectionParameter_.maxDzPV
297  <<"\t maxChi2 " << selectionParameter_.maxChi2
298  <<"\t maxDpOverP " << selectionParameter_.maxDpOverP
299  <<"\t minOuterHit " << selectionParameter_.minOuterHit
300  <<"\t minLayerCrossed " << selectionParameter_.minLayerCrossed
301  <<"\t maxInMiss " << selectionParameter_.maxInMiss
302  <<"\t maxOutMiss " << selectionParameter_.maxOutMiss
303  <<"\t a_coneR " << a_coneR_
304  << ":" << a_coneR1_ << ":" << a_coneR2_
305  <<"\t a_charIsoR " << a_charIsoR_
306  <<"\t a_mipR " << a_mipR_
307  <<"\n pTrackMin_ " << pTrackMin_
308  <<"\t eEcalMax_ " << eEcalMax_
309  <<"\t maxRestrictionP_ "<< maxRestrictionP_
310  <<"\t slopeRestrictionP_ " << slopeRestrictionP_
311  <<"\t eIsolateStrong_ " << eIsolate1_
312  <<"\t eIsolateSoft_ " << eIsolate2_
313  <<"\t hcalScale_ " << hcalScale_
314  <<"\n\t useRaw_ " << useRaw_
315  <<"\t ignoreTrigger_ " << ignoreTrigger_
316  <<"\n\t useL1Trigegr_ " << useL1Trigger_
317  <<"\t dataType_ " << dataType_
318  <<"\t mode_ " << mode_
319  <<"\t unCorrect_ " << unCorrect_
320  <<"\t collapseDepth_ " << collapseDepth_
321  <<"\t L1TrigName_ " << l1TrigName_;
322  edm::LogVerbatim("HcalIsoTrack") << "Process " << processName_
323  << " L1Filter:" << l1Filter_ << " L2Filter:"
324  << l2Filter_ << " L3Filter:" << l3Filter_;
325  for (unsigned int k=0; k<trigNames_.size(); ++k) {
326  edm::LogVerbatim("HcalIsoTrack") << "Trigger[" << k << "] "
327  << trigNames_[k];
328  }
329 
330  for (int i=0; i<10;i++) phibins_.push_back(-M_PI+0.1*(2*i+1)*M_PI);
331  for (int i=0; i<8; ++i) etabins_.push_back(-2.1+0.6*i);
332  etadist_ = etabins_[1]-etabins_[0];
333  phidist_ = phibins_[1]-phibins_[0];
334  etahalfdist_ = 0.5*etadist_;
335  phihalfdist_ = 0.5*phidist_;
336  edm::LogVerbatim("HcalIsoTrack") << "EtaDist " << etadist_ << " "
337  << etahalfdist_ << " PhiDist " << phidist_
338  << " " <<phihalfdist_;
339  unsigned int k1(0), k2(0);
340  for (auto phi : phibins_) {
341  edm::LogVerbatim("HcalIsoTrack") << "phibin_[" << k1 << "] " << phi; ++k1;
342  }
343  for (auto eta : etabins_) {
344  edm::LogVerbatim("HcalIsoTrack") << "etabin_[" << k2 << "] " << eta; ++k2;
345  }
346 }
347 
349 
351 
352  t_Run = iEvent.id().run();
353  t_Event = iEvent.id().event();
355 #ifdef EDM_ML_DEBUG
356  edm::LogVerbatim("HcalIsoTrack") << "Run " << t_Run << " Event " << t_Event
357  << " type " << t_DataType << " Luminosity "
358  << iEvent.luminosityBlock() << " Bunch "
359  << iEvent.bunchCrossing();
360 #endif
361  //Get magnetic field and ECAL channel status
363  iSetup.get<IdealMagneticFieldRecord>().get(bFieldH);
364  const MagneticField *bField = bFieldH.product();
365 
366  // get handles to calogeometry and calotopology
368  iSetup.get<CaloGeometryRecord>().get(pG);
369  const CaloGeometry* geo = pG.product();
370 
372  iSetup.get<HcalRecNumberingRecord>().get(htopo);
373  const HcalTopology* theHBHETopology = htopo.product();
374 
376  iSetup.get<HcalRespCorrsRcd>().get(resp);
377  HcalRespCorrs* respCorrs = new HcalRespCorrs(*resp.product());
378  respCorrs->setTopo(theHBHETopology);
379 
380  //=== genParticle information
382  iEvent.getByToken(tok_parts_, genParticles);
383 
384  bool okC(true);
385  //Get track collection
387  iEvent.getByToken(tok_genTrack_, trkCollection);
388  reco::TrackCollection::const_iterator trkItr;
389  if (!trkCollection.isValid()) {
390  edm::LogWarning("HcalIsoTrack") << "Cannot access the collection "
391  << labelGenTrack_;
392  okC = false;
393  }
394 
395  //event weight for FLAT sample
396  t_EventWeight = 1.0;
398  iEvent.getByToken(tok_ew_, genEventInfo);
399  if (genEventInfo.isValid()) t_EventWeight = genEventInfo->weight();
400 
401  //Define the best vertex and the beamspot
403  iEvent.getByToken(tok_recVtx_, recVtxs);
404  edm::Handle<reco::BeamSpot> beamSpotH;
405  iEvent.getByToken(tok_bs_, beamSpotH);
406  math::XYZPoint leadPV(0,0,0);
407  t_goodPV = t_nVtx = 0;
408  if (recVtxs.isValid() && recVtxs->size()>0) {
409  t_nVtx = recVtxs->size();
410  for (unsigned int k=0; k<recVtxs->size(); ++k) {
411  if (!((*recVtxs)[k].isFake()) && ((*recVtxs)[k].ndof() > 4)) {
412  if (t_goodPV == 0) leadPV = math::XYZPoint((*recVtxs)[k].x(),(*recVtxs)[k].y(),(*recVtxs)[k].z());
413  t_goodPV++;
414  }
415  }
416  }
417  if (t_goodPV == 0 && beamSpotH.isValid()) {
418  leadPV = beamSpotH->position();
419  }
421 #ifdef EDM_ML_DEBUG
422  edm::LogVerbatim("HcalIsoTrack") << "Primary Vertex " << leadPV << " out of "
423  << t_goodPV << " vertex";
424  if (beamSpotH.isValid()) {
425  edm::LogVerbatim("HcalIsoTrack") << " Beam Spot " << beamSpotH->position();
426  }
427 #endif
428  // RecHits
429  edm::Handle<EcalRecHitCollection> barrelRecHitsHandle;
430  iEvent.getByToken(tok_EB_, barrelRecHitsHandle);
431  if (!barrelRecHitsHandle.isValid()) {
432  edm::LogWarning("HcalIsoTrack") << "Cannot access the collection "
433  << labelEB_;
434  okC = false;
435  }
436  edm::Handle<EcalRecHitCollection> endcapRecHitsHandle;
437  iEvent.getByToken(tok_EE_, endcapRecHitsHandle);
438  if (!endcapRecHitsHandle.isValid()) {
439  edm::LogWarning("HcalIsoTrack") << "Cannot access the collection "
440  << labelEE_;
441  okC = false;
442  }
444  iEvent.getByToken(tok_hbhe_, hbhe);
445  if (!hbhe.isValid()) {
446  edm::LogWarning("HcalIsoTrack") << "Cannot access the collection "
447  << labelHBHE_;
448  okC = false;
449  }
451  iEvent.getByToken(tok_cala_, caloTower);
452 
453  //Propagate tracks to calorimeter surface)
454  std::vector<spr::propagatedTrackDirection> trkCaloDirections;
455  spr::propagateCALO(trkCollection, geo, bField, theTrackQuality_,
456  trkCaloDirections, false);
457  std::vector<math::XYZTLorentzVector> vecL1, vecL3;
458  t_RunNo = iEvent.id().run();
459  t_EventNo = iEvent.id().event();
460  t_Tracks = trkCollection->size();
461  t_TracksProp = trkCaloDirections.size();
462  t_ietaAll->clear(); t_ietaGood->clear(); t_trackType->clear();
463 #ifdef EDM_ML_DEBUG
464  edm::LogVerbatim("HcalIsoTrack") << "# of propagated tracks " << t_TracksProp
465  << " out of " << t_Tracks << " with Trigger "
466  << ignoreTrigger_;
467 #endif
468 
469  //Trigger
470  t_trgbits->assign(trigNames_.size(),false);
471  t_hltbits->assign(trigNames_.size(),false);
473  t_L1Bit = true;
474  t_TrigPass = false;
475 
476  //L1
477  l1GtUtils_->retrieveL1(iEvent,iSetup,tok_alg_);
478  const std::vector<std::pair<std::string, bool> > & finalDecisions = l1GtUtils_->decisionsFinal();
479  for (const auto& decision : finalDecisions) {
480  if (decision.first.find(l1TrigName_.c_str()) != std::string::npos) {
481  t_L1Bit = decision.second;
482  break;
483  }
484  }
485 #ifdef EDM_ML_DEBUG
486  edm::LogVerbatim("HcalIsoTrack") << "Trigger Information for " << l1TrigName_
487  << " is " << t_L1Bit << " from a list of "
488  << finalDecisions.size() << " decisions";
489 #endif
490 
491  //HLT
493  iEvent.getByToken(tok_trigRes_, triggerResults);
494  if (triggerResults.isValid()) {
495  const edm::TriggerNames & triggerNames = iEvent.triggerNames(*triggerResults);
496  const std::vector<std::string> & names = triggerNames.triggerNames();
497  if (!trigNames_.empty()) {
498  for (unsigned int iHLT=0; iHLT<triggerResults->size(); iHLT++) {
499  int hlt = triggerResults->accept(iHLT);
500  for (unsigned int i=0; i<trigNames_.size(); ++i) {
501  if (names[iHLT].find(trigNames_[i].c_str())!=std::string::npos) {
502  t_trgbits->at(i) = (hlt>0);
503  t_hltbits->at(i) = (hlt>0);
504  if (hlt>0) t_TrigPass = true;
505 #ifdef EDM_ML_DEBUG
506  edm::LogVerbatim("HcalIsoTrack") << "This trigger "
507  << names[iHLT] << " Flag "
508  << hlt << ":" << t_trgbits->at(i);
509 #endif
510  }
511  }
512  }
513  }
514  }
515 #ifdef EDM_ML_DEBUG
516  edm::LogVerbatim("HcalIsoTrack") << "HLT Information shows " << t_TrigPass
517  << ":" << trigNames_.empty() << ":" << okC;
518 #endif
519 
520  std::array<int,3> ntksave{ {0,0,0} };
521  if (ignoreTrigger_ || useL1Trigger_) {
522  t_l1pt = t_l1eta = t_l1phi = 0;
523  t_l3pt = t_l3eta = t_l3phi = 0;
524  if (ignoreTrigger_ || t_L1Bit)
525  ntksave = fillTree(vecL1, vecL3, leadPV, trkCaloDirections, geo,
526  barrelRecHitsHandle, endcapRecHitsHandle, hbhe,
527  caloTower, genParticles, respCorrs);
528  t_TracksSaved = ntksave[0];
529  t_TracksLoose = ntksave[1];
530  t_TracksTight = ntksave[2];
531  } else {
532  trigger::TriggerEvent triggerEvent;
533  edm::Handle<trigger::TriggerEvent> triggerEventHandle;
534  iEvent.getByToken(tok_trigEvt_, triggerEventHandle);
535  if (!triggerEventHandle.isValid()) {
536  edm::LogWarning("HcalIsoTrack") << "Error! Can't get the product "
537  << triggerEvent_.label() ;
538  } else if (okC) {
539  triggerEvent = *(triggerEventHandle.product());
540  const trigger::TriggerObjectCollection& TOC(triggerEvent.getObjects());
541  bool done(false);
542  if (triggerResults.isValid()) {
543  std::vector<std::string> modules;
544  const edm::TriggerNames & triggerNames = iEvent.triggerNames(*triggerResults);
545  const std::vector<std::string> & names = triggerNames.triggerNames();
546  for (unsigned int iHLT=0; iHLT<triggerResults->size(); iHLT++) {
547  bool ok = (t_TrigPass) || (trigNames_.empty());
548  if (ok) {
549  unsigned int triggerindx = hltConfig_.triggerIndex(names[iHLT]);
550  const std::vector<std::string>& moduleLabels(hltConfig_.moduleLabels(triggerindx));
551  std::vector<math::XYZTLorentzVector> vecL2;
552  vecL1.clear(); vecL3.clear();
553  //loop over all trigger filters in event (i.e. filters passed)
554  for (unsigned int ifilter=0; ifilter<triggerEvent.sizeFilters();
555  ++ifilter) {
556  std::vector<int> Keys;
557  std::string label = triggerEvent.filterTag(ifilter).label();
558  //loop over keys to objects passing this filter
559  for (unsigned int imodule=0; imodule<moduleLabels.size(); imodule++) {
560  if (label.find(moduleLabels[imodule]) != std::string::npos) {
561 #ifdef EDM_ML_DEBUG
562  edm::LogVerbatim("HcalIsoTrack") << "FilterName " << label;
563 #endif
564  for (unsigned int ifiltrKey=0; ifiltrKey<triggerEvent.filterKeys(ifilter).size(); ++ifiltrKey) {
565  Keys.push_back(triggerEvent.filterKeys(ifilter)[ifiltrKey]);
566  const trigger::TriggerObject& TO(TOC[Keys[ifiltrKey]]);
567  math::XYZTLorentzVector v4(TO.px(), TO.py(), TO.pz(), TO.energy());
568  if (label.find(l2Filter_) != std::string::npos) {
569  vecL2.push_back(v4);
570  } else if (label.find(l3Filter_) != std::string::npos) {
571  vecL3.push_back(v4);
572  } else if (label.find(l1Filter_) != std::string::npos || l1Filter_ == "") {
573  vecL1.push_back(v4);
574  }
575 #ifdef EDM_ML_DEBUG
576  edm::LogVerbatim("HcalIsoTrack") << "key " << ifiltrKey
577  << " : pt " << TO.pt()
578  << " eta " << TO.eta()
579  << " phi " << TO.phi()
580  << " mass " << TO.mass()
581  <<" Id " << TO.id();
582 #endif
583  }
584 #ifdef EDM_ML_DEBUG
585  edm::LogVerbatim("HcalIsoTrack") << "sizes " << vecL1.size()
586  <<":" << vecL2.size() << ":"
587  << vecL3.size();
588 #endif
589  }
590  }
591  }
593  math::XYZTLorentzVector mindRvec1;
594  double mindR1(999);
595  for (unsigned int i=0; i<vecL2.size(); i++) {
596  double dr = dR(vecL1[0],vecL2[i]);
597 #ifdef EDM_ML_DEBUG
598  edm::LogVerbatim("HcalIsoTrack") << "lvl2[" << i << "] dR " << dr;
599 #endif
600  if (dr<mindR1) {
601  mindR1 = dr;
602  mindRvec1 = vecL2[i];
603  }
604  }
605 #ifdef EDM_ML_DEBUG
606  edm::LogVerbatim("HcalIsoTrack") << "L2 object closest to L1 "
607  << mindRvec1 << " at Dr "
608  << mindR1;
609 #endif
610 
611  if (vecL1.size()>0) {
612  t_l1pt = vecL1[0].pt();
613  t_l1eta = vecL1[0].eta();
614  t_l1phi = vecL1[0].phi();
615  } else {
616  t_l1pt = t_l1eta = t_l1phi = 0;
617  }
618  if (vecL3.size()>0) {
619  t_l3pt = vecL3[0].pt();
620  t_l3eta = vecL3[0].eta();
621  t_l3phi = vecL3[0].phi();
622  } else {
623  t_l3pt = t_l3eta = t_l3phi = 0;
624  }
625  // Now fill in the tree for each selected track
626  if (!done) {
627  ntksave = fillTree(vecL1, vecL3, leadPV, trkCaloDirections, geo,
628  barrelRecHitsHandle,endcapRecHitsHandle, hbhe,
629  caloTower, genParticles, respCorrs);
630  t_TracksSaved += ntksave[0];
631  t_TracksLoose += ntksave[1];
632  t_TracksTight += ntksave[2];
633  done = true;
634  }
635  }
636  }
637  }
638  }
639  }
640 #ifdef EDM_ML_DEBUG
641  edm::LogVerbatim("HcalIsoTrack") << "Final results on selected tracks "
642  << t_TracksSaved << ":" << t_TracksLoose
643  << ":" << t_TracksTight;
644 #endif
646  tree2->Fill();
647 }
648 
650 
651  tree = fs->make<TTree>("CalibTree", "CalibTree");
652 
653  tree->Branch("t_Run", &t_Run, "t_Run/I");
654  tree->Branch("t_Event", &t_Event, "t_Event/I");
655  tree->Branch("t_DataType", &t_DataType, "t_DataType/I");
656  tree->Branch("t_ieta", &t_ieta, "t_ieta/I");
657  tree->Branch("t_iphi", &t_iphi, "t_iphi/I");
658  tree->Branch("t_EventWeight", &t_EventWeight, "t_EventWeight/D");
659  tree->Branch("t_nVtx", &t_nVtx, "t_nVtx/I");
660  tree->Branch("t_nTrk", &t_nTrk, "t_nTrk/I");
661  tree->Branch("t_goodPV", &t_goodPV, "t_goodPV/I");
662  if (((mode_/10)%10) == 1) {
663  tree->Branch("t_l1pt", &t_l1pt, "t_l1pt/D");
664  tree->Branch("t_l1eta", &t_l1eta, "t_l1eta/D");
665  tree->Branch("t_l1phi", &t_l1phi, "t_l1phi/D");
666  tree->Branch("t_l3pt", &t_l3pt, "t_l3pt/D");
667  tree->Branch("t_l3eta", &t_l3eta, "t_l3eta/D");
668  tree->Branch("t_l3phi", &t_l3phi, "t_l3phi/D");
669  }
670  tree->Branch("t_p", &t_p, "t_p/D");
671  tree->Branch("t_pt", &t_pt, "t_pt/D");
672  tree->Branch("t_phi", &t_phi, "t_phi/D");
673  tree->Branch("t_mindR1", &t_mindR1, "t_mindR1/D");
674  tree->Branch("t_mindR2", &t_mindR2, "t_mindR2/D");
675  tree->Branch("t_eMipDR", &t_eMipDR, "t_eMipDR/D");
676  tree->Branch("t_eHcal", &t_eHcal, "t_eHcal/D");
677  tree->Branch("t_eHcal10", &t_eHcal10, "t_eHcal10/D");
678  tree->Branch("t_eHcal30", &t_eHcal30, "t_eHcal30/D");
679  tree->Branch("t_hmaxNearP", &t_hmaxNearP, "t_hmaxNearP/D");
680  tree->Branch("t_rhoh", &t_rhoh, "t_rhoh/D");
681  tree->Branch("t_selectTk", &t_selectTk, "t_selectTk/O");
682  tree->Branch("t_qltyFlag", &t_qltyFlag, "t_qltyFlag/O");
683  tree->Branch("t_qltyMissFlag",&t_qltyMissFlag,"t_qltyMissFlag/O");
684  tree->Branch("t_qltyPVFlag", &t_qltyPVFlag, "t_qltyPVFlag/O");
685  tree->Branch("t_gentrackP", &t_gentrackP, "t_gentrackP/D");
686 
687  t_DetIds = new std::vector<unsigned int>();
688  t_DetIds1 = new std::vector<unsigned int>();
689  t_DetIds3 = new std::vector<unsigned int>();
690  t_HitEnergies = new std::vector<double>();
691  t_HitEnergies1 = new std::vector<double>();
692  t_HitEnergies3 = new std::vector<double>();
693  t_trgbits = new std::vector<bool>();
694  tree->Branch("t_DetIds", "std::vector<unsigned int>", &t_DetIds);
695  tree->Branch("t_HitEnergies", "std::vector<double>", &t_HitEnergies);
696  if (((mode_/10)%10) == 1) {
697  tree->Branch("t_trgbits", "std::vector<bool>", &t_trgbits);
698  }
699  if ((mode_%10) == 1) {
700  tree->Branch("t_DetIds1", "std::vector<unsigned int>", &t_DetIds1);
701  tree->Branch("t_DetIds3", "std::vector<unsigned int>", &t_DetIds3);
702  tree->Branch("t_HitEnergies1", "std::vector<double>", &t_HitEnergies1);
703  tree->Branch("t_HitEnergies3", "std::vector<double>", &t_HitEnergies3);
704  }
705  tree2 = fs->make<TTree>("EventInfo", "Event Information");
706 
707  tree2->Branch("t_RunNo", &t_RunNo, "t_RunNo/i");
708  tree2->Branch("t_EventNo", &t_EventNo, "t_EventNo/i");
709  tree2->Branch("t_Tracks", &t_Tracks, "t_Tracks/I");
710  tree2->Branch("t_TracksProp", &t_TracksProp, "t_TracksProp/I");
711  tree2->Branch("t_TracksSaved", &t_TracksSaved, "t_TracksSaved/I");
712  tree2->Branch("t_TracksLoose", &t_TracksLoose, "t_TracksLoose/I");
713  tree2->Branch("t_TracksTight", &t_TracksTight, "t_TracksTight/I");
714  tree2->Branch("t_TrigPass", &t_TrigPass, "t_TrigPass/O");
715  tree2->Branch("t_TrigPassSel", &t_TrigPassSel, "t_TrigPassSel/O");
716  tree2->Branch("t_L1Bit", &t_L1Bit, "t_L1Bit/O");
717  tree2->Branch("t_allvertex", &t_allvertex, "t_allvertex/I");
718  t_hltbits = new std::vector<bool>();
719  t_ietaAll = new std::vector<int>();
720  t_ietaGood = new std::vector<int>();
721  t_trackType = new std::vector<int>();
722  tree2->Branch("t_ietaAll", "std::vector<int>", &t_ietaAll);
723  tree2->Branch("t_ietaGood", "std::vector<int>", &t_ietaGood);
724  tree2->Branch("t_trackType", "std::vector<int>", &t_trackType);
725  tree2->Branch("t_hltbits", "std::vector<bool>", &t_hltbits);
726 }
727 
728 
729 // ------------ method called when starting to processes a run ------------
730 void HcalIsoTrkAnalyzer::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
732  iSetup.get<HcalRecNumberingRecord>().get(pHRNDC);
733  hdc_ = pHRNDC.product();
734 
735  bool changed_(true);
736  bool flag = hltConfig_.init(iRun,iSetup,processName_,changed_);
737  edm::LogVerbatim("HcalIsoTrack") << "Run[" << nRun_ << "] " << iRun.run()
738  << " process " << processName_
739  << " init flag " << flag << " change flag "
740  << changed_;
741  // check if trigger names in (new) config
742  if (changed_) {
743  changed_ = false;
744 #ifdef EDM_ML_DEBUG
745  edm::LogVerbatim("HcalIsoTrack") << "New trigger menu found !!!";
746 #endif
747  const unsigned int n(hltConfig_.size());
748  for (unsigned itrig=0; itrig<trigNames_.size(); itrig++) {
749  unsigned int triggerindx = hltConfig_.triggerIndex(trigNames_[itrig]);
750  if (triggerindx >= n) {
751  edm::LogWarning("HcalIsoTrack") << trigNames_[itrig] << " "
752  << triggerindx << " does not exist in "
753  << "the current menu";
754 #ifdef EDM_ML_DEBUG
755  } else {
756  edm::LogVerbatim("HcalIsoTrack") << trigNames_[itrig] << " "
757  << triggerindx << " exists";
758 #endif
759  }
760  }
761  }
762 }
763 
764 // ------------ method called when ending the processing of a run ------------
766  nRun_++;
767  edm::LogVerbatim("HcalIsoTrack") << "endRun[" << nRun_ << "] " << iRun.run();
768 }
769 
772  std::vector<std::string> trig = {"HLT_PFJet40","HLT_PFJet60","HLT_PFJet80",
773  "HLT_PFJet140","HLT_PFJet200","HLT_PFJet260",
774  "HLT_PFJet320","HLT_PFJet400","HLT_PFJet450",
775  "HLT_PFJet500"};
776  desc.add<std::vector<std::string>>("triggers",trig);
777  desc.add<std::string>("processName","HLT");
778  desc.add<std::string>("l1Filter","");
779  desc.add<std::string>("l2Filter","L2Filter");
780  desc.add<std::string>("l3Filter","Filter");
781  // following 10 parameters are parameters to select good tracks
782  desc.add<std::string>("trackQuality","highPurity");
783  desc.add<double>("minTrackPt",1.0);
784  desc.add<double>("maxDxyPV",0.02);
785  desc.add<double>("maxDzPV",0.02);
786  desc.add<double>("maxChi2",5.0);
787  desc.add<double>("maxDpOverP",0.1);
788  desc.add<int>("minOuterHit",4);
789  desc.add<int>("minLayerCrossed",8);
790  desc.add<int>("maxInMiss",0);
791  desc.add<int>("maxOutMiss",0);
792  // Minimum momentum of selected isolated track and signal zone
793  desc.add<double>("minimumTrackP",20.0);
794  desc.add<double>("coneRadius",34.98);
795  // signal zone in ECAL and MIP energy cutoff
796  desc.add<double>("coneRadiusMIP",14.0);
797  desc.add<double>("maximumEcalEnergy",2.0);
798  // following 4 parameters are for isolation cuts and described in the code
799  desc.add<double>("maxTrackP",8.0);
800  desc.add<double>("slopeTrackP",0.05090504066);
801  desc.add<double>("isolationEnergyTight",2.0);
802  desc.add<double>("isolationEnergyLoose",10.0);
803  // energy thershold for ECAL (from Egamma group)
804  desc.add<double>("EBHitEnergyThreshold",0.10);
805  desc.add<double>("EEHitEnergyThreshold0",-41.0664);
806  desc.add<double>("EEHitEnergyThreshold1",68.7950);
807  desc.add<double>("EEHitEnergyThreshold2",-38.1483);
808  desc.add<double>("EEHitEnergyThreshold3",7.04303);
809  // various labels for collections used in the code
810  desc.add<edm::InputTag>("labelTriggerEvent",edm::InputTag("hltTriggerSummaryAOD","","HLT"));
811  desc.add<edm::InputTag>("labelTriggerResult",edm::InputTag("TriggerResults","","HLT"));
812  desc.add<std::string>("labelTrack","generalTracks");
813  desc.add<std::string>("labelVertex","offlinePrimaryVertices");
814  desc.add<std::string>("labelEBRecHit","EcalRecHitsEB");
815  desc.add<std::string>("labelEERecHit","EcalRecHitsEE");
816  desc.add<std::string>("labelHBHERecHit","hbhereco");
817  desc.add<std::string>("labelBeamSpot","offlineBeamSpot");
818  desc.add<std::string>("labelCaloTower","towerMaker");
819  desc.add<edm::InputTag>("algInputTag", edm::InputTag("gtStage2Digis"));
820  desc.add<edm::InputTag>("extInputTag", edm::InputTag("gtStage2Digis"));
821  desc.addUntracked<std::string>("moduleName","");
822  desc.addUntracked<std::string>("producerName","");
823  // Various flags used for selecting tracks, choice of energy Method2/0
824  // Data type 0/1 for single jet trigger or others
825  desc.addUntracked<int>("useRaw",0);
826  desc.addUntracked<bool>("ignoreTriggers",false);
827  desc.addUntracked<bool>("useL1Trigger",false);
828  desc.addUntracked<double>("hcalScale",1.0);
829  desc.addUntracked<int>("dataType",0);
830  desc.addUntracked<int>("outMode",11);
831  desc.addUntracked<bool>("unCorrect",false);
832  desc.addUntracked<bool>("collapseDepth",false);
833  desc.addUntracked<std::string>("l1TrigName","L1_SingleJet60");
834  descriptions.add("HcalIsoTrkAnalyzer",desc);
835 }
836 
837 std::array<int,3> HcalIsoTrkAnalyzer::fillTree(std::vector< math::XYZTLorentzVector>& vecL1,
838  std::vector< math::XYZTLorentzVector>& vecL3,
839  math::XYZPoint& leadPV,
840  std::vector<spr::propagatedTrackDirection>& trkCaloDirections,
841  const CaloGeometry* geo,
842  edm::Handle<EcalRecHitCollection>& barrelRecHitsHandle,
843  edm::Handle<EcalRecHitCollection>& endcapRecHitsHandle,
847  const HcalRespCorrs* respCorrs) {
848 
849  int nSave(0), nLoose(0), nTight(0);
850  //Loop over tracks
851  std::vector<spr::propagatedTrackDirection>::const_iterator trkDetItr;
852  unsigned int nTracks(0), nselTracks(0);
853  t_nTrk = trkCaloDirections.size();
854  t_rhoh = (tower.isValid()) ? rhoh(tower) : 0;
855  for (trkDetItr = trkCaloDirections.begin(),nTracks=0;
856  trkDetItr != trkCaloDirections.end(); trkDetItr++,nTracks++) {
857  const reco::Track* pTrack = &(*(trkDetItr->trkItr));
858  math::XYZTLorentzVector v4(pTrack->px(), pTrack->py(),
859  pTrack->pz(), pTrack->p());
860 #ifdef EDM_ML_DEBUG
861  edm::LogVerbatim("HcalIsoTrack") << "This track : " << nTracks
862  << " (pt|eta|phi|p) :" << pTrack->pt()
863  << "|" << pTrack->eta() << "|"
864  << pTrack->phi() << "|" <<pTrack->p();
865 #endif
866  t_mindR2 = 999;
867  for (unsigned int k=0; k<vecL3.size(); ++k) {
868  double dr = dR(vecL3[k],v4);
869  if (dr<t_mindR2) {
870  t_mindR2 = dr;
871  }
872  }
873  t_mindR1 = (vecL1.size() > 0) ? dR(vecL1[0],v4) : 999;
874 #ifdef EDM_ML_DEBUG
875  edm::LogVerbatim("HcalIsoTrack") << "Closest L3 object at dr :"
876  << t_mindR2 << " and from L1 " << t_mindR1;
877 #endif
878  t_ieta = t_iphi = 0;
879  if (trkDetItr->okHCAL) {
880  HcalDetId detId = (HcalDetId)(trkDetItr->detIdHCAL);
881  t_ieta = detId.ieta();
882  t_iphi = detId.iphi();
883  if (t_p > 40.0 && t_p <= 60.0) t_ietaAll->emplace_back(t_ieta);
884  }
885  //Selection of good track
886  t_selectTk = spr::goodTrack(pTrack,leadPV,selectionParameter_,false);
888  oneCutParameters.maxDxyPV = 10;
889  oneCutParameters.maxDzPV = 100;
890  oneCutParameters.maxInMiss = 2;
891  oneCutParameters.maxOutMiss= 2;
892  bool qltyFlag = spr::goodTrack(pTrack,leadPV,oneCutParameters,false);
893  oneCutParameters = selectionParameter_;
894  oneCutParameters.maxDxyPV = 10;
895  oneCutParameters.maxDzPV = 100;
896  t_qltyMissFlag = spr::goodTrack(pTrack,leadPV,oneCutParameters,false);
897  oneCutParameters = selectionParameter_;
898  oneCutParameters.maxInMiss = 2;
899  oneCutParameters.maxOutMiss= 2;
900  t_qltyPVFlag = spr::goodTrack(pTrack,leadPV,oneCutParameters,false);
901  double eIsolation = maxRestrictionP_*exp(slopeRestrictionP_*std::abs((double)t_ieta));
902  if (eIsolation < eIsolate1_) eIsolation = eIsolate1_;
903  if (eIsolation < eIsolate2_) eIsolation = eIsolate2_;
904 #ifdef EDM_ML_DEBUG
905  edm::LogVerbatim("HcalIsoTrack") << "qltyFlag|okECAL|okHCAL : "
906  << qltyFlag << "|" << trkDetItr->okECAL
907  << "|" << trkDetItr->okHCAL
908  << " eIsolation " << eIsolation;
909 #endif
910  t_qltyFlag = (qltyFlag && trkDetItr->okECAL && trkDetItr->okHCAL);
911  if (t_qltyFlag) {
912  nselTracks++;
913  int nNearTRKs(0);
914  std::vector<DetId> eIds;
915  std::vector<double> eHit;
916  t_eMipDR = spr::eCone_ecal(geo, barrelRecHitsHandle,
917  endcapRecHitsHandle, trkDetItr->pointHCAL,
918  trkDetItr->pointECAL, a_mipR_,
919  trkDetItr->directionECAL, eIds, eHit);
920  double eEcal(0);
921  for (unsigned int k=0; k<eIds.size(); ++k) {
922  const GlobalPoint& pos = geo->getPosition(eIds[k]);
923  double eta = std::abs(pos.eta());
924  double eThr = (eIds[k].subdetId() == EcalBarrel) ? hitEthrEB_ :
926  if (eHit[k] > eThr) eEcal += eHit[k];
927  }
928 #ifdef EDM_ML_DEBUG
929  edm::LogVerbatim("HcalIsoTrack") << "eMIP befor and after: " << t_eMipDR
930  << ":" << eEcal;
931 #endif
932  t_eMipDR = eEcal;
933  t_hmaxNearP = spr::chargeIsolationCone(nTracks, trkCaloDirections,
934  a_charIsoR_, nNearTRKs, false);
935  t_gentrackP = trackP(pTrack, genParticles);
936  if (t_eMipDR < eEcalMax_ && t_hmaxNearP < eIsolation) {
937  t_DetIds->clear(); t_HitEnergies->clear();
938  t_DetIds1->clear(); t_HitEnergies1->clear();
939  t_DetIds3->clear(); t_HitEnergies3->clear();
940  int nRecHits(-999), nRecHits1(-999), nRecHits3(-999);
941  std::vector<DetId> ids, ids1, ids3;
942  std::vector<double> edet0, edet1, edet3;
943  t_eHcal = spr::eCone_hcal(geo, hbhe, trkDetItr->pointHCAL,
944  trkDetItr->pointECAL, a_coneR_,
945  trkDetItr->directionHCAL,nRecHits,
946  ids, edet0, useRaw_);
947  storeEnergy(0,respCorrs,ids, edet0,t_eHcal, t_DetIds, t_HitEnergies);
948 
949  //----- hcal energy in the extended cone 1 (a_coneR+10) --------------
950  t_eHcal10 = spr::eCone_hcal(geo, hbhe, trkDetItr->pointHCAL,
951  trkDetItr->pointECAL, a_coneR1_,
952  trkDetItr->directionHCAL,nRecHits1,
953  ids1, edet1, useRaw_);
954  storeEnergy(1,respCorrs,ids1,edet1,t_eHcal10,t_DetIds1,t_HitEnergies1);
955 
956  //----- hcal energy in the extended cone 3 (a_coneR+30) --------------
957  t_eHcal30 = spr::eCone_hcal(geo, hbhe, trkDetItr->pointHCAL,
958  trkDetItr->pointECAL, a_coneR2_,
959  trkDetItr->directionHCAL,nRecHits3,
960  ids3, edet3, useRaw_);
961  storeEnergy(3,respCorrs,ids3,edet3,t_eHcal30,t_DetIds3,t_HitEnergies3);
962 
963  t_p = pTrack->p();
964  t_pt = pTrack->pt();
965  t_phi = pTrack->phi();
966 
967 #ifdef EDM_ML_DEBUG
968  edm::LogVerbatim("HcalIsoTrack") << "This track : " << nTracks
969  << " (pt|eta|phi|p) :" << t_pt
970  << "|" << pTrack->eta() << "|"
971  << t_phi << "|" << t_p
972  << " Generator Level p "
973  << t_gentrackP;
974  edm::LogVerbatim("HcalIsoTrack") << "e_MIP " << t_eMipDR
975  << " Chg Isolation " << t_hmaxNearP
976  << " eHcal" << t_eHcal << " ieta "
977  << t_ieta << " Quality "
978  << t_qltyMissFlag << ":"
979  << t_qltyPVFlag << ":" << t_selectTk;
980  for (unsigned int ll=0; ll<t_DetIds->size(); ll++) {
981  edm::LogVerbatim("HcalIsoTrack") << "det id is = " << t_DetIds->at(ll)
982  << " hit enery is = "
983  << t_HitEnergies->at(ll);
984  }
985  for (unsigned int ll=0; ll<t_DetIds1->size(); ll++) {
986  edm::LogVerbatim("HcalIsoTrack") << "det id is = " << t_DetIds1->at(ll)
987  << " hit enery is = "
988  << t_HitEnergies1->at(ll);
989  }
990  for (unsigned int ll=0; ll<t_DetIds3->size(); ll++) {
991  edm::LogVerbatim("HcalIsoTrack") << "det id is = " << t_DetIds3->at(ll)
992  << " hit enery is = "
993  << t_HitEnergies3->at(ll);
994  }
995 #endif
996  if (t_p>pTrackMin_) {
997  tree->Fill();
998  nSave++;
999  int type(0);
1000  if (t_eMipDR < 1.0) {
1001  if (t_hmaxNearP < eIsolate2_) { ++nLoose; type = 1;}
1002  if (t_hmaxNearP < eIsolate1_) { ++nTight; type = 2;}
1003  }
1004  if (t_p > 40.0 && t_p <= 60.0 && t_selectTk) {
1005  t_ietaGood->emplace_back(t_ieta);
1006  t_trackType->emplace_back(type);
1007  }
1008 #ifdef EDM_ML_DEBUG
1009  for (unsigned int k=0; k<t_trgbits->size(); k++) {
1010  edm::LogVerbatim("HcalIsoTrack") << "trigger bit is = "
1011  << t_trgbits->at(k);
1012  }
1013 #endif
1014  }
1015  }
1016  }
1017  }
1018  std::array<int,3> i3{ {nSave,nLoose,nTight} };
1019  return i3;
1020 }
1021 
1023  return reco::deltaR(vec1.eta(),vec1.phi(),vec2.eta(),vec2.phi());
1024 }
1025 
1028 
1029  double pmom = -1.0;
1030  if (genParticles.isValid()) {
1031  double mindR(999.9);
1032  for (const auto &p : (*genParticles)) {
1033  double dR = reco::deltaR(pTrack->eta(), pTrack->phi(),
1034  p.momentum().Eta(), p.momentum().Phi());
1035  if (dR < mindR) {
1036  mindR = dR; pmom = p.momentum().R();
1037  }
1038  }
1039  }
1040  return pmom;
1041 }
1042 
1044 
1045  std::vector<double> sumPFNallSMDQH2;
1046  sumPFNallSMDQH2.reserve(phibins_.size()*etabins_.size());
1047 
1048  for (auto eta : etabins_) {
1049  for (auto phi : phibins_) {
1050  double hadder = 0;
1051  for (const auto & pf_it : (*tower)) {
1052  if (fabs(eta-pf_it.eta())>etahalfdist_) continue;
1053  if (fabs(reco::deltaPhi(phi,pf_it.phi()))>phihalfdist_) continue;
1054  hadder += pf_it.hadEt();
1055  }
1056  sumPFNallSMDQH2.emplace_back(hadder);
1057  }
1058  }
1059 
1060  double evt_smdq(0);
1061  std::sort(sumPFNallSMDQH2.begin(),sumPFNallSMDQH2.end());
1062  if (sumPFNallSMDQH2.size()%2) evt_smdq = sumPFNallSMDQH2[(sumPFNallSMDQH2.size()-1)/2];
1063  else evt_smdq = (sumPFNallSMDQH2[sumPFNallSMDQH2.size()/2]+sumPFNallSMDQH2[(sumPFNallSMDQH2.size()-2)/2])/2.;
1064  double rhoh = evt_smdq/(etadist_*phidist_);
1065 #ifdef EDM_ML_DEBUG
1066  edm::LogVerbatim("HcalIsoTrack") << "Rho " << evt_smdq << ":" << rhoh;
1067 #endif
1068  return rhoh;
1069 }
1070 
1071 void HcalIsoTrkAnalyzer::storeEnergy(int indx, const HcalRespCorrs* respCorrs,
1072  const std::vector<DetId>& ids,
1073  std::vector<double>& edet,
1074  double & eHcal,
1075  std::vector<unsigned int> *detIds,
1076  std::vector<double> *hitEnergies) {
1077  double ehcal(0);
1078  if (unCorrect_) {
1079  for (unsigned int k=0; k<ids.size(); ++k) {
1080  double corr = (respCorrs->getValues(ids[k]))->getValue();
1081  if (corr != 0) edet[k] /= corr;
1082  ehcal += edet[k];
1083  }
1084  } else {
1085  for (const auto& en : edet) ehcal += en;
1086  }
1087  if (std::abs(ehcal-eHcal) > 0.001)
1088  edm::LogWarning("HcalIsoTrack") << "Check inconsistent energies: " << indx
1089  << " " << eHcal << ":" << ehcal
1090  << " from " << ids.size() << " cells";
1091  eHcal = hcalScale_*ehcal;
1092 
1093  if (collapseDepth_) {
1094  std::map<HcalDetId,double> hitMap;
1095  for (unsigned int k=0; k<ids.size(); ++k) {
1096  HcalDetId id = hdc_->mergedDepthDetId(HcalDetId(ids[k]));
1097  auto itr = hitMap.find(id);
1098  if (itr == hitMap.end()) {
1099  hitMap[id] = edet[k];
1100  } else {
1101  (itr->second) += edet[k];
1102  }
1103  }
1104  detIds->reserve(hitMap.size()); hitEnergies->reserve(hitMap.size());
1105  for (const auto& hit : hitMap) {
1106  detIds->emplace_back(hit.first.rawId());
1107  hitEnergies->emplace_back(hit.second);
1108  }
1109  } else {
1110  detIds->reserve(ids.size()); hitEnergies->reserve(ids.size());
1111  for (unsigned int k=0; k<ids.size(); ++k) {
1112  detIds->emplace_back(ids[k].rawId());
1113  hitEnergies->emplace_back(edet[k]);
1114  }
1115  }
1116 #ifdef EDM_ML_DEBUG
1117  edm::LogVerbatim("HcalIsoTrack") << "Input to storeEnergy with "
1118  << ids.size() << " cells";
1119  for (unsigned int k=0; k<ids.size(); ++k)
1120  edm::LogVerbatim("HcalIsoTrack") << "Hit [" << k << "] "
1121  << HcalDetId(ids[k]) << " E " << edet[k];
1122  edm::LogVerbatim("HcalIsoTrack") << "Output of storeEnergy with "
1123  << detIds->size() << " cells and Etot "
1124  << eHcal;
1125  for (unsigned int k=0; k<detIds->size(); ++k)
1126  edm::LogVerbatim("HcalIsoTrack") << "Hit [" << k << "] "
1127  << HcalDetId((*detIds)[k]) << " E "
1128  << (*hitEnergies)[k];
1129 #endif
1130 }
1131 
1132 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:39
unsigned int size() const
number of trigger paths in trigger table
static const std::string kSharedResource
Definition: TFileService.h:76
const std::string labelHBHE_
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
const std::vector< std::string > trigNames_
double p() const
momentum vector magnitude
Definition: TrackBase.h:615
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, int useRaw=0, bool debug=false)
type
Definition: HCALResponse.h:21
spr::trackSelectionParameters selectionParameter_
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
std::vector< spr::propagatedTrackID > propagateCALO(edm::Handle< reco::TrackCollection > &trkCollection, const CaloGeometry *geo, const MagneticField *bField, const std::string &theTrackQuality, bool debug=false)
const unsigned int nTracks(const reco::Vertex &sv)
const std::string l1TrigName_
const double maxRestrictionP_
edm::EDGetTokenT< EcalRecHitCollection > tok_EE_
int id() const
getters
Definition: TriggerObject.h:55
RunNumber_t run() const
Definition: RunBase.h:40
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:25
trigger::size_type sizeFilters() const
Definition: TriggerEvent.h:135
static const HistoName names[]
const std::string labelRecVtx_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
float phi() const
Definition: TriggerObject.h:58
TrackQuality
track quality
Definition: TrackBase.h:151
HcalDetId mergedDepthDetId(const HcalDetId &id) const
const std::string labelTower_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< int > * t_ietaAll
bool accept() const
Has at least one path accepted the event?
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:111
int bunchCrossing() const
Definition: EventBase.h:66
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:645
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
edm::EDGetTokenT< BXVector< GlobalAlgBlk > > tok_alg_
const Item * getValues(DetId fId, bool throwOnFail=true) const
edm::EDGetTokenT< EcalRecHitCollection > tok_EB_
float energy() const
Definition: TriggerObject.h:65
std::vector< double > * t_HitEnergies
double chargeIsolationCone(unsigned int trkIndex, std::vector< spr::propagatedTrackDirection > &trkDirs, double dR, int &nNearTRKs, bool debug=false)
virtual void beginRun(edm::Run const &, edm::EventSetup const &) override
edm::EDGetTokenT< reco::TrackCollection > tok_genTrack_
float eta() const
Definition: TriggerObject.h:57
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:627
double weight() const
void storeEnergy(int indx, const HcalRespCorrs *respCorrs, const std::vector< DetId > &ids, std::vector< double > &edet, double &eHcal, std::vector< unsigned int > *detIds, std::vector< double > *hitEnergies)
#define nullptr
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::vector< double > etabins_
Strings const & triggerNames() const
Definition: TriggerNames.cc:24
std::vector< unsigned int > * t_DetIds
edm::EDGetTokenT< HBHERecHitCollection > tok_hbhe_
std::vector< double > * t_HitEnergies1
virtual void analyze(edm::Event const &, edm::EventSetup const &) override
static const bool useL1GtTriggerMenuLite(true)
edm::EDGetTokenT< reco::GenParticleCollection > tok_parts_
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
static const bool useL1EventSetup(false)
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< trigger::TriggerEvent > tok_trigEvt_
std::vector< double > * t_HitEnergies3
const std::string labelGenTrack_
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:651
edm::EDGetTokenT< reco::BeamSpot > tok_bs_
double trackP(const reco::Track *, const edm::Handle< reco::GenParticleCollection > &)
edm::EDGetTokenT< GenEventInfoProduct > tok_ew_
edm::Service< TFileService > fs
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
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
l1t::L1TGlobalUtil * l1GtUtils_
unsigned int size() const
Get number of paths stored.
double pt() const
track transverse momentum
Definition: TrackBase.h:621
std::vector< bool > * t_hltbits
int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:74
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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)
static std::string const triggerResults
Definition: EdmProvDump.cc:41
ParameterDescriptionBase * add(U const &iLabel, T const &value)
HLTConfigProvider hltConfig_
bool isValid() const
Definition: HandleBase.h:74
const std::string l3Filter_
JetCorrectorParameters corr
Definition: classes.h:5
#define M_PI
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:639
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
int k[5][pyjets_maxn]
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
std::vector< bool > * t_trgbits
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:81
int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
const double slopeRestrictionP_
const edm::InputTag filterTag(trigger::size_type index) const
Definition: TriggerEvent.h:103
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:125
const std::string l2Filter_
T const * product() const
Definition: Handle.h:81
const std::string processName_
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
std::vector< size_type > Keys
const std::string labelEB_
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
std::vector< double > phibins_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
double rhoh(const edm::Handle< CaloTowerCollection > &)
double dR(math::XYZTLorentzVector &, math::XYZTLorentzVector &)
const edm::InputTag theTriggerResultsLabel_
std::string const & label() const
Definition: InputTag.h:36
T eta() const
Definition: PV3DBase.h:76
edm::EventID id() const
Definition: EventBase.h:60
virtual void endRun(edm::Run const &, edm::EventSetup const &) override
HLT enums.
HcalIsoTrkAnalyzer(edm::ParameterSet const &)
const HcalDDDRecConstants * hdc_
T get() const
Definition: EventSetup.h:63
reco::TrackBase::TrackQuality minQuality
const std::vector< std::pair< std::string, bool > > & decisionsFinal()
const JetExtendedData & getValue(const Container &, const reco::JetBaseRef &)
get value for the association. Throw exception if no association found
const Point & position() const
position
Definition: BeamSpot.h:62
std::vector< unsigned int > * t_DetIds1
edm::EDGetTokenT< edm::TriggerResults > tok_trigRes_
Definition: tree.py:1
const edm::InputTag triggerEvent_
float mass() const
Definition: TriggerObject.h:59
std::vector< int > * t_ietaGood
virtual void beginJob() override
std::array< int, 3 > fillTree(std::vector< math::XYZTLorentzVector > &vecL1, std::vector< math::XYZTLorentzVector > &vecL3, math::XYZPoint &leadPV, std::vector< spr::propagatedTrackDirection > &trkCaloDirections, const CaloGeometry *geo, edm::Handle< EcalRecHitCollection > &barrelRecHitsHandle, edm::Handle< EcalRecHitCollection > &endcapRecHitsHandle, edm::Handle< HBHERecHitCollection > &hbhe, edm::Handle< CaloTowerCollection > &towerHandle, edm::Handle< reco::GenParticleCollection > &genParticles, const HcalRespCorrs *respCorrs)
edm::EDGetTokenT< reco::VertexCollection > tok_recVtx_
edm::EDGetTokenT< CaloTowerCollection > tok_cala_
std::vector< vec1 > vec2
Definition: HCALResponse.h:16
std::vector< unsigned int > * t_DetIds3
T const * product() const
Definition: ESHandle.h:86
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:301
const std::string labelEE_
void setTopo(const HcalTopology *topo)
void retrieveL1(const edm::Event &iEvent, const edm::EventSetup &evSetup)
initialize the class (mainly reserve)
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:633
Definition: Run.h:44
const std::string l1Filter_
const std::string theTrackQuality_
std::vector< int > * t_trackType