ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/HbbAnalysis/src/HistosElecs.cc
(Generate patch)

Comparing UserCode/HbbAnalysis/src/HistosElecs.cc (file contents):
Revision 1.1 by amagnan, Wed Apr 15 10:24:16 2009 UTC vs.
Revision 1.3 by amagnan, Mon May 18 14:59:04 2009 UTC

# Line 1 | Line 1
1   #include <iostream>
2   #include <fstream>
3  
4 < #include "DataFormats/MuonReco/interface/Muon.h"
5 <
4 > #include "FWCore/MessageLogger/interface/MessageLogger.h"
5  
6   #include "UserCode/HbbAnalysis/interface/HistosElecs.hh"
7  
8   namespace HbbAnalysis {//namespace
9  
10 <  void HistosElecs::Initialise(TFileDirectory & aDir, std::string aName){
10 >  void HistosElecs::Initialise(TFileDirectory & aDir, std::string aName, bool aDoGenMatched){
11  
12 +    doGenMatched_ = aDoGenMatched;
13      CreateHistos(aName,aDir);
14  
15 <    p_nChambers = aDir.make<TH1F>("p_nChambers",";n_{chambers};n_{entries}",20,0,20);
15 >    p_nElectrons = aDir.make<TH1F>("p_nElectrons",";N_{electrons};N_{entries}",20,0,20);
16 >
17 >    p_electronID = aDir.make<TH1F>("p_electronID",";electronID;N_{entries}",10,0,10);
18 >
19 >    p_scSigmaEtaEta = aDir.make<TH1F>("p_scSigmaEtaEta",";;N_{entries}",100,0,0.1);
20 >    p_scSigmaIEtaIEta = aDir.make<TH1F>("p_scSigmaIEtaIEta",";;N_{entries}",100,0,0.1);
21 >    p_scE1x5 = aDir.make<TH1F>("p_scE1x5",";;N_{entries}",200,0,200);
22 >    p_scE2x5Max = aDir.make<TH1F>("p_scE2x5Max",";;N_{entries}",200,0,200);
23 >    p_scE5x5 = aDir.make<TH1F>("p_scE5x5",";;N_{entries}",500,0,500);
24 >
25 >    p_trackIso = aDir.make<TH1F>("p_trackIso",";;N_{entries}",400,0,20);
26 >    p_caloIso = aDir.make<TH1F>("p_caloIso",";;N_{entries}",400,0,20);
27 >    p_ecalIso = aDir.make<TH1F>("p_ecalIso",";;N_{entries}",400,0,20);
28 >    p_hcalIso = aDir.make<TH1F>("p_hcalIso",";;N_{entries}",400,0,20);
29 >
30 >    p_gsfTrk_pT = aDir.make<TH1F>("p_gsfTrk_pT",";;N_{entries}",200,0,200);
31 >    p_gsfTrk_IPxy = aDir.make<TH1F>("p_gsfTrk_IPxy",";;N_{entries}",100,-0.1,0.1);
32 >    p_gsfTrk_IPz = aDir.make<TH1F>("p_gsfTrk_IPz",";;N_{entries}",100,-1,1);
33 >
34  
35    }
36  
37 <  void HistosElecs::FillHistograms(const pat::Muon & aMuon){//FillHistograms
38 <    const reco::Muon* recoMuon = dynamic_cast<const reco::Muon*>(aMuon.originalObject());
37 >  void HistosElecs::FillEventHistograms(edm::Handle<std::vector<pat::Electron> > aCol){
38 >
39 >    if (doGenMatched_) {
40 >      unsigned int nMatched = 0;
41 >      for (std::vector<pat::Electron>::const_iterator iElec = aCol->begin();
42 >           iElec != aCol->end();
43 >           iElec++)
44 >        {
45 >          if (MatchesGenElectron(*iElec)) nMatched++;
46 >        }
47 >      p_nElectrons->Fill(nMatched);
48 >    }
49 >    else p_nElectrons->Fill(aCol->size());
50 >
51 >  }
52 >
53 >  void HistosElecs::FillHistograms(const pat::Electron & aElec, edm::Handle<std::vector<reco::Vertex> > aRecoVertices, bool isLead){//FillHistograms
54  
55 <    p_nChambers->Fill(recoMuon->numberOfChambers());
55 >    bool lIsGenMatched = !doGenMatched_ || (doGenMatched_ && MatchesGenElectron(aElec));
56 >    if (lIsGenMatched) {//genMatched
57 >      if (isLead) {//isLead
58 >        FillBaseHistograms(aElec.pt(),aElec.eta(),aElec.phi());
59 >
60 >        if ( aElec.gsfTrack().isAvailable() && !aElec.gsfTrack().isNull() ) {
61 >          p_gsfTrk_pT->Fill(aElec.gsfTrack()->pt());
62 >          if ( aRecoVertices->size() >= 1 ) {
63 >            const reco::Vertex & thePrimaryEventVertex = (*aRecoVertices->begin());
64 >            p_gsfTrk_IPxy->Fill(aElec.gsfTrack()->dxy(thePrimaryEventVertex.position()));
65 >            p_gsfTrk_IPz->Fill(aElec.gsfTrack()->dz(thePrimaryEventVertex.position()));
66 >          }
67 >        }
68 >
69 >        std::vector<std::pair<std::string,float> > lIds = aElec.electronIDs();
70 >        if (lIds.size() > 5) std::cout << "--- WARNING: histo will be out-of-range, number of electron IDs = " << lIds.size() << std::endl;
71 >        for (unsigned int iId(0); iId<lIds.size(); iId++){
72 >          const std::string & lName =  lIds.at(iId).first;
73 >          if (aElec.isElectronIDAvailable(lName)){
74 >            p_electronID->Fill(2*iId+aElec.electronID(lName));
75 >            assert (aElec.electronID(lName) ==  lIds.at(iId).second);
76 >          }
77 >        }
78 >    
79 >        p_scSigmaEtaEta->Fill(aElec.scSigmaEtaEta());
80 >        p_scSigmaIEtaIEta->Fill(aElec.scSigmaIEtaIEta());
81 >        p_scE1x5->Fill(aElec.scE1x5());
82 >        p_scE2x5Max->Fill(aElec.scE2x5Max());
83 >        p_scE5x5->Fill(aElec.scE5x5());
84 >
85 >        p_trackIso->Fill(aElec.trackIso());
86 >        p_caloIso->Fill(aElec.caloIso());
87 >        p_ecalIso->Fill(aElec.ecalIso());
88 >        p_hcalIso->Fill(aElec.hcalIso());
89 >
90  
91 <    FillBaseHistograms(aMuon.pt(),aMuon.eta(),aMuon.phi());
91 >      }//isLead
92 >    }//genMatched
93  
94    }//FillHistograms
95  
96 +  bool HistosElecs::MatchesGenElectron(const pat::Electron& aPatElec)
97 +  {
98 +    
99 +    bool isGenMatched = false;
100 +
101 +    const std::vector<reco::GenParticleRef> & lVec = aPatElec.genParticleRefs();
102 +    for ( std::vector<reco::GenParticleRef>::const_iterator it = lVec.begin();
103 +          it != lVec.end(); ++it ) {
104 +      if ( it->ref().isNonnull() && it->ref().isValid() ) {
105 +        const reco::GenParticleRef & genParticle = (*it);
106 +        if ( genParticle->pdgId() == -11 || genParticle->pdgId() == +11 ) isGenMatched = true;
107 +      } else {
108 +        edm::LogWarning("MatchesGenElectron") << " edm::Ref of genParticle associated to pat::Electron is invalid !!";
109 +      }
110 +    }
111 +    return isGenMatched;
112 +  }
113 +
114   }//namespace
115  
116  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines