GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Kinematics.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2024, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Costas Andreopoulos <c.andreopoulos \at cern.ch>
7  University of Liverpool
8 */
9 //____________________________________________________________________________
10 
11 #include <TMath.h>
12 #include <TLorentzVector.h>
13 #include <TRootIOCtor.h>
14 
17 
18 using std::endl;
19 
20 using namespace genie;
21 
23 
24 //____________________________________________________________________________
25 namespace genie {
26  ostream & operator << (ostream & stream, const Kinematics & kinematics)
27  {
28  kinematics.Print(stream);
29  return stream;
30  }
31 }
32 //___________________________________________________________________________
34 TObject()
35 {
36  this->Init();
37 }
38 //____________________________________________________________________________
39 Kinematics::Kinematics(const Kinematics & kinematics) :
40 TObject()
41 {
42  this->Init();
43  this->Copy(kinematics);
44 }
45 //____________________________________________________________________________
46 Kinematics::Kinematics(TRootIOCtor*) :
47 TObject(),
48 fP4Fsl(0),
49 fP4HadSyst(0)
50 {
51 
52 }
53 //____________________________________________________________________________
55 {
56  this->CleanUp();
57 }
58 //____________________________________________________________________________
59 void Kinematics::Init(void)
60 {
61  fKV.clear();
62 
63  fP4Fsl = new TLorentzVector;
64  fP4HadSyst = new TLorentzVector;
65 }
66 //____________________________________________________________________________
68 {
69  fKV.clear();
70 
71  delete fP4Fsl;
72  delete fP4HadSyst;
73 }
74 //____________________________________________________________________________
76 {
77  fKV.clear();
78 
79  this->SetFSLeptonP4 (0,0,0,0);
80  this->SetHadSystP4 (0,0,0,0);
81 }
82 //____________________________________________________________________________
83 void Kinematics::Copy(const Kinematics & kinematics)
84 {
85  this->Reset();
86 
87  map<KineVar_t, double>::const_iterator iter;
88 
89  for(iter = kinematics.fKV.begin(); iter != kinematics.fKV.end(); ++iter) {
90  KineVar_t kv = iter->first;
91  double val = iter->second;
92  this->SetKV(kv,val);
93  }
94 
95  this->SetFSLeptonP4 (*kinematics.fP4Fsl);
96  this->SetHadSystP4 (*kinematics.fP4HadSyst);
97 }
98 //____________________________________________________________________________
99 double Kinematics::x(bool selected) const
100 {
101 // returns the running or selected value of Bjorken scaling variable x
102 
103  KineVar_t kvar = (selected) ? kKVSelx : kKVx;
104 
105  if(this->KVSet(kvar)) { return this->GetKV(kvar); }
106  else {
107  LOG("Interaction", pWARN) << "Kinematic variable x was not set";
108  }
109  return -99999;
110 }
111 //____________________________________________________________________________
112 double Kinematics::y(bool selected) const
113 {
114 // returns the running or selected value of inelasticity y
115 
116  KineVar_t kvar = (selected) ? kKVSely : kKVy;
117 
118  if(this->KVSet(kvar)) { return this->GetKV(kvar); }
119  else {
120  LOG("Interaction", pWARN) << "Kinematic variable y was not set";
121  }
122  return -99999;
123 }
124 //____________________________________________________________________________
125 double Kinematics::Q2(bool selected) const
126 {
127 // returns the running or selected value of momentum transfer Q2 (>0)
128 
129  if(selected) {
130  if (this->KVSet(kKVSelQ2) ) { return this->GetKV(kKVSelQ2); }
131  else if (this->KVSet(kKVSelq2) ) { return -1* this->GetKV(kKVSelq2); }
132  } else {
133  if (this->KVSet(kKVQ2) ) { return this->GetKV(kKVQ2); }
134  else if (this->KVSet(kKVq2) ) { return -1* this->GetKV(kKVq2); }
135  }
136 
137  LOG("Interaction", pWARN) << "Kinematic variable Q2 was not set";
138  return -99999;
139 }
140 //____________________________________________________________________________
141 double Kinematics::q2(bool selected) const
142 {
143 // returns the running or selected value of momentum transfer q2 (<0)
144 
145  if(selected) {
146  if (this->KVSet(kKVSelQ2) ) { return -1* this->GetKV(kKVSelQ2); }
147  else if (this->KVSet(kKVSelq2) ) { return this->GetKV(kKVSelq2); }
148  } else {
149  if (this->KVSet(kKVQ2) ) { return -1* this->GetKV(kKVQ2); }
150  else if (this->KVSet(kKVq2) ) { return this->GetKV(kKVq2); }
151  }
152 
153  LOG("Interaction", pWARN) << "Kinematic variable q2 was not set";
154  return -99999;
155 }
156 //____________________________________________________________________________
157 double Kinematics::W(bool selected) const
158 {
159 // returns the running or selected value of invariant hadronic mass W
160 
161  KineVar_t kvar = (selected) ? kKVSelW : kKVW;
162 
163  if(this->KVSet(kvar)) { return this->GetKV(kvar); }
164  else {
165  LOG("Interaction", pWARN) << "Kinematic variable W was not set";
166  }
167  return -99999;
168 }
169 //____________________________________________________________________________
170 double Kinematics::t(bool selected) const
171 {
172 // returns the running or selected value of invariant hadronic mass W
173 
174  KineVar_t kvar = (selected) ? kKVSelt : kKVt;
175 
176  if(this->KVSet(kvar)) { return this->GetKV(kvar); }
177  else {
178  LOG("Interaction", pWARN) << "Kinematic variable t was not set";
179  }
180  return -99999;
181 }
182 //____________________________________________________________________________
183 double Kinematics::Logx(bool selected) const
184 {
185  double xs = this->x(selected);
186  return (xs>0) ? TMath::Log(xs) : -99999;
187 }
188 //____________________________________________________________________________
189 double Kinematics::Logy(bool selected) const
190 {
191  double ys = this->y(selected);
192  return (ys>0) ? TMath::Log(ys) : -99999;
193 }
194 //____________________________________________________________________________
195 double Kinematics::LogQ2(bool selected) const
196 {
197  double Q2s = this->Q2(selected);
198  return (Q2s>0) ? TMath::Log(Q2s) : -99999;
199 }
200 //____________________________________________________________________________
201 double Kinematics::LogW(bool selected) const
202 {
203  double Ws = this->W(selected);
204  return (Ws>0) ? TMath::Log(Ws) : -99999;
205 }
206 //____________________________________________________________________________
207 double Kinematics::Log10x(bool selected) const
208 {
209  double xs = this->x(selected);
210  return (xs>0) ? TMath::Log10(xs) : -99999;
211 }
212 //____________________________________________________________________________
213 double Kinematics::Log10y(bool selected) const
214 {
215  double ys = this->y(selected);
216  return (ys>0) ? TMath::Log10(ys) : -99999;
217 }
218 //____________________________________________________________________________
219 double Kinematics::Log10Q2(bool selected) const
220 {
221  double Q2s = this->Q2(selected);
222  return (Q2s>0) ? TMath::Log10(Q2s) : -99999;
223 }
224 //____________________________________________________________________________
225 double Kinematics::Log10W(bool selected) const
226 {
227  double Ws = this->W(selected);
228  return (Ws>0) ? TMath::Log10(Ws) : -99999;
229 }
230 //____________________________________________________________________________
231 void Kinematics::Setx(double xbj, bool selected)
232 {
233 // sets the running or selected value of Bjorken scaling variable x
234 
235  if(xbj<0 || xbj>1) {
236  LOG("Interaction", pWARN)
237  << "Setting unphysical value for x (x = " << xbj << ")";
238  }
239  KineVar_t kvar = (selected) ? kKVSelx : kKVx;
240  this->SetKV(kvar, xbj);
241 }
242 //____________________________________________________________________________
243 void Kinematics::Sety(double inel_y, bool selected)
244 {
245 // sets the running or selected value of inelasticity y
246 
247  if(inel_y<0 || inel_y>1) {
248  LOG("Interaction", pWARN)
249  << "Setting unphysical value for y (y = " << inel_y << ")";
250  }
251  KineVar_t kvar = (selected) ? kKVSely : kKVy;
252  this->SetKV(kvar, inel_y);
253 }
254 //____________________________________________________________________________
255 void Kinematics::SetQ2(double Qsqrd, bool selected)
256 {
257 // sets the running or selected value of momentum transfer Q2 (>0)
258 
259  if(Qsqrd<0) {
260  LOG("Interaction", pWARN)
261  << "Setting unphysical value for Q2 (Q2 = " << Qsqrd << ")";
262  }
263  KineVar_t kvar = (selected) ? kKVSelQ2 : kKVQ2;
264  this->SetKV(kvar, Qsqrd);
265 }
266 //____________________________________________________________________________
267 void Kinematics::Setq2(double qsqrd, bool selected)
268 {
269 // sets the running or selected value of momentum transfer q2 (<0)
270 
271  if(qsqrd>0) {
272  LOG("Interaction", pWARN)
273  << "Setting unphysical value for q2 (q2 = " << qsqrd << ")";
274  }
275  KineVar_t kvar = (selected) ? kKVSelq2 : kKVq2;
276  this->SetKV(kvar, qsqrd);
277 }
278 //____________________________________________________________________________
279 void Kinematics::SetW(double hadr_mass_W, bool selected)
280 {
281 // sets the running or selected value of invariant hadronic mass W
282 
283  if(hadr_mass_W<0) {
284  LOG("Interaction", pWARN)
285  << "Setting unphysical value for W (W = " << hadr_mass_W << ")";
286  }
287  KineVar_t kvar = (selected) ? kKVSelW : kKVW;
288  this->SetKV(kvar, hadr_mass_W);
289 }
290 //____________________________________________________________________________
291 void Kinematics::Sett(double tval, bool selected)
292 {
293  KineVar_t kvar = (selected) ? kKVSelt : kKVt;
294  this->SetKV(kvar, tval);
295 }
296 //____________________________________________________________________________
297 void Kinematics::SetFSLeptonP4(const TLorentzVector & p4)
298 {
299  fP4Fsl->SetPxPyPzE(p4.Px(), p4.Py(), p4.Pz(), p4.E());
300 }
301 //____________________________________________________________________________
302 void Kinematics::SetFSLeptonP4(double px, double py, double pz, double E)
303 {
304  fP4Fsl->SetPxPyPzE(px,py,pz,E);
305 }
306 //____________________________________________________________________________
307 void Kinematics::SetHadSystP4(const TLorentzVector & p4)
308 {
309  fP4HadSyst->SetPxPyPzE(p4.Px(), p4.Py(), p4.Pz(), p4.E());
310 }
311 //____________________________________________________________________________
312 void Kinematics::SetHadSystP4(double px, double py, double pz, double E)
313 {
314  fP4HadSyst->SetPxPyPzE(px,py,pz,E);
315 }
316 //____________________________________________________________________________
318 {
319  if(fKV.count(kv) == 1) return true;
320  else return false;
321 }
322 //____________________________________________________________________________
323 double Kinematics::GetKV(KineVar_t kv) const
324 {
325  if(this->KVSet(kv)) {
326  map<KineVar_t, double>::const_iterator iter = fKV.find(kv);
327  return iter->second;
328  } else {
329  LOG("Interaction", pWARN)
330  << "Kinematic variable: " << KineVar::AsString(kv) << " was not set";
331  }
332  return -99999;
333 }
334 //____________________________________________________________________________
335 void Kinematics::SetKV(KineVar_t kv, double value)
336 {
337  LOG("Interaction", pDEBUG)
338  << "Setting " << KineVar::AsString(kv) << " to " << value;
339 
340  if(this->KVSet(kv)) {
341  fKV[kv] = value;
342  } else {
343  fKV.insert( map<KineVar_t, double>::value_type(kv,value) );
344  }
345 }
346 //____________________________________________________________________________
348 {
349 // clear the running values (leave the selected ones)
350 //
351  fKV.erase( kKVx );
352  fKV.erase( kKVy );
353  fKV.erase( kKVQ2 );
354  fKV.erase( kKVq2 );
355  fKV.erase( kKVW );
356  fKV.erase( kKVt );
357 }
358 //____________________________________________________________________________
360 {
361 // copy the selected kinematics into the running ones
362 //
363  map<KineVar_t, double>::const_iterator iter;
364  iter = fKV.find(kKVSelx);
365  if(iter != fKV.end()) this->Setx(iter->second);
366  iter = fKV.find(kKVSely);
367  if(iter != fKV.end()) this->Sety(iter->second);
368  iter = fKV.find(kKVSelQ2);
369  if(iter != fKV.end()) this->SetQ2(iter->second);
370  iter = fKV.find(kKVSelq2);
371  if(iter != fKV.end()) this->Setq2(iter->second);
372  iter = fKV.find(kKVSelW);
373  if(iter != fKV.end()) this->SetW(iter->second);
374  iter = fKV.find(kKVSelt);
375  if(iter != fKV.end()) this->Sett(iter->second);
376 }
377 //____________________________________________________________________________
378 void Kinematics::Print(ostream & stream) const
379 {
380  stream << "[-] [Kinematics]" << endl;
381 
382  map<KineVar_t, double>::const_iterator iter;
383 
384  for(iter = fKV.begin(); iter != fKV.end(); ++iter) {
385  KineVar_t kv = iter->first;
386  double val = iter->second;
387  stream << " |--> " << KineVar::AsString(kv) << " = " << val << endl;
388  }
389 }
390 //____________________________________________________________________________
392 {
393  this->Copy(kinematics);
394  return (*this);
395 }
396 //___________________________________________________________________________
Kinematics & operator=(const Kinematics &kine)
Definition: Kinematics.cxx:391
TLorentzVector * fP4HadSyst
generated final state hadronic system 4-p (LAB)
Definition: Kinematics.h:104
double W(bool selected=false) const
Definition: Kinematics.cxx:157
double Log10y(bool selected=false) const
Definition: Kinematics.cxx:213
void Reset(void)
Definition: Kinematics.cxx:75
void SetQ2(double Q2, bool selected=false)
Definition: Kinematics.cxx:255
void Setq2(double q2, bool selected=false)
Definition: Kinematics.cxx:267
Generated/set kinematical variables for an event.
Definition: Kinematics.h:39
double x(bool selected=false) const
Definition: Kinematics.cxx:99
double Logx(bool selected=false) const
Definition: Kinematics.cxx:183
double y(bool selected=false) const
Definition: Kinematics.cxx:112
void UseSelectedKinematics(void)
Definition: Kinematics.cxx:359
double Logy(bool selected=false) const
Definition: Kinematics.cxx:189
double q2(bool selected=false) const
Definition: Kinematics.cxx:141
double LogQ2(bool selected=false) const
Definition: Kinematics.cxx:195
double Log10x(bool selected=false) const
Definition: Kinematics.cxx:207
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
bool KVSet(KineVar_t kv) const
Definition: Kinematics.cxx:317
void SetFSLeptonP4(const TLorentzVector &p4)
Definition: Kinematics.cxx:297
void Copy(const Kinematics &kine)
Definition: Kinematics.cxx:83
void Sett(double t, bool selected=false)
Definition: Kinematics.cxx:291
double GetKV(KineVar_t kv) const
Definition: Kinematics.cxx:323
void Init(void)
initialize
Definition: Kinematics.cxx:59
map< KineVar_t, double > fKV
selected kinematics
Definition: Kinematics.h:102
#define pWARN
Definition: Messenger.h:60
double Log10Q2(bool selected=false) const
Definition: Kinematics.cxx:219
enum genie::EKineVar KineVar_t
void Setx(double x, bool selected=false)
Definition: Kinematics.cxx:231
void SetKV(KineVar_t kv, double value)
Definition: Kinematics.cxx:335
void SetW(double W, bool selected=false)
Definition: Kinematics.cxx:279
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
void Sety(double y, bool selected=false)
Definition: Kinematics.cxx:243
static string AsString(KineVar_t kv)
Definition: KineVar.h:77
ClassImp(CacheBranchFx)
void SetHadSystP4(const TLorentzVector &p4)
Definition: Kinematics.cxx:307
double t(bool selected=false) const
Definition: Kinematics.cxx:170
TLorentzVector * fP4Fsl
generated final state primary lepton 4-p (LAB)
Definition: Kinematics.h:103
double Q2(bool selected=false) const
Definition: Kinematics.cxx:125
void ClearRunningValues(void)
Definition: Kinematics.cxx:347
double Log10W(bool selected=false) const
Definition: Kinematics.cxx:225
static constexpr double ys
Definition: Units.h:103
double LogW(bool selected=false) const
Definition: Kinematics.cxx:201
void CleanUp(void)
clean-up
Definition: Kinematics.cxx:67
#define pDEBUG
Definition: Messenger.h:63
void Print(ostream &stream) const
Definition: Kinematics.cxx:378