CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFProducer.cc
Go to the documentation of this file.
3 
20 
21 #include <sstream>
22 
23 #include "TFile.h"
24 
25 using namespace std;
26 
27 using namespace boost;
28 
29 using namespace edm;
30 
31 
32 
34 
35  //--ab: get calibration factors for HF:
36  bool calibHF_use;
37  std::vector<double> calibHF_eta_step;
38  std::vector<double> calibHF_a_EMonly;
39  std::vector<double> calibHF_b_HADonly;
40  std::vector<double> calibHF_a_EMHAD;
41  std::vector<double> calibHF_b_EMHAD;
42  calibHF_use = iConfig.getParameter<bool>("calibHF_use");
43  calibHF_eta_step = iConfig.getParameter<std::vector<double> >("calibHF_eta_step");
44  calibHF_a_EMonly = iConfig.getParameter<std::vector<double> >("calibHF_a_EMonly");
45  calibHF_b_HADonly = iConfig.getParameter<std::vector<double> >("calibHF_b_HADonly");
46  calibHF_a_EMHAD = iConfig.getParameter<std::vector<double> >("calibHF_a_EMHAD");
47  calibHF_b_EMHAD = iConfig.getParameter<std::vector<double> >("calibHF_b_EMHAD");
48  boost::shared_ptr<PFEnergyCalibrationHF>
49  thepfEnergyCalibrationHF ( new PFEnergyCalibrationHF(calibHF_use,calibHF_eta_step,calibHF_a_EMonly,calibHF_b_HADonly,calibHF_a_EMHAD,calibHF_b_EMHAD) ) ;
50  //-----------------
51 
52  inputTagBlocks_
53  = iConfig.getParameter<InputTag>("blocks");
54 
55  //Post cleaning of the muons
56  inputTagMuons_
57  = iConfig.getParameter<InputTag>("muons");
58  postMuonCleaning_
59  = iConfig.getParameter<bool>("postMuonCleaning");
60 
61  if( iConfig.existsAs<bool>("useEGammaFilters") ) {
62  use_EGammaFilters_ = iConfig.getParameter<bool>("useEGammaFilters");
63  } else {
64  use_EGammaFilters_ = false;
65  }
66 
67  usePFElectrons_
68  = iConfig.getParameter<bool>("usePFElectrons");
69 
70  usePFPhotons_
71  = iConfig.getParameter<bool>("usePFPhotons");
72 
73  // **************************** !! IMPORTANT !! ************************************
74  // When you code is swithed on, automatically turn off the old PFElectrons/PFPhotons.
75  // The two algorithms can not run at the same time
76  // *********************************************************************************
77 
78  if(use_EGammaFilters_) {
79  usePFElectrons_ = false;
80  usePFPhotons_ = false;
81  }
82 
83 
84  usePhotonReg_
85  = (usePFPhotons_) ? iConfig.getParameter<bool>("usePhotonReg") : false ;
86 
87  useRegressionFromDB_
88  = (usePFPhotons_) ? iConfig.getParameter<bool>("useRegressionFromDB") : false;
89 
90  useEGammaElectrons_
91  = iConfig.getParameter<bool>("useEGammaElectrons");
92 
93  if( useEGammaElectrons_) {
94  inputTagEgammaElectrons_ = iConfig.getParameter<edm::InputTag>("egammaElectrons");
95  }
96 
97  electronOutputCol_
98  = iConfig.getParameter<std::string>("pf_electron_output_col");
99 
100  bool usePFSCEleCalib;
101  std::vector<double> calibPFSCEle_Fbrem_barrel;
102  std::vector<double> calibPFSCEle_Fbrem_endcap;
103  std::vector<double> calibPFSCEle_barrel;
104  std::vector<double> calibPFSCEle_endcap;
105  usePFSCEleCalib = iConfig.getParameter<bool>("usePFSCEleCalib");
106  calibPFSCEle_Fbrem_barrel = iConfig.getParameter<std::vector<double> >("calibPFSCEle_Fbrem_barrel");
107  calibPFSCEle_Fbrem_endcap = iConfig.getParameter<std::vector<double> >("calibPFSCEle_Fbrem_endcap");
108  calibPFSCEle_barrel = iConfig.getParameter<std::vector<double> >("calibPFSCEle_barrel");
109  calibPFSCEle_endcap = iConfig.getParameter<std::vector<double> >("calibPFSCEle_endcap");
110  boost::shared_ptr<PFSCEnergyCalibration>
111  thePFSCEnergyCalibration ( new PFSCEnergyCalibration(calibPFSCEle_Fbrem_barrel,calibPFSCEle_Fbrem_endcap,
112  calibPFSCEle_barrel,calibPFSCEle_endcap ));
113 
114  bool useEGammaSupercluster = iConfig.getParameter<bool>("useEGammaSupercluster");
115  double sumEtEcalIsoForEgammaSC_barrel = iConfig.getParameter<double>("sumEtEcalIsoForEgammaSC_barrel");
116  double sumEtEcalIsoForEgammaSC_endcap = iConfig.getParameter<double>("sumEtEcalIsoForEgammaSC_endcap");
117  double coneEcalIsoForEgammaSC = iConfig.getParameter<double>("coneEcalIsoForEgammaSC");
118  double sumPtTrackIsoForEgammaSC_barrel = iConfig.getParameter<double>("sumPtTrackIsoForEgammaSC_barrel");
119  double sumPtTrackIsoForEgammaSC_endcap = iConfig.getParameter<double>("sumPtTrackIsoForEgammaSC_endcap");
120  double coneTrackIsoForEgammaSC = iConfig.getParameter<double>("coneTrackIsoForEgammaSC");
121  unsigned int nTrackIsoForEgammaSC = iConfig.getParameter<unsigned int>("nTrackIsoForEgammaSC");
122 
123 
124  // register products
125  produces<reco::PFCandidateCollection>();
126  produces<reco::PFCandidateCollection>("CleanedHF");
127  produces<reco::PFCandidateCollection>("CleanedCosmicsMuons");
128  produces<reco::PFCandidateCollection>("CleanedTrackerAndGlobalMuons");
129  produces<reco::PFCandidateCollection>("CleanedFakeMuons");
130  produces<reco::PFCandidateCollection>("CleanedPunchThroughMuons");
131  produces<reco::PFCandidateCollection>("CleanedPunchThroughNeutralHadrons");
132  produces<reco::PFCandidateCollection>("AddedMuonsAndHadrons");
133 
134 
135  if (usePFElectrons_) {
136  produces<reco::PFCandidateCollection>(electronOutputCol_);
137  produces<reco::PFCandidateElectronExtraCollection>(electronExtraOutputCol_);
138  }
139 
140  if (usePFPhotons_) {
141  produces<reco::PFCandidatePhotonExtraCollection>(photonExtraOutputCol_);
142  }
143 
144 
145  double nSigmaECAL
146  = iConfig.getParameter<double>("pf_nsigma_ECAL");
147  double nSigmaHCAL
148  = iConfig.getParameter<double>("pf_nsigma_HCAL");
149 
150  //PFElectrons Configuration
151  double mvaEleCut
152  = iConfig.getParameter<double>("pf_electron_mvaCut");
153 
154 
155  string mvaWeightFileEleID
156  = iConfig.getParameter<string>("pf_electronID_mvaWeightFile");
157 
158  bool applyCrackCorrectionsForElectrons
159  = iConfig.getParameter<bool>("pf_electronID_crackCorrection");
160 
161  string path_mvaWeightFileEleID;
162  if(usePFElectrons_)
163  {
164  path_mvaWeightFileEleID = edm::FileInPath ( mvaWeightFileEleID.c_str() ).fullPath();
165  }
166 
167  //PFPhoton Configuration
168 
169  string path_mvaWeightFileConvID;
170  string mvaWeightFileConvID;
171  string path_mvaWeightFileGCorr;
172  string path_mvaWeightFileLCorr;
173  string path_X0_Map;
174  string path_mvaWeightFileRes;
175  double mvaConvCut=-99.;
176  double sumPtTrackIsoForPhoton = 99.;
177  double sumPtTrackIsoSlopeForPhoton = 99.;
178 
179  if(usePFPhotons_ )
180  {
181  mvaWeightFileConvID =iConfig.getParameter<string>("pf_convID_mvaWeightFile");
182  mvaConvCut = iConfig.getParameter<double>("pf_conv_mvaCut");
183  path_mvaWeightFileConvID = edm::FileInPath ( mvaWeightFileConvID.c_str() ).fullPath();
184  sumPtTrackIsoForPhoton = iConfig.getParameter<double>("sumPtTrackIsoForPhoton");
185  sumPtTrackIsoSlopeForPhoton = iConfig.getParameter<double>("sumPtTrackIsoSlopeForPhoton");
186 
187  string X0_Map=iConfig.getParameter<string>("X0_Map");
188  path_X0_Map = edm::FileInPath( X0_Map.c_str() ).fullPath();
189 
190  if(!useRegressionFromDB_) {
191  string mvaWeightFileLCorr=iConfig.getParameter<string>("pf_locC_mvaWeightFile");
192  path_mvaWeightFileLCorr = edm::FileInPath( mvaWeightFileLCorr.c_str() ).fullPath();
193  string mvaWeightFileGCorr=iConfig.getParameter<string>("pf_GlobC_mvaWeightFile");
194  path_mvaWeightFileGCorr = edm::FileInPath( mvaWeightFileGCorr.c_str() ).fullPath();
195  string mvaWeightFileRes=iConfig.getParameter<string>("pf_Res_mvaWeightFile");
196  path_mvaWeightFileRes=edm::FileInPath(mvaWeightFileRes.c_str()).fullPath();
197 
198  TFile *fgbr = new TFile(path_mvaWeightFileGCorr.c_str(),"READ");
199  ReaderGC_ =(const GBRForest*)fgbr->Get("GBRForest");
200  TFile *fgbr2 = new TFile(path_mvaWeightFileLCorr.c_str(),"READ");
201  ReaderLC_ = (const GBRForest*)fgbr2->Get("GBRForest");
202  TFile *fgbr3 = new TFile(path_mvaWeightFileRes.c_str(),"READ");
203  ReaderRes_ = (const GBRForest*)fgbr3->Get("GBRForest");
204  LogDebug("PFProducer")<<"Will set regressions from binary files " <<endl;
205  }
206 
207  }
208 
209 
210  // Reading new EGamma selection cuts
211  bool useProtectionsForJetMET(false);
212  double ele_iso_pt(0.0), ele_iso_mva_barrel(0.0), ele_iso_mva_endcap(0.0),
213  ele_iso_combIso_barrel(0.0), ele_iso_combIso_endcap(0.0),
214  ele_noniso_mva(0.0);
215  unsigned int ele_missinghits(0);
216  double ph_MinEt(0.0), ph_combIso(0.0), ph_HoE(0.0),
217  ph_sietaieta_eb(0.0),ph_sietaieta_ee(0.0);
218  string ele_iso_mvaWeightFile(""), ele_iso_path_mvaWeightFile("");
219  edm::ParameterSet ele_protectionsForJetMET,ph_protectionsForJetMET;
220 
221  // Reading new EGamma ubiased collections and value maps
222  if(use_EGammaFilters_) {
223  ele_iso_mvaWeightFile = iConfig.getParameter<string>("isolatedElectronID_mvaWeightFile");
224  ele_iso_path_mvaWeightFile = edm::FileInPath ( ele_iso_mvaWeightFile.c_str() ).fullPath();
225  inputTagPFEGammaCandidates_ = iConfig.getParameter<edm::InputTag>("PFEGammaCandidates");
226  inputTagValueMapGedElectrons_ = iConfig.getParameter<edm::InputTag>("GedElectronValueMap");
227  inputTagValueMapGedPhotons_ = iConfig.getParameter<edm::InputTag>("GedPhotonValueMap");
228  ele_iso_pt = iConfig.getParameter<double>("electron_iso_pt");
229  ele_iso_mva_barrel = iConfig.getParameter<double>("electron_iso_mva_barrel");
230  ele_iso_mva_endcap = iConfig.getParameter<double>("electron_iso_mva_endcap");
231  ele_iso_combIso_barrel = iConfig.getParameter<double>("electron_iso_combIso_barrel");
232  ele_iso_combIso_endcap = iConfig.getParameter<double>("electron_iso_combIso_endcap");
233  ele_noniso_mva = iConfig.getParameter<double>("electron_noniso_mvaCut");
234  ele_missinghits = iConfig.getParameter<unsigned int>("electron_missinghits");
235  ph_MinEt = iConfig.getParameter<double>("photon_MinEt");
236  ph_combIso = iConfig.getParameter<double>("photon_combIso");
237  ph_HoE = iConfig.getParameter<double>("photon_HoE");
238  ph_sietaieta_eb = iConfig.getParameter<double>("photon_SigmaiEtaiEta_barrel");
239  ph_sietaieta_ee = iConfig.getParameter<double>("photon_SigmaiEtaiEta_endcap");
240  useProtectionsForJetMET =
241  iConfig.getParameter<bool>("useProtectionsForJetMET");
242  ele_protectionsForJetMET =
243  iConfig.getParameter<edm::ParameterSet>("electron_protectionsForJetMET");
244  ph_protectionsForJetMET =
245  iConfig.getParameter<edm::ParameterSet>("photon_protectionsForJetMET");
246  }
247 
248  //Secondary tracks and displaced vertices parameters
249 
250  bool rejectTracks_Bad
251  = iConfig.getParameter<bool>("rejectTracks_Bad");
252 
253  bool rejectTracks_Step45
254  = iConfig.getParameter<bool>("rejectTracks_Step45");
255 
256  bool usePFNuclearInteractions
257  = iConfig.getParameter<bool>("usePFNuclearInteractions");
258 
259  bool usePFConversions
260  = iConfig.getParameter<bool>("usePFConversions");
261 
262  bool usePFDecays
263  = iConfig.getParameter<bool>("usePFDecays");
264 
265  double dptRel_DispVtx
266  = iConfig.getParameter<double>("dptRel_DispVtx");
267 
268  edm::ParameterSet iCfgCandConnector
269  = iConfig.getParameter<edm::ParameterSet>("iCfgCandConnector");
270 
271 
272  // fToRead = iConfig.getUntrackedParameter<vector<string> >("toRead");
273 
274  useCalibrationsFromDB_
275  = iConfig.getParameter<bool>("useCalibrationsFromDB");
276 
277  boost::shared_ptr<PFEnergyCalibration>
278  calibration( new PFEnergyCalibration() );
279 
280  int algoType
281  = iConfig.getParameter<unsigned>("algoType");
282 
283  switch(algoType) {
284  case 0:
285  pfAlgo_.reset( new PFAlgo);
286  break;
287  default:
288  assert(0);
289  }
290 
291  pfAlgo_->setParameters( nSigmaECAL,
292  nSigmaHCAL,
293  calibration,
294  thepfEnergyCalibrationHF);
295 
296  //PFElectrons: call the method setpfeleparameters
297  pfAlgo_->setPFEleParameters(mvaEleCut,
298  path_mvaWeightFileEleID,
299  usePFElectrons_,
300  thePFSCEnergyCalibration,
301  calibration,
302  sumEtEcalIsoForEgammaSC_barrel,
303  sumEtEcalIsoForEgammaSC_endcap,
304  coneEcalIsoForEgammaSC,
305  sumPtTrackIsoForEgammaSC_barrel,
306  sumPtTrackIsoForEgammaSC_endcap,
307  nTrackIsoForEgammaSC,
308  coneTrackIsoForEgammaSC,
309  applyCrackCorrectionsForElectrons,
310  usePFSCEleCalib,
311  useEGammaElectrons_,
312  useEGammaSupercluster);
313 
314  // pfAlgo_->setPFConversionParameters(usePFConversions);
315 
316  // PFPhotons:
317  pfAlgo_->setPFPhotonParameters(usePFPhotons_,
318  path_mvaWeightFileConvID,
319  mvaConvCut,
320  usePhotonReg_,
321  path_X0_Map,
322  calibration,
323  sumPtTrackIsoForPhoton,
324  sumPtTrackIsoSlopeForPhoton);
325 
326 
327  // NEW EGamma Filters
328  pfAlgo_->setEGammaParameters(use_EGammaFilters_,
329  ele_iso_path_mvaWeightFile,
330  ele_iso_pt,
331  ele_iso_mva_barrel,
332  ele_iso_mva_endcap,
333  ele_iso_combIso_barrel,
334  ele_iso_combIso_endcap,
335  ele_noniso_mva,
336  ele_missinghits,
337  useProtectionsForJetMET,
338  ele_protectionsForJetMET,
339  ph_MinEt,
340  ph_combIso,
341  ph_HoE,
342  ph_sietaieta_eb,
343  ph_sietaieta_ee,
344  ph_protectionsForJetMET);
345 
346  //Secondary tracks and displaced vertices parameters
347 
348  pfAlgo_->setDisplacedVerticesParameters(rejectTracks_Bad,
349  rejectTracks_Step45,
350  usePFNuclearInteractions,
351  usePFConversions,
352  usePFDecays,
353  dptRel_DispVtx);
354 
355  if (usePFNuclearInteractions)
356  pfAlgo_->setCandConnectorParameters( iCfgCandConnector );
357 
358 
359 
360  // Set muon and fake track parameters
361  pfAlgo_->setPFMuonAndFakeParameters(iConfig);
362 
363  //Post cleaning of the HF
364  bool postHFCleaning
365  = iConfig.getParameter<bool>("postHFCleaning");
366  double minHFCleaningPt
367  = iConfig.getParameter<double>("minHFCleaningPt");
368  double minSignificance
369  = iConfig.getParameter<double>("minSignificance");
370  double maxSignificance
371  = iConfig.getParameter<double>("maxSignificance");
372  double minSignificanceReduction
373  = iConfig.getParameter<double>("minSignificanceReduction");
374  double maxDeltaPhiPt
375  = iConfig.getParameter<double>("maxDeltaPhiPt");
376  double minDeltaMet
377  = iConfig.getParameter<double>("minDeltaMet");
378 
379  // Set post HF cleaning muon parameters
380  pfAlgo_->setPostHFCleaningParameters(postHFCleaning,
381  minHFCleaningPt,
382  minSignificance,
383  maxSignificance,
384  minSignificanceReduction,
385  maxDeltaPhiPt,
386  minDeltaMet);
387 
388  // Input tags for HF cleaned rechits
389  inputTagCleanedHF_
390  = iConfig.getParameter< std::vector<edm::InputTag> >("cleanedHF");
391 
392  //MIKE: Vertex Parameters
393  vertices_ = iConfig.getParameter<edm::InputTag>("vertexCollection");
394  useVerticesForNeutral_ = iConfig.getParameter<bool>("useVerticesForNeutral");
395 
396  // Use HO clusters and links in the PF reconstruction
397  useHO_= iConfig.getParameter<bool>("useHO");
398  pfAlgo_->setHOTag(useHO_);
399 
400  verbose_ =
401  iConfig.getUntrackedParameter<bool>("verbose",false);
402 
403  bool debug_ =
404  iConfig.getUntrackedParameter<bool>("debug",false);
405 
406  pfAlgo_->setDebug( debug_ );
407 
408 }
409 
410 
411 
413 
414 void
416  const edm::EventSetup & es)
417 {
418 
419 
420  /*
421  static map<string, PerformanceResult::ResultType> functType;
422 
423  functType["PFfa_BARREL"] = PerformanceResult::PFfa_BARREL;
424  functType["PFfa_ENDCAP"] = PerformanceResult::PFfa_ENDCAP;
425  functType["PFfb_BARREL"] = PerformanceResult::PFfb_BARREL;
426  functType["PFfb_ENDCAP"] = PerformanceResult::PFfb_ENDCAP;
427  functType["PFfc_BARREL"] = PerformanceResult::PFfc_BARREL;
428  functType["PFfc_ENDCAP"] = PerformanceResult::PFfc_ENDCAP;
429  functType["PFfaEta_BARREL"] = PerformanceResult::PFfaEta_BARREL;
430  functType["PFfaEta_ENDCAP"] = PerformanceResult::PFfaEta_ENDCAP;
431  functType["PFfbEta_BARREL"] = PerformanceResult::PFfbEta_BARREL;
432  functType["PFfbEta_ENDCAP"] = PerformanceResult::PFfbEta_ENDCAP;
433  */
434 
435  if ( useCalibrationsFromDB_ ) {
436  // Read the PFCalibration functions from the global tags.
438  es.get<PFCalibrationRcd>().get(perfH);
439 
440  const PerformancePayloadFromTFormula *pfCalibrations = static_cast< const PerformancePayloadFromTFormula *>(perfH.product());
441 
442  pfAlgo_->thePFEnergyCalibration()->setCalibrationFunctions(pfCalibrations);
443  }
444 
445  /*
446  for(vector<string>::const_iterator name = fToRead.begin(); name != fToRead.end(); ++name) {
447 
448  cout << "Function: " << *name << endl;
449  PerformanceResult::ResultType fType = functType[*name];
450  pfCalibrations->printFormula(fType);
451 
452  // evaluate it @ 10 GeV
453  float energy = 10.;
454 
455  BinningPointByMap point;
456  point.insert(BinningVariables::JetEt, energy);
457 
458  if(pfCalibrations->isInPayload(fType, point)) {
459  float value = pfCalibrations->getResult(fType, point);
460  cout << " Energy before:: " << energy << " after: " << value << endl;
461  } else cout << "outside limits!" << endl;
462 
463  }
464  */
465 
466  if(useRegressionFromDB_) {
467  edm::ESHandle<GBRForest> readerPFLCEB;
468  edm::ESHandle<GBRForest> readerPFLCEE;
469  edm::ESHandle<GBRForest> readerPFGCEB;
470  edm::ESHandle<GBRForest> readerPFGCEEHR9;
471  edm::ESHandle<GBRForest> readerPFGCEELR9;
472  edm::ESHandle<GBRForest> readerPFRes;
473  es.get<GBRWrapperRcd>().get("PFLCorrectionBar",readerPFLCEB);
474  ReaderLCEB_=readerPFLCEB.product();
475  es.get<GBRWrapperRcd>().get("PFLCorrectionEnd",readerPFLCEE);
476  ReaderLCEE_=readerPFLCEE.product();
477  es.get<GBRWrapperRcd>().get("PFGCorrectionBar",readerPFGCEB);
478  ReaderGCBarrel_=readerPFGCEB.product();
479  es.get<GBRWrapperRcd>().get("PFGCorrectionEndHighR9",readerPFGCEEHR9);
480  ReaderGCEndCapHighr9_=readerPFGCEEHR9.product();
481  es.get<GBRWrapperRcd>().get("PFGCorrectionEndLowR9",readerPFGCEELR9);
482  ReaderGCEndCapLowr9_=readerPFGCEELR9.product();
483  es.get<GBRWrapperRcd>().get("PFEcalResolution",readerPFRes);
484  ReaderEcalRes_=readerPFRes.product();
485 
486  /*
487  LogDebug("PFProducer")<<"setting regressions from DB "<<endl;
488  */
489  }
490 
491  if(usePFPhotons_){
492  //pfAlgo_->setPFPhotonRegWeights(ReaderLC_, ReaderGC_, ReaderRes_);
493  pfAlgo_->setPFPhotonRegWeights(ReaderLCEB_,ReaderLCEE_,ReaderGCBarrel_,ReaderGCEndCapHighr9_, ReaderGCEndCapLowr9_, ReaderEcalRes_ );
494  }
495 }
496 
497 
498 void
500  const EventSetup& iSetup) {
501 
502  LogDebug("PFProducer")<<"START event: "
503  <<iEvent.id().event()
504  <<" in run "<<iEvent.id().run()<<endl;
505 
506 
507  // Get The vertices from the event
508  // and assign dynamic vertex parameters
510  bool gotVertices = iEvent.getByLabel(vertices_,vertices);
511  if(!gotVertices) {
512  ostringstream err;
513  err<<"Cannot find vertices for this event.Continuing Without them ";
514  LogError("PFProducer")<<err.str()<<endl;
515  }
516 
517  //Assign the PFAlgo Parameters
518  pfAlgo_->setPFVertexParameters(useVerticesForNeutral_,vertices.product());
519 
520  // get the collection of blocks
521 
523 
524  LogDebug("PFProducer")<<"getting blocks"<<endl;
525  bool found = iEvent.getByLabel( inputTagBlocks_, blocks );
526 
527  if(!found ) {
528 
529  ostringstream err;
530  err<<"cannot find blocks: "<<inputTagBlocks_;
531  LogError("PFProducer")<<err.str()<<endl;
532 
533  throw cms::Exception( "MissingProduct", err.str());
534  }
535 
536  // get the collection of muons
537 
539 
540  if ( postMuonCleaning_ ) {
541 
542  LogDebug("PFProducer")<<"getting muons"<<endl;
543  found = iEvent.getByLabel( inputTagMuons_, muons );
544  pfAlgo_->setMuonHandle(muons);
545  if(!found) {
546  ostringstream err;
547  err<<"cannot find muons: "<<inputTagMuons_;
548  LogError("PFProducer")<<err.str()<<endl;
549 
550  throw cms::Exception( "MissingProduct", err.str());
551 
552  }
553 
554  }
555 
556  if (useEGammaElectrons_) {
558 
559  LogDebug("PFProducer")<<" Reading e/gamma electrons activated "<<endl;
560  found = iEvent.getByLabel( inputTagEgammaElectrons_, egelectrons );
561 
562  if(!found) {
563  ostringstream err;
564  err<<"cannot find electrons: "<<inputTagEgammaElectrons_;
565  LogError("PFProducer")<<err.str()<<endl;
566 
567  throw cms::Exception( "MissingProduct", err.str());
568  }
569 
570  pfAlgo_->setEGElectronCollection(*egelectrons);
571  }
572 
573  if(use_EGammaFilters_) {
574 
575  // Read PFEGammaCandidates
576 
577  edm::Handle<edm::View<reco::PFCandidate> > pfEgammaCandidates;
578 
579  found=iEvent.getByLabel(inputTagPFEGammaCandidates_,pfEgammaCandidates);
580 
581  if(!found ) {
582  std::ostringstream err;
583  err<<" cannot get PFEGammaCandidates: "
584  << inputTagPFEGammaCandidates_ <<std::endl;
585  edm::LogError("PFProducer")<<err.str();
586  throw cms::Exception( "MissingProduct", err.str());
587  }
588 
589  // Get the value maps
590 
592  found = iEvent.getByLabel(inputTagValueMapGedElectrons_,valueMapGedElectrons);
593 
594  if(!found ) {
595  std::ostringstream err;
596  err<<" cannot get valueMapGedElectrons: "
597  << inputTagValueMapGedElectrons_ <<std::endl;
598  edm::LogError("PFProducer")<<err.str();
599  throw cms::Exception( "MissingProduct", err.str());
600  }
601 
602 
603  edm::Handle<edm::ValueMap<reco::PhotonRef> > valueMapGedPhotons;
604  found = iEvent.getByLabel(inputTagValueMapGedPhotons_,valueMapGedPhotons);
605 
606  if(!found ) {
607  std::ostringstream err;
608  err<<" cannot get valueMapGedPhotons: "
609  << inputTagValueMapGedPhotons_ <<std::endl;
610  edm::LogError("PFProducer")<<err.str();
611  throw cms::Exception( "MissingProduct", err.str());
612  }
613 
614  pfAlgo_->setEGammaCollections(*pfEgammaCandidates,
615  *valueMapGedElectrons,
616  *valueMapGedPhotons);
617 
618  }
619 
620 
621 
622  LogDebug("PFProducer")<<"particle flow is starting"<<endl;
623 
624  assert( blocks.isValid() );
625 
626  pfAlgo_->reconstructParticles( blocks );
627 
628  if(verbose_) {
629  ostringstream str;
630  str<<(*pfAlgo_)<<endl;
631  // cout << (*pfAlgo_) << endl;
632  LogInfo("PFProducer") <<str.str()<<endl;
633  }
634 
635 
636  // Florian 5/01/2011
637  // Save the PFElectron Extra Collection First as to be able to create valid References
638  if(usePFElectrons_) {
639  auto_ptr< reco::PFCandidateElectronExtraCollection >
640  pOutputElectronCandidateExtraCollection( pfAlgo_->transferElectronExtra() );
641 
643  iEvent.put(pOutputElectronCandidateExtraCollection,electronExtraOutputCol_);
644  pfAlgo_->setElectronExtraRef(electronExtraProd);
645  }
646 
647  // Daniele 18/05/2011
648  // Save the PFPhoton Extra Collection First as to be able to create valid References
649  if(usePFPhotons_) {
650  auto_ptr< reco::PFCandidatePhotonExtraCollection >
651  pOutputPhotonCandidateExtraCollection( pfAlgo_->transferPhotonExtra() );
652 
654  iEvent.put(pOutputPhotonCandidateExtraCollection,photonExtraOutputCol_);
655  pfAlgo_->setPhotonExtraRef(photonExtraProd);
656  }
657 
658  // Save cosmic cleaned muon candidates
659  auto_ptr< reco::PFCandidateCollection >
660  pCosmicsMuonCleanedCandidateCollection( pfAlgo_->getPFMuonAlgo()->transferCleanedCosmicCandidates() );
661  // Save tracker/global cleaned muon candidates
662  auto_ptr< reco::PFCandidateCollection >
663  pTrackerAndGlobalCleanedMuonCandidateCollection( pfAlgo_->getPFMuonAlgo()->transferCleanedTrackerAndGlobalCandidates() );
664  // Save fake cleaned muon candidates
665  auto_ptr< reco::PFCandidateCollection >
666  pFakeCleanedMuonCandidateCollection( pfAlgo_->getPFMuonAlgo()->transferCleanedFakeCandidates() );
667  // Save punch-through cleaned muon candidates
668  auto_ptr< reco::PFCandidateCollection >
669  pPunchThroughMuonCleanedCandidateCollection( pfAlgo_->getPFMuonAlgo()->transferPunchThroughCleanedMuonCandidates() );
670  // Save punch-through cleaned neutral hadron candidates
671  auto_ptr< reco::PFCandidateCollection >
672  pPunchThroughHadronCleanedCandidateCollection( pfAlgo_->getPFMuonAlgo()->transferPunchThroughCleanedHadronCandidates() );
673  // Save added muon candidates
674  auto_ptr< reco::PFCandidateCollection >
675  pAddedMuonCandidateCollection( pfAlgo_->getPFMuonAlgo()->transferAddedMuonCandidates() );
676 
677  // Check HF overcleaning
679  for ( unsigned ihf=0; ihf<inputTagCleanedHF_.size(); ++ihf ) {
681  bool foundHF = iEvent.getByLabel( inputTagCleanedHF_[ihf], hfCleaned );
682  if (!foundHF) continue;
683  for ( unsigned jhf=0; jhf<(*hfCleaned).size(); ++jhf ) {
684  hfCopy.push_back( (*hfCleaned)[jhf] );
685  }
686  }
687  pfAlgo_->checkCleaning( hfCopy );
688 
689  // Save recovered HF candidates
690  auto_ptr< reco::PFCandidateCollection >
691  pCleanedCandidateCollection( pfAlgo_->transferCleanedCandidates() );
692 
693 
694  // Save the final PFCandidate collection
695  auto_ptr< reco::PFCandidateCollection >
696  pOutputCandidateCollection( pfAlgo_->transferCandidates() );
697 
698 
699 
700  LogDebug("PFProducer")<<"particle flow: putting products in the event"<<endl;
701  if ( verbose_ ) std::cout <<"particle flow: putting products in the event. Here the full list"<<endl;
702  int nC=0;
703  for( reco::PFCandidateCollection::const_iterator itCand = (*pOutputCandidateCollection).begin(); itCand != (*pOutputCandidateCollection).end(); itCand++) {
704  nC++;
705  if (verbose_ ) std::cout << nC << ")" << (*itCand).particleId() << std::endl;
706 
707  }
708 
709 
710 
711  // Write in the event
712  iEvent.put(pOutputCandidateCollection);
713  iEvent.put(pCleanedCandidateCollection,"CleanedHF");
714 
715  if ( postMuonCleaning_ ) {
716  iEvent.put(pCosmicsMuonCleanedCandidateCollection,"CleanedCosmicsMuons");
717  iEvent.put(pTrackerAndGlobalCleanedMuonCandidateCollection,"CleanedTrackerAndGlobalMuons");
718  iEvent.put(pFakeCleanedMuonCandidateCollection,"CleanedFakeMuons");
719  iEvent.put(pPunchThroughMuonCleanedCandidateCollection,"CleanedPunchThroughMuons");
720  iEvent.put(pPunchThroughHadronCleanedCandidateCollection,"CleanedPunchThroughNeutralHadrons");
721  iEvent.put(pAddedMuonCandidateCollection,"AddedMuonsAndHadrons");
722  }
723 
724  if(usePFElectrons_)
725  {
726  auto_ptr< reco::PFCandidateCollection >
727  pOutputElectronCandidateCollection( pfAlgo_->transferElectronCandidates() );
728  iEvent.put(pOutputElectronCandidateCollection,electronOutputCol_);
729 
730  }
731 }
732 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:42
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:184
int ihf
std::vector< PFRecHit > PFRecHitCollection
collection of PFRecHit objects
Definition: PFRecHitFwd.h:9
virtual void produce(edm::Event &, const edm::EventSetup &) override
Definition: PFProducer.cc:499
PFProducer(const edm::ParameterSet &)
Definition: PFProducer.cc:33
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: PFProducer.cc:415
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
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:81
edm::EventID id() const
Definition: EventBase.h:56
tuple muons
Definition: patZpeak.py:38
tuple cout
Definition: gather_cfg.py:121
volatile std::atomic< bool > shutdown_flag false
Definition: PFAlgo.h:52
Definition: Run.h:41