]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/CalibMacros/MakeGlobalFit.C
3f3eded5a9789f463783de3531434da49d79d261
[u/mrichter/AliRoot.git] / TPC / CalibMacros / MakeGlobalFit.C
1  /*
2   gROOT->Macro("~/rootlogon.C")
3   gSystem->AddIncludePath("-I$ALICE_ROOT/STAT")
4   gSystem->AddIncludePath("-I$ALICE_ROOT/TPC")
5   gSystem->AddIncludePath("-I$ALICE_ROOT/TPC/macros")
6   gSystem->Load("libANALYSIS");
7   gSystem->Load("libTPCcalib");
8  
9   .L $ALICE_ROOT/TPC/CalibMacros/MakeGlobalFit.C+
10   MakeGlobalFit();
11  
12   rm matching.ps
13   aliroot -b -q $ALICE_ROOT/TPC/CalibMacros/MakeGlobalFit.C | tee globalFit.log
14   
15 */
16
17 #if !defined(__CINT__) || defined(__MAKECINT__)
18 #include "THnSparse.h"
19 #include "TLatex.h"
20 #include "TCanvas.h"
21 #include "TLegend.h"
22 #include "TSystem.h"
23 #include "TFile.h"
24 #include "TChain.h"
25 #include "TCut.h"
26 #include "TH3.h"
27 #include "TH2F.h"
28 #include "TProfile3D.h"
29 #include "TMath.h" 
30 #include "TVectorD.h"
31 #include "TMatrixD.h"
32 #include "TStatToolkit.h"
33 #include "TTreeStream.h"
34 #include "AliExternalTrackParam.h"
35 #include "AliESDfriend.h"
36 #include "AliTPCcalibTime.h"
37 #include "TROOT.h"
38 #include "AliXRDPROOFtoolkit.h"
39 #include "AliTPCCorrection.h"
40 #include "AliTPCExBTwist.h"
41 #include "AliTPCGGVoltError.h"
42 #include "AliTPCComposedCorrection.h"
43 #include "AliTPCExBConical.h"
44 #include "TPostScript.h"
45 #include "TStyle.h"
46 #include "AliTrackerBase.h"
47 #include "AliTPCCalibGlobalMisalignment.h"
48 #include "AliTPCExBEffective.h"
49 #include "TEntryList.h"
50 #endif
51
52 const char* chDetName[5]={"ITS","TRD", "Vertex", "TOF","Laser"};
53 const char* chParName[5]={"rphi","z", "snp", "tan","1/pt"};
54 const char* chSideName[2]={"A side","C side"};
55 Bool_t enableDet[5]={1,1,1,1,1};      // detector  for fit  ITS=0, TRD=1, Vertex=2, Laser=4
56 Bool_t enableParam[5]={1,0,1,0,1};    //
57 Bool_t enableSign=kFALSE;  
58 Bool_t useEff0=kFALSE;
59 Bool_t useEffD=kFALSE;
60 Bool_t useEffR=kFALSE;
61 //
62 TChain *chain    = 0;
63 TChain *chainRef = 0;
64 Bool_t printMatrix=kFALSE;
65 TString *fitString=0;
66 //
67 // cuts
68 //
69 TCut cut="1";
70 TCut cutD="1";
71
72 void MakeChain();
73 void MakeAliases();
74 void MakeCuts();
75 void MakeFit(TCut cutCustom);
76 TCanvas* DrawFitITS(const char *name);
77 TCanvas* DrawFitVertex(const char *name);
78 TCanvas*  DrawFitLaser(const char *cname);
79 TCanvas* DrawCorrdY();
80 TCanvas* DrawCorrdSnp();
81 TCanvas * DrawFitdY(const char *name);
82 TCanvas * DrawFitdSnp(const char *name);
83 void PrintMatch();
84 TCanvas * MakeComposedCorrection(const char * name);
85
86 void MakeAliases(){
87   chain->SetAlias("isITS","(dtype==0||dtype==2)");
88   chain->SetAlias("isTRD","(dtype==1)");
89   chain->SetAlias("isLaser","(dtype==4)");
90   chain->SetAlias("r","sqrt(gx*gx+gy*gy)");
91   chain->SetAlias("r250","(sqrt(gx*gx+gy*gy)/250.)");
92   chain->SetAlias("weight","((dtype==4)*rms*10+rms)");  // downscale laser
93   chain->SetAlias("side","(1+(theta>0)*2)");
94   chain->SetAlias("mdelta","(mean-R.mean-isLaser*((dRrec-R.dRrec)*tan(asin(snp))))");
95   chain->SetAlias("drift","(1-abs(gz/250))");
96   chain->SetAlias("r0","(r-160)/80");
97   chain->SetAlias("delta","(0*gx)");
98 }
99
100
101 void MakeGlobalFit(){
102   //
103   //
104   //
105   gROOT->Macro("~/rootlogon.C");
106   gROOT->Macro("NimStyle.C");
107   gSystem->AddIncludePath("-I$ALICE_ROOT/STAT");
108   gSystem->AddIncludePath("-I$ALICE_ROOT/TPC");
109   gSystem->AddIncludePath("-I$ALICE_ROOT/TPC/macros");
110   gSystem->Load("libANALYSIS");
111   gSystem->Load("libTPCcalib");
112
113   MakeChain();  
114   PrintMatch();
115   TPostScript *ps = new TPostScript("matching.ps", 112); 
116   gStyle->SetOptTitle(1);
117   gStyle->SetOptStat(0);
118
119   useEff0=kFALSE; useEffD=kFALSE; useEffR=kFALSE;
120   MakeFit("1");  
121   ps->NewPage();
122   DrawFitdY("dY-Physical")->Draw();
123   ps->NewPage();
124   DrawFitdSnp("dSnp-Physical")->Draw();
125   ps->NewPage();
126   DrawFitITS("ITS Physical")->Draw();
127   ps->NewPage();
128   DrawFitVertex("Vertex Physical")->Draw();
129   ps->NewPage();
130   DrawFitLaser("Laser Physical")->Draw();
131   ps->NewPage();
132   MakeComposedCorrection("Correction physical")->Draw();
133   //
134   //
135   //
136   //
137   useEff0=kTRUE; useEffD=kTRUE; useEffR=kTRUE; enableSign=kFALSE;
138   ps->NewPage();
139   MakeFit("1");
140   ps->NewPage();
141   DrawFitdY("dY-Physical+Effective ")->Draw();
142   ps->NewPage();
143   DrawFitdSnp("dSnp-Physical+Effective ")->Draw();
144   ps->NewPage();
145   DrawFitITS("ITS Physical+Effective")->Draw();
146   ps->NewPage();
147   DrawFitVertex("Vertex Physical+Effective")->Draw();
148   ps->NewPage();
149   DrawFitLaser("Laser Physical +Effective ")->Draw();
150   ps->NewPage();
151   MakeComposedCorrection("Correction physical+Effective")->Draw();
152   //
153   useEff0=kTRUE; useEffD=kTRUE; useEffR=kTRUE; enableSign=kTRUE;
154   ps->NewPage();
155   MakeFit("1");
156   ps->NewPage();
157   DrawFitdY("dY-Physical+Effective Sign")->Draw();
158   ps->NewPage();
159   DrawFitdSnp("dSnp-Physical+Effective Sign")->Draw();
160   ps->NewPage();
161   DrawFitITS("ITS Physical+Effective Sign")->Draw();
162   ps->NewPage();
163   DrawFitVertex("Vertex Physical+Effective Sign")->Draw();
164   ps->NewPage();
165   DrawFitLaser("Laser Physical +Effective Sign")->Draw();
166   ps->NewPage();
167   MakeComposedCorrection("Correction physical+Effective Sign")->Draw();
168   //
169   ps->Close();
170   delete ps;
171
172 }
173
174 void MakeChain(){
175   //
176   //
177   TH1::AddDirectory(0);
178   TFile * f =0;
179   TTree * tree=0;
180   TTree * treeF=0;
181   //
182   chain    = new TChain("fit","fit");
183   chainRef = new TChain("fit","fit");
184   for (Int_t idet=0; idet<5; idet++){
185     for (Int_t ipar=0; ipar<5; ipar++){
186       char fname[1000];      
187       f= TFile::Open(Form("../mergePlus/distortion%d_%d.root",idet,ipar));
188       if (f){
189         tree = (TTree*)f->Get("fit");
190         f= TFile::Open(Form("../mergeField0/distortion%d_%d.root",idet,ipar));
191         if (f && ipar!=4 &&ipar!=3 &&ipar!=1){
192           treeF = (TTree*)f->Get("fit");
193           if (tree && treeF) 
194             if (tree->GetEntries()>0 &&(tree->GetEntries()==treeF->GetEntries())){
195               printf("%d\t%d\n",Int_t(tree->GetEntries()),Int_t(treeF->GetEntries()));
196               chain->Add(Form("../mergePlus/distortion%d_%d.root",idet,ipar));
197               chainRef->Add(Form("../mergeField0/distortion%d_%d.root",idet,ipar));
198             }
199         }else{
200           f= TFile::Open(Form("../mergeMinus/distortion%d_%d.root",idet,ipar));
201           if (f){
202             treeF = (TTree*)f->Get("fit");
203             if (tree && treeF) 
204               if (tree->GetEntries()>0 &&(tree->GetEntries()==treeF->GetEntries())){
205                 printf("%d\t%d\n",Int_t(tree->GetEntries()),Int_t(treeF->GetEntries()));
206                 chain->Add(Form("../mergePlus/distortion%d_%d.root",idet,ipar));
207                 chainRef->Add(Form("../mergeMinus/distortion%d_%d.root",idet,ipar));
208             }       
209           }
210         }
211       }
212       f= TFile::Open(Form("../mergeMinus/distortion%d_%d.root",idet,ipar));
213       if (f){
214         tree = (TTree*)f->Get("fit");
215         f= TFile::Open(Form("../mergeField0/distortion%d_%d.root",idet,ipar));
216         if (f){
217           treeF = (TTree*)f->Get("fit");
218           if (tree && treeF) 
219             if (tree->GetEntries()>0 &&(tree->GetEntries()==treeF->GetEntries())){
220               printf("%d\t%d\n",Int_t(tree->GetEntries()),Int_t(treeF->GetEntries()));
221               chain->Add(Form("../mergeMinus/distortion%d_%d.root",idet,ipar));
222               chainRef->Add(Form("../mergeField0/distortion%d_%d.root",idet,ipar));
223             }
224         }
225         else{
226           f= TFile::Open(Form("../mergeMinus/distortion%d_%d.root",idet,ipar));
227           if (f && ipar!=4&&ipar!=3 &&ipar!=1){
228             treeF = (TTree*)f->Get("fit");
229             if (tree && treeF) 
230               if (tree->GetEntries()>0 &&(tree->GetEntries()==treeF->GetEntries())){
231                 printf("%d\t%d\n",Int_t(tree->GetEntries()),Int_t(treeF->GetEntries()));
232                 chain->Add(Form("../mergePlus/distortion%d_%d.root",idet,ipar));
233                 chainRef->Add(Form("../mergeMinus/distortion%d_%d.root",idet,ipar));
234               }     
235           }
236         }
237       }
238     }
239   }  
240   chain->AddFriend(chainRef,"R");
241   MakeAliases();
242   MakeCuts();
243 }
244
245
246 void MakeCuts(){
247   //
248   //
249   //
250   TCut cutS="((rms>0&&R.rms>0&&entries>0&&R.entries>0))";         // statistic cuts
251   TCut cutType="((dtype==R.dtype)&&(ptype==R.ptype))";            // corresponding types
252   TCut cutOut="(ptype==0)*abs(mdelta)<(0.3+rms)||(ptype==0&&abs(mdelta*85)<(0.3+rms*85))";            // corresponding types
253   //
254   
255   chain->Draw(">>outList",cutS+cutType+cutOut+"abs(snp)<0.5","entryList");
256   TEntryList *elistOut = (TEntryList*)gDirectory->Get("outList");
257   chain->SetEntryList(elistOut);
258  
259   
260 }
261
262
263 TMatrixD * MakeCorrelation(TMatrixD &matrix){
264   //
265   //
266   //
267   Int_t nrows = matrix.GetNrows();
268   TMatrixD * mat = new TMatrixD(nrows,nrows);
269   for (Int_t irow=0; irow<nrows; irow++)
270     for (Int_t icol=0; icol<nrows; icol++){
271       (*mat)(irow,icol)= matrix(irow,icol)/TMath::Sqrt(matrix(irow,irow)*matrix(icol,icol));
272     }
273   return mat;
274 }
275
276 void MakeDetCut(){  
277   cutD=Form("((dtype==%d)||(dtype==%d)||(dtype==%d)||(dtype==%d)||(dtype==%d))",enableDet[0]?0:0,enableDet[1]?1:0,enableDet[2]?2:0,enableDet[3]?3:0,enableDet[4]?4:0);
278   cutD+=Form("((ptype==%d)||(ptype==%d)||(ptype==%d)||(ptype==%d)||(ptype==%d))",enableParam[0]?0:0,enableParam[1]?1:0,enableParam[2]?2:0,enableParam[3]?3:0,enableParam[4]?4:0);
279 }
280
281 void MakeFit(TCut cutCustom){
282   MakeDetCut();
283   Int_t  npointsMax=30000000;
284   TStatToolkit toolkit;
285   Double_t chi2=0;
286   Int_t    npoints=0;
287   TVectorD param;
288   TMatrixD covar;
289   //
290   TString  fstring="";                       // magnetic part
291   fstring+="(tX1-R.tX1)++";                  // twist X
292   fstring+="(tY1-R.tY1)++";                   // twist Y
293   fstring+="(sign(bz)*(tX1-R.tX1))++";       // twist X
294   fstring+="(sign(bz)*(tY1-R.tY1))++";       // twist Y
295   fstring+="(exbT1-exb11-(R.exbT1-R.exb11))++";                // T1 adjustment
296   fstring+="(exbT2-exb11-(R.exbT2-R.exb11))++";                // T2 adjustment
297
298   {if (enableDet[0]){
299     fstring+="(isITS*shiftX)++";             // shift X - ITS
300     fstring+="(isITS*shiftY)++";             // shift Y - ITS
301     fstring+="(isITS*sign(bz)*shiftX)++";    // shift X - ITS
302     fstring+="(isITS*sign(bz)*shiftY)++";    // shift Y - ITS
303     }}
304   {if (enableDet[1]){
305     fstring+="(isTRD*shiftX)++";             // shift X - TRD
306     fstring+="(isTRD*shiftY)++";             // shift Y - TRD
307     fstring+="(isTRD*sign(bz)*shiftX)++";    // shift X - TRD
308     fstring+="(isTRD*sign(bz)*shiftY)++";    // shift Y - TRD
309     }}
310   //
311   if (enableDet[4]){
312   }
313   TString fstringCustom="";
314   if (useEff0){
315     fstringCustom+="(eff0_0_0-R.eff0_0_0)++";                  // effective correction constant part 
316     fstringCustom+="(eff1_0_0-R.eff1_0_0)++";                  // 
317   }
318   if (useEffD){
319     fstringCustom+="(eff0_0_1-R.eff0_0_1)++";                  // effective correction drift part
320     fstringCustom+="(eff1_0_1-R.eff1_0_1)++";                  // 
321     fstringCustom+="(eff0_0_2-R.eff0_0_2)++";                  // effective correction drift part 
322     fstringCustom+="(eff1_0_2-R.eff1_0_2)++";                  // 
323   }
324   if (useEffR){
325     fstringCustom+="(eff0_1_0-R.eff0_1_0)++";                  // effective correction radial part
326     fstringCustom+="(eff1_1_0-R.eff1_1_0)++";                  // 
327     fstringCustom+="(eff0_1_1-R.eff0_1_1)++";                  // effective correction radial part
328     fstringCustom+="(eff1_1_1-R.eff1_1_1)++";                  // 
329     fstringCustom+="(eff0_1_2-R.eff0_1_2)++";                  // effective correction radial part
330     fstringCustom+="(eff1_1_2-R.eff1_1_2)++";                  // 
331     fstringCustom+="(eff0_2_0-R.eff0_2_0)++";                  // effective correction radial part
332     fstringCustom+="(eff1_2_0-R.eff1_2_0)++";                  // 
333     fstringCustom+="(eff0_2_1-R.eff0_2_1)++";                  // effective correction radial part
334     fstringCustom+="(eff1_2_1-R.eff1_2_1)++";                  // 
335     fstringCustom+="(eff0_2_2-R.eff0_2_2)++";                  // effective correction radial part
336     fstringCustom+="(eff1_2_2-R.eff1_2_2)++";                  // 
337   }
338   if (enableSign){
339     if (useEff0){
340       fstringCustom+="sign(bz)*(eff0_0_0-R.eff0_0_0)++";                  // effective correction constant part 
341       fstringCustom+="sign(bz)*(eff1_0_0-R.eff1_0_0)++";                  // 
342     }
343     if (useEffD){
344       fstringCustom+="sign(bz)*(eff0_0_1-R.eff0_0_1)++";                  // effective correction drift part
345       fstringCustom+="sign(bz)*(eff1_0_1-R.eff1_0_1)++";                  // 
346       fstringCustom+="sign(bz)*(eff0_0_2-R.eff0_0_2)++";                  // effective correction drift part 
347       fstringCustom+="sign(bz)*(eff1_0_2-R.eff1_0_2)++";                  // 
348     } 
349     if (useEffR){
350       fstringCustom+="sign(bz)*(eff0_1_0-R.eff0_1_0)++";                  // effective correction radial part
351       fstringCustom+="sign(bz)*(eff1_1_0-R.eff1_1_0)++";                  // 
352       fstringCustom+="sign(bz)*(eff0_1_1-R.eff0_1_1)++";                  // effective correction radial part
353       fstringCustom+="sign(bz)*(eff1_1_1-R.eff1_1_1)++";                  // 
354       fstringCustom+="sign(bz)*(eff0_1_2-R.eff0_1_2)++";                  // effective correction radial part
355       fstringCustom+="sign(bz)*(eff1_1_2-R.eff1_1_2)++";                  // 
356       fstringCustom+="sign(bz)*(eff0_2_0-R.eff0_2_0)++";                  // effective correction radial part
357       fstringCustom+="sign(bz)*(eff1_2_0-R.eff1_2_0)++";                  // 
358       fstringCustom+="sign(bz)*(eff0_2_1-R.eff0_2_1)++";                  // effective correction radial part
359       fstringCustom+="sign(bz)*(eff1_2_1-R.eff1_2_1)++";                  // 
360       fstringCustom+="sign(bz)*(eff0_2_2-R.eff0_2_2)++";                  // effective correction radial part
361       fstringCustom+="sign(bz)*(eff1_2_2-R.eff1_2_2)++";                  // 
362     }
363   }
364   //
365   fstring+=fstringCustom;
366   //
367   TString *strDelta = TStatToolkit::FitPlane(chain,"mdelta:weight", fstring.Data(),cut+cutD+cutCustom, chi2,npoints,param,covar,-1,0, npointsMax, kTRUE);
368   if (printMatrix) MakeCorrelation(covar)->Print();
369   chain->SetAlias("delta",strDelta->Data());
370   strDelta->Tokenize("++")->Print();
371   fitString = strDelta;
372   PrintMatch();
373 }
374
375
376
377
378
379 void PrintMatch(){
380   //
381   // Print detector matching info
382   //
383   for (Int_t ipar=0; ipar<5; ipar++){      
384     for (Int_t idet=0; idet<5; idet++){
385       Double_t mean0,rms0,mean1,rms1;
386       Int_t entries = chain->Draw("delta-mdelta",cut+Form("dtype==%d&&ptype==%d",idet,ipar),"");
387       if (entries==0) continue;
388       TH1 * his = (TH1*)(chain->GetHistogram()->Clone());
389       mean1=his->GetMean();
390       rms1 =his->GetRMS();
391       delete his;
392       //
393       entries = chain->Draw("mdelta",cut+Form("dtype==%d&&ptype==%d",idet,ipar),"");
394       if (entries==0) continue;
395       his = (TH1*)(chain->GetHistogram()->Clone());
396       //
397       mean0=his->GetMean();
398       rms0 =his->GetRMS();
399       
400       printf("ptype==%s\tdtype==%s\tMean=%f -> %f\tRMS=%f -> %f\n",chParName[ipar],chDetName[idet], mean0,mean1,rms0,rms1);
401       delete his;
402     }
403   }
404 }
405
406
407
408
409 TCanvas* DrawFitITS(const char *name){
410   //
411   //
412   //
413   TLegend *legend=0;
414   TCanvas *canvas = new TCanvas(name,name,800,800);
415   canvas->Divide(1,2);
416   Int_t entries=0;
417   const char * grname[10]={"A side (B=0.5T)","A side (B=-0.5T)", "C side (B=0.5T)", "C side (B=-0.5T)",0};
418
419   TGraph *graphsdyITS[10];
420   TGraph *graphsdyITSc[10];
421   entries=chain->Draw("mdelta:phi",cut+"ptype==0&&dtype==0&&bz>0&&theta>0","goff");
422   graphsdyITS[0]=new TGraph(entries,chain->GetV2(), chain->GetV1());
423   entries=chain->Draw("mdelta:phi",cut+cut+"ptype==0&&dtype==0&&bz<0&&theta>0","goff");
424   graphsdyITS[1]=new TGraph(entries,chain->GetV2(), chain->GetV1());
425   entries=chain->Draw("mdelta:phi",cut+cut+"ptype==0&&dtype==0&&bz>0&&theta<0","goff");
426   graphsdyITS[2]=new TGraph(entries,chain->GetV2(), chain->GetV1());
427   entries=chain->Draw("mdelta:phi",cut+cut+"ptype==0&&dtype==0&&bz<0&&theta<0","goff");
428   graphsdyITS[3]=new TGraph(entries,chain->GetV2(), chain->GetV1());
429   //
430   entries=chain->Draw("mdelta-delta:phi",cut+cut+"ptype==0&&dtype==0&&bz>0&&theta>0","goff");
431   graphsdyITSc[0]=new TGraph(entries,chain->GetV2(), chain->GetV1());
432   entries=chain->Draw("mdelta-delta:phi",cut+cut+"ptype==0&&dtype==0&&bz<0&&theta>0","goff");
433   graphsdyITSc[1]=new TGraph(entries,chain->GetV2(), chain->GetV1());
434   entries=chain->Draw("mdelta-delta:phi",cut+cut+"ptype==0&&dtype==0&&bz>0&&theta<0","goff");
435   graphsdyITSc[2]=new TGraph(entries,chain->GetV2(), chain->GetV1());
436   entries=chain->Draw("mdelta-delta:phi",cut+cut+"ptype==0&&dtype==0&&bz<0&&theta<0","goff");
437   graphsdyITSc[3]=new TGraph(entries,chain->GetV2(), chain->GetV1());
438   
439   canvas->cd(1);
440   legend = new TLegend(0.6,0.6,1.0,1.0,"#Delta R#phi TPC-ITS");
441   for (Int_t i=0; i<4; i++){
442     graphsdyITS[i]->SetMaximum(0.5);
443     graphsdyITS[i]->SetMinimum(-0.5);
444     graphsdyITS[i]->SetMarkerColor(i+1);
445     graphsdyITS[i]->SetMarkerStyle(25+i);
446     //    graphsdyITS[i]->SetName(grname[i]);
447     graphsdyITS[i]->GetXaxis()->SetTitle("#phi");
448     graphsdyITS[i]->GetYaxis()->SetTitle("#Delta R#Phi (cm)");
449     if (i==0) graphsdyITS[i]->Draw("ap");
450     graphsdyITS[i]->Draw("p");
451     legend->AddEntry(graphsdyITS[i],grname[i]);
452   }
453   legend->Draw();
454   canvas->cd(2);
455   legend = new TLegend(0.6,0.6,1.0,1.0,"#Delta R#phi TPC-ITS corrected");
456   for (Int_t i=0; i<4; i++){
457     graphsdyITSc[i]->SetMaximum(0.5);
458     graphsdyITSc[i]->SetMinimum(-0.5);
459     graphsdyITSc[i]->SetMarkerColor(i+1);
460     graphsdyITSc[i]->SetMarkerStyle(25+i);
461     //    graphsdyITS[i]->SetName(grname[i]);
462     graphsdyITSc[i]->GetXaxis()->SetTitle("#phi");
463     graphsdyITSc[i]->GetYaxis()->SetTitle("#Delta R#Phi (cm)");
464     if (i==0) graphsdyITS[i]->Draw("ap");
465     graphsdyITSc[i]->Draw("p");
466     legend->AddEntry(graphsdyITSc[i],grname[i]);
467   }
468   legend->Draw();
469   return canvas;
470 }
471
472
473 TCanvas*  DrawFitLaser(const char *cname){
474   //
475   //
476   //
477   TH1::AddDirectory(0);
478   TCut cutLaser=cut+"isLaser&&bz<0";
479   TCanvas *canvas= new TCanvas(cname, cname,800,800);
480   canvas->Divide(2,2);
481   canvas->Draw();
482   TLegend*legend=0;
483   //
484   TH1 *his[16]={0};
485   {for (Int_t icorr=0; icorr<2; icorr++){
486     for (Int_t iside=0; iside<2; iside++){
487       canvas->cd(iside+1);
488       for (Int_t ib=0; ib<4; ib++){    
489         TCut cutB="1";
490         if (iside==0) cutB=Form("(id==%d&&gz>0)",ib);
491         if (iside==1) cutB=Form("(id==%d&&gz<0)",ib);
492         //cutB.Print();
493         if (icorr==0) chain->Draw("10*mdelta:r",cutLaser+cutB,"prof");
494         if (icorr==1) chain->Draw("10*(mdelta-delta):r",cutLaser+cutB,"prof");
495         his[icorr*8+iside*4+ib] = (TH1*)(chain->GetHistogram()->Clone());
496         his[icorr*8+iside*4+ib]->SetName(Form("B%d%d%d",icorr,iside,ib));
497         his[icorr*8+iside*4+ib]->SetTitle(Form("Bundle %d",ib));
498         his[icorr*8+iside*4+ib]->SetMarkerColor(ib+1);
499         his[icorr*8+iside*4+ib]->SetMarkerStyle(ib+25);
500         his[icorr*8+iside*4+ib]->SetMarkerSize(0.4);
501         his[icorr*8+iside*4+ib]->SetMaximum(3);
502         his[icorr*8+iside*4+ib]->SetMinimum(-3);
503         his[icorr*8+iside*4+ib]->GetXaxis()->SetTitle("r (cm)");
504         his[icorr*8+iside*4+ib]->GetYaxis()->SetTitle("#Delta r#phi (mm)");
505       }
506     }
507     }}
508     //
509   for (Int_t icorr=0; icorr<2; icorr++){
510     for (Int_t iside=0; iside<2; iside++){
511       canvas->cd(icorr*2+iside+1);
512       legend = new TLegend(0.6,0.6,1.0,1.0,Form("#Delta R#phi Laser-%s",chSideName[iside]));
513       for (Int_t ib=0; ib<4; ib++){    
514         if (ib==0) his[icorr*2+iside*4+ib]->Draw();
515         his[icorr*8+iside*4+ib]->Draw("same");
516         legend->AddEntry(his[icorr*8+iside*4+ib]);
517       }
518       legend->Draw();
519     }
520   }
521   return canvas;
522 }
523
524
525
526
527
528
529
530
531
532
533
534 TCanvas* DrawFitVertex(const char *name){
535   //
536   //
537   //
538   TLegend *legend=0;
539   TCanvas *canvas = new TCanvas(name,name,800,800);
540   canvas->Divide(1,2);
541   Int_t entries=0;
542   const char * grname[10]={"A side (B=0.5T)","A side (B=-0.5T)", "C side (B=0.5T)", "C side (B=-0.5T)",0};
543
544   TGraph *graphsdyVertex[10];
545   TGraph *graphsdyVertexc[10];
546   entries=chain->Draw("mdelta:phi",cut+cut+"ptype==0&&dtype==2&&bz>0&&theta>0","goff");
547   graphsdyVertex[0]=new TGraph(entries,chain->GetV2(), chain->GetV1());
548   entries=chain->Draw("mdelta:phi",cut+cut+"ptype==0&&dtype==2&&bz<0&&theta>0","goff");
549   graphsdyVertex[1]=new TGraph(entries,chain->GetV2(), chain->GetV1());
550   entries=chain->Draw("mdelta:phi",cut+cut+"ptype==0&&dtype==2&&bz>0&&theta<0","goff");
551   graphsdyVertex[2]=new TGraph(entries,chain->GetV2(), chain->GetV1());
552   entries=chain->Draw("mdelta:phi",cut+cut+"ptype==0&&dtype==2&&bz<0&&theta<0","goff");
553   graphsdyVertex[3]=new TGraph(entries,chain->GetV2(), chain->GetV1());
554   //
555   entries=chain->Draw("mdelta-delta:phi",cut+cut+"ptype==0&&dtype==2&&bz>0&&theta>0","goff");
556   graphsdyVertexc[0]=new TGraph(entries,chain->GetV2(), chain->GetV1());
557   entries=chain->Draw("mdelta-delta:phi",cut+cut+"ptype==0&&dtype==2&&bz<0&&theta>0","goff");
558   graphsdyVertexc[1]=new TGraph(entries,chain->GetV2(), chain->GetV1());
559   entries=chain->Draw("mdelta-delta:phi",cut+cut+"ptype==0&&dtype==2&&bz>0&&theta<0","goff");
560   graphsdyVertexc[2]=new TGraph(entries,chain->GetV2(), chain->GetV1());
561   entries=chain->Draw("mdelta-delta:phi",cut+cut+"ptype==0&&dtype==2&&bz<0&&theta<0","goff");
562   graphsdyVertexc[3]=new TGraph(entries,chain->GetV2(), chain->GetV1());
563   
564   canvas->cd(1);
565   legend = new TLegend(0.6,0.6,1.0,1.0,"#Delta R#phi TPC-Vertex");
566   for (Int_t i=0; i<4; i++){
567     graphsdyVertex[i]->SetMaximum(1);
568     graphsdyVertex[i]->SetMinimum(-1);
569     graphsdyVertex[i]->SetMarkerColor(i+1);
570     graphsdyVertex[i]->SetMarkerStyle(25+i);
571     //    graphsdyVertex[i]->SetName(grname[i]);
572     graphsdyVertex[i]->GetXaxis()->SetTitle("#phi");
573     graphsdyVertex[i]->GetYaxis()->SetTitle("#Delta R#Phi (cm)");
574     if (i==0) graphsdyVertex[i]->Draw("ap");
575     graphsdyVertex[i]->Draw("p");
576     legend->AddEntry(graphsdyVertex[i],grname[i]);
577   }
578   legend->Draw();
579   canvas->cd(2);
580   legend = new TLegend(0.6,0.6,1.0,1.0,"#Delta R#phi TPC-Vertex corrected");
581   for (Int_t i=0; i<4; i++){
582     graphsdyVertexc[i]->SetMaximum(1);
583     graphsdyVertexc[i]->SetMinimum(-1);
584     graphsdyVertexc[i]->SetMarkerColor(i+1);
585     graphsdyVertexc[i]->SetMarkerStyle(25+i);
586     //    graphsdyVertex[i]->SetName(grname[i]);
587     graphsdyVertexc[i]->GetXaxis()->SetTitle("#phi");
588     graphsdyVertexc[i]->GetYaxis()->SetTitle("#Delta R#Phi (cm)");
589     if (i==0) graphsdyVertex[i]->Draw("ap");
590     graphsdyVertexc[i]->Draw("p");
591     legend->AddEntry(graphsdyVertexc[i],grname[i]);
592   }
593   legend->Draw();
594   return canvas;
595 }
596
597
598
599
600
601
602 TCanvas* DrawCorrdY(){
603   
604   TLegend *legend=0;
605   TCanvas *canvas = new TCanvas("Corrections","Corrections",800,800);
606   canvas->Divide(1,3);
607
608   TGraph *graphsITS[10];
609   TGraph *graphsTRD[10];
610   TGraph *graphsVertex[10];
611   Int_t entries=0;
612   const char * grname[10]={"X twist (1 mrad)","Y twist (1 mrad)", "X shift (1 mm)", "Y shift (1 mm)", "drPhi (1 mm)"};
613   //
614   entries=chain->Draw("tX1:phi",cut+cut+"ptype==0&&dtype==0&&bz>0","goff");
615   graphsITS[0]=new TGraph(entries,chain->GetV2(), chain->GetV1());
616   entries=chain->Draw("tY1:phi",cut+cut+"ptype==0&&dtype==0&&bz>0","goff");
617   graphsITS[1]=new TGraph(entries,chain->GetV2(), chain->GetV1());
618   entries=chain->Draw("shiftX:phi",cut+cut+"ptype==0&&dtype==0&&bz>0","goff");
619   graphsITS[2]=new TGraph(entries,chain->GetV2(), chain->GetV1());
620   entries=chain->Draw("shiftY:phi",cut+cut+"ptype==0&&dtype==0&&bz>0","goff");
621   graphsITS[3]=new TGraph(entries,chain->GetV2(), chain->GetV1());
622   entries=chain->Draw("drPhiA+drPhiC:phi",cut+cut+"ptype==0&&dtype==0&&bz>0","goff");
623   graphsITS[4]=new TGraph(entries,chain->GetV2(), chain->GetV1());
624   //  
625   entries=chain->Draw("tX1:phi",cut+cut+"ptype==0&&dtype==1&&bz>0","goff");
626   graphsTRD[0]=new TGraph(entries,chain->GetV2(), chain->GetV1());
627   entries=chain->Draw("tY1:phi",cut+cut+"ptype==0&&dtype==1&&bz>0","goff");
628   graphsTRD[1]=new TGraph(entries,chain->GetV2(), chain->GetV1());
629   entries=chain->Draw("shiftX:phi",cut+cut+"ptype==0&&dtype==1&&bz>0","goff");
630   graphsTRD[2]=new TGraph(entries,chain->GetV2(), chain->GetV1());
631   entries=chain->Draw("shiftY:phi",cut+cut+"ptype==0&&dtype==1&&bz>0","goff");
632   graphsTRD[3]=new TGraph(entries,chain->GetV2(), chain->GetV1());
633   entries=chain->Draw("drPhiA+drPhiC:phi",cut+cut+"ptype==0&&dtype==1&&bz>0","goff");
634   graphsTRD[4]=new TGraph(entries,chain->GetV2(), chain->GetV1());
635   //
636   entries=chain->Draw("tX1:phi",cut+cut+"ptype==0&&dtype==2&&bz>0","goff");
637   graphsVertex[0]=new TGraph(entries,chain->GetV2(), chain->GetV1());
638   entries=chain->Draw("tY1:phi",cut+cut+"ptype==0&&dtype==2&&bz>0","goff");
639   graphsVertex[1]=new TGraph(entries,chain->GetV2(), chain->GetV1());
640   entries=chain->Draw("shiftX:phi",cut+cut+"ptype==0&&dtype==2&&bz>0","goff");
641   graphsVertex[2]=new TGraph(entries,chain->GetV2(), chain->GetV1());
642   entries=chain->Draw("shiftY:phi",cut+cut+"ptype==0&&dtype==2&&bz>0","goff");
643   graphsVertex[3]=new TGraph(entries,chain->GetV2(), chain->GetV1());
644   entries=chain->Draw("drPhiA+drPhiC:phi",cut+cut+"ptype==0&&dtype==2&&bz>0","goff");
645   graphsVertex[4]=new TGraph(entries,chain->GetV2(), chain->GetV1());
646
647   canvas->cd(1);
648   //
649   legend = new TLegend(0.6,0.6,1.0,1.0,"#Delta R#Phi TPC-Vertex");
650   for (Int_t i=0; i<5; i++){
651     graphsVertex[i]->SetMaximum(0.2);
652     graphsVertex[i]->SetMinimum(-0.2);
653     graphsVertex[i]->SetMarkerColor(i+1);
654     graphsVertex[i]->SetMarkerStyle(25+i);
655     graphsVertex[i]->SetName(grname[i]);
656     graphsVertex[i]->GetXaxis()->SetTitle("#phi");
657     graphsVertex[i]->GetYaxis()->SetTitle("#DeltaR#Phi (cm)");
658     if (i==0) graphsVertex[i]->Draw("ap");
659     graphsVertex[i]->Draw("p");
660     legend->AddEntry(graphsITS[i],grname[i]);
661   }
662   legend->Draw();
663
664   canvas->cd(2);
665   legend = new TLegend(0.6,0.6,1.0,1.0,"#Delta R#Phi ITS-TPC");
666   for (Int_t i=0; i<5; i++){
667     graphsITS[i]->SetMaximum(0.2);
668     graphsITS[i]->SetMinimum(-0.2);
669     graphsITS[i]->SetMarkerColor(i+1);
670     graphsITS[i]->SetMarkerStyle(25+i);
671     graphsITS[i]->SetName(grname[i]);
672     graphsITS[i]->GetXaxis()->SetTitle("#phi");
673     graphsITS[i]->GetYaxis()->SetTitle("#Delta R#Phi (cm)");
674     if (i==0) graphsITS[i]->Draw("ap");
675     graphsITS[i]->Draw("p");
676     legend->AddEntry(graphsITS[i],grname[i]);
677   }  
678   legend->Draw();
679   //
680   canvas->cd(3);
681   legend = new TLegend(0.6,0.6,1.0,1.0,"#Delta R#Phi TPC-TRD");
682   for (Int_t i=0; i<5; i++){
683     graphsTRD[i]->SetMaximum(0.2);
684     graphsTRD[i]->SetMinimum(-0.2);
685     graphsTRD[i]->SetMarkerColor(i+1);
686     graphsTRD[i]->SetMarkerStyle(25+i);
687     graphsTRD[i]->SetName(grname[i]);
688     graphsTRD[i]->GetXaxis()->SetTitle("#phi");
689     graphsTRD[i]->GetYaxis()->SetTitle("#DeltaR#Phi (cm)");
690     if (i==0) graphsTRD[i]->Draw("ap");
691     graphsTRD[i]->Draw("p");
692     legend->AddEntry(graphsITS[i],grname[i]);
693   }
694   legend->Draw();
695   return canvas;
696 }
697
698
699 TCanvas * DrawCorrdSnp(){
700   
701   TLegend *legend=0;
702   TCanvas *canvas = new TCanvas("Corrections dSnp","Corrections dSnp",800,800);
703   canvas->Divide(1,3);
704
705   TGraph *graphsITS[10];
706   TGraph *graphsTRD[10];
707   TGraph *graphsVertex[10];
708   Int_t entries=0;
709   const char * grname[10]={"X twist (1 mrad)","Y twist (1 mrad)", "X shift (1 mm)", "Y shift (1 mm)",0};
710   //
711   entries=chain->Draw("1000*tX1:phi",cut+cut+"ptype==2&&dtype==0&&bz>0","goff");
712   graphsITS[0]=new TGraph(entries,chain->GetV2(), chain->GetV1());
713   entries=chain->Draw("1000*tY1:phi",cut+cut+"ptype==2&&dtype==0&&bz>0","goff");
714   graphsITS[1]=new TGraph(entries,chain->GetV2(), chain->GetV1());
715   entries=chain->Draw("1000*shiftX:phi",cut+cut+"ptype==2&&dtype==0&&bz>0","goff");
716   graphsITS[2]=new TGraph(entries,chain->GetV2(), chain->GetV1());
717   entries=chain->Draw("1000*shiftY:phi",cut+cut+"ptype==2&&dtype==0&&bz>0","goff");
718   graphsITS[3]=new TGraph(entries,chain->GetV2(), chain->GetV1());
719   //  
720   entries=chain->Draw("1000*tX1:phi",cut+cut+"ptype==2&&dtype==1&&bz>0","goff");
721   graphsTRD[0]=new TGraph(entries,chain->GetV2(), chain->GetV1());
722   entries=chain->Draw("1000*tY1:phi",cut+cut+"ptype==2&&dtype==1&&bz>0","goff");
723   graphsTRD[1]=new TGraph(entries,chain->GetV2(), chain->GetV1());
724   entries=chain->Draw("1000*shiftX:phi",cut+cut+"ptype==2&&dtype==1&&bz>0","goff");
725   graphsTRD[2]=new TGraph(entries,chain->GetV2(), chain->GetV1());
726   entries=chain->Draw("1000*shiftY:phi",cut+cut+"ptype==2&&dtype==1&&bz>0","goff");
727   graphsTRD[3]=new TGraph(entries,chain->GetV2(), chain->GetV1());
728   //
729   entries=chain->Draw("1000*tX1:phi",cut+cut+"ptype==2&&dtype==2&&bz>0","goff");
730   graphsVertex[0]=new TGraph(entries,chain->GetV2(), chain->GetV1());
731   entries=chain->Draw("1000*tY1:phi",cut+cut+"ptype==2&&dtype==2&&bz>0","goff");
732   graphsVertex[1]=new TGraph(entries,chain->GetV2(), chain->GetV1());
733   entries=chain->Draw("1000*shiftX:phi",cut+cut+"ptype==2&&dtype==2&&bz>0","goff");
734   graphsVertex[2]=new TGraph(entries,chain->GetV2(), chain->GetV1());
735   entries=chain->Draw("1000*shiftY:phi",cut+cut+"ptype==2&&dtype==2&&bz>0","goff");
736   graphsVertex[3]=new TGraph(entries,chain->GetV2(), chain->GetV1());
737
738   canvas->cd(1);
739   //
740   legend = new TLegend(0.6,0.6,1.0,1.0,"#Delta sin(#phi) TPC-Vertex");
741   for (Int_t i=0; i<4; i++){
742     graphsVertex[i]->SetMaximum(2);
743     graphsVertex[i]->SetMinimum(2);
744     graphsVertex[i]->SetMarkerColor(i+1);
745     graphsVertex[i]->SetMarkerStyle(25+i);
746     graphsVertex[i]->SetName(grname[i]);
747     graphsVertex[i]->GetXaxis()->SetTitle("#phi");
748     graphsVertex[i]->GetYaxis()->SetTitle("#Deltasin(#phi) (mrad)");
749     if (i==0) graphsVertex[i]->Draw("ap");
750     graphsVertex[i]->Draw("p");
751     legend->AddEntry(graphsITS[i],grname[i]);
752   }
753   legend->Draw();
754
755   canvas->cd(2);
756   legend = new TLegend(0.6,0.6,1.0,1.0,"#Delta sin(#phi) ITS-TPC");
757   for (Int_t i=0; i<4; i++){
758     graphsITS[i]->SetMaximum(1);
759     graphsITS[i]->SetMinimum(-1);
760     graphsITS[i]->SetMarkerColor(i+1);
761     graphsITS[i]->SetMarkerStyle(25+i);
762     graphsITS[i]->SetName(grname[i]);
763     graphsITS[i]->GetXaxis()->SetTitle("#phi");
764     graphsITS[i]->GetYaxis()->SetTitle("#Delta sin(#phi) (mrad)");
765     if (i==0) graphsITS[i]->Draw("ap");
766     graphsITS[i]->Draw("p");
767     legend->AddEntry(graphsITS[i],grname[i]);
768   }  
769   legend->Draw();
770   //
771   canvas->cd(3);
772   legend = new TLegend(0.6,0.6,1.0,1.0,"#Delta sin(#phi) TPC-TRD");
773   for (Int_t i=0; i<4; i++){
774     graphsTRD[i]->SetMaximum(1);
775     graphsTRD[i]->SetMinimum(-1);
776     graphsTRD[i]->SetMarkerColor(i+1);
777     graphsTRD[i]->SetMarkerStyle(25+i);
778     graphsTRD[i]->SetName(grname[i]);
779     graphsTRD[i]->GetXaxis()->SetTitle("#phi");
780     graphsTRD[i]->GetYaxis()->SetTitle("#Deltasin(#phi) (mrad)");
781     if (i==0) graphsTRD[i]->Draw("ap");
782     graphsTRD[i]->Draw("p");
783     legend->AddEntry(graphsITS[i],grname[i]);
784   }
785   legend->Draw();
786   return canvas;
787  }
788
789  
790 TCanvas * DrawFitdY(const char *name){
791   //
792   //
793   //
794   TH1::AddDirectory(0);
795   TCanvas *canvas = new TCanvas(name,name,800,800);
796   canvas->Divide(3,5);
797   for (Int_t idet=0; idet<5; idet++){
798     chain->SetMarkerColor(4);
799     chain->SetMarkerStyle(25);
800     chain->SetMarkerSize(0.3);
801     chain->SetLineColor(2);
802     //
803     canvas->cd(idet*3+1);
804     chain->Draw("mdelta:delta",cut+Form("ptype==0&&dtype==%d",idet),"");
805     //
806     canvas->cd(idet*3+2);
807     chain->SetLineColor(2);
808     chain->Draw("mdelta-delta",cut+Form("ptype==0&&dtype==%d",idet),"");
809     chain->SetLineColor(1);
810     chain->Draw("mdelta",cut+Form("ptype==0&&dtype==%d",idet),"same");
811     //
812     canvas->cd(idet*3+3);
813     chain->SetMarkerColor(1);
814     chain->Draw("mdelta:phi",cut+Form("ptype==0&&dtype==%d&&theta>0&&bz>0",idet),"");
815     chain->SetMarkerColor(2);
816     chain->Draw("mdelta-delta:phi",cut+Form("ptype==0&&dtype==%d&&theta>0&&bz>0",idet),"same");
817
818   }
819   return canvas;
820 }
821
822 TCanvas * DrawFitdSnp(const char *name){
823   //
824   //
825   //
826   TH1::AddDirectory(0);
827   TCanvas *canvas = new TCanvas(name,name,800,800);
828   canvas->Divide(3,5);
829   {for (Int_t idet=0; idet<5; idet++){
830     chain->SetMarkerColor(4);
831     chain->SetMarkerStyle(25);
832     chain->SetMarkerSize(0.3);
833     chain->SetLineColor(2);
834     //
835     canvas->cd(idet*3+1);
836     chain->Draw("1000*mdelta:1000*delta",cut+Form("ptype==2&&dtype==%d",idet),"");
837     //
838     canvas->cd(idet*3+2);
839     chain->SetLineColor(2);
840     chain->Draw("1000*(mdelta-delta)",cut+Form("ptype==2&&dtype==%d",idet),"");
841     chain->SetLineColor(1);
842     chain->Draw("1000*mdelta",cut+Form("ptype==2&&dtype==%d",idet),"same");
843     //
844     canvas->cd(idet*3+3);    
845     chain->SetMarkerColor(1);
846     chain->Draw("1000*(mdelta):phi",cut+Form("ptype==2&&dtype==%d&&theta>0&&bz>0",idet),"");
847     chain->SetMarkerColor(2);
848     chain->Draw("1000*(mdelta-delta):phi",cut+Form("ptype==2&&dtype==%d&&theta>0&&bz>0",idet),"same");
849     }}
850   return canvas;
851 }
852
853 TCanvas * MakeComposedCorrection(const char *name){
854   
855   TString  fit = chain->GetAlias("delta");
856   TObjArray * array = fit.Tokenize("++");
857   Int_t nfun=array->GetEntries();
858   Double_t wt = 0.3 ; 
859   Double_t T1 = 0.9;
860   Double_t T2 = 1.5;
861   //
862   // sign independent correction
863   //
864   AliTPCExBEffective            *eff      = new  AliTPCExBEffective;
865   AliTPCCalibGlobalMisalignment *shiftITS = new  AliTPCCalibGlobalMisalignment;
866   AliTPCExBTwist                *twist    = new  AliTPCExBTwist;
867   //
868   // sign dependent correction
869   //
870   AliTPCExBEffective            *effS      = new  AliTPCExBEffective;
871   AliTPCCalibGlobalMisalignment *shiftITSS = new  AliTPCCalibGlobalMisalignment;
872   AliTPCExBTwist                *twistS    = new  AliTPCExBTwist;
873   
874   TMatrixD polA(100,4);
875   TMatrixD polC(100,4);
876   TMatrixD valA(100,1);
877   TMatrixD valC(100,1);
878   Int_t counterA=0;
879   Int_t counterC=0;
880
881   {
882     for (Int_t i=1; i<nfun;i++){
883       TObjString fitName=array->At(i)->GetName();
884       TObjString fitVal= &(fitName.String()[1+fitName.String().Last('(')]);
885       Double_t value= fitVal.String().Atof();
886       if (fitName.String().Contains("sign")) continue;
887       if (fitName.String().Contains("tX1")){
888         twist->SetXTwist(value*0.001);
889       }
890       if (fitName.String().Contains("tY1")){
891         twist->SetYTwist(value*0.001);
892       }
893       
894       if (fitName.String().Contains("shiftX")&&fitName.String().Contains("isITS")){
895         shiftITS->SetXShift(value*0.1);
896       }
897       if (fitName.String().Contains("shiftY")&&fitName.String().Contains("isITS")){
898         shiftITS->SetYShift(value*0.1);
899       }
900       
901       if (fitName.String().Contains("eff")){
902         Int_t index=fitName.String().First("_")-1;
903         Int_t side=atoi(&(fitName.String()[index]));
904         Int_t px  =atoi(&(fitName.String()[index+2]));
905         Int_t pd  =atoi(&(fitName.String()[index+4]));
906         Int_t pp  =0;
907         //printf("%s\t%d\t%d\t%d\t%d\t%f\n",fitName.GetName(),side,px,pd,pp, value);
908         if (side==0){
909           polA(counterA,0)=0;
910           polA(counterA,1)=px;
911           polA(counterA,2)=pd;
912           polA(counterA,3)=pp;
913           valA(counterA,0)=value*0.1;
914           counterA++;
915         }
916         if (side==1){
917           polC(counterC,0)=0;
918           polC(counterC,1)=px;
919           polC(counterC,2)=pd;
920           polC(counterC,3)=pp;
921           valC(counterC,0)=value*0.1;
922           counterC++;
923         }
924       }
925     }
926   }
927   polA.ResizeTo(counterA,4);
928   polC.ResizeTo(counterC,4);
929   valA.ResizeTo(counterA,1);
930   valC.ResizeTo(counterC,1);
931   eff->SetPolynoms(&polA,&polC);
932   eff->SetCoeficients(&valA,&valC);
933   eff->SetOmegaTauT1T2(wt,T1,T2);
934   shiftITS->SetOmegaTauT1T2(wt,T1,T2);
935   twist->SetOmegaTauT1T2(wt,T1,T2);
936   //
937   //
938   //
939   {
940     counterA=0;
941     counterC=0;
942     for (Int_t i=1; i<nfun;i++){
943       TObjString fitName=array->At(i)->GetName();
944       TObjString fitVal= &(fitName.String()[1+fitName.String().Last('(')]);
945       if (!fitName.String().Contains("sign")) continue;
946       Double_t value= fitVal.String().Atof();
947       if (fitName.String().Contains("tX1")){
948         twistS->SetXTwist(value*0.001);
949       }
950       if (fitName.String().Contains("tY1")){
951         twistS->SetYTwist(value*0.001);
952       }
953       
954       if (fitName.String().Contains("shiftX")&&fitName.String().Contains("isITS")){
955         shiftITSS->SetXShift(value*0.1);
956       }
957       if (fitName.String().Contains("shiftY")&&fitName.String().Contains("isITS")){
958         shiftITSS->SetYShift(value*0.1);
959       }
960       
961       if (fitName.String().Contains("eff")){
962         Int_t index=fitName.String().First("_")-1;
963         Int_t side=atoi(&(fitName.String()[index]));
964         Int_t px  =atoi(&(fitName.String()[index+2]));
965         Int_t pd  =atoi(&(fitName.String()[index+4]));
966         Int_t pp  =0;
967         //printf("%s\t%d\t%d\t%d\t%d\t%f\n",fitName.GetName(),side,px,pd,pp, value);
968         if (side==0){
969           polA(counterA,0)=0;
970           polA(counterA,1)=px;
971           polA(counterA,2)=pd;
972           polA(counterA,3)=pp;
973           valA(counterA,0)=value*0.1;
974           counterA++;
975         }
976         if (side==1){
977           polC(counterC,0)=0;
978           polC(counterC,1)=px;
979           polC(counterC,2)=pd;
980           polC(counterC,3)=pp;
981           valC(counterC,0)=value*0.1;
982           counterC++;
983         }
984       }
985     }
986   }
987   polA.ResizeTo(counterA,4);
988   polC.ResizeTo(counterC,4);
989   valA.ResizeTo(counterA,1);
990   valC.ResizeTo(counterC,1);
991   effS->SetPolynoms(&polA,&polC);
992   effS->SetCoeficients(&valA,&valC);
993   effS->SetOmegaTauT1T2(wt,T1,T2);
994   shiftITSS->SetOmegaTauT1T2(wt,T1,T2);
995   twistS->SetOmegaTauT1T2(wt,T1,T2);
996
997
998
999   //
1000   TCanvas *c = new TCanvas(name,name,800,800);
1001   c->Divide(3,2);
1002   c->cd(1);
1003   shiftITS->CreateHistoDRPhiinXY()->Draw("surf2");
1004   c->cd(2);
1005   twist->CreateHistoDRPhiinXY()->Draw("surf2");
1006   c->cd(3);
1007   eff->CreateHistoDRPhiinZR()->Draw("surf2");
1008   c->cd(4);
1009   shiftITSS->CreateHistoDRPhiinXY()->Draw("surf2");
1010   c->cd(5);
1011   twistS->CreateHistoDRPhiinXY()->Draw("surf2");
1012   c->cd(6);
1013   effS->CreateHistoDRPhiinZR()->Draw("surf2");
1014   TObjArray * corr = new TObjArray;
1015
1016   return c;
1017 }