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