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