CMS 3D CMS Logo

PFProducer.cc
Go to the documentation of this file.
3 
13 
14 #include <sstream>
15 
16 #include "TFile.h"
17 
18 using namespace std;
19 
20 using namespace boost;
21 
22 using namespace edm;
23 
24 
25 
27 
28  //--ab: get calibration factors for HF:
29  bool calibHF_use;
30  std::vector<double> calibHF_eta_step;
31  std::vector<double> calibHF_a_EMonly;
32  std::vector<double> calibHF_b_HADonly;
33  std::vector<double> calibHF_a_EMHAD;
34  std::vector<double> calibHF_b_EMHAD;
35  calibHF_use = iConfig.getParameter<bool>("calibHF_use");
36  calibHF_eta_step = iConfig.getParameter<std::vector<double> >("calibHF_eta_step");
37  calibHF_a_EMonly = iConfig.getParameter<std::vector<double> >("calibHF_a_EMonly");
38  calibHF_b_HADonly = iConfig.getParameter<std::vector<double> >("calibHF_b_HADonly");
39  calibHF_a_EMHAD = iConfig.getParameter<std::vector<double> >("calibHF_a_EMHAD");
40  calibHF_b_EMHAD = iConfig.getParameter<std::vector<double> >("calibHF_b_EMHAD");
41  boost::shared_ptr<PFEnergyCalibrationHF>
42  thepfEnergyCalibrationHF ( new PFEnergyCalibrationHF(calibHF_use,calibHF_eta_step,calibHF_a_EMonly,calibHF_b_HADonly,calibHF_a_EMHAD,calibHF_b_EMHAD) ) ;
43  //-----------------
44 
45  inputTagBlocks_ = consumes<reco::PFBlockCollection>(iConfig.getParameter<InputTag>("blocks"));
46 
47  //Post cleaning of the muons
48  inputTagMuons_ = consumes<reco::MuonCollection>(iConfig.getParameter<InputTag>("muons"));
49  postMuonCleaning_
50  = iConfig.getParameter<bool>("postMuonCleaning");
51 
52  if( iConfig.existsAs<bool>("useEGammaFilters") ) {
53  use_EGammaFilters_ = iConfig.getParameter<bool>("useEGammaFilters");
54  } else {
55  use_EGammaFilters_ = false;
56  }
57 
58  usePFElectrons_
59  = iConfig.getParameter<bool>("usePFElectrons");
60 
61  usePFPhotons_
62  = iConfig.getParameter<bool>("usePFPhotons");
63 
64  // **************************** !! IMPORTANT !! ************************************
65  // When you code is swithed on, automatically turn off the old PFElectrons/PFPhotons.
66  // The two algorithms can not run at the same time
67  // *********************************************************************************
68 
69  if(use_EGammaFilters_) {
70  usePFElectrons_ = false;
71  usePFPhotons_ = false;
72  }
73 
74 
75  usePhotonReg_
76  = (usePFPhotons_) ? iConfig.getParameter<bool>("usePhotonReg") : false ;
77 
78  useRegressionFromDB_
79  = (usePFPhotons_) ? iConfig.getParameter<bool>("useRegressionFromDB") : false;
80 
81  useEGammaElectrons_
82  = iConfig.getParameter<bool>("useEGammaElectrons");
83 
84  if( useEGammaElectrons_) {
85  inputTagEgammaElectrons_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("egammaElectrons"));
86  }
87 
88  electronOutputCol_
89  = iConfig.getParameter<std::string>("pf_electron_output_col");
90 
91  bool usePFSCEleCalib;
92  std::vector<double> calibPFSCEle_Fbrem_barrel;
93  std::vector<double> calibPFSCEle_Fbrem_endcap;
94  std::vector<double> calibPFSCEle_barrel;
95  std::vector<double> calibPFSCEle_endcap;
96  usePFSCEleCalib = iConfig.getParameter<bool>("usePFSCEleCalib");
97  calibPFSCEle_Fbrem_barrel = iConfig.getParameter<std::vector<double> >("calibPFSCEle_Fbrem_barrel");
98  calibPFSCEle_Fbrem_endcap = iConfig.getParameter<std::vector<double> >("calibPFSCEle_Fbrem_endcap");
99  calibPFSCEle_barrel = iConfig.getParameter<std::vector<double> >("calibPFSCEle_barrel");
100  calibPFSCEle_endcap = iConfig.getParameter<std::vector<double> >("calibPFSCEle_endcap");
101  boost::shared_ptr<PFSCEnergyCalibration>
102  thePFSCEnergyCalibration ( new PFSCEnergyCalibration(calibPFSCEle_Fbrem_barrel,calibPFSCEle_Fbrem_endcap,
103  calibPFSCEle_barrel,calibPFSCEle_endcap ));
104 
105  bool useEGammaSupercluster = iConfig.getParameter<bool>("useEGammaSupercluster");
106  double sumEtEcalIsoForEgammaSC_barrel = iConfig.getParameter<double>("sumEtEcalIsoForEgammaSC_barrel");
107  double sumEtEcalIsoForEgammaSC_endcap = iConfig.getParameter<double>("sumEtEcalIsoForEgammaSC_endcap");
108  double coneEcalIsoForEgammaSC = iConfig.getParameter<double>("coneEcalIsoForEgammaSC");
109  double sumPtTrackIsoForEgammaSC_barrel = iConfig.getParameter<double>("sumPtTrackIsoForEgammaSC_barrel");
110  double sumPtTrackIsoForEgammaSC_endcap = iConfig.getParameter<double>("sumPtTrackIsoForEgammaSC_endcap");
111  double coneTrackIsoForEgammaSC = iConfig.getParameter<double>("coneTrackIsoForEgammaSC");
112  unsigned int nTrackIsoForEgammaSC = iConfig.getParameter<unsigned int>("nTrackIsoForEgammaSC");
113 
114 
115  // register products
116  produces<reco::PFCandidateCollection>();
117  produces<reco::PFCandidateCollection>("CleanedHF");
118  produces<reco::PFCandidateCollection>("CleanedCosmicsMuons");
119  produces<reco::PFCandidateCollection>("CleanedTrackerAndGlobalMuons");
120  produces<reco::PFCandidateCollection>("CleanedFakeMuons");
121  produces<reco::PFCandidateCollection>("CleanedPunchThroughMuons");
122  produces<reco::PFCandidateCollection>("CleanedPunchThroughNeutralHadrons");
123  produces<reco::PFCandidateCollection>("AddedMuonsAndHadrons");
124 
125 
126  if (usePFElectrons_) {
127  produces<reco::PFCandidateCollection>(electronOutputCol_);
128  produces<reco::PFCandidateElectronExtraCollection>(electronExtraOutputCol_);
129  }
130 
131  if (usePFPhotons_) {
132  produces<reco::PFCandidatePhotonExtraCollection>(photonExtraOutputCol_);
133  }
134 
135 
136  double nSigmaECAL
137  = iConfig.getParameter<double>("pf_nsigma_ECAL");
138  double nSigmaHCAL
139  = iConfig.getParameter<double>("pf_nsigma_HCAL");
140 
141  //PFElectrons Configuration
142  double mvaEleCut
143  = iConfig.getParameter<double>("pf_electron_mvaCut");
144 
145 
146  string mvaWeightFileEleID
147  = iConfig.getParameter<string>("pf_electronID_mvaWeightFile");
148 
149  bool applyCrackCorrectionsForElectrons
150  = iConfig.getParameter<bool>("pf_electronID_crackCorrection");
151 
152  string path_mvaWeightFileEleID;
153  if(usePFElectrons_)
154  {
155  path_mvaWeightFileEleID = edm::FileInPath ( mvaWeightFileEleID.c_str() ).fullPath();
156  }
157 
158  //PFPhoton Configuration
159 
160  string path_mvaWeightFileConvID;
161  string mvaWeightFileConvID;
162  string path_mvaWeightFileGCorr;
163  string path_mvaWeightFileLCorr;
164  string path_X0_Map;
165  string path_mvaWeightFileRes;
166  double mvaConvCut=-99.;
167  double sumPtTrackIsoForPhoton = 99.;
168  double sumPtTrackIsoSlopeForPhoton = 99.;
169 
170  if(usePFPhotons_ )
171  {
172  mvaWeightFileConvID =iConfig.getParameter<string>("pf_convID_mvaWeightFile");
173  mvaConvCut = iConfig.getParameter<double>("pf_conv_mvaCut");
174  path_mvaWeightFileConvID = edm::FileInPath ( mvaWeightFileConvID.c_str() ).fullPath();
175  sumPtTrackIsoForPhoton = iConfig.getParameter<double>("sumPtTrackIsoForPhoton");
176  sumPtTrackIsoSlopeForPhoton = iConfig.getParameter<double>("sumPtTrackIsoSlopeForPhoton");
177 
178  string X0_Map=iConfig.getParameter<string>("X0_Map");
179  path_X0_Map = edm::FileInPath( X0_Map.c_str() ).fullPath();
180 
181  if(!useRegressionFromDB_) {
182  string mvaWeightFileLCorr=iConfig.getParameter<string>("pf_locC_mvaWeightFile");
183  path_mvaWeightFileLCorr = edm::FileInPath( mvaWeightFileLCorr.c_str() ).fullPath();
184  string mvaWeightFileGCorr=iConfig.getParameter<string>("pf_GlobC_mvaWeightFile");
185  path_mvaWeightFileGCorr = edm::FileInPath( mvaWeightFileGCorr.c_str() ).fullPath();
186  string mvaWeightFileRes=iConfig.getParameter<string>("pf_Res_mvaWeightFile");
187  path_mvaWeightFileRes=edm::FileInPath(mvaWeightFileRes.c_str()).fullPath();
188 
189  TFile *fgbr = new TFile(path_mvaWeightFileGCorr.c_str(),"READ");
190  ReaderGC_ =(const GBRForest*)fgbr->Get("GBRForest");
191  TFile *fgbr2 = new TFile(path_mvaWeightFileLCorr.c_str(),"READ");
192  ReaderLC_ = (const GBRForest*)fgbr2->Get("GBRForest");
193  TFile *fgbr3 = new TFile(path_mvaWeightFileRes.c_str(),"READ");
194  ReaderRes_ = (const GBRForest*)fgbr3->Get("GBRForest");
195  LogDebug("PFProducer")<<"Will set regressions from binary files " <<endl;
196  }
197 
198  }
199 
200 
201  // Reading new EGamma selection cuts
202  bool useProtectionsForJetMET(false);
203  double ele_iso_pt(0.0), ele_iso_mva_barrel(0.0), ele_iso_mva_endcap(0.0),
204  ele_iso_combIso_barrel(0.0), ele_iso_combIso_endcap(0.0),
205  ele_noniso_mva(0.0);
206  unsigned int ele_missinghits(0);
207  double ph_MinEt(0.0), ph_combIso(0.0), ph_HoE(0.0),
208  ph_sietaieta_eb(0.0),ph_sietaieta_ee(0.0);
209  string ele_iso_mvaWeightFile(""), ele_iso_path_mvaWeightFile("");
210  edm::ParameterSet ele_protectionsForJetMET,ele_protectionsForBadHcal,ph_protectionsForJetMET,ph_protectionsForBadHcal;
211  // Reading new EGamma ubiased collections and value maps
212  if(use_EGammaFilters_) {
213  ele_iso_mvaWeightFile = iConfig.getParameter<string>("isolatedElectronID_mvaWeightFile");
214  ele_iso_path_mvaWeightFile = edm::FileInPath ( ele_iso_mvaWeightFile.c_str() ).fullPath();
215  inputTagPFEGammaCandidates_ = consumes<edm::View<reco::PFCandidate> >((iConfig.getParameter<edm::InputTag>("PFEGammaCandidates")));
216  inputTagValueMapGedElectrons_ = consumes<edm::ValueMap<reco::GsfElectronRef>>(iConfig.getParameter<edm::InputTag>("GedElectronValueMap"));
217  inputTagValueMapGedPhotons_ = consumes<edm::ValueMap<reco::PhotonRef> >(iConfig.getParameter<edm::InputTag>("GedPhotonValueMap"));
218  ele_iso_pt = iConfig.getParameter<double>("electron_iso_pt");
219  ele_iso_mva_barrel = iConfig.getParameter<double>("electron_iso_mva_barrel");
220  ele_iso_mva_endcap = iConfig.getParameter<double>("electron_iso_mva_endcap");
221  ele_iso_combIso_barrel = iConfig.getParameter<double>("electron_iso_combIso_barrel");
222  ele_iso_combIso_endcap = iConfig.getParameter<double>("electron_iso_combIso_endcap");
223  ele_noniso_mva = iConfig.getParameter<double>("electron_noniso_mvaCut");
224  ele_missinghits = iConfig.getParameter<unsigned int>("electron_missinghits");
225  ph_MinEt = iConfig.getParameter<double>("photon_MinEt");
226  ph_combIso = iConfig.getParameter<double>("photon_combIso");
227  ph_HoE = iConfig.getParameter<double>("photon_HoE");
228  ph_sietaieta_eb = iConfig.getParameter<double>("photon_SigmaiEtaiEta_barrel");
229  ph_sietaieta_ee = iConfig.getParameter<double>("photon_SigmaiEtaiEta_endcap");
230  useProtectionsForJetMET =
231  iConfig.getParameter<bool>("useProtectionsForJetMET");
232  ele_protectionsForJetMET =
233  iConfig.getParameter<edm::ParameterSet>("electron_protectionsForJetMET");
234  ele_protectionsForBadHcal =
235  iConfig.getParameter<edm::ParameterSet>("electron_protectionsForBadHcal");
236  ph_protectionsForJetMET =
237  iConfig.getParameter<edm::ParameterSet>("photon_protectionsForJetMET");
238  ph_protectionsForBadHcal =
239  iConfig.getParameter<edm::ParameterSet>("photon_protectionsForBadHcal");
240  }
241 
242  //Secondary tracks and displaced vertices parameters
243 
244  bool rejectTracks_Bad
245  = iConfig.getParameter<bool>("rejectTracks_Bad");
246 
248  = iConfig.getParameter<bool>("rejectTracks_Step45");
249 
251  = iConfig.getParameter<bool>("usePFNuclearInteractions");
252 
253  bool usePFConversions
254  = iConfig.getParameter<bool>("usePFConversions");
255 
256  bool usePFDecays
257  = iConfig.getParameter<bool>("usePFDecays");
258 
259  double dptRel_DispVtx
260  = iConfig.getParameter<double>("dptRel_DispVtx");
261 
263  = iConfig.getParameter<edm::ParameterSet>("iCfgCandConnector");
264 
265 
266  // fToRead = iConfig.getUntrackedParameter<vector<string> >("toRead");
267 
268  useCalibrationsFromDB_
269  = iConfig.getParameter<bool>("useCalibrationsFromDB");
270 
271  if (useCalibrationsFromDB_)
272  calibrationsLabel_ = iConfig.getParameter<std::string>("calibrationsLabel");
273 
274  boost::shared_ptr<PFEnergyCalibration>
275  calibration( new PFEnergyCalibration() );
276 
277  int algoType
278  = iConfig.getParameter<unsigned>("algoType");
279 
280  switch(algoType) {
281  case 0:
282  pfAlgo_.reset( new PFAlgo);
283  break;
284  default:
285  assert(0);
286  }
287 
288  pfAlgo_->setParameters( nSigmaECAL,
289  nSigmaHCAL,
290  calibration,
291  thepfEnergyCalibrationHF);
292 
293  //PFElectrons: call the method setpfeleparameters
294  pfAlgo_->setPFEleParameters(mvaEleCut,
295  path_mvaWeightFileEleID,
296  usePFElectrons_,
297  thePFSCEnergyCalibration,
298  calibration,
299  sumEtEcalIsoForEgammaSC_barrel,
300  sumEtEcalIsoForEgammaSC_endcap,
301  coneEcalIsoForEgammaSC,
302  sumPtTrackIsoForEgammaSC_barrel,
303  sumPtTrackIsoForEgammaSC_endcap,
304  nTrackIsoForEgammaSC,
305  coneTrackIsoForEgammaSC,
306  applyCrackCorrectionsForElectrons,
307  usePFSCEleCalib,
308  useEGammaElectrons_,
309  useEGammaSupercluster);
310 
311  // pfAlgo_->setPFConversionParameters(usePFConversions);
312 
313  // PFPhotons:
314  pfAlgo_->setPFPhotonParameters(usePFPhotons_,
315  path_mvaWeightFileConvID,
316  mvaConvCut,
317  usePhotonReg_,
318  path_X0_Map,
319  calibration,
320  sumPtTrackIsoForPhoton,
321  sumPtTrackIsoSlopeForPhoton);
322 
323 
324  // NEW EGamma Filters
325  pfAlgo_->setEGammaParameters(use_EGammaFilters_,
326  ele_iso_path_mvaWeightFile,
327  ele_iso_pt,
328  ele_iso_mva_barrel,
329  ele_iso_mva_endcap,
330  ele_iso_combIso_barrel,
331  ele_iso_combIso_endcap,
332  ele_noniso_mva,
333  ele_missinghits,
334  useProtectionsForJetMET,
335  ele_protectionsForJetMET,
336  ele_protectionsForBadHcal,
337  ph_MinEt,
338  ph_combIso,
339  ph_HoE,
340  ph_sietaieta_eb,
341  ph_sietaieta_ee,
342  ph_protectionsForJetMET,
343  ph_protectionsForBadHcal);
344 
345  //Secondary tracks and displaced vertices parameters
346 
347  pfAlgo_->setDisplacedVerticesParameters(rejectTracks_Bad,
348  rejectTracks_Step45,
349  usePFNuclearInteractions,
350  usePFConversions,
351  usePFDecays,
352  dptRel_DispVtx);
353 
354  if (usePFNuclearInteractions)
355  pfAlgo_->setCandConnectorParameters( iCfgCandConnector );
356 
357 
358 
359  // Set muon and fake track parameters
360  pfAlgo_->setPFMuonAndFakeParameters(iConfig);
361  pfAlgo_->setBadHcalTrackParams(iConfig);
362 
363  //Post cleaning of the HF
364  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");
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  std::vector<edm::InputTag> tags =iConfig.getParameter< std::vector<edm::InputTag> >("cleanedHF");
390  for (unsigned int i=0;i<tags.size();++i)
391  inputTagCleanedHF_.push_back(consumes<reco::PFRecHitCollection>(tags[i]));
392  //MIKE: Vertex Parameters
393  vertices_ = consumes<reco::VertexCollection>(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(calibrationsLabel_, perfH);
439 
440  PerformancePayloadFromTFormula const * 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(usePFPhotons_ && 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.getByToken(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  iEvent.getByToken( inputTagBlocks_, blocks );
525 
526  // get the collection of muons
527 
529 
530  if ( postMuonCleaning_ ) {
531 
532  iEvent.getByToken( inputTagMuons_, muons );
533  pfAlgo_->setMuonHandle(muons);
534  }
535 
536  if (useEGammaElectrons_) {
538  iEvent.getByToken( inputTagEgammaElectrons_, egelectrons );
539  pfAlgo_->setEGElectronCollection(*egelectrons);
540  }
541 
542  if(use_EGammaFilters_) {
543 
544  // Read PFEGammaCandidates
545 
547  iEvent.getByToken(inputTagPFEGammaCandidates_,pfEgammaCandidates);
548 
549  // Get the value maps
550 
552  iEvent.getByToken(inputTagValueMapGedElectrons_,valueMapGedElectrons);
553 
554  edm::Handle<edm::ValueMap<reco::PhotonRef> > valueMapGedPhotons;
555  iEvent.getByToken(inputTagValueMapGedPhotons_,valueMapGedPhotons);
556 
557  pfAlgo_->setEGammaCollections(*pfEgammaCandidates,
558  *valueMapGedElectrons,
559  *valueMapGedPhotons);
560 
561  }
562 
563 
564  LogDebug("PFProducer")<<"particle flow is starting"<<endl;
565 
566  assert( blocks.isValid() );
567 
568  pfAlgo_->reconstructParticles( blocks );
569 
570  if(verbose_) {
571  ostringstream str;
572  str<<(*pfAlgo_)<<endl;
573  // cout << (*pfAlgo_) << endl;
574  LogInfo("PFProducer") <<str.str()<<endl;
575  }
576 
577 
578  // Florian 5/01/2011
579  // Save the PFElectron Extra Collection First as to be able to create valid References
580  if(usePFElectrons_) {
581  std::unique_ptr<reco::PFCandidateElectronExtraCollection> pOutputElectronCandidateExtraCollection( pfAlgo_->transferElectronExtra() );
582 
584  iEvent.put(std::move(pOutputElectronCandidateExtraCollection),electronExtraOutputCol_);
585  pfAlgo_->setElectronExtraRef(electronExtraProd);
586  }
587 
588  // Daniele 18/05/2011
589  // Save the PFPhoton Extra Collection First as to be able to create valid References
590  if(usePFPhotons_) {
591  std::unique_ptr<reco::PFCandidatePhotonExtraCollection> pOutputPhotonCandidateExtraCollection( pfAlgo_->transferPhotonExtra() );
592 
594  iEvent.put(std::move(pOutputPhotonCandidateExtraCollection),photonExtraOutputCol_);
595  pfAlgo_->setPhotonExtraRef(photonExtraProd);
596  }
597 
598  // Save cosmic cleaned muon candidates
599  std::unique_ptr<reco::PFCandidateCollection>
600  pCosmicsMuonCleanedCandidateCollection( pfAlgo_->getPFMuonAlgo()->transferCleanedCosmicCandidates() );
601  // Save tracker/global cleaned muon candidates
602  std::unique_ptr<reco::PFCandidateCollection>
603  pTrackerAndGlobalCleanedMuonCandidateCollection( pfAlgo_->getPFMuonAlgo()->transferCleanedTrackerAndGlobalCandidates() );
604  // Save fake cleaned muon candidates
605  std::unique_ptr<reco::PFCandidateCollection>
606  pFakeCleanedMuonCandidateCollection( pfAlgo_->getPFMuonAlgo()->transferCleanedFakeCandidates() );
607  // Save punch-through cleaned muon candidates
608  std::unique_ptr<reco::PFCandidateCollection>
609  pPunchThroughMuonCleanedCandidateCollection( pfAlgo_->getPFMuonAlgo()->transferPunchThroughCleanedMuonCandidates() );
610  // Save punch-through cleaned neutral hadron candidates
611  std::unique_ptr<reco::PFCandidateCollection>
612  pPunchThroughHadronCleanedCandidateCollection( pfAlgo_->getPFMuonAlgo()->transferPunchThroughCleanedHadronCandidates() );
613  // Save added muon candidates
614  std::unique_ptr<reco::PFCandidateCollection>
615  pAddedMuonCandidateCollection( pfAlgo_->getPFMuonAlgo()->transferAddedMuonCandidates() );
616 
617  // Check HF overcleaning
619  for ( unsigned ihf=0; ihf<inputTagCleanedHF_.size(); ++ihf ) {
621  bool foundHF = iEvent.getByToken( inputTagCleanedHF_[ihf], hfCleaned );
622  if (!foundHF) continue;
623  for ( unsigned jhf=0; jhf<(*hfCleaned).size(); ++jhf ) {
624  hfCopy.push_back( (*hfCleaned)[jhf] );
625  }
626  }
627 
628  if (postHFCleaning_)
629  pfAlgo_->checkCleaning( hfCopy );
630 
631  // Save recovered HF candidates
632  std::unique_ptr<reco::PFCandidateCollection> pCleanedCandidateCollection( pfAlgo_->transferCleanedCandidates() );
633 
634 
635  // Save the final PFCandidate collection
636  std::unique_ptr<reco::PFCandidateCollection> pOutputCandidateCollection( pfAlgo_->transferCandidates() );
637 
638 
639 
640  LogDebug("PFProducer")<<"particle flow: putting products in the event"<<endl;
641  if ( verbose_ ) std::cout <<"particle flow: putting products in the event. Here the full list"<<endl;
642  int nC=0;
643  for( reco::PFCandidateCollection::const_iterator itCand = (*pOutputCandidateCollection).begin(); itCand != (*pOutputCandidateCollection).end(); itCand++) {
644  nC++;
645  if (verbose_ ) std::cout << nC << ")" << (*itCand).particleId() << std::endl;
646 
647  }
648 
649 
650 
651  // Write in the event
652  iEvent.put(std::move(pOutputCandidateCollection));
653  iEvent.put(std::move(pCleanedCandidateCollection),"CleanedHF");
654 
655  if ( postMuonCleaning_ ) {
656  iEvent.put(std::move(pCosmicsMuonCleanedCandidateCollection),"CleanedCosmicsMuons");
657  iEvent.put(std::move(pTrackerAndGlobalCleanedMuonCandidateCollection),"CleanedTrackerAndGlobalMuons");
658  iEvent.put(std::move(pFakeCleanedMuonCandidateCollection),"CleanedFakeMuons");
659  iEvent.put(std::move(pPunchThroughMuonCleanedCandidateCollection),"CleanedPunchThroughMuons");
660  iEvent.put(std::move(pPunchThroughHadronCleanedCandidateCollection),"CleanedPunchThroughNeutralHadrons");
661  iEvent.put(std::move(pAddedMuonCandidateCollection),"AddedMuonsAndHadrons");
662  }
663 
664  if(usePFElectrons_)
665  {
666  std::unique_ptr<reco::PFCandidateCollection>
667  pOutputElectronCandidateCollection( pfAlgo_->transferElectronCandidates() );
668  iEvent.put(std::move(pOutputElectronCandidateCollection),electronOutputCol_);
669 
670  }
671 }
672 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
int ihf
Definition: CLHEP.h:16
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
~PFProducer() override
Definition: PFProducer.cc:412
std::vector< PFRecHit > PFRecHitCollection
collection of PFRecHit objects
Definition: PFRecHitFwd.h:9
void produce(edm::Event &, const edm::EventSetup &) override
Definition: PFProducer.cc:499
PFProducer(const edm::ParameterSet &)
Definition: PFProducer.cc:26
int iEvent
Definition: GenABIO.cc:230
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: PFProducer.cc:415
bool isValid() const
Definition: HandleBase.h:74
T const * product() const
Definition: Handle.h:81
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
T get() const
Definition: EventSetup.h:63
#define str(s)
Definition: PFAlgo.h:52
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:44