51 std::vector<const reco::PFCluster *> &,
56 unsigned plane)
const;
125 std::vector<reco::ConversionRefVector>
pfConv_;
142 using namespace reco;
154 inputTagIsoVals_.push_back(isoVals.getParameter<
edm::InputTag>(
"pfChargedHadrons"));
155 inputTagIsoVals_.push_back(isoVals.getParameter<
edm::InputTag>(
"pfPhotons"));
156 inputTagIsoVals_.push_back(isoVals.getParameter<
edm::InputTag>(
"pfNeutralHadrons"));
173 hOverEConeSize_ = iConfig.
getParameter<
double>(
"hOverEConeSize");
175 if (iConfig.
exists(
"emptyIsOk"))
180 produces<reco::BasicClusterCollection>(PFBasicClusterCollection_);
181 produces<reco::PreshowerClusterCollection>(PFPreshowerClusterCollection_);
182 produces<reco::SuperClusterCollection>(PFSuperClusterCollection_);
183 produces<reco::PhotonCoreCollection>(PFPhotonCoreCollection_);
184 produces<reco::PhotonCollection>(PFPhotonCollection_);
185 produces<reco::ConversionCollection>(PFConversionCollection_);
193 auto basicClusters_p = std::make_unique<reco::BasicClusterCollection>();
195 auto psClusters_p = std::make_unique<reco::PreshowerClusterCollection>();
206 outputSuperClusterCollection.clear();
207 outputOneLegConversionCollection.clear();
208 outputPhotonCoreCollection.clear();
215 iEvent.getByLabel(EGPhotonCollection_, egPhotons);
220 for (
size_t j = 0;
j < inputTagIsoVals_.size(); ++
j) {
225 photPFCandidateIndex_.clear();
226 basicClusters_.clear();
228 preshowerClusters_.clear();
229 superClusters_.clear();
230 basicClusterPtr_.clear();
231 preshowerClusterPtr_.clear();
232 CandidatePtr_.clear();
234 egPhotonRef_.clear();
235 pfPhotonMva_.clear();
236 energyRegression_.clear();
237 energyRegressionError_.clear();
239 pfSingleLegConv_.clear();
240 pfSingleLegConvMva_.clear();
241 conv1legPFCandidateIndex_.clear();
242 conv2legPFCandidateIndex_.clear();
252 unsigned iconv1leg = 0;
253 unsigned iconv2leg = 0;
255 for (
unsigned i = 0;
i < ncand; ++
i) {
260 if (
cand.mva_nothing_gamma() > 0.001)
266 if (!
cand.photonExtraRef()->conversionRef().empty()) {
270 for (
unsigned int iconv = 0; iconv < doubleLegConvColl.
size(); iconv++) {
271 pfConv_[iconv2leg].push_back(doubleLegConvColl[iconv]);
274 conv2legPFCandidateIndex_.push_back(iconv2leg);
277 conv2legPFCandidateIndex_.push_back(-1);
279 const std::vector<reco::TrackRef> &singleLegConvColl =
cand.photonExtraRef()->singleLegConvTrackRef();
280 const std::vector<float> &singleLegConvCollMva =
cand.photonExtraRef()->singleLegConvMva();
284 if (!singleLegConvColl.empty()) {
285 pfSingleLegConv_.push_back(std::vector<reco::TrackRef>());
286 pfSingleLegConvMva_.push_back(std::vector<float>());
289 for (
unsigned int itk = 0; itk < singleLegConvColl.size(); itk++) {
292 pfSingleLegConv_[iconv1leg].push_back(singleLegConvColl[itk]);
293 pfSingleLegConvMva_[iconv1leg].push_back(singleLegConvCollMva[itk]);
296 conv1legPFCandidateIndex_.push_back(iconv1leg);
300 conv1legPFCandidateIndex_.push_back(-1);
303 photPFCandidateIndex_.push_back(
i);
304 pfPhotonMva_.push_back(
cand.mva_nothing_gamma());
305 energyRegression_.push_back(
cand.photonExtraRef()->MVAGlobalCorrE());
306 energyRegressionError_.push_back(
cand.photonExtraRef()->MVAGlobalCorrEError());
308 pfClusters_.push_back(std::vector<const reco::PFCluster *>());
313 CandidatePtr_.push_back(ptrToPFPhoton);
314 egSCRef_.push_back(
cand.superClusterRef());
318 for (reco::PhotonCollection::const_iterator gamIter = egPhotons->begin(); gamIter != egPhotons->end(); ++gamIter) {
319 if (
cand.superClusterRef() == gamIter->superCluster()) {
321 egPhotonRef_.push_back(PhotRef);
328 for (
unsigned iele = 0; iele <
cand.elementsInBlocks().size(); ++iele) {
332 unsigned elementIndex =
cand.elementsInBlocks()[iele].second;
347 createBasicCluster(pfbe, basicClusters_[iphot], pfClusters_[iphot], correspondingDaughterCandidate(
cand, pfbe));
351 createPreshowerCluster(pfbe, preshowerClusters_[iphot], 1);
355 createPreshowerCluster(pfbe, preshowerClusters_[iphot], 2);
361 basicClusters_p->insert(basicClusters_p->end(), basicClusters_[iphot].begin(), basicClusters_[iphot].end());
363 psClusters_p->insert(psClusters_p->end(), preshowerClusters_[iphot].begin(), preshowerClusters_[iphot].end());
379 createBasicClusterPtrs(bcRefProd);
381 createPreshowerClusterPtrs(psRefProd);
386 createSuperClusters(*
pfCandidates, outputSuperClusterCollection);
391 auto superClusters_p = std::make_unique<reco::SuperClusterCollection>(outputSuperClusterCollection);
406 createOneLegConversions(scRefProd, outputOneLegConversionCollection);
408 auto SingleLeg_p = std::make_unique<reco::ConversionCollection>(outputOneLegConversionCollection);
428 createPhotonCores(scRefProd, ConvRefProd, outputPhotonCoreCollection);
433 auto photonCores_p = std::make_unique<reco::PhotonCoreCollection>(outputPhotonCoreCollection);
469 bool validVertex =
true;
470 iEvent.getByLabel(vertexProducer_, vertexHandle);
472 edm::LogWarning(
"PhotonProducer") <<
"Error! Can't get the product primary Vertex Collection "
577 if (!
found && !emptyIsOk_) {
578 std::ostringstream
err;
579 err <<
" cannot get PFCandidates: " <<
tag << std::endl;
590 std::vector<const reco::PFCluster *> &pfClusters,
593 if (myPFClusterRef.
isNull())
597 pfClusters.push_back(&myPFCluster);
608 myPFCluster.
seed()));
613 unsigned plane)
const {
616 myPFClusterRef->energy(), myPFClusterRef->position(), myPFClusterRef->hitsAndFractions(), plane));
621 unsigned size = photPFCandidateIndex_.size();
622 unsigned basicClusterCounter = 0;
623 basicClusterPtr_.resize(
size);
625 for (
unsigned iphot = 0; iphot <
size; ++iphot)
627 unsigned nbc = basicClusters_[iphot].size();
628 for (
unsigned ibc = 0; ibc < nbc; ++ibc)
632 basicClusterPtr_[iphot].push_back(bcPtr);
633 ++basicClusterCounter;
640 unsigned size = photPFCandidateIndex_.size();
641 unsigned psClusterCounter = 0;
642 preshowerClusterPtr_.resize(
size);
644 for (
unsigned iphot = 0; iphot <
size; ++iphot)
646 unsigned nbc = preshowerClusters_[iphot].size();
647 for (
unsigned ibc = 0; ibc < nbc; ++ibc)
651 preshowerClusterPtr_[iphot].push_back(psPtr);
659 unsigned nphot = photPFCandidateIndex_.size();
660 for (
unsigned iphot = 0; iphot < nphot; ++iphot) {
664 double sclusterE = 0;
669 unsigned nbasics = basicClusters_[iphot].size();
670 for (
unsigned ibc = 0; ibc < nbasics; ++ibc) {
673 double e = basicClusters_[iphot][ibc].energy();
675 posX +=
e * basicClusters_[iphot][ibc].position().X();
676 posY +=
e * basicClusters_[iphot][ibc].position().Y();
677 posZ +=
e * basicClusters_[iphot][ibc].position().Z();
693 double correctedEnergy = pfCand[photPFCandidateIndex_[iphot]].ecalEnergy();
700 mySuperCluster.
setSeed(basicClusterPtr_[iphot][0]);
711 for (
unsigned ibc = 0; ibc < nbasics; ++ibc) {
712 mySuperCluster.
addCluster(basicClusterPtr_[iphot][ibc]);
714 const std::vector<std::pair<DetId, float> > &v1 = basicClusters_[iphot][ibc].hitsAndFractions();
716 for (std::vector<std::pair<DetId, float> >::const_iterator diIt = v1.begin(); diIt != v1.end(); ++diIt) {
722 unsigned nps = preshowerClusterPtr_[iphot].size();
723 for (
unsigned ips = 0; ips < nps; ++ips) {
729 pfCand[photPFCandidateIndex_[iphot]].pS2Energy());
749 unsigned nphot = photPFCandidateIndex_.size();
750 for (
unsigned iphot = 0; iphot < nphot; ++iphot) {
754 if (conv1legPFCandidateIndex_[iphot] > -1) {
755 for (
unsigned iConv = 0; iConv < pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]].size(); iConv++) {
757 std::vector<reco::CaloClusterPtr> matchingBC;
760 new reco::Vertex(pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->innerPosition(),
error);
765 std::vector<reco::TrackRef> OneLegConvVector;
766 OneLegConvVector.push_back(pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]);
768 std::vector<reco::TrackRef> tr = OneLegConvVector;
769 std::vector<math::XYZPointF> trackPositionAtEcalVec;
770 std::vector<math::XYZPointF> innPointVec;
771 std::vector<math::XYZVectorF> trackPinVec;
772 std::vector<math::XYZVectorF> trackPoutVec;
774 pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->outerPosition().
X(),
775 pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->outerPosition().
Y(),
776 pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->outerPosition().
Z());
777 math::XYZPointF innPoint(pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->innerPosition().
X(),
778 pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->innerPosition().
Y(),
779 pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->innerPosition().
Z());
780 math::XYZVectorF trackPin(pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->innerMomentum().
X(),
781 pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->innerMomentum().
Y(),
782 pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->innerMomentum().
Z());
783 math::XYZVectorF trackPout(pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->outerMomentum().
X(),
784 pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->outerMomentum().
Y(),
785 pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->outerMomentum().
Z());
786 float DCA = pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]][iConv]->d0();
787 trackPositionAtEcalVec.push_back(trackPositionAtEcal);
788 innPointVec.push_back(innPoint);
789 trackPinVec.push_back(trackPin);
790 trackPoutVec.push_back(trackPout);
791 std::vector<float> OneLegMvaVector;
794 trackPositionAtEcalVec,
801 pfSingleLegConvMva_[conv1legPFCandidateIndex_[iphot]][iConv],
803 OneLegMvaVector.push_back(pfSingleLegConvMva_[conv1legPFCandidateIndex_[iphot]][iConv]);
820 oneLegConversions.push_back(myOneLegConversion);
833 unsigned nphot = photPFCandidateIndex_.size();
835 unsigned i1legtot = 0;
837 for (
unsigned iphot = 0; iphot < nphot; ++iphot) {
859 if (conv1legPFCandidateIndex_[iphot] > -1) {
860 for (
unsigned int iConv = 0; iConv < pfSingleLegConv_[conv1legPFCandidateIndex_[iphot]].size(); iConv++) {
885 if (conv2legPFCandidateIndex_[iphot] > -1) {
886 for (
unsigned int iConv = 0; iConv < pfConv_[conv2legPFCandidateIndex_[iphot]].size(); iConv++) {
909 photonCores.push_back(myPhotonCore);
922 unsigned nphot = photPFCandidateIndex_.size();
924 for (
unsigned iphot = 0; iphot < nphot; ++iphot) {
937 math::XYZVector P3 = direction.unit() * PCref->parentSuperCluster()->energy();
938 LorentzVector P4(P3.x(), P3.y(), P3.z(), PCref->parentSuperCluster()->energy());
940 reco::Photon myPhoton(P4, PCref->parentSuperCluster()->position(), PCref,
vtx);
949 showerShape.e1x5 = egPhotonRef_[iphot]->e1x5();
950 showerShape.e2x5 = egPhotonRef_[iphot]->e2x5();
951 showerShape.e3x3 = egPhotonRef_[iphot]->e3x3();
952 showerShape.e5x5 = egPhotonRef_[iphot]->e5x5();
953 showerShape.maxEnergyXtal = egPhotonRef_[iphot]->maxEnergyXtal();
954 showerShape.sigmaEtaEta = egPhotonRef_[iphot]->sigmaEtaEta();
955 showerShape.sigmaIetaIeta = egPhotonRef_[iphot]->sigmaIetaIeta();
956 showerShape.hcalDepth1OverEcal = egPhotonRef_[iphot]->hadronicDepth1OverEm();
957 showerShape.hcalDepth2OverEcal = egPhotonRef_[iphot]->hadronicDepth2OverEm();
958 myPhoton.setShowerShapeVariables(showerShape);
960 saturationInfo.
nSaturatedXtals = egPhotonRef_[iphot]->nSaturatedXtals();
961 saturationInfo.
isSeedSaturated = egPhotonRef_[iphot]->isSeedSaturated();
962 myPhoton.setSaturationInfo(saturationInfo);
964 fiducialFlags.
isEB = egPhotonRef_[iphot]->isEB();
965 fiducialFlags.
isEE = egPhotonRef_[iphot]->isEE();
966 fiducialFlags.
isEBEtaGap = egPhotonRef_[iphot]->isEBEtaGap();
967 fiducialFlags.
isEBPhiGap = egPhotonRef_[iphot]->isEBPhiGap();
968 fiducialFlags.
isEERingGap = egPhotonRef_[iphot]->isEERingGap();
969 fiducialFlags.
isEEDeeGap = egPhotonRef_[iphot]->isEEDeeGap();
970 fiducialFlags.
isEBEEGap = egPhotonRef_[iphot]->isEBEEGap();
971 myPhoton.setFiducialVolumeFlags(fiducialFlags);
973 isolationVariables03.
ecalRecHitSumEt = egPhotonRef_[iphot]->ecalRecHitSumEtConeDR03();
974 isolationVariables03.
hcalTowerSumEt = egPhotonRef_[iphot]->hcalTowerSumEtConeDR03();
975 isolationVariables03.
hcalDepth1TowerSumEt = egPhotonRef_[iphot]->hcalDepth1TowerSumEtConeDR03();
976 isolationVariables03.
hcalDepth2TowerSumEt = egPhotonRef_[iphot]->hcalDepth2TowerSumEtConeDR03();
977 isolationVariables03.
trkSumPtSolidCone = egPhotonRef_[iphot]->trkSumPtSolidConeDR03();
978 isolationVariables03.
trkSumPtHollowCone = egPhotonRef_[iphot]->trkSumPtHollowConeDR03();
979 isolationVariables03.
nTrkSolidCone = egPhotonRef_[iphot]->nTrkSolidConeDR03();
980 isolationVariables03.
nTrkHollowCone = egPhotonRef_[iphot]->nTrkHollowConeDR03();
981 isolationVariables04.
ecalRecHitSumEt = egPhotonRef_[iphot]->ecalRecHitSumEtConeDR04();
982 isolationVariables04.
hcalTowerSumEt = egPhotonRef_[iphot]->hcalTowerSumEtConeDR04();
983 isolationVariables04.
hcalDepth1TowerSumEt = egPhotonRef_[iphot]->hcalDepth1TowerSumEtConeDR04();
984 isolationVariables04.
hcalDepth2TowerSumEt = egPhotonRef_[iphot]->hcalDepth2TowerSumEtConeDR04();
985 isolationVariables04.
trkSumPtSolidCone = egPhotonRef_[iphot]->trkSumPtSolidConeDR04();
986 isolationVariables04.
trkSumPtHollowCone = egPhotonRef_[iphot]->trkSumPtHollowConeDR04();
987 isolationVariables04.
nTrkSolidCone = egPhotonRef_[iphot]->nTrkSolidConeDR04();
988 isolationVariables04.
nTrkHollowCone = egPhotonRef_[iphot]->nTrkHollowConeDR04();
989 myPhoton.setIsolationVariables(isolationVariables04, isolationVariables03);
995 myPhoton.setPflowIsolationVariables(myPFIso);
1002 myPFVariables.
mva = pfPhotonMva_[iphot];
1003 myPhoton.setPflowIDVariables(myPFVariables);
1008 myPhoton.setCorrectedEnergy(
1073 unsigned refindex = pfbe.
index();
1078 for (; myDaughterCandidate != itend; ++myDaughterCandidate) {
1086 return *myPFCandidate;