00001 #include "RecoParticleFlow/PFProducer/plugins/PFProducer.h"
00002 #include "RecoParticleFlow/PFProducer/interface/PFAlgo.h"
00003 #include "FWCore/Framework/interface/ESHandle.h"
00004 #include "FWCore/Framework/interface/EventSetup.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h"
00007 #include "RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibrationHF.h"
00008 #include "RecoParticleFlow/PFClusterTools/interface/PFSCEnergyCalibration.h"
00009 #include "CondFormats/PhysicsToolsObjects/interface/PerformancePayloadFromTFormula.h"
00010 #include "CondFormats/DataRecord/interface/PFCalibrationRcd.h"
00011 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00012 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00013 #include "DataFormats/ParticleFlowReco/interface/PFRecHitFwd.h"
00014 #include "DataFormats/ParticleFlowReco/interface/PFRecHit.h"
00015 #include "DataFormats/ParticleFlowReco/interface/PFBlockElementSuperClusterFwd.h"
00016 #include "DataFormats/ParticleFlowReco/interface/PFBlockElementSuperCluster.h"
00017 #include <sstream>
00018
00019 using namespace std;
00020
00021 using namespace boost;
00022
00023 using namespace edm;
00024
00025
00026
00027 PFProducer::PFProducer(const edm::ParameterSet& iConfig) {
00028
00029
00030 bool calibHF_use;
00031 std::vector<double> calibHF_eta_step;
00032 std::vector<double> calibHF_a_EMonly;
00033 std::vector<double> calibHF_b_HADonly;
00034 std::vector<double> calibHF_a_EMHAD;
00035 std::vector<double> calibHF_b_EMHAD;
00036 calibHF_use = iConfig.getParameter<bool>("calibHF_use");
00037 calibHF_eta_step = iConfig.getParameter<std::vector<double> >("calibHF_eta_step");
00038 calibHF_a_EMonly = iConfig.getParameter<std::vector<double> >("calibHF_a_EMonly");
00039 calibHF_b_HADonly = iConfig.getParameter<std::vector<double> >("calibHF_b_HADonly");
00040 calibHF_a_EMHAD = iConfig.getParameter<std::vector<double> >("calibHF_a_EMHAD");
00041 calibHF_b_EMHAD = iConfig.getParameter<std::vector<double> >("calibHF_b_EMHAD");
00042 boost::shared_ptr<PFEnergyCalibrationHF>
00043 thepfEnergyCalibrationHF ( new PFEnergyCalibrationHF(calibHF_use,calibHF_eta_step,calibHF_a_EMonly,calibHF_b_HADonly,calibHF_a_EMHAD,calibHF_b_EMHAD) ) ;
00044
00045
00046 inputTagBlocks_
00047 = iConfig.getParameter<InputTag>("blocks");
00048
00049
00050 inputTagMuons_
00051 = iConfig.getParameter<InputTag>("muons");
00052 postMuonCleaning_
00053 = iConfig.getParameter<bool>("postMuonCleaning");
00054
00055 usePFElectrons_
00056 = iConfig.getParameter<bool>("usePFElectrons");
00057
00058 usePFPhotons_
00059 = iConfig.getParameter<bool>("usePFPhotons");
00060
00061 useEGammaElectrons_
00062 = iConfig.getParameter<bool>("useEGammaElectrons");
00063
00064 if( useEGammaElectrons_) {
00065 inputTagEgammaElectrons_ = iConfig.getParameter<edm::InputTag>("egammaElectrons");
00066 }
00067
00068 electronOutputCol_
00069 = iConfig.getParameter<std::string>("pf_electron_output_col");
00070
00071 bool usePFSCEleCalib;
00072 std::vector<double> calibPFSCEle_Fbrem_barrel;
00073 std::vector<double> calibPFSCEle_Fbrem_endcap;
00074 std::vector<double> calibPFSCEle_barrel;
00075 std::vector<double> calibPFSCEle_endcap;
00076 usePFSCEleCalib = iConfig.getParameter<bool>("usePFSCEleCalib");
00077 calibPFSCEle_Fbrem_barrel = iConfig.getParameter<std::vector<double> >("calibPFSCEle_Fbrem_barrel");
00078 calibPFSCEle_Fbrem_endcap = iConfig.getParameter<std::vector<double> >("calibPFSCEle_Fbrem_endcap");
00079 calibPFSCEle_barrel = iConfig.getParameter<std::vector<double> >("calibPFSCEle_barrel");
00080 calibPFSCEle_endcap = iConfig.getParameter<std::vector<double> >("calibPFSCEle_endcap");
00081 boost::shared_ptr<PFSCEnergyCalibration>
00082 thePFSCEnergyCalibration ( new PFSCEnergyCalibration(calibPFSCEle_Fbrem_barrel,calibPFSCEle_Fbrem_endcap,
00083 calibPFSCEle_barrel,calibPFSCEle_endcap ));
00084
00085 bool useEGammaSupercluster = iConfig.getParameter<bool>("useEGammaSupercluster");
00086 double sumEtEcalIsoForEgammaSC_barrel = iConfig.getParameter<double>("sumEtEcalIsoForEgammaSC_barrel");
00087 double sumEtEcalIsoForEgammaSC_endcap = iConfig.getParameter<double>("sumEtEcalIsoForEgammaSC_endcap");
00088 double coneEcalIsoForEgammaSC = iConfig.getParameter<double>("coneEcalIsoForEgammaSC");
00089 double sumPtTrackIsoForEgammaSC_barrel = iConfig.getParameter<double>("sumPtTrackIsoForEgammaSC_barrel");
00090 double sumPtTrackIsoForEgammaSC_endcap = iConfig.getParameter<double>("sumPtTrackIsoForEgammaSC_endcap");
00091 double coneTrackIsoForEgammaSC = iConfig.getParameter<double>("coneTrackIsoForEgammaSC");
00092 unsigned int nTrackIsoForEgammaSC = iConfig.getParameter<unsigned int>("nTrackIsoForEgammaSC");
00093
00094
00095
00096 produces<reco::PFCandidateCollection>();
00097 produces<reco::PFCandidateCollection>("CleanedHF");
00098 produces<reco::PFCandidateCollection>("CleanedCosmicsMuons");
00099 produces<reco::PFCandidateCollection>("CleanedTrackerAndGlobalMuons");
00100 produces<reco::PFCandidateCollection>("CleanedFakeMuons");
00101 produces<reco::PFCandidateCollection>("CleanedPunchThroughMuons");
00102 produces<reco::PFCandidateCollection>("CleanedPunchThroughNeutralHadrons");
00103 produces<reco::PFCandidateCollection>("AddedMuonsAndHadrons");
00104
00105
00106 if (usePFElectrons_) {
00107 produces<reco::PFCandidateCollection>(electronOutputCol_);
00108 produces<reco::PFCandidateElectronExtraCollection>(electronExtraOutputCol_);
00109 }
00110
00111 double nSigmaECAL
00112 = iConfig.getParameter<double>("pf_nsigma_ECAL");
00113 double nSigmaHCAL
00114 = iConfig.getParameter<double>("pf_nsigma_HCAL");
00115
00116
00117 double mvaEleCut
00118 = iConfig.getParameter<double>("pf_electron_mvaCut");
00119
00120 string mvaWeightFileEleID
00121 = iConfig.getParameter<string>("pf_electronID_mvaWeightFile");
00122
00123 bool applyCrackCorrectionsForElectrons
00124 = iConfig.getParameter<bool>("pf_electronID_crackCorrection");
00125
00126 string path_mvaWeightFileEleID;
00127 if(usePFElectrons_)
00128 {
00129 path_mvaWeightFileEleID = edm::FileInPath ( mvaWeightFileEleID.c_str() ).fullPath();
00130 }
00131
00132
00133
00134 string path_mvaWeightFileConvID;
00135 string mvaWeightFileConvID;
00136 double mvaConvCut=-99.;
00137 if(usePFPhotons_)
00138 {
00139 mvaWeightFileConvID =iConfig.getParameter<string>("pf_convID_mvaWeightFile");
00140
00141 mvaConvCut = iConfig.getParameter<double>("pf_conv_mvaCut");
00142 path_mvaWeightFileConvID = edm::FileInPath ( mvaWeightFileConvID.c_str() ).fullPath();
00143 }
00144
00145
00146
00147
00148 bool rejectTracks_Bad
00149 = iConfig.getParameter<bool>("rejectTracks_Bad");
00150
00151 bool rejectTracks_Step45
00152 = iConfig.getParameter<bool>("rejectTracks_Step45");
00153
00154 bool usePFNuclearInteractions
00155 = iConfig.getParameter<bool>("usePFNuclearInteractions");
00156
00157 bool usePFConversions
00158 = iConfig.getParameter<bool>("usePFConversions");
00159
00160 bool usePFDecays
00161 = iConfig.getParameter<bool>("usePFDecays");
00162
00163 double dptRel_DispVtx
00164 = iConfig.getParameter<double>("dptRel_DispVtx");
00165
00166 edm::ParameterSet iCfgCandConnector
00167 = iConfig.getParameter<edm::ParameterSet>("iCfgCandConnector");
00168
00169
00170
00171
00172 useCalibrationsFromDB_
00173 = iConfig.getParameter<bool>("useCalibrationsFromDB");
00174
00175 boost::shared_ptr<PFEnergyCalibration>
00176 calibration( new PFEnergyCalibration() );
00177
00178 int algoType
00179 = iConfig.getParameter<unsigned>("algoType");
00180
00181 switch(algoType) {
00182 case 0:
00183 pfAlgo_.reset( new PFAlgo);
00184 break;
00185 default:
00186 assert(0);
00187 }
00188
00189 pfAlgo_->setParameters( nSigmaECAL,
00190 nSigmaHCAL,
00191 calibration,
00192 thepfEnergyCalibrationHF);
00193
00194
00195 pfAlgo_->setPFEleParameters(mvaEleCut,
00196 path_mvaWeightFileEleID,
00197 usePFElectrons_,
00198 thePFSCEnergyCalibration,
00199 calibration,
00200 sumEtEcalIsoForEgammaSC_barrel,
00201 sumEtEcalIsoForEgammaSC_endcap,
00202 coneEcalIsoForEgammaSC,
00203 sumPtTrackIsoForEgammaSC_barrel,
00204 sumPtTrackIsoForEgammaSC_endcap,
00205 nTrackIsoForEgammaSC,
00206 coneTrackIsoForEgammaSC,
00207 applyCrackCorrectionsForElectrons,
00208 usePFSCEleCalib,
00209 useEGammaElectrons_,
00210 useEGammaSupercluster);
00211
00212
00213
00214
00215 pfAlgo_->setPFPhotonParameters(usePFPhotons_,
00216 path_mvaWeightFileConvID,
00217 mvaConvCut,
00218 calibration);
00219
00220
00221
00222
00223 pfAlgo_->setDisplacedVerticesParameters(rejectTracks_Bad,
00224 rejectTracks_Step45,
00225 usePFNuclearInteractions,
00226 usePFConversions,
00227 usePFDecays,
00228 dptRel_DispVtx);
00229
00230 if (usePFNuclearInteractions)
00231 pfAlgo_->setCandConnectorParameters( iCfgCandConnector );
00232
00233
00234 std::vector<double> muonHCAL
00235 = iConfig.getParameter<std::vector<double> >("muon_HCAL");
00236 std::vector<double> muonECAL
00237 = iConfig.getParameter<std::vector<double> >("muon_ECAL");
00238 assert ( muonHCAL.size() == 2 && muonECAL.size() == 2 );
00239
00240
00241 double nSigmaTRACK
00242 = iConfig.getParameter<double>("nsigma_TRACK");
00243
00244 double ptError
00245 = iConfig.getParameter<double>("pt_Error");
00246
00247 std::vector<double> factors45
00248 = iConfig.getParameter<std::vector<double> >("factors_45");
00249 assert ( factors45.size() == 2 );
00250
00251 bool usePFMuonMomAssign
00252 = iConfig.getParameter<bool>("usePFMuonMomAssign");
00253
00254
00255 pfAlgo_->setPFMuonAndFakeParameters(muonHCAL,
00256 muonECAL,
00257 nSigmaTRACK,
00258 ptError,
00259 factors45,
00260 usePFMuonMomAssign);
00261
00262
00263 bool postHFCleaning
00264 = iConfig.getParameter<bool>("postHFCleaning");
00265
00266 double minHFCleaningPt
00267 = iConfig.getParameter<double>("minHFCleaningPt");
00268 double minSignificance
00269 = iConfig.getParameter<double>("minSignificance");
00270 double maxSignificance
00271 = iConfig.getParameter<double>("maxSignificance");
00272 double minSignificanceReduction
00273 = iConfig.getParameter<double>("minSignificanceReduction");
00274 double maxDeltaPhiPt
00275 = iConfig.getParameter<double>("maxDeltaPhiPt");
00276 double minDeltaMet
00277 = iConfig.getParameter<double>("minDeltaMet");
00278
00279
00280 pfAlgo_->setPostHFCleaningParameters(postHFCleaning,
00281 minHFCleaningPt,
00282 minSignificance,
00283 maxSignificance,
00284 minSignificanceReduction,
00285 maxDeltaPhiPt,
00286 minDeltaMet);
00287
00288
00289 inputTagCleanedHF_
00290 = iConfig.getParameter< std::vector<edm::InputTag> >("cleanedHF");
00291
00292
00293 vertices_ = iConfig.getParameter<edm::InputTag>("vertexCollection");
00294 useVerticesForNeutral_ = iConfig.getParameter<bool>("useVerticesForNeutral");
00295
00296
00297
00298 verbose_ =
00299 iConfig.getUntrackedParameter<bool>("verbose",false);
00300
00301 bool debug_ =
00302 iConfig.getUntrackedParameter<bool>("debug",false);
00303
00304 pfAlgo_->setDebug( debug_ );
00305
00306 }
00307
00308
00309
00310 PFProducer::~PFProducer() {}
00311
00312
00313 void
00314 PFProducer::beginJob() {}
00315
00316 void
00317 PFProducer::beginRun(edm::Run & run,
00318 const edm::EventSetup & es)
00319 {
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337 if ( useCalibrationsFromDB_ ) {
00338
00339 edm::ESHandle<PerformancePayload> perfH;
00340 es.get<PFCalibrationRcd>().get(perfH);
00341
00342 const PerformancePayloadFromTFormula *pfCalibrations = static_cast< const PerformancePayloadFromTFormula *>(perfH.product());
00343
00344 pfAlgo_->thePFEnergyCalibration()->setCalibrationFunctions(pfCalibrations);
00345 }
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368 }
00369
00370
00371 void
00372 PFProducer::produce(Event& iEvent,
00373 const EventSetup& iSetup) {
00374
00375 LogDebug("PFProducer")<<"START event: "
00376 <<iEvent.id().event()
00377 <<" in run "<<iEvent.id().run()<<endl;
00378
00379
00380
00381
00382 edm::Handle<reco::VertexCollection> vertices;
00383 bool gotVertices = iEvent.getByLabel(vertices_,vertices);
00384 if(!gotVertices) {
00385 ostringstream err;
00386 err<<"Cannot find vertices for this event.Continuing Without them ";
00387 LogError("PFProducer")<<err.str()<<endl;
00388 }
00389
00390
00391 pfAlgo_->setPFVertexParameters(useVerticesForNeutral_,*vertices);
00392
00393
00394
00395 Handle< reco::PFBlockCollection > blocks;
00396
00397 LogDebug("PFProducer")<<"getting blocks"<<endl;
00398 bool found = iEvent.getByLabel( inputTagBlocks_, blocks );
00399
00400 if(!found ) {
00401
00402 ostringstream err;
00403 err<<"cannot find blocks: "<<inputTagBlocks_;
00404 LogError("PFProducer")<<err.str()<<endl;
00405
00406 throw cms::Exception( "MissingProduct", err.str());
00407 }
00408
00409
00410
00411 Handle< reco::MuonCollection > muons;
00412
00413 if ( postMuonCleaning_ ) {
00414
00415 LogDebug("PFProducer")<<"getting muons"<<endl;
00416 found = iEvent.getByLabel( inputTagMuons_, muons );
00417
00418 if(!found) {
00419 ostringstream err;
00420 err<<"cannot find muons: "<<inputTagMuons_;
00421 LogError("PFProducer")<<err.str()<<endl;
00422
00423 throw cms::Exception( "MissingProduct", err.str());
00424 }
00425
00426 }
00427
00428 if (useEGammaElectrons_) {
00429 Handle < reco::GsfElectronCollection > egelectrons;
00430
00431 LogDebug("PFProducer")<<" Reading e/gamma electrons activated "<<endl;
00432 found = iEvent.getByLabel( inputTagEgammaElectrons_, egelectrons );
00433
00434 if(!found) {
00435 ostringstream err;
00436 err<<"cannot find electrons: "<<inputTagEgammaElectrons_;
00437 LogError("PFProducer")<<err.str()<<endl;
00438
00439 throw cms::Exception( "MissingProduct", err.str());
00440 }
00441
00442 pfAlgo_->setEGElectronCollection(*egelectrons);
00443 }
00444
00445
00446 LogDebug("PFProducer")<<"particle flow is starting"<<endl;
00447
00448 assert( blocks.isValid() );
00449
00450 pfAlgo_->reconstructParticles( blocks );
00451
00452 if(verbose_) {
00453 ostringstream str;
00454 str<<(*pfAlgo_)<<endl;
00455
00456 LogInfo("PFProducer") <<str.str()<<endl;
00457 }
00458
00459
00460 if ( postMuonCleaning_ )
00461 pfAlgo_->postMuonCleaning( muons, *vertices );
00462
00463
00464
00465 if(usePFElectrons_) {
00466 auto_ptr< reco::PFCandidateElectronExtraCollection >
00467 pOutputElectronCandidateExtraCollection( pfAlgo_->transferElectronExtra() );
00468
00469 const edm::OrphanHandle<reco::PFCandidateElectronExtraCollection > electronExtraProd=
00470 iEvent.put(pOutputElectronCandidateExtraCollection,electronExtraOutputCol_);
00471 pfAlgo_->setElectronExtraRef(electronExtraProd);
00472 }
00473
00474
00475
00476 auto_ptr< reco::PFCandidateCollection >
00477 pCosmicsMuonCleanedCandidateCollection( pfAlgo_->transferCosmicsMuonCleanedCandidates() );
00478
00479 auto_ptr< reco::PFCandidateCollection >
00480 pTrackerAndGlobalCleanedMuonCandidateCollection( pfAlgo_->transferCleanedTrackerAndGlobalMuonCandidates() );
00481
00482 auto_ptr< reco::PFCandidateCollection >
00483 pFakeCleanedMuonCandidateCollection( pfAlgo_->transferFakeMuonCleanedCandidates() );
00484
00485 auto_ptr< reco::PFCandidateCollection >
00486 pPunchThroughMuonCleanedCandidateCollection( pfAlgo_->transferPunchThroughMuonCleanedCandidates() );
00487
00488 auto_ptr< reco::PFCandidateCollection >
00489 pPunchThroughHadronCleanedCandidateCollection( pfAlgo_->transferPunchThroughHadronCleanedCandidates() );
00490
00491 auto_ptr< reco::PFCandidateCollection >
00492 pAddedMuonCandidateCollection( pfAlgo_->transferAddedMuonCandidates() );
00493
00494
00495 reco::PFRecHitCollection hfCopy;
00496 for ( unsigned ihf=0; ihf<inputTagCleanedHF_.size(); ++ihf ) {
00497 Handle< reco::PFRecHitCollection > hfCleaned;
00498 bool foundHF = iEvent.getByLabel( inputTagCleanedHF_[ihf], hfCleaned );
00499 if (!foundHF) continue;
00500 for ( unsigned jhf=0; jhf<(*hfCleaned).size(); ++jhf ) {
00501 hfCopy.push_back( (*hfCleaned)[jhf] );
00502 }
00503 }
00504 pfAlgo_->checkCleaning( hfCopy );
00505
00506
00507 auto_ptr< reco::PFCandidateCollection >
00508 pCleanedCandidateCollection( pfAlgo_->transferCleanedCandidates() );
00509
00510
00511
00512 auto_ptr< reco::PFCandidateCollection >
00513 pOutputCandidateCollection( pfAlgo_->transferCandidates() );
00514
00515
00516
00517 LogDebug("PFProducer")<<"particle flow: putting products in the event"<<endl;
00518 if ( verbose_ ) std::cout <<"particle flow: putting products in the event. Here the full list"<<endl;
00519 int nC=0;
00520 for( reco::PFCandidateCollection::const_iterator itCand = (*pOutputCandidateCollection).begin(); itCand != (*pOutputCandidateCollection).end(); itCand++) {
00521 nC++;
00522 if (verbose_ ) std::cout << nC << ")" << (*itCand).particleId() << std::endl;
00523
00524 }
00525
00526
00527 iEvent.put(pOutputCandidateCollection);
00528 iEvent.put(pCleanedCandidateCollection,"CleanedHF");
00529
00530 if ( postMuonCleaning_ ) {
00531 iEvent.put(pCosmicsMuonCleanedCandidateCollection,"CleanedCosmicsMuons");
00532 iEvent.put(pTrackerAndGlobalCleanedMuonCandidateCollection,"CleanedTrackerAndGlobalMuons");
00533 iEvent.put(pFakeCleanedMuonCandidateCollection,"CleanedFakeMuons");
00534 iEvent.put(pPunchThroughMuonCleanedCandidateCollection,"CleanedPunchThroughMuons");
00535 iEvent.put(pPunchThroughHadronCleanedCandidateCollection,"CleanedPunchThroughNeutralHadrons");
00536 iEvent.put(pAddedMuonCandidateCollection,"AddedMuonsAndHadrons");
00537 }
00538
00539 if(usePFElectrons_)
00540 {
00541 auto_ptr< reco::PFCandidateCollection >
00542 pOutputElectronCandidateCollection( pfAlgo_->transferElectronCandidates() );
00543 iEvent.put(pOutputElectronCandidateCollection,electronOutputCol_);
00544
00545 }
00546 }
00547