AliPhysics  8d00e07 (8d00e07)
GRP.C
Go to the documentation of this file.
1 
10 // #include <fstream>
11 
19 struct GRPData
20 {
24  struct Beam
25  {
36  {
37  return e * float(z)/a;
38  }
47  {
48  Double_t be = GetEnergy(e);
49  Double_t mp =TDatabasePDG::Instance()->GetParticle(2212)->Mass();
50  return TMath::Sqrt(be*be-mp*mp);
51  }
57  Bool_t IsP() const { return z == 1 && a == 1; }
63  Bool_t IsA() const { return !IsP(); }
69  const char* Name() { return (IsP() ? "P" : IsA() ? "A" : ""); }
75  void Set(UInt_t b)
76  {
77  z = b % 1000;
78  a = b / 1000;
79  }
85  void Set(const TString& b)
86  {
87  b.ToUpper();
88  a = 0;
89  z = 0;
90  if (b.EqualTo("P") || b.EqualTo("PROTON")) {
91  z = a = 1;
92  }
93  else if (b.EqualTo("A") || b.BeginsWidth("PB")) {
94  z = 82;
95  a = 208;
96  }
97  }
98  };
99  UInt_t beamEnergy; // Total energy in center of mass
100  UInt_t energy; // Center of mass energy per nucleon
101  TString period; // The period
102  UInt_t run; // The run number
103  Beam beam1; // Target beam
104  Beam beam2; // Projectile beam
111  : beamEnergy(0), energy(0), period(""), beam1(), beam2(), run(r)
112  {
113  Info("GRP", "Will try from file %s", FileName());
114  if (!ReadFromFile()) {
115  Warning("GRP", "Failed to read from file, trying from OCDB");
116  if (!ReadFromOCDB(run))
117  Fatal("GRP", "Failed to get GRP values");
118  }
119  Print();
120  }
125  void Print()
126  {
127  Printf("%s run %d\n"
128  " Beam energy: %d GeV\n"
129  " sqrt(s_NN): %d GeV\n"
130  " Beam 1: %s (%d %d)\n"
131  " Beam 2: %s (%d %d)",
132  period.Data(), run, beamEnergy, energy,
133  beam1.Name(), beam1.a, beam1.z,
134  beam2.Name(), beam2.a, beam2.z);
135  }
141  Bool_t IsPP() const { return beam1.IsP() && beam2.IsP(); }
147  Bool_t IsPA() const { return beam1.IsP() && beam2.IsA(); }
153  Bool_t IsAP() const { return beam1.IsA() && beam2.IsP(); }
159  Bool_t IsAA() const { return beam1.IsA() && beam2.IsA(); }
160 
161  UInt_t CMEnergy(UShort_t how=0) const
162  {
163  switch (how) {
164  case 1:
165  return UInt_t(2*TMath::Sqrt(Float_t(beam1.z*beam2.z)/beam1.a/beam2.a)
166  * beamEnergy);
167  case 2:
168  return
169  UInt_t(TMath::Sqrt(TMath::Power(BeamEnergy(1)+BeamEnergy(2),2)-
170  TMath::Power(BeamMomentum(1)-BeamMomentum(2),2)));
171 
172  }
173  return energy;
174  }
176  {
177  switch (which) {
178  case 1: return beam1.GetEnergy(beamEnergy);
179  case 2: return beam2.GetEnergy(beamEnergy);
180  }
181  return beamEnergy;
182  }
184  {
185  switch (which) {
186  case 1: return beam1.GetMomentum(beamEnergy);
187  case 2: return beam2.GetMomentum(beamEnergy);
188  }
189  return beamEnergy;
190  }
196  UInt_t Year() const
197  {
198  TString tmp = period(3,2);
199  return tmp.Atoi() + 2000;
200  }
201  const char* FileName() const { return "grp.dat"; }
209  static UInt_t Obj2UInt(const TObject* o)
210  {
211  return (static_cast<TObjString*>(o))->String().Atoi();
212  }
219  {
220  if (gSystem->AccessPathName(FileName())) {
221  Info("GRP", "Cannot open file %s", FileName());
222  return false;
223  }
224 
225  std::ifstream* pin = new std::ifstream("grp.dat");
226  std::ifstream& in = *pin;
227  TString line;
228  TString env;
229  do {
230  line.ReadLine(in);
231  if (line.IsNull()) continue;
232  if (line[0] == '#') continue;
233  env = line;
234  break;
235  } while (!in.eof());
236  if (env.IsNull()) {
237  Info("GRP", "No line found");
238  return false;
239  }
240  Info("GRP", "Got the line %s", env.Data());
241  TObjArray* tokens = env.Tokenize(":");
242  if (tokens->GetEntries() < 8) {
243  Warning("GRP", "Failed to get enough field from GRP_SUMMARY=%s",
244  env.Data());
245  return false;
246  }
247  period = tokens->At(0)->GetName();
248  run = Obj2UInt(tokens->At(1));
249  beamEnergy = Obj2UInt(tokens->At(2));
250  energy = Obj2UInt(tokens->At(3));
251  beam1.a = Obj2UInt(tokens->At(4));
252  beam1.z = Obj2UInt(tokens->At(5));
253  beam2.a = Obj2UInt(tokens->At(6));
254  beam2.z = Obj2UInt(tokens->At(7));
255  pin->close();
256  delete pin;
257  return true;
258  }
267  {
268  AliCDBManager* cdb = AliCDBManager::Instance();
269  cdb->SetDefaultStorageFromRun(r);
270  cdb->SetRun(r);
271  AliCDBEntry* ent = cdb->Get("GRP/GRP/Data");
272  if (!ent) {
273  Warning("GRP", "No GRP data found");
274  cdb->SetRun(-1);
275  return false;
276  }
277  // Info("GRP", "Got GRP");
278  // ent->PrintMetaData();
279 
280  AliGRPObject* obj = static_cast<AliGRPObject*>(ent->GetObject());
281  // obj->Dump();
282  run = r;
283  period = obj->GetLHCPeriod();
284  beamEnergy = TMath::Ceil(obj->GetBeamEnergy());
285  TString beam1T = obj->GetSingleBeamType(0);
286  TString beam2T = obj->GetSingleBeamType(1);
287 
288  if (!beam1T.IsNull() && !beam2T.IsNull()) {
289  beam1.Set(beam1T.Atoi());
290  beam2.Set(beam2T.Atoi());
291  }
292  else {
293  TString beamType = obj->GetBeamType();
294  if (beamType.IsNull()) {
295  Warning("GRP", "No beam type");
296  cdb->SetRun(-1);
297  return false;
298  }
299 
300  TObjArray* ab = beamType.Tokenize("-");
301  ab->ls();
302  beam1T = ab->At(0)->GetName();
303  beam2T = ab->At(1)->GetName();
304  beam1.Set(beam1T);
305  beam2.Set(beam2T);
306  }
307  if (beam1.IsA() && beam2.IsA()) {
308  // Revert calculation done in AliGRPObject - sigh
309  beamEnergy *= 208./82;
310  }
311  // Massage the beam energy in case we had sqrt{s_NN} instead of
312  // beam energy.
313  if (TMath::Abs(beamEnergy - 1379.8) < 10 && beam1.IsA() && beam2.IsA())
314  beamEnergy = 3500;
315  Float_t sNN = 2*beamEnergy *
316  TMath::Sqrt(Float_t(beam1.z*beam2.z)/(beam1.a*beam2.a));
317  energy = (TMath::Abs(sNN - 2760) < 10 ? 2760 :
318  TMath::Abs(sNN - 5023) < 10 ? 5023 :
319  TMath::Abs(sNN - 5100) < 30 ? 5100 :
320  TMath::Abs(sNN - 5440) < 30 ? 5440 :
321  TMath::Abs(sNN - 2360) < 10 ? 2360 :
322  TMath::Abs(sNN - 900) < 10 ? 900 :
323  TMath::Abs(sNN - 7000) < 10 ? 7000 :
324  TMath::Abs(sNN - 8000) < 10 ? 8000 :
325  TMath::Abs(sNN - 13000) < 10 ? 13000 :
326  0);
327 
328  const char* fn = FileName();
329  std::ofstream* pout = new std::ofstream(fn);
330  std::ofstream& out = *pout;
331  out << "# PERIOD:RUN:BEAMENERGY:ENERGY:BEAM1A:BEAM1Z:BEAM2A:BEAM2Z\n"
332  << period << ":"
333  << run << ":"
334  << beamEnergy << ":"
335  << energy << ":"
336  << beam1.a << ":"
337  << beam1.z << ":"
338  << beam2.a << ":"
339  << beam2.z << "\n"
340  << "# EOF " << std::endl;
341  pout->close();
342  delete pout;
343  cdb->SetRun(-1);
344  return true;
345  }
354  static UInt_t Env2UInt(const char* envName, UInt_t def)
355  {
356  TString val(gSystem->Getenv(envName));
357  if (val.IsNull()) return def;
358  return UInt_t(val.Atoll());
359  }
360 };
362 void GRP(UInt_t run=0)
363 {
364  grp = new GRPData(run);
365 }
366 //
367 // EOF
368 //
369 
370 
371 
372 
UInt_t run
Definition: GRP.C:102
double Double_t
Definition: External.C:58
UInt_t Year() const
Definition: GRP.C:196
Beam beam1
Definition: GRP.C:103
Bool_t IsPA() const
Definition: GRP.C:147
TSystem * gSystem
const char * FileName() const
Definition: GRP.C:201
const char * Name()
Definition: GRP.C:69
static UInt_t Env2UInt(const char *envName, UInt_t def)
Definition: GRP.C:354
Bool_t IsAA() const
Definition: GRP.C:159
void Set(const TString &b)
Definition: GRP.C:85
Definition: GRP.C:19
unsigned int UInt_t
Definition: External.C:33
float Float_t
Definition: External.C:68
Beam beam2
Definition: GRP.C:104
UInt_t CMEnergy(UShort_t how=0) const
Definition: GRP.C:161
UInt_t energy
Definition: GRP.C:100
static UInt_t Obj2UInt(const TObject *o)
Definition: GRP.C:209
Bool_t IsA() const
Definition: GRP.C:63
UInt_t beamEnergy
Definition: GRP.C:99
void Print()
Definition: GRP.C:125
TString period
Definition: GRP.C:101
GRPData(UInt_t r)
Definition: GRP.C:110
Double_t BeamEnergy(UShort_t which)
Definition: GRP.C:175
UInt_t a
Definition: GRP.C:27
void GRP(UInt_t run=0)
Definition: GRP.C:362
GRPData * grp
Definition: GRP.C:361
Bool_t IsPP() const
Definition: GRP.C:141
void Set(UInt_t b)
Definition: GRP.C:75
Float_t GetMomentum(Float_t e) const
Definition: GRP.C:46
Bool_t IsP() const
Definition: GRP.C:57
unsigned short UShort_t
Definition: External.C:28
Bool_t ReadFromOCDB(UInt_t r)
Definition: GRP.C:266
Double_t BeamMomentum(UShort_t which)
Definition: GRP.C:183
bool Bool_t
Definition: External.C:53
Float_t GetEnergy(Float_t e) const
Definition: GRP.C:35
Bool_t ReadFromFile()
Definition: GRP.C:218
Bool_t IsAP() const
Definition: GRP.C:153
UInt_t z
Definition: GRP.C:26