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