Moving some private members from f to g
[u/mrichter/AliRoot.git] / TPC / CalibMacros / AnalyzeLaserCE.C
1 /*
2
3 Macro to perform fits of the Laser Central electrode data
4 Several fit methods implemented
5
6 0. RebuildCE("ce.root","pul.root"); - rebuild data from the scratch
7                                     - the data will be storered in file inname
8                                     
9 1. RebuildData() - transform arbitrary layout of the Input data to the internal format
10    StoreData();  - The data tree expected in file inname (see variable bellow)
11    StoreTree();  - Modify inname and xxside and tcor in order to transform data
12
13
14 2. MakeFit();    - Make a fit of the data - already in internal format    
15    StoreData();  - Store
16    StoreTree();
17
18 3. MakeRes();    - Make the final calibration  + combination of different components
19
20 4. LoadViewer(); - Browse the fit parameters
21  
22
23 .x ~/rootlogon.C
24 gSystem->AddIncludePath("-I$ALICE_ROOT/TPC -I$ALICE_ROOT/STAT");
25 gSystem->Load("libSTAT.so");
26 .L $ALICE_ROOT/TPC/CalibMacros/AnalyzeLaserCE.C+
27 // setup aliases
28 qaside="CE_Q";
29 taside="CE_T";
30 raside="CE_RMS";
31 qcside="CE_Q";
32 tcside="CE_T";
33 rcside="CE_RMS";
34
35
36
37
38 Calibration viewer variables:
39
40 Result  -  resulting correction
41 out     -  outlyers not used for fit
42 tcor    -  offset specified by user before fitting
43 timeF1  -  sector local fit - plane
44 timeF2  -  sector local fit - parabola
45 timeIn  -  input times
46 qIn     -  input charge
47 out     -  outlyers not used for fit
48 tcor    -  offset specified by user before fitting
49 timeF1  -  sector time local fit - plane
50 timeF2  -  sector time local fit - parabola
51 qF1     -  sector q local fit    - plane
52 qF2     -  sector q local fit    - parabola
53 // fitted values
54 //
55 ffit0   - base fit
56 ffit1   - adding common shifts    - alpha dependendent
57 ffit2   - adding opposite shifts  - alpha dependent
58 //
59 fGXY    -  global fit parameter - XY
60 fInOut  -  global fit parameter - inner-outer sector matching
61 fLX     -  global LX  dependence
62 //
63 Gloabl fit o consist of
64 -fGXY~-fLX~-fTL~-fOff~:ffit0~
65
66 //
67 // Control variable - check results
68 //
69 //
70 ffit2~-(timeIn~+tcor~):lx~  - fit value minus input time 
71
72 result cosntruction:
73 (timeF2~-ffit2~+fTL~+fInOut~+tcor~):Result~+tcor~
74 //
75 timeF2~-Result~:ffit2~-fTL~-fInOut~
76
77
78 */
79 #include "TString.h"
80 #include "TSystem.h"
81 #include "TTree.h"
82 #include "TCut.h"
83 #include "TStatToolkit.h"
84 #include "AliTPCCalibViewer.h"
85 #include "AliTPCCalibViewerGUI.h"
86 #include "AliTPCPreprocessorOnline.h"
87 #include "AliTPCCalibCE.h"
88 #include "AliTPCCalibPulser.h"
89 //
90 //Define interesting variables - file names
91 //
92 char * inname = "treeCE.root";  // input file with tree
93 //
94 // variable name definition in input tree - change it according the input
95 //
96 TString qaside("CE_Q");
97 TString taside("CE_T");
98 TString raside("CE_RMS");
99 TString qcside("CE_Q");
100 TString tcside("CE_T");
101 TString rcside("CE_RMS");
102
103 //
104 // correction variable - usually Pulser time
105 //
106 //TString tcor("(sector%36>30)*2");
107 TString tcor("-pulCorr");
108
109 //
110 char * fname  = "treefitCE.root";       // output file with tree
111 char * oname  = "fitCE.root";           // output file with CalPads fit 
112
113 //
114 //
115 // Input CalPads
116 //
117 AliTPCCalPad *calPadIn  = 0;            // original time pad
118 AliTPCCalPad *calPadF1  = 0;            // original time pad - fit plane
119 AliTPCCalPad *calPadF2  = 0;            // original time pad - fit parabola
120 AliTPCCalPad *calPadQIn = 0;            // original Q pad
121 AliTPCCalPad *calPadQF1 = 0;            // original Q pad
122 AliTPCCalPad *calPadQF2 = 0;            // original Q pad
123
124 AliTPCCalPad *calPadCor = 0;            // base correction CalPad
125 AliTPCCalPad *calPadOut = 0;            // outlyer CalPad
126 //
127 // cuts
128 //
129 const Float_t tThr=0.5;                // max diff in the sector
130 const Float_t qThr0=0.5;               // max Q diff in the sector
131 const Float_t qThr1=2;                 // max Q diff in the sector
132
133 //
134 //
135 // fit Cal Pads
136 AliTPCCalPad *calPad0   = 0;            // global fit 0 - base
137 AliTPCCalPad *calPad1   = 0;            // global fit 1 - common behavior rotation -A-C
138 AliTPCCalPad *calPad2   = 0;            // gloabl fit 2 - CE missalign rotation     A-C
139 //
140 AliTPCCalPad *calPadInOut = 0;          // misaalign in-out
141 AliTPCCalPad *calPadLX    = 0;          // local x missalign
142 AliTPCCalPad *calPadTL   = 0;           // tan 
143 AliTPCCalPad *calPadQ     = 0;          // time (q)  correction
144 AliTPCCalPad *calPadGXY   = 0;          // global XY missalign (drift velocity grad) 
145 AliTPCCalPad *calPadOff   = 0;          // normalization offset fit
146 AliTPCCalPad *calPadRes   = 0;          // final calibration  
147
148
149 //
150 // working variables
151 //
152 AliTPCCalibViewerGUI * viewer=0;   //viewerGUI
153 AliTPCCalibViewer    *makePad=0;   //viewer
154 TTree * tree=0;                    // working tree
155
156 void LoadViewer();
157 void RebuildData();   // transform the input data to the fit format 
158 void MakeFit();       // make fits
159 void MakeFitPulser(); // make fit for pulser correction data
160 //
161 //   internal functions
162 //
163 void MakeAliases0();  // Make Aliases 0  - for user tree
164 void MakeAliases1();  // Make Aliases 1  - for default tree   
165 void LoadData();      // Load data
166 void StoreData();     // store current data
167 void StoreTree();     // store fit data in the output tree
168
169
170 void AnalyzeLaser(){
171   //
172   //
173   //
174   LoadViewer();
175   MakeAliases1();
176 }
177
178 void MakeFitPulser(){
179   TStatToolkit stat;
180   Int_t npoints;
181   Double_t chi2;
182   TVectorD vec0,vec1,vec2;
183   TMatrixD mat;
184   TString fitvar="P_T.fElements";
185   TCut out("abs(P_T.fElements/P_T_Mean.fElements-1.001)<.002");
186   TCut fitadd("P_T.fElements>446");
187   TString fstring="";
188   fstring+="(sector>=0&&sector<9)++";
189   fstring+="(sector>=9&&sector<18)++";
190   fstring+="(sector>=18&&sector<27)++";
191   fstring+="(sector>=27&&sector<36)++";
192   fstring+="(sector>=36&&sector<45)++";
193   fstring+="(sector>=45&&sector<54)++";
194   fstring+="(sector>=54&&sector<63)++";
195   fstring+="(sector>=63&&sector<72)";
196
197   TString *pulOff =stat.FitPlane(tree,fitvar.Data(),fstring.Data(),(out+fitadd).GetTitle(),chi2,npoints,vec0,mat);
198
199   tree->SetAlias("pul0",pulOff->Data());
200   tree->SetAlias("pulCorr","P_T.fElements-pul0");
201   tree->SetAlias("pulOut",out.GetTitle());
202 }
203
204 void MakeFit(){
205   //
206   //
207   LoadData();
208   LoadViewer();
209   MakeFitPulser();
210   TStatToolkit stat;
211   Int_t npoints;
212   Double_t chi2;
213   TVectorD vec0,vec1,vec2;
214   TMatrixD mat;
215   TString fstring="";
216   //
217   //Basic  correction
218   //
219   fstring+="side++";        // offset on 2 different sides              //1
220   //fstring+="(1/qp)++";      // Q -threshold effect correction           //2
221   //fstring+="(qp)++";        // Q -threshold effect correction           //3
222   fstring+="(inn)++";       //  inner outer misalign   - common         //4 
223   fstring+="(side*inn)++";  //                         - opposite       //5
224   //
225   fstring+="(gyr)++";       // drift velocity gradient - common         //6
226   fstring+="(side*gyr)++";  //                         - opposite       //7
227   fstring+="(gxr)++";       //  global x tilt          - common         //8
228   fstring+="(side*gxr)++";  //                         - opposite       //9
229   //
230   fstring+="tl^2++";        // local phi correction                     //10
231   //
232   fstring+="(lxr)++";       // zr            angle      - common        //11
233   fstring+="(side*lxr)++";  //                          - opposite      //12
234   fstring+="(inn*lxr)++";   // inner outer angle        - common        //13             
235   fstring+="(side*inn*lxr)++";//                        - opposite      //14
236   fstring+="(lxr^2)++";       // zr          second     - common        //15
237   fstring+="(side*lxr^2)++";  //                        - opposite      //16
238   //
239   TString *fit0 =stat.FitPlane(tree,"dt",fstring.Data(),"cutF&&cutCE",chi2,npoints,vec0,mat);
240   tree->SetAlias("f0",fit0->Data());
241   //
242   // Common "deformation" tendencies
243   //
244   fstring+="(sin(atan2(gy.fElements,gx.fElements)))++";
245   fstring+="(cos(atan2(gy.fElements,gx.fElements)))++";
246   //
247   fstring+="(sin(atan2(gy.fElements,gx.fElements)*2))++";
248   fstring+="(cos(atan2(gy.fElements,gx.fElements)*2))++";
249   fstring+="(sin(atan2(gy.fElements,gx.fElements)*3))++";
250   fstring+="(cos(atan2(gy.fElements,gx.fElements)*3))++";
251   //
252   fstring+="(sin(atan2(gy.fElements,gx.fElements)*2))*lxr++";
253   fstring+="(cos(atan2(gy.fElements,gx.fElements)*2))*lxr++";
254   fstring+="(sin(atan2(gy.fElements,gx.fElements)*3))*lxr++";
255   fstring+="(cos(atan2(gy.fElements,gx.fElements)*3))*lxr++";
256   //
257
258   TString *fit1 =stat.FitPlane(tree,"dt",fstring.Data(),"cutF&&cutCE",chi2,npoints,vec1,mat);
259   tree->SetAlias("f1",fit1->Data());
260   //
261   // Central electrode "deformation"
262   //
263   fstring+="(side*sin(atan2(gy.fElements,gx.fElements)))++";
264   fstring+="(side*cos(atan2(gy.fElements,gx.fElements)))++";
265   //
266   fstring+="(side*sin(atan2(gy.fElements,gx.fElements)*2))++";
267   fstring+="(side*cos(atan2(gy.fElements,gx.fElements)*2))++";
268   fstring+="(side*sin(atan2(gy.fElements,gx.fElements)*3))++";
269   fstring+="(side*cos(atan2(gy.fElements,gx.fElements)*3))++";
270   // 
271   fstring+="(side*sin(atan2(gy.fElements,gx.fElements)*2))*lxr++";
272   fstring+="(side*cos(atan2(gy.fElements,gx.fElements)*2))*lxr++";
273   fstring+="(side*sin(atan2(gy.fElements,gx.fElements)*3))*lxr++";
274   fstring+="(side*cos(atan2(gy.fElements,gx.fElements)*3))*lxr++";
275    
276   TString *fit2 =stat.FitPlane(tree,"dt",fstring.Data(),"cutF&&abs(dt-f0)<0.7&&cutCE",chi2,npoints,vec2,mat);
277   tree->SetAlias("f2",fit2->Data());
278   //
279   // Extract variables
280   //
281   TString tmpstr = fstring;
282   TObjArray *arr = tmpstr.Tokenize("++");
283   TString fitQ("0");       // q correction 
284   TString fitLX("0");      // lx correction 
285   TString fitInOut("0");   // inner-outer - match
286   TString fitGXY("0");      // global xy fit
287   TString fitOff("0");  // side offsets
288   TString fitTL("0");  // side offsets
289   //
290   fitOff+="+";
291   fitOff+=vec2[0];
292   fitOff+="+side*";
293   fitOff+=vec2[1];
294   {
295   for(Int_t i=0;i<arr->GetEntriesFast();i++){
296     if (!arr->At(i)) continue;
297     TString *fitstr = new TString(arr->At(i)->GetName());
298     //
299     //Bool_t isQ      = fitstr->Contains("qp)");
300     Bool_t isRot    = fitstr->Contains("sin(")+fitstr->Contains("cos(");
301     Bool_t isLX     = fitstr->Contains("lxr");
302     Bool_t isIn     = fitstr->Contains("inn");
303     Bool_t isGXY    = fitstr->Contains("gxr")+fitstr->Contains("gyr");
304     if (fitstr->Contains("tl^2")){
305       fitTL+="+";
306       fitTL+=(*fitstr)+"*";
307       fitTL+=vec2[i+1];
308     }
309     if (isGXY){
310       fitGXY+="+";
311       fitGXY+=(*fitstr)+"*";
312       fitGXY+=vec2[i+1];
313     }
314     //if (isQ){
315     //  //
316     //  fitQ+="+";
317     //  fitQ+=(*fitstr)+"*";
318     //  fitQ+=vec2[i+1];
319     //}
320     //
321     if (isLX&&!isRot&&!isIn){
322       fitLX+="+";
323       fitLX+=(*fitstr)+"*";
324       fitLX+=vec2[i+1];
325     }
326     //
327     if (!isRot&&isIn){
328       fitInOut+="+";
329       fitInOut+=(*fitstr)+"*";
330       fitInOut+=vec2[i+1];
331     }
332   }
333   }
334   //
335   tree->SetAlias("fInOut",fitInOut.Data());
336   tree->SetAlias("fLX",fitLX.Data());
337   tree->SetAlias("fGXY",fitGXY.Data());
338   tree->SetAlias("fOff",fitOff.Data());
339   //tree->SetAlias("fQ",fitQ.Data());
340   tree->SetAlias("fTL",fitTL.Data());
341   //
342   //
343   // fits
344   // 
345   calPad0      = makePad->GetCalPad("f0","1", "ffit0");
346   calPad1      = makePad->GetCalPad("f1","1", "ffit1");
347   calPad2      = makePad->GetCalPad("f2","1", "ffit2");
348   calPadInOut  = makePad->GetCalPad("fInOut","1", "fInOut");
349   calPadLX     = makePad->GetCalPad("fLX","1", "fLX");
350   calPadTL     = makePad->GetCalPad("fTL","1", "fTL");
351   //calPadQ      = makePad->GetCalPad("fQ","1", "fQ");
352   calPadGXY    = makePad->GetCalPad("fGXY","1", "fGXY");
353   calPadOff    = makePad->GetCalPad("fOff","1", "fOff");  
354 }
355
356
357
358 void LoadViewer(){
359   //
360   // Load calib Viewer
361   //
362   TObjArray * array = AliTPCCalibViewerGUI::ShowGUI(fname);
363   viewer = (AliTPCCalibViewerGUI*)array->At(0);
364   makePad = viewer->GetViewer();
365   tree = viewer->GetViewer()->GetTree();
366   MakeAliases1();  
367 }
368
369
370
371
372
373
374 void RebuildData(){
375   //
376   // transform the input data to the fit format 
377   //
378   makePad = new AliTPCCalibViewer(inname);
379   tree = makePad->GetTree();
380   MakeFitPulser();
381   MakeAliases0(); //
382   //
383   printf("0.   GetCalPads\n");
384
385   calPadCor = makePad->GetCalPad("tcor","1", "tcor");
386   calPadOut = makePad->GetCalPad("1","!((cutA||cutC)&&abs(ly.fElements/lx.fElements)<0.155)", "out");
387   calPadIn  = makePad->GetCalPad("dt-tcor","1","timeIn");
388   calPadF1  = calPadIn->GlobalFit("timeF1", calPadOut,kTRUE,0,0.9);
389   calPadQIn = makePad->GetCalPad("qa*(sector%36<18)+qc*(sector%36>17)","1","qIn");
390   //
391   //
392   printf("1.   Create outlyer map\n");
393
394   //
395   // Update outlyer maps
396   //
397   for (Int_t isector=0;isector<72; isector++){
398     for (UInt_t ich=0;ich<calPadIn->GetCalROC(isector)->GetNchannels();ich++){
399       Float_t val0= calPadIn->GetCalROC(isector)->GetValue(ich);
400       Float_t val1= calPadF1->GetCalROC(isector)->GetValue(ich);
401       if (TMath::Abs(val0-val1)>tThr) calPadOut->GetCalROC(isector)->SetValue(ich,1);
402     }
403   }
404   printf("1.   Fit sector parabolas\n");
405
406   calPadF1  = calPadIn->GlobalFit("timeF1", calPadOut,kTRUE,0,0.9);
407   calPadF2  = calPadIn->GlobalFit("timeF2", calPadOut,kTRUE,1,0.9);
408   calPadQF1 = calPadQIn->GlobalFit("qF1", calPadOut,kTRUE,0,0.9);
409   calPadQF2 = calPadQIn->GlobalFit("qF2", calPadOut,kFALSE,1);
410
411   //
412   // Update outlyer maps
413   //
414   printf("2.   Update outlyer map\n");
415   for (Int_t isector=0;isector<72; isector++){
416     for (UInt_t ich=0;ich<calPadIn->GetCalROC(isector)->GetNchannels();ich++){
417       Float_t val0= calPadQIn->GetCalROC(isector)->GetValue(ich);
418       Float_t val1= calPadQF2->GetCalROC(isector)->GetValue(ich);
419       if (val1<0.1)  {
420         calPadOut->GetCalROC(isector)->SetValue(ich,1);
421         continue;
422       }
423       if (TMath::Abs(val0/val1)<qThr0) calPadOut->GetCalROC(isector)->SetValue(ich,1);
424       if (TMath::Abs(val0/val1)>qThr1) calPadOut->GetCalROC(isector)->SetValue(ich,1);
425     }
426   }
427   printf("3.  Redo fit of the of parabola \n");
428   //
429   //
430   AliTPCCalPad *calPadInCor  = makePad->GetCalPad("dt","1","timeIn");
431   calPadF1  = calPadInCor->GlobalFit("timeF1", calPadOut,kTRUE,0,0.9);
432   calPadF2  = calPadInCor->GlobalFit("timeF2", calPadOut,kTRUE,1,0.9);
433   calPadQF1 = calPadQIn->GlobalFit("qF1", calPadOut,kFALSE,0,0.9);
434   calPadQF2 = calPadQIn->GlobalFit("qF2", calPadOut,kFALSE,1);
435 }
436
437 void LoadData(){
438   //
439   // Get Data
440   //
441   TFile f(oname);
442   calPadIn  = (AliTPCCalPad*)f.Get("timeIn");  // original time pad
443   calPadF1  = (AliTPCCalPad*)f.Get("timeF1");  // original time pad - fit plane
444   calPadF2  = (AliTPCCalPad*)f.Get("timeF2");  // original time pad - fit parabola
445   //
446   calPadQIn  = (AliTPCCalPad*)f.Get("qIn");  // original time pad
447   calPadQF1  = (AliTPCCalPad*)f.Get("qF1");  // original time pad - fit plane
448   calPadQF2  = (AliTPCCalPad*)f.Get("qF2");  // original time pad - fit parabola
449   //
450   calPadCor = (AliTPCCalPad*)f.Get("tcor");    // base correction CalPad
451   calPadOut = (AliTPCCalPad*)f.Get("out");     // outlyer CalPad  
452   //
453   calPad0   = (AliTPCCalPad*)f.Get("ffit0");   // global fit 0 - base
454   calPad1   = (AliTPCCalPad*)f.Get("ffit1");   // global fit 1 - common behavior rotation -A-C
455   calPad2   = (AliTPCCalPad*)f.Get("ffit2");   // gloabl fit 2 - CE missalign rotation     A-C
456   calPadInOut = (AliTPCCalPad*)f.Get("fInOut");// misaalign in-out
457   calPadLX    = (AliTPCCalPad*)f.Get("fLX");   // local x missalign
458   calPadTL    = (AliTPCCalPad*)f.Get("fTL");   // local y/x missalign
459   calPadQ     = (AliTPCCalPad*)f.Get("fQ");    // time (q)  correction
460   calPadGXY   = (AliTPCCalPad*)f.Get("fGXY");  // global XY missalign (drift velocity grad) 
461   calPadOff   = (AliTPCCalPad*)f.Get("fOff");  // normalization offset fit
462   calPadRes   = (AliTPCCalPad*)f.Get("Result");  //resulting calibration
463 }
464
465 void StoreData(){
466   //
467   // Store data
468   // 
469   TFile * fstore = new TFile(oname,"recreate");
470   if (calPadIn) calPadIn->Write("timeIn");   // original time pad
471   if (calPadF1) calPadF1->Write("timeF1");   // original time pad - fit plane
472   if (calPadF2) calPadF2->Write("timeF2");   // original time pad - fit parabola
473   //
474   if (calPadQIn) calPadQIn->Write("qIn");   // original time pad
475   if (calPadQF1) calPadQF1->Write("qF1");   // original time pad - fit plane
476   if (calPadQF2) calPadQF2->Write("qF2");   // original time pad - fit parabola
477   //
478   if (calPadCor) calPadCor->Write("tcor");   // base correction CalPad
479   if (calPadOut) calPadOut->Write("out");    // outlyer CalPad  
480   //
481   if (calPad0)   calPad0->Write("ffit0");    // global fit 0 - base
482   if (calPad1)   calPad1->Write("ffit1");    // global fit 1 - common behavior rotation -A-C
483   if (calPad2)   calPad2->Write("ffit2");    // gloabl fit 2 - CE missalign rotation     A-C
484   if (calPadInOut)calPadInOut->Write("fInOut");   // misaalign in-out
485   if (calPadLX)  calPadLX->Write("fLX");     // local x missalign
486   if (calPadTL)  calPadTL->Write("fTL");     // local y/x missalign
487   if (calPadQ)   calPadQ->Write("fQ");       // time (q)  correction
488   if (calPadGXY) calPadGXY->Write("fGXY");   // global XY missalign (drift velocity grad) 
489   if (calPadOff) calPadOff->Write("fOff");   // normalization offset fit
490   if (calPadRes) calPadRes->Write("Result");   //resulting calibration
491   fstore->Close();
492   delete fstore;
493 }
494
495 void StoreTree(){
496   //
497   //
498   //
499   AliTPCPreprocessorOnline * preprocesor = new AliTPCPreprocessorOnline;
500   //
501   if (calPadIn) preprocesor->AddComponent(calPadIn->Clone());
502   if (calPadF1) preprocesor->AddComponent(calPadF1->Clone());   
503   if (calPadF2) preprocesor->AddComponent(calPadF2->Clone());   
504   //
505   if (calPadQIn) preprocesor->AddComponent(calPadQIn->Clone());
506   if (calPadQF1) preprocesor->AddComponent(calPadQF1->Clone());   
507   if (calPadQF2) preprocesor->AddComponent(calPadQF2->Clone());   
508   //
509   if (calPadCor) preprocesor->AddComponent(calPadCor->Clone());   
510   if (calPadOut) preprocesor->AddComponent(calPadOut->Clone());  
511   //
512   if (calPad0)   preprocesor->AddComponent(calPad0->Clone());
513   if (calPad1)   preprocesor->AddComponent(calPad1->Clone());
514   if (calPad2)   preprocesor->AddComponent(calPad2->Clone());
515   if (calPadInOut)preprocesor->AddComponent(calPadInOut->Clone());
516   if (calPadLX)  preprocesor->AddComponent(calPadLX->Clone());
517   if (calPadTL)  preprocesor->AddComponent(calPadTL->Clone());
518   if (calPadQ)   preprocesor->AddComponent(calPadQ->Clone());
519   if (calPadGXY) preprocesor->AddComponent(calPadGXY->Clone());
520   if (calPadOff) preprocesor->AddComponent(calPadOff->Clone());
521   if (calPadRes) preprocesor->AddComponent(calPadRes->Clone());
522   preprocesor->DumpToFile(fname);
523   delete preprocesor;
524 }
525
526
527 void MakeAliases0(){
528   //
529   // Define variables and selection of outliers - for user defined tree
530   //
531   tree->SetAlias("tcor",tcor.Data());          // correction variable
532   tree->SetAlias("ta",taside+".fElements");
533   tree->SetAlias("tc",tcside+".fElements");
534   tree->SetAlias("qa",qaside+".fElements");
535   tree->SetAlias("qc",qcside+".fElements");
536   tree->SetAlias("ra",raside+".fElements");
537   tree->SetAlias("rc",rcside+".fElements");
538   tree->SetAlias("side","1-(sector%36>17)*2");
539   tree->SetAlias("dt","(ta)*(sector%36<18)+(tc)*(sector%36>17)+tcor");
540   tree->SetAlias("cutA","qa>30&&qa<400&&abs(ta)<2&&ra>0.5&&ra<2");
541   tree->SetAlias("cutC","qc>30&&qc<400&&abs(tc)<2&&rc>0.5&&rc<2");
542   tree->SetAlias("cutF","(pad.fElements%4==0)&&(row.fElements%3==0)");
543   tree->SetAlias("cutCE","V.out.fElements");
544   //
545   // fit param aliases
546   //
547   tree->SetAlias("inn","sector<36");
548   tree->SetAlias("gxr","(gx.fElements/250.)"); //
549   tree->SetAlias("gyr","(gy.fElements/250.)"); //
550   tree->SetAlias("lxr","(lx.fElements-133.41)/250.");
551   tree->SetAlias("qp","((sector%36<18)*sqrt(qa)/10.+(sector%36>17)*sqrt(qc)/10.)"); //
552   tree->SetAlias("tl","(ly.fElements/lx.fElements)/0.17");  
553 }
554
555
556 void MakeAliases1(){
557   //
558   // Define variables and selection of outliers -for default usage
559   //
560   tree->SetAlias("tcor","tcor.fElements");          // correction variable  
561   tree->SetAlias("side","1-(sector%36>17)*2");
562   tree->SetAlias("dt","timeIn.fElements+tcor");
563   //
564   tree->SetAlias("cutA","out.fElements==1");
565   tree->SetAlias("cutC","out.fElements==1");
566   tree->SetAlias("cutF","(pad.fElements%5==0)&&(row.fElements%4==0)");
567   tree->SetAlias("cutCE","out.fElements<0.5");
568   //
569   // fit param aliases
570   //
571   tree->SetAlias("inn","sector<36");
572   tree->SetAlias("gxr","(gx.fElements/250.)"); //
573   tree->SetAlias("gyr","(gy.fElements/250.)"); //
574   tree->SetAlias("lxr","(lx.fElements-133.41)/250.");
575   tree->SetAlias("qp","(sqrt(qIn.fElements)/10.+(out.fElements>0.5))"); //
576   tree->SetAlias("tl","(ly.fElements/lx.fElements)/0.17");  
577 }
578
579
580 void MakeRes()
581 {
582   //
583   // make final calibration
584   //
585   AliTPCCalPad * calPadRes0 =new AliTPCCalPad(*calPadIn);
586   calPadRes0->Add(calPadCor);       // add correction
587   calPadRes0->Add(calPad2,-1);      // remove global fit
588   calPadRes  = calPadRes0->GlobalFit("Result", calPadOut,kTRUE,1,0.9);
589   //
590   //
591   {
592     Float_t tlmedian =  calPadTL->GetMedian();
593     for (Int_t isector=0;isector<72; isector++){
594       for (UInt_t ich=0;ich<calPadIn->GetCalROC(isector)->GetNchannels();ich++){
595         //
596         //
597         Float_t val0 = calPadRes->GetCalROC(isector)->GetValue(ich);
598         if (TMath::Abs(val0)>0.5) calPadRes->GetCalROC(isector)->SetValue(ich,0);
599         Float_t tl = calPadTL->GetCalROC(isector)->GetValue(ich);
600         Float_t inOut = calPadInOut->GetCalROC(isector)->GetValue(ich);
601         calPadRes->GetCalROC(isector)->SetValue(ich,calPadRes->GetCalROC(isector)->GetValue(ich)+tl+inOut);
602         //
603       }
604     }
605   }
606   calPadRes->Add(calPadCor,-1);     // remove back correction (e.g Pulser time 0)
607
608 }
609
610
611
612
613 void RebuildCE(char *finname, char *pulname){
614   //
615   // Transformation from the CE to the visualization-analisys output
616   //
617   // finname = CE_Vscan_Run_61684-50_170.root;
618   TFile f(finname);
619   AliTPCCalibCE * ce  = (AliTPCCalibCE*)f.Get("AliTPCCalibCE");
620   //
621   AliTPCCalPad *padtime = new AliTPCCalPad((TObjArray*)ce->GetCalPadT0());
622   AliTPCCalPad *padRMS = new AliTPCCalPad((TObjArray*)ce->GetCalPadRMS());
623   AliTPCCalPad *padq = new AliTPCCalPad((TObjArray*)ce->GetCalPadQ());
624   padtime->SetName("CE_T");
625   padRMS->SetName("CE_RMS");
626   padq->SetName("CE_Q");
627
628   TFile f2(pulname);
629   AliTPCCalibPulser *pul = (AliTPCCalibPulser*)f2.Get("AliTPCCalibPulser");
630   AliTPCCalPad *pultime = new AliTPCCalPad((TObjArray*)pul->GetCalPadT0());
631   AliTPCCalPad *pulRMS = new AliTPCCalPad((TObjArray*)pul->GetCalPadRMS());
632   AliTPCCalPad *pulq = new AliTPCCalPad((TObjArray*)pul->GetCalPadQ());
633   pultime->SetName("P_T");
634   pulRMS->SetName("P_RMS");
635   pulq->SetName("P_Q");
636
637
638   AliTPCPreprocessorOnline * preprocesor = new AliTPCPreprocessorOnline;
639   preprocesor->AddComponent(padtime);
640   preprocesor->AddComponent(padq);
641   preprocesor->AddComponent(padRMS);
642   preprocesor->AddComponent(pultime);
643   preprocesor->AddComponent(pulq);
644   preprocesor->AddComponent(pulRMS);
645   preprocesor->DumpToFile(inname);
646 }