ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Morgan/src/MuonAnalyzer.cc
Revision: 1.15
Committed: Wed Jun 10 12:09:11 2009 UTC (15 years, 10 months ago) by lethuill
Content type: text/plain
Branch: MAIN
CVS Tags: all_2_2_9_03, all_2_2_9_02, all_2_2_9_01
Branch point for: CMSSW_2_2_X_br
Changes since 1.14: +3 -1 lines
Log Message:
Add candidate ecal and hcal energy in a cone for pat::Muon

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     localMuon.setID(
123     int(muon->isGood(reco::Muon::TrackerMuonArbitrated))
124     ,int(muon->isGood(reco::Muon::AllArbitrated))
125     ,int(muon->isGood(reco::Muon::GlobalMuonPromptTight))
126     ,int(muon->isGood(reco::Muon::TMLastStationLoose))
127     ,int(muon->isGood(reco::Muon::TMLastStationTight))
128     ,int(muon->isGood(reco::Muon::TM2DCompatibilityLoose))
129     ,int(muon->isGood(reco::Muon::TM2DCompatibilityTight))
130     );
131    
132 lethuill 1.7 // Variables from reco::Track
133 lethuill 1.13
134     // Track in muon detector only
135     reco::TrackRef outerTK = muon->outerTrack();
136     if ( outerTK.isNonnull() )
137     {
138     //cout << "outerTK (px,py,pz)=" << outerTK->px() <<" , " << outerTK->py() <<" , " << outerTK->pz() <<" )" << endl;
139     localMuon.setXYZTOuterTrack( outerTK->px(), outerTK->py(), outerTK->pz(), outerTK->p() );
140     }
141    
142     // Track in tracker + muon detector
143     reco::TrackRef globalTK = muon->globalTrack();
144     if ( globalTK.isNonnull() )
145     {
146     //cout << "globalTK (px,py,pz)=" << globalTK->px() <<" , " << globalTK->py() <<" , " << globalTK->pz() <<" )" << endl;
147     localMuon.setXYZTGlobalTrack( globalTK->px(), globalTK->py(), globalTK->pz(), globalTK->p() );
148     }
149    
150     // Track in tracker only
151 lethuill 1.7 reco::TrackRef track = muon->innerTrack();
152     if ( track.isNonnull() )
153     {
154 lethuill 1.13 //cout << "innerTK (px,py,pz)=" << track->px() <<" , " << track->py() <<" , " << track->pz() <<" )" << endl;
155     localMuon.setXYZTInnerTrack( track->px(), track->py(), track->pz(), track->p() );
156 lethuill 1.7 const reco::HitPattern& hit = track->hitPattern();
157 lethuill 1.11 localMuon.setNumberOfValidPixelHits(hit.numberOfValidPixelHits());
158     localMuon.setNumberOfValidTrackerHits(hit.numberOfValidTrackerHits());
159 lethuill 1.8 localMuon.setPixelLayersWithMeasurement(hit.pixelLayersWithMeasurement());
160     localMuon.setStripLayersWithMeasurement(hit.stripLayersWithMeasurement());
161 lethuill 1.11
162     if (doBeamSpot_)
163     {
164     if ( rootBeamSpot->sigmaZ() > 0. ) // Check beam spot was correctly initialised
165     {
166     const reco::TrackBase::Point point( rootBeamSpot->x(), rootBeamSpot->y(), rootBeamSpot->z() );
167     localMuon.setD0( -1.*(track->dxy(point)) );
168     localMuon.setDsz( track->dsz(point) );
169     }
170     else
171     {
172     localMuon.setD0( -1.*(track->dxy()) );
173     localMuon.setDsz( track->dsz() );
174     }
175     }
176     else
177     {
178     localMuon.setD0( -1.*(track->dxy()) );
179     localMuon.setDsz( track->dsz() );
180     }
181    
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 }