ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/HbbAnalysis/plugins/HbbTreeMaker.cc
Revision: 1.46
Committed: Tue Oct 25 13:26:51 2011 UTC (13 years, 6 months ago) by agilbert
Content type: text/plain
Branch: MAIN
Changes since 1.45: +393 -367 lines
Log Message:
Significant code re-write.  Compiles under 4_2_4 but may not work as expected.  Files marked as broken may need to be fixed in the future.

File Contents

# Content
1 #include "TLorentzVector.h"
2 #include <limits>
3
4 #include "DataFormats/Common/interface/Handle.h"
5 #include "DataFormats/Common/interface/TriggerResults.h"
6 #include "DataFormats/Common/interface/HLTenums.h"
7 #include "DataFormats/Common/interface/ValueMap.h"
8
9 #include "DataFormats/Candidate/interface/Candidate.h"
10 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
11 #include "DataFormats/Scalers/interface/DcsStatus.h"
12 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
13 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
14
15 #include "DataFormats/MuonReco/interface/Muon.h"
16 #include "DataFormats/MuonReco/interface/MuonFwd.h"
17 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
18 #include "DataFormats/MuonReco/interface/MuonChamberMatch.h"
19 #include "DataFormats/MuonReco/interface/MuonIsolation.h"
20 #include "DataFormats/MuonReco/interface/MuonEnergy.h"
21 #include "DataFormats/MuonReco/interface/MuonTime.h"
22 #include "DataFormats/MuonReco/interface/MuonQuality.h"
23
24 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
25 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
26 #include "DataFormats/RecoCandidate/interface/IsoDepositFwd.h"
27
28
29 #include "DataFormats/VertexReco/interface/Vertex.h"
30 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
31 #include "DataFormats/TrackReco/interface/Track.h"
32 #include "DataFormats/TrackReco/interface/TrackFwd.h"
33 #include "DataFormats/JetReco/interface/GenJet.h"
34
35 #include "DataFormats/PatCandidates/interface/Lepton.h"
36 #include "DataFormats/PatCandidates/interface/Muon.h"
37 #include "DataFormats/PatCandidates/interface/Electron.h"
38 #include "DataFormats/PatCandidates/interface/Tau.h"
39 #include "DataFormats/PatCandidates/interface/Jet.h"
40 #include "DataFormats/PatCandidates/interface/JetCorrFactors.h"
41 #include "DataFormats/PatCandidates/interface/MET.h"
42
43 #include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
44 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
45 #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
46
47 #include "FWCore/ServiceRegistry/interface/Service.h"
48 #include "FWCore/Framework/interface/Run.h"
49 #include "FWCore/Framework/interface/ESHandle.h"
50 #include "CommonTools/UtilAlgos/interface/TFileService.h"
51
52 #include "PhysicsTools/SelectorUtils/interface/SimpleCutBasedElectronIDSelectionFunctor.h"
53 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
54 #include "MagneticField/Engine/interface/MagneticField.h"
55
56 #include "UserCode/HbbAnalysis/interface/Electron.hh"
57 #include "UserCode/HbbAnalysis/interface/Muon.hh"
58 //#include "UserCode/HbbAnalysis/interface/Tau.hh" //CURRENTLY BROKEN
59 #include "UserCode/HbbAnalysis/interface/Jet.hh"
60 #include "UserCode/HbbAnalysis/interface/Met.hh"
61 #include "UserCode/HbbAnalysis/interface/Trigger.hh"
62 #include "UserCode/HbbAnalysis/interface/Vertex.hh"
63 //#include "UserCode/HbbAnalysis/interface/L1Object.hh" //CURRENTLY BROKEN
64 //#include "UserCode/HbbAnalysis/interface/HLTObject.hh" //CURRENTLY BROKEN
65
66 //AJG
67 #include "DataFormats/JetReco/interface/JPTJetCollection.h"
68 #include "DataFormats/JetReco/interface/JPTJet.h"
69 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
70 #include "SimDataFormats/Vertex/interface/SimVertex.h"
71
72 #include "CondFormats/JetMETObjects/interface/JetCorrectionUncertainty.h"
73 #include "CondFormats/JetMETObjects/interface/JetCorrectorParameters.h"
74 #include "JetMETCorrections/Objects/interface/JetCorrectionsRecord.h"
75 #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
76 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
77
78 #include "UserCode/HbbAnalysis/plugins/HbbTreeMaker.hh"
79 #include "boost/regex.hpp"
80 #include "boost/lexical_cast.hpp"
81
82 HbbTreeMaker::HbbTreeMaker(const edm::ParameterSet & pset):
83 jecUncSet_(0),
84 debug_(pset.getParameter<int>("DEBUG")),
85 processData_(false),
86 flavour_(pset.getParameter<unsigned int>("JetFlavour")),
87 doGen_(pset.getParameter<bool>("DOGEN")),
88 genParticleSrc_(pset.getParameter<edm::InputTag>("GenParticles")),
89 genJetSrc_(pset.getParameter<edm::InputTag>("GenJets")),
90 partonJetSrc_(pset.getParameter<edm::InputTag>("PartonJets")),
91 ak7genJetSrc_(pset.getParameter<edm::InputTag>("AK7GenJets")),
92 ak7partonJetSrc_(pset.getParameter<edm::InputTag>("AK7PartonJets")),
93 trackSrc_(pset.getParameter<edm::InputTag>("Tracks")),
94 dcsSrc_(pset.getParameter<edm::InputTag>("DCSInfo")),
95 electronSrc_(pset.getParameter<edm::InputTag>("Electrons")),
96 muonSrc_(pset.getParameter<edm::InputTag>("Muons")),
97 caloTauSrc_(pset.getParameter<edm::InputTag>("CaloTaus")),
98 pfTauSrc_(pset.getParameter<edm::InputTag>("PFTaus")),
99 caloJetSrc_(pset.getParameter<edm::InputTag>("CaloJets")),
100 jptJetSrc_(pset.getParameter<edm::InputTag>("JPTJets")),
101 ak7JetSrc_(pset.getParameter<edm::InputTag>("AK7Jets")),
102 pfJetSrc_(pset.getParameter<edm::InputTag>("PFJets")),
103 ak7pfJetSrc_(pset.getParameter<edm::InputTag>("AK7PFJets")),
104 caloMetSrc_(pset.getParameter<edm::InputTag>("CaloMET")),
105 tcMetSrc_(pset.getParameter<edm::InputTag>("TCMET")),
106 pfMetSrc_(pset.getParameter<edm::InputTag>("PFMET")),
107 //pairSrc_(pset.getParameter<edm::InputTag>("Pair")),
108 //mmPairSrc_(pset.getParameter<edm::InputTag>("MuMuPair")),
109 //etPairSrc_(pset.getParameter<edm::InputTag>("ETauPair")),
110 //mtPairSrc_(pset.getParameter<edm::InputTag>("MuTauPair")),
111 vertexSrc_(pset.getParameter<edm::InputTag>("Vertex")),
112 triggerSrc_(pset.getParameter<edm::InputTag>("Trigger")),
113 hltPaths_(pset.getParameter<std::vector<std::string> >("HLTPaths")),
114 l1CenJetSrc_(pset.getParameter<edm::InputTag>("L1CenJet")),
115 l1TauJetSrc_(pset.getParameter<edm::InputTag>("L1TauJet")),
116 l1FwdJetSrc_(pset.getParameter<edm::InputTag>("L1FwdJet")),
117 hltSummarySrc_(pset.getParameter<edm::InputTag>("HLTSummary")),
118 status1ToKeep_(pset.getParameter<std::vector<std::string> >("Status1ToKeep")),
119 status2ToKeep_(pset.getParameter<std::vector<std::string> >("Status2ToKeep")),
120 status3ToKeep_(pset.getParameter<std::vector<std::string> >("Status3ToKeep")),
121 event_(0),
122 tree_(0)
123 //processVec_(pset.getParameter<std::vector<std::string> >("ProcessVec"))
124 {//constructor
125 for (unsigned i = 0; i < status1ToKeep_.size(); ++i){
126 status1ToKeepRegex_.push_back(boost::regex(status1ToKeep_[i]));
127 }
128 for (unsigned i = 0; i < status2ToKeep_.size(); ++i){
129 status2ToKeepRegex_.push_back(boost::regex(status2ToKeep_[i]));
130 }
131 for (unsigned i = 0; i < status3ToKeep_.size(); ++i){
132 status3ToKeepRegex_.push_back(boost::regex(status3ToKeep_[i]));
133 }
134 }//constructor
135
136 HbbTreeMaker::~HbbTreeMaker()
137 {//destructor
138 if (jecUncSet_){
139 delete jecUncCalo;
140 delete jecUncPF;
141 delete jecUncJPT;
142 }
143
144 }//destructor
145
146
147
148 void HbbTreeMaker::beginJob(){//beginJob
149
150
151 edm::Service<TFileService> lFileService;
152
153 TFileDirectory lDir = lFileService->mkdir("HbbAnalysis");
154
155 tree_ = lDir.make<TTree>("Tree","Tree");
156 tree_->Branch("HbbEvent","HbbAnalysis::HbbEvent",&event_);
157 event_ = new HbbAnalysis::HbbEvent();
158
159 if (debug_) std::cout << "Initialising JetFlavour : " << std::endl;
160
161 lDir = lFileService->mkdir("JetFlavours");
162 jetFlav_.Initialise(lDir, debug_, flavour_);
163
164
165 }//beginJob
166
167
168
169 void HbbTreeMaker::endJob(){//endJob
170 if (!processData_) jetFlav_.printSummary();
171
172 //tree_->Write();
173 //delete tree_;
174 //delete event_;
175
176 }//endJob
177
178 void HbbTreeMaker::beginRun(const edm::Run& aRun, const edm::EventSetup& aEvtSetup){//beginRun
179 bool changed(true);
180 if (hltConfig_.init(aRun,aEvtSetup,"HLT",changed)) {
181 // if init returns TRUE, initialisation has succeeded!
182 if (changed) {
183 // The HLT config has actually changed wrt the previous Run, hence rebook your
184 // histograms or do anything else dependent on the revised HLT config
185 }
186 } else {
187 // if init returns FALSE, initialisation has NOT succeeded, which indicates a problem
188 // with the file and/or code and needs to be investigated!
189 std::cerr << " HLT config extraction failure with process name " << "HLT";
190 // In this case, all access methods will return empty values!
191 }
192
193 }
194
195 void HbbTreeMaker::analyze(const edm::Event& aEvt, const edm::EventSetup& aEvtSetup){//analyze
196
197 //dumpContent(aEvt,"","MuTauPAT");
198 if (debug_) std::cout << "Processing event #" << aEvt.id().event() << std::endl;
199
200
201 static bool firstEvent = true;
202 if (!jecUncSet_){
203 edm::ESHandle<JetCorrectorParametersCollection> JetCorParCollCalo;
204 edm::ESHandle<JetCorrectorParametersCollection> JetCorParCollPF;
205 edm::ESHandle<JetCorrectorParametersCollection> JetCorParCollJPT;
206 aEvtSetup.get<JetCorrectionsRecord>().get("AK5Calo",JetCorParCollCalo);
207 aEvtSetup.get<JetCorrectionsRecord>().get("AK5PF",JetCorParCollPF);
208 aEvtSetup.get<JetCorrectionsRecord>().get("AK5JPT",JetCorParCollJPT);
209 JetCorrectorParameters const & JetCorParCalo = (*JetCorParCollCalo)["Uncertainty"];
210 JetCorrectorParameters const & JetCorParPF = (*JetCorParCollPF)["Uncertainty"];
211 JetCorrectorParameters const & JetCorParJPT = (*JetCorParCollJPT)["Uncertainty"];
212
213 jecUncCalo = new JetCorrectionUncertainty(JetCorParCalo);
214 jecUncPF = new JetCorrectionUncertainty(JetCorParPF);
215 jecUncJPT = new JetCorrectionUncertainty(JetCorParJPT);
216 jecUncSet_ = true;
217 }
218
219 event_->Clear();
220 event_->event(aEvt.id().event());
221 processData_ = aEvt.isRealData();
222
223 event_->run(aEvt.run());
224 event_->lumiBlock(aEvt.luminosityBlock());
225 event_->isRealData(aEvt.isRealData());
226 event_->bx(aEvt.bunchCrossing());
227
228 edm::Handle<reco::BeamSpot> lBeamSpot;
229 try {
230 aEvt.getByLabel(edm::InputTag("offlineBeamSpot"), lBeamSpot);
231 } catch(cms::Exception& e) {
232 std::cout<< "AMM: No beam spot found. Exception : " << e.what() << "." << std::endl;
233 }
234 HbbBeamSpot(lBeamSpot,event_->beamSpot());
235
236 //AJG - This will only work on RECO sample
237 /*
238 std::cout << "Beamspot = (" << lBeamSpot->x0() << "," << lBeamSpot->y0() << "," << lBeamSpot->z0() << ")" << std::endl;
239
240 edm::Handle<edm::SimVertexContainer> simVertexCollection;
241 aEvt.getByLabel("g4SimHits", simVertexCollection);
242 const edm::SimVertexContainer simVC = *(simVertexCollection.product());
243 std::cout << "SimVertexContainer size = " << simVC.size() << std::endl;
244 std::cout << "SimVertex[0] = (" << simVC.at(0).position().x() << ","
245 << simVC.at(0).position().y() << ","
246 << simVC.at(0).position().z() << ")" << std::endl;
247 */
248
249 //used in jet method....
250 edm::Handle<reco::GenParticleCollection> lGenParticles;
251
252 if (!processData_) {
253 edm::Handle<edm::HepMCProduct> mcProd;
254 edm::Handle<GenRunInfoProduct> lRunProd;
255 try {
256 aEvt.getByLabel("generator", mcProd );
257 } catch(cms::Exception& e) {
258 std::cout << "AMM: Collection HepMCProduct not available! Exception : " << e.what() << ". " << std::endl;
259 }
260 try {
261 aEvt.getRun().getByLabel("generator",lRunProd);
262 } catch(cms::Exception& e) {
263 std::cout << "AMM: Collection GenInfoProduct not available! Exception : " << e.what() << ". " << std::endl;
264 }
265
266 if (mcProd.isValid() && lRunProd.isValid()){
267 HbbGenInfo(mcProd,lRunProd);
268 }
269
270 edm::Handle<reco::GenJetCollection> lGenJets;
271 try {
272 aEvt.getByLabel(genJetSrc_,lGenJets);
273 if (debug_) std::cout << "** ngenJets = " << lGenJets->size() << std::endl;
274 } catch(cms::Exception& e) {
275 std::cout << "AMM: Collection GenJets not available! Exception : " << e.what() << ". " << std::endl;
276 }
277
278 //do not save components
279 if (lGenJets.isValid()) HbbGenJets(lGenJets,event_->genjets(),false);
280
281 edm::Handle<reco::GenJetCollection> lPartonJets;
282 try {
283 aEvt.getByLabel(partonJetSrc_,lPartonJets);
284 if (debug_) std::cout << "** npartonJets = " << lPartonJets->size() << std::endl;
285 } catch(cms::Exception& e) {
286 std::cout << "AMM: Collection PartonJets not available! Exception : " << e.what() << ". " << std::endl;
287 }
288
289 //save components
290 if (lPartonJets.isValid()) HbbGenJets(lPartonJets,event_->partonjets(),true);
291
292 //AK7
293 edm::Handle<reco::GenJetCollection> lAk7GenJets;
294 try {
295 aEvt.getByLabel(ak7genJetSrc_,lAk7GenJets);
296 if (debug_) std::cout << "** ngenJets = " << lAk7GenJets->size() << std::endl;
297 } catch(cms::Exception& e) {
298 std::cout << "AMM: Collection GenJets not available! Exception : " << e.what() << ". " << std::endl;
299 }
300
301 //do not save components
302 if (lAk7GenJets.isValid()) HbbGenJets(lAk7GenJets,event_->ak7genjets(),false);
303
304 edm::Handle<reco::GenJetCollection> lAk7PartonJets;
305 try {
306 aEvt.getByLabel(ak7partonJetSrc_,lAk7PartonJets);
307 if (debug_) std::cout << "** npartonJets = " << lAk7PartonJets->size() << std::endl;
308 } catch(cms::Exception& e) {
309 std::cout << "AMM: Collection PartonJets not available! Exception : " << e.what() << ". " << std::endl;
310 }
311
312 //save components
313 if (lAk7PartonJets.isValid()) HbbGenJets(lAk7PartonJets,event_->ak7partonjets(),true);
314
315 edm::Handle<LHEEventProduct> lLHEEvt;
316 try {
317 aEvt.getByType(lLHEEvt);
318 } catch(cms::Exception& e) {
319 std::cout << "AMM: Collection of LHEEventProduct not available! Exception : " << e.what() << ". " << std::endl;
320 }
321
322 if (lLHEEvt.isValid()){
323 HbbLHEInfo(lLHEEvt,event_->lheParticles());
324 }
325
326 edm::Handle<std::vector<PileupSummaryInfo> > lPUInfo;
327 try {
328 aEvt.getByLabel("addPileupInfo",lPUInfo);
329 } catch(cms::Exception& e) {
330 std::cout << "AMM: Collection of PileupSummaryInfo not available! Exception : " << e.what() << ". " << std::endl;
331 }
332
333 if (lPUInfo.isValid()){
334 HbbPUInfo(lPUInfo,event_->puVars());
335 }
336
337 try {
338 aEvt.getByLabel(genParticleSrc_,lGenParticles);
339 if (debug_) std::cout << "** ngenParticles = " << lGenParticles->size() << std::endl;
340 } catch(cms::Exception& e) {
341 std::cout << "AMM: Collection genParticles not available! Exception : " << e.what() << ". " << std::endl;
342 }
343
344 //if (doGen_) HbbParticles(lGenParticles,event_->particles());
345 HbbParticles(lGenParticles,event_->particles(), event_->p4total());
346
347 unsigned int lNPartons = 0;
348 lNPartons = jetFlav_.fillPartons(lGenParticles);
349
350 if (debug_) std::cout << "--- Number of partons = " << lNPartons << "." << std::endl;
351 }
352
353 edm::Handle<std::vector<reco::Vertex> > lRecoVertices;
354 try {
355 aEvt.getByLabel(vertexSrc_, lRecoVertices);
356 if (!lRecoVertices.isValid()){
357 edm::LogInfo("ERROR")<< "Error! Can't get vertex by label. ";
358 }
359 if (debug_) std::cout << "** vertexcollection = " << lRecoVertices->size() << " elements." << std::endl;
360 } catch(cms::Exception& e) {
361 std::cout << "AMM: Collection " << vertexSrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
362 }
363
364 HbbVertices(lRecoVertices,event_->vertices());
365
366 edm::Handle<std::vector<pat::Electron> > lElectronCollection;
367
368 try {
369 aEvt.getByLabel(electronSrc_,lElectronCollection);
370 if (!lElectronCollection.isValid()){
371 edm::LogInfo("ERROR")<< "Error! Can't get electron by label. ";
372 }
373 if (debug_) std::cout << "** electroncollection = " << lElectronCollection->size() << " elements." << std::endl;
374 } catch(cms::Exception& e) {
375 std::cout << "AMM: Collection " << electronSrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
376 }
377
378 HbbElectrons(lElectronCollection,event_->electrons(),lBeamSpot);
379
380 edm::Handle<std::vector<pat::Muon> > lMuonCollection;
381
382 try {
383 aEvt.getByLabel(muonSrc_,lMuonCollection);
384 if (!lMuonCollection.isValid()){
385 edm::LogInfo("ERROR")<< "Error! Can't get muon by label. ";
386 }
387 if (debug_) std::cout << "** muoncollection = " << lMuonCollection->size() << " elements." << std::endl;
388 } catch(cms::Exception& e) {
389 std::cout << "AMM: Collection " << muonSrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
390 }
391
392 HbbMuons(lMuonCollection,lRecoVertices,lBeamSpot,event_->muons());
393
394
395 /*
396 if (!( caloTauSrc_.label()=="" && caloTauSrc_.instance()=="" )) {
397 edm::Handle<std::vector<pat::Tau> > lTauCollection;
398
399 try {
400 aEvt.getByLabel(caloTauSrc_,lTauCollection);
401 if (!lTauCollection.isValid()){
402 edm::LogInfo("ERROR")<< "Error! Can't get caloTau by label. ";
403 }
404 if (debug_) std::cout << "** caloTaucollection = " << lTauCollection->size() << " elements." << std::endl;
405 } catch(cms::Exception& e) {
406 std::cout << "AMM: Collection " << caloTauSrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
407 }
408
409 HbbTaus(lTauCollection,lRecoVertices,event_->caloTaus());
410 }
411
412 edm::Handle<std::vector<pat::Tau> > lPFTauCollection;
413
414 try {
415 aEvt.getByLabel(pfTauSrc_,lPFTauCollection);
416 if (!lPFTauCollection.isValid()){
417 edm::LogInfo("ERROR")<< "Error! Can't get pfTau by label. ";
418 }
419 if (debug_) std::cout << "** pfTaucollection = " << lPFTauCollection->size() << " elements." << std::endl;
420 } catch(cms::Exception& e) {
421 std::cout << "AMM: Collection " << pfTauSrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
422 }
423
424 HbbTaus(lPFTauCollection,lRecoVertices,event_->pfTaus());
425 */
426
427 edm::Handle<std::vector<pat::Jet> > lCaloJetCollection;
428
429 try {
430 aEvt.getByLabel(caloJetSrc_,lCaloJetCollection);
431 if (!lCaloJetCollection.isValid()){
432 edm::LogInfo("ERROR")<< "Error! Can't get caloJets by label. ";
433 }
434 if (debug_) std::cout << "** caloJetcollection = " << lCaloJetCollection->size() << " elements." << std::endl;
435 } catch(cms::Exception& e) {
436 std::cout << "AMM: Collection " << caloJetSrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
437 }
438
439 HbbJets(lCaloJetCollection,jetFlav_,lGenParticles,event_->caloJets());
440
441 //AJG - Process reco JPT Jet Corrections:
442 //This section should be uncommented for testing purposes
443
444 /*
445 edm::Handle<reco::JPTJetCollection > lJptRL2L3RESJetCollection;
446 edm::Handle<reco::JPTJetCollection > lJptRL1L2L3RESJetCollection;
447
448 edm::Handle<reco::JPTJetCollection > lJptRRAWJetCollection;
449 try {
450 aEvt.getByLabel("JetPlusTrackZSPCorJetAntiKt5",lJptRRAWJetCollection);
451 if (!lJptRRAWJetCollection.isValid()){
452 edm::LogInfo("ERROR")<< "Error! Can't get JetPlusZSPCorJetAntiKt5 by label. ";
453 }
454 if (debug_) std::cout << "** jetPlusTrackZSPCorJetAntiKt5 = " << lJptRRAWJetCollection->size() << " elements." << std::endl;
455 } catch(cms::Exception& e) {
456 std::cout << "AJG: Collection not available! Exception : " << e.what() << ". " << std::endl;
457 }
458
459 try {
460 aEvt.getByLabel("ak5JPTJetsL2L3Residual",lJptRL2L3RESJetCollection);
461 aEvt.getByLabel("JetPlusTrackZSPCorJetAntiKt5",lJptRRAWJetCollection);
462 aEvt.getByLabel("ak5JPTJetsL1L2L3Residual",lJptRL1L2L3RESJetCollection);
463 if (!lJptRRAWJetCollection.isValid()){
464 edm::LogInfo("ERROR")<< "Error! Can't get jptRecoJets by label. ";
465 }
466 if (debug_) std::cout << "** jptRecoJetcollection = " << lJptRRAWJetCollection->size() << " elements." << std::endl;
467 } catch(cms::Excepftion& e) {
468 std::cout << "AJG: Collection " << jptJetSrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
469 }
470
471
472 for(reco::JPTJetCollection::const_iterator jptjet = lJptRRAWJetCollection->begin(); jptjet != lJptRRAWJetCollection->end(); ++jptjet ) {
473
474 std::cout << "pT = " << jptjet->pt() << std::endl;
475
476 reco::TrackRefVector tpionsInVInC = jptjet->getPionsInVertexInCalo();
477 std::cout << "Pion Track Count (reco) = " << tpionsInVInC.size() << std::endl;
478 }
479
480 reco::JPTJetCollection::const_iterator jptRAWjet = lJptRRAWJetCollection->begin();
481 reco::JPTJetCollection::const_iterator jptL2L3RESjet = lJptRL2L3RESJetCollection->begin();
482 reco::JPTJetCollection::const_iterator jptL1L2L3RESjet = lJptRL1L2L3RESJetCollection->begin();
483 std::cout << "pT RAW = " << jptRAWjet->pt() << std::endl;
484 std::cout << "pT L2L3RES = " << jptL2L3RESjet->pt() << std::endl;
485 std::cout << "pT L1L2L3RES = " << jptL1L2L3RESjet->pt() << std::endl;
486 */
487
488
489
490 edm::Handle<std::vector<pat::Jet> > lJptJetCollection;
491
492 try {
493 aEvt.getByLabel(jptJetSrc_,lJptJetCollection);
494 if (!lJptJetCollection.isValid()){
495 edm::LogInfo("ERROR")<< "Error! Can't get jptJets by label. ";
496 }
497 if (debug_) std::cout << "** jptJetcollection = " << lJptJetCollection->size() << " elements." << std::endl;
498 } catch(cms::Exception& e) {
499 std::cout << "AMM: Collection " << jptJetSrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
500 }
501
502 //std::cout << "Processing JPT jets:" << std::endl;
503 HbbJets(lJptJetCollection,jetFlav_,lGenParticles,event_->jptJets());
504
505 edm::Handle<std::vector<pat::Jet> > lAk7JetCollection;
506
507 try {
508 aEvt.getByLabel(ak7JetSrc_,lAk7JetCollection);
509 if (!lAk7JetCollection.isValid()){
510 edm::LogInfo("ERROR")<< "Error! Can't get ak7Jets by label. ";
511 }
512 if (debug_) std::cout << "** ak7Jetcollection = " << lAk7JetCollection->size() << " elements." << std::endl;
513 } catch(cms::Exception& e) {
514 std::cout << "AMM: Collection " << ak7JetSrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
515 }
516
517 //std::cout << "Processing JPT jets:" << std::endl;
518 HbbJets(lAk7JetCollection,jetFlav_,lGenParticles,event_->ak7Jets());
519
520 edm::Handle<std::vector<pat::Jet> > lPfJetCollection;
521
522 try {
523 aEvt.getByLabel(pfJetSrc_,lPfJetCollection);
524 if (!lPfJetCollection.isValid()){
525 edm::LogInfo("ERROR")<< "Error! Can't get pfJets by label. ";
526 }
527 if (debug_) std::cout << "** pfJetcollection = " << lPfJetCollection->size() << " elements." << std::endl;
528 } catch(cms::Exception& e) {
529 std::cout << "AMM: Collection " << pfJetSrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
530 }
531
532 //std::cout << "Processing PF jets:" << std::endl;
533 HbbJets(lPfJetCollection,jetFlav_,lGenParticles,event_->pfJets());
534
535 edm::Handle<std::vector<pat::Jet> > lAk7PfJetCollection;
536
537 try {
538 aEvt.getByLabel(ak7pfJetSrc_,lAk7PfJetCollection);
539 if (!lAk7PfJetCollection.isValid()){
540 edm::LogInfo("ERROR")<< "Error! Can't get ak7pfJets by label. ";
541 }
542 if (debug_) std::cout << "** ak7pfJetcollection = " << lAk7PfJetCollection->size() << " elements." << std::endl;
543 } catch(cms::Exception& e) {
544 std::cout << "AMM: Collection " << ak7pfJetSrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
545 }
546
547 //std::cout << "Processing PF jets:" << std::endl;
548 HbbJets(lAk7PfJetCollection,jetFlav_,lGenParticles,event_->ak7pfJets());
549
550
551 edm::Handle<std::vector<pat::MET> > lCaloMetCol;
552
553 try {
554 aEvt.getByLabel(caloMetSrc_,lCaloMetCol);
555 if (!lCaloMetCol.isValid()){
556 edm::LogInfo("ERROR")<< "Error! Can't get caloMet by label. ";
557 }
558 if (debug_) std::cout << "** caloMet = " << lCaloMetCol->size() << " elements." << std::endl;
559 } catch(cms::Exception& e) {
560 std::cout << "AMM: Collection " << caloMetSrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
561 }
562
563 HbbMet(lCaloMetCol,event_->caloMet());
564
565 edm::Handle<std::vector<pat::MET> > lTcMetCol;
566
567 try {
568 aEvt.getByLabel(tcMetSrc_,lTcMetCol);
569 if (!lTcMetCol.isValid()){
570 edm::LogInfo("ERROR")<< "Error! Can't get tcMet by label. ";
571 }
572 if (debug_) std::cout << "** tcMet = " << lTcMetCol->size() << " elements." << std::endl;
573 } catch(cms::Exception& e) {
574 std::cout << "AMM: Collection " << tcMetSrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
575 }
576
577 HbbMet(lTcMetCol,event_->tcMet());
578
579 edm::Handle<std::vector<pat::MET> > lPfMetCol;
580
581 try {
582 aEvt.getByLabel(pfMetSrc_,lPfMetCol);
583 if (!lPfMetCol.isValid()){
584 edm::LogInfo("ERROR")<< "Error! Can't get pfMet by label. ";
585 }
586 if (debug_) std::cout << "** pfMet = " << lPfMetCol->size() << " elements." << std::endl;
587 } catch(cms::Exception& e) {
588 std::cout << "AMM: Collection " << pfMetSrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
589 }
590
591 HbbMet(lPfMetCol,event_->pfMet());
592
593
594
595 //triggers
596 edm::Handle<edm::TriggerResults> lTrigCol;
597 try {
598 aEvt.getByLabel(triggerSrc_,lTrigCol);
599 if (!lTrigCol.isValid()){
600 edm::LogInfo("ERROR")<< "Error! Can't get triggers by label. ";
601 }
602 if (debug_) std::cout << "** triggers = " << lTrigCol->size() << std::endl;
603 } catch(cms::Exception& e) {
604 std::cout << "AMM: Collection " << triggerSrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
605 }
606 if (lTrigCol.isValid()) {
607 const edm::TriggerNames & lNames = aEvt.triggerNames(*lTrigCol);
608 int prescaleSet = hltConfig_.prescaleSet(aEvt, aEvtSetup);
609 HbbTrigger(lTrigCol,lNames,event_->triggers(), prescaleSet);
610 }
611
612 //L1 jet objects
613
614 /*
615 edm::Handle<l1extra::L1JetParticleCollection> lCenJet;
616 edm::Handle<l1extra::L1JetParticleCollection> lFwdJet;
617 edm::Handle<l1extra::L1JetParticleCollection> lTauJet;
618 try {
619 aEvt.getByLabel(l1CenJetSrc_,lCenJet);
620 aEvt.getByLabel(l1TauJetSrc_,lTauJet);
621 aEvt.getByLabel(l1FwdJetSrc_,lFwdJet);
622 } catch(cms::Exception& e) {
623 std::cout << "AMM: L1 Collections " << l1CenJetSrc_ << ", " << l1TauJetSrc_ << ", " << l1FwdJetSrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
624 }
625 if (lCenJet.isValid()) {
626 HbbL1Objects(lCenJet,event_->l1Jets(),1);
627 }
628 if (lTauJet.isValid()) {
629 HbbL1Objects(lTauJet,event_->l1Jets(),2);
630 }
631 if (lFwdJet.isValid()) {
632 HbbL1Objects(lFwdJet,event_->l1Jets(),3);
633 }
634
635
636 edm::Handle<trigger::TriggerEvent> lHltSummary;
637 try {
638 aEvt.getByLabel(hltSummarySrc_,lHltSummary);
639 } catch(cms::Exception& e) {
640 std::cout << "AMM: collection " << hltSummarySrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
641 }
642 if (lHltSummary.isValid()) {
643 HbbHLTObjects(lHltSummary,event_->hltObjects());
644 }
645 */
646
647
648
649 //event_->order();
650 tree_->Fill();
651 firstEvent = false;
652
653 }//analyze
654
655
656 void HbbTreeMaker::HbbBeamSpot(const edm::Handle<reco::BeamSpot> & aBeamSpot,
657 HbbAnalysis::BeamSpot & aBS)
658 {
659
660 if (aBeamSpot.isValid()) {
661 HbbAnalysis::BeamSpotVars lbs;
662 lbs.x0 = aBeamSpot->x0();
663 lbs.y0 = aBeamSpot->y0();
664 lbs.z0 = aBeamSpot->z0();
665 lbs.sigmaZ = aBeamSpot->sigmaZ();
666 lbs.BeamWidthX = aBeamSpot->BeamWidthX();
667 lbs.BeamWidthY = aBeamSpot->BeamWidthY();
668 lbs.x0Error = aBeamSpot->x0Error();
669 lbs.y0Error = aBeamSpot->y0Error();
670 lbs.z0Error = aBeamSpot->z0Error();
671 lbs.sigmaZ0Error = aBeamSpot->sigmaZ0Error();
672 lbs.BeamWidthXError = aBeamSpot->BeamWidthXError();
673 lbs.BeamWidthYError = aBeamSpot->BeamWidthYError();
674
675 aBS.bsVars(lbs);
676 }
677
678 }
679
680
681 void HbbTreeMaker::HbbElectrons(const edm::Handle<std::vector<pat::Electron> > & aCol,
682 std::vector<HbbAnalysis::Electron> & aVec, const edm::Handle<reco::BeamSpot> & aBeamSpot)
683 {//HbbElectrons
684
685 if (aCol.isValid()){
686 if (aCol->size() > 0) {
687
688 unsigned int iEle = 0;
689 for (std::vector<pat::Electron>::const_iterator iter = aCol->begin();
690 iter != aCol->end();
691 ++iter,++iEle)
692 {
693 //if (debug_ > 1) std::cout << "**** Ele #" << iEle << ", pT,eta,phi = " << (*iter).pt() << " " << (*iter).eta() << " " << (*iter).phi() << std::endl;
694 // get the track collection
695
696
697
698 // define your function for WPXX using relative or absolute isolations
699 SimpleCutBasedElectronIDSelectionFunctor patSeleR95(SimpleCutBasedElectronIDSelectionFunctor::relIso95);
700 SimpleCutBasedElectronIDSelectionFunctor patSeleR90(SimpleCutBasedElectronIDSelectionFunctor::relIso90);
701 SimpleCutBasedElectronIDSelectionFunctor patSeleR85(SimpleCutBasedElectronIDSelectionFunctor::relIso85);
702 SimpleCutBasedElectronIDSelectionFunctor patSeleR80(SimpleCutBasedElectronIDSelectionFunctor::relIso80);
703 SimpleCutBasedElectronIDSelectionFunctor patSeleR70(SimpleCutBasedElectronIDSelectionFunctor::relIso70);
704 SimpleCutBasedElectronIDSelectionFunctor patSeleR60(SimpleCutBasedElectronIDSelectionFunctor::relIso60);
705 SimpleCutBasedElectronIDSelectionFunctor patSeleC95(SimpleCutBasedElectronIDSelectionFunctor::cIso95);
706 SimpleCutBasedElectronIDSelectionFunctor patSeleC90(SimpleCutBasedElectronIDSelectionFunctor::cIso90);
707 SimpleCutBasedElectronIDSelectionFunctor patSeleC85(SimpleCutBasedElectronIDSelectionFunctor::cIso85);
708 SimpleCutBasedElectronIDSelectionFunctor patSeleC80(SimpleCutBasedElectronIDSelectionFunctor::cIso80);
709 SimpleCutBasedElectronIDSelectionFunctor patSeleC70(SimpleCutBasedElectronIDSelectionFunctor::cIso70);
710 SimpleCutBasedElectronIDSelectionFunctor patSeleC60(SimpleCutBasedElectronIDSelectionFunctor::cIso60);
711
712
713 //----------------------------------------------------------------------
714 HbbAnalysis::FourMomentum lFourVec;
715 //----------------------------------------------------------------------
716 lFourVec.e = (*iter).energy();
717 lFourVec.px = (*iter).px();
718 lFourVec.py = (*iter).py();
719 lFourVec.pz = (*iter).pz();
720 //----------------------------------------------------------------------
721 HbbAnalysis::LeptonVars lLep;
722 //----------------------------------------------------------------------
723 lLep.vertexPCA.vx = (*iter).vx();
724 lLep.vertexPCA.vy = (*iter).vy();
725 lLep.vertexPCA.vz = (*iter).vz();
726 lLep.charge = (*iter).charge();
727 lLep.dBeamspot= (*iter).gsfTrack()->dxy(*aBeamSpot);
728 //lLep.dBeamspot = (*iter).dB(pat::Electron::BS2D);
729 lLep.dVertex = (*iter).dB(pat::Electron::PV2D);
730 if ((*iter).triggerObjectMatches().size() > 0){
731 lLep.hltMatchPaths = (*iter).triggerObjectMatches().at(0).pathNames(1,1);
732 lLep.hltMatchFilters = (*iter).triggerObjectMatches().at(0).filterLabels();
733 }
734 //Construct a GenParticle if processing MC and a match has been found by PAT
735 if (!processData_ && (*iter).genLepton()){
736 HbbAnalysis::FourMomentum lGenFourVec;
737 HbbAnalysis::GenVars lGen;
738 lGenFourVec.px = (*iter).genLepton()->px();
739 lGenFourVec.py = (*iter).genLepton()->py();
740 lGenFourVec.pz = (*iter).genLepton()->pz();
741 lGenFourVec.e = (*iter).genLepton()->energy();
742 lGen.charge = (*iter).genLepton()->charge();
743 lGen.pdgId = (*iter).genLepton()->pdgId();
744 lGen.status = (*iter).genLepton()->status();
745 lGen.vertex.vx = (*iter).genLepton()->vx();
746 lGen.vertex.vy = (*iter).genLepton()->vy();
747 lGen.vertex.vz = (*iter).genLepton()->vz();
748 lLep.genMatches.push_back(HbbAnalysis::GenParticle(lGenFourVec, lGen));
749 }
750
751
752 //TESTING CODE
753 /*
754 std::cout << "-----------------------------------------------" << std::endl;
755 std::cout << "Electron: " << iEle << std::endl;
756 std::cout << "--Found " << (*iter).triggerObjectMatches().size() << " matched trigger objects" << std::endl;
757 for (unsigned i = 0; i < (*iter).triggerObjectMatches().size(); ++i){
758 std::vector<std::string> HLTpathNames = (*iter).triggerObjectMatches().at(i).pathNames(1,1);
759 std::cout << "---HLT Path Names:" << std::endl;
760 for (unsigned j = 0; j < HLTpathNames.size(); ++j){
761 std::cout << "----" << HLTpathNames.at(j) << std::endl;
762 }
763 std::vector<std::string> HLTfilterLabels = (*iter).triggerObjectMatches().at(i).filterLabels();
764 std::cout << "---HLT FilterLabels:" << std::endl;
765 for (unsigned j = 0; j < HLTfilterLabels.size(); ++j){
766 std::cout << "----" << HLTfilterLabels.at(j) << std::endl;
767 }
768 }
769 */
770
771
772 HbbAnalysis::SCVars lSC;
773 if ( (*iter).superCluster().isAvailable() && (*iter).superCluster().isNonnull() )
774 lSC.eta = (*iter).superCluster()->eta();
775 else lSC.eta = (*iter).eta();
776 lSC.sigmaEtaEta = (*iter).scSigmaEtaEta();
777 lSC.sigmaIEtaIEta = (*iter).scSigmaIEtaIEta();
778 lSC.e1x5 = (*iter).scE1x5();
779 lSC.e2x5Max = (*iter).scE2x5Max();
780 lSC.e5x5 = (*iter).scE5x5();
781 lSC.eOverP = (*iter).eSuperClusterOverP();
782
783 HbbAnalysis::EleIsoVars lIso;
784 lIso.track = (*iter).trackIso();
785 lIso.ecal = (*iter).ecalIso();
786 lIso.hcal = (*iter).hcalIso();
787
788 HbbAnalysis::EleIDVars lID;
789 lID.idAndIso =
790 (patSeleR95(*iter)<<11) | (patSeleR90(*iter)<<10) |
791 (patSeleR85(*iter)<<9) | (patSeleR80(*iter)<<8) |
792 (patSeleR70(*iter)<<7) | (patSeleR60(*iter)<<6) |
793 (patSeleC95(*iter)<<5) | (patSeleC90(*iter)<<4) |
794 (patSeleC85(*iter)<<3) | (patSeleC80(*iter)<<2) |
795 (patSeleC70(*iter)<<1) | (patSeleC60(*iter));
796 std::vector<std::pair<std::string,float> > electronIDsTemp = (*iter).electronIDs();
797 for (unsigned iIDs = 0; iIDs < electronIDsTemp.size(); ++iIDs){
798 lID.electronIDs[electronIDsTemp.at(iIDs).first] = electronIDsTemp.at(iIDs).second;
799 }
800 lID.hOverE = (*iter).hadronicOverEm();
801 lID.deltaPhiIn = (*iter).deltaPhiSuperClusterTrackAtVtx();
802 lID.deltaEtaIn = (*iter).deltaEtaSuperClusterTrackAtVtx();
803 lID.ecalDrivenSeed = (*iter).ecalDrivenSeed();
804 lID.trackerDrivenSeed = (*iter).trackerDrivenSeed();
805
806 aVec.push_back(HbbAnalysis::Electron(lFourVec,lLep,lSC,lIso,lID));
807 }
808 }
809 }
810
811 }//HbbElectrons
812
813
814 void HbbTreeMaker::HbbMuons(const edm::Handle<std::vector<pat::Muon> > & aCol,
815 const edm::Handle<std::vector<reco::Vertex> > & aRecoVertices,
816 const edm::Handle<reco::BeamSpot> & aBeamSpot,
817 std::vector<HbbAnalysis::Muon> & aVec)
818 {//HbbMuons
819
820 if (aCol.isValid()){
821 if (aCol->size() > 0) {
822
823 unsigned int iEle = 0;
824 for (std::vector<pat::Muon>::const_iterator iter = aCol->begin();
825 iter != aCol->end();
826 ++iter,++iEle)
827 {
828 const reco::Muon* recoMuon = dynamic_cast<const reco::Muon*>((*iter).originalObject());
829
830 //select only global and tracker muons
831 if (!recoMuon->isGlobalMuon() || !recoMuon->isTrackerMuon()) continue;
832
833 //----------------------------------------------------------------------
834 HbbAnalysis::FourMomentum lFourVec;
835 //----------------------------------------------------------------------
836 lFourVec.e = (*iter).energy();
837 lFourVec.px = (*iter).px();
838 lFourVec.py = (*iter).py();
839 lFourVec.pz = (*iter).pz();
840 //----------------------------------------------------------------------
841 HbbAnalysis::LeptonVars lLep;
842 //----------------------------------------------------------------------
843 lLep.vertexPCA.vx = (*iter).vx();
844 lLep.vertexPCA.vy = (*iter).vy();
845 lLep.vertexPCA.vz = (*iter).vz();
846 lLep.charge = (*iter).charge();
847 lLep.dBeamspot = (*iter).dB(pat::Muon::BS2D);
848 lLep.dVertex = (*iter).dB(pat::Muon::PV2D);
849 if ((*iter).triggerObjectMatches().size() > 0){
850 lLep.hltMatchPaths = (*iter).triggerObjectMatches().at(0).pathNames(1,1);
851 lLep.hltMatchFilters = (*iter).triggerObjectMatches().at(0).filterLabels();
852 }
853 //Construct a GenParticle if processing MC and a match has been found by PAT
854 if (!processData_ && (*iter).genLepton()){
855 HbbAnalysis::FourMomentum lGenFourVec;
856 HbbAnalysis::GenVars lGen;
857 lGenFourVec.px = (*iter).genLepton()->px();
858 lGenFourVec.py = (*iter).genLepton()->py();
859 lGenFourVec.pz = (*iter).genLepton()->pz();
860 lGenFourVec.e = (*iter).genLepton()->energy();
861 lGen.charge = (*iter).genLepton()->charge();
862 lGen.pdgId = (*iter).genLepton()->pdgId();
863 lGen.status = (*iter).genLepton()->status();
864 lGen.vertex.vx = (*iter).genLepton()->vx();
865 lGen.vertex.vy = (*iter).genLepton()->vy();
866 lGen.vertex.vz = (*iter).genLepton()->vz();
867 lLep.genMatches.push_back(HbbAnalysis::GenParticle(lGenFourVec, lGen));
868 }
869
870
871 //TESTING CODE
872 /*
873 std::cout << "-----------------------------------------------" << std::endl;
874 std::cout << "Muon: " << iEle << std::endl;
875 std::cout << "--Found " << (*iter).triggerObjectMatches().size() << " matched trigger objects" << std::endl;
876 for (unsigned i = 0; i < (*iter).triggerObjectMatches().size(); ++i){
877 std::vector<std::string> HLTpathNames = (*iter).triggerObjectMatches().at(i).pathNames(1,1);
878 std::cout << "---HLT Path Names:" << std::endl;
879 for (unsigned j = 0; j < HLTpathNames.size(); ++j){
880 std::cout << "----" << HLTpathNames.at(j) << std::endl;
881 }
882 std::vector<std::string> HLTfilterLabels = (*iter).triggerObjectMatches().at(i).filterLabels();
883 std::cout << "---HLT FilterLabels:" << std::endl;
884 for (unsigned j = 0; j < HLTfilterLabels.size(); ++j){
885 std::cout << "----" << HLTfilterLabels.at(j) << std::endl;
886 }
887 }
888 */
889
890
891 HbbAnalysis::MuTrkVars lTrk;
892 reco::TrackRef glmuon = recoMuon->globalTrack();
893 reco::TrackRef tkmuon = recoMuon->innerTrack();
894
895 if ( glmuon.isAvailable() && glmuon.isNonnull() ) {
896 if (aBeamSpot.isValid()) {
897 lTrk.dxy = glmuon->dxy(aBeamSpot->position());
898 lTrk.dz = glmuon->dz(aBeamSpot->position());
899 }
900 else {
901 lTrk.dxy = 0;
902 lTrk.dz = 0;
903 }
904 lTrk.normalizedChi2 = glmuon->normalizedChi2();
905 lTrk.muonHits = glmuon->hitPattern().numberOfValidMuonHits();
906 lTrk.charge = glmuon->charge();
907 }
908 else {
909 lTrk.dxy = 0;
910 lTrk.dz = 0;
911 lTrk.normalizedChi2 = 0;
912 lTrk.muonHits = 0;
913 lTrk.charge = 0;
914 }
915 if ( tkmuon.isAvailable() && tkmuon.isNonnull() ) {
916 lTrk.trackerHits = tkmuon->hitPattern().numberOfValidTrackerHits();
917 lTrk.pixelHits = tkmuon->hitPattern().numberOfValidPixelHits();
918 }
919 else {
920 lTrk.trackerHits = 0;
921 lTrk.pixelHits = 0;
922 }
923
924 HbbAnalysis::MuIsoVars lIsoR03;
925 lIsoR03.sumPt = recoMuon->isolationR03().sumPt;
926 lIsoR03.emEt = recoMuon->isolationR03().emEt;
927 lIsoR03.hadEt = recoMuon->isolationR03().hadEt;
928 lIsoR03.nTracks = recoMuon->isolationR03().nTracks;
929
930 HbbAnalysis::MuIsoVars lIsoR05;
931 lIsoR05.sumPt = recoMuon->isolationR05().sumPt;
932 lIsoR05.emEt = recoMuon->isolationR05().emEt;
933 lIsoR05.hadEt = recoMuon->isolationR05().hadEt;
934 lIsoR05.nTracks = recoMuon->isolationR05().nTracks;
935
936 HbbAnalysis::MuIDVars lID;
937 //if (recoMuon->isGlobalMuon()) lID.type = 1;
938 //else if (recoMuon->isTrackerMuon()) lID.type = 2;
939 //else if (recoMuon->isStandAloneMuon()) lID.type = 3;
940 //else if (recoMuon->isCaloMuon()) lID.type = 4;
941 //else lID.type = 0;
942 lID.type = (recoMuon->isCaloMuon()<<3) | (recoMuon->isStandAloneMuon()<<2) | (recoMuon->isTrackerMuon()<<1) | recoMuon->isGlobalMuon();
943
944 if (muon::isGoodMuon(*recoMuon,muon::AllGlobalMuons)) lID.ids.push_back(1);
945 if (muon::isGoodMuon(*recoMuon,muon::AllStandAloneMuons)) lID.ids.push_back(2);
946 if (muon::isGoodMuon(*recoMuon,muon::AllTrackerMuons)) lID.ids.push_back(3);
947 if (muon::isGoodMuon(*recoMuon,muon::TrackerMuonArbitrated)) lID.ids.push_back(4);
948 if (muon::isGoodMuon(*recoMuon,muon::AllArbitrated)) lID.ids.push_back(5);
949 if (muon::isGoodMuon(*recoMuon,muon::GlobalMuonPromptTight)) lID.ids.push_back(6);
950 if (muon::isGoodMuon(*recoMuon,muon::TMLastStationLoose)) lID.ids.push_back(7);
951 if (muon::isGoodMuon(*recoMuon,muon::TMLastStationTight)) lID.ids.push_back(8);
952 if (muon::isGoodMuon(*recoMuon,muon::TM2DCompatibilityLoose)) lID.ids.push_back(9);
953 if (muon::isGoodMuon(*recoMuon,muon::TM2DCompatibilityTight)) lID.ids.push_back(10);
954 if (muon::isGoodMuon(*recoMuon,muon::TMOneStationLoose)) lID.ids.push_back(11);
955 if (muon::isGoodMuon(*recoMuon,muon::TMOneStationTight)) lID.ids.push_back(12);
956 if (muon::isGoodMuon(*recoMuon,muon::TMLastStationOptimizedLowPtLoose)) lID.ids.push_back(13);
957 if (muon::isGoodMuon(*recoMuon,muon::TMLastStationOptimizedLowPtTight)) lID.ids.push_back(14);
958 if (muon::isGoodMuon(*recoMuon,muon::GMTkChiCompatibility)) lID.ids.push_back(15);
959 if (muon::isGoodMuon(*recoMuon,muon::GMStaChiCompatibility)) lID.ids.push_back(16);
960 if (muon::isGoodMuon(*recoMuon,muon::GMTkKinkTight)) lID.ids.push_back(17);
961 if (muon::isGoodMuon(*recoMuon,muon::TMLastStationAngLoose)) lID.ids.push_back(18);
962 if (muon::isGoodMuon(*recoMuon,muon::TMLastStationAngTight)) lID.ids.push_back(19);
963 if (muon::isGoodMuon(*recoMuon,muon::TMOneStationAngLoose)) lID.ids.push_back(20);
964 if (muon::isGoodMuon(*recoMuon,muon::TMOneStationAngTight)) lID.ids.push_back(21);
965 if (muon::isGoodMuon(*recoMuon,muon::TMLastStationOptimizedBarrelLowPtLoose)) lID.ids.push_back(22);
966 if (muon::isGoodMuon(*recoMuon,muon::TMLastStationOptimizedBarrelLowPtTight)) lID.ids.push_back(23);
967
968 lID.caloCompat = recoMuon->caloCompatibility();
969 lID.segCompat = muon::segmentCompatibility(*recoMuon);
970 lID.nChambers = recoMuon->numberOfChambers();
971 lID.nMatchesLoose = recoMuon->numberOfMatches(reco::Muon::NoArbitration);
972 lID.nMatchesMedium = recoMuon->numberOfMatches(reco::Muon::SegmentArbitration);
973 lID.nMatchesTight = recoMuon->numberOfMatches(reco::Muon::SegmentAndTrackArbitration);
974
975 aVec.push_back(HbbAnalysis::Muon(lFourVec,lLep,lTrk,lIsoR03,lIsoR05,lID));
976 }
977 }
978 }
979
980 }//HbbMuons
981
982 /*
983 void HbbTreeMaker::HbbTaus(const edm::Handle<std::vector<pat::Tau> > & aCol,
984 const edm::Handle<std::vector<reco::Vertex> > & aRecoVertices,
985 std::vector<HbbAnalysis::Tau> & aVec)
986 {//HbbTaus
987
988 if (aCol.isValid()){
989 if (aCol->size() > 0) {
990
991 unsigned int iEle = 0;
992 for (std::vector<pat::Tau>::const_iterator iter = aCol->begin();
993 iter != aCol->end();
994 ++iter,++iEle)
995 {
996 //if (debug_ > 1) std::cout << "**** Ele #" << iEle << ", pT,eta,phi = " << (*iter).pt() << " " << (*iter).eta() << " " << (*iter).phi() << std::endl;
997
998 HbbAnalysis::GenVars lGen;
999 if (!processData_ && (*iter).genLepton()){
1000 lGen.valid = true;
1001 lGen.E = (*iter).genLepton()->energy();
1002 lGen.pT = (*iter).genLepton()->pt();
1003 lGen.eta = (*iter).genLepton()->eta();
1004 lGen.y = (*iter).genLepton()->y();
1005 lGen.phi = (*iter).genLepton()->phi();
1006 lGen.charge = (*iter).genLepton()->charge();
1007 lGen.pdgId = (*iter).genLepton()->pdgId();
1008 lGen.status = (*iter).genLepton()->status();
1009 lGen.mass = (*iter).genLepton()->mass();
1010 lGen.vx = (*iter).genLepton()->vx();
1011 lGen.vy = (*iter).genLepton()->vy();
1012 lGen.vz = (*iter).genLepton()->vz();
1013 }
1014 else {
1015 lGen.valid = false;
1016 lGen.E = 0;
1017 lGen.pT = 0;
1018 lGen.eta = 0;
1019 lGen.y = 0;
1020 lGen.phi = 0;
1021 lGen.charge = 0;
1022 lGen.pdgId = 0;
1023 lGen.status = 0;
1024 lGen.mass = 0;
1025 lGen.vx = 0;
1026 lGen.vy = 0;
1027 lGen.vz = 0;
1028 }
1029
1030
1031 HbbAnalysis::GenVars lGenJet;
1032 if (!processData_ && (*iter).genJet()){
1033 lGenJet.valid = true;
1034 lGenJet.E = (*iter).genJet()->energy();
1035 lGenJet.pT = (*iter).genJet()->pt();
1036 lGenJet.eta = (*iter).genJet()->eta();
1037 lGenJet.y = (*iter).genJet()->y();
1038 lGenJet.phi = (*iter).genJet()->phi();
1039 lGenJet.charge = (*iter).genJet()->charge();
1040 lGenJet.pdgId = (*iter).genJet()->pdgId();
1041 lGenJet.status = (*iter).genJet()->status();
1042 lGenJet.mass = (*iter).genJet()->mass();
1043 lGenJet.vx = (*iter).genJet()->vx();
1044 lGenJet.vy = (*iter).genJet()->vy();
1045 lGenJet.vz = (*iter).genJet()->vz();
1046 }
1047 else {
1048 lGenJet.valid = false;
1049 lGenJet.E = 0;
1050 lGenJet.pT = 0;
1051 lGenJet.eta = 0;
1052 lGenJet.y = 0;
1053 lGenJet.phi = 0;
1054 lGenJet.charge = 0;
1055 lGenJet.pdgId = 0;
1056 lGenJet.status = 0;
1057 lGenJet.mass = 0;
1058 lGenJet.vx = 0;
1059 lGenJet.vy = 0;
1060 lGenJet.vz = 0;
1061 }
1062
1063 HbbAnalysis::BaseVars lReco;
1064 lReco.E = (*iter).energy();
1065 lReco.pT = (*iter).pt();
1066 lReco.eta = (*iter).eta();
1067 lReco.y = (*iter).y();
1068 lReco.phi = (*iter).phi();
1069 lReco.charge = (*iter).charge();
1070 lReco.vx = (*iter).vx();
1071 lReco.vy = (*iter).vy();
1072 lReco.vz = (*iter).vz();
1073
1074 bool isCalo = (*iter).isCaloTau();
1075 bool isPF = (*iter).isPFTau();
1076
1077 assert (isCalo == !isPF);
1078
1079 HbbAnalysis::TrkVars lLead;
1080 if (isCalo) {
1081 lLead.signedSipt = (*iter).leadTracksignedSipt();
1082
1083 reco::TrackRef lCaloTrk = (*iter).leadTrack();
1084
1085 if ( lCaloTrk.isAvailable() && lCaloTrk.isNonnull() ) {
1086 lLead.pT = lCaloTrk->pt();
1087 lLead.eta = lCaloTrk->eta();
1088 lLead.phi = lCaloTrk->phi();
1089
1090 lLead.matchDist = reco::deltaR(lCaloTrk->momentum(), (*iter).p4());
1091
1092 if ( aRecoVertices->size() >= 1 ) {
1093 const reco::Vertex& thePrimaryEventVertex = (*aRecoVertices->begin());
1094 lLead.IPxy = lCaloTrk->dxy(thePrimaryEventVertex.position());
1095 lLead.IPz = lCaloTrk->dz(thePrimaryEventVertex.position());
1096 }
1097 else {
1098 lLead.IPxy = 0;
1099 lLead.IPz = 0;
1100 }
1101 }
1102 else {
1103 lLead.pT = 0;
1104 lLead.eta = 0;
1105 lLead.phi = 0;
1106 lLead.matchDist = 0;
1107 lLead.IPxy = 0;
1108 lLead.IPz = 0;
1109 lLead.signedSipt = 0;
1110 }
1111 }//calo
1112 else {
1113 lLead.signedSipt = (*iter).leadPFChargedHadrCandsignedSipt();
1114
1115 reco::PFCandidateRef lHadrCand = (*iter).leadPFChargedHadrCand();
1116
1117 if ( lHadrCand.isAvailable() && lHadrCand.isNonnull() ) {
1118 lLead.pT = lHadrCand->pt();
1119 lLead.eta = lHadrCand->eta();
1120 lLead.phi = lHadrCand->phi();
1121
1122 lLead.matchDist = reco::deltaR(lHadrCand->p4(), (*iter).p4());
1123
1124 reco::TrackRef lTrk = lHadrCand->trackRef();
1125
1126 if ( aRecoVertices->size() >= 1) {
1127 const reco::Vertex& thePrimaryEventVertex = (*aRecoVertices->begin());
1128 lLead.IPxy = lTrk->dxy(thePrimaryEventVertex.position());
1129 lLead.IPz = lTrk->dz(thePrimaryEventVertex.position());
1130 }
1131 else {
1132 lLead.IPxy = 0;
1133 lLead.IPz = 0;
1134 }
1135 }
1136 else {
1137 lLead.pT = 0;
1138 lLead.eta = 0;
1139 lLead.phi = 0;
1140 lLead.matchDist = 0;
1141 lLead.IPxy = 0;
1142 lLead.IPz = 0;
1143 lLead.signedSipt = 0;
1144 }
1145
1146 }//pf
1147
1148
1149
1150 const std::vector<std::pair<std::string,float> > & lIDs = (*iter).tauIDs();
1151 bool lPrint = false;
1152 //a few warning if additional discriminants are found:
1153 if ((isPF && lIDs.size() != 16) ||
1154 (isCalo && lIDs.size() != 3))
1155 lPrint = true;
1156
1157 if (lPrint) {
1158 std::cout << "!!!!!!! Discriminants changed, please update tree !!!!!!!" << std::endl;
1159 std::cout << "--- isCaloTau = " << isCalo << ", isPFTau = " << isPF << std::endl;
1160 std::cout << "------ ID names = " << std::endl;
1161 }
1162
1163
1164 HbbAnalysis::CaloTauIDVars lcaloId;
1165 lcaloId.byIsolation = 0;
1166 lcaloId.byLeadingTrackFinding = 0;
1167 lcaloId.byLeadingTrackPtCut = 0;
1168
1169 HbbAnalysis::PFTauIDVars lpfId;
1170 lpfId.byLeadingTrackFinding = 0;
1171 lpfId.byLeadingTrackPtCut = 0;
1172 lpfId.byTrackIsolation = 0;
1173 lpfId.byECALIsolation = 0;
1174 lpfId.byIsolation = 0;
1175 lpfId.againstElectron = 0;
1176 lpfId.againstMuon = 0;
1177 lpfId.byIsolationUsingLeadingPion = 0;
1178 lpfId.byTaNC = 0;
1179 lpfId.byTaNCfrHalfPercent = 0;
1180 lpfId.byTaNCfrOnePercent = 0;
1181 lpfId.byTaNCfrQuarterPercent = 0;
1182 lpfId.byTaNCfrTenthPercent = 0;
1183 lpfId.ecalIsolationUsingLeadingPion = 0;
1184 lpfId.leadingPionPtCut = 0;
1185 lpfId.trackIsolationUsingLeadingPion = 0;
1186
1187
1188
1189 for (unsigned int id(0); id<lIDs.size(); ++id){
1190
1191 std::string lName = lIDs.at(id).first;
1192 float lDiscri = lIDs.at(id).second;
1193
1194 if (lPrint) std::cout << "--------- " << lName << " = " << lDiscri << std::endl;
1195 //pf
1196
1197 if (isPF) {
1198 if (lName.find("leadingTrackFinding") != lName.npos) lpfId.byLeadingTrackFinding = lDiscri;
1199 if (lName.find("leadingTrackPtCut") != lName.npos) lpfId.byLeadingTrackPtCut = lDiscri;
1200 if (lName.find("trackIsolationUsingLeadingPion") != lName.npos) lpfId.trackIsolationUsingLeadingPion = lDiscri;
1201 if (lName.find("trackIsolation") != lName.npos &&
1202 lName.find("trackIsolationUsingLeadingPion") == lName.npos) lpfId.byTrackIsolation = lDiscri;
1203 if (lName.find("ecalIsolationUsingLeadingPion") != lName.npos) lpfId.ecalIsolationUsingLeadingPion = lDiscri;
1204 if (lName.find("ecalIsolation") != lName.npos &&
1205 lName.find("ecalIsolationUsingLeadingPion") == lName.npos) lpfId.byECALIsolation = lDiscri;
1206 if (lName.find("byIsolationUsingLeadingPion") != lName.npos) lpfId.byIsolationUsingLeadingPion = lDiscri;
1207 if (lName.find("byIsolation") != lName.npos &&
1208 lName.find("byIsolationUsingLeadingPion") == lName.npos) lpfId.byIsolation = lDiscri;
1209 if (lName.find("againstElectron") != lName.npos) lpfId.againstElectron = lDiscri;
1210 if (lName.find("againstMuon") != lName.npos) lpfId.againstMuon = lDiscri;
1211 if (lName.find("byTaNCfrHalfPercent") != lName.npos) lpfId.byTaNCfrHalfPercent = lDiscri;
1212 if (lName.find("byTaNCfrOnePercent") != lName.npos) lpfId.byTaNCfrOnePercent = lDiscri;
1213 if (lName.find("byTaNCfrQuarterPercent") != lName.npos) lpfId.byTaNCfrQuarterPercent = lDiscri;
1214 if (lName.find("byTaNCfrTenthPercent") != lName.npos) lpfId.byTaNCfrTenthPercent = lDiscri;
1215 if (lName.find("byTaNC") != lName.npos &&
1216 lName.find("byTaNCfr") == lName.npos) lpfId.byTaNC = lDiscri;
1217 if (lName.find("leadingPionPtCut") != lName.npos) lpfId.leadingPionPtCut = lDiscri;
1218 }
1219 if (isCalo){
1220 if (lName.find("byIsolation") != lName.npos) lcaloId.byIsolation = lDiscri;
1221 if (lName.find("leadingTrackFinding") != lName.npos) lcaloId.byLeadingTrackFinding = lDiscri;
1222 if (lName.find("leadingTrackPtCut") != lName.npos) lcaloId.byLeadingTrackPtCut = lDiscri;
1223 }
1224
1225
1226 }
1227
1228
1229 if (isCalo){
1230
1231 HbbAnalysis::CaloTauIsoVars lcaloIso;
1232 lcaloIso.nIsoTracks = (*iter).isolationTracks().size();
1233 lcaloIso.nSigTracks = (*iter).signalTracks().size();
1234 lcaloIso.leadTrackHCAL3x3hitsEtSum = (*iter).leadTrackHCAL3x3hitsEtSum();
1235 lcaloIso.leadTrackHCAL3x3hottesthitDEta = (*iter).leadTrackHCAL3x3hottesthitDEta();
1236 lcaloIso.signalTracksInvariantMass = (*iter).signalTracksInvariantMass();
1237 lcaloIso.tracksInvariantMass = (*iter).TracksInvariantMass();
1238 lcaloIso.isolationTracksPtSum = (*iter).isolationTracksPtSum();
1239 lcaloIso.isolationECALhitsEtSum = (*iter).isolationECALhitsEtSum();
1240 lcaloIso.maximumHCALhitEt = (*iter).maximumHCALhitEt();
1241
1242 HbbAnalysis::Tau lObj(lGen,lGenJet,lReco,lLead,lcaloIso,lcaloId);
1243 aVec.push_back(lObj);
1244 }
1245 else {
1246
1247 HbbAnalysis::PFTauIsoVars lpfIso;
1248 lpfIso.nSigCands = (*iter).signalPFCands().size();
1249 lpfIso.nIsoCands = (*iter).isolationPFCands().size();
1250 lpfIso.maximumHCALPFClusterEt = (*iter).maximumHCALPFClusterEt();
1251 //lpfIso.emFraction = (*iter).emFraction();
1252 lpfIso.hcalTotOverPLead = (*iter).hcalTotOverPLead();
1253 lpfIso.hcalMaxOverPLead = (*iter).hcalMaxOverPLead();
1254 lpfIso.hcal3x3OverPLead = (*iter).hcal3x3OverPLead();
1255 lpfIso.ecalStripSumEOverPLead = (*iter).ecalStripSumEOverPLead();
1256 lpfIso.bremsRecoveryEOverPLead = (*iter).bremsRecoveryEOverPLead();
1257
1258 HbbAnalysis::PFTauCandVars lHadr;
1259 lHadr.nSigCands = (*iter).signalPFChargedHadrCands().size();
1260 lHadr.nIsoCands = (*iter).isolationPFChargedHadrCands().size();
1261 lHadr.isolationPtSum = (*iter).isolationPFChargedHadrCandsPtSum();
1262
1263 HbbAnalysis::PFTauCandVars lNeutr;
1264 lNeutr.nSigCands = (*iter).signalPFNeutrHadrCands().size();
1265 lNeutr.nIsoCands = (*iter).isolationPFNeutrHadrCands().size();
1266 lNeutr.isolationPtSum = (*iter).neutralHadronIso();
1267
1268 HbbAnalysis::PFTauCandVars lGamma;
1269 lGamma.nSigCands = (*iter).signalPFGammaCands().size();
1270 lGamma.nIsoCands = (*iter).isolationPFGammaCands().size();
1271 lGamma.isolationPtSum = (*iter).isolationPFGammaCandsEtSum();
1272
1273 HbbAnalysis::PFTauEleIDVars lEleId;
1274 if ( (*iter).electronPreIDTrack().isAvailable() && (*iter).electronPreIDTrack().isNonnull() ) {
1275 lEleId.pT = (*iter).electronPreIDTrack()->pt();
1276 lEleId.eta = (*iter).electronPreIDTrack()->eta();
1277 lEleId.phi = (*iter).electronPreIDTrack()->phi();
1278 }
1279 else {
1280 lEleId.pT = 0;
1281 lEleId.eta = 0;
1282 lEleId.phi = 0;
1283 }
1284
1285 lEleId.output = (*iter).electronPreIDOutput();
1286 lEleId.decision = (*iter).electronPreIDDecision();
1287
1288 HbbAnalysis::PFTauMuIDVars lMuId;
1289 lMuId.caloCompat = (*iter).caloComp();
1290 lMuId.segCompat = (*iter).segComp();
1291 lMuId.decision = (*iter).muonDecision();
1292
1293 HbbAnalysis::Tau lObj(lGen,lGenJet,lReco,lLead,lpfIso,lHadr,lNeutr,lGamma,lpfId,lEleId,lMuId);
1294 aVec.push_back(lObj);
1295 }
1296 }
1297 }
1298 }
1299
1300 }//HbbTaus
1301 */
1302
1303 void HbbTreeMaker::HbbJets(const edm::Handle<std::vector<pat::Jet> > & aCol,
1304 const HbbAnalysis::JetFlavour & aJetFlav,
1305 const edm::Handle<reco::GenParticleCollection> & aGenParticles,
1306 std::vector<HbbAnalysis::Jet> & aVec)
1307 {//HbbJets
1308
1309 if (aCol.isValid()){//valid
1310 if (aCol->size() > 0) {//non empty
1311
1312 unsigned int iEle = 0;
1313 for (std::vector<pat::Jet>::const_iterator iter = aCol->begin();
1314 iter != aCol->end();
1315 ++iter,++iEle)
1316 {//loop on element
1317 //if (debug_ > 1) std::cout << "**** Ele #" << iEle << ", pT,eta,phi = " << (*iter).pt() << " " << (*iter).eta() << " " << (*iter).phi() << std::endl;
1318
1319 //----------------------------------------------------------------------
1320 HbbAnalysis::FourMomentum lFourVec;
1321 //----------------------------------------------------------------------
1322 lFourVec.e = (*iter).energy();
1323 lFourVec.px = (*iter).px();
1324 lFourVec.py = (*iter).py();
1325 lFourVec.pz = (*iter).pz();
1326 //----------------------------------------------------------------------
1327 HbbAnalysis::JetVars lJet;
1328 //----------------------------------------------------------------------
1329 unsigned int lFlav = 0;
1330 if (!processData_ && aJetFlav.nPartons()) {
1331 lFlav = aJetFlav.partonMatchingGenJet((*iter),aGenParticles,0.4).second;
1332 }
1333 lJet.mcFlavour = lFlav;
1334 lJet.partonFlavour = (*iter).partonFlavour();
1335 lJet.nAssociatedTracks = ((*iter).associatedTracks()).size();
1336 lJet.etaMean = (*iter).etaPhiStatistics().etaMean;
1337 lJet.phiMean = (*iter).etaPhiStatistics().phiMean;
1338 lJet.etaEtaMoment = (*iter).etaPhiStatistics().etaEtaMoment;
1339 lJet.phiPhiMoment = (*iter).etaPhiStatistics().phiPhiMoment;
1340 lJet.etaPhiMoment = (*iter).etaPhiStatistics().etaPhiMoment;
1341 //Construct a GenParticle if processing MC and a match has been found by PAT
1342 if (!processData_ && (*iter).genParton()){
1343 HbbAnalysis::FourMomentum lGenFourVec;
1344 HbbAnalysis::GenVars lGen;
1345 lGenFourVec.px = (*iter).genParton()->px();
1346 lGenFourVec.py = (*iter).genParton()->py();
1347 lGenFourVec.pz = (*iter).genParton()->pz();
1348 lGenFourVec.e = (*iter).genParton()->energy();
1349 lGen.charge = (*iter).genParton()->charge();
1350 lGen.pdgId = (*iter).genParton()->pdgId();
1351 lGen.status = (*iter).genParton()->status();
1352 lGen.vertex.vx = (*iter).genParton()->vx();
1353 lGen.vertex.vy = (*iter).genParton()->vy();
1354 lGen.vertex.vz = (*iter).genParton()->vz();
1355 lJet.genMatches.push_back(HbbAnalysis::GenParticle(lGenFourVec, lGen));
1356 }
1357 //Construct a GenJet if processing MC and a match has been found by PAT
1358 if (!processData_ && (*iter).genJet()){
1359 HbbAnalysis::FourMomentum lGenJetFourVec;
1360 HbbAnalysis::GenJetVars lGenJet;
1361 lGenJetFourVec.px = (*iter).genJet()->px();
1362 lGenJetFourVec.py = (*iter).genJet()->py();
1363 lGenJetFourVec.pz = (*iter).genJet()->pz();
1364 lGenJetFourVec.e = (*iter).genJet()->energy();
1365 lGenJet.flavour = 0; //Flavour unknown in this context (will be filled for parton jets)
1366 lGenJet.mass = (*iter).genJet()->mass();
1367 lGenJet.nConstituents = (*iter).genJet()->getGenConstituents().size();
1368 lJet.genJetMatches.push_back(HbbAnalysis::GenJet(lGenJetFourVec, lGenJet));
1369 }
1370
1371 HbbAnalysis::JetECorVars lEnergyCorrections;
1372 if ((*iter).jecSetsAvailable()){
1373 std::vector<std::string> lJECnames = (*iter).availableJECSets();
1374 for (unsigned int iSet(0); iSet < lJECnames.size(); ++iSet){
1375 if (debug_) std::cout << " -- JEC SET " << iSet << " " << lJECnames[iSet] << std::endl;
1376 std::vector<std::string> lJEClevels = (*iter).availableJECLevels(iSet);
1377 for (unsigned int iLev(0); iLev<lJEClevels.size(); ++iLev){
1378 if (debug_) std::cout << " ---- JEC level " << iLev << " " << lJEClevels[iLev]
1379 << " , factor = " << (*iter).jecFactor(iLev,pat::JetCorrFactors::NONE,iSet)
1380 << std::endl;
1381 lEnergyCorrections.Levels[(lJEClevels[iLev])] = (*iter).jecFactor(iLev,pat::JetCorrFactors::NONE,iSet);
1382 }
1383 }
1384 }
1385 //Care must be taken here with getUncertainty calls, this appears to "reset" the corrector object and if called again
1386 //without re-setting Eta and Pt will cause a crash.
1387 if(jecUncCalo && jecUncPF && jecUncJPT){
1388 if ((*iter).isCaloJet()) {
1389 jecUncCalo->setJetEta((*iter).eta());
1390 jecUncCalo->setJetPt((*iter).pt());
1391 lEnergyCorrections.Levels["Uncertainty"] = jecUncCalo->getUncertainty(true);
1392 } else if ((*iter).isPFJet()) {
1393 jecUncPF->setJetEta((*iter).eta());
1394 jecUncPF->setJetPt((*iter).pt());
1395 lEnergyCorrections.Levels["Uncertainty"] = jecUncPF->getUncertainty(true);
1396 } else if ((*iter).isJPTJet()) {
1397 jecUncJPT->setJetEta((*iter).eta());
1398 jecUncJPT->setJetPt((*iter).pt());
1399 lEnergyCorrections.Levels["Uncertainty"] = jecUncJPT->getUncertainty(true);
1400 }
1401 }
1402
1403 HbbAnalysis::JetBtagVars lBtag;
1404 lBtag.cSV = (*iter).bDiscriminator("combinedSecondaryVertexBJetTags");
1405 lBtag.cSVMVA = (*iter).bDiscriminator("combinedSecondaryVertexMVABJetTags");
1406 lBtag.iPMVA = (*iter).bDiscriminator("impactParameterMVABJetTags");
1407 lBtag.bProba = (*iter).bDiscriminator("jetBProbabilityBJetTags");
1408 lBtag.probability = (*iter).bDiscriminator("jetProbabilityBJetTags");
1409 lBtag.sSVHP = (*iter).bDiscriminator("simpleSecondaryVertexHighPurBJetTags");
1410 lBtag.sSVHE = (*iter).bDiscriminator("simpleSecondaryVertexHighEffBJetTags");
1411 lBtag.softElectronByPt = ((*iter).bDiscriminator("softElectronByPtBJetTags") < -100) ? -100 : (*iter).bDiscriminator("softElectronByPtBJetTags");
1412 lBtag.softElectronByIP3d = ((*iter).bDiscriminator("softElectronByIP3dBJetTags") < -100) ? -100 : (*iter).bDiscriminator("softElectronByIP3dBJetTags");
1413 lBtag.softMuon = ((*iter).bDiscriminator("softMuonBJetTags") < -100) ? -100 : (*iter).bDiscriminator("softMuonBJetTags");
1414 lBtag.softMuonByPt = ((*iter).bDiscriminator("softMuonByPtBJetTags") < -100) ? -100 : (*iter).bDiscriminator("softMuonByPtBJetTags");
1415 lBtag.softMuonByIP3d = ((*iter).bDiscriminator("softMuonByIP3dBJetTags") < -100) ? -100 : (*iter).bDiscriminator("softMuonByIP3dBJetTags");
1416 lBtag.tCHE = (*iter).bDiscriminator("trackCountingHighEffBJetTags");
1417 lBtag.tCHP = (*iter).bDiscriminator("trackCountingHighPurBJetTags");
1418
1419 //std::cout << " -- New values of b-discri for jet : " << iEle << std::endl
1420 // << " ---- softElecs: " << lBtag.softElectronByPt << " " << lBtag.softElectronByIP3d << std::endl
1421 // << " ---- softMus: " << lBtag.softMuon << " " << lBtag.softMuonByPt << " " << lBtag.softMuonByIP3d << std::endl;
1422
1423
1424
1425 std::vector<HbbAnalysis::JetSecVertexVars> jetSecVertexVars;
1426 for (unsigned iVtx = 0; iVtx < (*iter).tagInfoSecondaryVertex()->nVertices(); ++iVtx){
1427 HbbAnalysis::JetSecVertexVars jetSecVertexVarsTmp;
1428 math::XYZTLorentzVectorD vec = (*iter).tagInfoSecondaryVertex()->secondaryVertex(iVtx).p4();
1429 jetSecVertexVarsTmp.fourVec.e = vec.E();
1430 jetSecVertexVarsTmp.fourVec.px = vec.Px();
1431 jetSecVertexVarsTmp.fourVec.py = vec.Py();
1432 jetSecVertexVarsTmp.fourVec.pz = vec.Pz();
1433 jetSecVertexVarsTmp.vertex.vx = (*iter).tagInfoSecondaryVertex()->secondaryVertex(iVtx).x();
1434 jetSecVertexVarsTmp.vertex.vy = (*iter).tagInfoSecondaryVertex()->secondaryVertex(iVtx).y();
1435 jetSecVertexVarsTmp.vertex.vz = (*iter).tagInfoSecondaryVertex()->secondaryVertex(iVtx).z();
1436 jetSecVertexVars.push_back(jetSecVertexVarsTmp);
1437 }
1438
1439
1440 bool isCalo = (*iter).isCaloJet();
1441 bool isPF = (*iter).isPFJet();
1442 bool isJPT = (*iter).isJPTJet();
1443
1444 //std::cout << " -- isCalo = " << isCalo << ", isPF = " << isPF << std::endl;
1445
1446 //assert (isCalo == !isPF);
1447 HbbAnalysis::JetIDVars lId;
1448 if (isCalo || isJPT) {
1449 lId.fHPD = (*iter).jetID().fHPD;
1450 lId.fRBX = (*iter).jetID().fRBX;
1451 lId.n90Hits = (*iter).jetID().n90Hits;
1452 lId.hitsInN90 = (*iter).jetID().hitsInN90;
1453 lId.restrictedEMF = (*iter).jetID().restrictedEMF;
1454 lId.nHCALTowers = (*iter).jetID().nHCALTowers;
1455 lId.nECALTowers = (*iter).jetID().nECALTowers;
1456 }
1457
1458 if (isCalo){
1459 HbbAnalysis::CaloJetVars lCalo;
1460 lCalo.maxEInEmTowers = (*iter).maxEInEmTowers();
1461 lCalo.maxEInHadTowers = (*iter).maxEInHadTowers();
1462 lCalo.energyFractionHadronic = (*iter).energyFractionHadronic();
1463 lCalo.emEnergyFraction = (*iter).emEnergyFraction();
1464 lCalo.hadEnergyInHB = (*iter).hadEnergyInHB();
1465 lCalo.hadEnergyInHO = (*iter).hadEnergyInHO();
1466 lCalo.hadEnergyInHE = (*iter).hadEnergyInHE();
1467 lCalo.hadEnergyInHF = (*iter).hadEnergyInHF();
1468 lCalo.emEnergyInEB = (*iter).emEnergyInEB();
1469 lCalo.emEnergyInEE = (*iter).emEnergyInEE();
1470 lCalo.emEnergyInHF = (*iter).emEnergyInHF();
1471 lCalo.towersArea = (*iter).towersArea();
1472 lCalo.n90 = (*iter).n90();
1473 lCalo.n60 = (*iter).n60();
1474 HbbAnalysis::Jet lObj(lFourVec,lJet,lCalo,lBtag,lId,lEnergyCorrections);
1475 lObj.secVertexVars(jetSecVertexVars);
1476 aVec.push_back(lObj);
1477 }
1478
1479 HbbAnalysis::JPTPFJetVars lJPTPF;
1480 if (isPF || isJPT){
1481 lJPTPF.chargedEmEnergy = (*iter).chargedEmEnergy();
1482 lJPTPF.neutralEmEnergy = (*iter).neutralEmEnergy();
1483 lJPTPF.muonMultiplicity = (*iter).muonMultiplicity();
1484 lJPTPF.chargedHadronEnergy = (*iter).chargedHadronEnergy();
1485 lJPTPF.neutralHadronEnergy = (*iter).neutralHadronEnergy();
1486 lJPTPF.chargedMultiplicity = (*iter).chargedMultiplicity();
1487 lJPTPF.chargedHadronEnergyFraction = (*iter).chargedHadronEnergyFraction();
1488 lJPTPF.neutralHadronEnergyFraction = (*iter).neutralHadronEnergyFraction();
1489 lJPTPF.chargedEmEnergyFraction = (*iter).chargedEmEnergyFraction();
1490 lJPTPF.neutralEmEnergyFraction = (*iter).neutralEmEnergyFraction();
1491 }
1492 if (isJPT) {
1493 HbbAnalysis::JPTJetVars lJPT;
1494 reco::TrackRefVector pionsInVInC = (*iter).pionsInVertexInCalo();
1495 reco::TrackRefVector pionsInVOuC = (*iter).pionsInVertexOutCalo();
1496 reco::TrackRefVector pionsOuVInC = (*iter).pionsOutVertexInCalo();
1497
1498 reco::TrackRefVector muonsInVInC = (*iter).muonsInVertexInCalo();
1499 reco::TrackRefVector muonsInVOuC = (*iter).muonsInVertexOutCalo();
1500 reco::TrackRefVector muonsOuVInC = (*iter).muonsOutVertexInCalo();
1501
1502 reco::TrackRefVector elecsInVInC = (*iter).elecsInVertexInCalo();
1503 reco::TrackRefVector elecsInVOuC = (*iter).elecsInVertexOutCalo();
1504 reco::TrackRefVector elecsOuVInC = (*iter).elecsOutVertexInCalo();
1505
1506 /*
1507 unsigned test_track_count = pionsInVInC.size() + pionsInVOuC.size() + pionsOuVInC.size();
1508 std::cout << "Total Pion Track Count = " << test_track_count << std::endl;
1509 */
1510
1511 for (reco::TrackRefVector::const_iterator trk_iter = pionsInVInC.begin();
1512 trk_iter != pionsInVInC.end();
1513 ++trk_iter) {
1514 lJPT.particleStatusPt.push_back(std::pair<unsigned int,double>(1,(*trk_iter)->pt()));
1515 }
1516 for (reco::TrackRefVector::const_iterator trk_iter = pionsInVOuC.begin();
1517 trk_iter != pionsInVOuC.end();
1518 ++trk_iter) {
1519 lJPT.particleStatusPt.push_back(std::pair<unsigned int,double>(2,(*trk_iter)->pt()));
1520 }
1521 for (reco::TrackRefVector::const_iterator trk_iter = pionsOuVInC.begin();
1522 trk_iter != pionsOuVInC.end();
1523 ++trk_iter) {
1524 lJPT.particleStatusPt.push_back(std::pair<unsigned int,double>(3,(*trk_iter)->pt()));
1525 }
1526
1527 for (reco::TrackRefVector::const_iterator trk_iter = muonsInVInC.begin();
1528 trk_iter != muonsInVInC.end();
1529 ++trk_iter) {
1530 lJPT.particleStatusPt.push_back(std::pair<unsigned int,double>(4,(*trk_iter)->pt()));
1531 }
1532 for (reco::TrackRefVector::const_iterator trk_iter = muonsInVOuC.begin();
1533 trk_iter != muonsInVOuC.end();
1534 ++trk_iter) {
1535 lJPT.particleStatusPt.push_back(std::pair<unsigned int,double>(5,(*trk_iter)->pt()));
1536 }
1537 for (reco::TrackRefVector::const_iterator trk_iter = muonsOuVInC.begin();
1538 trk_iter != muonsOuVInC.end();
1539 ++trk_iter) {
1540 lJPT.particleStatusPt.push_back(std::pair<unsigned int,double>(6,(*trk_iter)->pt()));
1541 }
1542
1543 for (reco::TrackRefVector::const_iterator trk_iter = elecsInVInC.begin();
1544 trk_iter != elecsInVInC.end();
1545 ++trk_iter) {
1546 lJPT.particleStatusPt.push_back(std::pair<unsigned int,double>(7,(*trk_iter)->pt()));
1547 }
1548 for (reco::TrackRefVector::const_iterator trk_iter = elecsInVOuC.begin();
1549 trk_iter != elecsInVOuC.end();
1550 ++trk_iter) {
1551 lJPT.particleStatusPt.push_back(std::pair<unsigned int,double>(8,(*trk_iter)->pt()));
1552 }
1553 for (reco::TrackRefVector::const_iterator trk_iter = elecsOuVInC.begin();
1554 trk_iter != elecsOuVInC.end();
1555 ++trk_iter) {
1556 lJPT.particleStatusPt.push_back(std::pair<unsigned int,double>(9,(*trk_iter)->pt()));
1557 }
1558
1559 // const reco::TrackRefVector& pionsInVertexInCalo () const{return jptSpecific().pionsInVertexInCalo; }
1560 // const reco::TrackRefVector& pionsInVertexOutCalo() const{return jptSpecific().pionsInVertexOutCalo;}
1561 // const reco::TrackRefVector& pionsOutVertexInCalo() const{return jptSpecific().pionsOutVertexInCalo;}
1562 // const reco::TrackRefVector& muonsInVertexInCalo () const{return jptSpecific().muonsInVertexInCalo; }
1563 // const reco::TrackRefVector& muonsInVertexOutCalo() const{return jptSpecific().muonsInVertexOutCalo;}
1564 // const reco::TrackRefVector& muonsOutVertexInCalo() const{return jptSpecific().muonsOutVertexInCalo;}
1565 // const reco::TrackRefVector& elecsInVertexInCalo () const{return jptSpecific().elecsInVertexInCalo; }
1566 // const reco::TrackRefVector& elecsInVertexOutCalo() const{return jptSpecific().elecsInVertexOutCalo;}
1567 // const reco::TrackRefVector& elecsOutVertexInCalo() const{return jptSpecific().elecsOutVertexInCalo;}
1568 lJPT.zspCorrection = (*iter).zspCorrection();
1569 lJPT.elecMultiplicity = (*iter).elecMultiplicity();
1570
1571 HbbAnalysis::CaloJetVars lCalo;
1572 const reco::JPTJet * lJetRef = dynamic_cast<const reco::JPTJet *>((*iter).originalObject());
1573 edm::RefToBase<reco::Jet> jptjetRef = lJetRef->getCaloJetRef();
1574
1575 // Dynamic_cast to CaloJet object
1576 reco::CaloJet const * rawcalojet =
1577 dynamic_cast<reco::CaloJet const *>( &* jptjetRef);
1578 lJPT.calopT = rawcalojet->pt();
1579 lJPT.caloEta = rawcalojet->eta();
1580 if (debug_) {
1581 std::cout << " -- Raw CaloJet pT = " << rawcalojet->pt() << std::endl;
1582 std::cout << " -- Raw CaloJet Eta = " << rawcalojet->eta() << std::endl;
1583 }
1584 lCalo.maxEInEmTowers = rawcalojet->maxEInEmTowers();
1585 lCalo.maxEInHadTowers = rawcalojet->maxEInHadTowers();
1586 lCalo.energyFractionHadronic = rawcalojet->energyFractionHadronic();
1587 lCalo.emEnergyFraction = rawcalojet->emEnergyFraction();
1588 lCalo.hadEnergyInHB = rawcalojet->hadEnergyInHB();
1589 lCalo.hadEnergyInHO = rawcalojet->hadEnergyInHO();
1590 lCalo.hadEnergyInHE = rawcalojet->hadEnergyInHE();
1591 lCalo.hadEnergyInHF = rawcalojet->hadEnergyInHF();
1592 lCalo.emEnergyInEB = rawcalojet->emEnergyInEB();
1593 lCalo.emEnergyInEE = rawcalojet->emEnergyInEE();
1594 lCalo.emEnergyInHF = rawcalojet->emEnergyInHF();
1595 lCalo.towersArea = rawcalojet->towersArea();
1596 lCalo.n90 = rawcalojet->n90();
1597 lCalo.n60 = rawcalojet->n60();
1598
1599 lJet.etaMean = rawcalojet->etaPhiStatistics().etaMean;
1600 lJet.phiMean = rawcalojet->etaPhiStatistics().phiMean;
1601 lJet.etaEtaMoment = rawcalojet->etaPhiStatistics().etaEtaMoment;
1602 lJet.phiPhiMoment = rawcalojet->etaPhiStatistics().phiPhiMoment;
1603 lJet.etaPhiMoment = rawcalojet->etaPhiStatistics().etaPhiMoment;
1604
1605 HbbAnalysis::Jet lObj(lFourVec,lJet,lCalo,lJPT,lJPTPF,lBtag,lId,lEnergyCorrections);
1606 lObj.secVertexVars(jetSecVertexVars);
1607 aVec.push_back(lObj);
1608 }
1609 if (isPF) {
1610 HbbAnalysis::PFJetVars lPF;
1611 lPF.chargedMuEnergy = (*iter).chargedMuEnergy();
1612 lPF.chargedMuEnergyFraction = (*iter).chargedMuEnergyFraction();
1613 lPF.neutralMultiplicity = (*iter).neutralMultiplicity();
1614 lPF.numberOfDaughters = (*iter).numberOfDaughters();
1615 lPF.HFHadronEnergy = (*iter).HFHadronEnergy();
1616
1617 HbbAnalysis::Jet lObj(lFourVec,lJet,lPF,lJPTPF,lBtag,lEnergyCorrections);
1618 lObj.secVertexVars(jetSecVertexVars);
1619 aVec.push_back(lObj);
1620 }
1621
1622 }//loop on element
1623 }//non empty
1624 }//valid
1625
1626 }//HbbJets
1627
1628 void HbbTreeMaker::HbbMet(const edm::Handle<std::vector<pat::MET> > & aCol,
1629 HbbAnalysis::Met & aMet)
1630 {//HbbMet
1631 if (aCol.isValid()) {
1632 HbbAnalysis::MetVars lGen;
1633 HbbAnalysis::MetVars lReco;
1634
1635 assert(aCol->size() == 1);
1636 const pat::MET & lMet = *(aCol->begin());
1637
1638 lReco.mET = lMet.pt();
1639 lReco.mEx = lMet.px();
1640 lReco.mEy = lMet.py();
1641 lReco.sumET = lMet.sumEt();
1642 lReco.phi = lMet.phi();
1643 lReco.mEtSig = lMet.mEtSig();
1644
1645 const reco::GenMET *lGenMET = lMet.genMET();
1646
1647 if (!processData_ && lGenMET){
1648 lGen.mET = lGenMET->pt();
1649 lGen.mEx = lGenMET->px();
1650 lGen.mEy = lGenMET->py();
1651 lGen.sumET = lGenMET->sumEt();
1652 lGen.phi = lGenMET->phi();
1653 lGen.mEtSig = lGenMET->mEtSig();
1654 }
1655 else {
1656 lGen.mET = 0;
1657 lGen.mEx = 0;
1658 lGen.mEy = 0;
1659 lGen.sumET = 0;
1660 lGen.phi = 0;
1661 lGen.mEtSig = 0;
1662 }
1663
1664 aMet.genVars(lGen);
1665 aMet.recoVars(lReco);
1666 }
1667 }//HbbMet
1668
1669 void HbbTreeMaker::HbbTrigger(const edm::Handle<edm::TriggerResults> & aCol,
1670 const edm::TriggerNames & aNames,
1671 std::vector<HbbAnalysis::Trigger> & aVec, int prescaleSet)
1672 {//HbbTrigger
1673
1674 if (aCol.isValid()){
1675 //edm::TriggerNames lNames;
1676 //lNames.init(*aCol);
1677
1678 //for (unsigned int j=0; j<hltPaths_.size(); j++) {
1679 //bool valid=false;
1680 for (unsigned int i=0; i<aCol->size(); ++i){
1681 std::string trueName = aNames.triggerName(i);//.at(i);
1682 if (aCol->accept(i)){
1683 HbbAnalysis::TriggerVars lTrigVars;
1684 lTrigVars.name = trueName;
1685 lTrigVars.index = i;
1686 lTrigVars.accept = aCol->accept(i);
1687 lTrigVars.prescale = hltConfig_.prescaleValue(prescaleSet, trueName);
1688 HbbAnalysis::Trigger lObj(lTrigVars);
1689 aVec.push_back(lObj);
1690 }//If trigger path is passed
1691 }//Loop through trigger paths
1692 }
1693
1694 }
1695
1696 void HbbTreeMaker::HbbParticles(const edm::Handle<reco::GenParticleCollection> & aCol,
1697 std::vector<HbbAnalysis::GenParticle> & aVec, HbbAnalysis::P4Total & p4total)
1698 {//genparticles
1699
1700
1701 const reco::GenParticle *ptrToFirst = 0;
1702 if (aCol->size() > 0) ptrToFirst = &((*aCol)[0]);
1703 //add genParticle inside vector
1704 p4total.comE = 0.0;
1705 p4total.sumPx = 0.0;
1706 p4total.sumPy = 0.0;
1707 p4total.sumPz = 0.0;
1708 p4total.sumE = 0.0;
1709 for (unsigned int mccount = 0;mccount<aCol->size();++mccount)
1710 {//loop on particles
1711 const reco::GenParticle & p = (*aCol)[mccount];
1712
1713 if (p.status() == 3 && p.pdgId() == 2212){
1714 p4total.comE += p.energy();
1715 }
1716 if (p.status() == 1){
1717 p4total.sumPx += p.px();
1718 p4total.sumPy += p.py();
1719 p4total.sumPz += p.pz();
1720 p4total.sumE += p.energy();
1721 }
1722
1723 bool keep = false;
1724 if (p.status() == 1){
1725 for (unsigned i = 0; i < status1ToKeepRegex_.size(); ++i){
1726 if (boost::regex_match(boost::lexical_cast<std::string>(p.pdgId()),status1ToKeepRegex_[i]) && p.pt() > 5.0) keep = true;
1727 if (abs(p.pdgId()) <= 16) keep = true; //Keep all status 1 leptons, regardless of matches passed through config
1728 }
1729 }
1730 if (p.status() == 2){
1731 for (unsigned i = 0; i < status2ToKeepRegex_.size(); ++i){
1732 if (boost::regex_match(boost::lexical_cast<std::string>(p.pdgId()),status2ToKeepRegex_[i])) keep = true;
1733 }
1734 }
1735 if (p.status() == 3){
1736 for (unsigned i = 0; i < status3ToKeepRegex_.size(); ++i){
1737 if (boost::regex_match(boost::lexical_cast<std::string>(p.pdgId()),status3ToKeepRegex_[i])) keep = true;
1738 }
1739 }
1740
1741 if (keep){
1742
1743 HbbAnalysis::FourMomentum lGenFourVec;
1744 HbbAnalysis::GenVars lGen;
1745 lGenFourVec.px = p.px();
1746 lGenFourVec.py = p.py();
1747 lGenFourVec.pz = p.pz();
1748 lGenFourVec.e = p.energy();
1749 lGen.charge = p.charge();
1750 lGen.pdgId = p.pdgId();
1751 lGen.status = p.status();
1752 lGen.index = mccount;
1753 lGen.vertex.vx = p.vx();
1754 lGen.vertex.vy = p.vy();
1755 lGen.vertex.vz = p.vz();
1756
1757 HbbAnalysis::GenParticle lObj(lGenFourVec,lGen);
1758
1759 for (unsigned i = 0; i < p.numberOfMothers(); ++i){
1760 lObj.setParent((reco::GenParticle*)p.mother(i) - ptrToFirst);
1761 //std::cout << ((reco::GenParticle*)p.mother(i) - ptrToFirst) << " " << p.mother(i) << "\t";
1762 }
1763 //std::cout << std::endl;
1764 //std::cout << "Daughters: ";
1765 for (unsigned i = 0; i < p.numberOfDaughters(); ++i){
1766 lObj.setChild((reco::GenParticle*)p.daughter(i) - ptrToFirst);
1767 //std::cout << ((reco::GenParticle*)p.daughter(i) - ptrToFirst) << " " << p.daughter(i) << "\t";
1768 }
1769 aVec.push_back(lObj);
1770 //std::cout << std::endl;
1771 }
1772 /*
1773 unsigned int nMum = p.numberOfMothers();
1774 //std::cout << mccount << " index = " << const_cast<reco::GenParticle *>(&p)-lBegin << " has " << nMum << " mother(s)." << std::endl;
1775
1776 if ( (!doGen_ &&
1777 (p.status()==3 ||
1778 (p.status()==2 && (abs(p.pdgId())==4 || abs(p.pdgId())==5)) ||
1779 (p.status()==1 && ( (p.pt()>5 && abs(p.pdgId()) > 16) || abs(p.pdgId()) <= 16) )
1780 )) || doGen_){
1781 for(unsigned int mum=0;mum<nMum;++mum){//loop on mothers
1782 const reco::Candidate * pMother = p.mother(mum);
1783 //std::cout << "-- mother index = " << pMother-lBegin << std::endl;
1784 for (unsigned int mccount2 = 0;mccount2<mccount;++mccount2)
1785 {//loop on particles
1786 const reco::Candidate & p2 = (*aCol)[mccount2];
1787 if (pMother == &p2) {
1788 lObj.setParent(mccount2);
1789 break;
1790 }
1791 }
1792 }//loop on mothers
1793 */
1794 }//loop on particles
1795
1796
1797 if (debug_>1){
1798 for (unsigned int imc(0); imc < aVec.size(); ++imc){
1799 //HbbAnalysis::GenParticle & p = aVec.at(imc);
1800 //p.print();
1801 }
1802 }
1803
1804
1805 }//genparticles
1806
1807 void HbbTreeMaker::HbbGenJets(const edm::Handle<reco::GenJetCollection> & aCol,
1808 std::vector<HbbAnalysis::GenJet> & aVec,
1809 const bool aSaveConstituants)
1810 {
1811
1812 if (aCol.isValid()){//valid
1813 if (aCol->size() > 0) {//non empty
1814
1815 unsigned int iEle = 0;
1816 for (std::vector<reco::GenJet>::const_iterator iter = aCol->begin();
1817 iter != aCol->end();
1818 ++iter,++iEle)
1819 {//loop on element
1820 //if (debug_ > 1) std::cout << "**** Ele #" << iEle << ", pT,eta,phi = " << (*iter).pt() << " " << (*iter).eta() << " " << (*iter).phi() << std::endl;
1821
1822 HbbAnalysis::FourMomentum lGenJetFourVec;
1823 HbbAnalysis::GenJetVars lGenJet;
1824 lGenJetFourVec.px = (*iter).px();
1825 lGenJetFourVec.py = (*iter).py();
1826 lGenJetFourVec.pz = (*iter).pz();
1827 lGenJetFourVec.e = (*iter).energy();
1828 lGenJet.mass = (*iter).mass();
1829 lGenJet.nConstituents = (*iter).getGenConstituents().size();
1830 lGenJet.flavour = 0; //Flavour will be set if constituents are added
1831
1832
1833 //only status 1 saved !!!!
1834 //get flavour from list of constituants.
1835 //std::vector <const reco::GenParticle*> lConst = (*iter).getGenConstituents();
1836 //unsigned int nb=0, nc=0;
1837 // for (unsigned int iMC(0); iMC<lConst.size(); ++iMC){
1838 // const reco::GenParticle* lPart = lConst[iMC];
1839 // //std::cout << lPart->pdgId() << " " << fabs(lPart->pdgId()) << " " << abs(lPart->pdgId()) << std::endl;
1840 // if (fabs(lPart->pdgId()) == 5){
1841 // ++nb;
1842 // break;
1843 // }
1844 // if (fabs(lPart->pdgId()) == 4) ++nc;
1845 // }
1846 // if (nb > 0) lGenJet.pdgId = 5;
1847 // else if (nc > 0) lGenJet.pdgId = 4;
1848 // else lGenJet.pdgId = 3;
1849
1850 HbbAnalysis::GenJet lObj(lGenJetFourVec, lGenJet);
1851 if (aSaveConstituants){
1852 for (unsigned int iC(0); iC<(*iter).getGenConstituents().size(); ++iC){
1853 const reco::GenParticle* p = (*iter).getGenConstituent(iC);
1854 HbbAnalysis::FourMomentum lGenFourVec;
1855 HbbAnalysis::GenVars lGen;
1856 lGenFourVec.px = p->px();
1857 lGenFourVec.py = p->py();
1858 lGenFourVec.pz = p->pz();
1859 lGenFourVec.e = p->energy();
1860 lGen.charge = p->charge();
1861 lGen.pdgId = p->pdgId();
1862 lGen.status = p->status();
1863 lGen.index = -1; //We don't know this now
1864 lGen.vertex.vx = p->vx();
1865 lGen.vertex.vy = p->vy();
1866 lGen.vertex.vz = p->vz();
1867 lObj.addConstituent(HbbAnalysis::GenParticle(lGenFourVec,lGen));
1868 }
1869 }
1870 aVec.push_back(lObj);
1871 }
1872 }
1873 }
1874 }
1875
1876 void HbbTreeMaker::HbbVertices(const edm::Handle<std::vector<reco::Vertex> > & aCol,
1877 std::vector<HbbAnalysis::Vertex> & aVec)
1878 {
1879
1880 if (aCol.isValid()) {
1881 for (std::vector<reco::Vertex>::const_iterator iter = aCol->begin();
1882 iter != aCol->end();
1883 ++iter)
1884 {
1885
1886 if (!((*iter).isValid()) || (*iter).isFake()) continue;
1887
1888 HbbAnalysis::VertexVars lVtx;
1889 double sumPtSqTmp = 0;
1890
1891 if ((*iter).tracksSize() > 0) {
1892 for (std::vector<reco::TrackBaseRef>::const_iterator lTrk = (*iter).tracks_begin();
1893 lTrk != (*iter).tracks_end();
1894 ++lTrk) {
1895 sumPtSqTmp += ( ((*(*lTrk)).pt()) * ((*(*lTrk)).pt()) );
1896 }
1897 }
1898
1899 lVtx.sumPtSq = sumPtSqTmp;
1900 lVtx.chi2 = (*iter).chi2();
1901 lVtx.ndof = (*iter).ndof();
1902 lVtx.x = (*iter).x();
1903 lVtx.y = (*iter).y();
1904 lVtx.z = (*iter).z();
1905 lVtx.rho = (*iter).position().Rho();
1906 lVtx.xError = (*iter).xError();
1907 lVtx.yError = (*iter).yError();
1908 lVtx.zError = (*iter).zError();
1909 lVtx.cov01 = (*iter).covariance(0,1);
1910 lVtx.cov02 = (*iter).covariance(0,2);
1911 lVtx.cov12 = (*iter).covariance(1,2);
1912
1913 //AJG
1914 /*
1915 std::cout << "Vertex (" << (*iter).x() << ","
1916 << (*iter).y() << ","
1917 << (*iter).z() << ")" << std::endl;
1918 */
1919
1920 aVec.push_back(HbbAnalysis::Vertex(lVtx));
1921 }
1922 }
1923
1924 }
1925
1926 /*
1927 void HbbTreeMaker::HbbL1Objects(const edm::Handle<l1extra::L1JetParticleCollection> & aCol,
1928 std::vector<HbbAnalysis::L1Object> & aVec,
1929 const unsigned int aType)
1930 {
1931
1932 for (l1extra::L1JetParticleCollection::const_iterator iter = aCol->begin();
1933 iter != aCol->end();
1934 ++iter)
1935 {
1936
1937 HbbAnalysis::L1Vars lVars;
1938 lVars.pT = (*iter).pt();
1939 lVars.ET = (*iter).et();
1940 lVars.eta = (*iter).eta();
1941 lVars.phi = (*iter).phi();
1942 lVars.bx = (*iter).bx();
1943 lVars.type = aType;
1944
1945 HbbAnalysis::L1Object lObj(lVars);
1946 aVec.push_back(lObj);
1947
1948 }
1949
1950 }
1951
1952
1953 void HbbTreeMaker::HbbHLTObjects(const edm::Handle<trigger::TriggerEvent> & aCol,
1954 std::vector<HbbAnalysis::HLTObject> & aVec)
1955 {
1956
1957
1958 //cout
1959 //const trigger::TriggerObjectCollection & toc(aCol->getObjects());
1960 //for (unsigned i=0; i<aCol->sizeFilters(); i++){
1961 //const edm::InputTag & lTag = aCol->filterTag(i);
1962 //std::cout << " -- ele " << i << ": " << lTag << ", key ids = " ;
1963 ////const int index = aCol->filterIndex(lTag);
1964 ////if (index >= aCol->sizeFilters()) {
1965 ////std::cout << " -- Filter " << aTag << " not found !" << std::endl;
1966 ////continue;
1967 ////}
1968 //const trigger::Keys & k = aCol->filterKeys(i);
1969 //for (trigger::Keys::const_iterator ki = k.begin(); ki !=k.end(); ++ki ) {
1970 //std::cout << toc[*ki].id() << ", " ;
1971 //}
1972 //std::cout << std::endl;
1973 //}
1974
1975 }
1976
1977 void HbbTreeMaker::fillHLTVector(const edm::InputTag & aTag,
1978 const edm::Handle<trigger::TriggerEvent> & aCol,
1979 std::vector<HbbAnalysis::HLTObject> & aVec,
1980 const unsigned int aType){
1981
1982 const trigger::TriggerObjectCollection & toc(aCol->getObjects());
1983 const int index = aCol->filterIndex(aTag);
1984 if (index >= aCol->sizeFilters()) {
1985 //std::cout << " -- Filter " << aTag << " not found !" << std::endl;
1986 return;
1987 }
1988
1989 const trigger::Keys & k = aCol->filterKeys(index);
1990
1991 for (trigger::Keys::const_iterator ki = k.begin(); ki !=k.end(); ++ki ) {
1992 HbbAnalysis::HLTVars lVars;
1993 lVars.pT = toc[*ki].pt();
1994 lVars.eta = toc[*ki].eta();
1995 lVars.phi = toc[*ki].phi();
1996 lVars.id = toc[*ki].id();
1997 lVars.mass = toc[*ki].mass();
1998 lVars.type = aType;
1999 HbbAnalysis::HLTObject lObj(lVars);
2000 aVec.push_back(lObj);
2001 }
2002 }
2003 */
2004 void HbbTreeMaker::HbbGenInfo(const edm::Handle<edm::HepMCProduct> & amcProd,
2005 const edm::Handle<GenRunInfoProduct> & aRunProd)
2006 {
2007 const HepMC::GenEvent * genEvt = amcProd->GetEvent();
2008 HbbAnalysis::GenInfo lInfo;
2009
2010 lInfo.processID(genEvt->signal_process_id());
2011 lInfo.ptHat(genEvt->event_scale());
2012
2013 lInfo.internalXS(aRunProd->internalXSec().value(),
2014 aRunProd->internalXSec().error());
2015
2016 lInfo.externalXSLO(aRunProd->externalXSecLO().value(),
2017 aRunProd->externalXSecLO().error());
2018
2019 lInfo.externalXSNLO(aRunProd->externalXSecNLO().value(),
2020 aRunProd->externalXSecNLO().error());
2021
2022 lInfo.filterEff(aRunProd->filterEfficiency());
2023
2024 event_->generatorInfo(lInfo);
2025
2026 }
2027
2028 void HbbTreeMaker::HbbPUInfo(const edm::Handle<std::vector<PileupSummaryInfo> > & aPUInfo,
2029 std::vector<HbbAnalysis::PUVars> & aVec) {
2030 std::vector<PileupSummaryInfo>::const_iterator PVI;
2031 for (PVI = aPUInfo->begin(); PVI != aPUInfo->end(); ++PVI) {
2032 HbbAnalysis::PUVars aVars;
2033 aVars.bunchCrossing = PVI->getBunchCrossing();
2034 aVars.numInteractions = PVI->getPU_NumInteractions();
2035 aVec.push_back(aVars);
2036 }
2037 }
2038
2039 void HbbTreeMaker::HbbLHEInfo(const edm::Handle<LHEEventProduct> & aLHEEvt,
2040 std::vector<HbbAnalysis::GenParticle> & aVec) {
2041
2042 const lhef::HEPEUP lhepeup = aLHEEvt->hepeup();
2043
2044 //4-momentum (px,py,pz,E)+mass
2045 const std::vector<lhef::HEPEUP::FiveVector> lpup = lhepeup.PUP;
2046 //pdgid int
2047 const std::vector<int> lidup = lhepeup.IDUP;
2048 //status int
2049 const std::vector<int> listup = lhepeup.ISTUP;
2050 //mother: pair<int,int>
2051 const std::vector<std::pair<int,int> > lmothup = lhepeup.MOTHUP;
2052
2053
2054 //add genParticle inside vector
2055 for (unsigned int imc = 0;imc<lpup.size();++imc)
2056 {//loop on particles
2057
2058 HbbAnalysis::FourMomentum lFourVec;
2059 HbbAnalysis::GenVars lMC;
2060 lMC.index = imc;
2061
2062 TLorentzVector lVec((lpup[imc])[0],(lpup[imc])[1],(lpup[imc])[2],(lpup[imc])[3]);
2063
2064 lFourVec.e = lVec.E();
2065 lFourVec.px = lVec.Px();
2066 lFourVec.py = lVec.Py();
2067 lFourVec.pz = lVec.Pz();
2068 /*
2069 // Special case if pT = 0 (otherwise ROOT complains)
2070 if (fabs(0.0 - lVec.Pt()) < std::numeric_limits<double>::epsilon()){
2071 if (lVec.Pz() >= 0) {
2072 lMC.eta = 1E10;
2073 lMC.y = 1E10;
2074 } else {
2075 lMC.eta = -1E10;
2076 lMC.y = -1E10;
2077 }
2078 } else {
2079 lMC.eta = lVec.Eta();
2080 lMC.y = lVec.Rapidity();
2081 }
2082 lMC.phi = lVec.Phi();
2083 */
2084 lMC.pdgId = lidup[imc];
2085 lMC.status = listup[imc];
2086
2087 HbbAnalysis::GenParticle lObj(lFourVec,lMC);
2088 lObj.setParent(lmothup[imc].first);
2089 lObj.setParent(lmothup[imc].second);
2090 aVec.push_back(lObj);
2091
2092 }//loop on particles
2093
2094 if (debug_>1){
2095 for (unsigned int imc(0); imc < aVec.size(); ++imc){
2096 //HbbAnalysis::GenParticle & p = aVec.at(imc);
2097 //p.print();
2098 }
2099 }
2100 }
2101
2102 #include "FWCore/Framework/interface/MakerMacros.h"
2103 DEFINE_FWK_MODULE(HbbTreeMaker);
2104
2105