LOGO

RestFrames  v1.0.1
RestFrames HEP Event Analysis Software Library
MinMassesCombJigsaw.cc
Go to the documentation of this file.
1 // RestFrames: particle physics event analysis library
3 // --------------------------------------------------------------------
4 // Copyright (c) 2014-2016, Christopher Rogan
14 // This file is part of RestFrames.
15 //
16 // RestFrames is free software; you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation; either version 2 of the License, or
19 // (at your option) any later version.
20 //
21 // RestFrames is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with RestFrames. If not, see <http://www.gnu.org/licenses/>.
29 
30 #include "RestFrames/RestFrame.hh"
32 
33 namespace RestFrames {
34 
36  // MinMassesCombJigsaw class methods
38  MinMassesCombJigsaw::MinMassesCombJigsaw(const std::string& sname,
39  const std::string& stitle) :
40  CombinatoricJigsaw(sname, stitle, 2, 2) {}
41 
43 
44  MinMassesCombJigsaw::~MinMassesCombJigsaw() {}
45 
47  return MinMassesCombJigsaw::m_Empty;
48  }
49 
50  void MinMassesCombJigsaw::AddFrame(const RestFrame& frame, int i){
51  if(!frame) return;
52  if(!GetGroup()) return;
53 
54  ConstRestFrameList frames =
55  frame.GetListVisibleFrames()+
56  frame.GetListInvisibleFrames();
57  int N = frames.GetN();
58  for(int f = 0; f < N; f++){
59  if(GetGroup().ContainsFrame(frames[f]))
60  AddChildFrame(frames[f], i);
61  AddDependancyFrame(frames[f], i);
62  }
63  }
64 
66  int N = frames.GetN();
67  for(int f = 0; f < N; f++)
68  AddFrame(frames[f],i);
69  }
70 
71  bool MinMassesCombJigsaw::AnalyzeEvent(){
72  if(!IsSoundMind() || !GetGroup())
73  return SetSpirit(false);
74 
75  if(!InitializeCombinatoric()){
76  m_Log << LogWarning;
77  m_Log << "Problem initializing event info" << LogEnd;
78  return SetSpirit(false);
79  }
80 
81  int Ninput = GetNInputStates();
82 
83  bool DO_N3 = (Ninput >= 2) &&
86  if(DO_N3){
87  DO_N3 =
88  (GetNinputForChild(0) <= 1) &&
89  (GetNinputForChild(1) <= 1) &&
90  !IsNinputExclForChild(0) &&
91  !IsNinputExclForChild(1) &&
92  !IsChargeSetForChild(0) &&
93  !IsChargeSetForChild(1) &&
94  !IsChargeSetForObject(0) &&
95  !IsChargeSetForObject(1);
96  }
97  if(!DO_N3){
98  if(!CombinatoricJigsaw::LoopCombinatoric()){
99  m_Log << LogWarning;
100  m_Log << "Problem looping over combinatorics" << LogEnd;
101  return SetSpirit(false);
102  }
103  return SetSpirit(true);
104  }
105 
106  // DO N^3 calculation
107  std::vector<TLorentzVector> inputs;
108  for(int i = 0; i < Ninput; i++){
109  inputs.push_back(GetInputState(i).GetFourVector());
110  if(inputs[i].M() < 0.) inputs[i].SetVectM(inputs[i].Vect(),0.);
111  }
112 
113  // boost input vectors to CM frame
114  TLorentzVector TOT(0.,0.,0.,0.);
115 
116  if(IsTransverse()){
117  for(int i = 0; i < Ninput; i++){
118  TVector3 p = inputs[i].Vect();
119  p = p - p.Dot(GetTransverseAxis())*GetTransverseAxis();
120  inputs[i].SetVectM(p, inputs[i].M());
121  }
122  }
123 
124  for(int i = 0; i < Ninput; i++) TOT += inputs[i];
125  TVector3 boost = TOT.BoostVector();
126  if(boost.Mag() >= 1.)
127  boost = (1.-1.e-8)/boost.Mag()*boost;
128  for(int i = 0; i < Ninput; i++) inputs[i].Boost(-boost);
129 
130  int ip_max[2];
131  int jp_max[2];
132  for(int i = 0; i < 2; i++) ip_max[i] = -1;
133  for(int i = 0; i < 2; i++) jp_max[i] = -1;
134  double metric_max = -1.;
135  // Loop over all 2-jet seed probes
136  int ip[2], jp[2];
137  for(ip[0] = 0; ip[0] < Ninput-1; ip[0]++){
138  for(ip[1] = ip[0]+1; ip[1] < Ninput; ip[1]++){
139  TVector3 nRef = inputs[ip[0]].Vect().Cross(inputs[ip[1]].Vect());
140  int Nhem[2];
141  TLorentzVector hem[2];
142  for(int i = 0; i < 2; i++){
143  Nhem[i] = 0;
144  hem[i].SetPxPyPzE(0.,0.,0.,0.);
145  }
146  // Loop over all jets
147  for(int i = 0; i < Ninput; i++){
148  if((i == ip[0]) || (i ==ip[1])) continue;
149  int ihem = int(inputs[i].Vect().Dot(nRef) > 0.);
150  Nhem[ihem]++;
151  hem[ihem] += inputs[i];
152  }
153  // assign 2 probes
154  for(jp[0] = 0; jp[0] < 2; jp[0]++){
155  for(jp[1] = 0; jp[1] < 2; jp[1]++){
156  if(jp[0] == jp[1] && Nhem[!jp[0]] == 0) continue;
157  TLorentzVector hem_probes[2];
158  for(int i = 0; i < 2; i++) hem_probes[i] = hem[i];
159  for(int i = 0; i < 2; i++) hem_probes[jp[i]] += inputs[ip[i]];
160  double metric = hem_probes[0].P() + hem_probes[1].P();
161  if(metric > metric_max){
162  metric_max = metric;
163  for(int i = 0; i < 2; i++) ip_max[i] = ip[i];
164  for(int i = 0; i < 2; i++) jp_max[i] = jp[i];
165  }
166  }
167  }
168  }
169  }
170  if(metric_max < 0){
171  return false;
172  }
173 
174  // initialize output states
175  for(int i = 0; i < 2; i++) GetChildState(i).ClearElements();
176  for(int i = 0; i < 2; i++){
177  GetChildState(jp_max[i]).AddElement(GetInputState(ip_max[i]));
178  }
179  TVector3 nRef = inputs[ip_max[0]].Vect().Cross(inputs[ip_max[1]].Vect());
180  for(int i = 0; i < Ninput; i++){
181  if((i == ip_max[0]) || (i == ip_max[1])) continue;
182  int ihem = int(inputs[i].Vect().Dot(nRef) > 0.);
183  GetChildState(ihem).AddElement(GetInputState(i));
184  }
185  if(GetChildState(1).GetFourVector().M() > GetChildState(1).GetFourVector().M()){
186  std::vector<VisibleStateList> flip;
187  for(int i = 0; i < 2; i++) flip.push_back(GetChildState(i).GetElements());
188  for(int i = 0; i < 2; i++) GetChildState(i).ClearElements();
189  for(int i = 0; i < 2; i++) GetChildState(i).AddElements(flip[(i+1)%2]);
190  }
191 
192  ExecuteDependancyJigsaws();
193 
194  return SetSpirit(true);
195  }
196 
197  bool MinMassesCombJigsaw::EvaluateMetric(double& metric) const {
198 
199  TLorentzVector P1, P2;
200  if(!IsTransverse()){
201  P1 = GetDependancyStates(0).GetFourVector();
202  P2 = GetDependancyStates(1).GetFourVector();
203  } else { // set transverse
204  int N1 = GetDependancyStates(0).GetN();
205  for(int i = 0; i < N1; i++){
206  TLorentzVector v = GetDependancyStates(0)[i].GetFourVector();
207  TVector3 p = v.Vect() - v.Vect().Dot(GetTransverseAxis())*GetTransverseAxis();
208  v.SetVectM(p, v.M());
209  P1 += v;
210  }
211  int N2 = GetDependancyStates(1).GetN();
212  for(int i = 0; i < N2; i++){
213  TLorentzVector v = GetDependancyStates(1)[i].GetFourVector();
214  TVector3 p = v.Vect() - v.Vect().Dot(GetTransverseAxis())*GetTransverseAxis();
215  v.SetVectM(p, v.M());
216  P2 += v;
217  }
218  }
219 
220  double P = GetP((P1+P2).M(), P1.M(), P2.M());
221  if(P <= 0)
222  metric = -1.;
223  else
224  metric = 1./P;
225 
226  return true;
227  }
228 
229  MinMassesCombJigsaw MinMassesCombJigsaw::m_Empty;
230 
231 }
232 
RestFrames::RestFrame::GetListInvisibleFrames
virtual RestFrameList GetListInvisibleFrames() const
Returns a list of InvisibleFrame s inheriting from this.
Definition: RestFrame.cc:348
MinMassesCombJigsaw.hh
RestFrames::Jigsaw::GetDependancyFrames
virtual ConstRestFrameList const & GetDependancyFrames(int i) const
Returns list of frames in which this jigsaw depends on.
Definition: Jigsaw.cc:214
RestFrames::RestFrame
abstract base class for all Frame objects
Definition: RestFrame.hh:45
RestFrames::CombinatoricState::AddElement
void AddElement(VisibleState &state)
Adds element to this state.
Definition: CombinatoricState.cc:87
RestFrames::RFList< const RestFrame >
RestFrames::Jigsaw::GetChildFrames
virtual ConstRestFrameList const & GetChildFrames(int i) const
Returns list of child frames associated with this jigsaw.
Definition: Jigsaw.cc:208
RestFrames::CombinatoricState::AddElements
void AddElements(const VisibleStateList &states)
Adds elements to this state.
Definition: CombinatoricState.cc:92
RestFrames::CombinatoricState::ClearElements
void ClearElements()
Clears all elements associated with this state.
Definition: CombinatoricState.cc:83
RestFrames::MinMassesCombJigsaw
Definition: MinMassesCombJigsaw.hh:40
RestFrames::CombinatoricJigsaw::GetGroup
virtual CombinatoricGroup & GetGroup() const
Returns group (Group) associated with this jigsaw.
Definition: CombinatoricJigsaw.cc:67
RestFrames::MinMassesCombJigsaw::MinMassesCombJigsaw
MinMassesCombJigsaw()
Empty constructor.
Definition: MinMassesCombJigsaw.cc:42
RestFrames::RestFrame::GetListVisibleFrames
virtual RestFrameList GetListVisibleFrames() const
Returns a list of VisibleFrame s inheriting from this.
Definition: RestFrame.cc:344
RestFrames::CombinatoricJigsaw
Definition: CombinatoricJigsaw.hh:40
RestFrames::MinMassesCombJigsaw::Empty
static MinMassesCombJigsaw & Empty()
Returns empty MinMassesCombJigsaw.
Definition: MinMassesCombJigsaw.cc:46
RestFrames::MinMassesCombJigsaw::AddFrame
virtual void AddFrame(const RestFrame &frame, int i=0)
Adds frame to current jigsaw.
Definition: MinMassesCombJigsaw.cc:50
RestFrames::MinMassesCombJigsaw::AddFrames
virtual void AddFrames(const ConstRestFrameList &frames, int i=0)
Adds a list of frames to current jigsaw.
Definition: MinMassesCombJigsaw.cc:65
RestFrame.hh