test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 #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 : 0 );
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 ) return getComp( name.substr( 0, pos ) )
123  ->getDaug( name.substr( pos + 1 ) );
124  map<const string,
125  const reco::Candidate*>::const_iterator iter = dMap.find( name );
126  return ( iter != dMap.end() ? iter->second : 0 );
127 }
128 
129 
131  // return a previously reconstructed particle from the name
132  // return null pointer if not found
133  map<const string,
134  BPHRecoConstCandPtr>::const_iterator iter = cMap.find( name );
135  return ( iter != cMap.end() ? iter->second : 0 );
136 }
137 
138 
139 const vector<BPHDecayMomentum::Component>&
141  // return an object filled in the constructor
142  // to be used in the creation of other bases of BPHRecoCandidate
143  return compList;
144 }
145 
146 
147 void BPHDecayMomentum::addP( const string& name,
148  const reco::Candidate* daug, double mass ) {
149  if ( dMap.find( name ) != dMap.end() ) {
150  edm::LogPrint( "TooManyParticles" )
151  << "BPHDecayMomentum::add: "
152  << "Decay product already inserted with name " << name
153  << " , skipped";
154  }
155  setNotUpdated();
156  reco::Candidate* dnew = daug->clone();
157  if ( mass > 0.0 ) dnew->setMass( mass );
158  nList.push_back( name );
159  dList.push_back( dnew );
160  dMap[name] = dnew;
161  clonesMap[dnew] = daug;
162  return;
163 }
164 
165 
166 void BPHDecayMomentum::addP( const string& name,
167  const BPHRecoConstCandPtr& comp ) {
168  setNotUpdated();
169  nComp.push_back( name );
170  cList.push_back( comp );
171  cMap[name] = comp;
172  clonesMap.insert( comp->clonesMap.begin(), comp->clonesMap.end() );
173  return;
174 }
175 
176 
178  oldMom = true;
179  return;
180 }
181 
182 
183 void BPHDecayMomentum::clonesList( const map<string,Component>& daugMap ) {
184  int n = daugMap.size();
185  dList.resize( n );
186  nList.resize( n );
187  // reset and fill a list
188  // to be used in the creation of other bases of BPHRecoCandidate
189  compList.clear();
190  compList.reserve( n );
191  // loop over daughters
192  int i = 0;
193  double mass;
194  reco::Candidate* dnew;
195  map<string,Component>::const_iterator iter = daugMap.begin();
196  map<string,Component>::const_iterator iend = daugMap.end();
197  while ( iter != iend ) {
198  const pair<string,Component>& entry = *iter++;
199  const Component& comp = entry.second;
200  const reco::Candidate* cand = comp.cand;
201  // store component for usage
202  // in the creation of other bases of BPHRecoCandidate
203  compList.push_back( comp );
204  // clone particle and store it with its name
205  dList[i] = dnew = cand->clone();
206  const string& name = nList[i++] = entry.first;
207  dMap[name] = dnew;
208  clonesMap[dnew] = cand;
209  // set daughter mass if requested
210  mass = comp.mass;
211  if ( mass > 0 ) dnew->setMass( mass );
212  }
213  return;
214 }
215 
216 
218  // fill lists of previously reconstructed particles and their names
219  // and retrieve cascade decay products
220  int n = cMap.size();
221  cList.resize( n );
222  nComp.resize( n );
223  int i = 0;
224  map<string,BPHRecoConstCandPtr>::const_iterator iter = cMap.begin();
225  map<string,BPHRecoConstCandPtr>::const_iterator iend = cMap.end();
226  while ( iter != iend ) {
227  const pair<string,BPHRecoConstCandPtr>& entry = *iter++;
228  nComp[i] = entry.first;
229  BPHRecoConstCandPtr comp = entry.second;
230  cList[i++] = comp;
231  clonesMap.insert( comp->clonesMap.begin(), comp->clonesMap.end() );
232  }
233  return;
234 }
235 
236 
238  const vector<const reco::Candidate*> dl ) const {
239  // add the particles to pat::CompositeCandidate
240  int n = dl.size();
241  while ( n-- ) compCand.addDaughter( *dl[n] );
242  return;
243 }
244 
245 
246 void BPHDecayMomentum::fillDaug( vector<const reco::Candidate*>& ad ) const {
247  // recursively fill the list of simple particles, produced
248  // directly or in cascade decays
249  ad.insert( ad.end(), dList.begin(), dList.end() );
250  int n = cList.size();
251  while ( n-- ) cList[n]->fillDaug( ad );
252  return;
253 }
254 
255 
257  // reset full list of daughters
258  dFull.clear();
259  fillDaug( dFull );
260  // reset and fill pat::CompositeCandidate
262  sumMomentum( dFull );
263  // compute the total momentum
264  AddFourMomenta addP4;
265  addP4.set( compCand );
266  oldMom = false;
267  return;
268 }
269 
Analysis-level particle class.
const reco::Candidate * cand
int i
Definition: DBlmapReader.cc:9
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()
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
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
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< 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
list entry
Definition: mps_splice.py:62
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