ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MPIAnalyzer/src/MPIntuple.cc
Revision: 1.28
Committed: Fri Feb 25 15:25:20 2011 UTC (14 years, 2 months ago) by naodell
Content type: text/plain
Branch: MAIN
Changes since 1.27: +8 -7 lines
Log Message:
Fixed MET and type casting for various variables

File Contents

# User Rev Content
1 naodell 1.1 // Original Author: "Nathaniel Odell"
2     // Secondary Author: Steven Won
3 andrey 1.2 // With contributions from: Andrey Pozdnyakov
4 naodell 1.1 // Created: Thurs April 22 2010
5 naodell 1.28 // $Id: MPIntuple.cc,v 1.27 2011/02/14 11:38:18 naodell Exp $
6 naodell 1.1
7     // system include files
8     #include <memory>
9     #include <string>
10    
11     // user include files
12     #include "FWCore/Framework/interface/Frameworkfwd.h"
13     #include "FWCore/Framework/interface/EDAnalyzer.h"
14     #include "FWCore/Framework/interface/ESHandle.h"
15     #include "FWCore/Framework/interface/EventSetup.h"
16     #include "FWCore/Framework/interface/Event.h"
17     #include "FWCore/Framework/interface/MakerMacros.h"
18 naodell 1.26 #include "FWCore/Framework/interface/LuminosityBlock.h"
19 naodell 1.1 #include "FWCore/ParameterSet/interface/ParameterSet.h"
20 naodell 1.26
21     #include "Geometry/Records/interface/CaloGeometryRecord.h"
22 naodell 1.1 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
23 naodell 1.26 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
24     #include "DataFormats/GeometryVector/interface/LocalPoint.h"
25     #include "DataFormats/GeometryVector/interface/LocalVector.h"
26     #include "DataFormats/Math/interface/Point3D.h"
27     #include "DataFormats/Math/interface/Vector3D.h"
28     #include "DataFormats/Math/interface/LorentzVector.h"
29 naodell 1.10 #include "DataFormats/Math/interface/deltaPhi.h"
30 naodell 1.1
31 naodell 1.15 // Libraries for objects
32 naodell 1.26 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
33     #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
34     #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
35 naodell 1.1 #include "DataFormats/JetReco/interface/CaloJet.h"
36     #include "DataFormats/JetReco/interface/CaloJetCollection.h"
37 naodell 1.26 #include "DataFormats/JetReco/interface/GenJet.h"
38     #include "DataFormats/JetReco/interface/GenJetCollection.h"
39 naodell 1.1 #include "DataFormats/JetReco/interface/PFJet.h"
40     #include "DataFormats/JetReco/interface/PFJetCollection.h"
41 naodell 1.27 #include "DataFormats/METReco/interface/PFMET.h"
42     #include "DataFormats/METReco/interface/PFMETCollection.h"
43     #include "DataFormats/METReco/interface/PFMETFwd.h"
44     #include "DataFormats/METReco/interface/MET.h"
45     #include "DataFormats/METReco/interface/METCollection.h"
46     #include "DataFormats/METReco/interface/METFwd.h"
47 naodell 1.26 #include "DataFormats/MuonReco/interface/Muon.h"
48     #include "DataFormats/MuonReco/interface/MuonFwd.h"
49     #include "DataFormats/MuonReco/interface/MuonSelectors.h"
50     #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
51     #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
52     #include "DataFormats/EgammaCandidates/interface/Photon.h"
53     #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
54     #include "DataFormats/TrackReco/interface/Track.h"
55     #include "DataFormats/TrackReco/interface/TrackFwd.h"
56     #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
57 naodell 1.1 #include "DataFormats/VertexReco/interface/Vertex.h"
58     #include "DataFormats/VertexReco/interface/VertexFwd.h"
59 naodell 1.7 #include "DataFormats/BTauReco/interface/JetTag.h"
60 naodell 1.16 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
61 naodell 1.26 #include "DataFormats/Luminosity/interface/LumiSummary.h"
62     #include "DataFormats/Common/interface/ValueMap.h"
63 naodell 1.18 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
64 naodell 1.24 #include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
65 naodell 1.26 #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
66 naodell 1.18
67 devildog 1.11 //#include "RecoVertex/PrimaryVertexProducer/interface/VertexHigherPtSquared.h"
68 naodell 1.7
69 naodell 1.26 // Need to get corrections
70 naodell 1.4 #include "JetMETCorrections/Objects/interface/JetCorrector.h"
71    
72     // ntuple storage classes
73     #include "TCJet.h"
74 naodell 1.27 #include "TCMET.h"
75 naodell 1.4 #include "TCPrimaryVtx.h"
76 naodell 1.25 #include "TCGenJet.h"
77 naodell 1.26 #include "TCMuon.h"
78     #include "TCElectron.h"
79 naodell 1.4
80 andrey 1.2 // Need for HLT trigger info:
81     #include "FWCore/Common/interface/TriggerNames.h"
82     #include "DataFormats/Common/interface/TriggerResults.h"
83     #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
84    
85 naodell 1.4 //Root stuff
86 naodell 1.1 #include "TROOT.h"
87 naodell 1.15 #include "TH1.h"
88 naodell 1.16 #include "TH2.h"
89 naodell 1.15 #include "TProfile.h"
90 naodell 1.1 #include "TFile.h"
91     #include "TTree.h"
92     #include "TString.h"
93     #include "TObject.h"
94     #include "TObjArray.h"
95     #include "TClonesArray.h"
96     #include "TRefArray.h"
97     #include "TLorentzVector.h"
98     #include "TVector3.h"
99    
100     using namespace edm;
101     using namespace std;
102     using namespace reco;
103    
104     //
105     // class declaration
106     //
107    
108     class MPIntuple : public edm::EDAnalyzer {
109     public:
110     explicit MPIntuple(const edm::ParameterSet&);
111     ~MPIntuple();
112    
113    
114     private:
115     virtual void beginJob() ;
116 naodell 1.26 virtual void beginRun(const edm::Run&, const edm::EventSetup&) ;
117 naodell 1.1 virtual void analyze(const edm::Event&, const edm::EventSetup&);
118 naodell 1.26 virtual void endLuminosityBlock(const edm::LuminosityBlock&,const edm::EventSetup&);
119     virtual void endRun(const edm::Run&, const edm::EventSetup&);
120 naodell 1.1 virtual void endJob() ;
121    
122 naodell 1.26 bool triggerDecision(edm::Handle<edm::TriggerResults>& hltR, int iTrigger);
123 naodell 1.27 float sumPtSquared(const Vertex& v);
124 andrey 1.2
125 naodell 1.1 // ----------member data ---------------------------
126    
127    
128 naodell 1.26 int eventNumber, runNumber, lumiSection, bunchCross;
129 naodell 1.27 float ptHat, qScale, crossSection;
130     float lumiDeadCount, lumiLiveFrac, intDelLumi;
131 naodell 1.18
132 naodell 1.26 TTree* sTree;
133     TFile* ntupleFile;
134     edm::InputTag recoJetTag_;
135 naodell 1.27 edm::InputTag recoMETTag_;
136 naodell 1.26 edm::InputTag genJetTag_;
137     edm::InputTag muonTag_;
138     edm::InputTag electronTag_;
139     edm::InputTag primaryVtxTag_;
140     edm::InputTag triggerResultsTag_;
141     edm::InputTag electronIDMap_;
142     bool doGenJets_;
143     bool doPFJets_;
144     bool triggerHLT_;
145     bool isRealData;
146     string rootfilename;
147    
148     TClonesArray* recoJets;
149 naodell 1.27 TClonesArray* recoMET;
150 naodell 1.26 TClonesArray* genJets;
151     TClonesArray* primaryVtx;
152     TClonesArray* recoMuons;
153     TClonesArray* recoElectrons;
154    
155     //Triggers
156     string hlTriggerResults_, hltProcess_, triggerName_;
157     TriggerNames triggerNames;
158     HLTConfigProvider hltConfig_;
159     vector<string> hlNames;
160 naodell 1.27 vector<string> mpiTriggers_;
161 naodell 1.26 unsigned int triggerStatus;
162 naodell 1.27 unsigned int hltPrescale[32];
163    
164 naodell 1.26
165     //Histograms
166 naodell 1.27 TH1D * h1_ptHat;
167 naodell 1.26 TH1D * h1_fracAssociatedTracks;
168     TH1D * h1_meanJetTrackZ;
169     TH1D * h1_trackDxy;
170     TH1D * h1_jetVertexZ;
171     TH1D * h1_associatedSumPt;
172     TH1D * h1_associatedVertexIndex;
173     TH2F * h2_nAssTracksVsJetPt;
174     TProfile * p1_nVtcs;
175 naodell 1.1 };
176    
177 naodell 1.18 MPIntuple::MPIntuple(const edm::ParameterSet& iConfig)
178 naodell 1.1 {
179 naodell 1.26 recoJetTag_ = iConfig.getUntrackedParameter<edm::InputTag>("RecoJetTag");
180 naodell 1.27 recoMETTag_ = iConfig.getUntrackedParameter<edm::InputTag>("RecoMETTag");
181 naodell 1.26 muonTag_ = iConfig.getUntrackedParameter<edm::InputTag>("MuonTag");
182     electronTag_ = iConfig.getUntrackedParameter<edm::InputTag>("ElectronTag");
183     genJetTag_ = iConfig.getUntrackedParameter<edm::InputTag>("GenJetTag");
184     primaryVtxTag_ = iConfig.getUntrackedParameter<edm::InputTag>("PrimaryVtxTag");
185     electronIDMap_ = iConfig.getParameter<edm::InputTag>("electronIDMap");
186     doGenJets_ = iConfig.getUntrackedParameter<bool>("doGenJets");
187     doPFJets_ = iConfig.getUntrackedParameter<bool>("doPFJets");
188     triggerHLT_ = iConfig.getUntrackedParameter<bool>("triggerHLT");
189 naodell 1.18 hlTriggerResults_ = iConfig.getUntrackedParameter<string>("HLTriggerResults","TriggerResults");
190 naodell 1.27 hltProcess_ = iConfig.getUntrackedParameter<string>("hltName");
191     mpiTriggers_ = iConfig.getUntrackedParameter<vector<string> >("triggers");
192 naodell 1.26 rootfilename = iConfig.getUntrackedParameter<string>("rootfilename");
193 naodell 1.1 }
194    
195     MPIntuple::~MPIntuple()
196     {
197    
198     }
199    
200     //
201     // member functions
202     //
203    
204     // ------------ method called to for each event ------------
205     void MPIntuple::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
206     {
207    
208 naodell 1.6 eventNumber = iEvent.id().event();
209     runNumber = iEvent.id().run();
210 naodell 1.1 lumiSection = (unsigned int)iEvent.getLuminosityBlock().luminosityBlock();
211 naodell 1.8 bunchCross = (unsigned int)iEvent.bunchCrossing();
212     isRealData = iEvent.isRealData();
213    
214 naodell 1.16 edm::Handle<reco::BeamSpot> beamSpotHandle;
215     iEvent.getByLabel("offlineBeamSpot", beamSpotHandle);
216     reco::BeamSpot vertexBeamSpot = *beamSpotHandle;
217    
218     int pfCount = 0;
219     int genCount = 0;
220     int vtxCount = 0;
221 naodell 1.27 float primaryVertexZ = -999;
222 naodell 1.16
223     //////////////////////////
224     //Get vertex information//
225     //////////////////////////
226    
227     Handle<reco::VertexCollection> primaryVtcs;
228 naodell 1.26 iEvent.getByLabel(primaryVtxTag_, primaryVtcs);
229 naodell 1.16
230     for(VertexCollection::const_iterator vtx_iter = primaryVtcs->begin(); vtx_iter!= primaryVtcs->end(); ++vtx_iter){
231     reco::Vertex myVtx = reco::Vertex(*vtx_iter);
232     if(!myVtx.isValid() || myVtx.isFake()) continue;
233     TCPrimaryVtx* vtxCon = new ((*primaryVtx)[vtxCount]) TCPrimaryVtx;
234     vtxCon->SetPosition(myVtx.x(), myVtx.y(), myVtx.z());
235     vtxCon->SetNDof(myVtx.ndof());
236     vtxCon->SetChi2(myVtx.chi2());
237     vtxCon->SetNTrks(myVtx.tracksSize());
238     vtxCon->SetSumPt2Trks(sumPtSquared(myVtx));
239     if(vtxCount == 0) primaryVertexZ = myVtx.z();
240     ++vtxCount;
241     }
242    
243     p1_nVtcs->Fill(runNumber, vtxCount);
244    
245     ///////////////////////
246     //get jet information//
247     ///////////////////////
248 naodell 1.1
249     if(doPFJets_){
250 naodell 1.4
251 naodell 1.7 edm::Handle<reco::JetTagCollection> bTagHandle1;
252     iEvent.getByLabel("trackCountingHighEffBJetTags", bTagHandle1);
253     const reco::JetTagCollection & bTags1 = *(bTagHandle1.product());
254     reco::JetTagCollection::const_iterator jet_it_1;
255    
256     edm::Handle<reco::JetTagCollection> bTagHandle2;
257     iEvent.getByLabel("trackCountingHighPurBJetTags", bTagHandle2);
258     const reco::JetTagCollection & bTags2 = *(bTagHandle2.product());
259     reco::JetTagCollection::const_iterator jet_it_2;
260    
261 naodell 1.27 const JetCorrector* correctorL2 = JetCorrector::getJetCorrector("ak5PFL2Relative",iSetup);
262     const JetCorrector* correctorL3 = JetCorrector::getJetCorrector("ak5PFL3Absolute",iSetup);
263     const JetCorrector* correctorRes = JetCorrector::getJetCorrector("ak5PFL2L3Residual", iSetup);
264 naodell 1.4
265 naodell 1.1 Handle<reco::PFJetCollection> PFJets;
266 naodell 1.26 iEvent.getByLabel(recoJetTag_, PFJets);
267 naodell 1.16
268 naodell 1.27 for (PFJetCollection::const_iterator jet_iter = PFJets->begin(); jet_iter!= PFJets->end(); ++jet_iter) {
269 naodell 1.1
270     reco::PFJet myJet = reco::PFJet(*jet_iter);
271 naodell 1.27 if (myJet.pt() > 5) {
272 naodell 1.7
273 naodell 1.27 for (jet_it_1 = bTags1.begin(); jet_it_1 != bTags1.end(); jet_it_1++) {
274     if ((fabs(jet_it_1->first->eta() - myJet.eta()) < .005) && (deltaPhi(jet_it_1->first->phi(),myJet.phi()) < .005)) break;
275 naodell 1.7 }
276    
277 naodell 1.27 for (jet_it_2 = bTags2.begin(); jet_it_2 != bTags2.end(); jet_it_2++) {
278     if ((fabs(jet_it_2->first->eta() - myJet.eta()) < .005) && (deltaPhi(jet_it_2->first->phi(),myJet.phi()) < .005)) break;
279 naodell 1.7 }
280 naodell 1.6
281 naodell 1.26 TCJet* jetCon = new ((*recoJets)[pfCount]) TCJet;
282 naodell 1.6
283     jetCon->SetP4(myJet.px(), myJet.py(), myJet.pz(), myJet.energy());
284 naodell 1.15 jetCon->SetVtx(-999.0, -999.0, -999.0);
285 naodell 1.6 jetCon->SetChHadFrac(myJet.chargedHadronEnergyFraction());
286     jetCon->SetNeuHadFrac(myJet.neutralHadronEnergyFraction());
287     jetCon->SetChEmFrac(myJet.chargedEmEnergyFraction());
288     jetCon->SetNeuEmFrac(myJet.neutralEmEnergyFraction());
289     jetCon->SetNumConstit(myJet.chargedMultiplicity() + myJet.neutralMultiplicity());
290     jetCon->SetNumChPart(myJet.chargedMultiplicity());
291 naodell 1.4
292 naodell 1.7 if(jet_it_2 != bTags2.end()) jetCon->SetBDiscrTrkCountHiPure(jet_it_2->second);
293     if(jet_it_1 != bTags1.end()) jetCon->SetBDiscrTrkCountHiEff(jet_it_1->second);
294    
295 naodell 1.27 float scale2 = correctorL2->correction(myJet);
296 naodell 1.7 myJet.scaleEnergy(scale2);
297 naodell 1.27 float scale3 = correctorL3->correction(myJet);
298 naodell 1.7 myJet.scaleEnergy(scale3);
299     //more corrections?
300    
301 naodell 1.6 jetCon->SetJetCorr(2, scale2);
302     jetCon->SetJetCorr(3, scale3);
303 naodell 1.7
304 naodell 1.27 if (isRealData) {
305     float scaleRes = correctorRes->correction(myJet);
306     myJet.scaleEnergy(scaleRes);
307     jetCon->SetJetCorr(4, scaleRes);
308     }
309    
310 naodell 1.16 /////////////////////////
311     //get associated tracks//
312     /////////////////////////
313 naodell 1.15
314     const reco::TrackRefVector &tracks = myJet.getTrackRefs();
315    
316 naodell 1.24 vector<TVector3> vtxPositionCollection;
317 naodell 1.27 vector<float> associatedTrackSumPt;
318 naodell 1.24 vector<unsigned int> jetTrackAddresses;
319 naodell 1.27 float sumTrackX, sumTrackY, sumTrackZ, sumTrackIP, sumTrackPt;
320 naodell 1.24 int nJetTracks, nVertexTracks, nAssociatedTracks, vertexIndex;
321 naodell 1.23 int vCount = 0;
322 naodell 1.16
323 naodell 1.24 nJetTracks = nVertexTracks = nAssociatedTracks = 0;
324     sumTrackX = sumTrackY = sumTrackZ = sumTrackIP = sumTrackPt = 0;
325 naodell 1.15
326 naodell 1.23 if(myJet.pt() > 10 && fabs(myJet.eta()) < 2.4){
327 naodell 1.17
328 naodell 1.15 for(TrackRefVector::const_iterator iTrack = tracks.begin(); iTrack != tracks.end(); ++iTrack){
329 naodell 1.23 const reco::Track &myJetTrack = **iTrack;
330 naodell 1.20
331 naodell 1.23 sumTrackPt += myJetTrack.pt();
332 naodell 1.24 sumTrackX += myJetTrack.vx();
333     sumTrackY += myJetTrack.vy();
334 naodell 1.23 sumTrackZ += myJetTrack.vz();
335 naodell 1.21 sumTrackIP += myJetTrack.dxy(vertexBeamSpot.position());
336 naodell 1.24 jetTrackAddresses.push_back((unsigned int)&myJetTrack);
337     ++nJetTracks;
338     }
339    
340 naodell 1.26 if (nJetTracks > 0) {
341 naodell 1.24 jetCon->SetVtx(sumTrackX/nJetTracks, sumTrackY/nJetTracks, sumTrackZ/nJetTracks);
342     h1_meanJetTrackZ->Fill(sumTrackZ/nJetTracks);
343     h1_trackDxy->Fill(sumTrackIP/nJetTracks);
344 naodell 1.23 }
345 naodell 1.24 if(jetTrackAddresses.size() > 0){
346 naodell 1.23
347 naodell 1.26 for (VertexCollection::const_iterator vtx_iter = primaryVtcs->begin(); vtx_iter!= primaryVtcs->end(); ++vtx_iter) {
348 naodell 1.24 reco::Vertex myVtx = reco::Vertex(*vtx_iter);
349 naodell 1.23 if(!myVtx.isValid() || myVtx.isFake()) continue;
350 naodell 1.24 TVector3 *iVtxPosition = new TVector3(myVtx.x(), myVtx.y(), myVtx.z());
351     vtxPositionCollection.push_back(*iVtxPosition);
352     associatedTrackSumPt.push_back(0);
353    
354 naodell 1.23 for(Vertex::trackRef_iterator iTrackRef = myVtx.tracks_begin(); iTrackRef != myVtx.tracks_end(); ++iTrackRef){
355 naodell 1.24 const edm::RefToBase<reco::Track> &myTrackRef = *iTrackRef;
356 naodell 1.23 if(myTrackRef.isAvailable()){
357     const reco::Track &myVertexTrack = *myTrackRef.get();
358    
359 naodell 1.24 for(vector<unsigned int>::const_iterator iTrackAddress = jetTrackAddresses.begin(); iTrackAddress != jetTrackAddresses.end(); ++iTrackAddress){
360 naodell 1.26 if (*iTrackAddress == (unsigned int)&myVertexTrack) {
361 naodell 1.24 associatedTrackSumPt.at(vCount) += myVertexTrack.pt()/sumTrackPt;
362     ++nAssociatedTracks;
363     }
364     }
365 naodell 1.23 }
366 naodell 1.24 }
367     ++vCount;
368     }
369    
370 naodell 1.27 float maxSumPtFraction = 0;
371 naodell 1.24 vCount = vertexIndex = 0;
372    
373 naodell 1.27 for (vector<float>::const_iterator iTrackSumPt = associatedTrackSumPt.begin(); iTrackSumPt != associatedTrackSumPt.end(); ++iTrackSumPt) {
374 naodell 1.26 if (*iTrackSumPt > maxSumPtFraction) {
375 naodell 1.24 maxSumPtFraction = *iTrackSumPt;
376     vertexIndex = vCount + 1;
377     }
378     ++vCount;
379     }
380 naodell 1.26 if (vertexIndex > 0) {
381 naodell 1.24 h1_jetVertexZ->Fill(vtxPositionCollection[vertexIndex-1].z());
382     }
383 naodell 1.27
384     jetCon->SetVtxSumPtFrac(maxSumPtFraction);
385     jetCon->SetVtxSumPt(sumTrackPt);
386     jetCon->SetVtxTrackFrac((float)nAssociatedTracks/(float)nJetTracks);
387     jetCon->SetVtxNTracks(nJetTracks);
388 naodell 1.24 jetCon->SetVtxIndex(vertexIndex);
389 naodell 1.23 }
390 naodell 1.24 }
391 naodell 1.16 ++pfCount;
392 naodell 1.4 }
393     }
394 naodell 1.1 }
395 naodell 1.26
396    
397 naodell 1.27 //////////////////
398     // Get MET info //
399     //////////////////
400    
401    
402     Handle<PFMETCollection> MET;
403     iEvent.getByLabel(recoMETTag_, MET);
404    
405     int metCount = 0;
406     for (PFMETCollection::const_iterator iMET = MET->begin(); iMET != MET->end(); ++iMET) {
407     TCMET* metCon = new ((*recoMET)[metCount]) TCMET;
408     metCon->SetSumEt(iMET->sumEt());
409     metCon->SetMet(iMET->et());
410     metCon->SetPhi(iMET->phi());
411     metCon->SetPhotonEtFraction(iMET->photonEtFraction());
412     metCon->SetElectronEtFraction(iMET->electronEtFraction());
413     metCon->SetMuonEtFraction(iMET->muonEtFraction());
414     metCon->SetNeutralHadronEtFraction(iMET->neutralHadronEtFraction());
415     metCon->SetChargedHadronEtFraction(iMET->chargedHadronEtFraction());
416     metCon->SetHFHadronEtFraction(iMET->HFHadronEtFraction());
417     metCon->SetHFEMEtFraction(iMET->HFEMEtFraction());
418     }
419    
420 naodell 1.26 ///////////////////
421     // Get muon info //
422     ///////////////////
423    
424    
425     Handle<MuonCollection> muons;
426 naodell 1.27 iEvent.getByLabel(muonTag_, muons);
427 naodell 1.26
428     int muCount = 0;
429     for (MuonCollection::const_iterator mu = muons->begin(); mu != muons->end(); ++mu) {
430     if (mu->isGlobalMuon() && mu->pt() > 8){
431     TCMuon* lepCon = new ((*recoMuons)[muCount]) TCMuon;
432     lepCon->Setp4(mu->px(), mu->py(), mu->pz(), mu->p());
433     lepCon->SetVtx(mu->globalTrack()->vx(),mu->globalTrack()->vy(),mu->globalTrack()->vz());
434     lepCon->SetEta(mu->eta());
435     lepCon->SetPhi(mu->phi());
436     lepCon->SetCharge(mu->charge());
437     lepCon->SetisGLB(mu->isGlobalMuon());
438     lepCon->SetisTRK(mu->isTrackerMuon());
439     lepCon->Setdxy(mu->globalTrack()->dxy(vertexBeamSpot.position()));
440     lepCon->SetnPXLHits(mu->globalTrack()->hitPattern().numberOfValidPixelHits());
441     lepCon->SetnTRKHits(mu->globalTrack()->hitPattern().numberOfValidTrackerHits());
442     lepCon->SetnValidMuHits(mu->globalTrack()->hitPattern().numberOfValidMuonHits());
443     lepCon->SetnMatchSeg(mu->numberOfMatches());
444     lepCon->SetNormChi2(mu->globalTrack()->normalizedChi2());
445     lepCon->SetCaloComp(mu->caloCompatibility());
446     lepCon->SetSegComp(muon::segmentCompatibility(*mu));
447     lepCon->SetEMIso(mu->isolationR03().emEt);
448     lepCon->SetHADIso(mu->isolationR03().hadEt);
449     lepCon->SetTRKIso(mu->isolationR03().sumPt);
450     muCount++;
451     }
452     }
453    
454 naodell 1.1
455 naodell 1.26 ///////////////////////
456     // Get electron info //
457     ///////////////////////
458    
459    
460     Handle<edm::ValueMap<float> > eIDValueMap;
461     iEvent.getByLabel( electronIDMap_ , eIDValueMap );
462     const edm::ValueMap<float> & eIDmap = * eIDValueMap ;
463    
464     Handle<GsfElectronCollection> electrons;
465 naodell 1.27 iEvent.getByLabel(electronTag_, electrons);
466 naodell 1.26
467     int elCount = 0;
468     for (unsigned int i = 0; i < electrons->size(); i++){
469     edm::Ref<reco::GsfElectronCollection> electronRef(electrons,i);
470     if ( eIDmap[electronRef] == 7 && electronRef->pt() > 15){
471     TCElectron* lepCon = new ((*recoElectrons)[elCount]) TCElectron;
472     lepCon->Setp4(electronRef->px(),electronRef->py(),electronRef->pz(),electronRef->p());
473     lepCon->SetVtx(electronRef->gsfTrack()->vx(),electronRef->gsfTrack()->vy(),electronRef->gsfTrack()->vz());
474     lepCon->SetCharge(electronRef->charge());
475     lepCon->SetEta(electronRef->eta());
476     lepCon->SetPhi(electronRef->phi());
477     lepCon->Setdxy(electronRef->gsfTrack()->dxy(vertexBeamSpot.position()));
478     lepCon->SetNormChi2(electronRef->gsfTrack()->normalizedChi2());
479     lepCon->SetEMIso(electronRef->dr03EcalRecHitSumEt());
480     lepCon->SetHADIso(electronRef->dr03HcalTowerSumEt());
481     lepCon->SetTRKIso(electronRef->dr03TkSumPt());
482     elCount++;
483     }
484     }
485    
486    
487     ////////////////////////
488     // Get gen-level info //
489     ////////////////////////
490 naodell 1.27
491 naodell 1.26
492     if (!isRealData) {
493 naodell 1.1
494 naodell 1.24 Handle<GenEventInfoProduct> GenEventInfoHandle;
495     iEvent.getByLabel("generator", GenEventInfoHandle);
496     Handle<GenRunInfoProduct> GenRunInfoHandle;
497     iEvent.getByLabel("generator", GenRunInfoHandle);
498 naodell 1.1 Handle<reco::GenJetCollection> GenJets;
499 naodell 1.26 iEvent.getByLabel(genJetTag_, GenJets);
500 naodell 1.18
501 naodell 1.24 ptHat = qScale = -1; crossSection = 0;
502 naodell 1.18
503 naodell 1.26 if (GenEventInfoHandle.isValid()) {
504 naodell 1.24 qScale = GenEventInfoHandle->qScale();
505     ptHat = (GenEventInfoHandle->hasBinningValues() ? GenEventInfoHandle->binningValues()[0] : 0.0);
506 naodell 1.27 h1_ptHat->Fill(ptHat);
507 naodell 1.24 }
508 naodell 1.26 if (GenRunInfoHandle.isValid()) {
509 naodell 1.24 crossSection = GenRunInfoHandle->crossSection();
510 naodell 1.18 }
511 naodell 1.16
512 naodell 1.26 for (GenJetCollection::const_iterator jet_iter = GenJets->begin(); jet_iter!= GenJets->end(); ++jet_iter) {
513     reco::GenJet myJet = reco::GenJet(*jet_iter);
514     if (myJet.pt() > 5) {
515 naodell 1.25
516 naodell 1.26 TCGenJet* jetCon = new ((*genJets)[genCount]) TCGenJet;
517 naodell 1.25 jetCon->SetP4(myJet.px(), myJet.py(), myJet.pz(), myJet.energy());
518     jetCon->SetHadEnergy(myJet.hadEnergy());
519     jetCon->SetEmEnergy(myJet.emEnergy());
520     jetCon->SetInvEnergy(myJet.invisibleEnergy());
521     jetCon->SetAuxEnergy(myJet.auxiliaryEnergy());
522     jetCon->SetNumConstit(myJet.getGenConstituents().size());
523 naodell 1.24
524 naodell 1.26 /*const reco::GenParticle *myGenParticle = myJet.getGenConstituent(0);
525 naodell 1.24
526 naodell 1.26 if(myGenParticle->numberOfMothers() == 1)
527 naodell 1.24 {
528 naodell 1.26 const reco::Candidate *myMother = myGenParticle->mother();
529     int nGrandMas = myMother->numberOfMothers();
530    
531     for(int iter = 0; nGrandMas != 0 ; ++iter)
532     {
533     myMother = myMother->mother();
534     nGrandMas = myMother->mother()->numberOfMothers();
535     //cout<<myMother->pdgId()<<endl;
536     }
537     //if(nGrandMas == 0) jetCon->SetJetFlavor((int)myMother->pdgId()); else jetCon->SetJetFlavor(0);
538     }*/
539     ++genCount;
540 naodell 1.1 }
541 naodell 1.13 }
542 naodell 1.1 }
543 naodell 1.10
544 naodell 1.16 ///////////////////////////
545     //get trigger information//
546     ///////////////////////////
547 andrey 1.2
548 naodell 1.26 if (triggerHLT_) {
549 andrey 1.2
550 naodell 1.7 edm::Handle<TriggerResults> hltR;
551 naodell 1.26 triggerResultsTag_ = InputTag(hlTriggerResults_,"",hltProcess_);
552 naodell 1.7 iEvent.getByLabel(triggerResultsTag_,hltR);
553 naodell 1.26
554 naodell 1.7 const TriggerNames & triggerNames = iEvent.triggerNames(*hltR);
555 naodell 1.26 hlNames=triggerNames.triggerNames();
556    
557     triggerStatus = 0x0;
558 naodell 1.27 //int nTriggers = sizeof(mpiTriggers_) / sizeof(int);
559    
560     for(int i = 0; i < (int)mpiTriggers_.size(); ++i) hltPrescale[i] = hltConfig_.prescaleValue(iEvent, iSetup, mpiTriggers_[i]);
561    
562 naodell 1.26 for (int i=0; i < (int)hlNames.size(); ++i) {
563 naodell 1.27 if (triggerDecision(hltR, i)) {
564     for (int j = 0; j < (int)mpiTriggers_.size(); ++j){
565     if (hlNames[i] == mpiTriggers_[j]) {
566 naodell 1.24 triggerStatus |= 0x01 << j;
567 naodell 1.27 hltPrescale[j] = hltConfig_.prescaleValue(iEvent, iSetup, mpiTriggers_[j]);
568 naodell 1.24 }
569 naodell 1.7 }
570 naodell 1.4 }
571 naodell 1.7 }
572     }
573 naodell 1.27
574 naodell 1.24 if((pfCount > 1 || genCount > 1) && vtxCount > 0) sTree -> Fill();
575 naodell 1.15
576 naodell 1.26 recoJets->Clear();
577 naodell 1.27 recoMET->Clear();
578 naodell 1.26 recoElectrons->Clear();
579     recoMuons->Clear();
580 naodell 1.5 primaryVtx->Clear();
581 naodell 1.26 genJets->Clear();
582 naodell 1.1 }
583    
584     // ------------ method called once each job just before starting event loop ------------
585     void MPIntuple::beginJob()
586 naodell 1.26 {
587 naodell 1.24 ntupleFile = new TFile(rootfilename.c_str(), "RECREATE");
588     sTree = new TTree("mpiTree", "Tree for Jets");
589 naodell 1.15
590 naodell 1.27 h1_ptHat = new TH1D("h1_ptHat", "ptHat", 15, 10.0, 160.0);
591 naodell 1.24 h1_fracAssociatedTracks = new TH1D("h1_fracAssociatedTracks", "Fraction of associated jet tracks", 20, 0.0, 1.0);
592     h1_trackDxy = new TH1D("h1_trackDxy", "dxy for all associated tracks", 50, -0.4, 0.4);
593     h1_meanJetTrackZ = new TH1D("h1_meanJetTrackZ", "<z> from jet tracks", 50, -25.0, 25.0);
594     h1_jetVertexZ = new TH1D("h1_jetVertexZ", "z for vertex associated to jet", 50, -25.0, 25.0);
595     h1_associatedSumPt = new TH1D("h1_associatedSumPt", "ratio of sum p_{T} between associatedTracks and jetTracks", 20, 0.0, 1.0);
596     h1_associatedVertexIndex = new TH1D("h1_associatedVertex", "number of jets associated to primary vertex", 5, -0.5, 4.5);
597     h2_nAssTracksVsJetPt = new TH2F("h2_nAssTracksVsJetPt", "nTracks vs Jet p_{T}", 50, 0, 100, 20, -0.5, 19.5);
598     p1_nVtcs = new TProfile("p1_nVtcs", "<N> per run", 5200.0, 132300.0, 137500.0, 0.0, 6.0);
599    
600 naodell 1.26 recoJets = new TClonesArray("TCJet");
601 naodell 1.27 recoMET = new TClonesArray("TCMET");
602 naodell 1.26 recoElectrons = new TClonesArray("TCElectron");
603     recoMuons = new TClonesArray("TCMuon");
604     genJets = new TClonesArray("TCGenJet");
605 naodell 1.24 primaryVtx = new TClonesArray("TCPrimaryVtx");
606 naodell 1.1
607 naodell 1.26 sTree->Branch("recoJets",&recoJets, 6400, 0);
608     sTree->Branch("recoElectrons",&recoElectrons, 6400, 0);
609     sTree->Branch("recoMuons",&recoMuons, 6400, 0);
610     sTree->Branch("genJets",&genJets, 6400, 0);
611 naodell 1.5 sTree->Branch("primaryVtx",&primaryVtx, 6400, 0);
612 naodell 1.28 sTree->Branch("recoMET",&recoMET, 6400, 0);
613 naodell 1.1 sTree->Branch("eventNumber",&eventNumber, "eventNumber/I");
614     sTree->Branch("runNumber",&runNumber, "runNumber/I");
615     sTree->Branch("lumiSection",&lumiSection, "lumiSection/I");
616 naodell 1.6 sTree->Branch("triggerStatus",&triggerStatus, "triggerStatus/i");
617 naodell 1.27 sTree->Branch("hltPrescale",hltPrescale, "hltPrescale[32]/i");
618 naodell 1.8 sTree->Branch("isRealData",&isRealData, "isRealData/i");
619     sTree->Branch("bunchCross",&bunchCross, "bunchCross/i");
620 naodell 1.28 sTree->Branch("lumiDeadCount",&lumiDeadCount, "lumiDeadCount/f");
621     sTree->Branch("lumiLiveFrac",&lumiLiveFrac, "lumiLiveFrac/f");
622     sTree->Branch("intDelLumi",&intDelLumi, "intDelLumi/f");
623     sTree->Branch("ptHat",&ptHat, "ptHat/f");
624     sTree->Branch("qScale", &qScale, "qScale/f");
625     sTree->Branch("crossSection", &crossSection, "crossSection/f");
626 naodell 1.1 }
627    
628 naodell 1.26 void MPIntuple::beginRun(const edm::Run& iRun, const edm::EventSetup& iEvent)
629     {
630     bool changed = true;
631     hltConfig_.init(iRun, iEvent, hltProcess_, changed);
632     }
633    
634     void MPIntuple::endLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup& iEvent)
635     {
636     edm::Handle<LumiSummary> lumiSummary;
637     iLumi.getByLabel("lumiProducer", lumiSummary);
638    
639 naodell 1.27 lumiDeadCount = lumiSummary->deadcount();
640     lumiLiveFrac = lumiSummary->liveFrac();
641     intDelLumi = lumiSummary->avgInsDelLumi()*93.244;
642    
643     //cout<<iLumi.id().luminosityBlock()<<endl;
644     //cout<<"\t Dead Count = "<<lumiSummary->deadcount()<<endl;
645     //cout<<"\t Fraction of dead time = "<<1 - lumiSummary->liveFrac()<<endl;
646     //cout<<"\t Integrated luminosity = "<<lumiSummary->avgInsDelLumi()*93.244<<endl;
647     //cout<<"\t Dead time corrected luminosity = "<<lumiSummary->avgInsDelLumi()*lumiSummary->liveFrac()*93.244<<endl;
648 naodell 1.26 }
649    
650     void MPIntuple::endRun(const edm::Run& iRun, const edm::EventSetup& iEvent)
651     {
652 naodell 1.27 //for (int i = 0; i < (int)mpiTriggers_.size(); ++i) cout << mpiTriggers_[i] << " prescale = " << hltPrescale[i] <<endl;
653 naodell 1.26 }
654 naodell 1.1 // ------------ method called once each job just after ending the event loop ------------
655     void MPIntuple::endJob()
656     {
657 naodell 1.17 ntupleFile->cd();
658    
659 naodell 1.27 h1_ptHat->Write();
660 naodell 1.24 h1_fracAssociatedTracks->Write();
661     h1_meanJetTrackZ->Write();
662 naodell 1.16 h1_trackDxy->Write();
663 naodell 1.24 h1_jetVertexZ->Write();
664     h1_associatedSumPt->Write();
665     h1_associatedVertexIndex->Write();
666 naodell 1.16 h2_nAssTracksVsJetPt->Write();
667 naodell 1.15 p1_nVtcs->Write();
668    
669 naodell 1.1 ntupleFile->Write();
670     ntupleFile->Close();
671     }
672    
673    
674 andrey 1.2 bool MPIntuple::triggerDecision(edm::Handle<edm::TriggerResults> &hltR, int iTrigger)
675     {
676     bool triggerPassed = false;
677     if(hltR->wasrun(iTrigger) &&
678     hltR->accept(iTrigger) &&
679     !hltR->error(iTrigger) ){
680     triggerPassed = true;
681     }
682     return triggerPassed;
683 naodell 1.16 }
684    
685 naodell 1.27 float MPIntuple::sumPtSquared(const Vertex & v)
686 naodell 1.16 {
687 naodell 1.27 float sum = 0.;
688     float pT;
689 naodell 1.16 for (Vertex::trackRef_iterator it = v.tracks_begin(); it != v.tracks_end(); it++) {
690     pT = (**it).pt();
691 naodell 1.27 float epT=(**it).ptError(); pT=pT>epT ? pT-epT : 0;
692 naodell 1.16
693     sum += pT*pT;
694 andrey 1.2 }
695 naodell 1.16 return sum;
696     }
697 andrey 1.2
698 naodell 1.1 //define this as a plug-in
699     DEFINE_FWK_MODULE(MPIntuple);