ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/CmsHi/JetAnalysis/modifiedFiles/PFRootEventManager.cc
Revision: 1.1
Committed: Thu Sep 15 22:04:26 2011 UTC (13 years, 7 months ago) by yilmaz
Content type: text/plain
Branch: MAIN
CVS Tags: HiForest_V02_85, HiForest_V02_84, HiForest_V02_83, HiForest_V02_82, HiForest_V02_81, HiForest_V02_80, HiForest_V02_79, HiForest_V02_78, HiForest_V02_77, HiForest_V02_76, HiForest_V02_75, HiForest_V02_74, HiForest_V02_73, HiForest_V02_72, HiForest_V02_71, HiForest_V02_70, HiForest_V02_69, HiForest_V02_68, HiForest_V02_67, HiForest_V02_66, HiForest_V02_65, HiForest_V02_64, HiForest_V02_63, HiForest_V02_62, HiForest_V02_61, HiForest_V02_60, HiForest_V02_59, HiForest_V02_58, HiForest_V02_57, HiForest_V02_56, HiForest_V02_55, HiForest_V02_54, HiForest_V02_53, HiForest_V02_52, HiForest_V02_51, HiForest_V02_50, HiForest_V02_49, HiForest_V02_48, HiForest_V02_47, HiForest_V02_46, HiForest_V02_45, HiForest_V02_44, HiForest_V02_43, HiForest_V02_42, HiForest_V02_41, HiForest_V02_40, HiForest_V02_39, HiForest_V02_38, HiForest_V02_37, HiForest_V02_36, HiForest_V02_35, HiForest_V02_34, HiForest_V02_33, HiForest_V02_32, HiForest_V02_31, HiForest_V02_30, HiForest_V02_27, HiForest_V02_26, QM_2012, HiForest_V02_25, HiForest_V02_24, HiForest_V02_23, HiForest_V02_22, HiForest_V02_21, HiForest_V02_20, HiForest_V02_19, HiForest_V02_18, HiForest_V02_17, HiForest_V02_16, HiForest_V02_15, HiForest_V02_14, HiForest_V02_13, HiForest_V02_12, HiForest_V02_11, HiForest_V02_10, HiForest_V02_09, HiForest_V02_08, HiForest_V02_07, HiForest_V02_06, HiForest_V02_05, HiForest_V02_04, HiForest_V02_03, HiForest_V02_02, HiForest_V02_01, HiForest_V02_00, hi44X_02, hi413_03, hi441_1, hi441_0, hi413_11, hi413_10, hi413_09, hi413_08, hi413_07, hi413_06, hi413_05, hi413_04, hi413_02, hi39X_01, HEAD
Branch point for: branch_44x
Log Message:
muons

File Contents

# User Rev Content
1 yilmaz 1.1 #include "DataFormats/Common/interface/OrphanHandle.h"
2     #include "DataFormats/Provenance/interface/ProductID.h"
3     #include "DataFormats/Common/interface/RefToPtr.h"
4    
5     #include "DataFormats/Math/interface/LorentzVector.h"
6     #include "DataFormats/Math/interface/Point3D.h"
7    
8     #include "DataFormats/ParticleFlowReco/interface/PFLayer.h"
9    
10     #include "DataFormats/ParticleFlowReco/interface/PFBlock.h"
11     #include "DataFormats/ParticleFlowReco/interface/PFBlockElement.h"
12    
13     #include "DataFormats/FWLite/interface/ChainEvent.h"
14    
15     #include "RecoParticleFlow/PFClusterProducer/interface/PFClusterAlgo.h"
16     #include "RecoParticleFlow/PFProducer/interface/PFGeometry.h"
17    
18     #include "RecoParticleFlow/PFRootEvent/interface/PFRootEventManager.h"
19    
20     #include "RecoParticleFlow/PFRootEvent/interface/IO.h"
21    
22     #include "RecoParticleFlow/PFRootEvent/interface/PFJetAlgorithm.h"
23     #include "RecoParticleFlow/PFRootEvent/interface/JetMaker.h"
24    
25     #include "RecoParticleFlow/PFRootEvent/interface/Utils.h"
26     #include "RecoParticleFlow/PFRootEvent/interface/EventColin.h"
27     #include "RecoParticleFlow/PFRootEvent/interface/METManager.h"
28    
29     #include "RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h"
30     #include "RecoParticleFlow/PFClusterTools/interface/PFSCEnergyCalibration.h"
31     #include "RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibrationHF.h"
32     #include "RecoParticleFlow/PFClusterTools/interface/PFClusterCalibration.h"
33     #include "RecoParticleFlow/PFClusterTools/interface/PFEnergyResolution.h"
34    
35     #include "FWCore/ServiceRegistry/interface/Service.h"
36     #include "DQMServices/Core/interface/DQMStore.h"
37     #include "DQMServices/Core/interface/MonitorElement.h"
38    
39     #include "FWCore/FWLite/interface/AutoLibraryLoader.h"
40    
41     #include "TFile.h"
42     #include "TTree.h"
43     #include "TBranch.h"
44     #include "TCutG.h"
45     #include "TVector3.h"
46     #include "TROOT.h"
47    
48     #include <iostream>
49     #include <vector>
50     #include <stdlib.h>
51    
52     using namespace std;
53     using namespace boost;
54     using namespace reco;
55    
56    
57    
58     PFRootEventManager::PFRootEventManager() {}
59    
60    
61    
62     PFRootEventManager::PFRootEventManager(const char* file)
63     :
64     iEvent_(0),
65     options_(0),
66     ev_(0),
67     tree_(0),
68     outTree_(0),
69     outEvent_(0),
70     // clusters_(new reco::PFClusterCollection),
71     eventAuxiliary_( new edm::EventAuxiliary ),
72     clustersECAL_(new reco::PFClusterCollection),
73     clustersHCAL_(new reco::PFClusterCollection),
74     clustersHFEM_(new reco::PFClusterCollection),
75     clustersHFHAD_(new reco::PFClusterCollection),
76     clustersPS_(new reco::PFClusterCollection),
77     pfBlocks_(new reco::PFBlockCollection),
78     pfCandidates_(new reco::PFCandidateCollection),
79     //pfJets_(new reco::PFJetCollection),
80     outFile_(0),
81     calibFile_(0)
82     {
83    
84    
85     // iEvent_=0;
86     h_deltaETvisible_MCEHT_
87     = new TH1F("h_deltaETvisible_MCEHT","Jet Et difference CaloTowers-MC"
88     ,1000,-50.,50.);
89     h_deltaETvisible_MCPF_
90     = new TH1F("h_deltaETvisible_MCPF" ,"Jet Et difference ParticleFlow-MC"
91     ,1000,-50.,50.);
92    
93     readOptions(file, true, true);
94    
95     initializeEventInformation();
96    
97     // maxERecHitEcal_ = -1;
98     // maxERecHitHcal_ = -1;
99    
100     }
101    
102    
103     void PFRootEventManager::initializeEventInformation() {
104    
105     unsigned int nev = ev_->size();
106     for ( unsigned int entry = 0; entry < nev; ++entry ) {
107     ev_->to(entry);
108     const edm::EventBase& iEv = *ev_;
109     mapEventToEntry_[iEv.id().run()][iEv.id().luminosityBlock()][iEv.id().event()] = entry;
110     }
111    
112     cout<<"Number of events: "<< nev
113     <<" starting with event: "<<mapEventToEntry_.begin()->first<<endl;
114     }
115    
116    
117     void PFRootEventManager::reset() {
118    
119     if(outEvent_) {
120     outEvent_->reset();
121     outTree_->GetBranch("event")->SetAddress(&outEvent_);
122     }
123    
124     if ( ev_ && ev_->isValid() )
125     ev_->getTFile()->cd();
126     }
127    
128    
129    
130     void PFRootEventManager::readOptions(const char* file,
131     bool refresh,
132     bool reconnect) {
133    
134     readSpecificOptions(file);
135    
136     cout<<"calling PFRootEventManager::readOptions"<<endl;
137    
138    
139     reset();
140    
141     PFGeometry pfGeometry; // initialize geometry
142    
143     // cout<<"reading options "<<endl;
144    
145     try {
146     if( !options_ )
147     options_ = new IO(file);
148     else if( refresh) {
149     delete options_;
150     options_ = new IO(file);
151     }
152     }
153     catch( const string& err ) {
154     cout<<err<<endl;
155     return;
156     }
157    
158    
159     debug_ = false;
160     options_->GetOpt("rootevent", "debug", debug_);
161    
162    
163     // output text file for calibration
164     string calibfilename;
165     options_->GetOpt("calib","outfile",calibfilename);
166     if (!calibfilename.empty()) {
167     calibFile_ = new std::ofstream(calibfilename.c_str());
168     std::cout << "Calib file name " << calibfilename << " " << calibfilename.c_str() << std::endl;
169     }
170    
171     // output root file ------------------------------------------
172    
173    
174     if(!outFile_) {
175     string outfilename;
176     options_->GetOpt("root","outfile", outfilename);
177     bool doOutTree = false;
178     options_->GetOpt("root","outtree", doOutTree);
179     if(doOutTree) {
180     if(!outfilename.empty() ) {
181     outFile_ = TFile::Open(outfilename.c_str(), "recreate");
182    
183     outFile_->cd();
184     //options_->GetOpt("root","outtree", doOutTree);
185     //if(doOutTree) {
186     // cout<<"do tree"<<endl;
187     outEvent_ = new EventColin();
188     outTree_ = new TTree("Eff","");
189     outTree_->Branch("event","EventColin", &outEvent_,32000,2);
190     }
191     // cout<<"don't do tree"<<endl;
192     }
193     }
194     // PFJet benchmark options and output jetfile to be open before input file!!!--
195    
196     doPFJetBenchmark_ = false;
197     options_->GetOpt("pfjet_benchmark", "on/off", doPFJetBenchmark_);
198    
199     if (doPFJetBenchmark_) {
200     string outjetfilename;
201     options_->GetOpt("pfjet_benchmark", "outjetfile", outjetfilename);
202    
203     bool pfjBenchmarkDebug;
204     options_->GetOpt("pfjet_benchmark", "debug", pfjBenchmarkDebug);
205    
206     bool plotAgainstReco=0;
207     options_->GetOpt("pfjet_benchmark", "plotAgainstReco", plotAgainstReco);
208    
209     bool onlyTwoJets=1;
210     options_->GetOpt("pfjet_benchmark", "onlyTwoJets", onlyTwoJets);
211    
212     double deltaRMax=0.1;
213     options_->GetOpt("pfjet_benchmark", "deltaRMax", deltaRMax);
214    
215     fastsim_=true;
216     options_->GetOpt("Simulation","Fast",fastsim_);
217    
218     PFJetBenchmark_.setup( outjetfilename,
219     pfjBenchmarkDebug,
220     plotAgainstReco,
221     onlyTwoJets,
222     deltaRMax );
223     }
224    
225     // PFMET benchmark options and output jetfile to be open before input file!!!--
226    
227     doPFMETBenchmark_ = false;
228     options_->GetOpt("pfmet_benchmark", "on/off", doPFMETBenchmark_);
229    
230     if (doPFMETBenchmark_) {
231     //COLIN : looks like this benchmark is not written in the standard output file. Any particular reason for it?
232    
233     doMet_ = false;
234     options_->GetOpt("MET", "on/off", doMet_);
235    
236     JECinCaloMet_ = false;
237     options_->GetOpt("pfmet_benchmark", "JECinCaloMET", JECinCaloMet_);
238    
239     std::string outmetfilename;
240     options_->GetOpt("pfmet_benchmark", "outmetfile", outmetfilename);
241    
242     // define here the various benchmark comparison
243     metManager_.reset( new METManager(outmetfilename) );
244     metManager_->addGenBenchmark("PF");
245     metManager_->addGenBenchmark("Calo");
246     if ( doMet_ ) metManager_->addGenBenchmark("recompPF");
247     if (JECinCaloMet_) metManager_->addGenBenchmark("corrCalo");
248    
249     bool pfmetBenchmarkDebug;
250     options_->GetOpt("pfmet_benchmark", "debug", pfmetBenchmarkDebug);
251    
252     MET1cut = 10.0;
253     options_->GetOpt("pfmet_benchmark", "truemetcut", MET1cut);
254    
255     DeltaMETcut = 30.0;
256     options_->GetOpt("pfmet_benchmark", "deltametcut", DeltaMETcut);
257    
258     DeltaPhicut = 0.8;
259     options_->GetOpt("pfmet_benchmark", "deltaphicut", DeltaPhicut);
260    
261    
262     std::vector<unsigned int> vIgnoreParticlesIDs;
263     options_->GetOpt("pfmet_benchmark", "trueMetIgnoreParticlesIDs", vIgnoreParticlesIDs);
264     //std::cout << "FL: vIgnoreParticlesIDs.size() = " << vIgnoreParticlesIDs.size() << std::endl;
265     //std::cout << "FL: first = " << vIgnoreParticlesIDs[0] << std::endl;
266     metManager_->SetIgnoreParticlesIDs(&vIgnoreParticlesIDs);
267    
268     std::vector<unsigned int> trueMetSpecificIdCut;
269     std::vector<double> trueMetSpecificEtaCut;
270     options_->GetOpt("pfmet_benchmark", "trueMetSpecificIdCut", trueMetSpecificIdCut);
271     options_->GetOpt("pfmet_benchmark", "trueMetSpecificEtaCut", trueMetSpecificEtaCut);
272     if (trueMetSpecificIdCut.size()!=trueMetSpecificEtaCut.size()) std::cout << "Warning: PFRootEventManager: trueMetSpecificIdCut.size()!=trueMetSpecificEtaCut.size()" << std::endl;
273     else metManager_->SetSpecificIdCut(&trueMetSpecificIdCut,&trueMetSpecificEtaCut);
274    
275     }
276    
277     doPFCandidateBenchmark_ = true;
278     options_->GetOpt("pfCandidate_benchmark", "on/off", doPFCandidateBenchmark_);
279     if (doPFCandidateBenchmark_) {
280     cout<<"+++ Setting PFCandidate benchmark"<<endl;
281     TDirectory* dir = outFile_->mkdir("DQMData");
282     dir = dir->mkdir("PFTask");
283     dir = dir->mkdir("particleFlowManager");
284     pfCandidateManager_.setDirectory( dir );
285    
286     float dRMax = 0.5;
287     options_->GetOpt("pfCandidate_benchmark", "dRMax", dRMax);
288     float ptMin = 2;
289     options_->GetOpt("pfCandidate_benchmark", "ptMin", ptMin);
290     bool matchCharge = true;
291     options_->GetOpt("pfCandidate_benchmark", "matchCharge", matchCharge);
292     int mode = static_cast<int>(Benchmark::DEFAULT);
293     options_->GetOpt("pfCandidate_benchmark", "mode", mode);
294    
295     pfCandidateManager_.setParameters( dRMax, matchCharge,
296     static_cast<Benchmark::Mode>(mode));
297     pfCandidateManager_.setRange( ptMin, 10e5, -4.5, 4.5, -10, 10);
298     pfCandidateManager_.setup();
299     //COLIN need to set the subdirectory.
300     cout<<"+++ Done "<<endl;
301     }
302    
303     std::string outputFile0;
304     TFile* file0 = 0;
305     TH2F* hBNeighbour0 = 0;
306     TH2F* hENeighbour0 = 0;
307     options_->GetOpt("clustering", "ECAL", outputFile0);
308     if(!outputFile0.empty() ) {
309     file0 = TFile::Open(outputFile0.c_str(),"recreate");
310     hBNeighbour0 = new TH2F("BNeighbour0","f_{Neighbours} vs 1/E_{Seed} (ECAL Barrel)",500, 0., 0.5, 1000,0.,1.);
311     hENeighbour0 = new TH2F("ENeighbour0","f_{Neighbours} vs 1/E_{Seed} (ECAL Endcap)",500, 0., 0.2, 1000,0.,1.);
312     }
313    
314     std::string outputFile1;
315     TFile* file1 = 0;
316     TH2F* hBNeighbour1 = 0;
317     TH2F* hENeighbour1 = 0;
318     options_->GetOpt("clustering", "HCAL", outputFile1);
319     if(!outputFile1.empty() ) {
320     file1 = TFile::Open(outputFile1.c_str(),"recreate");
321     hBNeighbour1 = new TH2F("BNeighbour1","f_{Neighbours} vs 1/E_{Seed} (HCAL Barrel)",500, 0., 0.05, 400,0.,1.);
322     hENeighbour1 = new TH2F("ENeighbour1","f_{Neighbours} vs 1/E_{Seed} (HCAL Endcap)",500, 0., 0.05, 400,0.,1.);
323     }
324    
325     std::string outputFile2;
326     TFile* file2 = 0;
327     TH2F* hBNeighbour2 = 0;
328     TH2F* hENeighbour2 = 0;
329     options_->GetOpt("clustering", "HFEM", outputFile2);
330     if(!outputFile2.empty() ) {
331     file2 = TFile::Open(outputFile2.c_str(),"recreate");
332     hBNeighbour2 = new TH2F("BNeighbour2","f_{Neighbours} vs 1/E_{Seed} (HFEM Barrel)",500, 0., 0.02, 400,0.,1.);
333     hENeighbour2 = new TH2F("ENeighbour2","f_{Neighbours} vs 1/E_{Seed} (HFEM Endcap)",500, 0., 0.02, 400,0.,1.);
334     }
335    
336     std::string outputFile3;
337     TFile* file3 = 0;
338     TH2F* hBNeighbour3 = 0;
339     TH2F* hENeighbour3 = 0;
340     options_->GetOpt("clustering", "HFHAD", outputFile3);
341     if(!outputFile3.empty() ) {
342     file3 = TFile::Open(outputFile3.c_str(),"recreate");
343     hBNeighbour3 = new TH2F("BNeighbour3","f_{Neighbours} vs 1/E_{Seed} (HFHAD Barrel)",500, 0., 0.02, 400,0.,1.);
344     hENeighbour3 = new TH2F("ENeighbour3","f_{Neighbours} vs 1/E_{Seed} (HFHAD Endcap)",500, 0., 0.02, 400,0.,1.);
345     }
346    
347     std::string outputFile4;
348     TFile* file4 = 0;
349     TH2F* hBNeighbour4 = 0;
350     TH2F* hENeighbour4 = 0;
351     options_->GetOpt("clustering", "Preshower", outputFile4);
352     if(!outputFile4.empty() ) {
353     file4 = TFile::Open(outputFile4.c_str(),"recreate");
354     hBNeighbour4 = new TH2F("BNeighbour4","f_{Neighbours} vs 1/E_{Seed} (Preshower Barrel)",200, 0., 1000., 400,0.,1.);
355     hENeighbour4 = new TH2F("ENeighbour4","f_{Neighbours} vs 1/E_{Seed} (Preshower Endcap)",200, 0., 1000., 400,0.,1.);
356     }
357    
358     // input root file --------------------------------------------
359    
360     if( reconnect )
361     connect();
362    
363     // filter --------------------------------------------------------------
364    
365     filterNParticles_ = 0;
366     options_->GetOpt("filter", "nparticles", filterNParticles_);
367    
368     filterHadronicTaus_ = true;
369     options_->GetOpt("filter", "hadronic_taus", filterHadronicTaus_);
370    
371     filterTaus_.clear();
372     options_->GetOpt("filter", "taus", filterTaus_);
373     if( !filterTaus_.empty() &&
374     filterTaus_.size() != 2 ) {
375     cerr<<"PFRootEventManager::ReadOptions, bad filter/taus option."<<endl
376     <<"please use : "<<endl
377     <<"\tfilter taus n_charged n_neutral"<<endl;
378     filterTaus_.clear();
379     }
380    
381    
382     // clustering parameters -----------------------------------------------
383    
384     doClustering_ = true;
385     //options_->GetOpt("clustering", "on/off", doClustering_);
386    
387     bool clusteringDebug = false;
388     options_->GetOpt("clustering", "debug", clusteringDebug );
389    
390     findRecHitNeighbours_ = true;
391     options_->GetOpt("clustering", "findRecHitNeighbours",
392     findRecHitNeighbours_);
393    
394     double threshEcalBarrel = 0.1;
395     options_->GetOpt("clustering", "thresh_Ecal_Barrel", threshEcalBarrel);
396    
397     double threshPtEcalBarrel = 0.0;
398     options_->GetOpt("clustering", "thresh_Pt_Ecal_Barrel", threshPtEcalBarrel);
399    
400     double threshSeedEcalBarrel = 0.3;
401     options_->GetOpt("clustering", "thresh_Seed_Ecal_Barrel",
402     threshSeedEcalBarrel);
403    
404     double threshPtSeedEcalBarrel = 0.0;
405     options_->GetOpt("clustering", "thresh_Pt_Seed_Ecal_Barrel",
406     threshPtSeedEcalBarrel);
407    
408     double threshCleanEcalBarrel = 1E5;
409     options_->GetOpt("clustering", "thresh_Clean_Ecal_Barrel",
410     threshCleanEcalBarrel);
411    
412     std::vector<double> minS4S1CleanEcalBarrel;
413     options_->GetOpt("clustering", "minS4S1_Clean_Ecal_Barrel",
414     minS4S1CleanEcalBarrel);
415    
416     double threshDoubleSpikeEcalBarrel = 10.;
417     options_->GetOpt("clustering", "thresh_DoubleSpike_Ecal_Barrel",
418     threshDoubleSpikeEcalBarrel);
419    
420     double minS6S2DoubleSpikeEcalBarrel = 0.04;
421     options_->GetOpt("clustering", "minS6S2_DoubleSpike_Ecal_Barrel",
422     minS6S2DoubleSpikeEcalBarrel);
423    
424     double threshEcalEndcap = 0.2;
425     options_->GetOpt("clustering", "thresh_Ecal_Endcap", threshEcalEndcap);
426    
427     double threshPtEcalEndcap = 0.0;
428     options_->GetOpt("clustering", "thresh_Pt_Ecal_Endcap", threshPtEcalEndcap);
429    
430     double threshSeedEcalEndcap = 0.8;
431     options_->GetOpt("clustering", "thresh_Seed_Ecal_Endcap",
432     threshSeedEcalEndcap);
433    
434     double threshPtSeedEcalEndcap = 0.0;
435     options_->GetOpt("clustering", "thresh_Pt_Seed_Ecal_Endcap",
436     threshPtSeedEcalEndcap);
437    
438     double threshCleanEcalEndcap = 1E5;
439     options_->GetOpt("clustering", "thresh_Clean_Ecal_Endcap",
440     threshCleanEcalEndcap);
441    
442     std::vector<double> minS4S1CleanEcalEndcap;
443     options_->GetOpt("clustering", "minS4S1_Clean_Ecal_Endcap",
444     minS4S1CleanEcalEndcap);
445    
446     double threshDoubleSpikeEcalEndcap = 1E9;
447     options_->GetOpt("clustering", "thresh_DoubleSpike_Ecal_Endcap",
448     threshDoubleSpikeEcalEndcap);
449    
450     double minS6S2DoubleSpikeEcalEndcap = -1.;
451     options_->GetOpt("clustering", "minS6S2_DoubleSpike_Ecal_Endcap",
452     minS6S2DoubleSpikeEcalEndcap);
453    
454     double showerSigmaEcal = 3;
455     options_->GetOpt("clustering", "shower_Sigma_Ecal",
456     showerSigmaEcal);
457    
458     int nNeighboursEcal = 4;
459     options_->GetOpt("clustering", "neighbours_Ecal", nNeighboursEcal);
460    
461     int posCalcNCrystalEcal = -1;
462     options_->GetOpt("clustering", "posCalc_nCrystal_Ecal",
463     posCalcNCrystalEcal);
464    
465     double posCalcP1Ecal
466     = threshEcalBarrel<threshEcalEndcap ? threshEcalBarrel:threshEcalEndcap;
467     // options_->GetOpt("clustering", "posCalc_p1_Ecal",
468     // posCalcP1Ecal);
469    
470     bool useCornerCellsEcal = false;
471     options_->GetOpt("clustering", "useCornerCells_Ecal",
472     useCornerCellsEcal);
473    
474     clusterAlgoECAL_.setHistos(file0,hBNeighbour0,hENeighbour0);
475    
476     clusterAlgoECAL_.setThreshBarrel( threshEcalBarrel );
477     clusterAlgoECAL_.setThreshSeedBarrel( threshSeedEcalBarrel );
478    
479     clusterAlgoECAL_.setThreshPtBarrel( threshPtEcalBarrel );
480     clusterAlgoECAL_.setThreshPtSeedBarrel( threshPtSeedEcalBarrel );
481    
482     clusterAlgoECAL_.setThreshCleanBarrel(threshCleanEcalBarrel);
483     clusterAlgoECAL_.setS4S1CleanBarrel(minS4S1CleanEcalBarrel);
484    
485     clusterAlgoECAL_.setThreshDoubleSpikeBarrel( threshDoubleSpikeEcalBarrel );
486     clusterAlgoECAL_.setS6S2DoubleSpikeBarrel( minS6S2DoubleSpikeEcalBarrel );
487    
488     clusterAlgoECAL_.setThreshEndcap( threshEcalEndcap );
489     clusterAlgoECAL_.setThreshSeedEndcap( threshSeedEcalEndcap );
490    
491     clusterAlgoECAL_.setThreshPtEndcap( threshPtEcalEndcap );
492     clusterAlgoECAL_.setThreshPtSeedEndcap( threshPtSeedEcalEndcap );
493    
494     clusterAlgoECAL_.setThreshCleanEndcap(threshCleanEcalEndcap);
495     clusterAlgoECAL_.setS4S1CleanEndcap(minS4S1CleanEcalEndcap);
496    
497     clusterAlgoECAL_.setThreshDoubleSpikeEndcap( threshDoubleSpikeEcalEndcap );
498     clusterAlgoECAL_.setS6S2DoubleSpikeEndcap( minS6S2DoubleSpikeEcalEndcap );
499    
500     clusterAlgoECAL_.setNNeighbours( nNeighboursEcal );
501     clusterAlgoECAL_.setShowerSigma( showerSigmaEcal );
502    
503     clusterAlgoECAL_.setPosCalcNCrystal( posCalcNCrystalEcal );
504     clusterAlgoECAL_.setPosCalcP1( posCalcP1Ecal );
505    
506     clusterAlgoECAL_.setUseCornerCells( useCornerCellsEcal );
507    
508     clusterAlgoECAL_.enableDebugging( clusteringDebug );
509    
510     int dcormode = 0;
511     options_->GetOpt("clustering", "depthCor_Mode", dcormode);
512    
513     double dcora = -1;
514     options_->GetOpt("clustering", "depthCor_A", dcora);
515     double dcorb = -1;
516     options_->GetOpt("clustering", "depthCor_B", dcorb);
517     double dcorap = -1;
518     options_->GetOpt("clustering", "depthCor_A_preshower", dcorap);
519     double dcorbp = -1;
520     options_->GetOpt("clustering", "depthCor_B_preshower", dcorbp);
521    
522     // if( dcormode > 0 &&
523     // dcora > -0.5 &&
524     // dcorb > -0.5 &&
525     // dcorap > -0.5 &&
526     // dcorbp > -0.5 ) {
527    
528     // cout<<"set depth correction "
529     // <<dcormode<<" "<<dcora<<" "<<dcorb<<" "<<dcorap<<" "<<dcorbp<<endl;
530     reco::PFCluster::setDepthCorParameters( dcormode,
531     dcora, dcorb,
532     dcorap, dcorbp);
533     // }
534     // else {
535     // reco::PFCluster::setDepthCorParameters( -1,
536     // 0,0 ,
537     // 0,0 );
538     // }
539    
540    
541    
542     double threshHcalBarrel = 0.8;
543     options_->GetOpt("clustering", "thresh_Hcal_Barrel", threshHcalBarrel);
544    
545     double threshPtHcalBarrel = 0.0;
546     options_->GetOpt("clustering", "thresh_Pt_Hcal_Barrel", threshPtHcalBarrel);
547    
548     double threshSeedHcalBarrel = 1.4;
549     options_->GetOpt("clustering", "thresh_Seed_Hcal_Barrel",
550     threshSeedHcalBarrel);
551    
552     double threshPtSeedHcalBarrel = 0.0;
553     options_->GetOpt("clustering", "thresh_Pt_Seed_Hcal_Barrel",
554     threshPtSeedHcalBarrel);
555    
556     double threshCleanHcalBarrel = 1E5;
557     options_->GetOpt("clustering", "thresh_Clean_Hcal_Barrel",
558     threshCleanHcalBarrel);
559    
560     std::vector<double> minS4S1CleanHcalBarrel;
561     options_->GetOpt("clustering", "minS4S1_Clean_Hcal_Barrel",
562     minS4S1CleanHcalBarrel);
563    
564     double threshHcalEndcap = 0.8;
565     options_->GetOpt("clustering", "thresh_Hcal_Endcap", threshHcalEndcap);
566    
567     double threshPtHcalEndcap = 0.0;
568     options_->GetOpt("clustering", "thresh_Pt_Hcal_Endcap", threshPtHcalEndcap);
569    
570     double threshSeedHcalEndcap = 1.4;
571     options_->GetOpt("clustering", "thresh_Seed_Hcal_Endcap",
572     threshSeedHcalEndcap);
573    
574     double threshPtSeedHcalEndcap = 0.0;
575     options_->GetOpt("clustering", "thresh_Pt_Seed_Hcal_Endcap",
576     threshPtSeedHcalEndcap);
577    
578     double threshCleanHcalEndcap = 1E5;
579     options_->GetOpt("clustering", "thresh_Clean_Hcal_Endcap",
580     threshCleanHcalEndcap);
581    
582     std::vector<double> minS4S1CleanHcalEndcap;
583     options_->GetOpt("clustering", "minS4S1_Clean_Hcal_Endcap",
584     minS4S1CleanHcalEndcap);
585    
586     double showerSigmaHcal = 15;
587     options_->GetOpt("clustering", "shower_Sigma_Hcal",
588     showerSigmaHcal);
589    
590     int nNeighboursHcal = 4;
591     options_->GetOpt("clustering", "neighbours_Hcal", nNeighboursHcal);
592    
593     int posCalcNCrystalHcal = 5;
594     options_->GetOpt("clustering", "posCalc_nCrystal_Hcal",
595     posCalcNCrystalHcal);
596    
597     bool useCornerCellsHcal = false;
598     options_->GetOpt("clustering", "useCornerCells_Hcal",
599     useCornerCellsHcal);
600    
601     bool cleanRBXandHPDs = false;
602     options_->GetOpt("clustering", "cleanRBXandHPDs_Hcal",
603     cleanRBXandHPDs);
604    
605     double posCalcP1Hcal
606     = threshHcalBarrel<threshHcalEndcap ? threshHcalBarrel:threshHcalEndcap;
607     // options_->GetOpt("clustering", "posCalc_p1_Hcal",
608     // posCalcP1Hcal);
609    
610    
611     clusterAlgoHCAL_.setHistos(file1,hBNeighbour1,hENeighbour1);
612    
613    
614     clusterAlgoHCAL_.setThreshBarrel( threshHcalBarrel );
615     clusterAlgoHCAL_.setThreshSeedBarrel( threshSeedHcalBarrel );
616    
617     clusterAlgoHCAL_.setThreshPtBarrel( threshPtHcalBarrel );
618     clusterAlgoHCAL_.setThreshPtSeedBarrel( threshPtSeedHcalBarrel );
619    
620     clusterAlgoHCAL_.setThreshCleanBarrel(threshCleanHcalBarrel);
621     clusterAlgoHCAL_.setS4S1CleanBarrel(minS4S1CleanHcalBarrel);
622    
623     clusterAlgoHCAL_.setThreshEndcap( threshHcalEndcap );
624     clusterAlgoHCAL_.setThreshSeedEndcap( threshSeedHcalEndcap );
625    
626     clusterAlgoHCAL_.setThreshPtEndcap( threshPtHcalEndcap );
627     clusterAlgoHCAL_.setThreshPtSeedEndcap( threshPtSeedHcalEndcap );
628    
629     clusterAlgoHCAL_.setThreshCleanEndcap(threshCleanHcalEndcap);
630     clusterAlgoHCAL_.setS4S1CleanEndcap(minS4S1CleanHcalEndcap);
631    
632     clusterAlgoHCAL_.setNNeighbours( nNeighboursHcal );
633     clusterAlgoHCAL_.setShowerSigma( showerSigmaHcal );
634    
635     clusterAlgoHCAL_.setPosCalcNCrystal( posCalcNCrystalHcal );
636     clusterAlgoHCAL_.setPosCalcP1( posCalcP1Hcal );
637    
638     clusterAlgoHCAL_.setUseCornerCells( useCornerCellsHcal );
639     clusterAlgoHCAL_.setCleanRBXandHPDs( cleanRBXandHPDs );
640    
641     clusterAlgoHCAL_.enableDebugging( clusteringDebug );
642    
643    
644     // clustering HF EM
645    
646     double threshHFEM = 0.;
647     options_->GetOpt("clustering", "thresh_HFEM", threshHFEM);
648    
649     double threshPtHFEM = 0.;
650     options_->GetOpt("clustering", "thresh_Pt_HFEM", threshPtHFEM);
651    
652     double threshSeedHFEM = 0.001;
653     options_->GetOpt("clustering", "thresh_Seed_HFEM",
654     threshSeedHFEM);
655    
656     double threshPtSeedHFEM = 0.0;
657     options_->GetOpt("clustering", "thresh_Pt_Seed_HFEM",
658     threshPtSeedHFEM);
659    
660     double threshCleanHFEM = 1E5;
661     options_->GetOpt("clustering", "thresh_Clean_HFEM",
662     threshCleanHFEM);
663    
664     std::vector<double> minS4S1CleanHFEM;
665     options_->GetOpt("clustering", "minS4S1_Clean_HFEM",
666     minS4S1CleanHFEM);
667    
668     double showerSigmaHFEM = 0.1;
669     options_->GetOpt("clustering", "shower_Sigma_HFEM",
670     showerSigmaHFEM);
671    
672     int nNeighboursHFEM = 4;
673     options_->GetOpt("clustering", "neighbours_HFEM", nNeighboursHFEM);
674    
675     int posCalcNCrystalHFEM = -1;
676     options_->GetOpt("clustering", "posCalc_nCrystal_HFEM",
677     posCalcNCrystalHFEM);
678    
679     bool useCornerCellsHFEM = false;
680     options_->GetOpt("clustering", "useCornerCells_HFEM",
681     useCornerCellsHFEM);
682    
683     double posCalcP1HFEM = threshHFEM;
684     // options_->GetOpt("clustering", "posCalc_p1_HFEM",
685     // posCalcP1HFEM);
686    
687    
688     clusterAlgoHFEM_.setHistos(file2,hBNeighbour2,hENeighbour2);
689    
690     clusterAlgoHFEM_.setThreshEndcap( threshHFEM );
691     clusterAlgoHFEM_.setThreshSeedEndcap( threshSeedHFEM );
692    
693     clusterAlgoHFEM_.setThreshPtEndcap( threshPtHFEM );
694     clusterAlgoHFEM_.setThreshPtSeedEndcap( threshPtSeedHFEM );
695    
696     clusterAlgoHFEM_.setThreshCleanEndcap(threshCleanHFEM);
697     clusterAlgoHFEM_.setS4S1CleanEndcap(minS4S1CleanHFEM);
698    
699     clusterAlgoHFEM_.setNNeighbours( nNeighboursHFEM );
700     clusterAlgoHFEM_.setShowerSigma( showerSigmaHFEM );
701    
702     clusterAlgoHFEM_.setPosCalcNCrystal( posCalcNCrystalHFEM );
703     clusterAlgoHFEM_.setPosCalcP1( posCalcP1HFEM );
704    
705     clusterAlgoHFEM_.setUseCornerCells( useCornerCellsHFEM );
706    
707     clusterAlgoHFEM_.enableDebugging( clusteringDebug );
708    
709     // clustering HFHAD
710    
711     double threshHFHAD = 0.;
712     options_->GetOpt("clustering", "thresh_HFHAD", threshHFHAD);
713    
714     double threshPtHFHAD = 0.;
715     options_->GetOpt("clustering", "thresh_Pt_HFHAD", threshPtHFHAD);
716    
717     double threshSeedHFHAD = 0.001;
718     options_->GetOpt("clustering", "thresh_Seed_HFHAD",
719     threshSeedHFHAD);
720    
721     double threshPtSeedHFHAD = 0.0;
722     options_->GetOpt("clustering", "thresh_Pt_Seed_HFHAD",
723     threshPtSeedHFHAD);
724    
725     double threshCleanHFHAD = 1E5;
726     options_->GetOpt("clustering", "thresh_Clean_HFHAD",
727     threshCleanHFHAD);
728    
729     std::vector<double> minS4S1CleanHFHAD;
730     options_->GetOpt("clustering", "minS4S1_Clean_HFHAD",
731     minS4S1CleanHFHAD);
732    
733     double showerSigmaHFHAD = 0.1;
734     options_->GetOpt("clustering", "shower_Sigma_HFHAD",
735     showerSigmaHFHAD);
736    
737     int nNeighboursHFHAD = 4;
738     options_->GetOpt("clustering", "neighbours_HFHAD", nNeighboursHFHAD);
739    
740     int posCalcNCrystalHFHAD = -1;
741     options_->GetOpt("clustering", "posCalc_nCrystal_HFHAD",
742     posCalcNCrystalHFHAD);
743    
744     bool useCornerCellsHFHAD = false;
745     options_->GetOpt("clustering", "useCornerCells_HFHAD",
746     useCornerCellsHFHAD);
747    
748     double posCalcP1HFHAD = threshHFHAD;
749     // options_->GetOpt("clustering", "posCalc_p1_HFHAD",
750     // posCalcP1HFHAD);
751    
752    
753     clusterAlgoHFHAD_.setHistos(file3,hBNeighbour3,hENeighbour3);
754    
755     clusterAlgoHFHAD_.setThreshEndcap( threshHFHAD );
756     clusterAlgoHFHAD_.setThreshSeedEndcap( threshSeedHFHAD );
757    
758     clusterAlgoHFHAD_.setThreshPtEndcap( threshPtHFHAD );
759     clusterAlgoHFHAD_.setThreshPtSeedEndcap( threshPtSeedHFHAD );
760    
761     clusterAlgoHFHAD_.setThreshCleanEndcap(threshCleanHFHAD);
762     clusterAlgoHFHAD_.setS4S1CleanEndcap(minS4S1CleanHFHAD);
763    
764     clusterAlgoHFHAD_.setNNeighbours( nNeighboursHFHAD );
765     clusterAlgoHFHAD_.setShowerSigma( showerSigmaHFHAD );
766    
767     clusterAlgoHFHAD_.setPosCalcNCrystal( posCalcNCrystalHFHAD );
768     clusterAlgoHFHAD_.setPosCalcP1( posCalcP1HFHAD );
769    
770     clusterAlgoHFHAD_.setUseCornerCells( useCornerCellsHFHAD );
771    
772     clusterAlgoHFHAD_.enableDebugging( clusteringDebug );
773    
774     // clustering preshower
775    
776     double threshPS = 0.0001;
777     options_->GetOpt("clustering", "thresh_PS", threshPS);
778    
779     double threshPtPS = 0.0;
780     options_->GetOpt("clustering", "thresh_Pt_PS", threshPtPS);
781    
782     double threshSeedPS = 0.001;
783     options_->GetOpt("clustering", "thresh_Seed_PS",
784     threshSeedPS);
785    
786     double threshPtSeedPS = 0.0;
787     options_->GetOpt("clustering", "thresh_Pt_Seed_PS", threshPtSeedPS);
788    
789     double threshCleanPS = 1E5;
790     options_->GetOpt("clustering", "thresh_Clean_PS", threshCleanPS);
791    
792     std::vector<double> minS4S1CleanPS;
793     options_->GetOpt("clustering", "minS4S1_Clean_PS", minS4S1CleanPS);
794    
795     //Comment Michel: PSBarrel shall be removed?
796     double threshPSBarrel = threshPS;
797     double threshSeedPSBarrel = threshSeedPS;
798    
799     double threshPtPSBarrel = threshPtPS;
800     double threshPtSeedPSBarrel = threshPtSeedPS;
801    
802     double threshCleanPSBarrel = threshCleanPS;
803     std::vector<double> minS4S1CleanPSBarrel = minS4S1CleanPS;
804    
805     double threshPSEndcap = threshPS;
806     double threshSeedPSEndcap = threshSeedPS;
807    
808     double threshPtPSEndcap = threshPtPS;
809     double threshPtSeedPSEndcap = threshPtSeedPS;
810    
811     double threshCleanPSEndcap = threshCleanPS;
812     std::vector<double> minS4S1CleanPSEndcap = minS4S1CleanPS;
813    
814     double showerSigmaPS = 0.1;
815     options_->GetOpt("clustering", "shower_Sigma_PS",
816     showerSigmaPS);
817    
818     int nNeighboursPS = 4;
819     options_->GetOpt("clustering", "neighbours_PS", nNeighboursPS);
820    
821     int posCalcNCrystalPS = -1;
822     options_->GetOpt("clustering", "posCalc_nCrystal_PS",
823     posCalcNCrystalPS);
824    
825     bool useCornerCellsPS = false;
826     options_->GetOpt("clustering", "useCornerCells_PS",
827     useCornerCellsPS);
828    
829     double posCalcP1PS = threshPS;
830     // options_->GetOpt("clustering", "posCalc_p1_PS",
831     // posCalcP1PS);
832    
833    
834     clusterAlgoPS_.setHistos(file4,hBNeighbour4,hENeighbour4);
835    
836    
837    
838     clusterAlgoPS_.setThreshBarrel( threshPSBarrel );
839     clusterAlgoPS_.setThreshSeedBarrel( threshSeedPSBarrel );
840    
841     clusterAlgoPS_.setThreshPtBarrel( threshPtPSBarrel );
842     clusterAlgoPS_.setThreshPtSeedBarrel( threshPtSeedPSBarrel );
843    
844     clusterAlgoPS_.setThreshCleanBarrel(threshCleanPSBarrel);
845     clusterAlgoPS_.setS4S1CleanBarrel(minS4S1CleanPSBarrel);
846    
847     clusterAlgoPS_.setThreshEndcap( threshPSEndcap );
848     clusterAlgoPS_.setThreshSeedEndcap( threshSeedPSEndcap );
849    
850     clusterAlgoPS_.setThreshPtEndcap( threshPtPSEndcap );
851     clusterAlgoPS_.setThreshPtSeedEndcap( threshPtSeedPSEndcap );
852    
853     clusterAlgoPS_.setThreshCleanEndcap(threshCleanPSEndcap);
854     clusterAlgoPS_.setS4S1CleanEndcap(minS4S1CleanPSEndcap);
855    
856     clusterAlgoPS_.setNNeighbours( nNeighboursPS );
857     clusterAlgoPS_.setShowerSigma( showerSigmaPS );
858    
859     clusterAlgoPS_.setPosCalcNCrystal( posCalcNCrystalPS );
860     clusterAlgoPS_.setPosCalcP1( posCalcP1PS );
861    
862     clusterAlgoPS_.setUseCornerCells( useCornerCellsPS );
863    
864     clusterAlgoPS_.enableDebugging( clusteringDebug );
865    
866     // options for particle flow ---------------------------------------------
867    
868    
869     doParticleFlow_ = true;
870     doCompare_ = false;
871     options_->GetOpt("particle_flow", "on/off", doParticleFlow_);
872     options_->GetOpt("particle_flow", "comparison", doCompare_);
873    
874     std::vector<double> DPtovPtCut;
875     std::vector<unsigned> NHitCut;
876     bool useIterTracking;
877     int nuclearInteractionsPurity;
878     options_->GetOpt("particle_flow", "DPtoverPt_Cut", DPtovPtCut);
879     options_->GetOpt("particle_flow", "NHit_Cut", NHitCut);
880     options_->GetOpt("particle_flow", "useIterTracking", useIterTracking);
881     options_->GetOpt("particle_flow", "nuclearInteractionsPurity", nuclearInteractionsPurity);
882    
883    
884     try {
885     pfBlockAlgo_.setParameters( DPtovPtCut,
886     NHitCut,
887     useIterTracking,
888     useConvBremPFRecTracks_,
889     nuclearInteractionsPurity);
890     }
891     catch( std::exception& err ) {
892     cerr<<"exception setting PFBlockAlgo parameters: "
893     <<err.what()<<". terminating."<<endl;
894     delete this;
895     exit(1);
896     }
897    
898    
899     bool blockAlgoDebug = false;
900     options_->GetOpt("blockAlgo", "debug", blockAlgoDebug);
901     pfBlockAlgo_.setDebug( blockAlgoDebug );
902    
903     bool AlgoDebug = false;
904     options_->GetOpt("PFAlgo", "debug", AlgoDebug);
905     pfAlgo_.setDebug( AlgoDebug );
906    
907     // read PFCluster calibration parameters
908    
909    
910     double e_slope = 1.0;
911     options_->GetOpt("particle_flow","calib_ECAL_slope", e_slope);
912     double e_offset = 0;
913     options_->GetOpt("particle_flow","calib_ECAL_offset", e_offset);
914    
915     double eh_eslope = 1.05;
916     options_->GetOpt("particle_flow","calib_ECAL_HCAL_eslope", eh_eslope);
917     double eh_hslope = 1.06;
918     options_->GetOpt("particle_flow","calib_ECAL_HCAL_hslope", eh_hslope);
919     double eh_offset = 6.11;
920     options_->GetOpt("particle_flow","calib_ECAL_HCAL_offset", eh_offset);
921    
922     double h_slope = 2.17;
923     options_->GetOpt("particle_flow","calib_HCAL_slope", h_slope);
924     double h_offset = 1.73;
925     options_->GetOpt("particle_flow","calib_HCAL_offset", h_offset);
926     double h_damping = 2.49;
927     options_->GetOpt("particle_flow","calib_HCAL_damping", h_damping);
928    
929    
930     unsigned newCalib = 0;
931     options_->GetOpt("particle_flow", "newCalib", newCalib);
932     std::cout << "New calib = " << newCalib << std::endl;
933    
934     shared_ptr<pftools::PFClusterCalibration>
935     clusterCalibration( new pftools::PFClusterCalibration() );
936     clusterCalibration_ = clusterCalibration;
937    
938     shared_ptr<PFEnergyCalibration>
939     calibration( new PFEnergyCalibration( e_slope,
940     e_offset,
941     eh_eslope,
942     eh_hslope,
943     eh_offset,
944     h_slope,
945     h_offset,
946     h_damping,
947     newCalib) );
948     calibration_ = calibration;
949    
950     bool usePFSCEleCalib;
951     std::vector<double> calibPFSCEle_barrel;
952     std::vector<double> calibPFSCEle_endcap;
953     options_->GetOpt("particle_flow","usePFSCEleCalib",usePFSCEleCalib);
954     options_->GetOpt("particle_flow","calibPFSCEle_barrel",calibPFSCEle_barrel);
955     options_->GetOpt("particle_flow","calibPFSCEle_endcap",calibPFSCEle_endcap);
956     shared_ptr<PFSCEnergyCalibration>
957     thePFSCEnergyCalibration ( new PFSCEnergyCalibration(calibPFSCEle_barrel,calibPFSCEle_endcap ));
958    
959     bool useEGammaSupercluster;
960     double sumEtEcalIsoForEgammaSC_barrel;
961     double sumEtEcalIsoForEgammaSC_endcap;
962     double coneEcalIsoForEgammaSC;
963     double sumPtTrackIsoForEgammaSC_barrel;
964     double sumPtTrackIsoForEgammaSC_endcap;
965     unsigned int nTrackIsoForEgammaSC;
966     double coneTrackIsoForEgammaSC;
967     bool useEGammaElectrons;
968     options_->GetOpt("particle_flow","useEGammaSupercluster",useEGammaSupercluster);
969     options_->GetOpt("particle_flow","sumEtEcalIsoForEgammaSC_barrel",sumEtEcalIsoForEgammaSC_barrel);
970     options_->GetOpt("particle_flow","sumEtEcalIsoForEgammaSC_endcap",sumEtEcalIsoForEgammaSC_endcap);
971     options_->GetOpt("particle_flow","coneEcalIsoForEgammaSC",coneEcalIsoForEgammaSC);
972     options_->GetOpt("particle_flow","sumPtTrackIsoForEgammaSC_barrel",sumPtTrackIsoForEgammaSC_barrel);
973     options_->GetOpt("particle_flow","sumPtTrackIsoForEgammaSC_endcap",sumPtTrackIsoForEgammaSC_endcap);
974     options_->GetOpt("particle_flow","nTrackIsoForEgammaSC",nTrackIsoForEgammaSC);
975     options_->GetOpt("particle_flow","coneTrackIsoForEgammaSC",coneTrackIsoForEgammaSC);
976     options_->GetOpt("particle_flow","useEGammaElectrons",useEGammaElectrons);
977    
978     //--ab: get calibration factors for HF:
979     bool calibHF_use = false;
980     std::vector<double> calibHF_eta_step;
981     std::vector<double> calibHF_a_EMonly;
982     std::vector<double> calibHF_b_HADonly;
983     std::vector<double> calibHF_a_EMHAD;
984     std::vector<double> calibHF_b_EMHAD;
985    
986     options_->GetOpt("particle_flow","calib_calibHF_use",calibHF_use);
987     options_->GetOpt("particle_flow","calib_calibHF_eta_step",calibHF_eta_step);
988     options_->GetOpt("particle_flow","calib_calibHF_a_EMonly",calibHF_a_EMonly);
989     options_->GetOpt("particle_flow","calib_calibHF_b_HADonly",calibHF_b_HADonly);
990     options_->GetOpt("particle_flow","calib_calibHF_a_EMHAD",calibHF_a_EMHAD);
991     options_->GetOpt("particle_flow","calib_calibHF_b_EMHAD",calibHF_b_EMHAD);
992    
993     shared_ptr<PFEnergyCalibrationHF> thepfEnergyCalibrationHF
994     ( new PFEnergyCalibrationHF(calibHF_use,calibHF_eta_step,calibHF_a_EMonly,calibHF_b_HADonly,calibHF_a_EMHAD,calibHF_b_EMHAD) ) ;
995    
996     thepfEnergyCalibrationHF_ = thepfEnergyCalibrationHF;
997    
998    
999     //----------------------------------------
1000     double nSigmaECAL = 99999;
1001     options_->GetOpt("particle_flow", "nsigma_ECAL", nSigmaECAL);
1002     double nSigmaHCAL = 99999;
1003     options_->GetOpt("particle_flow", "nsigma_HCAL", nSigmaHCAL);
1004    
1005     // pfAlgo_.setNewCalibration(newCalib);
1006    
1007     // Set the parameters for the brand-new calibration
1008     double g0, g1, e0, e1;
1009     options_->GetOpt("correction", "globalP0", g0);
1010     options_->GetOpt("correction", "globalP1", g1);
1011     options_->GetOpt("correction", "lowEP0", e0);
1012     options_->GetOpt("correction", "lowEP1", e1);
1013     clusterCalibration->setCorrections(e0, e1, g0, g1);
1014    
1015     int allowNegative(0);
1016     options_->GetOpt("correction", "allowNegativeEnergy", allowNegative);
1017     clusterCalibration->setAllowNegativeEnergy(allowNegative);
1018    
1019     int doCorrection(1);
1020     options_->GetOpt("correction", "doCorrection", doCorrection);
1021     clusterCalibration->setDoCorrection(doCorrection);
1022    
1023     int doEtaCorrection(1);
1024     options_->GetOpt("correction", "doEtaCorrection", doEtaCorrection);
1025     clusterCalibration->setDoEtaCorrection(doEtaCorrection);
1026    
1027     double barrelEta;
1028     options_->GetOpt("evolution", "barrelEndcapEtaDiv", barrelEta);
1029     clusterCalibration->setBarrelBoundary(barrelEta);
1030    
1031     double ecalEcut;
1032     options_->GetOpt("evolution", "ecalECut", ecalEcut);
1033     double hcalEcut;
1034     options_->GetOpt("evolution", "hcalECut", hcalEcut);
1035     clusterCalibration->setEcalHcalEnergyCuts(ecalEcut,hcalEcut);
1036    
1037     std::vector<std::string>* names = clusterCalibration->getKnownSectorNames();
1038     for(std::vector<std::string>::iterator i = names->begin(); i != names->end(); ++i) {
1039     std::string sector = *i;
1040     std::vector<double> params;
1041     options_->GetOpt("evolution", sector.c_str(), params);
1042     clusterCalibration->setEvolutionParameters(sector, params);
1043     }
1044    
1045     std::vector<double> etaCorrectionParams;
1046     options_->GetOpt("evolution","etaCorrection", etaCorrectionParams);
1047     clusterCalibration->setEtaCorrectionParameters(etaCorrectionParams);
1048    
1049     try {
1050     pfAlgo_.setParameters( nSigmaECAL, nSigmaHCAL,
1051     calibration,
1052     clusterCalibration,thepfEnergyCalibrationHF_, newCalib);
1053     }
1054     catch( std::exception& err ) {
1055     cerr<<"exception setting PFAlgo parameters: "
1056     <<err.what()<<". terminating."<<endl;
1057     delete this;
1058     exit(1);
1059     }
1060    
1061     std::vector<double> muonHCAL;
1062     std::vector<double> muonECAL;
1063     options_->GetOpt("particle_flow", "muon_HCAL", muonHCAL);
1064     options_->GetOpt("particle_flow", "muon_ECAL", muonECAL);
1065     assert ( muonHCAL.size() == 2 && muonECAL.size() == 2 );
1066    
1067     double nSigmaTRACK = 3.0;
1068     options_->GetOpt("particle_flow", "nsigma_TRACK", nSigmaTRACK);
1069    
1070     double ptError = 1.0;
1071     options_->GetOpt("particle_flow", "pt_error", ptError);
1072    
1073     std::vector<double> factors45;
1074     options_->GetOpt("particle_flow", "factors_45", factors45);
1075     assert ( factors45.size() == 2 );
1076    
1077     bool usePFMuonMomAssign = false;
1078     options_->GetOpt("particle_flow", "usePFMuonMomAssign", usePFMuonMomAssign);
1079    
1080     try {
1081     pfAlgo_.setPFMuonAndFakeParameters(muonHCAL,
1082     muonECAL,
1083     nSigmaTRACK,
1084     ptError,
1085     factors45,
1086     usePFMuonMomAssign);
1087     }
1088     catch( std::exception& err ) {
1089     cerr<<"exception setting PFAlgo Muon and Fake parameters: "
1090     <<err.what()<<". terminating."<<endl;
1091     delete this;
1092     exit(1);
1093     }
1094    
1095     bool postHFCleaning = true;
1096     options_->GetOpt("particle_flow", "postHFCleaning", postHFCleaning);
1097     double minHFCleaningPt = 5.;
1098     options_->GetOpt("particle_flow", "minHFCleaningPt", minHFCleaningPt);
1099     double minSignificance = 2.5;
1100     options_->GetOpt("particle_flow", "minSignificance", minSignificance);
1101     double maxSignificance = 2.5;
1102     options_->GetOpt("particle_flow", "maxSignificance", maxSignificance);
1103     double minSignificanceReduction = 1.4;
1104     options_->GetOpt("particle_flow", "minSignificanceReduction", minSignificanceReduction);
1105     double maxDeltaPhiPt = 7.0;
1106     options_->GetOpt("particle_flow", "maxDeltaPhiPt", maxDeltaPhiPt);
1107     double minDeltaMet = 0.4;
1108     options_->GetOpt("particle_flow", "minDeltaMet", minDeltaMet);
1109    
1110     // Set post HF cleaning muon parameters
1111     try {
1112     pfAlgo_.setPostHFCleaningParameters(postHFCleaning,
1113     minHFCleaningPt,
1114     minSignificance,
1115     maxSignificance,
1116     minSignificanceReduction,
1117     maxDeltaPhiPt,
1118     minDeltaMet);
1119     }
1120     catch( std::exception& err ) {
1121     cerr<<"exception setting post HF cleaning parameters: "
1122     <<err.what()<<". terminating."<<endl;
1123     delete this;
1124     exit(1);
1125     }
1126    
1127     useAtHLT = false;
1128     options_->GetOpt("particle_flow", "useAtHLT", useAtHLT);
1129     cout<<"use HLT tracking "<<useAtHLT<<endl;
1130    
1131    
1132     bool usePFElectrons = false; // set true to use PFElectrons
1133     options_->GetOpt("particle_flow", "usePFElectrons", usePFElectrons);
1134     cout<<"use PFElectrons "<<usePFElectrons<<endl;
1135    
1136     if( usePFElectrons ) {
1137     // PFElectrons options -----------------------------
1138     double mvaEleCut = -1.; // if = -1. get all the pre-id electrons
1139     options_->GetOpt("particle_flow", "electron_mvaCut", mvaEleCut);
1140    
1141     bool applyCrackCorrections=true;
1142     options_->GetOpt("particle_flow","electron_crackCorrection",applyCrackCorrections);
1143    
1144     string mvaWeightFileEleID = "";
1145     options_->GetOpt("particle_flow", "electronID_mvaWeightFile",
1146     mvaWeightFileEleID);
1147     mvaWeightFileEleID = expand(mvaWeightFileEleID);
1148    
1149     try {
1150     pfAlgo_.setPFEleParameters(mvaEleCut,
1151     mvaWeightFileEleID,
1152     usePFElectrons,
1153     thePFSCEnergyCalibration,
1154     sumEtEcalIsoForEgammaSC_barrel,
1155     sumEtEcalIsoForEgammaSC_endcap,
1156     coneEcalIsoForEgammaSC,
1157     sumPtTrackIsoForEgammaSC_barrel,
1158     sumPtTrackIsoForEgammaSC_endcap,
1159     nTrackIsoForEgammaSC,
1160     coneTrackIsoForEgammaSC,
1161     applyCrackCorrections,
1162     usePFSCEleCalib,
1163     useEGammaElectrons,
1164     useEGammaSupercluster);
1165     }
1166     catch( std::exception& err ) {
1167     cerr<<"exception setting PFAlgo Electron parameters: "
1168     <<err.what()<<". terminating."<<endl;
1169     delete this;
1170     exit(1);
1171     }
1172     }
1173    
1174    
1175     bool rejectTracks_Bad = true;
1176     bool rejectTracks_Step45 = true;
1177     bool usePFConversions = false; // set true to use PFConversions
1178     bool usePFDisplacedVertexs = false;
1179     bool usePFV0s = false;
1180    
1181     double dptRel_DispVtx = 20;
1182    
1183    
1184     options_->GetOpt("particle_flow", "usePFConversions", usePFConversions);
1185    
1186     options_->GetOpt("particle_flow", "usePFV0s", usePFV0s);
1187    
1188     options_->GetOpt("particle_flow", "usePFDisplacedVertexs", usePFDisplacedVertexs);
1189    
1190     options_->GetOpt("particle_flow", "dptRel_DispVtx", dptRel_DispVtx);
1191    
1192     try {
1193     pfAlgo_.setDisplacedVerticesParameters(rejectTracks_Bad,
1194     rejectTracks_Step45,
1195     usePFDisplacedVertexs,
1196     usePFConversions,
1197     usePFV0s,
1198     dptRel_DispVtx);
1199     }
1200     catch( std::exception& err ) {
1201     cerr<<"exception setting PFAlgo Conversions parameters: "
1202     <<err.what()<<". terminating."<<endl;
1203     delete this;
1204     exit(1);
1205     }
1206    
1207    
1208    
1209     int algo = 2;
1210     options_->GetOpt("particle_flow", "algorithm", algo);
1211    
1212     pfAlgo_.setAlgo( algo );
1213     // pfAlgoOther_.setAlgo( 1 );
1214    
1215    
1216     // jets options ---------------------------------
1217    
1218     doJets_ = false;
1219     options_->GetOpt("jets", "on/off", doJets_);
1220    
1221     jetsDebug_ = false;
1222     options_->GetOpt("jets", "debug", jetsDebug_);
1223    
1224     jetAlgoType_=3; //FastJet as Default
1225     options_->GetOpt("jets", "algo", jetAlgoType_);
1226    
1227     double mEtInputCut = 0.5;
1228     options_->GetOpt("jets", "EtInputCut", mEtInputCut);
1229    
1230     double mEInputCut = 0.;
1231     options_->GetOpt("jets", "EInputCut", mEInputCut);
1232    
1233     double seedThreshold = 1.0;
1234     options_->GetOpt("jets", "seedThreshold", seedThreshold);
1235    
1236     double coneRadius = 0.5;
1237     options_->GetOpt("jets", "coneRadius", coneRadius);
1238    
1239     double coneAreaFraction= 1.0;
1240     options_->GetOpt("jets", "coneAreaFraction", coneAreaFraction);
1241    
1242     int maxPairSize=2;
1243     options_->GetOpt("jets", "maxPairSize", maxPairSize);
1244    
1245     int maxIterations=100;
1246     options_->GetOpt("jets", "maxIterations", maxIterations);
1247    
1248     double overlapThreshold = 0.75;
1249     options_->GetOpt("jets", "overlapThreshold", overlapThreshold);
1250    
1251     double ptMin = 10.;
1252     options_->GetOpt("jets", "ptMin", ptMin);
1253    
1254     double rparam = 1.0;
1255     options_->GetOpt("jets", "rParam", rparam);
1256    
1257     jetMaker_.setmEtInputCut (mEtInputCut);
1258     jetMaker_.setmEInputCut(mEInputCut);
1259     jetMaker_.setSeedThreshold(seedThreshold);
1260     jetMaker_.setConeRadius(coneRadius);
1261     jetMaker_.setConeAreaFraction(coneAreaFraction);
1262     jetMaker_.setMaxPairSize(maxPairSize);
1263     jetMaker_.setMaxIterations(maxIterations) ;
1264     jetMaker_.setOverlapThreshold(overlapThreshold) ;
1265     jetMaker_.setPtMin (ptMin);
1266     jetMaker_.setRParam (rparam);
1267     jetMaker_.setDebug(jetsDebug_);
1268     jetMaker_.updateParameter();
1269     cout <<"Opt: doJets? " << doJets_ <<endl;
1270     cout <<"Opt: jetsDebug " << jetsDebug_ <<endl;
1271     cout <<"Opt: algoType " << jetAlgoType_ <<endl;
1272     cout <<"----------------------------------" << endl;
1273    
1274    
1275     // tau benchmark options ---------------------------------
1276    
1277     doTauBenchmark_ = false;
1278     options_->GetOpt("tau_benchmark", "on/off", doTauBenchmark_);
1279    
1280     if (doTauBenchmark_) {
1281     double coneAngle = 0.5;
1282     options_->GetOpt("tau_benchmark", "cone_angle", coneAngle);
1283    
1284     double seedEt = 0.4;
1285     options_->GetOpt("tau_benchmark", "seed_et", seedEt);
1286    
1287     double coneMerge = 100.0;
1288     options_->GetOpt("tau_benchmark", "cone_merge", coneMerge);
1289    
1290     options_->GetOpt("tau_benchmark", "debug", tauBenchmarkDebug_);
1291    
1292     // cout<<"jets debug "<<jetsDebug_<<endl;
1293    
1294     if( tauBenchmarkDebug_ ) {
1295     cout << "Tau Benchmark Options : ";
1296     cout << "Angle=" << coneAngle << " seedEt=" << seedEt
1297     << " Merge=" << coneMerge << endl;
1298     }
1299    
1300     jetAlgo_.SetConeAngle(coneAngle);
1301     jetAlgo_.SetSeedEt(seedEt);
1302     jetAlgo_.SetConeMerge(coneMerge);
1303     }
1304    
1305    
1306    
1307     // print flags -------------
1308    
1309     printRecHits_ = false;
1310     printRecHitsEMin_ = 0.;
1311     options_->GetOpt("print", "rechits", printRecHits_ );
1312     options_->GetOpt("print", "rechits_emin", printRecHitsEMin_ );
1313    
1314     printClusters_ = false;
1315     printClustersEMin_ = 0.;
1316     options_->GetOpt("print", "clusters", printClusters_ );
1317     options_->GetOpt("print", "clusters_emin", printClustersEMin_ );
1318    
1319     printPFBlocks_ = false;
1320     options_->GetOpt("print", "PFBlocks", printPFBlocks_ );
1321    
1322     printPFCandidates_ = true;
1323     printPFCandidatesPtMin_ = 0.;
1324     options_->GetOpt("print", "PFCandidates", printPFCandidates_ );
1325     options_->GetOpt("print", "PFCandidates_ptmin", printPFCandidatesPtMin_ );
1326    
1327     printPFJets_ = true;
1328     printPFJetsPtMin_ = 0.;
1329     options_->GetOpt("print", "jets", printPFJets_ );
1330     options_->GetOpt("print", "jets_ptmin", printPFJetsPtMin_ );
1331    
1332     printSimParticles_ = true;
1333     printSimParticlesPtMin_ = 0.;
1334     options_->GetOpt("print", "simParticles", printSimParticles_ );
1335     options_->GetOpt("print", "simParticles_ptmin", printSimParticlesPtMin_ );
1336    
1337     printGenParticles_ = true;
1338     printGenParticlesPtMin_ = 0.;
1339     options_->GetOpt("print", "genParticles", printGenParticles_ );
1340     options_->GetOpt("print", "genParticles_ptmin", printGenParticlesPtMin_ );
1341    
1342     //MCTruthMatching Tool set to false by default
1343     //can only be used with fastsim and the UnFoldedMode set to true
1344     //when generating the simulated file
1345     printMCTruthMatching_ = false;
1346     options_->GetOpt("print", "mctruthmatching", printMCTruthMatching_ );
1347    
1348    
1349     verbosity_ = VERBOSE;
1350     options_->GetOpt("print", "verbosity", verbosity_ );
1351     cout<<"verbosity : "<<verbosity_<<endl;
1352    
1353    
1354    
1355    
1356    
1357     }
1358    
1359     void PFRootEventManager::connect( const char* infilename ) {
1360    
1361     cout<<"Opening input root files"<<endl;
1362    
1363     options_->GetOpt("root","file", inFileNames_);
1364    
1365    
1366    
1367     try {
1368     AutoLibraryLoader::enable();
1369     }
1370     catch(string& err) {
1371     cout<<err<<endl;
1372     }
1373    
1374     ev_ = new fwlite::ChainEvent(inFileNames_);
1375    
1376    
1377     if ( !ev_ || !ev_->isValid() ) {
1378     cout << "The rootfile(s) " << endl;
1379     for ( unsigned int ifile=0; ifile<inFileNames_.size(); ++ifile )
1380     std::cout << " - " << inFileNames_[ifile] << std::endl;
1381     cout << " is (are) not valid file(s) to open" << endl;
1382     return;
1383     } else {
1384     cout << "The rootfile(s) : " << endl;
1385     for ( unsigned int ifile=0; ifile<inFileNames_.size(); ++ifile )
1386     std::cout << " - " << inFileNames_[ifile] << std::endl;
1387     cout<<" are opened with " << ev_->size() << " events." <<endl;
1388     }
1389    
1390     // hits branches ----------------------------------------------
1391     std::string rechitsECALtagname;
1392     options_->GetOpt("root","rechits_ECAL_inputTag", rechitsECALtagname);
1393     rechitsECALTag_ = edm::InputTag(rechitsECALtagname);
1394    
1395     std::string rechitsHCALtagname;
1396     options_->GetOpt("root","rechits_HCAL_inputTag", rechitsHCALtagname);
1397     rechitsHCALTag_ = edm::InputTag(rechitsHCALtagname);
1398    
1399     std::string rechitsHFEMtagname;
1400     options_->GetOpt("root","rechits_HFEM_inputTag", rechitsHFEMtagname);
1401     rechitsHFEMTag_ = edm::InputTag(rechitsHFEMtagname);
1402    
1403     std::string rechitsHFHADtagname;
1404     options_->GetOpt("root","rechits_HFHAD_inputTag", rechitsHFHADtagname);
1405     rechitsHFHADTag_ = edm::InputTag(rechitsHFHADtagname);
1406    
1407     std::vector<string> rechitsCLEANEDtagnames;
1408     options_->GetOpt("root","rechits_CLEANED_inputTags", rechitsCLEANEDtagnames);
1409     for ( unsigned tags = 0; tags<rechitsCLEANEDtagnames.size(); ++tags )
1410     rechitsCLEANEDTags_.push_back(edm::InputTag(rechitsCLEANEDtagnames[tags]));
1411     rechitsCLEANEDV_.resize(rechitsCLEANEDTags_.size());
1412     rechitsCLEANEDHandles_.resize(rechitsCLEANEDTags_.size());
1413    
1414    
1415     // Tracks branches
1416     std::string rechitsPStagname;
1417     options_->GetOpt("root","rechits_PS_inputTag", rechitsPStagname);
1418     rechitsPSTag_ = edm::InputTag(rechitsPStagname);
1419    
1420     std::string recTrackstagname;
1421     options_->GetOpt("root","recTracks_inputTag", recTrackstagname);
1422     recTracksTag_ = edm::InputTag(recTrackstagname);
1423    
1424     std::string primaryVerticestagname;
1425     options_->GetOpt("root","primaryVertices_inputTag", primaryVerticestagname);
1426     primaryVerticesTag_ = edm::InputTag(primaryVerticestagname);
1427    
1428     std::string stdTrackstagname;
1429     options_->GetOpt("root","stdTracks_inputTag", stdTrackstagname);
1430     stdTracksTag_ = edm::InputTag(stdTrackstagname);
1431    
1432     std::string gsfrecTrackstagname;
1433     options_->GetOpt("root","gsfrecTracks_inputTag", gsfrecTrackstagname);
1434     gsfrecTracksTag_ = edm::InputTag(gsfrecTrackstagname);
1435    
1436     useConvBremPFRecTracks_ = false;
1437     options_->GetOpt("particle_flow", "useConvBremPFRecTracks", useConvBremPFRecTracks_);
1438     if ( useConvBremPFRecTracks_ ) {
1439     std::string convBremGsfrecTrackstagname;
1440     options_->GetOpt("root","convBremGsfrecTracks_inputTag", convBremGsfrecTrackstagname);
1441     convBremGsfrecTracksTag_ = edm::InputTag(convBremGsfrecTrackstagname);
1442     }
1443    
1444    
1445     // muons branch
1446     std::string muonstagname;
1447     options_->GetOpt("root","muon_inputTag", muonstagname);
1448     muonsTag_ = edm::InputTag(muonstagname);
1449    
1450     // conversion
1451     usePFConversions_=false;
1452     options_->GetOpt("particle_flow", "usePFConversions", usePFConversions_);
1453     if( usePFConversions_ ) {
1454     std::string conversiontagname;
1455     options_->GetOpt("root","conversion_inputTag", conversiontagname);
1456     conversionTag_ = edm::InputTag(conversiontagname);
1457     }
1458    
1459     // V0
1460     usePFV0s_=false;
1461     options_->GetOpt("particle_flow", "usePFV0s", usePFV0s_);
1462     if( usePFV0s_ ) {
1463     std::string v0tagname;
1464     options_->GetOpt("root","V0_inputTag", v0tagname);
1465     v0Tag_ = edm::InputTag(v0tagname);
1466     }
1467    
1468     //Displaced Vertices
1469     usePFDisplacedVertexs_=false;
1470     options_->GetOpt("particle_flow", "usePFDisplacedVertexs", usePFDisplacedVertexs_);
1471     if( usePFDisplacedVertexs_ ) {
1472     std::string pfDisplacedTrackerVertextagname;
1473     options_->GetOpt("root","PFDisplacedVertex_inputTag", pfDisplacedTrackerVertextagname);
1474     pfDisplacedTrackerVertexTag_ = edm::InputTag(pfDisplacedTrackerVertextagname);
1475     }
1476    
1477     std::string trueParticlestagname;
1478     options_->GetOpt("root","trueParticles_inputTag", trueParticlestagname);
1479     trueParticlesTag_ = edm::InputTag(trueParticlestagname);
1480    
1481     std::string MCTruthtagname;
1482     options_->GetOpt("root","MCTruth_inputTag", MCTruthtagname);
1483     MCTruthTag_ = edm::InputTag(MCTruthtagname);
1484    
1485     std::string caloTowerstagname;
1486     options_->GetOpt("root","caloTowers_inputTag", caloTowerstagname);
1487     caloTowersTag_ = edm::InputTag(caloTowerstagname);
1488    
1489     std::string genJetstagname;
1490     options_->GetOpt("root","genJets_inputTag", genJetstagname);
1491     genJetsTag_ = edm::InputTag(genJetstagname);
1492    
1493    
1494     std::string genParticlesforMETtagname;
1495     options_->GetOpt("root","genParticlesforMET_inputTag", genParticlesforMETtagname);
1496     genParticlesforMETTag_ = edm::InputTag(genParticlesforMETtagname);
1497    
1498     std::string genParticlesforJetstagname;
1499     options_->GetOpt("root","genParticlesforJets_inputTag", genParticlesforJetstagname);
1500     genParticlesforJetsTag_ = edm::InputTag(genParticlesforJetstagname);
1501    
1502     // PF candidates
1503     std::string pfCandidatetagname;
1504     options_->GetOpt("root","particleFlowCand_inputTag", pfCandidatetagname);
1505     pfCandidateTag_ = edm::InputTag(pfCandidatetagname);
1506    
1507     std::string caloJetstagname;
1508     options_->GetOpt("root","CaloJets_inputTag", caloJetstagname);
1509     caloJetsTag_ = edm::InputTag(caloJetstagname);
1510    
1511     std::string corrcaloJetstagname;
1512     options_->GetOpt("root","corrCaloJets_inputTag", corrcaloJetstagname);
1513     corrcaloJetsTag_ = edm::InputTag(corrcaloJetstagname);
1514    
1515     std::string pfJetstagname;
1516     options_->GetOpt("root","PFJets_inputTag", pfJetstagname);
1517     pfJetsTag_ = edm::InputTag(pfJetstagname);
1518    
1519     std::string pfMetstagname;
1520     options_->GetOpt("root","PFMET_inputTag", pfMetstagname);
1521     pfMetsTag_ = edm::InputTag(pfMetstagname);
1522    
1523     std::string caloMetstagname;
1524     options_->GetOpt("root","CaloMET_inputTag", caloMetstagname);
1525     caloMetsTag_ = edm::InputTag(caloMetstagname);
1526    
1527     std::string tcMetstagname;
1528     options_->GetOpt("root","TCMET_inputTag", tcMetstagname);
1529     tcMetsTag_ = edm::InputTag(tcMetstagname);
1530    
1531     }
1532    
1533    
1534    
1535    
1536    
1537     PFRootEventManager::~PFRootEventManager() {
1538    
1539     if(outFile_) {
1540     outFile_->Close();
1541     }
1542    
1543     if(outEvent_) delete outEvent_;
1544    
1545     delete options_;
1546    
1547     }
1548    
1549    
1550     void PFRootEventManager::write() {
1551    
1552     if(doPFJetBenchmark_) PFJetBenchmark_.write();
1553     if(doPFMETBenchmark_) metManager_->write();
1554     clusterAlgoECAL_.write();
1555     clusterAlgoHCAL_.write();
1556     clusterAlgoPS_.write();
1557     clusterAlgoHFEM_.write();
1558     clusterAlgoHFHAD_.write();
1559    
1560    
1561     if(outFile_) {
1562     outFile_->Write();
1563     // outFile_->cd();
1564     // // write histos here
1565     // cout<<"writing output to "<<outFile_->GetName()<<endl;
1566     // h_deltaETvisible_MCEHT_->Write();
1567     // h_deltaETvisible_MCPF_->Write();
1568     // if(outTree_) outTree_->Write();
1569     // if(doPFCandidateBenchmark_) pfCandidateBenchmark_.write();
1570     }
1571     }
1572    
1573    
1574     int PFRootEventManager::eventToEntry(int run, int lumi, int event) const {
1575    
1576     RunsMap::const_iterator iR = mapEventToEntry_.find( run );
1577     if( iR != mapEventToEntry_.end() ) {
1578     LumisMap::const_iterator iL = iR->second.find( lumi );
1579     if( iL != iR->second.end() ) {
1580     EventToEntry::const_iterator iE = iL->second.find( event );
1581     if( iE != iL->second.end() ) {
1582     return iE->second;
1583     }
1584     else {
1585     cout<<"event "<<event<<" not found in run "<<run<<", lumi "<<lumi<<endl;
1586     }
1587     }
1588     else {
1589     cout<<"lumi "<<lumi<<" not found in run "<<run<<endl;
1590     }
1591     }
1592     else{
1593     cout<<"run "<<run<<" not found"<<endl;
1594     }
1595     return -1;
1596     }
1597    
1598     bool PFRootEventManager::processEvent(int run, int lumi, int event) {
1599    
1600     int entry = eventToEntry(run, lumi, event);
1601     if( entry < 0 ) {
1602     cout<<"event "<<event<<" is not present, sorry."<<endl;
1603     return false;
1604     }
1605     else
1606     return processEntry( entry );
1607     }
1608    
1609    
1610     bool PFRootEventManager::processEntry(int entry) {
1611    
1612     reset();
1613    
1614     iEvent_ = entry;
1615    
1616     bool exists = ev_->to(entry);
1617     if ( !exists ) {
1618     std::cout << "Entry " << entry << " does not exist " << std::endl;
1619     return false;
1620     }
1621     const edm::EventBase& iEvent = *ev_;
1622    
1623     if( outEvent_ ) outEvent_->setNumber(entry);
1624    
1625     if(verbosity_ == VERBOSE ||
1626     //entry < 10000 ||
1627     (entry < 100 && entry%10 == 0) ||
1628     (entry < 1000 && entry%100 == 0) ||
1629     entry%1000 == 0 )
1630     cout<<"process entry "<< entry
1631     <<", run "<<iEvent.id().run()
1632     <<", lumi "<<iEvent.id().luminosityBlock()
1633     <<", event:"<<iEvent.id().event()
1634     << endl;
1635    
1636     //ev_->getTFile()->cd();
1637     bool goodevent = readFromSimulation(entry);
1638    
1639     /*
1640     std::cout << "Rechits cleaned : " << std::endl;
1641     for(unsigned i=0; i<rechitsCLEANED_.size(); i++) {
1642     string seedstatus = " ";
1643     printRecHit(rechitsCLEANED_[i], i, seedstatus.c_str());
1644     }
1645     */
1646    
1647     if(verbosity_ == VERBOSE ) {
1648     cout<<"number of vertices : "<<primaryVertices_.size()<<endl;
1649     cout<<"number of recTracks : "<<recTracks_.size()<<endl;
1650     cout<<"number of gsfrecTracks : "<<gsfrecTracks_.size()<<endl;
1651     cout<<"number of convBremGsfrecTracks : "<<convBremGsfrecTracks_.size()<<endl;
1652     cout<<"number of muons : "<<muons_.size()<<endl;
1653     cout<<"number of displaced vertices : "<<pfDisplacedTrackerVertex_.size()<<endl;
1654     cout<<"number of conversions : "<<conversion_.size()<<endl;
1655     cout<<"number of v0 : "<<v0_.size()<<endl;
1656     cout<<"number of stdTracks : "<<stdTracks_.size()<<endl;
1657     cout<<"number of true particles : "<<trueParticles_.size()<<endl;
1658     cout<<"number of ECAL rechits : "<<rechitsECAL_.size()<<endl;
1659     cout<<"number of HCAL rechits : "<<rechitsHCAL_.size()<<endl;
1660     cout<<"number of HFEM rechits : "<<rechitsHFEM_.size()<<endl;
1661     cout<<"number of HFHAD rechits : "<<rechitsHFHAD_.size()<<endl;
1662     cout<<"number of HF Cleaned rechits : "<<rechitsCLEANED_.size()<<endl;
1663     cout<<"number of PS rechits : "<<rechitsPS_.size()<<endl;
1664     }
1665    
1666     if( doClustering_ ) clustering();
1667     else if( verbosity_ == VERBOSE )
1668     cout<<"clustering is OFF - clusters come from the input file"<<endl;
1669    
1670     if(verbosity_ == VERBOSE ) {
1671     if(clustersECAL_.get() ) {
1672     cout<<"number of ECAL clusters : "<<clustersECAL_->size()<<endl;
1673     }
1674     if(clustersHCAL_.get() ) {
1675     cout<<"number of HCAL clusters : "<<clustersHCAL_->size()<<endl;
1676     }
1677     if(clustersHFEM_.get() ) {
1678     cout<<"number of HFEM clusters : "<<clustersHFEM_->size()<<endl;
1679     }
1680     if(clustersHFHAD_.get() ) {
1681     cout<<"number of HFHAD clusters : "<<clustersHFHAD_->size()<<endl;
1682     }
1683     if(clustersPS_.get() ) {
1684     cout<<"number of PS clusters : "<<clustersPS_->size()<<endl;
1685     }
1686     }
1687    
1688     if(doParticleFlow_) {
1689     particleFlow();
1690    
1691     if (doCompare_) pfCandCompare(entry);
1692     }
1693    
1694     if(doJets_) {
1695     reconstructGenJets();
1696     reconstructCaloJets();
1697     reconstructPFJets();
1698     }
1699    
1700    
1701     // call print() in verbose mode
1702     if( verbosity_ == VERBOSE ) print();
1703    
1704     //COLIN the PFJet and PFMET benchmarks are very messy.
1705     //COLIN compare with the filling of the PFCandidateBenchmark, which is one line.
1706    
1707     goodevent = eventAccepted();
1708    
1709     // evaluate PFJet Benchmark
1710     if(doPFJetBenchmark_) { // start PFJet Benchmark
1711    
1712     PFJetBenchmark_.process(pfJets_, genJets_);
1713     double resPt = PFJetBenchmark_.resPtMax();
1714     double resChargedHadEnergy = PFJetBenchmark_.resChargedHadEnergyMax();
1715     double resNeutralHadEnergy = PFJetBenchmark_.resNeutralHadEnergyMax();
1716     double resNeutralEmEnergy = PFJetBenchmark_.resNeutralEmEnergyMax();
1717    
1718     if( verbosity_ == VERBOSE ){ //start debug print
1719    
1720     cout << " =====================PFJetBenchmark =================" << endl;
1721     cout<<"Resol Pt max "<<resPt
1722     <<" resChargedHadEnergy Max " << resChargedHadEnergy
1723     <<" resNeutralHadEnergy Max " << resNeutralHadEnergy
1724     << " resNeutralEmEnergy Max "<< resNeutralEmEnergy << endl;
1725     } // end debug print
1726    
1727     // PJ : printout for bad events (selected by the "if")
1728     if ( resPt < -1. ) {
1729     cout << " =====================PFJetBenchmark =================" << endl;
1730     cout<<"process entry "<< entry << endl;
1731     cout<<"Resol Pt max "<<resPt
1732     <<" resChargedHadEnergy Max " << resChargedHadEnergy
1733     <<" resNeutralHadEnergy Max " << resNeutralHadEnergy
1734     << " resNeutralEmEnergy Max "<< resNeutralEmEnergy
1735     << " Jet pt " << genJets_[0].pt() << endl;
1736     // return true;
1737     } else {
1738     // return false;
1739     }
1740     // if (resNeutralEmEnergy>0.5) return true;
1741     // else return false;
1742     }// end PFJet Benchmark
1743    
1744     //COLIN would be nice to move this long code to a separate function.
1745     // is it necessary to re-set everything at each event??
1746     if(doPFMETBenchmark_) { // start PFMet Benchmark
1747    
1748     // Fill here the various met benchmarks
1749     // pfMET vs GenMET
1750     metManager_->setMET1(&genParticlesCMSSW_);
1751     metManager_->setMET2(&pfMetsCMSSW_[0]);
1752     metManager_->FillHisto("PF");
1753     // cout events in tail
1754     metManager_->coutTailEvents(entry,DeltaMETcut,DeltaPhicut, MET1cut);
1755    
1756     // caloMET vs GenMET
1757     metManager_->setMET2(&caloMetsCMSSW_[0]);
1758     metManager_->FillHisto("Calo");
1759    
1760     if ( doMet_ ) {
1761     // recomputed pfMET vs GenMET
1762     metManager_->setMET2(*pfCandidates_);
1763     metManager_->FillHisto("recompPF");
1764     metManager_->coutTailEvents(entry,DeltaMETcut,DeltaPhicut, MET1cut);
1765     }
1766    
1767     if (JECinCaloMet_)
1768     {
1769     // corrCaloMET vs GenMET
1770     metManager_->setMET2(&caloMetsCMSSW_[0]);
1771     metManager_->propagateJECtoMET2(caloJetsCMSSW_, corrcaloJetsCMSSW_);
1772     metManager_->FillHisto("corrCalo");
1773     }
1774     }// end PFMET Benchmark
1775    
1776     if( goodevent && doPFCandidateBenchmark_ ) {
1777     pfCandidateManager_.fill( *pfCandidates_, genParticlesCMSSW_);
1778     }
1779    
1780     // evaluate tau Benchmark
1781     if( goodevent && doTauBenchmark_) { // start tau Benchmark
1782     double deltaEt = 0.;
1783     deltaEt = tauBenchmark( *pfCandidates_ );
1784     if( verbosity_ == VERBOSE ) cout<<"delta E_t ="<<deltaEt <<endl;
1785     // cout<<"delta E_t ="<<deltaEt<<" delta E_t Other ="<<deltaEt1<<endl;
1786    
1787    
1788     // if( deltaEt>0.4 ) {
1789     // cout<<deltaEt<<endl;
1790     // return true;
1791     // }
1792     // else return false;
1793    
1794    
1795     } // end tau Benchmark
1796    
1797     if(goodevent && outTree_)
1798     outTree_->Fill();
1799    
1800     if(calibFile_)
1801     printMCCalib(*calibFile_);
1802    
1803     return goodevent;
1804    
1805     }
1806    
1807    
1808    
1809     bool PFRootEventManager::eventAccepted() const {
1810     // return highPtJet(10);
1811     //return highPtPFCandidate( 10, PFCandidate::h );
1812     return true;
1813     }
1814    
1815    
1816     bool PFRootEventManager::highPtJet(double ptMin) const {
1817     for( unsigned i=0; i<pfJets_.size(); ++i) {
1818     if( pfJets_[i].pt() > ptMin ) return true;
1819     }
1820     return false;
1821     }
1822    
1823     bool PFRootEventManager::highPtPFCandidate( double ptMin,
1824     PFCandidate::ParticleType type) const {
1825     for( unsigned i=0; i<pfCandidates_->size(); ++i) {
1826    
1827     const PFCandidate& pfc = (*pfCandidates_)[i];
1828     if(type!= PFCandidate::X &&
1829     pfc.particleId() != type ) continue;
1830     if( pfc.pt() > ptMin ) return true;
1831     }
1832     return false;
1833     }
1834    
1835    
1836     bool PFRootEventManager::readFromSimulation(int entry) {
1837    
1838     if (verbosity_ == VERBOSE ) {
1839     cout <<"start reading from simulation"<<endl;
1840     }
1841    
1842    
1843     // if(!tree_) return false;
1844    
1845     const edm::EventBase& iEvent = *ev_;
1846    
1847    
1848     bool foundstdTracks = iEvent.getByLabel(stdTracksTag_,stdTracksHandle_);
1849     if ( foundstdTracks ) {
1850     stdTracks_ = *stdTracksHandle_;
1851     // cout << "Found " << stdTracks_.size() << " standard tracks" << endl;
1852     } else {
1853     cerr<<"PFRootEventManager::ProcessEntry : stdTracks Collection not found : "
1854     <<entry << " " << stdTracksTag_<<endl;
1855     }
1856    
1857     bool foundMCTruth = iEvent.getByLabel(MCTruthTag_,MCTruthHandle_);
1858     if ( foundMCTruth ) {
1859     MCTruth_ = *MCTruthHandle_;
1860     // cout << "Found MC truth" << endl;
1861     } else {
1862     cerr<<"PFRootEventManager::ProcessEntry : MCTruth Collection not found : "
1863     <<entry << " " << MCTruthTag_<<endl;
1864     }
1865    
1866     bool foundTP = iEvent.getByLabel(trueParticlesTag_,trueParticlesHandle_);
1867     if ( foundTP ) {
1868     trueParticles_ = *trueParticlesHandle_;
1869     // cout << "Found " << trueParticles_.size() << " true particles" << endl;
1870     } else {
1871     cerr<<"PFRootEventManager::ProcessEntry : trueParticles Collection not found : "
1872     <<entry << " " << trueParticlesTag_<<endl;
1873     }
1874    
1875     bool foundECAL = iEvent.getByLabel(rechitsECALTag_,rechitsECALHandle_);
1876     if ( foundECAL ) {
1877     rechitsECAL_ = *rechitsECALHandle_;
1878     // cout << "Found " << rechitsECAL_.size() << " ECAL rechits" << endl;
1879     } else {
1880     cerr<<"PFRootEventManager::ProcessEntry : rechitsECAL Collection not found : "
1881     <<entry << " " << rechitsECALTag_<<endl;
1882     }
1883    
1884     bool foundHCAL = iEvent.getByLabel(rechitsHCALTag_,rechitsHCALHandle_);
1885     if ( foundHCAL ) {
1886     rechitsHCAL_ = *rechitsHCALHandle_;
1887     // cout << "Found " << rechitsHCAL_.size() << " HCAL rechits" << endl;
1888     } else {
1889     cerr<<"PFRootEventManager::ProcessEntry : rechitsHCAL Collection not found : "
1890     <<entry << " " << rechitsHCALTag_<<endl;
1891     }
1892    
1893     bool foundHFEM = iEvent.getByLabel(rechitsHFEMTag_,rechitsHFEMHandle_);
1894     if ( foundHFEM ) {
1895     rechitsHFEM_ = *rechitsHFEMHandle_;
1896     // cout << "Found " << rechitsHFEM_.size() << " HFEM rechits" << endl;
1897     } else {
1898     cerr<<"PFRootEventManager::ProcessEntry : rechitsHFEM Collection not found : "
1899     <<entry << " " << rechitsHFEMTag_<<endl;
1900     }
1901    
1902     bool foundHFHAD = iEvent.getByLabel(rechitsHFHADTag_,rechitsHFHADHandle_);
1903     if ( foundHFHAD ) {
1904     rechitsHFHAD_ = *rechitsHFHADHandle_;
1905     // cout << "Found " << rechitsHFHAD_.size() << " HFHAD rechits" << endl;
1906     } else {
1907     cerr<<"PFRootEventManager::ProcessEntry : rechitsHFHAD Collection not found : "
1908     <<entry << " " << rechitsHFHADTag_<<endl;
1909     }
1910    
1911     for ( unsigned i=0; i<rechitsCLEANEDTags_.size(); ++i ) {
1912     bool foundCLEANED = iEvent.getByLabel(rechitsCLEANEDTags_[i],
1913     rechitsCLEANEDHandles_[i]);
1914     if ( foundCLEANED ) {
1915     rechitsCLEANEDV_[i] = *(rechitsCLEANEDHandles_[i]);
1916     // cout << "Found " << rechitsCLEANEDV_[i].size() << " CLEANED rechits" << endl;
1917     } else {
1918     cerr<<"PFRootEventManager::ProcessEntry : rechitsCLEANED Collection not found : "
1919     <<entry << " " << rechitsCLEANEDTags_[i]<<endl;
1920     }
1921    
1922     }
1923    
1924     bool foundPS = iEvent.getByLabel(rechitsPSTag_,rechitsPSHandle_);
1925     if ( foundPS ) {
1926     rechitsPS_ = *rechitsPSHandle_;
1927     // cout << "Found " << rechitsPS_.size() << " PS rechits" << endl;
1928     } else {
1929     cerr<<"PFRootEventManager::ProcessEntry : rechitsPS Collection not found : "
1930     <<entry << " " << rechitsPSTag_<<endl;
1931     }
1932    
1933     bool foundCT = iEvent.getByLabel(caloTowersTag_,caloTowersHandle_);
1934     if ( foundCT ) {
1935     caloTowers_ = *caloTowersHandle_;
1936     // cout << "Found " << caloTowers_.size() << " calo Towers" << endl;
1937     } else {
1938     cerr<<"PFRootEventManager::ProcessEntry : caloTowers Collection not found : "
1939     <<entry << " " << caloTowersTag_<<endl;
1940     }
1941    
1942     bool foundPV = iEvent.getByLabel(primaryVerticesTag_,primaryVerticesHandle_);
1943     if ( foundPV ) {
1944     primaryVertices_ = *primaryVerticesHandle_;
1945     // cout << "Found " << primaryVertices_.size() << " primary vertices" << endl;
1946     } else {
1947     cerr<<"PFRootEventManager::ProcessEntry : primaryVertices Collection not found : "
1948     <<entry << " " << primaryVerticesTag_<<endl;
1949     }
1950    
1951     bool foundPFV = iEvent.getByLabel(pfDisplacedTrackerVertexTag_,pfDisplacedTrackerVertexHandle_);
1952     if ( foundPFV ) {
1953     pfDisplacedTrackerVertex_ = *pfDisplacedTrackerVertexHandle_;
1954     // cout << "Found " << pfDisplacedTrackerVertex_.size() << " secondary PF vertices" << endl;
1955     } else if ( usePFDisplacedVertexs_ ) {
1956     cerr<<"PFRootEventManager::ProcessEntry : pfDisplacedTrackerVertex Collection not found : "
1957     <<entry << " " << pfDisplacedTrackerVertexTag_<<endl;
1958     }
1959    
1960     bool foundrecTracks = iEvent.getByLabel(recTracksTag_,recTracksHandle_);
1961     if ( foundrecTracks ) {
1962     recTracks_ = *recTracksHandle_;
1963     // cout << "Found " << recTracks_.size() << " PFRecTracks" << endl;
1964     } else {
1965     cerr<<"PFRootEventManager::ProcessEntry : recTracks Collection not found : "
1966     <<entry << " " << recTracksTag_<<endl;
1967     }
1968    
1969     bool foundgsfrecTracks = iEvent.getByLabel(gsfrecTracksTag_,gsfrecTracksHandle_);
1970     if ( foundgsfrecTracks ) {
1971     gsfrecTracks_ = *gsfrecTracksHandle_;
1972     // cout << "Found " << gsfrecTracks_.size() << " GsfPFRecTracks" << endl;
1973     } else {
1974     cerr<<"PFRootEventManager::ProcessEntry : gsfrecTracks Collection not found : "
1975     <<entry << " " << gsfrecTracksTag_<<endl;
1976     }
1977    
1978     bool foundconvBremGsfrecTracks = iEvent.getByLabel(convBremGsfrecTracksTag_,convBremGsfrecTracksHandle_);
1979     if ( foundconvBremGsfrecTracks ) {
1980     convBremGsfrecTracks_ = *convBremGsfrecTracksHandle_;
1981     // cout << "Found " << convBremGsfrecTracks_.size() << " ConvBremGsfPFRecTracks" << endl;
1982     } else if ( useConvBremPFRecTracks_ ) {
1983     cerr<<"PFRootEventManager::ProcessEntry : convBremGsfrecTracks Collection not found : "
1984     <<entry << " " << convBremGsfrecTracksTag_<<endl;
1985     }
1986    
1987     bool foundmuons = iEvent.getByLabel(muonsTag_,muonsHandle_);
1988     if ( foundmuons ) {
1989     muons_ = *muonsHandle_;
1990     // cout << "Found " << muons_.size() << " muons" << endl;
1991     } else {
1992     cerr<<"PFRootEventManager::ProcessEntry : muons Collection not found : "
1993     <<entry << " " << muonsTag_<<endl;
1994     }
1995    
1996     bool foundconversion = iEvent.getByLabel(conversionTag_,conversionHandle_);
1997     if ( foundconversion ) {
1998     conversion_ = *conversionHandle_;
1999     // cout << "Found " << conversion_.size() << " conversion" << endl;
2000     } else if ( usePFConversions_ ) {
2001     cerr<<"PFRootEventManager::ProcessEntry : conversion Collection not found : "
2002     <<entry << " " << conversionTag_<<endl;
2003     }
2004    
2005     bool foundv0 = iEvent.getByLabel(v0Tag_,v0Handle_);
2006     if ( foundv0 ) {
2007     v0_ = *v0Handle_;
2008     // cout << "Found " << v0_.size() << " v0" << endl;
2009     } else if ( usePFV0s_ ) {
2010     cerr<<"PFRootEventManager::ProcessEntry : v0 Collection not found : "
2011     <<entry << " " << v0Tag_<<endl;
2012     }
2013    
2014     bool foundgenJets = iEvent.getByLabel(genJetsTag_,genJetsHandle_);
2015     if ( foundgenJets ) {
2016     genJetsCMSSW_ = *genJetsHandle_;
2017     // cout << "Found " << genJetsCMSSW_.size() << " genJets" << endl;
2018     } else {
2019     cerr<<"PFRootEventManager::ProcessEntry : genJets Collection not found : "
2020     <<entry << " " << genJetsTag_<<endl;
2021     }
2022    
2023     bool foundgenParticlesforJets = iEvent.getByLabel(genParticlesforJetsTag_,genParticlesforJetsHandle_);
2024     if ( foundgenParticlesforJets ) {
2025     genParticlesforJets_ = *genParticlesforJetsHandle_;
2026     // cout << "Found " << genParticlesforJets_.size() << " genParticlesforJets" << endl;
2027     } else {
2028     cerr<<"PFRootEventManager::ProcessEntry : genParticlesforJets Collection not found : "
2029     <<entry << " " << genParticlesforJetsTag_<<endl;
2030     }
2031    
2032     bool foundgenParticlesforMET = iEvent.getByLabel(genParticlesforMETTag_,genParticlesforMETHandle_);
2033     if ( foundgenParticlesforMET ) {
2034     genParticlesCMSSW_ = *genParticlesforMETHandle_;
2035     // cout << "Found " << genParticlesCMSSW_.size() << " genParticlesforMET" << endl;
2036     } else {
2037     cerr<<"PFRootEventManager::ProcessEntry : genParticlesforMET Collection not found : "
2038     <<entry << " " << genParticlesforMETTag_<<endl;
2039     }
2040    
2041     bool foundcaloJets = iEvent.getByLabel(caloJetsTag_,caloJetsHandle_);
2042     if ( foundcaloJets ) {
2043     caloJetsCMSSW_ = *caloJetsHandle_;
2044     // cout << "Found " << caloJetsCMSSW_.size() << " caloJets" << endl;
2045     } else {
2046     cerr<<"PFRootEventManager::ProcessEntry : caloJets Collection not found : "
2047     <<entry << " " << caloJetsTag_<<endl;
2048     }
2049    
2050     bool foundcorrcaloJets = iEvent.getByLabel(corrcaloJetsTag_,corrcaloJetsHandle_);
2051     if ( foundcorrcaloJets ) {
2052     corrcaloJetsCMSSW_ = *corrcaloJetsHandle_;
2053     // cout << "Found " << corrcaloJetsCMSSW_.size() << " corrcaloJets" << endl;
2054     } else {
2055     //cerr<<"PFRootEventManager::ProcessEntry : corrcaloJets Collection not found : "
2056     // <<entry << " " << corrcaloJetsTag_<<endl;
2057     }
2058    
2059     bool foundpfJets = iEvent.getByLabel(pfJetsTag_,pfJetsHandle_);
2060     if ( foundpfJets ) {
2061     pfJetsCMSSW_ = *pfJetsHandle_;
2062     // cout << "Found " << pfJetsCMSSW_.size() << " PFJets" << endl;
2063     } else {
2064     cerr<<"PFRootEventManager::ProcessEntry : PFJets Collection not found : "
2065     <<entry << " " << pfJetsTag_<<endl;
2066     }
2067    
2068     bool foundpfCands = iEvent.getByLabel(pfCandidateTag_,pfCandidateHandle_);
2069     if ( foundpfCands ) {
2070     pfCandCMSSW_ = *pfCandidateHandle_;
2071     // cout << "Found " << pfCandCMSSW_.size() << " PFCandidates" << endl;
2072     } else {
2073     cerr<<"PFRootEventManager::ProcessEntry : PFCandidate Collection not found : "
2074     <<entry << " " << pfCandidateTag_<<endl;
2075     }
2076    
2077     bool foundpfMets = iEvent.getByLabel(pfMetsTag_,pfMetsHandle_);
2078     if ( foundpfMets ) {
2079     pfMetsCMSSW_ = *pfMetsHandle_;
2080     //cout << "Found " << pfMetsCMSSW_.size() << " PFMets" << endl;
2081     } else {
2082     cerr<<"PFRootEventManager::ProcessEntry : PFMets Collection not found : "
2083     <<entry << " " << pfMetsTag_<<endl;
2084     }
2085    
2086     bool foundtcMets = iEvent.getByLabel(tcMetsTag_,tcMetsHandle_);
2087     if ( foundtcMets ) {
2088     tcMetsCMSSW_ = *tcMetsHandle_;
2089     //cout << "Found " << tcMetsCMSSW_.size() << " TCMets" << endl;
2090     } else {
2091     cerr<<"TCRootEventManager::ProcessEntry : TCMets Collection not found : "
2092     <<entry << " " << tcMetsTag_<<endl;
2093     }
2094    
2095     bool foundcaloMets = iEvent.getByLabel(caloMetsTag_,caloMetsHandle_);
2096     if ( foundcaloMets ) {
2097     caloMetsCMSSW_ = *caloMetsHandle_;
2098     //cout << "Found " << caloMetsCMSSW_.size() << " CALOMets" << endl;
2099     } else {
2100     cerr<<"CALORootEventManager::ProcessEntry : CALOMets Collection not found : "
2101     <<entry << " " << caloMetsTag_<<endl;
2102     }
2103    
2104     // now can use the tree
2105    
2106     bool goodevent = true;
2107     if(trueParticles_.size() ) {
2108     // this is a filter to select single particle events.
2109     if(filterNParticles_ && doTauBenchmark_ &&
2110     trueParticles_.size() != filterNParticles_ ) {
2111     cout << "PFRootEventManager : event discarded Nparticles="
2112     <<filterNParticles_<< endl;
2113     goodevent = false;
2114     }
2115     if(goodevent && doTauBenchmark_ && filterHadronicTaus_ && !isHadronicTau() ) {
2116     cout << "PFRootEventManager : leptonic tau discarded " << endl;
2117     goodevent = false;
2118     }
2119     if( goodevent && doTauBenchmark_ && !filterTaus_.empty()
2120     && !countChargedAndPhotons() ) {
2121     assert( filterTaus_.size() == 2 );
2122     cout <<"PFRootEventManager : tau discarded: "
2123     <<"number of charged and neutral particles different from "
2124     <<filterTaus_[0]<<","<<filterTaus_[1]<<endl;
2125     goodevent = false;
2126     }
2127    
2128     if(goodevent)
2129     fillOutEventWithSimParticles( trueParticles_ );
2130    
2131     }
2132    
2133     // if(caloTowersBranch_) {
2134     // if(goodevent)
2135     // fillOutEventWithCaloTowers( caloTowers_ );
2136     // }
2137    
2138     if(rechitsECAL_.size()) {
2139     PreprocessRecHits( rechitsECAL_ , findRecHitNeighbours_);
2140     }
2141     if(rechitsHCAL_.size()) {
2142     PreprocessRecHits( rechitsHCAL_ , findRecHitNeighbours_);
2143     }
2144     if(rechitsHFEM_.size()) {
2145     PreprocessRecHits( rechitsHFEM_ , findRecHitNeighbours_);
2146     }
2147     if(rechitsHFHAD_.size()) {
2148     PreprocessRecHits( rechitsHFHAD_ , findRecHitNeighbours_);
2149     }
2150     rechitsCLEANED_.clear();
2151     for ( unsigned i=0; i<rechitsCLEANEDV_.size(); ++i ) {
2152     if(rechitsCLEANEDV_[i].size()) {
2153     PreprocessRecHits( rechitsCLEANEDV_[i] , false);
2154     for ( unsigned j=0; j<rechitsCLEANEDV_[i].size(); ++j ) {
2155     rechitsCLEANED_.push_back( (rechitsCLEANEDV_[i])[j] );
2156     }
2157     }
2158     }
2159    
2160     if(rechitsPS_.size()) {
2161     PreprocessRecHits( rechitsPS_ , findRecHitNeighbours_);
2162     }
2163    
2164     if ( recTracks_.size() ) {
2165     PreprocessRecTracks( recTracks_);
2166     }
2167    
2168     if(gsfrecTracks_.size()) {
2169     PreprocessRecTracks( gsfrecTracks_);
2170     }
2171    
2172     if(convBremGsfrecTracks_.size()) {
2173     PreprocessRecTracks( convBremGsfrecTracks_);
2174     }
2175    
2176     return goodevent;
2177     }
2178    
2179    
2180     bool PFRootEventManager::isHadronicTau() const {
2181    
2182     for ( unsigned i=0; i < trueParticles_.size(); i++) {
2183     const reco::PFSimParticle& ptc = trueParticles_[i];
2184     const std::vector<int>& ptcdaughters = ptc.daughterIds();
2185     if (abs(ptc.pdgCode()) == 15) {
2186     for ( unsigned int dapt=0; dapt < ptcdaughters.size(); ++dapt) {
2187    
2188     const reco::PFSimParticle& daughter
2189     = trueParticles_[ptcdaughters[dapt]];
2190    
2191    
2192     int pdgdaugther = daughter.pdgCode();
2193     int abspdgdaughter = abs(pdgdaugther);
2194    
2195    
2196     if (abspdgdaughter == 11 ||
2197     abspdgdaughter == 13) {
2198     return false;
2199     }//electron or muons?
2200     }//loop daughter
2201     }//tau
2202     }//loop particles
2203    
2204    
2205     return true;
2206     }
2207    
2208    
2209    
2210     bool PFRootEventManager::countChargedAndPhotons() const {
2211    
2212     int nPhoton = 0;
2213     int nCharged = 0;
2214    
2215     for ( unsigned i=0; i < trueParticles_.size(); i++) {
2216     const reco::PFSimParticle& ptc = trueParticles_[i];
2217    
2218     const std::vector<int>& daughters = ptc.daughterIds();
2219    
2220     // if the particle decays before ECAL, we do not want to
2221     // consider it.
2222     if(!daughters.empty() ) continue;
2223    
2224     double charge = ptc.charge();
2225     double pdgCode = ptc.pdgCode();
2226    
2227     if( abs(charge)>1e-9)
2228     nCharged++;
2229     else if( pdgCode==22 )
2230     nPhoton++;
2231     }
2232    
2233     // const HepMC::GenEvent* myGenEvent = MCTruth_.GetEvent();
2234     // if(!myGenEvent) {
2235     // cerr<<"impossible to filter on the number of charged and "
2236     // <<"neutral particles without the HepMCProduct. "
2237     // <<"Please check that the branch edmHepMCProduct_*_*_* is found"<<endl;
2238     // exit(1);
2239     // }
2240    
2241     // for ( HepMC::GenEvent::particle_const_iterator
2242     // piter = myGenEvent->particles_begin();
2243     // piter != myGenEvent->particles_end();
2244     // ++piter ) {
2245    
2246     // const HepMC::GenParticle* p = *piter;
2247     // int partId = p->pdg_id();Long64_t lines = T->ReadFile("mon_fichier","i:j:k:x:y:z");
2248    
2249     // // pdgTable_->GetParticle( partId )->Print();
2250    
2251     // int charge = chargeValue(partId);
2252     // cout<<partId <<" "<<charge/3.<<endl;
2253    
2254     // if(charge)
2255     // nCharged++;
2256     // else
2257     // nNeutral++;
2258     // }
2259    
2260     if( nCharged == filterTaus_[0] &&
2261     nPhoton == filterTaus_[1] )
2262     return true;
2263     else
2264     return false;
2265     }
2266    
2267    
2268    
2269     int PFRootEventManager::chargeValue(const int& Id) const {
2270    
2271    
2272     //...Purpose: to give three times the charge for a particle/parton.
2273    
2274     // ID = particle ID
2275     // hepchg = particle charge times 3
2276    
2277     int kqa,kq1,kq2,kq3,kqj,irt,kqx,kqn;
2278     int hepchg;
2279    
2280    
2281     int ichg[109]={-1,2,-1,2,-1,2,-1,2,0,0,-3,0,-3,0,-3,0,
2282     -3,0,0,0,0,0,0,3,0,0,0,0,0,0,3,0,3,6,0,0,3,6,0,0,-1,2,-1,2,-1,2,0,0,0,0,
2283     -3,0,-3,0,-3,0,0,0,0,0,-1,2,-1,2,-1,2,0,0,0,0,
2284     -3,0,-3,0,-3,0,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
2285    
2286    
2287     //...Initial values. Simple case of direct readout.
2288     hepchg=0;
2289     kqa=abs(Id);
2290     kqn=kqa/1000000000%10;
2291     kqx=kqa/1000000%10;
2292     kq3=kqa/1000%10;
2293     kq2=kqa/100%10;
2294     kq1=kqa/10%10;
2295     kqj=kqa%10;
2296     irt=kqa%10000;
2297    
2298     //...illegal or ion
2299     //...set ion charge to zero - not enough information
2300     if(kqa==0 || kqa >= 10000000) {
2301    
2302     if(kqn==1) {hepchg=0;}
2303     }
2304     //... direct translation
2305     else if(kqa<=100) {hepchg = ichg[kqa-1];}
2306     //... deuteron or tritium
2307     else if(kqa==100 || kqa==101) {hepchg = -3;}
2308     //... alpha or He3
2309     else if(kqa==102 || kqa==104) {hepchg = -6;}
2310     //... KS and KL (and undefined)
2311     else if(kqj == 0) {hepchg = 0;}
2312     //C... direct translation
2313     else if(kqx>0 && irt<100)
2314     {
2315     hepchg = ichg[irt-1];
2316     if(kqa==1000017 || kqa==1000018) {hepchg = 0;}
2317     if(kqa==1000034 || kqa==1000052) {hepchg = 0;}
2318     if(kqa==1000053 || kqa==1000054) {hepchg = 0;}
2319     if(kqa==5100061 || kqa==5100062) {hepchg = 6;}
2320     }
2321     //...Construction from quark content for heavy meson, diquark, baryon.
2322     //...Mesons.
2323     else if(kq3==0)
2324     {
2325     hepchg = ichg[kq2-1]-ichg[kq1-1];
2326     //...Strange or beauty mesons.
2327     if((kq2==3) || (kq2==5)) {hepchg = ichg[kq1-1]-ichg[kq2-1];}
2328     }
2329     else if(kq1 == 0) {
2330     //...Diquarks.
2331     hepchg = ichg[kq3-1] + ichg[kq2-1];
2332     }
2333    
2334     else{
2335     //...Baryons
2336     hepchg = ichg[kq3-1]+ichg[kq2-1]+ichg[kq1-1];
2337     }
2338    
2339     //... fix sign of charge
2340     if(Id<0 && hepchg!=0) {hepchg = -1*hepchg;}
2341    
2342     // cout << hepchg<< endl;
2343     return hepchg;
2344     }
2345    
2346    
2347    
2348     void
2349     PFRootEventManager::PreprocessRecTracks(reco::PFRecTrackCollection& recTracks) {
2350     for( unsigned i=0; i<recTracks.size(); ++i ) {
2351     recTracks[i].calculatePositionREP();
2352     }
2353     }
2354    
2355     void
2356     PFRootEventManager::PreprocessRecTracks(reco::GsfPFRecTrackCollection& recTracks) {
2357     for( unsigned i=0; i<recTracks.size(); ++i ) {
2358     recTracks[i].calculatePositionREP();
2359     recTracks[i].calculateBremPositionREP();
2360     }
2361     }
2362    
2363    
2364    
2365     void
2366     PFRootEventManager::PreprocessRecHits(reco::PFRecHitCollection& rechits,
2367     bool findNeighbours) {
2368    
2369    
2370     map<unsigned, unsigned> detId2index;
2371    
2372     for(unsigned i=0; i<rechits.size(); i++) {
2373     rechits[i].calculatePositionREP();
2374    
2375     if(findNeighbours)
2376     detId2index.insert( make_pair(rechits[i].detId(), i) );
2377     }
2378    
2379     if(findNeighbours) {
2380     for(unsigned i=0; i<rechits.size(); i++) {
2381     setRecHitNeigbours( rechits[i], detId2index );
2382     }
2383     }
2384     }
2385    
2386    
2387     void PFRootEventManager::setRecHitNeigbours
2388     ( reco::PFRecHit& rh,
2389     const map<unsigned, unsigned>& detId2index ) {
2390    
2391     rh.clearNeighbours();
2392    
2393     vector<unsigned> neighbours4DetId = rh.neighboursIds4();
2394     vector<unsigned> neighbours8DetId = rh.neighboursIds8();
2395    
2396     for( unsigned i=0; i<neighbours4DetId.size(); i++) {
2397     unsigned detId = neighbours4DetId[i];
2398     // cout<<"finding n for detId "<<detId<<endl;
2399     const map<unsigned, unsigned>::const_iterator& it = detId2index.find(detId);
2400    
2401     if(it != detId2index.end() ) {
2402     // cout<<"found n index "<<it->second<<endl;
2403     rh.add4Neighbour( it->second );
2404     }
2405     }
2406    
2407     for( unsigned i=0; i<neighbours8DetId.size(); i++) {
2408     unsigned detId = neighbours8DetId[i];
2409     // cout<<"finding n for detId "<<detId<<endl;
2410     const map<unsigned, unsigned>::const_iterator& it = detId2index.find(detId);
2411    
2412     if(it != detId2index.end() ) {
2413     // cout<<"found n index "<<it->second<<endl;
2414     rh.add8Neighbour( it->second );
2415     }
2416     }
2417    
2418    
2419     }
2420    
2421    
2422     void PFRootEventManager::clustering() {
2423    
2424     if (verbosity_ == VERBOSE ) {
2425     cout <<"start clustering"<<endl;
2426     }
2427    
2428     // ECAL clustering -------------------------------------------
2429    
2430     vector<bool> mask;
2431     fillRecHitMask( mask, rechitsECAL_ );
2432     clusterAlgoECAL_.setMask( mask );
2433    
2434     // edm::OrphanHandle< reco::PFRecHitCollection > rechitsHandleECAL( &rechitsECAL_, edm::ProductID(10001) );
2435     clusterAlgoECAL_.doClustering( rechitsECAL_ );
2436     clustersECAL_ = clusterAlgoECAL_.clusters();
2437    
2438     assert(clustersECAL_.get() );
2439    
2440     fillOutEventWithClusters( *clustersECAL_ );
2441    
2442     // HCAL clustering -------------------------------------------
2443    
2444     fillRecHitMask( mask, rechitsHCAL_ );
2445     clusterAlgoHCAL_.setMask( mask );
2446     // edm::OrphanHandle< reco::PFRecHitCollection > rechitsHandleHCAL( &rechitsHCAL_, edm::ProductID(10002) );
2447     clusterAlgoHCAL_.doClustering( rechitsHCAL_ );
2448     clustersHCAL_ = clusterAlgoHCAL_.clusters();
2449    
2450     fillOutEventWithClusters( *clustersHCAL_ );
2451    
2452     // HF clustering -------------------------------------------
2453    
2454     fillRecHitMask( mask, rechitsHFEM_ );
2455     clusterAlgoHFEM_.setMask( mask );
2456     clusterAlgoHFEM_.doClustering( rechitsHFEM_ );
2457     clustersHFEM_ = clusterAlgoHFEM_.clusters();
2458    
2459     fillRecHitMask( mask, rechitsHFHAD_ );
2460     clusterAlgoHFHAD_.setMask( mask );
2461     clusterAlgoHFHAD_.doClustering( rechitsHFHAD_ );
2462     clustersHFHAD_ = clusterAlgoHFHAD_.clusters();
2463    
2464    
2465     // PS clustering -------------------------------------------
2466    
2467     fillRecHitMask( mask, rechitsPS_ );
2468     clusterAlgoPS_.setMask( mask );
2469     // edm::OrphanHandle< reco::PFRecHitCollection > rechitsHandlePS( &rechitsPS_, edm::ProductID(10003) );
2470     clusterAlgoPS_.doClustering( rechitsPS_ );
2471     clustersPS_ = clusterAlgoPS_.clusters();
2472    
2473     fillOutEventWithClusters( *clustersPS_ );
2474    
2475     }
2476    
2477    
2478    
2479     void
2480     PFRootEventManager::fillOutEventWithClusters(const reco::PFClusterCollection&
2481     clusters) {
2482    
2483     if(!outEvent_) return;
2484    
2485     for(unsigned i=0; i<clusters.size(); i++) {
2486     EventColin::Cluster cluster;
2487     cluster.eta = clusters[i].position().Eta();
2488     cluster.phi = clusters[i].position().Phi();
2489     cluster.e = clusters[i].energy();
2490     cluster.layer = clusters[i].layer();
2491     cluster.type = 1;
2492    
2493     reco::PFTrajectoryPoint::LayerType tpLayer =
2494     reco::PFTrajectoryPoint::NLayers;
2495     switch( clusters[i].layer() ) {
2496     case PFLayer::ECAL_BARREL:
2497     case PFLayer::ECAL_ENDCAP:
2498     tpLayer = reco::PFTrajectoryPoint::ECALEntrance;
2499     break;
2500     case PFLayer::HCAL_BARREL1:
2501     case PFLayer::HCAL_ENDCAP:
2502     tpLayer = reco::PFTrajectoryPoint::HCALEntrance;
2503     break;
2504     default:
2505     break;
2506     }
2507     if(tpLayer < reco::PFTrajectoryPoint::NLayers) {
2508     try {
2509     double peta = -10;
2510     double phi = -10;
2511     double pe = -10;
2512    
2513     const reco::PFSimParticle& ptc
2514     = closestParticle( tpLayer,
2515     cluster.eta, cluster.phi,
2516     peta, phi, pe );
2517    
2518    
2519     cluster.particle.eta = peta;
2520     cluster.particle.phi = phi;
2521     cluster.particle.e = pe;
2522     cluster.particle.pdgCode = ptc.pdgCode();
2523    
2524    
2525     }
2526     catch( std::exception& err ) {
2527     // cerr<<err.what()<<endl;
2528     }
2529     }
2530    
2531     outEvent_->addCluster(cluster);
2532     }
2533     }
2534    
2535    
2536     void
2537     PFRootEventManager::fillOutEventWithSimParticles(const reco::PFSimParticleCollection& trueParticles ) {
2538    
2539     if(!outEvent_) return;
2540    
2541     for ( unsigned i=0; i < trueParticles.size(); i++) {
2542    
2543     const reco::PFSimParticle& ptc = trueParticles[i];
2544    
2545     unsigned ntrajpoints = ptc.nTrajectoryPoints();
2546    
2547     if(ptc.daughterIds().empty() ) { // stable
2548     reco::PFTrajectoryPoint::LayerType ecalEntrance
2549     = reco::PFTrajectoryPoint::ECALEntrance;
2550    
2551     if(ntrajpoints == 3) {
2552     // old format for PFSimCandidates.
2553     // in this case, the PFSimCandidate which does not decay
2554     // before ECAL has 3 points: initial, ecal entrance, hcal entrance
2555     ecalEntrance = static_cast<reco::PFTrajectoryPoint::LayerType>(1);
2556     }
2557     // else continue; // endcap case we do not care;
2558    
2559     const reco::PFTrajectoryPoint& tpatecal
2560     = ptc.extrapolatedPoint( ecalEntrance );
2561    
2562     EventColin::Particle outptc;
2563     outptc.eta = tpatecal.position().Eta();
2564     outptc.phi = tpatecal.position().Phi();
2565     outptc.e = tpatecal.momentum().E();
2566     outptc.pdgCode = ptc.pdgCode();
2567    
2568    
2569     outEvent_->addParticle(outptc);
2570     }
2571     }
2572     }
2573    
2574     void
2575     PFRootEventManager::fillOutEventWithPFCandidates(const reco::PFCandidateCollection& pfCandidates ) {
2576    
2577     if(!outEvent_) return;
2578    
2579     for ( unsigned i=0; i < pfCandidates.size(); i++) {
2580    
2581     const reco::PFCandidate& candidate = pfCandidates[i];
2582    
2583     EventColin::Particle outptc;
2584     outptc.eta = candidate.eta();
2585     outptc.phi = candidate.phi();
2586     outptc.e = candidate.energy();
2587     outptc.pdgCode = candidate.particleId();
2588    
2589    
2590     outEvent_->addCandidate(outptc);
2591     }
2592     }
2593    
2594    
2595     void
2596     PFRootEventManager::fillOutEventWithCaloTowers( const CaloTowerCollection& cts ){
2597    
2598     if(!outEvent_) return;
2599    
2600     for ( unsigned i=0; i < cts.size(); i++) {
2601    
2602     const CaloTower& ct = cts[i];
2603    
2604     EventColin::CaloTower outct;
2605     outct.e = ct.energy();
2606     outct.ee = ct.emEnergy();
2607     outct.eh = ct.hadEnergy();
2608    
2609     outEvent_->addCaloTower( outct );
2610     }
2611     }
2612    
2613    
2614     void
2615     PFRootEventManager::fillOutEventWithBlocks( const reco::PFBlockCollection&
2616     blocks ) {
2617    
2618     if(!outEvent_) return;
2619    
2620     for ( unsigned i=0; i < blocks.size(); i++) {
2621    
2622     // const reco::PFBlock& block = blocks[i];
2623    
2624     EventColin::Block outblock;
2625    
2626     outEvent_->addBlock( outblock );
2627     }
2628     }
2629    
2630    
2631    
2632     void PFRootEventManager::particleFlow() {
2633    
2634     if (verbosity_ == VERBOSE ) {
2635     cout <<"start particle flow"<<endl;
2636     }
2637    
2638    
2639     if( debug_) {
2640     cout<<"PFRootEventManager::particleFlow start"<<endl;
2641     // cout<<"number of elements in memory: "
2642     // <<reco::PFBlockElement::instanceCounter()<<endl;
2643     }
2644    
2645    
2646     edm::OrphanHandle< reco::PFRecTrackCollection > trackh( &recTracks_,
2647     edm::ProductID(1) );
2648    
2649     edm::OrphanHandle< reco::PFClusterCollection > ecalh( clustersECAL_.get(),
2650     edm::ProductID(2) );
2651    
2652     edm::OrphanHandle< reco::PFClusterCollection > hcalh( clustersHCAL_.get(),
2653     edm::ProductID(3) );
2654    
2655     edm::OrphanHandle< reco::PFClusterCollection > hfemh( clustersHFEM_.get(),
2656     edm::ProductID(31) );
2657    
2658     edm::OrphanHandle< reco::PFClusterCollection > hfhadh( clustersHFHAD_.get(),
2659     edm::ProductID(32) );
2660    
2661     edm::OrphanHandle< reco::PFClusterCollection > psh( clustersPS_.get(),
2662     edm::ProductID(4) );
2663    
2664     edm::OrphanHandle< reco::GsfPFRecTrackCollection > gsftrackh( &gsfrecTracks_,
2665     edm::ProductID(5) );
2666    
2667     edm::OrphanHandle< reco::MuonCollection > muonh( &muons_,
2668     edm::ProductID(6) );
2669    
2670     edm::OrphanHandle< reco::PFDisplacedTrackerVertexCollection > displacedh( &pfDisplacedTrackerVertex_,
2671     edm::ProductID(7) );
2672    
2673     edm::OrphanHandle< reco::PFConversionCollection > convh( &conversion_,
2674     edm::ProductID(8) );
2675    
2676     edm::OrphanHandle< reco::PFV0Collection > v0( &v0_,
2677     edm::ProductID(9) );
2678    
2679    
2680     edm::OrphanHandle< reco::VertexCollection > vertexh( &primaryVertices_,
2681     edm::ProductID(10) );
2682    
2683     edm::OrphanHandle< reco::GsfPFRecTrackCollection > convBremGsftrackh( &convBremGsfrecTracks_,
2684     edm::ProductID(11) );
2685    
2686     vector<bool> trackMask;
2687     fillTrackMask( trackMask, recTracks_ );
2688     vector<bool> gsftrackMask;
2689     fillTrackMask( gsftrackMask, gsfrecTracks_ );
2690     vector<bool> ecalMask;
2691     fillClusterMask( ecalMask, *clustersECAL_ );
2692     vector<bool> hcalMask;
2693     fillClusterMask( hcalMask, *clustersHCAL_ );
2694     vector<bool> hfemMask;
2695     fillClusterMask( hfemMask, *clustersHFEM_ );
2696     vector<bool> hfhadMask;
2697     fillClusterMask( hfhadMask, *clustersHFHAD_ );
2698     vector<bool> psMask;
2699     fillClusterMask( psMask, *clustersPS_ );
2700    
2701    
2702     if ( !useAtHLT )
2703     pfBlockAlgo_.setInput( trackh, gsftrackh, convBremGsftrackh,
2704     muonh, displacedh, convh, v0,
2705     ecalh, hcalh, hfemh, hfhadh, psh,
2706     trackMask,gsftrackMask,
2707     ecalMask, hcalMask, hfemMask, hfhadMask, psMask );
2708     else
2709     pfBlockAlgo_.setInput( trackh, muonh, ecalh, hcalh, hfemh, hfhadh, psh,
2710     trackMask, ecalMask, hcalMask, psMask );
2711    
2712     pfBlockAlgo_.findBlocks();
2713    
2714     if( debug_) cout<<pfBlockAlgo_<<endl;
2715    
2716     pfBlocks_ = pfBlockAlgo_.transferBlocks();
2717    
2718     pfAlgo_.setPFVertexParameters(true, primaryVertices_);
2719    
2720     pfAlgo_.reconstructParticles( *pfBlocks_.get() );
2721     // pfAlgoOther_.reconstructParticles( blockh );
2722    
2723     pfAlgo_.checkCleaning( rechitsCLEANED_ );
2724    
2725     if( debug_) cout<< pfAlgo_<<endl;
2726     pfCandidates_ = pfAlgo_.transferCandidates();
2727     // pfCandidatesOther_ = pfAlgoOther_.transferCandidates();
2728    
2729     fillOutEventWithPFCandidates( *pfCandidates_ );
2730    
2731     if( debug_) cout<<"PFRootEventManager::particleFlow stop"<<endl;
2732     }
2733    
2734     void PFRootEventManager::pfCandCompare(int entry) {
2735    
2736     bool differentSize = pfCandCMSSW_.size() != pfCandidates_->size();
2737     if ( differentSize ) {
2738     cout << "+++WARNING+++ PFCandidate size changed for entry "
2739     << entry << " !" << endl
2740     << " - original size : " << pfCandCMSSW_.size() << endl
2741     << " - current size : " << pfCandidates_->size() << endl;
2742     } else {
2743     for(unsigned i=0; i<pfCandidates_->size(); i++) {
2744     double deltaE = (*pfCandidates_)[i].energy()-pfCandCMSSW_[i].energy();
2745     double deltaEta = (*pfCandidates_)[i].eta()-pfCandCMSSW_[i].eta();
2746     double deltaPhi = (*pfCandidates_)[i].phi()-pfCandCMSSW_[i].phi();
2747     if ( fabs(deltaE) > 1E-5 ||
2748     fabs(deltaEta) > 1E-9 ||
2749     fabs(deltaPhi) > 1E-9 ) {
2750     cout << "+++WARNING+++ PFCandidate " << i
2751     << " changed for entry " << entry << " ! " << endl
2752     << " - Original : " << pfCandCMSSW_[i] << endl
2753     << " - Current : " << (*pfCandidates_)[i] << endl
2754     << " DeltaE = : " << deltaE << endl
2755     << " DeltaEta = : " << deltaEta << endl
2756     << " DeltaPhi = : " << deltaPhi << endl << endl;
2757     }
2758     }
2759     }
2760    
2761     }
2762    
2763    
2764     void PFRootEventManager::reconstructGenJets() {
2765    
2766     if (verbosity_ == VERBOSE || jetsDebug_) {
2767     cout<<endl;
2768     cout<<"start reconstruct GenJets --- "<<endl;
2769     cout<< " input gen particles for jet: all neutrinos removed ; muons present" << endl;
2770     }
2771    
2772     genJets_.clear();
2773     genParticlesforJetsPtrs_.clear();
2774    
2775     for(unsigned i=0; i<genParticlesforJets_.size(); i++) {
2776    
2777     const reco::GenParticle& genPart = *(genParticlesforJets_[i]);
2778    
2779     // remove all muons/neutrinos for PFJet studies
2780     // if (reco::isNeutrino( genPart ) || reco::isMuon( genPart )) continue;
2781     // remove all neutrinos for PFJet studies
2782     if (reco::isNeutrino( genPart )) continue;
2783     // Work-around a bug in the pythia di-jet gun.
2784     if (abs(genPart.pdgId())<7 || abs(genPart.pdgId())==21 ) continue;
2785    
2786     if (jetsDebug_ ) {
2787     cout << " #" << i << " PDG code:" << genPart.pdgId()
2788     << " status " << genPart.status()
2789     << ", p/pt/eta/phi: " << genPart.p() << '/' << genPart.pt()
2790     << '/' << genPart.eta() << '/' << genPart.phi() << endl;
2791     }
2792    
2793     genParticlesforJetsPtrs_.push_back( refToPtr(genParticlesforJets_[i]) );
2794     }
2795    
2796     vector<ProtoJet> protoJets;
2797     reconstructFWLiteJets(genParticlesforJetsPtrs_, protoJets );
2798    
2799    
2800     // Convert Protojets to GenJets
2801     int ijet = 0;
2802     typedef vector <ProtoJet>::const_iterator IPJ;
2803     for (IPJ ipj = protoJets.begin(); ipj != protoJets.end (); ipj++) {
2804     const ProtoJet& protojet = *ipj;
2805     const ProtoJet::Constituents& constituents = protojet.getTowerList();
2806    
2807     reco::Jet::Point vertex (0,0,0); // do not have true vertex yet, use default
2808     GenJet::Specific specific;
2809     JetMaker::makeSpecific(constituents, &specific);
2810     // constructor without constituents
2811     GenJet newJet (protojet.p4(), vertex, specific);
2812    
2813     // last step is to copy the constituents into the jet (new jet definition since 18X)
2814     // namespace reco {
2815     //class Jet : public CompositeRefBaseCandidate {
2816     // public:
2817     // typedef reco::CandidateBaseRefVector Constituents;
2818    
2819     ProtoJet::Constituents::const_iterator constituent = constituents.begin();
2820     for (; constituent != constituents.end(); ++constituent) {
2821     // find index of this ProtoJet constituent in the overall collection PFconstit
2822     // see class IndexedCandidate in JetRecoTypes.h
2823     uint index = constituent->index();
2824     newJet.addDaughter( genParticlesforJetsPtrs_[index] );
2825     } // end loop on ProtoJet constituents
2826     // last step: copy ProtoJet Variables into Jet
2827     newJet.setJetArea(protojet.jetArea());
2828     newJet.setPileup(protojet.pileup());
2829     newJet.setNPasses(protojet.nPasses());
2830     ++ijet;
2831     if (jetsDebug_ ) cout<<" gen jet "<<ijet<<" "<<newJet.print()<<endl;
2832     genJets_.push_back (newJet);
2833    
2834     } // end loop on protojets iterator IPJ
2835    
2836     }
2837    
2838     void PFRootEventManager::reconstructCaloJets() {
2839    
2840     if (verbosity_ == VERBOSE || jetsDebug_ ) {
2841     cout<<endl;
2842     cout<<"start reconstruct CaloJets --- "<<endl;
2843     }
2844     caloJets_.clear();
2845     caloTowersPtrs_.clear();
2846    
2847     for( unsigned i=0; i<caloTowers_.size(); i++) {
2848     reco::CandidatePtr candPtr( &caloTowers_, i );
2849     caloTowersPtrs_.push_back( candPtr );
2850     }
2851    
2852     reconstructFWLiteJets( caloTowersPtrs_, caloJets_ );
2853    
2854     if (jetsDebug_ ) {
2855     for(unsigned ipj=0; ipj<caloJets_.size(); ipj++) {
2856     const ProtoJet& protojet = caloJets_[ipj];
2857     cout<<" calo jet "<<ipj<<" "<<protojet.pt() <<endl;
2858     }
2859     }
2860    
2861     }
2862    
2863    
2864     void PFRootEventManager::reconstructPFJets() {
2865    
2866     if (verbosity_ == VERBOSE || jetsDebug_) {
2867     cout<<endl;
2868     cout<<"start reconstruct PF Jets --- "<<endl;
2869     }
2870     pfJets_.clear();
2871     pfCandidatesPtrs_.clear();
2872    
2873     for( unsigned i=0; i<pfCandidates_->size(); i++) {
2874     reco::CandidatePtr candPtr( pfCandidates_.get(), i );
2875     pfCandidatesPtrs_.push_back( candPtr );
2876     }
2877    
2878     vector<ProtoJet> protoJets;
2879     reconstructFWLiteJets(pfCandidatesPtrs_, protoJets );
2880    
2881     // Convert Protojets to PFJets
2882    
2883     int ijet = 0;
2884     typedef vector <ProtoJet>::const_iterator IPJ;
2885     for (IPJ ipj = protoJets.begin(); ipj != protoJets.end (); ipj++) {
2886     const ProtoJet& protojet = *ipj;
2887     const ProtoJet::Constituents& constituents = protojet.getTowerList();
2888    
2889     reco::Jet::Point vertex (0,0,0); // do not have true vertex yet, use default
2890     PFJet::Specific specific;
2891     JetMaker::makeSpecific(constituents, &specific);
2892     // constructor without constituents
2893     PFJet newJet (protojet.p4(), vertex, specific);
2894    
2895     // last step is to copy the constituents into the jet (new jet definition since 18X)
2896     // namespace reco {
2897     //class Jet : public CompositeRefBaseCandidate {
2898     // public:
2899     // typedef reco::CandidateBaseRefVector Constituents;
2900    
2901     ProtoJet::Constituents::const_iterator constituent = constituents.begin();
2902     for (; constituent != constituents.end(); ++constituent) {
2903     // find index of this ProtoJet constituent in the overall collection PFconstit
2904     // see class IndexedCandidate in JetRecoTypes.h
2905     uint index = constituent->index();
2906     newJet.addDaughter(pfCandidatesPtrs_[index]);
2907     } // end loop on ProtoJet constituents
2908     // last step: copy ProtoJet Variables into Jet
2909     newJet.setJetArea(protojet.jetArea());
2910     newJet.setPileup(protojet.pileup());
2911     newJet.setNPasses(protojet.nPasses());
2912     ++ijet;
2913     if (jetsDebug_ ) cout<<" PF jet "<<ijet<<" "<<newJet.print()<<endl;
2914     pfJets_.push_back (newJet);
2915    
2916     } // end loop on protojets iterator IPJ
2917    
2918     }
2919    
2920     void
2921     PFRootEventManager::reconstructFWLiteJets(const reco::CandidatePtrVector& Candidates, vector<ProtoJet>& output ) {
2922    
2923     // cout<<"!!! Make FWLite Jets "<<endl;
2924     JetReco::InputCollection input;
2925     // vector<ProtoJet> output;
2926     jetMaker_.applyCuts (Candidates, &input);
2927     if (jetAlgoType_==1) {// ICone
2928     /// Produce jet collection using CMS Iterative Cone Algorithm
2929     jetMaker_.makeIterativeConeJets(input, &output);
2930     }
2931     if (jetAlgoType_==2) {// MCone
2932     jetMaker_.makeMidpointJets(input, &output);
2933     }
2934     if (jetAlgoType_==3) {// Fastjet
2935     jetMaker_.makeFastJets(input, &output);
2936     }
2937     if((jetAlgoType_>3)||(jetAlgoType_<0)) {
2938     cout<<"Unknown Jet Algo ! " <<jetAlgoType_ << endl;
2939     }
2940     //if (jetsDebug_) cout<<"Proto Jet Size " <<output.size()<<endl;
2941    
2942     }
2943    
2944    
2945    
2946     ///COLIN need to get rid of this mess.
2947     double
2948     PFRootEventManager::tauBenchmark( const reco::PFCandidateCollection& candidates) {
2949     //std::cout << "building jets from MC particles,"
2950     // << "PF particles and caloTowers" << std::endl;
2951    
2952     //initialize Jets Reconstruction
2953     jetAlgo_.Clear();
2954    
2955     //COLIN The following comment is not really adequate,
2956     // since partTOTMC is not an action..
2957     // one should say what this variable is for.
2958     // see my comment later
2959     //MAKING TRUE PARTICLE JETS
2960     // TLorentzVector partTOTMC;
2961    
2962     // colin: the following is not necessary
2963     // since the lorentz vectors are initialized to 0,0,0,0.
2964     // partTOTMC.SetPxPyPzE(0.0, 0.0, 0.0, 0.0);
2965    
2966     //MAKING JETS WITH TAU DAUGHTERS
2967     //Colin: this vector vectPART is not necessary !!
2968     //it was just an efficient copy of trueparticles_.....
2969     // vector<reco::PFSimParticle> vectPART;
2970     // for ( unsigned i=0; i < trueParticles_.size(); i++) {
2971     // const reco::PFSimParticle& ptc = trueParticles_[i];
2972     // vectPART.push_back(ptc);
2973     // }//loop
2974    
2975    
2976     //COLIN one must not loop on trueParticles_ to find taus.
2977     //the code was giving wrong results on non single tau events.
2978    
2979     // first check that this is a single tau event.
2980    
2981     TLorentzVector partTOTMC;
2982     bool tauFound = false;
2983     bool tooManyTaus = false;
2984     if (fastsim_){
2985    
2986     for ( unsigned i=0; i < trueParticles_.size(); i++) {
2987     const reco::PFSimParticle& ptc = trueParticles_[i];
2988     if (abs(ptc.pdgCode()) == 15) {
2989     // this is a tau
2990     if( i ) tooManyTaus = true;
2991     else tauFound=true;
2992     }
2993     }
2994    
2995     if(!tauFound || tooManyTaus ) {
2996     // cerr<<"PFRootEventManager::tauBenchmark : not a single tau event"<<endl;
2997     return -9999;
2998     }
2999    
3000     // loop on the daugthers of the tau
3001     const std::vector<int>& ptcdaughters = trueParticles_[0].daughterIds();
3002    
3003     // will contain the sum of the lorentz vectors of the visible daughters
3004     // of the tau.
3005    
3006    
3007     for ( unsigned int dapt=0; dapt < ptcdaughters.size(); ++dapt) {
3008    
3009     const reco::PFTrajectoryPoint& tpatvtx
3010     = trueParticles_[ptcdaughters[dapt]].trajectoryPoint(0);
3011     TLorentzVector partMC;
3012     partMC.SetPxPyPzE(tpatvtx.momentum().Px(),
3013     tpatvtx.momentum().Py(),
3014     tpatvtx.momentum().Pz(),
3015     tpatvtx.momentum().E());
3016    
3017     partTOTMC += partMC;
3018     if (tauBenchmarkDebug_) {
3019     //pdgcode
3020     int pdgcode = trueParticles_[ptcdaughters[dapt]].pdgCode();
3021     cout << pdgcode << endl;
3022     cout << tpatvtx << endl;
3023     cout << partMC.Px() << " " << partMC.Py() << " "
3024     << partMC.Pz() << " " << partMC.E()
3025     << " PT="
3026     << sqrt(partMC.Px()*partMC.Px()+partMC.Py()*partMC.Py())
3027     << endl;
3028     }//debug
3029     }//loop daughter
3030     }else{
3031    
3032     uint itau=0;
3033     const HepMC::GenEvent* myGenEvent = MCTruth_.GetEvent();
3034     for ( HepMC::GenEvent::particle_const_iterator
3035     piter = myGenEvent->particles_begin();
3036     piter != myGenEvent->particles_end();
3037     ++piter ) {
3038    
3039    
3040     if (abs((*piter)->pdg_id())==15){
3041     itau++;
3042     tauFound=true;
3043     for ( HepMC::GenVertex::particles_out_const_iterator bp =
3044     (*piter)->end_vertex()->particles_out_const_begin();
3045     bp != (*piter)->end_vertex()->particles_out_const_end(); ++bp ) {
3046     uint nuId=abs((*bp)->pdg_id());
3047     bool isNeutrino=(nuId==12)||(nuId==14)||(nuId==16);
3048     if (!isNeutrino){
3049    
3050    
3051     TLorentzVector partMC;
3052     partMC.SetPxPyPzE((*bp)->momentum().x(),
3053     (*bp)->momentum().y(),
3054     (*bp)->momentum().z(),
3055     (*bp)->momentum().e());
3056     partTOTMC += partMC;
3057     }
3058     }
3059     }
3060     }
3061     if (itau>1) tooManyTaus=true;
3062    
3063     if(!tauFound || tooManyTaus ) {
3064     cerr<<"PFRootEventManager::tauBenchmark : not a single tau event"<<endl;
3065     return -9999;
3066     }
3067     }
3068    
3069    
3070    
3071    
3072    
3073    
3074    
3075     EventColin::Jet jetmc;
3076    
3077     jetmc.eta = partTOTMC.Eta();
3078     jetmc.phi = partTOTMC.Phi();
3079     jetmc.et = partTOTMC.Et();
3080     jetmc.e = partTOTMC.E();
3081    
3082     if(outEvent_) outEvent_->addJetMC( jetmc );
3083    
3084     /*
3085     //MC JETS RECONSTRUCTION (visible energy)
3086     for ( unsigned i=0; i < trueParticles_.size(); i++) {
3087     const reco::PFSimParticle& ptc = trueParticles_[i];
3088     const std::vector<int>& ptcdaughters = ptc.daughterIds();
3089    
3090     //PARTICULE NOT DISINTEGRATING BEFORE ECAL
3091     if(ptcdaughters.size() != 0) continue;
3092    
3093     //TAKE INFO AT VERTEX //////////////////////////////////////////////////
3094     const reco::PFTrajectoryPoint& tpatvtx = ptc.trajectoryPoint(0);
3095     TLorentzVector partMC;
3096     partMC.SetPxPyPzE(tpatvtx.momentum().Px(),
3097     tpatvtx.momentum().Py(),
3098     tpatvtx.momentum().Pz(),
3099     tpatvtx.momentum().E());
3100    
3101     partTOTMC += partMC;
3102     if (tauBenchmarkDebug_) {
3103     //pdgcode
3104     int pdgcode = ptc.pdgCode();
3105     cout << pdgcode << endl;
3106     cout << tpatvtx << endl;
3107     cout << partMC.Px() << " " << partMC.Py() << " "
3108     << partMC.Pz() << " " << partMC.E()
3109     << " PT="
3110     << sqrt(partMC.Px()*partMC.Px()+partMC.Py()*partMC.Py())
3111     << endl;
3112     }//debug?
3113     }//loop true particles
3114     */
3115     if (tauBenchmarkDebug_) {
3116     cout << " ET Vector=" << partTOTMC.Et()
3117     << " " << partTOTMC.Eta()
3118     << " " << partTOTMC.Phi() << endl; cout << endl;
3119     }//debug
3120    
3121     //////////////////////////////////////////////////////////////////////////
3122     //CALO TOWER JETS (ECAL+HCAL Towers)
3123     //cout << endl;
3124     //cout << "THERE ARE " << caloTowers_.size() << " CALO TOWERS" << endl;
3125    
3126     vector<TLorentzVector> allcalotowers;
3127     // vector<double> allemenergy;
3128     // vector<double> allhadenergy;
3129     double threshCaloTowers = 1E-10;
3130     for ( unsigned int i = 0; i < caloTowers_.size(); ++i) {
3131    
3132     if(caloTowers_[i].energy() < threshCaloTowers) {
3133     // cout<<"skipping calotower"<<endl;
3134     continue;
3135     }
3136    
3137     TLorentzVector caloT;
3138     TVector3 pepr( caloTowers_[i].eta(),
3139     caloTowers_[i].phi(),
3140     caloTowers_[i].energy());
3141     TVector3 pxyz = Utils::VectorEPRtoXYZ( pepr );
3142     caloT.SetPxPyPzE(pxyz.X(),pxyz.Y(),pxyz.Z(),caloTowers_[i].energy());
3143     allcalotowers.push_back(caloT);
3144     // allemenergy.push_back( caloTowers_[i].emEnergy() );
3145     // allhadenergy.push_back( caloTowers_[i].hadEnergy() );
3146     }//loop calo towers
3147     if ( tauBenchmarkDebug_)
3148     cout << " RETRIEVED " << allcalotowers.size()
3149     << " CALOTOWER 4-VECTORS " << endl;
3150    
3151     //ECAL+HCAL tower jets computation
3152     jetAlgo_.Clear();
3153     const vector< PFJetAlgorithm::Jet >& caloTjets
3154     = jetAlgo_.FindJets( &allcalotowers );
3155    
3156     //cout << caloTjets.size() << " CaloTower Jets found" << endl;
3157     double JetEHTETmax = 0.0;
3158     for ( unsigned i = 0; i < caloTjets.size(); i++) {
3159     TLorentzVector jetmom = caloTjets[i].GetMomentum();
3160     double jetcalo_pt = sqrt(jetmom.Px()*jetmom.Px()+jetmom.Py()*jetmom.Py());
3161     double jetcalo_et = jetmom.Et();
3162    
3163    
3164    
3165     EventColin::Jet jet;
3166     jet.eta = jetmom.Eta();
3167     jet.phi = jetmom.Phi();
3168     jet.et = jetmom.Et();
3169     jet.e = jetmom.E();
3170    
3171     const vector<int>& indexes = caloTjets[i].GetIndexes();
3172     for( unsigned ii=0; ii<indexes.size(); ii++){
3173     jet.ee += caloTowers_[ indexes[ii] ].emEnergy();
3174     jet.eh += caloTowers_[ indexes[ii] ].hadEnergy();
3175     jet.ete += caloTowers_[ indexes[ii] ].emEt();
3176     jet.eth += caloTowers_[ indexes[ii] ].hadEt();
3177     }
3178    
3179     if(outEvent_) outEvent_->addJetEHT( jet );
3180    
3181     if ( tauBenchmarkDebug_) {
3182     cout << " ECAL+HCAL jet : " << caloTjets[i] << endl;
3183     cout << jetmom.Px() << " " << jetmom.Py() << " "
3184     << jetmom.Pz() << " " << jetmom.E()
3185     << " PT=" << jetcalo_pt << endl;
3186     }//debug
3187    
3188     if (jetcalo_et >= JetEHTETmax)
3189     JetEHTETmax = jetcalo_et;
3190     }//loop MCjets
3191    
3192     //////////////////////////////////////////////////////////////////
3193     //PARTICLE FLOW JETS
3194     vector<TLorentzVector> allrecparticles;
3195     // if ( tauBenchmarkDebug_) {
3196     // cout << endl;
3197     // cout << " THERE ARE " << pfBlocks_.size() << " EFLOW BLOCKS" << endl;
3198     // }//debug
3199    
3200     // for ( unsigned iefb = 0; iefb < pfBlocks_.size(); iefb++) {
3201     // const std::vector< PFBlockParticle >& recparticles
3202     // = pfBlocks_[iefb].particles();
3203    
3204    
3205    
3206     for(unsigned i=0; i<candidates.size(); i++) {
3207    
3208     // if (tauBenchmarkDebug_)
3209     // cout << " there are " << recparticles.size()
3210     // << " particle in this block" << endl;
3211    
3212     const reco::PFCandidate& candidate = candidates[i];
3213    
3214     if (tauBenchmarkDebug_) {
3215     cout << i << " " << candidate << endl;
3216     int type = candidate.particleId();
3217     cout << " type= " << type << " " << candidate.charge()
3218     << endl;
3219     }//debug
3220    
3221     const math::XYZTLorentzVector& PFpart = candidate.p4();
3222    
3223     TLorentzVector partRec(PFpart.Px(),
3224     PFpart.Py(),
3225     PFpart.Pz(),
3226     PFpart.E());
3227    
3228     //loading 4-vectors of Rec particles
3229     allrecparticles.push_back( partRec );
3230    
3231     }//loop on candidates
3232    
3233    
3234     if (tauBenchmarkDebug_)
3235     cout << " THERE ARE " << allrecparticles.size()
3236     << " RECONSTRUCTED 4-VECTORS" << endl;
3237    
3238     jetAlgo_.Clear();
3239     const vector< PFJetAlgorithm::Jet >& PFjets
3240     = jetAlgo_.FindJets( &allrecparticles );
3241    
3242     if (tauBenchmarkDebug_)
3243     cout << PFjets.size() << " PF Jets found" << endl;
3244     double JetPFETmax = 0.0;
3245     for ( unsigned i = 0; i < PFjets.size(); i++) {
3246     TLorentzVector jetmom = PFjets[i].GetMomentum();
3247     double jetpf_pt = sqrt(jetmom.Px()*jetmom.Px()+jetmom.Py()*jetmom.Py());
3248     double jetpf_et = jetmom.Et();
3249    
3250     EventColin::Jet jet;
3251     jet.eta = jetmom.Eta();
3252     jet.phi = jetmom.Phi();
3253     jet.et = jetmom.Et();
3254     jet.e = jetmom.E();
3255    
3256     if(outEvent_) outEvent_->addJetPF( jet );
3257    
3258     if (tauBenchmarkDebug_) {
3259     cout <<" Rec jet : "<< PFjets[i] <<endl;
3260     cout << jetmom.Px() << " " << jetmom.Py() << " "
3261     << jetmom.Pz() << " " << jetmom.E()
3262     << " PT=" << jetpf_pt << " eta="<< jetmom.Eta()
3263     << " Phi=" << jetmom.Phi() << endl;
3264     cout << "------------------------------------------------" << endl;
3265     }//debug
3266    
3267     if (jetpf_et >= JetPFETmax)
3268     JetPFETmax = jetpf_et;
3269     }//loop PF jets
3270    
3271     //fill histos
3272    
3273     double deltaEtEHT = JetEHTETmax - partTOTMC.Et();
3274     h_deltaETvisible_MCEHT_->Fill(deltaEtEHT);
3275    
3276     double deltaEt = JetPFETmax - partTOTMC.Et();
3277     h_deltaETvisible_MCPF_ ->Fill(deltaEt);
3278    
3279     if (verbosity_ == VERBOSE ) {
3280     cout << "tau benchmark E_T(PF) - E_T(true) = " << deltaEt << endl;
3281     }
3282    
3283     return deltaEt/partTOTMC.Et();
3284     }//Makejets
3285    
3286    
3287    
3288    
3289    
3290     /*
3291    
3292     void PFRootEventManager::lookForGenParticle(unsigned barcode) {
3293    
3294     const HepMC::GenEvent* event = MCTruth_.GetEvent();
3295     if(!event) {
3296     cerr<<"no GenEvent"<<endl;
3297     return;
3298     }
3299    
3300     const HepMC::GenParticle* particle = event->barcode_to_particle(barcode);
3301     if(!particle) {
3302     cerr<<"no particle with barcode "<<barcode<<endl;
3303     return;
3304     }
3305    
3306     math::XYZTLorentzVector momentum(particle->momentum().px(),
3307     particle->momentum().py(),
3308     particle->momentum().pz(),
3309     particle->momentum().e());
3310    
3311     double eta = momentum.Eta();
3312     double phi = momentum.phi();
3313    
3314     double phisize = 0.05;
3315     double etasize = 0.05;
3316    
3317     double etagate = displayZoomFactor_ * etasize;
3318     double phigate = displayZoomFactor_ * phisize;
3319    
3320     if(displayHist_[EPE]) {
3321     displayHist_[EPE]->GetXaxis()->SetRangeUser(eta-etagate, eta+etagate);
3322     displayHist_[EPE]->GetYaxis()->SetRangeUser(phi-phigate, phi+phigate);
3323     }
3324     if(displayHist_[EPH]) {
3325     displayHist_[EPH]->GetXaxis()->SetRangeUser(eta-etagate, eta+etagate);
3326     displayHist_[EPH]->GetYaxis()->SetRangeUser(phi-phigate, phi+phigate);
3327     }
3328    
3329     updateDisplay();
3330    
3331     }
3332     */
3333    
3334    
3335    
3336     string PFRootEventManager::expand(const string& oldString) const {
3337    
3338     string newString = oldString;
3339    
3340     string dollar = "$";
3341     string slash = "/";
3342    
3343     // protection necessary or segv !!
3344     int dollarPos = newString.find(dollar,0);
3345     if( dollarPos == -1 ) return oldString;
3346    
3347     int lengh = newString.find(slash,0) - newString.find(dollar,0) + 1;
3348     string env_variable =
3349     newString.substr( ( newString.find(dollar,0) + 1 ), lengh -2);
3350     // the env var could be defined between { }
3351     int begin = env_variable.find_first_of("{");
3352     int end = env_variable.find_last_of("}");
3353    
3354     // cout << "var=" << env_variable << begin<<" "<<end<< endl;
3355    
3356    
3357     env_variable = env_variable.substr( begin+1, end-1 );
3358     // cout << "var=" << env_variable <<endl;
3359    
3360    
3361     // cerr<<"call getenv "<<endl;
3362     char* directory = getenv( env_variable.c_str() );
3363    
3364     if(!directory) {
3365     cerr<<"please define environment variable $"<<env_variable<<endl;
3366     delete this;
3367     exit(1);
3368     }
3369     string sdir = directory;
3370     sdir += "/";
3371    
3372     newString.replace( 0, lengh , sdir);
3373    
3374     if (verbosity_ == VERBOSE ) {
3375     cout << "expand " <<oldString<<" to "<< newString << endl;
3376     }
3377    
3378     return newString;
3379     }
3380    
3381    
3382     void
3383     PFRootEventManager::printMCCalib(ofstream& out) const {
3384    
3385     if(!out) return;
3386     // if (!out.is_open()) return;
3387    
3388     // Use only for one PFSimParticle/GenParticles
3389     const HepMC::GenEvent* myGenEvent = MCTruth_.GetEvent();
3390     if(!myGenEvent) return;
3391     int nGen = 0;
3392     for ( HepMC::GenEvent::particle_const_iterator
3393     piter = myGenEvent->particles_begin();
3394     piter != myGenEvent->particles_end();
3395     ++piter ) nGen++;
3396     int nSim = trueParticles_.size();
3397     if ( nGen != 1 || nSim != 1 ) return;
3398    
3399     // One GenJet
3400     if ( genJets_.size() != 1 ) return;
3401     double true_E = genJets_[0].p();
3402     double true_eta = genJets_[0].eta();
3403     double true_phi = genJets_[0].phi();
3404    
3405     // One particle-flow jet
3406     // if ( pfJets_.size() != 1 ) return;
3407     double rec_ECALEnergy = 0.;
3408     double rec_HCALEnergy = 0.;
3409     double deltaRMin = 999.;
3410     unsigned int theJet = 0;
3411     for ( unsigned int ijet=0; ijet<pfJets_.size(); ++ijet ) {
3412     double rec_ECAL = pfJets_[ijet].neutralEmEnergy();
3413     double rec_HCAL = pfJets_[ijet].neutralHadronEnergy();
3414     double rec_eta = pfJets_[0].eta();
3415     double rec_phi = pfJets_[0].phi();
3416     double deltaR = std::sqrt( (rec_eta-true_eta)*(rec_eta-true_eta)
3417     + (rec_phi-true_phi)*(rec_phi-true_phi) );
3418     if ( deltaR < deltaRMin ) {
3419     deltaRMin = deltaR;
3420     rec_ECALEnergy = rec_ECAL;
3421     rec_HCALEnergy = rec_HCAL;
3422     }
3423     }
3424     if ( deltaRMin > 0.1 ) return;
3425    
3426     std::vector < PFCandidatePtr > constituents = pfJets_[theJet].getPFConstituents ();
3427     double pat_ECALEnergy = 0.;
3428     double pat_HCALEnergy = 0.;
3429     for (unsigned ic = 0; ic < constituents.size (); ++ic) {
3430     if ( constituents[ic]->particleId() < 4 ) continue;
3431     if ( constituents[ic]->particleId() == 4 )
3432     pat_ECALEnergy += constituents[ic]->rawEcalEnergy();
3433     else if ( constituents[ic]->particleId() == 5 )
3434     pat_HCALEnergy += constituents[ic]->rawHcalEnergy();
3435     }
3436    
3437     double col_ECALEnergy = rec_ECALEnergy * 1.05;
3438     double col_HCALEnergy = rec_HCALEnergy;
3439     if ( col_HCALEnergy > 1E-6 )
3440     col_HCALEnergy = col_ECALEnergy > 1E-6 ?
3441     6. + 1.06*rec_HCALEnergy : (2.17*rec_HCALEnergy+1.73)/(1.+std::exp(2.49/rec_HCALEnergy));
3442    
3443     double jam_ECALEnergy = rec_ECALEnergy;
3444     double jam_HCALEnergy = rec_HCALEnergy;
3445     clusterCalibration_->
3446     getCalibratedEnergyEmbedAInHcal(jam_ECALEnergy, jam_HCALEnergy, true_eta, true_phi);
3447    
3448     out << true_eta << " " << true_phi << " " << true_E
3449     << " " << rec_ECALEnergy << " " << rec_HCALEnergy
3450     << " " << pat_ECALEnergy << " " << pat_HCALEnergy
3451     << " " << deltaRMin << std::endl;
3452     }
3453    
3454     void PFRootEventManager::print(ostream& out,int maxNLines ) const {
3455    
3456     if(!out) return;
3457    
3458     //If McTruthMatching print a detailed list
3459     //of matching between simparticles and PFCandidates
3460     //MCTruth Matching vectors.
3461     std::vector< std::list <simMatch> > candSimMatchTrack;
3462     std::vector< std::list <simMatch> > candSimMatchEcal;
3463     if( printMCTruthMatching_){
3464     mcTruthMatching( std::cout,
3465     *pfCandidates_,
3466     candSimMatchTrack,
3467     candSimMatchEcal);
3468     }
3469    
3470    
3471     if( printRecHits_ ) {
3472     out<<"ECAL RecHits ==============================================="<<endl;
3473     printRecHits(rechitsECAL_, clusterAlgoECAL_, out ); out<<endl;
3474     out<<"HCAL RecHits ==============================================="<<endl;
3475     printRecHits(rechitsHCAL_, clusterAlgoHCAL_, out ); out<<endl;
3476     out<<"HFEM RecHits ==============================================="<<endl;
3477     printRecHits(rechitsHFEM_, clusterAlgoHFEM_, out ); out<<endl;
3478     out<<"HFHAD RecHits =============================================="<<endl;
3479     printRecHits(rechitsHFHAD_, clusterAlgoHFHAD_, out ); out<<endl;
3480     out<<"PS RecHits ================================================="<<endl;
3481     printRecHits(rechitsPS_, clusterAlgoPS_, out ); out<<endl;
3482     }
3483    
3484     if( printClusters_ ) {
3485     out<<"ECAL Clusters ============================================="<<endl;
3486     printClusters( *clustersECAL_, out); out<<endl;
3487     out<<"HCAL Clusters ============================================="<<endl;
3488     printClusters( *clustersHCAL_, out); out<<endl;
3489     out<<"HFEM Clusters ============================================="<<endl;
3490     printClusters( *clustersHFEM_, out); out<<endl;
3491     out<<"HFHAD Clusters ============================================"<<endl;
3492     printClusters( *clustersHFHAD_, out); out<<endl;
3493     out<<"PS Clusters ============================================="<<endl;
3494     printClusters( *clustersPS_, out); out<<endl;
3495     }
3496     bool printTracks = true;
3497     if( printTracks) {
3498    
3499     }
3500     if( printPFBlocks_ ) {
3501     out<<"Particle Flow Blocks ======================================"<<endl;
3502     for(unsigned i=0; i<pfBlocks_->size(); i++) {
3503     out<<i<<" "<<(*pfBlocks_)[i]<<endl;
3504     }
3505     out<<endl;
3506     }
3507     if(printPFCandidates_) {
3508     out<<"Particle Flow Candidates =================================="<<endl;
3509     double mex = 0.;
3510     double mey = 0.;
3511     for(unsigned i=0; i<pfCandidates_->size(); i++) {
3512     const PFCandidate& pfc = (*pfCandidates_)[i];
3513     mex -= pfc.px();
3514     mey -= pfc.py();
3515     if(pfc.pt()>printPFCandidatesPtMin_)
3516     out<<i<<" " <<(*pfCandidates_)[i]<<endl;
3517     }
3518     out<<endl;
3519     out<< "MEX, MEY, MET ============================================" <<endl
3520     << mex << " " << mey << " " << sqrt(mex*mex+mey*mey);
3521     out<<endl;
3522     out<<endl;
3523    
3524     //print a detailed list of PFSimParticles matching
3525     //the PFCandiates
3526     if(printMCTruthMatching_){
3527     cout<<"MCTruthMatching Results"<<endl;
3528     for(unsigned icand=0; icand<pfCandidates_->size();
3529     icand++) {
3530     out <<icand<<" " <<(*pfCandidates_)[icand]<<endl;
3531     out << "is matching:" << endl;
3532    
3533     //tracking
3534     ITM it_t = candSimMatchTrack[icand].begin();
3535     ITM itend_t = candSimMatchTrack[icand].end();
3536     for(;it_t!=itend_t;++it_t){
3537     unsigned simid = it_t->second;
3538     out << "\tSimParticle " << trueParticles_[simid]
3539     <<endl;
3540     out << "\t\tthrough Track matching pTrectrack="
3541     << it_t->first << " GeV" << endl;
3542     }//loop simparticles
3543    
3544     ITM it_e = candSimMatchEcal[icand].begin();
3545     ITM itend_e = candSimMatchEcal[icand].end();
3546     for(;it_e!=itend_e;++it_e){
3547     unsigned simid = it_e->second;
3548     out << "\tSimParticle " << trueParticles_[simid]
3549     << endl;
3550     out << "\t\tsimparticle contributing to a total of "
3551     << it_e->first
3552     << " GeV of its ECAL cluster"
3553     << endl;
3554     }//loop simparticles
3555     cout<<"________________"<<endl;
3556     }//loop candidates
3557     }////print mc truth matching
3558     }
3559     if(printPFJets_) {
3560     out<<"Jets ====================================================="<<endl;
3561     out<<"Particle Flow: "<<endl;
3562     for(unsigned i=0; i<pfJets_.size(); i++) {
3563     if (pfJets_[i].pt() > printPFJetsPtMin_ )
3564     out<<i<<pfJets_[i].print()<<endl;
3565     }
3566     out<<endl;
3567     out<<"Generated: "<<endl;
3568     for(unsigned i=0; i<genJets_.size(); i++) {
3569     if (genJets_[i].pt() > printPFJetsPtMin_ )
3570     out<<i<<genJets_[i].print()<<endl;
3571     // <<" invisible energy = "<<genJets_[i].invisibleEnergy()<<endl;
3572     }
3573     out<<endl;
3574     out<<"Calo: "<<endl;
3575     for(unsigned i=0; i<caloJets_.size(); i++) {
3576     out<<"pt = "<<caloJets_[i].pt()<<endl;
3577     }
3578     out<<endl;
3579     }
3580     if( printSimParticles_ ) {
3581     out<<"Sim Particles ==========================================="<<endl;
3582    
3583     for(unsigned i=0; i<trueParticles_.size(); i++) {
3584     if( trackInsideGCut( trueParticles_[i]) ){
3585    
3586     const reco::PFSimParticle& ptc = trueParticles_[i];
3587    
3588     // get trajectory at start point
3589     const reco::PFTrajectoryPoint& tp0 = ptc.extrapolatedPoint( 0 );
3590    
3591     if(tp0.momentum().pt()>printSimParticlesPtMin_)
3592     out<<"\t"<<trueParticles_[i]<<endl;
3593     }
3594     }
3595    
3596     //print a detailed list of PFSimParticles matching
3597     //the PFCandiates
3598     if(printMCTruthMatching_) {
3599     cout<<"MCTruthMatching Results"<<endl;
3600     for ( unsigned i=0; i < trueParticles_.size(); i++) {
3601     cout << "==== Particle Simulated " << i << endl;
3602     const reco::PFSimParticle& ptc = trueParticles_[i];
3603     out <<i<<" "<<trueParticles_[i]<<endl;
3604    
3605     if(!ptc.daughterIds().empty()){
3606     cout << "Look at the desintegration products" << endl;
3607     cout << endl;
3608     continue;
3609     }
3610    
3611     //TRACKING
3612     if(ptc.rectrackId() != 99999){
3613     cout << "matching pfCandidate (trough tracking): " << endl;
3614     for( unsigned icand=0; icand<pfCandidates_->size()
3615     ; icand++ )
3616     {
3617     ITM it = candSimMatchTrack[icand].begin();
3618     ITM itend = candSimMatchTrack[icand].end();
3619     for(;it!=itend;++it)
3620     if( i == it->second ){
3621     out<<icand<<" "<<(*pfCandidates_)[icand]<<endl;
3622     cout << endl;
3623     }
3624     }//loop candidate
3625     }//trackmatch
3626    
3627     //CALORIMETRY
3628     vector<unsigned> rechitSimIDs
3629     = ptc.recHitContrib();
3630     vector<double> rechitSimFrac
3631     = ptc.recHitContribFrac();
3632     //cout << "Number of rechits contrib =" << rechitSimIDs.size() << endl;
3633     if( !rechitSimIDs.size() ) continue; //no rechit
3634    
3635     cout << "matching pfCandidate (through ECAL): " << endl;
3636    
3637     //look at total ECAL desposition:
3638     double totalEcalE = 0.0;
3639     for(unsigned irh=0; irh<rechitsECAL_.size();++irh)
3640     for ( unsigned isimrh=0; isimrh < rechitSimIDs.size();
3641     isimrh++ )
3642     if(rechitSimIDs[isimrh] == rechitsECAL_[irh].detId())
3643     totalEcalE += (rechitsECAL_[irh].energy()*rechitSimFrac[isimrh]/100.0);
3644     cout << "For info, this particle deposits E=" << totalEcalE
3645     << "(GeV) in the ECAL" << endl;
3646    
3647     for( unsigned icand=0; icand<pfCandidates_->size()
3648     ; icand++ )
3649     {
3650     ITM it = candSimMatchEcal[icand].begin();
3651     ITM itend = candSimMatchEcal[icand].end();
3652     for(;it!=itend;++it)
3653     if( i == it->second )
3654     out<<icand<<" "<<it->first<<"GeV "<<(*pfCandidates_)[icand]<<endl;
3655     }//loop candidate
3656     cout << endl;
3657     }//loop particles
3658     }//mctruthmatching
3659    
3660     }
3661    
3662    
3663     if ( printGenParticles_ ) {
3664     printGenParticles(out,maxNLines);
3665     }
3666     }
3667    
3668    
3669     void
3670     PFRootEventManager::printGenParticles(std::ostream& out,
3671     int maxNLines) const {
3672    
3673    
3674     const HepMC::GenEvent* myGenEvent = MCTruth_.GetEvent();
3675     if(!myGenEvent) return;
3676    
3677     out<<"GenParticles ==========================================="<<endl;
3678    
3679     std::cout << "Id Gen Name eta phi pT E Vtx1 "
3680     << " x y z "
3681     << "Moth Vtx2 eta phi R Z Da1 Da2 Ecal?"
3682     << std::endl;
3683    
3684     int nLines = 0;
3685     for ( HepMC::GenEvent::particle_const_iterator
3686     piter = myGenEvent->particles_begin();
3687     piter != myGenEvent->particles_end();
3688     ++piter ) {
3689    
3690     if( nLines == maxNLines) break;
3691     nLines++;
3692    
3693     HepMC::GenParticle* p = *piter;
3694     /* */
3695     int partId = p->pdg_id();
3696    
3697     // We have here a subset of particles only.
3698     // To be filled according to the needs.
3699     /*switch(partId) {
3700     case 1: { name = "d"; break; }
3701     case 2: { name = "u"; break; }
3702     case 3: { name = "s"; break; }
3703     case 4: { name = "c"; break; }
3704     case 5: { name = "b"; break; }
3705     case 6: { name = "t"; break; }
3706     case -1: { name = "~d"; break; }
3707     case -2: { name = "~u"; break; }
3708     case -3: { name = "~s"; break; }
3709     case -4: { name = "~c"; break; }
3710     case -5: { name = "~b"; break; }
3711     case -6: { name = "~t"; break; }
3712     case 11: { name = "e-"; break; }
3713     case -11: { name = "e+"; break; }
3714     case 12: { name = "nu_e"; break; }
3715     case -12: { name = "~nu_e"; break; }
3716     case 13: { name = "mu-"; break; }
3717     case -13: { name = "mu+"; break; }
3718     case 14: { name = "nu_mu"; break; }
3719     case -14: { name = "~nu_mu"; break; }
3720     case 15: { name = "tau-"; break; }
3721     case -15: { name = "tau+"; break; }
3722     case 16: { name = "nu_tau"; break; }
3723     case -16: { name = "~nu_tau"; break; }
3724     case 21: { name = "gluon"; break; }
3725     case 22: { name = "gamma"; break; }
3726     case 23: { name = "Z0"; break; }
3727     case 24: { name = "W+"; break; }
3728     case 25: { name = "H0"; break; }
3729     case -24: { name = "W-"; break; }
3730     case 111: { name = "pi0"; break; }
3731     case 113: { name = "rho0"; break; }
3732     case 223: { name = "omega"; break; }
3733     case 333: { name = "phi"; break; }
3734     case 443: { name = "J/psi"; break; }
3735     case 553: { name = "Upsilon"; break; }
3736     case 130: { name = "K0L"; break; }
3737     case 211: { name = "pi+"; break; }
3738     case -211: { name = "pi-"; break; }
3739     case 213: { name = "rho+"; break; }
3740     case -213: { name = "rho-"; break; }
3741     case 221: { name = "eta"; break; }
3742     case 331: { name = "eta'"; break; }
3743     case 441: { name = "etac"; break; }
3744     case 551: { name = "etab"; break; }
3745     case 310: { name = "K0S"; break; }
3746     case 311: { name = "K0"; break; }
3747     case -311: { name = "Kbar0"; break; }
3748     case 321: { name = "K+"; break; }
3749     case -321: { name = "K-"; break; }
3750     case 411: { name = "D+"; break; }
3751     case -411: { name = "D-"; break; }
3752     case 421: { name = "D0"; break; }
3753     case 431: { name = "Ds_+"; break; }
3754     case -431: { name = "Ds_-"; break; }
3755     case 511: { name = "B0"; break; }
3756     case 521: { name = "B+"; break; }
3757     case -521: { name = "B-"; break; }
3758     case 531: { name = "Bs_0"; break; }
3759     case 541: { name = "Bc_+"; break; }
3760     case -541: { name = "Bc_+"; break; }
3761     case 313: { name = "K*0"; break; }
3762     case -313: { name = "K*bar0"; break; }
3763     case 323: { name = "K*+"; break; }
3764     case -323: { name = "K*-"; break; }
3765     case 413: { name = "D*+"; break; }
3766     case -413: { name = "D*-"; break; }
3767     case 423: { name = "D*0"; break; }
3768     case 513: { name = "B*0"; break; }
3769     case 523: { name = "B*+"; break; }
3770     case -523: { name = "B*-"; break; }
3771     case 533: { name = "B*_s0"; break; }
3772     case 543: { name = "B*_c+"; break; }
3773     case -543: { name = "B*_c-"; break; }
3774     case 1114: { name = "Delta-"; break; }
3775     case -1114: { name = "Deltabar+"; break; }
3776     case -2112: { name = "nbar0"; break; }
3777     case 2112: { name = "n"; break; }
3778     case 2114: { name = "Delta0"; break; }
3779     case -2114: { name = "Deltabar0"; break; }
3780     case 3122: { name = "Lambda0"; break; }
3781     case -3122: { name = "Lambdabar0"; break; }
3782     case 3112: { name = "Sigma-"; break; }
3783     case -3112: { name = "Sigmabar+"; break; }
3784     case 3212: { name = "Sigma0"; break; }
3785     case -3212: { name = "Sigmabar0"; break; }
3786     case 3214: { name = "Sigma*0"; break; }
3787     case -3214: { name = "Sigma*bar0"; break; }
3788     case 3222: { name = "Sigma+"; break; }
3789     case -3222: { name = "Sigmabar-"; break; }
3790     case 2212: { name = "p"; break; }
3791     case -2212: { name = "~p"; break; }
3792     case -2214: { name = "Delta-"; break; }
3793     case 2214: { name = "Delta+"; break; }
3794     case -2224: { name = "Deltabar--"; break; }
3795     case 2224: { name = "Delta++"; break; }
3796     default: {
3797     name = "unknown";
3798     cout << "Unknown code : " << partId << endl;
3799     }
3800     }
3801     */
3802     std::string latexString;
3803     std::string name = getGenParticleName(partId,latexString);
3804    
3805     math::XYZTLorentzVector momentum1(p->momentum().px(),
3806     p->momentum().py(),
3807     p->momentum().pz(),
3808     p->momentum().e() );
3809    
3810     if(momentum1.pt()<printGenParticlesPtMin_) continue;
3811    
3812     int vertexId1 = 0;
3813    
3814     if ( !p->production_vertex() && p->pdg_id() == 2212 ) continue;
3815    
3816     math::XYZVector vertex1;
3817     vertexId1 = -1;
3818    
3819     if(p->production_vertex() ) {
3820     vertex1.SetCoordinates( p->production_vertex()->position().x()/10.,
3821     p->production_vertex()->position().y()/10.,
3822     p->production_vertex()->position().z()/10. );
3823     vertexId1 = p->production_vertex()->barcode();
3824     }
3825    
3826     out.setf(std::ios::fixed, std::ios::floatfield);
3827     out.setf(std::ios::right, std::ios::adjustfield);
3828    
3829     out << std::setw(4) << p->barcode() << " "
3830     << name;
3831    
3832     for(unsigned int k=0;k<11-name.length() && k<12; k++) out << " ";
3833    
3834     double eta = momentum1.eta();
3835     if ( eta > +10. ) eta = +10.;
3836     if ( eta < -10. ) eta = -10.;
3837    
3838     out << std::setw(6) << std::setprecision(2) << eta << " "
3839     << std::setw(6) << std::setprecision(2) << momentum1.phi() << " "
3840     << std::setw(7) << std::setprecision(2) << momentum1.pt() << " "
3841     << std::setw(7) << std::setprecision(2) << momentum1.e() << " "
3842     << std::setw(4) << vertexId1 << " "
3843     << std::setw(6) << std::setprecision(1) << vertex1.x() << " "
3844     << std::setw(6) << std::setprecision(1) << vertex1.y() << " "
3845     << std::setw(6) << std::setprecision(1) << vertex1.z() << " ";
3846    
3847    
3848     if( p->production_vertex() ) {
3849     if ( p->production_vertex()->particles_in_size() ) {
3850     const HepMC::GenParticle* mother =
3851     *(p->production_vertex()->particles_in_const_begin());
3852    
3853     out << std::setw(4) << mother->barcode() << " ";
3854     }
3855     else
3856     out << " " ;
3857     }
3858    
3859     if ( p->end_vertex() ) {
3860     math::XYZTLorentzVector vertex2(p->end_vertex()->position().x()/10.,
3861     p->end_vertex()->position().y()/10.,
3862     p->end_vertex()->position().z()/10.,
3863     p->end_vertex()->position().t()/10.);
3864     int vertexId2 = p->end_vertex()->barcode();
3865    
3866     std::vector<const HepMC::GenParticle*> children;
3867     HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
3868     p->end_vertex()->particles_out_const_begin();
3869     HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
3870     p->end_vertex()->particles_out_const_end();
3871     for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
3872     children.push_back(*firstDaughterIt);
3873     }
3874    
3875     out << std::setw(4) << vertexId2 << " "
3876     << std::setw(6) << std::setprecision(2) << vertex2.eta() << " "
3877     << std::setw(6) << std::setprecision(2) << vertex2.phi() << " "
3878     << std::setw(5) << std::setprecision(1) << vertex2.pt() << " "
3879     << std::setw(6) << std::setprecision(1) << vertex2.z() << " ";
3880    
3881     for ( unsigned id=0; id<children.size(); ++id )
3882     out << std::setw(4) << children[id]->barcode() << " ";
3883     }
3884     out << std::endl;
3885     }
3886     }
3887    
3888     void PFRootEventManager::printRecHits(const reco::PFRecHitCollection& rechits, const PFClusterAlgo& clusterAlgo, ostream& out) const{
3889    
3890     for(unsigned i=0; i<rechits.size(); i++) {
3891     string seedstatus = " ";
3892     if(clusterAlgo.isSeed(i) )
3893     seedstatus = "SEED";
3894     printRecHit(rechits[i], i, seedstatus.c_str(), out);
3895     }
3896     return;
3897     }
3898    
3899     void PFRootEventManager::printRecHit(const reco::PFRecHit& rh,
3900     unsigned index,
3901     const char* seedstatus,
3902     ostream& out) const {
3903    
3904     if(!out) return;
3905     double eta = rh.position().Eta();
3906     double phi = rh.position().Phi();
3907     double energy = rh.energy();
3908    
3909     if(energy<printRecHitsEMin_) return;
3910    
3911     TCutG* cutg = (TCutG*) gROOT->FindObject("CUTG");
3912     if( !cutg || cutg->IsInside( eta, phi ) )
3913     out<<index<<"\t"<<seedstatus<<" "<<rh<<endl;
3914     }
3915    
3916     void PFRootEventManager::printClusters(const reco::PFClusterCollection& clusters,
3917     ostream& out ) const {
3918     for(unsigned i=0; i<clusters.size(); i++) {
3919     printCluster(clusters[i], out);
3920     }
3921     return;
3922     }
3923    
3924     void PFRootEventManager::printCluster(const reco::PFCluster& cluster,
3925     ostream& out ) const {
3926    
3927     if(!out) return;
3928    
3929     double eta = cluster.position().Eta();
3930     double phi = cluster.position().Phi();
3931     double energy = cluster.energy();
3932    
3933     if(energy<printClustersEMin_) return;
3934    
3935     TCutG* cutg = (TCutG*) gROOT->FindObject("CUTG");
3936     if( !cutg || cutg->IsInside( eta, phi ) )
3937     out<<cluster<<endl;
3938     }
3939    
3940    
3941    
3942    
3943    
3944     bool PFRootEventManager::trackInsideGCut( const reco::PFTrack& track ) const {
3945    
3946     TCutG* cutg = (TCutG*) gROOT->FindObject("CUTG");
3947     if(!cutg) return true;
3948    
3949     const vector< reco::PFTrajectoryPoint >& points = track.trajectoryPoints();
3950    
3951     for( unsigned i=0; i<points.size(); i++) {
3952     if( ! points[i].isValid() ) continue;
3953    
3954     const math::XYZPoint& pos = points[i].position();
3955     if( cutg->IsInside( pos.Eta(), pos.Phi() ) ) return true;
3956     }
3957    
3958     // no point inside cut
3959     return false;
3960     }
3961    
3962    
3963     void
3964     PFRootEventManager::fillRecHitMask( vector<bool>& mask,
3965     const reco::PFRecHitCollection& rechits )
3966     const {
3967    
3968     TCutG* cutg = (TCutG*) gROOT->FindObject("CUTG");
3969     if(!cutg) return;
3970    
3971     mask.clear();
3972     mask.reserve( rechits.size() );
3973     for(unsigned i=0; i<rechits.size(); i++) {
3974    
3975     double eta = rechits[i].position().Eta();
3976     double phi = rechits[i].position().Phi();
3977    
3978     if( cutg->IsInside( eta, phi ) )
3979     mask.push_back( true );
3980     else
3981     mask.push_back( false );
3982     }
3983     }
3984    
3985     void
3986     PFRootEventManager::fillClusterMask(vector<bool>& mask,
3987     const reco::PFClusterCollection& clusters)
3988     const {
3989    
3990     TCutG* cutg = (TCutG*) gROOT->FindObject("CUTG");
3991     if(!cutg) return;
3992    
3993     mask.clear();
3994     mask.reserve( clusters.size() );
3995     for(unsigned i=0; i<clusters.size(); i++) {
3996    
3997     double eta = clusters[i].position().Eta();
3998     double phi = clusters[i].position().Phi();
3999    
4000     if( cutg->IsInside( eta, phi ) )
4001     mask.push_back( true );
4002     else
4003     mask.push_back( false );
4004     }
4005     }
4006    
4007     void
4008     PFRootEventManager::fillTrackMask(vector<bool>& mask,
4009     const reco::PFRecTrackCollection& tracks)
4010     const {
4011    
4012     TCutG* cutg = (TCutG*) gROOT->FindObject("CUTG");
4013     if(!cutg) return;
4014    
4015     mask.clear();
4016     mask.reserve( tracks.size() );
4017     for(unsigned i=0; i<tracks.size(); i++) {
4018     if( trackInsideGCut( tracks[i] ) )
4019     mask.push_back( true );
4020     else
4021     mask.push_back( false );
4022     }
4023     }
4024    
4025     void
4026     PFRootEventManager::fillTrackMask(vector<bool>& mask,
4027     const reco::GsfPFRecTrackCollection& tracks)
4028     const {
4029    
4030     TCutG* cutg = (TCutG*) gROOT->FindObject("CUTG");
4031     if(!cutg) return;
4032    
4033     mask.clear();
4034     mask.reserve( tracks.size() );
4035     for(unsigned i=0; i<tracks.size(); i++) {
4036     if( trackInsideGCut( tracks[i] ) )
4037     mask.push_back( true );
4038     else
4039     mask.push_back( false );
4040     }
4041     }
4042    
4043    
4044     const reco::PFSimParticle&
4045     PFRootEventManager::closestParticle( reco::PFTrajectoryPoint::LayerType layer,
4046     double eta, double phi,
4047     double& peta, double& pphi, double& pe)
4048     const {
4049    
4050    
4051     if( trueParticles_.empty() ) {
4052     string err = "PFRootEventManager::closestParticle : ";
4053     err += "vector of PFSimParticles is empty";
4054     throw std::length_error( err.c_str() );
4055     }
4056    
4057     double mindist2 = 99999999;
4058     unsigned iClosest=0;
4059     for(unsigned i=0; i<trueParticles_.size(); i++) {
4060    
4061     const reco::PFSimParticle& ptc = trueParticles_[i];
4062    
4063     // protection for old version of the PFSimParticle
4064     // dataformats.
4065     if( layer >= reco::PFTrajectoryPoint::NLayers ||
4066     ptc.nTrajectoryMeasurements() + layer >=
4067     ptc.nTrajectoryPoints() ) {
4068     continue;
4069     }
4070    
4071     const reco::PFTrajectoryPoint& tp
4072     = ptc.extrapolatedPoint( layer );
4073    
4074     peta = tp.position().Eta();
4075     pphi = tp.position().Phi();
4076     pe = tp.momentum().E();
4077    
4078     double deta = peta - eta;
4079     double dphi = pphi - phi;
4080    
4081     double dist2 = deta*deta + dphi*dphi;
4082    
4083     if(dist2<mindist2) {
4084     mindist2 = dist2;
4085     iClosest = i;
4086     }
4087     }
4088    
4089     return trueParticles_[iClosest];
4090     }
4091    
4092    
4093    
4094     //-----------------------------------------------------------
4095     void
4096     PFRootEventManager::readCMSSWJets() {
4097    
4098     cout<<"CMSSW Gen jets : size = " << genJetsCMSSW_.size() << endl;
4099     for ( unsigned i = 0; i < genJetsCMSSW_.size(); i++) {
4100     cout<<"Gen jet Et : " << genJetsCMSSW_[i].et() << endl;
4101     }
4102     cout<<"CMSSW PF jets : size = " << pfJetsCMSSW_.size() << endl;
4103     for ( unsigned i = 0; i < pfJetsCMSSW_.size(); i++) {
4104     cout<<"PF jet Et : " << pfJetsCMSSW_[i].et() << endl;
4105     }
4106     cout<<"CMSSW Calo jets : size = " << caloJetsCMSSW_.size() << endl;
4107     for ( unsigned i = 0; i < caloJetsCMSSW_.size(); i++) {
4108     cout<<"Calo jet Et : " << caloJetsCMSSW_[i].et() << endl;
4109     }
4110     }
4111     //________________________________________________________________
4112     std::string PFRootEventManager::getGenParticleName(int partId, std::string &latexString) const
4113     {
4114     std::string name;
4115     switch(partId) {
4116     case 1: { name = "d";latexString="d"; break; }
4117     case 2: { name = "u";latexString="u";break; }
4118     case 3: { name = "s";latexString="s" ;break; }
4119     case 4: { name = "c";latexString="c" ; break; }
4120     case 5: { name = "b";latexString="b" ; break; }
4121     case 6: { name = "t";latexString="t" ; break; }
4122     case -1: { name = "~d";latexString="#bar{d}" ; break; }
4123     case -2: { name = "~u";latexString="#bar{u}" ; break; }
4124     case -3: { name = "~s";latexString="#bar{s}" ; break; }
4125     case -4: { name = "~c";latexString="#bar{c}" ; break; }
4126     case -5: { name = "~b";latexString="#bar{b}" ; break; }
4127     case -6: { name = "~t";latexString="#bar{t}" ; break; }
4128     case 11: { name = "e-";latexString=name ; break; }
4129     case -11: { name = "e+";latexString=name ; break; }
4130     case 12: { name = "nu_e";latexString="#nu_{e}" ; break; }
4131     case -12: { name = "~nu_e";latexString="#bar{#nu}_{e}" ; break; }
4132     case 13: { name = "mu-";latexString="#mu-" ; break; }
4133     case -13: { name = "mu+";latexString="#mu+" ; break; }
4134     case 14: { name = "nu_mu";latexString="#nu_{mu}" ; break; }
4135     case -14: { name = "~nu_mu";latexString="#bar{#nu}_{#mu}"; break; }
4136     case 15: { name = "tau-";latexString="#tau^{-}" ; break; }
4137     case -15: { name = "tau+";latexString="#tau^{+}" ; break; }
4138     case 16: { name = "nu_tau";latexString="#nu_{#tau}" ; break; }
4139     case -16: { name = "~nu_tau";latexString="#bar{#nu}_{#tau}"; break; }
4140     case 21: { name = "gluon";latexString= name; break; }
4141     case 22: { name = "gamma";latexString= "#gamma"; break; }
4142     case 23: { name = "Z0";latexString="Z^{0}" ; break; }
4143     case 24: { name = "W+";latexString="W^{+}" ; break; }
4144     case 25: { name = "H0";latexString=name ; break; }
4145     case -24: { name = "W-";latexString="W^{-}" ; break; }
4146     case 111: { name = "pi0";latexString="#pi^{0}" ; break; }
4147     case 113: { name = "rho0";latexString="#rho^{0}" ; break; }
4148     case 223: { name = "omega";latexString="#omega" ; break; }
4149     case 333: { name = "phi";latexString= "#phi"; break; }
4150     case 443: { name = "J/psi";latexString="J/#psi" ; break; }
4151     case 553: { name = "Upsilon";latexString="#Upsilon" ; break; }
4152     case 130: { name = "K0L";latexString=name ; break; }
4153     case 211: { name = "pi+";latexString="#pi^{+}" ; break; }
4154     case -211: { name = "pi-";latexString="#pi^{-}" ; break; }
4155     case 213: { name = "rho+";latexString="#rho^{+}" ; break; }
4156     case -213: { name = "rho-";latexString="#rho^{-}" ; break; }
4157     case 221: { name = "eta";latexString="#eta" ; break; }
4158     case 331: { name = "eta'";latexString="#eta'" ; break; }
4159     case 441: { name = "etac";latexString="#eta_{c}" ; break; }
4160     case 551: { name = "etab";latexString= "#eta_{b}"; break; }
4161     case 310: { name = "K0S";latexString=name ; break; }
4162     case 311: { name = "K0";latexString="K^{0}" ; break; }
4163     case -311: { name = "Kbar0";latexString="#bar{#Kappa}^{0}" ; break; }
4164     case 321: { name = "K+";latexString= "K^{+}"; break; }
4165     case -321: { name = "K-";latexString="K^{-}"; break; }
4166     case 411: { name = "D+";latexString="D^{+}" ; break; }
4167     case -411: { name = "D-";latexString="D^{-}"; break; }
4168     case 421: { name = "D0";latexString=name ; break; }
4169     case 431: { name = "Ds_+";latexString="Ds_{+}" ; break; }
4170     case -431: { name = "Ds_-";latexString="Ds_{-}" ; break; }
4171     case 511: { name = "B0";latexString= name; break; }
4172     case 521: { name = "B+";latexString="B^{+}" ; break; }
4173     case -521: { name = "B-";latexString="B^{-}" ; break; }
4174     case 531: { name = "Bs_0";latexString="Bs_{0}" ; break; }
4175     case 541: { name = "Bc_+";latexString="Bc_{+}" ; break; }
4176     case -541: { name = "Bc_+";latexString="Bc_{+}" ; break; }
4177     case 313: { name = "K*0";latexString="K^{*0}" ; break; }
4178     case -313: { name = "K*bar0";latexString="#bar{K}^{*0}" ; break; }
4179     case 323: { name = "K*+";latexString="#K^{*+}"; break; }
4180     case -323: { name = "K*-";latexString="#K^{*-}" ; break; }
4181     case 413: { name = "D*+";latexString= "D^{*+}"; break; }
4182     case -413: { name = "D*-";latexString= "D^{*-}" ; break; }
4183     case 423: { name = "D*0";latexString="D^{*0}" ; break; }
4184     case 513: { name = "B*0";latexString="B^{*0}" ; break; }
4185     case 523: { name = "B*+";latexString="B^{*+}" ; break; }
4186     case -523: { name = "B*-";latexString="B^{*-}" ; break; }
4187     case 533: { name = "B*_s0";latexString="B^{*}_{s0}" ; break; }
4188     case 543: { name = "B*_c+";latexString= "B^{*}_{c+}"; break; }
4189     case -543: { name = "B*_c-";latexString= "B^{*}_{c-}"; break; }
4190     case 1114: { name = "Delta-";latexString="#Delta^{-}" ; break; }
4191     case -1114: { name = "Deltabar+";latexString="#bar{#Delta}^{+}" ; break; }
4192     case -2112: { name = "nbar0";latexString="{bar}n^{0}" ; break; }
4193     case 2112: { name = "n"; latexString=name ;break;}
4194     case 2114: { name = "Delta0"; latexString="#Delta^{0}" ;break; }
4195     case -2114: { name = "Deltabar0"; latexString="#bar{#Delta}^{0}" ;break; }
4196     case 3122: { name = "Lambda0";latexString= "#Lambda^{0}"; break; }
4197     case -3122: { name = "Lambdabar0";latexString="#bar{#Lambda}^{0}" ; break; }
4198     case 3112: { name = "Sigma-"; latexString="#Sigma" ;break; }
4199     case -3112: { name = "Sigmabar+"; latexString="#bar{#Sigma}^{+}" ;break; }
4200     case 3212: { name = "Sigma0";latexString="#Sigma^{0}" ; break; }
4201     case -3212: { name = "Sigmabar0";latexString="#bar{#Sigma}^{0}" ; break; }
4202     case 3214: { name = "Sigma*0"; latexString="#Sigma^{*0}" ;break; }
4203     case -3214: { name = "Sigma*bar0";latexString="#bar{#Sigma}^{*0}" ; break; }
4204     case 3222: { name = "Sigma+"; latexString="#Sigma^{+}" ;break; }
4205     case -3222: { name = "Sigmabar-"; latexString="#bar{#Sigma}^{-}";break; }
4206     case 2212: { name = "p";latexString=name ; break; }
4207     case -2212: { name = "~p";latexString="#bar{p}" ; break; }
4208     case -2214: { name = "Delta-";latexString="#Delta^{-}" ; break; }
4209     case 2214: { name = "Delta+";latexString="#Delta^{+}" ; break; }
4210     case -2224: { name = "Deltabar--"; latexString="#bar{#Delta}^{--}" ;break; }
4211     case 2224: { name = "Delta++"; latexString= "#Delta^{++}";break; }
4212     default:
4213     {
4214     name = "unknown";
4215     cout << "Unknown code : " << partId << endl;
4216     break;
4217     }
4218    
4219    
4220     }
4221     return name;
4222    
4223     }
4224    
4225     //_____________________________________________________________________________
4226     void PFRootEventManager::mcTruthMatching( std::ostream& out,
4227     const reco::PFCandidateCollection& candidates,
4228     std::vector< std::list <simMatch> >& candSimMatchTrack,
4229     std::vector< std::list <simMatch> >& candSimMatchEcal) const
4230     {
4231    
4232     if(!out) return;
4233     out << endl;
4234     out << "Running Monte Carlo Truth Matching Tool" << endl;
4235     out << endl;
4236    
4237     //resize matching vectors
4238     candSimMatchTrack.resize(candidates.size());
4239     candSimMatchEcal.resize(candidates.size());
4240    
4241     for(unsigned i=0; i<candidates.size(); i++) {
4242     const reco::PFCandidate& pfCand = candidates[i];
4243    
4244     //Matching with ECAL clusters
4245     if (verbosity_ == VERBOSE ) {
4246     out <<i<<" " <<(*pfCandidates_)[i]<<endl;
4247     out << "is matching:" << endl;
4248     }
4249    
4250     PFCandidate::ElementsInBlocks eleInBlocks
4251     = pfCand.elementsInBlocks();
4252    
4253     for(unsigned iel=0; iel<eleInBlocks.size(); ++iel) {
4254     PFBlockRef blockRef = eleInBlocks[iel].first;
4255     unsigned indexInBlock = eleInBlocks[iel].second;
4256    
4257     //Retrieving elements of the block
4258     const reco::PFBlock& blockh
4259     = *blockRef;
4260     const edm::OwnVector< reco::PFBlockElement >&
4261     elements_h = blockh.elements();
4262    
4263     reco::PFBlockElement::Type type
4264     = elements_h[ indexInBlock ].type();
4265     // cout <<"(" << blockRef.key() << "|" <<indexInBlock <<"|"
4266     // << elements_h[ indexInBlock ].type() << ")," << endl;
4267    
4268     //TRACK=================================
4269     if(type == reco::PFBlockElement::TRACK){
4270     const reco::PFRecTrackRef trackref
4271     = elements_h[ indexInBlock ].trackRefPF();
4272     assert( !trackref.isNull() );
4273     const reco::PFRecTrack& track = *trackref;
4274     const reco::TrackRef trkREF = track.trackRef();
4275     unsigned rtrkID = track.trackId();
4276    
4277     //looking for the matching charged simulated particle:
4278     for ( unsigned isim=0; isim < trueParticles_.size(); isim++) {
4279     const reco::PFSimParticle& ptc = trueParticles_[isim];
4280     unsigned trackIDM = ptc.rectrackId();
4281     if(trackIDM != 99999
4282     && trackIDM == rtrkID){
4283    
4284     if (verbosity_ == VERBOSE )
4285     out << "\tSimParticle " << isim
4286     << " through Track matching pTrectrack="
4287     << trkREF->pt() << " GeV" << endl;
4288    
4289     //store info
4290     std::pair<double, unsigned> simtrackmatch
4291     = make_pair(trkREF->pt(),trackIDM);
4292     candSimMatchTrack[i].push_back(simtrackmatch);
4293     }//match
4294     }//loop simparticles
4295    
4296     }//TRACK
4297    
4298     //ECAL=================================
4299     if(type == reco::PFBlockElement::ECAL)
4300     {
4301     const reco::PFClusterRef clusterref
4302     = elements_h[ indexInBlock ].clusterRef();
4303     assert( !clusterref.isNull() );
4304     const reco::PFCluster& cluster = *clusterref;
4305    
4306     const std::vector< reco::PFRecHitFraction >&
4307     fracs = cluster.recHitFractions();
4308    
4309     // cout << "This is an ecal cluster of energy "
4310     // << cluster.energy() << endl;
4311     vector<unsigned> simpID;
4312     vector<double> simpEC(trueParticles_.size(),0.0);
4313     vector<unsigned> simpCN(trueParticles_.size(),0);
4314     for(unsigned int rhit = 0; rhit < fracs.size(); ++rhit){
4315    
4316     const reco::PFRecHitRef& rh = fracs[rhit].recHitRef();
4317     if(rh.isNull()) continue;
4318     const reco::PFRecHit& rechit_cluster = *rh;
4319     // cout << rhit << " ID=" << rechit_cluster.detId()
4320     // << " E=" << rechit_cluster.energy()
4321     // << " fraction=" << fracs[rhit].fraction() << " ";
4322    
4323     //loop on sim particules
4324     // cout << "coming from sim particles: ";
4325     for ( unsigned isim=0; isim < trueParticles_.size(); isim++) {
4326     const reco::PFSimParticle& ptc = trueParticles_[isim];
4327    
4328     vector<unsigned> rechitSimIDs
4329     = ptc.recHitContrib();
4330     vector<double> rechitSimFrac
4331     = ptc.recHitContribFrac();
4332     //cout << "Number of rechits contrib =" << rechitSimIDs.size() << endl;
4333     if( !rechitSimIDs.size() ) continue; //no rechit
4334    
4335     for ( unsigned isimrh=0; isimrh < rechitSimIDs.size(); isimrh++) {
4336     if( rechitSimIDs[isimrh] == rechit_cluster.detId() ){
4337    
4338     bool takenalready = false;
4339     for(unsigned iss = 0; iss < simpID.size(); ++iss)
4340     if(simpID[iss] == isim) takenalready = true;
4341     if(!takenalready) simpID.push_back(isim);
4342    
4343     simpEC[isim] +=
4344     ((rechit_cluster.energy()*rechitSimFrac[isimrh])/100.0)
4345     *fracs[rhit].fraction();
4346    
4347     simpCN[isim]++; //counting rechits
4348    
4349     // cout << isim << " with contribution of ="
4350     // << rechitSimFrac[isimrh] << "%, ";
4351     }//match rechit
4352     }//loop sim rechit
4353     }//loop sim particules
4354     // cout << endl;
4355     }//loop cand rechit
4356    
4357     for(unsigned is=0; is < simpID.size(); ++is)
4358     {
4359     double frac_of_cluster
4360     = (simpEC[simpID[is]]/cluster.energy())*100.0;
4361    
4362     //store info
4363     std::pair<double, unsigned> simecalmatch
4364     = make_pair(simpEC[simpID[is]],simpID[is]);
4365     candSimMatchEcal[i].push_back(simecalmatch);
4366    
4367     if (verbosity_ == VERBOSE ) {
4368     out << "\tSimParticle " << simpID[is]
4369     << " through ECAL matching Epfcluster="
4370     << cluster.energy()
4371     << " GeV with N=" << simpCN[simpID[is]]
4372     << " rechits in common "
4373     << endl;
4374     out << "\t\tsimparticle contributing to a total of "
4375     << simpEC[simpID[is]]
4376     << " GeV of this cluster ("
4377     << frac_of_cluster << "%) "
4378     << endl;
4379     }
4380     }//loop particle matched
4381     }//ECAL clusters
4382    
4383     }//loop elements
4384    
4385     if (verbosity_ == VERBOSE )
4386     cout << "==============================================================="
4387     << endl;
4388    
4389     }//loop pfCandidates_
4390    
4391     if (verbosity_ == VERBOSE ){
4392    
4393     cout << "=================================================================="
4394     << endl;
4395     cout << "SimParticles" << endl;
4396    
4397     //loop simulated particles
4398     for ( unsigned i=0; i < trueParticles_.size(); i++) {
4399     cout << "==== Particle Simulated " << i << endl;
4400     const reco::PFSimParticle& ptc = trueParticles_[i];
4401     out <<i<<" "<<trueParticles_[i]<<endl;
4402    
4403     if(!ptc.daughterIds().empty()){
4404     cout << "Look at the desintegration products" << endl;
4405     cout << endl;
4406     continue;
4407     }
4408    
4409     //TRACKING
4410     if(ptc.rectrackId() != 99999){
4411     cout << "matching pfCandidate (trough tracking): " << endl;
4412     for( unsigned icand=0; icand<candidates.size(); icand++ )
4413     {
4414     ITM it = candSimMatchTrack[icand].begin();
4415     ITM itend = candSimMatchTrack[icand].end();
4416     for(;it!=itend;++it)
4417     if( i == it->second ){
4418     out<<icand<<" "<<(*pfCandidates_)[icand]<<endl;
4419     cout << endl;
4420     }
4421     }//loop candidate
4422     }//trackmatch
4423    
4424    
4425     //CALORIMETRY
4426     vector<unsigned> rechitSimIDs
4427     = ptc.recHitContrib();
4428     vector<double> rechitSimFrac
4429     = ptc.recHitContribFrac();
4430     //cout << "Number of rechits contrib =" << rechitSimIDs.size() << endl;
4431     if( !rechitSimIDs.size() ) continue; //no rechit
4432    
4433     cout << "matching pfCandidate (through ECAL): " << endl;
4434    
4435     //look at total ECAL desposition:
4436     double totalEcalE = 0.0;
4437     for(unsigned irh=0; irh<rechitsECAL_.size();++irh)
4438     for ( unsigned isimrh=0; isimrh < rechitSimIDs.size();
4439     isimrh++ )
4440     if(rechitSimIDs[isimrh] == rechitsECAL_[irh].detId())
4441     totalEcalE += (rechitsECAL_[irh].energy()*rechitSimFrac[isimrh]/100.0);
4442     cout << "For info, this particle deposits E=" << totalEcalE
4443     << "(GeV) in the ECAL" << endl;
4444    
4445     for( unsigned icand=0; icand<candidates.size(); icand++ )
4446     {
4447     ITM it = candSimMatchEcal[icand].begin();
4448     ITM itend = candSimMatchEcal[icand].end();
4449     for(;it!=itend;++it)
4450     if( i == it->second )
4451     out<<icand<<" "<<it->first<<"GeV "<<(*pfCandidates_)[icand]<<endl;
4452     }//loop candidate
4453     cout << endl;
4454     }//loop particles
4455     }//verbose
4456    
4457     }//mctruthmatching
4458     //_____________________________________________________________________________
4459    
4460     edm::InputTag
4461     PFRootEventManager::stringToTag(const std::vector< std::string >& tagname) {
4462    
4463     if ( tagname.size() == 1 )
4464     return edm::InputTag(tagname[0]);
4465    
4466     else if ( tagname.size() == 2 )
4467     return edm::InputTag(tagname[0], tagname[1]);
4468    
4469     else if ( tagname.size() == 3 )
4470     return tagname[2] == '*' ?
4471     edm::InputTag(tagname[0], tagname[1]) :
4472     edm::InputTag(tagname[0], tagname[1], tagname[2]);
4473     else {
4474     cout << "Invalid tag name with " << tagname.size() << " strings "<< endl;
4475     return edm::InputTag();
4476     }
4477    
4478     }