CMS 3D CMS Logo

BPHDecayMomentum.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author Paolo Ronchese INFN Padova
5  *
6  */
7 
8 //-----------------------
9 // This Class' Header --
10 //-----------------------
12 
13 //-------------------------------
14 // Collaborating Class Headers --
15 //-------------------------------
19 
20 //---------------
21 // C++ Headers --
22 //---------------
23 using namespace std;
24 
25 //-------------------
26 // Initializations --
27 //-------------------
28 
29 //----------------
30 // Constructors --
31 //----------------
32 BPHDecayMomentum::BPHDecayMomentum(int daugNum, int compNum) : oldMom(true) {
33  nList.reserve(daugNum);
34  dList.reserve(daugNum);
35  nComp.reserve(compNum);
36  cList.reserve(compNum);
37 }
38 
39 BPHDecayMomentum::BPHDecayMomentum(const map<string, BPHDecayMomentum::Component>& daugMap, int compNum)
40  : oldMom(true) {
41  // clone and store simple particles
43  nComp.reserve(compNum);
44  cList.reserve(compNum);
45 }
46 
47 BPHDecayMomentum::BPHDecayMomentum(const map<string, BPHDecayMomentum::Component>& daugMap,
48  const map<string, BPHRecoConstCandPtr> compMap)
49  : // store the map of names to previously reconstructed particles
50  cMap(compMap),
51  oldMom(true) {
52  // clone and store simple particles
54  // store previously reconstructed particles using information in cMap
55  dCompList();
56 }
57 
58 //--------------
59 // Destructor --
60 //--------------
62  // delete all clones
63  int n = dList.size();
64  while (n--)
65  delete dList[n];
66 }
67 
68 //--------------
69 // Operations --
70 //--------------
72  if (oldMom)
74  return compCand;
75 }
76 
77 const vector<string>& BPHDecayMomentum::daugNames() const { return nList; }
78 
79 const vector<string>& BPHDecayMomentum::compNames() const { return nComp; }
80 
81 const vector<const reco::Candidate*>& BPHDecayMomentum::daughters() const { return dList; }
82 
83 const vector<const reco::Candidate*>& BPHDecayMomentum::daughFull() const {
84  // compute total momentum to update the full list of decay products
85  if (oldMom)
87  return dFull;
88 }
89 
91  // return the original particle for a given clone
92  // return null pointer if not found
93  map<const reco::Candidate*, const reco::Candidate*>::const_iterator iter = clonesMap.find(daug);
94  return (iter != clonesMap.end() ? iter->second : nullptr);
95 }
96 
97 const vector<BPHRecoConstCandPtr>& BPHDecayMomentum::daughComp() const {
98  // return the list of previously reconstructed particles
99  return cList;
100 }
101 
102 const reco::Candidate* BPHDecayMomentum::getDaug(const string& name) const {
103  // return a simple particle from the name
104  // return null pointer if not found
105  string::size_type pos = name.find('/');
106  if (pos != string::npos) {
107  const BPHRecoCandidate* comp = getComp(name.substr(0, pos)).get();
108  return (comp == nullptr ? nullptr : comp->getDaug(name.substr(pos + 1)));
109  }
110  map<const string, const reco::Candidate*>::const_iterator iter = dMap.find(name);
111  return (iter != dMap.end() ? iter->second : nullptr);
112 }
113 
115  // return a previously reconstructed particle from the name
116  // return null pointer if not found
117  string::size_type pos = name.find('/');
118  if (pos != string::npos) {
119  const BPHRecoCandidate* comp = getComp(name.substr(0, pos)).get();
120  return (comp == nullptr ? nullptr : comp->getComp(name.substr(pos + 1)));
121  }
122  map<const string, BPHRecoConstCandPtr>::const_iterator iter = cMap.find(name);
123  return (iter != cMap.end() ? iter->second : nullptr);
124 }
125 
126 const vector<BPHDecayMomentum::Component>& BPHDecayMomentum::componentList() const {
127  // return an object filled in the constructor
128  // to be used in the creation of other bases of BPHRecoCandidate
129  return compList;
130 }
131 
132 void BPHDecayMomentum::addP(const string& name, const reco::Candidate* daug, double mass) {
133  if (dMap.find(name) != dMap.end()) {
134  edm::LogPrint("TooManyParticles") << "BPHDecayMomentum::add: "
135  << "Decay product already inserted with name " << name << " , skipped";
136  }
137  setNotUpdated();
138  reco::Candidate* dnew = daug->clone();
139  if (mass > 0.0)
140  dnew->setMass(mass);
141  nList.push_back(name);
142  dList.push_back(dnew);
143  dMap[name] = dnew;
144  clonesMap[dnew] = daug;
145  return;
146 }
147 
148 void BPHDecayMomentum::addP(const string& name, const BPHRecoConstCandPtr& comp) {
149  setNotUpdated();
150  nComp.push_back(name);
151  cList.push_back(comp);
152  cMap[name] = comp;
153  clonesMap.insert(comp->clonesMap.begin(), comp->clonesMap.end());
154  return;
155 }
156 
158  oldMom = true;
159  return;
160 }
161 
162 void BPHDecayMomentum::clonesList(const map<string, Component>& daugMap) {
163  int n = daugMap.size();
164  dList.resize(n);
165  nList.resize(n);
166  // reset and fill a list
167  // to be used in the creation of other bases of BPHRecoCandidate
168  compList.clear();
169  compList.reserve(n);
170  // loop over daughters
171  int i = 0;
172  double mass;
173  reco::Candidate* dnew;
174  map<string, Component>::const_iterator iter = daugMap.begin();
175  map<string, Component>::const_iterator iend = daugMap.end();
176  while (iter != iend) {
177  const map<string, Component>::value_type& entry = *iter++;
178  const Component& comp = entry.second;
179  const reco::Candidate* cand = comp.cand;
180  // store component for usage
181  // in the creation of other bases of BPHRecoCandidate
182  compList.push_back(comp);
183  // clone particle and store it with its name
184  dList[i] = dnew = cand->clone();
185  const string& name = nList[i++] = entry.first;
186  dMap[name] = dnew;
187  clonesMap[dnew] = cand;
188  // set daughter mass if requested
189  mass = comp.mass;
190  if (mass > 0)
191  dnew->setMass(mass);
192  }
193  return;
194 }
195 
197  // fill lists of previously reconstructed particles and their names
198  // and retrieve cascade decay products
199  int n = cMap.size();
200  cList.resize(n);
201  nComp.resize(n);
202  int i = 0;
203  map<string, BPHRecoConstCandPtr>::const_iterator c_iter = cMap.begin();
204  map<string, BPHRecoConstCandPtr>::const_iterator c_iend = cMap.end();
205  while (c_iter != c_iend) {
206  const map<string, BPHRecoConstCandPtr>::value_type& c_entry = *c_iter++;
207  nComp[i] = c_entry.first;
208  BPHRecoConstCandPtr comp = c_entry.second;
209  cList[i++] = comp;
210  clonesMap.insert(comp->clonesMap.begin(), comp->clonesMap.end());
211  }
212  return;
213 }
214 
215 void BPHDecayMomentum::sumMomentum(const vector<const reco::Candidate*>& dl, const vector<string>& dn) const {
216  // add the particles to pat::CompositeCandidate
217  int n = dl.size();
218  while (n--)
219  compCand.addDaughter(*dl[n], dn[n]);
220  return;
221 }
222 
223 void BPHDecayMomentum::fillDaug(vector<const reco::Candidate*>& ad, const string& name, vector<string>& an) const {
224  // recursively fill the list of simple particles, produced
225  // directly or in cascade decays
226  ad.insert(ad.end(), dList.begin(), dList.end());
227  vector<string>::const_iterator iter = nList.begin();
228  vector<string>::const_iterator iend = nList.end();
229  while (iter != iend)
230  an.push_back(name + *iter++);
231  int n = cList.size();
232  while (n--)
233  cList[n]->fillDaug(ad, name + nComp[n] + "/", an);
234  return;
235 }
236 
238  // reset full list of daughters
239  dFull.clear();
240  dFull.reserve(10);
241  vector<string> nFull;
242  nFull.reserve(10);
243  fillDaug(dFull, "", nFull);
244  // reset and fill pat::CompositeCandidate
246  sumMomentum(dFull, nFull);
247  // compute the total momentum
248  AddFourMomenta addP4;
249  addP4.set(compCand);
250  oldMom = false;
251  return;
252 }
virtual const reco::Candidate * originalReco(const reco::Candidate *daug) const
get the original particle from the clone
Analysis-level particle class.
std::vector< BPHRecoConstCandPtr > cList
void set(reco::Candidate &c) const
set up a candidate
virtual void computeMomentum() const
BPHGenericPtr< const BPHRecoCandidate >::type BPHRecoConstCandPtr
virtual ~BPHDecayMomentum()
const std::vector< Component > & componentList() const
std::map< std::string, const reco::Candidate * > dMap
uint16_t size_type
virtual const std::vector< const reco::Candidate * > & daughFull() const
std::vector< const reco::Candidate * > dList
virtual const reco::Candidate * getDaug(const std::string &name) const
std::vector< Component > compList
std::vector< const reco::Candidate * > dFull
Log< level::Warning, true > LogPrint
BPHDecayMomentum(const BPHDecayMomentum &x)=delete
virtual void addP(const std::string &name, const reco::Candidate *daug, double mass=-1.0)
void addDaughter(const Candidate &, const std::string &s="")
add a clone of the passed candidate as daughter
virtual void sumMomentum(const std::vector< const reco::Candidate *> &dl, const std::vector< std::string > &dn) const
virtual const std::vector< std::string > & compNames() const
virtual Candidate * clone() const =0
returns a clone of the Candidate object
void clearDaughters()
clear daughters
virtual BPHRecoConstCandPtr getComp(const std::string &name) const
virtual const std::vector< BPHRecoConstCandPtr > & daughComp() const
void clonesList(const std::map< std::string, Component > &daugMap)
virtual void fillDaug(std::vector< const reco::Candidate *> &ad, const std::string &name, std::vector< std::string > &an) const
std::map< const reco::Candidate *, const reco::Candidate * > clonesMap
virtual const std::vector< std::string > & daugNames() const
virtual void setNotUpdated() const
pat::CompositeCandidate compCand
const std::map< std::string, const reco::Candidate * > & daugMap() const
virtual const std::vector< const reco::Candidate * > & daughters() const
std::vector< std::string > nList
std::vector< std::string > nComp
std::map< std::string, BPHRecoConstCandPtr > cMap
virtual void setMass(double m)=0
set particle mass
virtual const pat::CompositeCandidate & composite() const
get a composite by the simple sum of simple particles