CMS 3D CMS Logo

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