CMS 3D CMS Logo

Classes | Public Types | Public Member Functions | Static Protected Member Functions | Protected Attributes | Private Attributes

PFRecoTauDecayModeDeterminator Class Reference

Inheritance diagram for PFRecoTauDecayModeDeterminator:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Classes

struct  gammaMatchContainer

Public Types

typedef std::list
< CompositeCandidate
compCandList
typedef std::list
< CompositeCandidate >
::reverse_iterator 
compCandRevIter

Public Member Functions

void mergePiZeroes (compCandList &, compCandRevIter)
void mergePiZeroesByBestMatch (compCandList &)
 PFRecoTauDecayModeDeterminator (const edm::ParameterSet &iConfig)
virtual void produce (edm::Event &, const edm::EventSetup &)
 ~PFRecoTauDecayModeDeterminator ()

Static Protected Member Functions

static bool gammaMatchSorter (const gammaMatchContainer &first, const gammaMatchContainer &second)

Protected Attributes

const double chargedPionMass
const double neutralPionMass

Private Attributes

AddFourMomenta addP4
TauTagTools::sortByAscendingPt
< CompositeCandidate
candAscendingSorter
TauTagTools::sortByDescendingPt
< CompositeCandidate
candDescendingSorter
bool filterPhotons_
bool filterTwoProngs_
uint32_t maxPhotonsToMerge_
double maxPiZeroMass_
bool mergeByBestMatch_
bool mergeLowPtPhotonsFirst_
double minPtFractionForSecondProng_
double minPtFractionPiZeroes_
double minPtFractionSinglePhotons_
edm::InputTag PFTauProducer_
bool refitTracks_
bool setChargedPionMass_
bool setMergedPi0Mass_
bool setPi0Mass_
PFCandCommonVertexFitterBasevertexFitter_

Detailed Description

Definition at line 44 of file PFRecoTauDecayModeDeterminator.cc.


Member Typedef Documentation

Definition at line 47 of file PFRecoTauDecayModeDeterminator.cc.

Definition at line 48 of file PFRecoTauDecayModeDeterminator.cc.


Constructor & Destructor Documentation

PFRecoTauDecayModeDeterminator::PFRecoTauDecayModeDeterminator ( const edm::ParameterSet iConfig) [explicit]

Definition at line 90 of file PFRecoTauDecayModeDeterminator.cc.

References filterPhotons_, filterTwoProngs_, edm::ParameterSet::getParameter(), maxPhotonsToMerge_, maxPiZeroMass_, mergeByBestMatch_, mergeLowPtPhotonsFirst_, minPtFractionForSecondProng_, minPtFractionPiZeroes_, minPtFractionSinglePhotons_, PFTauProducer_, refitTracks_, setChargedPionMass_, setMergedPi0Mass_, setPi0Mass_, and vertexFitter_.

                                                                                            :chargedPionMass(0.13957),neutralPionMass(0.13497){
  PFTauProducer_                = iConfig.getParameter<edm::InputTag>("PFTauProducer");
  maxPhotonsToMerge_            = iConfig.getParameter<uint32_t>("maxPhotonsToMerge");
  maxPiZeroMass_                = iConfig.getParameter<double>("maxPiZeroMass");             
  mergeLowPtPhotonsFirst_       = iConfig.getParameter<bool>("mergeLowPtPhotonsFirst");
  mergeByBestMatch_             = iConfig.getParameter<bool>("mergeByBestMatch");
  setChargedPionMass_           = iConfig.getParameter<bool>("setChargedPionMass");
  setPi0Mass_                   = iConfig.getParameter<bool>("setPi0Mass");
  setMergedPi0Mass_             = iConfig.getParameter<bool>("setMergedPi0Mass");
  refitTracks_                  = iConfig.getParameter<bool>("refitTracks");
  filterTwoProngs_              = iConfig.getParameter<bool>("filterTwoProngs");
  filterPhotons_                = iConfig.getParameter<bool>("filterPhotons");
  minPtFractionForSecondProng_  = iConfig.getParameter<double>("minPtFractionForSecondProng");
  minPtFractionSinglePhotons_   = iConfig.getParameter<double>("minPtFractionSinglePhotons");
  minPtFractionPiZeroes_        = iConfig.getParameter<double>("minPtFractionPiZeroes");
  //setup vertex fitter
  vertexFitter_ = new PFCandCommonVertexFitter<KalmanVertexFitter>(iConfig);
  produces<PFTauDecayModeAssociation>();      
}
PFRecoTauDecayModeDeterminator::~PFRecoTauDecayModeDeterminator ( )

Definition at line 110 of file PFRecoTauDecayModeDeterminator.cc.

{
//   delete vertexFitter_;  //now a very small memory leak, fix me later
}

Member Function Documentation

bool PFRecoTauDecayModeDeterminator::gammaMatchSorter ( const gammaMatchContainer first,
const gammaMatchContainer second 
) [static, protected]

Definition at line 172 of file PFRecoTauDecayModeDeterminator.cc.

References PFRecoTauDecayModeDeterminator::gammaMatchContainer::matchQuality.

Referenced by mergePiZeroesByBestMatch().

{
   return (first.matchQuality < second.matchQuality);
}
void PFRecoTauDecayModeDeterminator::mergePiZeroes ( compCandList input,
compCandRevIter  seed 
)

Definition at line 121 of file PFRecoTauDecayModeDeterminator.cc.

References abs, addP4, newFWLiteAna::base, reco::Candidate::daughter(), maxPhotonsToMerge_, maxPiZeroMass_, neutralPionMass, and AddFourMomenta::set().

Referenced by produce().

{
   //uses std::list instead of vector, so that iterators can be deleted in situ
   //we go backwards for historical reasons ;)
   if(seed == input.rend())
      return;
   compCandRevIter bestMatchSoFar;
   LorentzVector combinationCandidate;
   float closestInvariantMassDifference = maxPiZeroMass_ + 1;
   bool foundACompatibleMatch = false;
   //find the best match to make a pi0
   compCandRevIter potentialMatch = seed;
   ++potentialMatch;
   for(; potentialMatch != input.rend(); ++potentialMatch)
   {
      // see how close this combination comes to the pion mass
      LorentzVector seedFourVector              = seed->p4();
      LorentzVector toAddFourVect               = potentialMatch->p4();
      combinationCandidate                      = seedFourVector + toAddFourVect;
      float combinationCandidateMass            = combinationCandidate.M();
      float differenceToTruePiZeroMass          = std::abs(combinationCandidateMass - neutralPionMass);
      if(combinationCandidateMass < maxPiZeroMass_ && differenceToTruePiZeroMass < closestInvariantMassDifference)
      {
         closestInvariantMassDifference = differenceToTruePiZeroMass;
         bestMatchSoFar = potentialMatch;
         foundACompatibleMatch = true;
      }
   }
   //if we found a combination that might make a pi0, combine it into the seed gamma, erase it, then see if we can add anymore
   if(foundACompatibleMatch && seed->numberOfDaughters() < maxPhotonsToMerge_)
   {
      //combine match into Seed and update four vector
      if(bestMatchSoFar->numberOfDaughters() > 0)
      {
         const Candidate* photonToAdd = (*bestMatchSoFar).daughter(0);
         seed->addDaughter(*photonToAdd);
      }
      addP4.set(*seed);
      //remove match as it is now contained in the seed 
      input.erase( (++bestMatchSoFar).base() );  //convert to normal iterator, after correct for offset
      mergePiZeroes(input, seed);
   } else
   {
      // otherwise move to next highest object and recurse
      addP4.set(*seed);
      ++seed;
      mergePiZeroes(input, seed);
   }
}
void PFRecoTauDecayModeDeterminator::mergePiZeroesByBestMatch ( compCandList input)

Definition at line 178 of file PFRecoTauDecayModeDeterminator.cc.

References abs, addP4, PFRecoTauDecayModeDeterminator::gammaMatchContainer::firstIndex, gammaMatchSorter(), PFRecoTauDecayModeDeterminator::gammaMatchContainer::matchQuality, maxPiZeroMass_, neutralPionMass, PFRecoTauDecayModeDeterminator::gammaMatchContainer::secondIndex, AddFourMomenta::set(), and python::multivaluedict::sort().

Referenced by produce().

{
   if(!input.size()) //nothing to merge... (NOTE: this line is necessary, as for size_t x, x in [0, +inf), x < -1 = true)
      return;

   std::vector<compCandList::iterator> gammas;       // iterators to all the gammas.  needed as we are using a list for compatability
                                                // with the original merging algorithm, and this implementation requires random access
   std::vector<gammaMatchContainer> matches;

   // populate the list of gammas
   for(compCandList::iterator iGamma = input.begin(); iGamma != input.end(); ++iGamma)
      gammas.push_back(iGamma);


   for(size_t gammaA = 0; gammaA < gammas.size()-1; ++gammaA)
   {
      for(size_t gammaB = gammaA+1; gammaB < gammas.size(); ++gammaB)
      {
         //construct invariant mass of this pair
         LorentzVector piZeroAB = gammas[gammaA]->p4() + gammas[gammaB]->p4();
         //different to true pizero mass
         double piZeroABMass               = piZeroAB.M();
         double differenceToTruePiZeroMass = std::abs(piZeroABMass - neutralPionMass);

         if(piZeroABMass < maxPiZeroMass_)
         {
            gammaMatchContainer   aMatch;
            aMatch.matchQuality = differenceToTruePiZeroMass;
            aMatch.firstIndex   = gammaA;
            aMatch.secondIndex  = gammaB;
            matches.push_back(aMatch);
         }
      }
   }

   sort(matches.begin(), matches.end(), gammaMatchSorter);
   //the pairs whose mass is closest to the true pi0 mass are now at the beginning
   //of this vector

   for(std::vector<gammaMatchContainer>::iterator iMatch  = matches.begin(); 
                                             iMatch != matches.end();
                                           ++iMatch)
   {
      size_t gammaA = iMatch->firstIndex;
      size_t gammaB = iMatch->secondIndex;
      //check to see that both gammas in this match have not been used (ie their iterators set to input.end())
      if( gammas[gammaA] != input.end() && gammas[gammaB] != input.end() )
      {
         //merge the second gamma into the first; loop occurs in case of multiple gamma merging option
         for(size_t bDaughter = 0; bDaughter < gammas[gammaB]->numberOfDaughters(); ++bDaughter)
            gammas[gammaA]->addDaughter( *(gammas[gammaB]->daughter(bDaughter)) );
         //update the four vector information
         addP4.set(*gammas[gammaA]);
         //delete gammaB from the list of photons/pi zeroes, as it has been merged into gammaA
         input.erase(gammas[gammaB]);
         //mark both as "merged"
         gammas[gammaA] = input.end();
         gammas[gammaB] = input.end();
      } // else this match contains a photon that has already been merged
   }

}
void PFRecoTauDecayModeDeterminator::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 241 of file PFRecoTauDecayModeDeterminator.cc.

References reco::CompositeCandidate::addDaughter(), addP4, edm::RefVector< C, T, F >::begin(), candAscendingSorter, candDescendingSorter, chargedPionMass, reco::CompositeCandidate::daughter(), edm::RefVector< C, T, F >::end(), filterPhotons_, filterTwoProngs_, edm::EventSetup::get(), edm::Event::getByLabel(), mergeByBestMatch_, mergeLowPtPhotonsFirst_, mergePiZeroes(), mergePiZeroesByBestMatch(), minPtFractionForSecondProng_, minPtFractionPiZeroes_, minPtFractionSinglePhotons_, neutralPionMass, reco::CompositeCandidate::numberOfDaughters(), reco::LeafCandidate::p4(), reco::Candidate::p4(), PFTauProducer_, edm::ESHandle< T >::product(), edm::Event::put(), refitTracks_, query::result, AddFourMomenta::set(), PFCandCommonVertexFitterBase::set(), setChargedPionMass_, reco::LeafCandidate::setMass(), reco::Candidate::setMass(), setMergedPi0Mass_, reco::PFTauDecayMode::setPFTauRef(), setPi0Mass_, reco::PFTau::signalPFChargedHadrCands(), reco::PFTau::signalPFGammaCands(), edm::RefVector< C, T, F >::size(), and vertexFitter_.

                                                                                        {

  edm::ESHandle<TransientTrackBuilder> myTransientTrackBuilder;
  edm::ESHandle<MagneticField> myMF;

  if (refitTracks_)
  {
     iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",myTransientTrackBuilder);
     iSetup.get<IdealMagneticFieldRecord>().get(myMF);
  }

  edm::Handle<PFTauCollection> thePFTauCollection;
  iEvent.getByLabel(PFTauProducer_,thePFTauCollection);

  auto_ptr<PFTauDecayModeAssociation> result(new PFTauDecayModeAssociation(PFTauRefProd(thePFTauCollection)));

  size_t numberOfPFTaus = thePFTauCollection->size();
  for(size_t iPFTau = 0; iPFTau < numberOfPFTaus; ++iPFTau)
  {
     //get the reference to the PFTau
     PFTauRef           pfTauRef(thePFTauCollection, iPFTau);
     PFTau              myPFTau = *pfTauRef;
     
     //get the charged & neutral collections corresponding to this PFTau
     const PFCandidateRefVector& theChargedHadronCandidates = myPFTau.signalPFChargedHadrCands();
     const PFCandidateRefVector& theGammaCandidates         = myPFTau.signalPFGammaCands();

     LorentzVector totalFourVector;                       //contains non-filtered stuff only.

     //shallow clone everything
     std::vector<ShallowCloneCandidate>    chargedCandidates;
     std::list<CompositeCandidate>         gammaCandidates;
     VertexCompositeCandidate         chargedCandsToAdd;  
     CompositeCandidate               filteredStuff;      //empty for now.

     bool needToProcessTracks = true;
     if (filterTwoProngs_ && theChargedHadronCandidates.size() == 2)
     {
        size_t indexOfHighestPt = (theChargedHadronCandidates[0]->pt() > theChargedHadronCandidates[1]->pt()) ? 0 : 1;
        size_t indexOfLowerPt   = ( indexOfHighestPt ) ? 0 : 1; 
        //maybe include a like signed requirement?? (future)
        double highPt = theChargedHadronCandidates[indexOfHighestPt]->pt();
        double lowPt  = theChargedHadronCandidates[indexOfLowerPt]->pt();
        if (lowPt/highPt < minPtFractionForSecondProng_)  //if it is super low, filter it!
        {
           needToProcessTracks = false;  //we are doing it here instead
           chargedCandsToAdd.addDaughter(ShallowCloneCandidate(CandidateBaseRef(theChargedHadronCandidates[indexOfHighestPt])));
           Candidate* justAdded = chargedCandsToAdd.daughter(chargedCandsToAdd.numberOfDaughters()-1);
           totalFourVector += justAdded->p4();
           if(setChargedPionMass_)
              justAdded->setMass(chargedPionMass);
           //add the two prong to the list of filtered stuff (to be added to the isolation collection later)
           filteredStuff.addDaughter(ShallowCloneCandidate(CandidateBaseRef(theChargedHadronCandidates[indexOfLowerPt])));
        }
     }

     if(needToProcessTracks) //not a two prong, filter is turned off, or 2nd prong passes cuts
     {
        for( PFCandidateRefVector::const_iterator iCharged  = theChargedHadronCandidates.begin();
              iCharged != theChargedHadronCandidates.end();
              ++iCharged)
        {
           // copy as shallow clone, and asssume mass of pi+
           chargedCandsToAdd.addDaughter(ShallowCloneCandidate(CandidateBaseRef(*iCharged)));
           Candidate* justAdded = chargedCandsToAdd.daughter(chargedCandsToAdd.numberOfDaughters()-1);
           totalFourVector += justAdded->p4();
           if(setChargedPionMass_)
              justAdded->setMass(chargedPionMass);
        }
     }

     for( PFCandidateRefVector::const_iterator iGamma  = theGammaCandidates.begin();
                                               iGamma != theGammaCandidates.end();
                                             ++iGamma)
     {
        CompositeCandidate potentialPiZero;
        potentialPiZero.addDaughter(ShallowCloneCandidate(CandidateBaseRef(*iGamma)));
        addP4.set(potentialPiZero);
        totalFourVector += potentialPiZero.p4();
        gammaCandidates.push_back(potentialPiZero);
     }

     //sort the photons by pt before passing to merger
     if (mergeLowPtPhotonsFirst_)
        gammaCandidates.sort(candDescendingSorter);
     else
        gammaCandidates.sort(candAscendingSorter);

     if (mergeByBestMatch_)
        mergePiZeroesByBestMatch(gammaCandidates);
     else
        mergePiZeroes(gammaCandidates, gammaCandidates.rbegin());

     if (filterPhotons_)
     {
        //sort by pt, from high to low.
        gammaCandidates.sort(candAscendingSorter);

        compCandRevIter wimp = gammaCandidates.rbegin();

        bool doneFiltering = false;
        while(!doneFiltering && wimp != gammaCandidates.rend())
        {
           double ptFraction          = wimp->pt()/totalFourVector.pt();
           size_t numberOfPhotons     = wimp->numberOfDaughters();

           //check if it is a single photon or has been merged
           if ( (numberOfPhotons == 1 && ptFraction < minPtFractionSinglePhotons_) ||
                (numberOfPhotons  > 1 && ptFraction < minPtFractionPiZeroes_     )    )
           {
              //remove
              totalFourVector -= wimp->p4();
              for(size_t iDaughter = 0; iDaughter < numberOfPhotons; ++iDaughter)
              {
                 filteredStuff.addDaughter(ShallowCloneCandidate(CandidateBaseRef( wimp->daughter(iDaughter)->masterClone() )));
              }

              //move to the next photon to filter
              ++wimp;
           } else
           {
              //if this pizero passes the filter, we are done looking
              doneFiltering = true;
           }
        }
        //delete the filtered objects
        gammaCandidates.erase(wimp.base(), gammaCandidates.end());
     }


     CompositeCandidate mergedPiZerosToAdd;
     for( std::list<CompositeCandidate>::iterator iGamma  = gammaCandidates.begin();
                                             iGamma != gammaCandidates.end();
                                           ++iGamma)
     {
        if (setPi0Mass_) // set mass as pi 0
        {
           if (iGamma->numberOfDaughters() == 1) // for merged gamma pairs, check if user wants to keep ECAL mass
              iGamma->setMass(neutralPionMass);
           else if (setMergedPi0Mass_)
              iGamma->setMass(neutralPionMass);
        }
        mergedPiZerosToAdd.addDaughter(*iGamma);
     }

     // apply vertex fitting.
     if (refitTracks_ && chargedCandsToAdd.numberOfDaughters() > 1)
     {
        vertexFitter_->set(myMF.product());
        vertexFitter_->set(chargedCandsToAdd);  //refits tracks, adds vertexing info
     }

     // correctly set the four vectors of the composite candidates
     addP4.set(chargedCandsToAdd);
     addP4.set(mergedPiZerosToAdd);
     addP4.set(filteredStuff);

     /*
     LorentzVector refitFourVector = chargedCandsToAdd.p4() + mergedPiZerosToAdd.p4();

     edm::LogInfo("PFTauDecayModeDeterminator") << "Found nCharged: " << chargedCandsToAdd.numberOfDaughters()
                                  << " and nNeutral: " << mergedPiZerosToAdd.numberOfDaughters()
                                  << " Former mass: " << totalFourVector.mass() 
                                  << " New mass: " << refitFourVector.mass();
     */

     PFTauDecayMode myDecayModeTau(chargedCandsToAdd, mergedPiZerosToAdd, filteredStuff);
     myDecayModeTau.setPFTauRef(pfTauRef);
     result->setValue(iPFTau, myDecayModeTau);
  }
  iEvent.put(result);
}

Member Data Documentation

Definition at line 87 of file PFRecoTauDecayModeDeterminator.cc.

Referenced by produce().

Definition at line 86 of file PFRecoTauDecayModeDeterminator.cc.

Referenced by produce().

Definition at line 58 of file PFRecoTauDecayModeDeterminator.cc.

Referenced by produce().

Definition at line 82 of file PFRecoTauDecayModeDeterminator.cc.

Referenced by PFRecoTauDecayModeDeterminator(), and produce().

Definition at line 81 of file PFRecoTauDecayModeDeterminator.cc.

Referenced by PFRecoTauDecayModeDeterminator(), and produce().

Definition at line 76 of file PFRecoTauDecayModeDeterminator.cc.

Referenced by PFRecoTauDecayModeDeterminator(), and produce().

Definition at line 75 of file PFRecoTauDecayModeDeterminator.cc.

Referenced by PFRecoTauDecayModeDeterminator(), and produce().

Definition at line 83 of file PFRecoTauDecayModeDeterminator.cc.

Referenced by PFRecoTauDecayModeDeterminator(), and produce().

Definition at line 85 of file PFRecoTauDecayModeDeterminator.cc.

Referenced by PFRecoTauDecayModeDeterminator(), and produce().

Definition at line 84 of file PFRecoTauDecayModeDeterminator.cc.

Referenced by PFRecoTauDecayModeDeterminator(), and produce().

Definition at line 71 of file PFRecoTauDecayModeDeterminator.cc.

Referenced by PFRecoTauDecayModeDeterminator(), and produce().

Definition at line 80 of file PFRecoTauDecayModeDeterminator.cc.

Referenced by PFRecoTauDecayModeDeterminator(), and produce().

Definition at line 77 of file PFRecoTauDecayModeDeterminator.cc.

Referenced by PFRecoTauDecayModeDeterminator(), and produce().

Definition at line 79 of file PFRecoTauDecayModeDeterminator.cc.

Referenced by PFRecoTauDecayModeDeterminator(), and produce().

Definition at line 78 of file PFRecoTauDecayModeDeterminator.cc.

Referenced by PFRecoTauDecayModeDeterminator(), and produce().

Definition at line 70 of file PFRecoTauDecayModeDeterminator.cc.

Referenced by PFRecoTauDecayModeDeterminator(), and produce().