2 // Make lookup of distortion TPC distortion +(ITS and TRD)
3 // Input: Residual histograms obtained in the AliTPCcalibTime
5 // Residual histograms:
6 // 1. TPC-ITS - entrance of the TPC
7 // 2. TPC-ITS - at the vertex
8 // 3. TPC-TRD - outer wall of the TPC
12 // 2. Phi - global phi at the entrance (case 1,2) and at the outer wall of TPC (case 3)
13 // 3. snp(phi) - fP2 - local inclination angle at reference X
16 // Mean residuals, rms and number of entries in each bing
23 gROOT->Macro("~/rootlogon.C")
24 gSystem->AddIncludePath("-I$ALICE_ROOT/STAT")
25 gSystem->AddIncludePath("-I$ALICE_ROOT/TPC")
26 gSystem->AddIncludePath("-I$ALICE_ROOT/TPC/macros")
27 gSystem->Load("libANALYSIS");
28 gSystem->Load("libTPCcalib");
29 .L $ALICE_ROOT/TPC/CalibMacros/MakeLookup.C+
31 // .x $ALICE_ROOT/ANALYSIS/CalibMacros/Pass0/ConfigCalibTrain.C(run,"local:///lustre/alice/alien/alice/data/2010/OCDB")
35 //Local check of procedure
36 TTreeSRedirector * pcstream = new TTreeSRedirector("mean.root");
37 TFile f("CalibObjects.root");
38 AliTPCcalibTime *calibTime= f.Get("calibTime");
39 THnSparse * his = calibTime->GetResHistoTPCITS(0);
40 his->GetAxis(1)->SetRangeUser(-1,1);
41 his->GetAxis(2)->SetRange(0,1000000);
42 his->GetAxis(3)->SetRangeUser(-0.3,0.3);
49 #if !defined(__CINT__) || defined(__MAKECINT__)
50 #include "THnSparse.h"
59 #include "TProfile3D.h"
63 #include "TStatToolkit.h"
64 #include "TTreeStream.h"
65 #include "AliExternalTrackParam.h"
66 #include "AliESDfriend.h"
67 #include "AliTPCcalibTime.h"
69 #include "AliXRDPROOFtoolkit.h"
70 #include "AliTPCCorrection.h"
71 #include "AliTPCExBTwist.h"
72 #include "AliTPCGGVoltError.h"
73 #include "AliTPCComposedCorrection.h"
74 #include "AliTPCExBConical.h"
75 #include "TPostScript.h"
77 #include "AliTrackerBase.h"
78 #include "AliTPCCalibGlobalMisalignment.h"
79 #include "AliTPCExBEffective.h"
80 #include "AliTPCExBBShape.h"
84 void MakeLookup(Int_t run, Int_t mode);
85 //void MakeLookupHisto(THnSparse * his, TTreeSRedirector *pcstream, const char* hname, Int_t run);
86 void FitLookup(TChain *chainIn, const char *prefix, TVectorD &vecA, TVectorD &vecC, TVectorD& vecStatA, TVectorD &vecStatD, TCut cut, TObjArray *picArray);
87 void MakeFits(Int_t run);
89 void DrawDistortionDy(TCut cutUser="", Double_t ymin=-0.6, Double_t ymax=0.6);
90 void DrawDistortionMaps(const char *fname="mean.root");
91 TCanvas * DrawDistortionMaps(TTree * treedy, TTree * treedsnp, TTree* treed1Pt, const char * name, const char *title);
92 AliTPCComposedCorrection * MakeComposedCorrection();
94 void AddEffectiveCorrection(AliTPCComposedCorrection* comp);
96 void MakeLookup(Int_t run, Int_t mode){
98 // make a lookup tree with mean values
101 gSystem->AddIncludePath("-I$ALICE_ROOT/STAT");
102 gSystem->Load("libANALYSIS");
103 gSystem->Load("libTPCcalib");
104 if (mode==5) {MakeLaserTree();return;};
105 if (mode==4) {DrawDistortionMaps();return;}
107 DrawDistortionDy("abs(snp)<0.25");
108 DrawDistortionMaps();
111 if (mode==2) return MakeFitTree();
112 TFile f("TPCTimeObjects.root");
113 AliTPCcalibTime *calibTime= (AliTPCcalibTime*)f.Get("calibTime");
115 TFile* f2 = new TFile("CalibObjects.root");
116 calibTime= (AliTPCcalibTime*)f2->Get("calibTime");
118 TFile* f3 = new TFile("../CalibObjects.root");
119 calibTime= (AliTPCcalibTime*)f3->Get("calibTime");
123 TTreeSRedirector * pcstream = new TTreeSRedirector("mean.root");
125 const char * hname[5]={"dy","dz","dsnp","dtheta","d1pt"};
127 for (Int_t ihis=0; ihis<5;ihis++){
128 his = calibTime->GetResHistoTPCITS(ihis);
129 his->GetAxis(1)->SetRangeUser(-1.1,1.1);
130 his->GetAxis(2)->SetRange(0,1000000);
131 his->GetAxis(3)->SetRangeUser(-0.5,0.5);
132 AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("ITS%s",hname[ihis]),run);
134 his = calibTime->GetResHistoTPCvertex(ihis);
135 his->GetAxis(1)->SetRangeUser(-1.1,1.1);
136 his->GetAxis(2)->SetRange(0,1000000);
137 his->GetAxis(3)->SetRangeUser(-0.5,0.5);
138 AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("Vertex%s",hname[ihis]),run);
140 his = calibTime->GetResHistoTPCTRD(ihis);
141 his->GetAxis(1)->SetRangeUser(-1.1,1.1);
142 his->GetAxis(2)->SetRange(0,1000000);
143 his->GetAxis(3)->SetRangeUser(-0.5,0.5);
144 AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("TRD%s",hname[ihis]),run);
145 his = calibTime->GetResHistoTPCTOF(ihis);
147 his->GetAxis(1)->SetRangeUser(-1.1,1.1);
148 his->GetAxis(2)->SetRange(0,1000000);
149 his->GetAxis(3)->SetRangeUser(-0.5,0.5);
150 AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("TOF%s",hname[ihis]),run);
155 gSystem->Exec("echo `pwd`/mean.root > distort.txt");
160 void MakeFits(Int_t run){
162 // Make the fits of distortion
163 // store fit results and QA pictures in the file distortFit.root
165 TCut cut="entries>50&&rms>0";
166 TTreeSRedirector *pcstream = new TTreeSRedirector("distortFit.root");
167 AliXRDPROOFtoolkit tool;
168 TVectorD vecA[100],vecC[100], vecStatA[100],vecStatC[100];
169 TObjArray * picArray= new TObjArray();
171 TChain *chainITSdy = tool.MakeChain("distort.txt","ITSdy",0,100000);
172 TChain *chainITSdsnp = tool.MakeChain("distort.txt","ITSdsnp",0,100000);
173 TChain *chainTRDdy = tool.MakeChain("distort.txt","TRDdy",0,100000);
174 TChain *chainTRDdsnp = tool.MakeChain("distort.txt","TRDdsnp",0,100000);
175 TChain *chainVertexdy = tool.MakeChain("distort.txt","Vertexdy",0,100000);
176 TChain *chainVertexdsnp = tool.MakeChain("distort.txt","Vertexdsnp",0,100000);
178 (*pcstream)<<"fits"<<"run="<<run;
180 FitLookup(chainITSdy, "yits-tpc",vecA[0],vecC[0],vecStatA[0],vecStatC[0],cut, picArray);
181 (*pcstream)<<"fits"<<"itsdyA.="<<&vecA[0]<<"itsdyC.="<<&vecC[0];
182 (*pcstream)<<"fits"<<"itsdyAS.="<<&vecStatA[0]<<"itsdyCS.="<<&vecStatC[0];
183 FitLookup(chainITSdsnp, "snpits-tpc",vecA[1],vecC[1],vecStatA[1],vecStatC[1],cut, picArray);
184 (*pcstream)<<"fits"<<"itsdsnpA.="<<&vecA[1]<<"itsdsnpC.="<<&vecC[1];
185 (*pcstream)<<"fits"<<"itsdsnpAS.="<<&vecStatA[1]<<"itsdsnpCS.="<<&vecStatC[1];
187 FitLookup(chainTRDdy, "ytrd-tpc",vecA[5],vecC[5],vecStatA[5],vecStatC[5],cut, picArray);
188 (*pcstream)<<"fits"<<"trddyA.="<<&vecA[5]<<"trddyC="<<&vecC[5];
189 (*pcstream)<<"fits"<<"trddyAS.="<<&vecStatA[5]<<"trddyCS.="<<&vecStatC[5];
190 FitLookup(chainTRDdsnp, "snptrd-tpc",vecA[6],vecC[6],vecStatA[6],vecStatC[6],cut, picArray);
191 (*pcstream)<<"fits"<<"trddsnpA.="<<&vecA[6]<<"trddsnpC.="<<&vecC[6];
192 (*pcstream)<<"fits"<<"trddsnpAS.="<<&vecStatA[6]<<"trddsnpCS.="<<&vecStatC[6];
194 FitLookup(chainVertexdy, "yvertex-tpc",vecA[10],vecC[10],vecStatA[10],vecStatC[10],cut, picArray);
195 (*pcstream)<<"fits"<<"vertexdyA.="<<&vecA[10]<<"vertexdyC.="<<&vecC[10];
196 (*pcstream)<<"fits"<<"vertexdyAS.="<<&vecStatA[10]<<"vertexdyCS.="<<&vecStatC[10];
197 FitLookup(chainVertexdsnp, "snpvertex-tpc",vecA[11],vecC[11],vecStatA[11],vecStatC[11],cut, picArray);
198 (*pcstream)<<"fits"<<"vertexdsnpA.="<<&vecA[11]<<"vertexdsnpC.="<<&vecC[11];
199 (*pcstream)<<"fits"<<"vertexdsnpAS.="<<&vecStatA[11]<<"vertexdsnpCS.="<<&vecStatC[11];
201 (*pcstream)<<"fits"<<"\n";
203 pcstream->GetFile()->cd();
204 for (Int_t i=0;i<picArray->GetEntries(); i++){
205 TObject * obj = picArray->At(i);
206 if (obj) obj->Write(obj->GetName());
211 chainITSdy->AddFriend(chainITSdy,"ITSdy");
212 chainITSdy->AddFriend(chainITSdsnp,"ITSdsnp");
213 chainITSdy->AddFriend(chainTRDdy,"TRDdy");
214 chainITSdy->AddFriend(chainTRDdsnp,"TRDdsnp");
215 chainITSdy->AddFriend(chainVertexdy,"Vertexdy");
216 chainITSdy->AddFriend(chainVertexdsnp,"Vertexdsnp");
217 TTree * tree = chainITSdy->CloneTree();
218 tree->Write("distortionTree");
229 void FitLookup(TChain *chainIn, const char *prefix, TVectorD &vecA, TVectorD &vecC, TVectorD& vecStatA, TVectorD &vecStatC, TCut cut, TObjArray *picArray){
230 // TCut cut="entries>100&&rms>0";
231 vecStatA.ResizeTo(6);
232 vecStatC.ResizeTo(6);
235 Int_t npointsMax=30000000;
236 TStatToolkit toolkit;
247 TString fstring=""; // magnetic part
248 //fstring+="(1)++"; //0 - offset value
249 fstring+="(cos(phi))++"; //1 - cos part
250 fstring+="(sin(phi))++"; //2 - sin part
252 fstring+="(theta)++"; //3
253 fstring+="(theta*cos(phi))++"; //4
254 fstring+="(theta*sin(phi))++"; //5
256 fstring+="(snp)++"; //6 - delta X(radial) coeficients - offset
257 fstring+="(snp*cos(phi))++"; //7 - delta X(radial) coeficient
258 fstring+="(snp*sin(phi))++"; //8
261 strFitYA = TStatToolkit::FitPlane(chainIn,"mean", fstring.Data(),cut+"theta>0", chi2A,npointsA,paramA,covar,-1,0, npointsMax, kFALSE);
262 strFitYC = TStatToolkit::FitPlane(chainIn,"mean", fstring.Data(),cut+"theta<0", chi2C,npointsC,paramC,covar,-1,0, npointsMax,kFALSE);
263 strFitYA->Tokenize("++")->Print();
264 strFitYC->Tokenize("++")->Print();
265 chainIn->SetAlias("dyA",strFitYA->Data());
266 chainIn->SetAlias("dyC",strFitYC->Data());
269 vecA.ResizeTo(paramA.GetNrows());
270 vecC.ResizeTo(paramC.GetNrows());
274 vecStatA[0]=npointsA;
275 vecStatA[1]=TMath::Sqrt(chi2A/npointsA);
276 chainIn->Draw("mean",cut+"theta>0");
277 his=chainIn->GetHistogram();
278 his->SetName(Form("Orig #Delta%sA",prefix));
279 his->SetTitle(Form("Orig #Delta%sA",prefix));
280 picArray->AddLast(his->Clone());
281 vecStatA[2] = his->GetMean();
282 vecStatA[3] = his->GetRMS();
283 chainIn->Draw("mean-dyA",cut+"theta>0");
284 his=chainIn->GetHistogram();
285 his->SetName(Form("Corr. #Delta%sA",prefix));
286 his->SetTitle(Form("Corr. #Delta%sA",prefix));
287 picArray->AddLast(his->Clone());
288 vecStatA[4] = his->GetMean();
289 vecStatA[5] = his->GetRMS();
292 vecStatC[0]=npointsC;
293 vecStatC[1]=TMath::Sqrt(chi2C/npointsC);
294 chainIn->Draw("mean",cut+"theta<0");
295 his=chainIn->GetHistogram();
296 his->SetName(Form("Orig #Delta%sC",prefix));
297 his->SetTitle(Form("Orig #Delta%sC",prefix));
298 picArray->AddLast(his->Clone());
299 vecStatC[2] = his->GetMean();
300 vecStatC[3] = his->GetRMS();
301 chainIn->Draw("mean-dyC",cut+"theta<0");
302 his=chainIn->GetHistogram();
303 his->SetName(Form("Corr. #Delta%sC",prefix));
304 his->SetTitle(Form("Corr. #Delta%sC",prefix));
305 picArray->AddLast(his->Clone());
306 vecStatC[4] = his->GetMean();
307 vecStatC[5] = his->GetRMS();
315 void DrawDistortionDy(TCut cutUser, Double_t ymin, Double_t ymax){
319 TFile fplus("meanBplus.root");
320 TFile fminus("meanBminus.root");
321 TTree * titsDyPlus= (TTree*)fplus.Get("ITSdy");
322 TTree * titsDyMinus= (TTree*)fminus.Get("ITSdy");
323 TTree * ttrdDyPlus= (TTree*)fplus.Get("TRDdy");
324 TTree * ttrdDyMinus= (TTree*)fminus.Get("TRDdy");
326 TTree * titsDsnpPlus= (TTree*)fplus.Get("ITSdsnp");
327 TTree * titsDsnpMinus= (TTree*)fminus.Get("ITSdsnp");
328 TTree * ttrdDsnpPlus= (TTree*)fplus.Get("TRDdsnp");
329 TTree * ttrdDsnpMinus= (TTree*)fminus.Get("TRDdsnp");
330 TTree * titsDthetaPlus= (TTree*)fplus.Get("ITSdtheta");
331 TTree * titsDthetaMinus= (TTree*)fminus.Get("ITSdtheta");
332 TTree * ttrdDthetaPlus= (TTree*)fplus.Get("TRDdtheta");
333 TTree * ttrdDthetaMinus= (TTree*)fminus.Get("TRDdtheta");
334 TCut cut="rms>0&&entries>100&&abs(theta)<1&&abs(snp)<0.3";
337 titsDyPlus->AddFriend(titsDyMinus,"TM.");
338 titsDyPlus->AddFriend(titsDsnpMinus,"Tsnp.");
339 titsDyPlus->AddFriend(titsDthetaMinus,"Ttheta.");
340 ttrdDyPlus->AddFriend(ttrdDyMinus,"TM.");
341 titsDsnpPlus->AddFriend(titsDsnpMinus,"TM.");
342 ttrdDsnpPlus->AddFriend(ttrdDsnpMinus,"TM.");
348 TGraph * graphITSYC[3];
349 TGraph * graphITSYA[3];
350 TGraph * graphTRDYC[3];
351 TGraph * graphTRDYA[3];
354 entries=titsDyPlus->Draw("mean-TM..mean:phi",cut+"theta<-0.1","goff");
355 graphITSYC[0] = new TGraph(entries, titsDyPlus->GetV2(),titsDyPlus->GetV1());
356 titsDyMinus->Draw("mean:phi",cut+"theta<-0.1","goff");
357 graphITSYC[2] = new TGraph(entries, titsDyMinus->GetV2(),titsDyMinus->GetV1());
358 titsDyPlus->Draw("mean:phi",cut+"theta<-0.1","goff");
359 graphITSYC[1] = new TGraph(entries, titsDyPlus->GetV2(),titsDyPlus->GetV1());
361 entries=titsDyPlus->Draw("mean-TM..mean:phi",cut+"theta>0.1","goff");
362 graphITSYA[0] = new TGraph(entries, titsDyPlus->GetV2(),titsDyPlus->GetV1());
363 titsDyMinus->Draw("mean:phi",cut+"theta>0.1","goff");
364 graphITSYA[2] = new TGraph(entries, titsDyMinus->GetV2(),titsDyMinus->GetV1());
365 titsDyPlus->Draw("mean:phi",cut+"theta>0.1","goff");
366 graphITSYA[1] = new TGraph(entries, titsDyPlus->GetV2(),titsDyPlus->GetV1());
368 entries=ttrdDyPlus->Draw("mean-TM..mean:phi",cut+"theta<-0.1&&TM..entries>100","goff");
369 graphTRDYC[0] = new TGraph(entries, ttrdDyPlus->GetV2(),ttrdDyPlus->GetV1());
370 ttrdDyMinus->Draw("mean:phi",cut+"theta<-0.1","goff");
371 graphTRDYC[2] = new TGraph(entries, ttrdDyMinus->GetV2(),ttrdDyMinus->GetV1());
372 ttrdDyPlus->Draw("mean:phi",cut+"theta<-0.1","goff");
373 graphTRDYC[1] = new TGraph(entries, ttrdDyPlus->GetV2(),ttrdDyPlus->GetV1());
375 entries=ttrdDyPlus->Draw("mean-TM..mean:phi",cut+"theta>0.1&&TM..entries>100","goff");
376 graphTRDYA[0] = new TGraph(entries, ttrdDyPlus->GetV2(),ttrdDyPlus->GetV1());
377 ttrdDyMinus->Draw("mean:phi",cut+"theta>0.1","goff");
378 graphTRDYA[2] = new TGraph(entries, ttrdDyMinus->GetV2(),ttrdDyMinus->GetV1());
379 ttrdDyPlus->Draw("mean:phi",cut+"theta>0.1","goff");
380 graphTRDYA[1] = new TGraph(entries, ttrdDyPlus->GetV2(),ttrdDyPlus->GetV1());
385 {for (Int_t i=0; i<3; i++){
386 graphITSYC[i]->SetMaximum(ymax+0.2); graphITSYC[i]->SetMinimum(ymin);
387 graphITSYC[i]->GetXaxis()->SetTitle("#phi"); graphITSYC[i]->GetYaxis()->SetTitle("#Delta r#phi (cm)");
388 graphITSYC[i]->SetMarkerColor(i+1); graphITSYC[i]->SetMarkerStyle(20+i);
389 graphITSYA[i]->SetMaximum(ymax+0.2); graphITSYA[i]->SetMinimum(ymin);
390 graphITSYA[i]->GetXaxis()->SetTitle("#phi"); graphITSYA[i]->GetYaxis()->SetTitle("#Delta r#phi (cm)");
391 graphITSYA[i]->SetMarkerColor(i+1); graphITSYA[i]->SetMarkerStyle(20+i);
392 graphTRDYC[i]->SetMaximum(ymax+0.2); graphTRDYC[i]->SetMinimum(ymin);
393 graphTRDYC[i]->GetXaxis()->SetTitle("#phi"); graphTRDYC[i]->GetYaxis()->SetTitle("#Delta r#phi (cm)");
394 graphTRDYC[i]->SetMarkerColor(i+1); graphTRDYC[i]->SetMarkerStyle(20+i);
395 graphTRDYA[i]->SetMaximum(ymax+0.2); graphTRDYA[i]->SetMinimum(ymin);
396 graphTRDYA[i]->GetXaxis()->SetTitle("#phi"); graphTRDYA[i]->GetYaxis()->SetTitle("#Delta r#phi (cm)");
397 graphTRDYA[i]->SetMarkerColor(i+1); graphTRDYA[i]->SetMarkerStyle(20+i);
401 TString cname="cdeltaY";
402 TString dirName=gSystem->GetFromPipe("dirname `pwd` | xargs basename ");
403 TString splus=gSystem->GetFromPipe("ls -al meanBplus.root | gawk '{print \"File: \"$8\" \"$6\" \"$7\" \";}'");
404 TString sminus=gSystem->GetFromPipe("ls -al meanBminus.root | gawk '{print \"File: \"$8\" \"$6\" \"$7\" \";}'");
406 TCanvas *cdeltaY = new TCanvas("cdeltaY","cdeltaY",1300,800);
407 cdeltaY->Divide(2,2);
410 graphITSYC[0]->Draw("ap");
411 graphITSYC[1]->Draw("p");
412 graphITSYC[2]->Draw("p");
413 legend = new TLegend(0.6,0.6,1.0,1.0,"ITS-TPC C side #Delta r-#phi");
414 legend->AddEntry("",dirName.Data());
415 legend->AddEntry("",splus.Data());
416 legend->AddEntry("",sminus.Data());
417 legend->AddEntry(graphITSYC[0],"B_{plus}-B_{minus}");
418 legend->AddEntry(graphITSYC[1],"B_{plus}");
419 legend->AddEntry(graphITSYC[2],"B_{minus}");
423 graphITSYA[0]->Draw("ap");
424 graphITSYA[1]->Draw("p");
425 graphITSYA[2]->Draw("p");
426 legend = new TLegend(0.6,0.6,1.0,1.0,"ITS-TPC A side #Delta r-#phi");
427 legend->AddEntry(graphITSYA[0],"B_{plus}-B_{minus}");
428 legend->AddEntry(graphITSYA[1],"B_{plus}");
429 legend->AddEntry(graphITSYA[2],"B_{minus}");
434 graphTRDYC[0]->Draw("ap");
435 graphTRDYC[1]->Draw("p");
436 graphTRDYC[2]->Draw("p");
437 legend = new TLegend(0.6,0.6,1.0,1.0,"TRD-TPC C side #Delta r-#phi");
438 legend->AddEntry(graphTRDYC[0],"B_{plus}-B_{minus}");
439 legend->AddEntry(graphTRDYC[1],"B_{plus}");
440 legend->AddEntry(graphTRDYC[2],"B_{minus}");
444 graphTRDYA[0]->Draw("ap");
445 graphTRDYA[1]->Draw("p");
446 graphTRDYA[2]->Draw("p");
447 legend = new TLegend(0.6,0.6,1.0,1.0,"TRD-TPC A side #Delta r-#phi");
448 legend->AddEntry(graphTRDYA[0],"B_{plus}-B_{minus}");
449 legend->AddEntry(graphTRDYA[1],"B_{plus}");
450 legend->AddEntry(graphTRDYA[2],"B_{minus}");
452 cdeltaY->SaveAs(dirName+"_deltaY.pdf");
463 // 1. Initialize ocdb e.g
464 // .x $ALICE_ROOT/ANALYSIS/CalibMacros/Pass0/ConfigCalibTrain.C(114972,)
465 // .x $ALICE_ROOT/ANALYSIS/CalibMacros/Pass0/ConfigCalibTrain.C(114972,"local:///lustre/alice/alien/alice/data/2010/OCDB")
469 AliTPCComposedCorrection *cc= MakeComposedCorrection();
470 TObjArray * corr = (TObjArray*)(cc->GetCorrections());
471 // corr->AddLast(cc);
472 const Int_t kskip=23;
474 TFile f("mean.root");
476 tree = (TTree*)f.Get("ITSdy");
478 AliTPCCorrection::MakeTrackDistortionTree(tree,0,0,corr,kskip);
479 tree = (TTree*)f.Get("TRDdy");
481 AliTPCCorrection::MakeTrackDistortionTree(tree,1,0,corr,kskip);
482 tree = (TTree*)f.Get("Vertexdy");
483 printf("Vertexdy\n");
484 AliTPCCorrection::MakeTrackDistortionTree(tree,2,0,corr,kskip);
485 tree = (TTree*)f.Get("TOFdy");
487 if (tree) AliTPCCorrection::MakeTrackDistortionTree(tree,3,0,corr,kskip);
490 tree = (TTree*)f.Get("ITSdsnp");
492 AliTPCCorrection::MakeTrackDistortionTree(tree,0,2,corr,kskip);
493 tree = (TTree*)f.Get("TRDdsnp");
495 AliTPCCorrection::MakeTrackDistortionTree(tree,1,2,corr,kskip);
496 tree = (TTree*)f.Get("Vertexdsnp");
497 printf("Vertexdsnp\n");
498 AliTPCCorrection::MakeTrackDistortionTree(tree,2,2,corr,kskip);
501 tree = (TTree*)f.Get("ITSd1pt");
503 if (tree) AliTPCCorrection::MakeTrackDistortionTree(tree,0,4,corr,kskip);
505 tree = (TTree*)f.Get("TOFdz");
507 if (tree) AliTPCCorrection::MakeTrackDistortionTree(tree,3,0,corr,kskip);
510 tree = (TTree*)f.Get("ITSdz");
512 AliTPCCorrection::MakeTrackDistortionTree(tree,0,1,corr,kskip);
513 tree = (TTree*)f.Get("Vertexdz");
514 printf("Vertexdz\n");
515 AliTPCCorrection::MakeTrackDistortionTree(tree,2,1,corr,kskip);
518 tree = (TTree*)f.Get("ITSdtheta");
519 printf("ITSdtheta\n");
520 AliTPCCorrection::MakeTrackDistortionTree(tree,0,3,corr,kskip);
522 tree = (TTree*)f.Get("Vertexdtheta");
523 printf("Vertexdtheta\n");
524 AliTPCCorrection::MakeTrackDistortionTree(tree,2,3,corr,kskip);
531 void MakeGlobalFit(){
532 AliXRDPROOFtoolkit tool;
533 TChain *chain = tool.MakeChain("distortion.txt","fit",0,100000);
535 TCut cutS="rms>0&&entries>100";
536 TCut cut=cutS+"(ptype==0||ptype==2||ptype==3||(ptype==4&&dtype==0))";
537 Int_t npointsMax=30000000;
538 TStatToolkit toolkit;
543 chain->SetAlias("side","(1+(theta>0)*2)");
544 TString fstring=""; // magnetic part
545 fstring+="tX1++"; //1 - twist x in mrad
546 fstring+="tY1++"; //2 - twist y in mrad
547 fstring+="ExBCon++"; //3 - custom
548 fstring+="ExBCon*cos(phi)++"; //3 - custom
549 fstring+="ExBCon*sin(phi)++"; //3 - custom
550 fstring+="ggA++"; //4 - gating grid
551 fstring+="ggA*cos(phi)++"; //4 - gating grid
552 fstring+="ggA*sin(phi)++"; //4 - gating grid
553 fstring+="ggC++"; //5 - gating grid
554 fstring+="ggC*cos(phi)++"; //5 - gating grid
555 fstring+="ggC*sin(phi)++"; //5 - gating grid
556 fstring+="(ptype==2)++";
557 fstring+="(ptype==3)++";
558 fstring+="(ptype==4)++";
559 fstring+="(ptype==4)*bz++";
561 TString *strDelta = TStatToolkit::FitPlane(chain,"mean:rms", fstring.Data(),cut+"(Entry$%13==0)", chi2,npoints,param,covar,-1,0, npointsMax, kTRUE);
562 chain->SetAlias("delta",strDelta->Data());
563 strDelta->Tokenize("++")->Print();
568 void MakeGlobalFitRelative(Int_t highFrequency=0){
570 // Make a global fit of ExB
571 // To get rid of the misalignment errors -
572 // Use relative change of deltas for 2 different filed settings
575 AliXRDPROOFtoolkit tool;
576 // TChain *chain = tool.MakeChain("distortion.txt","fit",0,100000);
577 TChain *chainPlus = tool.MakeChain("distortionPlus.txt","fit",0,100000);
578 TChain *chainMinus = tool.MakeChain("distortionMinus.txt","fit",0,100000);
579 TChain *chain0 = tool.MakeChain("distortionField0.txt","fit",0,100000);
581 chainPlus->AddFriend(chainMinus,"M");
582 chainPlus->AddFriend(chain0,"F0");
584 TCut cut="rms>0&&M.rms>0&&entries>100&&dtype==0&&(ptype==0||ptype==2||ptype==4)";
585 chainPlus->SetAlias("deltaM","mean-M.mean");
586 Int_t npointsMax=30000000;
587 TStatToolkit toolkit;
593 TString fstring=""; // fit string
594 fstring+="(ptype==0)*cos(phi)++"; // - primitive gx movement
595 fstring+="(ptype==0)*sin(phi)++"; // - primitive gy movement
597 fstring+="(tX1-M.tX1)++"; // 1 - twist x in mrad
598 fstring+="(tY1-M.tY1)++"; // 2 - twist y in mrad
600 fstring+="(ExBConA-M.ExBConA)++"; // 3 conical shape A side
601 fstring+="(ExBConC-M.ExBConC)++"; // 4 conical shape C side
603 fstring+="(ggA-M.ggA)++"; // 3 conical shape A side
604 fstring+="(ggC-M.ggC)++"; // 4 conical shape C side
606 if (highFrequency) {for (Int_t i=1; i<highFrequency; i++){
607 fstring+=Form("((ggA-M.ggA)*cos(%d*phi))++",i);
608 fstring+=Form("((ggA-M.ggA)*sin(%d*phi))++",i);
610 fstring+=Form("((ggC-M.ggC)*cos(%d*phi))++",i);
611 fstring+=Form("((ggC-M.ggC)*sin(%d*phi))++",i);
613 fstring+=Form("((ExBConA-M.ExBConA)*cos(%d*phi))++",i);
614 fstring+=Form("((ExBConA-M.ExBConA)*sin(%d*phi))++",i);
615 fstring+=Form("((ExBConC-M.ExBConC)*cos(%d*phi))++",i);
616 fstring+=Form("((ExBConC-M.ExBConC)*sin(%d*phi))++",i);
620 TString *strDelta = TStatToolkit::FitPlane(chainPlus,"deltaM:rms", fstring.Data(),cut+"(Entry$%7==0)", chi2,npoints,param,covar,-1,0, npointsMax, kTRUE);
621 chainPlus->SetAlias("delta",strDelta->Data());
622 TObjArray *fitArray = strDelta->Tokenize("++");
628 TH1::AddDirectory(0);
629 TLatex *lfit=new TLatex;
632 TCanvas * canvasdY= new TCanvas(Form("deltaY%d",highFrequency),Form("deltaY%d",highFrequency),1200,800);
633 TCanvas * canvasdSnp= new TCanvas(Form("deltaSnp%d",highFrequency),Form("deltaSnp%d",highFrequency),1200,800);
634 TCanvas * canvasd1pt= new TCanvas(Form("delta1pt%d",highFrequency),Form("delta1pt%d",highFrequency),1200,800);
636 canvasdY->Divide(3,2);
637 chainPlus->SetMarkerStyle(25);
638 chainPlus->SetMarkerSize(0.5);
639 chainPlus->SetMarkerColor(1);
641 chainPlus->Draw("deltaM:delta",cut+"theta>0&&abs(snp)<0.2&&ptype==0","");
643 chainPlus->SetMarkerColor(1);
644 chainPlus->Draw("deltaM-delta>>deltaCorr(50,-0.4,0.4)",cut+"theta>0&&abs(snp)<0.2&&ptype==0","err");
645 chainPlus->SetMarkerColor(3);
646 chainPlus->Draw("deltaM",cut+"theta>0&&abs(snp)<0.2&&ptype==0","errsame");
648 chainPlus->SetMarkerColor(1);
649 chainPlus->Draw("deltaM:phi",cut+"theta>0&&abs(snp)<0.2&&ptype==0","");
650 chainPlus->SetMarkerColor(2);
651 chainPlus->Draw("deltaM-delta:phi",cut+"theta>0&&abs(snp)<0.2&&ptype==0","same");
653 chainPlus->SetMarkerStyle(26);
654 chainPlus->SetMarkerColor(1);
655 chainPlus->Draw("deltaM:phi",cut+"theta<0&&abs(snp)<0.2&&ptype==0","");
656 chainPlus->SetMarkerColor(4);
657 chainPlus->Draw("deltaM-delta:phi",cut+"theta<0&&abs(snp)<0.2&&ptype==0","same");
661 canvasdSnp->Divide(3,2);
662 chainPlus->SetMarkerStyle(25);
663 chainPlus->SetMarkerSize(0.5);
664 chainPlus->SetMarkerColor(1);
666 chainPlus->Draw("1000*deltaM:1000*delta",cut+"theta>0&&abs(snp)<0.2&&ptype==2","");
668 chainPlus->SetMarkerColor(1);
669 chainPlus->Draw("1000*(deltaM-delta)>>deltaCorr(50,-4.,4)",cut+"theta>0&&abs(snp)<0.2&&ptype==2","err");
670 chainPlus->SetMarkerColor(3);
671 chainPlus->Draw("1000*deltaM",cut+"theta>0&&abs(snp)<0.2&&ptype==2","errsame");
673 chainPlus->SetMarkerColor(1);
674 chainPlus->Draw("1000*(deltaM):phi",cut+"theta>0&&abs(snp)<0.2&&ptype==2","");
675 chainPlus->SetMarkerColor(2);
676 chainPlus->Draw("1000*(deltaM-delta):phi",cut+"theta>0&&abs(snp)<0.2&&ptype==2","same");
678 chainPlus->SetMarkerStyle(26);
679 chainPlus->SetMarkerColor(1);
680 chainPlus->Draw("1000*(deltaM):phi",cut+"theta<0&&abs(snp)<0.2&&ptype==2","");
681 chainPlus->SetMarkerColor(4);
682 chainPlus->Draw("1000*(deltaM-delta):phi",cut+"theta<0&&abs(snp)<0.2&&ptype==2","same");
686 canvasd1pt->Divide(3,2);
687 chainPlus->SetMarkerStyle(25);
688 chainPlus->SetMarkerSize(0.5);
689 chainPlus->SetMarkerColor(1);
691 chainPlus->Draw("deltaM:delta",cut+"theta>0&&abs(snp)<0.2&&ptype==4","");
693 chainPlus->SetMarkerColor(1);
694 chainPlus->Draw("deltaM-delta>>deltaCorr(50,-0.15,0.15)",cut+"theta>0&&abs(snp)<0.2&&ptype==4","err");
695 chainPlus->GetHistogram()->Fit("gaus");
696 chainPlus->SetMarkerColor(3);
697 chainPlus->Draw("deltaM",cut+"theta>0&&abs(snp)<0.2&&ptype==4","errsame");
699 chainPlus->SetMarkerColor(1);
700 chainPlus->Draw("deltaM:phi",cut+"theta>0&&abs(snp)<0.2&&ptype==4","");
701 chainPlus->SetMarkerColor(2);
702 chainPlus->Draw("deltaM-delta:phi",cut+"theta>0&&abs(snp)<0.2&&ptype==4","same");
704 chainPlus->SetMarkerStyle(26);
705 chainPlus->SetMarkerColor(1);
706 chainPlus->Draw("deltaM:phi",cut+"theta<0&&abs(snp)<0.2&&ptype==4","");
707 chainPlus->SetMarkerColor(4);
708 chainPlus->Draw("deltaM-delta:phi",cut+"theta<0&&abs(snp)<0.2&&ptype==4","same");
710 {for (Int_t ipad=0; ipad<3;ipad++){
711 if (ipad==0) canvasdY->cd(5);
712 if (ipad==1) canvasdSnp->cd(5);
713 if (ipad==2) canvasd1pt->cd(5);
714 lfit->SetTextAlign(12); lfit->SetTextSize(0.04);
715 {for (Int_t i=1; i<fitArray->GetEntries(); i++){
716 lfit->DrawLatex(0.1,1-i/9.,fitArray->At(i)->GetName());
718 if (ipad==0) canvasdY->cd(4);
719 if (ipad==1) canvasdSnp->cd(4);
720 if (ipad==2) canvasd1pt->cd(4);
721 lfit->DrawLatex(0.1,0.9,"Global fit - TPC ITS matching in r-#phi");
722 lfit->DrawLatex(0.1,0.8,"Residual minimization:");
723 lfit->DrawLatex(0.1,0.7,"r#phi_{0.5T}-r#phi_{-0.5T} (cm)");
724 lfit->DrawLatex(0.1,0.6,"sin(r#phi)_{0.5T}-sin(r#phi)_{-0.5T} (mrad)");
725 lfit->DrawLatex(0.1,0.5,"1/pt_{0.5T}-1/pt_{-0.5T} (1/GeV)");
729 TFile *fpic = new TFile(Form("fitPictures%d.root",highFrequency),"update");
734 canvasd1pt->SaveAs(Form("fitd1pt%d.pdf",highFrequency));
735 canvasdY->SaveAs(Form("fitdy%d.pdf",highFrequency));
736 canvasdSnp->SaveAs(Form("fitdsnp%d.pdf",highFrequency));
740 void DrawDistortionMaps(const char *fname){
742 TTree *ITSdy=(TTree*)f.Get("ITSdy");
743 TTree *ITSdsnp=(TTree*)f.Get("ITSdsnp");
744 TTree *ITSd1pt=(TTree*)f.Get("ITSd1pt");
745 TTree *TRDdy=(TTree*)f.Get("TRDdy");
746 TTree *TRDdsnp=(TTree*)f.Get("TRDdsnp");
747 TTree *TRDd1pt=(TTree*)f.Get("TRDd1pt");
748 TTree *Vertexdy=(TTree*)f.Get("Vertexdy");
749 TTree *Vertexdsnp=(TTree*)f.Get("Vertexdsnp");
750 TTree *Vertexd1pt=(TTree*)f.Get("Vertexd1pt");
751 TCanvas *cits = DrawDistortionMaps(ITSdy,ITSdsnp,ITSd1pt,"ITS","ITS");
752 cits->SaveAs("matchingITS.pdf");
753 TCanvas *ctrd = DrawDistortionMaps(TRDdy,TRDdsnp,TRDd1pt,"TRD","TRD");
754 ctrd->SaveAs("matchingTRD.pdf");
755 TCanvas *cvertex = DrawDistortionMaps(Vertexdy,Vertexdsnp,Vertexd1pt,"Vertex","Vertex");
756 cvertex->SaveAs("matchingVertex.pdf");
759 TPostScript *ps = new TPostScript("matching.ps", 112);
760 gStyle->SetOptTitle(1);
761 gStyle->SetOptStat(0);
773 TCanvas * DrawDistortionMaps(TTree * treedy, TTree * treedsnp, TTree* treed1pt, const char * name, const char *title){
777 TH1::AddDirectory(0);
778 TCanvas *cdist = new TCanvas(name,name,1200,800);
784 treedy->Draw("10*mean","rms>0&&abs(snp)<0.25&&entries>100","");
785 his = (TH1*)treedy->GetHistogram()->Clone();
786 his->SetName("dY"); his->SetXTitle("#Delta_{r#phi} (cm)");
790 treedsnp->Draw("1000*mean","rms>0&&abs(snp)<0.25&&entries>200","");
791 his = (TH1*)treedsnp->GetHistogram()->Clone();
792 his->SetName("dsnp"); his->SetXTitle("#Delta_{sin(#phi)}");
796 treed1pt->Draw("mean","rms>0&&abs(snp)<0.15&&entries>400","");
797 his = (TH1*)treed1pt->GetHistogram()->Clone();
798 his->SetName("d1pt"); his->SetXTitle("#Delta_{1/pt} (1/GeV)");
801 treedy->SetMarkerSize(1);
802 treedsnp->SetMarkerSize(1);
803 treed1pt->SetMarkerSize(1);
804 {for (Int_t type=0; type<3; type++){
806 TTree * tree =treedy;
807 if (type==1) tree=treedsnp;
808 if (type==2) tree=treed1pt;
810 for (Double_t theta=-1; theta<=1; theta+=0.2){
811 if (TMath::Abs(theta)<0.11) continue;
812 TCut cut=Form("rms>0&&abs(snp)<0.25&&entries>20&&abs(theta-%f)<0.1",theta);
813 tree->SetMarkerStyle(20+counter);
814 Option_t *option=(counter==0)? "": "same";
815 if (theta>0) tree->SetMarkerColor(2);
816 if (theta<0) tree->SetMarkerColor(4);
817 if (type==0) tree->Draw("10*mean:phi>>his(45,-pi,pi)",cut,"profgoff");
818 if (type==1) tree->Draw("1000*mean:phi>>his(45,-pi,pi)",cut,"profgoff");
819 if (type==2) tree->Draw("mean:phi>>his(45,-pi,pi)",cut,"profgoff");
820 his = (TH1*)tree->GetHistogram()->Clone();
821 his->SetName(Form("%d_%d",counter,type));
822 his->SetXTitle("#phi");
826 his->SetMaximum(0.06);
827 his->SetMinimum(-0.06);
834 // cdist->SaveAs(Form("%s.pdf"),name);
842 AliTPCComposedCorrection * MakeComposedCorrection(){
845 Double_t bzField=AliTrackerBase::GetBz();
846 AliMagF* magF= (AliMagF*)(TGeoGlobalMagField::Instance()->GetField());
847 Double_t vdrift = 2.6; // [cm/us] // to be updated: per second (ideally)
848 Double_t ezField = 400; // [V/cm] // to be updated: never (hopefully)
849 Double_t wt = -10.0 * (bzField*10) * vdrift / ezField ;
856 AliTPCExBTwist *twistX1= new AliTPCExBTwist;
857 twistX1->SetXTwist(0.001); // 1 mrad twist in x
858 twistX1->SetName("tX1");
860 AliTPCExBTwist *twistY1= new AliTPCExBTwist;
861 twistY1->SetYTwist(0.001); // 1 mrad twist in Y
862 twistY1->SetName("tY1");
864 AliTPCGGVoltError* ggErrorA = new AliTPCGGVoltError;
865 ggErrorA->SetDeltaVGGA(40.); // delta GG - 1 mm
866 ggErrorA->SetName("ggA");
868 AliTPCGGVoltError* ggErrorC = new AliTPCGGVoltError;
869 ggErrorC->SetDeltaVGGC(40.); // delta GG - 1 mm
870 ggErrorC->SetName("ggC");
871 // conical free param
873 AliTPCCalibGlobalMisalignment *shiftX=new AliTPCCalibGlobalMisalignment;
874 shiftX->SetXShift(0.1);
875 shiftX->SetName("shiftX");
876 AliTPCCalibGlobalMisalignment *shiftY=new AliTPCCalibGlobalMisalignment;
877 shiftY->SetYShift(0.1);
878 shiftY->SetName("shiftY");
880 AliTPCExBBShape *exb11 = new AliTPCExBBShape;
881 exb11->SetBField(magF);
882 exb11->SetName("exb11");
883 AliTPCExBBShape *exbT1 = new AliTPCExBBShape;
884 exbT1->SetBField(magF);
885 exbT1->SetName("exbT1");
886 AliTPCExBBShape *exbT2 = new AliTPCExBBShape;
887 exbT2->SetBField(magF);
888 exbT2->SetName("exbT2");
890 TObjArray * corr = new TObjArray;
891 corr->AddLast(twistX1);
892 corr->AddLast(twistY1);
893 corr->AddLast(ggErrorA);
894 corr->AddLast(ggErrorC);
895 corr->AddLast(shiftX);
896 corr->AddLast(shiftY);
897 corr->AddLast(exb11);
898 corr->AddLast(exbT1);
899 corr->AddLast(exbT2);
901 AliTPCComposedCorrection *cc= new AliTPCComposedCorrection ;
902 cc->SetCorrections((TObjArray*)(corr));
903 AddEffectiveCorrection(cc);
904 cc->SetOmegaTauT1T2(wt,T1,T2);
905 exbT1->SetOmegaTauT1T2(wt,T1+0.1,T2);
906 exbT2->SetOmegaTauT1T2(wt,T1,T2+0.1);
909 cc->Print("DA"); // Print used correction classes
916 void AddEffectiveCorrection(AliTPCComposedCorrection* comp){
925 { for (Int_t iside=0; iside<=1; iside++){
926 {for (Int_t ir=0; ir<3; ir++)
927 for (Int_t id=0; id<3; id++) {
942 TObjArray * array = (TObjArray*) comp->GetCorrections();
943 { for (Int_t iside=0; iside<=1; iside++)
944 for (Int_t ir=0; ir<3; ir++)
945 for (Int_t id=0; id<3; id++) {
946 AliTPCExBEffective *eff=new AliTPCExBEffective;
949 eff->SetName(Form("eff%d_%d_%d",iside,ir,id));
950 if (iside==0) valA(counter,0)=0.1;
951 if (iside==1) valC(counter,0)=0.1;
952 eff->SetPolynoms(&polA,&polC);
953 eff->SetCoeficients(&valA,&valC);
964 void MakeLaserTree(){
968 AliTPCComposedCorrection *cc= MakeComposedCorrection();
969 TObjArray * corr = (TObjArray*)(cc->GetCorrections());
970 // corr->AddLast(cc);
971 TFile f("laserMean.root");
972 TTree* tree =(TTree*)f.Get("Mean");
973 AliTPCCorrection::MakeLaserDistortionTree(tree,corr,0);