Target.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  @ Oct 09, 2007 - CA
14  Hit nucleon not auto-set for hit nucleon targets
15  @ May 05, 2010 - CR
16  Adding special ctor for ROOT I/O purposes so as to avoid memory leak due to
17  memory allocated in the default ctor when objects of this class are read by
18  the ROOT Streamer.
19  @ Nov 28, 2011 - CA
20  Now a nucleon-cluster ID is an accepted option for SetHitNucPdg().
21  @ Mar 18, 2016 - JJ (SD)
22  Added methods to store and retrieve the struck nucleon position. Position
23  is stored as a double, indicating the distance from the center of the
24  nucleus.
25 */
26 //____________________________________________________________________________
27 
28 #include <sstream>
29 
30 #include <TParticlePDG.h>
31 #include <TRootIOCtor.h>
32 
40 
41 using std::endl;
42 using std::ostringstream;
43 
44 using namespace genie;
45 using namespace genie::constants;
46 
48 
49 //____________________________________________________________________________
51  ostream & operator << (ostream & stream, const Target & target)
52  {
53  target.Print(stream);
54  return stream;
55  }
56 }
57 //___________________________________________________________________________
59 TObject()
60 {
61  this->Init();
62 }
63 //___________________________________________________________________________
64 Target::Target(int pdgc) :
65 TObject()
66 {
67  this->Init();
68  this->SetId(pdgc);
69 }
70 //___________________________________________________________________________
71 Target::Target(int ZZ, int AA) :
72 TObject()
73 {
74  this->Init();
75  this->SetId(ZZ,AA);
76 }
77 //___________________________________________________________________________
78 Target::Target(int ZZ, int AA, int hit_nucleon_pdgc) :
79 TObject()
80 {
81  this->Init();
82  this->SetId(ZZ,AA);
83  this->SetHitNucPdg(hit_nucleon_pdgc);
84 }
85 //___________________________________________________________________________
86 Target::Target(const Target & tgt) :
87 TObject()
88 {
89  this->Init();
90  this->Copy(tgt);
91 }
92 //___________________________________________________________________________
93 Target::Target(TRootIOCtor*) :
94 TObject(),
95 fZ(0),
96 fA(0),
97 fTgtPDG(0),
98 fHitNucPDG(0),
99 fHitSeaQrk(false),
100 fHitNucP4(0)
101 {
102 
103 }
104 //___________________________________________________________________________
106 {
107  this->CleanUp();
108 }
109 //___________________________________________________________________________
110 void Target::Reset(void)
111 {
112  this->CleanUp();
113  this->Init();
114 }
115 //___________________________________________________________________________
116 void Target::Init(void)
117 {
118  fZ = 0;
119  fA = 0;
120  fTgtPDG = 0;
121  fHitNucPDG = 0;
122  fHitQrkPDG = 0;
123  fHitSeaQrk = false;
124  fHitNucP4 = new TLorentzVector(0,0,0,kNucleonMass);
125  fHitNucRad = 0.;
126 }
127 //___________________________________________________________________________
128 void Target::CleanUp(void)
129 {
130  delete fHitNucP4;
131 }
132 //___________________________________________________________________________
133 void Target::Copy(const Target & tgt)
134 {
135  fTgtPDG = tgt.fTgtPDG;
136 
137  if( pdg::IsIon(fTgtPDG) ) {
138 
139  fZ = tgt.fZ; // copy A,Z
140  fA = tgt.fA;
141  fHitNucPDG = tgt.fHitNucPDG; // struck nucleon PDG
142  fHitQrkPDG = tgt.fHitQrkPDG; // struck quark PDG
143  fHitSeaQrk = tgt.fHitSeaQrk; // struck quark is from sea?
144 
145  //// valgrind warns about this ... try something else
146  // (*fHitNucP4) = (*tgt.fHitNucP4);
147  const TLorentzVector& p4 = *(tgt.fHitNucP4);
148  // *fHitNucP4 = p4; // nope
149  //// this works for valgrind
150  fHitNucP4->SetX(p4.X());
151  fHitNucP4->SetY(p4.Y());
152  fHitNucP4->SetZ(p4.Z());
153  fHitNucP4->SetT(p4.T());
154 
155  fHitNucRad = tgt.fHitNucRad;
156 
157  // look-up the nucleus in the isotopes chart
158  this->ForceNucleusValidity();
159 
160  // make sure the hit nucleus constituent object is either
161  // a nucleon (p or n) or a di-nucleon cluster (p+p, p+n, n+n)
162  this->ForceHitNucValidity();
163  }
164 }
165 //___________________________________________________________________________
166 void Target::SetId(int pdgc)
167 {
168  fTgtPDG = pdgc;
169  if( pdg::IsIon(pdgc) ) {
170  fZ = pdg::IonPdgCodeToZ(pdgc);
171  fA = pdg::IonPdgCodeToA(pdgc);
172  }
173 
174  this->ForceNucleusValidity(); // search at the isotopes chart
175  //this->AutoSetHitNuc(); // struck nuc := tgt for free nucleon tgt
176 }
177 //___________________________________________________________________________
178 void Target::SetId(int ZZ, int AA)
179 {
180  fTgtPDG = pdg::IonPdgCode(AA,ZZ);
181  fZ = ZZ;
182  fA = AA;
183 
184  this->ForceNucleusValidity(); // search at the isotopes chart
185  //this->AutoSetHitNuc(); // struck nuc := tgt for free nucleon tgt
186 }
187 //___________________________________________________________________________
188 void Target::SetHitNucPdg(int nucl_pdgc)
189 {
190  fHitNucPDG = nucl_pdgc;
191  bool is_valid = this->ForceHitNucValidity(); // p, n or a di-nucleon
192 
193  // If it is a valid struck nucleon pdg code, initialize its 4P:
194  // at-rest + on-mass-shell
195  if(is_valid) {
196  double M = PDGLibrary::Instance()->Find(nucl_pdgc)->Mass();
197  fHitNucP4->SetPxPyPzE(0,0,0,M);
198  }
199 }
200 //___________________________________________________________________________
201 void Target::SetHitQrkPdg(int pdgc)
202 {
203  if(pdg::IsQuark(pdgc) || pdg::IsAntiQuark(pdgc)) fHitQrkPDG = pdgc;
204 }
205 //___________________________________________________________________________
206 void Target::SetHitNucP4(const TLorentzVector & p4)
207 {
208  if(fHitNucP4) delete fHitNucP4;
209  fHitNucP4 = new TLorentzVector(p4);
210 }
211 //___________________________________________________________________________
213 {
214  fHitSeaQrk = tf;
215 }
216 //___________________________________________________________________________
218 {
219  if(this->HitNucIsSet()) {
220  double m = this->HitNucMass();
221  double p = this->HitNucP4Ptr()->P();
222  double e = TMath::Sqrt(p*p+m*m);
223  this->HitNucP4Ptr()->SetE(e);
224  }
225 }
226 //___________________________________________________________________________
228 {
229  fHitNucRad = r;
230 }
231 //___________________________________________________________________________
232 double Target::Charge(void) const
233 {
234 // Shortcut for commonly used code for extracting the nucleus charge from PDG
235 //
236  TParticlePDG * p = PDGLibrary::Instance()->Find(fTgtPDG);
237  if(p) return p->Charge() / 3.; // in +e
238  return 0;
239 }
240 //___________________________________________________________________________
241 double Target::Mass(void) const
242 {
243 // Shortcut for commonly used code for extracting the nucleus mass from PDG
244 //
245  TParticlePDG * p = PDGLibrary::Instance()->Find(fTgtPDG);
246  if(p) return p->Mass(); // in GeV
247  return 0.;
248 }
249 //___________________________________________________________________________
250 double Target::HitNucMass(void) const
251 {
252  if(!fHitNucPDG) {
253  LOG("Target", pWARN) << "Returning struck nucleon mass = 0";
254  return 0;
255  }
256  return PDGLibrary::Instance()->Find(fHitNucPDG)->Mass();
257 }
258 //___________________________________________________________________________
259 int Target::HitQrkPdg(void) const
260 {
261  return fHitQrkPDG;
262 }
263 //___________________________________________________________________________
264 TLorentzVector * Target::HitNucP4Ptr(void) const
265 {
266  if(!fHitNucP4) {
267  LOG("Target", pWARN) << "Returning NULL struck nucleon 4-momentum";
268  return 0;
269  }
270 
271  return fHitNucP4;
272 }
273 //___________________________________________________________________________
274 bool Target::IsFreeNucleon(void) const
275 {
276  return (fA == 1 && (fZ == 0 || fZ == 1));
277 }
278 //___________________________________________________________________________
279 bool Target::IsProton(void) const
280 {
281  return (fA == 1 && fZ == 1);
282 }
283 //___________________________________________________________________________
284 bool Target::IsNeutron(void) const
285 {
286  return (fA == 1 && fZ == 0);
287 }
288 //___________________________________________________________________________
289 bool Target::IsNucleus(void) const
290 {
291  return (fA > 1); // IsValidNucleus() was ensured when A,Z were set
292 }
293 //___________________________________________________________________________
294 bool Target::IsParticle(void) const
295 {
296  TParticlePDG * p = PDGLibrary::Instance()->Find(fTgtPDG);
297  return (p && fA==0 && fZ==0);
298 }
299 //___________________________________________________________________________
300 bool Target::HitNucIsSet(void) const
301 {
302  bool ok =
305 
306  return ok;
307 }
308 //___________________________________________________________________________
309 bool Target::HitQrkIsSet(void) const
310 {
311  return (
313  );
314 }
315 //___________________________________________________________________________
316 bool Target::HitSeaQrk(void) const
317 {
318  return fHitSeaQrk;
319 }
320 //___________________________________________________________________________
321 int Target::HitNucPdg(void) const
322 {
323  return fHitNucPDG;
324 }
325 //___________________________________________________________________________
326 bool Target::IsValidNucleus(void) const
327 {
328  //-- it is valid if it is a free nucleon...
329  if(this->IsFreeNucleon()) return true;
330 
331  //-- ... or a nucleus that can be found in the MINOS ion PDG extensions
332  int pdg_code = pdg::IonPdgCode(fA, fZ);
333  TParticlePDG * p = PDGLibrary::Instance()->Find(pdg_code);
334  if(p) return true;
335 
336  return false;
337 }
338 //___________________________________________________________________________
339 bool Target::IsEvenEven(void) const
340 {
341  if( this->IsNucleus() ) {
342  int NN = this->N();
343  int ZZ = this->Z();
344  if( NN % 2 == 0 && ZZ % 2 == 0 ) return true;
345  }
346  return false;
347 }
348 //___________________________________________________________________________
349 bool Target::IsEvenOdd(void) const
350 {
351  if( this->IsNucleus() ) {
352  if(! this->IsEvenEven() && ! this->IsOddOdd() ) return true;
353  }
354  return false;
355 }
356 //___________________________________________________________________________
357 bool Target::IsOddOdd(void) const
358 {
359  if( this->IsNucleus() ) {
360  int NN = this->N();
361  int ZZ = this->Z();
362  if( NN % 2 == 1 && ZZ % 2 == 1 ) return true;
363  }
364  return false;
365 }
366 //___________________________________________________________________________
368 {
369 // resets the struck nucleon pdg-code if it is found not to be a valid one
370 
371  bool valid =
374  (fHitNucPDG==0); /* not set */
375 
376  return valid;
377 }
378 //___________________________________________________________________________
380 {
381 // resets the target pdg-code if it is found not to be a valid one
382 
383  if( ! this->IsValidNucleus() ) {
384  LOG("Target", pWARN) << "Invalid target -- Reseting to Z = 0, A = 0";
385  fZ = 0;
386  fA = 0;
387  }
388 }
389 //___________________________________________________________________________
391 {
392 // for free nucleon targets -> (auto)set struck nucleon = target
393 
394  if( this->IsFreeNucleon() ) {
395  if( this->IsProton() ) this->SetHitNucPdg(kPdgProton);
396  else this->SetHitNucPdg(kPdgNeutron);
397  }
398 }
399 //___________________________________________________________________________
400 string Target::AsString(void) const
401 {
402  ostringstream s;
403 
404  s << this->Pdg();
405  if(this->HitNucIsSet())
406  s << "[N=" << this->HitNucPdg() << "]";
407  if(this->HitQrkIsSet()) {
408  s << "[q=" << this->HitQrkPdg();
409  s << (this->HitSeaQrk() ? "(s)" : "(v)");
410  s << "]";
411  }
412 
413  return s.str();
414 }
415 //___________________________________________________________________________
416 void Target::Print(ostream & stream) const
417 {
418  stream << " target PDG code = " << fTgtPDG << endl;
419 
420  if( this->IsNucleus() || this->IsFreeNucleon() ) {
421  stream << " Z = " << fZ << ", A = " << fA << endl;
422  }
423 
424  if( this->HitNucIsSet() ) {
425  TParticlePDG * p = PDGLibrary::Instance()->Find(fHitNucPDG);
426  stream << " struck nucleon = " << p->GetName()
427  << ", P4 = " << utils::print::P4AsString(fHitNucP4) << endl;
428  }
429 
430  if( this->HitQrkIsSet() ) {
431  TParticlePDG * q = PDGLibrary::Instance()->Find(fHitQrkPDG);
432  stream << " struck quark = " << q->GetName()
433  << " (from sea: "
435  << ")";
436  }
437 }
438 //___________________________________________________________________________
439 bool Target::Compare(const Target & target) const
440 {
441  int tgt_pdg = target.Pdg();
442  int struck_nuc_pdg = target.HitNucPdg();
443  int struck_qrk_pdg = target.HitQrkPdg();
444  bool struck_sea_qrk = target.HitSeaQrk();
445 
446  bool equal = ( fTgtPDG == tgt_pdg ) &&
447  ( fHitNucPDG == struck_nuc_pdg ) &&
448  ( fHitQrkPDG == struck_qrk_pdg ) &&
449  ( fHitSeaQrk == struck_sea_qrk );
450  return equal;
451 }
452 //___________________________________________________________________________
453 bool Target::operator == (const Target & target) const
454 {
455  return this->Compare(target);
456 }
457 //___________________________________________________________________________
459 {
460  this->Copy(target);
461  return (*this);
462 }
463 //___________________________________________________________________________
Target & operator=(const Target &t)
copy
Definition: Target.cxx:458
Basic constants.
string AsString(void) const
Definition: Target.cxx:400
bool HitSeaQrk(void) const
Definition: Target.cxx:316
const XML_Char * target
Definition: expat.h:268
void AutoSetHitNuc(void)
Definition: Target.cxx:390
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
static const double kNucleonMass
Definition: Constants.h:78
int HitNucPdg(void) const
Definition: Target.cxx:321
bool IsNeutron(void) const
Definition: Target.cxx:284
int fZ
nuclear target Z
Definition: Target.h:118
bool IsNucleon(int pdgc)
Definition: PDGUtils.cxx:309
int HitQrkPdg(void) const
Definition: Target.cxx:259
bool operator==(const Target &t) const
equal?
Definition: Target.cxx:453
string BoolAsYNString(bool b)
Definition: PrintUtils.cxx:115
double HitNucMass(void) const
Definition: Target.cxx:250
const char * p
Definition: xmltok.h:285
bool IsNucleus(void) const
Definition: Target.cxx:289
bool equal(T *first, T *second)
int Pdg(void) const
Definition: Target.h:72
int IonPdgCodeToA(int pdgc)
Definition: PDGUtils.cxx:61
void SetHitNucP4(const TLorentzVector &p4)
Definition: Target.cxx:206
bool IsAntiQuark(int pdgc)
Definition: PDGUtils.cxx:241
void SetHitQrkPdg(int pdgc)
Definition: Target.cxx:201
string P4AsString(const TLorentzVector *p)
Definition: PrintUtils.cxx:34
void SetHitNucPosition(double r)
Definition: Target.cxx:227
constexpr bool is_valid(IDNumber_t< L > const id)
Definition: IDNumber.h:112
Timing fit.
double Mass(void) const
Definition: Target.cxx:241
void SetId(int pdgc)
Definition: Target.cxx:166
void Init(void)
Definition: Target.cxx:116
double Charge(void) const
Definition: Target.cxx:232
bool IsValidNucleus(void) const
Definition: Target.cxx:326
int fHitNucPDG
hit nucleon PDG code
Definition: Target.h:121
int fHitQrkPDG
hit quark PDG code
Definition: Target.h:122
void CleanUp(void)
Definition: Target.cxx:128
const XML_Char * s
Definition: expat.h:262
bool IsEvenEven(void) const
Definition: Target.cxx:339
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
A Neutrino Interaction Target. Is a transparent encapsulation of quite different physical systems suc...
Definition: Target.h:41
int Z(void) const
Definition: Target.h:69
bool IsOddOdd(void) const
Definition: Target.cxx:357
int fTgtPDG
nuclear target PDG code
Definition: Target.h:120
#define pWARN
Definition: Messenger.h:61
bool IsEvenOdd(void) const
Definition: Target.cxx:349
void Reset(void)
Definition: Target.cxx:110
bool Is2NucleonCluster(int pdgc)
Definition: PDGUtils.cxx:365
int N(void) const
Definition: Target.h:70
TLorentzVector * HitNucP4Ptr(void) const
Definition: Target.cxx:264
static PDGLibrary * Instance(void)
Definition: PDGLibrary.cxx:43
bool IsIon(int pdgc)
Definition: PDGUtils.cxx:40
bool Compare(const Target &t) const
Definition: Target.cxx:439
bool HitNucIsSet(void) const
Definition: Target.cxx:300
bool HitQrkIsSet(void) const
Definition: Target.cxx:309
Var Sqrt(const Var &v)
Use to take sqrt of a var.
Definition: Var.cxx:326
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
void SetHitNucPdg(int pdgc)
Definition: Target.cxx:188
bool IsQuark(int pdgc)
Definition: PDGUtils.cxx:233
ClassImp(Target) namespace genie
Definition: Target.cxx:47
TParticlePDG * Find(int pdgc)
Definition: PDGLibrary.cxx:61
int IonPdgCode(int A, int Z)
Definition: PDGUtils.cxx:69
double fHitNucRad
hit nucleon position
Definition: Target.h:125
TRandom3 r(0)
TLorentzVector * fHitNucP4
hit nucleon 4p
Definition: Target.h:124
void Copy(const Target &t)
Definition: Target.cxx:133
int IonPdgCodeToZ(int pdgc)
Definition: PDGUtils.cxx:53
const int kPdgProton
Definition: PDGCodes.h:65
Float_t e
Definition: plot.C:35
void SetHitSeaQrk(bool tf)
Definition: Target.cxx:212
void Print(ostream &stream) const
Definition: Target.cxx:416
bool fHitSeaQrk
hit quark from sea?
Definition: Target.h:123
bool IsProton(void) const
Definition: Target.cxx:279
const int kPdgNeutron
Definition: PDGCodes.h:67
Most commonly used PDG codes. A set of utility functions to handle PDG codes is provided in PDGUtils...
#define NN
bool IsParticle(void) const
Definition: Target.cxx:294
bool ForceHitNucValidity(void)
Definition: Target.cxx:367
void ForceNucleusValidity(void)
Definition: Target.cxx:379
bool IsFreeNucleon(void) const
Definition: Target.cxx:274
void ForceHitNucOnMassShell(void)
Definition: Target.cxx:217
int fA
nuclear target A
Definition: Target.h:119