ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Morgan/src/MuonAnalyzer.cc
Revision: 1.7
Committed: Thu Apr 9 16:55:09 2009 UTC (16 years ago) by lethuill
Content type: text/plain
Branch: MAIN
Changes since 1.6: +20 -0 lines
Log Message:
add infos on associated inner track (impact parameter, hits multiplicity)

File Contents

# User Rev Content
1 lethuill 1.2 #include "../interface/MuonAnalyzer.h"
2 lethuill 1.1
3     using namespace std;
4     using namespace reco;
5     using namespace edm;
6    
7 lethuill 1.4 MuonAnalyzer::MuonAnalyzer(const edm::ParameterSet& producersNames):verbosity_(0),useMC_(false)
8 lethuill 1.1 {
9 lethuill 1.2 dataType_ = producersNames.getUntrackedParameter<string>("dataType","unknown");
10 lethuill 1.1 muonProducer_ = producersNames.getParameter<edm::InputTag>("muonProducer");
11     }
12    
13 lethuill 1.4 MuonAnalyzer::MuonAnalyzer(const edm::ParameterSet& producersNames, const edm::ParameterSet& myConfig, int verbosity):verbosity_(verbosity)
14 lethuill 1.1 {
15 lethuill 1.2 dataType_ = producersNames.getUntrackedParameter<string>("dataType","unknown");
16 lethuill 1.1 muonProducer_ = producersNames.getParameter<edm::InputTag>("muonProducer");
17 lethuill 1.4 useMC_ = myConfig.getUntrackedParameter<bool>("doMuonMC");
18 lethuill 1.1 }
19    
20     MuonAnalyzer::~MuonAnalyzer()
21     {
22     }
23    
24     void MuonAnalyzer::Process(const edm::Event& iEvent, TClonesArray* rootMuons)
25     {
26    
27     Float_t sintheta = 0.;
28 lethuill 1.2 unsigned int nMuons=0;
29    
30     edm::Handle < std::vector <reco::Muon> > recoMuons;
31     if( dataType_=="RECO" || dataType_=="AOD" )
32     {
33     iEvent.getByLabel(muonProducer_, recoMuons);
34     nMuons = recoMuons->size();
35     }
36    
37     edm::Handle < std::vector <pat::Muon> > patMuons;
38     if( dataType_=="PAT" || dataType_=="PATAOD" )
39     {
40     iEvent.getByLabel(muonProducer_, patMuons);
41     nMuons = patMuons->size();
42     }
43    
44     if(verbosity_>1) std::cout << " Number of muons = " << nMuons << " Label: " << muonProducer_.label() << " Instance: " << muonProducer_.instance() << std::endl;
45    
46     for (unsigned int j=0; j<nMuons; j++)
47 lethuill 1.1 {
48 lethuill 1.3 const reco::Muon* muon = 0;
49     if( dataType_=="RECO" || dataType_=="AOD" ) muon = &((*recoMuons)[j]);
50     if( dataType_=="PAT" || dataType_=="PATAOD" ) muon = (const reco::Muon*) ( & ((*patMuons)[j]) );
51 lethuill 1.2
52 lethuill 1.1 TRootMuon localMuon(
53 lethuill 1.3 muon->px()
54     ,muon->py()
55     ,muon->pz()
56     ,muon->energy()
57     ,muon->vx()
58     ,muon->vy()
59     ,muon->vz()
60 lethuill 1.6 ,muon->pdgId()
61 lethuill 1.3 ,muon->charge()
62 lethuill 1.1 );
63    
64 lethuill 1.4 // Variables from reco::Muon
65 lethuill 1.1 sintheta = sin( localMuon.Theta() );
66 lethuill 1.2
67 lethuill 1.3 localMuon.setCaloEnergy(
68     muon->calEnergy().em * sintheta
69     ,muon->calEnergy().emS9 * sintheta
70     ,muon->calEnergy().had * sintheta
71     ,muon->calEnergy().hadS9 * sintheta
72     ,muon->calEnergy().ho * sintheta
73     ,muon->calEnergy().hoS9 * sintheta
74     ,muon->caloCompatibility()
75     );
76    
77     localMuon.setIsoR03(
78     muon->isolationR03().emEt
79     ,muon->isolationR03().hadEt
80     ,muon->isolationR03().hoEt
81     ,muon->isolationR03().sumPt
82     ,muon->isolationR03().nTracks
83     ,muon->isolationR03().nJets
84     );
85    
86     localMuon.setIsoR05(
87     muon->isolationR05().emEt
88     ,muon->isolationR05().hadEt
89     ,muon->isolationR05().hoEt
90     ,muon->isolationR05().sumPt
91     ,muon->isolationR05().nTracks
92     ,muon->isolationR05().nJets
93     );
94    
95     localMuon.setValidity(
96     muon->isEnergyValid()
97     ,muon->isMatchesValid()
98     ,muon->isIsolationValid()
99     );
100    
101     localMuon.setDirection( muon->time().direction() );
102     localMuon.setAlgo( muon->type() );
103     localMuon.setID(
104     int(muon->isGood(reco::Muon::TrackerMuonArbitrated))
105     ,int(muon->isGood(reco::Muon::AllArbitrated))
106     ,int(muon->isGood(reco::Muon::GlobalMuonPromptTight))
107     ,int(muon->isGood(reco::Muon::TMLastStationLoose))
108     ,int(muon->isGood(reco::Muon::TMLastStationTight))
109     ,int(muon->isGood(reco::Muon::TM2DCompatibilityLoose))
110     ,int(muon->isGood(reco::Muon::TM2DCompatibilityTight))
111     );
112    
113 lethuill 1.7 // Variables from reco::Track
114     reco::TrackRef track = muon->innerTrack();
115     if ( track.isNonnull() )
116     {
117     const reco::HitPattern& hit = track->hitPattern();
118     localMuon.setNumberOfValidPixelHits(hit.numberOfValidPixelHits());
119     localMuon.setNumberOfValidTrackerHits(hit.numberOfValidTrackerHits());
120     // FIXME - replace with double dxy(const Point& myBeamSpot) method ?
121     localMuon.setD0(track->d0());
122     localMuon.setD0Error(track->d0Error());
123     // FIXME - replace with double dsz(const Point& myBeamSpot) method ?
124     localMuon.setDsz(track->dsz());
125     localMuon.setDszError(track->dszError());
126     localMuon.setNormalizedChi2(track->normalizedChi2());
127     localMuon.setPtError(track->ptError());
128     localMuon.setEtaError(track->etaError());
129     localMuon.setPhiError(track->phiError());
130     }
131    
132    
133 lethuill 1.3 if( dataType_=="RECO" || dataType_=="AOD" )
134 lethuill 1.2 {
135 lethuill 1.3 // Some specific methods requiring RECO / AOD format
136     // Do association to genParticle ?
137     // Add InnerTrack, OuterTrack, GlobalTrack infos ?
138 lethuill 1.2 }
139    
140 lethuill 1.3 if( dataType_=="PATAOD" || dataType_=="PAT" )
141 lethuill 1.2 {
142     // Some specific methods to pat::Muon
143     const pat::Muon *patMuon = dynamic_cast<const pat::Muon*>(&*muon);
144 lethuill 1.3 // Use existing reference to genParticle [ pat::PATObject::genParticleRef() ] ?
145     // Alternative methode for isolation (isoDeposit) ?
146     //
147     // leptonID apparently not initialised in PAT...
148     // cout << "Valeur pourrie du leptonID=" << patMuon->leptonID() << endl;
149 lethuill 1.4
150     if(useMC_)
151     {
152     // MC truth associator index
153     if ((patMuon->genParticleRef()).isNonnull()) {
154 lethuill 1.5 localMuon.setGenParticleIndex((patMuon->genParticleRef()).index());
155 lethuill 1.4 } else {
156 lethuill 1.5 localMuon.setGenParticleIndex(-1);
157 lethuill 1.4 }
158     }
159 lethuill 1.2 }
160 lethuill 1.6
161 lethuill 1.1 new( (*rootMuons)[j] ) TRootMuon(localMuon);
162     if(verbosity_>2) cout << " ["<< setw(3) << j << "] " << localMuon << endl;
163     }
164     }