3 * @author Christian Holm Christensen <cholm@nbi.dk>
4 * @date Wed Aug 20 10:00:39 2014
6 * @brief Class that hold summary of GRP data.
13 * Class that hold summary of GRP data, and has methods to obtain
14 * these, either from a previously dumped file, or directly from OCDB.
16 * This is used by the simulation setup to ensure we have the proper
17 * beam settings for an anchor run.
29 * Get the per nucleon beam energy given a per charge beam energy
31 * @param e Per charge beam energy
33 * @return Per nucleon beam energy
35 Float_t GetEnergy(Float_t e) const
37 return e * sqrt(float(z)/a);
40 * Check if this is a proton
42 * @return True if z and a are 1
44 Bool_t IsP() const { return z == 1 && a == 1; }
46 * Check if this is a nucleus
48 * @return true if not P
50 Bool_t IsA() const { return !IsP(); }
52 * Get the beam type name
56 const char* Name() { return (IsP() ? "P" : IsA() ? "A" : ""); }
58 * Set the beam type from single beam spec from LHC
60 * @param b Beam type from LHC
68 * Set from either a full LHC spec or from ALICE spec
72 void Set(const TString& b)
77 if (b.EqualTo("P") || b.EqualTo("PROTON")) {
80 else if (b.EqualTo("A") || b.BeginsWidth("PB")) {
86 UInt_t beamEnergy; // Total energy in center of mass
87 UInt_t energy; // Center of mass energy per nucleon
88 TString period; // The period
89 UInt_t run; // The run number
90 Beam beam1; // Target beam
91 Beam beam2; // Projectile beam
98 : beamEnergy(0), energy(0), period(""), beam1(), beam2(), run(r)
100 Info("GRP", "Will try from file %s", FileName());
101 if (!ReadFromFile()) {
102 Warning("GRP", "Failed to read from file, trying from OCDB");
103 if (!ReadFromOCDB(run))
104 Fatal("GRP", "Failed to get GRP values");
115 " Beam energy: %d GeV\n"
116 " sqrt(s_NN): %d GeV\n"
117 " Beam 1: %s (%d %d)\n"
118 " Beam 2: %s (%d %d)",
119 period.Data(), run, beamEnergy, energy,
120 beam1.Name(), beam1.a, beam1.z,
121 beam2.Name(), beam2.a, beam2.z);
124 * Check if this run was a p-p run
126 * @return Return true if both beams are p
128 Bool_t IsPP() const { return beam1.IsP() && beam2.IsP(); }
130 * Check if this run was a p-A run
132 * @return Return true beam 1 is p and 2 is A
134 Bool_t IsPA() const { return beam1.IsP() && beam2.IsA(); }
136 * Check if this run was a A-p run
138 * @return Return true beam 1 is A and 2 is p
140 Bool_t IsAP() const { return beam1.IsA() && beam2.IsP(); }
142 * Check if this run was a A-A run
144 * @return Return true if both beams are A
146 Bool_t IsAA() const { return beam1.IsA() && beam2.IsA(); }
154 TString tmp = period(3,2);
155 return tmp.Atoi() + 2000;
157 const char* FileName() const { return "grp.dat"; }
159 * Get unsigned int value from string value of TObjString
165 static UInt_t Obj2UInt(const TObject* o)
167 return (static_cast<TObjString*>(o))->String().Atoi();
170 * Read values from a file
172 * @return true on success
174 Bool_t ReadFromFile()
176 if (gSystem->AccessPathName(FileName())) {
177 Info("GRP", "Cannot open file %s", FileName());
181 std::ifstream* pin = new std::ifstream("grp.dat");
182 std::ifstream& in = *pin;
187 if (line.IsNull()) continue;
188 if (line[0] == '#') continue;
193 Info("GRP", "No line found");
196 Info("GRP", "Got the line %s", env.Data());
197 TObjArray* tokens = env.Tokenize(":");
198 if (tokens->GetEntries() < 8) {
199 Warning("GRP", "Failed to get enough field from GRP_SUMMARY=%s",
203 period = tokens->At(0)->GetName();
204 run = Obj2UInt(tokens->At(1));
205 beamEnergy = Obj2UInt(tokens->At(2));
206 energy = Obj2UInt(tokens->At(3));
207 beam1.a = Obj2UInt(tokens->At(4));
208 beam1.z = Obj2UInt(tokens->At(5));
209 beam2.a = Obj2UInt(tokens->At(6));
210 beam2.z = Obj2UInt(tokens->At(7));
216 * Read values from OCDB. Also dumps values to file.
218 * @param r run number
220 * @return true on success
222 Bool_t ReadFromOCDB(UInt_t r)
224 AliCDBManager* cdb = AliCDBManager::Instance();
225 cdb->SetDefaultStorageFromRun(r);
227 AliCDBEntry* ent = cdb->Get("GRP/GRP/Data");
229 Warning("GRP", "No GRP data found");
233 // Info("GRP", "Got GRP");
234 // ent->PrintMetaData();
236 AliGRPObject* obj = static_cast<AliGRPObject*>(ent->GetObject());
239 period = obj->GetLHCPeriod();
240 beamEnergy = TMath::Ceil(obj->GetBeamEnergy());
241 TString beam1T = obj->GetSingleBeamType(0);
242 TString beam2T = obj->GetSingleBeamType(1);
244 if (!beam1T.IsNull() && !beam2T.IsNull()) {
245 beam1.Set(beam1T.Atoi());
246 beam2.Set(beam2T.Atoi());
249 TString beamType = obj->GetBeamType();
250 if (beamType.IsNull()) {
251 Warning("GRP", "No beam type");
256 TObjArray* ab = beamType.Tokenize("-");
258 beam1T = ab->At(0)->GetName();
259 beam2T = ab->At(1)->GetName();
263 // Massage the beam energy in case we had sqrt{s_NN} instead of
265 if (TMath::Abs(beamEnergy - 1379.8) < 10 && beam1.IsA() && beam2.IsA())
267 energy = TMath::Ceil(2*beamEnergy * TMath::Sqrt(Float_t(beam1.z*beam2.z)/
270 const char* fn = FileName();
271 std::ofstream* pout = new std::ofstream(fn);
272 std::ofstream& out = *pout;
273 out << "# PERIOD:RUN:BEAMENERGY:ENERGY:BEAM1A:BEAM1Z:BEAM2A:BEAM2Z\n"
282 << "# EOF " << std::endl;
289 * Get the value of an environment variable as a unsigned int
291 * @param envName Enviroment variable name
292 * @param def Default value
294 * @return As unsigned int, or default
296 static UInt_t Env2UInt(const char* envName, UInt_t def)
298 TString val(gSystem->Getenv(envName));
299 if (val.IsNull()) return def;
300 return UInt_t(val.Atoll());
304 void GRP(UInt_t run=0)
306 grp = new GRPData(run);