Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:25

0001 //
0002 //
0003 
0004 #include "DataFormats/PatCandidates/interface/Photon.h"
0005 #include "DataFormats/Common/interface/RefToPtr.h"
0006 
0007 using pat::Photon;
0008 
0009 /// default constructor
0010 Photon::Photon()
0011     : PATObject<reco::Photon>(reco::Photon()),
0012       embeddedSuperCluster_(false),
0013       embeddedSeedCluster_(false),
0014       embeddedRecHits_(false),
0015       passElectronVeto_(false),
0016       hasPixelSeed_(false),
0017       seedEnergy_(0.0),
0018       eMax_(0.0),
0019       e2nd_(0.0),
0020       e3x3_(0.0),
0021       eTop_(0.0),
0022       eBottom_(0.0),
0023       eLeft_(0.0),
0024       eRight_(0.0),
0025       see_(-999.),
0026       spp_(-999.),
0027       sep_(-999.),
0028       maxDR_(-999.),
0029       maxDRDPhi_(-999.),
0030       maxDRDEta_(-999.),
0031       maxDRRawEnergy_(-999.),
0032       subClusRawE1_(-999.),
0033       subClusRawE2_(-999.),
0034       subClusRawE3_(-999.),
0035       subClusDPhi1_(-999.),
0036       subClusDPhi2_(-999.),
0037       subClusDPhi3_(-999.),
0038       subClusDEta1_(-999.),
0039       subClusDEta2_(-999.),
0040       subClusDEta3_(-999.),
0041       cryEta_(-999.),
0042       cryPhi_(-999),
0043       iEta_(-999),
0044       iPhi_(-999) {}
0045 
0046 /// constructor from reco::Photon
0047 Photon::Photon(const reco::Photon& aPhoton)
0048     : PATObject<reco::Photon>(aPhoton),
0049       embeddedSuperCluster_(false),
0050       embeddedSeedCluster_(false),
0051       embeddedRecHits_(false),
0052       passElectronVeto_(false),
0053       hasPixelSeed_(false),
0054       seedEnergy_(0.0),
0055       eMax_(0.0),
0056       e2nd_(0.0),
0057       e3x3_(0.0),
0058       eTop_(0.0),
0059       eBottom_(0.0),
0060       eLeft_(0.0),
0061       eRight_(0.0),
0062       see_(-999.),
0063       spp_(-999.),
0064       sep_(-999.),
0065       maxDR_(-999.),
0066       maxDRDPhi_(-999.),
0067       maxDRDEta_(-999.),
0068       maxDRRawEnergy_(-999.),
0069       subClusRawE1_(-999.),
0070       subClusRawE2_(-999.),
0071       subClusRawE3_(-999.),
0072       subClusDPhi1_(-999.),
0073       subClusDPhi2_(-999.),
0074       subClusDPhi3_(-999.),
0075       subClusDEta1_(-999.),
0076       subClusDEta2_(-999.),
0077       subClusDEta3_(-999.),
0078       cryEta_(-999.),
0079       cryPhi_(-999),
0080       iEta_(-999),
0081       iPhi_(-999) {}
0082 
0083 /// constructor from ref to reco::Photon
0084 Photon::Photon(const edm::RefToBase<reco::Photon>& aPhotonRef)
0085     : PATObject<reco::Photon>(aPhotonRef),
0086       embeddedSuperCluster_(false),
0087       embeddedSeedCluster_(false),
0088       embeddedRecHits_(false),
0089       passElectronVeto_(false),
0090       hasPixelSeed_(false),
0091       seedEnergy_(0.0),
0092       eMax_(0.0),
0093       e2nd_(0.0),
0094       e3x3_(0.0),
0095       eTop_(0.0),
0096       eBottom_(0.0),
0097       eLeft_(0.0),
0098       eRight_(0.0),
0099       see_(-999.),
0100       spp_(-999.),
0101       sep_(-999.),
0102       maxDR_(-999.),
0103       maxDRDPhi_(-999.),
0104       maxDRDEta_(-999.),
0105       maxDRRawEnergy_(-999.),
0106       subClusRawE1_(-999.),
0107       subClusRawE2_(-999.),
0108       subClusRawE3_(-999.),
0109       subClusDPhi1_(-999.),
0110       subClusDPhi2_(-999.),
0111       subClusDPhi3_(-999.),
0112       subClusDEta1_(-999.),
0113       subClusDEta2_(-999.),
0114       subClusDEta3_(-999.),
0115       cryEta_(-999.),
0116       cryPhi_(-999),
0117       iEta_(-999),
0118       iPhi_(-999) {}
0119 
0120 /// constructor from ref to reco::Photon
0121 Photon::Photon(const edm::Ptr<reco::Photon>& aPhotonRef)
0122     : PATObject<reco::Photon>(aPhotonRef),
0123       embeddedSuperCluster_(false),
0124       embeddedSeedCluster_(false),
0125       embeddedRecHits_(false),
0126       passElectronVeto_(false),
0127       hasPixelSeed_(false),
0128       seedEnergy_(0.0),
0129       eMax_(0.0),
0130       e2nd_(0.0),
0131       e3x3_(0.0),
0132       eTop_(0.0),
0133       eBottom_(0.0),
0134       eLeft_(0.0),
0135       eRight_(0.0),
0136       see_(-999.),
0137       spp_(-999.),
0138       sep_(-999.),
0139       maxDR_(-999.),
0140       maxDRDPhi_(-999.),
0141       maxDRDEta_(-999.),
0142       maxDRRawEnergy_(-999.),
0143       subClusRawE1_(-999.),
0144       subClusRawE2_(-999.),
0145       subClusRawE3_(-999.),
0146       subClusDPhi1_(-999.),
0147       subClusDPhi2_(-999.),
0148       subClusDPhi3_(-999.),
0149       subClusDEta1_(-999.),
0150       subClusDEta2_(-999.),
0151       subClusDEta3_(-999.),
0152       cryEta_(-999.),
0153       cryPhi_(-999),
0154       iEta_(-999),
0155       iPhi_(-999) {}
0156 
0157 /// destructor
0158 Photon::~Photon() {}
0159 
0160 std::ostream& reco::operator<<(std::ostream& out, const pat::Photon& obj) {
0161   if (!out)
0162     return out;
0163 
0164   out << "\tpat::Photon: ";
0165   out << std::setiosflags(std::ios::right);
0166   out << std::setiosflags(std::ios::fixed);
0167   out << std::setprecision(3);
0168   out << " E/pT/eta/phi " << obj.energy() << "/" << obj.pt() << "/" << obj.eta() << "/" << obj.phi();
0169   return out;
0170 }
0171 
0172 /// override the superCluster method from CaloJet, to access the internal storage of the supercluster
0173 /// this returns a transient Ref which *should never be persisted*!
0174 reco::SuperClusterRef Photon::superCluster() const {
0175   if (embeddedSuperCluster_) {
0176     if (embeddedSeedCluster_ || !basicClusters_.empty() || !preshowerClusters_.empty()) {
0177       if (!superClusterRelinked_.isSet()) {
0178         std::unique_ptr<std::vector<reco::SuperCluster> > sc(new std::vector<reco::SuperCluster>(superCluster_));
0179         if (embeddedSeedCluster_ && !(*sc)[0].seed().isAvailable()) {
0180           (*sc)[0].setSeed(seed());
0181         }
0182         if (!basicClusters_.empty() && !(*sc)[0].clusters().isAvailable()) {
0183           reco::CaloClusterPtrVector clusters;
0184           for (unsigned int iclus = 0; iclus < basicClusters_.size(); ++iclus) {
0185             clusters.push_back(reco::CaloClusterPtr(&basicClusters_, iclus));
0186           }
0187           (*sc)[0].setClusters(clusters);
0188         }
0189         if (!preshowerClusters_.empty() && !(*sc)[0].preshowerClusters().isAvailable()) {
0190           reco::CaloClusterPtrVector clusters;
0191           for (unsigned int iclus = 0; iclus < preshowerClusters_.size(); ++iclus) {
0192             clusters.push_back(reco::CaloClusterPtr(&preshowerClusters_, iclus));
0193           }
0194           (*sc)[0].setPreshowerClusters(clusters);
0195         }
0196         superClusterRelinked_.set(std::move(sc));
0197       }
0198       return reco::SuperClusterRef(&*superClusterRelinked_, 0);
0199     } else {
0200       return reco::SuperClusterRef(&superCluster_, 0);
0201     }
0202   } else {
0203     return reco::Photon::superCluster();
0204   }
0205 }
0206 
0207 /// direct access to the seed cluster
0208 reco::CaloClusterPtr Photon::seed() const {
0209   if (embeddedSeedCluster_) {
0210     return reco::CaloClusterPtr(&seedCluster_, 0);
0211   } else {
0212     return reco::Photon::superCluster()->seed();
0213   }
0214 }
0215 
0216 /// method to store the photon's supercluster internally
0217 void Photon::embedSuperCluster() {
0218   superCluster_.clear();
0219   if (reco::Photon::superCluster().isNonnull()) {
0220     superCluster_.push_back(*reco::Photon::superCluster());
0221     embeddedSuperCluster_ = true;
0222   }
0223 }
0224 
0225 /// Stores the electron's SeedCluster (reco::BasicClusterPtr) internally
0226 void Photon::embedSeedCluster() {
0227   seedCluster_.clear();
0228   if (reco::Photon::superCluster().isNonnull() && reco::Photon::superCluster()->seed().isNonnull()) {
0229     seedCluster_.push_back(*reco::Photon::superCluster()->seed());
0230     embeddedSeedCluster_ = true;
0231   }
0232 }
0233 
0234 /// Stores the electron's BasicCluster (reco::CaloCluster) internally
0235 void Photon::embedBasicClusters() {
0236   basicClusters_.clear();
0237   if (reco::Photon::superCluster().isNonnull()) {
0238     reco::CaloCluster_iterator itscl = reco::Photon::superCluster()->clustersBegin();
0239     reco::CaloCluster_iterator itsclE = reco::Photon::superCluster()->clustersEnd();
0240     for (; itscl != itsclE; ++itscl) {
0241       basicClusters_.push_back(**itscl);
0242     }
0243   }
0244 }
0245 
0246 /// Stores the electron's PreshowerCluster (reco::CaloCluster) internally
0247 void Photon::embedPreshowerClusters() {
0248   preshowerClusters_.clear();
0249   if (reco::Photon::superCluster().isNonnull()) {
0250     reco::CaloCluster_iterator itscl = reco::Photon::superCluster()->preshowerClustersBegin();
0251     reco::CaloCluster_iterator itsclE = reco::Photon::superCluster()->preshowerClustersEnd();
0252     for (; itscl != itsclE; ++itscl) {
0253       preshowerClusters_.push_back(**itscl);
0254     }
0255   }
0256 }
0257 
0258 // method to store the RecHits internally
0259 void Photon::embedRecHits(const EcalRecHitCollection* rechits) {
0260   if (rechits != nullptr) {
0261     recHits_ = *rechits;
0262     embeddedRecHits_ = true;
0263   }
0264 }
0265 
0266 // method to retrieve a photon ID (or throw)
0267 Bool_t Photon::photonID(const std::string& name) const {
0268   for (std::vector<IdPair>::const_iterator it = photonIDs_.begin(), ed = photonIDs_.end(); it != ed; ++it) {
0269     if (it->first == name)
0270       return it->second;
0271   }
0272   cms::Exception ex("Key not found");
0273   ex << "pat::Photon: the ID " << name << " can't be found in this pat::Photon.\n";
0274   ex << "The available IDs are: ";
0275   for (std::vector<IdPair>::const_iterator it = photonIDs_.begin(), ed = photonIDs_.end(); it != ed; ++it) {
0276     ex << "'" << it->first << "' ";
0277   }
0278   ex << ".\n";
0279   throw ex;
0280 }
0281 // check if an ID is there
0282 bool Photon::isPhotonIDAvailable(const std::string& name) const {
0283   for (std::vector<IdPair>::const_iterator it = photonIDs_.begin(), ed = photonIDs_.end(); it != ed; ++it) {
0284     if (it->first == name)
0285       return true;
0286   }
0287   return false;
0288 }
0289 
0290 edm::RefVector<pat::PackedCandidateCollection> Photon::associatedPackedPFCandidates() const {
0291   edm::RefVector<pat::PackedCandidateCollection> ret(packedPFCandidates_.id());
0292   for (uint16_t idx : associatedPackedFCandidateIndices_) {
0293     ret.push_back(edm::Ref<pat::PackedCandidateCollection>(packedPFCandidates_, idx));
0294   }
0295   return ret;
0296 }
0297 
0298 /// Returns the reference to the parent PF candidate with index i.
0299 /// For use in TopProjector.
0300 reco::CandidatePtr Photon::sourceCandidatePtr(size_type i) const {
0301   if (i >= associatedPackedFCandidateIndices_.size()) {
0302     return reco::CandidatePtr();
0303   } else {
0304     return reco::CandidatePtr(edm::refToPtr(
0305         edm::Ref<pat::PackedCandidateCollection>(packedPFCandidates_, associatedPackedFCandidateIndices_[i])));
0306   }
0307 }