CMS 3D CMS Logo

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