ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Morgan/src/MuonAnalyzer.cc
Revision: 1.17
Committed: Wed Oct 28 16:05:50 2009 UTC (15 years, 6 months ago) by lethuill
Content type: text/plain
Branch: MAIN
CVS Tags: all_3_3_2_01, HEAD
Changes since 1.16: +6 -13 lines
Error occurred while calculating annotation data.
Log Message:
Use primary vertex instead of beam spot in d0 and dz calculation

File Contents

# Content
1 #include "../interface/MuonAnalyzer.h"
2
3 using namespace std;
4 using namespace reco;
5 using namespace edm;
6
7 MuonAnalyzer::MuonAnalyzer(const edm::ParameterSet& producersNames, const edm::ParameterSet& myConfig, int verbosity):LeptonAnalyzer(producersNames, myConfig, verbosity)
8 {
9 useMC_ = myConfig.getUntrackedParameter<bool>("doMuonMC");
10 muonProducer_ = producersNames.getParameter<edm::InputTag>("muonProducer");
11 }
12
13 MuonAnalyzer::~MuonAnalyzer()
14 {
15 }
16
17 bool MuonAnalyzer::process(const edm::Event& iEvent, TRootBeamSpot* rootBeamSpot, TClonesArray* rootMuons)
18 {
19
20 Float_t sintheta = 0.;
21 unsigned int nMuons=0;
22
23 edm::Handle < std::vector <reco::Muon> > recoMuons;
24 if( dataType_=="RECO" )
25 {
26 try
27 {
28 iEvent.getByLabel(muonProducer_, recoMuons);
29 nMuons = recoMuons->size();
30 }
31 catch (cms::Exception& exception)
32 {
33 if ( !allowMissingCollection_ )
34 {
35 cout << " ##### ERROR IN MuonAnalyzer::process => reco::Muon collection is missing #####"<<endl;
36 throw exception;
37 }
38 if(verbosity_>1) cout << " ===> No reco::Muon collection, skip muon info" << endl;
39 return false;
40 }
41 }
42
43 edm::Handle < std::vector <pat::Muon> > patMuons;
44 if( dataType_=="PAT" )
45 {
46 try
47 {
48 iEvent.getByLabel(muonProducer_, patMuons);
49 nMuons = patMuons->size();
50 }
51 catch (cms::Exception& exception)
52 {
53 if ( !allowMissingCollection_ )
54 {
55 cout << " ##### ERROR IN MuonAnalyzer::process => pat::Muon collection is missing #####"<<endl;
56 throw exception;
57 }
58 if(verbosity_>1) cout << " ===> No pat::Muon collection, skip muon info" << endl;
59 return false;
60 }
61 }
62
63 if(verbosity_>1) std::cout << " Number of muons = " << nMuons << " Label: " << muonProducer_.label() << " Instance: " << muonProducer_.instance() << std::endl;
64
65 for (unsigned int j=0; j<nMuons; j++)
66 {
67 const reco::Muon* muon = 0;
68 if( dataType_=="RECO" ) muon = &((*recoMuons)[j]);
69 if( dataType_=="PAT" ) muon = (const reco::Muon*) ( & ((*patMuons)[j]) );
70
71 TRootMuon localMuon(
72 muon->px()
73 ,muon->py()
74 ,muon->pz()
75 ,muon->energy()
76 ,muon->vx()
77 ,muon->vy()
78 ,muon->vz()
79 ,muon->pdgId()
80 ,muon->charge()
81 );
82
83 // Variables from reco::Muon
84 sintheta = sin( localMuon.Theta() );
85
86 localMuon.setCaloEnergy(
87 muon->calEnergy().em * sintheta
88 ,muon->calEnergy().emS9 * sintheta
89 ,muon->calEnergy().had * sintheta
90 ,muon->calEnergy().hadS9 * sintheta
91 ,muon->calEnergy().ho * sintheta
92 ,muon->calEnergy().hoS9 * sintheta
93 ,muon->caloCompatibility()
94 );
95
96 localMuon.setIsoR03(
97 muon->isolationR03().emEt
98 ,muon->isolationR03().hadEt
99 ,muon->isolationR03().hoEt
100 ,muon->isolationR03().sumPt
101 ,muon->isolationR03().nTracks
102 ,muon->isolationR03().nJets
103 );
104
105 localMuon.setIsoR05(
106 muon->isolationR05().emEt
107 ,muon->isolationR05().hadEt
108 ,muon->isolationR05().hoEt
109 ,muon->isolationR05().sumPt
110 ,muon->isolationR05().nTracks
111 ,muon->isolationR05().nJets
112 );
113
114 localMuon.setValidity(
115 muon->isEnergyValid()
116 ,muon->isMatchesValid()
117 ,muon->isIsolationValid()
118 );
119
120 localMuon.setDirection( muon->time().direction() );
121 localMuon.setAlgo( muon->type() );
122 localMuon.setID(
123 // int( muon::isGoodMuon( &muon, muon::AllGlobalMuons ) )
124 // ,int( muon::isGoodMuon( &muon, muon::AllStandAloneMuons ) )
125 // ,int( muon::isGoodMuon( &muon, muon::AllTrackerMuons ) )
126 int( muon::isGoodMuon( *muon, muon::TrackerMuonArbitrated ) )
127 ,int( muon::isGoodMuon( *muon, muon::AllArbitrated ) )
128 ,int( muon::isGoodMuon( *muon, muon::GlobalMuonPromptTight ) )
129 ,int( muon::isGoodMuon( *muon, muon::TMLastStationLoose ) )
130 ,int( muon::isGoodMuon( *muon, muon::TMLastStationTight ) )
131 ,int( muon::isGoodMuon( *muon, muon::TM2DCompatibilityLoose ) )
132 ,int( muon::isGoodMuon( *muon, muon::TM2DCompatibilityTight ) )
133 // ,int( muon::isGoodMuon( &muon, muon::TMOneStationLoose ) )
134 // ,int( muon::isGoodMuon( &muon, muon::TMOneStationTight ) )
135 // ,int( muon::isGoodMuon( &muon, muon::TMLastStationOptimizedLowPtLoose ) )
136 // ,int( muon::isGoodMuon( &muon, muon::TMLastStationOptimizedLowPtTight ) )
137 );
138
139 // Variables from reco::Track
140
141 // Track in muon detector only
142 reco::TrackRef outerTK = muon->outerTrack();
143 if ( outerTK.isNonnull() )
144 {
145 //cout << "outerTK (px,py,pz)=" << outerTK->px() <<" , " << outerTK->py() <<" , " << outerTK->pz() <<" )" << endl;
146 localMuon.setXYZTOuterTrack( outerTK->px(), outerTK->py(), outerTK->pz(), outerTK->p() );
147 }
148
149 // Track in tracker + muon detector
150 reco::TrackRef globalTK = muon->globalTrack();
151 if ( globalTK.isNonnull() )
152 {
153 //cout << "globalTK (px,py,pz)=" << globalTK->px() <<" , " << globalTK->py() <<" , " << globalTK->pz() <<" )" << endl;
154 localMuon.setXYZTGlobalTrack( globalTK->px(), globalTK->py(), globalTK->pz(), globalTK->p() );
155 }
156
157 // Track in tracker only
158 reco::TrackRef track = muon->innerTrack();
159 if ( track.isNonnull() )
160 {
161 //cout << "innerTK (px,py,pz)=" << track->px() <<" , " << track->py() <<" , " << track->pz() <<" )" << endl;
162 localMuon.setXYZTInnerTrack( track->px(), track->py(), track->pz(), track->p() );
163 const reco::HitPattern& hit = track->hitPattern();
164 localMuon.setNumberOfValidPixelHits(hit.numberOfValidPixelHits());
165 localMuon.setNumberOfValidTrackerHits(hit.numberOfValidTrackerHits());
166 localMuon.setPixelLayersWithMeasurement(hit.pixelLayersWithMeasurement());
167 localMuon.setStripLayersWithMeasurement(hit.stripLayersWithMeasurement());
168
169 if (vertexPoint_!=0)
170 {
171 const reco::TrackBase::Point point( vertexPoint_->x(), vertexPoint_->y(), vertexPoint_->z() );
172 localMuon.setD0( -1.*(track->dxy(point)) );
173 localMuon.setDsz( track->dsz(point) );
174 }
175 else
176 {
177 localMuon.setD0( -1.*(track->dxy()) );
178 localMuon.setDsz( track->dsz() );
179 }
180
181 // FIXME - Add Vertex error quadratically
182 localMuon.setD0Error(track->d0Error());
183 localMuon.setDszError(track->dszError());
184
185 localMuon.setNormalizedChi2(track->normalizedChi2());
186 localMuon.setPtError(track->ptError());
187 localMuon.setEtaError(track->etaError());
188 localMuon.setPhiError(track->phiError());
189
190 if(doPrimaryVertex_)
191 {
192 // FIXME - Should be Tracker track... what if STA muon ?
193 const reco::TransientTrack transtrack = trackBuilder_->build( track ) ;
194 float sig3d = ip3DSignificance(transtrack);
195 localMuon.setIP3DSignificance(sig3d);
196 }
197 }
198
199
200 if( dataType_=="RECO" )
201 {
202 // Some specific methods requiring RECO / AOD format
203 // Do association to genParticle ?
204 // Add InnerTrack, OuterTrack, GlobalTrack infos ?
205 }
206
207 if( dataType_=="PAT" )
208 {
209 // Some specific methods to pat::Muon
210 const pat::Muon *patMuon = dynamic_cast<const pat::Muon*>(&*muon);
211 localMuon.setEcalCandEnergy(patMuon->ecalIsoDeposit()->candEnergy() );
212 localMuon.setHcalCandEnergy(patMuon->hcalIsoDeposit()->candEnergy() );
213 // Use existing reference to genParticle [ pat::PATObject::genParticleRef() ] ?
214 // Alternative methode for isolation (isoDeposit) ?
215 //
216 // leptonID apparently not initialised in PAT...
217 // cout << "Valeur pourrie du leptonID=" << patMuon->leptonID() << endl;
218
219 if(useMC_)
220 {
221 // MC truth associator index
222 if ((patMuon->genParticleRef()).isNonnull()) {
223 localMuon.setGenParticleIndex((patMuon->genParticleRef()).index());
224 } else {
225 localMuon.setGenParticleIndex(-1);
226 }
227 }
228 }
229
230 new( (*rootMuons)[j] ) TRootMuon(localMuon);
231 if(verbosity_>2) cout << " ["<< setw(3) << j << "] " << localMuon << endl;
232 }
233
234 return true;
235 }