ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/LJMet/Fix/src/Muon.cc
Revision: 1.2
Committed: Mon Sep 13 23:25:32 2010 UTC (14 years, 7 months ago) by kukartse
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +9 -24 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 kukartse 1.1 //
2     // $Id: Muon.cc,v 1.26 2010/05/13 15:52:13 rwolf Exp $
3     //
4    
5     #include "DataFormats/PatCandidates/interface/Muon.h"
6     #include "DataFormats/MuonReco/interface/MuonSelectors.h"
7     #include "FWCore/Utilities/interface/Exception.h"
8    
9     #include <limits>
10    
11     using namespace pat;
12    
13    
14     /// default constructor
15     Muon::Muon() :
16     Lepton<reco::Muon>(),
17     embeddedTrack_(false),
18     embeddedStandAloneMuon_(false),
19     embeddedCombinedMuon_(false),
20     embeddedTCMETMuonCorrs_(false),
21     embeddedCaloMETMuonCorrs_(false),
22     embeddedPickyMuon_(false),
23     embeddedTpfmsMuon_(false),
24     pickyMuonRef_(),
25     tpfmsMuonRef_(),
26     embeddedPFCandidate_(false),
27     pfCandidateRef_(),
28     cachedNormChi2_(false),
29     cachedDB_(false),
30     cachedNumberOfValidHits_(0),
31     normChi2_(0.0),
32     dB_(0.0),
33     edB_(0.0),
34     numberOfValidHits_(0)
35     {
36 kukartse 1.2 initImpactParameters();
37 kukartse 1.1 }
38    
39    
40     /// constructor from reco::Muon
41     Muon::Muon(const reco::Muon & aMuon) :
42     Lepton<reco::Muon>(aMuon),
43     embeddedTrack_(false),
44     embeddedStandAloneMuon_(false),
45     embeddedCombinedMuon_(false),
46     embeddedTCMETMuonCorrs_(false),
47     embeddedCaloMETMuonCorrs_(false),
48     embeddedPickyMuon_(false),
49     embeddedTpfmsMuon_(false),
50     pickyMuonRef_(),
51     tpfmsMuonRef_(),
52     embeddedPFCandidate_(false),
53     pfCandidateRef_(),
54     cachedNormChi2_(false),
55     cachedDB_(false),
56     cachedNumberOfValidHits_(0),
57     normChi2_(0.0),
58     dB_(0.0),
59     edB_(0.0),
60     numberOfValidHits_(0)
61     {
62 kukartse 1.2 initImpactParameters();
63 kukartse 1.1 }
64    
65    
66     /// constructor from ref to reco::Muon
67     Muon::Muon(const edm::RefToBase<reco::Muon> & aMuonRef) :
68     Lepton<reco::Muon>(aMuonRef),
69     embeddedTrack_(false),
70     embeddedStandAloneMuon_(false),
71     embeddedCombinedMuon_(false),
72     embeddedTCMETMuonCorrs_(false),
73     embeddedCaloMETMuonCorrs_(false),
74     embeddedPickyMuon_(false),
75     embeddedTpfmsMuon_(false),
76     pickyMuonRef_(),
77     tpfmsMuonRef_(),
78     embeddedPFCandidate_(false),
79     pfCandidateRef_(),
80     cachedNormChi2_(false),
81     cachedDB_(false),
82     cachedNumberOfValidHits_(0),
83     normChi2_(0.0),
84     dB_(0.0),
85     edB_(0.0),
86     numberOfValidHits_(0)
87     {
88 kukartse 1.2 initImpactParameters();
89 kukartse 1.1 }
90    
91    
92     /// constructor from ref to reco::Muon
93     Muon::Muon(const edm::Ptr<reco::Muon> & aMuonRef) :
94     Lepton<reco::Muon>(aMuonRef),
95     embeddedTrack_(false),
96     embeddedStandAloneMuon_(false),
97     embeddedCombinedMuon_(false),
98     embeddedTCMETMuonCorrs_(false),
99     embeddedCaloMETMuonCorrs_(false),
100     embeddedPickyMuon_(false),
101     embeddedTpfmsMuon_(false),
102     pickyMuonRef_(),
103     tpfmsMuonRef_(),
104     embeddedPFCandidate_(false),
105     pfCandidateRef_(),
106     cachedNormChi2_(false),
107     cachedDB_(false),
108     cachedNumberOfValidHits_(0),
109     normChi2_(0.0),
110     dB_(0.0),
111     edB_(0.0),
112     numberOfValidHits_(0)
113     {
114 kukartse 1.2 initImpactParameters();
115 kukartse 1.1 }
116    
117    
118     /// destructor
119     Muon::~Muon() {
120     }
121    
122    
123 kukartse 1.2 // initialize impact parameter container vars
124     void Muon::initImpactParameters() {
125 kukartse 1.1 for (int i_ = 0; i_<5; ++i_){
126 kukartse 1.2 ip_.push_back(0.0);
127     eip_.push_back(0.0);
128     cachedIP_.push_back(false);
129 kukartse 1.1 }
130     }
131    
132    
133     /// reference to Track reconstructed in the tracker only (reimplemented from reco::Muon)
134     reco::TrackRef Muon::track() const {
135     if (embeddedTrack_) {
136     return reco::TrackRef(&track_, 0);
137     } else {
138     return reco::Muon::innerTrack();
139     }
140     }
141    
142    
143     /// reference to Track reconstructed in the muon detector only (reimplemented from reco::Muon)
144     reco::TrackRef Muon::standAloneMuon() const {
145     if (embeddedStandAloneMuon_) {
146     return reco::TrackRef(&standAloneMuon_, 0);
147     } else {
148     return reco::Muon::outerTrack();
149     }
150     }
151    
152    
153     /// reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon)
154     reco::TrackRef Muon::combinedMuon() const {
155     if (embeddedCombinedMuon_) {
156     return reco::TrackRef(&combinedMuon_, 0);
157     } else {
158     return reco::Muon::globalTrack();
159     }
160     }
161    
162     /// reference to Track reconstructed using hits in the tracker + "good" muon hits
163     reco::TrackRef Muon::pickyMuon() const {
164     if (embeddedPickyMuon_) {
165     return reco::TrackRef(&pickyMuon_, 0);
166     } else {
167     return pickyMuonRef_;
168     }
169     }
170    
171     /// reference to Track reconstructed using hits in the tracker + info from the first muon station that has hits
172     reco::TrackRef Muon::tpfmsMuon() const {
173     if (embeddedTpfmsMuon_) {
174     return reco::TrackRef(&tpfmsMuon_, 0);
175     } else {
176     return tpfmsMuonRef_;
177     }
178     }
179    
180     /// reference to the source IsolatedPFCandidates
181     reco::PFCandidateRef Muon::pfCandidateRef() const {
182     if (embeddedPFCandidate_) {
183     return reco::PFCandidateRef(&pfCandidate_, 0);
184     } else {
185     return pfCandidateRef_;
186     }
187     }
188    
189    
190     /// embed the Track reconstructed in the tracker only
191     void Muon::embedTrack() {
192     track_.clear();
193     if (reco::Muon::innerTrack().isNonnull()) {
194     track_.push_back(*reco::Muon::innerTrack());
195     embeddedTrack_ = true;
196     }
197     }
198    
199    
200     /// embed the Track reconstructed in the muon detector only
201     void Muon::embedStandAloneMuon() {
202     standAloneMuon_.clear();
203     if (reco::Muon::outerTrack().isNonnull()) {
204     standAloneMuon_.push_back(*reco::Muon::outerTrack());
205     embeddedStandAloneMuon_ = true;
206     }
207     }
208    
209    
210     /// embed the Track reconstructed in both tracked and muon detector
211     void Muon::embedCombinedMuon() {
212     combinedMuon_.clear();
213     if (reco::Muon::globalTrack().isNonnull()) {
214     combinedMuon_.push_back(*reco::Muon::globalTrack());
215     embeddedCombinedMuon_ = true;
216     }
217     }
218    
219     /// embed the MuonMETCorrectionData for muon corrected caloMET
220     void Muon::embedCaloMETMuonCorrs(const reco::MuonMETCorrectionData& t) {
221     caloMETMuonCorrs_.clear();
222     caloMETMuonCorrs_.push_back(t);
223     embeddedCaloMETMuonCorrs_ = true;
224     }
225    
226     /// embed the MuonMETCorrectionData for tcMET
227     void Muon::embedTcMETMuonCorrs(const reco::MuonMETCorrectionData& t) {
228     tcMETMuonCorrs_.clear();
229     tcMETMuonCorrs_.push_back(t);
230     embeddedTCMETMuonCorrs_ = true;
231     }
232    
233     /// embed the picky Track
234     void Muon::embedPickyMuon() {
235     pickyMuon_.clear();
236     if (pickyMuonRef_.isNonnull()) {
237     pickyMuon_.push_back(*pickyMuonRef_);
238     embeddedPickyMuon_ = true;
239     }
240     }
241    
242     /// embed the tpfms Track
243     void Muon::embedTpfmsMuon() {
244     tpfmsMuon_.clear();
245     if (tpfmsMuonRef_.isNonnull()) {
246     tpfmsMuon_.push_back(*tpfmsMuonRef_);
247     embeddedTpfmsMuon_ = true;
248     }
249     }
250    
251     /// embed the IsolatedPFCandidate pointed to by pfCandidateRef_
252     void Muon::embedPFCandidate() {
253     pfCandidate_.clear();
254     if ( pfCandidateRef_.isAvailable() && pfCandidateRef_.isNonnull()) {
255     pfCandidate_.push_back( *pfCandidateRef_ );
256     embeddedPFCandidate_ = true;
257     }
258     }
259    
260     bool Muon::muonID(const std::string& name) const {
261     muon::SelectionType st = muon::selectionTypeFromString(name);
262     return muon::isGoodMuon(*this, st);
263     }
264    
265    
266     /// Norm chi2 gives the normalized chi2 of the global track.
267     /// The user can choose to cache this info so they can drop the
268     /// global track, or they can use the track itself if it is present
269     /// in the event.
270     double Muon::normChi2() const {
271     if ( cachedNormChi2_ ) {
272     return normChi2_;
273     } else {
274     reco::TrackRef t = globalTrack();
275     return t->chi2() / t->ndof();
276     }
277     }
278    
279     /// numberOfValidHits returns the number of valid hits on the global track.
280     /// The user can choose to cache this info so they can drop the
281     /// global track, or they can use the track itself if it is present
282     /// in the event.
283     unsigned int Muon::numberOfValidHits() const {
284     if ( cachedNumberOfValidHits_ ) {
285     return numberOfValidHits_;
286     } else {
287     reco::TrackRef t = innerTrack();
288     return t->numberOfValidHits();
289     }
290     }
291    
292     // embed various impact parameters with errors
293     // IpType defines the type of the impact parameter
294     // None is default and reverts to old behavior controlled by
295     // patMuons.usePV = True/False
296     double Muon::dB(IpType type_) const {
297    
298     // preserve old functionality exactly
299     if (type_ == None){
300     if ( cachedDB_ ) {
301     return dB_;
302     }
303     else {
304     return std::numeric_limits<double>::max();
305     }
306     }
307    
308     // more IP types (new)
309     else if ( cachedIP_[type_] ) {
310     return ip_[type_];
311     } else {
312     return std::numeric_limits<double>::max();
313     }
314     }
315    
316    
317     // embed various impact parameters with errors
318     // IpType defines the type of the impact parameter
319     // None is default and reverts to old behavior controlled by
320     // patMuons.usePV = True/False
321     double Muon::edB(IpType type_) const {
322    
323     // preserve old functionality exactly
324     if (type_ == None){
325     if ( cachedDB_ ) {
326     return edB_;
327     }
328     else {
329     return std::numeric_limits<double>::max();
330     }
331     }
332    
333     // more IP types (new)
334     else if ( cachedIP_[type_] ) {
335     return eip_[type_];
336     } else {
337     return std::numeric_limits<double>::max();
338     }
339     }
340    
341    
342     double Muon::segmentCompatibility(reco::Muon::ArbitrationType arbitrationType) const {
343     return muon::segmentCompatibility(*this, arbitrationType);
344     }
345    
346