00001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00002 #include "FWCore/Framework/interface/ESHandle.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 #include "RecoParticleFlow/PFProducer/plugins/PFPhotonTranslator.h"
00006
00007 #include "RecoParticleFlow/PFClusterTools/interface/PFClusterWidthAlgo.h"
00008 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00009 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00010 #include "DataFormats/EgammaReco/interface/PreshowerCluster.h"
00011 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00012 #include "DataFormats/EgammaCandidates/interface/PhotonCore.h"
00013 #include "DataFormats/EgammaCandidates/interface/Photon.h"
00014 #include "DataFormats/EgammaCandidates/interface/PhotonCoreFwd.h"
00015 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
00016 #include "DataFormats/VertexReco/interface/Vertex.h"
00017 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00018
00019 #include "DataFormats/ParticleFlowReco/interface/PFBlockElement.h"
00020 #include "DataFormats/ParticleFlowReco/interface/PFBlockFwd.h"
00021 #include "DataFormats/ParticleFlowReco/interface/PFBlock.h"
00022
00023 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
00024 #include "RecoEgamma/PhotonIdentification/interface/PhotonIsolationCalculator.h"
00025 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaTowerIsolation.h"
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidatePhotonExtra.h"
00042
00043 #include "DataFormats/Math/interface/Vector3D.h"
00044 #include "DataFormats/Math/interface/LorentzVector.h"
00045 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00046 #include "DataFormats/Common/interface/AssociationVector.h"
00047 #include "RecoEcal/EgammaCoreTools/interface/Mustache.h"
00048
00049 #include <Math/VectorUtil.h>
00050 #include <vector>
00051 #include "TLorentzVector.h"
00052 #include "TMath.h"
00053
00054 using namespace edm;
00055 using namespace std;
00056 using namespace reco;
00057
00058 using namespace ROOT::Math::VectorUtil;
00059 typedef math::XYZTLorentzVector LorentzVector;
00060 typedef math::XYZPoint Point;
00061 typedef math::XYZVector Vector;
00062
00063
00064 PFPhotonTranslator::PFPhotonTranslator(const edm::ParameterSet & iConfig) {
00065
00066
00067
00068 inputTagPFCandidates_
00069 = iConfig.getParameter<edm::InputTag>("PFCandidate");
00070
00071 edm::ParameterSet isoVals = iConfig.getParameter<edm::ParameterSet> ("isolationValues");
00072 inputTagIsoVals_.push_back(isoVals.getParameter<edm::InputTag>("pfChargedHadrons"));
00073 inputTagIsoVals_.push_back(isoVals.getParameter<edm::InputTag>("pfPhotons"));
00074 inputTagIsoVals_.push_back(isoVals.getParameter<edm::InputTag>("pfNeutralHadrons"));
00075
00076
00077 PFBasicClusterCollection_ = iConfig.getParameter<std::string>("PFBasicClusters");
00078 PFPreshowerClusterCollection_ = iConfig.getParameter<std::string>("PFPreshowerClusters");
00079 PFSuperClusterCollection_ = iConfig.getParameter<std::string>("PFSuperClusters");
00080 PFConversionCollection_ = iConfig.getParameter<std::string>("PFConversionCollection");
00081 PFPhotonCoreCollection_ = iConfig.getParameter<std::string>("PFPhotonCores");
00082 PFPhotonCollection_ = iConfig.getParameter<std::string>("PFPhotons");
00083
00084 EGPhotonCollection_ = iConfig.getParameter<std::string>("EGPhotons");
00085
00086 vertexProducer_ = iConfig.getParameter<std::string>("primaryVertexProducer");
00087
00088 barrelEcalHits_ = iConfig.getParameter<edm::InputTag>("barrelEcalHits");
00089 endcapEcalHits_ = iConfig.getParameter<edm::InputTag>("endcapEcalHits");
00090
00091 hcalTowers_ = iConfig.getParameter<edm::InputTag>("hcalTowers");
00092 hOverEConeSize_ = iConfig.getParameter<double>("hOverEConeSize");
00093
00094 if (iConfig.exists("emptyIsOk")) emptyIsOk_ = iConfig.getParameter<bool>("emptyIsOk");
00095 else emptyIsOk_=false;
00096
00097 produces<reco::BasicClusterCollection>(PFBasicClusterCollection_);
00098 produces<reco::PreshowerClusterCollection>(PFPreshowerClusterCollection_);
00099 produces<reco::SuperClusterCollection>(PFSuperClusterCollection_);
00100 produces<reco::PhotonCoreCollection>(PFPhotonCoreCollection_);
00101 produces<reco::PhotonCollection>(PFPhotonCollection_);
00102 produces<reco::ConversionCollection>(PFConversionCollection_);
00103 }
00104
00105 PFPhotonTranslator::~PFPhotonTranslator() {}
00106
00107 void PFPhotonTranslator::beginRun(edm::Run& run,const edm::EventSetup & es) {
00108
00109 }
00110
00111 void PFPhotonTranslator::produce(edm::Event& iEvent,
00112 const edm::EventSetup& iSetup) {
00113
00114
00115
00116 std::auto_ptr<reco::BasicClusterCollection>
00117 basicClusters_p(new reco::BasicClusterCollection);
00118
00119 std::auto_ptr<reco::PreshowerClusterCollection>
00120 psClusters_p(new reco::PreshowerClusterCollection);
00121
00122
00123
00124
00125
00126
00127 reco::SuperClusterCollection outputSuperClusterCollection;
00128 reco::ConversionCollection outputOneLegConversionCollection;
00129 reco::PhotonCoreCollection outputPhotonCoreCollection;
00130 reco::PhotonCollection outputPhotonCollection;
00131
00132 outputSuperClusterCollection.clear();
00133 outputOneLegConversionCollection.clear();
00134 outputPhotonCoreCollection.clear();
00135 outputPhotonCollection.clear();
00136
00137
00138 edm::Handle<reco::PFCandidateCollection> pfCandidates;
00139 bool status=fetchCandidateCollection(pfCandidates,
00140 inputTagPFCandidates_,
00141 iEvent );
00142
00143 edm::Handle<reco::PhotonCollection> egPhotons;
00144 iEvent.getByLabel(EGPhotonCollection_, egPhotons);
00145
00146
00147 Handle<reco::VertexCollection> vertexHandle;
00148
00149
00150 IsolationValueMaps isolationValues(inputTagIsoVals_.size());
00151 for (size_t j = 0; j<inputTagIsoVals_.size(); ++j) {
00152 iEvent.getByLabel(inputTagIsoVals_[j], isolationValues[j]);
00153 }
00154
00155
00156
00157 photPFCandidateIndex_.clear();
00158 basicClusters_.clear();
00159 pfClusters_.clear();
00160 preshowerClusters_.clear();
00161 superClusters_.clear();
00162 basicClusterPtr_.clear();
00163 preshowerClusterPtr_.clear();
00164 CandidatePtr_.clear();
00165 egSCRef_.clear();
00166 egPhotonRef_.clear();
00167 pfPhotonMva_.clear();
00168 energyRegression_.clear();
00169 energyRegressionError_.clear();
00170 pfConv_.clear();
00171 pfSingleLegConv_.clear();
00172 pfSingleLegConvMva_.clear();
00173 conv1legPFCandidateIndex_.clear();
00174 conv2legPFCandidateIndex_.clear();
00175
00176
00177
00178
00179
00180
00181 unsigned ncand=(status)?pfCandidates->size():0;
00182
00183 unsigned iphot=0;
00184 unsigned iconv1leg=0;
00185 unsigned iconv2leg=0;
00186
00187 for( unsigned i=0; i<ncand; ++i ) {
00188
00189 const reco::PFCandidate& cand = (*pfCandidates)[i];
00190 if(cand.particleId()!=reco::PFCandidate::gamma) continue;
00191
00192 if(cand. mva_nothing_gamma()>0.001)
00193 {
00194
00195
00196
00197
00198
00199 if (cand.photonExtraRef()->conversionRef().size()>0){
00200
00201 pfConv_.push_back(reco::ConversionRefVector());
00202
00203 const reco::ConversionRefVector & doubleLegConvColl = cand.photonExtraRef()->conversionRef();
00204 for (unsigned int iconv=0; iconv<doubleLegConvColl.size(); iconv++){
00205 pfConv_[iconv2leg].push_back(doubleLegConvColl[iconv]);
00206 }
00207
00208 conv2legPFCandidateIndex_.push_back(iconv2leg);
00209 iconv2leg++;
00210 }
00211 else conv2legPFCandidateIndex_.push_back(-1);
00212
00213 const std::vector<reco::TrackRef> & singleLegConvColl = cand.photonExtraRef()->singleLegConvTrackRef();
00214 const std::vector<float>& singleLegConvCollMva = cand.photonExtraRef()->singleLegConvMva();
00215
00216
00217
00218 if (singleLegConvColl.size()>0){
00219
00220 pfSingleLegConv_.push_back(std::vector<reco::TrackRef>());
00221 pfSingleLegConvMva_.push_back(std::vector<float>());
00222
00223
00224 for (unsigned int itk=0; itk<singleLegConvColl.size(); itk++){
00225
00226
00227 pfSingleLegConv_[iconv1leg].push_back(singleLegConvColl[itk]);
00228 pfSingleLegConvMva_[iconv1leg].push_back(singleLegConvCollMva[itk]);
00229 }
00230
00231
00232 conv1legPFCandidateIndex_.push_back(iconv1leg);
00233
00234 iconv1leg++;
00235 }
00236 else conv1legPFCandidateIndex_.push_back(-1);
00237
00238 }
00239
00240 photPFCandidateIndex_.push_back(i);
00241 pfPhotonMva_.push_back(cand.mva_nothing_gamma());
00242 energyRegression_.push_back(cand.photonExtraRef()->MVAGlobalCorrE());
00243 energyRegressionError_.push_back(cand.photonExtraRef()->MVAGlobalCorrEError());
00244 basicClusters_.push_back(reco::BasicClusterCollection());
00245 pfClusters_.push_back(std::vector<const reco::PFCluster *>());
00246 preshowerClusters_.push_back(reco::PreshowerClusterCollection());
00247 superClusters_.push_back(reco::SuperClusterCollection());
00248
00249 reco::PFCandidatePtr ptrToPFPhoton(pfCandidates,i);
00250 CandidatePtr_.push_back(ptrToPFPhoton);
00251 egSCRef_.push_back(cand.superClusterRef());
00252
00253
00254 int iegphot=0;
00255 for (reco::PhotonCollection::const_iterator gamIter = egPhotons->begin(); gamIter != egPhotons->end(); ++gamIter){
00256 if (cand.superClusterRef()==gamIter->superCluster()){
00257 reco::PhotonRef PhotRef(reco::PhotonRef(egPhotons, iegphot));
00258 egPhotonRef_.push_back(PhotRef);
00259 }
00260 iegphot++;
00261 }
00262
00263
00264
00265
00266 for(unsigned iele=0; iele<cand.elementsInBlocks().size(); ++iele) {
00267
00268 reco::PFBlockRef blockRef = cand.elementsInBlocks()[iele].first;
00269
00270 unsigned elementIndex = cand.elementsInBlocks()[iele].second;
00271
00272 if(blockRef.isNull()) continue;
00273
00274
00275 const edm::OwnVector< reco::PFBlockElement >& elements = (*blockRef).elements();
00276
00277 const reco::PFBlockElement & pfbe (elements[elementIndex]);
00278
00279 if(pfbe.type()==reco::PFBlockElement::ECAL)
00280 {
00281
00282
00283
00284
00285
00286 createBasicCluster(pfbe,basicClusters_[iphot],pfClusters_[iphot],correspondingDaughterCandidate(cand,pfbe));
00287 }
00288 if(pfbe.type()==reco::PFBlockElement::PS1)
00289 {
00290
00291 createPreshowerCluster(pfbe,preshowerClusters_[iphot],1);
00292 }
00293 if(pfbe.type()==reco::PFBlockElement::PS2)
00294 {
00295
00296 createPreshowerCluster(pfbe,preshowerClusters_[iphot],2);
00297 }
00298
00299
00300 }
00301
00302
00303 basicClusters_p->insert(basicClusters_p->end(),basicClusters_[iphot].begin(), basicClusters_[iphot].end());
00304
00305 psClusters_p->insert(psClusters_p->end(),preshowerClusters_[iphot].begin(),preshowerClusters_[iphot].end());
00306
00307 ++iphot;
00308
00309 }
00310
00311
00312
00313
00314 const edm::OrphanHandle<reco::BasicClusterCollection> bcRefProd =
00315 iEvent.put(basicClusters_p,PFBasicClusterCollection_);
00316
00317
00318 const edm::OrphanHandle<reco::PreshowerClusterCollection> psRefProd =
00319 iEvent.put(psClusters_p,PFPreshowerClusterCollection_);
00320
00321
00322 createBasicClusterPtrs(bcRefProd);
00323
00324 createPreshowerClusterPtrs(psRefProd);
00325
00326
00327
00328 if(status) createSuperClusters(*pfCandidates,outputSuperClusterCollection);
00329
00330
00331
00332
00333 std::auto_ptr<reco::SuperClusterCollection> superClusters_p(new reco::SuperClusterCollection(outputSuperClusterCollection));
00334 const edm::OrphanHandle<reco::SuperClusterCollection> scRefProd = iEvent.put(superClusters_p,PFSuperClusterCollection_);
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349 if (status) createOneLegConversions(scRefProd, outputOneLegConversionCollection);
00350
00351
00352 std::auto_ptr<reco::ConversionCollection> SingleLeg_p(new reco::ConversionCollection(outputOneLegConversionCollection));
00353 const edm::OrphanHandle<reco::ConversionCollection> ConvRefProd = iEvent.put(SingleLeg_p,PFConversionCollection_);
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 if(status) createPhotonCores(scRefProd, ConvRefProd, outputPhotonCoreCollection);
00371
00372
00373
00374
00375 std::auto_ptr<reco::PhotonCoreCollection> photonCores_p(new reco::PhotonCoreCollection(outputPhotonCoreCollection));
00376
00377 const edm::OrphanHandle<reco::PhotonCoreCollection> pcRefProd = iEvent.put(photonCores_p,PFPhotonCoreCollection_);
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409 reco::VertexCollection vertexCollection;
00410 bool validVertex=true;
00411 iEvent.getByLabel(vertexProducer_, vertexHandle);
00412 if (!vertexHandle.isValid()) {
00413 edm::LogWarning("PhotonProducer") << "Error! Can't get the product primary Vertex Collection "<< "\n";
00414 validVertex=false;
00415 }
00416 if (validVertex) vertexCollection = *(vertexHandle.product());
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453 if(status) createPhotons(vertexCollection, egPhotons, pcRefProd, isolationValues, outputPhotonCollection);
00454
00455
00456 std::auto_ptr<reco::PhotonCollection> photons_p(new reco::PhotonCollection(outputPhotonCollection));
00457
00458 const edm::OrphanHandle<reco::PhotonCollection> photonRefProd = iEvent.put(photons_p,PFPhotonCollection_);
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509 }
00510
00511 bool PFPhotonTranslator::fetchCandidateCollection(edm::Handle<reco::PFCandidateCollection>& c,
00512 const edm::InputTag& tag,
00513 const edm::Event& iEvent) const {
00514 bool found = iEvent.getByLabel(tag, c);
00515
00516 if(!found && !emptyIsOk_)
00517 {
00518 std::ostringstream err;
00519 err<<" cannot get PFCandidates: "
00520 <<tag<<std::endl;
00521 edm::LogError("PFPhotonTranslator")<<err.str();
00522 }
00523 return found;
00524
00525 }
00526
00527
00528
00529
00530 void PFPhotonTranslator::createBasicCluster(const reco::PFBlockElement & PFBE,
00531 reco::BasicClusterCollection & basicClusters,
00532 std::vector<const reco::PFCluster *> & pfClusters,
00533 const reco::PFCandidate & coCandidate) const
00534 {
00535 reco::PFClusterRef myPFClusterRef = PFBE.clusterRef();
00536 if(myPFClusterRef.isNull()) return;
00537
00538 const reco::PFCluster & myPFCluster (*myPFClusterRef);
00539 pfClusters.push_back(&myPFCluster);
00540
00541
00542
00543
00544 basicClusters.push_back(reco::CaloCluster(coCandidate.rawEcalEnergy(),
00545 myPFCluster.position(),
00546 myPFCluster.caloID(),
00547 myPFCluster.hitsAndFractions(),
00548 myPFCluster.algo(),
00549 myPFCluster.seed()));
00550 }
00551
00552 void PFPhotonTranslator::createPreshowerCluster(const reco::PFBlockElement & PFBE, reco::PreshowerClusterCollection& preshowerClusters,unsigned plane) const
00553 {
00554 reco::PFClusterRef myPFClusterRef= PFBE.clusterRef();
00555 preshowerClusters.push_back(reco::PreshowerCluster(myPFClusterRef->energy(),myPFClusterRef->position(),
00556 myPFClusterRef->hitsAndFractions(),plane));
00557 }
00558
00559 void PFPhotonTranslator::createBasicClusterPtrs(const edm::OrphanHandle<reco::BasicClusterCollection> & basicClustersHandle )
00560 {
00561 unsigned size=photPFCandidateIndex_.size();
00562 unsigned basicClusterCounter=0;
00563 basicClusterPtr_.resize(size);
00564
00565 for(unsigned iphot=0;iphot<size;++iphot)
00566 {
00567 unsigned nbc=basicClusters_[iphot].size();
00568 for(unsigned ibc=0;ibc<nbc;++ibc)
00569 {
00570
00571 reco::CaloClusterPtr bcPtr(basicClustersHandle,basicClusterCounter);
00572 basicClusterPtr_[iphot].push_back(bcPtr);
00573 ++basicClusterCounter;
00574 }
00575 }
00576 }
00577
00578 void PFPhotonTranslator::createPreshowerClusterPtrs(const edm::OrphanHandle<reco::PreshowerClusterCollection> & preshowerClustersHandle )
00579 {
00580 unsigned size=photPFCandidateIndex_.size();
00581 unsigned psClusterCounter=0;
00582 preshowerClusterPtr_.resize(size);
00583
00584 for(unsigned iphot=0;iphot<size;++iphot)
00585 {
00586 unsigned nbc=preshowerClusters_[iphot].size();
00587 for(unsigned ibc=0;ibc<nbc;++ibc)
00588 {
00589
00590 reco::CaloClusterPtr psPtr(preshowerClustersHandle,psClusterCounter);
00591 preshowerClusterPtr_[iphot].push_back(psPtr);
00592 ++psClusterCounter;
00593 }
00594 }
00595 }
00596
00597 void PFPhotonTranslator::createSuperClusters(const reco::PFCandidateCollection & pfCand,
00598 reco::SuperClusterCollection &superClusters) const
00599 {
00600 unsigned nphot=photPFCandidateIndex_.size();
00601 for(unsigned iphot=0;iphot<nphot;++iphot)
00602 {
00603
00604
00605
00606
00607 double sclusterE=0;
00608 double posX=0.;
00609 double posY=0.;
00610 double posZ=0.;
00611
00612 unsigned nbasics=basicClusters_[iphot].size();
00613 for(unsigned ibc=0;ibc<nbasics;++ibc)
00614 {
00615
00616
00617 double e = basicClusters_[iphot][ibc].energy();
00618 sclusterE += e;
00619 posX += e * basicClusters_[iphot][ibc].position().X();
00620 posY += e * basicClusters_[iphot][ibc].position().Y();
00621 posZ += e * basicClusters_[iphot][ibc].position().Z();
00622 }
00623 posX /=sclusterE;
00624 posY /=sclusterE;
00625 posZ /=sclusterE;
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635 PFClusterWidthAlgo pfwidth(pfClusters_[iphot]);
00636
00637 double correctedEnergy=pfCand[photPFCandidateIndex_[iphot]].ecalEnergy();
00638 reco::SuperCluster mySuperCluster(correctedEnergy,math::XYZPoint(posX,posY,posZ));
00639
00640 if(nbasics)
00641 {
00642
00643
00644
00645 mySuperCluster.setSeed(basicClusterPtr_[iphot][0]);
00646 }
00647 else
00648 {
00649
00650
00651
00652
00653
00654 mySuperCluster.setSeed(reco::CaloClusterPtr());
00655 }
00656
00657
00658 for(unsigned ibc=0;ibc<nbasics;++ibc)
00659 {
00660 mySuperCluster.addCluster(basicClusterPtr_[iphot][ibc]);
00661
00662 const std::vector< std::pair<DetId, float> > & v1 = basicClusters_[iphot][ibc].hitsAndFractions();
00663
00664 for( std::vector< std::pair<DetId, float> >::const_iterator diIt = v1.begin();
00665 diIt != v1.end();
00666 ++diIt ) {
00667
00668 mySuperCluster.addHitAndFraction(diIt->first,diIt->second);
00669 }
00670 }
00671
00672 unsigned nps=preshowerClusterPtr_[iphot].size();
00673 for(unsigned ips=0;ips<nps;++ips)
00674 {
00675 mySuperCluster.addPreshowerCluster(preshowerClusterPtr_[iphot][ips]);
00676 }
00677
00678
00679
00680 mySuperCluster.setPreshowerEnergy(pfCand[photPFCandidateIndex_[iphot]].pS1Energy()+
00681 pfCand[photPFCandidateIndex_[iphot]].pS2Energy());
00682
00683
00684 mySuperCluster.setEtaWidth(pfwidth.pflowEtaWidth());
00685 mySuperCluster.setPhiWidth(pfwidth.pflowPhiWidth());
00686
00687 mySuperCluster.rawEnergy();
00688
00689
00690
00691 superClusters.push_back(mySuperCluster);
00692
00693 }
00694 }
00695
00696 void PFPhotonTranslator::createOneLegConversions(const edm::OrphanHandle<reco::SuperClusterCollection> & superClustersHandle, reco::ConversionCollection &oneLegConversions)
00697 {
00698
00699
00700
00701 unsigned nphot=photPFCandidateIndex_.size();
00702 for(unsigned iphot=0;iphot<nphot;++iphot)
00703 {
00704
00705
00706
00707
00708
00709 if (conv1legPFCandidateIndex_[iphot]>-1){
00710
00711 for (unsigned iConv=0; iConv<pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]].size(); iConv++){
00712
00713 reco::CaloClusterPtrVector scPtrVec;
00714
00715 math::Error<3>::type error;
00716 const reco::Vertex * convVtx = new reco::Vertex(pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->innerPosition(), error);
00717
00718
00719
00720
00721 std::vector<reco::TrackRef> OneLegConvVector;
00722 OneLegConvVector.push_back(pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]);
00723
00724 reco::Conversion myOneLegConversion(scPtrVec, OneLegConvVector, *convVtx, reco::Conversion::pflow);
00725
00726
00727 std::vector< float > OneLegMvaVector;
00728 OneLegMvaVector.push_back(pfSingleLegConvMva_[conv1legPFCandidateIndex_[iphot]][iConv]);
00729 myOneLegConversion.setOneLegMVA(OneLegMvaVector);
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743 oneLegConversions.push_back(myOneLegConversion);
00744
00745
00746
00747 }
00748 }
00749 }
00750 }
00751
00752
00753 void PFPhotonTranslator::createPhotonCores(const edm::OrphanHandle<reco::SuperClusterCollection> & superClustersHandle, const edm::OrphanHandle<reco::ConversionCollection> & oneLegConversionHandle, reco::PhotonCoreCollection &photonCores)
00754 {
00755
00756
00757
00758 unsigned nphot=photPFCandidateIndex_.size();
00759
00760 unsigned i1legtot = 0;
00761
00762 for(unsigned iphot=0;iphot<nphot;++iphot)
00763 {
00764
00765
00766 reco::PhotonCore myPhotonCore;
00767
00768 reco::SuperClusterRef SCref(reco::SuperClusterRef(superClustersHandle, iphot));
00769
00770 myPhotonCore.setPFlowPhoton(true);
00771 myPhotonCore.setStandardPhoton(false);
00772 myPhotonCore.setPflowSuperCluster(SCref);
00773 myPhotonCore.setSuperCluster(egSCRef_[iphot]);
00774
00775 reco::ElectronSeedRefVector pixelSeeds = egPhotonRef_[iphot]->electronPixelSeeds();
00776 for (unsigned iseed=0; iseed<pixelSeeds.size(); iseed++){
00777 myPhotonCore.addElectronPixelSeed(pixelSeeds[iseed]);
00778 }
00779
00780
00781
00782
00783
00784
00785 if (conv1legPFCandidateIndex_[iphot]>-1){
00786 for (unsigned int iConv=0; iConv<pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]].size(); iConv++){
00787
00788 const reco::ConversionRef & OneLegRef(reco::ConversionRef(oneLegConversionHandle, i1legtot));
00789 myPhotonCore.addOneLegConversion(OneLegRef);
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808 i1legtot++;
00809 }
00810 }
00811
00812 if (conv2legPFCandidateIndex_[iphot]>-1){
00813 for(unsigned int iConv=0; iConv<pfConv_[conv2legPFCandidateIndex_[iphot]].size(); iConv++) {
00814
00815 const reco::ConversionRef & TwoLegRef(pfConv_[conv2legPFCandidateIndex_[iphot]][iConv]);
00816 myPhotonCore.addConversion(TwoLegRef);
00817
00818 }
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836 }
00837
00838 photonCores.push_back(myPhotonCore);
00839
00840 }
00841
00842
00843 }
00844
00845
00846 void PFPhotonTranslator::createPhotons(reco::VertexCollection &vertexCollection, edm::Handle<reco::PhotonCollection> &egPhotons, const edm::OrphanHandle<reco::PhotonCoreCollection> & photonCoresHandle, const IsolationValueMaps& isolationValues, reco::PhotonCollection &photons)
00847 {
00848
00849
00850
00851 unsigned nphot=photPFCandidateIndex_.size();
00852
00853 for(unsigned iphot=0;iphot<nphot;++iphot)
00854 {
00855
00856
00857 reco::PhotonCoreRef PCref(reco::PhotonCoreRef(photonCoresHandle, iphot));
00858
00859 math::XYZPoint vtx(0.,0.,0.);
00860 if (vertexCollection.size()>0) vtx = vertexCollection.begin()->position();
00861
00862
00863 math::XYZVector direction = PCref->pfSuperCluster()->position() - vtx;
00864
00865
00866 math::XYZVector P3 = direction.unit() * PCref->pfSuperCluster()->energy();
00867 LorentzVector P4(P3.x(), P3.y(), P3.z(), PCref->pfSuperCluster()->energy());
00868
00869 reco::Photon myPhoton(P4, PCref->pfSuperCluster()->position(), PCref, vtx);
00870
00871
00872
00873
00874 reco::Photon::ShowerShape showerShape;
00875 reco::Photon::FiducialFlags fiducialFlags;
00876 reco::Photon::IsolationVariables isolationVariables03;
00877 reco::Photon::IsolationVariables isolationVariables04;
00878
00879 showerShape.e1x5= egPhotonRef_[iphot]->e1x5();
00880 showerShape.e2x5= egPhotonRef_[iphot]->e2x5();
00881 showerShape.e3x3= egPhotonRef_[iphot]->e3x3();
00882 showerShape.e5x5= egPhotonRef_[iphot]->e5x5();
00883 showerShape.maxEnergyXtal = egPhotonRef_[iphot]->maxEnergyXtal();
00884 showerShape.sigmaEtaEta = egPhotonRef_[iphot]->sigmaEtaEta();
00885 showerShape.sigmaIetaIeta = egPhotonRef_[iphot]->sigmaIetaIeta();
00886 showerShape.hcalDepth1OverEcal = egPhotonRef_[iphot]->hadronicDepth1OverEm();
00887 showerShape.hcalDepth2OverEcal = egPhotonRef_[iphot]->hadronicDepth2OverEm();
00888 myPhoton.setShowerShapeVariables ( showerShape );
00889
00890 fiducialFlags.isEB = egPhotonRef_[iphot]->isEB();
00891 fiducialFlags.isEE = egPhotonRef_[iphot]->isEE();
00892 fiducialFlags.isEBEtaGap = egPhotonRef_[iphot]->isEBEtaGap();
00893 fiducialFlags.isEBPhiGap = egPhotonRef_[iphot]->isEBPhiGap();
00894 fiducialFlags.isEERingGap = egPhotonRef_[iphot]->isEERingGap();
00895 fiducialFlags.isEEDeeGap = egPhotonRef_[iphot]->isEEDeeGap();
00896 fiducialFlags.isEBEEGap = egPhotonRef_[iphot]->isEBEEGap();
00897 myPhoton.setFiducialVolumeFlags ( fiducialFlags );
00898
00899 isolationVariables03.ecalRecHitSumEt = egPhotonRef_[iphot]->ecalRecHitSumEtConeDR03();
00900 isolationVariables03.hcalTowerSumEt = egPhotonRef_[iphot]->hcalTowerSumEtConeDR03();
00901 isolationVariables03.hcalDepth1TowerSumEt = egPhotonRef_[iphot]->hcalDepth1TowerSumEtConeDR03();
00902 isolationVariables03.hcalDepth2TowerSumEt = egPhotonRef_[iphot]->hcalDepth2TowerSumEtConeDR03();
00903 isolationVariables03.trkSumPtSolidCone = egPhotonRef_[iphot]->trkSumPtSolidConeDR03();
00904 isolationVariables03.trkSumPtHollowCone = egPhotonRef_[iphot]->trkSumPtHollowConeDR03();
00905 isolationVariables03.nTrkSolidCone = egPhotonRef_[iphot]->nTrkSolidConeDR03();
00906 isolationVariables03.nTrkHollowCone = egPhotonRef_[iphot]->nTrkHollowConeDR03();
00907 isolationVariables04.ecalRecHitSumEt = egPhotonRef_[iphot]->ecalRecHitSumEtConeDR04();
00908 isolationVariables04.hcalTowerSumEt = egPhotonRef_[iphot]->hcalTowerSumEtConeDR04();
00909 isolationVariables04.hcalDepth1TowerSumEt = egPhotonRef_[iphot]->hcalDepth1TowerSumEtConeDR04();
00910 isolationVariables04.hcalDepth2TowerSumEt = egPhotonRef_[iphot]->hcalDepth2TowerSumEtConeDR04();
00911 isolationVariables04.trkSumPtSolidCone = egPhotonRef_[iphot]->trkSumPtSolidConeDR04();
00912 isolationVariables04.trkSumPtHollowCone = egPhotonRef_[iphot]->trkSumPtHollowConeDR04();
00913 isolationVariables04.nTrkSolidCone = egPhotonRef_[iphot]->nTrkSolidConeDR04();
00914 isolationVariables04.nTrkHollowCone = egPhotonRef_[iphot]->nTrkHollowConeDR04();
00915 myPhoton.setIsolationVariables(isolationVariables04, isolationVariables03);
00916
00917
00918
00919
00920 reco::Photon::PflowIsolationVariables myPFIso;
00921 myPFIso.chargedHadronIso=(*isolationValues[0])[CandidatePtr_[iphot]];
00922 myPFIso.photonIso=(*isolationValues[1])[CandidatePtr_[iphot]];
00923 myPFIso.neutralHadronIso=(*isolationValues[2])[CandidatePtr_[iphot]];
00924 myPhoton.setPflowIsolationVariables(myPFIso);
00925
00926 reco::Photon::PflowIDVariables myPFVariables;
00927
00928 reco::Mustache myMustache;
00929 myMustache.MustacheID(*(myPhoton.pfSuperCluster()), myPFVariables.nClusterOutsideMustache, myPFVariables.etOutsideMustache );
00930 myPFVariables.mva = pfPhotonMva_[iphot];
00931 myPhoton.setPflowIDVariables(myPFVariables);
00932
00933
00934
00935
00936 myPhoton.setCorrectedEnergy(reco::Photon::regression2,energyRegression_[iphot],energyRegressionError_[iphot],false);
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994 photons.push_back(myPhoton);
00995
00996 }
00997
00998
00999 }
01000
01001
01002 const reco::PFCandidate & PFPhotonTranslator::correspondingDaughterCandidate(const reco::PFCandidate & cand, const reco::PFBlockElement & pfbe) const
01003 {
01004 unsigned refindex=pfbe.index();
01005
01006 reco::PFCandidate::const_iterator myDaughterCandidate=cand.begin();
01007 reco::PFCandidate::const_iterator itend=cand.end();
01008
01009 for(;myDaughterCandidate!=itend;++myDaughterCandidate)
01010 {
01011 const reco::PFCandidate * myPFCandidate = (const reco::PFCandidate*)&*myDaughterCandidate;
01012 if(myPFCandidate->elementsInBlocks().size()!=1)
01013 {
01014
01015 return cand;
01016 }
01017 if(myPFCandidate->elementsInBlocks()[0].second==refindex)
01018 {
01019
01020 return *myPFCandidate;
01021 }
01022 }
01023 return cand;
01024 }
01025