ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/LJMet/Utils/src/CheckEventContent.cc
Revision: 1.1
Committed: Tue Oct 27 23:24:12 2009 UTC (15 years, 6 months ago) by kukartse
Content type: text/plain
Branch: MAIN
Log Message:
added event content checker

File Contents

# User Rev Content
1 kukartse 1.1 // -*- C++ -*-
2     //
3     // Package: CheckEventContent
4     // Class: CheckEventContent
5     //
6     /**\class CheckEventContent CheckEventContent.h LJMet/Utils/interface/CheckEventContent.h
7    
8     Description: times various aspects of data processing
9    
10     Implementation:
11     Keep this class as simple and fast as possible
12     */
13     //
14     // Original Author: "Gennadiy Kukartsev"
15     // Created: Tue Oct 6 13:39:12 CDT 2009
16     // $Id: CheckEventContent.cc,v 1.4 2009/10/27 22:39:44 kukartse Exp $
17     //
18     //
19    
20     #include "LJMet/Utils/interface/CheckEventContent.h"
21     #include "FWCore/Framework/interface/TriggerNames.h"
22     #include "DataFormats/Common/interface/TriggerResults.h"
23     #include "DataFormats/PatCandidates/interface/Jet.h"
24     #include "DataFormats/PatCandidates/interface/Electron.h"
25     #include "DataFormats/PatCandidates/interface/Muon.h"
26     #include "DataFormats/PatCandidates/interface/MET.h"
27     #include "DataFormats/PatCandidates/interface/TriggerPath.h"
28     #include "DataFormats/BeamSpot/interface/BeamSpot.h"
29     #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
30     #include "DataFormats/Math/interface/deltaR.h"
31    
32     using namespace edm;
33    
34     CheckEventContent::CheckEventContent(const edm::ParameterSet& iConfig){
35     }
36    
37    
38     CheckEventContent::~CheckEventContent()
39     {
40     }
41    
42    
43     void
44     CheckEventContent::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
45     {
46     //
47     //_____ check trigger
48     //
49     cout << std::endl << "===> Check trigger: " << std::endl;
50     Handle<std::vector<pat::TriggerPath> > trigs;
51     iEvent.getByLabel("patTrigger", trigs);
52     std::string triggerName = "HLT_Mu9";
53     for (std::vector<pat::TriggerPath>::const_iterator trig = trigs->begin();
54     trig!=trigs->end();
55     ++trig){
56     //cout << "Trigger name and number: " << trig->name() << ", " << trig->index() << std::endl;
57     if( trig->name().find(triggerName)!=std::string::npos ){
58     cout << "Trigger " << triggerName << " is found in the event..." << std::endl;
59     //trig->wasAccept();
60     }
61     }
62     //
63     //_____ check PAT muons _______________________________________________
64     //
65     cout << std::endl << "===> Check PAT muons: " << std::endl;
66     Handle< vector< pat::Muon > > muons;
67     iEvent . getByLabel( "selectedLayer1Muons", muons );
68     for ( vector<pat::Muon>::const_iterator mu = muons -> begin(); mu != muons -> end(); mu++){
69     cout << "Global muon selector: " << mu->isGlobalMuon() << std::endl;
70     }
71     //
72     //_____ check Beam spot _____________________________________________________
73     //
74     cout << std::endl << "===> Check Beam spot: " << std::endl;
75     Handle< reco::BeamSpot > beamSpotHandle;
76     iEvent . getByLabel( "offlineBeamSpot", beamSpotHandle);
77     reco::BeamSpot beamSpot;
78     if ( beamSpotHandle.isValid() ){
79     beamSpot = *beamSpotHandle;
80     cout << "beam spot present in the Event..." << std::endl;
81     }
82     else{
83     edm::LogInfo("TtLJetsAnalyzer")
84     << "No beam spot available in the event \n";
85     }
86     cout << beamSpot.x0() << " " << beamSpot.y0() << " " << beamSpot.z0() << std::endl;
87     }
88    
89    
90     void
91     CheckEventContent::beginJob()
92     {
93     }
94    
95    
96     void
97     CheckEventContent::endJob() {
98     }
99    
100    
101     /*
102     bool CheckEventContent::is_muon(std::string mLabel,
103     double mPt,
104     double mEta,
105     int mNHits,
106     double mD0,
107     double mChi2Ndof,
108     double mEmVeto,
109     double mHadVeto,
110     double mRelIso,
111     const edm::Event& iEvent){
112     bool result = false;
113     //cout << "Cut Flow: passed stage 1 (mu+jets) or stage 2 (e+jets): ";
114     Handle< vector< pat::Muon > > muons;
115     iEvent . getByLabel( "selectedLayer1Muons", muons );
116     //
117     //_____ loop over muons _______________________________________________
118     //
119     double _pt = 0.0;
120     double _abseta = 0.0;
121     int _nhits = 0;
122     double _d0 = 0.0;
123     double _chi2ndof = 0.0;
124     double _emveto = 10000.0;
125     double _hadveto = 10000.0;
126     double _trackiso = 10000.0;
127     double _caloiso = 10000.0;
128     double _reliso = 10000.0;
129     MeanCounter passed_muons("");
130     for ( vector<pat::Muon>::const_iterator mu = muons -> begin(); mu != muons -> end(); mu++){
131     //_____ check that the muon is global
132     if( !(mu->isGlobalMuon()) ) continue;
133     _pt = mu->pt();
134     _abseta = fabs(mu->eta());
135     //_d0 = mu->dB(); // global track
136     _d0 = -(mu->innerTrack()->dxy(_bs));
137     _chi2ndof = mu->normChi2();
138     _nhits = mu->numberOfValidHits();
139     reco::TrackRef _track = mu->track();
140     //_____ check that there is a track
141     if(_track.isNull()) continue;
142     //_nhits = _track->numberOfValidHits();
143     //_d0 = -(_track->dxy(_bs));
144     //_chi2ndof = _track->normalizedChi2();
145     //_chi2ndof = (_track->chi2())/(_track->ndof());
146     //_____ check that isolation is valid
147     if ( !(mu->isIsolationValid()) ) continue;
148     _emveto = mu->isolationR03().emVetoEt;
149     _hadveto = mu->isolationR03().hadVetoEt;
150     _trackiso = mu->isolationR03().sumPt;
151     _caloiso = mu->isolationR03().emEt + mu->isolationR03().hadEt;
152     _reliso = (_trackiso + _caloiso)/_pt;
153     if (_pt > mPt &&
154     _abseta < mEta &&
155     _nhits >= mNHits &&
156     fabs(_d0) < mD0 &&
157     _chi2ndof < mChi2Ndof &&
158     fabs(_emveto) < mEmVeto &&
159     fabs(_hadveto) < mHadVeto &&
160     fabs(_reliso) < mRelIso
161     ){
162     passed_muons.count();
163     muon_index = (int)(mu - muons->begin());
164     if (passed_muons.getCount()==1){
165     cout << _pt << ", ";
166     cout << _abseta << ", ";
167     cout << _nhits << ", ";
168     cout << _d0 << ", ";
169     cout << _chi2ndof << ", ";
170     cout << _emveto << ", ";
171     cout << _hadveto << ", ";
172     cout << _trackiso << ", ";
173     cout << _caloiso << ", ";
174     cout << _reliso;
175     //cout << std::endl;
176     }
177     }
178     }
179     cout << "Number of good muons: " << passed_muons.getCount();
180     result = passed_muons.getCount()==1;
181     return result;
182     }
183    
184    
185     bool CheckEventContent::is_jets(std::string mLabel,
186     double mPt,
187     double mEta,
188     const edm::Event& iEvent){
189     bool result = false;
190    
191     //cout << "Cut Flow: passed stage 2: ";
192    
193     Handle< vector< pat::Jet > > jets;
194     iEvent . getByLabel( mLabel, jets );
195     MeanCounter c_jets("");
196     MeanCounter passed_jets("");
197     for ( vector<pat::Jet>::const_iterator jet = jets -> begin(); jet != jets -> end(); jet++ ){
198     c_jets.count();
199     double _pt = jet->pt();
200     double _eta = jet->eta();
201     if (
202     ( fabs( _eta ) < mEta ) &&
203     ( _pt > mPt )
204     )
205     {
206     passed_jets.count();
207     }
208     if (c_jets.getCount()<=4){
209     cout << _pt << ", ";
210     cout << _eta;
211     }
212     }
213     //cout << std::endl;
214     result = passed_jets.getCount() >=4;
215     return result;
216     }
217    
218    
219     bool CheckEventContent::no_loose_muon(std::string mLabel,
220     double mEta,
221     double mPt,
222     double mRelIso,
223     const edm::Event& iEvent){
224     bool result = false;
225     //cout << "Cut Flow: passed stage 3: ";
226     Handle< vector< pat::Muon > > muons;
227     iEvent . getByLabel( "selectedLayer1Muons", muons );
228     //
229     //_____ loop over muons _______________________________________________
230     //
231     double _pt = 0.0;
232     double _abseta = 0.0;
233     double _trackiso = 10000.0;
234     double _caloiso = 10000.0;
235     double _reliso = 10000.0;
236     MeanCounter passed_muons("");
237     for ( vector<pat::Muon>::const_iterator mu = muons -> begin(); mu != muons -> end(); mu++){
238     //_____ check that the muon is global
239     if( !(mu->isGlobalMuon()) ) continue;
240     _pt = mu->pt();
241     _abseta = fabs(mu->eta());
242     //_____ check that isolation is valid
243     if ( !(mu->isIsolationValid()) ) continue;
244     _trackiso = mu->isolationR03().sumPt;
245     _caloiso = mu->isolationR03().emEt + mu->isolationR03().hadEt;
246     _reliso = (_trackiso + _caloiso)/_pt;
247     int _index = (int)(mu - muons->begin());
248     if (_pt > mPt &&
249     _abseta < mEta &&
250     _reliso < mRelIso &&
251     _index != muon_index
252     ){
253     passed_muons.count();
254     }
255     }
256     result = passed_muons.getCount()==0;
257     //cout << std::endl;
258     return result;
259     }
260    
261    
262     bool CheckEventContent::no_loose_electron(std::string mLabel,
263     double mEta,
264     double mPt,
265     double mRelIso,
266     const edm::Event& iEvent){
267     bool result = false;
268     //cout << "Cut Flow: passed stage 4: ";
269     Handle< vector< pat::Electron > > electrons;
270     iEvent . getByLabel( "selectedLayer1Electrons", electrons );
271     //
272     //_____ loop over electrons _______________________________________________
273     //
274     double _pt = 0.0;
275     double _abseta = 0.0;
276     double _trackiso = 10000.0;
277     double _caloiso = 10000.0;
278     double _reliso = 10000.0;
279     MeanCounter passed_electrons("");
280     for ( vector<pat::Electron>::const_iterator e = electrons -> begin(); e != electrons -> end(); e++){
281     _pt = e->pt();
282     _abseta = fabs(e->eta());
283     _trackiso = e->dr03IsolationVariables().tkSumPt;
284     _caloiso = e->dr03IsolationVariables().ecalRecHitSumEt + e->dr03IsolationVariables().hcalDepth1TowerSumEt + e->dr03IsolationVariables().hcalDepth2TowerSumEt;
285     _reliso = (_trackiso + _caloiso)/_pt;
286     int _index = (int)(e - electrons->begin());
287     if (_pt > mPt &&
288     _abseta < mEta &&
289     _reliso < mRelIso &&
290     _index != electron_index
291     ){
292     passed_electrons.count();
293     }
294     }
295     result = passed_electrons.getCount()==0;
296     //cout << std::endl;
297     return result;
298     }
299    
300    
301     bool CheckEventContent::has_electron(std::string mLabel,
302     const edm::Event& iEvent){
303     bool result = false;
304     Handle< vector< pat::Electron > > electrons;
305     iEvent . getByLabel( mLabel, electrons );
306     result = electrons->size()>0;
307     return result;
308     }
309    
310    
311     bool CheckEventContent::is_electron(std::string mLabel,
312     double mPt,
313     double mEta,
314     double mD0,
315     double mRelIso,
316     const edm::Event& iEvent){
317     bool result = false;
318     //cout << "Cut Flow: passed stage 1: ";
319     Handle< vector< pat::Electron > > electrons;
320     iEvent . getByLabel( "selectedLayer1Electrons", electrons );
321     Handle< reco::BeamSpot > beamSpotHandle;
322     iEvent . getByLabel( "offlineBeamSpot", beamSpotHandle);
323     //
324     //_____ Beam spot _____________________________________________________
325     //
326     reco::BeamSpot beamSpot;
327     if ( beamSpotHandle.isValid() ){
328     beamSpot = *beamSpotHandle;
329     }
330     else{
331     edm::LogInfo("TtLJetsAnalyzer")
332     << "No beam spot available from EventSetup \n";
333     }
334     const reco::BeamSpot::Point _bs(beamSpot.x0(), beamSpot.y0(),beamSpot.z0());
335     //
336     //_____ loop over electrons _______________________________________________
337     //
338     double _pt = 0.0;
339     double _abseta = 0.0;
340     double _d0 = 0.0;
341     double _d0_pat = 0.0;
342     double _trackiso = 10000.0;
343     double _ecaloiso = 10000.0;
344     double _ecaloiso2 = 10000.0;
345     double _pat_ecaloiso = 10000.0;
346     double _hcaloiso1 = 10000.0;
347     double _hcaloiso2 = 10000.0;
348     double _caloiso = 10000.0;
349     double _reliso = 10000.0;
350     MeanCounter passed_electrons("");
351     for ( vector<pat::Electron>::const_iterator e = electrons -> begin(); e != electrons -> end(); e++){
352     //_____ check that the electron is robust-tight
353     if( !(e->electronID("eidRobustTight")) ) continue;
354     _pt = e->pt();
355     _abseta = fabs(e->eta());
356     _d0_pat = e->dB();
357     _d0 = -(e->gsfTrack()->dxy(_bs));
358     _trackiso = e->dr03IsolationVariables().tkSumPt;
359     _ecaloiso = e->dr04IsolationVariables().ecalRecHitSumEt;
360     _ecaloiso2 = e->dr03IsolationVariables().ecalRecHitSumEt;
361     _pat_ecaloiso = e->isolation(pat::ECalIso);
362     _hcaloiso1 = e->dr04IsolationVariables().hcalDepth1TowerSumEt;
363     _hcaloiso2 = e->dr04IsolationVariables().hcalDepth2TowerSumEt;
364     _caloiso = _ecaloiso + _hcaloiso1 + _hcaloiso2;
365     //_caloiso = _pat_ecaloiso +_hcaloiso1 + _hcaloiso2;
366     _reliso = (_trackiso + _caloiso)/_pt;
367     if (_pt > mPt &&
368     _abseta < mEta &&
369     fabs(_d0) < mD0 &&
370     fabs(_reliso) < mRelIso
371     ){
372     passed_electrons.count();
373     electron_index = (int)(e - electrons->begin());
374     if (passed_electrons.getCount()==1){
375     cout << "pt=" << _pt << ", abseta=";
376     cout << _abseta << ", d0=";
377     cout << _d0 << ", trackiso=";
378     cout << _trackiso << ", ecaloiso04=";
379     cout << _ecaloiso << ", ecaloiso03=";
380     cout << _ecaloiso2 << ", pat_ecaloiso=";
381     cout << _pat_ecaloiso << ", hcaloiso1=";
382     cout << _hcaloiso1 << ", hcaloiso2=";
383     cout << _hcaloiso2 << ", caloiso04=";
384     cout << _caloiso << ", reliso=";
385     cout << _reliso;
386     //cout << std::endl;
387     }
388     }
389     }
390     //cout << "Number of good electrons: " << passed_electrons.getCount();
391     result = passed_electrons.getCount()==1;
392     return result;
393     }
394    
395    
396     int CheckEventContent::count_jets(std::string jLabel,
397     double jPt,
398     double jEta,
399     std::string lLabel,
400     double lPt,
401     double lEta,
402     double lD0,
403     double lDR,
404     const edm::Event & iEvent){
405     MeanCounter _njets("");
406     Handle< vector< pat::Jet > > jets;
407     iEvent . getByLabel( jLabel, jets );
408     Handle< vector< pat::Electron > > electrons;
409     iEvent . getByLabel( lLabel, electrons );
410     Handle< reco::BeamSpot > beamSpotHandle;
411     iEvent . getByLabel( "offlineBeamSpot", beamSpotHandle);
412     //
413     //_____ Beam spot _____________________________________________________
414     //
415     reco::BeamSpot beamSpot;
416     if ( beamSpotHandle.isValid() ){
417     beamSpot = *beamSpotHandle;
418     }
419     else{
420     edm::LogInfo("TtLJetsAnalyzer")
421     << "No beam spot available from EventSetup \n";
422     }
423     const reco::BeamSpot::Point _bs(beamSpot.x0(), beamSpot.y0(),beamSpot.z0());
424     //
425     //_____ loop over jets _______________________________________________
426     //
427     double j_pt = 0.0;
428     double j_eta = 0.0;
429     for ( vector<pat::Jet>::const_iterator jet = jets -> begin(); jet != jets -> end(); ++jet){
430     j_pt = jet->pt();
431     j_eta = jet->eta();
432     //
433     //_____ loop over electrons _______________________________________________
434     //
435     double e_pt = 0.0;
436     double e_abseta = 0.0;
437     double e_d0 = 0.0;
438     double e_dr = 0.0;
439     bool jet_removed = false;
440     for ( vector<pat::Electron>::const_iterator e = electrons -> begin(); e != electrons -> end(); e++){
441     //_____ check that the electron is robust-tight
442     if( !(e->electronID("eidRobustTight")) ) continue;
443     e_pt = e->pt();
444     e_abseta = fabs(e->eta());
445     e_d0 = -(e->gsfTrack()->dxy(_bs));
446     e_dr = reco::deltaR(*jet, *e);
447     if ( e_pt > lPt && e_abseta < lEta && fabs(e_d0)<lD0 && e_dr<lDR){
448     jet_removed = true;
449     }
450     }
451     if (j_pt>jPt && fabs(j_eta)<jEta && !jet_removed) _njets.count();
452     }
453     cout << "Number of jets after cleaning: " << _njets.getCount();
454     return _njets.getCount();
455     }
456    
457     */
458    
459     //define this as a plug-in
460     DEFINE_FWK_MODULE(CheckEventContent);