CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GEDPhotonProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <vector>
3 #include <memory>
4 
5 // Framework
9 
11 
16 
17 
29 
30 
33 
36 
39 
44 
45 namespace {
46  inline double ptFast( const double energy,
47  const math::XYZPoint& position,
48  const math::XYZPoint& origin ) {
49  const auto v = position - origin;
50  return energy*std::sqrt(v.perp2()/v.mag2());
51  }
52 }
53 
55 
56  conf_(config)
57 {
58 
59  // use configuration file to setup input/output collection names
60  //
61  photonProducer_ = conf_.getParameter<edm::InputTag>("photonProducer");
62  reconstructionStep_ = conf_.getParameter<std::string>("reconstructionStep");
63 
64  if ( reconstructionStep_ == "final" ) {
66  consumes<reco::PhotonCollection>(photonProducer_);
67  pfCandidates_ =
68  consumes<reco::PFCandidateCollection>(conf_.getParameter<edm::InputTag>("pfCandidates"));
69 
70  } else {
71 
73  consumes<reco::PhotonCoreCollection>(photonProducer_);
74 
75  }
76 
78  consumes<reco::PFCandidateCollection>(conf_.getParameter<edm::InputTag>("pfEgammaCandidates"));
80  consumes<EcalRecHitCollection>(conf_.getParameter<edm::InputTag>("barrelEcalHits"));
82  consumes<EcalRecHitCollection>(conf_.getParameter<edm::InputTag>("endcapEcalHits"));
84  consumes<EcalRecHitCollection>(conf_.getParameter<edm::InputTag>("preshowerHits"));
86  consumes<reco::VertexCollection>(conf_.getParameter<edm::InputTag>("primaryVertexProducer"));
87 
88  hcalTowers_ =
89  consumes<CaloTowerCollection>(conf_.getParameter<edm::InputTag>("hcalTowers"));
90  //
91  photonCollection_ = conf_.getParameter<std::string>("outputPhotonCollection");
92  hOverEConeSize_ = conf_.getParameter<double>("hOverEConeSize");
93  highEt_ = conf_.getParameter<double>("highEt");
94  // R9 value to decide converted/unconverted
95  minR9Barrel_ = conf_.getParameter<double>("minR9Barrel");
96  minR9Endcap_ = conf_.getParameter<double>("minR9Endcap");
97  usePrimaryVertex_ = conf_.getParameter<bool>("usePrimaryVertex");
98  runMIPTagger_ = conf_.getParameter<bool>("runMIPTagger");
99 
100  candidateP4type_ = config.getParameter<std::string>("candidateP4type") ;
101  valueMapPFCandPhoton_ = config.getParameter<std::string>("valueMapPhotons");
102 
103 
105  config.getParameter<edm::ParameterSet>("posCalcParameters");
106  posCalculator_ = PositionCalc(posCalcParameters);
107 
108 
109  //AA
110  //Flags and Severities to be excluded from photon calculations
111  const std::vector<std::string> flagnamesEB =
112  config.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEB");
113 
114  const std::vector<std::string> flagnamesEE =
115  config.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEE");
116 
117  flagsexclEB_=
118  StringToEnumValue<EcalRecHit::Flags>(flagnamesEB);
119 
120  flagsexclEE_=
121  StringToEnumValue<EcalRecHit::Flags>(flagnamesEE);
122 
123  const std::vector<std::string> severitynamesEB =
124  config.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEB");
125 
127  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEB);
128 
129  const std::vector<std::string> severitynamesEE =
130  config.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEE");
131 
133  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEE);
134 
137  if( conf_.existsAs<edm::ParameterSet>("regressionConfig") ) {
138  auto sumes = consumesCollector();
139  thePhotonEnergyCorrector_->gedRegression()->setConsumes(sumes);
140  }
141 
142  //AA
143 
144  //
145 
146  // Parameters for the position calculation:
147  // std::map<std::string,double> providedParameters;
148  // providedParameters.insert(std::make_pair("LogWeighted",conf_.getParameter<bool>("posCalc_logweight")));
149  //providedParameters.insert(std::make_pair("T0_barl",conf_.getParameter<double>("posCalc_t0_barl")));
150  //providedParameters.insert(std::make_pair("T0_endc",conf_.getParameter<double>("posCalc_t0_endc")));
151  //providedParameters.insert(std::make_pair("T0_endcPresh",conf_.getParameter<double>("posCalc_t0_endcPresh")));
152  //providedParameters.insert(std::make_pair("W0",conf_.getParameter<double>("posCalc_w0")));
153  //providedParameters.insert(std::make_pair("X0",conf_.getParameter<double>("posCalc_x0")));
154  //posCalculator_ = PositionCalc(providedParameters);
155  // cut values for pre-selection
156  preselCutValuesBarrel_.push_back(conf_.getParameter<double>("minSCEtBarrel"));
157  preselCutValuesBarrel_.push_back(conf_.getParameter<double>("maxHoverEBarrel"));
158  preselCutValuesBarrel_.push_back(conf_.getParameter<double>("ecalRecHitSumEtOffsetBarrel"));
159  preselCutValuesBarrel_.push_back(conf_.getParameter<double>("ecalRecHitSumEtSlopeBarrel"));
160  preselCutValuesBarrel_.push_back(conf_.getParameter<double>("hcalTowerSumEtOffsetBarrel"));
161  preselCutValuesBarrel_.push_back(conf_.getParameter<double>("hcalTowerSumEtSlopeBarrel"));
162  preselCutValuesBarrel_.push_back(conf_.getParameter<double>("nTrackSolidConeBarrel"));
163  preselCutValuesBarrel_.push_back(conf_.getParameter<double>("nTrackHollowConeBarrel"));
164  preselCutValuesBarrel_.push_back(conf_.getParameter<double>("trackPtSumSolidConeBarrel"));
165  preselCutValuesBarrel_.push_back(conf_.getParameter<double>("trackPtSumHollowConeBarrel"));
166  preselCutValuesBarrel_.push_back(conf_.getParameter<double>("sigmaIetaIetaCutBarrel"));
167  //
168  preselCutValuesEndcap_.push_back(conf_.getParameter<double>("minSCEtEndcap"));
169  preselCutValuesEndcap_.push_back(conf_.getParameter<double>("maxHoverEEndcap"));
170  preselCutValuesEndcap_.push_back(conf_.getParameter<double>("ecalRecHitSumEtOffsetEndcap"));
171  preselCutValuesEndcap_.push_back(conf_.getParameter<double>("ecalRecHitSumEtSlopeEndcap"));
172  preselCutValuesEndcap_.push_back(conf_.getParameter<double>("hcalTowerSumEtOffsetEndcap"));
173  preselCutValuesEndcap_.push_back(conf_.getParameter<double>("hcalTowerSumEtSlopeEndcap"));
174  preselCutValuesEndcap_.push_back(conf_.getParameter<double>("nTrackSolidConeEndcap"));
175  preselCutValuesEndcap_.push_back(conf_.getParameter<double>("nTrackHollowConeEndcap"));
176  preselCutValuesEndcap_.push_back(conf_.getParameter<double>("trackPtSumSolidConeEndcap"));
177  preselCutValuesEndcap_.push_back(conf_.getParameter<double>("trackPtSumHollowConeEndcap"));
178  preselCutValuesEndcap_.push_back(conf_.getParameter<double>("sigmaIetaIetaCutEndcap"));
179  //
180 
181  //moved from beginRun to here, I dont see how this could cause harm as its just reading in the exactly same parameters each run
182  if ( reconstructionStep_ != "final"){
184  edm::ParameterSet isolationSumsCalculatorSet = conf_.getParameter<edm::ParameterSet>("isolationSumsCalculatorSet");
185  thePhotonIsolationCalculator_->setup(isolationSumsCalculatorSet, flagsexclEB_, flagsexclEE_, severitiesexclEB_, severitiesexclEE_,consumesCollector());
187  edm::ParameterSet mipVariableSet = conf_.getParameter<edm::ParameterSet>("mipVariableSet");
189 
190  }else{
193  }
194  // Register the product
195  produces< reco::PhotonCollection >(photonCollection_);
196  produces< edm::ValueMap<reco::PhotonRef> > (valueMapPFCandPhoton_);
197 
198 
199 }
200 
202 {
206  //delete energyCorrectionF;
207 }
208 
209 
210 
211 void GEDPhotonProducer::beginRun (edm::Run const& r, edm::EventSetup const & theEventSetup) {
212 
213  if ( reconstructionStep_ == "final" ) {
215  edm::ParameterSet pfIsolationCalculatorSet = conf_.getParameter<edm::ParameterSet>("PFIsolationCalculatorSet");
216  thePFBasedIsolationCalculator_->setup(pfIsolationCalculatorSet);
217  }else{
218  thePhotonEnergyCorrector_ -> init(theEventSetup);
219  }
220 
221 }
222 
223 void GEDPhotonProducer::endRun (edm::Run const& r, edm::EventSetup const & theEventSetup) {
224 
225  if ( reconstructionStep_ == "final" ) {
227  }
228 }
229 
230 
231 void GEDPhotonProducer::produce(edm::Event& theEvent, const edm::EventSetup& theEventSetup) {
232 
233  using namespace edm;
234  // nEvt_++;
235 
236  reco::PhotonCollection outputPhotonCollection;
237  std::auto_ptr< reco::PhotonCollection > outputPhotonCollection_p(new reco::PhotonCollection);
238  edm::ValueMap<reco::PhotonRef> pfEGCandToPhotonMap;
239 
240 
241  // Get the PhotonCore collection
242  bool validPhotonCoreHandle=false;
243  Handle<reco::PhotonCoreCollection> photonCoreHandle;
244  bool validPhotonHandle= false;
245  Handle<reco::PhotonCollection> photonHandle;
246 
247  if ( reconstructionStep_ == "final" ) {
248  theEvent.getByToken(photonProducerT_,photonHandle);
249  if ( photonHandle.isValid()) {
250  validPhotonHandle=true;
251  } else {
252  throw cms::Exception("GEDPhotonProducer") << "Error! Can't get the product " << photonProducer_.label() << "\n";
253  }
254  } else {
255 
256  theEvent.getByToken(photonCoreProducerT_,photonCoreHandle);
257  if (photonCoreHandle.isValid()) {
258  validPhotonCoreHandle=true;
259  } else {
260  throw cms::Exception("GEDPhotonProducer")
261  << "Error! Can't get the photonCoreProducer" << photonProducer_.label() << "\n";
262  }
263  }
264 
265  // Get EcalRecHits
266  bool validEcalRecHits=true;
267  Handle<EcalRecHitCollection> barrelHitHandle;
268  const EcalRecHitCollection dummyEB;
269  theEvent.getByToken(barrelEcalHits_, barrelHitHandle);
270  if (!barrelHitHandle.isValid()) {
271  validEcalRecHits=false;
272  throw cms::Exception("GEDPhotonProducer")
273  << "Error! Can't get the barrelEcalHits";
274  }
275  const EcalRecHitCollection& barrelRecHits(validEcalRecHits ? *(barrelHitHandle.product()) : dummyEB);
276 
277  Handle<EcalRecHitCollection> endcapHitHandle;
278  theEvent.getByToken(endcapEcalHits_, endcapHitHandle);
279  const EcalRecHitCollection dummyEE;
280  if (!endcapHitHandle.isValid()) {
281  validEcalRecHits=false;
282  throw cms::Exception("GEDPhotonProducer")
283  << "Error! Can't get the endcapEcalHits";
284  }
285  const EcalRecHitCollection& endcapRecHits(validEcalRecHits ? *(endcapHitHandle.product()) : dummyEE);
286 
287  bool validPreshowerRecHits=true;
288  Handle<EcalRecHitCollection> preshowerHitHandle;
289  theEvent.getByToken(preshowerHits_, preshowerHitHandle);
290  EcalRecHitCollection preshowerRecHits;
291  if (!preshowerHitHandle.isValid()) {
292  validPreshowerRecHits=false;
293  throw cms::Exception("GEDPhotonProducer")
294  << "Error! Can't get the preshowerEcalHits";
295  }
296  if( validPreshowerRecHits ) preshowerRecHits = *(preshowerHitHandle.product());
297 
298 
299 
300  Handle<reco::PFCandidateCollection> pfEGCandidateHandle;
301  // Get the PF refined cluster collection
302  theEvent.getByToken(pfEgammaCandidates_,pfEGCandidateHandle);
303  if (!pfEGCandidateHandle.isValid()) {
304  throw cms::Exception("GEDPhotonProducer")
305  << "Error! Can't get the pfEgammaCandidates";
306  }
307 
308  Handle<reco::PFCandidateCollection> pfCandidateHandle;
309 
310  if ( reconstructionStep_ == "final" ) {
311  // Get the PF candidates collection
312  theEvent.getByToken(pfCandidates_,pfCandidateHandle);
313  if (!pfCandidateHandle.isValid()) {
314  throw cms::Exception("GEDPhotonProducer")
315  << "Error! Can't get the pfCandidates";
316  }
317  }
318 
319  //AA
320  //Get the severity level object
322  theEventSetup.get<EcalSeverityLevelAlgoRcd>().get(sevLv);
323  //
324 
325 
326 // get Hcal towers collection
327  Handle<CaloTowerCollection> hcalTowersHandle;
328  theEvent.getByToken(hcalTowers_, hcalTowersHandle);
329 
330 
331  // get the geometry from the event setup:
332  theEventSetup.get<CaloGeometryRecord>().get(theCaloGeom_);
333 
334  //
335  // update energy correction function
336  // energyCorrectionF->init(theEventSetup);
337 
338  edm::ESHandle<CaloTopology> pTopology;
339  theEventSetup.get<CaloTopologyRecord>().get(theCaloTopo_);
341 
342  // Get the primary event vertex
343  Handle<reco::VertexCollection> vertexHandle;
344  const reco::VertexCollection dummyVC;
345  bool validVertex=true;
346  if ( usePrimaryVertex_ ) {
347  theEvent.getByToken(vertexProducer_, vertexHandle);
348  if (!vertexHandle.isValid()) {
349  validVertex=false;
350  throw cms::Exception("GEDPhotonProducer")
351  << "Error! Can't get the product primary Vertex Collection";
352  }
353  }
354  const reco::VertexCollection& vertexCollection(usePrimaryVertex_ && validVertex ? *(vertexHandle.product()) : dummyVC);
355 
356  // math::XYZPoint vtx(0.,0.,0.);
357  //if (vertexCollection.size()>0) vtx = vertexCollection.begin()->position();
358 
359  // get the regression calculator ready
360  thePhotonEnergyCorrector_->init(theEventSetup);
362  thePhotonEnergyCorrector_->gedRegression()->setEvent(theEvent);
363  thePhotonEnergyCorrector_->gedRegression()->setEventContent(theEventSetup);
364  }
365 
366 
367  int iSC=0; // index in photon collection
368  // Loop over barrel and endcap SC collections and fill the photon collection
369  if ( validPhotonCoreHandle)
370  fillPhotonCollection(theEvent,
371  theEventSetup,
372  photonCoreHandle,
373  topology,
374  &barrelRecHits,
375  &endcapRecHits,
376  &preshowerRecHits,
377  hcalTowersHandle,
378  //vtx,
379  vertexCollection,
380  outputPhotonCollection,
381  iSC);
382 
383  iSC=0;
384  if ( validPhotonHandle && reconstructionStep_ == "final" )
385  fillPhotonCollection(theEvent,
386  theEventSetup,
387  photonHandle,
388  pfCandidateHandle,
389  pfEGCandidateHandle,
390  pfEGCandToPhotonMap,
391  vertexHandle,
392  outputPhotonCollection,
393  iSC);
394 
395 
396 
397  // put the product in the event
398  edm::LogInfo("GEDPhotonProducer") << " Put in the event " << iSC << " Photon Candidates \n";
399  outputPhotonCollection_p->assign(outputPhotonCollection.begin(),outputPhotonCollection.end());
400  const edm::OrphanHandle<reco::PhotonCollection> photonOrphHandle = theEvent.put(outputPhotonCollection_p, photonCollection_);
401 
402 
403  if ( reconstructionStep_ != "final" ) {
405  std::auto_ptr<edm::ValueMap<reco::PhotonRef> > pfEGCandToPhotonMap_p(new edm::ValueMap<reco::PhotonRef>());
406  edm::ValueMap<reco::PhotonRef>::Filler filler(*pfEGCandToPhotonMap_p);
407  unsigned nObj = pfEGCandidateHandle->size();
408  std::vector<reco::PhotonRef> values(nObj);
410  for(unsigned int lCand=0; lCand < nObj; lCand++) {
411  reco::PFCandidateRef pfCandRef (reco::PFCandidateRef(pfEGCandidateHandle,lCand));
412  reco::SuperClusterRef pfScRef = pfCandRef -> superClusterRef();
413 
414  for(unsigned int lSC=0; lSC < photonOrphHandle->size(); lSC++) {
415  reco::PhotonRef photonRef(reco::PhotonRef(photonOrphHandle, lSC));
416  reco::SuperClusterRef scRef=photonRef->superCluster();
417  if ( pfScRef != scRef ) continue;
418  values[lCand] = photonRef;
419  }
420  }
421 
422 
423  filler.insert(pfEGCandidateHandle,values.begin(),values.end());
424  filler.fill();
425  theEvent.put(pfEGCandToPhotonMap_p,valueMapPFCandPhoton_);
426 
427 
428  }
429 
430 
431 
432 
433 
434 
435 }
436 
438  edm::EventSetup const & es,
439  const edm::Handle<reco::PhotonCoreCollection> & photonCoreHandle,
440  const CaloTopology* topology,
441  const EcalRecHitCollection* ecalBarrelHits,
442  const EcalRecHitCollection* ecalEndcapHits,
443  const EcalRecHitCollection* preshowerHits,
444  const edm::Handle<CaloTowerCollection> & hcalTowersHandle,
446  reco::PhotonCollection & outputPhotonCollection, int& iSC) {
447 
448 
450  const EcalRecHitCollection* hits = 0 ;
451  std::vector<double> preselCutValues;
452  std::vector<int> flags_, severitiesexcl_;
453 
454  for(unsigned int lSC=0; lSC < photonCoreHandle->size(); lSC++) {
455 
456  reco::PhotonCoreRef coreRef(reco::PhotonCoreRef(photonCoreHandle, lSC));
457  reco::SuperClusterRef parentSCRef = coreRef->parentSuperCluster();
458  reco::SuperClusterRef scRef=coreRef->superCluster();
459 
460 
461 
462  // const reco::SuperCluster* pClus=&(*scRef);
463  iSC++;
464 
465  int subdet = scRef->seed()->hitsAndFractions()[0].first.subdetId();
466  if (subdet==EcalBarrel) {
467  preselCutValues = preselCutValuesBarrel_;
468  hits = ecalBarrelHits;
469  flags_ = flagsexclEB_;
470  severitiesexcl_ = severitiesexclEB_;
471  } else if (subdet==EcalEndcap) {
472  preselCutValues = preselCutValuesEndcap_;
473  hits = ecalEndcapHits;
474  flags_ = flagsexclEE_;
475  severitiesexcl_ = severitiesexclEE_;
476  } else {
477  edm::LogWarning("")<<"GEDPhotonProducer: do not know if it is a barrel or endcap SuperCluster";
478  }
479 
480 
481 
482 
483  // SC energy preselection
484  if (parentSCRef.isNonnull() &&
485  ptFast(parentSCRef->energy(),parentSCRef->position(),math::XYZPoint(0,0,0)) <= preselCutValues[0] ) continue;
486  // calculate HoE
487 
488  const CaloTowerCollection* hcalTowersColl = hcalTowersHandle.product();
489  EgammaTowerIsolation towerIso1(hOverEConeSize_,0.,0.,1,hcalTowersColl) ;
490  EgammaTowerIsolation towerIso2(hOverEConeSize_,0.,0.,2,hcalTowersColl) ;
491  double HoE1=towerIso1.getTowerESum(&(*scRef))/scRef->energy();
492  double HoE2=towerIso2.getTowerESum(&(*scRef))/scRef->energy();
493 
494  EgammaHadTower towerIsoBehindClus(es);
495  towerIsoBehindClus.setTowerCollection(hcalTowersHandle.product());
496  std::vector<CaloTowerDetId> TowersBehindClus = towerIsoBehindClus.towersOf(*scRef);
497  float hcalDepth1OverEcalBc = towerIsoBehindClus.getDepth1HcalESum(TowersBehindClus)/scRef->energy();
498  float hcalDepth2OverEcalBc = towerIsoBehindClus.getDepth2HcalESum(TowersBehindClus)/scRef->energy();
499  // std::cout << " GEDPhotonProducer calculation of HoE with towers in a cone " << HoE1 << " " << HoE2 << std::endl;
500  //std::cout << " GEDPhotonProducer calcualtion of HoE with towers behind the BCs " << hcalDepth1OverEcalBc << " " << hcalDepth2OverEcalBc << std::endl;
501 
502  float maxXtal = EcalClusterTools::eMax( *(scRef->seed()), &(*hits) );
503  //AA
504  //Change these to consider severity level of hits
505  float e1x5 = EcalClusterTools::e1x5( *(scRef->seed()), &(*hits), &(*topology));
506  float e2x5 = EcalClusterTools::e2x5Max( *(scRef->seed()), &(*hits), &(*topology));
507  float e3x3 = EcalClusterTools::e3x3( *(scRef->seed()), &(*hits), &(*topology));
508  float e5x5 = EcalClusterTools::e5x5( *(scRef->seed()), &(*hits), &(*topology));
509  std::vector<float> cov = EcalClusterTools::covariances( *(scRef->seed()), &(*hits), &(*topology), geometry);
510  std::vector<float> locCov = EcalClusterTools::localCovariances( *(scRef->seed()), &(*hits), &(*topology));
511 
512  float sigmaEtaEta = sqrt(cov[0]);
513  float sigmaIetaIeta = sqrt(locCov[0]);
514 
515  float full5x5_maxXtal = noZS::EcalClusterTools::eMax( *(scRef->seed()), &(*hits) );
516  //AA
517  //Change these to consider severity level of hits
518  float full5x5_e1x5 = noZS::EcalClusterTools::e1x5( *(scRef->seed()), &(*hits), &(*topology));
519  float full5x5_e2x5 = noZS::EcalClusterTools::e2x5Max( *(scRef->seed()), &(*hits), &(*topology));
520  float full5x5_e3x3 = noZS::EcalClusterTools::e3x3( *(scRef->seed()), &(*hits), &(*topology));
521  float full5x5_e5x5 = noZS::EcalClusterTools::e5x5( *(scRef->seed()), &(*hits), &(*topology));
522  std::vector<float> full5x5_cov = noZS::EcalClusterTools::covariances( *(scRef->seed()), &(*hits), &(*topology), geometry);
523  std::vector<float> full5x5_locCov = noZS::EcalClusterTools::localCovariances( *(scRef->seed()), &(*hits), &(*topology));
524 
525  float full5x5_sigmaEtaEta = sqrt(full5x5_cov[0]);
526  float full5x5_sigmaIetaIeta = sqrt(full5x5_locCov[0]);
527 
528  // compute position of ECAL shower
529  math::XYZPoint caloPosition = scRef->position();
530 
531 
533  double photonEnergy=1.;
534  math::XYZPoint vtx(0.,0.,0.);
535  if (vertexCollection.size()>0) vtx = vertexCollection.begin()->position();
536  // compute momentum vector of photon from primary vertex and cluster position
537  math::XYZVector direction = caloPosition - vtx;
538  //math::XYZVector momentum = direction.unit() * photonEnergy ;
539  math::XYZVector momentum = direction.unit() ;
540 
541  // Create dummy candidate with unit momentum and zero energy to allow setting of all variables. The energy is set for last.
542  math::XYZTLorentzVectorD p4(momentum.x(), momentum.y(), momentum.z(), photonEnergy );
543  reco::Photon newCandidate(p4, caloPosition, coreRef, vtx);
544 
545  //std::cout << " standard p4 before " << newCandidate.p4() << " energy " << newCandidate.energy() << std::endl;
546  //std::cout << " type " <<newCandidate.getCandidateP4type() << " standard p4 after " << newCandidate.p4() << " energy " << newCandidate.energy() << std::endl;
547 
548  // Calculate fiducial flags and isolation variable. Blocked are filled from the isolationCalculator
549  reco::Photon::FiducialFlags fiducialFlags;
550  reco::Photon::IsolationVariables isolVarR03, isolVarR04;
551  thePhotonIsolationCalculator_-> calculate ( &newCandidate,evt,es,fiducialFlags,isolVarR04, isolVarR03);
552  newCandidate.setFiducialVolumeFlags( fiducialFlags );
553  newCandidate.setIsolationVariables(isolVarR04, isolVarR03 );
554 
556  reco::Photon::ShowerShape showerShape;
557  showerShape.e1x5= e1x5;
558  showerShape.e2x5= e2x5;
559  showerShape.e3x3= e3x3;
560  showerShape.e5x5= e5x5;
561  showerShape.maxEnergyXtal = maxXtal;
562  showerShape.sigmaEtaEta = sigmaEtaEta;
563  showerShape.sigmaIetaIeta = sigmaIetaIeta;
564  showerShape.hcalDepth1OverEcal = HoE1;
565  showerShape.hcalDepth2OverEcal = HoE2;
566  showerShape.hcalDepth1OverEcalBc = hcalDepth1OverEcalBc;
567  showerShape.hcalDepth2OverEcalBc = hcalDepth2OverEcalBc;
568  showerShape.hcalTowersBehindClusters = TowersBehindClus;
570  const float spp = (!edm::isFinite(locCov[2]) ? 0. : sqrt(locCov[2]));
571  const float sep = locCov[1];
572  showerShape.sigmaIetaIphi = sep;
573  showerShape.sigmaIphiIphi = spp;
574  showerShape.e2nd = EcalClusterTools::e2nd(*(scRef->seed()),&(*hits));
575  showerShape.eTop = EcalClusterTools::eTop(*(scRef->seed()), &(*hits), &(*topology));
576  showerShape.eLeft = EcalClusterTools::eLeft(*(scRef->seed()), &(*hits), &(*topology));
577  showerShape.eRight = EcalClusterTools::eRight(*(scRef->seed()), &(*hits), &(*topology));
578  showerShape.eBottom = EcalClusterTools::eBottom(*(scRef->seed()), &(*hits), &(*topology));
579  showerShape.e1x3 = EcalClusterTools::e1x3(*(scRef->seed()), &(*hits), &(*topology));
580  showerShape.e2x2 = EcalClusterTools::e2x2(*(scRef->seed()), &(*hits), &(*topology));
581  showerShape.e2x5Max = EcalClusterTools::e2x5Max(*(scRef->seed()), &(*hits), &(*topology));
582  showerShape.e2x5Left = EcalClusterTools::e2x5Left(*(scRef->seed()), &(*hits), &(*topology));
583  showerShape.e2x5Right = EcalClusterTools::e2x5Right(*(scRef->seed()), &(*hits), &(*topology));
584  showerShape.e2x5Top = EcalClusterTools::e2x5Top(*(scRef->seed()), &(*hits), &(*topology));
585  showerShape.e2x5Bottom = EcalClusterTools::e2x5Bottom(*(scRef->seed()), &(*hits), &(*topology));
586  // fill preshower shapes
588  const float sigmaRR = toolsforES.eseffsirir( *scRef );
589  showerShape.effSigmaRR = sigmaRR;
590  newCandidate.setShowerShapeVariables ( showerShape );
591 
593  reco::Photon::ShowerShape full5x5_showerShape;
594  full5x5_showerShape.e1x5= full5x5_e1x5;
595  full5x5_showerShape.e2x5= full5x5_e2x5;
596  full5x5_showerShape.e3x3= full5x5_e3x3;
597  full5x5_showerShape.e5x5= full5x5_e5x5;
598  full5x5_showerShape.maxEnergyXtal = full5x5_maxXtal;
599  full5x5_showerShape.sigmaEtaEta = full5x5_sigmaEtaEta;
600  full5x5_showerShape.sigmaIetaIeta = full5x5_sigmaIetaIeta;
602  const float full5x5_spp = (!edm::isFinite(full5x5_locCov[2]) ? 0. : sqrt(full5x5_locCov[2]));
603  const float full5x5_sep = full5x5_locCov[1];
604  full5x5_showerShape.sigmaIetaIphi = full5x5_sep;
605  full5x5_showerShape.sigmaIphiIphi = full5x5_spp;
606  full5x5_showerShape.e2nd = noZS::EcalClusterTools::e2nd(*(scRef->seed()),&(*hits));
607  full5x5_showerShape.eTop = noZS::EcalClusterTools::eTop(*(scRef->seed()), &(*hits), &(*topology));
608  full5x5_showerShape.eLeft = noZS::EcalClusterTools::eLeft(*(scRef->seed()), &(*hits), &(*topology));
609  full5x5_showerShape.eRight = noZS::EcalClusterTools::eRight(*(scRef->seed()), &(*hits), &(*topology));
610  full5x5_showerShape.eBottom = noZS::EcalClusterTools::eBottom(*(scRef->seed()), &(*hits), &(*topology));
611  full5x5_showerShape.e1x3 = noZS::EcalClusterTools::e1x3(*(scRef->seed()), &(*hits), &(*topology));
612  full5x5_showerShape.e2x2 = noZS::EcalClusterTools::e2x2(*(scRef->seed()), &(*hits), &(*topology));
613  full5x5_showerShape.e2x5Max = noZS::EcalClusterTools::e2x5Max(*(scRef->seed()), &(*hits), &(*topology));
614  full5x5_showerShape.e2x5Left = noZS::EcalClusterTools::e2x5Left(*(scRef->seed()), &(*hits), &(*topology));
615  full5x5_showerShape.e2x5Right = noZS::EcalClusterTools::e2x5Right(*(scRef->seed()), &(*hits), &(*topology));
616  full5x5_showerShape.e2x5Top = noZS::EcalClusterTools::e2x5Top(*(scRef->seed()), &(*hits), &(*topology));
617  full5x5_showerShape.e2x5Bottom = noZS::EcalClusterTools::e2x5Bottom(*(scRef->seed()), &(*hits), &(*topology));
618  // fill preshower shapes
619  full5x5_showerShape.effSigmaRR = sigmaRR;
620  newCandidate.full5x5_setShowerShapeVariables ( full5x5_showerShape );
621 
622 
623 
626  // Photon candidate takes by default (set in photons_cfi.py)
627  // a 4-momentum derived from the ecal photon-specific corrections.
628  thePhotonEnergyCorrector_->calculate(evt, newCandidate, subdet, vertexCollection, es);
629  if ( candidateP4type_ == "fromEcalEnergy") {
630  newCandidate.setP4( newCandidate.p4(reco::Photon::ecal_photons) );
631  newCandidate.setCandidateP4type(reco::Photon::ecal_photons);
632  } else if ( candidateP4type_ == "fromRegression1") {
633  newCandidate.setP4( newCandidate.p4(reco::Photon::regression1) );
634  newCandidate.setCandidateP4type(reco::Photon::regression1);
635  } else if ( candidateP4type_ == "fromRegression2") {
636  newCandidate.setP4( newCandidate.p4(reco::Photon::regression2) );
637  newCandidate.setCandidateP4type(reco::Photon::regression2);
638  } else if ( candidateP4type_ == "fromRefinedSCRegression" ) {
639  newCandidate.setP4( newCandidate.p4(reco::Photon::regression2) );
640  newCandidate.setCandidateP4type(reco::Photon::regression2);
641  }
642 
643  // std::cout << " final p4 " << newCandidate.p4() << " energy " << newCandidate.energy() << std::endl;
644 
645 
646  // std::cout << " GEDPhotonProducer from candidate HoE with towers in a cone " << newCandidate.hadronicOverEm() << " " << newCandidate.hadronicDepth1OverEm() << " " << newCandidate.hadronicDepth2OverEm() << std::endl;
647  // std::cout << " GEDPhotonProducer from candidate of HoE with towers behind the BCs " << newCandidate.hadTowOverEm() << " " << newCandidate.hadTowDepth1OverEm() << " " << newCandidate.hadTowDepth2OverEm() << std::endl;
648 
649 
650  // fill MIP Vairables for Halo: Block for MIP are filled from PhotonMIPHaloTagger
652  if(subdet==EcalBarrel && runMIPTagger_ )
653  {
654 
655  thePhotonMIPHaloTagger_-> MIPcalculate( &newCandidate,evt,es,mipVar);
656  newCandidate.setMIPVariables(mipVar);
657  }
658 
659 
660 
662  bool isLooseEM=true;
663  if ( newCandidate.pt() < highEt_) {
664  if ( newCandidate.hadronicOverEm() >= preselCutValues[1] ) isLooseEM=false;
665  if ( newCandidate.ecalRecHitSumEtConeDR04() > preselCutValues[2]+ preselCutValues[3]*newCandidate.pt() ) isLooseEM=false;
666  if ( newCandidate.hcalTowerSumEtConeDR04() > preselCutValues[4]+ preselCutValues[5]*newCandidate.pt() ) isLooseEM=false;
667  if ( newCandidate.nTrkSolidConeDR04() > int(preselCutValues[6]) ) isLooseEM=false;
668  if ( newCandidate.nTrkHollowConeDR04() > int(preselCutValues[7]) ) isLooseEM=false;
669  if ( newCandidate.trkSumPtSolidConeDR04() > preselCutValues[8] ) isLooseEM=false;
670  if ( newCandidate.trkSumPtHollowConeDR04() > preselCutValues[9] ) isLooseEM=false;
671  if ( newCandidate.sigmaIetaIeta() > preselCutValues[10] ) isLooseEM=false;
672  }
673 
674 
675 
676  if ( isLooseEM)
677  outputPhotonCollection.push_back(newCandidate);
678 
679 
680  }
681 }
682 
683 
684 
685 
687  edm::EventSetup const & es,
688  const edm::Handle<reco::PhotonCollection> & photonHandle,
689  const edm::Handle<reco::PFCandidateCollection> pfCandidateHandle,
690  const edm::Handle<reco::PFCandidateCollection> pfEGCandidateHandle,
691  edm::ValueMap<reco::PhotonRef> pfEGCandToPhotonMap,
693  reco::PhotonCollection & outputPhotonCollection, int& iSC) {
694 
695 
696 
697  std::vector<double> preselCutValues;
698 
699 
700  for(unsigned int lSC=0; lSC < photonHandle->size(); lSC++) {
701  reco::PhotonRef phoRef(reco::PhotonRef(photonHandle, lSC));
702  reco::SuperClusterRef parentSCRef = phoRef->parentSuperCluster();
703  reco::SuperClusterRef scRef=phoRef->superCluster();
704  int subdet = scRef->seed()->hitsAndFractions()[0].first.subdetId();
705  if (subdet==EcalBarrel) {
706  preselCutValues = preselCutValuesBarrel_;
707  } else if (subdet==EcalEndcap) {
708  preselCutValues = preselCutValuesEndcap_;
709  } else {
710  edm::LogWarning("")<<"GEDPhotonProducer: do not know if it is a barrel or endcap SuperCluster";
711  }
712 
713 
714 
715  // SC energy preselection
716  if (parentSCRef.isNonnull() &&
717  ptFast(parentSCRef->energy(),parentSCRef->position(),math::XYZPoint(0,0,0)) <= preselCutValues[0] ) continue;
718  reco::Photon newCandidate(*phoRef);
719  iSC++;
720 
721 
722  // Calculate the PF isolation and ID - for the time being there is no calculation. Only the setting
725  thePFBasedIsolationCalculator_->calculate (&newCandidate, pfCandidateHandle, vertexHandle, evt, es, pfIso );
726  newCandidate.setPflowIsolationVariables(pfIso);
727  newCandidate.setPflowIDVariables(pfID);
728 
729  // do the regression
730  thePhotonEnergyCorrector_->calculate(evt, newCandidate, subdet, *vertexHandle, es);
731  if ( candidateP4type_ == "fromEcalEnergy") {
732  newCandidate.setP4( newCandidate.p4(reco::Photon::ecal_photons) );
734  } else if ( candidateP4type_ == "fromRegression1") {
735  newCandidate.setP4( newCandidate.p4(reco::Photon::regression1) );
737  } else if ( candidateP4type_ == "fromRegression2") {
738  newCandidate.setP4( newCandidate.p4(reco::Photon::regression2) );
740  } else if ( candidateP4type_ == "fromRefinedSCRegression" ) {
741  newCandidate.setP4( newCandidate.p4(reco::Photon::regression2) );
743  }
744 
745  // std::cout << " GEDPhotonProducer pf based isolation chargedHadron " << newCandidate.chargedHadronIso() << " neutralHadron " << newCandidate.neutralHadronIso() << " Photon " << newCandidate.photonIso() << std::endl;
746  //std::cout << " GEDPhotonProducer from candidate HoE with towers in a cone " << newCandidate.hadronicOverEm() << " " << newCandidate.hadronicDepth1OverEm() << " " << newCandidate.hadronicDepth2OverEm() << std::endl;
747  //std::cout << " GEDPhotonProducer from candidate of HoE with towers behind the BCs " << newCandidate.hadTowOverEm() << " " << newCandidate.hadTowDepth1OverEm() << " " << newCandidate.hadTowDepth2OverEm() << std::endl;
748  //std::cout << " standard p4 before " << newCandidate.p4() << " energy " << newCandidate.energy() << std::endl;
749  //std::cout << " type " <<newCandidate.getCandidateP4type() << " standard p4 after " << newCandidate.p4() << " energy " << newCandidate.energy() << std::endl;
750  //std::cout << " final p4 " << newCandidate.p4() << " energy " << newCandidate.energy() << std::endl;
751 
752  outputPhotonCollection.push_back(newCandidate);
753 
754  }
755 
756 }
edm::InputTag photonProducer_
void setPflowIsolationVariables(const PflowIsolationVariables &pfisol)
Set Particle Flow Isolation variables.
Definition: Photon.h:479
T getParameter(std::string const &) const
PhotonEnergyCorrector * thePhotonEnergyCorrector_
PhotonMIPHaloTagger * thePhotonMIPHaloTagger_
virtual void endRun(edm::Run const &, edm::EventSetup const &) overridefinal
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
edm::EDGetTokenT< reco::PFCandidateCollection > pfCandidates_
edm::ESHandle< CaloGeometry > theCaloGeom_
static float e2x5Bottom(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
std::vector< CaloTowerDetId > hcalTowersBehindClusters
Definition: Photon.h:151
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
void setCandidateP4type(const P4type type)
Definition: Photon.h:284
static std::vector< float > covariances(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology, const CaloGeometry *geometry, float w0=4.7)
edm::EDGetTokenT< CaloTowerCollection > hcalTowers_
CaloTopology const * topology(0)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
static float eMax(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits)
int init
Definition: HydjetWrapper.h:67
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
std::vector< int > flagsexclEB_
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::EDGetTokenT< EcalRecHitCollection > endcapEcalHits_
std::string reconstructionStep_
PhotonIsolationCalculator * thePhotonIsolationCalculator_
std::vector< int > severitiesexclEE_
tuple vertexCollection
std::unique_ptr< ModifyObjectValueBase > & gedRegression()
double ptFast(const double energy, const math::XYZPoint &position, const math::XYZPoint &origin)
void setup(const edm::ParameterSet &conf)
std::string photonCollection_
static float e2x5Top(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
bool isFinite(T x)
edm::ESHandle< CaloTopology > theCaloTopo_
void setTowerCollection(const CaloTowerCollection *towercollection)
edm::EDGetTokenT< EcalRecHitCollection > barrelEcalHits_
PositionCalc posCalculator_
double getDepth1HcalESum(const reco::SuperCluster &sc) const
static float e2x2(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
T sqrt(T t)
Definition: SSEVec.h:18
double p4[4]
Definition: TauolaWrapper.h:92
void setup(const edm::ParameterSet &conf, std::vector< int > const &flagsEB_, std::vector< int > const &flagsEE_, std::vector< int > const &severitiesEB_, std::vector< int > const &severitiesEE_, edm::ConsumesCollector &&iC)
void setPflowIDVariables(const PflowIDVariables &pfid)
Definition: Photon.h:502
static float e2nd(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits)
PFPhotonIsolationCalculator * thePFBasedIsolationCalculator_
std::vector< int > flagsexclEE_
edm::EDGetTokenT< reco::PhotonCoreCollection > photonCoreProducerT_
static float e2x5Max(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static float eBottom(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static float e2x5Right(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
void init(const edm::EventSetup &theEventSetup)
void setup(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
double getTowerESum(const reco::Candidate *cand, const std::vector< CaloTowerDetId > *detIdToExclude=0) const
edm::EDGetTokenT< reco::PFCandidateCollection > pfEgammaCandidates_
std::vector< int > severitiesexclEB_
static float eTop(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
void calculate(edm::Event &evt, reco::Photon &, int subdet, const reco::VertexCollection &vtxcol, const edm::EventSetup &iSetup)
GEDPhotonProducer(const edm::ParameterSet &ps)
T const * product() const
Definition: Handle.h:81
std::vector< double > preselCutValuesBarrel_
edm::EDGetTokenT< reco::PhotonCollection > photonProducerT_
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
const T & get() const
Definition: EventSetup.h:56
std::vector< double > preselCutValuesEndcap_
T const * product() const
Definition: ESHandle.h:86
static float e2x5Left(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
const LorentzVector & p4(P4type type) const
std::string candidateP4type_
void fillPhotonCollection(edm::Event &evt, edm::EventSetup const &es, const edm::Handle< reco::PhotonCoreCollection > &photonCoreHandle, const CaloTopology *topology, const EcalRecHitCollection *ecalBarrelHits, const EcalRecHitCollection *ecalEndcapHits, const EcalRecHitCollection *preshowerHits, const edm::Handle< CaloTowerCollection > &hcalTowersHandle, const reco::VertexCollection &pvVertices, reco::PhotonCollection &outputCollection, int &iSC)
virtual void beginRun(edm::Run const &r, edm::EventSetup const &es) overridefinal
std::string const & label() const
Definition: InputTag.h:36
std::vector< CaloTowerDetId > towersOf(const reco::SuperCluster &sc) const
double getDepth2HcalESum(const reco::SuperCluster &sc) const
ESHandle< TrackerGeometry > geometry
static int position[264][3]
Definition: ReadPGInfo.cc:509
edm::ParameterSet conf_
static float eRight(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static float e3x3(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static float e1x3(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
edm::EDGetTokenT< reco::VertexCollection > vertexProducer_
static float eLeft(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static std::vector< float > localCovariances(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology, float w0=4.7)
edm::EDGetTokenT< EcalRecHitCollection > preshowerHits_
virtual void produce(edm::Event &evt, const edm::EventSetup &es)
static float e1x5(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
Definition: Run.h:43
void setP4(P4type type, const LorentzVector &p4, float p4Error, bool setToRecoCandidate)
void calculate(const reco::Photon *, const edm::Handle< reco::PFCandidateCollection > pfCandidateHandle, edm::Handle< reco::VertexCollection > &vertices, const edm::Event &e, const edm::EventSetup &es, reco::Photon::PflowIsolationVariables &phoisol03)
std::string valueMapPFCandPhoton_
static float e5x5(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)