File indexing completed on 2023-03-17 11:05:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHDecayMomentum.h"
0012
0013
0014
0015
0016 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHRecoCandidate.h"
0017 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHAddFourMomenta.h"
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019
0020
0021
0022
0023 using namespace std;
0024
0025
0026
0027
0028
0029
0030
0031
0032 BPHDecayMomentum::BPHDecayMomentum(int daugNum, int compNum) : oldMom(true) {
0033 nList.reserve(daugNum);
0034 dList.reserve(daugNum);
0035 nComp.reserve(compNum);
0036 cList.reserve(compNum);
0037 }
0038
0039 BPHDecayMomentum::BPHDecayMomentum(const map<string, BPHDecayMomentum::Component>& daugMap, int compNum)
0040 : oldMom(true) {
0041
0042 clonesList(daugMap);
0043 nComp.reserve(compNum);
0044 cList.reserve(compNum);
0045 }
0046
0047 BPHDecayMomentum::BPHDecayMomentum(const map<string, BPHDecayMomentum::Component>& daugMap,
0048 const map<string, BPHRecoConstCandPtr> compMap)
0049 :
0050 cMap(compMap),
0051 oldMom(true) {
0052
0053 clonesList(daugMap);
0054
0055 dCompList();
0056 }
0057
0058
0059
0060
0061 BPHDecayMomentum::~BPHDecayMomentum() {
0062
0063 int n = dList.size();
0064 while (n--)
0065 delete dList[n];
0066 }
0067
0068
0069
0070
0071 const pat::CompositeCandidate& BPHDecayMomentum::composite() const {
0072 if (oldMom)
0073 computeMomentum();
0074 return compCand;
0075 }
0076
0077 const vector<string>& BPHDecayMomentum::daugNames() const { return nList; }
0078
0079 const vector<string>& BPHDecayMomentum::compNames() const { return nComp; }
0080
0081 const vector<const reco::Candidate*>& BPHDecayMomentum::daughters() const { return dList; }
0082
0083 const vector<const reco::Candidate*>& BPHDecayMomentum::daughFull() const {
0084
0085 if (oldMom)
0086 computeMomentum();
0087 return dFull;
0088 }
0089
0090 const reco::Candidate* BPHDecayMomentum::originalReco(const reco::Candidate* daug) const {
0091
0092
0093 map<const reco::Candidate*, const reco::Candidate*>::const_iterator iter = clonesMap.find(daug);
0094 return (iter != clonesMap.end() ? iter->second : nullptr);
0095 }
0096
0097 const vector<BPHRecoConstCandPtr>& BPHDecayMomentum::daughComp() const {
0098
0099 return cList;
0100 }
0101
0102 const reco::Candidate* BPHDecayMomentum::getDaug(const string& name) const {
0103
0104
0105 string::size_type pos = name.find('/');
0106 if (pos != string::npos) {
0107 const BPHRecoCandidate* comp = getComp(name.substr(0, pos)).get();
0108 return (comp == nullptr ? nullptr : comp->getDaug(name.substr(pos + 1)));
0109 }
0110 map<const string, const reco::Candidate*>::const_iterator iter = dMap.find(name);
0111 return (iter != dMap.end() ? iter->second : nullptr);
0112 }
0113
0114 BPHRecoConstCandPtr BPHDecayMomentum::getComp(const string& name) const {
0115
0116
0117 string::size_type pos = name.find('/');
0118 if (pos != string::npos) {
0119 const BPHRecoCandidate* comp = getComp(name.substr(0, pos)).get();
0120 return (comp == nullptr ? nullptr : comp->getComp(name.substr(pos + 1)));
0121 }
0122 map<const string, BPHRecoConstCandPtr>::const_iterator iter = cMap.find(name);
0123 return (iter != cMap.end() ? iter->second : nullptr);
0124 }
0125
0126 const vector<BPHDecayMomentum::Component>& BPHDecayMomentum::componentList() const {
0127
0128
0129 return compList;
0130 }
0131
0132 void BPHDecayMomentum::addP(const string& name, const reco::Candidate* daug, double mass) {
0133 if (dMap.find(name) != dMap.end()) {
0134 edm::LogPrint("TooManyParticles") << "BPHDecayMomentum::add: "
0135 << "Decay product already inserted with name " << name << " , skipped";
0136 }
0137 setNotUpdated();
0138 reco::Candidate* dnew = daug->clone();
0139 if (mass > 0.0)
0140 dnew->setMass(mass);
0141 nList.push_back(name);
0142 dList.push_back(dnew);
0143 dMap[name] = dnew;
0144 clonesMap[dnew] = daug;
0145 return;
0146 }
0147
0148 void BPHDecayMomentum::addP(const string& name, const BPHRecoConstCandPtr& comp) {
0149 setNotUpdated();
0150 nComp.push_back(name);
0151 cList.push_back(comp);
0152 cMap[name] = comp;
0153 clonesMap.insert(comp->clonesMap.begin(), comp->clonesMap.end());
0154 return;
0155 }
0156
0157 void BPHDecayMomentum::setNotUpdated() const {
0158 oldMom = true;
0159 return;
0160 }
0161
0162 void BPHDecayMomentum::clonesList(const map<string, Component>& daugMap) {
0163 int n = daugMap.size();
0164 dList.resize(n);
0165 nList.resize(n);
0166
0167
0168 compList.clear();
0169 compList.reserve(n);
0170
0171 int i = 0;
0172 double mass;
0173 reco::Candidate* dnew;
0174 map<string, Component>::const_iterator iter = daugMap.begin();
0175 map<string, Component>::const_iterator iend = daugMap.end();
0176 while (iter != iend) {
0177 const map<string, Component>::value_type& entry = *iter++;
0178 const Component& comp = entry.second;
0179 const reco::Candidate* cand = comp.cand;
0180
0181
0182 compList.push_back(comp);
0183
0184 dList[i] = dnew = cand->clone();
0185 const string& name = nList[i++] = entry.first;
0186 dMap[name] = dnew;
0187 clonesMap[dnew] = cand;
0188
0189 mass = comp.mass;
0190 if (mass > 0)
0191 dnew->setMass(mass);
0192 }
0193 return;
0194 }
0195
0196 void BPHDecayMomentum::dCompList() {
0197
0198
0199 int n = cMap.size();
0200 cList.resize(n);
0201 nComp.resize(n);
0202 int i = 0;
0203 map<string, BPHRecoConstCandPtr>::const_iterator c_iter = cMap.begin();
0204 map<string, BPHRecoConstCandPtr>::const_iterator c_iend = cMap.end();
0205 while (c_iter != c_iend) {
0206 const map<string, BPHRecoConstCandPtr>::value_type& c_entry = *c_iter++;
0207 nComp[i] = c_entry.first;
0208 BPHRecoConstCandPtr comp = c_entry.second;
0209 cList[i++] = comp;
0210 clonesMap.insert(comp->clonesMap.begin(), comp->clonesMap.end());
0211 }
0212 return;
0213 }
0214
0215 void BPHDecayMomentum::sumMomentum(const vector<const reco::Candidate*>& dl, const vector<string>& dn) const {
0216
0217 int n = dl.size();
0218 while (n--)
0219 compCand.addDaughter(*dl[n], dn[n]);
0220 return;
0221 }
0222
0223 void BPHDecayMomentum::fillDaug(vector<const reco::Candidate*>& ad, const string& name, vector<string>& an) const {
0224
0225
0226 ad.insert(ad.end(), dList.begin(), dList.end());
0227 vector<string>::const_iterator iter = nList.begin();
0228 vector<string>::const_iterator iend = nList.end();
0229 while (iter != iend)
0230 an.push_back(name + *iter++);
0231 int n = cList.size();
0232 while (n--)
0233 cList[n]->fillDaug(ad, name + nComp[n] + "/", an);
0234 return;
0235 }
0236
0237 void BPHDecayMomentum::computeMomentum() const {
0238
0239 dFull.clear();
0240 dFull.reserve(10);
0241 vector<string> nFull;
0242 nFull.reserve(10);
0243 fillDaug(dFull, "", nFull);
0244
0245 compCand.clearDaughters();
0246 sumMomentum(dFull, nFull);
0247
0248 AddFourMomenta addP4;
0249 addP4.set(compCand);
0250 oldMom = false;
0251 return;
0252 }