ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/auterman/Analysis/FinalPlots/src/FinalPlots.cc
Revision: 1.2
Committed: Wed Apr 14 15:45:21 2010 UTC (15 years, 1 month ago) by auterman
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +449 -98 lines
Error occurred while calculating annotation data.
Log Message:
*** empty log message ***

File Contents

# Content
1 // -*- C++ -*-
2 //
3 // Package: FinalPlots
4 // Class: FinalPlots
5 //
6 /**\class FinalPlots FinalPlots.cc Analysis/FinalPlots/src/FinalPlots.cc
7
8 Description: <one line class summary>
9
10 Implementation:
11 <Notes on implementation>
12 */
13 //
14 // Original Author: Christian Autermann,68/112,2115,
15 // Created: Sun Oct 18 20:00:45 CEST 2009
16 // $Id: FinalPlots.cc,v 1.1.1.1 2010/03/26 17:01:13 auterman Exp $
17 //
18 //
19
20
21 // system include files
22 #include <memory>
23 #include <string>
24 #include <cmath>
25 #include <numeric>
26
27 // user include files
28 #include "FWCore/Framework/interface/Frameworkfwd.h"
29 #include "FWCore/Framework/interface/EDAnalyzer.h"
30 #include "FWCore/Framework/interface/Event.h"
31 #include "FWCore/Framework/interface/MakerMacros.h"
32 #include "FWCore/ParameterSet/interface/ParameterSet.h"
33 #include "DataFormats/Math/interface/LorentzVector.h"
34 #include "DataFormats/Math/interface/deltaPhi.h"
35 #include "DataFormats/METReco/interface/CaloMET.h"
36 #include "DataFormats/METReco/interface/MET.h"
37 #include "DataFormats/JetReco/interface/CaloJet.h"
38 #include "DataFormats/PatCandidates/interface/Jet.h"
39 #include "DataFormats/JetReco/interface/PFJet.h"
40 #include "DataFormats/Candidate/interface/Candidate.h"
41 #include "DataFormats/Math/interface/deltaR.h"
42 #include "DataFormats/Math/interface/deltaPhi.h"
43 #include "FWCore/ServiceRegistry/interface/Service.h"
44 #include "CommonTools/UtilAlgos/interface/TFileService.h"
45
46 #include "FWCore/Framework/interface/EventSetup.h"
47 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
48 #include "Geometry/Records/interface/CaloGeometryRecord.h"
49 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
50 #include "FWCore/Framework/interface/ESHandle.h"
51 #include "MagneticField/Engine/interface/MagneticField.h"
52 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
53 #include "FWCore/Framework/interface/eventSetupGetImplementation.h"
54 #include "PhysicsTools/IsolationAlgos/interface/PropagateToCal.h"
55
56 #include "TH1F.h"
57 #include "TH2F.h"
58
59 //#include "CommonTools/Utils/interface/PtComparator.h"
60 template<typename T>
61 struct PtrGreaterByPt {
62 typedef T first_argument_type;
63 typedef T second_argument_type;
64 bool operator()( const T & t1, const T & t2 ) const {
65 return t1->pt() > t2->pt();
66 }
67 };
68
69 //
70 // class decleration
71 //
72
73 class FinalPlots : public edm::EDAnalyzer {
74 public:
75 explicit FinalPlots(const edm::ParameterSet&);
76 ~FinalPlots();
77
78
79 private:
80 void bookHistograms(const edm::EventSetup&);
81 virtual void analyze(const edm::Event&, const edm::EventSetup&);
82 virtual void endJob() ;
83 double dPhiBiased(const std::vector<const reco::Candidate*>& jets, const reco::Candidate& excljet);
84 double summedTowerEnergy(CaloTowerDetId& towerId, CaloTowerCollection towers, int ntw);
85
86 typedef ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > LorentzV;
87 std::vector<double> deltaSumPt_permutations(const std::vector<LorentzV>& p4s);
88 double alphaT(const std::vector<LorentzV>& p4s);
89
90 // ----------member data ---------------------------
91 edm::InputTag weightName_;
92 edm::InputTag Jet_;
93 edm::InputTag Met_;
94 std::string name_;
95 double weight_, jetptmin_, jetetamax_;
96 double tmaxEta_, tminPt_, tmaxChiSquare_;
97 int tminNumOfHits_;
98 double tminDeltaR_;
99
100 //Jet & MET plots
101 TH1F * HT_;
102 TH1F * MHT_;
103 TH1F * MET_;
104 TH1F * AllJetsPt_;
105 TH1F * Jet1Pt_, *Jet2Pt_, *Jet3Pt_, *Jet4Pt_;
106 TH1F * Jet1E_, *Jet2E_, *Jet3E_, *Jet4E_;
107 TH1F * Jet1Phi_,*Jet2Phi_,*Jet3Phi_,*Jet4Phi_;
108 TH1F * Jet1Eta_,*Jet2Eta_,*Jet3Eta_,*Jet4Eta_;
109 TH1F * JetMult_;
110 TH1F * dPhiMin_;
111 TH1F * dPhiBiased_;
112
113 //Track & Tower plots
114 TH1F * AllTracksPt_, *AllTracksPhi_;
115 TH1F * Track1Pt_, *Track2Pt_, *Track3Pt_, *Track4Pt_;
116 TH1F * Track1Phi_,*Track2Phi_,*Track3Phi_,*Track4Phi_,*Track15Phi_;
117 TH1F * Track1Eta_,*Track2Eta_,*Track3Eta_,*Track4Eta_;
118 TH1F * Track1NumOfHits_,*Track2NumOfHits_,*Track3NumOfHits_,*Track4NumOfHits_;
119 TH1F * Track1ChiSquare_,*Track2ChiSquare_,*Track3ChiSquare_,*Track4ChiSquare_;
120 TH2F * Track1NOHvsPhi_,*Track2NOHvsPhi_,*Track3NOHvsPhi_,*Track4NOHvsPhi_;
121 TH2F * Track1PtvsPhi_,*Track2PtvsPhi_,*Track3PtvsPhi_,*Track4PtvsPhi_;
122 TH1F * TrackMult_;
123
124 TH1F * IsoTrack1Pt_;
125 TH1F * IsoTrack1Phi_;
126 TH1F * IsoTrack1Eta_;
127 TH1F * IsoTrack1NumOfHits_;
128 TH1F * IsoTrack1ChiSquare_;
129 TH2F * IsoTrack1NOHvsPhi_;
130 TH2F * IsoTrack1PtvsPhi_;
131 TH1F * IsoTrack1DeltaR_;
132 TH1F * IsoTrack1OuterDeltaR_;
133 TH1F * TwoTracksDeltaPhi_,*TwoTracksDeltaPt_;
134
135 edm::InputTag tracks_;
136 edm::InputTag towers_;
137 //PropagateToCal* toEcal_;
138 PropagateToCal* toHcal_;
139 TH1F * TrackTower_dEta_, *TrackTower_dPhi_, *TrackTower_dPt_;
140 TH1F * TrackTower_E1x1_, *TrackTower_E3x3_;
141 TH1F * Response_E1x1_, *Response_E3x3_;
142 int nTowerGroup_;
143 double maxDeltaEta_, maxDeltaPhi_;
144
145 bool histogramsBooked;
146 int tracksFound, towersFound;
147 };
148
149 FinalPlots::FinalPlots(const edm::ParameterSet& iConfig):
150 weightName_(iConfig.getParameter<edm::InputTag>("weightName") ),
151 Jet_( iConfig.getParameter<edm::InputTag>("Jet") ),
152 Met_( iConfig.getParameter<edm::InputTag>("MET") ),
153 name_( iConfig.getParameter<std::string>("uncertainty_name") ),
154 jetptmin_ ( iConfig.getParameter<double>("JetPtMin") ),
155 jetetamax_( iConfig.getParameter<double>("JetEtaMax") ),
156 //tracks & Towers:
157 tracks_( iConfig.getParameter<edm::InputTag>( "Tracks" ) ),
158 towers_( iConfig.getParameter<edm::InputTag>( "Towers" ) ),
159 nTowerGroup_( iConfig.getParameter<int>( "GroupNTowers" ) ),
160 maxDeltaEta_ ( iConfig.getParameter<double>("TowerDeltaEtaMax") ),
161 maxDeltaPhi_ ( iConfig.getParameter<double>("TowerDeltaPhiMax") ),
162 tmaxEta_ ( iConfig.getParameter<double>("TrackEtaMax") ),
163 tminPt_( iConfig.getParameter<double>("TrackPtMin") ),
164 tmaxChiSquare_( iConfig.getParameter<double>("TrackChiSquareMax") ),
165 tminNumOfHits_( iConfig.getParameter<int>( "TrackNumOfHitsMin" ) ),
166 tminDeltaR_( iConfig.getParameter<double>("TrackDeltaRMin") )
167 {
168 histogramsBooked = false;
169 }
170
171 // ------------ method called once each job just before starting event loop ------------
172 void
173 FinalPlots::bookHistograms(const edm::EventSetup&)
174 {
175 edm::Service<TFileService> fs;
176 if( !fs ){
177 throw edm::Exception( edm::errors::Configuration,
178 "TFile Service is not registered in cfg file" );
179 }
180
181 std::string histname = "HT"+name_;
182 HT_ = fs->make<TH1F>(histname.c_str(),";HT [GeV];events", 100, 0.0, 100.0);
183 HT_->Sumw2();
184
185 histname = "MHT"+name_;
186 MHT_ = fs->make<TH1F>(histname.c_str(),";MHT [GeV];events", 100, 0.0, 50.0);
187 MHT_->Sumw2();
188 histname = "MET"+name_;
189 MET_ = fs->make<TH1F>(histname.c_str(),";MET [GeV];events", 100, 0.0, 50.0);
190 MET_->Sumw2();
191
192 histname = "AllJetsPt"+name_;
193 AllJetsPt_ = fs->make<TH1F>(histname.c_str(),";All Jets, Pt [GeV];events", 100, 0.0, 50.0);
194 AllJetsPt_->Sumw2();
195
196 histname = "Jet1Pt"+name_;
197 Jet1Pt_ = fs->make<TH1F>(histname.c_str(),";1. Jet, Pt [GeV];events", 40, 0.0, 20.0);
198 Jet1Pt_->Sumw2();
199 histname = "Jet2Pt"+name_;
200 Jet2Pt_ = fs->make<TH1F>(histname.c_str(),";2. Jet, Pt [GeV];events", 40, 0.0, 20.0);
201 Jet2Pt_->Sumw2();
202 histname = "Jet3Pt"+name_;
203 Jet3Pt_ = fs->make<TH1F>(histname.c_str(),";3. Jet, Pt [GeV];events", 40, 0.0, 20.0);
204 Jet3Pt_->Sumw2();
205 histname = "Jet4Pt"+name_;
206 Jet4Pt_ = fs->make<TH1F>(histname.c_str(),";4. Jet, Pt [GeV];events", 40, 0.0, 20.0);
207 Jet4Pt_->Sumw2();
208
209 histname = "Jet1E"+name_;
210 Jet1E_ = fs->make<TH1F>(histname.c_str(),";1. Jet, E [GeV];events", 40, 0.0, 20.0);
211 Jet1E_->Sumw2();
212 histname = "Jet2E"+name_;
213 Jet2E_ = fs->make<TH1F>(histname.c_str(),";2. Jet, E [GeV];events", 40, 0.0, 20.0);
214 Jet2E_->Sumw2();
215 histname = "Jet3E"+name_;
216 Jet3E_ = fs->make<TH1F>(histname.c_str(),";3. Jet, E [GeV];events", 40, 0.0, 20.0);
217 Jet3E_->Sumw2();
218 histname = "Jet4E"+name_;
219 Jet4E_ = fs->make<TH1F>(histname.c_str(),";4. Jet, E [GeV];events", 40, 0.0, 20.0);
220 Jet4E_->Sumw2();
221
222 histname = "Jet1Phi"+name_;
223 Jet1Phi_ = fs->make<TH1F>(histname.c_str(),";1. Jet, #phi;events", 40, -3.2, 3.2);
224 Jet1Phi_->Sumw2();
225 histname = "Jet2Phi"+name_;
226 Jet2Phi_ = fs->make<TH1F>(histname.c_str(),";2. Jet, #phi;events", 40, -3.2, 3.2);
227 Jet2Phi_->Sumw2();
228 histname = "Jet3Phi"+name_;
229 Jet3Phi_ = fs->make<TH1F>(histname.c_str(),";3. Jet, #phi;events", 40, -3.2, 3.2);
230 Jet3Phi_->Sumw2();
231 histname = "Jet4Phi"+name_;
232 Jet4Phi_ = fs->make<TH1F>(histname.c_str(),";4. Jet, #phi;events", 40, -3.2, 3.2);
233 Jet4Phi_->Sumw2();
234
235 histname = "Jet1Eta"+name_;
236 Jet1Eta_ = fs->make<TH1F>(histname.c_str(),";1. Jet, #eta;events", 40, -4.0, 4.0);
237 Jet1Eta_->Sumw2();
238 histname = "Jet2Eta"+name_;
239 Jet2Eta_ = fs->make<TH1F>(histname.c_str(),";2. Jet, #eta;events", 40, -4.0, 4.0);
240 Jet2Eta_->Sumw2();
241 histname = "Jet3Eta"+name_;
242 Jet3Eta_ = fs->make<TH1F>(histname.c_str(),";3. Jet, #eta;events", 40, -4.0, 4.0);
243 Jet3Eta_->Sumw2();
244 histname = "Jet4Eta"+name_;
245 Jet4Eta_ = fs->make<TH1F>(histname.c_str(),";4. Jet, #eta;events", 40, -4.0, 4.0);
246 Jet4Eta_->Sumw2();
247
248 histname = "JetMult"+name_;
249 JetMult_ = fs->make<TH1F>(histname.c_str(),";Jet multiplicity;events", 21, -0.5, 20.5);
250 JetMult_->Sumw2();
251 histname = "dPhiMin"+name_;
252 dPhiMin_ = fs->make<TH1F>(histname.c_str(),";#Delta#phi_{min};events", 20, 0.0, 3.2);
253 dPhiMin_->Sumw2();
254 histname = "dPhiBiased"+name_;
255 dPhiBiased_ = fs->make<TH1F>(histname.c_str(),";#Delta#phi_{biased};events", 20, 0.0, 3.2);
256 dPhiBiased_->Sumw2();
257
258
259 // Track & Tower
260 histname = "AllTracksPt"+name_;
261 AllTracksPt_ = fs->make<TH1F>(histname.c_str(),";All Tracks, Pt [GeV];events", 100, 0.0, 50.0);
262 AllTracksPt_->Sumw2();
263 histname = "AllTracksPhi"+name_;
264 AllTracksPhi_ = fs->make<TH1F>(histname.c_str(),";All Tracks, #phi;events", 40, -3.2, 3.2);
265 AllTracksPhi_->Sumw2();
266
267 histname = "Track1Pt"+name_;
268 Track1Pt_ = fs->make<TH1F>(histname.c_str(),";1. Track, Pt [GeV];events", 40, 0.0, 20.0);
269 Track1Pt_->Sumw2();
270 histname = "Track2Pt"+name_;
271 Track2Pt_ = fs->make<TH1F>(histname.c_str(),";2. Track, Pt [GeV];events", 40, 0.0, 20.0);
272 Track2Pt_->Sumw2();
273 histname = "Track3Pt"+name_;
274 Track3Pt_ = fs->make<TH1F>(histname.c_str(),";3. Track, Pt [GeV];events", 40, 0.0, 20.0);
275 Track3Pt_->Sumw2();
276 histname = "Track4Pt"+name_;
277 Track4Pt_ = fs->make<TH1F>(histname.c_str(),";4. Track, Pt [GeV];events", 40, 0.0, 20.0);
278 Track4Pt_->Sumw2();
279 histname = "IsoTrack1Pt"+name_;
280 IsoTrack1Pt_ = fs->make<TH1F>(histname.c_str(),";1. Track, Pt [GeV];events", 40, 0.0, 20.0);
281 IsoTrack1Pt_->Sumw2();
282
283 histname = "Track1Phi"+name_;
284 Track1Phi_ = fs->make<TH1F>(histname.c_str(),";1. Track, #phi;events", 40, -3.2, 3.2);
285 Track1Phi_->Sumw2();
286 histname = "Track2Phi"+name_;
287 Track2Phi_ = fs->make<TH1F>(histname.c_str(),";2. Track, #phi;events", 40, -3.2, 3.2);
288 Track2Phi_->Sumw2();
289 histname = "Track3Phi"+name_;
290 Track3Phi_ = fs->make<TH1F>(histname.c_str(),";3. Track, #phi;events", 40, -3.2, 3.2);
291 Track3Phi_->Sumw2();
292 histname = "Track4Phi"+name_;
293 Track4Phi_ = fs->make<TH1F>(histname.c_str(),";4. Track, #phi;events", 40, -3.2, 3.2);
294 Track4Phi_->Sumw2();
295 histname = "Track15Phi"+name_;
296 Track15Phi_ = fs->make<TH1F>(histname.c_str(),";15. Track, #phi;events", 40, -3.2, 3.2);
297 Track15Phi_->Sumw2();
298 histname = "IsoTrack1Phi"+name_;
299 IsoTrack1Phi_ = fs->make<TH1F>(histname.c_str(),";1. Track, #phi;events", 40, -3.2, 3.2);
300 IsoTrack1Phi_->Sumw2();
301
302
303 histname = "Track1Eta"+name_;
304 Track1Eta_ = fs->make<TH1F>(histname.c_str(),";1. Track, #eta;events", 40, -4.0, 4.0);
305 Track1Eta_->Sumw2();
306 histname = "Track2Eta"+name_;
307 Track2Eta_ = fs->make<TH1F>(histname.c_str(),";2. Track, #eta;events", 40, -4.0, 4.0);
308 Track2Eta_->Sumw2();
309 histname = "Track3Eta"+name_;
310 Track3Eta_ = fs->make<TH1F>(histname.c_str(),";3. Track, #eta;events", 40, -4.0, 4.0);
311 Track3Eta_->Sumw2();
312 histname = "Track4Eta"+name_;
313 Track4Eta_ = fs->make<TH1F>(histname.c_str(),";4. Track, #eta;events", 40, -4.0, 4.0);
314 Track4Eta_->Sumw2();
315 histname = "IsoTrack1Eta"+name_;
316 IsoTrack1Eta_ = fs->make<TH1F>(histname.c_str(),";1. Track, #eta;events", 40, -4.0, 4.0);
317 IsoTrack1Eta_->Sumw2();
318
319 histname = "Track1NumOfHits"+name_;
320 Track1NumOfHits_ = fs->make<TH1F>(histname.c_str(),";1. Track, Number Of Hits;events", 40, 0., 40.);
321 Track1NumOfHits_->Sumw2();
322 histname = "Track2NumOfHits"+name_;
323 Track2NumOfHits_ = fs->make<TH1F>(histname.c_str(),";2. Track, Number Of Hits;events", 40, 0., 40.);
324 Track2NumOfHits_->Sumw2();
325 histname = "Track3NumOfHits"+name_;
326 Track3NumOfHits_ = fs->make<TH1F>(histname.c_str(),";3. Track, Number Of Hits;events", 40, 0., 40.);
327 Track3NumOfHits_->Sumw2();
328 histname = "Track4NumOfHits"+name_;
329 Track4NumOfHits_ = fs->make<TH1F>(histname.c_str(),";4. Track, Number Of Hits;events", 40, 0., 40.);
330 Track4NumOfHits_->Sumw2();
331 histname = "IsoTrack1NumOfHits"+name_;
332 IsoTrack1NumOfHits_ = fs->make<TH1F>(histname.c_str(),";1. Track, Number Of Hits;events", 40, 0., 40.);
333 IsoTrack1NumOfHits_->Sumw2();
334
335 histname = "Track1ChiSquare"+name_;
336 Track1ChiSquare_ = fs->make<TH1F>(histname.c_str(),";1. Track, #chi^{2};events", 40, 0., 10.);
337 Track1ChiSquare_->Sumw2();
338 histname = "Track2ChiSquare"+name_;
339 Track2ChiSquare_ = fs->make<TH1F>(histname.c_str(),";2. Track, #chi^{2};events", 40, -0., 10.);
340 Track2ChiSquare_->Sumw2();
341 histname = "Track3ChiSquare"+name_;
342 Track3ChiSquare_ = fs->make<TH1F>(histname.c_str(),";3. Track, #chi^{2};events", 40, 0., 10.);
343 Track3ChiSquare_->Sumw2();
344 histname = "Track4ChiSquare"+name_;
345 Track4ChiSquare_ = fs->make<TH1F>(histname.c_str(),";4. Track, #chi^{2};events", 40, 0., 10.);
346 Track4ChiSquare_->Sumw2();
347 histname = "IsoTrack1ChiSquare"+name_;
348 IsoTrack1ChiSquare_ = fs->make<TH1F>(histname.c_str(),";1. Track, #chi^{2};events", 40, 0., 10.);
349 IsoTrack1ChiSquare_->Sumw2();
350
351 histname = "Track1NOHvsPhi"+name_;
352 Track1NOHvsPhi_ = fs->make<TH2F>(histname.c_str(),";1. Track, Number Of Hits;#phi;events", 40, 0., 40., 40, -4.0, 4.0);
353 Track1NOHvsPhi_->Sumw2();
354 histname = "Track2NOHvsPhi"+name_;
355 Track2NOHvsPhi_ = fs->make<TH2F>(histname.c_str(),";2. Track, Number Of Hits;#phi;events", 40, 0., 40., 40, -4.0, 4.0);
356 Track2NOHvsPhi_->Sumw2();
357 histname = "Track3NOHvsPhi"+name_;
358 Track3NOHvsPhi_ = fs->make<TH2F>(histname.c_str(),";3. Track, Number Of Hits;#phi;events", 40, 0., 40., 40, -4.0, 4.0);
359 Track3NOHvsPhi_->Sumw2();
360 histname = "Track4NOHvsPhi"+name_;
361 Track4NOHvsPhi_ = fs->make<TH2F>(histname.c_str(),";4. Track, Number Of Hits;#phi;events", 40, 0., 40., 40, -4.0, 4.0);
362 Track4NOHvsPhi_->Sumw2();
363 histname = "IsoTrack1NOHvsPhi"+name_;
364 IsoTrack1NOHvsPhi_ = fs->make<TH2F>(histname.c_str(),";1. Track, Number Of Hits;#phi;events", 40, 0., 40., 40, -4.0, 4.0);
365 IsoTrack1NOHvsPhi_->Sumw2();
366
367 histname = "Track1PtvsPhi"+name_;
368 Track1PtvsPhi_ = fs->make<TH2F>(histname.c_str(),";1. Track, Pt [GeV];#phi;events", 40, 0., 20., 40, -4.0, 4.0);
369 Track1PtvsPhi_->Sumw2();
370 histname = "Track2PtvsPhi"+name_;
371 Track2PtvsPhi_ = fs->make<TH2F>(histname.c_str(),";2. Track, Pt [GeV];#phi;events", 40, 0., 20., 40, -4.0, 4.0);
372 Track2PtvsPhi_->Sumw2();
373 histname = "Track3PtvsPhi"+name_;
374 Track3PtvsPhi_ = fs->make<TH2F>(histname.c_str(),";3. Track, Pt [GeV];#phi;events", 40, 0., 20., 40, -4.0, 4.0);
375 Track3PtvsPhi_->Sumw2();
376 histname = "Track4PtvsPhi"+name_;
377 Track4PtvsPhi_ = fs->make<TH2F>(histname.c_str(),";4. Track, Pt [GeV];#phi;events", 40, 0., 20., 40, -4.0, 4.0);
378 Track4PtvsPhi_->Sumw2();
379 histname = "IsoTrack1PtvsPhi"+name_;
380 IsoTrack1PtvsPhi_ = fs->make<TH2F>(histname.c_str(),";1. Track, Pt [GeV];#phi;events", 40, 0., 20., 40, -4.0, 4.0);
381 IsoTrack1PtvsPhi_->Sumw2();
382
383 histname = "TrackMult"+name_;
384 TrackMult_ = fs->make<TH1F>(histname.c_str(),";Track multiplicity;events", 21, -0.5, 20.5);
385 TrackMult_->Sumw2();
386
387 histname = "IsoTrack1DeltaR"+name_;
388 IsoTrack1DeltaR_ = fs->make<TH1F>(histname.c_str(),";#DeltaR_{min} of 1. Track;events", 40, 0.0, 6.0);
389 IsoTrack1DeltaR_->Sumw2();
390 histname = "IsoTrack1OuterDeltaR"+name_;
391 IsoTrack1OuterDeltaR_ = fs->make<TH1F>(histname.c_str(),";#DeltaR_{min} of 1. Track;events", 40, 0.0, 6.0);
392 IsoTrack1OuterDeltaR_->Sumw2();
393
394 histname = "TrackTower_E1x1"+name_;
395 TrackTower_E1x1_ = fs->make<TH1F>(histname.c_str(),";Tower Energy in 1x1 cell, E [GeV];events", 40, 0.0, 20.0);
396 TrackTower_E1x1_->Sumw2();
397 histname = "TrackTower_E3x3"+name_;
398 TrackTower_E3x3_ = fs->make<TH1F>(histname.c_str(),";Tower Energy in 3x3 cell, E [GeV];events", 40, 0.0, 20.0);
399 TrackTower_E3x3_->Sumw2();
400
401 histname = "Response_E1x1"+name_;
402 Response_E1x1_ = fs->make<TH1F>(histname.c_str(),";Tower Response in 1x1 cell, #frac{E_{CaloTower} [GeV]}{Pt_{Track} [GeV]};events", 40, 0.0, 5.0);
403 Response_E1x1_->Sumw2();
404 histname = "Response_E3x3"+name_;
405 Response_E3x3_ = fs->make<TH1F>(histname.c_str(),";Tower Response in 3x3 cell, #frac{E_{CaloTower} [GeV]}{Pt_{Track} [GeV]};events", 40, 0.0, 5.0);
406 Response_E3x3_->Sumw2();
407
408 histname = "TwoTracksDeltaPhi"+name_;
409 TwoTracksDeltaPhi_ = fs->make<TH1F>(histname.c_str(),";#Delta#phi in two track events;events", 40, 0.0, 4.0);
410 TwoTracksDeltaPhi_->Sumw2();
411 histname = "TwoTracksDeltaPt"+name_;
412 TwoTracksDeltaPt_ = fs->make<TH1F>(histname.c_str(),";|#DeltaPt| [GeV] in two track events;events", 40, 0.0, 20.0);
413 TwoTracksDeltaPt_->Sumw2();
414
415 histname = "TrackTower_dEta"+name_;
416 TrackTower_dEta_ = fs->make<TH1F>(histname.c_str(),";#Delta#eta(track, tower);events", 40, -5.0, 5.0);
417 TrackTower_dEta_->Sumw2();
418
419 histname = "TrackTower_dPhi"+name_;
420 TrackTower_dPhi_ = fs->make<TH1F>(histname.c_str(),";#Delta#phi(track, tower);events", 40, 0.0, 4.0);
421 TrackTower_dPhi_->Sumw2();
422
423 histname = "TrackTower_dPt"+name_;
424 TrackTower_dPt_ = fs->make<TH1F>(histname.c_str(),";#DeltaPt(track, tower);events", 40, -20.0, 20.0);
425 TrackTower_dPt_->Sumw2();
426
427 histogramsBooked = true;
428 }
429
430
431 FinalPlots::~FinalPlots()
432 {
433
434 // do anything here that needs to be done at desctruction time
435 // (e.g. close files, deallocate resources etc.)
436
437 }
438
439
440 //
441 // member functions
442 //
443 // ------------ biased delta phi ----------------------------
444 double FinalPlots::dPhiBiased(const std::vector<const reco::Candidate*>& jets, const reco::Candidate& excljet)
445 {
446 math::PtEtaPhiMLorentzVector htvec(0.0, 0.0, 0.0, 0.0);
447 for (std::vector<const reco::Candidate*>::const_iterator jet=jets.begin();
448 jet!=jets.end(); ++jet){
449 if ( fabs( (*jet)->eta())>jetetamax_ ) continue;
450 if ( (*jet)->pt()<jetptmin_ ) continue;
451 if ( (*jet)->phi()==excljet.phi()&&(*jet)->eta()==excljet.eta() ) continue;
452 htvec+=(*jet)->p4();
453 }
454 return fabs(deltaPhi(htvec, excljet));
455 }
456
457 std::vector<double> FinalPlots::deltaSumPt_permutations(const std::vector<LorentzV>& p4s)
458 {
459 std::vector<std::vector<double> > ht( 1<<(p4s.size()-1) , std::vector<double>( 2, 0.) );
460 for(unsigned i=0; i < ht.size(); i++) {
461 for(unsigned j=0; j < p4s.size(); j++) {
462 ht [i] [(i/(1<<j))%2] += p4s[j].pt();
463 }
464 }
465 std::vector<double> deltaHT; for(unsigned i=0; i<ht.size(); i++) deltaHT.push_back(fabs(ht[i][0]-ht[i][1]));
466 return deltaHT;
467 }
468
469 double FinalPlots::summedTowerEnergy(CaloTowerDetId& towerId, CaloTowerCollection towers, int ntw)
470 {
471 double summedTowerEnergy=0;
472 for(int iphi = towerId.iphi()-ntw; iphi<=towerId.iphi()+ntw; ++iphi){
473 for(int ieta = towerId.ieta()-ntw; ieta<=towerId.ieta()+ntw; ++ieta){
474 CaloTowerDetId id(ieta,iphi);
475 CaloTowerCollection::const_iterator tower = towers.find(id);
476 if(tower == towers.end() ) continue;
477 summedTowerEnergy+=tower->et();
478 }
479 }
480 return summedTowerEnergy;
481 }
482
483 /*
484 void FinalPlots::createPDFs()
485 {
486 edm::Service<TFileService> fs;
487 if( !fs ){
488 throw edm::Exception( edm::errors::Configuration,
489 "TFile Service is not registered in cfg file" );
490 }
491
492 TCanvas *cHT = fs->make<TCanvas>("cHT","cHT",800,800);
493 cHT->cd(1);
494 HT_->Draw();
495 cHT->Update();
496 cHT->Print("histograms/HT.pdf","Portrait pdf");
497 }
498 */
499
500 // ------------ method called to for each event ------------
501 void
502 FinalPlots::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
503 {
504 using namespace edm;
505 using namespace std;
506
507 if (!histogramsBooked) bookHistograms(iSetup);
508
509 //Make Jet & MET plots: -------------------------------------------------
510 edm::Handle< double > event_weight;
511 iEvent.getByLabel(weightName_, event_weight);
512 weight_ = (event_weight.isValid() ? (*event_weight) : 1.0);
513
514 edm::Handle<edm::View<reco::Candidate> > jet_hnd;
515 iEvent.getByLabel(Jet_, jet_hnd);
516 edm::View<reco::Candidate> Jets = *jet_hnd;
517
518
519 edm::Handle<edm::View<reco::MET> > met_hnd;
520 iEvent.getByLabel(Met_, met_hnd);
521
522 MET_->Fill( met_hnd->front().et(), weight_ );
523
524 //apply JEC for PAT jets:
525 std::vector<const reco::Candidate*> cJets;
526 for (edm::View<reco::Candidate>::const_iterator jet=Jets.begin();
527 jet!=Jets.end(); ++jet){
528 const pat::Jet * patJet = 0;
529 patJet = dynamic_cast <const pat::Jet*> ( &(*jet) );
530 const reco::Candidate * cJet;
531 if (patJet)
532 cJet = new pat::Jet( patJet->correctedJet("part", "b") );
533 else
534 cJet = &(*jet);
535 cJets.push_back( cJet );
536 }
537 // sort jets in Et
538 PtrGreaterByPt<const reco::Candidate*> pTComparator_;
539 std::sort(cJets.begin(), cJets.end(), pTComparator_);
540
541 double ht=0.0, dphimin=999., dphibiased=999.;
542 int jetmult = 0;
543 math::PtEtaPhiMLorentzVector htvec(0.0, 0.0, 0.0, 0.0);
544 std::vector <LorentzV> forAlphaT;
545
546 for (std::vector<const reco::Candidate*>::const_iterator cJet=cJets.begin();
547 cJet!=cJets.end(); ++cJet) {
548
549 if ( fabs((*cJet)->eta())>jetetamax_ ) continue;
550 if ( (*cJet)->pt()<jetptmin_ ) continue;
551 forAlphaT.push_back((*cJet)->p4());
552 htvec+=(*cJet)->p4();
553 ht+=(*cJet)->pt();
554 AllJetsPt_->Fill( (*cJet)->pt() );
555 if (jetmult==0) {
556 Jet1E_->Fill( (*cJet)->energy(), weight_ );
557 Jet1Pt_->Fill( (*cJet)->pt(), weight_ );
558 Jet1Phi_->Fill( (*cJet)->phi(), weight_ );
559 Jet1Eta_->Fill( (*cJet)->eta(), weight_ );
560 }
561 else if (jetmult==1) {
562 Jet2E_->Fill( (*cJet)->energy(), weight_ );
563 Jet2Pt_->Fill( (*cJet)->pt(), weight_ );
564 Jet2Phi_->Fill( (*cJet)->phi(), weight_ );
565 Jet2Eta_->Fill( (*cJet)->eta(), weight_ );
566 }
567 else if (jetmult==2) {
568 Jet3E_->Fill( (*cJet)->energy(), weight_ );
569 Jet3Pt_->Fill( (*cJet)->pt(), weight_ );
570 Jet3Phi_->Fill( (*cJet)->phi(), weight_ );
571 Jet3Eta_->Fill( (*cJet)->eta(), weight_ );
572 }
573 else if (jetmult==3) {
574 Jet4E_->Fill( (*cJet)->energy(), weight_ );
575 Jet4Pt_->Fill( (*cJet)->pt(), weight_ );
576 Jet4Phi_->Fill( (*cJet)->phi(), weight_ );
577 Jet4Eta_->Fill( (*cJet)->eta(), weight_ );
578 }
579 ++jetmult;
580
581 if ( fabs(deltaPhi(**cJet, met_hnd->front())) < dphimin )
582 dphimin = fabs(deltaPhi( **cJet, met_hnd->front()));
583
584 double thisdphi = dPhiBiased(cJets, **cJet);
585 if (thisdphi < dphibiased)
586 dphibiased = thisdphi;
587
588 }
589 HT_ ->Fill( ht, weight_ );
590 MHT_->Fill( htvec.pt(), weight_ );
591 JetMult_->Fill( jetmult, weight_ );
592 dPhiMin_->Fill( dphimin, weight_ );
593 dPhiBiased_->Fill( dphibiased, weight_ );
594
595 //other variables
596 //MPT...
597
598
599 //Analyze Tracks <-> Towers ----------------------------------------------------------------------
600
601 edm::Handle<CaloTowerCollection> towers;
602 iEvent.getByLabel(towers_,towers);
603
604 edm::Handle<reco::TrackCollection> tracks;
605 iEvent.getByLabel(tracks_,tracks);
606 reco::TrackCollection trackcollection = *tracks;
607
608 std::vector<const reco::Track*> trackPtrs;
609 reco::TrackCollection::const_iterator tracki = tracks->begin();
610 for( ; tracki!=tracks->end(); ++tracki ){
611 trackPtrs.push_back( &(*tracki) );
612 }
613
614 // sort tracks in Pt
615 PtrGreaterByPt<const reco::Track*> trackPtComparator_;
616 std::sort(trackPtrs.begin(), trackPtrs.end(), trackPtComparator_);
617
618
619 /*
620 double trkIso=-1.;
621 reco::Track selTrack;
622 //----------------------------------------------------------------
623 //search for most isolated track of good quality
624 //----------------------------------------------------------------
625 //Isolation::const_iterator iso = isolation->begin();
626
627 //these parameters should be defined in the cfg file:
628 double maxEta_ = 2.4;
629 double minPt_ = 5.0;
630 double maxChiSquare_ = 40.0; //just a guess!
631 int minNumOfHits_ = 10;
632
633 reco::TrackCollection::const_iterator track = tracks->begin();
634 for(iso = isolation->begin(); iso!=isolation->end(); ++iso ){
635
636
637 //double isolation = *iso-track->pt();
638 //if(trkIso<0 || isolation<trkIso){
639 // selTrack =*track;
640 // trkIso=isolation;
641 //}
642 }
643 */
644
645
646
647 int trackmult = 0;
648 bool found_isolated_track = false;
649 std::vector<const reco::Track*>::const_iterator track = trackPtrs.begin();
650
651 double trackDeltaR, deltaR;
652 double trackOuterDeltaR, outerDeltaR;
653 reco::Track track1, track2;
654 reco::TrackCollection::const_iterator iso;
655 for( ; track!=trackPtrs.end(); ++track ){ //loop over all tracks
656
657 if( !(fabs((*track)->eta())<tmaxEta_) ) continue;
658 if( !(tminPt_<(*track)->pt()) ) continue;
659 if( !((*track)->normalizedChi2()<tmaxChiSquare_) ) continue;
660 if( !((*track)->found()>tminNumOfHits_) ) continue;
661 //check also for isolation
662 //e.g. check also if track is a Pion (if running on MC)
663
664 AllTracksPt_->Fill( (*track)->pt() );
665 AllTracksPhi_->Fill( (*track)->phi() );
666 if (trackmult==0) {
667 track1 = *(*track);
668 Track1Pt_->Fill( (*track)->pt(), weight_ );
669 Track1Phi_->Fill( (*track)->phi(), weight_ );
670 Track1Eta_->Fill( (*track)->eta(), weight_ );
671 Track1NumOfHits_->Fill( (*track)->found(), weight_ );
672 Track1ChiSquare_->Fill( (*track)->normalizedChi2(), weight_ );
673 Track1NOHvsPhi_->Fill( (*track)->found(), (*track)->phi(), weight_ );
674 Track1PtvsPhi_->Fill( (*track)->pt(), (*track)->phi(), weight_ );
675 }
676 else if (trackmult==1) {
677 track2 = *(*track);
678 Track2Pt_->Fill( (*track)->pt(), weight_ );
679 Track2Phi_->Fill( (*track)->phi(), weight_ );
680 Track2Eta_->Fill( (*track)->eta(), weight_ );
681 Track2NumOfHits_->Fill( (*track)->found(), weight_ );
682 Track2ChiSquare_->Fill( (*track)->normalizedChi2(), weight_ );
683 Track2NOHvsPhi_->Fill( (*track)->found(), (*track)->phi(), weight_ );
684 Track2PtvsPhi_->Fill( (*track)->pt(), (*track)->phi(), weight_ );
685 }
686 else if (trackmult==2) {
687 Track3Pt_->Fill( (*track)->pt(), weight_ );
688 Track3Phi_->Fill( (*track)->phi(), weight_ );
689 Track3Eta_->Fill( (*track)->eta(), weight_ );
690 Track3NumOfHits_->Fill( (*track)->found(), weight_ );
691 Track3ChiSquare_->Fill( (*track)->normalizedChi2(), weight_ );
692 Track3NOHvsPhi_->Fill( (*track)->found(), (*track)->phi(), weight_ );
693 Track3PtvsPhi_->Fill( (*track)->pt(), (*track)->phi(), weight_ );
694 }
695 else if (trackmult==3) {
696 Track4Pt_->Fill( (*track)->pt(), weight_ );
697 Track4Phi_->Fill( (*track)->phi(), weight_ );
698 Track4Eta_->Fill( (*track)->eta(), weight_ );
699 Track4NumOfHits_->Fill( (*track)->found(), weight_ );
700 Track4ChiSquare_->Fill( (*track)->normalizedChi2(), weight_ );
701 Track4NOHvsPhi_->Fill( (*track)->found(), (*track)->phi(), weight_ );
702 Track4PtvsPhi_->Fill( (*track)->pt(), (*track)->phi(), weight_ );
703 }
704 else if (trackmult==14) {
705 Track15Phi_->Fill( (*track)->phi(), weight_ );
706 }
707
708
709
710 //----------------------------------------------------------------
711 //search for highest Pt isolated track that is isolated enough
712 //----------------------------------------------------------------
713 if (!found_isolated_track) //only leading isolated track
714 {
715 trackDeltaR = -1.;
716 trackOuterDeltaR = -1.;
717 iso = tracks->begin();
718 ++iso;
719 for(; iso!=tracks->end(); ++iso )
720 {
721 deltaR = reco::deltaR((*track)->eta(), (*track)->phi(), iso->eta(), iso->phi());
722 outerDeltaR = reco::deltaR((*track)->outerEta(), (*track)->outerPhi(), iso->outerEta(), iso->outerPhi());
723 if (deltaR < tminDeltaR_ || outerDeltaR < tminDeltaR_)
724 {
725 trackDeltaR = -1.;
726 trackOuterDeltaR = -1.;
727 continue;
728 }
729 if(trackDeltaR < 0 || deltaR < trackDeltaR)
730 {
731 trackDeltaR = deltaR;
732 }
733 if(trackOuterDeltaR < 0 || outerDeltaR < trackOuterDeltaR)
734 {
735 trackOuterDeltaR = outerDeltaR;
736 }
737 }
738
739 if (trackDeltaR >= 0)
740 {
741 found_isolated_track = true;
742 IsoTrack1Pt_->Fill( (*track)->pt(), weight_ );
743 IsoTrack1Phi_->Fill( (*track)->phi(), weight_ );
744 IsoTrack1Eta_->Fill( (*track)->eta(), weight_ );
745 IsoTrack1NumOfHits_->Fill( (*track)->found(), weight_ );
746 IsoTrack1ChiSquare_->Fill( (*track)->normalizedChi2(), weight_ );
747 IsoTrack1NOHvsPhi_->Fill( (*track)->found(), (*track)->phi(), weight_ );
748 IsoTrack1PtvsPhi_->Fill( (*track)->pt(), (*track)->phi(), weight_ );
749 IsoTrack1DeltaR_->Fill( trackDeltaR, weight_ );
750 }
751 if (trackOuterDeltaR >= 0)
752 {
753 IsoTrack1OuterDeltaR_->Fill( trackOuterDeltaR, weight_ );
754 }
755
756
757 //Propagate a track to the calorimeter surface:
758 /*
759 edm::ESHandle<MagneticField> field;
760 iSetup.get<IdealMagneticFieldRecord>().get(field);
761 */
762
763
764 edm::ESHandle<CaloGeometry> geometry;
765 iSetup.get<CaloGeometryRecord>().get(geometry);
766 const CaloSubdetectorGeometry* towerGeometry = geometry->getSubdetectorGeometry(DetId::Calo, CaloTowerDetId::SubdetId);
767
768 //these parameters should be defined in the cfg file:
769 double maxDeltaEta_ = 0.3;
770 double maxDeltaPhi_ = 0.3;
771
772
773 double en1x1=0, enSum=0, dPhi=0, dEta=0;
774 if(trackDeltaR >= 0){ // && trkIso<maxIsolation_ ){
775 //----------------------------------------------------------------
776 //propagate track to hcal and
777 //search for closest calo tower
778 //----------------------------------------------------------------
779
780 /*
781 const GlobalPoint vtx((*track)->vx(), (*track)->vy(), (*track)->vz());
782 GlobalVector atHcal((*track)->px(), (*track)->py(), (*track)->pz());//track at hcal
783 toHcal_->propagate( vtx, atHcal, (*track)->charge(), &*field); //no field atm
784 const GlobalPoint poI(atHcal.x(), atHcal.y(), atHcal.z()); //point of incidence
785 CaloTowerDetId towerId = towerGeometry->getClosestCell(poI);
786
787 CaloTowerDetId id(towerId.ieta(),towerId.iphi());
788 CaloTowerCollection::const_iterator selTower = towers->find(id);
789 if(selTower!=towers->end()){
790 */
791
792 // GlobalVector::Polar atOuterTracker((*track)->outerTheta(), (*track)->outerPhi(), 1.5*(*track)->outerRadius());
793 // const GlobalPoint poI(atOuterTracker.x(), atOuterTracker.y(), atOuterTracker.z()); //point of incidence
794 const GlobalPoint poI ( GlobalPoint::Polar((*track)->outerTheta(), (*track)->outerPhi(), 1.5*(*track)->outerRadius()) ); //point of incidence
795 CaloTowerDetId towerId = towerGeometry->getClosestCell(poI);
796
797 CaloTowerDetId id(towerId.ieta(),towerId.iphi());
798 fprintf(stdout, "ieta = %i, iphi = %i\n", towerId.ieta(), towerId.iphi());
799 CaloTowerCollection::const_iterator selTower = towers->find(id);
800 tracksFound++;
801 if(selTower!=towers->end()){
802 towersFound++;
803
804
805 dEta = selTower->eta()-(**track).eta();
806 dPhi = deltaPhi(selTower->phi(),(**track).phi());
807
808 if( fabs(dEta)<maxDeltaEta_ && fabs(dPhi<maxDeltaPhi_) ){
809 for(int iphi = towerId.iphi()-nTowerGroup_; iphi<=towerId.iphi()+nTowerGroup_; ++iphi){
810 for(int ieta = towerId.ieta()-nTowerGroup_; ieta<=towerId.ieta()+nTowerGroup_; ++ieta){
811 CaloTowerDetId id(ieta,iphi);
812 CaloTowerCollection::const_iterator twr = towers->find(id);
813 if(twr == towers->end() ) continue;
814 }
815 }
816 en1x1 = summedTowerEnergy(towerId, *towers, 0);
817 enSum = summedTowerEnergy(towerId, *towers, nTowerGroup_);
818 TrackTower_E1x1_->Fill(en1x1);
819 TrackTower_E3x3_->Fill(enSum);
820 Response_E1x1_->Fill(en1x1 / (*track)->pt());
821 Response_E3x3_->Fill(enSum / (*track)->pt());
822 }
823 }
824 }
825
826 }
827
828
829 double dRmin2 = 99999.;
830 double dEta=0, dPhi=0, dPt=0, dEtaMin, dPhiMin;
831
832 //loop over all towers
833 for (CaloTowerCollection::const_iterator tower = towers->begin(); tower!=towers->end(); ++tower) {
834
835 //dEta = track->eta() - tower->p4( track.vertex() ).eta();
836 dEta = (*track)->outerEta() - tower->eta();
837 dPhi = deltaPhi((*track)->outerPhi(),tower->phi());
838 if (dEta*dEta+dPhi*dPhi<dRmin2) { //find closest tower to track
839 dRmin2 = dEta*dEta+dPhi*dPhi;
840 dPt = (*track)->pt() - tower->pt();
841 dEtaMin = dEta;
842 dPhiMin = dPhi;
843 }
844 }
845
846 //fill histograms
847 TrackTower_dEta_->Fill( dEtaMin );
848 TrackTower_dPhi_->Fill( dPhiMin );
849 TrackTower_dPt_ ->Fill( dPt );
850
851 ++trackmult;
852 }
853 TrackMult_->Fill( trackmult, weight_ );
854
855 if (trackmult == 2)
856 {
857 TwoTracksDeltaPhi_->Fill( reco::deltaPhi(track1.phi(), track2.phi()) );
858 TwoTracksDeltaPt_->Fill( fabs(track1.pt() - track2.pt()) );
859 }
860 }
861
862
863 // ------------ method called once each job just after ending the event loop ------------
864 void
865 FinalPlots::endJob() {
866 fprintf(stdout, "Found %i Towers for %i Tracks.\n", towersFound, tracksFound);
867 }
868
869 //define this as a plug-in
870 DEFINE_FWK_MODULE(FinalPlots);