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
Log Message:
Use primary vertex instead of beam spot in d0 and dz calculation

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.12 MuonAnalyzer::MuonAnalyzer(const edm::ParameterSet& producersNames, const edm::ParameterSet& myConfig, int verbosity):LeptonAnalyzer(producersNames, myConfig, verbosity)
8 lethuill 1.1 {
9 lethuill 1.12 useMC_ = myConfig.getUntrackedParameter<bool>("doMuonMC");
10 lethuill 1.1 muonProducer_ = producersNames.getParameter<edm::InputTag>("muonProducer");
11     }
12    
13     MuonAnalyzer::~MuonAnalyzer()
14     {
15     }
16    
17 lethuill 1.14 bool MuonAnalyzer::process(const edm::Event& iEvent, TRootBeamSpot* rootBeamSpot, TClonesArray* rootMuons)
18 lethuill 1.1 {
19    
20     Float_t sintheta = 0.;
21 lethuill 1.2 unsigned int nMuons=0;
22    
23     edm::Handle < std::vector <reco::Muon> > recoMuons;
24 lethuill 1.14 if( dataType_=="RECO" )
25 lethuill 1.2 {
26 lethuill 1.14 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 lethuill 1.2 }
42    
43     edm::Handle < std::vector <pat::Muon> > patMuons;
44 lethuill 1.14 if( dataType_=="PAT" )
45 lethuill 1.2 {
46 lethuill 1.14 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 lethuill 1.2 }
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 lethuill 1.1 {
67 lethuill 1.3 const reco::Muon* muon = 0;
68 lethuill 1.14 if( dataType_=="RECO" ) muon = &((*recoMuons)[j]);
69     if( dataType_=="PAT" ) muon = (const reco::Muon*) ( & ((*patMuons)[j]) );
70 lethuill 1.2
71 lethuill 1.1 TRootMuon localMuon(
72 lethuill 1.3 muon->px()
73     ,muon->py()
74     ,muon->pz()
75     ,muon->energy()
76     ,muon->vx()
77     ,muon->vy()
78     ,muon->vz()
79 lethuill 1.6 ,muon->pdgId()
80 lethuill 1.3 ,muon->charge()
81 lethuill 1.1 );
82    
83 lethuill 1.4 // Variables from reco::Muon
84 lethuill 1.1 sintheta = sin( localMuon.Theta() );
85 lethuill 1.2
86 lethuill 1.3 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 lethuill 1.16 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 lethuill 1.7 // Variables from reco::Track
140 lethuill 1.13
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 lethuill 1.7 reco::TrackRef track = muon->innerTrack();
159     if ( track.isNonnull() )
160     {
161 lethuill 1.13 //cout << "innerTK (px,py,pz)=" << track->px() <<" , " << track->py() <<" , " << track->pz() <<" )" << endl;
162     localMuon.setXYZTInnerTrack( track->px(), track->py(), track->pz(), track->p() );
163 lethuill 1.7 const reco::HitPattern& hit = track->hitPattern();
164 lethuill 1.11 localMuon.setNumberOfValidPixelHits(hit.numberOfValidPixelHits());
165     localMuon.setNumberOfValidTrackerHits(hit.numberOfValidTrackerHits());
166 lethuill 1.8 localMuon.setPixelLayersWithMeasurement(hit.pixelLayersWithMeasurement());
167     localMuon.setStripLayersWithMeasurement(hit.stripLayersWithMeasurement());
168 lethuill 1.11
169 lethuill 1.17 if (vertexPoint_!=0)
170 lethuill 1.11 {
171 lethuill 1.17 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 lethuill 1.11 }
175     else
176     {
177     localMuon.setD0( -1.*(track->dxy()) );
178     localMuon.setDsz( track->dsz() );
179     }
180 lethuill 1.17
181     // FIXME - Add Vertex error quadratically
182 lethuill 1.7 localMuon.setD0Error(track->d0Error());
183     localMuon.setDszError(track->dszError());
184 lethuill 1.11
185 lethuill 1.7 localMuon.setNormalizedChi2(track->normalizedChi2());
186     localMuon.setPtError(track->ptError());
187     localMuon.setEtaError(track->etaError());
188     localMuon.setPhiError(track->phiError());
189 lethuill 1.10
190     if(doPrimaryVertex_)
191     {
192 lethuill 1.11 // FIXME - Should be Tracker track... what if STA muon ?
193 lethuill 1.10 const reco::TransientTrack transtrack = trackBuilder_->build( track ) ;
194 lethuill 1.14 float sig3d = ip3DSignificance(transtrack);
195 lethuill 1.15 localMuon.setIP3DSignificance(sig3d);
196 lethuill 1.10 }
197 lethuill 1.7 }
198    
199    
200 lethuill 1.14 if( dataType_=="RECO" )
201 lethuill 1.2 {
202 lethuill 1.3 // Some specific methods requiring RECO / AOD format
203     // Do association to genParticle ?
204     // Add InnerTrack, OuterTrack, GlobalTrack infos ?
205 lethuill 1.2 }
206    
207 lethuill 1.14 if( dataType_=="PAT" )
208 lethuill 1.2 {
209     // Some specific methods to pat::Muon
210     const pat::Muon *patMuon = dynamic_cast<const pat::Muon*>(&*muon);
211 lethuill 1.15 localMuon.setEcalCandEnergy(patMuon->ecalIsoDeposit()->candEnergy() );
212     localMuon.setHcalCandEnergy(patMuon->hcalIsoDeposit()->candEnergy() );
213 lethuill 1.14 // Use existing reference to genParticle [ pat::PATObject::genParticleRef() ] ?
214 lethuill 1.3 // Alternative methode for isolation (isoDeposit) ?
215     //
216     // leptonID apparently not initialised in PAT...
217     // cout << "Valeur pourrie du leptonID=" << patMuon->leptonID() << endl;
218 lethuill 1.4
219     if(useMC_)
220     {
221     // MC truth associator index
222     if ((patMuon->genParticleRef()).isNonnull()) {
223 lethuill 1.5 localMuon.setGenParticleIndex((patMuon->genParticleRef()).index());
224 lethuill 1.4 } else {
225 lethuill 1.5 localMuon.setGenParticleIndex(-1);
226 lethuill 1.4 }
227     }
228 lethuill 1.2 }
229 lethuill 1.6
230 lethuill 1.1 new( (*rootMuons)[j] ) TRootMuon(localMuon);
231     if(verbosity_>2) cout << " ["<< setw(3) << j << "] " << localMuon << endl;
232     }
233 lethuill 1.14
234     return true;
235 lethuill 1.1 }