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());
100 hn->GetAxis(0)->SetNameTitle("r","r (cm)");
101 hn->GetAxis(1)->SetNameTitle("phi","#varphi");
102 hn->GetAxis(2)->SetNameTitle("z","z (cm)");
103 hn->GetAxis(3)->SetNameTitle("drphi","#Delta(r#varphi)");
105 for (Int_t iev=0; iev<t->GetEntries(); ++iev) {
110 if (npTRD<2) continue;
111 Double_t pt=1./TMath::Abs(soneOverPt);
112 if (pt<0.8) continue;
114 Float_t resRphiRandom = resRphi*trackRes;
115 Float_t deviation = trackY+resRphiRandom-pointY;
117 Double_t xx[4]={radius, trackPhi, trackZ ,deviation};
121 // do fits and fill tree
122 TTreeSRedirector stream(outFile.Data());
127 stream.GetFile()->cd();
137 void AnaDeltaTree2(TString file/*, TString outDir="."*/)
140 // NOTE: not finished
144 TTree *t = (TTree*)f.Get("delta");
145 Float_t soneOverPt=0.;
157 t->SetBranchAddress("soneOverPt" , &soneOverPt);
158 t->SetBranchAddress("r" , &radius);
159 t->SetBranchAddress("trackPhi" , &trackPhi);
160 t->SetBranchAddress("trackY" , &trackY);
161 t->SetBranchAddress("trackZ" , &trackZ);
162 t->SetBranchAddress("resRphi" , &resRphi);
163 t->SetBranchAddress("trackRes" , &trackRes);
164 t->SetBranchAddress("pointY" , &pointY);
165 t->SetBranchAddress("pointZ" , &pointZ);
166 t->SetBranchAddress("npTRD" , &npTRD);
167 t->SetBranchAddress("event" , &event);
170 TVectorD *vZ = MakeLinBinning(50,-250.,250.);
171 TVectorD *vPhi = MakeLinBinning(18*8,0.,TMath::Pi());
172 TVectorD *vR = MakeLinBinning(16,86.,250.);
174 TObjArray arrZ(vZ->GetNrows()-1);
177 for (Int_t iev=0; iev<t->GetEntries(); ++iev) {
182 if (npTRD<2) continue;
184 Float_t resRphiRandom=resRphi*trackRes;
186 Int_t binZ = TMath::BinarySearch(vZ->GetNrows(),vZ->GetMatrixArray(),(Double_t)trackZ);
187 Int_t binPhi = TMath::BinarySearch(vPhi->GetNrows(),vPhi->GetMatrixArray(),(Double_t)trackPhi);
188 Int_t binR = TMath::BinarySearch(vR->GetNrows(),vR->GetMatrixArray(),(Double_t)radius);
191 if (binPhi<0) binPhi=0;
194 TObjArray *arrPhi=(TObjArray*)arrZ.UncheckedAt(binZ);
196 arrPhi=new TObjArray(vPhi->GetNrows()-1);
197 arrZ.AddAt(arrPhi,binZ);
200 TObjArray *arrR=(TObjArray*)arrPhi->UncheckedAt(binPhi);
202 arrR=new TObjArray(vR->GetNrows()-1);
203 arrPhi->AddAt(arrR,binPhi);
206 TH1S *h = (TH1S*)arrR->UncheckedAt(binR);
208 h = new TH1S(Form("h_%02d_%02d_%d02",binZ, binPhi, binR),
209 Form("z,phi,r: %02d,%02d,%d02; #Delta r#phi (cm)",binZ, binPhi, binR),
211 arrR->AddAt(h, binR);
214 h->Fill(trackY+resRphiRandom-pointY);
217 // do fits and fill tree
220 void AnaDeltaResiduals(TString fluctuationMap, TString averageMap, TString outFile="deltas_residuals.root")
226 TFile fFluct(fluctuationMap);
227 AliTPCCorrectionLookupTable *corrFluct = (AliTPCCorrectionLookupTable*)fFluct.Get("map");
230 TFile fAverage(averageMap);
231 AliTPCCorrectionLookupTable *corrAverage = (AliTPCCorrectionLookupTable*)fAverage.Get("map");
234 TObjArray *arrMaps = new TObjArray(2);
235 arrMaps->Add(corrAverage); // correction with the average Map
236 arrMaps->Add(corrFluct); // distortion with the fluctuation Map
238 // create the composed correction
239 // if the weight are set to +1 and -1, the first map will be responsible for the distortions
240 // The second map for the corrections
241 // !!!!! In AliTPCComposedCorrection::GetDistortion MakeInverseIterator is called !!!!
242 // for this reason we have to add the maps in the wrong order
244 AliTPCComposedCorrection *residualDistortion = new AliTPCComposedCorrection(arrMaps, AliTPCComposedCorrection::kQueueResidual);
248 weights(1)=-AliToyMCEventGenerator::GetSCScalingFactor(corrFluct, corrAverage,dummy);
249 residualDistortion->SetWeights(&weights);
251 TVectorD *vR = MakeLinBinning(10,86.,250.);
252 TVectorD *vPhi = MakeLinBinning(18*8,0.,2*TMath::Pi());
253 TVectorD *vZ = MakeLinBinning(50,-250.,250.);
256 Int_t bins[nbins] = {vR->GetNrows()-1, vPhi->GetNrows()-1, vZ->GetNrows()-1, 80};
257 // Int_t bins[nbins] = {16, 18*5, 50, 80};
258 Double_t xmin[nbins] = {86. , 0., -250., -2.};
259 Double_t xmax[nbins] = {250., 2*TMath::Pi(), 250., 2.};
260 THnF *hn = new THnF("hn", "hn", nbins, bins, xmin, xmax);
262 hn->GetAxis(0)->Set(vR ->GetNrows()-1, vR ->GetMatrixArray());
263 hn->GetAxis(1)->Set(vPhi->GetNrows()-1, vPhi->GetMatrixArray());
264 hn->GetAxis(2)->Set(vZ ->GetNrows()-1, vZ ->GetMatrixArray());
266 AliExternalTrackParam vv;
268 for (Float_t iz=-245; iz<=245; iz+=1) {
269 Short_t roc=(iz>=0)?0:18;
270 for (Float_t ir=86; ir<250; ir+=1) {
271 for (Float_t iphi=0; iphi<TMath::TwoPi(); iphi+=1*TMath::DegToRad()){
272 Float_t x=ir*(Float_t)TMath::Cos(iphi);
273 Float_t y=ir*(Float_t)TMath::Sin(iphi);
274 Float_t x3[3] = {x,y,iz};
275 Float_t dx3[3] = {0.,0.,0.};
276 residualDistortion->GetDistortion(x3,roc,dx3);
278 Double_t ddx3[3]={dx3[0], dx3[1], dx3[2]};
279 vv.Global2LocalPosition(ddx3,iphi);
281 Double_t xx[4]={ir, iphi, iz ,ddx3[1]};
288 TTreeSRedirector stream(outFile.Data());
293 stream.GetFile()->cd();
301 delete residualDistortion;
304 void DumpHn(THn *hn, TTreeSRedirector &stream)
306 TAxis *ar = hn->GetAxis(0);
307 TAxis *aphi = hn->GetAxis(1);
308 TAxis *az = hn->GetAxis(2);
312 Int_t bins[nbins] = {1,1,1};
313 Double_t xmin[nbins] = {0.,0.,0.};
314 Double_t xmax[nbins] = {1.,1.,1.};
315 THnF hnRes("hnRes", "hnRes", nbins, bins, xmin, xmax);
317 ar ->Copy(*hnRes.GetAxis(0));
318 aphi->Copy(*hnRes.GetAxis(1));
319 az ->Copy(*hnRes.GetAxis(2));
322 for (Int_t iz=0; iz<az->GetNbins(); ++iz) {
323 az->SetRange(iz+1,iz+1);
325 arrFits.SetName(Form("z_%02d",iz));
328 for (Int_t ir=0; ir<ar->GetNbins(); ++ir) {
329 ar->SetRange(ir+1,ir+1);
330 for (Int_t iphi=0; iphi<aphi->GetNbins(); ++iphi) {
331 aphi->SetRange(iphi+1,iphi+1);
333 TH1 *hProj = hn->Projection(3);
334 if (hProj->GetEntries()<1) {
339 TF1 fg("fg","gaus",-2,2);
340 Double_t cr = ar->GetBinCenter(ir+1);
341 Double_t cphi = aphi->GetBinCenter(iphi+1);
342 Double_t cz = az->GetBinCenter(iz+1);
343 hProj->SetNameTitle(Form("h_%02d_%02d_%02d",iz, iphi, ir),
344 Form("z,phi,r: %02d,%02d,%02d (%.2f, %.2f, %.2f)",iz,iphi,ir, cz, cphi, cr )
346 hProj->Fit(&fg,"LMQR");
349 Float_t mean = fg.GetParameter(1);
350 Float_t meanErr = fg.GetParError(1);
351 Float_t sigma = fg.GetParameter(2);
352 Float_t sigmaErr = fg.GetParError(2);
353 Int_t entries = hProj->GetEntries();
354 Float_t chi2ndf = fg.GetChisquare()/fg.GetNDF();
355 Float_t mean2 = hProj->GetMean();
356 Float_t meanErr2 = hProj->GetMeanError();
357 Float_t rms2 = hProj->GetRMS();
358 Float_t rmsErr2 = hProj->GetRMSError();
368 "meanErr=" << meanErr <<
370 "sigmaErr=" << sigmaErr <<
371 "histMean=" << mean2 <<
372 "histMeanErr=" << meanErr2 <<
373 "histRMS=" << rms2 <<
374 "histRMSErr=" << rmsErr2 <<
375 "entries=" << entries <<
376 "chi2ndf=" << chi2ndf <<
379 Double_t x[nbins]={cr, cphi, cz};
380 if (meanErr<0.3) hnRes.Fill(x,mean);
383 stream.GetFile()->cd();
384 arrFits.Write(0x0,TObject::kSingleKey);
388 stream.GetFile()->cd();
393 //______________________________________________________________________________
394 TVectorD* MakeLogBinning(Int_t nbinsX, Double_t xmin, Double_t xmax)
397 // Make logarithmic binning
398 // the user has to delete the array afterwards!!!
402 if (xmin<1e-20 || xmax<1e-20){
403 printf("For Log binning xmin and xmax must be > 1e-20. Using linear binning instead!");
404 return MakeLinBinning(nbinsX, xmin, xmax);
411 TVectorD *binLim=new TVectorD(nbinsX+1);
414 Double_t expMax=TMath::Log(last/first);
415 for (Int_t i=0; i<nbinsX+1; ++i){
416 (*binLim)[i]=first*TMath::Exp(expMax/nbinsX*(Double_t)i);
421 //______________________________________________________________________________
422 TVectorD* MakeLinBinning(Int_t nbinsX, Double_t xmin, Double_t xmax)
425 // Make linear binning
426 // the user has to delete the array afterwards!!!
433 TVectorD *binLim=new TVectorD(nbinsX+1);
436 Double_t binWidth=(last-first)/nbinsX;
437 for (Int_t i=0; i<nbinsX+1; ++i){
438 (*binLim)[i]=first+binWidth*(Double_t)i;
443 //_____________________________________________________________________________
444 TVectorD* MakeArbitraryBinning(const char* bins)
447 // Make arbitrary binning, bins separated by a ','
449 TString limits(bins);
450 if (limits.IsNull()){
451 printf("Bin Limit string is empty, cannot add the variable");
455 TObjArray *arr=limits.Tokenize(",");
456 Int_t nLimits=arr->GetEntries();
458 printf("Need at leas 2 bin limits, cannot add the variable");
463 TVectorD *binLimits=new TVectorD(nLimits);
464 for (Int_t iLim=0; iLim<nLimits; ++iLim){
465 (*binLimits)[iLim]=(static_cast<TObjString*>(arr->At(iLim)))->GetString().Atof();
472 void PlotFromTree(TTree *d, TString outDir=".")
474 TCanvas *c=new TCanvas;
475 gStyle->SetOptStat(0);
476 d->SetMarkerStyle(20);
479 TProfile2D pRZ("pRZ",";z (cm); r(cm)",50,-250,250,10,85,250);
480 d->Draw("entries:cr:cz>>pRZ","","profcolz");
481 pRZ.GetZaxis()->UnZoom();
482 c->SaveAs(Form("%s/entries_average.png",outDir.Data()));
483 d->Draw("entries:cr:cz>>pRZ","iphi==2","profcolz");
484 c->SaveAs(Form("%s/entries_onePhi.png",outDir.Data()));
486 pRZ.SetMaximum(0.04);
487 d->Draw("meanErr:cr:cz>>pRZ","","profcolz");
488 c->SaveAs(Form("%s/meanErr_average.png",outDir.Data()));
489 d->Draw("meanErr:cr:cz>>pRZ","iphi==2","profcolz");
490 c->SaveAs(Form("%s/meanErr_onePhi.png",outDir.Data()));
493 d->Draw("mean:cphi:cr","iz==25","colz");
494 c->SaveAs(Form("%s/mean_oneZ_phi_allR.png",outDir.Data()));
495 d->Draw("mean:meanErr:cphi","iz==25&&ir==2","goff");
496 TGraphErrors *grmean_phi=new TGraphErrors(d->GetSelectedRows(),d->GetV3(),d->GetV1(),0,d->GetV2());
497 grmean_phi->SetTitle(";#varphi;#LT#Delta r#varphi#GT");
498 grmean_phi->SetMarkerStyle(20);
499 grmean_phi->SetMarkerSize(1);
500 grmean_phi->Draw("ap");
501 c->SaveAs(Form("%s/mean_oneZ_phi_oneR.png",outDir.Data()));
503 d->Draw("mean:cr:cphi","iz==25","colz");
504 c->SaveAs(Form("%s/mean_oneZ_r_allPhi.png",outDir.Data()));
506 d->Draw("mean:meanErr:cr","iz==25&&iphi==2","goff");
507 TGraphErrors *grmean_r=new TGraphErrors(d->GetSelectedRows(),d->GetV3(),d->GetV1(),0,d->GetV2());
508 grmean_r->SetTitle(";r (cm);#LT#Delta r#varphi#GT");
509 grmean_r->SetMarkerStyle(20);
510 grmean_r->SetMarkerSize(1);
511 grmean_r->Draw("ap");
512 c->SaveAs(Form("%s/mean_oneZ_r_onePhi.png",outDir.Data()));
515 d->Draw("meanErr:cphi:cr","iz==25","colz");
516 c->SaveAs(Form("%s/meanErr_oneZ_phi_allR.png",outDir.Data()));
517 d->Draw("meanErr:cphi","iz==25&&ir==2");
518 c->SaveAs(Form("%s/meanErr_oneZ_phi_oneR.png",outDir.Data()));
520 d->Draw("meanErr:cr:cphi","iz==25","colz");
521 c->SaveAs(Form("%s/meanErr_oneZ_r_allPhi.png",outDir.Data()));
523 d->Draw("meanErr:cr","iz==25&&iphi==2");
524 c->SaveAs(Form("%s/meanErr_oneZ_r_onePhi.png",outDir.Data()));