CMS 3D CMS Logo

PatElectronAnalyzer.cc
Go to the documentation of this file.
1 #include "TH1.h"
2 #include "TH2.h"
3 #include "TMath.h"
4 
11 
14 
15 class PatElectronAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
16 public:
17  explicit PatElectronAnalyzer(const edm::ParameterSet &);
18  ~PatElectronAnalyzer() override;
19 
20 private:
21  void beginJob() override;
22  void analyze(const edm::Event &, const edm::EventSetup &) override;
23  void endJob() override;
24 
25  // restrictions for the electron to be
26  // considered
27  double minPt_;
28  double maxEta_;
29 
30  // decide in which mode to run the analyzer
31  // 0 : genMatch, 1 : tagAndProbe are
32  // supported depending on the line comments
33  unsigned int mode_;
34 
35  // choose a given electronID for the electron
36  // in consideration; the following types are
37  // available:
38  // * eidRobustLoose
39  // * eidRobustTight
40  // * eidLoose
41  // * eidTight
42  // * eidRobustHighEnergy
44 
45  // source of electrons
47  // source of generator particles
49 
52 
53  // internal variables for genMatchMode and
54  // tagAndProbeMode
55  double maxDeltaR_;
56  double maxDeltaM_;
57  double maxTagIso_;
58 
59  // book histograms of interest
60  TH1I *nr_;
61  TH1F *pt_;
62  TH1F *eta_;
63  TH1F *phi_;
64  TH1F *genPt_;
65  TH1F *genEta_;
66  TH1F *genPhi_;
67  TH1F *deltaR_;
68  TH1F *isoTag_;
69  TH1F *invMass_;
70  TH1F *deltaPhi_;
71 };
72 
73 #include "Math/VectorUtil.h"
74 
76  : minPt_(cfg.getParameter<double>("minPt")),
77  maxEta_(cfg.getParameter<double>("maxEta")),
78  mode_(cfg.getParameter<unsigned int>("mode")),
79  electronID_(cfg.getParameter<std::string>("electronID")),
80  electronSrcToken_(consumes<std::vector<pat::Electron> >(cfg.getParameter<edm::InputTag>("electronSrc"))),
81  particleSrcToken_(consumes<reco::GenParticleCollection>(cfg.getParameter<edm::InputTag>("particleSrc"))),
82  genMatchMode_(cfg.getParameter<edm::ParameterSet>("genMatchMode")),
83  tagAndProbeMode_(cfg.getParameter<edm::ParameterSet>("tagAndProbeMode")) {
84  usesResource(TFileService::kSharedResource);
85 
86  // complete the configuration of the analyzer
87  maxDeltaR_ = genMatchMode_.getParameter<double>("maxDeltaR");
88  maxDeltaM_ = tagAndProbeMode_.getParameter<double>("maxDeltaM");
89  maxTagIso_ = tagAndProbeMode_.getParameter<double>("maxTagIso");
90 
91  // register histograms to the TFileService
93  nr_ = fs->make<TH1I>("nr", "nr", 10, 0, 10);
94  pt_ = fs->make<TH1F>("pt", "pt", 20, 0., 100.);
95  eta_ = fs->make<TH1F>("eta", "eta", 30, -3., 3.);
96  phi_ = fs->make<TH1F>("phi", "phi", 35, -3.5, 3.5);
97  genPt_ = fs->make<TH1F>("genPt", "pt", 20, 0., 100.);
98  genEta_ = fs->make<TH1F>("genEta", "eta", 30, -3., 3.);
99  genPhi_ = fs->make<TH1F>("genPhi", "phi", 35, -3.5, 3.5);
100  deltaR_ = fs->make<TH1F>("deltaR", "log(dR)", 50, -5., 0.);
101  isoTag_ = fs->make<TH1F>("isoTag", "iso", 50, 0., 10.);
102  invMass_ = fs->make<TH1F>("invMass", "m", 100, 50., 150.);
103  deltaPhi_ = fs->make<TH1F>("deltaPhi", "deltaPhi", 100, -3.5, 3.5);
104 }
105 
107 
109  // get electron collection
112  // get generator particle collection
115 
116  nr_->Fill(electrons->size());
117 
118  // ----------------------------------------------------------------------
119  //
120  // First Part Mode 0: genMatch
121  //
122  // ----------------------------------------------------------------------
123  if (mode_ == 0) {
124  // loop generator particles
125  for (reco::GenParticleCollection::const_iterator part = particles->begin(); part != particles->end(); ++part) {
126  // only loop stable electrons
127  if (part->status() == 1 && abs(part->pdgId()) == 11) {
128  if (part->pt() > minPt_ && fabs(part->eta()) < maxEta_) {
129  genPt_->Fill(part->pt());
130  genEta_->Fill(part->eta());
131  genPhi_->Fill(part->phi());
132  }
133  }
134  }
135 
136  // loop electrons
137  for (std::vector<pat::Electron>::const_iterator elec = electrons->begin(); elec != electrons->end(); ++elec) {
138  if (elec->genLepton()) {
139  float deltaR = ROOT::Math::VectorUtil::DeltaR(elec->genLepton()->p4(), elec->p4());
140  deltaR_->Fill(TMath::Log10(deltaR));
141  if (deltaR < maxDeltaR_) {
142  if (electronID_ != "none") {
143  if (elec->electronID(electronID_) < 0.5)
144  continue;
145  }
146  if (elec->pt() > minPt_ && fabs(elec->eta()) < maxEta_) {
147  pt_->Fill(elec->pt());
148  eta_->Fill(elec->eta());
149  phi_->Fill(elec->phi());
150  }
151  }
152  }
153  }
154  }
155 
156  // ----------------------------------------------------------------------
157  //
158  // Second Part Mode 1: tagAndProbe
159  //
160  // ----------------------------------------------------------------------
161  if (mode_ == 1) {
162  // loop tag electron
163  for (std::vector<pat::Electron>::const_iterator elec = electrons->begin(); elec != electrons->end(); ++elec) {
164  isoTag_->Fill(elec->trackIso());
165  if (elec->trackIso() < maxTagIso_ && elec->electronID("eidTight") > 0.5) {
166  // loop probe electron
167  for (std::vector<pat::Electron>::const_iterator probe = electrons->begin(); probe != electrons->end();
168  ++probe) {
169  // skip the tag electron itself
170  if (probe == elec)
171  continue;
172 
173  float zMass = (probe->p4() + elec->p4()).mass();
174  invMass_->Fill(zMass);
175  float deltaPhi = ROOT::Math::VectorUtil::DeltaPhi(elec->p4(), probe->p4());
176  deltaPhi_->Fill(deltaPhi);
177 
178  // check for the Z mass
179  if (fabs(zMass - 90.) < maxDeltaM_) {
180  if (electronID_ != "none") {
181  if (probe->electronID(electronID_) < 0.5)
182  continue;
183  }
184  if (probe->pt() > minPt_ && fabs(probe->eta()) < maxEta_) {
185  pt_->Fill(probe->pt());
186  eta_->Fill(probe->eta());
187  phi_->Fill(probe->phi());
188  }
189  }
190  }
191  }
192  }
193  }
194 }
195 
197 
199 
static const std::string kSharedResource
Definition: TFileService.h:76
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< std::vector< pat::Electron > > electronSrcToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:536
Definition: HeavyIon.h:7
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< reco::GenParticleCollection > particleSrcToken_
edm::ParameterSet tagAndProbeMode_
part
Definition: HCALResponse.h:20
fixed size matrix
HLT enums.
edm::ParameterSet genMatchMode_
void analyze(const edm::Event &, const edm::EventSetup &) override
PatElectronAnalyzer(const edm::ParameterSet &)