ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Morgan/src/MuonAnalyzer.cc
Revision: 1.10
Committed: Fri Apr 17 15:17:38 2009 UTC (16 years ago) by lethuill
Content type: text/plain
Branch: MAIN
Changes since 1.9: +12 -4 lines
Log Message:
Add significance of the 3D impact parameter for leptons.
Calculation done in new LeptonAnalyzer class (Base for MuonAnalyzer and ElectronAnalyzer)

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