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