ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Betchart/TopRefTuple/interface/Tuple_Muon.h
Revision: 1.1
Committed: Wed Nov 7 21:53:10 2012 UTC (12 years, 5 months ago) by bbetchar
Content type: text/plain
Branch: MAIN
Log Message:
Grab ntuplizing codes from UserCode/SusyCAF

File Contents

# User Rev Content
1 bbetchar 1.1 #ifndef TUPLE_MUON
2     #define TUPLE_MUON
3    
4     #include "FWCore/Framework/interface/EDProducer.h"
5     #include "FWCore/Framework/interface/Frameworkfwd.h"
6     #include "FWCore/Framework/interface/Event.h"
7     #include "FWCore/Framework/interface/ESHandle.h"
8     #include "FWCore/Utilities/interface/InputTag.h"
9     #include "FWCore/ParameterSet/interface/ParameterSet.h"
10    
11     #include "DataFormats/MuonReco/interface/Muon.h"
12     #include "DataFormats/PatCandidates/interface/Muon.h"
13     #include "DataFormats/BeamSpot/interface/BeamSpot.h"
14     #include "DataFormats/VertexReco/interface/VertexFwd.h"
15     #include "DataFormats/VertexReco/interface/Vertex.h"
16     #include <string>
17     #include <algorithm>
18    
19     template< typename T >
20     class Tuple_Muon : public edm::EDProducer {
21     public:
22     explicit Tuple_Muon(const edm::ParameterSet&);
23     private:
24     void initTemplate();
25     void initRECO();
26     void initPAT();
27     void produce(edm::Event &, const edm::EventSetup & );
28     void produceTemplate(edm::Event &, const edm::EventSetup &, edm::Handle<std::vector<T> > &);
29     void produceRECO(edm::Event &, const edm::EventSetup &, edm::Handle<std::vector<T> > &);
30     void producePAT(edm::Event &, const edm::EventSetup &, edm::Handle<std::vector<T> > &);
31     bool isInCollection(const T&, const std::vector<T>&);
32     reco::Candidate::LorentzVector muonP4FromP(const reco::Candidate::Vector &);
33    
34     typedef reco::Candidate::LorentzVector LorentzVector;
35     typedef reco::Candidate::Vector Vector;
36     const edm::InputTag inputTag,selectedTag;
37     const std::string Prefix,Suffix;
38     };
39    
40    
41    
42     template< typename T >
43     Tuple_Muon<T>::Tuple_Muon(const edm::ParameterSet& iConfig) :
44     inputTag(iConfig.getParameter<edm::InputTag>("InputTag")),
45     selectedTag(iConfig.getParameter<edm::InputTag>("SelectedMuons")),
46     Prefix(iConfig.getParameter<std::string>("Prefix")),
47     Suffix(iConfig.getParameter<std::string>("Suffix"))
48     {
49     initTemplate();
50     }
51    
52     template< typename T >
53     void Tuple_Muon<T>::initRECO()
54     {
55     produces <bool> ( Prefix + "HandleValid" + Suffix);
56     produces <std::vector<LorentzVector> > ( Prefix + "P4" + Suffix );
57     produces <std::vector<LorentzVector> > ( Prefix + "InnerTrackP4" + Suffix );
58     produces <std::vector<LorentzVector> > ( Prefix + "GlobalTrackP4" + Suffix );
59     produces <std::vector<LorentzVector> > ( Prefix + "OuterTrackP4" + Suffix );
60     produces <std::vector<int> > ( Prefix + "Charge" + Suffix);
61     produces <std::vector<double> > ( Prefix + "GlobalTracknormalizedChi2" + Suffix);
62     produces <std::vector<unsigned> > ( Prefix + "GlobalTracknumberOfValidHits" + Suffix);
63     produces <std::vector<unsigned> > ( Prefix + "GlobalTracknumberOfValidTrackerHits" + Suffix);
64     produces <std::vector<unsigned> > ( Prefix + "GlobalTracknumberOfValidMuonHits" + Suffix);
65    
66     produces <std::vector<int> > (Prefix + "Selected" + Suffix );
67    
68     produces <std::vector<double> > ( Prefix + "GlobalTrackDxy" + Suffix);
69     produces <std::vector<double> > ( Prefix + "GlobalTrackDz" + Suffix);
70     produces <std::vector<double> > ( Prefix + "GlobalTrackDxyBS" + Suffix);
71     produces <std::vector<double> > ( Prefix + "GlobalTrackDzBS" + Suffix);
72     produces <std::vector<double> > ( Prefix + "GlobalTrackDxyError" + Suffix);
73     produces <std::vector<double> > ( Prefix + "GlobalTrackDzError" + Suffix);
74    
75     produces <std::vector<double> > ( Prefix + "InnerTrackDxy" + Suffix);
76     produces <std::vector<double> > ( Prefix + "InnerTrackDxyBS" + Suffix);
77     produces <std::vector<double> > ( Prefix + "InnerTrackDz" + Suffix);
78     produces <std::vector<double> > ( Prefix + "InnerTrackDzBS" + Suffix);
79     produces <std::vector<double> > ( Prefix + "InnerTrackVertexz" + Suffix);
80     produces <std::vector<double> > ( Prefix + "InnerTrackDxyError" + Suffix);
81     produces <std::vector<double> > ( Prefix + "InnerTrackDzError" + Suffix);
82    
83     produces <std::vector<double> > ( Prefix + "InnerTrackNormalizedChi2" + Suffix);
84     produces <std::vector<unsigned> > ( Prefix + "InnerTrackNumberOfValidHits" + Suffix);
85     produces <std::vector<unsigned> > ( Prefix + "NumberOfValidPixelHits" + Suffix);
86     produces <std::vector<unsigned> > ( Prefix + "NumberOfPixelLayersWithMeasurement" + Suffix);
87     produces <std::vector<unsigned> > ( Prefix + "NumberOfTrackerLayersWithMeasurement" + Suffix);
88    
89     produces <std::vector<double> > ( Prefix + "OuterTrackNormalizedChi2" + Suffix);
90     produces <std::vector<unsigned> > ( Prefix + "OuterTrackNumberOfValidHits" + Suffix);
91     produces <std::vector<float> > ( Prefix + "CaloCompatibility" + Suffix);
92     produces <std::vector<float> > ( Prefix + "IsolationR03sumPt" + Suffix);
93     produces <std::vector<float> > ( Prefix + "IsolationR03emEt" + Suffix);
94     produces <std::vector<float> > ( Prefix + "IsolationR03hadEt" + Suffix);
95    
96     produces <std::vector<float> > ( Prefix + "PfIsolationR03ChgHadPt" + Suffix);
97     produces <std::vector<float> > ( Prefix + "PfIsolationR03ChgParPt" + Suffix);
98     produces <std::vector<float> > ( Prefix + "PfIsolationR03NeuHadEt" + Suffix);
99     produces <std::vector<float> > ( Prefix + "PfIsolationR03GamEt" + Suffix);
100     produces <std::vector<float> > ( Prefix + "PfIsolationR03NeuHadHiThrEt" + Suffix);
101     produces <std::vector<float> > ( Prefix + "PfIsolationR03GamHiThrEt" + Suffix);
102     produces <std::vector<float> > ( Prefix + "PfIsolationR03PUPt" + Suffix);
103     produces <std::vector<float> > ( Prefix + "PfIsolationR03DeltaBCorrected" + Suffix);
104    
105     produces <std::vector<float> > ( Prefix + "PfIsolationR04ChgHadPt" + Suffix);
106     produces <std::vector<float> > ( Prefix + "PfIsolationR04ChgParPt" + Suffix);
107     produces <std::vector<float> > ( Prefix + "PfIsolationR04NeuHadEt" + Suffix);
108     produces <std::vector<float> > ( Prefix + "PfIsolationR04GamEt" + Suffix);
109     produces <std::vector<float> > ( Prefix + "PfIsolationR04NeuHadHiThrEt" + Suffix);
110     produces <std::vector<float> > ( Prefix + "PfIsolationR04GamHiThrEt" + Suffix);
111     produces <std::vector<float> > ( Prefix + "PfIsolationR04PUPt" + Suffix);
112     produces <std::vector<float> > ( Prefix + "PfIsolationR04DeltaBCorrected" + Suffix);
113    
114     produces <std::vector<math::XYZPoint> > ( Prefix + "Vertex" + Suffix);
115     produces <std::vector<double> > ( Prefix + "VertexChi2" + Suffix);
116     produces <std::vector<double> > ( Prefix + "VertexNdof" + Suffix);
117     produces <std::vector<int> > ( Prefix + "IsGlobalMuon" + Suffix);
118     produces <std::vector<int> > ( Prefix + "IsTrackerMuon" + Suffix);
119     produces <std::vector<int> > ( Prefix + "IsPFMuon" + Suffix);
120     produces <std::vector<int> > ( Prefix + "IsStandAloneMuon" + Suffix);
121     produces <std::vector<int> > ( Prefix + "HasOverlap" + Suffix);
122     produces <std::vector<unsigned> > ( Prefix + "NumberOfMatches" + Suffix );
123     produces <std::vector<unsigned> > ( Prefix + "NumberOfMatchedStations" + Suffix );
124     produces <std::vector<double> > ( Prefix + "SigmaPt" + Suffix);
125    
126     //AGB - add EcalVetoDep and HcalVetoDep
127     produces <std::vector<float> > (Prefix + "EcalVetoDep" + Suffix);
128     produces <std::vector<float> > (Prefix + "HcalVetoDep" + Suffix);
129     }
130    
131     // extra information stored for PAT data
132     template< typename T >
133     void Tuple_Muon<T>::initPAT()
134     {
135     produces <std::vector<int> > (Prefix + "IDGlobalMuonPromptTight" + Suffix);
136     produces <std::vector<int> > (Prefix + "TMLastStationAngTight" + Suffix);
137     produces <std::vector<int> > (Prefix + "TMLastStationOptimizedLowPtTight" + Suffix);
138     produces <std::vector<int> > (Prefix + "TMLastStationOptimizedLowPtLoose" + Suffix);
139     produces <std::vector<int> > (Prefix + "TMLastStationOptimizedBarrelLowPtTight" + Suffix);
140     produces <std::vector<int> > (Prefix + "TMLastStationOptimizedBarrelLowPtLoose" + Suffix);
141     produces <std::vector<float> > (Prefix + "EcalIso" + Suffix);
142     produces <std::vector<float> > (Prefix + "HcalIso" + Suffix);
143     produces <std::vector<float> > (Prefix + "TrackIso" + Suffix);
144    
145     produces <std::vector<int> > (Prefix + "TrackerMuonArbitrated" + Suffix);
146     produces <std::vector<int> > (Prefix + "AllArbitrated" + Suffix);
147     produces <std::vector<int> > (Prefix + "TMLastStationLoose" + Suffix);
148     produces <std::vector<int> > (Prefix + "TMLastStationTight" + Suffix);
149     produces <std::vector<int> > (Prefix + "TM2DCompatibilityLoose" + Suffix);
150     produces <std::vector<int> > (Prefix + "TM2DCompatibilityTight" + Suffix);
151     produces <std::vector<int> > (Prefix + "TMOneStationLoose" + Suffix);
152     produces <std::vector<int> > (Prefix + "TMOneStationTight" + Suffix);
153     produces <std::vector<int> > (Prefix + "GMTkChiCompatibility" + Suffix);
154     produces <std::vector<int> > (Prefix + "GMStaChiCompatibility" + Suffix);
155     produces <std::vector<int> > (Prefix + "GMTkKinkTight" + Suffix);
156     produces <std::vector<int> > (Prefix + "TMLastStationAngLoose" + Suffix);
157     produces <std::vector<int> > (Prefix + "TMOneStationAngLoose" + Suffix);
158     produces <std::vector<int> > (Prefix + "TMOneStationAngTight" + Suffix);
159    
160    
161     //pf muons - AGB 18/12/09
162     produces <std::vector<int> > (Prefix + "ProducedFromPF" + Suffix);
163     produces <std::vector<float> > (Prefix + "ParticleIso" + Suffix);
164     produces <std::vector<float> > (Prefix + "ChargedHadronIso" + Suffix);
165     produces <std::vector<float> > (Prefix + "NeutralHadronIso" + Suffix);
166     produces <std::vector<float> > (Prefix + "PhotonIso" + Suffix);
167    
168     }
169    
170    
171     template< typename T >
172     void Tuple_Muon<T>::
173     produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
174     edm::Handle<std::vector<T> > collection;
175     iEvent.getByLabel(inputTag,collection);
176    
177     produceTemplate(iEvent, iSetup, collection);
178     }
179    
180    
181     template< typename T >
182     void Tuple_Muon<T>::
183     produceRECO(edm::Event& iEvent, const edm::EventSetup& iSetup, edm::Handle<std::vector<T> >& collection) {
184     std::auto_ptr<bool> isHandleValid ( new bool(collection.isValid()) );
185     std::auto_ptr<std::vector<LorentzVector> > p4 ( new std::vector<LorentzVector>() );
186     std::auto_ptr<std::vector<LorentzVector> > innerTrackP4 ( new std::vector<LorentzVector>() );
187     std::auto_ptr<std::vector<LorentzVector> > globalTrackP4 ( new std::vector<LorentzVector>() );
188     std::auto_ptr<std::vector<LorentzVector> > outerTrackP4 ( new std::vector<LorentzVector>() );
189     std::auto_ptr<std::vector<int> > charge ( new std::vector<int>() ) ;
190     std::auto_ptr<std::vector<int> > selected ( new std::vector<int>() ) ;
191     std::auto_ptr<std::vector<double> > globalTrack_normalizedChi2 ( new std::vector<double>() ) ;
192     std::auto_ptr<std::vector<unsigned> > globalTrack_numberOfValidHits ( new std::vector<unsigned>() ) ;
193     std::auto_ptr<std::vector<unsigned> > globalTrack_numberOfValidTrackerHits ( new std::vector<unsigned>() ) ;
194     std::auto_ptr<std::vector<unsigned> > globalTrack_numberOfValidMuonHits ( new std::vector<unsigned>() ) ;
195     std::auto_ptr<std::vector<double> > globalTrack_dxy ( new std::vector<double>() ) ;
196     std::auto_ptr<std::vector<double> > globalTrack_dz ( new std::vector<double>() ) ;
197     std::auto_ptr<std::vector<double> > globalTrack_dxyBS ( new std::vector<double>() ) ;
198     std::auto_ptr<std::vector<double> > globalTrack_dzBS ( new std::vector<double>() ) ;
199     std::auto_ptr<std::vector<double> > globalTrack_dxyError ( new std::vector<double>() ) ;
200     std::auto_ptr<std::vector<double> > globalTrack_dzError ( new std::vector<double>() ) ;
201     std::auto_ptr<std::vector<double> > innerTrack_normalizedChi2 ( new std::vector<double>() ) ;
202     std::auto_ptr<std::vector<unsigned> > innerTrack_numberOfValidHits ( new std::vector<unsigned>() ) ;
203     std::auto_ptr<std::vector<unsigned> > pixel_numberOfValidHits ( new std::vector<unsigned>() ) ;
204     std::auto_ptr<std::vector<unsigned> > pixel_LayersWithMeasurement ( new std::vector<unsigned>() ) ;
205     std::auto_ptr<std::vector<unsigned> > tracker_LayersWithMeasurement ( new std::vector<unsigned>() ) ;
206     std::auto_ptr<std::vector<double> > innerTrack_dxy ( new std::vector<double>() ) ;
207     std::auto_ptr<std::vector<double> > innerTrack_dxyBS ( new std::vector<double>() ) ;
208     std::auto_ptr<std::vector<double> > innerTrack_dxyError ( new std::vector<double>() ) ;
209     std::auto_ptr<std::vector<double> > innerTrack_dz ( new std::vector<double>() ) ;
210     std::auto_ptr<std::vector<double> > innerTrack_vertexz ( new std::vector<double>() ) ;
211     std::auto_ptr<std::vector<double> > innerTrack_dzBS ( new std::vector<double>() ) ;
212     std::auto_ptr<std::vector<double> > innerTrack_dzError ( new std::vector<double>() ) ;
213     std::auto_ptr<std::vector<double> > outerTrack_normalizedChi2 ( new std::vector<double>() ) ;
214     std::auto_ptr<std::vector<unsigned> > outerTrack_numberOfValidHits ( new std::vector<unsigned>() ) ;
215     std::auto_ptr<std::vector<float> > caloCompatibility ( new std::vector<float>() ) ;
216     std::auto_ptr<std::vector<float> > isolationR03sumPt ( new std::vector<float>() ) ;
217     std::auto_ptr<std::vector<float> > isolationR03emEt ( new std::vector<float>() ) ;
218     std::auto_ptr<std::vector<float> > isolationR03hadEt ( new std::vector<float>() ) ;
219    
220     std::auto_ptr<std::vector<float> > pfIsolationR03ChgHadPt ( new std::vector<float>() ) ;
221     std::auto_ptr<std::vector<float> > pfIsolationR03ChgParPt ( new std::vector<float>() ) ;
222     std::auto_ptr<std::vector<float> > pfIsolationR03NeuHadEt ( new std::vector<float>() ) ;
223     std::auto_ptr<std::vector<float> > pfIsolationR03GamEt ( new std::vector<float>() ) ;
224     std::auto_ptr<std::vector<float> > pfIsolationR03NeuHadHiThrEt ( new std::vector<float>() ) ;
225     std::auto_ptr<std::vector<float> > pfIsolationR03GamHiThrEt ( new std::vector<float>() ) ;
226     std::auto_ptr<std::vector<float> > pfIsolationR03PUPt ( new std::vector<float>() ) ;
227     std::auto_ptr<std::vector<float> > pfIsolationR03DeltaB ( new std::vector<float>() ) ;
228    
229     std::auto_ptr<std::vector<float> > pfIsolationR04ChgHadPt ( new std::vector<float>() ) ;
230     std::auto_ptr<std::vector<float> > pfIsolationR04ChgParPt ( new std::vector<float>() ) ;
231     std::auto_ptr<std::vector<float> > pfIsolationR04NeuHadEt ( new std::vector<float>() ) ;
232     std::auto_ptr<std::vector<float> > pfIsolationR04GamEt ( new std::vector<float>() ) ;
233     std::auto_ptr<std::vector<float> > pfIsolationR04NeuHadHiThrEt ( new std::vector<float>() ) ;
234     std::auto_ptr<std::vector<float> > pfIsolationR04GamHiThrEt ( new std::vector<float>() ) ;
235     std::auto_ptr<std::vector<float> > pfIsolationR04PUPt ( new std::vector<float>() ) ;
236     std::auto_ptr<std::vector<float> > pfIsolationR04DeltaB ( new std::vector<float>() ) ;
237    
238     std::auto_ptr<std::vector<math::XYZPoint> > vertex ( new std::vector<math::XYZPoint>() ) ;
239     std::auto_ptr<std::vector<double> > vertexChi2 ( new std::vector<double>() ) ;
240     std::auto_ptr<std::vector<double> > vertexNdof ( new std::vector<double>() ) ;
241     std::auto_ptr<std::vector<int> > isGlobalMuon ( new std::vector<int>() ) ;
242     std::auto_ptr<std::vector<int> > isTrackerMuon ( new std::vector<int>() ) ;
243     std::auto_ptr<std::vector<int> > isPFMuon ( new std::vector<int>() ) ;
244     std::auto_ptr<std::vector<int> > isStandAloneMuon ( new std::vector<int>() ) ;
245     std::auto_ptr<std::vector<int> > hasOverlap ( new std::vector<int>() ) ;
246     std::auto_ptr<std::vector<unsigned> > numberOfMatches ( new std::vector<unsigned>() ) ;
247     std::auto_ptr<std::vector<unsigned> > numberOfMatchedStations ( new std::vector<unsigned>() ) ;
248     std::auto_ptr<std::vector<double> > sigmapt ( new std::vector<double>() ) ;
249    
250     std::auto_ptr<std::vector<float> > EcalVetoDep( new std::vector<float>());
251     std::auto_ptr<std::vector<float> > HcalVetoDep( new std::vector<float>());
252    
253     math::XYZPoint bs = math::XYZPoint(0.,0.,0.);
254     math::XYZPoint vx = math::XYZPoint(0.,0.,0.);
255     edm::Handle<reco::BeamSpot> beamspots; iEvent.getByLabel("offlineBeamSpot", beamspots);
256     edm::Handle<reco::VertexCollection> vertices; iEvent.getByLabel("offlinePrimaryVertices", vertices);
257     if (beamspots.isValid()){ bs = beamspots->position();}
258    
259     edm::Handle<std::vector<T> > selectedHandle;
260     iEvent.getByLabel(selectedTag,selectedHandle);
261    
262     if (collection.isValid()) {
263     int indx1 = 0;
264     for(typename std::vector<T>::const_iterator it = collection->begin(); it!=collection->end(); it++) {
265    
266     // check if there is an overlap with other muons //LG
267     bool tmpHasOverlap = false;
268     bool sumHasOverlap = false;
269     int indx2 = 0;
270     for(typename std::vector<T>::const_iterator it2 = collection->begin(); it2!=collection->end(); it2++) {
271     if (indx2==indx1) { continue; }
272     tmpHasOverlap = muon::overlap(*it, *it2, 1.,1., false);
273     sumHasOverlap += tmpHasOverlap;
274     indx2++;
275     }
276     indx1++;
277    
278     p4->push_back(it->p4());
279     charge->push_back(it->charge());
280     selected->push_back(selectedHandle.isValid() && isInCollection(*it, *selectedHandle) ) ;
281     caloCompatibility->push_back(it->caloCompatibility());
282     isolationR03sumPt->push_back(it->isolationR03().sumPt);
283     isolationR03emEt->push_back(it->isolationR03().emEt);
284     isolationR03hadEt->push_back(it->isolationR03().hadEt);
285    
286     {
287    
288     const reco::MuonPFIsolation& pfIso03 = it->pfIsolationR03();
289     float sumChgHadPt03 = pfIso03.sumChargedHadronPt;
290     float sumNeuHadEt03 = pfIso03.sumNeutralHadronEt;
291     float sumGamEt03 = pfIso03.sumPhotonEt;
292     float sumPUPt03 = pfIso03.sumPUPt;
293     float isoDelB03 = (sumChgHadPt03 + std::max(0., (sumNeuHadEt03 + sumGamEt03 - 0.5*sumPUPt03)))/(it->p4()).Pt();
294    
295     pfIsolationR03ChgHadPt->push_back(sumChgHadPt03);
296     pfIsolationR03ChgParPt->push_back(pfIso03.sumChargedParticlePt);
297    
298     pfIsolationR03GamEt->push_back(sumGamEt03);
299     pfIsolationR03GamHiThrEt->push_back(pfIso03.sumPhotonEtHighThreshold);
300    
301     pfIsolationR03NeuHadEt->push_back(sumNeuHadEt03);
302     pfIsolationR03NeuHadHiThrEt->push_back(pfIso03.sumNeutralHadronEtHighThreshold);
303     pfIsolationR03PUPt->push_back(sumPUPt03);
304     pfIsolationR03DeltaB->push_back(isoDelB03);
305    
306     const reco::MuonPFIsolation& pfIso04 = it->pfIsolationR04();
307     float sumChgHadPt = pfIso04.sumChargedHadronPt;
308     float sumNeuHadEt = pfIso04.sumNeutralHadronEt;
309     float sumGamEt = pfIso04.sumPhotonEt;
310     float sumPUPt = pfIso04.sumPUPt;
311     float isoDelB = (sumChgHadPt + std::max(0., (sumNeuHadEt + sumGamEt - 0.5*sumPUPt)))/(it->p4()).Pt();
312    
313     pfIsolationR04ChgHadPt->push_back(sumChgHadPt);
314     pfIsolationR04ChgParPt->push_back(pfIso04.sumChargedParticlePt);
315    
316     pfIsolationR04GamEt->push_back(sumGamEt);
317     pfIsolationR04GamHiThrEt->push_back(pfIso04.sumPhotonEtHighThreshold);
318    
319     pfIsolationR04NeuHadEt->push_back(sumNeuHadEt);
320     pfIsolationR04NeuHadHiThrEt->push_back(pfIso04.sumNeutralHadronEtHighThreshold);
321     pfIsolationR04PUPt->push_back(sumPUPt);
322     pfIsolationR04DeltaB->push_back(isoDelB);
323     }
324    
325     vertex->push_back(it->vertex());
326     vertexChi2->push_back(it->vertexChi2());
327     vertexNdof->push_back(it->vertexNdof());
328     isGlobalMuon->push_back(it->isGlobalMuon());
329     isTrackerMuon->push_back(it->isTrackerMuon());
330     isPFMuon->push_back(it->isPFMuon());
331     isStandAloneMuon->push_back(it->isStandAloneMuon());
332     numberOfMatches->push_back(it->numberOfMatches());
333     numberOfMatchedStations->push_back(it->numberOfMatchedStations());
334     if (sumHasOverlap) { hasOverlap->push_back(1); }
335     else { hasOverlap->push_back(0); }
336    
337     bool global = it->globalTrack().isNonnull();
338     //if(global && vertices.isValid() && vertices->size()) vx = Tuple_functions::closestDzPrimaryVertexPosition(it->globalTrack().get(),*vertices);
339     globalTrack_dxy->push_back( global? it->globalTrack()->dxy(vx) : 999999999.);
340     globalTrack_dz->push_back( global? it->globalTrack()->dz(vx) : 999999999.);
341     globalTrack_dxyBS->push_back( global? it->globalTrack()->dxy(bs) : 999999999.);
342     globalTrack_dzBS->push_back( global? it->globalTrack()->dz(bs) : 999999999.);
343     globalTrack_dxyError->push_back( global? it->globalTrack()->dxyError() : -10000);
344     globalTrack_dzError->push_back( global? it->globalTrack()->dzError() : -10000);
345     globalTrack_normalizedChi2->push_back( global? it->globalTrack()->normalizedChi2() : -1);
346     globalTrack_numberOfValidHits->push_back( global? it->globalTrack()->numberOfValidHits() : 0);
347     globalTrack_numberOfValidTrackerHits->push_back( global? it->globalTrack()->hitPattern().numberOfValidTrackerHits() : 0);
348     globalTrack_numberOfValidMuonHits->push_back( global? it->globalTrack()->hitPattern().numberOfValidMuonHits() : 0);
349     globalTrackP4->push_back( global ? muonP4FromP(it->globalTrack()->momentum()) : LorentzVector() );
350    
351     bool inner = it->innerTrack().isNonnull();
352     //if(inner && vertices.isValid() && vertices->size()) vx = Tuple_functions::closestDzPrimaryVertexPosition(it->innerTrack().get(),*vertices);
353     innerTrack_dxy->push_back( inner? it->innerTrack()->dxy(vx) : 999999999.);
354     innerTrack_dz->push_back( inner? it->innerTrack()->dz(vx) : 999999999.);
355     innerTrack_dxyBS->push_back( inner? it->innerTrack()->dxy(bs) : 999999999.);
356     innerTrack_dzBS->push_back( inner? it->innerTrack()->dz(bs) : 999999999.);
357     innerTrack_vertexz->push_back( inner? it->innerTrack()->vertex().z() : 999999999.);
358     innerTrack_dxyError->push_back( inner? it->innerTrack()->dxyError() : -10000);
359     innerTrack_dzError->push_back( inner? it->innerTrack()->dzError() : -10000);
360     innerTrack_normalizedChi2->push_back( inner? it->innerTrack()->normalizedChi2() : -1);
361     innerTrack_numberOfValidHits->push_back( inner? it->innerTrack()->numberOfValidHits() : 0);
362     pixel_numberOfValidHits->push_back( inner? it->innerTrack()->hitPattern().numberOfValidPixelHits() : 0);
363     pixel_LayersWithMeasurement->push_back( inner? it->innerTrack()->hitPattern().pixelLayersWithMeasurement() : 0 );
364     tracker_LayersWithMeasurement->push_back( inner? it->innerTrack()->hitPattern().trackerLayersWithMeasurement() : 0 );
365     innerTrackP4->push_back( inner ? muonP4FromP(it->innerTrack()->momentum()) : LorentzVector() );
366    
367     bool outer = it->outerTrack().isNonnull();
368     outerTrack_normalizedChi2->push_back( outer? it->outerTrack()->normalizedChi2() : -1);
369     outerTrack_numberOfValidHits->push_back(outer? it->outerTrack()->numberOfValidHits() : 0);
370     outerTrackP4->push_back( outer ? muonP4FromP(it->outerTrack()->momentum()) : LorentzVector() );
371    
372     sigmapt->push_back(global? it->globalTrack()->ptError(): it->pt());
373    
374     EcalVetoDep->push_back(it->isolationR03().emVetoEt);
375     HcalVetoDep->push_back(it->isolationR03().hadVetoEt);
376    
377     }
378     }
379    
380     iEvent.put( isHandleValid, Prefix + "HandleValid" + Suffix );
381     iEvent.put( p4, Prefix + "P4" + Suffix );
382     iEvent.put( innerTrackP4, Prefix + "InnerTrackP4" + Suffix );
383     iEvent.put( globalTrackP4, Prefix + "GlobalTrackP4" + Suffix );
384     iEvent.put( outerTrackP4, Prefix + "OuterTrackP4" + Suffix );
385     iEvent.put( charge, Prefix + "Charge" + Suffix );
386     iEvent.put( selected, Prefix + "Selected" + Suffix );
387     iEvent.put( globalTrack_normalizedChi2, Prefix + "GlobalTracknormalizedChi2" + Suffix );
388     iEvent.put( globalTrack_numberOfValidHits, Prefix + "GlobalTracknumberOfValidHits" + Suffix );
389     iEvent.put( globalTrack_numberOfValidTrackerHits, Prefix + "GlobalTracknumberOfValidTrackerHits" + Suffix );
390     iEvent.put( globalTrack_numberOfValidMuonHits, Prefix + "GlobalTracknumberOfValidMuonHits" + Suffix );
391     iEvent.put( globalTrack_dxy, Prefix + "GlobalTrackDxy" + Suffix );
392     iEvent.put( globalTrack_dz, Prefix + "GlobalTrackDz" + Suffix );
393     iEvent.put( globalTrack_dxyBS, Prefix + "GlobalTrackDxyBS" + Suffix );
394     iEvent.put( globalTrack_dzBS, Prefix + "GlobalTrackDzBS" + Suffix );
395     iEvent.put( globalTrack_dxyError, Prefix + "GlobalTrackDxyError" + Suffix );
396     iEvent.put( globalTrack_dzError, Prefix + "GlobalTrackDzError" + Suffix );
397     iEvent.put( innerTrack_dxy, Prefix + "InnerTrackDxy" + Suffix );
398     iEvent.put( innerTrack_dz, Prefix + "InnerTrackDz" + Suffix );
399     iEvent.put( innerTrack_dxyBS, Prefix + "InnerTrackDxyBS" + Suffix );
400     iEvent.put( innerTrack_dzBS, Prefix + "InnerTrackDzBS" + Suffix );
401     iEvent.put( innerTrack_vertexz, Prefix + "InnerTrackVertexz" + Suffix );
402     iEvent.put( innerTrack_dxyError, Prefix + "InnerTrackDxyError" + Suffix );
403     iEvent.put( innerTrack_dzError, Prefix + "InnerTrackDzError" + Suffix );
404     iEvent.put( innerTrack_normalizedChi2, Prefix + "InnerTrackNormalizedChi2" + Suffix );
405     iEvent.put( innerTrack_numberOfValidHits, Prefix + "InnerTrackNumberOfValidHits" + Suffix );
406     //iEvent.put( LongDistTrackvsPriVer, Prefix + "LongDistTrackvsPriVer" + Suffix ); //NEW
407     iEvent.put( pixel_numberOfValidHits, Prefix + "NumberOfValidPixelHits" + Suffix );
408     iEvent.put( pixel_LayersWithMeasurement, Prefix + "NumberOfPixelLayersWithMeasurement" + Suffix );
409     iEvent.put( tracker_LayersWithMeasurement, Prefix + "NumberOfTrackerLayersWithMeasurement" + Suffix );
410     iEvent.put( outerTrack_normalizedChi2, Prefix + "OuterTrackNormalizedChi2" + Suffix );
411     iEvent.put( outerTrack_numberOfValidHits, Prefix + "OuterTrackNumberOfValidHits" + Suffix );
412     iEvent.put( caloCompatibility, Prefix + "CaloCompatibility" + Suffix );
413     iEvent.put( isolationR03sumPt, Prefix + "IsolationR03sumPt" + Suffix );
414     iEvent.put( isolationR03emEt, Prefix + "IsolationR03emEt" + Suffix );
415     iEvent.put( isolationR03hadEt, Prefix + "IsolationR03hadEt" + Suffix );
416    
417     iEvent.put( pfIsolationR03ChgHadPt, Prefix + "PfIsolationR03ChgHadPt" + Suffix);
418     iEvent.put( pfIsolationR03ChgParPt, Prefix + "PfIsolationR03ChgParPt" + Suffix);
419     iEvent.put( pfIsolationR03NeuHadEt, Prefix + "PfIsolationR03NeuHadEt" + Suffix);
420     iEvent.put( pfIsolationR03GamEt, Prefix + "PfIsolationR03GamEt" + Suffix);
421     iEvent.put( pfIsolationR03NeuHadHiThrEt, Prefix + "PfIsolationR03NeuHadHiThrEt" + Suffix);
422     iEvent.put( pfIsolationR03GamHiThrEt, Prefix + "PfIsolationR03GamHiThrEt" + Suffix);
423     iEvent.put( pfIsolationR03PUPt, Prefix + "PfIsolationR03PUPt" + Suffix);
424     iEvent.put( pfIsolationR03DeltaB, Prefix + "PfIsolationR03DeltaBCorrected" + Suffix);
425    
426     iEvent.put( pfIsolationR04ChgHadPt, Prefix + "PfIsolationR04ChgHadPt" + Suffix);
427     iEvent.put( pfIsolationR04ChgParPt, Prefix + "PfIsolationR04ChgParPt" + Suffix);
428     iEvent.put( pfIsolationR04NeuHadEt, Prefix + "PfIsolationR04NeuHadEt" + Suffix);
429     iEvent.put( pfIsolationR04GamEt, Prefix + "PfIsolationR04GamEt" + Suffix);
430     iEvent.put( pfIsolationR04NeuHadHiThrEt, Prefix + "PfIsolationR04NeuHadHiThrEt" + Suffix);
431     iEvent.put( pfIsolationR04GamHiThrEt, Prefix + "PfIsolationR04GamHiThrEt" + Suffix);
432     iEvent.put( pfIsolationR04PUPt, Prefix + "PfIsolationR04PUPt" + Suffix);
433     iEvent.put( pfIsolationR04DeltaB, Prefix + "PfIsolationR04DeltaBCorrected" + Suffix);
434    
435     iEvent.put( vertex, Prefix + "Vertex" + Suffix );
436     iEvent.put( vertexChi2, Prefix + "VertexChi2" + Suffix );
437     iEvent.put( vertexNdof, Prefix + "VertexNdof" + Suffix );
438     iEvent.put( isGlobalMuon, Prefix + "IsGlobalMuon" + Suffix );
439     iEvent.put( isTrackerMuon, Prefix + "IsTrackerMuon" + Suffix );
440     iEvent.put( isPFMuon, Prefix + "IsPFMuon" + Suffix );
441     iEvent.put( isStandAloneMuon, Prefix + "IsStandAloneMuon" + Suffix );
442     iEvent.put( hasOverlap, Prefix + "HasOverlap" + Suffix );
443     iEvent.put( numberOfMatches, Prefix + "NumberOfMatches" + Suffix );
444     iEvent.put( numberOfMatchedStations, Prefix + "NumberOfMatchedStations" + Suffix );
445     iEvent.put(sigmapt,Prefix + "SigmaPt" + Suffix );
446    
447     iEvent.put(EcalVetoDep, Prefix + "EcalVetoDep" + Suffix);
448     iEvent.put(HcalVetoDep, Prefix + "HcalVetoDep" + Suffix);
449     }
450    
451    
452     // extra information stored for PAT data
453     template< typename T >
454     void Tuple_Muon<T>::
455     producePAT(edm::Event& iEvent, const edm::EventSetup& iSetup, edm::Handle<std::vector<T> >& collection) {
456     std::auto_ptr<std::vector<int> > IDGlobalMuonPromptTight( new std::vector<int>() );
457     std::auto_ptr<std::vector<int> > TMLastStationAngTight( new std::vector<int>() );
458     std::auto_ptr<std::vector<int> > TMLastStationOptimLowPtTight (new std::vector<int>());
459     std::auto_ptr<std::vector<int> > TMLastStationOptimLowPtLoose (new std::vector<int>());
460     std::auto_ptr<std::vector<int> > TMLastStationOptimBarrelLowPtTight (new std::vector<int>());
461     std::auto_ptr<std::vector<int> > TMLastStationOptimBarrelLowPtLoose (new std::vector<int>());
462     std::auto_ptr<std::vector<float> > ecalIso( new std::vector<float>() );
463     std::auto_ptr<std::vector<float> > hcalIso( new std::vector<float>() );
464     std::auto_ptr<std::vector<float> > trackIso( new std::vector<float>() );
465    
466     std::auto_ptr<std::vector<int> > TrackerMuonArbitrated_( new std::vector<int>() );
467     std::auto_ptr<std::vector<int> > AllArbitrated_( new std::vector<int>() );
468     std::auto_ptr<std::vector<int> > TMLastStationLoose_( new std::vector<int>() );
469     std::auto_ptr<std::vector<int> > TMLastStationTight_( new std::vector<int>() );
470     std::auto_ptr<std::vector<int> > TM2DCompatibilityLoose_( new std::vector<int>() );
471     std::auto_ptr<std::vector<int> > TM2DCompatibilityTight_( new std::vector<int>() );
472     std::auto_ptr<std::vector<int> > TMOneStationLoose_( new std::vector<int>() );
473     std::auto_ptr<std::vector<int> > TMOneStationTight_( new std::vector<int>() );
474     std::auto_ptr<std::vector<int> > GMTkChiCompatibility_( new std::vector<int>() );
475     std::auto_ptr<std::vector<int> > GMStaChiCompatibility_( new std::vector<int>() );
476     std::auto_ptr<std::vector<int> > GMTkKinkTight_( new std::vector<int>() );
477     std::auto_ptr<std::vector<int> > TMLastStationAngLoose_( new std::vector<int>() );
478     std::auto_ptr<std::vector<int> > TMOneStationAngLoose_( new std::vector<int>() );
479     std::auto_ptr<std::vector<int> > TMOneStationAngTight_( new std::vector<int>() );
480    
481     std::auto_ptr<std::vector<int> > ispf (new std::vector<int>() );
482     std::auto_ptr<std::vector<float> > partIso (new std::vector<float>() );
483     std::auto_ptr<std::vector<float> > charHadIso (new std::vector<float>() );
484     std::auto_ptr<std::vector<float> > neutHadIso (new std::vector<float>() );
485     std::auto_ptr<std::vector<float> > photIso (new std::vector<float>() );
486    
487     if (collection.isValid()){
488     for(typename std::vector<T>::const_iterator it = collection->begin(); it!=collection->end(); it++) {
489     IDGlobalMuonPromptTight->push_back(it->muonID("GlobalMuonPromptTight"));
490     TMLastStationAngTight->push_back(it->muonID("TMLastStationAngTight"));
491     TMLastStationOptimLowPtTight->push_back(it->muonID("TMLastStationOptimizedLowPtTight"));
492     TMLastStationOptimLowPtLoose->push_back(it->muonID("TMLastStationOptimizedLowPtLoose"));
493     TMLastStationOptimBarrelLowPtTight->push_back(it->muonID("TMLastStationOptimizedBarrelLowPtTight"));
494     TMLastStationOptimBarrelLowPtLoose->push_back(it->muonID("TMLastStationOptimizedBarrelLowPtLoose"));
495    
496     TrackerMuonArbitrated_->push_back(it->muonID("TrackerMuonArbitrated"));
497     AllArbitrated_->push_back(it->muonID("AllArbitrated"));
498     TMLastStationLoose_->push_back(it->muonID("TMLastStationLoose"));
499     TMLastStationTight_->push_back(it->muonID("TMLastStationTight"));
500     TM2DCompatibilityLoose_->push_back(it->muonID("TM2DCompatibilityLoose"));
501     TM2DCompatibilityTight_->push_back(it->muonID("TM2DCompatibilityTight"));
502     TMOneStationLoose_->push_back(it->muonID("TMOneStationLoose"));
503     TMOneStationTight_->push_back(it->muonID("TMOneStationTight"));
504     GMTkChiCompatibility_->push_back(it->muonID("GMTkChiCompatibility"));
505     GMStaChiCompatibility_->push_back(it->muonID("GMStaChiCompatibility"));
506     GMTkKinkTight_->push_back(it->muonID("GMTkKinkTight"));
507     TMLastStationAngLoose_->push_back(it->muonID("TMLastStationAngLoose"));
508     TMOneStationAngLoose_->push_back(it->muonID("TMOneStationAngLoose"));
509     TMOneStationAngTight_->push_back(it->muonID("TMOneStationAngTight"));
510    
511     ecalIso->push_back(it->ecalIso());
512     hcalIso->push_back(it->hcalIso());
513     trackIso->push_back(it->trackIso());
514    
515     ispf->push_back(it->pfCandidateRef().isAvailable());
516     partIso->push_back(it->particleIso());
517     charHadIso->push_back(it->chargedHadronIso());
518     neutHadIso->push_back(it->neutralHadronIso());
519     photIso->push_back(it->photonIso());
520     }
521     }
522    
523     iEvent.put(IDGlobalMuonPromptTight, Prefix + "IDGlobalMuonPromptTight" + Suffix );
524     iEvent.put(TMLastStationAngTight, Prefix + "TMLastStationAngTight" + Suffix);
525     iEvent.put(TMLastStationOptimLowPtTight, Prefix + "TMLastStationOptimizedLowPtTight" + Suffix);
526     iEvent.put(TMLastStationOptimLowPtLoose, Prefix + "TMLastStationOptimizedLowPtLoose" + Suffix);
527     iEvent.put(TMLastStationOptimBarrelLowPtTight, Prefix + "TMLastStationOptimizedBarrelLowPtTight" + Suffix);
528     iEvent.put(TMLastStationOptimBarrelLowPtLoose, Prefix + "TMLastStationOptimizedBarrelLowPtLoose" + Suffix);
529    
530     iEvent.put(TrackerMuonArbitrated_, Prefix + "TrackerMuonArbitrated" + Suffix);
531     iEvent.put(AllArbitrated_, Prefix + "AllArbitrated" + Suffix);
532     iEvent.put(TMLastStationLoose_, Prefix + "TMLastStationLoose" + Suffix);
533     iEvent.put(TMLastStationTight_, Prefix + "TMLastStationTight" + Suffix);
534     iEvent.put(TM2DCompatibilityLoose_, Prefix + "TM2DCompatibilityLoose" + Suffix);
535     iEvent.put(TM2DCompatibilityTight_, Prefix + "TM2DCompatibilityTight" + Suffix);
536     iEvent.put(TMOneStationLoose_, Prefix + "TMOneStationLoose" + Suffix);
537     iEvent.put(TMOneStationTight_, Prefix + "TMOneStationTight" + Suffix);
538     iEvent.put(GMTkChiCompatibility_, Prefix + "GMTkChiCompatibility" + Suffix);
539     iEvent.put(GMStaChiCompatibility_, Prefix + "GMStaChiCompatibility" + Suffix);
540     iEvent.put(GMTkKinkTight_, Prefix + "GMTkKinkTight" + Suffix);
541     iEvent.put(TMLastStationAngLoose_, Prefix + "TMLastStationAngLoose" + Suffix);
542     iEvent.put(TMOneStationAngLoose_, Prefix + "TMOneStationAngLoose" + Suffix);
543     iEvent.put(TMOneStationAngTight_, Prefix + "TMOneStationAngTight" + Suffix);
544    
545    
546     iEvent.put(ecalIso, Prefix + "EcalIso" + Suffix);
547     iEvent.put(hcalIso, Prefix + "HcalIso" + Suffix);
548     iEvent.put(trackIso, Prefix + "TrackIso" + Suffix);
549     iEvent.put(ispf, Prefix + "ProducedFromPF" + Suffix);
550     iEvent.put(partIso, Prefix + "ParticleIso" + Suffix);
551     iEvent.put(charHadIso, Prefix + "ChargedHadronIso" + Suffix);
552     iEvent.put(neutHadIso, Prefix + "NeutralHadronIso" + Suffix);
553     iEvent.put(photIso, Prefix + "PhotonIso" + Suffix);
554     }
555    
556     #endif