Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 23:29:55

0001 #include "DataFormats/TauReco/interface/PFTauDecayMode.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 
0004 namespace reco {
0005   PFTauDecayMode::PFTauDecayMode(const VertexCompositeCandidate& chargedPions,
0006                                  const CompositeCandidate& piZeroes,
0007                                  const CompositeCandidate& filteredObjects) {
0008     chargedPions_ = chargedPions;
0009     piZeroes_ = piZeroes;
0010     filteredObjects_ = filteredObjects;
0011 
0012     // determine decay mode
0013     unsigned int nCharged = chargedPions_.numberOfDaughters();
0014     unsigned int nNeutral = piZeroes_.numberOfDaughters();
0015     hadronicTauDecayModes hadronicTauDecayIndex =
0016         static_cast<hadronicTauDecayModes>(((nCharged - 1) * (maxNumberOfPiZeroCandidatesAllowed + 1) + nNeutral));
0017     if (nNeutral > maxNumberOfPiZeroCandidatesAllowed)
0018       hadronicTauDecayIndex = static_cast<hadronicTauDecayModes>(tauDecayOther);
0019     this->setDecayMode(hadronicTauDecayIndex);
0020 
0021     // setup Particle base
0022     for (size_type iCand = 0; iCand < nCharged; ++iCand) {
0023       const Candidate* theCandToAdd = chargedPions_.daughter(iCand);
0024       this->addDaughter(*theCandToAdd);
0025     }
0026     for (size_type iCand = 0; iCand < nNeutral; ++iCand) {
0027       const Candidate* theCandToAdd = piZeroes_.daughter(iCand);
0028       this->addDaughter(*theCandToAdd);
0029     }
0030 
0031     this->setCharge(chargedPions_.charge());
0032     this->setP4(chargedPions_.p4() + piZeroes_.p4());
0033     this->setStatus(2);  //decayed
0034     this->setPdgId(12);  //everyone's favorite lepton!
0035   }
0036 
0037   PFTauDecayMode* PFTauDecayMode::clone() const { return new PFTauDecayMode(*this); }
0038 
0039   const VertexCompositeCandidate& PFTauDecayMode::chargedPions() const { return chargedPions_; }
0040 
0041   const CompositeCandidate& PFTauDecayMode::neutralPions() const { return piZeroes_; }
0042 
0043   const CompositeCandidate& PFTauDecayMode::filteredObjects() const { return filteredObjects_; }
0044 
0045   std::vector<const Candidate*> PFTauDecayMode::chargedPionCandidates() const {
0046     size_type numberOfChargedPions = chargedPions_.numberOfDaughters();
0047     std::vector<const Candidate*> output;
0048     for (size_type iterCand = 0; iterCand < numberOfChargedPions; ++iterCand)
0049       output.push_back(chargedPions_.daughter(iterCand));
0050     return output;
0051   }
0052 
0053   std::vector<const Candidate*> PFTauDecayMode::neutralPionCandidates() const {
0054     size_type numberOfChargedPions = piZeroes_.numberOfDaughters();
0055     std::vector<const Candidate*> output;
0056     for (size_type iterCand = 0; iterCand < numberOfChargedPions; ++iterCand)
0057       output.push_back(piZeroes_.daughter(iterCand));
0058     return output;
0059   }
0060 
0061   std::vector<const Candidate*> PFTauDecayMode::decayProductCandidates() const {
0062     std::vector<const Candidate*> output = this->chargedPionCandidates();
0063     std::vector<const Candidate*> neutralObjects = this->neutralPionCandidates();
0064 
0065     output.insert(output.end(), neutralObjects.begin(), neutralObjects.end());
0066     return output;
0067   }
0068 
0069   std::vector<const Candidate*> PFTauDecayMode::filteredObjectCandidates(int absCharge) const {
0070     size_t numberOfFilteredObjects = filteredObjects_.numberOfDaughters();
0071     std::vector<const Candidate*> output;
0072     for (size_t iFilteredCand = 0; iFilteredCand < numberOfFilteredObjects; ++iFilteredCand) {
0073       const Candidate* myCand = filteredObjects_.daughter(iFilteredCand);
0074       if (absCharge < 0 || abs(myCand->charge()) == absCharge)
0075         output.push_back(myCand);
0076     }
0077     return output;
0078   }
0079 
0080   std::vector<const Candidate*> PFTauDecayMode::chargedFilteredObjectCandidates() const {
0081     return filteredObjectCandidates(1);
0082   }
0083 
0084   std::vector<const Candidate*> PFTauDecayMode::neutralFilteredObjectCandidates() const {
0085     return filteredObjectCandidates(0);
0086   }
0087 
0088   void PFTauDecayMode::pfMasterClones(const Candidate* input, PFCandidateRefVector& toFill) const {
0089     if (input->numberOfDaughters() == 0)  //we have reached a leaf
0090     {
0091       if (input->hasMasterClone())  // has a master clone
0092       {
0093         PFCandidateRef theCandRef = input->masterClone().castTo<PFCandidateRef>();
0094         toFill.push_back(theCandRef);
0095       } else
0096         edm::LogError("PFTauDecayMode")
0097             << "Error in pfMasterClones(...) - found a leaf candidate with no Master clone reference!";
0098     } else  // recurse down composite chain
0099     {
0100       size_type numberOfDaughters = input->numberOfDaughters();
0101       for (size_type iCand = 0; iCand < numberOfDaughters; ++iCand) {
0102         const Candidate* currentCand = input->daughter(iCand);
0103         pfMasterClones(currentCand, toFill);
0104       }
0105     }
0106   }
0107 
0108   PFCandidateRefVector PFTauDecayMode::associatedChargedPFCandidates() const {
0109     PFCandidateRefVector output;
0110     const Candidate* input = static_cast<const Candidate*>(&chargedPions_);
0111     if (input->numberOfDaughters())
0112       pfMasterClones(input, output);
0113     return output;
0114   }
0115 
0116   PFCandidateRefVector PFTauDecayMode::associatedNeutralPFCandidates() const {
0117     PFCandidateRefVector output;
0118     const Candidate* input = static_cast<const Candidate*>(&piZeroes_);
0119     if (input->numberOfDaughters())
0120       pfMasterClones(input, output);
0121     return output;
0122   }
0123 
0124   PFCandidateRefVector PFTauDecayMode::filteredPFCandidates() const {
0125     PFCandidateRefVector output;
0126     const Candidate* input = static_cast<const Candidate*>(&filteredObjects_);
0127     if (input->numberOfDaughters())
0128       pfMasterClones(input, output);
0129     return output;
0130   }
0131 
0132 }  // namespace reco