FairRoot/PandaRoot
PhotosBranch.cxx
Go to the documentation of this file.
1 #include <vector>
2 #include <list>
3 #include "PH_HEPEVT_Interface.h"
4 #include "PhotosParticle.h"
5 #include "PhotosBranch.h"
6 #include "Photos.h"
7 #include "Log.h"
8 using std::vector;
9 using std::list;
10 using std::endl;
11 
12 namespace Photospp
13 {
14 
16 {
17  daughters = p->getDaughters();
18 
19  //Suppress if somehow got stable particle
20  if(daughters.size()==0)
21  {
22  Log::Debug(1)<<"Stable particle."<<endl;
23  suppression = 1;
24  forcing = 0;
25  particle = NULL;
26  return;
27  }
28  else if(daughters.at(0)->getMothers().size()==1)
29  {
30  // Regular case - one mother
31  Log::Debug(1)<<"Regular case."<<endl;
32  particle = p;
34  }
35  else
36  {
37  // Advanced case - branch with multiple mothers - no mid-particle
38  Log::Debug(1)<<"Advanced case."<<endl;
39  particle = NULL;
40  mothers = daughters.at(0)->getMothers();
41  }
44  else suppression = 0;
45 
46  // Even if forced or passed suppression check, we still have to check few things
47  if(!suppression)
48  {
49  // Check momentum conservation
51  if(suppression) Log::Warning()<<"Branching ignored due to 4-momentum non conservation"<<endl;
52 
53  // Check if advanced case has only one daughter
54  if(!particle && daughters.size()==1) suppression=-1;
55 
56  // If any of special cases is true, we're not forcing this branch
57  if(suppression) forcing=0;
58  }
59 }
60 
62 {
63  Log::Debug(703)<<" Processing barcode: "<<( (particle) ? particle->getBarcode() : ( (mothers.size()) ? mothers.at(0)->getBarcode() : -1) )<<endl;
64  /*
65  cout<<"Particles send to photos (with barcodes in brackets):"<<endl;
66  vector<PhotosParticle *> get = getParticles();
67  for(int i=0;i<(int)get.size();i++) cout<<"ID: "<<get.at(i)->getPdgID()<<" ("<<get.at(i)->getBarcode()<<"), "; cout<<endl;
68  */
69  int index = PH_HEPEVT_Interface::set(this);
71  photos_make_c_(&index);
75 }
76 
77 vector<PhotosParticle *> PhotosBranch::getParticles()
78 {
79  vector<PhotosParticle *> ret = mothers;
80  if(particle) ret.push_back(particle);
81  ret.insert(ret.end(),daughters.begin(),daughters.end());
82  return ret;
83 }
84 
86 {
88  if(mothers.size()>0) return mothers.at(0)->checkMomentumConservation();
89  return true;
90 }
91 
92 vector<PhotosBranch *> PhotosBranch::createBranches(vector<PhotosParticle *> particles)
93 {
94  Log::Debug(700)<<"PhotosBranch::createBranches - filtering started"<<endl;
95  list<PhotosParticle *> list(particles.begin(),particles.end());
96  vector<PhotosBranch *> branches;
97 
98  // First - add all forced decays
100  {
101  std::list<PhotosParticle *>::iterator it;
102  for(it=list.begin();it!=list.end();it++)
103  {
104  PhotosBranch *branch = new PhotosBranch(*it);
105  int forcing = branch->getForcingStatus();
106  if(forcing)
107  {
108  Log::Debug(701)<<" Forced: "<<(*it)->getPdgID()<<" (barcode: "<<(*it)->getBarcode()<<") with forcing status= "<<forcing<<endl;
109  branches.push_back(branch);
110  it = list.erase(it);
111  --it;
112  // If forcing consecutive decays
113  if(forcing==2)
114  {
115  PhotosParticle *p = branch->getDecayingParticle();
116  if(!p){
117  if(branch->getMothers().size()>0) p = branch->getMothers().at(0);
118  }else {continue;}
119  vector<PhotosParticle *> tree = p->getDecayTree();
120  //Add branches for all particles from the list - max O(n*m)
121  std::list<PhotosParticle *>::iterator it2;
122  for(it2=list.begin();it2!=list.end();it2++)
123  {
124  for(int i=0;i<(int)tree.size();i++)
125  {
126  if(tree.at(i)->getBarcode()==(*it2)->getBarcode())
127  {
128  PhotosBranch *b = new PhotosBranch(*it2);
129  branches.push_back(b);
130  // If we were to delete our next particle in line
131  if(it==it2) --it;
132  it2 = list.erase(it2);
133  --it2;
134  break;
135  }
136  }
137  }
138  }
139  }
140  else delete branch;
141  }
142  }
143  // Quit if we're suppressing everything
144  if(Photos::isSuppressed) return branches;
145  // Now - check if remaining decays are suppressed
146  while(!list.empty())
147  {
148  PhotosParticle *particle = list.front();
149  list.pop_front();
150  if(!particle) continue;
151 
152  PhotosBranch *branch = new PhotosBranch(particle);
153  int suppression = branch->getSuppressionStatus();
154  if(!suppression) branches.push_back(branch);
155  else
156  {
157  Log::Debug(702)<<" Suppressed: "<<particle->getPdgID()<<" (barcode: "<<particle->getBarcode()<<") with suppression status= "<<suppression<<endl;
158  //If suppressing consecutive decays
159  if(suppression==2)
160  {
161  PhotosParticle *p = branch->getDecayingParticle();
162  if(!p){
163  if(branch->getMothers().size()>0) p = branch->getMothers().at(0);
164  }else {continue;}
165  vector<PhotosParticle *> tree = p->getDecayTree();
166  //Remove all particles from the list - max O(n*m)
167  std::list<PhotosParticle *>::iterator it;
168  for(it=list.begin();it!=list.end();it++)
169  {
170  for(int i=0;i<(int)tree.size();i++)
171  {
172  if(tree.at(i)->getBarcode()==(*it)->getBarcode())
173  {
174  it = list.erase(it);
175  --it;
176  break;
177  }
178  }
179  }
180  }
181  delete branch;
182  continue;
183  }
184 
185  //In case we don't have mid-particle erase rest of the mothers from list
186  if(!branch->getDecayingParticle())
187  {
188  vector<PhotosParticle *> mothers = branch->getMothers();
189  for(int i=0;i<(int)mothers.size();i++)
190  {
191  PhotosParticle *m = mothers.at(i);
192  if(m->getBarcode()==particle->getBarcode()) continue;
193  std::list<PhotosParticle *>::iterator it;
194  for(it=list.begin();it!=list.end();it++)
195  if(m->getBarcode()==(*it)->getBarcode())
196  {
197  it = list.erase(it);
198  break;
199  }
200  }
201  }
202  }
203  return branches;
204 }
205 
206 int PhotosBranch::checkList(bool forceOrSuppress)
207 {
208  vector< vector<int>* > *list = (forceOrSuppress) ? Photos::forceBremList : Photos::supBremList;
209  if(!list) return 0;
210 
211  // Can't check without pdgid
212  int motherID;
213  if(particle) motherID = particle->getPdgID();
214  else
215  {
216  if(mothers.size()==0) return 0;
217  motherID = mothers.at(0)->getPdgID();
218  }
219 
220  // Create list of daughters
221  vector<int> dID;
222  for(int j=0;j<(int)daughters.size();j++) dID.push_back(daughters[j]->getPdgID());
223 
224  vector< vector<int> *> &patternList = *list;
225 
226  // Check if the mother and list of daughters matches any of the declared patterns
227  for(int j=0; j<(int)patternList.size();j++)
228  {
229  // Skip patterns that don't have our mother
230  if(motherID!=(*patternList[j])[0]) continue;
231 
232  // Compare decay daughters with pattern - max O(n*m)
233  vector<int> &pattern = *patternList[j];
234  bool fullMatch=true;
235  for(int k = 1; k<(int)pattern.size()-1; k++)
236  {
237  bool oneMatch=false;
238  for(int l=0;l<(int)dID.size(); l++)
239  if(pattern[k]==dID[l]) { oneMatch=true; break; }
240  if(!oneMatch) { fullMatch=false; break; }
241  }
242  // Check if the matching pattern is set for consecutive suppression
243  /*
244  Currently minimal matching is used.
245  If e.g. 25 -> -15 is suppressed, then 25 -> 15,-15 and 25 -> 15,-15,22 etc. is suppressed too
246  For exact matching (then suppress 25 -> 15,-15 ; 25 -> 15,-15,22 etc. must be done separately) uncoment line ...:
247  */
248  // if(pattern.size()<=2 || (fullMatch && dID.size()==pattern.size()-2) )
249  // ...and comment out line:
250  if(pattern.size()<=2 || fullMatch)
251  return (pattern.back()==1) ? 2 : 1;
252  }
253  return 0;
254 }
255 
256 } // namespace Photospp
static vector< PhotosBranch * > createBranches(vector< PhotosParticle * > particles)
Int_t i
Definition: run_full.C:25
__m128 m
Definition: P4_F32vec4.h:28
TTree * b
TTree * tree
Definition: plot_dirc.C:12
vector< PhotosParticle * > getMothers()
Definition: PhotosBranch.h:33
static vector< vector< int > * > * forceBremList
Definition: Photos.h:163
PhotosParticle * getDecayingParticle()
Definition: PhotosBranch.h:30
static vector< vector< int > * > * supBremList
Definition: Photos.h:160
Double_t p
Definition: anasim.C:58
std::vector< PhotosParticle * > findProductionMothers()
virtual int getPdgID()=0
Definition: Log.h:30
virtual int getBarcode()=0
static ostream & Debug(unsigned short int code=0, bool count=true)
Definition: Log.cxx:30
static bool isSuppressed
Definition: Photos.h:154
vector< PhotosParticle * > daughters
Definition: PhotosBranch.h:75
void photos_make_c_(int *id)
std::vector< PhotosParticle * > getDecayTree()
PhotosParticle * particle
Definition: PhotosBranch.h:71
vector< PhotosParticle * > mothers
Definition: PhotosBranch.h:73
vector< PhotosParticle * > getParticles()
PhotosBranch(PhotosParticle *p)
static ostream & Warning(bool count=true)
Definition: Log.cxx:46
virtual bool checkMomentumConservation()=0
int checkList(bool forceOrSuppress)
static int set(PhotosBranch *branch)
virtual std::vector< PhotosParticle * > getDaughters()=0