]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/alice-macros/make_residuals.C
aa4444d89be873bf727229775404ae328f4da46f
[u/mrichter/AliRoot.git] / EVE / alice-macros / make_residuals.C
1
2 #if !defined(__CINT__) || defined(__MAKECINT__)
3 #include <TCanvas.h>
4 #include <TGButton.h>
5 #include <TGButtonGroup.h>
6 #include <TFile.h>
7 #include <TGLabel.h>
8 #include <TGNumberEntry.h>
9 #include <TG3DLine.h>
10 #include <TApplication.h>
11 #include <TGComboBox.h>
12 #include <TLatex.h>
13 #include <TTree.h>
14 #include <TEveUtil.h>
15
16 #include <STEER/CDB/AliCDBManager.h>
17 #include <STEER/ESD/AliESDEvent.h>
18 #include <STEER/ESD/AliESDfriendTrack.h>
19 #include <STEER/STEER/AliGeomManager.h>
20 #include <EVE/EveBase/AliEveEventManager.h>
21
22 /* Not sure which ConfigCalibTrain.C macro ? 
23  * From ANALYSIS or from PWGPP?
24  */
25 #include "ANALYSIS/macros/ConfigCalibTrain.C" 
26 #endif
27
28 class ButtonWindow : public TGMainFrame {
29
30 protected:
31    TGComboBox *option1;
32    TGComboBox *option2;
33    TGComboBox *option3;
34    TGComboBox *option4;
35    TGComboBox *option5;
36    TGComboBox *option6;
37    TGComboBox *option7;
38    TGComboBox *option8;
39    TGComboBox *option9;
40    TGComboBox *option10;
41    TGTextEntry *cut1;
42    TGTextEntry *cut2;
43    TGTextEntry *cut3;
44    TGTextEntry *cut4;
45    TGTextEntry *customCutSelection;
46    TGTextEntry *customDrawSelection;
47    TGNumberEntry *nEntries;
48    TGNumberEntry *firstEntry;
49
50 public:
51    ButtonWindow();
52    void DrawResiduals();
53    
54    ClassDef(ButtonWindow, 0)
55 };
56
57 //________________________________________________
58
59 ButtonWindow::ButtonWindow() : TGMainFrame(gClient->GetRoot(), 10, 10, kHorizontalFrame)
60 {
61    // Main test window.
62
63    SetCleanup(kDeepCleanup);
64
65    // Controls on right
66    TGVerticalFrame *controls = new TGVerticalFrame(this);
67    AddFrame(controls, new TGLayoutHints(kLHintsRight | kLHintsExpandY, 5, 5, 5, 5));
68
69    // control margins of the text
70
71    TGLabel *label1 = 0;
72    TGLabel *label2 = 0;
73    TGLabel *label3 = 0;
74   
75    TGHorizontal3DLine *separator = 0;
76
77    TGGroupFrame *margins = new TGGroupFrame(controls, "Residuals Drawing Options");
78    margins->SetTitlePos(TGGroupFrame::kCenter);
79
80 //==========================
81
82    separator = new TGHorizontal3DLine(margins);
83
84    margins->AddFrame(separator, new TGLayoutHints(kLHintsExpandX));
85
86    label1 = new TGLabel(margins, "Axes");
87
88    margins->AddFrame(label1, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
89
90    TGHorizontalFrame *hframe1 = new TGHorizontalFrame(margins, 400, 20, kFixedWidth);
91    
92    label1 = new TGLabel(hframe1, "X axis: ");
93
94    option1 = new TGComboBox(hframe1,"Draw option");
95    option1->AddEntry("fX",1);
96    option1->AddEntry("fY",2);
97    option1->AddEntry("fZ",3);
98    option1->AddEntry("fR",4);
99    option1->Resize(120,20);
100
101    label3 = new TGLabel(hframe1, "Y axis: ");
102
103    option2 = new TGComboBox(hframe1,"Draw option");
104    option2->AddEntry("fPx",1);
105    option2->AddEntry("fPy",2);
106    option2->AddEntry("fPz",3);
107    option2->AddEntry("fPt",4);
108    option2->AddEntry("fP",5);
109    option2->Resize(120,20);
110
111    hframe1->AddFrame(label1, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
112    hframe1->AddFrame(option1, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
113    hframe1->AddFrame(label3, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
114    hframe1->AddFrame(option2, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
115
116    margins->AddFrame(hframe1, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
117
118 //==========================
119
120    separator = new TGHorizontal3DLine(margins);
121
122    margins->AddFrame(separator, new TGLayoutHints(kLHintsExpandX));
123
124    label1 = new TGLabel(margins, "Cut Selection");
125
126    margins->AddFrame(label1, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
127
128 //===============================
129
130    TGHorizontalFrame *hframe3 = new TGHorizontalFrame(margins, 400, 20, kFixedWidth);
131    
132    label1 = new TGLabel(hframe3, " 1. ");
133
134    option3 = new TGComboBox(hframe3,"Cut");
135    option3->AddEntry("fPx",1);
136    option3->AddEntry("fPy",2);
137    option3->AddEntry("fPz",3);
138    option3->AddEntry("fPt",4);
139    option3->AddEntry("fP",5);
140    option3->Resize(100,20);
141
142    option4 = new TGComboBox(hframe3,"-");
143    option4->AddEntry("(no cut)",0);
144    option4->AddEntry("<",1);
145    option4->AddEntry(">",2);
146    option4->Resize(100,20);
147
148    cut1 = new TGTextEntry(hframe3);
149
150    hframe3->AddFrame(label1, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
151    hframe3->AddFrame(option3, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
152    hframe3->AddFrame(option4, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
153    hframe3->AddFrame(cut1, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
154
155    margins->AddFrame(hframe3, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
156
157 //=====================================
158
159    TGHorizontalFrame *hframe4 = new TGHorizontalFrame(margins, 400, 20, kFixedWidth);
160    
161    label1 = new TGLabel(hframe4, "2. ");
162
163    option5 = new TGComboBox(hframe4,"Cut");
164    option5->AddEntry("fPx",1);
165    option5->AddEntry("fPy",2);
166    option5->AddEntry("fPz",3);
167    option5->AddEntry("fPt",4);
168    option5->AddEntry("fP",5);
169    option5->Resize(100,20);
170
171    option6 = new TGComboBox(hframe4,"-");
172    option6->AddEntry("(no cut)",0);
173    option6->AddEntry("<",1);
174    option6->AddEntry(">",2);
175    option6->Resize(100,20);
176
177    cut2 = new TGTextEntry(hframe4);
178 //   cut2 = new TGNumberEntryField(hframe4, 40, 20, kFixedWidth);
179
180    hframe4->AddFrame(label1, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
181    hframe4->AddFrame(option5, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
182    hframe4->AddFrame(option6, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
183    hframe4->AddFrame(cut2, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
184
185    margins->AddFrame(hframe4, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
186
187    separator = new TGHorizontal3DLine(margins);
188
189    margins->AddFrame(separator, new TGLayoutHints(kLHintsExpandX));
190
191    label1 = new TGLabel(margins, "Custom Cut Selection");
192
193    margins->AddFrame(label1, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
194
195    customCutSelection = new TGTextEntry(margins);
196
197    margins->AddFrame(customCutSelection, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
198
199 //========================================
200
201    separator = new TGHorizontal3DLine(margins);
202
203    margins->AddFrame(separator, new TGLayoutHints(kLHintsExpandX));
204
205    label1 = new TGLabel(margins, "Draw Selection");
206
207    margins->AddFrame(label1, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
208
209 //========================================
210
211    TGHorizontalFrame *hframe5 = new TGHorizontalFrame(margins, 400, 20, kFixedWidth);
212    
213    label1 = new TGLabel(hframe5, "1. ");
214
215    option7 = new TGComboBox(hframe5,"Cut");
216    option7->AddEntry("fPx",1);
217    option7->AddEntry("fPy",2);
218    option7->AddEntry("fPz",3);
219    option7->AddEntry("fPt",4);
220    option7->AddEntry("fP",5);
221    option7->Resize(100,20);
222
223    option8 = new TGComboBox(hframe5,"-");
224    option8->AddEntry("(no cut)",0);
225    option8->AddEntry("<",1);
226    option8->AddEntry(">",2);
227    option8->Resize(100,20);
228
229    cut3 = new TGTextEntry(hframe5);
230 //   cut3 = new TGNumberEntryField(hframe5, 40, 20, kFixedWidth);
231
232    hframe5->AddFrame(label1, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
233    hframe5->AddFrame(option7, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
234    hframe5->AddFrame(option8, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
235    hframe5->AddFrame(cut3, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
236
237    margins->AddFrame(hframe5, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
238
239 //=======================================
240
241    TGHorizontalFrame *hframe6 = new TGHorizontalFrame(margins, 400, 20, kFixedWidth);
242    
243    label1 = new TGLabel(hframe6, "2. ");
244
245    option9 = new TGComboBox(hframe6,"Cut");
246    option9->AddEntry("fPx",1);
247    option9->AddEntry("fPy",2);
248    option9->AddEntry("fPz",3);
249    option9->AddEntry("fPt",4);
250    option9->AddEntry("fP",5);
251    option9->Resize(100,20);
252
253    option10 = new TGComboBox(hframe6,"-");
254    option10->AddEntry("(no cut)",0);
255    option10->AddEntry("<",1);
256    option10->AddEntry(">",2);
257    option10->Resize(100,20);
258
259    cut4 = new TGTextEntry(hframe6);
260 //   cut4 = new TGNumberEntryField(hframe6, 40, 20, kFixedWidth);
261
262    hframe6->AddFrame(label1, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
263    hframe6->AddFrame(option9, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
264    hframe6->AddFrame(option10, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
265    hframe6->AddFrame(cut4, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
266
267    margins->AddFrame(hframe6, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
268
269    separator = new TGHorizontal3DLine(margins);
270
271    margins->AddFrame(separator, new TGLayoutHints(kLHintsExpandX));
272
273    label1 = new TGLabel(margins, "Custom Draw Selection");
274
275    margins->AddFrame(label1, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
276
277    customDrawSelection = new TGTextEntry(margins);
278
279    margins->AddFrame(customDrawSelection, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
280
281 //==========================
282
283    separator = new TGHorizontal3DLine(margins);
284
285    margins->AddFrame(separator, new TGLayoutHints(kLHintsExpandX));
286
287    label1 = new TGLabel(margins, "Entries Selection");
288
289    margins->AddFrame(label1, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
290
291 //========================================
292
293    TGHorizontalFrame *hframe7 = new TGHorizontalFrame(margins, 400, 20, kFixedWidth);
294    
295    label1 = new TGLabel(hframe7, "nEntries");
296
297    nEntries = new TGNumberEntry(hframe7, 40, 20, kFixedWidth);
298
299    label2 = new TGLabel(hframe7, "firstEntry");
300
301    firstEntry = new TGNumberEntry(hframe7, 40, 20, kFixedWidth);
302
303    hframe7->AddFrame(label1, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
304    hframe7->AddFrame(nEntries, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
305    hframe7->AddFrame(label2, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
306    hframe7->AddFrame(firstEntry, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
307
308    margins->AddFrame(hframe7, new TGLayoutHints(kLHintsExpandX, 5, 5, 1, 1));
309
310 //==========================
311
312    separator = new TGHorizontal3DLine(margins);
313
314    margins->AddFrame(separator, new TGLayoutHints(kLHintsExpandX));
315
316    const TGFont *font = gClient->GetFont("-*-times-bold-r-*-*-16-*-*-*-*-*-*-*");
317 //   const TGFont *font = gClient->GetFont("-*-symbol-medium-r-normal-*-16-*-*-*-*-*-*-*");
318    FontStruct_t buttonFont = font->GetFontStruct();
319    ULong_t buttonRedColor;
320    gClient->GetColorByName("red", buttonRedColor);
321    TGTextButton *draw = new TGTextButton(margins,"Draw Residuals");
322    draw->SetTextColor(buttonRedColor);
323    draw->SetFont(buttonFont);
324    draw->Connect("Clicked()", "ButtonWindow", this, "DrawResiduals()");
325    margins->AddFrame(draw, new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5));
326
327    controls->AddFrame(margins, new TGLayoutHints(kLHintsExpandX));
328
329    MapSubwindows();
330    Resize();
331
332    SetWMSizeHints(GetDefaultWidth(), GetDefaultHeight(), 1000, 1000, 0 ,0);
333    SetWindowName("Residuals");
334    MapRaised();
335 }
336
337 //______________________________________________________________________________
338 void ButtonWindow::DrawResiduals()
339 {
340
341       TString selection1, selection2, selection3, selection4, selection5, selection6, selection7, selection8, selection9, selection10;
342
343       switch(option1->GetSelected())
344       {
345          case 1:
346             selection1 = "fX";
347             break;
348          case 2:
349             selection1 = "fY";
350             break;
351          case 3:
352             selection1 = "fZ";
353             break;
354          default:
355             selection1 = "fX";
356             break;
357       }
358     
359       switch(option2->GetSelected())
360       {
361          case 1:
362             selection2 = "fPx";
363             break;
364          case 2:
365             selection2 = "fPy";
366             break;
367          case 3:
368             selection2 = "fPz";
369             break;
370          case 4:
371             selection2 = "fPt";
372             break;
373          case 5:
374             selection2 = "fP";
375             break;
376          default:
377             selection2 = "fP";
378             break;
379       }
380
381       switch(option3->GetSelected())
382       {
383          case 1:
384             selection3 = "fPx";
385             break;
386          case 2:
387             selection3 = "fPy";
388             break;
389          case 3:
390             selection3 = "fPz";
391             break;
392          case 4:
393             selection3 = "fPt";
394             break;
395          case 5:
396             selection3 = "fP";
397             break;
398          default:
399             selection3 = "fP";
400             break;
401       }
402
403       switch(option4->GetSelected())
404       {
405          case 1:
406             selection4 = "<";
407             break;
408          case 2:
409             selection4 = ">";
410             break;
411          default:
412             selection4 = "<";
413             break;
414       }
415
416       switch(option5->GetSelected())
417       {
418          case 1:
419             selection5 = "fPx";
420             break;
421          case 2:
422             selection5 = "fPy";
423             break;
424          case 3:
425             selection5 = "fPz";
426             break;
427          case 4:
428             selection5 = "fPt";
429             break;
430          case 5:
431             selection5 = "fP";
432             break;
433          default:
434             selection5 = "fP";
435             break;
436       }
437
438       switch(option6->GetSelected())
439       {
440          case 1:
441             selection6 = "<";
442             break;
443          case 2:
444             selection6 = ">";
445             break;
446          default:
447             selection6 = "<";
448             break;
449       }
450
451       switch(option7->GetSelected())
452       {
453          case 1:
454             selection7 = "fPx";
455             break;
456          case 2:
457             selection7 = "fPy";
458             break;
459          case 3:
460             selection7 = "fPz";
461             break;
462          case 4:
463             selection7 = "fPt";
464             break;
465          case 5:
466             selection7 = "fP";
467             break;
468          default:
469             selection7 = "fP";
470             break;
471       }
472
473       switch(option8->GetSelected())
474       {
475          case 1:
476             selection8 = "<";
477             break;
478          case 2:
479             selection8 = ">";
480             break;
481          default:
482             selection8 = "<";
483             break;
484       }
485
486       switch(option9->GetSelected())
487       {
488          case 1:
489             selection9 = "fPx";
490             break;
491          case 2:
492             selection9 = "fPy";
493             break;
494          case 3:
495             selection9 = "fPz";
496             break;
497          case 4:
498             selection9 = "fPt";
499             break;
500          case 5:
501             selection9 = "fP";
502             break;
503          default:
504             selection3 = "fP";
505             break;
506       }
507
508       switch(option10->GetSelected())
509       {
510          case 1:
511             selection10 = "<";
512             break;
513          case 2:
514             selection10 = ">";
515             break;
516          default:
517             selection10 = "<";
518             break;
519       }
520
521       TString cutSelectionMerged;// = ("abs(ESDfriend.fTracks[].fTPCOut."+selection3+"[4])"+selection4+cut1->GetText());
522       TString drawSelectionMerged1 = ("track[]."+selection2+"[0]:track[]."+selection1);
523       TString drawSelectionMerged2;// = ("abs(track[]."+selection7+"[0])"+selection8+cut3->GetText());
524
525       if(customCutSelection->GetText())
526         cutSelectionMerged = customCutSelection->GetText();
527
528       if(customDrawSelection->GetText())
529         drawSelectionMerged2 = customDrawSelection->GetText();
530
531
532       Info("make_residuals::DrawResiduals", "%s abs(ESDfriend.fTracks[].fTPCOut.fP[4])<0.5", cutSelectionMerged.Data());
533       Info("make_residuals::DrawResiduals", "%s track[].fP[0]:track[].fX", drawSelectionMerged1.Data());
534       Info("make_residuals::DrawResiduals", "%s abs(track[].fP[0])<20", drawSelectionMerged2.Data());
535       Info("make_residuals::DrawResiduals", "nEntries: %f", nEntries->GetNumber());
536       Info("make_residuals::DrawResiduals", "firstEntry: %f", firstEntry->GetNumber());
537       
538       TEveUtil::LoadMacro("ConfigCalibTrain.C");
539
540       AliESDEvent *esd = AliEveEventManager::AssertESD();
541
542       ConfigCalibTrain(esd->GetRunNumber());
543
544       /* OBSOLETE CODE - No function members defined
545        * 
546       AliESDfriendTrack::MakeDebugStreamer(kTRUE);
547
548       TTreeSRedirector *pcstreamRes = AliESDfriendTrack::GetDebugStreamer();
549       */
550       
551       TFile fRes("AliESDfriends.root");
552
553       TTree *treeRes = (TTree*)fRes.Get("esdFriendTree");     
554
555       TCanvas* cnv = new TCanvas();
556       
557       
558       treeRes->Draw("ESDfriend.fTracks[].MakeResidualGraph(1)",cutSelectionMerged," ",nEntries->GetNumber(),firstEntry->GetNumber());
559 //      treeRes->Draw("ESDfriend.fTracks[].MakeResidualGraph(1)","abs(ESDfriend.fTracks[].fTPCOut.fP[4])<0.5"," ",nEntries,firstEntry);
560
561       //delete pcstreamRes;
562
563       /*  OBSOLETE CODE -dump not defined
564
565       TFile fRes("residual.root");
566
567       dump.Draw(drawSelectionMerged1,drawSelectionMerged2);
568       */
569 //      dump.Draw("track[].fP[0]:track[].fX","abs(track[].fP[0])<20");
570
571 }
572
573 //_____________________________________________________________________________
574 void make_residuals()
575 {
576
577       new ButtonWindow();
578
579 }