FairRoot/PandaRoot
PhotosHEPEVTParticle.cxx
Go to the documentation of this file.
1 #include "PhotosHEPEVTParticle.h"
2 #include "Log.h"
3 
4 namespace Photospp
5 {
6 
8 {
9  // Cleanup particles that do not belong to event
10  for(unsigned int i=0;i<cache.size();i++)
11  if(cache[i]->m_barcode<0)
12  delete cache[i];
13 }
14 
15 PhotosHEPEVTParticle::PhotosHEPEVTParticle(int pdgid, int status, double px, double py, double pz, double e, double m, int ms, int me, int ds, int de){
16  m_px = px;
17  m_py = py;
18  m_pz = pz;
19  m_e = e;
21 
22  m_pdgid = pdgid;
23  m_status = status;
24 
25  m_first_mother = ms;
27  m_daughter_start = ds;
29 
30  m_barcode = -1;
31  m_event = NULL;
32 }
33 
36 {
37  if(!m_event) Log::Fatal("PhotosHEPEVTParticle::addDaughter - particle not in event record");
38 
39  std::vector<PhotosParticle*> mothers = daughter->getMothers();
40 
41  mothers.push_back( (PhotosParticle*)this );
42 
43  daughter->setMothers(mothers);
44 
45  int bc = daughter->getBarcode();
46 
47  if(m_daughter_end < 0)
48  {
49  m_daughter_start = bc;
50  m_daughter_end = bc;
51  }
52  // if it's in the middle of the event record
53  else if(m_daughter_end != bc-1)
54  {
56 
57  // Move all particles one spot down the list, to make place for new particle
58  for(int i=bc-1;i>m_daughter_end;i--)
59  {
61  move->setBarcode(i+1);
62  m_event->setParticle(i+1,move);
63  }
64 
65  m_daughter_end++;
66  newPart->setBarcode(m_daughter_end);
67  m_event->setParticle(m_daughter_end,newPart);
68 
69  // Now: correct all pointers before new particle
70  for(int i=0;i<m_daughter_end;i++)
71  {
73  int m = check->getDaughterRangeEnd();
74  if(m!=-1 && m>m_daughter_end)
75  {
76  check->setDaughterRangeEnd(m+1);
78  }
79  }
80  }
81  else m_daughter_end = bc;
82 }
83 
84 void PhotosHEPEVTParticle::setMothers(vector<PhotosParticle*> mothers){
85 
86  // If this particle has not yet been added to the event record
87  // then add it to the mothers' event record
88  if(m_barcode<0 && mothers.size()>0)
89  {
90  PhotosHEPEVTEvent *evt = ((PhotosHEPEVTParticle*)mothers[0])->m_event;
91  evt->addParticle(this);
92  }
93 
94  if(mothers.size()>2) Log::Fatal("PhotosHEPEVTParticle::setMothers: HEPEVT does not allow more than two mothers!");
95 
96  if(mothers.size()>0) m_first_mother = mothers[0]->getBarcode();
97  if(mothers.size()>1) m_second_mother = mothers[1]->getBarcode();
98 }
99 
100 void PhotosHEPEVTParticle::setDaughters(vector<PhotosParticle*> daughters){
101 
102  // This particle must be inside some event record to be able to add daughters
103  if(m_event==NULL) Log::Fatal("PhotosHEPEVTParticle::setDaughters: particle not inside event record.");
104 
105  int beg = 65535, end = -1;
106 
107  for(unsigned int i=0;i<daughters.size();i++)
108  {
109  int bc = daughters[i]->getBarcode();
110  if(bc<0) Log::Fatal("PhotosHEPEVTParticle::setDaughters: all daughters has to be in event record first");
111  if(bc<beg) beg = bc;
112  if(bc>end) end = bc;
113  }
114  if(end == -1) beg = -1;
115 
116  m_daughter_start = beg;
117  m_daughter_end = end;
118 }
119 
120 std::vector<PhotosParticle*> PhotosHEPEVTParticle::getMothers(){
121 
122  std::vector<PhotosParticle*> mothers;
123 
124  PhotosParticle *p1 = NULL;
125  PhotosParticle *p2 = NULL;
126 
129 
130  if(p1) mothers.push_back(p1);
131  if(p2) mothers.push_back(p2);
132 
133  return mothers;
134 }
135 
136 // WARNING: this method also corrects daughter indices
137 // if such were not defined
138 std::vector<PhotosParticle*> PhotosHEPEVTParticle::getDaughters(){
139 
140  std::vector<PhotosParticle*> daughters;
141 
142  if(!m_event) return daughters;
143 
144  // Check if m_daughter_start and m_daughter_end are set
145  // If not - try to get list of daughters from event
146  if(m_daughter_end<0)
147  {
148  int min_d=65535, max_d=-1;
149  for(int i=0;i<m_event->getParticleCount();i++)
150  {
151  if(m_event->getParticle(i)->isDaughterOf(this))
152  {
153  if(i<min_d) min_d = i;
154  if(i>max_d) max_d = i;
155  }
156  }
157  if(max_d>=0)
158  {
159  m_daughter_start = min_d;
160  m_daughter_end = max_d;
161  m_status = 2;
162  }
163  }
164 
165  // If m_daughter_end is still not set - there are no daughters
166  // Otherwsie - get daughters
167  if(m_daughter_end>=0)
168  {
169  for(int i=m_daughter_start;i<=m_daughter_end;i++)
170  {
172  if(p==NULL)
173  {
174  Log::Warning()<<"PhotosHEPEVTParticle::getDaughters(): No particle with index "<<i<<endl;
175  return daughters;
176  }
177 
178  daughters.push_back(p);
179  }
180  }
181 
182  return daughters;
183 }
184 
185 std::vector<PhotosParticle*> PhotosHEPEVTParticle::getAllDecayProducts()
186 {
187  std::vector<PhotosParticle*> list;
188 
189  if(!hasDaughters()) // if this particle has no daughters
190  return list;
191 
192  std::vector<PhotosParticle*> daughters = getDaughters();
193 
194  // copy daughters to list of all decay products
195  list.insert(list.end(),daughters.begin(),daughters.end());
196 
197  // Now, get all daughters recursively, without duplicates.
198  // That is, for each daughter:
199  // 1) get list of her daughters
200  // 2) for each particle on this list:
201  // a) check if it is already on the list
202  // b) if it's not, add her to the end of the list
203  for(unsigned int i=0;i<list.size();i++)
204  {
205  std::vector<PhotosParticle*> daughters2 = list[i]->getDaughters();
206 
207  if(!list[i]->hasDaughters()) continue;
208  for(unsigned int j=0;j<daughters2.size();j++)
209  {
210  bool add=true;
211  for(unsigned int k=0;k<list.size();k++)
212  if( daughters2[j]->getBarcode() == list[k]->getBarcode() )
213  {
214  add=false;
215  break;
216  }
217 
218  if(add) list.push_back(daughters2[j]);
219  }
220  }
221 
222  return list;
223 }
224 
226 
227  if(!m_event) return true;
228  if(m_daughter_end < 0) return true;
229 
231 
232  int first_mother_idx = buf->getFirstMotherIndex();
233  int second_mother_idx = buf->getSecondMotherIndex();
234 
235  double px =0.0, py =0.0, pz =0.0, e =0.0;
236  double px2=0.0, py2=0.0, pz2=0.0, e2=0.0;
237 
238  for(int i=m_daughter_start;i<=m_daughter_end;i++)
239  {
240  buf = m_event->getParticle(i);
241  px += buf->getPx();
242  py += buf->getPy();
243  pz += buf->getPz();
244  e += buf->getE ();
245  }
246 
247  if(first_mother_idx>=0)
248  {
249  buf = m_event->getParticle(first_mother_idx);
250  px2 += buf->getPx();
251  py2 += buf->getPy();
252  pz2 += buf->getPz();
253  e2 += buf->getE();
254  }
255 
256  if(second_mother_idx>=0)
257  {
258  buf = m_event->getParticle(second_mother_idx);
259  px2 += buf->getPx();
260  py2 += buf->getPy();
261  pz2 += buf->getPz();
262  e2 += buf->getE();
263  }
264  // 3-momentum // test HepMC style
265  double dp = sqrt( (px-px2)*(px-px2) + (py-py2)*(py-py2) + (pz-pz2)*(pz-pz2) );
266  // virtuality test as well.
267  double m1 = sqrt( fabs( e*e - px*px - py*py - pz*pz ) );
268  double m2 = sqrt( fabs( e2*e2 - px2*px2 - py2*py2 - pz2*pz2 ) );
269 
270  if( fabs(m1-m2) > 0.0001 || dp > 0.0001*(e+e2))
271  {
272  Log::RedirectOutput( Log::Warning()<<"Momentum not conserved in vertex: " );
273  if(first_mother_idx >=0) m_event->getParticle(first_mother_idx) ->print();
274  if(second_mother_idx>=0) m_event->getParticle(second_mother_idx)->print();
277  return false;
278  }
279 
280  return true;
281 }
282 
284  int pdg_id, int status, double mass,
285  double px, double py, double pz, double e){
286 
287  // New particles created using this method are added to cache
288  // They will be deleted when this particle will be deleted
289 
290  cache.push_back(new PhotosHEPEVTParticle(pdg_id,status,px,py,pz,e,mass,-1,-1,-1,-1));
291  return cache.back();
292 }
293 
295 {
296  Log::Warning()<<"PhotosParticle::createHistoryEntry() not implemented for HEPEVT."<<endl;
297 }
298 
300 {
301  Log::Warning()<<"PhotosHEPEVTParticle::createSelfDecayVertex() not implemented for HEPEVT."<<endl;
302 }
303 
305 {
306  int bc = p->getBarcode();
307  if(bc==m_first_mother || bc==m_second_mother) return true;
308 
309  return false;
310 }
311 
313 {
314  int bc = p->getBarcode();
315  if(bc>=m_daughter_start && bc<=m_daughter_end) return true;
316 
317  return false;
318 }
319 
321  char buf[256];
322  sprintf(buf,"P: (%2i) %6i %2i | %11.4e %11.4e %11.4e %11.4e | %11.4e | M: %2i %2i | D: %2i %2i\n",
325 
326  cout<<buf;
327 }
328 
329 /******** Getter and Setter methods: ***********************/
330 
332  m_pdgid = pdg_id;
333 }
334 
336  m_status = status;
337 }
338 
340  m_generated_mass = mass;
341 }
342 
344  return m_pdgid;
345 }
346 
348  return m_status;
349 }
350 
352  return m_generated_mass;
353 }
354 
356  return m_px;
357 }
358 
360  return m_py;
361 }
362 
364  return m_pz;
365 }
366 
368  return m_e;
369 }
370 
372  m_px = px;
373 }
374 
376  m_py = py;
377 }
378 
379 
381  m_pz = pz;
382 }
383 
385  m_e = e;
386 }
387 
389  return m_barcode;
390 }
391 
393  m_barcode = barcode;
394 }
395 
397  m_event = event;
398 }
399 
401  return m_first_mother;
402 }
403 
405  return m_second_mother;
406 }
407 
409  return m_daughter_start;
410 }
411 
413  return m_daughter_end;
414 }
415 
416 } // namespace Photospp
PhotosHEPEVTParticle * createNewParticle(int pdg_id, int status, double mass, double px, double py, double pz, double e)
Int_t i
Definition: run_full.C:25
__m128 m
Definition: P4_F32vec4.h:28
static const double me
Definition: mzparameters.h:12
void setEvent(PhotosHEPEVTEvent *event)
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
std::vector< PhotosParticle * > getMothers()
PhotosHEPEVTParticle * getParticle(int i)
int evt
Definition: checkhelixhit.C:36
double de
Definition: anaLmdDigi.C:68
std::string move
std::vector< PhotosParticle * > getAllDecayProducts()
Double_t p
Definition: anasim.C:58
std::vector< PhotosParticle * > getDaughters()
bool isMotherOf(PhotosHEPEVTParticle *p)
Definition: Log.h:30
TString m2(TString pts, TString exts="e px py pz")
Definition: invexp.C:117
virtual int getBarcode()=0
virtual void setMothers(std::vector< PhotosParticle * > mothers)=0
void setDaughters(std::vector< PhotosParticle * > daughters)
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
static ostream & Warning(bool count=true)
Definition: Log.cxx:46
TPad * p2
Definition: hist-t7.C:117
void setMothers(std::vector< PhotosParticle * > mothers)
PhotosHEPEVTParticle(int pdgid, int status, double px, double py, double pz, double e, double m, int ms, int me, int ds, int de)
static void Fatal(string text, unsigned short int code=0)
TPad * p1
Definition: hist-t7.C:116
return buf
bool isDaughterOf(PhotosHEPEVTParticle *p)
vector< PhotosHEPEVTParticle * > cache
void createSelfDecayVertex(PhotosParticle *out)
virtual std::vector< PhotosParticle * > getMothers()=0
void setParticle(int i, PhotosHEPEVTParticle *p)
static void RevertOutput()
Definition: Log.h:90
void addDaughter(PhotosParticle *daughter)
void addParticle(PhotosHEPEVTParticle *p)
static void RedirectOutput(void(*func)(), ostream &where=*out)
Definition: Log.cxx:90
double pz[39]
Definition: pipisigmas.h:14
int status[10]
Definition: f_Init.h:28