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.2 by amagnan, Fri Apr 17 14:26:35 2009 UTC

# Line 1 | Line 1
1   #include <iostream>
2   #include <fstream>
3  
4 < #include "DataFormats/MuonReco/interface/Muon.h"
4 > //#include "DataFormats/EgammaReco/interface/Electron.h"
5  
6  
7 + #include "FWCore/MessageLogger/interface/MessageLogger.h"
8 +
9   #include "UserCode/HbbAnalysis/interface/HistosElecs.hh"
10  
11   namespace HbbAnalysis {//namespace
12  
13 <  void HistosElecs::Initialise(TFileDirectory & aDir, std::string aName){
13 >  void HistosElecs::Initialise(TFileDirectory & aDir, std::string aName, bool aDoGenMatched){
14  
15 +    doGenMatched_ = aDoGenMatched;
16      CreateHistos(aName,aDir);
17  
18 +    p_nElectrons = aDir.make<TH1F>("p_nElectrons",";N_{electrons};N_{entries}",20,0,20);
19 +
20      p_nChambers = aDir.make<TH1F>("p_nChambers",";n_{chambers};n_{entries}",20,0,20);
21  
22    }
23  
24 <  void HistosElecs::FillHistograms(const pat::Muon & aMuon){//FillHistograms
25 <    const reco::Muon* recoMuon = dynamic_cast<const reco::Muon*>(aMuon.originalObject());
24 >  void HistosElecs::FillEventHistograms(edm::Handle<std::vector<pat::Electron> > aCol){
25 >
26 >    if (doGenMatched_) {
27 >      unsigned int nMatched = 0;
28 >      for (std::vector<pat::Electron>::const_iterator iElec = aCol->begin();
29 >           iElec != aCol->end();
30 >           iElec++)
31 >        {
32 >          if (MatchesGenElectron(*iElec)) nMatched++;
33 >        }
34 >      p_nElectrons->Fill(nMatched);
35 >    }
36 >    else p_nElectrons->Fill(aCol->size());
37 >
38 >  }
39 >
40 >  void HistosElecs::FillHistograms(const pat::Electron & aElec, bool isLead){//FillHistograms
41  
42 <    p_nChambers->Fill(recoMuon->numberOfChambers());
42 >    bool lIsGenMatched = !doGenMatched_ || (doGenMatched_ && MatchesGenElectron(aElec));
43 >    if (lIsGenMatched) {//genMatched
44 >      if (isLead) {//isLead
45 >        FillBaseHistograms(aElec.pt(),aElec.eta(),aElec.phi());
46  
47 <    FillBaseHistograms(aMuon.pt(),aMuon.eta(),aMuon.phi());
47 >      }//isLead
48 >    }//genMatched
49  
50    }//FillHistograms
51  
52 +  bool HistosElecs::MatchesGenElectron(const pat::Electron& aPatElec)
53 +  {
54 +    
55 +    bool isGenMatched = false;
56 +
57 +    const std::vector<reco::GenParticleRef> & lVec = aPatElec.genParticleRefs();
58 +    for ( std::vector<reco::GenParticleRef>::const_iterator it = lVec.begin();
59 +          it != lVec.end(); ++it ) {
60 +      if ( it->ref().isNonnull() && it->ref().isValid() ) {
61 +        const reco::GenParticleRef & genParticle = (*it);
62 +        if ( genParticle->pdgId() == -11 || genParticle->pdgId() == +11 ) isGenMatched = true;
63 +      } else {
64 +        edm::LogWarning("MatchesGenElectron") << " edm::Ref of genParticle associated to pat::Electron is invalid !!";
65 +      }
66 +    }
67 +    return isGenMatched;
68 +  }
69 +
70   }//namespace
71  
72  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines