CbmRoot
Loading...
Searching...
No Matches
PairAnalysisMetaData.cxx
Go to the documentation of this file.
1/* Copyright (C) 2015-2021 Justus-Liebig-Universitaet Giessen, Giessen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Julian Book [committer] */
4
5/*
6 Meta data container that stores basic information on the setup, system,
7 beam/c.m.s. energy, selected events, cbmroot revision, date, ...
8
9 The DrawSame(TString opt) provides an easy way to add a standardised
10 caption to a plot.
11
12 */
13
14#include <TCollection.h>
15#include <TDatime.h>
16#include <TList.h>
17#include <TPad.h>
18#include <TROOT.h>
19#include <TSystem.h>
20// #include "TParamater<Int_t>.h"
21// #include "TParamater<Double_t>.h"
22#include <TGeoElement.h>
23#include <TNamed.h>
24#include <TParameter.h>
25#include <TPaveText.h>
26
28#include "URun.h"
29
31
32
34 : PairAnalysisMetaData("PairAnalysis_MetaData", "PairAnalysis MetaData Container")
35{
36 //
37 // Default constructor
38 //
39}
40
41//_____________________________________________________________________________
42PairAnalysisMetaData::PairAnalysisMetaData(const char* name, const char* title) : TNamed(name, title), fMetaList()
43{
44 //
45 // TNamed constructor
46 //
47 fMetaList.SetOwner(kTRUE);
48 fMetaList.SetName(name);
49}
50
51//_____________________________________________________________________________
53{
54 //
55 // Destructor
56 //
57 fMetaList.Clear();
58}
59
60//_____________________________________________________________________________
62{
63 //
64 // Init meta data objects and add to list
65 //
66
67 TNamed* pSetup = new TNamed("setup", "undefined");
68 // pSetup->SetTitle(gSystem->Getenv("USER")); //e.g. sis100
69 fMetaList.Add(pSetup);
70
71 TNamed* pSystem = new TNamed("system", "Au+Au");
72 // pSystem->SetTitle(gSystem->Getenv("USER"));
73 fMetaList.Add(pSystem);
74
75 TNamed* pProduction = new TNamed("production", "SIS");
76 // pProduction->SetTitle(gProduction->Getenv("USER"));
77 fMetaList.Add(pProduction);
78
79 TParameter<Double_t>* pBeamEnergy = new TParameter<Double_t>("beamenergy", 4.107);
80 // pBeamEnergy->SetBit(TParameter<Double_t>::kIsConst);
81 pBeamEnergy->SetBit(TParameter<Double_t>::kFirst);
82 fMetaList.Add(pBeamEnergy);
83
84 TParameter<Int_t>* pEvents = new TParameter<Int_t>("events", 0);
85 pEvents->SetMergeMode('+');
86 fMetaList.Add(pEvents);
87
88 TParameter<Bool_t>* pMC = new TParameter<Bool_t>("mc", kTRUE);
89 pMC->SetBit(TParameter<Bool_t>::kIsConst);
90 fMetaList.Add(pMC);
91
92
93 TNamed* pTrainOp = new TNamed("operator", "undefined");
94 pTrainOp->SetTitle(gSystem->Getenv("USER"));
95 fMetaList.Add(pTrainOp);
96
97 // TNamed *pRootVers = new TNamed("root", "XXX");
98 // pRootVers->SetTitle(gROOT->GetVersion());
99 TParameter<Int_t>* pRootVers = new TParameter<Int_t>("root", gROOT->GetVersionInt());
100 pRootVers->SetBit(TParameter<Int_t>::kIsConst);
101 fMetaList.Add(pRootVers);
102
103 gSystem->Setenv("CBMROOT_SVN_REVISION", gSystem->GetFromPipe("svnversion $VMCWORKDIR"));
104 TString rev = gSystem->Getenv("CBMROOT_SVN_REVISION");
105 TParameter<Int_t>* pCbmRev = new TParameter<Int_t>("cbmroot", 0);
106 pCbmRev->SetBit(TParameter<Int_t>::kIsConst);
107 pCbmRev->SetVal(rev.Atoi());
108 fMetaList.Add(pCbmRev);
109
110 TDatime dat;
111 TParameter<Int_t>* pDate = new TParameter<Int_t>("date", dat.GetDate());
112 pDate->SetBit(TParameter<Int_t>::kMin);
113 fMetaList.Add(pDate);
114
115 TParameter<Int_t>* pTime = new TParameter<Int_t>("time", dat.GetTime());
116 pTime->SetBit(TParameter<Int_t>::kMin);
117 fMetaList.Add(pTime);
118}
119
120//_____________________________________________________________________________
121void PairAnalysisMetaData::SetMetaData(TList& list, Bool_t setOwner /*=kTRUE*/)
122{
123 //
124 // set container classes to this instance. It will take onwnership!
125 //
127 TString name(GetName());
128 if (name == "PairAnalysisMetaData") SetName(list.GetName());
129 TIter next(&list);
130 TObject* o;
131 while ((o = next())) {
132 fMetaList.Add(o);
133 }
134 if (setOwner) {
135 list.SetOwner(kFALSE);
136 fMetaList.SetOwner(kTRUE);
137 }
138 else {
139 fMetaList.SetOwner(kFALSE);
140 }
141}
142
143void PairAnalysisMetaData::FillMeta(const char* name, Double_t val)
144{
145 //
146 // fill meta data of doubles
147 //
148 TParameter<Double_t>* par = dynamic_cast<TParameter<Double_t>*>(fMetaList.FindObject(name));
149 par->SetVal(val);
150}
151
152void PairAnalysisMetaData::FillMeta(const char* name, Int_t val)
153{
154 //
155 // fill meta data of integers
156 //
157 TParameter<Int_t>* par = dynamic_cast<TParameter<Int_t>*>(fMetaList.FindObject(name));
158 par->SetVal(val);
159}
160
161void PairAnalysisMetaData::FillMeta(const char* name, const char* val)
162{
163 //
164 // fill meta data of strings
165 //
166 TNamed* par = dynamic_cast<TNamed*>(fMetaList.FindObject(name));
167 par->SetTitle(val);
168}
169
170void PairAnalysisMetaData::GetMeta(const char* name, Int_t* val)
171{
172 //
173 // get meta data value for integers
174 //
175 TParameter<Int_t>* par = dynamic_cast<TParameter<Int_t>*>(fMetaList.FindObject(name));
176 if (par) *val = par->GetVal();
177}
178
179void PairAnalysisMetaData::GetMeta(const char* name, Double_t* val)
180{
181 //
182 // get meta data value for doubles
183 //
184 TParameter<Double_t>* par = dynamic_cast<TParameter<Double_t>*>(fMetaList.FindObject(name));
185 if (par) *val = par->GetVal();
186}
187
188void PairAnalysisMetaData::DrawSame(TString opt /*="msb"*/)
189{
190 //
191 // draw meta data into current pad
192 // use option string to select information displayed:
193 // m := mc -> 'Simulation'
194 // s := system e.g. 'Au+Au', 'p+Au'
195 // b := lab beam energy Ebeam
196 // S := sqrt s_NN
197 // n := number of events (after event selection)
198 //
199 if (fMetaList.GetEntries() < 1) return;
200
201 TPaveText* pt = new TPaveText(gPad->GetLeftMargin() + 0.05, 1. - gPad->GetTopMargin() + 0.01,
202 1. - gPad->GetRightMargin() - 0.05, 0.99, "NDCNB");
203 pt->SetName("meta");
204 pt->SetTextAlign(kHAlignLeft + kVAlignCenter);
205 pt->SetMargin(0.01); //default 0.05
206
207 TString line = "CBM";
208 TString tmp = "";
209
210 // simulation (only if true)
211 TParameter<Bool_t>* parB = dynamic_cast<TParameter<Bool_t>*>(fMetaList.FindObject("mc"));
212 if (opt.Contains("m") && parB && parB->GetVal()) {
213 tmp = Form(" Simulation");
214 line += tmp;
215 }
216
217 // system
218 TNamed* par = dynamic_cast<TNamed*>(fMetaList.FindObject("system"));
219 if (opt.Contains("s") && par) tmp = par->GetTitle();
220 if (!tmp.IsNull()) line += ", " + tmp;
221
222 // beamenergy
223 TParameter<Double_t>* parD = dynamic_cast<TParameter<Double_t>*>(fMetaList.FindObject("beamenergy"));
224 if (opt.Contains("b") && parD) {
225 if (tmp.Contains("p")) tmp = Form("#it{E}_{beam} = %.2f GeV", parD->GetVal());
226 else
227 tmp = Form("#it{E}_{beam} = %.2f #it{A}GeV", parD->GetVal());
228 if (!tmp.IsNull()) line += " " + tmp;
229 }
230 else if (opt.Contains("S") && parD) {
231 TString sys(par->GetTitle());
232 sys.ReplaceAll("+", "");
233 sys.ReplaceAll("-", "");
234 Int_t aProj = 0;
235 Int_t zProj = 0;
236 Int_t aTarg = 0;
237 Int_t zTarg = 0;
238
239 if (sys.EqualTo("pp")) {
240 aProj = 1;
241 zProj = 1;
242 aTarg = 1;
243 zTarg = 1;
244 }
245 else {
247 TGeoElementTable g(0);
248 TString targ = (sys(sys.Length() - 2, sys.Length()));
249 TString proj = (sys(0, sys.Length() - 2));
250 proj.ReplaceAll("p", "H");
251 aProj = g.FindElement(proj.Data())->A() + 0.05; // add a small number to get proper rounding (e.g. Au: 196->197)
252 zProj = g.FindElement(proj.Data())->Z();
253 aTarg = g.FindElement(targ.Data())->A() + 0.05;
254 zTarg = g.FindElement(targ.Data())->Z();
255 }
256 // else if(sys.EqualTo("pAu")) { aProj=1; zProj=1; aTarg=197; zTarg=79; }
257 // else if(sys.EqualTo("pNi")) { aProj=1; zProj=1; aTarg=58; zTarg=28; }
258 // else if(sys.EqualTo("AuAu")) { aProj=197; zProj=79; aTarg=197; zTarg=79; }
259 // else if(sys.EqualTo("AgAg")) { aProj=107; zProj=47; aTarg=107; zTarg=47; }
260 // else if(sys.EqualTo("NiNi")) { aProj=58; zProj=28; aTarg=58; zTarg=28; }
261 // else if(sys.EqualTo("NiAu")) { aProj=58; zProj=28; aTarg=197; zTarg=79; }
262 // else if(sys.EqualTo("AgAu")) { aProj=107; zProj=47; aTarg=197; zTarg=79; }
263 // Get the cm energy, according to URun::GetNNSqrtS
264 URun run("", "", aProj, zProj, parD->GetVal(), aTarg, zTarg, 0., 0., 0., 0, 0., 0., 0., 0);
265 tmp = Form("#sqrt{#it{s}_{NN}} = %.2f GeV", run.GetNNSqrtS());
266 if (!tmp.IsNull()) line += " " + tmp;
267 }
268
269 // events
270 TParameter<Int_t>* parI = dynamic_cast<TParameter<Int_t>*>(fMetaList.FindObject("events"));
271 if (opt.Contains("n") && parD) {
272 // tmp=Form("#it{N}_{evt} = %.1f#times10^{6}",parI->GetVal()/1.e+6);
273 tmp = Form("#it{N}_{evt} = %.1fM", parI->GetVal() / 1.e+6);
274 if (!tmp.IsNull()) line += ", " + tmp;
275 }
276
277 pt->AddText(line.Data());
278
279
280 pt->SetLineColorAlpha(0, 0.0);
281 pt->SetFillColorAlpha(0, 0.0);
282 pt->SetFillStyle(kFEmpty);
283 // pt->Print();
284 pt->Draw();
285}
ClassImp(PairAnalysisMetaData) PairAnalysisMetaData
void SetMetaData(TList &list, Bool_t setOwner=kTRUE)
void DrawSame(TString opt="msb")
void FillMeta(const char *name, Double_t val)
void GetMeta(const char *name, Int_t *val)
Definition URun.h:12
Double_t GetNNSqrtS()
Definition URun.cxx:152