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