ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MPIAnalyzer/src/MPIntuple.cc
(Generate patch)

Comparing UserCode/MPIAnalyzer/src/MPIntuple.cc (file contents):
Revision 1.4 by naodell, Sat May 22 23:34:09 2010 UTC vs.
Revision 1.29 by naodell, Mon Feb 28 16:46:30 2011 UTC

# Line 1 | Line 1
1 /*
2 Description: <one line class summary>
3
4 Implementation:
5     n-tuple creator for jet studies
6 */
7 //
1   // Original Author:  "Nathaniel Odell"
2   // Secondary Author: Steven Won
3   // With contributions from: Andrey Pozdnyakov
4   //         Created:  Thurs April 22  2010
5   // $Id$
13 //
14 //
15
6  
7   // system include files
8   #include <memory>
# Line 25 | Line 15
15   #include "FWCore/Framework/interface/EventSetup.h"
16   #include "FWCore/Framework/interface/Event.h"
17   #include "FWCore/Framework/interface/MakerMacros.h"
18 <
18 > #include "FWCore/Framework/interface/LuminosityBlock.h"
19   #include "FWCore/ParameterSet/interface/ParameterSet.h"
20  
31 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
21   #include "Geometry/Records/interface/CaloGeometryRecord.h"
22 <
23 < // Jet and vertex functions
22 > #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
23 > #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 > #include "DataFormats/Math/interface/deltaPhi.h"
30 >
31 > // Libraries for objects
32 > #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
33 > #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
34 > #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
35   #include "DataFormats/JetReco/interface/CaloJet.h"
36   #include "DataFormats/JetReco/interface/CaloJetCollection.h"
37 #include "DataFormats/JetReco/interface/PFJet.h"
38 #include "DataFormats/JetReco/interface/PFJetCollection.h"
37   #include "DataFormats/JetReco/interface/GenJet.h"
38   #include "DataFormats/JetReco/interface/GenJetCollection.h"
39 < #include "DataFormats/JetReco/interface/Jet.h"
39 > #include "DataFormats/JetReco/interface/PFJet.h"
40 > #include "DataFormats/JetReco/interface/PFJetCollection.h"
41 > #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 > #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   #include "DataFormats/VertexReco/interface/Vertex.h"
58   #include "DataFormats/VertexReco/interface/VertexFwd.h"
59 + #include "DataFormats/BTauReco/interface/JetTag.h"
60 + #include "DataFormats/BeamSpot/interface/BeamSpot.h"
61 + #include "DataFormats/Luminosity/interface/LumiSummary.h"
62 + #include "DataFormats/Common/interface/ValueMap.h"
63 + #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
64 + #include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
65 + #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
66  
67 < // Need to get correctors
67 > //#include "RecoVertex/PrimaryVertexProducer/interface/VertexHigherPtSquared.h"
68 >
69 > // Need to get corrections
70   #include "JetMETCorrections/Objects/interface/JetCorrector.h"
71  
72   // ntuple storage classes
73   #include "TCJet.h"
74 + #include "TCMET.h"
75   #include "TCPrimaryVtx.h"
76 + #include "TCGenJet.h"
77 + #include "TCMuon.h"
78 + #include "TCElectron.h"
79  
80   // Need for HLT trigger info:
81   #include "FWCore/Common/interface/TriggerNames.h"
# Line 56 | Line 84
84  
85   //Root  stuff
86   #include "TROOT.h"
87 + #include "TH1.h"
88 + #include "TH2.h"
89 + #include "TProfile.h"
90   #include "TFile.h"
91   #include "TTree.h"
92   #include "TString.h"
# Line 82 | Line 113 | class MPIntuple : public edm::EDAnalyzer
113  
114     private:
115        virtual void beginJob() ;
116 +      virtual void beginRun(const edm::Run&, const edm::EventSetup&) ;
117        virtual void analyze(const edm::Event&, const edm::EventSetup&);
118 +      virtual void endLuminosityBlock(const edm::LuminosityBlock&,const edm::EventSetup&);
119 +      virtual void endRun(const edm::Run&, const edm::EventSetup&);
120        virtual void endJob() ;
121  
122 <  bool triggerDecision(edm::Handle<edm::TriggerResults> &hltR, int iTrigger);
122 >      bool triggerDecision(edm::Handle<edm::TriggerResults>& hltR, int iTrigger);
123 >      float sumPtSquared(const Vertex& v);
124  
125        // ----------member data ---------------------------
126  
92  edm::InputTag PFJetHandle_;
93  edm::InputTag GenJetHandle_;
94  edm::InputTag PrimaryVtxHandle_;
95  edm::InputTag triggerResultsTag_;
96
97
98  //  Counting variables   //
99
100  int eventNumber, runNumber, lumiSection;
101
102  TTree *sTree;
103  TFile* ntupleFile;
104
105  TClonesArray* jet_ak5PF;
106  TClonesArray* jetP4_ak5Gen;
107  TClonesArray* vtx_offline;
108
109  bool doGenJets_;
110  bool doPFJets_;
111
112  string rootfilename;
113
114  //Triggers
115  string hlTriggerResults_, hltName_, triggerName_;
116  TriggerNames triggerNames;
117  HLTConfigProvider hltConfig_;
118  vector<string>  hlNames;
119
127  
128 +      int eventNumber, runNumber, lumiSection, bunchCross;
129 +      float ptHat, qScale, crossSection;
130 +      float lumiDeadCount, lumiLiveFrac, intDelLumi;
131 +  
132 +      TTree* sTree;
133 +      TFile* ntupleFile;
134 +      edm::InputTag recoJetTag_;
135 +      edm::InputTag recoMETTag_;
136 +      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 +      TClonesArray* recoMET;
150 +      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 +      vector<string>  mpiTriggers_;
161 +      unsigned int triggerStatus;
162 +      unsigned int hltPrescale[32];
163 +
164 +
165 +      //Histograms
166 +      TH1D * h1_ptHat;
167 +      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   };
176  
177 < MPIntuple::MPIntuple(const edm::ParameterSet& iConfig):
124 <
125 <  PFJetHandle_(iConfig.getUntrackedParameter<edm::InputTag>("PFJetTag")),
126 <  GenJetHandle_(iConfig.getUntrackedParameter<edm::InputTag>("GenJetTag")),
127 <  PrimaryVtxHandle_(iConfig.getUntrackedParameter<edm::InputTag>("PrimaryVtxTag")),
128 <  doGenJets_(iConfig.getUntrackedParameter<bool>("doGenJets")),
129 <  doPFJets_(iConfig.getUntrackedParameter<bool>("doPFJets")),
130 <  rootfilename(iConfig.getUntrackedParameter<string>("rootfilename")),
131 <  hlTriggerResults_(iConfig.getUntrackedParameter<string>("HLTriggerResults","TriggerResults")),
132 <  hltName_(iConfig.getUntrackedParameter<string>("hltName","HLT"))
177 > MPIntuple::MPIntuple(const edm::ParameterSet& iConfig)
178   {
179 <  //edm::TriggerNames
180 <  // triggerNames(iConfig);
181 <
179 >  recoJetTag_       = iConfig.getUntrackedParameter<edm::InputTag>("RecoJetTag");
180 >  recoMETTag_       = iConfig.getUntrackedParameter<edm::InputTag>("RecoMETTag");
181 >  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 >  hlTriggerResults_ = iConfig.getUntrackedParameter<string>("HLTriggerResults","TriggerResults");
190 >  hltProcess_       = iConfig.getUntrackedParameter<string>("hltName");
191 >  mpiTriggers_      = iConfig.getUntrackedParameter<vector<string> >("triggers");
192 >  rootfilename      = iConfig.getUntrackedParameter<string>("rootfilename");
193   }
194  
139
195   MPIntuple::~MPIntuple()
196   {
197  
# Line 150 | Line 205 | MPIntuple::~MPIntuple()
205   void MPIntuple::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
206   {
207  
208 <  eventNumber = iEvent.id().event();
209 <  runNumber   = iEvent.id().run();
208 >  eventNumber  = iEvent.id().event();
209 >  runNumber    = iEvent.id().run();
210    lumiSection  = (unsigned int)iEvent.getLuminosityBlock().luminosityBlock();
211 +  bunchCross   = (unsigned int)iEvent.bunchCrossing();
212 +  isRealData   = iEvent.isRealData();
213 +
214 +  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 +  float primaryVertexZ = -999;
222 +
223 +  //////////////////////////
224 +  //Get vertex information//
225 +  //////////////////////////
226 +
227 +  Handle<reco::VertexCollection> primaryVtcs;
228 +  iEvent.getByLabel(primaryVtxTag_, primaryVtcs);
229    
230 <  int PFcount = 0;
231 <  int Gencount = 0;
232 <  int Vtxcount = 0;
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  
249    if(doPFJets_){
250  
251 <    const JetCorrector* correctorL2 = JetCorrector::getJetCorrector ("ak5PFL2Relative",iSetup);
252 <    const JetCorrector* correctorL3 = JetCorrector::getJetCorrector ("ak5PFL3Absolute",iSetup);
251 >    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 >    const JetCorrector* correctorL2  = JetCorrector::getJetCorrector("ak5PFL2Relative",iSetup);
262 >    const JetCorrector* correctorL3  = JetCorrector::getJetCorrector("ak5PFL3Absolute",iSetup);
263 >    const JetCorrector* correctorRes = JetCorrector::getJetCorrector("ak5PFL2L3Residual", iSetup);
264  
265      Handle<reco::PFJetCollection> PFJets;
266 <    iEvent.getByLabel(PFJetHandle_, PFJets);
267 <    
268 <    PFcount = 0;
170 <    
171 <    for(PFJetCollection::const_iterator jet_iter = PFJets->begin(); jet_iter!= PFJets->end(); ++jet_iter){
266 >    iEvent.getByLabel(recoJetTag_, PFJets);
267 >        
268 >    for (PFJetCollection::const_iterator jet_iter = PFJets->begin(); jet_iter!= PFJets->end(); ++jet_iter) {
269        
270        reco::PFJet myJet = reco::PFJet(*jet_iter);
271 +      if (myJet.pt() > 5) {
272  
273 <      float scale2 = correctorL2->correction(myJet);
274 <      float scale3 = correctorL3->correction(myJet);
275 <
276 <      if(myJet.et() > 5){
277 <        
278 <        TCJet jetCon;
279 <        
182 <        jetCon.SetP4(myJet.px(), myJet.py(), myJet.pz(), myJet.energy());
183 <        jetCon.SetVtx(myJet.vx(), myJet.vy(), myJet.vz());
184 <
185 <        jetCon.SetChHadFrac(myJet.chargedHadronEnergyFraction());
186 <        jetCon.SetNeuHadFrac(myJet.neutralHadronEnergyFraction());
187 <        jetCon.SetChEmFrac(myJet.chargedEmEnergyFraction());
188 <        jetCon.SetNeuEmFrac(myJet.neutralEmEnergyFraction());
189 <
190 <        jetCon.SetNumConstit(myJet.chargedMultiplicity() + myJet.neutralMultiplicity());
191 <        jetCon.SetNumChPart(myJet.chargedMultiplicity());
192 <
193 <        jetCon.SetNumChPart(myJet.chargedMultiplicity());
194 <
195 <        jetCon.SetJetCorr(2, scale2);
196 <        jetCon.SetJetCorr(3, scale3);
197 <        
198 <        new ((*jet_ak5PF)[PFcount]) TCJet(jetCon);
273 >        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 >        }
276 >
277 >        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 >        }
280                  
281 <        ++PFcount;
281 >        TCJet* jetCon = new ((*recoJets)[pfCount]) TCJet;
282 >      
283 >        jetCon->SetP4(myJet.px(), myJet.py(), myJet.pz(), myJet.energy());
284 >        jetCon->SetVtx(-999.0, -999.0, -999.0);
285 >        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 >
292 >        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 >        float scale2 = correctorL2->correction(myJet);
296 >        myJet.scaleEnergy(scale2);
297 >        float scale3 = correctorL3->correction(myJet);
298 >        myJet.scaleEnergy(scale3);
299 >        //more corrections?
300 >
301 >        jetCon->SetJetCorr(2, scale2);
302 >        jetCon->SetJetCorr(3, scale3);
303 >
304 >        if (isRealData) {
305 >          float scaleRes = correctorRes->correction(myJet);
306 >          myJet.scaleEnergy(scaleRes);
307 >          jetCon->SetJetCorr(4, scaleRes);
308 >        }
309 >
310 >        /////////////////////////
311 >        //get associated tracks//
312 >        /////////////////////////
313 >
314 >        const reco::TrackRefVector &tracks = myJet.getTrackRefs();
315 >
316 >        vector<TVector3> vtxPositionCollection;
317 >        vector<float>  associatedTrackSumPt;
318 >        vector<unsigned int> jetTrackAddresses;
319 >        float sumTrackX, sumTrackY, sumTrackZ, sumTrackIP, sumTrackPt;
320 >        int   nJetTracks, nVertexTracks, nAssociatedTracks, vertexIndex;
321 >        int   vCount = 0;
322 >
323 >        nJetTracks = nVertexTracks = nAssociatedTracks = 0;
324 >        sumTrackX = sumTrackY = sumTrackZ  = sumTrackIP  = sumTrackPt = 0;
325 >
326 >        if(myJet.pt() > 10 && fabs(myJet.eta()) < 2.4){
327 >
328 >          for(TrackRefVector::const_iterator iTrack = tracks.begin(); iTrack != tracks.end(); ++iTrack){
329 >            const reco::Track &myJetTrack = **iTrack;
330 >
331 >            sumTrackPt += myJetTrack.pt();
332 >            sumTrackX  += myJetTrack.vx();
333 >            sumTrackY  += myJetTrack.vy();            
334 >            sumTrackZ  += myJetTrack.vz();
335 >            sumTrackIP += myJetTrack.dxy(vertexBeamSpot.position());
336 >            jetTrackAddresses.push_back((unsigned int)&myJetTrack);
337 >            ++nJetTracks;
338 >          }
339 >
340 >          if (nJetTracks > 0) {
341 >            jetCon->SetVtx(sumTrackX/nJetTracks, sumTrackY/nJetTracks, sumTrackZ/nJetTracks);          
342 >            h1_meanJetTrackZ->Fill(sumTrackZ/nJetTracks);
343 >            h1_trackDxy->Fill(sumTrackIP/nJetTracks);
344 >          }
345 >          if(jetTrackAddresses.size() > 0){
346 >
347 >            for (VertexCollection::const_iterator vtx_iter = primaryVtcs->begin(); vtx_iter!= primaryVtcs->end(); ++vtx_iter) {      
348 >              reco::Vertex myVtx = reco::Vertex(*vtx_iter);
349 >              if(!myVtx.isValid() || myVtx.isFake()) continue;
350 >              TVector3 *iVtxPosition = new TVector3(myVtx.x(), myVtx.y(), myVtx.z());
351 >              vtxPositionCollection.push_back(*iVtxPosition);
352 >              associatedTrackSumPt.push_back(0);            
353 >            
354 >              for(Vertex::trackRef_iterator iTrackRef = myVtx.tracks_begin(); iTrackRef != myVtx.tracks_end(); ++iTrackRef){
355 >                const edm::RefToBase<reco::Track> &myTrackRef = *iTrackRef;
356 >                if(myTrackRef.isAvailable()){
357 >                  const reco::Track &myVertexTrack = *myTrackRef.get();        
358 >
359 >                  for(vector<unsigned int>::const_iterator iTrackAddress = jetTrackAddresses.begin(); iTrackAddress != jetTrackAddresses.end(); ++iTrackAddress){
360 >                    if (*iTrackAddress == (unsigned int)&myVertexTrack) {
361 >                      associatedTrackSumPt.at(vCount) += myVertexTrack.pt()/sumTrackPt;
362 >                      ++nAssociatedTracks;
363 >                    }
364 >                  }
365 >                }
366 >              }
367 >              ++vCount;  
368 >            }
369 >                    
370 >            float maxSumPtFraction = 0;
371 >            vCount = vertexIndex = 0;
372 >
373 >            for (vector<float>::const_iterator iTrackSumPt = associatedTrackSumPt.begin(); iTrackSumPt != associatedTrackSumPt.end(); ++iTrackSumPt) {
374 >              if (*iTrackSumPt > maxSumPtFraction) {
375 >                maxSumPtFraction = *iTrackSumPt;  
376 >                vertexIndex      = vCount + 1;
377 >              }
378 >              ++vCount;
379 >            }
380 >            if (vertexIndex > 0) {
381 >              h1_jetVertexZ->Fill(vtxPositionCollection[vertexIndex-1].z());
382 >            }
383 >
384 >            jetCon->SetVtxSumPtFrac(maxSumPtFraction);
385 >            jetCon->SetVtxSumPt(sumTrackPt);
386 >            jetCon->SetVtxTrackFrac((float)nAssociatedTracks/(float)nJetTracks);
387 >            jetCon->SetVtxNTracks(nJetTracks);
388 >            jetCon->SetVtxIndex(vertexIndex);
389 >          }
390 >        }        
391 >        ++pfCount;
392        }      
393      }  
394    }
395 +
396 +
397 +  //////////////////
398 +  // Get MET info //
399 +  //////////////////
400 +
401    
402 <  if(doGenJets_){
403 <    
404 <    Handle<reco::GenJetCollection> GenJets;
405 <    iEvent.getByLabel(GenJetHandle_, GenJets);
406 <    
407 <    
408 <    for(GenJetCollection::const_iterator jet_iter = GenJets->begin(); jet_iter!= GenJets->end(); ++jet_iter){
409 <      
410 <      reco::GenJet myJet = reco::GenJet(*jet_iter);
411 <      
412 <      if(myJet.pt() > 5){
413 <        
414 <        new ((*jetP4_ak5Gen)[Gencount]) TLorentzVector(myJet.px(), myJet.py(), myJet.pz(), myJet.energy());
415 <        
416 <        ++Gencount;
417 <        
418 <      }
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 >  ///////////////////
421 >  // Get muon info //
422 >  ///////////////////
423 >
424 >
425 >  Handle<MuonCollection> muons;
426 >  iEvent.getByLabel(muonTag_, muons);
427 >
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 +  
455 +  ///////////////////////
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 +  iEvent.getByLabel(electronTag_, electrons);
466 +
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 <  Handle<reco::VertexCollection> primaryVtx;
488 <  iEvent.getByLabel(PrimaryVtxHandle_, primaryVtx);
487 >  ////////////////////////
488 >  // Get gen-level info //
489 >  ////////////////////////
490 >  
491  
492 <  for(VertexCollection::const_iterator vtx_iter = primaryVtx->begin(); vtx_iter!= primaryVtx->end(); ++vtx_iter){
492 >  if (!isRealData) {
493      
494 <    reco::Vertex myVtx = reco::Vertex(*vtx_iter);
495 <    
496 <    TCPrimaryVtx vtxCon;
497 <      
498 <    vtxCon.SetPosition(myVtx.x(), myVtx.y(), myVtx.z());
499 <    vtxCon.SetNDof(myVtx.ndof());
237 <    vtxCon.SetChi2(myVtx.chi2());
238 <      
239 <    new ((*vtx_offline)[Vtxcount]) TCPrimaryVtx(vtxCon);
240 <      
241 <    ++Vtxcount;
242 <    
243 <  }
494 >    Handle<GenEventInfoProduct> GenEventInfoHandle;
495 >    iEvent.getByLabel("generator", GenEventInfoHandle);
496 >    Handle<GenRunInfoProduct> GenRunInfoHandle;
497 >    iEvent.getByLabel("generator", GenRunInfoHandle);
498 >    Handle<reco::GenJetCollection> GenJets;
499 >    iEvent.getByLabel(genJetTag_, GenJets);
500  
501 +    ptHat = qScale = -1; crossSection = 0;
502  
503 +    if (GenEventInfoHandle.isValid()) {
504 +      qScale       = GenEventInfoHandle->qScale();
505 +      ptHat        = (GenEventInfoHandle->hasBinningValues() ? GenEventInfoHandle->binningValues()[0] : 0.0);
506 +      h1_ptHat->Fill(ptHat);
507 +    }
508 +   if (GenRunInfoHandle.isValid()) {
509 +      crossSection = GenRunInfoHandle->crossSection();
510 +    }
511 +        
512 +    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 +
516 +        TCGenJet* jetCon = new ((*genJets)[genCount]) TCGenJet;
517 +        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 +
524 +        /*const reco::GenParticle *myGenParticle = myJet.getGenConstituent(0);
525 +
526 +        if(myGenParticle->numberOfMothers() == 1)
527 +        {
528 +          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 +      }
541 +    }    
542 +  }
543 +  
544 +  ///////////////////////////  
545 +  //get trigger information//
546 +  ///////////////////////////
547  
548 <  //----------  Filling HLT trigger bits!  ------------
548 >  if (triggerHLT_) {
549  
550 <  edm::Handle<TriggerResults> hltR;
551 <  triggerResultsTag_ = InputTag(hlTriggerResults_,"",hltName_);
552 <  iEvent.getByLabel(triggerResultsTag_,hltR);
550 >    edm::Handle<TriggerResults> hltR;
551 >    triggerResultsTag_ = InputTag(hlTriggerResults_,"",hltProcess_);
552 >    iEvent.getByLabel(triggerResultsTag_,hltR);
553  
554 <  const TriggerNames & triggerNames = iEvent.triggerNames(*hltR);
555 <  hlNames=triggerNames.triggerNames();
554 >    const TriggerNames & triggerNames = iEvent.triggerNames(*hltR);
555 >    hlNames=triggerNames.triggerNames();  
556  
557 <  string MPI_TriggerNames[32] = {"HLT_PixelTracks_Multiplicity70", "HLT_MinBiasBSC_NoBPTX", "HLT_PixelTracks_Multiplicity40","HLT_L1Tech_HCAL_HF", "HLT_IsoTrackHB_8E29", "HLT_IsoTrackHE_8E29", "HLT_L1Tech_RPC_TTU_RBst1_collisions", "HLT_L1_BscMinBiasOR_BptxPlusORMinus", "HLT_L1Tech_BSC_halo_forPhysicsBackground", "HLT_L1Tech_BSC_HighMultiplicity", "HLT_MinBiasPixel_DoubleIsoTrack5", "HLT_MinBiasPixel_DoubleTrack", "HLT_MinBiasPixel_SingleTrack", "HLT_ZeroBiasPixel_SingleTrack", "HLT_MinBiasBSC", "HLT_StoppedHSCP_8E29", "HLT_Jet15U_HcalNoiseFiltered", "HLT_QuadJet15U", "HLT_DiJetAve30U_8E29", "HLT_DiJetAve15U_8E29", "HLT_FwdJet20U", "HLT_Jet50U", "HLT_Jet30U", "HLT_Jet15U", "HLT_BTagMu_Jet10U", "HLT_DoubleJet15U_ForwardBackward", "HLT_BTagIP_Jet50U", "HLT_DoubleLooseIsoTau15", "HLT_SingleLooseIsoTau20", "HLT_HT100U", "HLT_MET100", "HLT_MET45"};
557 >    triggerStatus = 0x0;    
558 >    //int nTriggers = sizeof(mpiTriggers_) / sizeof(int);
559  
560 <  bool triggerPassed = false;
259 <  unsigned int triggerStatus = 0x0;
260 <  
261 <  for (uint iT=0; iT<hlNames.size(); ++iT) {
560 >    for(int i = 0; i < (int)mpiTriggers_.size(); ++i) hltPrescale[i] = hltConfig_.prescaleValue(iEvent, iSetup, mpiTriggers_[i]);
561  
562 <    triggerPassed = triggerDecision(hltR, iT);
563 <    
564 <    if(triggerPassed){
565 <      
566 <      for (int j = 0; j != 32; ++j){
268 <        
269 <        if (hlNames[iT] == MPI_TriggerNames[j])
270 <          {
271 <            cout<<"trigger name: "<<hlNames[iT]<<"  status: "<<triggerPassed<<endl;
272 <            triggerStatus |= 0x01 << j;
562 >    for (int i=0; i < (int)hlNames.size(); ++i) {      
563 >      if (triggerDecision(hltR, i)) {  
564 >        for (int j = 0; j < (int)mpiTriggers_.size(); ++j){
565 >          if (hlNames[i] == mpiTriggers_[j]) {
566 >            triggerStatus |= 0x01 << j;      
567            }
568 +        }
569        }
570 <    }
571 <  }
277 <  
278 <  cout<<triggerStatus<<endl;
570 >    }
571 >  }
572  
573 <  if(PFcount > 0 || Gencount > 0 || Vtxcount > 0);  sTree -> Fill();
281 <  
282 <  jet_ak5PF->Clear();
283 <  vtx_offline->Clear();
284 <  jetP4_ak5Gen->Clear();
573 >  if((pfCount > 1 || genCount > 1) && vtxCount > 0) sTree -> Fill();
574  
575 +  recoJets->Clear();
576 +  recoMET->Clear();
577 +  recoElectrons->Clear();
578 +  recoMuons->Clear();
579 +  primaryVtx->Clear();
580 +  genJets->Clear();
581   }
582  
288
583   // ------------ method called once each job just before starting event loop  ------------
584   void  MPIntuple::beginJob()
585 < {
586 <  
587 <  ntupleFile           = new TFile(rootfilename.c_str(), "RECREATE");
588 <  sTree                = new TTree("dpsTree", "Tree for Jets");
589 <  
590 <  jet_ak5PF            = new TClonesArray("TCJet");
591 <  jetP4_ak5Gen         = new TClonesArray("TLorentzVector");
592 <  vtx_offline          = new TClonesArray("TCPrimaryVtx");
593 <
594 <  sTree->Branch("jet_ak5PF",&jet_ak5PF, 6400, 0);
595 <  sTree->Branch("jetP4_ak5Gen",&jetP4_ak5Gen, 6400, 0);
596 <  sTree->Branch("vtx_offline",&vtx_offline, 6400, 0);
597 <
585 > {  
586 >  ntupleFile               = new TFile(rootfilename.c_str(), "RECREATE");
587 >  sTree                    = new TTree("mpiTree", "Tree for Jets");
588 >
589 >  h1_ptHat                 = new TH1D("h1_ptHat", "ptHat", 15, 10.0, 160.0);
590 >  h1_fracAssociatedTracks  = new TH1D("h1_fracAssociatedTracks", "Fraction of associated jet tracks", 20, 0.0, 1.0);
591 >  h1_trackDxy              = new TH1D("h1_trackDxy", "dxy for all associated tracks", 50, -0.4, 0.4);
592 >  h1_meanJetTrackZ         = new TH1D("h1_meanJetTrackZ", "<z> from jet tracks", 50, -25.0, 25.0);
593 >  h1_jetVertexZ            = new TH1D("h1_jetVertexZ", "z for vertex associated to jet", 50, -25.0, 25.0);
594 >  h1_associatedSumPt       = new TH1D("h1_associatedSumPt", "ratio of sum p_{T} between associatedTracks and jetTracks", 20, 0.0, 1.0);
595 >  h1_associatedVertexIndex = new TH1D("h1_associatedVertex", "number of jets associated to primary vertex", 5, -0.5, 4.5);
596 >  h2_nAssTracksVsJetPt     = new TH2F("h2_nAssTracksVsJetPt", "nTracks vs Jet p_{T}", 50, 0, 100, 20, -0.5, 19.5);
597 >  p1_nVtcs                 = new TProfile("p1_nVtcs", "<N> per run", 5200.0, 132300.0, 137500.0, 0.0, 6.0);
598 >
599 >  recoJets                 = new TClonesArray("TCJet");
600 >  recoMET                  = new TClonesArray("TCMET");
601 >  recoElectrons            = new TClonesArray("TCElectron");
602 >  recoMuons                = new TClonesArray("TCMuon");
603 >  genJets                  = new TClonesArray("TCGenJet");
604 >  primaryVtx               = new TClonesArray("TCPrimaryVtx");
605 >
606 >  sTree->Branch("recoJets",&recoJets, 6400, 0);
607 >  sTree->Branch("recoElectrons",&recoElectrons, 6400, 0);
608 >  sTree->Branch("recoMuons",&recoMuons, 6400, 0);
609 >  sTree->Branch("genJets",&genJets, 6400, 0);
610 >  sTree->Branch("primaryVtx",&primaryVtx, 6400, 0);
611 >  sTree->Branch("recoMET",&recoMET, 6400, 0);
612    sTree->Branch("eventNumber",&eventNumber, "eventNumber/I");
613    sTree->Branch("runNumber",&runNumber, "runNumber/I");
614    sTree->Branch("lumiSection",&lumiSection, "lumiSection/I");
615 +  sTree->Branch("triggerStatus",&triggerStatus, "triggerStatus/i");
616 +  sTree->Branch("hltPrescale",hltPrescale, "hltPrescale[32]/i");
617 +  sTree->Branch("isRealData",&isRealData, "isRealData/i");
618 +  sTree->Branch("bunchCross",&bunchCross, "bunchCross/i");
619 +  sTree->Branch("lumiDeadCount",&lumiDeadCount, "lumiDeadCount/f");
620 +  sTree->Branch("lumiLiveFrac",&lumiLiveFrac, "lumiLiveFrac/f");
621 +  sTree->Branch("intDelLumi",&intDelLumi, "intDelLumi/f");
622 +  sTree->Branch("ptHat",&ptHat, "ptHat/f");
623 +  sTree->Branch("qScale", &qScale, "qScale/f");
624 +  sTree->Branch("crossSection", &crossSection, "crossSection/f");
625 + }
626 +
627 + void MPIntuple::beginRun(const edm::Run& iRun, const edm::EventSetup& iEvent)
628 + {
629 +  bool changed = true;
630 +  hltConfig_.init(iRun, iEvent, hltProcess_, changed);
631 + }
632 +
633 + void MPIntuple::endLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup& iEvent)
634 + {
635 +  edm::Handle<LumiSummary> lumiSummary;
636 +  iLumi.getByLabel("lumiProducer", lumiSummary);
637  
638 +  lumiDeadCount  = lumiSummary->deadcount();
639 +  lumiLiveFrac   = lumiSummary->liveFrac();
640 +  intDelLumi     = lumiSummary->avgInsDelLumi()*93.244;
641 +
642 +  //cout<<iLumi.id().luminosityBlock()<<endl;
643 +  //cout<<"\t Dead Count = "<<lumiSummary->deadcount()<<endl;
644 +  //cout<<"\t Fraction of dead time = "<<1 - lumiSummary->liveFrac()<<endl;
645 +  //cout<<"\t Integrated luminosity = "<<lumiSummary->avgInsDelLumi()*93.244<<endl;
646 +  //cout<<"\t Dead time corrected luminosity = "<<lumiSummary->avgInsDelLumi()*lumiSummary->liveFrac()*93.244<<endl;
647   }
648  
649 + void MPIntuple::endRun(const edm::Run& iRun, const edm::EventSetup& iEvent)
650 + {
651 +  //for (int i = 0; i < (int)mpiTriggers_.size(); ++i) cout << mpiTriggers_[i] << " prescale = " << hltPrescale[i] <<endl;
652 + }
653   // ------------ method called once each job just after ending the event loop  ------------
654   void MPIntuple::endJob()
655   {
656 +  ntupleFile->cd();
657 +
658 +  h1_ptHat->Write();
659 +  h1_fracAssociatedTracks->Write();
660 +  h1_meanJetTrackZ->Write();
661 +  h1_trackDxy->Write();
662 +  h1_jetVertexZ->Write();
663 +  h1_associatedSumPt->Write();
664 +  h1_associatedVertexIndex->Write();
665 +  h2_nAssTracksVsJetPt->Write();
666 +  p1_nVtcs->Write();
667 +
668    ntupleFile->Write();
669    ntupleFile->Close();
315
670   }
671  
672  
# Line 325 | Line 679 | bool MPIntuple::triggerDecision(edm::Han
679        triggerPassed = true;
680      }
681      return triggerPassed;
682 <  }
682 > }
683 >
684 > float MPIntuple::sumPtSquared(const Vertex & v)
685 > {
686 >  float sum = 0.;
687 >  float pT;
688 >  for (Vertex::trackRef_iterator it = v.tracks_begin(); it != v.tracks_end(); it++) {
689 >    pT = (**it).pt();
690 >    float epT=(**it).ptError(); pT=pT>epT ? pT-epT : 0;
691  
692 +    sum += pT*pT;
693 +  }
694 +  return sum;
695 + }
696  
697   //define this as a plug-in
698   DEFINE_FWK_MODULE(MPIntuple);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines