]>
Commit | Line | Data |
---|---|---|
1 | // | |
2 | // Author: Michele Floris APR2011 | |
3 | // Derived by root's the statusBar.C tutorial | |
4 | // This macro allows to browse the OADB of the spectra | |
5 | ||
6 | ||
7 | #include <TApplication.h> | |
8 | #include <TGClient.h> | |
9 | #include <TGButton.h> | |
10 | #include <TGFrame.h> | |
11 | #include <TFrame.h> | |
12 | #include <TRootEmbeddedCanvas.h> | |
13 | #include <TGStatusBar.h> | |
14 | #include <TGComboBox.h> | |
15 | #include <TCanvas.h> | |
16 | #include <TF1.h> | |
17 | #include <TRandom.h> | |
18 | #include <TGraph.h> | |
19 | #include <TAxis.h> | |
20 | #include <AliOADBPWG2Spectra.h> | |
21 | #include "TSystem.h" | |
22 | #include "AliOADBContainer.h" | |
23 | #include <TGTextEntry.h> | |
24 | #include "TFile.h" | |
25 | #include <iostream> | |
26 | #include "TH1D.h" | |
27 | #include "TInterpreter.h" | |
28 | #include "AliBWFunc.h" | |
29 | #include "TDatabasePDG.h" | |
30 | ||
31 | using namespace std; | |
32 | ||
33 | ||
34 | ||
35 | class MyMainFrame : public TGMainFrame { | |
36 | ||
37 | private: | |
38 | TRootEmbeddedCanvas *fEcan; // embedded canvas | |
39 | TGStatusBar *fStatusBar;// status bar | |
40 | TGComboBox *fComboDetector;//detectors | |
41 | TGComboBox *fComboParticle;//particle | |
42 | TGComboBox *fComboCharge;//charge | |
43 | TGComboBox *fComboPID;//PID | |
44 | TGComboBox *fComboContainer;//container | |
45 | TGTextEntry *fRunNumber; // run number | |
46 | TGComboBox *fComboCentr; // centr tag | |
47 | TGTextEntry *fTextCentrBin; // centrality bin | |
48 | TGTextEntry *fTextDrawOpt; // draw opt | |
49 | TGTextEntry *fTextSaveName; // save name | |
50 | AliOADBPWG2Spectra *fOADBSpectra; // spectra OADB | |
51 | AliOADBContainer *fOADBContainer; // OADB container | |
52 | ||
53 | Double_t fMass[3]; //masses | |
54 | AliBWFunc * fFuncMan; // functions | |
55 | static const char * fkContainers[]; | |
56 | static const Int_t fkNContainers ; | |
57 | static const char * fkCentrTags[]; | |
58 | static const Int_t fkNCentrTags ; | |
59 | ||
60 | public: | |
61 | MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h); | |
62 | virtual ~MyMainFrame(); | |
63 | void DoExit(); | |
64 | void DoDraw(); | |
65 | void DoRatio(); | |
66 | void DoFit(); | |
67 | void DoLegend(); | |
68 | void DoLoad(); | |
69 | void DoClear(); | |
70 | void DoPrint(); | |
71 | void DoSelectedDetector(Int_t id); | |
72 | void SetStatusText(const char *txt, Int_t pi); | |
73 | void EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected); | |
74 | ||
75 | ClassDef(MyMainFrame, 0) | |
76 | }; | |
77 | ||
78 | const char * MyMainFrame::fkContainers[] = {"Corrected", "Raw"}; | |
79 | const Int_t MyMainFrame::fkNContainers = 2; | |
80 | const char * MyMainFrame::fkCentrTags[] = {"V0M", "MB", "Ntracks", "SPD2"}; | |
81 | const Int_t MyMainFrame::fkNCentrTags = 4; | |
82 | ||
83 | void MyMainFrame::DoSelectedDetector(Int_t id) { | |
84 | // Change the analysis type based on the detector | |
85 | cout << "ID " << id << endl; | |
86 | if (id == AliOADBPWG2Spectra::kTOFTPC) { | |
87 | fComboPID->Select(AliOADBPWG2Spectra::kNSigma); | |
88 | } | |
89 | else { | |
90 | fComboPID->Select(AliOADBPWG2Spectra::kGaussFit); | |
91 | } | |
92 | ||
93 | } | |
94 | ||
95 | void MyMainFrame::DoFit() | |
96 | { | |
97 | // print to file | |
98 | static TF1 * func = 0; | |
99 | if(func) delete func; | |
100 | func = fFuncMan->GetLevi(fMass[fComboParticle->GetSelected()], 0.12, 7, 1.5); | |
101 | TCanvas *c1 = fEcan->GetCanvas(); | |
102 | TH1D * h = (TH1D*) c1->GetListOfPrimitives()->At(c1->GetListOfPrimitives()->GetEntries()-1); | |
103 | h->Fit(func,"","same"); | |
104 | c1->Update(); | |
105 | c1->Modified(); | |
106 | c1->Update(); | |
107 | ||
108 | } | |
109 | ||
110 | void MyMainFrame::DoPrint() | |
111 | { | |
112 | // print to file | |
113 | TCanvas *c1 = fEcan->GetCanvas(); | |
114 | c1->Print(fTextSaveName->GetText()); | |
115 | } | |
116 | void MyMainFrame::DoClear() | |
117 | { | |
118 | // clear canvas | |
119 | TCanvas *c1 = fEcan->GetCanvas(); | |
120 | c1->Clear(); | |
121 | c1->Update(); | |
122 | c1->Modified(); | |
123 | c1->Update(); | |
124 | ||
125 | } | |
126 | ||
127 | void MyMainFrame::DoLoad() | |
128 | { | |
129 | // Load file | |
130 | cout << "Getting " << fkContainers[fComboContainer->GetSelected()] << endl; | |
131 | cout << fRunNumber->GetText() << endl; | |
132 | ||
133 | TString fileName = AliOADBPWG2Spectra::GetOADBPWG2SpectraFileName(); | |
134 | TFile * f = new TFile (fileName); | |
135 | fOADBContainer = (AliOADBContainer*) f->Get(fkContainers[fComboContainer->GetSelected()]); | |
136 | if(!fOADBContainer) return; | |
137 | f->Close(); | |
138 | fOADBSpectra = (AliOADBPWG2Spectra*) fOADBContainer->GetObject(atoi(fRunNumber->GetText() )); | |
139 | if(!fOADBSpectra) fOADBContainer->List(); | |
140 | fOADBSpectra->Print(); | |
141 | } | |
142 | ||
143 | void MyMainFrame::DoLegend() | |
144 | { | |
145 | // legend | |
146 | gInterpreter->ProcessLine("NewLegend(\"\", \"lpf\",0,1,0);"); | |
147 | TCanvas *c1 = fEcan->GetCanvas(); | |
148 | c1->Update(); | |
149 | c1->Modified(); | |
150 | c1->Update(); | |
151 | } | |
152 | void MyMainFrame::DoRatio() { | |
153 | // Divide 2 histos on canvas | |
154 | gInterpreter->ProcessLine("Divide2HistosOnCanvas();"); | |
155 | } | |
156 | ||
157 | ||
158 | void MyMainFrame::DoDraw() | |
159 | { | |
160 | // Draw something in the canvas | |
161 | ||
162 | Printf("Slot DoDraw()"); | |
163 | cout << "DET " << fComboDetector->GetSelected() << endl; | |
164 | if(!fOADBSpectra) { | |
165 | cout << "spectra not loaded" << endl; | |
166 | DoLoad(); | |
167 | if(!fOADBSpectra) { | |
168 | cout << "ERROR: Cannot load spectra" << endl; | |
169 | return; | |
170 | } | |
171 | } | |
172 | ||
173 | TCanvas *c1 = fEcan->GetCanvas(); | |
174 | c1->cd(); | |
175 | TH1D * h = 0; | |
176 | if(strcmp(fkCentrTags[fComboCentr->GetSelected()],"")){ | |
177 | h = fOADBSpectra->GetHisto(fComboDetector->GetSelected(), | |
178 | fComboPID->GetSelected(), | |
179 | fComboParticle->GetSelected(), | |
180 | fComboCharge->GetSelected(), | |
181 | fkCentrTags[fComboCentr->GetSelected()], | |
182 | atoi(fTextCentrBin->GetText())); | |
183 | ||
184 | } | |
185 | else { | |
186 | h = fOADBSpectra->GetHisto(fComboDetector->GetSelected(), | |
187 | fComboPID->GetSelected(), | |
188 | fComboParticle->GetSelected(), | |
189 | fComboCharge->GetSelected()); | |
190 | ||
191 | } | |
192 | // Draw the selected histogram | |
193 | ||
194 | if(!h) { | |
195 | cout << "Cannot get pointer to histo" << endl; | |
196 | ||
197 | cout << fkCentrTags[fComboCentr->GetSelected()] << " " << | |
198 | ||
199 | fOADBSpectra->GetHistoName(fComboDetector->GetSelected(), | |
200 | fComboPID->GetSelected(), | |
201 | fComboParticle->GetSelected(), | |
202 | fComboCharge->GetSelected(), | |
203 | fkCentrTags[fComboCentr->GetSelected()], | |
204 | atoi(fTextCentrBin->GetText())) | |
205 | << endl; | |
206 | ||
207 | return; | |
208 | } | |
209 | TString opt = fTextDrawOpt->GetText(); | |
210 | if(opt=="auto") { | |
211 | c1->GetListOfPrimitives()->Print(); | |
212 | if (c1->GetListOfPrimitives()->GetEntries()>0) opt = "same"; | |
213 | else opt = ""; | |
214 | } | |
215 | ||
216 | h->SetXTitle("p_{T} (GeV/c)"); | |
217 | // h->SetXTitle("dN/dp_{T}"); | |
218 | h->Draw(opt); | |
219 | ||
220 | // TCanvas::Update() draws the frame, after which it can be changed | |
221 | c1->Update(); | |
222 | c1->Modified(); | |
223 | c1->Update(); | |
224 | } | |
225 | ||
226 | void MyMainFrame::DoExit() | |
227 | { | |
228 | printf("Exit application..."); | |
229 | gApplication->Terminate(0); | |
230 | } | |
231 | ||
232 | void MyMainFrame::SetStatusText(const char *txt, Int_t pi) | |
233 | { | |
234 | // Set text in status bar. | |
235 | fStatusBar->SetText(txt,pi); | |
236 | } | |
237 | ||
238 | void MyMainFrame::EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected) | |
239 | { | |
240 | // Writes the event status in the status bar parts | |
241 | ||
242 | const char *text0, *text1, *text3; | |
243 | char text2[50]; | |
244 | text0 = selected->GetTitle(); | |
245 | SetStatusText(text0,0); | |
246 | text1 = selected->GetName(); | |
247 | SetStatusText(text1,1); | |
248 | if (event == kKeyPress) | |
249 | sprintf(text2, "%c", (char) px); | |
250 | else | |
251 | sprintf(text2, "%d,%d", px, py); | |
252 | SetStatusText(text2,2); | |
253 | text3 = selected->GetObjectInfo(px,py); | |
254 | SetStatusText(text3,3); | |
255 | } | |
256 | ||
257 | MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) : | |
258 | TGMainFrame(p, w, h), fOADBContainer(0), fOADBSpectra(0) | |
259 | { | |
260 | // Create a horizontal frame (canvas and status bar on the left, buttons on the right) | |
261 | TGHorizontalFrame *hframeMain = new TGHorizontalFrame(this, 200, 40); | |
262 | ||
263 | // Create a vertical frame for the canvas and for the status bar | |
264 | TGVerticalFrame *vframeCanvas = new TGVerticalFrame(this, 200, 40); | |
265 | ||
266 | // Create the embedded canvas | |
267 | fEcan = new TRootEmbeddedCanvas(0,this,500,400); | |
268 | Int_t wid = fEcan->GetCanvasWindowId(); | |
269 | TCanvas *myc = new TCanvas("MyCanvas", 10,10,wid); | |
270 | cout << myc << endl; | |
271 | ||
272 | fEcan->AdoptCanvas(myc); | |
273 | myc->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)","MyMainFrame",this, | |
274 | "EventInfo(Int_t,Int_t,Int_t,TObject*)"); | |
275 | ||
276 | vframeCanvas->AddFrame(fEcan, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY,0,0,1,1)); | |
277 | // status bar | |
278 | Int_t parts[] = {45, 15, 10, 30}; | |
279 | fStatusBar = new TGStatusBar(this, 50, 10, kVerticalFrame); | |
280 | fStatusBar->SetParts(parts, 4); | |
281 | fStatusBar->Draw3DCorner(kFALSE); | |
282 | vframeCanvas->AddFrame(fStatusBar, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0)); | |
283 | ||
284 | hframeMain->AddFrame(vframeCanvas, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2)); | |
285 | ||
286 | // Create a vertical frame containing buttons and controls | |
287 | TGVerticalFrame *vframeButtons = new TGVerticalFrame(this, 200, 40); | |
288 | ||
289 | // Container | |
290 | fComboContainer = new TGComboBox(vframeButtons); | |
291 | vframeButtons->AddFrame(fComboContainer, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
292 | for(Int_t icont = 0; icont < fkNContainers; icont++){ | |
293 | fComboContainer->AddEntry(fkContainers[icont],icont); | |
294 | } | |
295 | fComboContainer->Select(0); | |
296 | fComboContainer->Resize(120,20); | |
297 | fRunNumber = new TGTextEntry (vframeButtons, "116562"); | |
298 | vframeButtons->AddFrame(fRunNumber, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
299 | ||
300 | ||
301 | TGTextButton *load = new TGTextButton(vframeButtons, "&Load"); | |
302 | load->Connect("Clicked()", "MyMainFrame", this, "DoLoad()"); | |
303 | vframeButtons->AddFrame(load, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
304 | ||
305 | // Combos | |
306 | fComboDetector = new TGComboBox(vframeButtons); | |
307 | vframeButtons->AddFrame(fComboDetector, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
308 | for(Int_t idet = 0; idet < AliOADBPWG2Spectra::kNDetectors; idet++){ | |
309 | fComboDetector->AddEntry(AliOADBPWG2Spectra::GetDetectorName(idet),idet); | |
310 | } | |
311 | fComboDetector->Resize(120,20); | |
312 | fComboDetector->Select(1); | |
313 | fComboDetector->Connect("Selected(Int_t)", "MyMainFrame", this, "DoSelectedDetector(Int_t)"); | |
314 | ||
315 | fComboPID = new TGComboBox(vframeButtons); | |
316 | vframeButtons->AddFrame(fComboPID, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
317 | for(Int_t idet = 0; idet < AliOADBPWG2Spectra::kNPIDTypes; idet++){ | |
318 | fComboPID->AddEntry(AliOADBPWG2Spectra::GetPIDName(idet),idet); | |
319 | } | |
320 | fComboPID->Resize(120,20); | |
321 | fComboPID->Select(0); | |
322 | ||
323 | fComboCharge = new TGComboBox(vframeButtons); | |
324 | vframeButtons->AddFrame(fComboCharge, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
325 | for(Int_t idet = 0; idet < AliOADBPWG2Spectra::kNCharge; idet++){ | |
326 | fComboCharge->AddEntry(AliOADBPWG2Spectra::GetChargeName(idet),idet); | |
327 | } | |
328 | fComboCharge->Resize(120,20); | |
329 | fComboCharge->Select(0); | |
330 | ||
331 | fComboParticle = new TGComboBox(vframeButtons); | |
332 | vframeButtons->AddFrame(fComboParticle, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
333 | for(Int_t idet = 0; idet < AliOADBPWG2Spectra::kNParticle; idet++){ | |
334 | fComboParticle->AddEntry(AliOADBPWG2Spectra::GetParticleName(idet),idet); | |
335 | } | |
336 | fComboParticle->Resize(120,20); | |
337 | fComboParticle->Select(0); | |
338 | ||
339 | fComboCentr = new TGComboBox(vframeButtons); | |
340 | vframeButtons->AddFrame(fComboCentr, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
341 | for(Int_t icentr = 0; icentr < fkNCentrTags; icentr++){ | |
342 | fComboCentr->AddEntry(fkCentrTags[icentr],icentr); | |
343 | } | |
344 | fComboCentr->Resize(120,20); | |
345 | fComboCentr->Select(0); | |
346 | ||
347 | // Text fields | |
348 | fTextCentrBin = new TGTextEntry (vframeButtons, "1"); | |
349 | fTextCentrBin->Resize(120,20); | |
350 | vframeButtons->AddFrame(fTextCentrBin, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
351 | fTextDrawOpt = new TGTextEntry (vframeButtons, "auto"); | |
352 | vframeButtons->AddFrame(fTextDrawOpt, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
353 | fTextDrawOpt->Resize(120,20); | |
354 | fTextSaveName = new TGTextEntry (vframeButtons, "spectra.png"); | |
355 | vframeButtons->AddFrame(fTextSaveName, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
356 | fTextSaveName->Resize(120,20); | |
357 | ||
358 | // buttons | |
359 | TGTextButton *draw = new TGTextButton(vframeButtons, "&Draw"); | |
360 | draw->Connect("Clicked()", "MyMainFrame", this, "DoDraw()"); | |
361 | vframeButtons->AddFrame(draw, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
362 | TGTextButton *legend = new TGTextButton(vframeButtons, "&Legend"); | |
363 | legend->Connect("Clicked()", "MyMainFrame", this, "DoLegend()"); | |
364 | vframeButtons->AddFrame(legend, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
365 | TGTextButton *ratio = new TGTextButton(vframeButtons, "&Ratio"); | |
366 | ratio->Connect("Clicked()", "MyMainFrame", this, "DoRatio()"); | |
367 | vframeButtons->AddFrame(ratio, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
368 | TGTextButton *clear = new TGTextButton(vframeButtons, "&Clear"); | |
369 | clear->Connect("Clicked()", "MyMainFrame", this, "DoClear()"); | |
370 | vframeButtons->AddFrame(clear, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
371 | TGTextButton *print = new TGTextButton(vframeButtons, "&Print"); | |
372 | print->Connect("Clicked()", "MyMainFrame", this, "DoPrint()"); | |
373 | vframeButtons->AddFrame(print, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
374 | TGTextButton *fit = new TGTextButton(vframeButtons, "&Fit"); | |
375 | fit->Connect("Clicked()", "MyMainFrame", this, "DoFit()"); | |
376 | vframeButtons->AddFrame(fit, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
377 | TGTextButton *exit = new TGTextButton(vframeButtons, "&Exit "); | |
378 | exit->Connect("Pressed()", "MyMainFrame", this, "DoExit()"); | |
379 | vframeButtons->AddFrame(exit, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); | |
380 | ||
381 | ||
382 | ||
383 | ||
384 | hframeMain->AddFrame(vframeButtons, new TGLayoutHints(kLHintsRight, 2, 2, 2, 2)); | |
385 | ||
386 | AddFrame(hframeMain,new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2)); | |
387 | ||
388 | // Set a name to the main frame | |
389 | SetWindowName("Spectra OADB Browser"); | |
390 | MapSubwindows(); | |
391 | ||
392 | // Initialize the layout algorithm via Resize() | |
393 | Resize(GetDefaultSize()); | |
394 | ||
395 | // Map main frame | |
396 | MapWindow(); | |
397 | ||
398 | // Misc init | |
399 | fMass[AliOADBPWG2Spectra::kPion] = TDatabasePDG::Instance()->GetParticle("pi+")->Mass(); | |
400 | fMass[AliOADBPWG2Spectra::kKaon] = TDatabasePDG::Instance()->GetParticle("K+")->Mass(); | |
401 | fMass[AliOADBPWG2Spectra::kProton] = TDatabasePDG::Instance()->GetParticle("proton")->Mass(); | |
402 | ||
403 | fFuncMan = new AliBWFunc; | |
404 | fFuncMan->SetVarType(AliBWFunc::kdNdpt); | |
405 | ||
406 | } | |
407 | ||
408 | ||
409 | MyMainFrame::~MyMainFrame() | |
410 | { | |
411 | // Clean up main frame... | |
412 | Cleanup(); | |
413 | delete fEcan; | |
414 | } | |
415 | ||
416 | ||
417 | void spectraOADBGUI() | |
418 | { | |
419 | // Popup the GUI... | |
420 | ||
421 | new MyMainFrame(gClient->GetRoot(), 200, 200); | |
422 | } |