CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFEGammaProducer.cc
Go to the documentation of this file.
3 
22 #include <sstream>
23 
24 #include "TFile.h"
25 
26 using namespace std;
27 
28 using namespace boost;
29 
30 using namespace edm;
31 
32 typedef std::list< reco::PFBlockRef >::iterator IBR;
33 
34 
36 
37 
38  inputTagBlocks_
39  = iConfig.getParameter<InputTag>("blocks");
40 
41  usePhotonReg_
42  = iConfig.getParameter<bool>("usePhotonReg");
43 
44  useRegressionFromDB_
45  = iConfig.getParameter<bool>("useRegressionFromDB");
46 
47 
48  bool usePFSCEleCalib;
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 ));
61 
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");
70 
71 
72  // register products
73  produces<reco::PFCandidateCollection>();
74  produces<reco::PFCandidateEGammaExtraCollection>();
75  produces<reco::CaloClusterCollection>("EBEEClusters");
76  produces<reco::CaloClusterCollection>("ESClusters");
77  produces<reco::SuperClusterCollection>();
78 
79  //PFElectrons Configuration
80  double mvaEleCut
81  = iConfig.getParameter<double>("pf_electron_mvaCut");
82 
83 
84  string mvaWeightFileEleID
85  = iConfig.getParameter<string>("pf_electronID_mvaWeightFile");
86 
87  bool applyCrackCorrectionsForElectrons
88  = iConfig.getParameter<bool>("pf_electronID_crackCorrection");
89 
90  string path_mvaWeightFileEleID;
91 
92  path_mvaWeightFileEleID = edm::FileInPath ( mvaWeightFileEleID.c_str() ).fullPath();
93 
94 
95  //PFPhoton Configuration
96 
97  string path_mvaWeightFileConvID;
98  string mvaWeightFileConvID;
99  string path_mvaWeightFileGCorr;
100  string path_mvaWeightFileLCorr;
101  string path_X0_Map;
102  string path_mvaWeightFileRes;
103  double mvaConvCut=-99.;
104  double sumPtTrackIsoForPhoton = 99.;
105  double sumPtTrackIsoSlopeForPhoton = 99.;
106 
107 
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");
113 
114  string X0_Map=iConfig.getParameter<string>("X0_Map");
115  path_X0_Map = edm::FileInPath( X0_Map.c_str() ).fullPath();
116 
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();
124 
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;
132  }
133 
134  edm::ParameterSet iCfgCandConnector
135  = iConfig.getParameter<edm::ParameterSet>("iCfgCandConnector");
136 
137 
138  // fToRead = iConfig.getUntrackedParameter<vector<string> >("toRead");
139 
140  useCalibrationsFromDB_
141  = iConfig.getParameter<bool>("useCalibrationsFromDB");
142 
143  boost::shared_ptr<PFEnergyCalibration>
144  calibration( new PFEnergyCalibration() );
145 
146  int algoType
147  = iConfig.getParameter<unsigned>("algoType");
148 
149  switch(algoType) {
150  case 0:
151  //pfAlgo_.reset( new PFAlgo);
152  break;
153  default:
154  assert(0);
155  }
156 
157  //PFEGamma
158  setPFEGParameters(mvaEleCut,
159  path_mvaWeightFileEleID,
160  true,
161  thePFSCEnergyCalibration,
162  calibration,
163  sumEtEcalIsoForEgammaSC_barrel,
164  sumEtEcalIsoForEgammaSC_endcap,
165  coneEcalIsoForEgammaSC,
166  sumPtTrackIsoForEgammaSC_barrel,
167  sumPtTrackIsoForEgammaSC_endcap,
168  nTrackIsoForEgammaSC,
169  coneTrackIsoForEgammaSC,
170  applyCrackCorrectionsForElectrons,
171  usePFSCEleCalib,
172  useEGammaElectrons_,
173  useEGammaSupercluster,
174  true,
175  path_mvaWeightFileConvID,
176  mvaConvCut,
177  usePhotonReg_,
178  path_X0_Map,
179  sumPtTrackIsoForPhoton,
180  sumPtTrackIsoSlopeForPhoton
181  );
182 
183  //MIKE: Vertex Parameters
184  vertices_ = iConfig.getParameter<edm::InputTag>("vertexCollection");
185 
186  verbose_ =
187  iConfig.getUntrackedParameter<bool>("verbose",false);
188 
189 // bool debug_ =
190 // iConfig.getUntrackedParameter<bool>("debug",false);
191 
192 }
193 
194 
195 
197 
198 void
200  const edm::EventSetup & es)
201 {
202 
203 
204  /*
205  static map<string, PerformanceResult::ResultType> functType;
206 
207  functType["PFfa_BARREL"] = PerformanceResult::PFfa_BARREL;
208  functType["PFfa_ENDCAP"] = PerformanceResult::PFfa_ENDCAP;
209  functType["PFfb_BARREL"] = PerformanceResult::PFfb_BARREL;
210  functType["PFfb_ENDCAP"] = PerformanceResult::PFfb_ENDCAP;
211  functType["PFfc_BARREL"] = PerformanceResult::PFfc_BARREL;
212  functType["PFfc_ENDCAP"] = PerformanceResult::PFfc_ENDCAP;
213  functType["PFfaEta_BARREL"] = PerformanceResult::PFfaEta_BARREL;
214  functType["PFfaEta_ENDCAP"] = PerformanceResult::PFfaEta_ENDCAP;
215  functType["PFfbEta_BARREL"] = PerformanceResult::PFfbEta_BARREL;
216  functType["PFfbEta_ENDCAP"] = PerformanceResult::PFfbEta_ENDCAP;
217  */
218 
219  /*
220  for(vector<string>::const_iterator name = fToRead.begin(); name != fToRead.end(); ++name) {
221 
222  cout << "Function: " << *name << endl;
223  PerformanceResult::ResultType fType = functType[*name];
224  pfCalibrations->printFormula(fType);
225 
226  // evaluate it @ 10 GeV
227  float energy = 10.;
228 
229  BinningPointByMap point;
230  point.insert(BinningVariables::JetEt, energy);
231 
232  if(pfCalibrations->isInPayload(fType, point)) {
233  float value = pfCalibrations->getResult(fType, point);
234  cout << " Energy before:: " << energy << " after: " << value << endl;
235  } else cout << "outside limits!" << endl;
236 
237  }
238  */
239 
240  if(useRegressionFromDB_) {
241  edm::ESHandle<GBRForest> readerPFLCEB;
242  edm::ESHandle<GBRForest> readerPFLCEE;
243  edm::ESHandle<GBRForest> readerPFGCEB;
244  edm::ESHandle<GBRForest> readerPFGCEEHR9;
245  edm::ESHandle<GBRForest> readerPFGCEELR9;
246  edm::ESHandle<GBRForest> readerPFRes;
247  es.get<GBRWrapperRcd>().get("PFLCorrectionBar",readerPFLCEB);
248  ReaderLCEB_=readerPFLCEB.product();
249  es.get<GBRWrapperRcd>().get("PFLCorrectionEnd",readerPFLCEE);
250  ReaderLCEE_=readerPFLCEE.product();
251  es.get<GBRWrapperRcd>().get("PFGCorrectionBar",readerPFGCEB);
252  ReaderGCBarrel_=readerPFGCEB.product();
253  es.get<GBRWrapperRcd>().get("PFGCorrectionEndHighR9",readerPFGCEEHR9);
254  ReaderGCEndCapHighr9_=readerPFGCEEHR9.product();
255  es.get<GBRWrapperRcd>().get("PFGCorrectionEndLowR9",readerPFGCEELR9);
256  ReaderGCEndCapLowr9_=readerPFGCEELR9.product();
257  es.get<GBRWrapperRcd>().get("PFEcalResolution",readerPFRes);
258  ReaderEcalRes_=readerPFRes.product();
259 
260  /*
261  LogDebug("PFEGammaProducer")<<"setting regressions from DB "<<endl;
262  */
263  }
264 
265 
266  //pfAlgo_->setPFPhotonRegWeights(ReaderLC_, ReaderGC_, ReaderRes_);
267  setPFPhotonRegWeights(ReaderLCEB_,ReaderLCEE_,ReaderGCBarrel_,ReaderGCEndCapHighr9_, ReaderGCEndCapLowr9_, ReaderEcalRes_ );
268 
269 }
270 
271 
272 void
274  const EventSetup& iSetup) {
275 
276  LogDebug("PFEGammaProducer")<<"START event: "
277  <<iEvent.id().event()
278  <<" in run "<<iEvent.id().run()<<endl;
279 
280 
281  // reset output collection
282  if(egCandidates_.get() )
283  egCandidates_->clear();
284  else
285  egCandidates_.reset( new reco::PFCandidateCollection );
286 
287  if(ebeeClusters_.get() )
288  ebeeClusters_->clear();
289  else
290  ebeeClusters_.reset( new reco::CaloClusterCollection );
291 
292  //printf("ebeeclusters->size() = %i\n",int(ebeeClusters_->size()));
293 
294  if(esClusters_.get() )
295  esClusters_->clear();
296  else
297  esClusters_.reset( new reco::CaloClusterCollection );
298 
299  if(sClusters_.get() )
300  sClusters_->clear();
301  else
302  sClusters_.reset( new reco::SuperClusterCollection );
303 
304  if(egExtra_.get() )
305  egExtra_->clear();
306  else
307  egExtra_.reset( new reco::PFCandidateEGammaExtraCollection );
308 
309  // Get The vertices from the event
310  // and assign dynamic vertex parameters
312  bool gotVertices = iEvent.getByLabel(vertices_,vertices);
313  if(!gotVertices) {
314  ostringstream err;
315  err<<"Cannot find vertices for this event.Continuing Without them ";
316  LogError("PFEGammaProducer")<<err.str()<<endl;
317  }
318 
319  //Assign the PFAlgo Parameters
320  setPFVertexParameters(useVerticesForNeutral_,vertices.product());
321 
322  // get the collection of blocks
323 
325 
326  LogDebug("PFEGammaProducer")<<"getting blocks"<<endl;
327  bool found = iEvent.getByLabel( inputTagBlocks_, blocks );
328 
329  if(!found ) {
330 
331  ostringstream err;
332  err<<"cannot find blocks: "<<inputTagBlocks_;
333  LogError("PFEGammaProducer")<<err.str()<<endl;
334 
335  throw cms::Exception( "MissingProduct", err.str());
336  }
337 
338 
339 
340  LogDebug("PFEGammaProducer")<<"particle flow is starting"<<endl;
341 
342  assert( blocks.isValid() );
343 
344  //pfAlgo_->reconstructParticles( blocks );
345 
346  if(verbose_) {
347  ostringstream str;
348  //str<<(*pfAlgo_)<<endl;
349  // cout << (*pfAlgo_) << endl;
350  LogInfo("PFEGammaProducer") <<str.str()<<endl;
351  }
352 
353  // sort elements in three lists:
354  std::list< reco::PFBlockRef > hcalBlockRefs;
355  std::list< reco::PFBlockRef > ecalBlockRefs;
356  std::list< reco::PFBlockRef > hoBlockRefs;
357  std::list< reco::PFBlockRef > otherBlockRefs;
358 
359  for( unsigned i=0; i<blocks->size(); ++i ) {
360  // reco::PFBlockRef blockref( blockh,i );
361  //reco::PFBlockRef blockref = createBlockRef( *blocks, i);
362  reco::PFBlockRef blockref(blocks, i);
363 
364  const reco::PFBlock& block = *blockref;
366  elements = block.elements();
367 
368  bool singleEcalOrHcal = false;
369  if( elements.size() == 1 ){
370  if( elements[0].type() == reco::PFBlockElement::ECAL ){
371  ecalBlockRefs.push_back( blockref );
372  singleEcalOrHcal = true;
373  }
374  if( elements[0].type() == reco::PFBlockElement::HCAL ){
375  hcalBlockRefs.push_back( blockref );
376  singleEcalOrHcal = true;
377  }
378  if( elements[0].type() == reco::PFBlockElement::HO ){
379  // Single HO elements are likely to be noise. Not considered for now.
380  hoBlockRefs.push_back( blockref );
381  singleEcalOrHcal = true;
382  }
383  }
384 
385  if(!singleEcalOrHcal) {
386  otherBlockRefs.push_back( blockref );
387  }
388  }//loop blocks
389 
390 
391 
392  // loop on blocks that are not single ecal,
393  // and not single hcal and produce unbiased collection of EGamma Candidates
394 
395  //printf("loop over blocks\n");
396  //unsigned nblcks = 0;
397  for( IBR io = otherBlockRefs.begin(); io!=otherBlockRefs.end(); ++io) {
398  const reco::PFBlockRef& blockref = *io;
399  const reco::PFBlock& block = **io;
401  // make a copy of the link data, which will be edited.
402  //PFBlock::LinkData linkData = block.linkData();
403 
404  // keep track of the elements which are still active.
405  vector<bool> active( elements.size(), true );
406 
407  //printf("pre algo: egCandidates size = %i\n",int(egCandidates_->size()));
408  if (pfeg_->isEGValidCandidate(blockref,active)){
409  //printf("getCandidates size = %i\n",int(pfeg_->getCandidates().size()));
410  egCandidates_->insert(egCandidates_->end(),pfeg_->getCandidates().begin(), pfeg_->getCandidates().end());
411  egExtra_->insert(egExtra_->end(), pfeg_->getEGExtra().begin(), pfeg_->getEGExtra().end());
412  }
413  // printf("post algo: egCandidates size = %i\n",int(egCandidates_->size()));
414 
415 
416 
417  }
418 
419 // edm::RefProd<reco::CaloClusterCollection> ebeeClusterProd = iEvent.getRefBeforePut<reco::CaloClusterCollection>("EBEEClusters");
420 // edm::RefProd<reco::CaloClusterCollection> esClusterProd = iEvent.getRefBeforePut<reco::CaloClusterCollection>("ESClusters");
422 
423  //printf("loop over candidates\n");
424  //make CaloClusters for Refined SuperClusters
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) {
428  reco::PFCandidate &cand = egCandidates_->at(icand);
429  //reco::PFCandidateEGammaExtra &extra = egExtra_->at(icand);
430 
431  //loop over blockelements
432  // printf("loop over blockelements\n");
433  for (reco::PFCandidate::ElementsInBlocks::const_iterator it=cand.elementsInBlocks().begin(); it!=cand.elementsInBlocks().end(); ++it) {
434  const reco::PFBlockElement &element = it->first->elements()[it->second];
435  if (element.type()==reco::PFBlockElement::ECAL) {
436  reco::CaloCluster cluster(*element.clusterRef().get());
437  ebeeClusters_->push_back(cluster);
438 
439  ebeeidxs[icand].push_back(ebeeClusters_->size()-1);
440  }
441  else if (element.type()==reco::PFBlockElement::PS1 || element.type()==reco::PFBlockElement::PS2) {
442  reco::CaloCluster cluster(*element.clusterRef().get());
443  esClusters_->push_back(cluster);
444 
445  esidxs[icand].push_back(esClusters_->size()-1);
446  }
447  }
448 
449  }
450 
451  //put cluster products
452  auto_ptr< reco::CaloClusterCollection >
453  pOutputEBEEClusters( ebeeClusters_ );
455  iEvent.put(pOutputEBEEClusters,"EBEEClusters");
456 
457  auto_ptr< reco::CaloClusterCollection >
458  pOutputESClusters( esClusters_ );
460  iEvent.put(pOutputESClusters,"ESClusters");
461 
462  //loop over sets of clusters to make superclusters
463  for (unsigned int iclus=0; iclus<egCandidates_->size(); ++iclus) {
464  reco::PFCandidate &cand = egCandidates_->at(iclus);
465  reco::PFCandidateEGammaExtra &extra = egExtra_->at(iclus);
466 
467  const std::vector<int> &ebeeidx = ebeeidxs[iclus];
468  const std::vector<int> &esidx = esidxs[iclus];
470 
471  reco::CaloClusterPtrVector ebeeclusters;
472  reco::CaloClusterPtrVector esclusters;
473 
474  double maxenergy = 0.;
475  double rawenergy = 0.;
476  double energy = 0.;
477 
478  double posX = 0.;
479  double posY = 0.;
480  double posZ = 0.;
481  for (unsigned int icaloclus=0; icaloclus<ebeeidx.size(); ++icaloclus) {
482  const reco::CaloCluster &cluster = ebeeClusterProd->at(ebeeidx[icaloclus]);
483  reco::CaloClusterPtr caloptr(ebeeClusterProd,ebeeidx[icaloclus]);
484  ebeeclusters.push_back(caloptr);
485 
486  rawenergy += cluster.energy();
487  energy += cluster.energy();
488 
489  posX += cluster.energy()*cluster.position().x();
490  posY += cluster.energy()*cluster.position().y();
491  posZ += cluster.energy()*cluster.position().z();
492 
493  if (cluster.energy()>maxenergy) {
494  maxenergy = cluster.energy();
495  seed = caloptr;
496  }
497 
498 
499 
500  }
501 
502  for (unsigned int icaloclus=0; icaloclus<esidx.size(); ++icaloclus) {
503  const reco::CaloCluster &cluster = esClusterProd->at(esidx[icaloclus]);
504 
505  reco::CaloClusterPtr caloptr(esClusterProd,esidx[icaloclus]);
506  esclusters.push_back(caloptr);
507 
508  energy += cluster.energy();
509  }
510 
511  posX /= rawenergy;
512  posY /= rawenergy;
513  posZ /= rawenergy;
514 
515  math::XYZPoint scposition(posX,posY,posZ);
516 
517  reco::SuperCluster refinedSC(rawenergy,scposition,seed,ebeeclusters,esclusters);
518  sClusters_->push_back(refinedSC);
519 
520  reco::SuperClusterRef scref(sClusterProd,sClusters_->size()-1);
521  cand.setSuperClusterRef(scref);
522  extra.setSuperClusterRef(scref);
523  }
524 
525 // Save the PFEGamma Extra Collection First as to be able to create valid References
526  auto_ptr< reco::PFCandidateEGammaExtraCollection >
527  pOutputEGammaCandidateExtraCollection( egExtra_ );
529  iEvent.put(pOutputEGammaCandidateExtraCollection);
530  //pfAlgo_->setEGammaExtraRef(egammaExtraProd);
531 
532  //final loop over Candidates to set PFCandidateEGammaExtra references
533  for (unsigned int icand=0; icand<egCandidates_->size(); ++icand) {
534  reco::PFCandidate &cand = egCandidates_->at(icand);
535 
536  reco::PFCandidateEGammaExtraRef extraref(egammaExtraProd,icand);
537  cand.setPFEGammaExtraRef(extraref);
538  }
539 
540 
541  auto_ptr< reco::SuperClusterCollection >
542  pOutputSClusters( sClusters_ );
543  //edm::OrphanHandle<reco::SuperClusterCollection > sClusterProd=
544  iEvent.put(pOutputSClusters);
545 
546  // Save the final PFCandidate collection
547  auto_ptr< reco::PFCandidateCollection >
548  pOutputCandidateCollection( egCandidates_ );
549 
550 
551 
552 // LogDebug("PFEGammaProducer")<<"particle flow: putting products in the event"<<endl;
553 // if ( verbose_ ) std::cout <<"particle flow: putting products in the event. Here the full list"<<endl;
554 // int nC=0;
555 // for( reco::PFCandidateCollection::const_iterator itCand = (*pOutputCandidateCollection).begin(); itCand != (*pOutputCandidateCollection).end(); itCand++) {
556 // nC++;
557 // if (verbose_ ) std::cout << nC << ")" << (*itCand).particleId() << std::endl;
558 //
559 // }
560 //
561 // // Write in the event
562  iEvent.put(pOutputCandidateCollection);
563 
564 }
565 
566 //PFEGammaAlgo: a new method added to set the parameters for electron and photon reconstruction.
567 void
569  string mvaWeightFileEleID,
570  bool usePFElectrons,
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,
582  bool useEGElectrons,
583  bool useEGammaSupercluster,
584  bool usePFPhotons,
585  std::string mvaWeightFileConvID,
586  double mvaConvCut,
587  bool useReg,
588  std::string X0_Map,
589  double sumPtTrackIsoForPhoton,
590  double sumPtTrackIsoSlopeForPhoton
591  ) {
592 
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;
607 
608 
609  if(!usePFElectrons_) return;
610  mvaWeightFileEleID_ = mvaWeightFileEleID;
611  FILE * fileEleID = fopen(mvaWeightFileEleID_.c_str(), "r");
612  if (fileEleID) {
613  fclose(fileEleID);
614  }
615  else {
616  string err = "PFAlgo: cannot open weight file '";
617  err += mvaWeightFileEleID;
618  err += "'";
619  throw invalid_argument( err );
620  }
621 
622  usePFPhotons_ = usePFPhotons;
623 
624  //for MVA pass PV if there is one in the collection otherwise pass a dummy
625  reco::Vertex dummy;
626  if(useVertices_)
627  {
628  dummy = primaryVertex_;
629  }
630  else { // create a dummy PV
632  e(0, 0) = 0.0015 * 0.0015;
633  e(1, 1) = 0.0015 * 0.0015;
634  e(2, 2) = 15. * 15.;
635  reco::Vertex::Point p(0, 0, 0);
636  dummy = reco::Vertex(p, e, 0, 0, 0);
637  }
638  // pv=&dummy;
639  //if(! usePFPhotons_) return;
640  FILE * filePhotonConvID = fopen(mvaWeightFileConvID.c_str(), "r");
641  if (filePhotonConvID) {
642  fclose(filePhotonConvID);
643  }
644  else {
645  string err = "PFAlgo: cannot open weight file '";
646  err += mvaWeightFileConvID;
647  err += "'";
648  throw invalid_argument( err );
649  }
650  const reco::Vertex* pv=&dummy;
651  pfeg_.reset(new PFEGammaAlgo(mvaEleCut_,mvaWeightFileEleID_,
652  thePFSCEnergyCalibration_,
653  thePFEnergyCalibration,
654  applyCrackCorrectionsElectrons_,
655  usePFSCEleCalib_,
656  useEGElectrons_,
657  useEGammaSupercluster_,
658  sumEtEcalIsoForEgammaSC_barrel_,
659  sumEtEcalIsoForEgammaSC_endcap_,
660  coneEcalIsoForEgammaSC_,
661  sumPtTrackIsoForEgammaSC_barrel_,
662  sumPtTrackIsoForEgammaSC_endcap_,
663  nTrackIsoForEgammaSC_,
664  coneTrackIsoForEgammaSC_,
665  mvaWeightFileConvID,
666  mvaConvCut,
667  useReg,
668  X0_Map,
669  *pv,
670  sumPtTrackIsoForPhoton,
671  sumPtTrackIsoSlopeForPhoton
672  ));
673  return;
674 
675 // pfele_= new PFElectronAlgo(mvaEleCut_,mvaWeightFileEleID_,
676 // thePFSCEnergyCalibration_,
677 // thePFEnergyCalibration,
678 // applyCrackCorrectionsElectrons_,
679 // usePFSCEleCalib_,
680 // useEGElectrons_,
681 // useEGammaSupercluster_,
682 // sumEtEcalIsoForEgammaSC_barrel_,
683 // sumEtEcalIsoForEgammaSC_endcap_,
684 // coneEcalIsoForEgammaSC_,
685 // sumPtTrackIsoForEgammaSC_barrel_,
686 // sumPtTrackIsoForEgammaSC_endcap_,
687 // nTrackIsoForEgammaSC_,
688 // coneTrackIsoForEgammaSC_);
689 }
690 
691 /*
692 void PFAlgo::setPFPhotonRegWeights(
693  const GBRForest *LCorrForest,
694  const GBRForest *GCorrForest,
695  const GBRForest *ResForest
696  ) {
697  if(usePFPhotons_)
698  pfpho_->setGBRForest(LCorrForest, GCorrForest, ResForest);
699 }
700 */
702  const GBRForest *LCorrForestEB,
703  const GBRForest *LCorrForestEE,
704  const GBRForest *GCorrForestBarrel,
705  const GBRForest *GCorrForestEndcapHr9,
706  const GBRForest *GCorrForestEndcapLr9, const GBRForest *PFEcalResolution
707  ){
708 
709  pfeg_->setGBRForest(LCorrForestEB,LCorrForestEE,
710  GCorrForestBarrel, GCorrForestEndcapHr9,
711  GCorrForestEndcapLr9, PFEcalResolution);
712 }
713 
714 void
716  const reco::VertexCollection* primaryVertices) {
717  useVertices_ = useVertex;
718 
719  //Set the vertices for muon cleaning
720 // pfmu_->setInputsForCleaning(primaryVertices);
721 
722 
723  //Now find the primary vertex!
724  //bool primaryVertexFound = false;
725  int nVtx=primaryVertices->size();
726  pfeg_->setnPU(nVtx);
727 // if(usePFPhotons_){
728 // pfpho_->setnPU(nVtx);
729 // }
730  primaryVertex_ = primaryVertices->front();
731  for (unsigned short i=0 ;i<primaryVertices->size();++i)
732  {
733  if(primaryVertices->at(i).isValid()&&(!primaryVertices->at(i).isFake()))
734  {
735  primaryVertex_ = primaryVertices->at(i);
736  //primaryVertexFound = true;
737  break;
738  }
739  }
740 
741  pfeg_->setPhotonPrimaryVtx(primaryVertex_ );
742 
743 }
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:42
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
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
Definition: CaloCluster.h:123
int i
Definition: DBlmapReader.cc:9
void setSuperClusterRef(reco::SuperClusterRef sc)
set reference to the corresponding supercluster
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:137
Type type() const
size_type size() const
Definition: OwnVector.h:247
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
list elements
Definition: asciidump.py:414
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
const edm::OwnVector< reco::PFBlockElement > & elements() const
Definition: PFBlock.h:107
void setPFPhotonRegWeights(const GBRForest *LCorrForestEB, const GBRForest *LCorrForestEE, const GBRForest *GCorrForestBarrel, const GBRForest *GCorrForestEndcapHr9, const GBRForest *GCorrForestEndcapLr9, const GBRForest *PFEcalResolution)
const ElementsInBlocks & elementsInBlocks() const
Definition: PFCandidate.h:365
int iEvent
Definition: GenABIO.cc:243
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
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
Definition: Vertex.h:40
double energy() const
cluster energy
Definition: CaloCluster.h:120
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
block
Formating index page&#39;s pieces.
Definition: Association.py:232
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
RefProd< PROD > getRefBeforePut()
Definition: Event.h:106
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
Definition: Point3D.h:13
const T & get() const
Definition: EventSetup.h:55
list blocks
Definition: gather_cfg.py:90
T const * product() const
Definition: ESHandle.h:62
T const * product() const
Definition: Handle.h:74
edm::EventID id() const
Definition: EventBase.h:56
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:35
void setPFEGammaExtraRef(const reco::PFCandidateEGammaExtraRef &ref)
set the PF EGamma Extra Ref
Definition: PFCandidate.cc:557
PFEGammaProducer(const edm::ParameterSet &)
void setSuperClusterRef(const reco::SuperClusterRef &scRef)
Definition: PFCandidate.cc:536
std::list< reco::PFBlockRef >::iterator IBR
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:242
virtual void produce(edm::Event &, const edm::EventSetup &) override
Definition: Run.h:36
Block of elements.
Definition: PFBlock.h:30