Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:24

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  \author Paolo Ronchese INFN Padova
0005  *
0006  */
0007 
0008 //-----------------------
0009 // This Class' Header --
0010 //-----------------------
0011 #include "HeavyFlavorAnalysis/SpecificDecay/interface/BPHOniaToMuMuBuilder.h"
0012 
0013 //-------------------------------
0014 // Collaborating Class Headers --
0015 //-------------------------------
0016 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHRecoBuilder.h"
0017 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHRecoSelect.h"
0018 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHPlusMinusCandidate.h"
0019 #include "HeavyFlavorAnalysis/SpecificDecay/interface/BPHMuonPtSelect.h"
0020 #include "HeavyFlavorAnalysis/SpecificDecay/interface/BPHMuonEtaSelect.h"
0021 #include "HeavyFlavorAnalysis/SpecificDecay/interface/BPHMassSelect.h"
0022 #include "HeavyFlavorAnalysis/SpecificDecay/interface/BPHChi2Select.h"
0023 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHMultiSelect.h"
0024 #include "HeavyFlavorAnalysis/SpecificDecay/interface/BPHParticleMasses.h"
0025 
0026 //---------------
0027 // C++ Headers --
0028 //---------------
0029 using namespace std;
0030 
0031 //-------------------
0032 // Initializations --
0033 //-------------------
0034 
0035 //----------------
0036 // Constructors --
0037 //----------------
0038 BPHOniaToMuMuBuilder::BPHOniaToMuMuBuilder(const edm::EventSetup& es,
0039                                            const BPHRecoBuilder::BPHGenericCollection* muPosCollection,
0040                                            const BPHRecoBuilder::BPHGenericCollection* muNegCollection)
0041     : muPosName("MuPos"),
0042       muNegName("MuNeg"),
0043       evSetup(&es),
0044       posCollection(muPosCollection),
0045       negCollection(muNegCollection) {
0046   setParameters(Phi, 2.0, 10.0, 0.50, 1.50, 0.0, BPHParticleMasses::phiMass, BPHParticleMasses::phiMWidth);
0047   setParameters(Psi1, 2.0, 10.0, 2.00, 3.40, 0.0, BPHParticleMasses::jPsiMass, BPHParticleMasses::jPsiMWidth);
0048   setParameters(Psi2, 2.0, 10.0, 3.40, 6.00, 0.0, BPHParticleMasses::psi2Mass, BPHParticleMasses::psi2MWidth);
0049   setParameters(Ups, 2.0, 10.0, 6.00, 12.00, 0.0, -1.0, 0.0);
0050   setParameters(Ups1, 2.0, 10.0, 6.00, 9.75, 0.0, BPHParticleMasses::ups1Mass, BPHParticleMasses::ups1MWidth);
0051   setParameters(Ups2, 2.0, 10.0, 9.75, 10.20, 0.0, BPHParticleMasses::ups2Mass, BPHParticleMasses::ups2MWidth);
0052   setParameters(Ups3, 2.0, 10.0, 10.20, 12.00, 0.0, BPHParticleMasses::ups3Mass, BPHParticleMasses::ups3MWidth);
0053   updated = false;
0054 }
0055 
0056 //--------------
0057 // Destructor --
0058 //--------------
0059 BPHOniaToMuMuBuilder::~BPHOniaToMuMuBuilder() {
0060   map<oniaType, OniaParameters>::iterator iter = oniaPar.begin();
0061   map<oniaType, OniaParameters>::iterator iend = oniaPar.end();
0062   while (iter != iend) {
0063     OniaParameters& par = iter++->second;
0064     delete par.ptSel;
0065     delete par.etaSel;
0066     delete par.massSel;
0067     delete par.chi2Sel;
0068   }
0069 }
0070 
0071 //--------------
0072 // Operations --
0073 //--------------
0074 vector<BPHPlusMinusConstCandPtr> BPHOniaToMuMuBuilder::build() {
0075   if (updated)
0076     return fullList;
0077 
0078   fullList.clear();
0079 
0080   BPHMultiSelect<BPHSlimSelect<BPHRecoSelect>> ptSel(BPHSelectOperation::or_mode);
0081   BPHMultiSelect<BPHSlimSelect<BPHRecoSelect>> etaSel(BPHSelectOperation::or_mode);
0082   BPHMultiSelect<BPHSlimSelect<BPHMomentumSelect>> mSel(BPHSelectOperation::or_mode);
0083   BPHMultiSelect<BPHSlimSelect<BPHVertexSelect>> vSel(BPHSelectOperation::or_mode);
0084 
0085   map<oniaType, OniaParameters>::iterator iter = oniaPar.begin();
0086   map<oniaType, OniaParameters>::iterator iend = oniaPar.end();
0087   while (iter != iend) {
0088     OniaParameters& par = iter++->second;
0089     ptSel.include(*par.ptSel);
0090     etaSel.include(*par.etaSel);
0091     mSel.include(*par.massSel);
0092     vSel.include(*par.chi2Sel);
0093   }
0094 
0095   BPHRecoBuilder bOnia(*evSetup);
0096   bOnia.add(muPosName, posCollection, BPHParticleMasses::muonMass, BPHParticleMasses::muonMSigma);
0097   bOnia.add(muNegName, negCollection, BPHParticleMasses::muonMass, BPHParticleMasses::muonMSigma);
0098   bOnia.filter(muPosName, ptSel);
0099   bOnia.filter(muNegName, ptSel);
0100   bOnia.filter(muPosName, etaSel);
0101   bOnia.filter(muNegName, etaSel);
0102   bOnia.filter(mSel);
0103   bOnia.filter(vSel);
0104 
0105   fullList = BPHPlusMinusCandidate::build(bOnia, muPosName, muNegName);
0106   updated = true;
0107   return fullList;
0108 }
0109 
0110 vector<BPHPlusMinusConstCandPtr> BPHOniaToMuMuBuilder::getList(
0111     oniaType type, BPHRecoSelect* dSel, BPHMomentumSelect* mSel, BPHVertexSelect* vSel, BPHFitSelect* kSel) {
0112   extractList(type);
0113   vector<BPHPlusMinusConstCandPtr>& list = oniaList[type];
0114   int i;
0115   int n = list.size();
0116   vector<BPHPlusMinusConstCandPtr> lsub;
0117   lsub.reserve(n);
0118   for (i = 0; i < n; ++i) {
0119     BPHPlusMinusConstCandPtr ptr = list[i];
0120     const reco::Candidate* muPos = ptr->originalReco(ptr->getDaug(muPosName));
0121     const reco::Candidate* muNeg = ptr->originalReco(ptr->getDaug(muNegName));
0122     if ((dSel != nullptr) && (!dSel->accept(*muPos)))
0123       continue;
0124     if ((dSel != nullptr) && (!dSel->accept(*muNeg)))
0125       continue;
0126     if ((mSel != nullptr) && (!mSel->accept(*ptr)))
0127       continue;
0128     if ((vSel != nullptr) && (!vSel->accept(*ptr)))
0129       continue;
0130     if ((kSel != nullptr) && (!kSel->accept(*ptr)))
0131       continue;
0132     lsub.push_back(list[i]);
0133   }
0134   return lsub;
0135 }
0136 
0137 BPHPlusMinusConstCandPtr BPHOniaToMuMuBuilder::getOriginalCandidate(const BPHRecoCandidate& cand) {
0138   const reco::Candidate* mp = cand.originalReco(cand.getDaug(muPosName));
0139   const reco::Candidate* mn = cand.originalReco(cand.getDaug(muNegName));
0140   int nc = fullList.size();
0141   int ic;
0142   for (ic = 0; ic < nc; ++ic) {
0143     BPHPlusMinusConstCandPtr pmp = fullList[ic];
0144     const BPHPlusMinusCandidate* pmc = pmp.get();
0145     if (pmc->originalReco(pmc->getDaug(muPosName)) != mp)
0146       continue;
0147     if (pmc->originalReco(pmc->getDaug(muNegName)) != mn)
0148       continue;
0149     return pmp;
0150   }
0151   return BPHPlusMinusConstCandPtr(nullptr);
0152 }
0153 
0154 /// set cuts
0155 void BPHOniaToMuMuBuilder::setPtMin(oniaType type, double pt) {
0156   setNotUpdated();
0157   OniaParameters& par = oniaPar[type];
0158   par.ptSel->setPtMin(pt);
0159   return;
0160 }
0161 
0162 void BPHOniaToMuMuBuilder::setEtaMax(oniaType type, double eta) {
0163   setNotUpdated();
0164   OniaParameters& par = oniaPar[type];
0165   par.etaSel->setEtaMax(eta);
0166   return;
0167 }
0168 
0169 void BPHOniaToMuMuBuilder::setMassMin(oniaType type, double m) {
0170   setNotUpdated();
0171   OniaParameters& par = oniaPar[type];
0172   par.massSel->setMassMin(m);
0173   return;
0174 }
0175 
0176 void BPHOniaToMuMuBuilder::setMassMax(oniaType type, double m) {
0177   setNotUpdated();
0178   OniaParameters& par = oniaPar[type];
0179   par.massSel->setMassMax(m);
0180   return;
0181 }
0182 
0183 void BPHOniaToMuMuBuilder::setProbMin(oniaType type, double p) {
0184   setNotUpdated();
0185   OniaParameters& par = oniaPar[type];
0186   par.chi2Sel->setProbMin(p);
0187   return;
0188 }
0189 
0190 void BPHOniaToMuMuBuilder::setConstr(oniaType type, double mass, double sigma) {
0191   setNotUpdated();
0192   OniaParameters& par = oniaPar[type];
0193   par.mass = mass;
0194   par.sigma = sigma;
0195   return;
0196 }
0197 
0198 /// get current cuts
0199 double BPHOniaToMuMuBuilder::getPtMin(oniaType type) const {
0200   const OniaParameters& par = oniaPar.at(type);
0201   return par.ptSel->getPtMin();
0202 }
0203 
0204 double BPHOniaToMuMuBuilder::getEtaMax(oniaType type) const {
0205   const OniaParameters& par = oniaPar.at(type);
0206   return par.etaSel->getEtaMax();
0207 }
0208 
0209 double BPHOniaToMuMuBuilder::getMassMin(oniaType type) const {
0210   const OniaParameters& par = oniaPar.at(type);
0211   return par.massSel->getMassMin();
0212 }
0213 
0214 double BPHOniaToMuMuBuilder::getMassMax(oniaType type) const {
0215   const OniaParameters& par = oniaPar.at(type);
0216   return par.massSel->getMassMax();
0217 }
0218 
0219 double BPHOniaToMuMuBuilder::getProbMin(oniaType type) const {
0220   const OniaParameters& par = oniaPar.at(type);
0221   return par.chi2Sel->getProbMin();
0222 }
0223 
0224 double BPHOniaToMuMuBuilder::getConstrMass(oniaType type) const {
0225   const OniaParameters& par = oniaPar.at(type);
0226   return par.mass;
0227 }
0228 
0229 double BPHOniaToMuMuBuilder::getConstrSigma(oniaType type) const {
0230   const OniaParameters& par = oniaPar.at(type);
0231   return par.sigma;
0232 }
0233 
0234 void BPHOniaToMuMuBuilder::setNotUpdated() {
0235   map<oniaType, OniaParameters>::iterator iter = oniaPar.begin();
0236   map<oniaType, OniaParameters>::iterator iend = oniaPar.end();
0237   while (iter != iend)
0238     iter++->second.updated = false;
0239   updated = false;
0240   return;
0241 }
0242 
0243 void BPHOniaToMuMuBuilder::setParameters(oniaType type,
0244                                          double ptMin,
0245                                          double etaMax,
0246                                          double massMin,
0247                                          double massMax,
0248                                          double probMin,
0249                                          double mass,
0250                                          double sigma) {
0251   OniaParameters& par = oniaPar[type];
0252   par.ptSel = new BPHMuonPtSelect(ptMin);
0253   par.etaSel = new BPHMuonEtaSelect(etaMax);
0254   par.massSel = new BPHMassSelect(massMin, massMax);
0255   par.chi2Sel = new BPHChi2Select(probMin);
0256   par.mass = mass;
0257   par.sigma = sigma;
0258   par.updated = false;
0259   return;
0260 }
0261 
0262 void BPHOniaToMuMuBuilder::extractList(oniaType type) {
0263   if (!updated)
0264     build();
0265   OniaParameters& par = oniaPar[type];
0266   vector<BPHPlusMinusConstCandPtr>& list = oniaList[type];
0267   if (par.updated)
0268     return;
0269   int i;
0270   int n = fullList.size();
0271   list.clear();
0272   list.reserve(n);
0273   for (i = 0; i < n; ++i) {
0274     BPHPlusMinusConstCandPtr ptr = fullList[i];
0275     const reco::Candidate* mcPos = ptr->getDaug("MuPos");
0276     const reco::Candidate* mcNeg = ptr->getDaug("MuNeg");
0277     const reco::Candidate* muPos = ptr->originalReco(mcPos);
0278     const reco::Candidate* muNeg = ptr->originalReco(mcNeg);
0279     if (!par.massSel->accept(*ptr))
0280       continue;
0281     if (!par.ptSel->accept(*muPos))
0282       continue;
0283     if (!par.etaSel->accept(*muPos))
0284       continue;
0285     if (!par.ptSel->accept(*muNeg))
0286       continue;
0287     if (!par.etaSel->accept(*muNeg))
0288       continue;
0289     if (!par.chi2Sel->accept(*ptr))
0290       continue;
0291     BPHPlusMinusCandidate* np = new BPHPlusMinusCandidate(evSetup);
0292     np->add("MuPos", muPos, ptr->getTrackSearchList(mcPos), BPHParticleMasses::muonMass, BPHParticleMasses::muonMSigma);
0293     np->add("MuNeg", muNeg, ptr->getTrackSearchList(mcNeg), BPHParticleMasses::muonMass, BPHParticleMasses::muonMSigma);
0294     if (par.mass > 0.0)
0295       np->setConstraint(par.mass, par.sigma);
0296     list.push_back(BPHPlusMinusConstCandPtr(np));
0297   }
0298   par.updated = true;
0299   return;
0300 }