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