KaliVeda  1.12/06
Heavy-Ion Analysis Toolkit
KVDBSystem.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * This program is free software; you can redistribute it and/or modify *
4  * it under the terms of the GNU General Public License as published by *
5  * the Free Software Foundation; either version 2 of the License, or *
6  * (at your option) any later version. *
7  * *
8  ***************************************************************************/
9 #include "KVDBSystem.h"
10 #include "KVDBRun.h"
11 #include "KV2Body.h"
12 #include "KVNumberList.h"
13 #include "KVUnits.h"
14 #include "TROOT.h"
15 #include "KVDBKey.h"
16 #include "KVDBTable.h"
17 
18 using namespace std;
19 
21 //___________________________________________________________________________
22 
24 
26 {
27  fZtarget = fAtarget = fZbeam = fAbeam = 0;
28  fEbeam = 0.;
29  fCinema = 0;
30  fTarget = 0;
31  fRunlist = 0;
32  fRuns = 0;
33 }
34 
35 
36 
38 
40  "Physical System")
41 {
42  fZtarget = fAtarget = fZbeam = fAbeam = 0;
43  fEbeam = 0.;
44  fCinema = 0;
45  fTarget = 0;
46  KVDBKey* dbk = AddKey("Runs", "List of Runs");
47  dbk->SetUniqueStatus(kTRUE);
48  fRunlist = 0;
49  fRuns = 0;
50 }
51 
52 
53 
56 
57 KVDBSystem::~KVDBSystem()
58 {
59  //Delete kinematics, target and associated runlist if they exist
60  if (fCinema) {
61  delete fCinema;
62  fCinema = 0;
63  }
64  delete fTarget;
65  if (fRunlist)
66  delete fRunlist;
67 }
68 
69 
70 
71 
78 
80 {
81  // Create (if it doesn't already exist) and return pointer to a KV2Body object initialised
82  // with the entrance channel corresponding to this system. Use this to obtain information
83  // such as the recoil velocity of the CM, available energy, etc. (see KV2Body).
84  //
85  // If no projectile and/or target are defined for the system, we return 0x0.
86 
87  if (GetZbeam()*GetZtarget() == 0) return nullptr;
88 
89  if (!fCinema) {
90  fCinema = new KV2Body();
95  }
96  return fCinema;
97 }
98 
99 
100 
103 
105 {
106  //retourne kTRUE, si le systeme est une collision ie projectile+cible
107  return (GetZbeam() * GetZtarget() != 0);
108 
109 }
110 
111 
112 
113 
117 
119 {
120  //Returns product of atomic number and velocity component parallel to beam axis of projectile nucleus in laboratory frame
121  //Units are cm/ns (velocity units)
122  KV2Body* kin = const_cast < KVDBSystem* >(this)->GetKinematics();
123  if (!kin) return 0.;
124  return (fZbeam * kin->GetNucleus(1)->GetVpar());
125 }
126 
127 
128 
129 
133 
135 {
136  //Returns momentum component parallel to beam axis of projectile nucleus in laboratory frame
137  //Units are MeV/c
138  KV2Body* kin = const_cast < KVDBSystem* >(this)->GetKinematics();
139  if (!kin) return 0.;
140  return (kin->GetNucleus(1)->GetMomentum().Z());
141 }
142 
143 
144 
145 
149 
151 {
152  //Returns total (mass + kinetic) energy of entrance channel corresponding to system
153  //Units are MeV
154  KV2Body* kin = const_cast < KVDBSystem* >(this)->GetKinematics();
155  if (!kin) return 0.;
156  return (kin->GetNucleus(1)->E() + kin->GetNucleus(2)->E());
157 }
158 
159 
160 
161 
165 
167 {
168  //Returns total available (CM) kinetic energy of entrance channel corresponding to system
169  //Units are MeV
170  KV2Body* kin = const_cast < KVDBSystem* >(this)->GetKinematics();
171  if (!kin) return 0.;
172  return (kin->GetCMEnergy());
173 }
174 
175 
176 
177 
183 
185 {
186  //Function used to sort lists of systems.
187  //Systems are sorted according to the number of the first run in the
188  //(sorted) list of runs associated to the system.
189  //Systems with lower first run numbers appear earlier in the list.
190 
191  if (!GetRuns())
192  return 0;
193  KVDBSystem* other_sys =
194  dynamic_cast < KVDBSystem* >(const_cast < TObject* >(obj));
195  if (!other_sys)
196  return 0;
197  KVList* other_runs;
198  if (!(other_runs = other_sys->GetRuns()))
199  return 0;
200  Int_t first = ((KVDBRecord*) fRunlist->At(0))->GetNumber();
201  Int_t other_first = ((KVDBRecord*) other_runs->At(0))->GetNumber();
202  return (first == other_first ? 0 : (other_first > first ? -1 : 1));
203 }
204 
205 
206 
207 
211 
213 {
214  //"translate" the KVRList returned by GetLinks into a standard
215  //TList which can then be sorted (Sort() is not implemented for TRefArray).
216  KVRList* _rlist = GetLinks("Runs");
217  TIter nxt(_rlist);
218  KVDBRun* db;
220  fRunlist = new KVList(kFALSE); //will be deleted with object
221  while ((db = (KVDBRun*) nxt()))
222  fRunlist->Add(db);
223  fRunlist->Sort();
224  return fRunlist;
225 }
226 
227 
228 
229 
232 
234 {
235  //Fills the KVNumberList object with the list of all run numbers associated with this system
236  list.Clear();
237  TIter next(GetRuns());
238  KVDBRun* run;
239  while ((run = (KVDBRun*)next())) {
240  list.Add(run->GetNumber());
241  }
242 }
243 
244 
245 
246 
257 
258 void KVDBSystem::Save(ostream& f) const
259 {
260  //Write informations on system in the format used in Systems.dat files:
261  //
262  //+155Gd + 238U 36 MeV/A '+' followed by name of system
263  //155 64 238 92 36.0 Aproj Zproj Atarg Ztarg Ebeam
264  //Target: 3 0.0 target with 3 layers, angle 0 degrees
265  //C 0.02 1st layer : carbon, 20 g/cm2
266  //238U 0.1 2nd layer : uranium-238, 100 g/cm2
267  //C 0.023 3rd layer : carbon, 23 g/cm2
268  //Runs: 770-804 list of runs in KVNumberList format
269 
270  f << "+" << GetName() << endl;
271  if (fZbeam) f << fAbeam << " " << fZbeam << " " << fAtarget << " " << fZtarget << " " << fEbeam << endl;
272  if (fTarget) {
273  f << "Target: " << fTarget->NumberOfLayers() << " " << fTarget->GetAngleToBeam() << endl;
274  TIter next(fTarget->GetLayers());
275  KVMaterial* lay;
276  while ((lay = (KVMaterial*)next())) {
277  if (lay->IsIsotopic()) f << Form("%d%s", (Int_t)lay->GetMass(), lay->GetType());
278  else f << lay->GetType();
279  f << " " << lay->GetAreaDensity() / KVUnits::mg << endl;
280  }
281  }
282  KVNumberList runlist;
283  GetRunList(runlist);
284  f << "Runs: " << runlist.AsString() << endl;
285 }
286 
287 
288 
289 
300 
301 void KVDBSystem::Load(istream& f)
302 {
303  //Read and set informations on system in the format used in Systems.dat files:
304  //
305  //+155Gd + 238U 36 MeV/A '+' followed by name of system
306  //155 64 238 92 36.0 Aproj Zproj Atarg Ztarg Ebeam
307  //Target: 3 0.0 target with 3 layers, angle 0 degrees
308  //C 0.02 1st layer : carbon, 20 ug/cm2
309  //238U 0.1 2nd layer : uranium-238, 100 ug/cm2
310  //C 0.023 3rd layer : carbon, 23 ug/cm2
311  //Runs: 770-804 list of runs in KVNumberList format
312 
313  TString line;
314  Float_t target_thickness;
315  fAbeam = fZbeam = fAtarget = fZtarget = 0;
316  fEbeam = target_thickness = 0;
317  KVNumberList runlist;
318  //'peek' at first character of next line
319  char next_char = f.peek();
320  if (next_char == '+') {
321  line.ReadLine(f, kFALSE);
322  line.Remove(0, 1);
323  SetName(line.Data());
324  cout << "New System : " << line.Data() << endl;
325  }
326  else {
327  Error("Load", "Should read system name : %s\n", line.Data());
328  return;
329  }
330  next_char = f.peek();
331  while (next_char != '+' && f.good() && !f.eof()) {
332  if ((next_char >= '0') && (next_char <= '9')) {
333  line.ReadLine(f, kFALSE);
334  if (sscanf(line.Data(), "%u %u %u %u %f %f", &fAbeam, &fZbeam, &fAtarget, &fZtarget, &target_thickness, &fEbeam) == 6) {
335  cout << "Zproj = " << fZbeam << " Ztarg = " << fZtarget << " targ_thick = " << target_thickness << " Ebeam = " << fEbeam << endl;
336  }
337  else if (sscanf(line.Data(), "%u %u %u %u %f", &fAbeam, &fZbeam, &fAtarget, &fZtarget, &fEbeam) == 5) {
338  cout << "Zproj = " << fZbeam << " Ztarg = " << fZtarget << " Ebeam = " << fEbeam << endl;
339  }
340  }
341  else {
342  line.ReadLine(f, kFALSE);
343  if (line.BeginsWith("Target")) {
344  fTarget = new KVTarget;
345  line.Remove(0, line.Index(":") + 1);
346  Int_t nlay;
347  Float_t angle;
348  sscanf(line.Data(), "%d %f", &nlay, &angle);
349  Char_t mat[10];
350  Float_t thick;
351  for (int i = 0; i < nlay; i++) {
352  line.ReadLine(f);
353  sscanf(line.Data(), "%s %f", mat, &thick);
354  fTarget->AddLayer(mat, thick);
355  }
356  fTarget->SetAngleToBeam(angle);
357  fTarget->Print();
358  }
359  else if (line.BeginsWith("Runs")) {
360  line.Remove(0, line.Index(":") + 1);
361  runlist.SetList(line.Data());
362  cout << "Runs : " << line.Data() << endl;
363  }
364  else if (line.BeginsWith("Run Range")) {
365  line.Remove(0, line.Index(":") + 1);
366  Int_t frun, lrun;
367  sscanf(line.Data(), "%i %i", &frun, &lrun);
368  runlist.Add(Form("%i-%i", frun, lrun));
369  cout << "Run range : " << line.Data() << endl;
370  }
371  }
372  next_char = f.peek();
373  }
374  if (runlist.GetNValues()) {
375  SetRuns(runlist);
376  }
377  //set target if not already done (old versions)
378  if (!fTarget && target_thickness > 0 && fZtarget > 0) {
380  fTarget = new KVTarget(n.GetSymbol(), target_thickness);
381  fTarget->Print();
382  }
383 }
384 
385 
386 
387 
391 
393 {
394  //Associate this system with the runs in the list
395  //Any previously associated runs are first removed (links in the runs will be removed too)
396  Info("SetRuns", "Setting runs for system %s : %s", GetName(), rl.AsString());
397  RemoveAllRuns();
398  rl.Begin();
399  KVDBTable* runtable = GetRunsTable();
400  Int_t run_number;
401  while (!rl.End()) {
402  run_number = rl.Next();
403  KVDBRun* run = (KVDBRun*)runtable->GetRecord(run_number);
404  if (run) {
405  if (run->GetSystem()) {
406 // Error("SetRuns", "Associating run %d with system \"%s\" : run already associated with system \"%s\"",
407 // run_number, GetName(), run->GetSystem()->GetName());
408  }
409  else {
410  if (AddLink("Runs", run)) {
411  //use name of system as title of run
412  run->SetTitle(GetName());
413  }
414  else {
415  Info("SetRuns", "Could not add link for run %d", run_number);
416  }
417  }
418  }
419  else {
420  //Info("SetRuns", "Run %d not found in database", run_number);
421  }
422  }
423 }
424 
425 
426 
427 
432 
434 {
435  //Associate the given run with this system.
436  //If the run was previously associated with another system, this association
437  //will be removed.
438  if (!rec) return;
439  if (!rec->InheritsFrom("KVDBRun")) {
440  Error("AddRun", "Called with pointer to an object of class %s; should inherit from KVDBRun!",
441  rec->ClassName());
442  return;
443  }
444  KVDBRun* run = (KVDBRun*)rec;
445  if (run->GetSystem()) run->GetSystem()->RemoveRun(run);
446  if (AddLink("Runs", run)) {
447  //Info("AddRun", "Added link for run %d", run->GetNumber());
448  //use name of system as title of run
449  run->SetTitle(GetName());
450  }
451  else {
452  Info("AddRun", "Could not add link for run %d", run->GetNumber());
453  }
454 }
455 
456 
457 
458 
463 
465 {
466  //Associate the given run with this system.
467  //If the run was previously associated with another system, this association
468  //will be removed.
469  AddRun(GetRunsTable()->GetRecord(run));
470 }
471 
472 
473 
474 
478 
480 {
481  //Unassociate the given run from this system. Cross-reference link to this system
482  //is removed from the run at the same time.
483  RemoveLink("Runs", run);
484 }
485 
486 
487 
488 
492 
494 {
495  //Unassociate the given run from this system. Cross-reference link to this system
496  //is removed from the run at the same time.
497  RemoveRun(GetRunsTable()->GetRecord(run));
498 }
499 
500 
501 
502 
506 
508 {
509  //Unassociate all runs from this system. Cross-reference links to this system
510  //are removed from the runs at the same time.
511  RemoveAllLinks("Runs");
512 }
513 
514 
515 
517 
519 {
520  cout << "________________________________________________________" <<
521  endl << "System : " << GetName() << endl;
522  KVNumberList r;
523  GetRunList(r);
524  cout << "Runs : " << r.AsString() << endl;
525  cout << " Zbeam : " << fZbeam
526  << endl << " Abeam : " << fAbeam << endl << " Ebeam : " << fEbeam
527  << " A.MeV" << endl << " Ztarget : " << fZtarget << endl <<
528  " Atarget : " << fAtarget << endl << " Target Thickness : " <<
529  const_cast <
530  KVDBSystem*
531  >(this)->
532  GetTargetThickness() << " mg/cm2" << endl <<
533  "________________________________________________________" << endl;
534 
535 }
536 
537 
538 
540 
542 {
543  KVNumberList r;
544  GetRunList(r);
545  cout << "KVDBSystem : " << GetName() << " Runs : " << r.AsString() << endl;
546 }
547 
548 
549 
556 
558 {
559  //Deduce path to runs table in database from full path to parent table of this record.
560  //The systems are stored in a table called "Systems"
561  //The runs are stored in a table called "Runs"
562  //Therefore if we take the full path to the Systems table and replace Systems with Runs,
563  //we can then use gROOT->FindObject to get the pointer to the Runs table.
564 
565  TString path = fFullPathTable.Data();
566  path.ReplaceAll("Systems", "Runs");
567  return (KVDBTable*)gROOT->FindObject(path.Data());
568 }
569 
570 
571 
572 
576 
578 {
579  // Gives name of system in compact form with all (unix-)illegal characters
580  // replaced by '_'. Can be used for naming batch jobs, files, etc.
581 
582  static KVString tmp;
583  tmp = "";
584  if (GetKinematics()) {
585  if (GetKinematics()->GetNucleus(1)) {
586  tmp = GetKinematics()->GetNucleus(1)->GetSymbol();
587  }
588  if (GetKinematics()->GetNucleus(2)) {
589  tmp += GetKinematics()->GetNucleus(2)->GetSymbol();
590  }
591  if (GetEbeam() > 0) {
592  tmp += TMath::Nint(GetEbeam());
593  }
594  }
595  if (tmp == "") {
596  tmp = GetName();
597  tmp.ReplaceAll(" ", "_");
598  tmp.ReplaceAll("/", "_");
599  }
600  return tmp.Data();
601 }
602 
603 
604 
int Int_t
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
ROOT::R::TRInterface & r
#define SafeDelete(p)
#define f(i)
char Char_t
const Bool_t kFALSE
bool Bool_t
double Double_t
float Float_t
const Bool_t kTRUE
const char Option_t
#define gROOT
char * Form(const char *fmt,...)
Relativistic binary kinematics calculator.
Definition: KV2Body.h:165
void SetTarget(const KVNucleus &)
Set target for reaction.
Definition: KV2Body.cpp:315
void SetProjectile(const KVNucleus &)
Set projectile for reaction.
Definition: KV2Body.cpp:340
void CalculateKinematics()
Definition: KV2Body.cpp:678
KVNucleus * GetNucleus(Int_t i) const
Definition: KV2Body.cpp:457
Double_t GetCMEnergy() const
Return available kinetic energy in centre of mass.
Definition: KV2Body.cpp:523
const Char_t * GetType() const
Definition: KVBase.h:170
Cross-reference in a KVDataBase.
Definition: KVDBKey.h:37
virtual void SetUniqueStatus(Bool_t unique)
Definition: KVDBKey.h:72
Record folder for the database.
Definition: KVDBRecord.h:42
virtual Bool_t AddKey(KVDBKey *key, Bool_t check=kTRUE)
Definition: KVDBRecord.cpp:65
TString fFullPathTable
full path to parent table in folder structure
Definition: KVDBRecord.h:46
virtual Bool_t AddLink(const Char_t *key_name, KVDBRecord *rec, Bool_t linkback=kTRUE)
Definition: KVDBRecord.cpp:122
virtual void RemoveLink(const Char_t *key_name, KVDBRecord *rec, Bool_t linkback=kTRUE)
Remove the link between this record and the record "rec" in the DB table"key_name".
Definition: KVDBRecord.cpp:145
virtual KVRList * GetLinks(const Char_t *key) const
Returns the list of records linked to this record in table "key".
Definition: KVDBRecord.cpp:206
virtual void RemoveAllLinks(const Char_t *key)
Remove all links between this record and the records in the DB table"key_name".
Definition: KVDBRecord.cpp:166
virtual Int_t GetNumber() const
Definition: KVDBRecord.h:72
Description of an experimental run in database ,.
Definition: KVDBRun.h:35
KVDBSystem * GetSystem() const
Definition: KVDBRun.cpp:242
Database class used to store information on different colliding systems studied during an experiment.
Definition: KVDBSystem.h:51
UInt_t GetZtarget() const
.............. inline functions ...............
Definition: KVDBSystem.h:156
virtual void Print(Option_t *option="") const
Definition: KVDBSystem.cpp:518
Bool_t IsCollision() const
retourne kTRUE, si le systeme est une collision ie projectile+cible
Definition: KVDBSystem.cpp:104
Int_t Compare(const TObject *) const
Definition: KVDBSystem.cpp:184
UInt_t GetAtarget() const
Definition: KVDBSystem.h:161
void SetRuns(KVNumberList &)
Definition: KVDBSystem.cpp:392
Float_t fEbeam
Energy of the beam in MeV/nucleon.
Definition: KVDBSystem.h:67
void RemoveRun(KVDBRecord *)
Definition: KVDBSystem.cpp:479
Double_t GetPtot() const
Definition: KVDBSystem.cpp:134
virtual void Save(std::ostream &) const
Definition: KVDBSystem.cpp:258
Double_t GetECM() const
Definition: KVDBSystem.cpp:166
KVList * fRunlist
used to store pointer to sorted list of runs
Definition: KVDBSystem.h:59
Float_t GetTargetThickness() const
Definition: KVDBSystem.h:206
void AddRun(KVDBRecord *)
Definition: KVDBSystem.cpp:433
KV2Body * GetKinematics()
Definition: KVDBSystem.cpp:79
Float_t GetEbeam() const
Definition: KVDBSystem.h:196
KVList * GetRuns() const
Returns a sorted list of all the runs associated with this system.
Definition: KVDBSystem.h:116
UInt_t fAbeam
Mass of the projectile nucleus.
Definition: KVDBSystem.h:64
Double_t GetZVtot() const
Definition: KVDBSystem.cpp:118
UInt_t GetZbeam() const
Definition: KVDBSystem.h:176
UInt_t GetAbeam() const
Definition: KVDBSystem.h:181
virtual void ls(Option_t *option="*") const
Definition: KVDBSystem.cpp:541
virtual void Load(std::istream &)
Definition: KVDBSystem.cpp:301
KVDBTable * GetRunsTable()
Definition: KVDBSystem.cpp:557
virtual const Char_t * GetBatchName()
Definition: KVDBSystem.cpp:577
Int_t fRuns
temporary variable used to stock number of associated runs
Definition: KVDBSystem.h:60
KV2Body * fCinema
used to calculate kinematics of entrance channel
Definition: KVDBSystem.h:55
UInt_t fZtarget
charge of the target nucleus
Definition: KVDBSystem.h:65
KVTarget * fTarget
physical target used for experiment run
Definition: KVDBSystem.h:57
virtual void GetRunList(KVNumberList &) const
Fills the KVNumberList object with the list of all run numbers associated with this system.
Definition: KVDBSystem.cpp:233
UInt_t fZbeam
charge of the projectile nucleus
Definition: KVDBSystem.h:63
UInt_t fAtarget
Mass of the target nucleus.
Definition: KVDBSystem.h:66
KVList * _GetRuns()
Definition: KVDBSystem.cpp:212
void RemoveAllRuns()
Definition: KVDBSystem.cpp:507
Double_t GetEtot() const
Definition: KVDBSystem.cpp:150
Table in a database.
Definition: KVDBTable.h:33
virtual KVDBRecord * GetRecord(const Char_t *rec_name) const
Definition: KVDBTable.h:57
Extended TList class which owns its objects by default.
Definition: KVList.h:27
void Sort(Bool_t order=kSortAscending)
Definition: KVList.h:34
Description of physical materials used to construct detectors; interface to range tables.
Definition: KVMaterial.h:41
Double_t GetAreaDensity() const
Return area density of material in g/cm**2.
Definition: KVMaterial.cpp:427
Bool_t IsIsotopic() const
Definition: KVMaterial.cpp:269
Double_t GetMass() const
Returns atomic mass of material. Will be isotopic mass if set.
Definition: KVMaterial.cpp:252
Description of properties and kinematics of atomic nuclei.
Definition: KVNucleus.h:125
const Char_t * GetSymbol(Option_t *opt="") const
Definition: KVNucleus.cpp:81
Strings used to represent a set of ranges of values.
Definition: KVNumberList.h:83
const Char_t * AsString(Int_t maxchars=0) const
Bool_t End(void) const
Definition: KVNumberList.h:196
Int_t GetNValues() const
void Begin(void) const
void SetList(const TString &)
void Add(Int_t)
Add value 'n' to the list.
void Clear(Option_t *="")
Empty number list, reset it to initial state.
Int_t Next(void) const
TVector3 GetMomentum() const
Definition: KVParticle.h:565
Double_t GetVpar() const
Definition: KVParticle.h:636
void SetEnergy(Double_t e)
Definition: KVParticle.h:560
Wrapper for TRefArray adding some functionality.
Definition: KVRList.h:36
virtual TObject * At(Int_t idx) const
virtual void Add(TObject *obj)
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:72
Calculation/correction of energy losses of particles through an experimental target.
Definition: KVTarget.h:126
void Print(Option_t *opt="") const
Show information on this material.
Definition: KVTarget.cpp:742
void SetAngleToBeam(Double_t a)
Definition: KVTarget.cpp:178
Int_t NumberOfLayers() const
Definition: KVTarget.h:165
void AddLayer(const Char_t *material, Double_t thick)
Definition: KVTarget.cpp:111
KVList * GetLayers() const
Definition: KVTarget.h:169
Double_t GetAngleToBeam()
Gives angle of target to incident beam direction in degrees.
Definition: KVTarget.cpp:193
Double_t E() const
virtual const char * GetName() const
virtual void SetTitle(const char *title="")
virtual void SetName(const char *name)
virtual const char * ClassName() const
virtual Bool_t InheritsFrom(const char *classname) const
virtual void Error(const char *method, const char *msgfmt,...) const
virtual void Info(const char *method, const char *msgfmt,...) const
const char * Data() const
TString & ReplaceAll(const char *s1, const char *s2)
Double_t Z() const
TLine * line
const Int_t n
const long double mg
Definition: KVUnits.h:74
Int_t Nint(T x)