00001
00002
00003 #include "DataFormats/Common/interface/OrphanHandle.h"
00004 #include "DataFormats/Provenance/interface/ProductID.h"
00005 #include "DataFormats/Common/interface/RefToPtr.h"
00006
00007 #include "DataFormats/Math/interface/Point3D.h"
00008
00009 #include "DataFormats/ParticleFlowReco/interface/PFLayer.h"
00010
00011 #include "DataFormats/ParticleFlowReco/interface/PFBlock.h"
00012 #include "DataFormats/ParticleFlowReco/interface/PFBlockElement.h"
00013
00014 #include "RecoParticleFlow/PFClusterAlgo/interface/PFClusterAlgo.h"
00015 #include "RecoParticleFlow/PFBlockAlgo/interface/PFGeometry.h"
00016
00017 #include "RecoParticleFlow/PFRootEvent/interface/PFRootEventManager.h"
00018
00019 #include "RecoParticleFlow/PFRootEvent/interface/IO.h"
00020
00021 #include "RecoParticleFlow/PFRootEvent/interface/PFJetAlgorithm.h"
00022 #include "RecoJets/JetAlgorithms/interface/JetMaker.h"
00023
00024
00025 #include "RecoParticleFlow/PFRootEvent/interface/Utils.h"
00026 #include "RecoParticleFlow/PFRootEvent/interface/EventColin.h"
00027 #include "RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h"
00028 #include "RecoParticleFlow/PFClusterTools/interface/PFClusterCalibration.h"
00029 #include "RecoParticleFlow/PFClusterTools/interface/PFEnergyResolution.h"
00030
00031
00032 #include "FWCore/FWLite/interface/AutoLibraryLoader.h"
00033
00034 #include "TFile.h"
00035 #include "TTree.h"
00036 #include "TBranch.h"
00037 #include "TCutG.h"
00038 #include "TVector3.h"
00039 #include "TROOT.h"
00040
00041 #include <iostream>
00042 #include <vector>
00043 #include <stdlib.h>
00044
00045 using namespace std;
00046 using namespace boost;
00047 using namespace reco;
00048
00049 PFRootEventManager::PFRootEventManager() {}
00050
00051
00052
00053 PFRootEventManager::PFRootEventManager(const char* file)
00054 :
00055 iEvent_(0),
00056 options_(0),
00057 tree_(0),
00058 outTree_(0),
00059 outEvent_(0),
00060
00061 clustersECAL_(new reco::PFClusterCollection),
00062 clustersHCAL_(new reco::PFClusterCollection),
00063 clustersPS_(new reco::PFClusterCollection),
00064 pfBlocks_(new reco::PFBlockCollection),
00065 pfCandidates_(new reco::PFCandidateCollection),
00066
00067 outFile_(0) {
00068
00069
00070
00071 h_deltaETvisible_MCEHT_
00072 = new TH1F("h_deltaETvisible_MCEHT","Jet Et difference CaloTowers-MC"
00073 ,1000,-50.,50.);
00074 h_deltaETvisible_MCPF_
00075 = new TH1F("h_deltaETvisible_MCPF" ,"Jet Et difference ParticleFlow-MC"
00076 ,1000,-50.,50.);
00077
00078 readOptions(file, true, true);
00079
00080
00081
00082
00083
00084 }
00085
00086 void PFRootEventManager::reset() {
00087
00088 if(outEvent_) {
00089 outEvent_->reset();
00090 outTree_->GetBranch("event")->SetAddress(&outEvent_);
00091 }
00092
00093
00094
00095 }
00096
00097 void PFRootEventManager::readOptions(const char* file,
00098 bool refresh,
00099 bool reconnect) {
00100
00101 readSpecificOptions(file);
00102
00103 cout<<"calling PFRootEventManager::readOptions"<<endl;
00104
00105
00106 reset();
00107
00108 PFGeometry pfGeometry;
00109
00110
00111
00112 try {
00113 if( !options_ )
00114 options_ = new IO(file);
00115 else if( refresh) {
00116 delete options_;
00117 options_ = new IO(file);
00118 }
00119 }
00120 catch( const string& err ) {
00121 cout<<err<<endl;
00122 return;
00123 }
00124
00125
00126 debug_ = false;
00127 options_->GetOpt("rootevent", "debug", debug_);
00128
00129
00130
00131
00132
00133 if(!outFile_) {
00134 string outfilename;
00135 options_->GetOpt("root","outfile", outfilename);
00136 if(!outfilename.empty() ) {
00137 outFile_ = TFile::Open(outfilename.c_str(), "recreate");
00138
00139 bool doOutTree = false;
00140 options_->GetOpt("root","outtree", doOutTree);
00141 if(doOutTree) {
00142 outFile_->cd();
00143
00144 outEvent_ = new EventColin();
00145 outTree_ = new TTree("Eff","");
00146 outTree_->Branch("event","EventColin", &outEvent_,32000,2);
00147 }
00148
00149 }
00150 }
00151
00152
00153 doPFJetBenchmark_ = false;
00154 options_->GetOpt("pfjet_benchmark", "on/off", doPFJetBenchmark_);
00155
00156 if (doPFJetBenchmark_) {
00157 string outjetfilename;
00158 options_->GetOpt("pfjet_benchmark", "outjetfile", outjetfilename);
00159
00160 bool pfjBenchmarkDebug;
00161 options_->GetOpt("pfjet_benchmark", "debug", pfjBenchmarkDebug);
00162
00163 bool plotAgainstReco=0;
00164 options_->GetOpt("pfjet_benchmark", "plotAgainstReco", plotAgainstReco);
00165
00166 bool onlyTwoJets=1;
00167 options_->GetOpt("pfjet_benchmark", "onlyTwoJets", onlyTwoJets);
00168
00169 double deltaRMax=0.1;
00170 options_->GetOpt("pfjet_benchmark", "deltaRMax", deltaRMax);
00171
00172
00173 fastsim_=true;
00174 options_->GetOpt("Simulation","Fast",fastsim_);
00175
00176 PFJetBenchmark_.setup( outjetfilename,
00177 pfjBenchmarkDebug,
00178 plotAgainstReco,
00179 onlyTwoJets,
00180 deltaRMax );
00181 }
00182
00183
00184
00185
00186 if( reconnect )
00187 connect( inFileName_.c_str() );
00188
00189
00190
00191
00192 filterNParticles_ = 0;
00193 options_->GetOpt("filter", "nparticles", filterNParticles_);
00194
00195 filterHadronicTaus_ = true;
00196 options_->GetOpt("filter", "hadronic_taus", filterHadronicTaus_);
00197
00198 filterTaus_.clear();
00199 options_->GetOpt("filter", "taus", filterTaus_);
00200 if( !filterTaus_.empty() &&
00201 filterTaus_.size() != 2 ) {
00202 cerr<<"PFRootEventManager::ReadOptions, bad filter/taus option."<<endl
00203 <<"please use : "<<endl
00204 <<"\tfilter taus n_charged n_neutral"<<endl;
00205 filterTaus_.clear();
00206 }
00207
00208
00209
00210
00211 doClustering_ = true;
00212 options_->GetOpt("clustering", "on/off", doClustering_);
00213
00214 bool clusteringDebug = false;
00215 options_->GetOpt("clustering", "debug", clusteringDebug );
00216
00217 findRecHitNeighbours_ = true;
00218 options_->GetOpt("clustering", "findRecHitNeighbours",
00219 findRecHitNeighbours_);
00220
00221 double threshEcalBarrel = 0.1;
00222 options_->GetOpt("clustering", "thresh_Ecal_Barrel", threshEcalBarrel);
00223
00224 double threshSeedEcalBarrel = 0.3;
00225 options_->GetOpt("clustering", "thresh_Seed_Ecal_Barrel",
00226 threshSeedEcalBarrel);
00227
00228 double threshEcalEndcap = 0.2;
00229 options_->GetOpt("clustering", "thresh_Ecal_Endcap", threshEcalEndcap);
00230
00231 double threshSeedEcalEndcap = 0.8;
00232 options_->GetOpt("clustering", "thresh_Seed_Ecal_Endcap",
00233 threshSeedEcalEndcap);
00234
00235 double showerSigmaEcal = 3;
00236 options_->GetOpt("clustering", "shower_Sigma_Ecal",
00237 showerSigmaEcal);
00238
00239 int nNeighboursEcal = 4;
00240 options_->GetOpt("clustering", "neighbours_Ecal", nNeighboursEcal);
00241
00242 int posCalcNCrystalEcal = -1;
00243 options_->GetOpt("clustering", "posCalc_nCrystal_Ecal",
00244 posCalcNCrystalEcal);
00245
00246 double posCalcP1Ecal = -1;
00247 options_->GetOpt("clustering", "posCalc_p1_Ecal",
00248 posCalcP1Ecal);
00249
00250
00251 clusterAlgoECAL_.setThreshBarrel( threshEcalBarrel );
00252 clusterAlgoECAL_.setThreshSeedBarrel( threshSeedEcalBarrel );
00253
00254 clusterAlgoECAL_.setThreshEndcap( threshEcalEndcap );
00255 clusterAlgoECAL_.setThreshSeedEndcap( threshSeedEcalEndcap );
00256
00257 clusterAlgoECAL_.setNNeighbours( nNeighboursEcal );
00258 clusterAlgoECAL_.setShowerSigma( showerSigmaEcal );
00259
00260 clusterAlgoECAL_.setPosCalcNCrystal( posCalcNCrystalEcal );
00261 clusterAlgoECAL_.setPosCalcP1( posCalcP1Ecal );
00262
00263 clusterAlgoECAL_.enableDebugging( clusteringDebug );
00264
00265
00266 int dcormode = 0;
00267 options_->GetOpt("clustering", "depthCor_Mode", dcormode);
00268
00269 double dcora = -1;
00270 options_->GetOpt("clustering", "depthCor_A", dcora);
00271 double dcorb = -1;
00272 options_->GetOpt("clustering", "depthCor_B", dcorb);
00273 double dcorap = -1;
00274 options_->GetOpt("clustering", "depthCor_A_preshower", dcorap);
00275 double dcorbp = -1;
00276 options_->GetOpt("clustering", "depthCor_B_preshower", dcorbp);
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 reco::PFCluster::setDepthCorParameters( dcormode,
00287 dcora, dcorb,
00288 dcorap, dcorbp);
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 double threshHcalBarrel = 0.8;
00299 options_->GetOpt("clustering", "thresh_Hcal_Barrel", threshHcalBarrel);
00300
00301 double threshSeedHcalBarrel = 1.4;
00302 options_->GetOpt("clustering", "thresh_Seed_Hcal_Barrel",
00303 threshSeedHcalBarrel);
00304
00305 double threshHcalEndcap = 0.8;
00306 options_->GetOpt("clustering", "thresh_Hcal_Endcap", threshHcalEndcap);
00307
00308 double threshSeedHcalEndcap = 1.4;
00309 options_->GetOpt("clustering", "thresh_Seed_Hcal_Endcap",
00310 threshSeedHcalEndcap);
00311
00312 double showerSigmaHcal = 15;
00313 options_->GetOpt("clustering", "shower_Sigma_Hcal",
00314 showerSigmaHcal);
00315
00316 int nNeighboursHcal = 4;
00317 options_->GetOpt("clustering", "neighbours_Hcal", nNeighboursHcal);
00318
00319 int posCalcNCrystalHcal = 5;
00320 options_->GetOpt("clustering", "posCalc_nCrystal_Hcal",
00321 posCalcNCrystalHcal);
00322
00323 double posCalcP1Hcal = 1.0;
00324 options_->GetOpt("clustering", "posCalc_p1_Hcal",
00325 posCalcP1Hcal);
00326
00327
00328
00329
00330 clusterAlgoHCAL_.setThreshBarrel( threshHcalBarrel );
00331 clusterAlgoHCAL_.setThreshSeedBarrel( threshSeedHcalBarrel );
00332
00333 clusterAlgoHCAL_.setThreshEndcap( threshHcalEndcap );
00334 clusterAlgoHCAL_.setThreshSeedEndcap( threshSeedHcalEndcap );
00335
00336 clusterAlgoHCAL_.setNNeighbours( nNeighboursHcal );
00337 clusterAlgoHCAL_.setShowerSigma( showerSigmaHcal );
00338
00339 clusterAlgoHCAL_.setPosCalcNCrystal( posCalcNCrystalHcal );
00340 clusterAlgoHCAL_.setPosCalcP1( posCalcP1Hcal );
00341
00342 clusterAlgoHCAL_.enableDebugging( clusteringDebug );
00343
00344
00345
00346
00347 double threshPS = 0.0001;
00348 options_->GetOpt("clustering", "thresh_PS", threshPS);
00349
00350 double threshSeedPS = 0.001;
00351 options_->GetOpt("clustering", "thresh_Seed_PS",
00352 threshSeedPS);
00353
00354
00355 double threshPSBarrel = threshPS;
00356 double threshSeedPSBarrel = threshSeedPS;
00357
00358 double threshPSEndcap = threshPS;
00359 double threshSeedPSEndcap = threshSeedPS;
00360
00361 double showerSigmaPS = 0.1;
00362 options_->GetOpt("clustering", "shower_Sigma_PS",
00363 showerSigmaPS);
00364
00365 int nNeighboursPS = 4;
00366 options_->GetOpt("clustering", "neighbours_PS", nNeighboursPS);
00367
00368 int posCalcNCrystalPS = -1;
00369 options_->GetOpt("clustering", "posCalc_nCrystal_PS",
00370 posCalcNCrystalPS);
00371
00372 double posCalcP1PS = 0.;
00373 options_->GetOpt("clustering", "posCalc_p1_PS",
00374 posCalcP1PS);
00375
00376
00377
00378
00379 clusterAlgoPS_.setThreshBarrel( threshPSBarrel );
00380 clusterAlgoPS_.setThreshSeedBarrel( threshSeedPSBarrel );
00381
00382 clusterAlgoPS_.setThreshEndcap( threshPSEndcap );
00383 clusterAlgoPS_.setThreshSeedEndcap( threshSeedPSEndcap );
00384
00385 clusterAlgoPS_.setNNeighbours( nNeighboursPS );
00386 clusterAlgoPS_.setShowerSigma( showerSigmaPS );
00387
00388 clusterAlgoPS_.setPosCalcNCrystal( posCalcNCrystalPS );
00389 clusterAlgoPS_.setPosCalcP1( posCalcP1PS );
00390
00391 clusterAlgoPS_.enableDebugging( clusteringDebug );
00392
00393
00394
00395
00396
00397
00398
00399 doParticleFlow_ = true;
00400 options_->GetOpt("particle_flow", "on/off", doParticleFlow_);
00401
00402 string map_ECAL_eta;
00403 options_->GetOpt("particle_flow", "resolution_map_ECAL_eta", map_ECAL_eta);
00404 string map_ECAL_phi;
00405 options_->GetOpt("particle_flow", "resolution_map_ECAL_phi", map_ECAL_phi);
00406 string map_ECALec_x;
00407 options_->GetOpt("particle_flow", "resolution_map_ECALec_x", map_ECALec_x);
00408 string map_ECALec_y;
00409 options_->GetOpt("particle_flow", "resolution_map_ECALec_y", map_ECALec_y);
00410 string map_HCAL_eta;
00411 options_->GetOpt("particle_flow", "resolution_map_HCAL_eta", map_HCAL_eta);
00412 string map_HCAL_phi;
00413 options_->GetOpt("particle_flow", "resolution_map_HCAL_phi", map_HCAL_phi);
00414
00415
00416 map_ECAL_eta = expand(map_ECAL_eta);
00417 map_ECAL_phi = expand(map_ECAL_phi);
00418 map_HCAL_eta = expand(map_HCAL_eta);
00419 map_HCAL_phi = expand(map_HCAL_phi);
00420
00421 double DPtovPtCut = 999.;
00422 options_->GetOpt("particle_flow", "DPtoverPt_Cut", DPtovPtCut);
00423 double chi2TrackECAL=100;
00424 options_->GetOpt("particle_flow", "chi2_ECAL_Track", chi2TrackECAL);
00425 double chi2GSFECAL=900;
00426 options_->GetOpt("particle_flow", "chi2_ECAL_GSF", chi2GSFECAL);
00427 double chi2TrackHCAL=100;
00428 options_->GetOpt("particle_flow", "chi2_HCAL_Track", chi2TrackHCAL);
00429 double chi2ECALHCAL=100;
00430 options_->GetOpt("particle_flow", "chi2_ECAL_HCAL", chi2ECALHCAL);
00431 double chi2PSECAL=100;
00432 options_->GetOpt("particle_flow", "chi2_PS_ECAL", chi2PSECAL);
00433 double chi2PSTrack=100;
00434 options_->GetOpt("particle_flow", "chi2_PS_Track", chi2PSTrack);
00435 double chi2PSHV=100;
00436 options_->GetOpt("particle_flow", "chi2_PSH_PSV", chi2PSHV);
00437 bool multiLink = false;
00438 options_->GetOpt("particle_flow", "multilink", multiLink);
00439
00440 try {
00441 pfBlockAlgo_.setParameters( map_ECAL_eta.c_str(),
00442 map_ECAL_phi.c_str(),
00443 map_HCAL_eta.c_str(),
00444 map_HCAL_phi.c_str(),
00445 DPtovPtCut,
00446 chi2TrackECAL,
00447 chi2GSFECAL,
00448 chi2TrackHCAL,
00449 chi2ECALHCAL,
00450 chi2PSECAL,
00451 chi2PSTrack,
00452 chi2PSHV,
00453 multiLink );
00454 }
00455 catch( std::exception& err ) {
00456 cerr<<"exception setting PFBlockAlgo parameters: "
00457 <<err.what()<<". terminating."<<endl;
00458 delete this;
00459 exit(1);
00460 }
00461
00462
00463 bool blockAlgoDebug = false;
00464 options_->GetOpt("blockAlgo", "debug", blockAlgoDebug);
00465 pfBlockAlgo_.setDebug( blockAlgoDebug );
00466
00467 bool AlgoDebug = false;
00468 options_->GetOpt("PFAlgo", "debug", AlgoDebug);
00469 pfAlgo_.setDebug( AlgoDebug );
00470
00471
00472
00473
00474 double e_slope = 1.0;
00475 options_->GetOpt("particle_flow","calib_ECAL_slope", e_slope);
00476 double e_offset = 0;
00477 options_->GetOpt("particle_flow","calib_ECAL_offset", e_offset);
00478
00479 double eh_eslope = 1.05;
00480 options_->GetOpt("particle_flow","calib_ECAL_HCAL_eslope", eh_eslope);
00481 double eh_hslope = 1.06;
00482 options_->GetOpt("particle_flow","calib_ECAL_HCAL_hslope", eh_hslope);
00483 double eh_offset = 6.11;
00484 options_->GetOpt("particle_flow","calib_ECAL_HCAL_offset", eh_offset);
00485
00486 double h_slope = 2.17;
00487 options_->GetOpt("particle_flow","calib_HCAL_slope", h_slope);
00488 double h_offset = 1.73;
00489 options_->GetOpt("particle_flow","calib_HCAL_offset", h_offset);
00490 double h_damping = 2.49;
00491 options_->GetOpt("particle_flow","calib_HCAL_damping", h_damping);
00492
00493
00494 shared_ptr<pftools::PFClusterCalibration>
00495 clusterCalibration( new pftools::PFClusterCalibration() );
00496
00497 shared_ptr<PFEnergyCalibration>
00498 calibration( new PFEnergyCalibration( e_slope,
00499 e_offset,
00500 eh_eslope,
00501 eh_hslope,
00502 eh_offset,
00503 h_slope,
00504 h_offset,
00505 h_damping ) );
00506
00507
00508 double nSigmaECAL = 99999;
00509 options_->GetOpt("particle_flow", "nsigma_ECAL", nSigmaECAL);
00510 double nSigmaHCAL = 99999;
00511 options_->GetOpt("particle_flow", "nsigma_HCAL", nSigmaHCAL);
00512
00513 bool clusterRecoveryAlgo = false;
00514 options_->GetOpt("particle_flow", "clusterRecovery", clusterRecoveryAlgo );
00515
00516 double mvaCut = 999999;
00517 options_->GetOpt("particle_flow", "mergedPhotons_mvaCut", mvaCut);
00518
00519 string mvaWeightFile = "";
00520 options_->GetOpt("particle_flow", "mergedPhotons_mvaWeightFile",
00521 mvaWeightFile);
00522 mvaWeightFile = expand( mvaWeightFile );
00523
00524 bool newCalib = false;
00525 options_->GetOpt("particle_flow", "newCalib", newCalib);
00526 std::cout << "New calib = " << newCalib << std::endl;
00527
00528
00529
00530 double g0, g1, e0, e1;
00531 options_->GetOpt("correction", "globalP0", g0);
00532 options_->GetOpt("correction", "globalP1", g1);
00533 options_->GetOpt("correction", "lowEP0", e0);
00534 options_->GetOpt("correction", "lowEP1", e1);
00535 clusterCalibration->setCorrections(e0, e1, g0, g1);
00536
00537 int allowNegative(0);
00538 options_->GetOpt("correction", "allowNegativeEnergy", allowNegative);
00539 clusterCalibration->setAllowNegativeEnergy(allowNegative);
00540
00541 int doCorrection(1);
00542 options_->GetOpt("correction", "doCorrection", doCorrection);
00543 clusterCalibration->setDoCorrection(doCorrection);
00544
00545 int doEtaCorrection(1);
00546 options_->GetOpt("correction", "doEtaCorrection", doEtaCorrection);
00547 clusterCalibration->setDoEtaCorrection(doEtaCorrection);
00548
00549 double barrelEta;
00550 options_->GetOpt("evolution", "barrelEndcapEtaDiv", barrelEta);
00551 clusterCalibration->setBarrelBoundary(barrelEta);
00552
00553 double ecalEcut;
00554 options_->GetOpt("evolution", "ecalECut", ecalEcut);
00555 double hcalEcut;
00556 options_->GetOpt("evolution", "hcalECut", hcalEcut);
00557 clusterCalibration->setEcalHcalEnergyCuts(ecalEcut,hcalEcut);
00558
00559 std::vector<std::string>* names = clusterCalibration->getKnownSectorNames();
00560 for(std::vector<std::string>::iterator i = names->begin(); i != names->end(); ++i) {
00561 std::string sector = *i;
00562 std::vector<double> params;
00563 options_->GetOpt("evolution", sector.c_str(), params);
00564 clusterCalibration->setEvolutionParameters(sector, params);
00565 }
00566
00567 std::vector<double> etaCorrectionParams;
00568 options_->GetOpt("evolution","etaCorrection", etaCorrectionParams);
00569 clusterCalibration->setEtaCorrectionParameters(etaCorrectionParams);
00570
00571
00572
00573 double PSCut = 999999;
00574 options_->GetOpt("particle_flow", "mergedPhotons_PSCut", PSCut);
00575
00576 try {
00577
00578
00579 pfAlgo_.setParameters( nSigmaECAL, nSigmaHCAL,
00580 calibration,
00581 clusterCalibration, newCalib,
00582 clusterRecoveryAlgo,
00583 PSCut, mvaCut, mvaWeightFile.c_str() );
00584 }
00585 catch( std::exception& err ) {
00586 cerr<<"exception setting PFAlgo parameters: "
00587 <<err.what()<<". terminating."<<endl;
00588 delete this;
00589 exit(1);
00590 }
00591
00592
00593 double chi2EcalGSF = 900;
00594 options_->GetOpt("particle_flow", "final_chi2cut_gsfecal", chi2EcalGSF);
00595
00596 double chi2EcalBrem = 25;
00597 options_->GetOpt("particle_flow", "final_chi2cut_bremecal", chi2EcalBrem);
00598
00599 double chi2HcalGSF = 100;
00600 options_->GetOpt("particle_flow", "final_chi2cut_gsfhcal", chi2HcalGSF);
00601
00602 double chi2HcalBrem = 25;
00603 options_->GetOpt("particle_flow", "final_chi2cut_bremhcal", chi2HcalBrem);
00604
00605 double chi2PsGSF = 100;
00606 options_->GetOpt("particle_flow", "final_chi2cut_gsfps", chi2PsGSF);
00607
00608 double chi2PsBrem = 25;
00609 options_->GetOpt("particle_flow", "final_chi2cut_bremps", chi2PsBrem);
00610
00611
00612 double mvaEleCut = -1.;
00613 options_->GetOpt("particle_flow", "electron_mvaCut", mvaEleCut);
00614
00615 bool usePFElectrons = false;
00616 options_->GetOpt("particle_flow", "usePFElectrons", usePFElectrons);
00617
00618 string mvaWeightFileEleID = "";
00619 options_->GetOpt("particle_flow", "electronID_mvaWeightFile",
00620 mvaWeightFileEleID);
00621 mvaWeightFileEleID = expand(mvaWeightFileEleID);
00622
00623 try {
00624 pfAlgo_.setPFEleParameters(chi2EcalGSF,
00625 chi2EcalBrem,
00626 chi2HcalGSF,
00627 chi2HcalBrem,
00628 chi2PsGSF,
00629 chi2PsBrem,
00630 mvaEleCut,
00631 mvaWeightFileEleID,
00632 usePFElectrons);
00633 }
00634 catch( std::exception& err ) {
00635 cerr<<"exception setting PFAlgo Electron parameters: "
00636 <<err.what()<<". terminating."<<endl;
00637 delete this;
00638 exit(1);
00639 }
00640
00641
00642 bool usePFConversions = false;
00643 options_->GetOpt("particle_flow", "usePFConversions", usePFConversions);
00644
00645 try {
00646 pfAlgo_.setPFConversionParameters(usePFConversions);
00647 }
00648 catch( std::exception& err ) {
00649 cerr<<"exception setting PFAlgo Conversions parameters: "
00650 <<err.what()<<". terminating."<<endl;
00651 delete this;
00652 exit(1);
00653 }
00654
00655
00656
00657 int algo = 2;
00658 options_->GetOpt("particle_flow", "algorithm", algo);
00659
00660 pfAlgo_.setAlgo( algo );
00661
00662
00663
00664
00665
00666 doJets_ = false;
00667 options_->GetOpt("jets", "on/off", doJets_);
00668
00669 jetsDebug_ = false;
00670 options_->GetOpt("jets", "debug", jetsDebug_);
00671
00672 jetAlgoType_=3;
00673 options_->GetOpt("jets", "algo", jetAlgoType_);
00674
00675 double mEtInputCut = 0.5;
00676 options_->GetOpt("jets", "EtInputCut", mEtInputCut);
00677
00678 double mEInputCut = 0.;
00679 options_->GetOpt("jets", "EInputCut", mEInputCut);
00680
00681 double seedThreshold = 1.0;
00682 options_->GetOpt("jets", "seedThreshold", seedThreshold);
00683
00684 double coneRadius = 0.5;
00685 options_->GetOpt("jets", "coneRadius", coneRadius);
00686
00687 double coneAreaFraction= 1.0;
00688 options_->GetOpt("jets", "coneAreaFraction", coneAreaFraction);
00689
00690 int maxPairSize=2;
00691 options_->GetOpt("jets", "maxPairSize", maxPairSize);
00692
00693 int maxIterations=100;
00694 options_->GetOpt("jets", "maxIterations", maxIterations);
00695
00696 double overlapThreshold = 0.75;
00697 options_->GetOpt("jets", "overlapThreshold", overlapThreshold);
00698
00699 double ptMin = 10.;
00700 options_->GetOpt("jets", "ptMin", ptMin);
00701
00702 double rparam = 1.0;
00703 options_->GetOpt("jets", "rParam", rparam);
00704
00705 jetMaker_.setmEtInputCut (mEtInputCut);
00706 jetMaker_.setmEInputCut(mEInputCut);
00707 jetMaker_.setSeedThreshold(seedThreshold);
00708 jetMaker_.setConeRadius(coneRadius);
00709 jetMaker_.setConeAreaFraction(coneAreaFraction);
00710 jetMaker_.setMaxPairSize(maxPairSize);
00711 jetMaker_.setMaxIterations(maxIterations) ;
00712 jetMaker_.setOverlapThreshold(overlapThreshold) ;
00713 jetMaker_.setPtMin (ptMin);
00714 jetMaker_.setRParam (rparam);
00715 jetMaker_.setDebug(jetsDebug_);
00716 jetMaker_.updateParameter();
00717 cout <<"Opt: doJets? " << doJets_ <<endl;
00718 cout <<"Opt: jetsDebug " << jetsDebug_ <<endl;
00719 cout <<"Opt: algoType " << jetAlgoType_ <<endl;
00720 cout <<"----------------------------------" << endl;
00721
00722
00723
00724
00725 doTauBenchmark_ = false;
00726 options_->GetOpt("tau_benchmark", "on/off", doTauBenchmark_);
00727
00728 if (doTauBenchmark_) {
00729 double coneAngle = 0.5;
00730 options_->GetOpt("tau_benchmark", "cone_angle", coneAngle);
00731
00732 double seedEt = 0.4;
00733 options_->GetOpt("tau_benchmark", "seed_et", seedEt);
00734
00735 double coneMerge = 100.0;
00736 options_->GetOpt("tau_benchmark", "cone_merge", coneMerge);
00737
00738 options_->GetOpt("tau_benchmark", "debug", tauBenchmarkDebug_);
00739
00740
00741
00742 if( tauBenchmarkDebug_ ) {
00743 cout << "Tau Benchmark Options : ";
00744 cout << "Angle=" << coneAngle << " seedEt=" << seedEt
00745 << " Merge=" << coneMerge << endl;
00746 }
00747
00748 jetAlgo_.SetConeAngle(coneAngle);
00749 jetAlgo_.SetSeedEt(seedEt);
00750 jetAlgo_.SetConeMerge(coneMerge);
00751 }
00752
00753
00754
00755
00756
00757 printRecHits_ = false;
00758 options_->GetOpt("print", "rechits", printRecHits_ );
00759
00760 printClusters_ = false;
00761 options_->GetOpt("print", "clusters", printClusters_ );
00762
00763 printPFBlocks_ = false;
00764 options_->GetOpt("print", "PFBlocks", printPFBlocks_ );
00765
00766 printPFCandidates_ = true;
00767 options_->GetOpt("print", "PFCandidates", printPFCandidates_ );
00768
00769 printPFJets_ = true;
00770 options_->GetOpt("print", "jets", printPFJets_ );
00771
00772 printSimParticles_ = true;
00773 options_->GetOpt("print", "simParticles", printSimParticles_ );
00774
00775 printGenParticles_ = true;
00776 options_->GetOpt("print", "genParticles", printGenParticles_ );
00777
00778
00779
00780
00781 printMCTruthMatching_ = false;
00782 options_->GetOpt("print", "mctruthmatching", printMCTruthMatching_ );
00783
00784
00785 verbosity_ = VERBOSE;
00786 options_->GetOpt("print", "verbosity", verbosity_ );
00787 cout<<"verbosity : "<<verbosity_<<endl;
00788
00789
00790 }
00791
00792 void PFRootEventManager::connect( const char* infilename ) {
00793
00794 string fname = infilename;
00795 if( fname.empty() )
00796 fname = inFileName_;
00797
00798
00799 cout<<"opening input root file"<<endl;
00800
00801 options_->GetOpt("root","file", inFileName_);
00802
00803
00804
00805 try {
00806 AutoLibraryLoader::enable();
00807 }
00808 catch(string& err) {
00809 cout<<err<<endl;
00810 }
00811
00812
00813
00814
00815 file_ = TFile::Open(inFileName_.c_str() );
00816
00817
00818 if(!file_ ) return;
00819 else if(file_->IsZombie() ) {
00820 return;
00821 }
00822 else
00823 cout<<"rootfile "<<inFileName_
00824 <<" opened"<<endl;
00825
00826
00827
00828 tree_ = (TTree*) file_->Get("Events");
00829 if(!tree_) {
00830 cerr<<"PFRootEventManager::ReadOptions :";
00831 cerr<<"input TTree Events not found in file "
00832 <<inFileName_<<endl;
00833 return;
00834 }
00835
00836 tree_->GetEntry();
00837
00838
00839
00840
00841 string rechitsECALbranchname;
00842 options_->GetOpt("root","rechits_ECAL_branch", rechitsECALbranchname);
00843
00844 rechitsECALBranch_ = tree_->GetBranch(rechitsECALbranchname.c_str());
00845 if(!rechitsECALBranch_) {
00846 cerr<<"PFRootEventManager::ReadOptions : rechits_ECAL_branch not found : "
00847 <<rechitsECALbranchname<<endl;
00848 }
00849
00850 string rechitsHCALbranchname;
00851 options_->GetOpt("root","rechits_HCAL_branch", rechitsHCALbranchname);
00852
00853 rechitsHCALBranch_ = tree_->GetBranch(rechitsHCALbranchname.c_str());
00854 if(!rechitsHCALBranch_) {
00855 cerr<<"PFRootEventManager::ReadOptions : rechits_HCAL_branch not found : "
00856 <<rechitsHCALbranchname<<endl;
00857 }
00858
00859 string rechitsPSbranchname;
00860 options_->GetOpt("root","rechits_PS_branch", rechitsPSbranchname);
00861
00862 rechitsPSBranch_ = tree_->GetBranch(rechitsPSbranchname.c_str());
00863 if(!rechitsPSBranch_) {
00864 cerr<<"PFRootEventManager::ReadOptions : rechits_PS_branch not found : "
00865 <<rechitsPSbranchname<<endl;
00866 }
00867
00868
00869
00870
00871
00872 clustersECALBranch_ = 0;
00873 clustersHCALBranch_ = 0;
00874 clustersPSBranch_ = 0;
00875
00876
00877 if( !doClustering_ ) {
00878 string clustersECALbranchname;
00879 options_->GetOpt("root","clusters_ECAL_branch", clustersECALbranchname);
00880
00881 clustersECALBranch_ = tree_->GetBranch(clustersECALbranchname.c_str());
00882 if(!clustersECALBranch_) {
00883 cerr <<"PFRootEventManager::ReadOptions : clusters_ECAL_branch not found:"
00884 <<clustersECALbranchname<<endl;
00885 }
00886
00887
00888 string clustersHCALbranchname;
00889 options_->GetOpt("root","clusters_HCAL_branch", clustersHCALbranchname);
00890
00891 clustersHCALBranch_ = tree_->GetBranch(clustersHCALbranchname.c_str());
00892 if(!clustersHCALBranch_) {
00893 cerr<<"PFRootEventManager::ReadOptions : clusters_HCAL_branch not found : "
00894 <<clustersHCALbranchname<<endl;
00895 }
00896
00897 string clustersPSbranchname;
00898 options_->GetOpt("root","clusters_PS_branch", clustersPSbranchname);
00899
00900 clustersPSBranch_ = tree_->GetBranch(clustersPSbranchname.c_str());
00901 if(!clustersPSBranch_) {
00902 cerr<<"PFRootEventManager::ReadOptions : clusters_PS_branch not found : "
00903 <<clustersPSbranchname<<endl;
00904 }
00905 }
00906
00907
00908
00909
00910 string clustersIslandBarrelbranchname;
00911 clustersIslandBarrelBranch_ = 0;
00912 options_->GetOpt("root","clusters_island_barrel_branch",
00913 clustersIslandBarrelbranchname);
00914 if(!clustersIslandBarrelbranchname.empty() ) {
00915 clustersIslandBarrelBranch_
00916 = tree_->GetBranch(clustersIslandBarrelbranchname.c_str());
00917 if(!clustersIslandBarrelBranch_) {
00918 cerr<<"PFRootEventManager::ReadOptions : clusters_island_barrel_branch not found : "
00919 <<clustersIslandBarrelbranchname<< endl;
00920 }
00921 }
00922 else {
00923 cerr<<"branch not found: root/clusters_island_barrel_branch"<<endl;
00924 }
00925
00926 string recTracksbranchname;
00927 options_->GetOpt("root","recTracks_branch", recTracksbranchname);
00928
00929 recTracksBranch_ = tree_->GetBranch(recTracksbranchname.c_str());
00930 if(!recTracksBranch_) {
00931 cerr<<"PFRootEventManager::ReadOptions : recTracks_branch not found : "
00932 <<recTracksbranchname<< endl;
00933 }
00934
00935 string stdTracksbranchname;
00936 options_->GetOpt("root","stdTracks_branch", stdTracksbranchname);
00937
00938 stdTracksBranch_ = tree_->GetBranch(stdTracksbranchname.c_str());
00939 if(!stdTracksBranch_) {
00940 cerr<<"PFRootEventManager::ReadOptions : stdTracks_branch not found : "
00941 <<stdTracksbranchname<< endl;
00942 }
00943
00944 string gsfTracksbranchname;
00945 options_->GetOpt("root","gsfrecTracks_branch",gsfTracksbranchname);
00946 gsfrecTracksBranch_ = tree_->GetBranch(gsfTracksbranchname.c_str());
00947 if(!gsfrecTracksBranch_) {
00948 cerr<<"PFRootEventManager::ReadOptions : gsfrecTracks_branch not found : "
00949 <<gsfTracksbranchname<< endl;
00950 }
00951
00952
00953 string muonbranchname;
00954 options_->GetOpt("root","muon_branch",muonbranchname);
00955 muonsBranch_= tree_->GetBranch(muonbranchname.c_str());
00956 if(!muonsBranch_) {
00957 cerr<<"PFRootEventManager::ReadOptions : muon_branch not found : "
00958 <<muonbranchname<< endl;
00959 }
00960
00961 useNuclear_=false;
00962 options_->GetOpt("particle_flow", "useNuclear", useNuclear_);
00963 if( useNuclear_ ) {
00964
00965 string nuclearbranchname;
00966 options_->GetOpt("root","nuclear_branch",nuclearbranchname);
00967 nuclearBranch_= tree_->GetBranch(nuclearbranchname.c_str());
00968 if(!nuclearBranch_) {
00969 cerr<<"PFRootEventManager::ReadOptions : nuclear_branch not found : "
00970 <<nuclearbranchname<< endl;
00971 }
00972 }
00973
00974
00975 useConversions_=false;
00976 options_->GetOpt("particle_flow", "usePFConversions", useConversions_);
00977 if( useConversions_ ) {
00978 string conversionbranchname;
00979 options_->GetOpt("root","conversion_branch",conversionbranchname);
00980 conversionBranch_= tree_->GetBranch(conversionbranchname.c_str());
00981 if(!conversionBranch_) {
00982 cerr<<"PFRootEventManager::ReadOptions : conversion_branch not found : "
00983 <<conversionbranchname<< endl;
00984 }
00985 }
00986
00987
00988
00989 useV0_=false;
00990 options_->GetOpt("particle_flow", "useV0", useV0_);
00991 if( useV0_ ) {
00992
00993 string V0branchname;
00994 options_->GetOpt("root","V0_branch",V0branchname);
00995 v0Branch_= tree_->GetBranch(V0branchname.c_str());
00996 if(!v0Branch_) {
00997 cerr<<"PFRootEventManager::ReadOptions : V0_branch not found : "
00998 <<V0branchname<< endl;
00999 }
01000 }
01001
01002
01003 string trueParticlesbranchname;
01004 options_->GetOpt("root","trueParticles_branch", trueParticlesbranchname);
01005
01006 trueParticlesBranch_ = tree_->GetBranch(trueParticlesbranchname.c_str());
01007 if(!trueParticlesBranch_) {
01008 cerr<<"PFRootEventManager::ReadOptions : trueParticles_branch not found : "
01009 <<trueParticlesbranchname<< endl;
01010 }
01011
01012
01013 string MCTruthbranchname;
01014 options_->GetOpt("root","MCTruth_branch", MCTruthbranchname);
01015
01016 MCTruthBranch_ = tree_->GetBranch(MCTruthbranchname.c_str());
01017 if(!MCTruthBranch_) {
01018 cerr<<"PFRootEventManager::ReadOptions : MCTruth_branch not found : "
01019 <<MCTruthbranchname << endl;
01020 }
01021
01022 string caloTowersBranchName;
01023 caloTowersBranch_ = 0;
01024 options_->GetOpt("root","caloTowers_branch", caloTowersBranchName);
01025 if(!caloTowersBranchName.empty() ) {
01026 caloTowersBranch_ = tree_->GetBranch(caloTowersBranchName.c_str());
01027 if(!caloTowersBranch_) {
01028 cerr<<"PFRootEventManager::ReadOptions : caloTowers_branch not found : "
01029 <<caloTowersBranchName<< endl;
01030 }
01031 }
01032
01033
01034 string genParticleCandBranchName;
01035 genParticlesforJetsBranch_ = 0;
01036 options_->GetOpt("root","genParticleforJets_branch",
01037 genParticleCandBranchName);
01038 if(!genParticleCandBranchName.empty() ){
01039 genParticlesforJetsBranch_=
01040 tree_->GetBranch(genParticleCandBranchName.c_str());
01041 if(!genParticlesforJetsBranch_) {
01042 cerr<<"PFRootEventanager::ReadOptions : "
01043 <<"genParticleforJets_branch not found : "
01044 <<genParticleCandBranchName<< endl;
01045 }
01046 }
01047
01048
01049 string caloTowerCandBranchName;
01050 caloTowerBaseCandidatesBranch_ = 0;
01051 options_->GetOpt("root","caloTowerBaseCandidates_branch",
01052 caloTowerCandBranchName);
01053 if(!caloTowerCandBranchName.empty() ){
01054 caloTowerBaseCandidatesBranch_=
01055 tree_->GetBranch(caloTowerCandBranchName.c_str());
01056 if(!caloTowerBaseCandidatesBranch_) {
01057 cerr<<"PFRootEventanager::ReadOptions : "
01058 <<"caloTowerBaseCandidates_branch not found : "
01059 <<caloTowerCandBranchName<< endl;
01060 }
01061 }
01062
01063
01064 string genJetBranchName;
01065 options_->GetOpt("root","genJetBranchName", genJetBranchName);
01066 if(!genJetBranchName.empty() ) {
01067 genJetBranch_= tree_->GetBranch(genJetBranchName.c_str());
01068 if(!genJetBranch_) {
01069 cerr<<"PFRootEventManager::ReadOptions :genJetBranch_ not found : "
01070 <<genJetBranchName<< endl;
01071 }
01072 }
01073
01074 string recCaloBranchName;
01075 options_->GetOpt("root","recCaloJetBranchName", recCaloBranchName);
01076 if(!recCaloBranchName.empty() ) {
01077 recCaloBranch_= tree_->GetBranch(recCaloBranchName.c_str());
01078 if(!recCaloBranch_) {
01079 cerr<<"PFRootEventManager::ReadOptions :recCaloBranch_ not found : "
01080 <<recCaloBranchName<< endl;
01081 }
01082 }
01083 string recPFBranchName;
01084 options_->GetOpt("root","recPFJetBranchName", recPFBranchName);
01085 if(!recPFBranchName.empty() ) {
01086 recPFBranch_= tree_->GetBranch(recPFBranchName.c_str());
01087 if(!recPFBranch_) {
01088 cerr<<"PFRootEventManager::ReadOptions :recPFBranch_ not found : "
01089 <<recPFBranchName<< endl;
01090 }
01091 }
01092 setAddresses();
01093
01094 }
01095
01096
01097
01098
01099 void PFRootEventManager::setAddresses() {
01100 if( rechitsECALBranch_ ) rechitsECALBranch_->SetAddress(&rechitsECAL_);
01101 if( rechitsHCALBranch_ ) rechitsHCALBranch_->SetAddress(&rechitsHCAL_);
01102 if( rechitsPSBranch_ ) rechitsPSBranch_->SetAddress(&rechitsPS_);
01103 if( clustersECALBranch_ ) clustersECALBranch_->SetAddress( clustersECAL_.get() );
01104 if( clustersHCALBranch_ ) clustersHCALBranch_->SetAddress( clustersHCAL_.get() );
01105 if( clustersPSBranch_ ) clustersPSBranch_->SetAddress( clustersPS_.get() );
01106 if( clustersIslandBarrelBranch_ )
01107 clustersIslandBarrelBranch_->SetAddress(&clustersIslandBarrel_);
01108 if( recTracksBranch_ ) recTracksBranch_->SetAddress(&recTracks_);
01109 if( stdTracksBranch_ ) stdTracksBranch_->SetAddress(&stdTracks_);
01110 if( gsfrecTracksBranch_ ) gsfrecTracksBranch_->SetAddress(&gsfrecTracks_);
01111 if( muonsBranch_ ) muonsBranch_->SetAddress(&muons_);
01112 if( nuclearBranch_ ) nuclearBranch_->SetAddress(&nuclear_);
01113 if( conversionBranch_ ) conversionBranch_->SetAddress(&conversion_);
01114 if( v0Branch_ ) v0Branch_->SetAddress(&v0_);
01115
01116 if( trueParticlesBranch_ ) trueParticlesBranch_->SetAddress(&trueParticles_);
01117 if( MCTruthBranch_ ) {
01118 MCTruthBranch_->SetAddress(&MCTruth_);
01119 }
01120 if( caloTowersBranch_ ) caloTowersBranch_->SetAddress(&caloTowers_);
01121 if( genParticlesforJetsBranch_ )
01122 genParticlesforJetsBranch_->SetAddress(&genParticlesforJets_);
01123
01124
01125
01126 if (genJetBranch_) genJetBranch_->SetAddress(&genJetsCMSSW_);
01127 if (recCaloBranch_) recCaloBranch_->SetAddress(&caloJetsCMSSW_);
01128 if (recPFBranch_) recPFBranch_->SetAddress(&pfJetsCMSSW_);
01129 }
01130
01131
01132 PFRootEventManager::~PFRootEventManager() {
01133
01134 if(outFile_) {
01135 outFile_->Close();
01136 }
01137
01138 if(outEvent_) delete outEvent_;
01139
01140 delete options_;
01141
01142 }
01143
01144
01145 void PFRootEventManager::write() {
01146
01147 if(doPFJetBenchmark_) PFJetBenchmark_.write();
01148
01149 if(!outFile_) return;
01150 else {
01151 outFile_->cd();
01152
01153 cout<<"writing output to "<<outFile_->GetName()<<endl;
01154 h_deltaETvisible_MCEHT_->Write();
01155 h_deltaETvisible_MCPF_->Write();
01156 if(outTree_) outTree_->Write();
01157 }
01158 }
01159
01160
01161 bool PFRootEventManager::processEntry(int entry) {
01162
01163 reset();
01164
01165 iEvent_ = entry;
01166
01167 if( outEvent_ ) outEvent_->setNumber(entry);
01168
01169 if(verbosity_ == VERBOSE ||
01170 entry < 100 && entry%10 == 0 ||
01171 entry < 1000 && entry%100 == 0 ||
01172 entry%1000 == 0 )
01173 cout<<"process entry "<< entry << endl;
01174
01175 bool goodevent = readFromSimulation(entry);
01176
01177 if(verbosity_ == VERBOSE ) {
01178 cout<<"number of recTracks : "<<recTracks_.size()<<endl;
01179 cout<<"number of gsfrecTracks : "<<gsfrecTracks_.size()<<endl;
01180 cout<<"number of muons : "<<muons_.size()<<endl;
01181 cout<<"number of nuclear ints : "<<nuclear_.size()<<endl;
01182 cout<<"number of conversions : "<<conversion_.size()<<endl;
01183 cout<<"number of v0 : "<<v0_.size()<<endl;
01184 cout<<"number of stdTracks : "<<stdTracks_.size()<<endl;
01185 cout<<"number of true particles : "<<trueParticles_.size()<<endl;
01186 cout<<"number of ECAL rechits : "<<rechitsECAL_.size()<<endl;
01187 cout<<"number of HCAL rechits : "<<rechitsHCAL_.size()<<endl;
01188 cout<<"number of PS rechits : "<<rechitsPS_.size()<<endl;
01189 }
01190
01191 if( doClustering_ ) clustering();
01192 else if( verbosity_ == VERBOSE )
01193 cout<<"clustering is OFF - clusters come from the input file"<<endl;
01194
01195 if(verbosity_ == VERBOSE ) {
01196 if(clustersECAL_.get() ) {
01197 cout<<"number of ECAL clusters : "<<clustersECAL_->size()<<endl;
01198 }
01199 if(clustersHCAL_.get() ) {
01200 cout<<"number of HCAL clusters : "<<clustersHCAL_->size()<<endl;
01201 }
01202 if(clustersPS_.get() ) {
01203 cout<<"number of PS clusters : "<<clustersPS_->size()<<endl;
01204 }
01205 }
01206
01207
01208 if(doParticleFlow_) particleFlow();
01209
01210 if(doJets_) {
01211 reconstructGenJets();
01212 reconstructCaloJets();
01213 reconstructPFJets();
01214 }
01215
01216
01217 if( verbosity_ == VERBOSE ) print();
01218
01219
01220
01221 if(doPFJetBenchmark_) {
01222
01223
01224 PFJetBenchmark_.process(pfJets_, genJets_);
01225 double resPt = PFJetBenchmark_.resPtMax();
01226 double resChargedHadEnergy = PFJetBenchmark_.resChargedHadEnergyMax();
01227 double resNeutralHadEnergy = PFJetBenchmark_.resNeutralHadEnergyMax();
01228 double resNeutralEmEnergy = PFJetBenchmark_.resNeutralEmEnergyMax();
01229
01230 if( verbosity_ == VERBOSE ){
01231
01232 cout << " =====================PFJetBenchmark =================" << endl;
01233 cout<<"Resol Pt max "<<resPt
01234 <<" resChargedHadEnergy Max " << resChargedHadEnergy
01235 <<" resNeutralHadEnergy Max " << resNeutralHadEnergy
01236 << " resNeutralEmEnergy Max "<< resNeutralEmEnergy << endl;
01237 }
01238
01239
01240 if ( resPt < -1. ) {
01241 cout << " =====================PFJetBenchmark =================" << endl;
01242 cout<<"process entry "<< entry << endl;
01243 cout<<"Resol Pt max "<<resPt
01244 <<" resChargedHadEnergy Max " << resChargedHadEnergy
01245 <<" resNeutralHadEnergy Max " << resNeutralHadEnergy
01246 << " resNeutralEmEnergy Max "<< resNeutralEmEnergy
01247 << " Jet pt " << genJets_[0].pt() << endl;
01248
01249 } else {
01250
01251 }
01252
01253
01254 }
01255
01256
01257 if( goodevent && doTauBenchmark_) {
01258 double deltaEt = 0.;
01259 deltaEt = tauBenchmark( *pfCandidates_ );
01260 if( verbosity_ == VERBOSE ) cout<<"delta E_t ="<<deltaEt <<endl;
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271 }
01272
01273 if(goodevent && outTree_)
01274 outTree_->Fill();
01275
01276 return goodevent;
01277
01278 }
01279
01280
01281
01282 bool PFRootEventManager::readFromSimulation(int entry) {
01283
01284 if (verbosity_ == VERBOSE ) {
01285 cout <<"start reading from simulation"<<endl;
01286 }
01287
01288
01289 if(!tree_) return false;
01290
01291 setAddresses();
01292
01293 if(stdTracksBranch_) {
01294 stdTracksBranch_->GetEntry(entry);
01295 }
01296 if(MCTruthBranch_) {
01297 MCTruthBranch_->GetEntry(entry);
01298 }
01299 if(trueParticlesBranch_ ) {
01300 trueParticlesBranch_->GetEntry(entry);
01301 }
01302 if(rechitsECALBranch_) {
01303 rechitsECALBranch_->GetEntry(entry);
01304 }
01305 if(rechitsHCALBranch_) {
01306 rechitsHCALBranch_->GetEntry(entry);
01307 }
01308 if(rechitsPSBranch_) {
01309 rechitsPSBranch_->GetEntry(entry);
01310 }
01311 if(clustersECALBranch_ && !doClustering_) {
01312 clustersECALBranch_->GetEntry(entry);
01313 }
01314 if(clustersHCALBranch_ && !doClustering_) {
01315 clustersHCALBranch_->GetEntry(entry);
01316 }
01317 if(clustersPSBranch_ && !doClustering_) {
01318 clustersPSBranch_->GetEntry(entry);
01319 }
01320 if(clustersIslandBarrelBranch_) {
01321 clustersIslandBarrelBranch_->GetEntry(entry);
01322 }
01323 if(caloTowersBranch_) {
01324 caloTowersBranch_->GetEntry(entry);
01325 }
01326 if(recTracksBranch_) {
01327 recTracksBranch_->GetEntry(entry);
01328 }
01329 if(gsfrecTracksBranch_) {
01330 gsfrecTracksBranch_->GetEntry(entry);
01331 }
01332 if(muonsBranch_) {
01333 muonsBranch_->GetEntry(entry);
01334 }
01335 if(nuclearBranch_) {
01336 nuclearBranch_->GetEntry(entry);
01337 }
01338 if(conversionBranch_) {
01339 conversionBranch_->GetEntry(entry);
01340 }
01341 if(v0Branch_) {
01342 v0Branch_->GetEntry(entry);
01343 }
01344
01345 if(genParticlesforJetsBranch_) {
01346 genParticlesforJetsBranch_->GetEntry(entry);
01347 }
01348
01349
01350
01351 if(genJetBranch_) {
01352 genJetBranch_->GetEntry(entry);
01353 }
01354 if(recCaloBranch_) {
01355 recCaloBranch_->GetEntry(entry);
01356 }
01357 if(recPFBranch_) {
01358 recPFBranch_->GetEntry(entry);
01359 }
01360
01361 tree_->GetEntry( entry, 0 );
01362
01363
01364
01365 bool goodevent = true;
01366 if(trueParticlesBranch_ ) {
01367
01368 if(filterNParticles_ &&
01369 trueParticles_.size() != filterNParticles_ ) {
01370 cout << "PFRootEventManager : event discarded Nparticles="
01371 <<filterNParticles_<< endl;
01372 goodevent = false;
01373 }
01374 if(goodevent && filterHadronicTaus_ && !isHadronicTau() ) {
01375 cout << "PFRootEventManager : leptonic tau discarded " << endl;
01376 goodevent = false;
01377 }
01378 if( goodevent && !filterTaus_.empty()
01379 && !countChargedAndPhotons() ) {
01380 assert( filterTaus_.size() == 2 );
01381 cout <<"PFRootEventManager : tau discarded: "
01382 <<"number of charged and neutral particles different from "
01383 <<filterTaus_[0]<<","<<filterTaus_[1]<<endl;
01384 goodevent = false;
01385 }
01386
01387 if(goodevent)
01388 fillOutEventWithSimParticles( trueParticles_ );
01389
01390 }
01391
01392
01393
01394
01395
01396
01397 if(rechitsECALBranch_) {
01398 PreprocessRecHits( rechitsECAL_ , findRecHitNeighbours_);
01399 }
01400 if(rechitsHCALBranch_) {
01401 PreprocessRecHits( rechitsHCAL_ , findRecHitNeighbours_);
01402 }
01403 if(rechitsPSBranch_) {
01404 PreprocessRecHits( rechitsPS_ , findRecHitNeighbours_);
01405 }
01406
01407 if ( recTracksBranch_ ) {
01408 PreprocessRecTracks( recTracks_);
01409 }
01410
01411 if(gsfrecTracksBranch_) {
01412 PreprocessRecTracks( gsfrecTracks_);
01413 }
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428 return goodevent;
01429 }
01430
01431
01432 bool PFRootEventManager::isHadronicTau() const {
01433
01434 for ( unsigned i=0; i < trueParticles_.size(); i++) {
01435 const reco::PFSimParticle& ptc = trueParticles_[i];
01436 const std::vector<int>& ptcdaughters = ptc.daughterIds();
01437 if (abs(ptc.pdgCode()) == 15) {
01438 for ( unsigned int dapt=0; dapt < ptcdaughters.size(); ++dapt) {
01439
01440 const reco::PFSimParticle& daughter
01441 = trueParticles_[ptcdaughters[dapt]];
01442
01443
01444 int pdgdaugther = daughter.pdgCode();
01445 int abspdgdaughter = abs(pdgdaugther);
01446
01447
01448 if (abspdgdaughter == 11 ||
01449 abspdgdaughter == 13) {
01450 return false;
01451 }
01452 }
01453 }
01454 }
01455
01456
01457 return true;
01458 }
01459
01460
01461
01462 bool PFRootEventManager::countChargedAndPhotons() const {
01463
01464 int nPhoton = 0;
01465 int nCharged = 0;
01466
01467 for ( unsigned i=0; i < trueParticles_.size(); i++) {
01468 const reco::PFSimParticle& ptc = trueParticles_[i];
01469
01470 const std::vector<int>& daughters = ptc.daughterIds();
01471
01472
01473
01474 if(!daughters.empty() ) continue;
01475
01476 double charge = ptc.charge();
01477 double pdgCode = ptc.pdgCode();
01478
01479 if( abs(charge)>1e-9)
01480 nCharged++;
01481 else if( pdgCode==22 )
01482 nPhoton++;
01483 }
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512 if( nCharged == filterTaus_[0] &&
01513 nPhoton == filterTaus_[1] )
01514 return true;
01515 else
01516 return false;
01517 }
01518
01519
01520
01521 int PFRootEventManager::chargeValue(const int& Id) const {
01522
01523
01524
01525
01526
01527
01528
01529 int kqa,kq1,kq2,kq3,kqj,irt,kqx,kqn;
01530 int hepchg;
01531
01532
01533 int ichg[109]={-1,2,-1,2,-1,2,-1,2,0,0,-3,0,-3,0,-3,0,
01534 -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,
01535 -3,0,-3,0,-3,0,0,0,0,0,-1,2,-1,2,-1,2,0,0,0,0,
01536 -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};
01537
01538
01539
01540 hepchg=0;
01541 kqa=abs(Id);
01542 kqn=kqa/1000000000%10;
01543 kqx=kqa/1000000%10;
01544 kq3=kqa/1000%10;
01545 kq2=kqa/100%10;
01546 kq1=kqa/10%10;
01547 kqj=kqa%10;
01548 irt=kqa%10000;
01549
01550
01551
01552 if(kqa==0 || kqa >= 10000000) {
01553
01554 if(kqn==1) {hepchg=0;}
01555 }
01556
01557 else if(kqa<=100) {hepchg = ichg[kqa-1];}
01558
01559 else if(kqa==100 || kqa==101) {hepchg = -3;}
01560
01561 else if(kqa==102 || kqa==104) {hepchg = -6;}
01562
01563 else if(kqj == 0) {hepchg = 0;}
01564
01565 else if(kqx>0 && irt<100)
01566 {
01567 hepchg = ichg[irt-1];
01568 if(kqa==1000017 || kqa==1000018) {hepchg = 0;}
01569 if(kqa==1000034 || kqa==1000052) {hepchg = 0;}
01570 if(kqa==1000053 || kqa==1000054) {hepchg = 0;}
01571 if(kqa==5100061 || kqa==5100062) {hepchg = 6;}
01572 }
01573
01574
01575 else if(kq3==0)
01576 {
01577 hepchg = ichg[kq2-1]-ichg[kq1-1];
01578
01579 if((kq2==3) || (kq2==5)) {hepchg = ichg[kq1-1]-ichg[kq2-1];}
01580 }
01581 else if(kq1 == 0) {
01582
01583 hepchg = ichg[kq3-1] + ichg[kq2-1];
01584 }
01585
01586 else{
01587
01588 hepchg = ichg[kq3-1]+ichg[kq2-1]+ichg[kq1-1];
01589 }
01590
01591
01592 if(Id<0 && hepchg!=0) {hepchg = -1*hepchg;}
01593
01594
01595 return hepchg;
01596 }
01597
01598
01599
01600 void
01601 PFRootEventManager::PreprocessRecTracks(reco::PFRecTrackCollection& recTracks) {
01602 for( unsigned i=0; i<recTracks.size(); ++i ) {
01603 recTracks[i].calculatePositionREP();
01604 }
01605 }
01606
01607 void
01608 PFRootEventManager::PreprocessRecTracks(reco::GsfPFRecTrackCollection& recTracks) {
01609 for( unsigned i=0; i<recTracks.size(); ++i ) {
01610 recTracks[i].calculatePositionREP();
01611 }
01612 }
01613
01614
01615
01616 void
01617 PFRootEventManager::PreprocessRecHits(reco::PFRecHitCollection& rechits,
01618 bool findNeighbours) {
01619
01620
01621 map<unsigned, unsigned> detId2index;
01622
01623 for(unsigned i=0; i<rechits.size(); i++) {
01624 rechits[i].calculatePositionREP();
01625
01626 if(findNeighbours)
01627 detId2index.insert( make_pair(rechits[i].detId(), i) );
01628 }
01629
01630 if(findNeighbours) {
01631 for(unsigned i=0; i<rechits.size(); i++) {
01632 setRecHitNeigbours( rechits[i], detId2index );
01633 }
01634 }
01635 }
01636
01637
01638 void PFRootEventManager::setRecHitNeigbours
01639 ( reco::PFRecHit& rh,
01640 const map<unsigned, unsigned>& detId2index ) {
01641
01642 rh.clearNeighbours();
01643
01644 vector<unsigned> neighbours4DetId = rh.neighboursIds4();
01645 vector<unsigned> neighbours8DetId = rh.neighboursIds8();
01646
01647 for( unsigned i=0; i<neighbours4DetId.size(); i++) {
01648 unsigned detId = neighbours4DetId[i];
01649
01650 const map<unsigned, unsigned>::const_iterator& it = detId2index.find(detId);
01651
01652 if(it != detId2index.end() ) {
01653
01654 rh.add4Neighbour( it->second );
01655 }
01656 }
01657
01658 for( unsigned i=0; i<neighbours8DetId.size(); i++) {
01659 unsigned detId = neighbours8DetId[i];
01660
01661 const map<unsigned, unsigned>::const_iterator& it = detId2index.find(detId);
01662
01663 if(it != detId2index.end() ) {
01664
01665 rh.add8Neighbour( it->second );
01666 }
01667 }
01668
01669
01670 }
01671
01672
01673 void PFRootEventManager::clustering() {
01674
01675 if (verbosity_ == VERBOSE ) {
01676 cout <<"start clustering"<<endl;
01677 }
01678
01679
01680
01681 vector<bool> mask;
01682 fillRecHitMask( mask, rechitsECAL_ );
01683 clusterAlgoECAL_.setMask( mask );
01684
01685
01686 clusterAlgoECAL_.doClustering( rechitsECAL_ );
01687 clustersECAL_ = clusterAlgoECAL_.clusters();
01688
01689 assert(clustersECAL_.get() );
01690
01691 fillOutEventWithClusters( *clustersECAL_ );
01692
01693
01694
01695 fillRecHitMask( mask, rechitsHCAL_ );
01696 clusterAlgoHCAL_.setMask( mask );
01697
01698 clusterAlgoHCAL_.doClustering( rechitsHCAL_ );
01699 clustersHCAL_ = clusterAlgoHCAL_.clusters();
01700
01701 fillOutEventWithClusters( *clustersHCAL_ );
01702
01703
01704
01705 fillRecHitMask( mask, rechitsPS_ );
01706 clusterAlgoPS_.setMask( mask );
01707
01708 clusterAlgoPS_.doClustering( rechitsPS_ );
01709 clustersPS_ = clusterAlgoPS_.clusters();
01710
01711 fillOutEventWithClusters( *clustersPS_ );
01712
01713 }
01714
01715
01716
01717 void
01718 PFRootEventManager::fillOutEventWithClusters(const reco::PFClusterCollection&
01719 clusters) {
01720
01721 if(!outEvent_) return;
01722
01723 for(unsigned i=0; i<clusters.size(); i++) {
01724 EventColin::Cluster cluster;
01725 cluster.eta = clusters[i].position().Eta();
01726 cluster.phi = clusters[i].position().Phi();
01727 cluster.e = clusters[i].energy();
01728 cluster.layer = clusters[i].layer();
01729 cluster.type = 1;
01730
01731 reco::PFTrajectoryPoint::LayerType tpLayer =
01732 reco::PFTrajectoryPoint::NLayers;
01733 switch( clusters[i].layer() ) {
01734 case PFLayer::ECAL_BARREL:
01735 case PFLayer::ECAL_ENDCAP:
01736 tpLayer = reco::PFTrajectoryPoint::ECALEntrance;
01737 break;
01738 case PFLayer::HCAL_BARREL1:
01739 case PFLayer::HCAL_ENDCAP:
01740 tpLayer = reco::PFTrajectoryPoint::HCALEntrance;
01741 break;
01742 default:
01743 break;
01744 }
01745 if(tpLayer < reco::PFTrajectoryPoint::NLayers) {
01746 try {
01747 double peta = -10;
01748 double phi = -10;
01749 double pe = -10;
01750
01751 const reco::PFSimParticle& ptc
01752 = closestParticle( tpLayer,
01753 cluster.eta, cluster.phi,
01754 peta, phi, pe );
01755
01756
01757 cluster.particle.eta = peta;
01758 cluster.particle.phi = phi;
01759 cluster.particle.e = pe;
01760 cluster.particle.pdgCode = ptc.pdgCode();
01761
01762
01763 }
01764 catch( std::exception& err ) {
01765
01766 }
01767 }
01768
01769 outEvent_->addCluster(cluster);
01770 }
01771 }
01772
01773
01774 void
01775 PFRootEventManager::fillOutEventWithSimParticles(const reco::PFSimParticleCollection& trueParticles ) {
01776
01777 if(!outEvent_) return;
01778
01779 for ( unsigned i=0; i < trueParticles.size(); i++) {
01780
01781 const reco::PFSimParticle& ptc = trueParticles[i];
01782
01783 unsigned ntrajpoints = ptc.nTrajectoryPoints();
01784
01785 if(ptc.daughterIds().empty() ) {
01786 reco::PFTrajectoryPoint::LayerType ecalEntrance
01787 = reco::PFTrajectoryPoint::ECALEntrance;
01788
01789 if(ntrajpoints == 3) {
01790
01791
01792
01793 ecalEntrance = static_cast<reco::PFTrajectoryPoint::LayerType>(1);
01794 }
01795
01796
01797 const reco::PFTrajectoryPoint& tpatecal
01798 = ptc.extrapolatedPoint( ecalEntrance );
01799
01800 EventColin::Particle outptc;
01801 outptc.eta = tpatecal.position().Eta();
01802 outptc.phi = tpatecal.position().Phi();
01803 outptc.e = tpatecal.momentum().E();
01804 outptc.pdgCode = ptc.pdgCode();
01805
01806
01807 outEvent_->addParticle(outptc);
01808 }
01809 }
01810 }
01811
01812 void
01813 PFRootEventManager::fillOutEventWithPFCandidates(const reco::PFCandidateCollection& pfCandidates ) {
01814
01815 if(!outEvent_) return;
01816
01817 for ( unsigned i=0; i < pfCandidates.size(); i++) {
01818
01819 const reco::PFCandidate& candidate = pfCandidates[i];
01820
01821 EventColin::Particle outptc;
01822 outptc.eta = candidate.eta();
01823 outptc.phi = candidate.phi();
01824 outptc.e = candidate.energy();
01825 outptc.pdgCode = candidate.particleId();
01826
01827
01828 outEvent_->addCandidate(outptc);
01829 }
01830 }
01831
01832
01833 void
01834 PFRootEventManager::fillOutEventWithCaloTowers( const CaloTowerCollection& cts ){
01835
01836 if(!outEvent_) return;
01837
01838 for ( unsigned i=0; i < cts.size(); i++) {
01839
01840 const CaloTower& ct = cts[i];
01841
01842 EventColin::CaloTower outct;
01843 outct.e = ct.energy();
01844 outct.ee = ct.emEnergy();
01845 outct.eh = ct.hadEnergy();
01846
01847 outEvent_->addCaloTower( outct );
01848 }
01849 }
01850
01851
01852 void
01853 PFRootEventManager::fillOutEventWithBlocks( const reco::PFBlockCollection&
01854 blocks ) {
01855
01856 if(!outEvent_) return;
01857
01858 for ( unsigned i=0; i < blocks.size(); i++) {
01859
01860
01861
01862 EventColin::Block outblock;
01863
01864 outEvent_->addBlock( outblock );
01865 }
01866 }
01867
01868
01869
01870 void PFRootEventManager::particleFlow() {
01871
01872 if (verbosity_ == VERBOSE ) {
01873 cout <<"start particle flow"<<endl;
01874 }
01875
01876
01877 if( debug_) {
01878 cout<<"PFRootEventManager::particleFlow start"<<endl;
01879
01880
01881 }
01882
01883 edm::OrphanHandle< reco::PFRecTrackCollection > trackh( &recTracks_,
01884 edm::ProductID(1) );
01885
01886 edm::OrphanHandle< reco::PFClusterCollection > ecalh( clustersECAL_.get(),
01887 edm::ProductID(2) );
01888
01889 edm::OrphanHandle< reco::PFClusterCollection > hcalh( clustersHCAL_.get(),
01890 edm::ProductID(3) );
01891
01892 edm::OrphanHandle< reco::PFClusterCollection > psh( clustersPS_.get(),
01893 edm::ProductID(4) );
01894
01895 edm::OrphanHandle< reco::GsfPFRecTrackCollection > gsftrackh( &gsfrecTracks_,
01896 edm::ProductID(5) );
01897
01898 edm::OrphanHandle< reco::MuonCollection > muonh( &muons_,
01899 edm::ProductID(6) );
01900
01901 edm::OrphanHandle< reco::PFNuclearInteractionCollection > nuclh( &nuclear_,
01902 edm::ProductID(7) );
01903
01904 edm::OrphanHandle< reco::PFConversionCollection > convh( &conversion_,
01905 edm::ProductID(8) );
01906
01907 edm::OrphanHandle< reco::PFV0Collection > v0( &v0_,
01908 edm::ProductID(9) );
01909
01910 vector<bool> trackMask;
01911 fillTrackMask( trackMask, recTracks_ );
01912 vector<bool> gsftrackMask;
01913 fillTrackMask( gsftrackMask, gsfrecTracks_ );
01914 vector<bool> ecalMask;
01915 fillClusterMask( ecalMask, *clustersECAL_ );
01916 vector<bool> hcalMask;
01917 fillClusterMask( hcalMask, *clustersHCAL_ );
01918 vector<bool> psMask;
01919 fillClusterMask( psMask, *clustersPS_ );
01920
01921 pfBlockAlgo_.setInput( trackh, gsftrackh,
01922 muonh,nuclh,convh,v0,
01923 ecalh, hcalh, psh,
01924 trackMask,gsftrackMask,
01925 ecalMask, hcalMask, psMask );
01926
01927
01928
01929
01930 pfBlockAlgo_.findBlocks();
01931
01932 if( debug_) cout<<pfBlockAlgo_<<endl;
01933
01934 pfBlocks_ = pfBlockAlgo_.transferBlocks();
01935
01936
01937
01938
01939
01940 pfAlgo_.reconstructParticles( *pfBlocks_.get() );
01941
01942 if( debug_) cout<< pfAlgo_<<endl;
01943 pfCandidates_ = pfAlgo_.transferCandidates();
01944
01945
01946 fillOutEventWithPFCandidates( *pfCandidates_ );
01947
01948 if( debug_) cout<<"PFRootEventManager::particleFlow stop"<<endl;
01949 }
01950
01951
01952
01953 void PFRootEventManager::reconstructGenJets() {
01954
01955 if (verbosity_ == VERBOSE || jetsDebug_) {
01956 cout<<endl;
01957 cout<<"start reconstruct GenJets --- "<<endl;
01958 cout<< " input gen particles for jet: all neutrinos removed ; muons present" << endl;
01959 }
01960
01961 genJets_.clear();
01962 genParticlesforJetsPtrs_.clear();
01963
01964 for(unsigned i=0; i<genParticlesforJets_.size(); i++) {
01965
01966 const reco::GenParticle& genPart = *(genParticlesforJets_[i]);
01967
01968
01969
01970
01971 if (reco::isNeutrino( genPart )) continue;
01972
01973 if (jetsDebug_ ) {
01974 cout << " #" << i << " PDG code:" << genPart.pdgId()
01975 << " status " << genPart.status()
01976 << ", p/pt/eta/phi: " << genPart.p() << '/' << genPart.pt()
01977 << '/' << genPart.eta() << '/' << genPart.phi() << endl;
01978 }
01979
01980 genParticlesforJetsPtrs_.push_back( refToPtr(genParticlesforJets_[i]) );
01981 }
01982
01983 vector<ProtoJet> protoJets;
01984 reconstructFWLiteJets(genParticlesforJetsPtrs_, protoJets );
01985
01986
01987
01988 int ijet = 0;
01989 typedef vector <ProtoJet>::const_iterator IPJ;
01990 for (IPJ ipj = protoJets.begin(); ipj != protoJets.end (); ipj++) {
01991 const ProtoJet& protojet = *ipj;
01992 const ProtoJet::Constituents& constituents = protojet.getTowerList();
01993
01994 reco::Jet::Point vertex (0,0,0);
01995 GenJet::Specific specific;
01996 JetMaker::makeSpecific(constituents, &specific);
01997
01998 GenJet newJet (protojet.p4(), vertex, specific);
01999
02000
02001
02002
02003
02004
02005
02006 ProtoJet::Constituents::const_iterator constituent = constituents.begin();
02007 for (; constituent != constituents.end(); ++constituent) {
02008
02009
02010 uint index = constituent->index();
02011 newJet.addDaughter( genParticlesforJetsPtrs_[index] );
02012 }
02013
02014 newJet.setJetArea(protojet.jetArea());
02015 newJet.setPileup(protojet.pileup());
02016 newJet.setNPasses(protojet.nPasses());
02017 ++ijet;
02018 if (jetsDebug_ ) cout<<" gen jet "<<ijet<<" "<<newJet.print()<<endl;
02019 genJets_.push_back (newJet);
02020
02021 }
02022
02023 }
02024
02025 void PFRootEventManager::reconstructCaloJets() {
02026
02027 if (verbosity_ == VERBOSE || jetsDebug_ ) {
02028 cout<<endl;
02029 cout<<"start reconstruct CaloJets --- "<<endl;
02030 }
02031 caloJets_.clear();
02032 caloTowersPtrs_.clear();
02033
02034 for( unsigned i=0; i<caloTowers_.size(); i++) {
02035 reco::CandidatePtr candPtr( &caloTowers_, i );
02036 caloTowersPtrs_.push_back( candPtr );
02037 }
02038
02039 reconstructFWLiteJets( caloTowersPtrs_, caloJets_ );
02040
02041 if (jetsDebug_ ) {
02042 for(unsigned ipj=0; ipj<caloJets_.size(); ipj++) {
02043 const ProtoJet& protojet = caloJets_[ipj];
02044 cout<<" calo jet "<<ipj<<" "<<protojet.pt() <<endl;
02045 }
02046 }
02047
02048 }
02049
02050
02051 void PFRootEventManager::reconstructPFJets() {
02052
02053 if (verbosity_ == VERBOSE || jetsDebug_) {
02054 cout<<endl;
02055 cout<<"start reconstruct PF Jets --- "<<endl;
02056 }
02057 pfJets_.clear();
02058 pfCandidatesPtrs_.clear();
02059
02060 for( unsigned i=0; i<pfCandidates_->size(); i++) {
02061 reco::CandidatePtr candPtr( pfCandidates_.get(), i );
02062 pfCandidatesPtrs_.push_back( candPtr );
02063 }
02064
02065 vector<ProtoJet> protoJets;
02066 reconstructFWLiteJets(pfCandidatesPtrs_, protoJets );
02067
02068
02069
02070 int ijet = 0;
02071 typedef vector <ProtoJet>::const_iterator IPJ;
02072 for (IPJ ipj = protoJets.begin(); ipj != protoJets.end (); ipj++) {
02073 const ProtoJet& protojet = *ipj;
02074 const ProtoJet::Constituents& constituents = protojet.getTowerList();
02075
02076 reco::Jet::Point vertex (0,0,0);
02077 PFJet::Specific specific;
02078 JetMaker::makeSpecific(constituents, &specific);
02079
02080 PFJet newJet (protojet.p4(), vertex, specific);
02081
02082
02083
02084
02085
02086
02087
02088 ProtoJet::Constituents::const_iterator constituent = constituents.begin();
02089 for (; constituent != constituents.end(); ++constituent) {
02090
02091
02092 uint index = constituent->index();
02093 newJet.addDaughter(pfCandidatesPtrs_[index]);
02094 }
02095
02096 newJet.setJetArea(protojet.jetArea());
02097 newJet.setPileup(protojet.pileup());
02098 newJet.setNPasses(protojet.nPasses());
02099 ++ijet;
02100 if (jetsDebug_ ) cout<<" PF jet "<<ijet<<" "<<newJet.print()<<endl;
02101 pfJets_.push_back (newJet);
02102
02103 }
02104
02105 }
02106
02107
02108
02109 void
02110 PFRootEventManager::reconstructFWLiteJets(const reco::CandidatePtrVector& Candidates, vector<ProtoJet>& output ) {
02111
02112
02113 JetReco::InputCollection input;
02114
02115 jetMaker_.applyCuts (Candidates, &input);
02116 if (jetAlgoType_==1) {
02118 jetMaker_.makeIterativeConeJets(input, &output);
02119 }
02120 if (jetAlgoType_==2) {
02121 jetMaker_.makeMidpointJets(input, &output);
02122 }
02123 if (jetAlgoType_==3) {
02124 jetMaker_.makeFastJets(input, &output);
02125 }
02126 if((jetAlgoType_>3)||(jetAlgoType_<0)) {
02127 cout<<"Unknown Jet Algo ! " <<jetAlgoType_ << endl;
02128 }
02129
02130
02131 }
02132
02133
02134
02135
02136 double
02137 PFRootEventManager::tauBenchmark( const reco::PFCandidateCollection& candidates) {
02138
02139
02140
02141
02142 jetAlgo_.Clear();
02143
02144
02145
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163
02164
02165
02166
02167
02168
02169
02170 TLorentzVector partTOTMC;
02171 bool tauFound = false;
02172 bool tooManyTaus = false;
02173 if (fastsim_){
02174
02175 for ( unsigned i=0; i < trueParticles_.size(); i++) {
02176 const reco::PFSimParticle& ptc = trueParticles_[i];
02177 if (abs(ptc.pdgCode()) == 15) {
02178
02179 if( i ) tooManyTaus = true;
02180 else tauFound=true;
02181 }
02182 }
02183
02184 if(!tauFound || tooManyTaus ) {
02185 cerr<<"PFRootEventManager::tauBenchmark : not a single tau event"<<endl;
02186 return -9999;
02187 }
02188
02189
02190 const std::vector<int>& ptcdaughters = trueParticles_[0].daughterIds();
02191
02192
02193
02194
02195
02196 for ( unsigned int dapt=0; dapt < ptcdaughters.size(); ++dapt) {
02197
02198 const reco::PFTrajectoryPoint& tpatvtx
02199 = trueParticles_[ptcdaughters[dapt]].trajectoryPoint(0);
02200 TLorentzVector partMC;
02201 partMC.SetPxPyPzE(tpatvtx.momentum().Px(),
02202 tpatvtx.momentum().Py(),
02203 tpatvtx.momentum().Pz(),
02204 tpatvtx.momentum().E());
02205
02206 partTOTMC += partMC;
02207 if (tauBenchmarkDebug_) {
02208
02209 int pdgcode = trueParticles_[ptcdaughters[dapt]].pdgCode();
02210 cout << pdgcode << endl;
02211 cout << tpatvtx << endl;
02212 cout << partMC.Px() << " " << partMC.Py() << " "
02213 << partMC.Pz() << " " << partMC.E()
02214 << " PT="
02215 << sqrt(partMC.Px()*partMC.Px()+partMC.Py()*partMC.Py())
02216 << endl;
02217 }
02218 }
02219 }else{
02220
02221 uint itau=0;
02222 const HepMC::GenEvent* myGenEvent = MCTruth_.GetEvent();
02223 for ( HepMC::GenEvent::particle_const_iterator
02224 piter = myGenEvent->particles_begin();
02225 piter != myGenEvent->particles_end();
02226 ++piter ) {
02227
02228
02229 if (abs((*piter)->pdg_id())==15){
02230 itau++;
02231 tauFound=true;
02232 for ( HepMC::GenVertex::particles_out_const_iterator bp =
02233 (*piter)->end_vertex()->particles_out_const_begin();
02234 bp != (*piter)->end_vertex()->particles_out_const_end(); ++bp ) {
02235 uint nuId=abs((*bp)->pdg_id());
02236 bool isNeutrino=(nuId==12)||(nuId==14)||(nuId==16);
02237 if (!isNeutrino){
02238
02239
02240 TLorentzVector partMC;
02241 partMC.SetPxPyPzE((*bp)->momentum().x(),
02242 (*bp)->momentum().y(),
02243 (*bp)->momentum().z(),
02244 (*bp)->momentum().e());
02245 partTOTMC += partMC;
02246 }
02247 }
02248 }
02249 }
02250 if (itau>1) tooManyTaus=true;
02251
02252 if(!tauFound || tooManyTaus ) {
02253 cerr<<"PFRootEventManager::tauBenchmark : not a single tau event"<<endl;
02254 return -9999;
02255 }
02256 }
02257
02258
02259
02260
02261
02262
02263
02264 EventColin::Jet jetmc;
02265
02266 jetmc.eta = partTOTMC.Eta();
02267 jetmc.phi = partTOTMC.Phi();
02268 jetmc.et = partTOTMC.Et();
02269 jetmc.e = partTOTMC.E();
02270
02271 if(outEvent_) outEvent_->addJetMC( jetmc );
02272
02273
02274
02275
02276
02277
02278
02279
02280
02281
02282
02283
02284
02285
02286
02287
02288
02289
02290
02291
02292
02293
02294
02295
02296
02297
02298
02299
02300
02301
02302
02303
02304 if (tauBenchmarkDebug_) {
02305 cout << " ET Vector=" << partTOTMC.Et()
02306 << " " << partTOTMC.Eta()
02307 << " " << partTOTMC.Phi() << endl; cout << endl;
02308 }
02309
02311
02312
02313
02314
02315 vector<TLorentzVector> allcalotowers;
02316
02317
02318 double threshCaloTowers = 0;
02319 for ( unsigned int i = 0; i < caloTowers_.size(); ++i) {
02320
02321 if(caloTowers_[i].energy() < threshCaloTowers) {
02322
02323 continue;
02324 }
02325
02326 TLorentzVector caloT;
02327 TVector3 pepr( caloTowers_[i].eta(),
02328 caloTowers_[i].phi(),
02329 caloTowers_[i].energy());
02330 TVector3 pxyz = Utils::VectorEPRtoXYZ( pepr );
02331 caloT.SetPxPyPzE(pxyz.X(),pxyz.Y(),pxyz.Z(),caloTowers_[i].energy());
02332 allcalotowers.push_back(caloT);
02333
02334
02335 }
02336 if ( tauBenchmarkDebug_)
02337 cout << " RETRIEVED " << allcalotowers.size()
02338 << " CALOTOWER 4-VECTORS " << endl;
02339
02340
02341 jetAlgo_.Clear();
02342 const vector< PFJetAlgorithm::Jet >& caloTjets
02343 = jetAlgo_.FindJets( &allcalotowers );
02344
02345
02346 double JetEHTETmax = 0.0;
02347 for ( unsigned i = 0; i < caloTjets.size(); i++) {
02348 TLorentzVector jetmom = caloTjets[i].GetMomentum();
02349 double jetcalo_pt = sqrt(jetmom.Px()*jetmom.Px()+jetmom.Py()*jetmom.Py());
02350 double jetcalo_et = jetmom.Et();
02351
02352
02353
02354 EventColin::Jet jet;
02355 jet.eta = jetmom.Eta();
02356 jet.phi = jetmom.Phi();
02357 jet.et = jetmom.Et();
02358 jet.e = jetmom.E();
02359
02360 const vector<int>& indexes = caloTjets[i].GetIndexes();
02361 for( unsigned ii=0; ii<indexes.size(); ii++){
02362 jet.ee += caloTowers_[ indexes[ii] ].emEnergy();
02363 jet.eh += caloTowers_[ indexes[ii] ].hadEnergy();
02364 jet.ete += caloTowers_[ indexes[ii] ].emEt();
02365 jet.eth += caloTowers_[ indexes[ii] ].hadEt();
02366 }
02367
02368 if(outEvent_) outEvent_->addJetEHT( jet );
02369
02370 if ( tauBenchmarkDebug_) {
02371 cout << " ECAL+HCAL jet : " << caloTjets[i] << endl;
02372 cout << jetmom.Px() << " " << jetmom.Py() << " "
02373 << jetmom.Pz() << " " << jetmom.E()
02374 << " PT=" << jetcalo_pt << endl;
02375 }
02376
02377 if (jetcalo_et >= JetEHTETmax)
02378 JetEHTETmax = jetcalo_et;
02379 }
02380
02382
02383 vector<TLorentzVector> allrecparticles;
02384
02385
02386
02387
02388
02389
02390
02391
02392
02393
02394
02395 for(unsigned i=0; i<candidates.size(); i++) {
02396
02397
02398
02399
02400
02401 const reco::PFCandidate& candidate = candidates[i];
02402
02403 if (tauBenchmarkDebug_) {
02404 cout << i << " " << candidate << endl;
02405 int type = candidate.particleId();
02406 cout << " type= " << type << " " << candidate.charge()
02407 << endl;
02408 }
02409
02410 const math::XYZTLorentzVector& PFpart = candidate.p4();
02411
02412 TLorentzVector partRec(PFpart.Px(),
02413 PFpart.Py(),
02414 PFpart.Pz(),
02415 PFpart.E());
02416
02417
02418 allrecparticles.push_back( partRec );
02419
02420 }
02421
02422
02423 if (tauBenchmarkDebug_)
02424 cout << " THERE ARE " << allrecparticles.size()
02425 << " RECONSTRUCTED 4-VECTORS" << endl;
02426
02427 jetAlgo_.Clear();
02428 const vector< PFJetAlgorithm::Jet >& PFjets
02429 = jetAlgo_.FindJets( &allrecparticles );
02430
02431 if (tauBenchmarkDebug_)
02432 cout << PFjets.size() << " PF Jets found" << endl;
02433 double JetPFETmax = 0.0;
02434 for ( unsigned i = 0; i < PFjets.size(); i++) {
02435 TLorentzVector jetmom = PFjets[i].GetMomentum();
02436 double jetpf_pt = sqrt(jetmom.Px()*jetmom.Px()+jetmom.Py()*jetmom.Py());
02437 double jetpf_et = jetmom.Et();
02438
02439 EventColin::Jet jet;
02440 jet.eta = jetmom.Eta();
02441 jet.phi = jetmom.Phi();
02442 jet.et = jetmom.Et();
02443 jet.e = jetmom.E();
02444
02445 if(outEvent_) outEvent_->addJetPF( jet );
02446
02447 if (tauBenchmarkDebug_) {
02448 cout <<" Rec jet : "<< PFjets[i] <<endl;
02449 cout << jetmom.Px() << " " << jetmom.Py() << " "
02450 << jetmom.Pz() << " " << jetmom.E()
02451 << " PT=" << jetpf_pt << " eta="<< jetmom.Eta()
02452 << " Phi=" << jetmom.Phi() << endl;
02453 cout << "------------------------------------------------" << endl;
02454 }
02455
02456 if (jetpf_et >= JetPFETmax)
02457 JetPFETmax = jetpf_et;
02458 }
02459
02460
02461
02462 double deltaEtEHT = JetEHTETmax - partTOTMC.Et();
02463 h_deltaETvisible_MCEHT_->Fill(deltaEtEHT);
02464
02465 double deltaEt = JetPFETmax - partTOTMC.Et();
02466 h_deltaETvisible_MCPF_ ->Fill(deltaEt);
02467
02468 if (verbosity_ == VERBOSE ) {
02469 cout << "tau benchmark E_T(PF) - E_T(true) = " << deltaEt << endl;
02470 }
02471
02472 return deltaEt/partTOTMC.Et();
02473 }
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487
02488
02489
02490
02491
02492
02493
02494
02495
02496
02497
02498
02499
02500
02501
02502
02503
02504
02505
02506
02507
02508
02509
02510
02511
02512
02513
02514
02515
02516
02517
02518
02519
02520
02521
02522
02523
02524
02525 string PFRootEventManager::expand(const string& oldString) const {
02526
02527 string newString = oldString;
02528
02529 string dollar = "$";
02530 string slash = "/";
02531
02532
02533 int dollarPos = newString.find(dollar,0);
02534 if( dollarPos == -1 ) return oldString;
02535
02536 int lengh = newString.find(slash,0) - newString.find(dollar,0) + 1;
02537 string env_variable =
02538 newString.substr( ( newString.find(dollar,0) + 1 ), lengh -2);
02539
02540 int begin = env_variable.find_first_of("{");
02541 int end = env_variable.find_last_of("}");
02542
02543
02544
02545
02546 env_variable = env_variable.substr( begin+1, end-1 );
02547
02548
02549
02550
02551 char* directory = getenv( env_variable.c_str() );
02552
02553 if(!directory) {
02554 cerr<<"please define environment variable $"<<env_variable<<endl;
02555 delete this;
02556 exit(1);
02557 }
02558 string sdir = directory;
02559 sdir += "/";
02560
02561 newString.replace( 0, lengh , sdir);
02562
02563 if (verbosity_ == VERBOSE ) {
02564 cout << "expand " <<oldString<<" to "<< newString << endl;
02565 }
02566
02567 return newString;
02568 }
02569
02570 void PFRootEventManager::print(ostream& out,int maxNLines ) const {
02571
02572 if(!out) return;
02573
02574
02575
02576
02577 std::vector< std::list <simMatch> > candSimMatchTrack;
02578 std::vector< std::list <simMatch> > candSimMatchEcal;
02579 if( printMCTruthMatching_){
02580 mcTruthMatching( std::cout,
02581 *pfCandidates_,
02582 candSimMatchTrack,
02583 candSimMatchEcal);
02584 }
02585
02586
02587 if( printRecHits_ ) {
02588 out<<"ECAL RecHits =============================================="<<endl;
02589 for(unsigned i=0; i<rechitsECAL_.size(); i++) {
02590 string seedstatus = " ";
02591 if(clusterAlgoECAL_.isSeed(i) )
02592 seedstatus = "SEED";
02593 printRecHit(rechitsECAL_[i], seedstatus.c_str(), out );
02594 }
02595 out<<endl;
02596 out<<"HCAL RecHits =============================================="<<endl;
02597 for(unsigned i=0; i<rechitsHCAL_.size(); i++) {
02598 string seedstatus = " ";
02599 if(clusterAlgoHCAL_.isSeed(i) )
02600 seedstatus = "SEED";
02601 printRecHit(rechitsHCAL_[i], seedstatus.c_str(), out);
02602 }
02603 out<<endl;
02604 out<<"PS RecHits ================================================"<<endl;
02605 for(unsigned i=0; i<rechitsPS_.size(); i++) {
02606 string seedstatus = " ";
02607 if(clusterAlgoPS_.isSeed(i) )
02608 seedstatus = "SEED";
02609 printRecHit(rechitsPS_[i], seedstatus.c_str(), out);
02610 }
02611 out<<endl;
02612 }
02613 if( printClusters_ ) {
02614 out<<"ECAL Clusters ============================================="<<endl;
02615 for(unsigned i=0; i<clustersECAL_->size(); i++) {
02616 printCluster((*clustersECAL_)[i], out);
02617 }
02618 out<<endl;
02619 out<<"HCAL Clusters ============================================="<<endl;
02620 for(unsigned i=0; i<clustersHCAL_->size(); i++) {
02621 printCluster((*clustersHCAL_)[i], out);
02622 }
02623 out<<endl;
02624 out<<"PS Clusters ============================================="<<endl;
02625 for(unsigned i=0; i<clustersPS_->size(); i++) {
02626 printCluster((*clustersPS_)[i], out);
02627 }
02628 out<<endl;
02629 }
02630 bool printTracks = true;
02631 if( printTracks) {
02632
02633 }
02634 if( printPFBlocks_ ) {
02635 out<<"Particle Flow Blocks ======================================"<<endl;
02636 for(unsigned i=0; i<pfBlocks_->size(); i++) {
02637 out<<i<<" "<<(*pfBlocks_)[i]<<endl;
02638 }
02639 out<<endl;
02640 }
02641 if(printPFCandidates_) {
02642 out<<"Particle Flow Candidates =================================="<<endl;
02643 for(unsigned i=0; i<pfCandidates_->size(); i++) {
02644 out<<i<<" " <<(*pfCandidates_)[i]<<endl;
02645 }
02646 out<<endl;
02647
02648
02649
02650 if(printMCTruthMatching_){
02651 cout<<"MCTruthMatching Results"<<endl;
02652 for(unsigned icand=0; icand<pfCandidates_->size();
02653 icand++) {
02654 out <<icand<<" " <<(*pfCandidates_)[icand]<<endl;
02655 out << "is matching:" << endl;
02656
02657
02658 ITM it_t = candSimMatchTrack[icand].begin();
02659 ITM itend_t = candSimMatchTrack[icand].end();
02660 for(;it_t!=itend_t;++it_t){
02661 unsigned simid = it_t->second;
02662 out << "\tSimParticle " << trueParticles_[simid]
02663 <<endl;
02664 out << "\t\tthrough Track matching pTrectrack="
02665 << it_t->first << " GeV" << endl;
02666 }
02667
02668 ITM it_e = candSimMatchEcal[icand].begin();
02669 ITM itend_e = candSimMatchEcal[icand].end();
02670 for(;it_e!=itend_e;++it_e){
02671 unsigned simid = it_e->second;
02672 out << "\tSimParticle " << trueParticles_[simid]
02673 << endl;
02674 out << "\t\tsimparticle contributing to a total of "
02675 << it_e->first
02676 << " GeV of its ECAL cluster"
02677 << endl;
02678 }
02679 cout<<"________________"<<endl;
02680 }
02681 }
02682 }
02683 if(printPFJets_) {
02684 out<<"Jets ====================================================="<<endl;
02685 out<<"Particle Flow: "<<endl;
02686 for(unsigned i=0; i<pfJets_.size(); i++) {
02687 out<<i<<pfJets_[i].print()<<endl;
02688 }
02689 out<<endl;
02690 out<<"Generated: "<<endl;
02691 for(unsigned i=0; i<genJets_.size(); i++) {
02692 out<<i<<genJets_[i].print()<<endl;
02693
02694 }
02695 out<<endl;
02696 out<<"Calo: "<<endl;
02697 for(unsigned i=0; i<caloJets_.size(); i++) {
02698 out<<"pt = "<<caloJets_[i].pt()<<endl;
02699 }
02700 out<<endl;
02701 }
02702 if( printSimParticles_ ) {
02703 out<<"Sim Particles ==========================================="<<endl;
02704
02705 for(unsigned i=0; i<trueParticles_.size(); i++) {
02706 if( trackInsideGCut( trueParticles_[i]) )
02707 out<<"\t"<<trueParticles_[i]<<endl;
02708 }
02709
02710
02711
02712 if(printMCTruthMatching_) {
02713 cout<<"MCTruthMatching Results"<<endl;
02714 for ( unsigned i=0; i < trueParticles_.size(); i++) {
02715 cout << "==== Particle Simulated " << i << endl;
02716 const reco::PFSimParticle& ptc = trueParticles_[i];
02717 out <<i<<" "<<trueParticles_[i]<<endl;
02718
02719 if(!ptc.daughterIds().empty()){
02720 cout << "Look at the desintegration products" << endl;
02721 cout << endl;
02722 continue;
02723 }
02724
02725
02726 if(ptc.rectrackId() != 99999){
02727 cout << "matching pfCandidate (trough tracking): " << endl;
02728 for( unsigned icand=0; icand<pfCandidates_->size()
02729 ; icand++ )
02730 {
02731 ITM it = candSimMatchTrack[icand].begin();
02732 ITM itend = candSimMatchTrack[icand].end();
02733 for(;it!=itend;++it)
02734 if( i == it->second ){
02735 out<<icand<<" "<<(*pfCandidates_)[icand]<<endl;
02736 cout << endl;
02737 }
02738 }
02739 }
02740
02741
02742 vector<unsigned> rechitSimIDs
02743 = ptc.recHitContrib();
02744 vector<double> rechitSimFrac
02745 = ptc.recHitContribFrac();
02746
02747 if( !rechitSimIDs.size() ) continue;
02748
02749 cout << "matching pfCandidate (through ECAL): " << endl;
02750
02751
02752 double totalEcalE = 0.0;
02753 for(unsigned irh=0; irh<rechitsECAL_.size();++irh)
02754 for ( unsigned isimrh=0; isimrh < rechitSimIDs.size();
02755 isimrh++ )
02756 if(rechitSimIDs[isimrh] == rechitsECAL_[irh].detId())
02757 totalEcalE += (rechitsECAL_[irh].energy()*rechitSimFrac[isimrh]/100.0);
02758 cout << "For info, this particle deposits E=" << totalEcalE
02759 << "(GeV) in the ECAL" << endl;
02760
02761 for( unsigned icand=0; icand<pfCandidates_->size()
02762 ; icand++ )
02763 {
02764 ITM it = candSimMatchEcal[icand].begin();
02765 ITM itend = candSimMatchEcal[icand].end();
02766 for(;it!=itend;++it)
02767 if( i == it->second )
02768 out<<icand<<" "<<it->first<<"GeV "<<(*pfCandidates_)[icand]<<endl;
02769 }
02770 cout << endl;
02771 }
02772 }
02773
02774 }
02775
02776
02777 if ( printGenParticles_ ) {
02778 printGenParticles(out,maxNLines);
02779 }
02780 }
02781
02782
02783 void
02784 PFRootEventManager::printGenParticles(std::ostream& out,
02785 int maxNLines) const {
02786
02787
02788 const HepMC::GenEvent* myGenEvent = MCTruth_.GetEvent();
02789 if(!myGenEvent) return;
02790
02791 out<<"GenParticles ==========================================="<<endl;
02792
02793 std::cout << "Id Gen Name eta phi pT E Vtx1 "
02794 << " x y z "
02795 << "Moth Vtx2 eta phi R Z Da1 Da2 Ecal?"
02796 << std::endl;
02797
02798 int nLines = 0;
02799 for ( HepMC::GenEvent::particle_const_iterator
02800 piter = myGenEvent->particles_begin();
02801 piter != myGenEvent->particles_end();
02802 ++piter ) {
02803
02804 if( nLines == maxNLines) break;
02805 nLines++;
02806
02807 HepMC::GenParticle* p = *piter;
02808
02809 int partId = p->pdg_id();
02810
02811
02812
02813
02814
02815
02816
02817
02818
02819
02820
02821
02822
02823
02824
02825
02826
02827
02828
02829
02830
02831
02832
02833
02834
02835
02836
02837
02838
02839
02840
02841
02842
02843
02844
02845
02846
02847
02848
02849
02850
02851
02852
02853
02854
02855
02856
02857
02858
02859
02860
02861
02862
02863
02864
02865
02866
02867
02868
02869
02870
02871
02872
02873
02874
02875
02876
02877
02878
02879
02880
02881
02882
02883
02884
02885
02886
02887
02888
02889
02890
02891
02892
02893
02894
02895
02896
02897
02898
02899
02900
02901
02902
02903
02904
02905
02906
02907
02908
02909
02910
02911
02912
02913
02914
02915
02916 std::string latexString;
02917 std::string name = getGenParticleName(partId,latexString);
02918
02919 math::XYZTLorentzVector momentum1(p->momentum().px(),
02920 p->momentum().py(),
02921 p->momentum().pz(),
02922 p->momentum().e() );
02923
02924 int vertexId1 = 0;
02925
02926 if ( !p->production_vertex() && p->pdg_id() == 2212 ) continue;
02927
02928 math::XYZVector vertex1;
02929 vertexId1 = -1;
02930
02931 if(p->production_vertex() ) {
02932 vertex1.SetCoordinates( p->production_vertex()->position().x()/10.,
02933 p->production_vertex()->position().y()/10.,
02934 p->production_vertex()->position().z()/10. );
02935 vertexId1 = p->production_vertex()->barcode();
02936 }
02937
02938 out.setf(std::ios::fixed, std::ios::floatfield);
02939 out.setf(std::ios::right, std::ios::adjustfield);
02940
02941 out << std::setw(4) << p->barcode() << " "
02942 << name;
02943
02944 for(unsigned int k=0;k<11-name.length() && k<12; k++) out << " ";
02945
02946 double eta = momentum1.eta();
02947 if ( eta > +10. ) eta = +10.;
02948 if ( eta < -10. ) eta = -10.;
02949
02950 out << std::setw(6) << std::setprecision(2) << eta << " "
02951 << std::setw(6) << std::setprecision(2) << momentum1.phi() << " "
02952 << std::setw(7) << std::setprecision(2) << momentum1.pt() << " "
02953 << std::setw(7) << std::setprecision(2) << momentum1.e() << " "
02954 << std::setw(4) << vertexId1 << " "
02955 << std::setw(6) << std::setprecision(1) << vertex1.x() << " "
02956 << std::setw(6) << std::setprecision(1) << vertex1.y() << " "
02957 << std::setw(6) << std::setprecision(1) << vertex1.z() << " ";
02958
02959
02960 if( p->production_vertex() ) {
02961 if ( p->production_vertex()->particles_in_size() ) {
02962 const HepMC::GenParticle* mother =
02963 *(p->production_vertex()->particles_in_const_begin());
02964
02965 out << std::setw(4) << mother->barcode() << " ";
02966 }
02967 else
02968 out << " " ;
02969 }
02970
02971 if ( p->end_vertex() ) {
02972 math::XYZTLorentzVector vertex2(p->end_vertex()->position().x()/10.,
02973 p->end_vertex()->position().y()/10.,
02974 p->end_vertex()->position().z()/10.,
02975 p->end_vertex()->position().t()/10.);
02976 int vertexId2 = p->end_vertex()->barcode();
02977
02978 std::vector<const HepMC::GenParticle*> children;
02979 HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
02980 p->end_vertex()->particles_out_const_begin();
02981 HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
02982 p->end_vertex()->particles_out_const_end();
02983 for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
02984 children.push_back(*firstDaughterIt);
02985 }
02986
02987 out << std::setw(4) << vertexId2 << " "
02988 << std::setw(6) << std::setprecision(2) << vertex2.eta() << " "
02989 << std::setw(6) << std::setprecision(2) << vertex2.phi() << " "
02990 << std::setw(5) << std::setprecision(1) << vertex2.pt() << " "
02991 << std::setw(6) << std::setprecision(1) << vertex2.z() << " ";
02992
02993 for ( unsigned id=0; id<children.size(); ++id )
02994 out << std::setw(4) << children[id]->barcode() << " ";
02995 }
02996 out << std::endl;
02997 }
02998 }
02999
03000
03001 void PFRootEventManager::printRecHit(const reco::PFRecHit& rh,
03002 const char* seedstatus,
03003 ostream& out) const {
03004
03005 if(!out) return;
03006
03007 double eta = rh.position().Eta();
03008 double phi = rh.position().Phi();
03009
03010
03011 TCutG* cutg = (TCutG*) gROOT->FindObject("CUTG");
03012 if( !cutg || cutg->IsInside( eta, phi ) )
03013 out<<seedstatus<<" "<<rh<<endl;;
03014 }
03015
03016 void PFRootEventManager::printCluster(const reco::PFCluster& cluster,
03017 ostream& out ) const {
03018
03019 if(!out) return;
03020
03021 double eta = cluster.position().Eta();
03022 double phi = cluster.position().Phi();
03023
03024 TCutG* cutg = (TCutG*) gROOT->FindObject("CUTG");
03025 if( !cutg || cutg->IsInside( eta, phi ) )
03026 out<<cluster<<endl;
03027 }
03028
03029
03030
03031
03032
03033 bool PFRootEventManager::trackInsideGCut( const reco::PFTrack& track ) const {
03034
03035 TCutG* cutg = (TCutG*) gROOT->FindObject("CUTG");
03036 if(!cutg) return true;
03037
03038 const vector< reco::PFTrajectoryPoint >& points = track.trajectoryPoints();
03039
03040 for( unsigned i=0; i<points.size(); i++) {
03041 if( ! points[i].isValid() ) continue;
03042
03043 const math::XYZPoint& pos = points[i].position();
03044 if( cutg->IsInside( pos.Eta(), pos.Phi() ) ) return true;
03045 }
03046
03047
03048 return false;
03049 }
03050
03051
03052 void
03053 PFRootEventManager::fillRecHitMask( vector<bool>& mask,
03054 const reco::PFRecHitCollection& rechits )
03055 const {
03056
03057 TCutG* cutg = (TCutG*) gROOT->FindObject("CUTG");
03058 if(!cutg) return;
03059
03060 mask.clear();
03061 mask.reserve( rechits.size() );
03062 for(unsigned i=0; i<rechits.size(); i++) {
03063
03064 double eta = rechits[i].position().Eta();
03065 double phi = rechits[i].position().Phi();
03066
03067 if( cutg->IsInside( eta, phi ) )
03068 mask.push_back( true );
03069 else
03070 mask.push_back( false );
03071 }
03072 }
03073
03074 void
03075 PFRootEventManager::fillClusterMask(vector<bool>& mask,
03076 const reco::PFClusterCollection& clusters)
03077 const {
03078
03079 TCutG* cutg = (TCutG*) gROOT->FindObject("CUTG");
03080 if(!cutg) return;
03081
03082 mask.clear();
03083 mask.reserve( clusters.size() );
03084 for(unsigned i=0; i<clusters.size(); i++) {
03085
03086 double eta = clusters[i].position().Eta();
03087 double phi = clusters[i].position().Phi();
03088
03089 if( cutg->IsInside( eta, phi ) )
03090 mask.push_back( true );
03091 else
03092 mask.push_back( false );
03093 }
03094 }
03095
03096 void
03097 PFRootEventManager::fillTrackMask(vector<bool>& mask,
03098 const reco::PFRecTrackCollection& tracks)
03099 const {
03100
03101 TCutG* cutg = (TCutG*) gROOT->FindObject("CUTG");
03102 if(!cutg) return;
03103
03104 mask.clear();
03105 mask.reserve( tracks.size() );
03106 for(unsigned i=0; i<tracks.size(); i++) {
03107 if( trackInsideGCut( tracks[i] ) )
03108 mask.push_back( true );
03109 else
03110 mask.push_back( false );
03111 }
03112 }
03113
03114 void
03115 PFRootEventManager::fillTrackMask(vector<bool>& mask,
03116 const reco::GsfPFRecTrackCollection& tracks)
03117 const {
03118
03119 TCutG* cutg = (TCutG*) gROOT->FindObject("CUTG");
03120 if(!cutg) return;
03121
03122 mask.clear();
03123 mask.reserve( tracks.size() );
03124 for(unsigned i=0; i<tracks.size(); i++) {
03125 if( trackInsideGCut( tracks[i] ) )
03126 mask.push_back( true );
03127 else
03128 mask.push_back( false );
03129 }
03130 }
03131
03132
03133 const reco::PFSimParticle&
03134 PFRootEventManager::closestParticle( reco::PFTrajectoryPoint::LayerType layer,
03135 double eta, double phi,
03136 double& peta, double& pphi, double& pe)
03137 const {
03138
03139
03140 if( trueParticles_.empty() ) {
03141 string err = "PFRootEventManager::closestParticle : ";
03142 err += "vector of PFSimParticles is empty";
03143 throw std::length_error( err.c_str() );
03144 }
03145
03146 double mindist2 = 99999999;
03147 unsigned iClosest=0;
03148 for(unsigned i=0; i<trueParticles_.size(); i++) {
03149
03150 const reco::PFSimParticle& ptc = trueParticles_[i];
03151
03152
03153
03154 if( layer >= reco::PFTrajectoryPoint::NLayers ||
03155 ptc.nTrajectoryMeasurements() + layer >=
03156 ptc.nTrajectoryPoints() ) {
03157 continue;
03158 }
03159
03160 const reco::PFTrajectoryPoint& tp
03161 = ptc.extrapolatedPoint( layer );
03162
03163 peta = tp.position().Eta();
03164 pphi = tp.position().Phi();
03165 pe = tp.momentum().E();
03166
03167 double deta = peta - eta;
03168 double dphi = pphi - phi;
03169
03170 double dist2 = deta*deta + dphi*dphi;
03171
03172 if(dist2<mindist2) {
03173 mindist2 = dist2;
03174 iClosest = i;
03175 }
03176 }
03177
03178 return trueParticles_[iClosest];
03179 }
03180
03181
03182
03183
03184 void
03185 PFRootEventManager::readCMSSWJets() {
03186
03187 cout<<"CMSSW Gen jets : size = " << genJetsCMSSW_.size() << endl;
03188 for ( unsigned i = 0; i < genJetsCMSSW_.size(); i++) {
03189 cout<<"Gen jet Et : " << genJetsCMSSW_[i].et() << endl;
03190 }
03191 cout<<"CMSSW PF jets : size = " << pfJetsCMSSW_.size() << endl;
03192 for ( unsigned i = 0; i < pfJetsCMSSW_.size(); i++) {
03193 cout<<"PF jet Et : " << pfJetsCMSSW_[i].et() << endl;
03194 }
03195 cout<<"CMSSW Calo jets : size = " << caloJetsCMSSW_.size() << endl;
03196 for ( unsigned i = 0; i < caloJetsCMSSW_.size(); i++) {
03197 cout<<"Calo jet Et : " << caloJetsCMSSW_[i].et() << endl;
03198 }
03199 }
03200
03201 std::string PFRootEventManager::getGenParticleName(int partId, std::string &latexString) const
03202 {
03203 std::string name;
03204 switch(partId) {
03205 case 1: { name = "d";latexString="d"; break; }
03206 case 2: { name = "u";latexString="u";break; }
03207 case 3: { name = "s";latexString="s" ;break; }
03208 case 4: { name = "c";latexString="c" ; break; }
03209 case 5: { name = "b";latexString="b" ; break; }
03210 case 6: { name = "t";latexString="t" ; break; }
03211 case -1: { name = "~d";latexString="#bar{d}" ; break; }
03212 case -2: { name = "~u";latexString="#bar{u}" ; break; }
03213 case -3: { name = "~s";latexString="#bar{s}" ; break; }
03214 case -4: { name = "~c";latexString="#bar{c}" ; break; }
03215 case -5: { name = "~b";latexString="#bar{b}" ; break; }
03216 case -6: { name = "~t";latexString="#bar{t}" ; break; }
03217 case 11: { name = "e-";latexString=name ; break; }
03218 case -11: { name = "e+";latexString=name ; break; }
03219 case 12: { name = "nu_e";latexString="#nu_{e}" ; break; }
03220 case -12: { name = "~nu_e";latexString="#bar{#nu}_{e}" ; break; }
03221 case 13: { name = "mu-";latexString="#mu-" ; break; }
03222 case -13: { name = "mu+";latexString="#mu+" ; break; }
03223 case 14: { name = "nu_mu";latexString="#nu_{mu}" ; break; }
03224 case -14: { name = "~nu_mu";latexString="#bar{#nu}_{#mu}"; break; }
03225 case 15: { name = "tau-";latexString="#tau^{-}" ; break; }
03226 case -15: { name = "tau+";latexString="#tau^{+}" ; break; }
03227 case 16: { name = "nu_tau";latexString="#nu_{#tau}" ; break; }
03228 case -16: { name = "~nu_tau";latexString="#bar{#nu}_{#tau}"; break; }
03229 case 21: { name = "gluon";latexString= name; break; }
03230 case 22: { name = "gamma";latexString= "#gamma"; break; }
03231 case 23: { name = "Z0";latexString="Z^{0}" ; break; }
03232 case 24: { name = "W+";latexString="W^{+}" ; break; }
03233 case 25: { name = "H0";latexString=name ; break; }
03234 case -24: { name = "W-";latexString="W^{-}" ; break; }
03235 case 111: { name = "pi0";latexString="#pi^{0}" ; break; }
03236 case 113: { name = "rho0";latexString="#rho^{0}" ; break; }
03237 case 223: { name = "omega";latexString="#omega" ; break; }
03238 case 333: { name = "phi";latexString= "#phi"; break; }
03239 case 443: { name = "J/psi";latexString="J/#psi" ; break; }
03240 case 553: { name = "Upsilon";latexString="#Upsilon" ; break; }
03241 case 130: { name = "K0L";latexString=name ; break; }
03242 case 211: { name = "pi+";latexString="#pi^{+}" ; break; }
03243 case -211: { name = "pi-";latexString="#pi^{-}" ; break; }
03244 case 213: { name = "rho+";latexString="#rho^{+}" ; break; }
03245 case -213: { name = "rho-";latexString="#rho^{-}" ; break; }
03246 case 221: { name = "eta";latexString="#eta" ; break; }
03247 case 331: { name = "eta'";latexString="#eta'" ; break; }
03248 case 441: { name = "etac";latexString="#eta_{c}" ; break; }
03249 case 551: { name = "etab";latexString= "#eta_{b}"; break; }
03250 case 310: { name = "K0S";latexString=name ; break; }
03251 case 311: { name = "K0";latexString="K^{0}" ; break; }
03252 case -311: { name = "Kbar0";latexString="#bar{#Kappa}^{0}" ; break; }
03253 case 321: { name = "K+";latexString= "K^{+}"; break; }
03254 case -321: { name = "K-";latexString="K^{-}"; break; }
03255 case 411: { name = "D+";latexString="D^{+}" ; break; }
03256 case -411: { name = "D-";latexString="D^{-}"; break; }
03257 case 421: { name = "D0";latexString=name ; break; }
03258 case 431: { name = "Ds_+";latexString="Ds_{+}" ; break; }
03259 case -431: { name = "Ds_-";latexString="Ds_{-}" ; break; }
03260 case 511: { name = "B0";latexString= name; break; }
03261 case 521: { name = "B+";latexString="B^{+}" ; break; }
03262 case -521: { name = "B-";latexString="B^{-}" ; break; }
03263 case 531: { name = "Bs_0";latexString="Bs_{0}" ; break; }
03264 case 541: { name = "Bc_+";latexString="Bc_{+}" ; break; }
03265 case -541: { name = "Bc_+";latexString="Bc_{+}" ; break; }
03266 case 313: { name = "K*0";latexString="K^{*0}" ; break; }
03267 case -313: { name = "K*bar0";latexString="#bar{K}^{*0}" ; break; }
03268 case 323: { name = "K*+";latexString="#K^{*+}"; break; }
03269 case -323: { name = "K*-";latexString="#K^{*-}" ; break; }
03270 case 413: { name = "D*+";latexString= "D^{*+}"; break; }
03271 case -413: { name = "D*-";latexString= "D^{*-}" ; break; }
03272 case 423: { name = "D*0";latexString="D^{*0}" ; break; }
03273 case 513: { name = "B*0";latexString="B^{*0}" ; break; }
03274 case 523: { name = "B*+";latexString="B^{*+}" ; break; }
03275 case -523: { name = "B*-";latexString="B^{*-}" ; break; }
03276 case 533: { name = "B*_s0";latexString="B^{*}_{s0}" ; break; }
03277 case 543: { name = "B*_c+";latexString= "B^{*}_{c+}"; break; }
03278 case -543: { name = "B*_c-";latexString= "B^{*}_{c-}"; break; }
03279 case 1114: { name = "Delta-";latexString="#Delta^{-}" ; break; }
03280 case -1114: { name = "Deltabar+";latexString="#bar{#Delta}^{+}" ; break; }
03281 case -2112: { name = "nbar0";latexString="{bar}n^{0}" ; break; }
03282 case 2112: { name = "n"; latexString=name ;break;}
03283 case 2114: { name = "Delta0"; latexString="#Delta^{0}" ;break; }
03284 case -2114: { name = "Deltabar0"; latexString="#bar{#Delta}^{0}" ;break; }
03285 case 3122: { name = "Lambda0";latexString= "#Lambda^{0}"; break; }
03286 case -3122: { name = "Lambdabar0";latexString="#bar{#Lambda}^{0}" ; break; }
03287 case 3112: { name = "Sigma-"; latexString="#Sigma" ;break; }
03288 case -3112: { name = "Sigmabar+"; latexString="#bar{#Sigma}^{+}" ;break; }
03289 case 3212: { name = "Sigma0";latexString="#Sigma^{0}" ; break; }
03290 case -3212: { name = "Sigmabar0";latexString="#bar{#Sigma}^{0}" ; break; }
03291 case 3214: { name = "Sigma*0"; latexString="#Sigma^{*0}" ;break; }
03292 case -3214: { name = "Sigma*bar0";latexString="#bar{#Sigma}^{*0}" ; break; }
03293 case 3222: { name = "Sigma+"; latexString="#Sigma^{+}" ;break; }
03294 case -3222: { name = "Sigmabar-"; latexString="#bar{#Sigma}^{-}";break; }
03295 case 2212: { name = "p";latexString=name ; break; }
03296 case -2212: { name = "~p";latexString="#bar{p}" ; break; }
03297 case -2214: { name = "Delta-";latexString="#Delta^{-}" ; break; }
03298 case 2214: { name = "Delta+";latexString="#Delta^{+}" ; break; }
03299 case -2224: { name = "Deltabar--"; latexString="#bar{#Delta}^{--}" ;break; }
03300 case 2224: { name = "Delta++"; latexString= "#Delta^{++}";break; }
03301 default:
03302 {
03303 name = "unknown";
03304 cout << "Unknown code : " << partId << endl;
03305 break;
03306 }
03307
03308
03309 }
03310 return name;
03311
03312 }
03313
03314
03315 void PFRootEventManager::mcTruthMatching( std::ostream& out,
03316 const reco::PFCandidateCollection& candidates,
03317 std::vector< std::list <simMatch> >& candSimMatchTrack,
03318 std::vector< std::list <simMatch> >& candSimMatchEcal) const
03319 {
03320
03321 if(!out) return;
03322 out << endl;
03323 out << "Running Monte Carlo Truth Matching Tool" << endl;
03324 out << endl;
03325
03326
03327 candSimMatchTrack.resize(candidates.size());
03328 candSimMatchEcal.resize(candidates.size());
03329
03330 for(unsigned i=0; i<candidates.size(); i++) {
03331 const reco::PFCandidate& pfCand = candidates[i];
03332
03333
03334 if (verbosity_ == VERBOSE ) {
03335 out <<i<<" " <<(*pfCandidates_)[i]<<endl;
03336 out << "is matching:" << endl;
03337 }
03338
03339 PFCandidate::ElementsInBlocks eleInBlocks
03340 = pfCand.elementsInBlocks();
03341
03342 for(unsigned iel=0; iel<eleInBlocks.size(); ++iel) {
03343 PFBlockRef blockRef = eleInBlocks[iel].first;
03344 unsigned indexInBlock = eleInBlocks[iel].second;
03345
03346
03347 const reco::PFBlock& blockh
03348 = *blockRef;
03349 const edm::OwnVector< reco::PFBlockElement >&
03350 elements_h = blockh.elements();
03351
03352 reco::PFBlockElement::Type type
03353 = elements_h[ indexInBlock ].type();
03354
03355
03356
03357
03358 if(type == reco::PFBlockElement::TRACK){
03359 const reco::PFRecTrackRef trackref
03360 = elements_h[ indexInBlock ].trackRefPF();
03361 assert( !trackref.isNull() );
03362 const reco::PFRecTrack& track = *trackref;
03363 const reco::TrackRef trkREF = track.trackRef();
03364 unsigned rtrkID = track.trackId();
03365
03366
03367 for ( unsigned isim=0; isim < trueParticles_.size(); isim++) {
03368 const reco::PFSimParticle& ptc = trueParticles_[isim];
03369 unsigned trackIDM = ptc.rectrackId();
03370 if(trackIDM != 99999
03371 && trackIDM == rtrkID){
03372
03373 if (verbosity_ == VERBOSE )
03374 out << "\tSimParticle " << isim
03375 << " through Track matching pTrectrack="
03376 << trkREF->pt() << " GeV" << endl;
03377
03378
03379 std::pair<double, unsigned> simtrackmatch
03380 = make_pair(trkREF->pt(),trackIDM);
03381 candSimMatchTrack[i].push_back(simtrackmatch);
03382 }
03383 }
03384
03385 }
03386
03387
03388 if(type == reco::PFBlockElement::ECAL)
03389 {
03390 const reco::PFClusterRef clusterref
03391 = elements_h[ indexInBlock ].clusterRef();
03392 assert( !clusterref.isNull() );
03393 const reco::PFCluster& cluster = *clusterref;
03394
03395 const std::vector< reco::PFRecHitFraction >&
03396 fracs = cluster.recHitFractions();
03397
03398
03399
03400 vector<unsigned> simpID;
03401 vector<double> simpEC(trueParticles_.size(),0.0);
03402 vector<unsigned> simpCN(trueParticles_.size(),0);
03403 for(unsigned int rhit = 0; rhit < fracs.size(); ++rhit){
03404
03405 const reco::PFRecHitRef& rh = fracs[rhit].recHitRef();
03406 if(rh.isNull()) continue;
03407 const reco::PFRecHit& rechit_cluster = *rh;
03408
03409
03410
03411
03412
03413
03414 for ( unsigned isim=0; isim < trueParticles_.size(); isim++) {
03415 const reco::PFSimParticle& ptc = trueParticles_[isim];
03416
03417 vector<unsigned> rechitSimIDs
03418 = ptc.recHitContrib();
03419 vector<double> rechitSimFrac
03420 = ptc.recHitContribFrac();
03421
03422 if( !rechitSimIDs.size() ) continue;
03423
03424 for ( unsigned isimrh=0; isimrh < rechitSimIDs.size(); isimrh++) {
03425 if( rechitSimIDs[isimrh] == rechit_cluster.detId() ){
03426
03427 bool takenalready = false;
03428 for(unsigned iss = 0; iss < simpID.size(); ++iss)
03429 if(simpID[iss] == isim) takenalready = true;
03430 if(!takenalready) simpID.push_back(isim);
03431
03432 simpEC[isim] +=
03433 ((rechit_cluster.energy()*rechitSimFrac[isimrh])/100.0)
03434 *fracs[rhit].fraction();
03435
03436 simpCN[isim]++;
03437
03438
03439
03440 }
03441 }
03442 }
03443
03444 }
03445
03446 for(unsigned is=0; is < simpID.size(); ++is)
03447 {
03448 double frac_of_cluster
03449 = (simpEC[simpID[is]]/cluster.energy())*100.0;
03450
03451
03452 std::pair<double, unsigned> simecalmatch
03453 = make_pair(simpEC[simpID[is]],simpID[is]);
03454 candSimMatchEcal[i].push_back(simecalmatch);
03455
03456 if (verbosity_ == VERBOSE ) {
03457 out << "\tSimParticle " << simpID[is]
03458 << " through ECAL matching Epfcluster="
03459 << cluster.energy()
03460 << " GeV with N=" << simpCN[simpID[is]]
03461 << " rechits in common "
03462 << endl;
03463 out << "\t\tsimparticle contributing to a total of "
03464 << simpEC[simpID[is]]
03465 << " GeV of this cluster ("
03466 << frac_of_cluster << "%) "
03467 << endl;
03468 }
03469 }
03470 }
03471
03472 }
03473
03474 if (verbosity_ == VERBOSE )
03475 cout << "==============================================================="
03476 << endl;
03477
03478 }
03479
03480 if (verbosity_ == VERBOSE ){
03481
03482 cout << "=================================================================="
03483 << endl;
03484 cout << "SimParticles" << endl;
03485
03486
03487 for ( unsigned i=0; i < trueParticles_.size(); i++) {
03488 cout << "==== Particle Simulated " << i << endl;
03489 const reco::PFSimParticle& ptc = trueParticles_[i];
03490 out <<i<<" "<<trueParticles_[i]<<endl;
03491
03492 if(!ptc.daughterIds().empty()){
03493 cout << "Look at the desintegration products" << endl;
03494 cout << endl;
03495 continue;
03496 }
03497
03498
03499 if(ptc.rectrackId() != 99999){
03500 cout << "matching pfCandidate (trough tracking): " << endl;
03501 for( unsigned icand=0; icand<candidates.size(); icand++ )
03502 {
03503 ITM it = candSimMatchTrack[icand].begin();
03504 ITM itend = candSimMatchTrack[icand].end();
03505 for(;it!=itend;++it)
03506 if( i == it->second ){
03507 out<<icand<<" "<<(*pfCandidates_)[icand]<<endl;
03508 cout << endl;
03509 }
03510 }
03511 }
03512
03513
03514
03515 vector<unsigned> rechitSimIDs
03516 = ptc.recHitContrib();
03517 vector<double> rechitSimFrac
03518 = ptc.recHitContribFrac();
03519
03520 if( !rechitSimIDs.size() ) continue;
03521
03522 cout << "matching pfCandidate (through ECAL): " << endl;
03523
03524
03525 double totalEcalE = 0.0;
03526 for(unsigned irh=0; irh<rechitsECAL_.size();++irh)
03527 for ( unsigned isimrh=0; isimrh < rechitSimIDs.size();
03528 isimrh++ )
03529 if(rechitSimIDs[isimrh] == rechitsECAL_[irh].detId())
03530 totalEcalE += (rechitsECAL_[irh].energy()*rechitSimFrac[isimrh]/100.0);
03531 cout << "For info, this particle deposits E=" << totalEcalE
03532 << "(GeV) in the ECAL" << endl;
03533
03534 for( unsigned icand=0; icand<candidates.size(); icand++ )
03535 {
03536 ITM it = candSimMatchEcal[icand].begin();
03537 ITM itend = candSimMatchEcal[icand].end();
03538 for(;it!=itend;++it)
03539 if( i == it->second )
03540 out<<icand<<" "<<it->first<<"GeV "<<(*pfCandidates_)[icand]<<endl;
03541 }
03542 cout << endl;
03543 }
03544 }
03545
03546 }
03547