CMS 3D CMS Logo

EopElecTreeWriter.cc
Go to the documentation of this file.
1 // -*- C++ -*- //
2 // Package: EopTreeWriter
3 // Class: EopTreeWriter
4 //
12 //
13 // Original Author: Holger Enderle
14 // Created: Thu Dec 4 11:22:48 CET 2008
15 // $Id: EopElecTreeWriter.cc,v 1.8 2012/08/30 08:40:51 cgoetzma Exp $
16 //
17 //
18 
19 // framework include files
76 
77 #include "TCanvas.h"
78 #include "TH1.h"
79 #include "TH2D.h"
80 #include "TLorentzVector.h"
81 #include "TMath.h"
82 #include "TTree.h"
83 
85  bool fired;
86  double prescale;
87  int index;
88 
90  fired = false;
91  prescale = 0;
92  index = 0;
93  }
94 };
95 
96 //
97 // class decleration
98 //
99 using namespace std;
100 
101 class EopElecTreeWriter : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
102 public:
103  explicit EopElecTreeWriter(const edm::ParameterSet&);
104  ~EopElecTreeWriter() override;
105 
107 
108 private:
109  // methods
110  void beginRun(const edm::Run&, const edm::EventSetup&) override;
111  void endRun(const edm::Run&, const edm::EventSetup&) override{};
112  void analyze(const edm::Event&, const edm::EventSetup&) override;
113  void endJob() override;
114 
115  // ----------member data ---------------------------
116  // ES tokens
120 
121  // EDM tokens
131 
132  // some static constants
133  static constexpr float k_etaBarrel = 1.55;
134  static constexpr float k_etaEndcap = 1.44;
135 
136  // other member data
141  TTree* tree_;
144  std::vector<std::string> triggerNames_;
146 
147  // histograms
148 
149  // Cut flow (events number)
150  TH1D* h_nEvents;
160 
161  // Cut flow (tracks number)
162  TH1D* h_nTracks;
164  TH1D* h_cut_Ptmin;
166 
167  TH1D* h_counter1;
168  TH1D* h_counter2;
169 
173  TH1D* h_Momentum;
174  TH1D* HcalEnergy;
175  TH1D* h_fBREM;
178 
179  TH2D* HcalVSEcal;
180 };
181 
182 namespace eopUtils {
183 
184  static constexpr float R_ECAL = 136.5;
185  static constexpr float Z_Endcap = 328.0;
186  static constexpr float etaBarrelEndcap = 1.479;
187 
188  // Function to convert the eta of the track to a detector eta (for matching with SC)
189  float ecalEta(float EtaParticle, float Zvertex, float RhoVertex) {
190  if (EtaParticle != 0.) {
191  float Theta = 0.0;
192  float ZEcal = (R_ECAL - RhoVertex) * sinh(EtaParticle) + Zvertex;
193 
194  if (ZEcal != 0.0)
195  Theta = atan(R_ECAL / ZEcal);
196  if (Theta < 0.0)
197  Theta = Theta + M_PI;
198 
199  float ETA = -log(tan(0.5 * Theta));
200 
201  if (fabs(ETA) > etaBarrelEndcap) {
202  float Zend = Z_Endcap;
203  if (EtaParticle < 0.0)
204  Zend = -Zend;
205  float Zlen = Zend - Zvertex;
206  float RR = Zlen / sinh(EtaParticle);
207  Theta = atan((RR + RhoVertex) / Zend);
208  if (Theta < 0.0)
209  Theta = Theta + M_PI;
210  ETA = -log(tan(0.5 * Theta));
211  }
212  return ETA;
213  } else {
214  edm::LogWarning("") << "[EcalPositionFromTrack::etaTransformation] Warning: Eta equals to zero, not correcting";
215  return EtaParticle;
216  }
217  }
218 } // namespace eopUtils
219 
220 // constructors and destructor
221 
223  : magFieldToken_(esConsumes()),
224  tkGeomToken_(esConsumes()),
225  caloGeomToken_(esConsumes()),
226  theVertexCollectionToken_(consumes<reco::VertexCollection>(edm::InputTag("offlinePrimaryVertices"))),
227  theHBHERecHitCollectionToken_(consumes<HBHERecHitCollection>(edm::InputTag("hbhereco", ""))),
228  theEcalRecHitCollectionToken_(consumes<EcalRecHitCollection>(edm::InputTag("ecalRecHit", "EcalRecHitsEB"))),
229  theBarrelSupClusCollectionToken_(
230  consumes<reco::SuperClusterCollection>(edm::InputTag("hybridSuperClusters", ""))),
231  theEndCapSupClusCollectionToken_(consumes<reco::SuperClusterCollection>(
232  edm::InputTag("multi5x5SuperClusters", "multi5x5EndcapSuperClusters"))),
233  theTriggerResultsToken_(consumes<edm::TriggerResults>(edm::InputTag("TriggerResults", "", "HLT"))),
234  theTriggerEventToken_(consumes<trigger::TriggerEvent>(edm::InputTag("hltTriggerSummaryAOD"))),
235  theGsfTrackCollectionToken_(consumes<reco::GsfTrackCollection>(iConfig.getParameter<edm::InputTag>("src"))),
236  theGsfElectronCoreCollectionToken_(
237  consumes<reco::GsfElectronCoreCollection>(edm::InputTag("gedGsfElectronCores"))),
238  theTrigger_(iConfig.getParameter<std::string>("triggerPath")),
239  theFilter_(iConfig.getParameter<std::string>("hltFilter")),
240  debugTriggerSelection_(iConfig.getParameter<bool>("debugTriggerSelection")) {
241  usesResource(TFileService::kSharedResource);
242 
243  // TTree creation
244  tree_ = fs_->make<TTree>("EopTree", "EopTree");
246  tree_->Branch("EopElecVariables", &treeMemPtr_); // address of pointer!
247 
248  // Control histograms declaration
249  h_distToClosestSC = fs_->make<TH1D>("distToClosestSC", "distToClosestSC", 100, 0, 0.1);
250  h_distToClosestSCgsf = fs_->make<TH1D>("distToClosestSCgsf", "distToClosestSCgsf", 100, 0, 0.1);
251  h_EcalEnergy = fs_->make<TH1D>("EcalEnergy", "EcalEnergy", 100, 0, 200);
252  h_Momentum = fs_->make<TH1D>("Momentum", "Momentum", 100, 0, 200);
253  HcalEnergy = fs_->make<TH1D>("HcalEnergy", "HcalEnergy", 100, 0, 40);
254  h_fBREM = fs_->make<TH1D>("fBREM", "fBREM", 100, -0.2, 1);
255  h_Eop_InnerNegative = fs_->make<TH1D>("Eop_InnerNegative", "Eop_InnerNegative", 100, 0, 3);
256  h_Eop_InnerPositive = fs_->make<TH1D>("Eop_InnerPositive", "Eop_InnerPositive", 100, 0, 3);
257  HcalVSEcal = fs_->make<TH2D>("HcalVSEcal", "HcalVSEcal", 100, 0, 160, 100, 0, 10);
258 
259  h_nEvents = fs_->make<TH1D>("nEvents", "nEvents", 1, 0, 1);
260  h_nEventsWithVertex = fs_->make<TH1D>("nEventsWithVertex", "nEventsWithVertex", 1, 0, 1);
261  h_nEventsTriggered = fs_->make<TH1D>("nEventsTriggered", "nEventsTriggered", 1, 0, 1);
262  h_nEventsHLTFilter = fs_->make<TH1D>("nEventsHLTFilter", "nEventsHLTFilter", 1, 0, 1);
263  h_nEventsHLTelectron = fs_->make<TH1D>("nEventsHLTelectron", "nEventsHLTelectron", 1, 0, 1);
264  h_nEventsHLTrejected = fs_->make<TH1D>("nEventsHLTrejected", "nEventsHLTrejected", 1, 0, 1);
265  h_nEvents2Elec = fs_->make<TH1D>("nEvents2Elec", "nEvents2Elec", 1, 0, 1);
266 
267  h_nHLTelectrons = fs_->make<TH1D>("nHLTelectrons", "nHLTelectrons", 20, 0, 20);
268  h_nTrkRejectedPerEvt = fs_->make<TH1D>("nTrkRejectedPerEvt", "nTrkRejectedPerEvt", 20, 0, 20);
269  h_nTrkSelectedPerEvt = fs_->make<TH1D>("nTrkSelectedPerEvt", "nTrkSelectedPerEvt", 20, 0, 20);
270 
271  h_nTracks = fs_->make<TH1D>("nTracks", "nTracks", 1, 0, 1);
272  h_nTracksFiltered = fs_->make<TH1D>("nTracksFiltered", "nTracksFiltered", 1, 0, 1);
273  h_cut_Ptmin = fs_->make<TH1D>("cut_Ptmin", "cut_Ptmin", 1, 0, 1);
274  h_cut_OneSCmatch = fs_->make<TH1D>("cut_OneSCmatch", "cut_OneSCmatch", 1, 0, 1);
275 
276  h_counter1 = fs_->make<TH1D>("counter1", "counter1", 1, 0, 1);
277  h_counter2 = fs_->make<TH1D>("counter2", "counter2", 1, 0, 1);
278 }
279 
281  // control histograms
282  h_distToClosestSC->SetXTitle("distance from track to closest SuperCluster in eta-phi plan (weighted matching)");
283  h_distToClosestSC->SetYTitle("# Tracks");
284 
285  h_distToClosestSCgsf->SetXTitle("distance from track to closest SuperCluster in eta-phi plan (gsfElectronCore)");
286  h_distToClosestSCgsf->SetYTitle("# Tracks");
287 
288  h_EcalEnergy->SetXTitle("Ecal energy deposit (GeV)");
289  h_EcalEnergy->SetYTitle("# tracks");
290 
291  HcalEnergy->SetXTitle("Hcal energy deposit (GeV)");
292  HcalEnergy->SetYTitle("# tracks");
293 
294  h_Momentum->SetXTitle("Momentum magnitude (GeV)");
295  h_Momentum->SetYTitle("# tracks");
296 
297  h_Eop_InnerNegative->SetXTitle("E/p");
298  h_Eop_InnerNegative->SetYTitle("# tracks");
299 
300  h_Eop_InnerPositive->SetXTitle("E/p");
301  h_Eop_InnerPositive->SetYTitle("# tracks");
302 
303  HcalVSEcal->SetXTitle("Ecal energy (GeV)");
304  HcalVSEcal->SetYTitle("Hcal energy (GeV)");
305 }
306 
307 //###########################################
308 //# method called to for each event #
309 //###########################################
310 
312  using namespace edm;
313  h_nEvents->Fill(0.5);
314 
315  Double_t EnergyHcalIn01;
316  Double_t EnergyHcalIn02;
317  Double_t EnergyHcalIn03;
318  Double_t EnergyHcalIn04;
319  Double_t EnergyHcalIn05;
320  Double_t etaWidth;
321  Double_t phiWidth;
322  Int_t algo_ID;
323  Double_t EnergyEcal;
324  Double_t fbrem;
325  Double_t pin;
326  Double_t etaIn;
327  Double_t phiIn;
328  Double_t pout;
329  Double_t etaOut;
330  Double_t phiOut;
331  Double_t MaxPtIn01;
332  Double_t SumPtIn01;
333  Bool_t NoTrackIn0015;
334  Double_t MaxPtIn02;
335  Double_t SumPtIn02;
336  Bool_t NoTrackIn0020;
337  Double_t MaxPtIn03;
338  Double_t SumPtIn03;
339  Bool_t NoTrackIn0025;
340  Double_t MaxPtIn04;
341  Double_t SumPtIn04;
342  Bool_t NoTrackIn0030;
343  Double_t MaxPtIn05;
344  Double_t SumPtIn05;
345  Bool_t NoTrackIn0035;
346  Bool_t NoTrackIn0040;
347  Double_t dRSC_first;
348  Double_t dRSC_second;
349  Double_t etaSC;
350  Double_t phiSC;
351  Int_t nbSC; //to count the nb of SuperCluster matching with a given track
352  Int_t nBasicClus; //to count the nb of basic cluster in a given superCluster
353  Bool_t isEcalDriven;
354  Bool_t isTrackerDriven;
355  Bool_t isBarrel;
356  Bool_t isEndcap;
357  Bool_t TrigTag;
358 
359  //--------------- for GsfTrack propagation through tracker ---------------
360 
361  const MagneticField* magField_ = &iSetup.getData(magFieldToken_);
362  const TrackerGeometry* trackerGeom_ = &iSetup.getData(tkGeomToken_);
363  MultiTrajectoryStateTransform mtsTransform(trackerGeom_, magField_);
364 
365  //--------------- Super Cluster -----------------
366 
367  // getting primary vertex (necessary to convert eta track to eta detector
369 
370  if (vertex.empty()) {
371  edm::LogError("EopElecTreeWriter") << "Error: no primary vertex found!";
372  return;
373  }
374  const reco::Vertex& vert = vertex.front();
375  h_nEventsWithVertex->Fill(0.5);
376 
377  // getting calorimeter geometry
378  const CaloGeometry* geo = &iSetup.getData(caloGeomToken_);
380  if (subGeo == nullptr)
381  edm::LogError("EopElecTreeWriter") << "ERROR: unable to find SubDetector geometry!!!";
382 
383  // getting Hcal rechits
385 
386  // getting Ecal rechits
388  if (rhc == nullptr)
389  edm::LogError("EopElecTreeWriter") << "ERROR: unable to find the EcalRecHit collection !!!";
390 
391  // getting SuperCluster
392  const reco::SuperClusterCollection* BarrelSupClusCollection = &iEvent.get(theBarrelSupClusCollectionToken_);
393  const reco::SuperClusterCollection* EndcapSupClusCollection = &iEvent.get(theEndCapSupClusCollectionToken_);
394 
395  // necessary to re-calculate phi and eta width of SuperClusters
396  SuperClusterShapeAlgo SCShape(rhc, subGeo);
397 
398  //--------------- Trigger -----------------
399  TrigTag = false;
400  const edm::TriggerResults* trigRes = &iEvent.get(theTriggerResultsToken_);
401 
402  // trigger event
404 
405  // our trigger table
406  std::map<std::string, EopTriggerType> HLTpaths;
407  for (const auto& triggerName : triggerNames_) {
408  if (triggerName.find(theTrigger_) != 0)
409  continue;
410  EopTriggerType myTrigger;
411 
412  const unsigned int prescaleSize = hltConfig_.prescaleSize();
413  for (unsigned int ps = 0; ps < prescaleSize; ps++) {
414  auto const prescaleValue = hltConfig_.prescaleValue<double>(ps, triggerName);
415  if (prescaleValue != 1) {
416  myTrigger.prescale = prescaleValue;
417  }
418  }
419 
421  if (myTrigger.index == -1)
422  continue;
423  myTrigger.fired =
424  trigRes->wasrun(myTrigger.index) && trigRes->accept(myTrigger.index) && !trigRes->error(myTrigger.index);
425  HLTpaths[triggerName] = myTrigger;
426  }
427 
428  // First cut : trigger cut
429  std::string firstFiredPath = "";
430  for (const auto& it : HLTpaths) {
431  if (it.second.fired) {
432  TrigTag = true;
433  firstFiredPath = it.first;
434  break;
435  }
436  }
437  if (!TrigTag)
438  return;
439  h_nEventsTriggered->Fill(0.5);
440 
441  // Displaying filters label from the first fired trigger
442  // Useful for finding the good filter label
443  std::vector<std::string> filters = hltConfig_.moduleLabels(firstFiredPath);
444 
446  edm::LogInfo("EopElecTreeWriter") << "filters : ";
447  for (unsigned int i = 0; i < filters.size(); i++) {
448  edm::LogInfo("EopElecTreeWriter") << filters[i] << " ";
449  }
450  }
451 
452  // Getting HLT electrons
453  edm::InputTag testTag(theFilter_, "", "HLT");
454  int testindex = triggerEvent->filterIndex(testTag);
455 
456  if (testindex >= triggerEvent->sizeFilters())
457  return;
458  h_nEventsHLTFilter->Fill(0.5);
459 
460  const trigger::Keys& KEYS_el(triggerEvent->filterKeys(testindex));
461 
462  std::vector<const trigger::TriggerObject*> HLTelectrons;
463  for (unsigned int i = 0; i != KEYS_el.size(); ++i) {
464  const trigger::TriggerObject* triggerObject_el = &(triggerEvent->getObjects().at(KEYS_el[i]));
465  HLTelectrons.push_back(triggerObject_el);
466  }
467 
468  h_nHLTelectrons->Fill(HLTelectrons.size());
469 
470  if (HLTelectrons.empty())
471  return;
472  h_nEventsHLTelectron->Fill(0.5);
473 
474  // finding the HLT electron with highest pt and saving the corresponding index
475  unsigned int HighPtIndex = 0;
476  double maxPtHLT = -5.;
477  for (unsigned int j = 0; j < HLTelectrons.size(); j++) {
478  if (HLTelectrons[j]->pt() > maxPtHLT) {
479  maxPtHLT = HLTelectrons[j]->pt();
480  HighPtIndex = j;
481  }
482  }
483 
484  //----------------- Tracks -------------------
485 
486  // getting GsfTrack
488 
489  // filtering track
490  int nRejected = 0;
491  int nSelected = 0;
492  std::vector<const reco::GsfTrack*> filterTracks;
493  for (const auto& track : tracks) {
494  h_nTracks->Fill(0.5);
495  double deltar =
496  reco::deltaR(track.eta(), track.phi(), HLTelectrons[HighPtIndex]->eta(), HLTelectrons[HighPtIndex]->phi());
497  // remove the triggered electron with highest pt
498  if (deltar < 0.025) {
503  nRejected++;
504  continue;
505  }
506  filterTracks.push_back(&track); // we use all the others
507  nSelected++;
508  h_nTracksFiltered->Fill(0.5);
509  }
510  h_nTrkRejectedPerEvt->Fill(nRejected);
511  h_nTrkSelectedPerEvt->Fill(nSelected);
512 
513  if (nRejected == 0)
514  return;
515  h_nEventsHLTrejected->Fill(0.5);
516 
517  if (filterTracks.empty())
518  return;
519  h_nEvents2Elec->Fill(0.5);
520 
521  //-------- test:Matching SC/track using gsfElectonCore collection --------
522 
524  for (const auto& elec : *electrons) {
525  double etaGSF = eopUtils::ecalEta((elec.gsfTrack())->eta(), vert.z(), (vert.position()).rho());
526  if ((elec.gsfTrack())->pt() < 10.)
527  continue;
528 
529  double DELTAR = 0;
530  DELTAR = reco::deltaR((elec.superCluster())->eta(), (elec.superCluster())->phi(), etaGSF, (elec.gsfTrack())->phi());
531 
532  if (DELTAR < 0.1)
533  h_distToClosestSCgsf->Fill(DELTAR);
534  }
535 
536  //------------------------------------------------------------
537  //-------------- Loop on tracks -------------------------
538 
539  for (const auto& track : filterTracks) {
540  // initializing variables
541  isEcalDriven = false;
542  isTrackerDriven = false;
543  isBarrel = false;
544  isEndcap = false;
545  etaWidth = 0;
546  phiWidth = 0;
547  etaSC = 0;
548  phiSC = 0;
549  fbrem = 0;
550  pin = 0;
551  etaIn = 0;
552  phiIn = 0;
553  pout = 0;
554  etaOut = 0;
555  phiOut = 0;
556  algo_ID = 0;
557  EnergyEcal = 0;
558  dRSC_first = 999;
559  dRSC_second = 9999;
560  nbSC = 0;
561  nBasicClus = 0;
562 
563  // First cut on momentum magnitude
564  h_Momentum->Fill(track->p());
565  if (track->pt() < 10.)
566  continue;
567  h_cut_Ptmin->Fill(0.5);
568 
569  // calculating track parameters at innermost and outermost for Gsf tracks
570  TrajectoryStateOnSurface inTSOS = mtsTransform.innerStateOnSurface(*track);
571  TrajectoryStateOnSurface outTSOS = mtsTransform.outerStateOnSurface(*track);
572  if (inTSOS.isValid() && outTSOS.isValid()) {
573  GlobalVector inMom;
574  //multiTrajectoryStateMode::momentumFromModeCartesian(inTSOS, inMom_);
576  pin = inMom.mag();
577  etaIn = inMom.eta();
578  phiIn = inMom.phi();
579  GlobalVector outMom;
580  //multiTrajectoryStateMode::momentumFromModeCartesian(outTSOS, outMom_);
582  pout = outMom.mag();
583  etaOut = outMom.eta();
584  phiOut = outMom.phi();
585  fbrem = (pin - pout) / pin;
586  h_fBREM->Fill(fbrem);
587  }
588 
589  // Matching track with Hcal rec hits
590  EnergyHcalIn01 = 0;
591  EnergyHcalIn02 = 0;
592  EnergyHcalIn03 = 0;
593  EnergyHcalIn04 = 0;
594  EnergyHcalIn05 = 0;
595 
596  //for (std::vector<HBHERecHit>::const_iterator hcal = (*HcalHits).begin(); hcal != (*HcalHits).end(); hcal++) {
597  for (const auto& hcal : *HcalHits) {
598  GlobalPoint posH = geo->getPosition(hcal.detid());
599  double phihit = posH.phi();
600  double etahit = posH.eta();
601  double dR = reco::deltaR(etahit, phihit, etaOut, phiOut);
602 
603  // saving Hcal energy deposit measured for different eta-phi radius
604  if (dR < 0.1)
605  EnergyHcalIn01 += hcal.energy();
606  if (dR < 0.2)
607  EnergyHcalIn02 += hcal.energy();
608  if (dR < 0.3)
609  EnergyHcalIn03 += hcal.energy();
610  if (dR < 0.4)
611  EnergyHcalIn04 += hcal.energy();
612  if (dR < 0.5)
613  EnergyHcalIn05 += hcal.energy();
614  }
615 
616  HcalEnergy->Fill(EnergyHcalIn02);
617 
618  //Isolation against charged particles
619  MaxPtIn01 = 0.;
620  SumPtIn01 = 0.;
621  NoTrackIn0015 = true;
622  MaxPtIn02 = 0.;
623  SumPtIn02 = 0.;
624  NoTrackIn0020 = true;
625  MaxPtIn03 = 0.;
626  SumPtIn03 = 0.;
627  NoTrackIn0025 = true;
628  MaxPtIn04 = 0.;
629  SumPtIn04 = 0.;
630  NoTrackIn0030 = true;
631  MaxPtIn05 = 0.;
632  SumPtIn05 = 0.;
633  NoTrackIn0035 = true;
634  NoTrackIn0040 = true;
635 
636  for (const auto& track1 : filterTracks) {
637  if (track == track1)
638  continue;
639 
640  double etaIn1 = 0.;
641  double phiIn1 = 0.;
642 
643  TrajectoryStateOnSurface inTSOS1 = mtsTransform.innerStateOnSurface(*track1);
644  if (inTSOS1.isValid()) {
645  GlobalVector inMom1;
647  etaIn1 = inMom1.eta();
648  phiIn1 = inMom1.phi();
649  }
650 
651  if (etaIn1 == 0 && phiIn1 == 0)
652  continue;
653 
654  double dR = reco::deltaR(etaIn1, phiIn1, etaIn, phiIn);
655 
656  // different radius of inner isolation cone
657  if (dR < 0.015)
658  NoTrackIn0015 = false;
659  if (dR < 0.020)
660  NoTrackIn0020 = false;
661  if (dR < 0.025)
662  NoTrackIn0025 = false;
663  if (dR < 0.030)
664  NoTrackIn0030 = false;
665  if (dR < 0.035)
666  NoTrackIn0035 = false;
667  if (dR < 0.040)
668  NoTrackIn0040 = false;
669 
670  //calculate maximum Pt and sum Pt inside cones of different radius
671  if (dR < 0.1) {
672  SumPtIn01 += track1->pt();
673  if (track1->pt() > MaxPtIn01) {
674  MaxPtIn01 = track1->pt();
675  }
676  }
677 
678  if (dR < 0.2) {
679  SumPtIn02 += track1->pt();
680  if (track1->pt() > MaxPtIn02) {
681  MaxPtIn02 = track1->pt();
682  }
683  }
684  if (dR < 0.3) {
685  SumPtIn03 += track1->pt();
686  if (track1->pt() > MaxPtIn03) {
687  MaxPtIn03 = track1->pt();
688  }
689  }
690  if (dR < 0.4) {
691  SumPtIn04 += track1->pt();
692  if (track1->pt() > MaxPtIn04) {
693  MaxPtIn04 = track1->pt();
694  }
695  }
696  if (dR < 0.5) {
697  SumPtIn05 += track1->pt();
698  if (track1->pt() > MaxPtIn05) {
699  MaxPtIn05 = track1->pt();
700  }
701  }
702  }
703 
704  // Track-SuperCluster matching
705 
706  double dRSC;
707  double etaAtEcal = 0; // to convert eta from track to detector frame
708  etaAtEcal = eopUtils::ecalEta(etaIn, vert.z(), (vert.position()).rho());
709 
710  //Barrel
711  if (std::abs(track->eta()) < k_etaBarrel) {
712  for (const auto& SC : *BarrelSupClusCollection) {
713  dRSC = reco::deltaR(SC.eta(), SC.phi(), etaAtEcal, phiIn);
714 
715  if (dRSC < dRSC_first) {
716  dRSC_first = dRSC;
717  } // distance in eta-phi plan to closest SC
718  else if (dRSC < dRSC_second) {
719  dRSC_second = dRSC;
720  } // to next closest SC
721 
722  if (dRSC < 0.09) {
723  //Calculate phiWidth & etaWidth for associated SuperClusters
724  SCShape.Calculate_Covariances(SC);
725  phiWidth = SCShape.phiWidth();
726  etaWidth = SCShape.etaWidth();
727 
728  etaSC = SC.eta();
729  phiSC = SC.phi();
730 
731  algo_ID = SC.algoID();
732  EnergyEcal = SC.energy();
733  nBasicClus = SC.clustersSize();
734  nbSC++;
735  isBarrel = true;
736  }
737  }
738  }
739 
740  // Endcap
741  if (std::abs(track->eta()) > k_etaEndcap) {
742  for (const auto& SC : *EndcapSupClusCollection) {
743  dRSC = reco::deltaR(SC.eta(), SC.phi(), etaAtEcal, phiIn);
744 
745  if (dRSC < dRSC_first) {
746  dRSC_first = dRSC;
747  } // distance in eta-phi plan to closest SC
748  else if (dRSC < dRSC_second) {
749  dRSC_second = dRSC;
750  } // to next closest SC
751 
752  if (dRSC < 0.09) {
753  //Calculate phiWidth & etaWidth for associated SuperClusters
754  SCShape.Calculate_Covariances(SC);
755  phiWidth = SCShape.phiWidth();
756  etaWidth = SCShape.etaWidth();
757 
758  etaSC = SC.eta();
759  phiSC = SC.phi();
760 
761  algo_ID = SC.algoID();
762  EnergyEcal = SC.energy();
763  nBasicClus = SC.clustersSize();
764  nbSC++;
765  isEndcap = true;
766  }
767  }
768  }
769 
770  if (dRSC_first < 0.1)
771  h_distToClosestSC->Fill(dRSC_first);
772  if (nbSC == 1)
773  h_counter1->Fill(0.5);
774  if (nbSC == 0)
775  h_counter2->Fill(0.5);
776 
777  if (nbSC > 1 || nbSC == 0)
778  continue;
779  h_cut_OneSCmatch->Fill(0.5);
780 
781  if (isBarrel && isEndcap) {
782  edm::LogError("EopElecTreeWriter") << "Error: Super Cluster double matching!";
783  return;
784  }
785 
786  h_EcalEnergy->Fill(EnergyEcal);
787  HcalVSEcal->Fill(EnergyEcal, EnergyHcalIn02);
788 
789  // E over p plots
790  if (track->charge() < 0)
791  h_Eop_InnerNegative->Fill(EnergyEcal / pin);
792  if (track->charge() > 0)
793  h_Eop_InnerPositive->Fill(EnergyEcal / pin);
794 
795  //Check if track-SuperCluster matching is Ecal or Tracker driven
796  edm::RefToBase<TrajectorySeed> seed = track->extra()->seedRef();
797  if (seed.isNull()) {
798  edm::LogError("GsfElectronCore") << "The GsfTrack has no seed ?!";
799  } else {
801  if (elseed.isNull()) {
802  edm::LogError("GsfElectronCore") << "The GsfTrack seed is not an ElectronSeed ?!";
803  } else {
804  isEcalDriven = elseed->isEcalDriven();
805  isTrackerDriven = elseed->isTrackerDriven();
806  }
807  }
808 
809  treeMemPtr_->charge = track->charge();
810  treeMemPtr_->nHits = track->numberOfValidHits();
811  treeMemPtr_->nLostHits = track->numberOfLostHits();
812  treeMemPtr_->innerOk = track->innerOk();
813  treeMemPtr_->outerRadius = track->outerRadius();
814  treeMemPtr_->chi2 = track->chi2();
815  treeMemPtr_->normalizedChi2 = track->normalizedChi2();
816  treeMemPtr_->px = track->px();
817  treeMemPtr_->py = track->py();
818  treeMemPtr_->pz = track->pz();
819  treeMemPtr_->p = track->p();
820  treeMemPtr_->pIn = pin;
821  treeMemPtr_->etaIn = etaIn;
822  treeMemPtr_->phiIn = phiIn;
823  treeMemPtr_->pOut = pout;
824  treeMemPtr_->etaOut = etaOut;
825  treeMemPtr_->phiOut = phiOut;
826  treeMemPtr_->pt = track->pt();
827  treeMemPtr_->ptError = track->ptError();
828  treeMemPtr_->theta = track->theta();
829  treeMemPtr_->eta = track->eta();
830  treeMemPtr_->phi = track->phi();
832  treeMemPtr_->MaxPtIn01 = MaxPtIn01;
833  treeMemPtr_->SumPtIn01 = SumPtIn01;
834  treeMemPtr_->NoTrackIn0015 = NoTrackIn0015;
835  treeMemPtr_->MaxPtIn02 = MaxPtIn02;
836  treeMemPtr_->SumPtIn02 = SumPtIn02;
837  treeMemPtr_->NoTrackIn0020 = NoTrackIn0020;
838  treeMemPtr_->MaxPtIn03 = MaxPtIn03;
839  treeMemPtr_->SumPtIn03 = SumPtIn03;
840  treeMemPtr_->NoTrackIn0025 = NoTrackIn0025;
841  treeMemPtr_->MaxPtIn04 = MaxPtIn04;
842  treeMemPtr_->SumPtIn04 = SumPtIn04;
843  treeMemPtr_->NoTrackIn0030 = NoTrackIn0030;
844  treeMemPtr_->MaxPtIn05 = MaxPtIn05;
845  treeMemPtr_->SumPtIn05 = SumPtIn05;
846  treeMemPtr_->NoTrackIn0035 = NoTrackIn0035;
847  treeMemPtr_->NoTrackIn0040 = NoTrackIn0040;
848  treeMemPtr_->SC_algoID = algo_ID;
849  treeMemPtr_->SC_energy = EnergyEcal;
850  treeMemPtr_->SC_nBasicClus = nBasicClus;
853  treeMemPtr_->SC_eta = etaSC;
854  treeMemPtr_->SC_phi = phiSC;
857  treeMemPtr_->dRto1stSC = dRSC_first;
858  treeMemPtr_->dRto2ndSC = dRSC_second;
859  treeMemPtr_->HcalEnergyIn01 = EnergyHcalIn01;
860  treeMemPtr_->HcalEnergyIn02 = EnergyHcalIn02;
861  treeMemPtr_->HcalEnergyIn03 = EnergyHcalIn03;
862  treeMemPtr_->HcalEnergyIn04 = EnergyHcalIn04;
863  treeMemPtr_->HcalEnergyIn05 = EnergyHcalIn05;
865  treeMemPtr_->isTrackerDriven = isTrackerDriven;
866  treeMemPtr_->RunNumber = iEvent.id().run();
867  treeMemPtr_->EvtNumber = iEvent.id().event();
868 
869  tree_->Fill();
870 
871  } // loop on tracks
872 } // analyze
873 
874 // ------------ method called once each job just after ending the event loop ------------
876  delete treeMemPtr_;
877  treeMemPtr_ = nullptr;
878 }
879 
880 // ------------ method called once each job just before starting event loop ------------
881 void EopElecTreeWriter::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
882  bool changed = true;
883 
884  // Load trigger configuration at each begin of run
885  // Fill the trigger names
886  if (hltConfig_.init(iRun, iSetup, "HLT", changed)) {
887  if (changed) {
889  }
890  }
891 
892  // Displaying the trigger names
894  unsigned int i = 0;
895  for (const auto& it : triggerNames_) {
896  edm::LogInfo("EopElecTreeWriter") << "HLTpath: " << (i++) << " = " << it;
897  }
898  }
899 }
900 
901 //*************************************************************
903 //*************************************************************
904 {
906  desc.setComment("Generate tree for Tracker Alignment E/p validation");
907  desc.add<edm::InputTag>("src", edm::InputTag("electronGsfTracks"));
908  desc.add<std::string>("triggerPath", "HLT_Ele");
909  desc.add<std::string>("hltFilter", "hltDiEle27L1DoubleEGWPTightHcalIsoFilter");
910  desc.add<bool>("debugTriggerSelection", false);
911  descriptions.addWithDefaultLabel(desc);
912 }
913 
914 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
bool accept() const
Has at least one path accepted the event?
const edm::EDGetTokenT< reco::SuperClusterCollection > theEndCapSupClusCollectionToken_
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void Calculate_Covariances(const reco::SuperCluster &passedCluster)
unsigned int prescaleSize() const
static void fillDescriptions(edm::ConfigurationDescriptions &)
bool error() const
Has any path encountered an error (exception)
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:26
double z() const
z coordinate
Definition: Vertex.h:134
Double_t px_rejected_track
const edm::EDGetTokenT< HBHERecHitCollection > theHBHERecHitCollectionToken_
std::vector< std::string > triggerNames_
TrajectoryStateOnSurface outerStateOnSurface(const reco::GsfTrack &tk) const
const Point & position() const
position
Definition: Vertex.h:128
void beginRun(const edm::Run &, const edm::EventSetup &) override
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
T eta() const
Definition: PV3DBase.h:73
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
float ecalEta(float EtaParticle, float Zvertex, float RhoVertex)
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
Log< level::Error, false > LogError
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeomToken_
EopElecVariables * treeMemPtr_
static constexpr float R_ECAL
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
void endJob() override
std::vector< TPRegexp > filters
Definition: eve_filter.cc:22
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
bool wasrun() const
Was at least one path run?
T prescaleValue(unsigned int set, const std::string &trigger) const
HLT prescale value in specific prescale set for a specific trigger path.
const edm::EDGetTokenT< EcalRecHitCollection > theEcalRecHitCollectionToken_
const edm::EDGetTokenT< reco::SuperClusterCollection > theBarrelSupClusCollectionToken_
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:21
edm::Service< TFileService > fs_
#define ETA
int iEvent
Definition: GenABIO.cc:224
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:50
const edm::EDGetTokenT< reco::GsfElectronCoreCollection > theGsfElectronCoreCollectionToken_
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
static constexpr float k_etaBarrel
TrajectoryStateOnSurface innerStateOnSurface(const reco::GsfTrack &tk) const
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
std::vector< GsfElectronCore > GsfElectronCoreCollection
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
T mag() const
Definition: PV3DBase.h:64
const edm::EDGetTokenT< reco::VertexCollection > theVertexCollectionToken_
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const edm::EDGetTokenT< edm::TriggerResults > theTriggerResultsToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
unsigned int triggerIndex(const std::string &triggerName) const
slot position of trigger path in trigger table (0 to size-1)
static constexpr float etaBarrelEndcap
HLTConfigProvider hltConfig_
Double_t p_rejected_track
bool isNull() const
Checks for null.
Definition: Ref.h:235
bool isEndcap(GeomDetEnumerators::SubDetector m)
void analyze(const edm::Event &, const edm::EventSetup &) override
#define M_PI
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
Log< level::Info, false > LogInfo
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::EDGetTokenT< trigger::TriggerEvent > theTriggerEventToken_
Definition: deltar.py:1
std::vector< size_type > Keys
Double_t pz_rejected_track
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
~EopElecTreeWriter() override
const std::vector< std::string > & triggerNames() const
names of trigger paths
bool momentumFromModePPhiEta(TrajectoryStateOnSurface const &tsos, GlobalVector &momentum)
fixed size matrix
HLT enums.
EopElecTreeWriter(const edm::ParameterSet &)
void endRun(const edm::Run &, const edm::EventSetup &) override
static constexpr float k_etaEndcap
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
Log< level::Warning, false > LogWarning
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
const edm::EDGetTokenT< reco::GsfTrackCollection > theGsfTrackCollectionToken_
Double_t py_rejected_track
static constexpr float Z_Endcap
Definition: Run.h:45
MultiTrajectoryStateTransform * mtsTransform_