CMS 3D CMS Logo

DQMExample_Step1.cc
Go to the documentation of this file.
3 
4 
5 // Geometry
9 #include "TLorentzVector.h"
10 
11 
12 #include <iostream>
13 #include <iomanip>
14 #include <cstdio>
15 #include <string>
16 #include <sstream>
17 #include <cmath>
18 
19 //
20 // -------------------------------------- Constructor --------------------------------------------
21 //
23 {
24  edm::LogInfo("DQMExample_Step1") << "Constructor DQMExample_Step1::DQMExample_Step1 " << std::endl;
25 
26  // Get parameters from configuration file
27  theElectronCollection_ = consumes<reco::GsfElectronCollection>(ps.getParameter<edm::InputTag>("electronCollection"));
28  theCaloJetCollection_ = consumes<reco::CaloJetCollection>(ps.getParameter<edm::InputTag>("caloJetCollection"));
29  thePfMETCollection_ = consumes<reco::PFMETCollection>(ps.getParameter<edm::InputTag>("pfMETCollection"));
30  theConversionCollection_ = consumes<reco::ConversionCollection>(ps.getParameter<edm::InputTag>("conversionsCollection"));
31  thePVCollection_ = consumes<reco::VertexCollection>(ps.getParameter<edm::InputTag>("PVCollection"));
32  theBSCollection_ = consumes<reco::BeamSpot>(ps.getParameter<edm::InputTag>("beamSpotCollection"));
33  triggerEvent_ = consumes<trigger::TriggerEvent>(ps.getParameter<edm::InputTag>("TriggerEvent"));
34  triggerResults_ = consumes<edm::TriggerResults>(ps.getParameter<edm::InputTag>("TriggerResults"));
35  triggerFilter_ = ps.getParameter<edm::InputTag>("TriggerFilter");
36  triggerPath_ = ps.getParameter<std::string>("TriggerPath");
37 
38 
39  // cuts:
40  ptThrL1_ = ps.getUntrackedParameter<double>("PtThrL1");
41  ptThrL2_ = ps.getUntrackedParameter<double>("PtThrL2");
42  ptThrJet_ = ps.getUntrackedParameter<double>("PtThrJet");
43  ptThrMet_ = ps.getUntrackedParameter<double>("PtThrMet");
44 
45 }
46 
47 //
48 // -- Destructor
49 //
51 {
52  edm::LogInfo("DQMExample_Step1") << "Destructor DQMExample_Step1::~DQMExample_Step1 " << std::endl;
53 }
54 
55 //
56 // -------------------------------------- beginRun --------------------------------------------
57 //
59 {
60  edm::LogInfo("DQMExample_Step1") << "DQMExample_Step1::beginRun" << std::endl;
61 }
62 //
63 // -------------------------------------- bookHistos --------------------------------------------
64 //
66 {
67  edm::LogInfo("DQMExample_Step1") << "DQMExample_Step1::bookHistograms" << std::endl;
68 
69  //book at beginRun
70  bookHistos(ibooker_);
71 }
72 //
73 // -------------------------------------- Analyze --------------------------------------------
74 //
76 {
77  edm::LogInfo("DQMExample_Step1") << "DQMExample_Step1::analyze" << std::endl;
78 
79 
80  //-------------------------------
81  //--- Vertex Info
82  //-------------------------------
84  e.getByToken(thePVCollection_, vertexHandle);
85  if ( !vertexHandle.isValid() )
86  {
87  edm::LogError ("DQMClientExample") << "invalid collection: vertex" << "\n";
88  return;
89  }
90 
91  int vertex_number = vertexHandle->size();
92  reco::VertexCollection::const_iterator v = vertexHandle->begin();
93 
94  math::XYZPoint PVPoint(-999, -999, -999);
95  if(vertex_number != 0)
96  PVPoint = math::XYZPoint(v->position().x(), v->position().y(), v->position().z());
97 
98  PVPoint_=PVPoint;
99 
100  //-------------------------------
101  //--- MET
102  //-------------------------------
103  edm::Handle<reco::PFMETCollection> pfMETCollection;
104  e.getByToken(thePfMETCollection_, pfMETCollection);
105  if ( !pfMETCollection.isValid() )
106  {
107  edm::LogError ("DQMClientExample") << "invalid collection: MET" << "\n";
108  return;
109  }
110  //-------------------------------
111  //--- Electrons
112  //-------------------------------
114  e.getByToken(theElectronCollection_, electronCollection);
115  if ( !electronCollection.isValid() )
116  {
117  edm::LogError ("DQMClientExample") << "invalid collection: electrons" << "\n";
118  return;
119  }
120 
121  float nEle=0;
122  int posEle=0, negEle=0;
123  const reco::GsfElectron* ele1 = nullptr;
124  const reco::GsfElectron* ele2 = nullptr;
125  for (reco::GsfElectronCollection::const_iterator recoElectron=electronCollection->begin(); recoElectron!=electronCollection->end(); ++recoElectron)
126  {
127  //decreasing pT
128  if( MediumEle(e,eSetup,*recoElectron) )
129  {
130  if(!ele1 && recoElectron->pt() > ptThrL1_)
131  ele1 = &(*recoElectron);
132 
133  else if(!ele2 && recoElectron->pt() > ptThrL2_)
134  ele2 = &(*recoElectron);
135 
136  }
137 
138  if(recoElectron->charge()==1)
139  posEle++;
140  else if(recoElectron->charge()==-1)
141  negEle++;
142 
143  } // end of loop over electrons
144 
145  nEle = posEle+negEle;
146 
147  //-------------------------------
148  //--- Jets
149  //-------------------------------
150  edm::Handle<reco::CaloJetCollection> caloJetCollection;
151  e.getByToken (theCaloJetCollection_,caloJetCollection);
152  if ( !caloJetCollection.isValid() )
153  {
154  edm::LogError ("DQMClientExample") << "invalid collection: jets" << "\n";
155  return;
156  }
157 
158  int nJet = 0;
159  const reco::CaloJet* jet1 = nullptr;
160  const reco::CaloJet* jet2 = nullptr;
161 
162  for (reco::CaloJetCollection::const_iterator i_calojet = caloJetCollection->begin(); i_calojet != caloJetCollection->end(); ++i_calojet)
163  {
164  //remove jet-ele matching
165  if(ele1)
166  if (Distance(*i_calojet,*ele1) < 0.3) continue;
167 
168  if(ele2)
169  if (Distance(*i_calojet,*ele2) < 0.3) continue;
170 
171  if (i_calojet->pt() < ptThrJet_) continue;
172 
173  nJet++;
174 
175  if (!jet1)
176  jet1 = &(*i_calojet);
177 
178  else if (!jet2)
179  jet2 = &(*i_calojet);
180  }
181 
182  // ---------------------------
183  // ---- Analyze Trigger Event
184  // ---------------------------
185 
186  //check what is in the menu
188  e.getByToken(triggerResults_,hltresults);
189 
190  if(!hltresults.isValid())
191  {
192  edm::LogError ("DQMClientExample") << "invalid collection: TriggerResults" << "\n";
193  return;
194  }
195 
196  bool hasFired = false;
197  const edm::TriggerNames& trigNames = e.triggerNames(*hltresults);
198  unsigned int numTriggers = trigNames.size();
199 
200  for( unsigned int hltIndex=0; hltIndex<numTriggers; ++hltIndex )
201  {
202  if (trigNames.triggerName(hltIndex)==triggerPath_ && hltresults->wasrun(hltIndex) && hltresults->accept(hltIndex))
203  hasFired = true;
204  }
205 
206 
207 
208  //access the trigger event
210  e.getByToken(triggerEvent_, triggerEvent);
211  if( triggerEvent.failedToGet() )
212  {
213  edm::LogError ("DQMClientExample") << "invalid collection: TriggerEvent" << "\n";
214  return;
215  }
216 
217 
218  reco::Particle* ele1_HLT = nullptr;
219  int nEle_HLT = 0;
220 
221  size_t filterIndex = triggerEvent->filterIndex( triggerFilter_ );
223  if( !(filterIndex >= triggerEvent->sizeFilters()) )
224  {
225  const trigger::Keys& keys = triggerEvent->filterKeys( filterIndex );
226  std::vector<reco::Particle> triggeredEle;
227 
228  for( size_t j = 0; j < keys.size(); ++j )
229  {
230  trigger::TriggerObject foundObject = triggerObjects[keys[j]];
231  if( abs( foundObject.particle().pdgId() ) != 11 ) continue; //make sure that it is an electron
232 
233  triggeredEle.push_back( foundObject.particle() );
234  ++nEle_HLT;
235  }
236 
237  if( !triggeredEle.empty() )
238  ele1_HLT = &(triggeredEle.at(0));
239  }
240 
241  //-------------------------------
242  //--- Fill the histos
243  //-------------------------------
244 
245  //vertex
246  h_vertex_number -> Fill( vertex_number );
247 
248  //met
249  h_pfMet -> Fill( pfMETCollection->begin()->et() );
250 
251  //multiplicities
252  h_eMultiplicity->Fill(nEle);
253  h_jMultiplicity->Fill(nJet);
254  h_eMultiplicity_HLT->Fill(nEle_HLT);
255 
256  //leading not matched
257  if(ele1)
258  {
259  h_ePt_leading->Fill(ele1->pt());
260  h_eEta_leading->Fill(ele1->eta());
261  h_ePhi_leading->Fill(ele1->phi());
262  }
263  if(ele1_HLT)
264  {
265  h_ePt_leading_HLT->Fill(ele1_HLT->pt());
266  h_eEta_leading_HLT->Fill(ele1_HLT->eta());
267  h_ePhi_leading_HLT->Fill(ele1_HLT->phi());
268  }
269  //leading Jet
270  if(jet1)
271  {
272  h_jPt_leading->Fill(jet1->pt());
273  h_jEta_leading->Fill(jet1->eta());
274  h_jPhi_leading->Fill(jet1->phi());
275  }
276 
277 
278  //fill only when the trigger candidate mathes with the reco one
279  if( ele1 && ele1_HLT && deltaR(*ele1_HLT,*ele1) < 0.3 && hasFired==true )
280  {
281  h_ePt_leading_matched->Fill(ele1->pt());
282  h_eEta_leading_matched->Fill(ele1->eta());
283  h_ePhi_leading_matched->Fill(ele1->phi());
284 
285  h_ePt_leading_HLT_matched->Fill(ele1_HLT->pt());
286  h_eEta_leading_HLT_matched->Fill(ele1_HLT->eta());
287  h_ePhi_leading_HLT_matched->Fill(ele1_HLT->phi());
288 
289  h_ePt_diff->Fill(ele1->pt()-ele1_HLT->pt());
290  }
291 }
292 
293 //
294 // -------------------------------------- endRun --------------------------------------------
295 //
297 {
298  edm::LogInfo("DQMExample_Step1") << "DQMExample_Step1::endRun" << std::endl;
299 }
300 
301 
302 //
303 // -------------------------------------- book histograms --------------------------------------------
304 //
306 {
307  ibooker_.cd();
308  ibooker_.setCurrentFolder("Physics/TopTest");
309 
310  h_vertex_number = ibooker_.book1D("Vertex_number", "Number of event vertices in collection", 40,-0.5, 39.5 );
311 
312  h_pfMet = ibooker_.book1D("pfMet", "Pf Missing E_{T}; GeV" , 20, 0.0 , 100);
313 
314  h_eMultiplicity = ibooker_.book1D("NElectrons","# of electrons per event",10,0.,10.);
315  h_ePt_leading_matched = ibooker_.book1D("ElePt_leading_matched","Pt of leading electron",50,0.,100.);
316  h_eEta_leading_matched = ibooker_.book1D("EleEta_leading_matched","Eta of leading electron",50,-5.,5.);
317  h_ePhi_leading_matched = ibooker_.book1D("ElePhi_leading_matched","Phi of leading electron",50,-3.5,3.5);
318 
319  h_ePt_leading = ibooker_.book1D("ElePt_leading","Pt of leading electron",50,0.,100.);
320  h_eEta_leading = ibooker_.book1D("EleEta_leading","Eta of leading electron",50,-5.,5.);
321  h_ePhi_leading = ibooker_.book1D("ElePhi_leading","Phi of leading electron",50,-3.5,3.5);
322 
323  h_jMultiplicity = ibooker_.book1D("NJets","# of electrons per event",10,0.,10.);
324  h_jPt_leading = ibooker_.book1D("JetPt_leading","Pt of leading Jet",150,0.,300.);
325  h_jEta_leading = ibooker_.book1D("JetEta_leading","Eta of leading Jet",50,-5.,5.);
326  h_jPhi_leading = ibooker_.book1D("JetPhi_leading","Phi of leading Jet",50,-3.5,3.5);
327 
328  h_eMultiplicity_HLT = ibooker_.book1D("NElectrons_HLT","# of electrons per event @HLT",10,0.,10.);
329  h_ePt_leading_HLT = ibooker_.book1D("ElePt_leading_HLT","Pt of leading electron @HLT",50,0.,100.);
330  h_eEta_leading_HLT = ibooker_.book1D("EleEta_leading_HLT","Eta of leading electron @HLT",50,-5.,5.);
331  h_ePhi_leading_HLT = ibooker_.book1D("ElePhi_leading_HLT","Phi of leading electron @HLT",50,-3.5,3.5);
332 
333  h_ePt_leading_HLT_matched = ibooker_.book1D("ElePt_leading_HLT_matched","Pt of leading electron @HLT",50,0.,100.);
334  h_eEta_leading_HLT_matched = ibooker_.book1D("EleEta_leading_HLT_matched","Eta of leading electron @HLT",50,-5.,5.);
335  h_ePhi_leading_HLT_matched = ibooker_.book1D("ElePhi_leading_HLT_matched","Phi of leading electron @HLT",50,-3.5,3.5);
336 
337  h_ePt_diff = ibooker_.book1D("ElePt_diff_matched","pT(RECO) - pT(HLT) for mathed candidates",100,-10,10.);
338 
339  ibooker_.cd();
340 
341 }
342 
343 
344 //
345 // -------------------------------------- functions --------------------------------------------
346 //
348  return deltaR(c1,c2);
349 }
350 
352  return deltaPhi(c1.p4().phi(),c2.p4().phi());
353 }
354 
355 // This always returns only a positive deltaPhi
356 double DQMExample_Step1::calcDeltaPhi(double phi1, double phi2) {
357  double deltaPhi = phi1 - phi2;
358  if (deltaPhi < 0) deltaPhi = -deltaPhi;
359  if (deltaPhi > 3.1415926) {
360  deltaPhi = 2 * 3.1415926 - deltaPhi;
361  }
362  return deltaPhi;
363 }
364 
365 //
366 // -------------------------------------- electronID --------------------------------------------
367 //
369 {
370 
371  //********* CONVERSION TOOLS
373  iEvent.getByToken(theConversionCollection_, conversions_h);
374 
375  bool isMediumEle = false;
376 
377  float pt = electron.pt();
378  float eta = electron.eta();
379 
380  int isEB = electron.isEB();
381  float sigmaIetaIeta = electron.sigmaIetaIeta();
382  float DetaIn = electron.deltaEtaSuperClusterTrackAtVtx();
383  float DphiIn = electron.deltaPhiSuperClusterTrackAtVtx();
384  float HOverE = electron.hadronicOverEm();
385  float ooemoop = (1.0/electron.ecalEnergy() - electron.eSuperClusterOverP()/electron.ecalEnergy());
386 
387  int mishits = electron.gsfTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS);
388  int nAmbiguousGsfTracks = electron.ambiguousGsfTracksSize();
389 
390  reco::GsfTrackRef eleTrack = electron.gsfTrack() ;
391  float dxy = eleTrack->dxy(PVPoint_);
392  float dz = eleTrack->dz (PVPoint_);
393 
395  iEvent.getByToken(theBSCollection_, BSHandle);
396  const reco::BeamSpot BS = *BSHandle;
397 
398  bool isConverted = ConversionTools::hasMatchedConversion(electron, conversions_h, BS.position());
399 
400  // default
401  if( (pt > 12.) && (fabs(eta) < 2.5) &&
402  ( ( (isEB == 1) && (fabs(DetaIn) < 0.004) ) || ( (isEB == 0) && (fabs(DetaIn) < 0.007) ) ) &&
403  ( ( (isEB == 1) && (fabs(DphiIn) < 0.060) ) || ( (isEB == 0) && (fabs(DphiIn) < 0.030) ) ) &&
404  ( ( (isEB == 1) && (sigmaIetaIeta < 0.010) ) || ( (isEB == 0) && (sigmaIetaIeta < 0.030) ) ) &&
405  ( ( (isEB == 1) && (HOverE < 0.120) ) || ( (isEB == 0) && (HOverE < 0.100) ) ) &&
406  ( ( (isEB == 1) && (fabs(ooemoop) < 0.050) ) || ( (isEB == 0) && (fabs(ooemoop) < 0.050) ) ) &&
407  ( ( (isEB == 1) && (fabs(dxy) < 0.020) ) || ( (isEB == 0) && (fabs(dxy) < 0.020) ) ) &&
408  ( ( (isEB == 1) && (fabs(dz) < 0.100) ) || ( (isEB == 0) && (fabs(dz) < 0.100) ) ) &&
409  ( ( (isEB == 1) && (!isConverted) ) || ( (isEB == 0) && (!isConverted) ) ) &&
410  ( mishits == 0 ) &&
411  ( nAmbiguousGsfTracks == 0 )
412  )
413  isMediumEle=true;
414 
415  return isMediumEle;
416 }
~DQMExample_Step1() override
double calcDeltaPhi(double phi1, double phi2)
MonitorElement * h_ePhi_leading_matched
T getParameter(std::string const &) const
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Definition: GsfElectron.h:185
T getUntrackedParameter(std::string const &, T const &) const
bool wasrun() const
Was at least one path run?
double pt() const
transverse momentum
Definition: Particle.h:104
MonitorElement * h_jMultiplicity
math::XYZPoint PVPoint_
bool MediumEle(const edm::Event &iEvent, const edm::EventSetup &iESetup, const reco::GsfElectron &electron)
double eta() const final
momentum pseudorapidity
edm::EDGetTokenT< reco::GsfElectronCollection > theElectronCollection_
Jets made from CaloTowers.
Definition: CaloJet.h:29
trigger::size_type sizeFilters() const
Definition: TriggerEvent.h:135
float eSuperClusterOverP() const
Definition: GsfElectron.h:245
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
bool accept() const
Has at least one path accepted the event?
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:111
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
Definition: TriggerEvent.h:123
reco::Particle particle(reco::Particle::Charge q=0, const reco::Particle::Point &vertex=reco::Particle::Point(0, 0, 0), int status=0, bool integerCharge=true) const
Definition: TriggerObject.h:69
MonitorElement * h_ePhi_leading_HLT_matched
double pt() const final
transverse momentum
MonitorElement * h_ePhi_leading
MonitorElement * h_eEta_leading_HLT
MonitorElement * h_jPhi_leading
edm::EDGetTokenT< reco::ConversionCollection > theConversionCollection_
Strings::size_type size() const
Definition: TriggerNames.cc:39
edm::EDGetTokenT< trigger::TriggerEvent > triggerEvent_
double Distance(const reco::Candidate &c1, const reco::Candidate &c2)
int pdgId() const
PDG identifier.
Definition: Particle.h:134
bool isEB() const
Definition: GsfElectron.h:352
DQMExample_Step1(const edm::ParameterSet &ps)
void Fill(long long x)
MonitorElement * h_eEta_leading
void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override
edm::EDGetTokenT< reco::BeamSpot > theBSCollection_
MonitorElement * h_ePt_leading_HLT
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:22
float deltaEtaSuperClusterTrackAtVtx() const
Definition: GsfElectron.h:249
int iEvent
Definition: GenABIO.cc:230
MonitorElement * h_ePt_diff
MonitorElement * h_ePt_leading_HLT_matched
float sigmaIetaIeta() const
Definition: GsfElectron.h:436
float hadronicOverEm() const
Definition: GsfElectron.h:491
double phi() const
momentum azimuthal angle
Definition: Particle.h:106
MonitorElement * h_jEta_leading
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
void bookHistos(DQMStore::IBooker &)
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:98
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
float deltaPhiSuperClusterTrackAtVtx() const
Definition: GsfElectron.h:252
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MonitorElement * h_eEta_leading_HLT_matched
MonitorElement * h_vertex_number
MonitorElement * h_ePt_leading
bool isValid() const
Definition: HandleBase.h:74
static bool hasMatchedConversion(const reco::GsfElectron &ele, const edm::Handle< reco::ConversionCollection > &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch=true, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
MonitorElement * h_eMultiplicity
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
MonitorElement * h_pfMet
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:81
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:74
bool failedToGet() const
Definition: HandleBase.h:78
edm::EDGetTokenT< edm::TriggerResults > triggerResults_
void endRun(edm::Run const &run, edm::EventSetup const &eSetup) override
MonitorElement * h_jPt_leading
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:27
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
std::vector< size_type > Keys
MonitorElement * h_ePt_leading_matched
GsfTrackRefVector::size_type ambiguousGsfTracksSize() const
Definition: GsfElectron.h:712
edm::EDGetTokenT< reco::PFMETCollection > thePfMETCollection_
edm::InputTag triggerFilter_
float ecalEnergy() const
Definition: GsfElectron.h:848
MonitorElement * h_ePhi_leading_HLT
double DistancePhi(const reco::Candidate &c1, const reco::Candidate &c2)
std::string triggerPath_
const Point & position() const
position
Definition: BeamSpot.h:62
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
MonitorElement * h_eMultiplicity_HLT
double eta() const
momentum pseudorapidity
Definition: Particle.h:110
double phi() const final
momentum azimuthal angle
MonitorElement * h_eEta_leading_matched
edm::EDGetTokenT< reco::VertexCollection > thePVCollection_
edm::EDGetTokenT< reco::CaloJetCollection > theCaloJetCollection_
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:301
Definition: Run.h:44
void analyze(edm::Event const &e, edm::EventSetup const &eSetup) override