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
7 #include <TApplication.h>
12 #include <TRootEmbeddedCanvas.h>
13 #include <TGStatusBar.h>
14 #include <TGComboBox.h>
20 #include <AliOADBPWG2Spectra.h>
22 #include "AliOADBContainer.h"
23 #include <TGTextEntry.h>
27 #include "TInterpreter.h"
28 #include "AliBWFunc.h"
29 #include "TDatabasePDG.h"
35 class MyMainFrame : public TGMainFrame {
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
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 ;
61 MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
62 virtual ~MyMainFrame();
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);
75 ClassDef(MyMainFrame, 0)
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;
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);
90 fComboPID->Select(AliOADBPWG2Spectra::kGaussFit);
95 void MyMainFrame::DoFit()
98 static TF1 * func = 0;
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");
110 void MyMainFrame::DoPrint()
113 TCanvas *c1 = fEcan->GetCanvas();
114 c1->Print(fTextSaveName->GetText());
116 void MyMainFrame::DoClear()
119 TCanvas *c1 = fEcan->GetCanvas();
127 void MyMainFrame::DoLoad()
130 cout << "Getting " << fkContainers[fComboContainer->GetSelected()] << endl;
131 cout << fRunNumber->GetText() << endl;
133 TString fileName = AliOADBPWG2Spectra::GetOADBPWG2SpectraFileName();
134 TFile * f = new TFile (fileName);
135 fOADBContainer = (AliOADBContainer*) f->Get(fkContainers[fComboContainer->GetSelected()]);
136 if(!fOADBContainer) return;
138 fOADBSpectra = (AliOADBPWG2Spectra*) fOADBContainer->GetObject(atoi(fRunNumber->GetText() ));
139 if(!fOADBSpectra) fOADBContainer->List();
140 fOADBSpectra->Print();
143 void MyMainFrame::DoLegend()
146 gInterpreter->ProcessLine("NewLegend(\"\", \"lpf\",0,1,0);");
147 TCanvas *c1 = fEcan->GetCanvas();
152 void MyMainFrame::DoRatio() {
153 // Divide 2 histos on canvas
154 gInterpreter->ProcessLine("Divide2HistosOnCanvas();");
158 void MyMainFrame::DoDraw()
160 // Draw something in the canvas
162 Printf("Slot DoDraw()");
163 cout << "DET " << fComboDetector->GetSelected() << endl;
165 cout << "spectra not loaded" << endl;
168 cout << "ERROR: Cannot load spectra" << endl;
173 TCanvas *c1 = fEcan->GetCanvas();
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()));
186 h = fOADBSpectra->GetHisto(fComboDetector->GetSelected(),
187 fComboPID->GetSelected(),
188 fComboParticle->GetSelected(),
189 fComboCharge->GetSelected());
192 // Draw the selected histogram
195 cout << "Cannot get pointer to histo" << endl;
197 cout << fkCentrTags[fComboCentr->GetSelected()] << " " <<
199 fOADBSpectra->GetHistoName(fComboDetector->GetSelected(),
200 fComboPID->GetSelected(),
201 fComboParticle->GetSelected(),
202 fComboCharge->GetSelected(),
203 fkCentrTags[fComboCentr->GetSelected()],
204 atoi(fTextCentrBin->GetText()))
209 TString opt = fTextDrawOpt->GetText();
211 c1->GetListOfPrimitives()->Print();
212 if (c1->GetListOfPrimitives()->GetEntries()>0) opt = "same";
216 h->SetXTitle("p_{T} (GeV/c)");
217 // h->SetXTitle("dN/dp_{T}");
220 // TCanvas::Update() draws the frame, after which it can be changed
226 void MyMainFrame::DoExit()
228 printf("Exit application...");
229 gApplication->Terminate(0);
232 void MyMainFrame::SetStatusText(const char *txt, Int_t pi)
234 // Set text in status bar.
235 fStatusBar->SetText(txt,pi);
238 void MyMainFrame::EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
240 // Writes the event status in the status bar parts
242 const char *text0, *text1, *text3;
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);
251 sprintf(text2, "%d,%d", px, py);
252 SetStatusText(text2,2);
253 text3 = selected->GetObjectInfo(px,py);
254 SetStatusText(text3,3);
257 MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
258 TGMainFrame(p, w, h), fOADBContainer(0), fOADBSpectra(0)
260 // Create a horizontal frame (canvas and status bar on the left, buttons on the right)
261 TGHorizontalFrame *hframeMain = new TGHorizontalFrame(this, 200, 40);
263 // Create a vertical frame for the canvas and for the status bar
264 TGVerticalFrame *vframeCanvas = new TGVerticalFrame(this, 200, 40);
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);
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*)");
276 vframeCanvas->AddFrame(fEcan, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY,0,0,1,1));
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));
284 hframeMain->AddFrame(vframeCanvas, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2));
286 // Create a vertical frame containing buttons and controls
287 TGVerticalFrame *vframeButtons = new TGVerticalFrame(this, 200, 40);
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);
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));
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));
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);
311 fComboDetector->Resize(120,20);
312 fComboDetector->Select(1);
313 fComboDetector->Connect("Selected(Int_t)", "MyMainFrame", this, "DoSelectedDetector(Int_t)");
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);
320 fComboPID->Resize(120,20);
321 fComboPID->Select(0);
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);
328 fComboCharge->Resize(120,20);
329 fComboCharge->Select(0);
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);
336 fComboParticle->Resize(120,20);
337 fComboParticle->Select(0);
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);
344 fComboCentr->Resize(120,20);
345 fComboCentr->Select(0);
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);
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));
384 hframeMain->AddFrame(vframeButtons, new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
386 AddFrame(hframeMain,new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2));
388 // Set a name to the main frame
389 SetWindowName("Spectra OADB Browser");
392 // Initialize the layout algorithm via Resize()
393 Resize(GetDefaultSize());
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();
403 fFuncMan = new AliBWFunc;
404 fFuncMan->SetVarType(AliBWFunc::kdNdpt);
409 MyMainFrame::~MyMainFrame()
411 // Clean up main frame...
417 void spectraOADBGUI()
421 new MyMainFrame(gClient->GetRoot(), 200, 200);