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() : 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 }
BPHDecayMomentum::daughComp
virtual const std::vector< BPHRecoConstCandPtr > & daughComp() const
Definition: BPHDecayMomentum.cc:89
BPHDecayMomentum::addP
virtual void addP(const std::string &name, const reco::Candidate *daug, double mass=-1.0)
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
reco::Candidate::setMass
virtual void setMass(double m)=0
set particle mass
BPHDecayMomentum::composite
virtual const pat::CompositeCandidate & composite() const
get a composite by the simple sum of simple particles
Definition: BPHDecayMomentum.cc:63
pat::CompositeCandidate
Analysis-level particle class.
Definition: CompositeCandidate.h:31
mps_splice.entry
entry
Definition: mps_splice.py:68
BPHDecayMomentum::cMap
std::map< std::string, BPHRecoConstCandPtr > cMap
Definition: BPHDecayMomentum.h:148
pos
Definition: PixelAliasList.h:18
BPHDecayMomentum.h
BPHDecayMomentum::getDaug
virtual const reco::Candidate * getDaug(const std::string &name) const
Definition: BPHDecayMomentum.cc:94
AlCaHLTBitMon_QueryRunRegistry.comp
comp
Definition: AlCaHLTBitMon_QueryRunRegistry.py:249
BPHDecayMomentum::compList
std::vector< Component > compList
Definition: BPHDecayMomentum.h:134
BPHDecayMomentum::sumMomentum
virtual void sumMomentum(const std::vector< const reco::Candidate * > dl) const
Definition: BPHDecayMomentum.cc:207
BPHDecayMomentum::computeMomentum
virtual void computeMomentum() const
Definition: BPHDecayMomentum.cc:225
BPHDecayMomentum::dList
std::vector< const reco::Candidate * > dList
Definition: BPHDecayMomentum.h:142
BPHDecayMomentum::BPHDecayMomentum
BPHDecayMomentum()
Definition: BPHDecayMomentum.cc:32
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
BPHDecayMomentum::oldMom
bool oldMom
Definition: BPHDecayMomentum.h:154
BPHDecayMomentum::fillDaug
virtual void fillDaug(std::vector< const reco::Candidate * > &ad) const
Definition: BPHDecayMomentum.cc:215
reco::CompositeCandidate::addDaughter
void addDaughter(const Candidate &, const std::string &s="")
add a clone of the passed candidate as daughter
Definition: CompositeCandidate.cc:108
funct::true
true
Definition: Factorize.h:173
reco::Candidate::clone
virtual Candidate * clone() const =0
returns a clone of the Candidate object
cand
Definition: decayParser.h:34
BPHDecayMomentum::clonesMap
std::map< const reco::Candidate *, const reco::Candidate * > clonesMap
Definition: BPHDecayMomentum.h:151
BPHDecayMomentum::Component
Definition: BPHDecayMomentum.h:101
BPHDecayMomentum::getComp
virtual BPHRecoConstCandPtr getComp(const std::string &name) const
Definition: BPHDecayMomentum.cc:106
edm::LogPrint
Definition: MessageLogger.h:342
BPHAddFourMomenta.h
BPHDecayMomentum::nComp
std::vector< std::string > nComp
Definition: BPHDecayMomentum.h:138
BPHDecayMomentum::setNotUpdated
virtual void setNotUpdated() const
Definition: BPHDecayMomentum.cc:149
get
#define get
BPHDecayMomentum::dFull
std::vector< const reco::Candidate * > dFull
Definition: BPHDecayMomentum.h:155
reco::Candidate
Definition: Candidate.h:27
BPHDecayMomentum::nList
std::vector< std::string > nList
Definition: BPHDecayMomentum.h:137
BPHDecayMomentum::compNames
virtual const std::vector< std::string > & compNames() const
Definition: BPHDecayMomentum.cc:71
std
Definition: JetResolutionObject.h:76
BPHDecayMomentum::originalReco
virtual const reco::Candidate * originalReco(const reco::Candidate *daug) const
get the original particle from the clone
Definition: BPHDecayMomentum.cc:82
reco::CompositeCandidate::clearDaughters
void clearDaughters()
clear daughters
Definition: CompositeCandidate.h:71
BPHDecayMomentum::daughFull
virtual const std::vector< const reco::Candidate * > & daughFull() const
Definition: BPHDecayMomentum.cc:75
BPHRecoCandidate.h
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
AddFourMomenta::set
void set(reco::Candidate &c) const
set up a candidate
Definition: AddFourMomenta.cc:6
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
BPHDecayMomentum::clonesList
void clonesList(const std::map< std::string, Component > &daugMap)
Definition: BPHDecayMomentum.cc:154
BPHDecayMomentum::daughters
virtual const std::vector< const reco::Candidate * > & daughters() const
Definition: BPHDecayMomentum.cc:73
AddFourMomenta
Definition: AddFourMomenta.h:18
BPHDecayMomentum::daugNames
virtual const std::vector< std::string > & daugNames() const
Definition: BPHDecayMomentum.cc:69
BPHRecoCandidate
Definition: BPHRecoCandidate.h:46
BPHDecayMomentum::componentList
const std::vector< Component > & componentList() const
Definition: BPHDecayMomentum.cc:118
BPHDecayMomentum::dCompList
void dCompList()
Definition: BPHDecayMomentum.cc:188
BPHDecayMomentum::dMap
std::map< std::string, const reco::Candidate * > dMap
Definition: BPHDecayMomentum.h:147
reco::Candidate::begin
const_iterator begin() const
first daughter const_iterator
Definition: Candidate.h:143
BPHDecayMomentum::cList
std::vector< BPHRecoConstCandPtr > cList
Definition: BPHDecayMomentum.h:143
BPHDecayMomentum::compCand
pat::CompositeCandidate compCand
Definition: BPHDecayMomentum.h:156
BPHRecoConstCandPtr
BPHGenericPtr< const BPHRecoCandidate >::type BPHRecoConstCandPtr
Definition: BPHRecoCandidatePtr.h:9
BPHDecayMomentum::~BPHDecayMomentum
virtual ~BPHDecayMomentum()
Definition: BPHDecayMomentum.cc:53