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