28 using namespace boost;
32 typedef std::list< reco::PFBlockRef >::iterator
IBR;
49 std::vector<double> calibPFSCEle_Fbrem_barrel;
50 std::vector<double> calibPFSCEle_Fbrem_endcap;
51 std::vector<double> calibPFSCEle_barrel;
52 std::vector<double> calibPFSCEle_endcap;
53 usePFSCEleCalib = iConfig.
getParameter<
bool>(
"usePFSCEleCalib");
54 calibPFSCEle_Fbrem_barrel = iConfig.
getParameter<std::vector<double> >(
"calibPFSCEle_Fbrem_barrel");
55 calibPFSCEle_Fbrem_endcap = iConfig.
getParameter<std::vector<double> >(
"calibPFSCEle_Fbrem_endcap");
56 calibPFSCEle_barrel = iConfig.
getParameter<std::vector<double> >(
"calibPFSCEle_barrel");
57 calibPFSCEle_endcap = iConfig.
getParameter<std::vector<double> >(
"calibPFSCEle_endcap");
58 boost::shared_ptr<PFSCEnergyCalibration>
59 thePFSCEnergyCalibration (
new PFSCEnergyCalibration(calibPFSCEle_Fbrem_barrel,calibPFSCEle_Fbrem_endcap,
60 calibPFSCEle_barrel,calibPFSCEle_endcap ));
62 bool useEGammaSupercluster = iConfig.
getParameter<
bool>(
"useEGammaSupercluster");
63 double sumEtEcalIsoForEgammaSC_barrel = iConfig.
getParameter<
double>(
"sumEtEcalIsoForEgammaSC_barrel");
64 double sumEtEcalIsoForEgammaSC_endcap = iConfig.
getParameter<
double>(
"sumEtEcalIsoForEgammaSC_endcap");
65 double coneEcalIsoForEgammaSC = iConfig.
getParameter<
double>(
"coneEcalIsoForEgammaSC");
66 double sumPtTrackIsoForEgammaSC_barrel = iConfig.
getParameter<
double>(
"sumPtTrackIsoForEgammaSC_barrel");
67 double sumPtTrackIsoForEgammaSC_endcap = iConfig.
getParameter<
double>(
"sumPtTrackIsoForEgammaSC_endcap");
68 double coneTrackIsoForEgammaSC = iConfig.
getParameter<
double>(
"coneTrackIsoForEgammaSC");
69 unsigned int nTrackIsoForEgammaSC = iConfig.
getParameter<
unsigned int>(
"nTrackIsoForEgammaSC");
73 produces<reco::PFCandidateCollection>();
74 produces<reco::PFCandidateEGammaExtraCollection>();
75 produces<reco::CaloClusterCollection>(
"EBEEClusters");
76 produces<reco::CaloClusterCollection>(
"ESClusters");
77 produces<reco::SuperClusterCollection>();
84 string mvaWeightFileEleID
85 = iConfig.
getParameter<
string>(
"pf_electronID_mvaWeightFile");
87 bool applyCrackCorrectionsForElectrons
88 = iConfig.
getParameter<
bool>(
"pf_electronID_crackCorrection");
90 string path_mvaWeightFileEleID;
92 path_mvaWeightFileEleID =
edm::FileInPath ( mvaWeightFileEleID.c_str() ).fullPath();
97 string path_mvaWeightFileConvID;
98 string mvaWeightFileConvID;
99 string path_mvaWeightFileGCorr;
100 string path_mvaWeightFileLCorr;
102 string path_mvaWeightFileRes;
103 double mvaConvCut=-99.;
104 double sumPtTrackIsoForPhoton = 99.;
105 double sumPtTrackIsoSlopeForPhoton = 99.;
108 mvaWeightFileConvID =iConfig.
getParameter<
string>(
"pf_convID_mvaWeightFile");
109 mvaConvCut = iConfig.
getParameter<
double>(
"pf_conv_mvaCut");
110 path_mvaWeightFileConvID =
edm::FileInPath ( mvaWeightFileConvID.c_str() ).fullPath();
111 sumPtTrackIsoForPhoton = iConfig.
getParameter<
double>(
"sumPtTrackIsoForPhoton");
112 sumPtTrackIsoSlopeForPhoton = iConfig.
getParameter<
double>(
"sumPtTrackIsoSlopeForPhoton");
117 if(!useRegressionFromDB_) {
118 string mvaWeightFileLCorr=iConfig.
getParameter<
string>(
"pf_locC_mvaWeightFile");
119 path_mvaWeightFileLCorr =
edm::FileInPath( mvaWeightFileLCorr.c_str() ).fullPath();
120 string mvaWeightFileGCorr=iConfig.
getParameter<
string>(
"pf_GlobC_mvaWeightFile");
121 path_mvaWeightFileGCorr =
edm::FileInPath( mvaWeightFileGCorr.c_str() ).fullPath();
122 string mvaWeightFileRes=iConfig.
getParameter<
string>(
"pf_Res_mvaWeightFile");
123 path_mvaWeightFileRes=
edm::FileInPath(mvaWeightFileRes.c_str()).fullPath();
125 TFile *fgbr =
new TFile(path_mvaWeightFileGCorr.c_str(),
"READ");
126 ReaderGC_ =(
const GBRForest*)fgbr->Get(
"GBRForest");
127 TFile *fgbr2 =
new TFile(path_mvaWeightFileLCorr.c_str(),
"READ");
128 ReaderLC_ = (
const GBRForest*)fgbr2->Get(
"GBRForest");
129 TFile *fgbr3 =
new TFile(path_mvaWeightFileRes.c_str(),
"READ");
130 ReaderRes_ = (
const GBRForest*)fgbr3->Get(
"GBRForest");
131 LogDebug(
"PFEGammaProducer")<<
"Will set regressions from binary files " <<endl;
140 useCalibrationsFromDB_
143 boost::shared_ptr<PFEnergyCalibration>
158 setPFEGParameters(mvaEleCut,
159 path_mvaWeightFileEleID,
161 thePFSCEnergyCalibration,
163 sumEtEcalIsoForEgammaSC_barrel,
164 sumEtEcalIsoForEgammaSC_endcap,
165 coneEcalIsoForEgammaSC,
166 sumPtTrackIsoForEgammaSC_barrel,
167 sumPtTrackIsoForEgammaSC_endcap,
168 nTrackIsoForEgammaSC,
169 coneTrackIsoForEgammaSC,
170 applyCrackCorrectionsForElectrons,
173 useEGammaSupercluster,
175 path_mvaWeightFileConvID,
179 sumPtTrackIsoForPhoton,
180 sumPtTrackIsoSlopeForPhoton
240 if(useRegressionFromDB_) {
248 ReaderLCEB_=readerPFLCEB.
product();
250 ReaderLCEE_=readerPFLCEE.
product();
252 ReaderGCBarrel_=readerPFGCEB.
product();
254 ReaderGCEndCapHighr9_=readerPFGCEEHR9.
product();
256 ReaderGCEndCapLowr9_=readerPFGCEELR9.
product();
258 ReaderEcalRes_=readerPFRes.
product();
267 setPFPhotonRegWeights(ReaderLCEB_,ReaderLCEE_,ReaderGCBarrel_,ReaderGCEndCapHighr9_, ReaderGCEndCapLowr9_, ReaderEcalRes_ );
276 LogDebug(
"PFEGammaProducer")<<
"START event: "
278 <<
" in run "<<iEvent.
id().
run()<<endl;
282 if(egCandidates_.get() )
283 egCandidates_->clear();
287 if(ebeeClusters_.get() )
288 ebeeClusters_->clear();
294 if(esClusters_.get() )
295 esClusters_->clear();
299 if(sClusters_.get() )
312 bool gotVertices = iEvent.
getByLabel(vertices_,vertices);
315 err<<
"Cannot find vertices for this event.Continuing Without them ";
316 LogError(
"PFEGammaProducer")<<err.str()<<endl;
320 setPFVertexParameters(useVerticesForNeutral_,vertices.
product());
326 LogDebug(
"PFEGammaProducer")<<
"getting blocks"<<endl;
332 err<<
"cannot find blocks: "<<inputTagBlocks_;
333 LogError(
"PFEGammaProducer")<<err.str()<<endl;
340 LogDebug(
"PFEGammaProducer")<<
"particle flow is starting"<<endl;
342 assert( blocks.isValid() );
350 LogInfo(
"PFEGammaProducer") <<str.str()<<endl;
354 std::list< reco::PFBlockRef > hcalBlockRefs;
355 std::list< reco::PFBlockRef > ecalBlockRefs;
356 std::list< reco::PFBlockRef > hoBlockRefs;
357 std::list< reco::PFBlockRef > otherBlockRefs;
359 for(
unsigned i=0;
i<blocks->size(); ++
i ) {
368 bool singleEcalOrHcal =
false;
369 if( elements.
size() == 1 ){
371 ecalBlockRefs.push_back( blockref );
372 singleEcalOrHcal =
true;
375 hcalBlockRefs.push_back( blockref );
376 singleEcalOrHcal =
true;
380 hoBlockRefs.push_back( blockref );
381 singleEcalOrHcal =
true;
385 if(!singleEcalOrHcal) {
386 otherBlockRefs.push_back( blockref );
397 for(
IBR io = otherBlockRefs.begin(); io!=otherBlockRefs.end(); ++io) {
405 vector<bool> active( elements.
size(),
true );
408 if (pfeg_->isEGValidCandidate(blockref,active)){
410 egCandidates_->insert(egCandidates_->end(),pfeg_->getCandidates().begin(), pfeg_->getCandidates().end());
411 egExtra_->insert(egExtra_->end(), pfeg_->getEGExtra().begin(), pfeg_->getEGExtra().end());
425 std::vector<std::vector<int> > ebeeidxs(egCandidates_->size());
426 std::vector<std::vector<int> > esidxs(egCandidates_->size());;
427 for (
unsigned int icand=0; icand<egCandidates_->size(); ++icand) {
437 ebeeClusters_->push_back(cluster);
439 ebeeidxs[icand].push_back(ebeeClusters_->size()-1);
443 esClusters_->push_back(cluster);
445 esidxs[icand].push_back(esClusters_->size()-1);
452 auto_ptr< reco::CaloClusterCollection >
453 pOutputEBEEClusters( ebeeClusters_ );
455 iEvent.
put(pOutputEBEEClusters,
"EBEEClusters");
457 auto_ptr< reco::CaloClusterCollection >
458 pOutputESClusters( esClusters_ );
460 iEvent.
put(pOutputESClusters,
"ESClusters");
463 for (
unsigned int iclus=0; iclus<egCandidates_->size(); ++iclus) {
467 const std::vector<int> &ebeeidx = ebeeidxs[iclus];
468 const std::vector<int> &esidx = esidxs[iclus];
474 double maxenergy = 0.;
475 double rawenergy = 0.;
481 for (
unsigned int icaloclus=0; icaloclus<ebeeidx.size(); ++icaloclus) {
486 rawenergy += cluster.
energy();
487 energy += cluster.
energy();
493 if (cluster.
energy()>maxenergy) {
494 maxenergy = cluster.
energy();
502 for (
unsigned int icaloclus=0; icaloclus<esidx.size(); ++icaloclus) {
508 energy += cluster.
energy();
518 sClusters_->push_back(refinedSC);
526 auto_ptr< reco::PFCandidateEGammaExtraCollection >
527 pOutputEGammaCandidateExtraCollection( egExtra_ );
529 iEvent.
put(pOutputEGammaCandidateExtraCollection);
533 for (
unsigned int icand=0; icand<egCandidates_->size(); ++icand) {
541 auto_ptr< reco::SuperClusterCollection >
542 pOutputSClusters( sClusters_ );
544 iEvent.
put(pOutputSClusters);
547 auto_ptr< reco::PFCandidateCollection >
548 pOutputCandidateCollection( egCandidates_ );
562 iEvent.
put(pOutputCandidateCollection);
569 string mvaWeightFileEleID,
571 const boost::shared_ptr<PFSCEnergyCalibration>& thePFSCEnergyCalibration,
572 const boost::shared_ptr<PFEnergyCalibration>& thePFEnergyCalibration,
573 double sumEtEcalIsoForEgammaSC_barrel,
574 double sumEtEcalIsoForEgammaSC_endcap,
575 double coneEcalIsoForEgammaSC,
576 double sumPtTrackIsoForEgammaSC_barrel,
577 double sumPtTrackIsoForEgammaSC_endcap,
578 unsigned int nTrackIsoForEgammaSC,
579 double coneTrackIsoForEgammaSC,
580 bool applyCrackCorrections,
581 bool usePFSCEleCalib,
583 bool useEGammaSupercluster,
589 double sumPtTrackIsoForPhoton,
590 double sumPtTrackIsoSlopeForPhoton
593 mvaEleCut_ = mvaEleCut;
594 usePFElectrons_ = usePFElectrons;
595 applyCrackCorrectionsElectrons_ = applyCrackCorrections;
596 usePFSCEleCalib_ = usePFSCEleCalib;
597 thePFSCEnergyCalibration_ = thePFSCEnergyCalibration;
598 useEGElectrons_ = useEGElectrons;
599 useEGammaSupercluster_ = useEGammaSupercluster;
600 sumEtEcalIsoForEgammaSC_barrel_ = sumEtEcalIsoForEgammaSC_barrel;
601 sumEtEcalIsoForEgammaSC_endcap_ = sumEtEcalIsoForEgammaSC_endcap;
602 coneEcalIsoForEgammaSC_ = coneEcalIsoForEgammaSC;
603 sumPtTrackIsoForEgammaSC_barrel_ = sumPtTrackIsoForEgammaSC_barrel;
604 sumPtTrackIsoForEgammaSC_endcap_ = sumPtTrackIsoForEgammaSC_endcap;
605 coneTrackIsoForEgammaSC_ = coneTrackIsoForEgammaSC;
606 nTrackIsoForEgammaSC_ = nTrackIsoForEgammaSC;
609 if(!usePFElectrons_)
return;
610 mvaWeightFileEleID_ = mvaWeightFileEleID;
611 FILE * fileEleID = fopen(mvaWeightFileEleID_.c_str(),
"r");
616 string err =
"PFAlgo: cannot open weight file '";
617 err += mvaWeightFileEleID;
619 throw invalid_argument( err );
622 usePFPhotons_ = usePFPhotons;
628 dummy = primaryVertex_;
632 e(0, 0) = 0.0015 * 0.0015;
633 e(1, 1) = 0.0015 * 0.0015;
640 FILE * filePhotonConvID = fopen(mvaWeightFileConvID.c_str(),
"r");
641 if (filePhotonConvID) {
642 fclose(filePhotonConvID);
645 string err =
"PFAlgo: cannot open weight file '";
646 err += mvaWeightFileConvID;
648 throw invalid_argument( err );
651 pfeg_.reset(
new PFEGammaAlgo(mvaEleCut_,mvaWeightFileEleID_,
652 thePFSCEnergyCalibration_,
653 thePFEnergyCalibration,
654 applyCrackCorrectionsElectrons_,
657 useEGammaSupercluster_,
658 sumEtEcalIsoForEgammaSC_barrel_,
659 sumEtEcalIsoForEgammaSC_endcap_,
660 coneEcalIsoForEgammaSC_,
661 sumPtTrackIsoForEgammaSC_barrel_,
662 sumPtTrackIsoForEgammaSC_endcap_,
663 nTrackIsoForEgammaSC_,
664 coneTrackIsoForEgammaSC_,
670 sumPtTrackIsoForPhoton,
671 sumPtTrackIsoSlopeForPhoton
709 pfeg_->setGBRForest(LCorrForestEB,LCorrForestEE,
710 GCorrForestBarrel, GCorrForestEndcapHr9,
711 GCorrForestEndcapLr9, PFEcalResolution);
717 useVertices_ = useVertex;
725 int nVtx=primaryVertices->size();
730 primaryVertex_ = primaryVertices->front();
731 for (
unsigned short i=0 ;
i<primaryVertices->size();++
i)
733 if(primaryVertices->at(
i).isValid()&&(!primaryVertices->at(
i).isFake()))
735 primaryVertex_ = primaryVertices->at(
i);
741 pfeg_->setPhotonPrimaryVtx(primaryVertex_ );
T getParameter(std::string const &) const
EventNumber_t event() const
Abstract base class for a PFBlock element (track, cluster...)
T getUntrackedParameter(std::string const &, T const &) const
const math::XYZPoint & position() const
cluster centroid position
void setSuperClusterRef(reco::SuperClusterRef sc)
set reference to the corresponding supercluster
void push_back(Ptr< T > const &iPtr)
math::Error< dimension >::type Error
covariance error matrix (3x3)
std::vector< Vertex > VertexCollection
collection of Vertex objects
const edm::OwnVector< reco::PFBlockElement > & elements() const
void setPFPhotonRegWeights(const GBRForest *LCorrForestEB, const GBRForest *LCorrForestEE, const GBRForest *GCorrForestBarrel, const GBRForest *GCorrForestEndcapHr9, const GBRForest *GCorrForestEndcapLr9, const GBRForest *PFEcalResolution)
const ElementsInBlocks & elementsInBlocks() const
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
void setPFVertexParameters(bool useVertex, const reco::VertexCollection *primaryVertices)
std::vector< reco::PFCandidateEGammaExtra > PFCandidateEGammaExtraCollection
collection of PFCandidateEGammaExtras
virtual PFClusterRef clusterRef() const
std::vector< CaloCluster > CaloClusterCollection
collection of CaloCluster objects
math::XYZPoint Point
point in the space
double energy() const
cluster energy
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
block
Formating index page's pieces.
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
RefProd< PROD > getRefBeforePut()
void setPFEGParameters(double mvaEleCut, std::string mvaWeightFileEleID, bool usePFElectrons, const boost::shared_ptr< PFSCEnergyCalibration > &thePFSCEnergyCalibration, const boost::shared_ptr< PFEnergyCalibration > &thePFEnergyCalibration, double sumEtEcalIsoForEgammaSC_barrel, double sumEtEcalIsoForEgammaSC_endcap, double coneEcalIsoForEgammaSC, double sumPtTrackIsoForEgammaSC_barrel, double sumPtTrackIsoForEgammaSC_endcap, unsigned int nTrackIsoForEgammaSC, double coneTrackIsoForEgammaSC, bool applyCrackCorrections, bool usePFSCEleCalib, bool useEGElectrons, bool useEGammaSupercluster, bool usePFPhoton, std::string mvaWeightFileConvID, double mvaConvCut, bool useReg, std::string X0_Map, double sumPtTrackIsoForPhoton, double sumPtTrackIsoSlopeForPhoton)
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
XYZPointD XYZPoint
point in space with cartesian internal representation
T const * product() const
T const * product() const
Particle reconstructed by the particle flow algorithm.
void setPFEGammaExtraRef(const reco::PFCandidateEGammaExtraRef &ref)
set the PF EGamma Extra Ref
PFEGammaProducer(const edm::ParameterSet &)
void setSuperClusterRef(const reco::SuperClusterRef &scRef)
std::list< reco::PFBlockRef >::iterator IBR
T const * get() const
Returns C++ pointer to the item.
virtual void produce(edm::Event &, const edm::EventSetup &) override