3 #include "PH_HEPEVT_Interface.h"
4 #include "PhotosParticle.h"
5 #include "PhotosBranch.h"
15 PhotosBranch::PhotosBranch(PhotosParticle* p)
17 daughters = p->getDaughters();
19 //Suppress if somehow got stable particle
20 if(daughters.size()==0)
22 Log::Debug(1)<<"Stable particle."<<endl;
28 else if(daughters.at(0)->getMothers().size()==1)
30 // Regular case - one mother
31 Log::Debug(1)<<"Regular case."<<endl;
33 mothers = p->findProductionMothers();
37 // Advanced case - branch with multiple mothers - no mid-particle
38 Log::Debug(1)<<"Advanced case."<<endl;
40 mothers = daughters.at(0)->getMothers();
43 //--------------------------------------------------
44 // Finalize suppression/forcing checks
45 // NOTE: if user forces decay of specific particle,
46 // this overrides any suppresion
47 //--------------------------------------------------
49 forcing = checkForcingLevel();
50 if(!forcing) suppression = checkSuppressionLevel();
53 // Even if forced or passed suppression check, we still have to check few things
56 // Check momentum conservation
57 suppression=!checkMomentumConservation();
58 if(suppression) Log::Warning()<<"Branching ignored due to 4-momentum non conservation"<<endl;
60 // Check if advanced case has only one daughter
61 if(!particle && daughters.size()==1) suppression=-1;
63 // If any of special cases is true, we're not forcing this branch
64 if(suppression) forcing=0;
68 void PhotosBranch::process()
70 Log::Debug(703)<<" Processing barcode: "<<( (particle) ? particle->getBarcode() : ( (mothers.size()) ? mothers.at(0)->getBarcode() : -1) )<<endl;
72 cout<<"Particles send to photos (with barcodes in brackets):"<<endl;
73 vector<PhotosParticle *> get = getParticles();
74 for(int i=0;i<(int)get.size();i++) cout<<"ID: "<<get.at(i)->getPdgID()<<" ("<<get.at(i)->getBarcode()<<"), "; cout<<endl;
76 int index = PH_HEPEVT_Interface::set(this);
77 PH_HEPEVT_Interface::prepare();
79 PH_HEPEVT_Interface::complete();
80 PH_HEPEVT_Interface::get();
81 checkMomentumConservation();
84 vector<PhotosParticle *> PhotosBranch::getParticles()
86 vector<PhotosParticle *> ret = mothers;
87 if(particle) ret.push_back(particle);
88 ret.insert(ret.end(),daughters.begin(),daughters.end());
92 bool PhotosBranch::checkMomentumConservation()
94 if(particle) return particle->checkMomentumConservation();
95 if(mothers.size()>0) return mothers.at(0)->checkMomentumConservation();
99 vector<PhotosBranch *> PhotosBranch::createBranches(vector<PhotosParticle *> particles)
101 Log::Debug(700)<<"PhotosBranch::createBranches - filtering started"<<endl;
102 list<PhotosParticle *> list(particles.begin(),particles.end());
103 vector<PhotosBranch *> branches;
105 // First - add all forced decays
106 if(Photos::forceBremList)
108 std::list<PhotosParticle *>::iterator it;
109 for(it=list.begin();it!=list.end();it++)
111 PhotosBranch *branch = new PhotosBranch(*it);
112 int forcing = branch->getForcingStatus();
115 Log::Debug(701)<<" Forced: "<<(*it)->getPdgID()<<" (barcode: "<<(*it)->getBarcode()<<") with forcing status= "<<forcing<<endl;
116 branches.push_back(branch);
119 // If forcing consecutive decays
122 PhotosParticle *p = branch->getDecayingParticle();
125 if(branch->getMothers().size()>0) p = branch->getMothers().at(0);
128 vector<PhotosParticle *> tree = p->getDecayTree();
129 //Add branches for all particles from the list - max O(n*m)
130 std::list<PhotosParticle *>::iterator it2;
131 for(it2=list.begin();it2!=list.end();it2++)
133 for(int i=0;i<(int)tree.size();i++)
135 if(tree.at(i)->getBarcode()==(*it2)->getBarcode())
137 PhotosBranch *b = new PhotosBranch(*it2);
138 branches.push_back(b);
139 // If we were to delete our next particle in line
141 it2 = list.erase(it2);
152 // Quit if we're suppressing everything
153 if(Photos::isSuppressed) return branches;
154 // Now - check if remaining decays are suppressed
157 PhotosParticle *particle = list.front();
159 if(!particle) continue;
161 PhotosBranch *branch = new PhotosBranch(particle);
162 int suppression = branch->getSuppressionStatus();
163 if(!suppression) branches.push_back(branch);
166 Log::Debug(702)<<" Suppressed: "<<particle->getPdgID()<<" (barcode: "<<particle->getBarcode()<<") with suppression status= "<<suppression<<endl;
167 //If suppressing consecutive decays
170 PhotosParticle *p = branch->getDecayingParticle();
173 if(branch->getMothers().size()>0) p = branch->getMothers().at(0);
176 vector<PhotosParticle *> tree = p->getDecayTree();
177 //Remove all particles from the list - max O(n*m)
178 std::list<PhotosParticle *>::iterator it;
179 for(it=list.begin();it!=list.end();it++)
181 for(int i=0;i<(int)tree.size();i++)
183 if(tree.at(i)->getBarcode()==(*it)->getBarcode())
196 //In case we don't have mid-particle erase rest of the mothers from list
197 if(!branch->getDecayingParticle())
199 vector<PhotosParticle *> mothers = branch->getMothers();
200 for(int i=0;i<(int)mothers.size();i++)
202 PhotosParticle *m = mothers.at(i);
203 if(m->getBarcode()==particle->getBarcode()) continue;
204 std::list<PhotosParticle *>::iterator it;
205 for(it=list.begin();it!=list.end();it++)
206 if(m->getBarcode()==(*it)->getBarcode())
217 int PhotosBranch::checkList(bool forceOrSuppress)
219 vector< vector<int>* > *list = (forceOrSuppress) ? Photos::forceBremList : Photos::supBremList;
222 // Can't check without pdgid
224 if(particle) motherID = particle->getPdgID();
227 if(mothers.size()==0) return 0;
228 motherID = mothers.at(0)->getPdgID();
231 // Create list of daughters
233 for(int j=0;j<(int)daughters.size();j++) dID.push_back(daughters[j]->getPdgID());
235 vector< vector<int> *> &patternList = *list;
237 // Check if the mother and list of daughters matches any of the declared patterns
238 for(int j=0; j<(int)patternList.size();j++)
240 // Skip patterns that don't have our mother
241 if(motherID!=(*patternList[j])[0]) continue;
243 // Compare decay daughters with pattern - max O(n*m)
244 vector<int> &pattern = *patternList[j];
246 for(int k = 1; k<(int)pattern.size()-1; k++)
249 for(int l=0;l<(int)dID.size(); l++)
250 if(pattern[k]==dID[l]) { oneMatch=true; break; }
251 if(!oneMatch) { fullMatch=false; break; }
253 // Check if the matching pattern is set for consecutive suppression
255 Currently minimal matching is used.
256 If e.g. 25 -> -15 is suppressed, then 25 -> 15,-15 and 25 -> 15,-15,22 etc. is suppressed too
257 For exact matching (then suppress 25 -> 15,-15 ; 25 -> 15,-15,22 etc. must be done separately) uncoment line ...:
259 // if(pattern.size()<=2 || (fullMatch && dID.size()==pattern.size()-2) )
260 // ...and comment out line:
261 if(pattern.size()<=2 || fullMatch)
262 return (pattern.back()==1) ? 2 : 1;
267 } // namespace Photospp