]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/CalibMacros/RegisterCorrection.C
ATO-17 - default number of itteration 4. Crosstalk matrix can be checked after each...
[u/mrichter/AliRoot.git] / TPC / CalibMacros / RegisterCorrection.C
1 /*
2   marian.ivanov@cern.ch
3   //
4   Register primitive corrections: base functions for minimization:
5   Id numbers are associated to given primitive corrections.
6   See comments in the function headers. 
7   Used only for residuals minimization not in the reconstruction.
8   File with all primitives expected to be in the current directory:
9   filenames:  
10   TPCCorrectionPrimitives.root                  - Alignment, Quadrants, 2D symentrid and rod misalingment
11   TPCCorrectionPrimitivesROC.root               - ExB distortion due to the common ROC misalignment
12   TPCCorrectionPrimitivesSector.root            - ExB distortion due to the one sector misalingment (sector 0)
13   //      
14
15   RegisterCorrection();                         - Reserved id's  0 -999
16   //
17   RegisterAliTPCFCVoltError3D();                - Reserved id's  0 -99
18   RegisterAliTPCBoundaryVoltError();            - Reserved id's  100-199
19   RegisterAliTPCCalibGlobalMisalignment();      - Reserved id's  200-499
20   RegisterAliTPCExBBShape();                    - Reserved id's  500-600
21   RegisterAliTPCExBTwist();                     - Reserved id's  600-700
22   RegisterAliTPCROCVoltError3D()                - Reserved id's  700-800
23   RegisterAliTPCROCVoltError3DSector()          - Reserved id's  800-900
24   .x ~/rootlogon.C
25   .L $ALICE_ROOT/TPC/CalibMacros/RegisterCorrection.C+
26   RegisterCorrection();
27
28 */
29 /*
30  ExampleDrawing()
31  .x ~/rootlogon.C
32  .L $ALICE_ROOT/TPC/CalibMacros/RegisterCorrection.C+
33  RegisterCorrection();
34
35  //dz shift
36  TF1 f705("f705","AliTPCCorrectionFit::EvalAtPar(0,0,x,0.1,705,0,10)",0,500);
37  f705->Draw();
38  TF1 f705Helix("f705Helix","AliTPCCorrectionFit::EvalAtHelix(0,0,x,0.1,705,0,10)",0,500);
39  f705Helix->Draw();
40  f705->Draw("same");
41
42
43 */
44
45
46 #if !defined(__CINT__) || defined(__MAKECINT__)
47 #include "TFile.h"
48 #include "TObjArray.h"
49 #include "TTreeStream.h"
50 #include "TMath.h" 
51 #include "TGraph.h" 
52 #include "TRandom.h"
53 #include "TTree.h"
54 #include "TF1.h"
55 #include "TH2F.h"
56 #include "TH3F.h"
57 #include "TAxis.h"
58 #include "TPad.h"
59 #include "TCanvas.h"
60 #include "TStyle.h"
61 #include "AliTPCParamSR.h"
62 #include "TDatabasePDG.h"
63 #include "AliTPCCorrection.h"
64 #include "AliTPCFCVoltError3D.h"
65 #include "AliTPCROCVoltError3D.h"
66 #include "AliTPCComposedCorrection.h"
67 #include "AliTPCBoundaryVoltError.h"
68 #include "AliTPCCalibGlobalMisalignment.h"
69 #include "AliTPCExBBShape.h"
70 #include "AliTPCExBTwist.h"
71 #include "AliTPCCorrectionDrift.h"
72 #include "AliMagF.h"
73 #include "AliCDBEntry.h"
74 #include "AliTPCROC.h"
75 #include <TStatToolkit.h>
76 #include "TCut.h"
77 #include "TGraphErrors.h"
78 #include  "AliTrackerBase.h"
79 #include  "TGeoGlobalMagField.h"
80 #include  "TROOT.h"
81 #include "TLinearFitter.h"
82 #endif
83
84
85
86
87 TFile *fCorrections=0;       //file with corrections
88 //
89 //models E field distortion   AliTPCFCVoltError3D
90 //
91 AliTPCFCVoltError3D *rotOFC  =0;     // fit models
92 AliTPCFCVoltError3D *rodOFC1 =0;
93 AliTPCFCVoltError3D *rodOFC2 =0;
94 AliTPCFCVoltError3D *rotIFC  =0;
95 AliTPCFCVoltError3D *rodIFC1 =0;
96 AliTPCFCVoltError3D *rodIFC2 =0;
97 AliTPCFCVoltError3D *rodIFCShift=0;     //common IFC shift
98 AliTPCFCVoltError3D *rodOFCShift=0;     //common OFC shift
99 AliTPCFCVoltError3D *rodIFCSin=0;       //common IFC shift -sinus
100 AliTPCFCVoltError3D *rodOFCSin=0;       //common OFC shift -sinus
101 AliTPCFCVoltError3D *rodIFCCos=0;       //common IFC shift -cos
102 AliTPCFCVoltError3D *rodOFCCos=0;       //common OFC shift -cos
103
104 AliTPCROCVoltError3D *rocRotgXA=0;     // roc rotation A side - inclination in X
105 AliTPCROCVoltError3D *rocRotgYA=0;     // roc rotation A side - inclination in Y
106 AliTPCROCVoltError3D *rocRotgXC=0;     // roc rotation C side - inclination in X
107 AliTPCROCVoltError3D *rocRotgYC=0;     // roc rotation C side - inclination in Y
108 //
109 AliTPCROCVoltError3D *rocDzIROCA=0;      // roc shift A side - in Z
110 AliTPCROCVoltError3D *rocDzIROCC=0;      // roc shift C side - in Z
111 AliTPCROCVoltError3D *rocRotIROCA=0;      // roc rotation A side - in Z
112 AliTPCROCVoltError3D *rocRotIROCC=0;      // roc rotation C side - in Z
113 AliTPCROCVoltError3D *rocDzUDA=0;         // roc shift Up-Down A side
114 AliTPCROCVoltError3D *rocDzUDC=0;         // roc shift Up-Down C side
115 AliTPCROCVoltError3D *rocRotUDA=0;        // roc rotation updown A side
116 AliTPCROCVoltError3D *rocRotUDC=0;        // roc rotation updown C side
117
118 //
119 AliTPCROCVoltError3D *rocShiftIROCA0=0;      // IROC shift A0 side
120 AliTPCROCVoltError3D *rocRotIROCA0=0;        // IROC rot   A0 side
121 AliTPCROCVoltError3D *rocShiftOROCA0=0;      // OROC shift A0 side
122 AliTPCROCVoltError3D *rocRotOROCA0=0;        // OROC rot   A0 side
123 AliTPCROCVoltError3D *rocShiftIROCC0=0;      // IROC shift C0 side
124 AliTPCROCVoltError3D *rocRotIROCC0=0;        // IROC rot   C0 side
125 AliTPCROCVoltError3D *rocShiftOROCC0=0;      // OROC shift C0 side
126 AliTPCROCVoltError3D *rocRotOROCC0=0;        // OROC rot   C0 side
127 //
128 //
129 //
130 AliTPCBoundaryVoltError *boundaryVoltErrorA[8];  // boundary voltage error A side
131 AliTPCBoundaryVoltError *boundaryVoltErrorC[8];  // boundary voltage error C side
132 AliTPCExBBShape *exbShape     = 0;               // nominal correctin
133 AliTPCExBBShape *exbShapeT1X  = 0;               // nominal +deltaT1=0.1
134 AliTPCExBBShape *exbShapeT2X  = 0;               // nominal +deltaT2=0.1
135 AliTPCExBTwist  *twistX    = 0;
136 AliTPCExBTwist  *twistY    = 0;
137 //
138 AliTPCCalibGlobalMisalignment *alignRot0=0;
139 AliTPCCalibGlobalMisalignment *alignRot1=0;
140 AliTPCCalibGlobalMisalignment *alignRot2=0;
141 AliTPCCalibGlobalMisalignment *alignTrans0=0;
142 AliTPCCalibGlobalMisalignment *alignTrans1=0;
143 AliTPCCalibGlobalMisalignment *alignTrans2=0;
144 //
145 AliTPCCalibGlobalMisalignment *alignTrans0D[4]={0};       // delta alignemnt 4 quadrants
146 AliTPCCalibGlobalMisalignment *alignTrans1D[4]={0};       // 
147 AliTPCCalibGlobalMisalignment *alignTrans2D[4]={0};       // 
148 AliTPCCalibGlobalMisalignment *alignRot0D[4]={0};
149 AliTPCCalibGlobalMisalignment *alignRot1D[4]={0};
150 AliTPCCalibGlobalMisalignment *alignRot2D[4]={0};
151
152
153
154
155 AliTPCCorrectionDrift  *calibDrift[7]={0};
156
157
158 //
159 void RegisterAliTPCFCVoltError3D();
160 void RegisterAliTPCCalibGlobalMisalignment();
161 void RegisterAliTPCBoundaryVoltError();
162 void RegisterAliTPCExBShape();
163 void RegisterAliTPCExBTwist();
164 void RegisterAliTPCROCVoltError3D();
165 void RegisterAliTPCROCVoltError3DSector();
166 void RegisterAliTPCCorrectionDrift();
167
168 //
169
170 void RegisterCorrection(Int_t type=0){
171   //
172   //
173   //
174   // check the presence of corrections in file
175   //
176   //gROOT->Macro("ConfigCalibTrain.C(119037)");
177   //
178   //
179   if (type==1) return RegisterAliTPCROCVoltError3D();
180   if (type==2) return RegisterAliTPCROCVoltError3DSector();
181   fCorrections = new TFile("TPCCorrectionPrimitives.root");
182   AliTPCComposedCorrection *corrField3D = (AliTPCComposedCorrection*) fCorrections->Get("TPCFCVoltError3D");
183   // if not make new file
184   if (!corrField3D) fCorrections = new TFile("TPCCorrectionPrimitives.root","update");
185   if (type==0) {
186     RegisterAliTPCROCVoltError3D();
187     RegisterAliTPCROCVoltError3DSector();
188   }
189   RegisterAliTPCCalibGlobalMisalignment();
190   RegisterAliTPCBoundaryVoltError();
191   RegisterAliTPCFCVoltError3D();
192   RegisterAliTPCExBShape();
193   RegisterAliTPCExBTwist();
194   RegisterAliTPCCorrectionDrift();
195   if (fCorrections) fCorrections->Close();
196   //
197 }
198
199
200
201 void RegisterAliTPCFCVoltError3D(){
202   //
203   // Load the models from the file
204   // Or create it
205   // Register functions with following IDs:
206   // IMPORTANT: The nominal shift is in mm 
207   //
208   //  rotOFC  - 0 
209   //  rodOFC1 - 1
210   //  rodOFC2 - 2 
211   //  rotIFC  - 3 
212   //  rodIFC1 - 4 
213   //  rodIFC2 - 5 
214   //  rodIFCShift - 6 
215   //  rodIFCSin   - 7 
216   //  rodIFCCos   - 8 
217   //  rodOFCShift - 9 
218   //  rodOFCSin   - 10 
219   //  rodOFCCos   - 11 
220   //
221   printf("RegisterAliTPCFCVoltError3D()");
222   Int_t volt = 40; // 40 V ~  1mm
223   AliTPCComposedCorrection *corrField3D = (AliTPCComposedCorrection*) fCorrections->Get("TPCFCVoltError3D");    
224   if (corrField3D) { // load form file
225     corrField3D->Print();
226     TCollection *iter = corrField3D->GetCorrections();    
227     rotOFC = (AliTPCFCVoltError3D*)iter->FindObject("rotOFC");
228     rodOFC1 = (AliTPCFCVoltError3D*)iter->FindObject("rodOFC1");
229     rodOFC2 = (AliTPCFCVoltError3D*)iter->FindObject("rodOFC2");
230     rotIFC = (AliTPCFCVoltError3D*)iter->FindObject("rotIFC");
231     rodIFC1 = (AliTPCFCVoltError3D*)iter->FindObject("rodIFC1");
232     rodIFC2 = (AliTPCFCVoltError3D*)iter->FindObject("rodIFC2");
233     //
234     rodIFCShift = (AliTPCFCVoltError3D*)iter->FindObject("rodIFCShift");
235     rodOFCShift = (AliTPCFCVoltError3D*)iter->FindObject("rodOFCShift");
236     rodIFCSin = (AliTPCFCVoltError3D*)iter->FindObject("rodIFCSin");
237     rodOFCSin = (AliTPCFCVoltError3D*)iter->FindObject("rodOFCSin");
238     rodIFCCos = (AliTPCFCVoltError3D*)iter->FindObject("rodIFCCos");
239     rodOFCCos = (AliTPCFCVoltError3D*)iter->FindObject("rodOFCCos");
240   } else {    
241     // OFC 
242     rotOFC = new AliTPCFCVoltError3D();
243     rotOFC->SetOmegaTauT1T2(0,1,1);
244     rotOFC->SetRotatedClipVoltA(1,volt);
245     rotOFC->SetRotatedClipVoltC(1,volt);
246     //
247     rodOFC1 = new AliTPCFCVoltError3D();
248     rodOFC1->SetOmegaTauT1T2(0,1,1);
249     rodOFC1->SetRodVoltShiftA(18,volt);
250     rodOFC1->SetRodVoltShiftC(18,volt);
251     //
252     rodOFC2 = new AliTPCFCVoltError3D();
253     rodOFC2->SetOmegaTauT1T2(0,1,1);
254     rodOFC2->SetCopperRodShiftA(18,volt);
255     rodOFC2->SetCopperRodShiftC(18,volt);    
256     // IFC     
257     rotIFC = new AliTPCFCVoltError3D();
258     rotIFC->SetOmegaTauT1T2(0,1,1);
259     rotIFC->SetRotatedClipVoltA(0,volt);
260     rotIFC->SetRotatedClipVoltC(0,volt);
261     //
262     rodIFC1 = new AliTPCFCVoltError3D();
263     rodIFC1->SetOmegaTauT1T2(0,1,1);
264     rodIFC1->SetRodVoltShiftA(0,volt);
265     rodIFC1->SetRodVoltShiftC(0,volt);
266     //
267     rodIFC2 = new AliTPCFCVoltError3D();
268     rodIFC2->SetOmegaTauT1T2(0,1,1);
269     rodIFC2->SetCopperRodShiftA(0,volt);
270     rodIFC2->SetCopperRodShiftC(0,volt);
271     //
272     rodIFCShift = new AliTPCFCVoltError3D();
273     rodIFCSin = new AliTPCFCVoltError3D();
274     rodIFCCos = new AliTPCFCVoltError3D();
275     rodOFCShift = new AliTPCFCVoltError3D();
276     rodOFCSin = new AliTPCFCVoltError3D();
277     rodOFCCos = new AliTPCFCVoltError3D();
278     for (Int_t isec=0; isec<18; isec++){
279       Double_t phi=TMath::Pi()*isec/9.;
280       rodIFCShift->SetOmegaTauT1T2(0,1,1);
281       rodIFCShift->SetRodVoltShiftA(isec,volt);
282       rodIFCShift->SetRodVoltShiftC(isec,volt);
283       rodIFCSin->SetOmegaTauT1T2(0,1,1);
284       rodIFCSin->SetRodVoltShiftA(isec,volt*TMath::Sin(phi));
285       rodIFCSin->SetRodVoltShiftC(isec,volt*TMath::Sin(phi));
286       rodIFCCos->SetOmegaTauT1T2(0,1,1);
287       rodIFCCos->SetRodVoltShiftA(isec,volt*TMath::Cos(phi));
288       rodIFCCos->SetRodVoltShiftC(isec,volt*TMath::Cos(phi));
289       //
290       rodOFCShift->SetOmegaTauT1T2(0,1,1);
291       rodOFCShift->SetRodVoltShiftA(18+isec,volt);
292       rodOFCShift->SetRodVoltShiftC(18+isec,volt);
293       rodOFCSin->SetOmegaTauT1T2(0,1,1);
294       rodOFCSin->SetRodVoltShiftA(18+isec,volt*TMath::Sin(phi));
295       rodOFCSin->SetRodVoltShiftC(18+isec,volt*TMath::Sin(phi));
296       rodOFCCos->SetOmegaTauT1T2(0,1,1);
297       rodOFCCos->SetRodVoltShiftA(18+isec,volt*TMath::Cos(phi));
298       rodOFCCos->SetRodVoltShiftC(18+isec,volt*TMath::Cos(phi));
299     }
300     //
301     //
302     // Initialization of the lookup tables
303     //
304     printf(" ------- OFC rotated clip:\n"); rotOFC->InitFCVoltError3D();
305     printf(" ------- OFC rod & strip:\n");  rodOFC1->InitFCVoltError3D();
306     printf(" ------- OFC copper rod:\n");   rodOFC2->InitFCVoltError3D();
307     printf(" ------- IFC rotated clip:\n"); rotIFC->InitFCVoltError3D();
308     printf(" ------- IFC rod & strip:\n");  rodIFC1->InitFCVoltError3D();
309     printf(" ------- IFC copper rod:\n");   rodIFC2->InitFCVoltError3D();
310
311     printf(" ------- IFC rod & strip shift:\n");  rodIFCShift->InitFCVoltError3D();
312     printf(" ------- IFC rod & strip sin:\n");    rodIFCSin->InitFCVoltError3D();
313     printf(" ------- IFC rod & strip cos:\n");    rodIFCCos->InitFCVoltError3D();
314     printf(" ------- OFC rod & strip shift:\n");  rodOFCShift->InitFCVoltError3D();
315     printf(" ------- OFC rod & strip sin:\n");    rodOFCSin->InitFCVoltError3D();
316     printf(" ------- OFC rod & strip cos:\n");    rodOFCCos->InitFCVoltError3D();
317
318     // give names
319     rotOFC->SetName("rotOFC");rotOFC->SetTitle("rotOFC");
320     rodOFC1->SetName("rodOFC1");rodOFC1->SetTitle("rodOFC1");
321     rodOFC2->SetName("rodOFC2");rodOFC2->SetTitle("rodOFC2");
322     rotIFC->SetName("rotIFC");rotIFC->SetTitle("rotIFC");
323     rodIFC1->SetName("rodIFC1");rodIFC1->SetTitle("rodIFC1");
324     rodIFC2->SetName("rodIFC2");rodIFC2->SetTitle("rodIFC2");
325     //
326     rodIFCShift->SetName("rodIFCShift");rodIFCShift->SetTitle("rodIFCShift");
327     rodIFCSin->SetName("rodIFCSin");rodIFCSin->SetTitle("rodIFCSin");
328     rodIFCCos->SetName("rodIFCCos");rodIFCCos->SetTitle("rodIFCCos");
329     //
330     rodOFCShift->SetName("rodOFCShift");rodOFCShift->SetTitle("rodOFCShift");
331     rodOFCSin->SetName("rodOFCSin");rodOFCSin->SetTitle("rodOFCSin");
332     rodOFCCos->SetName("rodOFCCos");rodOFCCos->SetTitle("rodOFCCos");
333     //
334     // save in file
335     corrField3D = new AliTPCComposedCorrection();
336     TObjArray *cs = new TObjArray();
337     cs->Add(rotIFC); cs->Add(rotOFC);
338     cs->Add(rodIFC1); cs->Add(rodOFC1);
339     cs->Add(rodIFC2); cs->Add(rodOFC2);
340     cs->Add(rodIFCShift);    cs->Add(rodIFCSin);    cs->Add(rodIFCCos);
341     cs->Add(rodOFCShift);    cs->Add(rodOFCSin);    cs->Add(rodOFCCos);
342     //
343     corrField3D->SetCorrections(cs);
344     corrField3D->SetOmegaTauT1T2(0,1.,1.);
345     corrField3D->Print();    
346     fCorrections->cd();
347     corrField3D->Write("TPCFCVoltError3D");
348   }
349   //
350   AliTPCCorrection::AddVisualCorrection(rotOFC,0); 
351   AliTPCCorrection::AddVisualCorrection(rodOFC1,1); 
352   AliTPCCorrection::AddVisualCorrection(rodOFC2,2); 
353   AliTPCCorrection::AddVisualCorrection(rotIFC,3); 
354   AliTPCCorrection::AddVisualCorrection(rodIFC1,4); 
355   AliTPCCorrection::AddVisualCorrection(rodIFC2,5); 
356   // common corrections
357   //
358   AliTPCCorrection::AddVisualCorrection(rodIFCShift,6); 
359   AliTPCCorrection::AddVisualCorrection(rodIFCSin,7); 
360   AliTPCCorrection::AddVisualCorrection(rodIFCCos,8); 
361   //
362   AliTPCCorrection::AddVisualCorrection(rodIFCShift,9); 
363   AliTPCCorrection::AddVisualCorrection(rodIFCSin,10); 
364   AliTPCCorrection::AddVisualCorrection(rodIFCCos,11); 
365 }
366
367
368 void RegisterAliTPCCalibGlobalMisalignment(){
369   //
370   // Register primitive alignment components.
371   // Linear conbination of primitev forulas used for fit
372   // The nominal delta 1 mm in shift and 1 mrad in rotation
373   // Primitive formulas registeren in AliTPCCoreection::AddvisualCorrection
374   // 20 - deltaX 
375   // 21 - deltaY
376   // 22 - deltaZ
377   // 23 - rot0 (phi)
378   // 24 - rot1 (theta)
379   // 25 - rot2 
380   //
381   printf("RegisterAliTPCCalibGlobalMisalignment()\n");
382   TGeoHMatrix matrixX;
383   TGeoHMatrix matrixY;
384   TGeoHMatrix matrixZ;
385   TGeoRotation rot0;
386   TGeoRotation rot1;
387   TGeoRotation rot2;  //transformation matrices
388   TGeoRotation rot90;  //transformation matrices
389   matrixX.SetDx(0.1); matrixY.SetDy(0.1); matrixZ.SetDz(0.1); //1 mm translation
390   rot0.SetAngles(0.001*TMath::RadToDeg(),0,0);
391   rot1.SetAngles(0,0.001*TMath::RadToDeg(),0);
392   rot2.SetAngles(0,0,0.001*TMath::RadToDeg());
393   //how to get rot02 ?
394   rot90.SetAngles(0,90,0);
395   rot2.MultiplyBy(&rot90,kTRUE);
396   rot90.SetAngles(0,-90,0);
397   rot2.MultiplyBy(&rot90,kFALSE);
398   //
399   alignRot0  =new  AliTPCCalibGlobalMisalignment;
400   alignRot0->SetAlignGlobal(&rot0);
401   alignRot0->SetName("alignRot0");
402   alignRot1=new  AliTPCCalibGlobalMisalignment;
403   alignRot1->SetAlignGlobal(&rot1);
404   alignRot1->SetName("alignRot1");
405   alignRot2=new  AliTPCCalibGlobalMisalignment;
406   alignRot2->SetAlignGlobal(&rot2);
407   alignRot2->SetName("alignRot2");
408   //
409   alignTrans0  =new  AliTPCCalibGlobalMisalignment;
410   alignTrans0->SetAlignGlobal(&matrixX);
411   alignTrans0->SetName("alignTrans0");
412   alignTrans1=new  AliTPCCalibGlobalMisalignment;
413   alignTrans1->SetAlignGlobal(&matrixY);
414   alignTrans1->SetName("alignTrans1");
415   alignTrans2=new  AliTPCCalibGlobalMisalignment;
416   alignTrans2->SetAlignGlobal(&matrixZ);
417   alignTrans2->SetName("alignTrans2");
418   //
419   
420
421   alignRot0D[0]  =new  AliTPCCalibGlobalMisalignment;
422   alignRot0D[0]->SetAlignGlobalDelta(&rot0);
423   alignRot0D[0]->SetName("alignRot0D");
424   alignRot1D[0]=new  AliTPCCalibGlobalMisalignment;
425   alignRot1D[0]->SetAlignGlobalDelta(&rot1);
426   alignRot1D[0]->SetName("alignRot1D");
427   alignRot2D[0]=new  AliTPCCalibGlobalMisalignment;
428   alignRot2D[0]->SetAlignGlobalDelta(&rot2);
429   alignRot2D[0]->SetName("alignRot2D");
430   //
431   alignTrans0D[0]  =new  AliTPCCalibGlobalMisalignment;
432   alignTrans0D[0]->SetAlignGlobalDelta(&matrixX);
433   alignTrans0D[0]->SetName("alignTrans0D");
434   alignTrans1D[0]=new  AliTPCCalibGlobalMisalignment;
435   alignTrans1D[0]->SetAlignGlobalDelta(&matrixY);
436   alignTrans1D[0]->SetName("alignTrans1D");
437   alignTrans2D[0]=new  AliTPCCalibGlobalMisalignment;
438   alignTrans2D[0]->SetAlignGlobalDelta(&matrixZ);
439   alignTrans2D[0]->SetName("alignTrans2D");
440
441   TObjArray * arrayDX = new TObjArray(72);
442   TObjArray * arrayDY = new TObjArray(72);
443   TObjArray * arrayDPhi = new TObjArray(72);
444   //
445   // Up down A side
446   //
447   for (Int_t isec=0; isec<72; isec++){  //A side
448     TGeoHMatrix *matrixDX = new TGeoHMatrix;
449     TGeoHMatrix *matrixDY = new TGeoHMatrix;
450     TGeoRotation *matrixDPhi= new TGeoRotation;
451     arrayDX->AddAt(matrixDX,isec);
452     arrayDY->AddAt(matrixDY,isec);
453     arrayDPhi->AddAt(matrixDPhi,isec);
454     if (isec%36<18) matrixDX->SetDx(isec%18<9?0.1:-0.1);
455     if (isec%36<18) matrixDY->SetDy(isec%18<9?0.1:-0.1);
456     if (isec%36<18) matrixDPhi->SetAngles((isec%18<9?0.001:-0.001)*TMath::RadToDeg(),0,0);
457   }
458   alignTrans0D[1]  =new  AliTPCCalibGlobalMisalignment;
459   alignTrans0D[1]->SetName("alignTrans0UDA");
460   alignTrans0D[1]->SetAlignSectors((TObjArray *)(arrayDX->Clone()));
461   alignTrans1D[1]  =new  AliTPCCalibGlobalMisalignment;
462   alignTrans1D[1]->SetName("alignTrans1UDA");
463   alignTrans1D[1]->SetAlignSectors((TObjArray *)(arrayDY->Clone()));
464   alignRot0D[1]  =new  AliTPCCalibGlobalMisalignment;
465   alignRot0D[1]->SetName("alignRot0UDA");
466   alignRot0D[1]->SetAlignSectors((TObjArray *)(arrayDPhi->Clone()));
467   //
468   // Uu-down C side
469   //
470   for (Int_t isec=0; isec<72; isec++){  //A side
471     TGeoHMatrix *matrixDX = new TGeoHMatrix;
472     TGeoHMatrix *matrixDY = new TGeoHMatrix;
473     TGeoRotation *matrixDPhi= new TGeoRotation;
474     arrayDX->AddAt(matrixDX,isec);
475     arrayDY->AddAt(matrixDY,isec);
476     arrayDPhi->AddAt(matrixDPhi,isec);
477     if (isec%36>=18) matrixDX->SetDx(isec%18<9?0.1:-0.1);
478     if (isec%36>=18) matrixDY->SetDy(isec%18<9?0.1:-0.1);
479     if (isec%36>=18) matrixDPhi->SetAngles((isec%18<9?0.001:-0.001)*TMath::RadToDeg(),0,0);
480   }
481   alignTrans0D[2]  =new  AliTPCCalibGlobalMisalignment;
482   alignTrans0D[2]->SetName("alignTrans0UDC");
483   alignTrans0D[2]->SetAlignSectors((TObjArray *)(arrayDX->Clone()));
484   alignTrans1D[2]  =new  AliTPCCalibGlobalMisalignment;
485   alignTrans1D[2]->SetName("alignTrans1UDC");
486   alignTrans1D[2]->SetAlignSectors((TObjArray *)(arrayDY->Clone()));
487   alignRot0D[2]  =new  AliTPCCalibGlobalMisalignment;
488   alignRot0D[2]->SetName("alignRot0UDC");
489   alignRot0D[2]->SetAlignSectors((TObjArray *)(arrayDPhi->Clone()));
490   //
491
492
493   //
494   AliTPCCorrection::AddVisualCorrection(alignTrans0  ,200);
495   AliTPCCorrection::AddVisualCorrection(alignTrans1  ,201);
496   AliTPCCorrection::AddVisualCorrection(alignTrans2  ,202);
497   AliTPCCorrection::AddVisualCorrection(alignRot0    ,203);
498   AliTPCCorrection::AddVisualCorrection(alignRot1    ,204);
499   AliTPCCorrection::AddVisualCorrection(alignRot2    ,205);
500  
501 }
502
503
504 void RegisterAliTPCBoundaryVoltError(){
505   //
506   // Register phi symetric E filed distortions
507   // 100-108 - A side 0 Field  
508   // 110-118 - C side 0 Field  
509   // 120-128 - A side +0.5 Field  
510   // 130-138 - C side +0.5 Field  
511   // 140-148 - A side -0.5 Field  
512   // 150-158 - C side -0.5 Field  
513   //
514   Double_t vdrift = 2.64; // [cm/us]   // to be updated: per second (ideally)
515   Double_t ezField = 400; // [V/cm]   // to be updated: never (hopefully)
516   Double_t T1 = 1.0;
517   Double_t T2 = 1.0;
518   Double_t wtP = -10.0 * (0.5*10) * vdrift /  ezField ; 
519   Double_t wtM = -10.0 * (0.5*10) * vdrift / -ezField ; 
520
521   printf("RegisterAliTPCBoundaryVoltError()\n");
522   AliTPCComposedCorrection *corrField2D = (AliTPCComposedCorrection*) fCorrections->Get("TPCFCVoltError2D");    
523   //
524   if (!corrField2D){
525     TObjArray *array=new TObjArray(16);
526     Double_t val = 40.; // 1mm
527     Float_t bound0[8] = { 0, 0,0,0,0,0,0,0};
528     Float_t boundAi[8] = { 0, 0,0,0,0,0,0,0};
529     Float_t boundCi[8] = { 0, 0,0,0,0,0,0,0};    
530     for (Int_t ipar=0; ipar<8; ipar++){
531       //
532       boundaryVoltErrorA[ipar] = new AliTPCBoundaryVoltError;
533       boundaryVoltErrorC[ipar] = new AliTPCBoundaryVoltError;
534       boundaryVoltErrorA[ipar]->SetName(Form("BoundaryVoltErrorAsidePar%d",ipar));
535       boundaryVoltErrorA[ipar]->SetTitle(Form("BoundaryVoltErrorAsidePar%d",ipar));
536       boundaryVoltErrorC[ipar]->SetName(Form("BoundaryVoltErrorCsidePar%d",ipar));
537       boundaryVoltErrorC[ipar]->SetTitle(Form("BoundaryVoltErrorCsidePar%d",ipar));
538       for (Int_t jpar=0; jpar<8; jpar++) if (ipar!=jpar){
539         boundAi[jpar]=0;
540         boundCi[jpar]=0;
541       }
542       boundAi[ipar]=val;
543       boundCi[ipar]=val;
544       //
545       boundaryVoltErrorA[ipar]->SetBoundariesA(boundAi);
546       boundaryVoltErrorA[ipar]->SetBoundariesC(bound0);
547       boundaryVoltErrorA[ipar]->InitBoundaryVoltErrorDistortion();  
548       boundaryVoltErrorA[ipar]->SetOmegaTauT1T2(0.,1,1); 
549       //
550       Float_t tempboundAi[8] = { 0, 0,0,0,0,0,-boundCi[6],-boundCi[7]};
551       boundaryVoltErrorC[ipar]->SetBoundariesA(tempboundAi);
552       boundaryVoltErrorC[ipar]->SetBoundariesC(boundCi);
553     
554       boundaryVoltErrorC[ipar]->InitBoundaryVoltErrorDistortion();  
555       boundaryVoltErrorC[ipar]->SetOmegaTauT1T2(0.,1,1); 
556       array->AddAt(boundaryVoltErrorA[ipar],ipar);
557       array->AddAt(boundaryVoltErrorC[ipar],ipar+8);
558       boundaryVoltErrorA[ipar]->Print();
559       boundaryVoltErrorC[ipar]->Print();
560       AliTPCCorrection::AddVisualCorrection(boundaryVoltErrorA[ipar], 100+ipar); 
561       AliTPCCorrection::AddVisualCorrection(boundaryVoltErrorC[ipar], 150+ipar);     
562     }
563     corrField2D = new AliTPCComposedCorrection;
564     corrField2D->SetCorrections(array);
565     corrField2D->SetOmegaTauT1T2(0,1.,1.);
566     corrField2D->Print();    
567     fCorrections->cd();
568     corrField2D->SetName("TPCFCVoltError2D");
569     corrField2D->SetTitle("TPCFCVoltError2D");
570     corrField2D->Write("TPCFCVoltError2D");
571   }else{
572     TObjArray *array = (TObjArray*)corrField2D->GetCorrections();
573     for (Int_t ipar=0; ipar<8; ipar++){
574       boundaryVoltErrorA[ipar] = (AliTPCBoundaryVoltError*) array->At(ipar);
575       boundaryVoltErrorC[ipar] = (AliTPCBoundaryVoltError*) array->At(ipar+8);      
576     }
577   }
578   //
579   // Register correction
580   for (Int_t ipar=0; ipar<8; ipar++){
581     AliTPCCorrection::AddVisualCorrection(boundaryVoltErrorA[ipar], 100+ipar); 
582     AliTPCCorrection::AddVisualCorrection(boundaryVoltErrorC[ipar], 110+ipar);     
583     //
584     // correction for +-0.5 T setting
585     AliTPCCorrection *corrField =0; 
586     corrField=(AliTPCCorrection *)boundaryVoltErrorA[ipar]->Clone();
587     corrField->SetOmegaTauT1T2(wtP,T1,T2);
588     AliTPCCorrection::AddVisualCorrection(corrField,120+ipar);
589
590     corrField=(AliTPCCorrection *)boundaryVoltErrorC[ipar]->Clone();
591     corrField->SetOmegaTauT1T2(wtP,T1,T2);
592     AliTPCCorrection::AddVisualCorrection(corrField,130+ipar);
593     // correction for +-0.5 T setting
594     corrField=(AliTPCCorrection *)boundaryVoltErrorA[ipar]->Clone();
595     corrField->SetOmegaTauT1T2(wtM,T1,T2);
596     AliTPCCorrection::AddVisualCorrection(corrField,140+ipar);
597
598     corrField=(AliTPCCorrection *)boundaryVoltErrorC[ipar]->Clone();
599     corrField->SetOmegaTauT1T2(wtM,T1,T2);
600     AliTPCCorrection::AddVisualCorrection(corrField,150+ipar);
601   }
602   
603 }
604
605
606
607 void RegisterAliTPCExBShape(){
608   //
609   //
610   // 
611   AliMagF *magF = new AliMagF("mag","mag");
612
613   exbShape             = new AliTPCExBBShape;
614   exbShape->SetBField(magF);
615   exbShape->SetName("TPCExBShape");
616   exbShape->SetTitle("TPCExBShape");
617   exbShape->SetOmegaTauT1T2(0,1.,1.);
618   exbShape->Print();   
619   AliTPCCorrection::AddVisualCorrection(exbShape,500); 
620   exbShapeT1X             = new AliTPCExBBShape;
621   exbShapeT1X->SetBField(magF);
622   exbShapeT1X->SetName("TPCExbShapeT1X");
623   exbShapeT1X->SetTitle("TPCExbShapeT1X");
624   exbShapeT1X->SetOmegaTauT1T2(0,1.2,1.);
625   exbShapeT1X->Print();   
626   AliTPCCorrection::AddVisualCorrection(exbShapeT1X,501); 
627   exbShapeT2X             = new AliTPCExBBShape;
628   exbShapeT2X->SetBField(magF);
629   exbShapeT2X->SetName("TPCExbShapeT2X");
630   exbShapeT2X->SetTitle("TPCExbShapeT2X");
631   exbShapeT2X->SetOmegaTauT1T2(0,1.0,1.2);
632   exbShapeT2X->Print();   
633   AliTPCCorrection::AddVisualCorrection(exbShapeT2X,502); 
634 }
635
636
637 void RegisterAliTPCExBTwist(){
638   //
639   //
640   //
641   twistX    = new  AliTPCExBTwist;
642   twistY    = new  AliTPCExBTwist;
643   twistX->SetXTwist(0.001);  // 1 mrad twist in x
644   twistX->SetName("ExBTwistX");
645   twistX->SetTitle("ExBTwistX");
646   twistY->SetYTwist(0.001);  // 1 mrad twist in y
647   twistY->SetName("ExBTwistY");
648   twistY->SetTitle("ExBTwistY");
649   twistX->SetOmegaTauT1T2(0,1.,1.);
650   twistY->SetOmegaTauT1T2(0,1.,1.);      
651   AliTPCCorrection::AddVisualCorrection(twistX,600); 
652   AliTPCCorrection::AddVisualCorrection(twistY,601); 
653 }
654
655 void RegisterAliTPCCorrectionDrift(){
656   //
657   // Drift distortion/correction
658   //
659   for (Int_t idrift=0; idrift<7; idrift++) {
660     calibDrift[idrift]=new AliTPCCorrectionDrift;
661   }
662   calibDrift[0]->SetName("driftT0");
663   calibDrift[0]->SetTitle("driftT0");
664   calibDrift[0]->fZ0Aside=0.1; 
665   calibDrift[0]->fZ0Cside=0.1;
666   calibDrift[1]->SetName("driftScale0");
667   calibDrift[1]->SetTitle("driftScale0");
668   calibDrift[1]->fVScale0=0.001;
669   calibDrift[2]->SetName("driftScaleR");
670   calibDrift[2]->SetTitle("driftScaleR");
671   calibDrift[2]->fVScaleR=0.001;
672   calibDrift[3]->SetName("driftScaleX");
673   calibDrift[3]->SetTitle("driftScaleX");
674   calibDrift[3]->fVScaleX=0.001;
675   calibDrift[4]->SetName("driftScaleY");
676   calibDrift[4]->SetTitle("driftScaleY");
677   calibDrift[4]->fVScaleY=0.001;
678   //
679   calibDrift[5]->SetName("driftIROCDZ");
680   calibDrift[5]->SetTitle("driftIROCDZ");
681   calibDrift[5]->fIROCZ0=0.1; //delta Z for IROCORC
682   //
683   calibDrift[6]->SetName("driftOROCDT");
684   calibDrift[6]->SetTitle("driftOROCDT");
685   calibDrift[6]->fOROCDZ=0.001; //delta Z for IROCORC
686   
687
688 }
689
690
691 void RegisterAliTPCROCVoltError3D(){
692   //
693   // ROC rotation transformation
694   //       700 -709 - 0 field
695   //       710 -719 - +0.5 field
696   //       720 -729 - -0.5 field
697   Double_t vdrift = 2.64; // [cm/us]   // to be updated: per second (ideally)
698   Double_t ezField = 400; // [V/cm]   // to be updated: never (hopefully)
699   Double_t T1 = 1.0;
700   Double_t T2 = 1.0;
701   Double_t wtP = -10.0 * (0.5*10) * vdrift /  ezField ; 
702   Double_t wtM = -10.0 * (0.5*10) * vdrift / -ezField ; 
703
704   //
705   rocRotgXA=0;     // roc rotation A side - inclination in X
706   rocRotgYA=0;     // roc rotation A side - inclination in Y
707   rocRotgXC=0;     // roc rotation C side - inclination in X
708   rocRotgYC=0;     // roc rotation C side - inclination in Y
709   rocDzIROCA=0;      // roc shift A side - in Z
710   rocDzIROCC=0;      // roc shift C side - in Z
711   //
712   rocDzUDA=0;        // roc shift up-down - A side
713   rocDzUDC=0;        // roc shift up-down - C side
714   //
715   rocRotIROCA=0;      // roc rot IROC A side - in Z
716   rocRotIROCC=0;      // roc rot OROC C side - in Z
717   rocRotUDA=0;        // roc rot updown A side
718   rocRotUDC=0;        // roc rot updown C side
719  //
720   printf("RegisterAliTPCROCVoltError3D()");
721   Double_t kAngle=0.001;
722   // reference in lx
723   AliTPCROC * rocInfo = AliTPCROC::Instance();
724   Double_t lxRef  = (rocInfo->GetPadRowRadii(0,62)+rocInfo->GetPadRowRadii(36,0))/2;
725   //
726   TMatrixD matrix(72,3);
727  
728   AliTPCComposedCorrection *corrField3D = 0;
729   TFile *fCorrectionsROC=0;
730   fCorrectionsROC = new TFile("TPCCorrectionPrimitivesROC.root");
731   corrField3D = ( AliTPCComposedCorrection *)fCorrectionsROC->Get("TPCROCVoltError3DRotationgXgY");
732   //
733   if (!corrField3D){
734     fCorrectionsROC = new TFile("TPCCorrectionPrimitivesROC.root","recreate");
735   }  
736   if (corrField3D) { // load from file
737     corrField3D->Print();
738     TCollection *iter = corrField3D->GetCorrections();
739    
740     rocRotgXA=(AliTPCROCVoltError3D*)iter->FindObject("rocRotgXA");    
741    
742     rocRotgYA=(AliTPCROCVoltError3D*)iter->FindObject("rocRotgYA");  
743    
744     rocRotgXC=(AliTPCROCVoltError3D*)iter->FindObject("rocRotgXC");  
745    
746     rocRotgYC=(AliTPCROCVoltError3D*)iter->FindObject("rocRotgYC");  
747     
748     rocDzIROCA=(AliTPCROCVoltError3D*)iter->FindObject("rocDzIROCA");  
749    
750     rocDzIROCC=(AliTPCROCVoltError3D*)iter->FindObject("rocDzIROCC");  
751     //
752     rocDzUDA=(AliTPCROCVoltError3D*)iter->FindObject("rocDzUDA");  
753    
754     rocDzUDC=(AliTPCROCVoltError3D*)iter->FindObject("rocDzUDC");  
755
756     rocRotIROCA=(AliTPCROCVoltError3D*)iter->FindObject("rocRotIROCA");  
757    
758     rocRotIROCC=(AliTPCROCVoltError3D*)iter->FindObject("rocRotIROCC");  
759
760     rocRotUDA=(AliTPCROCVoltError3D*)iter->FindObject("rocRotUDA");  
761    
762     rocRotUDC=(AliTPCROCVoltError3D*)iter->FindObject("rocRotUDC");  
763      
764   } else {
765     corrField3D = new AliTPCComposedCorrection;
766     rocRotgXA=new AliTPCROCVoltError3D;    
767     rocRotgYA=new AliTPCROCVoltError3D;  
768     rocRotgXC=new AliTPCROCVoltError3D;  
769     rocRotgYC=new AliTPCROCVoltError3D;  
770     rocDzIROCA=new AliTPCROCVoltError3D;  
771     rocDzIROCC=new AliTPCROCVoltError3D;  
772     rocDzUDA=new AliTPCROCVoltError3D;  
773     rocDzUDC=new AliTPCROCVoltError3D;  
774     rocRotIROCA=new AliTPCROCVoltError3D;  
775     rocRotIROCC=new AliTPCROCVoltError3D;  
776     rocRotUDA=new AliTPCROCVoltError3D;  
777     rocRotUDC=new AliTPCROCVoltError3D;  
778     //
779     for (Int_t isec=0; isec<72; isec++){
780       Double_t secAlpha = TMath::DegToRad()*(10.+20.*(((Int_t)isec)%18));
781       matrix(isec,0)=0; matrix(isec,1)=0; matrix(isec,2)=0;
782       if (isec%36<18){
783         matrix(isec,0) = kAngle*TMath::Cos(secAlpha)*lxRef;
784         matrix(isec,1) = kAngle*TMath::Cos(secAlpha);
785         matrix(isec,2) = -kAngle*TMath::Sin(secAlpha);
786       }
787     }
788     rocRotgXA->SetROCData(&matrix);
789     //
790     for (Int_t isec=0; isec<72; isec++){
791       Double_t secAlpha = TMath::DegToRad()*(10.+20.*(((Int_t)isec)%18));
792       matrix(isec,0)=0; matrix(isec,1)=0; matrix(isec,2)=0;
793       if (isec%36<18){
794         matrix(isec,0) = kAngle*TMath::Sin(secAlpha)*lxRef;
795         matrix(isec,1) = kAngle*TMath::Sin(secAlpha);
796         matrix(isec,2) = kAngle*TMath::Cos(secAlpha);
797       }
798     }
799     rocRotgYA->SetROCData(&matrix);
800     //
801     for (Int_t isec=0; isec<72; isec++){
802      Double_t secAlpha = TMath::DegToRad()*(10.+20.*(((Int_t)isec)%18));
803       matrix(isec,0)=0; matrix(isec,1)=0; matrix(isec,2)=0;
804       if (isec%36>=18){
805         matrix(isec,0) = kAngle*TMath::Cos(secAlpha)*lxRef;
806         matrix(isec,1) = kAngle*TMath::Cos(secAlpha);
807         matrix(isec,2) = -kAngle*TMath::Sin(secAlpha);
808       }
809     }
810     rocRotgXC->SetROCData(&matrix);
811     //
812     for (Int_t isec=0; isec<72; isec++){
813       Double_t secAlpha = TMath::DegToRad()*(10.+20.*(((Int_t)isec)%18));
814       matrix(isec,0)=0; matrix(isec,1)=0; matrix(isec,2)=0;
815       if (isec%36>=18){
816         matrix(isec,0) = kAngle*TMath::Sin(secAlpha)*lxRef;
817         matrix(isec,1) = kAngle*TMath::Sin(secAlpha);
818         matrix(isec,2) = kAngle*TMath::Cos(secAlpha);
819       }
820     }
821     rocRotgYC->SetROCData(&matrix);
822
823     //
824     //
825     for (Int_t isec=0; isec<72; isec++){
826       matrix(isec,0)=0; matrix(isec,1)=0; matrix(isec,2)=0;
827       if (isec<18){
828         matrix(isec,0) = 0.1;  // 1 mm 
829         matrix(isec,1) = 0;
830         matrix(isec,2) = 0;
831       }
832     }
833     rocDzIROCA->SetROCData(&matrix);
834     //
835     for (Int_t isec=0; isec<72; isec++){
836       matrix(isec,0)=0; matrix(isec,1)=0; matrix(isec,2)=0;
837       if (isec>=18 && isec<36){
838         matrix(isec,0) = 0.1;  // 1 mm 
839         matrix(isec,1) = 0;
840         matrix(isec,2) = 0;
841       }
842     }
843     rocDzIROCC->SetROCData(&matrix);
844
845     //
846     //
847     for (Int_t isec=0; isec<72; isec++){
848       matrix(isec,0)=0; matrix(isec,1)=0; matrix(isec,2)=0;
849       if (isec%36<18){
850         matrix(isec,0) = (isec%18<9)? 0.05:-0.05;  // 1 mm 
851         matrix(isec,1) = 0;
852         matrix(isec,2) = 0;
853       }
854     }
855     rocDzUDA->SetROCData(&matrix);
856     //
857     for (Int_t isec=0; isec<72; isec++){
858       matrix(isec,0)=0; matrix(isec,1)=0; matrix(isec,2)=0;
859       if (isec%36>=18){
860         matrix(isec,0) = (isec%18<9)?0.05:-0.05;  // 1 mm 
861         matrix(isec,1) = 0;
862         matrix(isec,2) = 0;
863       }
864     }
865     rocDzUDC->SetROCData(&matrix);
866     //
867     //
868     for (Int_t isec=0; isec<72; isec++){
869       matrix(isec,0)=0; matrix(isec,1)=0; matrix(isec,2)=0;
870       if (isec<18){
871         matrix(isec,0) = 0;   
872         matrix(isec,1) = kAngle;
873         matrix(isec,2) = 0;
874       }
875     }
876     //
877     rocRotIROCA->SetROCData(&matrix);
878     //
879     for (Int_t isec=0; isec<72; isec++){
880       matrix(isec,0)=0; matrix(isec,1)=0; matrix(isec,2)=0;
881       if (isec>=18 && isec<36){
882         matrix(isec,0) = 0;
883         matrix(isec,1) = kAngle;
884         matrix(isec,2) = 0;
885       }
886     }
887     rocRotIROCC->SetROCData(&matrix);
888     //
889     //
890     for (Int_t isec=0; isec<72; isec++){
891       matrix(isec,0)=0; matrix(isec,1)=0; matrix(isec,2)=0;
892       if (isec%36<18){
893         matrix(isec,0) = 0;   
894         matrix(isec,1) = (isec%18<9)?kAngle:-kAngle;
895         matrix(isec,2) = 0;
896       }
897     }
898     //
899     rocRotUDA->SetROCData(&matrix);
900     //
901     for (Int_t isec=0; isec<72; isec++){
902       matrix(isec,0)=0; matrix(isec,1)=0; matrix(isec,2)=0;
903       if (isec%36>=18){
904         matrix(isec,0) = 0;
905         matrix(isec,1) = (isec%18<9)?kAngle:-kAngle;
906         matrix(isec,2) = 0;
907       }
908     }
909     rocRotUDC->SetROCData(&matrix);
910
911
912     //
913     rocRotgXA->SetElectronArrivalCorrection(kFALSE);
914     rocRotgYA->SetElectronArrivalCorrection(kFALSE);
915     rocRotgXC->SetElectronArrivalCorrection(kFALSE);
916     rocRotgYC->SetElectronArrivalCorrection(kFALSE);
917     rocDzIROCA->SetElectronArrivalCorrection(kFALSE);
918     rocDzIROCC->SetElectronArrivalCorrection(kFALSE);
919     rocDzUDA->SetElectronArrivalCorrection(kFALSE);
920     rocDzUDC->SetElectronArrivalCorrection(kFALSE);
921     rocRotIROCA->SetElectronArrivalCorrection(kFALSE);
922     rocRotIROCC->SetElectronArrivalCorrection(kFALSE);
923     rocRotUDA->SetElectronArrivalCorrection(kFALSE);
924     rocRotUDC->SetElectronArrivalCorrection(kFALSE);
925
926     /* // verification plots
927     rocRotgXA.CreateHistoOfZAlignment(0,500,500)->Draw("surf2"); 
928     rocRotgYA.CreateHistoOfZAlignment(0,500,500)->Draw("surf2"); 
929     rocRotgXC.CreateHistoOfZAlignment(1,500,500)->Draw("surf2"); 
930     rocRotgYC.CreateHistoOfZAlignment(1,500,500)->Draw("surf2"); 
931     */
932
933     //
934     rocRotgXA->SetName("rocRotgXA");rocRotgXA->SetTitle("rocRotgXA");
935     rocRotgYA->SetName("rocRotgYA");rocRotgYA->SetTitle("rocRotgYA");
936     rocRotgXC->SetName("rocRotgXC");rocRotgXC->SetTitle("rocRotgXC");
937     rocRotgYC->SetName("rocRotgYC");rocRotgYC->SetTitle("rocRotgYC");
938     rocDzIROCA->SetName("rocDzIROCA");rocDzIROCA->SetTitle("rocDzIROCA");
939     rocDzIROCC->SetName("rocDzIROCC");rocDzIROCC->SetTitle("rocDzIROCC");
940     rocDzUDA->SetName("rocDzUDA");rocDzUDA->SetTitle("rocDzUDA");
941     rocDzUDC->SetName("rocDzUDC");rocDzUDC->SetTitle("rocDzUDC");
942     rocRotIROCA->SetName("rocRotIROCA");rocRotIROCA->SetTitle("rocRotIROCA");
943     rocRotIROCC->SetName("rocRotIROCC");rocRotIROCC->SetTitle("rocRotIROCC");
944     rocRotUDA->SetName("rocRotUDA");rocRotUDA->SetTitle("rocRotUDA");
945     rocRotUDC->SetName("rocRotUDC");rocRotUDC->SetTitle("rocRotUDC");
946     //
947     //
948     TObjArray *cs = new TObjArray();
949     cs->Add(rocRotgXA);
950     cs->Add(rocRotgYA);
951     cs->Add(rocRotgXC);
952     cs->Add(rocRotgYC);
953     cs->Add(rocDzIROCA);
954     cs->Add(rocDzIROCC);
955     cs->Add(rocDzUDA);
956     cs->Add(rocDzUDC);
957     cs->Add(rocRotIROCA);
958     cs->Add(rocRotIROCC);
959     cs->Add(rocRotUDA);
960     cs->Add(rocRotUDC);
961     corrField3D->SetCorrections(cs);
962     corrField3D->SetOmegaTauT1T2(0,1.,1.);
963     corrField3D->Print();
964     fCorrectionsROC->cd();
965     corrField3D->Init();
966     corrField3D->Print("da");
967     fCorrectionsROC->cd();
968     corrField3D->Write("TPCROCVoltError3DRotationgXgY");
969   }
970   AliTPCCorrection::AddVisualCorrection(rocRotgXA,701); 
971   AliTPCCorrection::AddVisualCorrection(rocRotgYA,702); 
972   AliTPCCorrection::AddVisualCorrection(rocRotgXC,703); 
973   AliTPCCorrection::AddVisualCorrection(rocRotgYC,704); 
974   AliTPCCorrection::AddVisualCorrection(rocDzIROCA,705); 
975   AliTPCCorrection::AddVisualCorrection(rocDzIROCC,706); 
976   AliTPCCorrection::AddVisualCorrection(rocDzUDA,709); 
977   AliTPCCorrection::AddVisualCorrection(rocDzUDC,710); 
978   AliTPCCorrection::AddVisualCorrection(rocRotIROCA,707); 
979   AliTPCCorrection::AddVisualCorrection(rocRotIROCC,708); 
980   AliTPCCorrection::AddVisualCorrection(rocRotUDA,711); 
981   AliTPCCorrection::AddVisualCorrection(rocRotUDC,712); 
982
983   AliTPCCorrection *corrPlus =0; 
984   //
985   corrPlus=(AliTPCCorrection *)rocRotgXA->Clone();
986   corrPlus->SetOmegaTauT1T2(wtP,T1,T2);
987   AliTPCCorrection::AddVisualCorrection(corrPlus,711);
988   //
989   corrPlus=(AliTPCCorrection *)rocRotgYA->Clone();
990   corrPlus->SetOmegaTauT1T2(wtP,T1,T2);
991   AliTPCCorrection::AddVisualCorrection(corrPlus,712);
992   //
993   corrPlus=(AliTPCCorrection *)rocRotgXC->Clone();
994   corrPlus->SetOmegaTauT1T2(wtP,T1,T2);
995   AliTPCCorrection::AddVisualCorrection(corrPlus,713);
996   //
997   corrPlus=(AliTPCCorrection *)rocRotgYC->Clone();
998   corrPlus->SetOmegaTauT1T2(wtP,T1,T2);
999   AliTPCCorrection::AddVisualCorrection(corrPlus,714);
1000   //
1001   corrPlus=(AliTPCCorrection *)rocDzIROCA->Clone();
1002   corrPlus->SetOmegaTauT1T2(wtP,T1,T2);
1003   AliTPCCorrection::AddVisualCorrection(corrPlus,715);
1004   //
1005   corrPlus=(AliTPCCorrection *)rocDzIROCC->Clone();
1006   corrPlus->SetOmegaTauT1T2(wtP,T1,T2);
1007   AliTPCCorrection::AddVisualCorrection(corrPlus,716);
1008   //
1009   corrPlus=(AliTPCCorrection *)rocRotIROCA->Clone();
1010   corrPlus->SetOmegaTauT1T2(wtP,T1,T2);
1011   AliTPCCorrection::AddVisualCorrection(corrPlus,717);
1012   //
1013   corrPlus=(AliTPCCorrection *)rocDzIROCC->Clone();
1014   corrPlus->SetOmegaTauT1T2(wtP,T1,T2);
1015   AliTPCCorrection::AddVisualCorrection(corrPlus,718);
1016   //
1017   //
1018   AliTPCCorrection *corrMinus =0; 
1019   //
1020   corrMinus=(AliTPCCorrection *)rocRotgXA->Clone();
1021   corrMinus->SetOmegaTauT1T2(wtM,T1,T2);
1022   AliTPCCorrection::AddVisualCorrection(corrMinus,721);
1023   //
1024   corrMinus=(AliTPCCorrection *)rocRotgYA->Clone();
1025   corrMinus->SetOmegaTauT1T2(wtM,T1,T2);
1026   AliTPCCorrection::AddVisualCorrection(corrMinus,722);
1027   //
1028   corrMinus=(AliTPCCorrection *)rocRotgXC->Clone();
1029   corrMinus->SetOmegaTauT1T2(wtM,T1,T2);
1030   AliTPCCorrection::AddVisualCorrection(corrMinus,723);
1031   //
1032   corrMinus=(AliTPCCorrection *)rocRotgYC->Clone();
1033   corrMinus->SetOmegaTauT1T2(wtM,T1,T2);
1034   AliTPCCorrection::AddVisualCorrection(corrMinus,724);
1035   //
1036   corrMinus=(AliTPCCorrection *)rocDzIROCA->Clone();
1037   corrMinus->SetOmegaTauT1T2(wtM,T1,T2);
1038   AliTPCCorrection::AddVisualCorrection(corrMinus,725);
1039   //
1040   corrMinus=(AliTPCCorrection *)rocDzIROCC->Clone();
1041   corrMinus->SetOmegaTauT1T2(wtM,T1,T2);
1042   AliTPCCorrection::AddVisualCorrection(corrMinus,726);
1043   //
1044   corrMinus=(AliTPCCorrection *)rocRotIROCA->Clone();
1045   corrMinus->SetOmegaTauT1T2(wtM,T1,T2);
1046   AliTPCCorrection::AddVisualCorrection(corrMinus,727);
1047   //
1048   corrMinus=(AliTPCCorrection *)rocDzIROCC->Clone();
1049   corrMinus->SetOmegaTauT1T2(wtM,T1,T2);
1050   AliTPCCorrection::AddVisualCorrection(corrMinus,728);
1051   //
1052
1053   fCorrectionsROC->Close();
1054   delete fCorrectionsROC;
1055 }
1056
1057
1058 void RegisterAliTPCROCVoltError3DSector(){
1059   //
1060   // ROC rotation and shift transformation
1061   // 800-819 -   0.0 Field
1062   // 820-839 -  +0.5 Field
1063   // 840-859 -  +0.5 Field
1064
1065   rocShiftIROCA0=0;      // IROC shift A0 side
1066   rocRotIROCA0=0;        // IROC rot   A0 side
1067   rocShiftOROCA0=0;      // OROC shift A0 side
1068   rocRotOROCA0=0;        // OROC rot   A0 side
1069   rocShiftIROCC0=0;      // IROC shift C0 side
1070   rocRotIROCC0=0;        // IROC rot   C0 side
1071   rocShiftOROCC0=0;      // OROC shift C0 side
1072   rocRotOROCC0=0;        // OROC rot   C0 side
1073   Double_t vdrift = 2.64; // [cm/us]   // to be updated: per second (ideally)
1074   Double_t ezField = 400; // [V/cm]   // to be updated: never (hopefully)
1075   Double_t T1 = 1.0;
1076   Double_t T2 = 1.0;
1077
1078   //  Double_t wt = -10.0 * (bzField*10) * vdrift / ezField ; 
1079
1080   //
1081   //
1082   printf("RegisterAliTPCROCVoltError3DSector()");
1083   Double_t kAngle=0.001;
1084   Double_t kDz=0.1;
1085   // reference in lx
1086   //
1087   TMatrixD matrix(72,3);
1088  
1089   AliTPCComposedCorrection *corrField3DSector = 0;
1090   TFile *fCorrectionsROC=0;
1091   fCorrectionsROC = new TFile("TPCCorrectionPrimitivesSector.root");
1092   corrField3DSector = ( AliTPCComposedCorrection *)fCorrectionsROC->Get("TPCROCVoltError3DSector");
1093   //
1094   if (!corrField3DSector){
1095     fCorrectionsROC = new TFile("TPCCorrectionPrimitivesSector.root","recreate");
1096   }  
1097   if (corrField3DSector) { // load from file
1098     corrField3DSector->Print();
1099     TCollection *iter = corrField3DSector->GetCorrections();
1100     //
1101     rocShiftIROCA0=(AliTPCROCVoltError3D*)iter->FindObject("rocShiftIROCA0");   // IROC shift A0 side
1102     rocRotIROCA0=(AliTPCROCVoltError3D*)iter->FindObject("rocRotIROCA0");       // IROC rot   A0 side
1103     rocShiftOROCA0=(AliTPCROCVoltError3D*)iter->FindObject("rocShiftOROCA0");   // OROC shift A0 side
1104     rocRotOROCA0=(AliTPCROCVoltError3D*)iter->FindObject("rocRotOROCA0");       // OROC rot   A0 side
1105     rocShiftIROCC0=(AliTPCROCVoltError3D*)iter->FindObject("rocShiftIROCC0");   // IROC shift C0 side
1106     rocRotIROCC0=(AliTPCROCVoltError3D*)iter->FindObject("rocRotIROCC0");       // IROC rot   C0 side
1107     rocShiftOROCC0=(AliTPCROCVoltError3D*)iter->FindObject("rocShiftOROCC0");   // OROC shift C0 side
1108     rocRotOROCC0=(AliTPCROCVoltError3D*)iter->FindObject("rocRotOROCC0");       // OROC rot   C0 side
1109      
1110   } else {
1111     corrField3DSector = new AliTPCComposedCorrection;
1112     rocShiftIROCA0=new AliTPCROCVoltError3D;      // IROC shift A0 side
1113     rocRotIROCA0=new AliTPCROCVoltError3D;        // IROC rot   A0 side
1114     rocShiftOROCA0=new AliTPCROCVoltError3D;      // OROC shift A0 side
1115     rocRotOROCA0=new AliTPCROCVoltError3D;        // OROC rot   A0 side
1116     rocShiftIROCC0=new AliTPCROCVoltError3D;      // IROC shift C0 side
1117     rocRotIROCC0=new AliTPCROCVoltError3D;        // IROC rot   C0 side
1118     rocShiftOROCC0=new AliTPCROCVoltError3D;      // OROC shift C0 side
1119     rocRotOROCC0=new AliTPCROCVoltError3D;        // OROC rot   C0 side
1120     //
1121     matrix.Zero(); matrix(0,0)=kDz; 
1122     rocShiftIROCA0->SetROCData(&matrix);
1123     matrix.Zero(); matrix(0,1)=kAngle; 
1124     rocRotIROCA0->SetROCData(&matrix);
1125     matrix.Zero(); matrix(36,0)=kDz; 
1126     rocShiftOROCA0->SetROCData(&matrix);
1127     matrix.Zero(); matrix(36,1)=kAngle; 
1128     rocRotOROCA0->SetROCData(&matrix);
1129
1130     matrix.Zero(); matrix(18,0)=kDz; 
1131     rocShiftIROCC0->SetROCData(&matrix);
1132     matrix.Zero(); matrix(18,1)=kAngle; 
1133     rocRotIROCC0->SetROCData(&matrix);
1134     matrix.Zero(); matrix(36+18,0)=kDz; 
1135     rocShiftOROCC0->SetROCData(&matrix);
1136     matrix.Zero(); matrix(36+18,1)=kAngle; 
1137     rocRotOROCC0->SetROCData(&matrix);
1138     //
1139     rocShiftIROCA0->SetElectronArrivalCorrection(kFALSE);     // IROC shift A0 side
1140     rocRotIROCA0->SetElectronArrivalCorrection(kFALSE);        // IROC rot   A0 side
1141     rocShiftOROCA0->SetElectronArrivalCorrection(kFALSE);      // OROC shift A0 side
1142     rocRotOROCA0->SetElectronArrivalCorrection(kFALSE);        // OROC rot   A0 side
1143     rocShiftIROCC0->SetElectronArrivalCorrection(kFALSE);      // IROC shift C0 side
1144     rocRotIROCC0->SetElectronArrivalCorrection(kFALSE);        // IROC rot   C0 side
1145     rocShiftOROCC0->SetElectronArrivalCorrection(kFALSE);      // OROC shift C0 side
1146     rocRotOROCC0->SetElectronArrivalCorrection(kFALSE);        // OROC rot   C0 side
1147
1148     /* // verification plots
1149     */
1150     //
1151     rocShiftIROCA0->SetName("rocShiftIROCA0");rocShiftIROCA0->SetTitle("rocShiftIROCA0");
1152     rocRotIROCA0->SetName("rocRotIROCA0");rocRotIROCA0->SetTitle("rocRotIROCA0");
1153     rocShiftOROCA0->SetName("rocShiftOROCA0"); rocShiftOROCA0->SetTitle("rocShiftOROCA0");
1154     rocRotOROCA0->SetName("rocRotOROCA0");rocRotOROCA0->SetTitle("rocRotOROCA0");
1155     //
1156     rocShiftIROCC0->SetName("rocShiftIROCC0");rocShiftIROCC0->SetTitle("rocShiftIROCC0");
1157     rocRotIROCC0->SetName("rocRotIROCC0");rocRotIROCC0->SetTitle("rocRotIROCC0");
1158     rocShiftOROCC0->SetName("rocShiftOROCC0");rocShiftOROCC0->SetTitle("rocShiftOROCC0");
1159     rocRotOROCC0->SetName("rocRotOROCC0");rocRotOROCC0->SetTitle("rocRotOROCC0");
1160     //
1161     //
1162     TObjArray *cs = new TObjArray();
1163     cs->Add(rocShiftIROCA0);      // IROC shift A0 side
1164     cs->Add(rocRotIROCA0);        // IROC rot   A0 side
1165     cs->Add(rocShiftOROCA0);      // OROC shift A0 side
1166     cs->Add(rocRotOROCA0);        // OROC rot   A0 side
1167     cs->Add(rocShiftIROCC0);      // IROC shift C0 side
1168     cs->Add(rocRotIROCC0);        // IROC rot   C0 side
1169     cs->Add(rocShiftOROCC0);      // OROC shift C0 side
1170     cs->Add(rocRotOROCC0);        // OROC rot   C0 side
1171     //
1172     corrField3DSector->SetCorrections(cs);
1173     corrField3DSector->SetOmegaTauT1T2(0,T1,T2);
1174     corrField3DSector->Print();
1175     //
1176
1177     fCorrectionsROC->cd();
1178     corrField3DSector->Init();
1179     corrField3DSector->Print("da");
1180     fCorrectionsROC->cd();
1181     corrField3DSector->Write("TPCROCVoltError3DSector");
1182   }
1183   AliTPCCorrection::AddVisualCorrection(rocShiftIROCA0,800);      // IROC shift A0 side
1184   AliTPCCorrection::AddVisualCorrection(rocRotIROCA0,801);        // IROC rot   A0 side
1185   AliTPCCorrection::AddVisualCorrection(rocShiftOROCA0,802);      // OROC shift A0 side
1186   AliTPCCorrection::AddVisualCorrection(rocRotOROCA0,803);        // OROC rot   A0 side
1187   AliTPCCorrection::AddVisualCorrection(rocShiftIROCC0,804);      // IROC shift C0 side
1188   AliTPCCorrection::AddVisualCorrection(rocRotIROCC0,805);        // IROC rot   C0 side
1189   AliTPCCorrection::AddVisualCorrection(rocShiftOROCC0,806);      // OROC shift C0 side
1190   AliTPCCorrection::AddVisualCorrection(rocRotOROCC0,807);        // OROC rot   C0 side 
1191   //
1192   // Register correction for plus setting
1193   AliTPCCorrection *corr =0; 
1194   Double_t wtp = -10.0 * (0.5*10) * vdrift / ezField ; 
1195   Double_t wtm = -10.0 * (0.5*10) * vdrift / -ezField ; 
1196
1197   corr=(AliTPCCorrection *)rocShiftIROCA0->Clone();
1198   corr->SetOmegaTauT1T2(wtp,T1,T2);
1199   AliTPCCorrection::AddVisualCorrection(corr,820);           // IROC shift A0 side + Plus field
1200   //
1201   corr=(AliTPCCorrection *)rocRotIROCA0->Clone();
1202   corr->SetOmegaTauT1T2(wtp,T1,T2);
1203   AliTPCCorrection::AddVisualCorrection(corr,821);           // IROC rot   A0 side
1204   //
1205   corr=(AliTPCCorrection *)rocShiftOROCA0->Clone();
1206   corr->SetOmegaTauT1T2(wtp,T1,T2);
1207   AliTPCCorrection::AddVisualCorrection(corr,822);            // OROC shift   A0 side
1208   //
1209   corr=(AliTPCCorrection *)rocRotOROCA0->Clone();
1210   corr->SetOmegaTauT1T2(wtp,T1,T2);
1211   AliTPCCorrection::AddVisualCorrection(corr,823);            // OROC rot   A0 side
1212   corr=(AliTPCCorrection *)rocShiftIROCC0->Clone();
1213   corr->SetOmegaTauT1T2(wtp,T1,T2);
1214   AliTPCCorrection::AddVisualCorrection(corr,824);           // IROC shift C0 side + Plus field
1215   //
1216   corr=(AliTPCCorrection *)rocRotIROCC0->Clone();
1217   corr->SetOmegaTauT1T2(wtp,T1,T2);
1218   AliTPCCorrection::AddVisualCorrection(corr,825);           // IROC rot   C0 side
1219   //
1220   corr=(AliTPCCorrection *)rocShiftOROCC0->Clone();
1221   corr->SetOmegaTauT1T2(wtp,T1,T2);
1222   AliTPCCorrection::AddVisualCorrection(corr,826);            // OROC shift   C0 side
1223   //
1224   corr=(AliTPCCorrection *)rocRotOROCC0->Clone();
1225   corr->SetOmegaTauT1T2(wtp,T1,T2);
1226   AliTPCCorrection::AddVisualCorrection(corr,827);            // OROC rot   C0 side
1227   //
1228   corr=(AliTPCCorrection *)rocShiftIROCA0->Clone();
1229   corr->SetOmegaTauT1T2(wtm,T1,T2);
1230   AliTPCCorrection::AddVisualCorrection(corr,840);           // IROC shift A0 side + Plus field
1231   //
1232   corr=(AliTPCCorrection *)rocRotIROCA0->Clone();
1233   corr->SetOmegaTauT1T2(wtm,T1,T2);
1234   AliTPCCorrection::AddVisualCorrection(corr,841);           // IROC rot   A0 side
1235   //
1236   corr=(AliTPCCorrection *)rocShiftOROCA0->Clone();
1237   corr->SetOmegaTauT1T2(wtm,T1,T2);
1238   AliTPCCorrection::AddVisualCorrection(corr,842);            // OROC shift   A0 side
1239   //
1240   corr=(AliTPCCorrection *)rocRotOROCA0->Clone();
1241   corr->SetOmegaTauT1T2(wtm,T1,T2);
1242   AliTPCCorrection::AddVisualCorrection(corr,843);            // OROC rot   A0 side
1243   corr=(AliTPCCorrection *)rocShiftIROCC0->Clone();
1244   corr->SetOmegaTauT1T2(wtm,T1,T2);
1245   AliTPCCorrection::AddVisualCorrection(corr,844);           // IROC shift C0 side + Plus field
1246   //
1247   corr=(AliTPCCorrection *)rocRotIROCC0->Clone();
1248   corr->SetOmegaTauT1T2(wtm,T1,T2);
1249   AliTPCCorrection::AddVisualCorrection(corr,845);           // IROC rot   C0 side
1250   //
1251   corr=(AliTPCCorrection *)rocShiftOROCC0->Clone();
1252   corr->SetOmegaTauT1T2(wtm,T1,T2);
1253   AliTPCCorrection::AddVisualCorrection(corr,846);            // OROC shift   C0 side
1254   //
1255   corr=(AliTPCCorrection *)rocRotOROCC0->Clone();
1256   corr->SetOmegaTauT1T2(wtm,T1,T2);
1257   AliTPCCorrection::AddVisualCorrection(corr,847);            // OROC rot   C0 side
1258   //
1259   fCorrectionsROC->Close();
1260   delete fCorrectionsROC;
1261 }
1262
1263
1264
1265
1266
1267 AliTPCComposedCorrection * MakeComposedCorrectionExB(){
1268   //
1269   // make composed corection for ExB scanning
1270   //
1271   RegisterCorrection();
1272   //
1273    //
1274   TObjArray * corr = new TObjArray;       // primitive corrections - for fitting
1275   TObjArray * testCorr = new TObjArray;   // test corrections - to be used as benchmark for fitting
1276   //
1277   corr->AddLast(twistX);
1278   corr->AddLast(twistY);
1279   corr->AddLast(exbShape);
1280   corr->AddLast(exbShapeT1X);
1281   corr->AddLast(exbShapeT2X);
1282   //
1283   for (Int_t i=0; i<8; i++){
1284     corr->AddLast(boundaryVoltErrorA[i]);
1285     corr->AddLast(boundaryVoltErrorC[i]);
1286   }
1287   //
1288   // ROD alignment
1289   //
1290   corr->AddLast(rodIFCCos);
1291   corr->AddLast(rodIFCSin);
1292   corr->AddLast(rodOFCSin);
1293   corr->AddLast(rodOFCCos);
1294   //alignment
1295   corr->AddLast(alignTrans0);
1296   corr->AddLast(alignTrans1);
1297   corr->AddLast(alignTrans2);
1298   corr->AddLast(alignRot0);
1299   corr->AddLast(alignRot1);
1300   corr->AddLast(alignRot2);
1301   //
1302   corr->AddLast(alignTrans0D[0]);
1303   corr->AddLast(alignTrans1D[0]);
1304   corr->AddLast(alignTrans2D[0]);
1305   corr->AddLast(alignRot0D[0]);
1306   corr->AddLast(alignRot1D[0]);
1307   corr->AddLast(alignRot2D[0]);
1308   corr->AddLast(alignTrans0D[1]);
1309   corr->AddLast(alignTrans1D[1]);
1310   corr->AddLast(alignRot0D[1]);
1311   corr->AddLast(alignTrans0D[2]);
1312   corr->AddLast(alignTrans1D[2]);
1313   corr->AddLast(alignRot0D[2]);
1314   //
1315   // z alignment + E field distortion due z misalignment
1316   //
1317   corr->AddLast(rocRotgXA);  // A side C side
1318   corr->AddLast(rocRotgYA);
1319   corr->AddLast(rocRotgXC);
1320   corr->AddLast(rocRotgYC);
1321   corr->AddLast(rocDzIROCA);
1322   corr->AddLast(rocDzIROCC);
1323   corr->AddLast(rocRotIROCA);
1324   corr->AddLast(rocRotIROCC);
1325   corr->AddLast(rocDzUDA);
1326   corr->AddLast(rocDzUDC);
1327   corr->AddLast(rocRotUDA);
1328   corr->AddLast(rocRotUDC);
1329   //
1330   //
1331   corr->AddLast(calibDrift[0]);
1332   corr->AddLast(calibDrift[1]);
1333   corr->AddLast(calibDrift[2]);
1334   corr->AddLast(calibDrift[3]);
1335   corr->AddLast(calibDrift[4]);
1336   corr->AddLast(calibDrift[5]);
1337   corr->AddLast(calibDrift[6]);
1338   //
1339   // setup test correction 
1340   // 
1341   testCorr->AddLast(rodIFCCos);
1342   testCorr->AddLast(rodIFCSin);
1343   testCorr->AddLast(rodOFCSin);
1344   testCorr->AddLast(rodOFCCos);
1345   //
1346   testCorr->AddLast(twistX);
1347   testCorr->AddLast(twistY);
1348   testCorr->AddLast(alignTrans0);
1349   testCorr->AddLast(alignTrans1);
1350   testCorr->AddLast(alignTrans2);
1351   testCorr->AddLast(alignRot0);
1352   testCorr->AddLast(alignRot1);
1353   testCorr->AddLast(alignRot2);  
1354   testCorr->AddLast(rocRotgXA);  // A side C side
1355   testCorr->AddLast(rocRotgYA);
1356   testCorr->AddLast(rocRotgXC);
1357   testCorr->AddLast(rocRotgYC);
1358   testCorr->AddLast(rocDzIROCA);
1359   testCorr->AddLast(rocDzIROCC);
1360   testCorr->AddLast(rocRotIROCA);
1361   testCorr->AddLast(rocRotIROCC);
1362   Int_t entries=testCorr->GetEntries();
1363   TVectorD weights(entries);
1364   for (Int_t i=0; i<entries; i++) weights[i]=1;
1365   //
1366   AliTPCComposedCorrection *composedTest= new AliTPCComposedCorrection ;
1367   composedTest->SetName("FitSample");
1368   composedTest->SetTitle("FitSample");
1369   composedTest->SetCorrections(testCorr);
1370   composedTest->SetWeights(&weights);
1371   //
1372   corr->AddLast(composedTest);
1373   AliTPCComposedCorrection *cc= new AliTPCComposedCorrection ;
1374   cc->SetCorrections((TObjArray*)(corr));
1375    //cc->Init();
1376   cc->Print("DA"); // Print used correction classes
1377   cc->SetName("ComposedExB");
1378   TFile fexb("RegisterCorrectionExB.root","recreate");
1379   cc->Write("ComposedExB");
1380   fexb.Close();
1381   return cc;
1382 }
1383
1384
1385 AliTPCComposedCorrection * GetCorrectionFromFile(){
1386   //
1387   // Getthe appropariate correction form the closest file
1388   //
1389   TFile * fexb= TFile::Open("RegisterCorrectionExB.root");
1390   if (!fexb)  fexb= TFile::Open("../RegisterCorrectionExB.root");
1391   if (!fexb)  fexb= TFile::Open("../../RegisterCorrectionExB.root");
1392   if (!fexb)  fexb= TFile::Open("../../../RegisterCorrectionExB.root");
1393   //
1394   if (!fexb)   return 0;
1395   TFile * fitter= TFile::Open("fitCorrection.root");
1396
1397   if (!fitter)  fitter= TFile::Open("../fitCorrection.root");
1398   if (!fitter)  fitter= TFile::Open("../../fitCorrection.root");
1399   if (!fitter)  fitter= TFile::Open("../../../fitCorrection.root");
1400   //
1401   AliTPCComposedCorrection *cc=  (AliTPCComposedCorrection*) fexb->Get("ComposedExB");
1402   {if (!cc){
1403     printf("File or correction RegisterCorrectionExB.root doees not exist or corrupted\n\n\n");
1404     return 0;
1405     }}
1406   TObjArray * corr = (TObjArray*)(cc->GetCorrections());
1407   TObjArray * corrLocal =new TObjArray;
1408   TObjArray * corrGlobal =new TObjArray;
1409   //
1410   if (fitter){
1411     if (fitter->GetKey("FitBoundary")) corr->AddLast(fitter->Get("FitBoundary"));
1412     if (fitter->GetKey("FitExBTwist"))  corr->AddLast(fitter->Get("FitExBTwist"));
1413     if (fitter->GetKey("FitAlignGlobal"))  corr->AddLast(fitter->Get("FitAlignGlobal"));
1414     if (fitter->GetKey("FitRodAlignGloba"))  corr->AddLast(fitter->Get("FitRodAlignGlobal"));
1415     if (fitter->GetKey("FitRocAlignGlobal"))  corr->AddLast(fitter->Get("FitRocAlignGlobal"));  
1416     if (fitter->GetKey("FitRocAlignZ"))  corr->AddLast(fitter->Get("FitRocAlignZ"));
1417     if (fitter->GetKey("FitAlignLocal"))  corr->AddLast(fitter->Get("FitAlignLocal"));
1418     if (fitter->GetKey("FitAlignTPC"))  corr->AddLast(fitter->Get("FitAlignTPC"));
1419     if (fitter->GetKey("FitAlignTOF"))  corr->AddLast(fitter->Get("FitAlignTOF"));
1420     if (fitter->GetKey("FitAlignTRD"))  corr->AddLast(fitter->Get("FitAlignTRD"));
1421   }
1422   return cc;
1423 }
1424
1425