CMS 3D CMS Logo

PFPhotonTranslator.cc
Go to the documentation of this file.
26 
27 class CaloGeometry;
28 class CaloTopology;
29 class DetId;
30 namespace edm {
31  class EventSetup;
32 } // namespace edm
33 
35 public:
36  explicit PFPhotonTranslator(const edm::ParameterSet &);
37  ~PFPhotonTranslator() override;
38 
39  void produce(edm::Event &, const edm::EventSetup &) override;
40 
41  typedef std::vector<edm::Handle<edm::ValueMap<double> > > IsolationValueMaps;
42 
43 private:
44  // to retrieve the collection from the event
46  const edm::InputTag &tag,
47  const edm::Event &iEvent) const;
48 
49  // makes a basic cluster from PFBlockElement and add it to the collection ; the corrected energy is taken
50  // from the PFCandidate
52  reco::BasicClusterCollection &basicClusters,
53  std::vector<const reco::PFCluster *> &,
54  const reco::PFCandidate &coCandidate) const;
55  // makes a preshower cluster from of PFBlockElement and add it to the collection
57  reco::PreshowerClusterCollection &preshowerClusters,
58  unsigned plane) const;
59 
60  // create the basic cluster Ptr
62 
63  // create the preshower cluster Refs
65 
66  // make a super cluster from its ingredients and add it to the collection
68 
70  reco::ConversionCollection &oneLegConversions);
71 
72  //create photon cores
74  const edm::OrphanHandle<reco::ConversionCollection> &oneLegConversionHandle,
75  reco::PhotonCoreCollection &photonCores);
76 
79  const edm::OrphanHandle<reco::PhotonCoreCollection> &photonCoresHandle,
82 
84  const reco::PFBlockElement &pfbe) const;
85 
87  std::vector<edm::InputTag> inputTagIsoVals_;
100 
101  // the collection of basic clusters associated to a photon
102  std::vector<reco::BasicClusterCollection> basicClusters_;
103  // the correcsponding PFCluster ref
104  std::vector<std::vector<const reco::PFCluster *> > pfClusters_;
105  // the collection of preshower clusters associated to a photon
106  std::vector<reco::PreshowerClusterCollection> preshowerClusters_;
107  // the super cluster collection (actually only one) associated to a photon
108  std::vector<reco::SuperClusterCollection> superClusters_;
109  // the references to the basic clusters associated to a photon
110  std::vector<reco::CaloClusterPtrVector> basicClusterPtr_;
111  // the references to the basic clusters associated to a photon
112  std::vector<reco::CaloClusterPtrVector> preshowerClusterPtr_;
113  // keep track of the index of the PF Candidate
114  std::vector<int> photPFCandidateIndex_;
115  // the list of candidatePtr
116  std::vector<reco::CandidatePtr> CandidatePtr_;
117  // the e/g SC associated
118  std::vector<reco::SuperClusterRef> egSCRef_;
119  // the e/g photon associated
120  std::vector<reco::PhotonRef> egPhotonRef_;
121  // the PF MVA and regression
122  std::vector<float> pfPhotonMva_;
123  std::vector<float> energyRegression_;
124  std::vector<float> energyRegressionError_;
125 
126  //Vector of vector of Conversions Refs
127  std::vector<reco::ConversionRefVector> pfConv_;
128  std::vector<std::vector<reco::TrackRef> > pfSingleLegConv_;
129  std::vector<std::vector<float> > pfSingleLegConvMva_;
130 
131  std::vector<int> conv1legPFCandidateIndex_;
132  std::vector<int> conv2legPFCandidateIndex_;
133 
136 
137  // Mustache SC parameters
140 
142 };
143 
145 
146 using namespace edm;
147 using namespace std;
148 using namespace reco;
149 
153 
155  //std::cout << "PFPhotonTranslator" << std::endl;
156 
157  inputTagPFCandidates_ = iConfig.getParameter<edm::InputTag>("PFCandidate");
158 
159  edm::ParameterSet isoVals = iConfig.getParameter<edm::ParameterSet>("isolationValues");
160  inputTagIsoVals_.push_back(isoVals.getParameter<edm::InputTag>("pfChargedHadrons"));
161  inputTagIsoVals_.push_back(isoVals.getParameter<edm::InputTag>("pfPhotons"));
162  inputTagIsoVals_.push_back(isoVals.getParameter<edm::InputTag>("pfNeutralHadrons"));
163 
164  PFBasicClusterCollection_ = iConfig.getParameter<std::string>("PFBasicClusters");
165  PFPreshowerClusterCollection_ = iConfig.getParameter<std::string>("PFPreshowerClusters");
166  PFSuperClusterCollection_ = iConfig.getParameter<std::string>("PFSuperClusters");
167  PFConversionCollection_ = iConfig.getParameter<std::string>("PFConversionCollection");
168  PFPhotonCoreCollection_ = iConfig.getParameter<std::string>("PFPhotonCores");
169  PFPhotonCollection_ = iConfig.getParameter<std::string>("PFPhotons");
170 
171  EGPhotonCollection_ = iConfig.getParameter<std::string>("EGPhotons");
172 
173  vertexProducer_ = iConfig.getParameter<std::string>("primaryVertexProducer");
174 
175  barrelEcalHits_ = iConfig.getParameter<edm::InputTag>("barrelEcalHits");
176  endcapEcalHits_ = iConfig.getParameter<edm::InputTag>("endcapEcalHits");
177 
178  hcalTowers_ = iConfig.getParameter<edm::InputTag>("hcalTowers");
179  hOverEConeSize_ = iConfig.getParameter<double>("hOverEConeSize");
180 
181  if (iConfig.exists("emptyIsOk"))
182  emptyIsOk_ = iConfig.getParameter<bool>("emptyIsOk");
183  else
184  emptyIsOk_ = false;
185 
186  ecalMustacheSCParametersToken_ = esConsumes<EcalMustacheSCParameters, EcalMustacheSCParametersRcd>();
187 
188  produces<reco::BasicClusterCollection>(PFBasicClusterCollection_);
189  produces<reco::PreshowerClusterCollection>(PFPreshowerClusterCollection_);
190  produces<reco::SuperClusterCollection>(PFSuperClusterCollection_);
191  produces<reco::PhotonCoreCollection>(PFPhotonCoreCollection_);
192  produces<reco::PhotonCollection>(PFPhotonCollection_);
193  produces<reco::ConversionCollection>(PFConversionCollection_);
194 }
195 
197 
199  //cout << "NEW EVENT"<<endl;
200  mustacheSCParams_ = &iSetup.getData(ecalMustacheSCParametersToken_);
201 
202  auto basicClusters_p = std::make_unique<reco::BasicClusterCollection>();
203 
204  auto psClusters_p = std::make_unique<reco::PreshowerClusterCollection>();
205 
206  /*
207  auto SingleLeg_p = std::make_unique<reco::ConversionCollection>();
208  */
209 
210  reco::SuperClusterCollection outputSuperClusterCollection;
211  reco::ConversionCollection outputOneLegConversionCollection;
212  reco::PhotonCoreCollection outputPhotonCoreCollection;
214 
215  outputSuperClusterCollection.clear();
216  outputOneLegConversionCollection.clear();
217  outputPhotonCoreCollection.clear();
218  outputPhotonCollection.clear();
219 
221  bool status = fetchCandidateCollection(pfCandidates, inputTagPFCandidates_, iEvent);
222 
224  iEvent.getByLabel(EGPhotonCollection_, egPhotons);
225 
226  Handle<reco::VertexCollection> vertexHandle;
227 
228  IsolationValueMaps isolationValues(inputTagIsoVals_.size());
229  for (size_t j = 0; j < inputTagIsoVals_.size(); ++j) {
230  iEvent.getByLabel(inputTagIsoVals_[j], isolationValues[j]);
231  }
232 
233  // clear the vectors
234  photPFCandidateIndex_.clear();
235  basicClusters_.clear();
236  pfClusters_.clear();
237  preshowerClusters_.clear();
238  superClusters_.clear();
239  basicClusterPtr_.clear();
240  preshowerClusterPtr_.clear();
241  CandidatePtr_.clear();
242  egSCRef_.clear();
243  egPhotonRef_.clear();
244  pfPhotonMva_.clear();
245  energyRegression_.clear();
246  energyRegressionError_.clear();
247  pfConv_.clear();
248  pfSingleLegConv_.clear();
249  pfSingleLegConvMva_.clear();
250  conv1legPFCandidateIndex_.clear();
251  conv2legPFCandidateIndex_.clear();
252 
253  // loop on the candidates
254  //CC@@
255  // we need first to create AND put the SuperCluster,
256  // basic clusters and presh clusters collection
257  // in order to get a working Handle
258  unsigned ncand = (status) ? pfCandidates->size() : 0;
259 
260  unsigned iphot = 0;
261  unsigned iconv1leg = 0;
262  unsigned iconv2leg = 0;
263 
264  for (unsigned i = 0; i < ncand; ++i) {
265  const reco::PFCandidate &cand = (*pfCandidates)[i];
266  if (cand.particleId() != reco::PFCandidate::gamma)
267  continue;
268  //cout << "cand.mva_nothing_gamma()="<<cand. mva_nothing_gamma()<<endl;
269  if (cand.mva_nothing_gamma() > 0.001) //Found PFPhoton with PFPhoton Extras saved
270  {
271  //cout << "NEW PHOTON" << endl;
272 
273  //std::cout << "nDoubleLegConv="<<cand.photonExtraRef()->conversionRef().size()<<std::endl;
274 
275  if (!cand.photonExtraRef()->conversionRef().empty()) {
276  pfConv_.push_back(reco::ConversionRefVector());
277 
278  const reco::ConversionRefVector &doubleLegConvColl = cand.photonExtraRef()->conversionRef();
279  for (unsigned int iconv = 0; iconv < doubleLegConvColl.size(); iconv++) {
280  pfConv_[iconv2leg].push_back(doubleLegConvColl[iconv]);
281  }
282 
283  conv2legPFCandidateIndex_.push_back(iconv2leg);
284  iconv2leg++;
285  } else
286  conv2legPFCandidateIndex_.push_back(-1);
287 
288  const std::vector<reco::TrackRef> &singleLegConvColl = cand.photonExtraRef()->singleLegConvTrackRef();
289  const std::vector<float> &singleLegConvCollMva = cand.photonExtraRef()->singleLegConvMva();
290 
291  //std::cout << "nSingleLegConv=" <<singleLegConvColl.size() << std::endl;
292 
293  if (!singleLegConvColl.empty()) {
294  pfSingleLegConv_.push_back(std::vector<reco::TrackRef>());
295  pfSingleLegConvMva_.push_back(std::vector<float>());
296 
297  //cout << "nTracks="<< singleLegConvColl.size()<<endl;
298  for (unsigned int itk = 0; itk < singleLegConvColl.size(); itk++) {
299  //cout << "Track pt="<< singleLegConvColl[itk]->pt() <<endl;
300 
301  pfSingleLegConv_[iconv1leg].push_back(singleLegConvColl[itk]);
302  pfSingleLegConvMva_[iconv1leg].push_back(singleLegConvCollMva[itk]);
303  }
304 
305  conv1legPFCandidateIndex_.push_back(iconv1leg);
306 
307  iconv1leg++;
308  } else
309  conv1legPFCandidateIndex_.push_back(-1);
310  }
311 
312  photPFCandidateIndex_.push_back(i);
313  pfPhotonMva_.push_back(cand.mva_nothing_gamma());
314  energyRegression_.push_back(cand.photonExtraRef()->MVAGlobalCorrE());
315  energyRegressionError_.push_back(cand.photonExtraRef()->MVAGlobalCorrEError());
316  basicClusters_.push_back(reco::BasicClusterCollection());
317  pfClusters_.push_back(std::vector<const reco::PFCluster *>());
318  preshowerClusters_.push_back(reco::PreshowerClusterCollection());
319  superClusters_.push_back(reco::SuperClusterCollection());
320 
321  reco::PFCandidatePtr ptrToPFPhoton(pfCandidates, i);
322  CandidatePtr_.push_back(ptrToPFPhoton);
323  egSCRef_.push_back(cand.superClusterRef());
324  //std::cout << "PFPhoton cand " << iphot << std::endl;
325 
326  int iegphot = 0;
327  for (reco::PhotonCollection::const_iterator gamIter = egPhotons->begin(); gamIter != egPhotons->end(); ++gamIter) {
328  if (cand.superClusterRef() == gamIter->superCluster()) {
329  reco::PhotonRef PhotRef(reco::PhotonRef(egPhotons, iegphot));
330  egPhotonRef_.push_back(PhotRef);
331  }
332  iegphot++;
333  }
334 
335  //std::cout << "Cand elements in blocks : " << cand.elementsInBlocks().size() << std::endl;
336 
337  for (unsigned iele = 0; iele < cand.elementsInBlocks().size(); ++iele) {
338  // first get the block
339  reco::PFBlockRef blockRef = cand.elementsInBlocks()[iele].first;
340  //
341  unsigned elementIndex = cand.elementsInBlocks()[iele].second;
342  // check it actually exists
343  if (blockRef.isNull())
344  continue;
345 
346  // then get the elements of the block
347  const edm::OwnVector<reco::PFBlockElement> &elements = (*blockRef).elements();
348 
349  const reco::PFBlockElement &pfbe(elements[elementIndex]);
350  // The first ECAL element should be the cluster associated to the GSF; defined as the seed
351  if (pfbe.type() == reco::PFBlockElement::ECAL) {
352  //std::cout << "BlockElement ECAL" << std::endl;
353  // the Brem photons are saved as daughter PFCandidate; this
354  // is convenient to access the corrected energy
355  // std::cout << " Found candidate " << correspondingDaughterCandidate(coCandidate,pfbe) << " " << coCandidate << std::endl;
356  createBasicCluster(pfbe, basicClusters_[iphot], pfClusters_[iphot], correspondingDaughterCandidate(cand, pfbe));
357  }
358  if (pfbe.type() == reco::PFBlockElement::PS1) {
359  //std::cout << "BlockElement PS1" << std::endl;
360  createPreshowerCluster(pfbe, preshowerClusters_[iphot], 1);
361  }
362  if (pfbe.type() == reco::PFBlockElement::PS2) {
363  //std::cout << "BlockElement PS2" << std::endl;
364  createPreshowerCluster(pfbe, preshowerClusters_[iphot], 2);
365  }
366 
367  } // loop on the elements
368 
369  // save the basic clusters
370  basicClusters_p->insert(basicClusters_p->end(), basicClusters_[iphot].begin(), basicClusters_[iphot].end());
371  // save the preshower clusters
372  psClusters_p->insert(psClusters_p->end(), preshowerClusters_[iphot].begin(), preshowerClusters_[iphot].end());
373 
374  ++iphot;
375 
376  } // loop on PFCandidates
377 
378  //Save the basic clusters and get an handle as to be able to create valid Refs (thanks to Claude)
379  // std::cout << " Number of basic clusters " << basicClusters_p->size() << std::endl;
381  iEvent.put(std::move(basicClusters_p), PFBasicClusterCollection_);
382 
383  //preshower clusters
385  iEvent.put(std::move(psClusters_p), PFPreshowerClusterCollection_);
386 
387  // now that the Basic clusters are in the event, the Ref can be created
388  createBasicClusterPtrs(bcRefProd);
389  // now that the preshower clusters are in the event, the Ref can be created
390  createPreshowerClusterPtrs(psRefProd);
391 
392  // and now the Super cluster can be created with valid references
393  //if(status) createSuperClusters(*pfCandidates,*superClusters_p);
394  if (status)
395  createSuperClusters(*pfCandidates, outputSuperClusterCollection);
396 
397  //std::cout << "nb superclusters in collection : "<<outputSuperClusterCollection.size()<<std::endl;
398 
399  // Let's put the super clusters in the event
400  auto superClusters_p = std::make_unique<reco::SuperClusterCollection>(outputSuperClusterCollection);
402  iEvent.put(std::move(superClusters_p), PFSuperClusterCollection_);
403 
404  /*
405  int ipho=0;
406  for (reco::SuperClusterCollection::const_iterator gamIter = scRefProd->begin(); gamIter != scRefProd->end(); ++gamIter){
407  std::cout << "SC i="<<ipho<<" energy="<<gamIter->energy()<<std::endl;
408  ipho++;
409  }
410  */
411 
412  //1-leg conversions
413 
414  if (status)
415  createOneLegConversions(scRefProd, outputOneLegConversionCollection);
416 
417  auto SingleLeg_p = std::make_unique<reco::ConversionCollection>(outputOneLegConversionCollection);
419  iEvent.put(std::move(SingleLeg_p), PFConversionCollection_);
420  /*
421  int iconv = 0;
422  for (reco::ConversionCollection::const_iterator convIter = ConvRefProd->begin(); convIter != ConvRefProd->end(); ++convIter){
423 
424  std::cout << "OneLegConv i="<<iconv<<" nTracks="<<convIter->nTracks()<<" EoverP="<<convIter->EoverP() <<std::endl;
425  std::vector<edm::RefToBase<reco::Track> > convtracks = convIter->tracks();
426  for (unsigned int itk=0; itk<convtracks.size(); itk++){
427  std::cout << "Track pt="<< convtracks[itk]->pt() << std::endl;
428  }
429 
430  iconv++;
431  }
432  */
433 
434  //create photon cores
435  //if(status) createPhotonCores(pfCandidates, scRefProd, *photonCores_p);
436  if (status)
437  createPhotonCores(scRefProd, ConvRefProd, outputPhotonCoreCollection);
438 
439  //std::cout << "nb photoncores in collection : "<<outputPhotonCoreCollection.size()<<std::endl;
440 
441  // Put the photon cores in the event
442  auto photonCores_p = std::make_unique<reco::PhotonCoreCollection>(outputPhotonCoreCollection);
443  //std::cout << "photon core collection put in unique_ptr"<<std::endl;
445  iEvent.put(std::move(photonCores_p), PFPhotonCoreCollection_);
446 
447  //std::cout << "photon core have been put in the event"<<std::endl;
448  /*
449  int ipho=0;
450  for (reco::PhotonCoreCollection::const_iterator gamIter = pcRefProd->begin(); gamIter != pcRefProd->end(); ++gamIter){
451  std::cout << "PhotonCore i="<<ipho<<" energy="<<gamIter->parentSuperCluster()->energy()<<std::endl;
452  //for (unsigned int i=0; i<)
453 
454  std::cout << "PhotonCore i="<<ipho<<" nconv2leg="<<gamIter->conversions().size()<<" nconv1leg="<<gamIter->conversionsOneLeg().size()<<std::endl;
455 
456  const reco::ConversionRefVector & conv = gamIter->conversions();
457  for (unsigned int iconv=0; iconv<conv.size(); iconv++){
458  cout << "2-leg iconv="<<iconv<<endl;
459  cout << "2-leg nTracks="<<conv[iconv]->nTracks()<<endl;
460  cout << "2-leg EoverP="<<conv[iconv]->EoverP()<<endl;
461  cout << "2-leg ConvAlgorithm="<<conv[iconv]->algo()<<endl;
462  }
463 
464  const reco::ConversionRefVector & convbis = gamIter->conversionsOneLeg();
465  for (unsigned int iconv=0; iconv<convbis.size(); iconv++){
466  cout << "1-leg iconv="<<iconv<<endl;
467  cout << "1-leg nTracks="<<convbis[iconv]->nTracks()<<endl;
468  cout << "1-leg EoverP="<<convbis[iconv]->EoverP()<<endl;
469  cout << "1-leg ConvAlgorithm="<<convbis[iconv]->algo()<<endl;
470  }
471 
472  ipho++;
473  }
474  */
475 
476  //load vertices
478  bool validVertex = true;
479  iEvent.getByLabel(vertexProducer_, vertexHandle);
480  if (!vertexHandle.isValid()) {
481  edm::LogWarning("PhotonProducer") << "Error! Can't get the product primary Vertex Collection "
482  << "\n";
483  validVertex = false;
484  }
485  if (validVertex)
486  vertexCollection = *(vertexHandle.product());
487 
488  /*
489  //load Ecal rechits
490  bool validEcalRecHits=true;
491  Handle<EcalRecHitCollection> barrelHitHandle;
492  EcalRecHitCollection barrelRecHits;
493  iEvent.getByLabel(barrelEcalHits_, barrelHitHandle);
494  if (!barrelHitHandle.isValid()) {
495  edm::LogError("PhotonProducer") << "Error! Can't get the product "<<barrelEcalHits_.label();
496  validEcalRecHits=false;
497  }
498  if ( validEcalRecHits) barrelRecHits = *(barrelHitHandle.product());
499 
500  Handle<EcalRecHitCollection> endcapHitHandle;
501  iEvent.getByLabel(endcapEcalHits_, endcapHitHandle);
502  EcalRecHitCollection endcapRecHits;
503  if (!endcapHitHandle.isValid()) {
504  edm::LogError("PhotonProducer") << "Error! Can't get the product "<<endcapEcalHits_.label();
505  validEcalRecHits=false;
506  }
507  if( validEcalRecHits) endcapRecHits = *(endcapHitHandle.product());
508 
509  //load detector topology & geometry
510  iSetup.get<CaloGeometryRecord>().get(theCaloGeom_);
511 
512  edm::ESHandle<CaloTopology> pTopology;
513  iSetup.get<CaloTopologyRecord>().get(theCaloTopo_);
514  const CaloTopology *topology = theCaloTopo_.product();
515 
516  // get Hcal rechits collection
517  Handle<CaloTowerCollection> hcalTowersHandle;
518  iEvent.getByLabel(hcalTowers_, hcalTowersHandle);
519  */
520 
521  //create photon collection
522  //if(status) createPhotons(vertexCollection, pcRefProd, topology, &barrelRecHits, &endcapRecHits, hcalRecHitsHandle, isolationValues, outputPhotonCollection);
523  if (status)
524  createPhotons(vertexCollection, egPhotons, pcRefProd, isolationValues, outputPhotonCollection);
525 
526  // Put the photons in the event
527  auto photons_p = std::make_unique<reco::PhotonCollection>(outputPhotonCollection);
528  //std::cout << "photon collection put in unique_ptr"<<std::endl;
529  const edm::OrphanHandle<reco::PhotonCollection> photonRefProd = iEvent.put(std::move(photons_p), PFPhotonCollection_);
530  //std::cout << "photons have been put in the event"<<std::endl;
531 
532  /*
533  ipho=0;
534  for (reco::PhotonCollection::const_iterator gamIter = photonRefProd->begin(); gamIter != photonRefProd->end(); ++gamIter){
535  std::cout << "Photon i="<<ipho<<" pfEnergy="<<gamIter->parentSuperCluster()->energy()<<std::endl;
536 
537  const reco::ConversionRefVector & conv = gamIter->conversions();
538  cout << "conversions obtained : conv.size()="<< conv.size()<<endl;
539  for (unsigned int iconv=0; iconv<conv.size(); iconv++){
540  cout << "iconv="<<iconv<<endl;
541  cout << "nTracks="<<conv[iconv]->nTracks()<<endl;
542  cout << "EoverP="<<conv[iconv]->EoverP()<<endl;
543 
544  cout << "Vtx x="<<conv[iconv]->conversionVertex().x() << " y="<< conv[iconv]->conversionVertex().y()<<" z="<<conv[iconv]->conversionVertex().z()<< endl;
545  cout << "VtxError x=" << conv[iconv]->conversionVertex().xError() << endl;
546 
547  std::vector<edm::RefToBase<reco::Track> > convtracks = conv[iconv]->tracks();
548  //cout << "nTracks="<< convtracks.size()<<endl;
549  for (unsigned int itk=0; itk<convtracks.size(); itk++){
550  double convtrackpt = convtracks[itk]->pt();
551  const edm::RefToBase<reco::Track> & mytrack = convtracks[itk];
552  cout << "Track pt="<< convtrackpt <<endl;
553  cout << "Track origin="<<gamIter->conversionTrackOrigin(mytrack)<<endl;
554  }
555  }
556 
557  //1-leg
558  const reco::ConversionRefVector & convbis = gamIter->conversionsOneLeg();
559  cout << "conversions obtained : conv.size()="<< convbis.size()<<endl;
560  for (unsigned int iconv=0; iconv<convbis.size(); iconv++){
561  cout << "iconv="<<iconv<<endl;
562  cout << "nTracks="<<convbis[iconv]->nTracks()<<endl;
563  cout << "EoverP="<<convbis[iconv]->EoverP()<<endl;
564 
565  cout << "Vtx x="<<convbis[iconv]->conversionVertex().x() << " y="<< convbis[iconv]->conversionVertex().y()<<" z="<<convbis[iconv]->conversionVertex().z()<< endl;
566  cout << "VtxError x=" << convbis[iconv]->conversionVertex().xError() << endl;
567 
568  std::vector<edm::RefToBase<reco::Track> > convtracks = convbis[iconv]->tracks();
569  //cout << "nTracks="<< convtracks.size()<<endl;
570  for (unsigned int itk=0; itk<convtracks.size(); itk++){
571  double convtrackpt = convtracks[itk]->pt();
572  cout << "Track pt="<< convtrackpt <<endl;
573  cout << "Track origin="<<gamIter->conversionTrackOrigin((convtracks[itk]))<<endl;
574  }
575  }
576  ipho++;
577  }
578  */
579 }
580 
582  const edm::InputTag &tag,
583  const edm::Event &iEvent) const {
584  bool found = iEvent.getByLabel(tag, c);
585 
586  if (!found && !emptyIsOk_) {
587  std::ostringstream err;
588  err << " cannot get PFCandidates: " << tag << std::endl;
589  edm::LogError("PFPhotonTranslator") << err.str();
590  }
591  return found;
592 }
593 
594 // The basic cluster is a copy of the PFCluster -> the energy is not corrected
595 // It should be possible to get the corrected energy (including the associated PS energy)
596 // from the PFCandidate daugthers ; Needs some work
598  reco::BasicClusterCollection &basicClusters,
599  std::vector<const reco::PFCluster *> &pfClusters,
600  const reco::PFCandidate &coCandidate) const {
601  const reco::PFClusterRef &myPFClusterRef = PFBE.clusterRef();
602  if (myPFClusterRef.isNull())
603  return;
604 
605  const reco::PFCluster &myPFCluster(*myPFClusterRef);
606  pfClusters.push_back(&myPFCluster);
607  //std::cout << " Creating BC " << myPFCluster.energy() << " " << coCandidate.ecalEnergy() <<" "<< coCandidate.rawEcalEnergy() <<std::endl;
608  //std::cout << " # hits " << myPFCluster.hitsAndFractions().size() << std::endl;
609 
610  // basicClusters.push_back(reco::CaloCluster(myPFCluster.energy(),
611  basicClusters.push_back(reco::CaloCluster( //coCandidate.rawEcalEnergy(),
612  myPFCluster.energy(),
613  myPFCluster.position(),
614  myPFCluster.caloID(),
615  myPFCluster.hitsAndFractions(),
616  myPFCluster.algo(),
617  myPFCluster.seed()));
618 }
619 
621  reco::PreshowerClusterCollection &preshowerClusters,
622  unsigned plane) const {
623  const reco::PFClusterRef &myPFClusterRef = PFBE.clusterRef();
624  preshowerClusters.push_back(reco::PreshowerCluster(
625  myPFClusterRef->energy(), myPFClusterRef->position(), myPFClusterRef->hitsAndFractions(), plane));
626 }
627 
629  const edm::OrphanHandle<reco::BasicClusterCollection> &basicClustersHandle) {
630  unsigned size = photPFCandidateIndex_.size();
631  unsigned basicClusterCounter = 0;
632  basicClusterPtr_.resize(size);
633 
634  for (unsigned iphot = 0; iphot < size; ++iphot) // loop on tracks
635  {
636  unsigned nbc = basicClusters_[iphot].size();
637  for (unsigned ibc = 0; ibc < nbc; ++ibc) // loop on basic clusters
638  {
639  // std::cout << "Track "<< iGSF << " ref " << basicClusterCounter << std::endl;
640  reco::CaloClusterPtr bcPtr(basicClustersHandle, basicClusterCounter);
641  basicClusterPtr_[iphot].push_back(bcPtr);
642  ++basicClusterCounter;
643  }
644  }
645 }
646 
648  const edm::OrphanHandle<reco::PreshowerClusterCollection> &preshowerClustersHandle) {
649  unsigned size = photPFCandidateIndex_.size();
650  unsigned psClusterCounter = 0;
651  preshowerClusterPtr_.resize(size);
652 
653  for (unsigned iphot = 0; iphot < size; ++iphot) // loop on tracks
654  {
655  unsigned nbc = preshowerClusters_[iphot].size();
656  for (unsigned ibc = 0; ibc < nbc; ++ibc) // loop on basic clusters
657  {
658  // std::cout << "Track "<< iGSF << " ref " << basicClusterCounter << std::endl;
659  reco::CaloClusterPtr psPtr(preshowerClustersHandle, psClusterCounter);
660  preshowerClusterPtr_[iphot].push_back(psPtr);
661  ++psClusterCounter;
662  }
663  }
664 }
665 
668  unsigned nphot = photPFCandidateIndex_.size();
669  for (unsigned iphot = 0; iphot < nphot; ++iphot) {
670  //cout << "SC iphot=" << iphot << endl;
671 
672  // Computes energy position a la e/gamma
673  double sclusterE = 0;
674  double posX = 0.;
675  double posY = 0.;
676  double posZ = 0.;
677 
678  unsigned nbasics = basicClusters_[iphot].size();
679  for (unsigned ibc = 0; ibc < nbasics; ++ibc) {
680  //cout << "BC in SC : iphot="<<iphot<<endl;
681 
682  double e = basicClusters_[iphot][ibc].energy();
683  sclusterE += e;
684  posX += e * basicClusters_[iphot][ibc].position().X();
685  posY += e * basicClusters_[iphot][ibc].position().Y();
686  posZ += e * basicClusters_[iphot][ibc].position().Z();
687  }
688  posX /= sclusterE;
689  posY /= sclusterE;
690  posZ /= sclusterE;
691 
692  /*
693  if(pfCand[gsfPFCandidateIndex_[iphot]].gsfTrackRef()!=GsfTrackRef_[iphot])
694  {
695  edm::LogError("PFElectronTranslator") << " Major problem in PFElectron Translator" << std::endl;
696  }
697  */
698 
699  // compute the width
700  PFClusterWidthAlgo pfwidth(pfClusters_[iphot]);
701 
702  double correctedEnergy = pfCand[photPFCandidateIndex_[iphot]].ecalEnergy();
703  reco::SuperCluster mySuperCluster(correctedEnergy, math::XYZPoint(posX, posY, posZ));
704  // protection against empty basic cluster collection ; the value is -2 in this case
705  if (nbasics) {
706  // std::cout << "SuperCluster creation; energy " << pfCand[gsfPFCandidateIndex_[iphot]].ecalEnergy();
707  // std::cout << " " << pfCand[gsfPFCandidateIndex_[iphot]].rawEcalEnergy() << std::endl;
708  // std::cout << "Seed energy from basic " << basicClusters_[iphot][0].energy() << std::endl;
709  mySuperCluster.setSeed(basicClusterPtr_[iphot][0]);
710  } else {
711  // std::cout << "SuperCluster creation ; seed energy " << 0 << std::endl;
712  //std::cout << "SuperCluster creation ; energy " << pfCand[photPFCandidateIndex_[iphot]].ecalEnergy();
713  //std::cout << " " << pfCand[photPFCandidateIndex_[iphot]].rawEcalEnergy() << std::endl;
714  // std::cout << " No seed found " << 0 << std::endl;
715  // std::cout << " MVA " << pfCand[gsfPFCandidateIndex_[iphot]].mva_e_pi() << std::endl;
716  mySuperCluster.setSeed(reco::CaloClusterPtr());
717  }
718  // the seed should be the first basic cluster
719 
720  for (unsigned ibc = 0; ibc < nbasics; ++ibc) {
721  mySuperCluster.addCluster(basicClusterPtr_[iphot][ibc]);
722  // std::cout <<"Adding Ref to SC " << basicClusterPtr_[iphot][ibc].index() << std::endl;
723  const std::vector<std::pair<DetId, float> > &v1 = basicClusters_[iphot][ibc].hitsAndFractions();
724  // std::cout << " Number of cells " << v1.size() << std::endl;
725  for (std::vector<std::pair<DetId, float> >::const_iterator diIt = v1.begin(); diIt != v1.end(); ++diIt) {
726  // std::cout << " Adding DetId " << (diIt->first).rawId() << " " << diIt->second << std::endl;
727  mySuperCluster.addHitAndFraction(diIt->first, diIt->second);
728  } // loop over rechits
729  }
730 
731  unsigned nps = preshowerClusterPtr_[iphot].size();
732  for (unsigned ips = 0; ips < nps; ++ips) {
733  mySuperCluster.addPreshowerCluster(preshowerClusterPtr_[iphot][ips]);
734  }
735 
736  // Set the preshower energy
737  mySuperCluster.setPreshowerEnergy(pfCand[photPFCandidateIndex_[iphot]].pS1Energy() +
738  pfCand[photPFCandidateIndex_[iphot]].pS2Energy());
739 
740  // Set the cluster width
741  mySuperCluster.setEtaWidth(pfwidth.pflowEtaWidth());
742  mySuperCluster.setPhiWidth(pfwidth.pflowPhiWidth());
743  // Force the computation of rawEnergy_ of the reco::SuperCluster
744  mySuperCluster.rawEnergy();
745 
746  //cout << "SC energy="<< mySuperCluster.energy()<<endl;
747 
748  superClusters.push_back(mySuperCluster);
749  //std::cout << "nb super clusters in collection : "<<superClusters.size()<<std::endl;
750  }
751 }
752 
754  const edm::OrphanHandle<reco::SuperClusterCollection> &superClustersHandle,
755  reco::ConversionCollection &oneLegConversions) {
756  //std::cout << "createOneLegConversions" << std::endl;
757 
758  unsigned nphot = photPFCandidateIndex_.size();
759  for (unsigned iphot = 0; iphot < nphot; ++iphot) {
760  //if (conv1legPFCandidateIndex_[iphot]==-1) cout << "No OneLegConversions to add"<<endl;
761  //else std::cout << "Phot "<<iphot<< " nOneLegConversions to add : "<<pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]].size()<<endl;
762 
763  if (conv1legPFCandidateIndex_[iphot] > -1) {
764  for (unsigned iConv = 0; iConv < pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]].size(); iConv++) {
766  std::vector<reco::CaloClusterPtr> matchingBC;
768  const reco::Vertex *convVtx =
769  new reco::Vertex(pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->innerPosition(), error);
770 
771  //cout << "Vtx x="<<convVtx->x() << " y="<< convVtx->y()<<" z="<<convVtx->z()<< endl;
772  //cout << "VtxError x=" << convVtx->xError() << endl;
773 
774  std::vector<reco::TrackRef> OneLegConvVector;
775  OneLegConvVector.push_back(pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]);
776 
777  std::vector<reco::TrackRef> tr = OneLegConvVector;
778  std::vector<math::XYZPointF> trackPositionAtEcalVec;
779  std::vector<math::XYZPointF> innPointVec;
780  std::vector<math::XYZVectorF> trackPinVec;
781  std::vector<math::XYZVectorF> trackPoutVec;
782  math::XYZPointF trackPositionAtEcal(
783  pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->outerPosition().X(),
784  pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->outerPosition().Y(),
785  pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->outerPosition().Z());
786  math::XYZPointF innPoint(pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->innerPosition().X(),
787  pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->innerPosition().Y(),
788  pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->innerPosition().Z());
789  math::XYZVectorF trackPin(pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->innerMomentum().X(),
790  pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->innerMomentum().Y(),
791  pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->innerMomentum().Z());
792  math::XYZVectorF trackPout(pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->outerMomentum().X(),
793  pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->outerMomentum().Y(),
794  pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->outerMomentum().Z());
795  float DCA = pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->d0();
796  trackPositionAtEcalVec.push_back(trackPositionAtEcal);
797  innPointVec.push_back(innPoint);
798  trackPinVec.push_back(trackPin);
799  trackPoutVec.push_back(trackPout);
800  std::vector<float> OneLegMvaVector;
801  reco::Conversion myOneLegConversion(scPtrVec,
802  OneLegConvVector,
803  trackPositionAtEcalVec,
804  *convVtx,
805  matchingBC,
806  DCA,
807  innPointVec,
808  trackPinVec,
809  trackPoutVec,
810  pfSingleLegConvMva_[conv1legPFCandidateIndex_[iphot]][iConv],
812  OneLegMvaVector.push_back(pfSingleLegConvMva_[conv1legPFCandidateIndex_[iphot]][iConv]);
813  myOneLegConversion.setOneLegMVA(OneLegMvaVector);
814  //reco::Conversion myOneLegConversion(scPtrVec,
815  //OneLegConvVector, *convVtx, reco::Conversion::pflow);
816 
817  /*
818  std::cout << "One leg conversion created" << endl;
819  std::vector<edm::RefToBase<reco::Track> > convtracks = myOneLegConversion.tracks();
820  const std::vector<float> mvalist = myOneLegConversion.oneLegMVA();
821 
822  cout << "nTracks="<< convtracks.size()<<endl;
823  for (unsigned int itk=0; itk<convtracks.size(); itk++){
824  //double convtrackpt = convtracks[itk]->pt();
825  std::cout << "Track pt="<< convtracks[itk]->pt() << std::endl;
826  std::cout << "Track mva="<< mvalist[itk] << std::endl;
827  }
828  */
829  oneLegConversions.push_back(myOneLegConversion);
830 
831  //cout << "OneLegConv added"<<endl;
832  }
833  }
834  }
835 }
836 
838  const edm::OrphanHandle<reco::ConversionCollection> &oneLegConversionHandle,
839  reco::PhotonCoreCollection &photonCores) {
840  //std::cout << "createPhotonCores" << std::endl;
841 
842  unsigned nphot = photPFCandidateIndex_.size();
843 
844  unsigned i1legtot = 0;
845 
846  for (unsigned iphot = 0; iphot < nphot; ++iphot) {
847  //std::cout << "iphot="<<iphot<<std::endl;
848 
849  reco::PhotonCore myPhotonCore;
850 
851  reco::SuperClusterRef SCref(reco::SuperClusterRef(superClustersHandle, iphot));
852 
853  myPhotonCore.setPFlowPhoton(true);
854  myPhotonCore.setStandardPhoton(false);
855  myPhotonCore.setParentSuperCluster(SCref);
856  myPhotonCore.setSuperCluster(egSCRef_[iphot]);
857 
858  reco::ElectronSeedRefVector pixelSeeds = egPhotonRef_[iphot]->electronPixelSeeds();
859  for (unsigned iseed = 0; iseed < pixelSeeds.size(); iseed++) {
860  myPhotonCore.addElectronPixelSeed(pixelSeeds[iseed]);
861  }
862 
863  //cout << "PhotonCores : SC OK" << endl;
864 
865  //cout << "conv1legPFCandidateIndex_[iphot]="<<conv1legPFCandidateIndex_[iphot]<<endl;
866  //cout << "conv2legPFCandidateIndex_[iphot]="<<conv2legPFCandidateIndex_[iphot]<<endl;
867 
868  if (conv1legPFCandidateIndex_[iphot] > -1) {
869  for (unsigned int iConv = 0; iConv < pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]].size(); iConv++) {
870  const reco::ConversionRef &OneLegRef(reco::ConversionRef(oneLegConversionHandle, i1legtot));
871  myPhotonCore.addOneLegConversion(OneLegRef);
872 
873  //cout << "PhotonCores : 1-leg OK" << endl;
874  /*
875  cout << "Testing 1-leg :"<<endl;
876  const reco::ConversionRefVector & conv = myPhotonCore.conversionsOneLeg();
877  for (unsigned int iconv=0; iconv<conv.size(); iconv++){
878  cout << "Testing 1-leg : iconv="<<iconv<<endl;
879  cout << "Testing 1-leg : nTracks="<<conv[iconv]->nTracks()<<endl;
880  cout << "Testing 1-leg : EoverP="<<conv[iconv]->EoverP()<<endl;
881  std::vector<edm::RefToBase<reco::Track> > convtracks = conv[iconv]->tracks();
882  for (unsigned int itk=0; itk<convtracks.size(); itk++){
883  //double convtrackpt = convtracks[itk]->pt();
884  std::cout << "Testing 1-leg : Track pt="<< convtracks[itk]->pt() << std::endl;
885  // std::cout << "Track mva="<< mvalist[itk] << std::endl;
886  }
887  }
888  */
889 
890  i1legtot++;
891  }
892  }
893 
894  if (conv2legPFCandidateIndex_[iphot] > -1) {
895  for (unsigned int iConv = 0; iConv < pfConv_[conv2legPFCandidateIndex_[iphot]].size(); iConv++) {
896  const reco::ConversionRef &TwoLegRef(pfConv_[conv2legPFCandidateIndex_[iphot]][iConv]);
897  myPhotonCore.addConversion(TwoLegRef);
898  }
899  //cout << "PhotonCores : 2-leg OK" << endl;
900 
901  /*
902  cout << "Testing 2-leg :"<<endl;
903  const reco::ConversionRefVector & conv = myPhotonCore.conversions();
904  for (unsigned int iconv=0; iconv<conv.size(); iconv++){
905  cout << "Testing 2-leg : iconv="<<iconv<<endl;
906  cout << "Testing 2-leg : nTracks="<<conv[iconv]->nTracks()<<endl;
907  cout << "Testing 2-leg : EoverP="<<conv[iconv]->EoverP()<<endl;
908  std::vector<edm::RefToBase<reco::Track> > convtracks = conv[iconv]->tracks();
909  for (unsigned int itk=0; itk<convtracks.size(); itk++){
910  //double convtrackpt = convtracks[itk]->pt();
911  std::cout << "Testing 2-leg : Track pt="<< convtracks[itk]->pt() << std::endl;
912  // std::cout << "Track mva="<< mvalist[itk] << std::endl;
913  }
914  }
915  */
916  }
917 
918  photonCores.push_back(myPhotonCore);
919  }
920 
921  //std::cout << "end of createPhotonCores"<<std::endl;
922 }
923 
926  const edm::OrphanHandle<reco::PhotonCoreCollection> &photonCoresHandle,
929  //cout << "createPhotons" << endl;
930 
931  unsigned nphot = photPFCandidateIndex_.size();
932 
933  for (unsigned iphot = 0; iphot < nphot; ++iphot) {
934  //std::cout << "iphot="<<iphot<<std::endl;
935 
936  reco::PhotonCoreRef PCref(reco::PhotonCoreRef(photonCoresHandle, iphot));
937 
938  math::XYZPoint vtx(0., 0., 0.);
939  if (!vertexCollection.empty())
940  vtx = vertexCollection.begin()->position();
941  //std::cout << "vtx made" << std::endl;
942 
943  math::XYZVector direction = PCref->parentSuperCluster()->position() - vtx;
944 
945  //It could be that pfSC energy gives not the best resolution : use smaller agregates for some cases ?
946  math::XYZVector P3 = direction.unit() * PCref->parentSuperCluster()->energy();
947  LorentzVector P4(P3.x(), P3.y(), P3.z(), PCref->parentSuperCluster()->energy());
948 
949  reco::Photon myPhoton(P4, PCref->parentSuperCluster()->position(), PCref, vtx);
950  //cout << "photon created"<<endl;
951 
952  reco::Photon::ShowerShape showerShape;
953  reco::Photon::SaturationInfo saturationInfo;
954  reco::Photon::FiducialFlags fiducialFlags;
955  reco::Photon::IsolationVariables isolationVariables03;
956  reco::Photon::IsolationVariables isolationVariables04;
957 
958  showerShape.e1x5 = egPhotonRef_[iphot]->e1x5();
959  showerShape.e2x5 = egPhotonRef_[iphot]->e2x5();
960  showerShape.e3x3 = egPhotonRef_[iphot]->e3x3();
961  showerShape.e5x5 = egPhotonRef_[iphot]->e5x5();
962  showerShape.maxEnergyXtal = egPhotonRef_[iphot]->maxEnergyXtal();
963  showerShape.sigmaEtaEta = egPhotonRef_[iphot]->sigmaEtaEta();
964  showerShape.sigmaIetaIeta = egPhotonRef_[iphot]->sigmaIetaIeta();
965  for (uint id = 0; id < showerShape.hcalOverEcal.size(); ++id) {
966  showerShape.hcalOverEcal[id] = egPhotonRef_[iphot]->hcalOverEcal(id + 1);
967  }
968  myPhoton.setShowerShapeVariables(showerShape);
969 
970  saturationInfo.nSaturatedXtals = egPhotonRef_[iphot]->nSaturatedXtals();
971  saturationInfo.isSeedSaturated = egPhotonRef_[iphot]->isSeedSaturated();
972  myPhoton.setSaturationInfo(saturationInfo);
973 
974  fiducialFlags.isEB = egPhotonRef_[iphot]->isEB();
975  fiducialFlags.isEE = egPhotonRef_[iphot]->isEE();
976  fiducialFlags.isEBEtaGap = egPhotonRef_[iphot]->isEBEtaGap();
977  fiducialFlags.isEBPhiGap = egPhotonRef_[iphot]->isEBPhiGap();
978  fiducialFlags.isEERingGap = egPhotonRef_[iphot]->isEERingGap();
979  fiducialFlags.isEEDeeGap = egPhotonRef_[iphot]->isEEDeeGap();
980  fiducialFlags.isEBEEGap = egPhotonRef_[iphot]->isEBEEGap();
981  myPhoton.setFiducialVolumeFlags(fiducialFlags);
982 
983  isolationVariables03.ecalRecHitSumEt = egPhotonRef_[iphot]->ecalRecHitSumEtConeDR03();
984  for (uint id = 0; id < isolationVariables03.hcalRecHitSumEt.size(); ++id) {
985  isolationVariables03.hcalRecHitSumEt[id] = egPhotonRef_[iphot]->hcalTowerSumEtConeDR03(id + 1);
986  }
987  isolationVariables03.trkSumPtSolidCone = egPhotonRef_[iphot]->trkSumPtSolidConeDR03();
988  isolationVariables03.trkSumPtHollowCone = egPhotonRef_[iphot]->trkSumPtHollowConeDR03();
989  isolationVariables03.nTrkSolidCone = egPhotonRef_[iphot]->nTrkSolidConeDR03();
990  isolationVariables03.nTrkHollowCone = egPhotonRef_[iphot]->nTrkHollowConeDR03();
991  isolationVariables04.ecalRecHitSumEt = egPhotonRef_[iphot]->ecalRecHitSumEtConeDR04();
992  for (uint id = 0; id < isolationVariables04.hcalRecHitSumEt.size(); ++id) {
993  isolationVariables04.hcalRecHitSumEt[id] = egPhotonRef_[iphot]->hcalTowerSumEtConeDR04(id + 1);
994  }
995  isolationVariables04.trkSumPtSolidCone = egPhotonRef_[iphot]->trkSumPtSolidConeDR04();
996  isolationVariables04.trkSumPtHollowCone = egPhotonRef_[iphot]->trkSumPtHollowConeDR04();
997  isolationVariables04.nTrkSolidCone = egPhotonRef_[iphot]->nTrkSolidConeDR04();
998  isolationVariables04.nTrkHollowCone = egPhotonRef_[iphot]->nTrkHollowConeDR04();
999  myPhoton.setIsolationVariables(isolationVariables04, isolationVariables03);
1000 
1002  myPFIso.chargedHadronIso = (*isolationValues[0])[CandidatePtr_[iphot]];
1003  myPFIso.photonIso = (*isolationValues[1])[CandidatePtr_[iphot]];
1004  myPFIso.neutralHadronIso = (*isolationValues[2])[CandidatePtr_[iphot]];
1005  myPhoton.setPflowIsolationVariables(myPFIso);
1006 
1007  reco::Photon::PflowIDVariables myPFVariables;
1008 
1009  reco::Mustache myMustache(mustacheSCParams_);
1010  myMustache.MustacheID(
1011  *(myPhoton.parentSuperCluster()), myPFVariables.nClusterOutsideMustache, myPFVariables.etOutsideMustache);
1012  myPFVariables.mva = pfPhotonMva_[iphot];
1013  myPhoton.setPflowIDVariables(myPFVariables);
1014 
1015  //cout << "chargedHadronIso="<<myPhoton.chargedHadronIso()<<" photonIso="<<myPhoton.photonIso()<<" neutralHadronIso="<<myPhoton.neutralHadronIso()<<endl;
1016 
1017  // set PF-regression energy
1018  myPhoton.setCorrectedEnergy(
1019  reco::Photon::regression2, energyRegression_[iphot], energyRegressionError_[iphot], false);
1020 
1021  /*
1022  if (basicClusters_[iphot].size()>0){
1023  // Cluster shape variables
1024  //Algorithms from EcalClusterTools could be adapted to PF photons ? (not based on 5x5 BC)
1025  //It happens that energy computed in eg e5x5 is greater than pfSC energy (EcalClusterTools gathering energies from adjacent crystals even if not belonging to the SC)
1026  const EcalRecHitCollection* hits = 0 ;
1027  int subdet = PCref->parentSuperCluster()->seed()->hitsAndFractions()[0].first.subdetId();
1028  if (subdet==EcalBarrel) hits = barrelRecHits;
1029  else if (subdet==EcalEndcap) hits = endcapRecHits;
1030  const CaloGeometry* geometry = theCaloGeom_.product();
1031 
1032  float maxXtal = EcalClusterTools::eMax( *(PCref->parentSuperCluster()->seed()), &(*hits) );
1033  //cout << "maxXtal="<<maxXtal<<endl;
1034  float e1x5 = EcalClusterTools::e1x5( *(PCref->parentSuperCluster()->seed()), &(*hits), &(*topology));
1035  //cout << "e1x5="<<e1x5<<endl;
1036  float e2x5 = EcalClusterTools::e2x5Max( *(PCref->parentSuperCluster()->seed()), &(*hits), &(*topology));
1037  //cout << "e2x5="<<e2x5<<endl;
1038  float e3x3 = EcalClusterTools::e3x3( *(PCref->parentSuperCluster()->seed()), &(*hits), &(*topology));
1039  //cout << "e3x3="<<e3x3<<endl;
1040  float e5x5 = EcalClusterTools::e5x5( *(PCref->parentSuperCluster()->seed()), &(*hits), &(*topology));
1041  //cout << "e5x5="<<e5x5<<endl;
1042  std::vector<float> cov = EcalClusterTools::covariances( *(PCref->parentSuperCluster()->seed()), &(*hits), &(*topology), geometry);
1043  float sigmaEtaEta = sqrt(cov[0]);
1044  //cout << "sigmaEtaEta="<<sigmaEtaEta<<endl;
1045  std::vector<float> locCov = EcalClusterTools::localCovariances( *(PCref->parentSuperCluster()->seed()), &(*hits), &(*topology));
1046  float sigmaIetaIeta = sqrt(locCov[0]);
1047  //cout << "sigmaIetaIeta="<<sigmaIetaIeta<<endl;
1048  //float r9 =e3x3/(PCref->parentSuperCluster()->rawEnergy());
1049 
1050 
1051  // calculate HoE
1052  const CaloTowerCollection* hcalTowersColl = hcalTowersHandle.product();
1053  EgammaTowerIsolation towerIso1(hOverEConeSize_,0.,0.,1,hcalTowersColl) ;
1054  EgammaTowerIsolation towerIso2(hOverEConeSize_,0.,0.,2,hcalTowersColl) ;
1055  double HoE1=towerIso1.getTowerESum(&(*PCref->parentSuperCluster()))/PCref->pfSuperCluster()->energy();
1056  double HoE2=towerIso2.getTowerESum(&(*PCref->parentSuperCluster()))/PCref->pfSuperCluster()->energy();
1057  //cout << "HoE1="<<HoE1<<endl;
1058  //cout << "HoE2="<<HoE2<<endl;
1059 
1060  reco::Photon::ShowerShape showerShape;
1061  showerShape.e1x5= e1x5;
1062  showerShape.e2x5= e2x5;
1063  showerShape.e3x3= e3x3;
1064  showerShape.e5x5= e5x5;
1065  showerShape.maxEnergyXtal = maxXtal;
1066  showerShape.sigmaEtaEta = sigmaEtaEta;
1067  showerShape.sigmaIetaIeta = sigmaIetaIeta;
1068  showerShape.hcalDepth1OverEcal = HoE1;
1069  showerShape.hcalDepth2OverEcal = HoE2;
1070  myPhoton.setShowerShapeVariables ( showerShape );
1071  //cout << "shower shape variables filled"<<endl;
1072  }
1073  */
1074 
1075  photons.push_back(myPhoton);
1076  }
1077 
1078  //std::cout << "end of createPhotons"<<std::endl;
1079 }
1080 
1082  const reco::PFBlockElement &pfbe) const {
1083  unsigned refindex = pfbe.index();
1084  // std::cout << " N daughters " << cand.numberOfDaughters() << std::endl;
1085  reco::PFCandidate::const_iterator myDaughterCandidate = cand.begin();
1087 
1088  for (; myDaughterCandidate != itend; ++myDaughterCandidate) {
1089  const reco::PFCandidate *myPFCandidate = (const reco::PFCandidate *)&*myDaughterCandidate;
1090  if (myPFCandidate->elementsInBlocks().size() != 1) {
1091  // std::cout << " Daughter with " << myPFCandidate.elementsInBlocks().size()<< " element in block " << std::endl;
1092  return cand;
1093  }
1094  if (myPFCandidate->elementsInBlocks()[0].second == refindex) {
1095  // std::cout << " Found it " << cand << std::endl;
1096  return *myPFCandidate;
1097  }
1098  }
1099  return cand;
1100 }
size
Write out results.
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:154
Abstract base class for a PFBlock element (track, cluster...)
std::vector< reco::PreshowerClusterCollection > preshowerClusters_
void setSuperCluster(const reco::SuperClusterRef &r)
set reference to SuperCluster
Definition: PhotonCore.h:48
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void addOneLegConversion(const reco::ConversionRef &r)
add single ConversionRef to the vector of Refs
Definition: PhotonCore.h:54
bool fetchCandidateCollection(edm::Handle< reco::PFCandidateCollection > &c, const edm::InputTag &tag, const edm::Event &iEvent) const
void MustacheID(const CaloClusterPtrVector &clusters, int &nclusters, float &EoutsideMustache)
Definition: Mustache.cc:95
void addConversion(const reco::ConversionRef &r)
add single ConversionRef to the vector of Refs
Definition: PhotonCore.h:52
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void createBasicClusterPtrs(const edm::OrphanHandle< reco::BasicClusterCollection > &basicClustersHandle)
void addHitAndFraction(DetId id, float fraction)
Definition: CaloCluster.h:203
AlgoId algo() const
algorithm identifier
Definition: CaloCluster.h:190
std::string PFPhotonCoreCollection_
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:42
void createBasicCluster(const reco::PFBlockElement &, reco::BasicClusterCollection &basicClusters, std::vector< const reco::PFCluster *> &, const reco::PFCandidate &coCandidate) const
std::vector< float > pfPhotonMva_
double pflowPhiWidth() const
edm::ESHandle< CaloTopology > theCaloTopo_
std::string PFConversionCollection_
edm::InputTag hcalTowers_
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:219
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
Definition: SuperCluster.h:60
bool exists(std::string const &parameterName) const
checks if a parameter exists
T const * product() const
Definition: Handle.h:70
std::vector< reco::ConversionRefVector > pfConv_
edm::InputTag endcapEcalHits_
std::vector< int > conv2legPFCandidateIndex_
double pflowEtaWidth() const
#define X(str)
Definition: MuonsGrabber.cc:38
std::vector< edm::Handle< edm::ValueMap< double > > > IsolationValueMaps
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
std::string PFPhotonCollection_
ErrorD< N >::type type
Definition: Error.h:32
void setSeed(const CaloClusterPtr &r)
list of used xtals by DetId // now inherited by CaloCluster
Definition: SuperCluster.h:109
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
Definition: Point3D.h:10
Log< level::Error, false > LogError
void setPhiWidth(double pw)
Definition: SuperCluster.h:75
const CaloID & caloID() const
Definition: CaloCluster.h:201
void createPreshowerCluster(const reco::PFBlockElement &PFBE, reco::PreshowerClusterCollection &preshowerClusters, unsigned plane) const
std::vector< Conversion > ConversionCollection
collectin of Conversion objects
Definition: ConversionFwd.h:9
std::vector< edm::InputTag > inputTagIsoVals_
std::vector< reco::PhotonRef > egPhotonRef_
std::vector< reco::SuperClusterRef > egSCRef_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
const reco::PFCandidate & correspondingDaughterCandidate(const reco::PFCandidate &cand, const reco::PFBlockElement &pfbe) const
void setEtaWidth(double ew)
Definition: SuperCluster.h:76
std::vector< reco::SuperClusterCollection > superClusters_
int iEvent
Definition: GenABIO.cc:224
const ElementsInBlocks & elementsInBlocks() const
Definition: PFCandidate.cc:663
math::XYZTLorentzVector LorentzVector
void setParentSuperCluster(const reco::SuperClusterRef &r)
set reference to PFlow SuperCluster
Definition: PhotonCore.h:50
std::string PFBasicClusterCollection_
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
void setStandardPhoton(const bool prov)
Definition: PhotonCore.h:59
const EcalMustacheSCParameters * mustacheSCParams_
PFPhotonTranslator(const edm::ParameterSet &)
unsigned index() const
std::string PFSuperClusterCollection_
double energy() const
cluster energy
Definition: PFCluster.h:74
virtual const PFClusterRef & clusterRef() const
std::vector< PreshowerCluster > PreshowerClusterCollection
collection of PreshowerCluster objects
edm::ESHandle< CaloGeometry > theCaloGeom_
math::XYZTLorentzVector LorentzVector
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
math::XYZPoint Point
void createPhotonCores(const edm::OrphanHandle< reco::SuperClusterCollection > &superClustersHandle, const edm::OrphanHandle< reco::ConversionCollection > &oneLegConversionHandle, reco::PhotonCoreCollection &photonCores)
std::vector< int > conv1legPFCandidateIndex_
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float > > XYZVectorF
spatial vector with cartesian internal representation
Definition: Vector3D.h:16
bool isNull() const
Checks for null.
Definition: Ref.h:235
void produce(edm::Event &, const edm::EventSetup &) override
void createPreshowerClusterPtrs(const edm::OrphanHandle< reco::PreshowerClusterCollection > &preshowerClustersHandle)
edm::InputTag barrelEcalHits_
std::string PFPreshowerClusterCollection_
void setPFlowPhoton(const bool prov)
set the provenance
Definition: PhotonCore.h:58
std::vector< int > photPFCandidateIndex_
Definition: DetId.h:17
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
edm::ESGetToken< EcalMustacheSCParameters, EcalMustacheSCParametersRcd > ecalMustacheSCParametersToken_
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
int iseed
Definition: AMPTWrapper.h:134
edm::InputTag inputTagPFCandidates_
std::vector< std::vector< const reco::PFCluster * > > pfClusters_
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
std::vector< reco::BasicClusterCollection > basicClusters_
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
void addPreshowerCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
Definition: SuperCluster.h:130
math::XYZVector Vector
void createPhotons(reco::VertexCollection &vertexCollection, edm::Handle< reco::PhotonCollection > &egPhotons, const edm::OrphanHandle< reco::PhotonCoreCollection > &photonCoresHandle, const IsolationValueMaps &isolationValues, reco::PhotonCollection &photons)
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
void createOneLegConversions(const edm::OrphanHandle< reco::SuperClusterCollection > &superClustersHandle, reco::ConversionCollection &oneLegConversions)
std::array< float, 7 > hcalRecHitSumEt
Definition: Photon.h:419
bool isValid() const
Definition: HandleBase.h:70
std::vector< PhotonCore > PhotonCoreCollection
collectin of PhotonCore objects
Definition: PhotonCoreFwd.h:9
std::vector< float > energyRegression_
void addCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
Definition: SuperCluster.h:124
std::vector< std::vector< reco::TrackRef > > pfSingleLegConv_
std::vector< reco::CaloClusterPtrVector > preshowerClusterPtr_
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
fixed size matrix
HLT enums.
void createSuperClusters(const reco::PFCandidateCollection &, reco::SuperClusterCollection &superClusters) const
void setOneLegMVA(const std::vector< float > &mva)
set the MVS output from PF for one leg conversions
Definition: Conversion.h:163
std::vector< reco::CaloClusterPtrVector > basicClusterPtr_
std::vector< reco::CandidatePtr > CandidatePtr_
std::string EGPhotonCollection_
std::vector< float > energyRegressionError_
Log< level::Warning, false > LogWarning
void addElectronPixelSeed(const reco::ElectronSeedRef &r)
set electron pixel seed ref
Definition: PhotonCore.h:56
def move(src, dest)
Definition: eostools.py:511
std::vector< std::vector< float > > pfSingleLegConvMva_
void setPreshowerEnergy(double preshowerEnergy)
Definition: SuperCluster.h:72