Belle II Software  release-06-02-00
PhotosBranch.cc
1 #include <vector>
2 #include <list>
3 #include "HEPEVT_struct.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 
15  {
16  daughters = p->getDaughters();
17 
18  //Suppress if somehow got stable particle
19  if (daughters.size() == 0) {
20  Log::Debug(1) << "Stable particle." << endl;
21  suppression = 1;
22  forcing = 0;
23  particle = NULL;
24  return;
25  } else if (daughters.at(0)->getMothers().size() == 1) {
26  // Regular case - one mother
27  Log::Debug(1) << "Regular case." << endl;
28  particle = p;
29  mothers = p->findProductionMothers();
30  } else {
31  // Advanced case - branch with multiple mothers - no mid-particle
32  Log::Debug(1) << "Advanced case." << endl;
33  particle = NULL;
34  mothers = daughters.at(0)->getMothers();
35  }
36 
37  //--------------------------------------------------
38  // Finalize suppression/forcing checks
39  // NOTE: if user forces decay of specific particle,
40  // this overrides any suppresion
41  //--------------------------------------------------
42 
45  else suppression = 0;
46 
47  // Even if forced or passed suppression check, we still have to check few things
48  if (!suppression) {
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(
64  0)->getBarcode() : -1)) << endl;
65  /*
66  cout<<"Particles send to photos (with barcodes in brackets):"<<endl;
67  vector<PhotosParticle *> get = getParticles();
68  for(int i=0;i<(int)get.size();i++) cout<<"ID: "<<get.at(i)->getPdgID()<<" ("<<get.at(i)->getBarcode()<<"), "; cout<<endl;
69  */
70  int index = HEPEVT_struct::set(this);
72  PHOTOS_MAKE_C(index);
76  }
77 
78  vector<PhotosParticle*> PhotosBranch::getParticles()
79  {
80  vector<PhotosParticle*> ret = mothers;
81  if (particle) ret.push_back(particle);
82  ret.insert(ret.end(), daughters.begin(), daughters.end());
83  return ret;
84  }
85 
87  {
89  if (mothers.size() > 0) return mothers.at(0)->checkMomentumConservation();
90  return true;
91  }
92 
93  vector<PhotosBranch*> PhotosBranch::createBranches(vector<PhotosParticle*> particles)
94  {
95  Log::Debug(700) << "PhotosBranch::createBranches - filtering started" << endl;
96  list<PhotosParticle*> list(particles.begin(), particles.end());
97  vector<PhotosBranch*> branches;
98 
99  // First - add all forced decays
100  if (Photos::forceBremList) {
101  std::list<PhotosParticle*>::iterator it;
102  for (it = list.begin(); it != list.end(); it++) {
103  PhotosBranch* branch = new PhotosBranch(*it);
104  int forcing_local = branch->getForcingStatus();
105  if (forcing_local) {
106  Log::Debug(701) << " Forced: " << (*it)->getPdgID() << " (barcode: " << (*it)->getBarcode() << ") with forcing status= "
107  << forcing_local
108  << endl;
109  branches.push_back(branch);
110  it = list.erase(it);
111  --it;
112  // If forcing consecutive decays
113  if (forcing_local == 2) {
114  PhotosParticle* p = branch->getDecayingParticle();
115  if (!p) {
116  if (branch->getMothers().size() > 0) p = branch->getMothers().at(0);
117  else continue;
118  }
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  for (int i = 0; i < (int)tree.size(); i++) {
124  if (tree.at(i)->getBarcode() == (*it2)->getBarcode()) {
125  PhotosBranch* b = new PhotosBranch(*it2);
126  branches.push_back(b);
127  // If we were to delete our next particle in line
128  if (it == it2) --it;
129  it2 = list.erase(it2);
130  --it2;
131  break;
132  }
133  }
134  }
135  }
136  } else delete branch;
137  }
138  }
139  // Quit if we're suppressing everything
140  if (Photos::isSuppressed) return branches;
141  // Now - check if remaining decays are suppressed
142  while (!list.empty()) {
143  PhotosParticle* particle_local = list.front();
144  list.pop_front();
145  if (!particle_local) continue;
146 
147  PhotosBranch* branch = new PhotosBranch(particle_local);
148  int suppression_local = branch->getSuppressionStatus();
149  if (!suppression_local) branches.push_back(branch);
150  else {
151  Log::Debug(702) << " Suppressed: " << particle_local->getPdgID() << " (barcode: " << particle_local->getBarcode() <<
152  ") with suppression status= " << suppression_local << endl;
153  //If suppressing consecutive decays
154  if (suppression_local == 2) {
155  PhotosParticle* p = branch->getDecayingParticle();
156  if (!p) {
157  if (branch->getMothers().size() > 0) p = branch->getMothers().at(0);
158  else continue;
159  }
160  vector<PhotosParticle*> tree = p->getDecayTree();
161  //Remove all particles from the list - max O(n*m)
162  std::list<PhotosParticle*>::iterator it;
163  for (it = list.begin(); it != list.end(); it++) {
164  for (int i = 0; i < (int)tree.size(); i++) {
165  if (tree.at(i)->getBarcode() == (*it)->getBarcode()) {
166  it = list.erase(it);
167  --it;
168  break;
169  }
170  }
171  }
172  }
173  delete branch;
174  continue;
175  }
176 
177  //In case we don't have mid-particle erase rest of the mothers from list
178  if (!branch->getDecayingParticle()) {
179  vector<PhotosParticle*> mothers_local = branch->getMothers();
180  for (int i = 0; i < (int)mothers_local.size(); i++) {
181  PhotosParticle* m = mothers_local.at(i);
182  if (m->getBarcode() == particle_local->getBarcode()) continue;
183  std::list<PhotosParticle*>::iterator it;
184  for (it = list.begin(); it != list.end(); it++)
185  if (m->getBarcode() == (*it)->getBarcode()) {
186  it = list.erase(it);
187  break;
188  }
189  }
190  }
191  }
192  return branches;
193  }
194 
195  int PhotosBranch::checkList(bool forceOrSuppress)
196  {
197  vector< vector<int>* >* list = (forceOrSuppress) ? Photos::forceBremList : Photos::supBremList;
198  if (!list) return 0;
199 
200  // Can't check without pdgid
201  int motherID;
202  if (particle) motherID = particle->getPdgID();
203  else {
204  if (mothers.size() == 0) return 0;
205  motherID = mothers.at(0)->getPdgID();
206  }
207 
208  // Create list of daughters
209  vector<int> dID;
210  for (int j = 0; j < (int)daughters.size(); j++) dID.push_back(daughters[j]->getPdgID());
211 
212  vector< vector<int> *>& patternList = *list;
213 
214  // Check if the mother and list of daughters matches any of the declared patterns
215  for (int j = 0; j < (int)patternList.size(); j++) {
216  // Skip patterns that don't have our mother
217  if (motherID != (*patternList[j])[0]) continue;
218 
219  // Compare decay daughters with pattern - max O(n*m)
220  vector<int>& pattern = *patternList[j];
221  bool fullMatch = true;
222  for (int k = 1; k < (int)pattern.size() - 1; k++) {
223  bool oneMatch = false;
224  for (int l = 0; l < (int)dID.size(); l++)
225  if (pattern[k] == dID[l]) { oneMatch = true; break; }
226  if (!oneMatch) { fullMatch = false; break; }
227  }
228  // Check if the matching pattern is set for consecutive suppression
229  /*
230  Currently minimal matching is used.
231  If e.g. 25 -> -15 is suppressed, then 25 -> 15,-15 and 25 -> 15,-15,22 etc. is suppressed too
232  For exact matching (then suppress 25 -> 15,-15 ; 25 -> 15,-15,22 etc. must be done separately) uncoment line ...:
233  */
234  // if(pattern.size()<=2 || (fullMatch && dID.size()==pattern.size()-2) )
235  // ...and comment out line:
236  if (pattern.size() <= 2 || fullMatch)
237  return (pattern.back() == 1) ? 2 : 1;
238  }
239  return 0;
240  }
241 
242 } // namespace Photospp
static void complete()
Finalize processing.
static void prepare()
Prepare particles for processing.
static void get()
Update event record with data from HEPEVT.
static int set(PhotosBranch *branch)
Convert PhotosBranch to HEPEVT.
static ostream & Debug(unsigned short int code=0, bool count=true)
Four logging entries.
Definition: Log.cc:32
static vector< PhotosBranch * > createBranches(vector< PhotosParticle * > particles)
Create branches from particles list.
Definition: PhotosBranch.cc:93
bool checkMomentumConservation()
Checks momentum conservation of decaying particle.
Definition: PhotosBranch.cc:86
void process()
Process single branch.
Definition: PhotosBranch.cc:61
PhotosParticle * getDecayingParticle()
Return decaying particle.
Definition: PhotosBranch.h:28
int checkSuppressionLevel()
Checks if branching is suppressed by PHOTOS.
Definition: PhotosBranch.h:56
int checkList(bool forceOrSuppress)
Algorithm used for suppression/forcing check.
int checkForcingLevel()
Checks if branching is forced by PHOTOS.
Definition: PhotosBranch.h:59
vector< PhotosParticle * > getMothers()
Get list of mothers.
Definition: PhotosBranch.h:31
vector< PhotosParticle * > daughters
List of daughters.
Definition: PhotosBranch.h:73
int getForcingStatus()
Check if branch is forced.
Definition: PhotosBranch.h:43
int getSuppressionStatus()
Check if branch is suppressed.
Definition: PhotosBranch.h:40
int forcing
State of branching forcing.
Definition: PhotosBranch.h:67
PhotosParticle * particle
Decaying particle.
Definition: PhotosBranch.h:69
vector< PhotosParticle * > getParticles()
Get list of all particles used by branch.
Definition: PhotosBranch.cc:78
vector< PhotosParticle * > mothers
List of mothers
Definition: PhotosBranch.h:71
int suppression
State of branching suppression.
Definition: PhotosBranch.h:65
PhotosBranch(PhotosParticle *p)
Create branch out of decaying particle.
Definition: PhotosBranch.cc:14
virtual bool checkMomentumConservation()=0
check that the 4 momentum in conserved at the vertices producing and ending this particle
virtual int getBarcode()=0
Get the barcode of this particle.
virtual int getPdgID()=0
Get the PDG ID code of this particle.
static vector< vector< int > * > * supBremList
List of suppressed decays.
Definition: Photos.h:189
static vector< vector< int > * > * forceBremList
List of forced decays.
Definition: Photos.h:192
static bool isSuppressed
Is in suppressed mode.
Definition: Photos.h:183