41 SelfAssemblingRecoFrame::SelfAssemblingRecoFrame(
const std::string& sname,
42 const std::string& stitle)
43 : DecayRecoFrame(sname,stitle)
45 m_RType = RDSelfAssembling;
46 m_IsAssembled =
false;
52 SelfAssemblingRecoFrame::~SelfAssemblingRecoFrame() {}
55 if(m_IsAssembled) Disassemble();
56 m_VisibleFrames.Clear();
57 m_DecayFrames.Clear();
61 bool SelfAssemblingRecoFrame::ResetRecoFrame(){
63 UnSoundMind(RF_FUNCTION);
64 return SetSpirit(
false);
66 if(m_IsAssembled) Disassemble();
72 m_ChildFrames_UnAssembled.Remove(frame);
76 void SelfAssemblingRecoFrame::Disassemble(){
82 lab_frame.RemoveTreeStates(m_VisibleStates);
85 m_ChildFrames_UnAssembled = ChildFrames;
87 AddChildFrames(m_ChildFrames_UnAssembled);
89 if(!InitializeTreeRecursive()){
91 m_Log <<
"Problem with recursive tree after disassembly";
98 if(!InitializeAnalysisRecursive()){
100 m_Log <<
"Problem connecting states after disassembly";
108 m_IsAssembled =
false;
111 void SelfAssemblingRecoFrame::Assemble(){
112 if(m_IsAssembled) Disassemble();
114 UnSoundMind(RF_FUNCTION);
119 m_VisibleStates.Clear();
121 std::vector<RestFrame*> frames;
123 std::vector<TLorentzVector> Ps;
126 m_ChildFrames_UnAssembled.Clear();
127 m_ChildFrames_UnAssembled += GetChildFrames();
129 int N = GetNChildren();
130 for(
int i = 0; i < N; i++){
132 bool expand_frame =
false;
133 if(GetChildStates(frame).GetN() == 1 && frame.IsVisibleFrame())
134 if(GetChildStates(frame)[0].IsCombinatoricState()){
136 VisibleStateList
const& elements =
137 static_cast<CombinatoricState&
>(GetChildStates(frame)[0]).GetElements();
138 int Nelement = elements.GetN();
139 for(
int e = 0; e < Nelement; e++){
140 VisibleState& element = elements[e];
141 VisibleRecoFrame& new_frame =
142 GetNewVisibleFrame(frame.GetName(),frame.GetTitle());
143 new_frame.SetCharge(element.GetCharge());
144 element.AddFrame(new_frame);
145 frames.push_back(&new_frame);
146 TLorentzVector V = element.GetFourVector();
147 if(V.M() < 0.) V.SetVectM(V.Vect(),0.);
149 m_VisibleStates += element;
152 expand_frame =
false;
156 TLorentzVector V = GetChildStates(frame).GetFourVector();
157 if(V.M() < 0.) V.SetVectM(V.Vect(),0.);
159 frames.push_back(&frame);
163 RestFrameList ChildFrames = m_ChildFrames_UnAssembled;
165 m_ChildFrames_UnAssembled = ChildFrames;
166 AssembleRecursive(*
this, frames, Ps);
167 if(!InitializeTreeRecursive()){
169 m_Log <<
"Problem with recursive tree after assembly";
176 const LabRecoFrame& lab_frame =
static_cast<const LabRecoFrame&
>(GetLabFrame());
177 lab_frame.AddTreeStates(m_VisibleStates);
178 if(!InitializeAnalysisRecursive()){
180 m_Log <<
"Problem connecting states after assembly";
186 m_IsAssembled =
true;
189 void SelfAssemblingRecoFrame::AssembleRecursive(RestFrame& frame,
190 std::vector<RestFrame*>& frames,
191 std::vector<TLorentzVector>& Ps){
192 int Ninput = frames.size();
194 for(
int i = 0; i < Ninput; i++) frame.AddChildFrame(*frames[i]);
198 TLorentzVector TOT(0.,0.,0.,0.);
199 for(
int i = 0; i < Ninput; i++) TOT += Ps[i];
200 TVector3 boost = TOT.BoostVector();
202 boost.SetMagThetaPhi(0.,boost.Theta(),boost.Phi());
203 for(
int i = 0; i < Ninput; i++){
205 Ps[i].SetVectM(Ps[i].Vect(),Ps[i].M());
211 for(
int i = 0; i < 2; i++) ip_max[i] = -1;
212 for(
int i = 0; i < 2; i++) jp_max[i] = -1;
213 double val_max = -1.;
216 for(ip[0] = 0; ip[0] < Ninput-1; ip[0]++){
217 for(ip[1] = ip[0]+1; ip[1] < Ninput; ip[1]++){
218 TVector3 nRef = Ps[ip[0]].Vect().Cross(Ps[ip[1]].Vect());
220 TLorentzVector hem[2];
221 for(
int i = 0; i < 2; i++){
223 hem[i].SetPxPyPzE(0.,0.,0.,0.);
226 for(
int i = 0; i < Ninput; i++){
227 if((i == ip[0]) || (i == ip[1]))
continue;
228 int ihem = int(Ps[i].Vect().Dot(nRef) > 0.);
233 for(jp[0] = 0; jp[0] < 2; jp[0]++){
234 for(jp[1] = 0; jp[1] < 2; jp[1]++){
235 if(jp[0] == jp[1] && Nhem[(jp[0]+1)%2] == 0)
continue;
236 TLorentzVector hem_probes[2];
237 for(
int i = 0; i < 2; i++) hem_probes[i] = hem[i];
238 for(
int i = 0; i < 2; i++) hem_probes[jp[i]] += Ps[ip[i]];
239 double val = hem_probes[0].P() + hem_probes[1].P();
242 for(
int i = 0; i < 2; i++) ip_max[i] = ip[i];
243 for(
int i = 0; i < 2; i++) jp_max[i] = jp[i];
250 std::vector<RestFrame*> child_frames[2];
251 std::vector<TLorentzVector> child_Ps[2];
252 TLorentzVector hem[2];
253 for(
int i = 0; i < 2; i++){
254 hem[i].SetPxPyPzE(0.,0.,0.,0.);
257 for(
int i = 0; i < 2; i++){
258 child_frames[jp_max[i]].push_back(frames[ip_max[i]]);
259 child_Ps[jp_max[i]].push_back(Ps[ip_max[i]]);
260 hem[jp_max[i]] += Ps[ip_max[i]];
263 TVector3 nRef = Ps[ip_max[0]].Vect().Cross(Ps[ip_max[1]].Vect());
264 for(
int i = 0; i < Ninput; i++){
265 if((i == ip_max[0]) || (i == ip_max[1]))
continue;
266 int ihem = int(Ps[i].Vect().Dot(nRef) > 0.);
267 child_frames[ihem].push_back(frames[i]);
268 child_Ps[ihem].push_back(Ps[i]);
272 int flip = int(hem[1].M() > hem[0].M());
273 for(
int i = 0; i < 2; i++){
275 if(child_frames[j].size() == 1){
276 frame.AddChildFrame(*child_frames[j][0]);
278 RestFrame& new_frame = GetNewDecayFrame(GetName(),GetTitle());
279 frame.AddChildFrame(new_frame);
280 AssembleRecursive(new_frame, child_frames[j], child_Ps[j]);
285 bool SelfAssemblingRecoFrame::ReconstructFrame(){
288 if(m_IsAssembled) Disassemble();
289 if(!AnalyzeEventRecursive()){
291 m_Log <<
"Unable to recursively analyze event with ";
292 m_Log <<
"disassembled SelfAssemblingRecoFrame" << LogEnd;
293 return SetSpirit(
false);
298 return ReconstructionFrame::ReconstructFrame();
301 void SelfAssemblingRecoFrame::ClearNewFrames(){
302 int N = m_DecayFrames.GetN();
303 for(
int i = 0; i < N; i++) m_DecayFrames[i].
Clear();
304 N = m_VisibleFrames.GetN();
305 for(
int i = 0; i < N; i++) m_VisibleFrames[i].
Clear();
308 DecayRecoFrame& SelfAssemblingRecoFrame::GetNewDecayFrame(
const std::string& sname,
309 const std::string& stitle){
310 if(m_Ndecay < m_DecayFrames.GetN()){
312 return m_DecayFrames.Get(m_Ndecay-1);
315 sprintf(strn,
"%d",m_Ndecay+1);
316 std::string name = sname+
"_"+std::string(strn);
317 std::string title =
"#left("+stitle+
"#right)_{"+std::string(strn)+
"}";
318 DecayRecoFrame* framePtr =
new DecayRecoFrame(name, title);
320 m_DecayFrames.Add(*framePtr);
321 AddDependent(framePtr);
326 VisibleRecoFrame& SelfAssemblingRecoFrame::GetNewVisibleFrame(
const std::string& sname,
327 const std::string& stitle){
328 if(m_Nvisible < m_VisibleFrames.GetN()){
330 return m_VisibleFrames.Get(m_Nvisible-1);
333 sprintf(strn,
"%d",m_Nvisible+1);
334 std::string name = sname+
"_"+std::string(strn);
335 std::string title =
"#left("+stitle+
"#right)_{"+std::string(strn)+
"}";
336 VisibleRecoFrame* framePtr =
new VisibleRecoFrame(name, title);
338 m_VisibleFrames.Add(*framePtr);
339 AddDependent(framePtr);
344 RestFrame
const& SelfAssemblingRecoFrame::GetFrame(
const RFKey& key)
const {
346 return RestFrame::Empty();
348 int N = GetNChildren();
349 for(
int i = 0; i < N; i++){
350 if(GetChildStates(i).Contains(key))
351 return GetChildStates(i).Get(key).GetListFrames()[0];
354 return RestFrame::Empty();
virtual void Clear()
Clears ReconstructionFrame of all connections to other objects.
virtual void Clear()
Clears ReconstructionFrame of all connections to other objects.
virtual void RemoveChildFrame(RestFrame &frame)
Remove a child of this frame.
abstract base class for all Frame objects
void RemoveChildFrame(RestFrame &frame)
Remove a child of this frame.
virtual ReconstructionFrame & GetChildFrame(int i=0) const
Get the frame of the i th child.
void RemoveChildFrames()
Remove all the children of this frame.