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