13 #include <TProfile2D.h>
14 #include <TGraphErrors.h>
15 #include <TTreeStream.h>
17 #include <AliExternalTrackParam.h>
18 #include <AliTPCComposedCorrection.h>
19 #include <AliTPCCorrectionLookupTable.h>
21 #include <AliToyMCEventGenerator.h>
25 .L $ALICE_ROOT/TPC/Upgrade/macros/AnaDelta.C+g
29 TVectorD* MakeLogBinning(Int_t nbinsX, Double_t xmin, Double_t xmax);
30 TVectorD* MakeLinBinning(Int_t nbinsX, Double_t xmin, Double_t xmax);
31 TVectorD* MakeArbitraryBinning(const char* bins);
33 void DumpHn(THn *hn, TTreeSRedirector &stream);
35 void AnaDelta(TString file, TString outDir=".")
43 TTreeSRedirector stream(Form("%s/deltas.root",outDir.Data()));
47 THn *hn=(THn*)f.Get("hn");
55 void AnaDeltaTree(TString file, TString outFile="deltas_tree.root")
59 TTree *t = (TTree*)f.Get("delta");
60 Float_t soneOverPt=0.;
72 t->SetBranchAddress("soneOverPt" , &soneOverPt);
73 t->SetBranchAddress("r" , &radius);
74 t->SetBranchAddress("trackPhi" , &trackPhi);
75 t->SetBranchAddress("trackY" , &trackY);
76 t->SetBranchAddress("trackZ" , &trackZ);
77 t->SetBranchAddress("resRphi" , &resRphi);
78 t->SetBranchAddress("trackRes" , &trackRes);
79 t->SetBranchAddress("pointY" , &pointY);
80 t->SetBranchAddress("pointZ" , &pointZ);
81 t->SetBranchAddress("npTRD" , &npTRD);
82 t->SetBranchAddress("event" , &event);
85 TVectorD *vR = MakeLinBinning(10,86.,250.);
86 TVectorD *vPhi = MakeLinBinning(18*8,0.,2*TMath::Pi());
87 TVectorD *vZ = MakeLinBinning(50,-250.,250.);
90 Int_t bins[nbins] = {vR->GetNrows()-1, vPhi->GetNrows()-1, vZ->GetNrows()-1, 80};
91 // Int_t bins[nbins] = {16, 18*5, 50, 80};
92 Double_t xmin[nbins] = {86. , 0., -250., -2.};
93 Double_t xmax[nbins] = {250., 2*TMath::Pi(), 250., 2.};
94 THnF *hn = new THnF("hn", "hn", nbins, bins, xmin, xmax);
96 hn->GetAxis(0)->Set(vR ->GetNrows()-1, vR ->GetMatrixArray());
97 hn->GetAxis(1)->Set(vPhi->GetNrows()-1, vPhi->GetMatrixArray());
98 hn->GetAxis(2)->Set(vZ ->GetNrows()-1, vZ ->GetMatrixArray());
101 for (Int_t iev=0; iev<t->GetEntries(); ++iev) {
106 if (npTRD<2) continue;
107 Double_t pt=1./TMath::Abs(soneOverPt);
108 if (pt<0.8) continue;
110 Float_t resRphiRandom = resRphi*trackRes;
111 Float_t deviation = trackY+resRphiRandom-pointY;
113 Double_t xx[4]={radius, trackPhi, trackZ ,deviation};
117 // do fits and fill tree
118 TTreeSRedirector stream(outFile.Data());
123 stream.GetFile()->cd();
133 void AnaDeltaTree2(TString file/*, TString outDir="."*/)
136 // NOTE: not finished
140 TTree *t = (TTree*)f.Get("delta");
141 Float_t soneOverPt=0.;
153 t->SetBranchAddress("soneOverPt" , &soneOverPt);
154 t->SetBranchAddress("r" , &radius);
155 t->SetBranchAddress("trackPhi" , &trackPhi);
156 t->SetBranchAddress("trackY" , &trackY);
157 t->SetBranchAddress("trackZ" , &trackZ);
158 t->SetBranchAddress("resRphi" , &resRphi);
159 t->SetBranchAddress("trackRes" , &trackRes);
160 t->SetBranchAddress("pointY" , &pointY);
161 t->SetBranchAddress("pointZ" , &pointZ);
162 t->SetBranchAddress("npTRD" , &npTRD);
163 t->SetBranchAddress("event" , &event);
166 TVectorD *vZ = MakeLinBinning(50,-250.,250.);
167 TVectorD *vPhi = MakeLinBinning(18*8,0.,TMath::Pi());
168 TVectorD *vR = MakeLinBinning(16,86.,250.);
170 TObjArray arrZ(vZ->GetNrows()-1);
173 for (Int_t iev=0; iev<t->GetEntries(); ++iev) {
178 if (npTRD<2) continue;
180 Float_t resRphiRandom=resRphi*trackRes;
182 Int_t binZ = TMath::BinarySearch(vZ->GetNrows(),vZ->GetMatrixArray(),(Double_t)trackZ);
183 Int_t binPhi = TMath::BinarySearch(vPhi->GetNrows(),vPhi->GetMatrixArray(),(Double_t)trackPhi);
184 Int_t binR = TMath::BinarySearch(vR->GetNrows(),vR->GetMatrixArray(),(Double_t)radius);
187 if (binPhi<0) binPhi=0;
190 TObjArray *arrPhi=(TObjArray*)arrZ.UncheckedAt(binZ);
192 arrPhi=new TObjArray(vPhi->GetNrows()-1);
193 arrZ.AddAt(arrPhi,binZ);
196 TObjArray *arrR=(TObjArray*)arrPhi->UncheckedAt(binPhi);
198 arrR=new TObjArray(vR->GetNrows()-1);
199 arrPhi->AddAt(arrR,binPhi);
202 TH1S *h = (TH1S*)arrR->UncheckedAt(binR);
204 h = new TH1S(Form("h_%02d_%02d_%d02",binZ, binPhi, binR),
205 Form("z,phi,r: %02d,%02d,%d02; #Delta r#phi (cm)",binZ, binPhi, binR),
207 arrR->AddAt(h, binR);
210 h->Fill(trackY+resRphiRandom-pointY);
213 // do fits and fill tree
216 void AnaDeltaResiduals(TString fluctuationMap, TString averageMap, TString outFile="deltas_residuals.root")
222 TFile fFluct(fluctuationMap);
223 AliTPCCorrectionLookupTable *corrFluct = (AliTPCCorrectionLookupTable*)fFluct.Get("map");
226 TFile fAverage(averageMap);
227 AliTPCCorrectionLookupTable *corrAverage = (AliTPCCorrectionLookupTable*)fAverage.Get("map");
230 TObjArray *arrMaps = new TObjArray(2);
231 arrMaps->Add(corrAverage); // correction with the average Map
232 arrMaps->Add(corrFluct); // distortion with the fluctuation Map
234 // create the composed correction
235 // if the weight are set to +1 and -1, the first map will be responsible for the distortions
236 // The second map for the corrections
237 // !!!!! In AliTPCComposedCorrection::GetDistortion MakeInverseIterator is called !!!!
238 // for this reason we have to add the maps in the wrong order
240 AliTPCComposedCorrection *residualDistortion = new AliTPCComposedCorrection(arrMaps, AliTPCComposedCorrection::kQueueResidual);
244 weights(0)=-AliToyMCEventGenerator::GetSCScalingFactor(corrFluct, corrAverage,dummy);
245 residualDistortion->SetWeights(&weights);
247 TVectorD *vR = MakeLinBinning(10,86.,250.);
248 TVectorD *vPhi = MakeLinBinning(18*8,0.,2*TMath::Pi());
249 TVectorD *vZ = MakeLinBinning(50,-250.,250.);
252 Int_t bins[nbins] = {vR->GetNrows()-1, vPhi->GetNrows()-1, vZ->GetNrows()-1, 80};
253 // Int_t bins[nbins] = {16, 18*5, 50, 80};
254 Double_t xmin[nbins] = {86. , 0., -250., -2.};
255 Double_t xmax[nbins] = {250., 2*TMath::Pi(), 250., 2.};
256 THnF *hn = new THnF("hn", "hn", nbins, bins, xmin, xmax);
258 hn->GetAxis(0)->Set(vR ->GetNrows()-1, vR ->GetMatrixArray());
259 hn->GetAxis(1)->Set(vPhi->GetNrows()-1, vPhi->GetMatrixArray());
260 hn->GetAxis(2)->Set(vZ ->GetNrows()-1, vZ ->GetMatrixArray());
262 AliExternalTrackParam vv;
264 for (Float_t iz=-245; iz<=245; iz+=1) {
265 Short_t roc=(iz>=0)?0:18;
266 for (Float_t ir=86; ir<250; ir+=1) {
267 for (Float_t iphi=0; iphi<TMath::TwoPi(); iphi+=1*TMath::DegToRad()){
268 Float_t x=ir*(Float_t)TMath::Cos(iphi);
269 Float_t y=ir*(Float_t)TMath::Sin(iphi);
270 Float_t x3[3] = {x,y,iz};
271 Float_t dx3[3] = {0.,0.,0.};
272 residualDistortion->GetDistortion(x3,roc,dx3);
274 Double_t ddx3[3]={dx3[0], dx3[1], dx3[2]};
275 vv.Global2LocalPosition(ddx3,iphi);
277 Double_t xx[4]={ir, iphi, iz ,ddx3[1]};
284 TTreeSRedirector stream(outFile.Data());
289 stream.GetFile()->cd();
297 delete residualDistortion;
300 void DumpHn(THn *hn, TTreeSRedirector &stream)
302 TAxis *ar = hn->GetAxis(0);
303 TAxis *aphi = hn->GetAxis(1);
304 TAxis *az = hn->GetAxis(2);
307 for (Int_t iz=0; iz<az->GetNbins(); ++iz) {
308 az->SetRange(iz+1,iz+1);
310 arrFits.SetName(Form("z_%02d",iz));
313 for (Int_t ir=0; ir<ar->GetNbins(); ++ir) {
314 ar->SetRange(ir+1,ir+1);
315 for (Int_t iphi=0; iphi<aphi->GetNbins(); ++iphi) {
316 aphi->SetRange(iphi+1,iphi+1);
318 TH1 *hProj = hn->Projection(3);
319 if (hProj->GetEntries()<1) {
324 TF1 fg("fg","gaus",-2,2);
325 Double_t cr = ar->GetBinCenter(ir+1);
326 Double_t cphi = aphi->GetBinCenter(iphi+1);
327 Double_t cz = az->GetBinCenter(iz+1);
328 hProj->SetNameTitle(Form("h_%02d_%02d_%02d",iz+1, iphi+1, ir+1),
329 Form("z,phi,r: %02d,%02d,%02d (%.2f, %.2f, %.2f)",iz+1,iphi+1,ir+1, cz, cphi, cr )
331 hProj->Fit(&fg,"QR");
334 Double_t mean = fg.GetParameter(1);
335 Double_t meanErr = fg.GetParError(1);
336 Double_t sigma = fg.GetParameter(2);
337 Double_t sigmaErr = fg.GetParError(2);
338 Int_t entries = hProj->GetEntries();
339 Double_t chi2ndf = fg.GetChisquare()/fg.GetNDF();
349 "meanErr=" << meanErr <<
351 "sigmaErr=" << sigmaErr <<
352 "entries=" << entries <<
353 "chi2ndf=" << chi2ndf <<
357 stream.GetFile()->cd();
358 arrFits.Write(0x0,TObject::kSingleKey);
364 //______________________________________________________________________________
365 TVectorD* MakeLogBinning(Int_t nbinsX, Double_t xmin, Double_t xmax)
368 // Make logarithmic binning
369 // the user has to delete the array afterwards!!!
373 if (xmin<1e-20 || xmax<1e-20){
374 printf("For Log binning xmin and xmax must be > 1e-20. Using linear binning instead!");
375 return MakeLinBinning(nbinsX, xmin, xmax);
382 TVectorD *binLim=new TVectorD(nbinsX+1);
385 Double_t expMax=TMath::Log(last/first);
386 for (Int_t i=0; i<nbinsX+1; ++i){
387 (*binLim)[i]=first*TMath::Exp(expMax/nbinsX*(Double_t)i);
392 //______________________________________________________________________________
393 TVectorD* MakeLinBinning(Int_t nbinsX, Double_t xmin, Double_t xmax)
396 // Make linear binning
397 // the user has to delete the array afterwards!!!
404 TVectorD *binLim=new TVectorD(nbinsX+1);
407 Double_t binWidth=(last-first)/nbinsX;
408 for (Int_t i=0; i<nbinsX+1; ++i){
409 (*binLim)[i]=first+binWidth*(Double_t)i;
414 //_____________________________________________________________________________
415 TVectorD* MakeArbitraryBinning(const char* bins)
418 // Make arbitrary binning, bins separated by a ','
420 TString limits(bins);
421 if (limits.IsNull()){
422 printf("Bin Limit string is empty, cannot add the variable");
426 TObjArray *arr=limits.Tokenize(",");
427 Int_t nLimits=arr->GetEntries();
429 printf("Need at leas 2 bin limits, cannot add the variable");
434 TVectorD *binLimits=new TVectorD(nLimits);
435 for (Int_t iLim=0; iLim<nLimits; ++iLim){
436 (*binLimits)[iLim]=(static_cast<TObjString*>(arr->At(iLim)))->GetString().Atof();
443 void PlotFromTree(TTree *d, TString outDir=".")
445 TCanvas *c=new TCanvas;
446 gStyle->SetOptStat(0);
447 d->SetMarkerStyle(20);
450 TProfile2D pRZ("pRZ",";z (cm); r(cm)",50,-250,250,10,85,250);
451 d->Draw("entries:cr:cz>>pRZ","","profcolz");
452 pRZ.GetZaxis()->UnZoom();
453 c->SaveAs(Form("%s/entries_average.png",outDir.Data()));
454 d->Draw("entries:cr:cz>>pRZ","iphi==2","profcolz");
455 c->SaveAs(Form("%s/entries_onePhi.png",outDir.Data()));
457 pRZ.SetMaximum(0.04);
458 d->Draw("meanErr:cr:cz>>pRZ","","profcolz");
459 c->SaveAs(Form("%s/meanErr_average.png",outDir.Data()));
460 d->Draw("meanErr:cr:cz>>pRZ","iphi==2","profcolz");
461 c->SaveAs(Form("%s/meanErr_onePhi.png",outDir.Data()));
464 d->Draw("mean:cphi:cr","iz==25","colz");
465 c->SaveAs(Form("%s/mean_oneZ_phi_allR.png",outDir.Data()));
466 d->Draw("mean:meanErr:cphi","iz==25&&ir==2","goff");
467 TGraphErrors *grmean_phi=new TGraphErrors(d->GetSelectedRows(),d->GetV3(),d->GetV1(),0,d->GetV2());
468 grmean_phi->SetTitle(";#varphi;#LT#Delta r#varphi#GT");
469 grmean_phi->SetMarkerStyle(20);
470 grmean_phi->SetMarkerSize(1);
471 grmean_phi->Draw("ap");
472 c->SaveAs(Form("%s/mean_oneZ_phi_oneR.png",outDir.Data()));
474 d->Draw("mean:cr:cphi","iz==25","colz");
475 c->SaveAs(Form("%s/mean_oneZ_r_allPhi.png",outDir.Data()));
477 d->Draw("mean:meanErr:cr","iz==25&&iphi==2","goff");
478 TGraphErrors *grmean_r=new TGraphErrors(d->GetSelectedRows(),d->GetV3(),d->GetV1(),0,d->GetV2());
479 grmean_r->SetTitle(";r (cm);#LT#Delta r#varphi#GT");
480 grmean_r->SetMarkerStyle(20);
481 grmean_r->SetMarkerSize(1);
482 grmean_r->Draw("ap");
483 c->SaveAs(Form("%s/mean_oneZ_r_onePhi.png",outDir.Data()));
486 d->Draw("meanErr:cphi:cr","iz==25","colz");
487 c->SaveAs(Form("%s/meanErr_oneZ_phi_allR.png",outDir.Data()));
488 d->Draw("meanErr:cphi","iz==25&&ir==2");
489 c->SaveAs(Form("%s/meanErr_oneZ_phi_oneR.png",outDir.Data()));
491 d->Draw("meanErr:cr:cphi","iz==25","colz");
492 c->SaveAs(Form("%s/meanErr_oneZ_r_allPhi.png",outDir.Data()));
494 d->Draw("meanErr:cr","iz==25&&iphi==2");
495 c->SaveAs(Form("%s/meanErr_oneZ_r_onePhi.png",outDir.Data()));