1 ///////////////////////////////////////////////////////
3 // Basic class for Performance/Calibration TRD tasks
5 // It performs generic tasks like :
6 // - data file manegment
7 // - reference container management
8 // - debug container management
9 // - interaction with AliAnalysisManager
10 // - Plot functor loop
12 // Author: Alexandru Bercuci <A.Bercuci@gsi.de>, 10/09/2008
14 /////////////////////////////////////////////////////////
18 #include "TMethodCall.h"
19 #include "TMethodArg.h"
28 #include "TObjArray.h"
29 #include "TDirectory.h"
30 #include "TTreeStream.h"
36 #include "AliAnalysisTask.h"
37 #include "AliAnalysisManager.h"
38 #include "AliExternalTrackParam.h"
40 #include "info/AliTRDchmbInfo.h"
41 #include "info/AliTRDeventInfo.h"
42 #include "info/AliTRDtrendingManager.h"
43 #include "AliTRDrecoTask.h"
44 #include "AliTRDtrackV1.h"
45 #include "AliTRDpidUtil.h"
47 ClassImp(AliTRDrecoTask)
49 Float_t AliTRDrecoTask::fgPt[AliTRDrecoTask::fgNPt+1] = {0.};
50 TTreeSRedirector* AliTRDrecoTask::fgDebugStream(NULL);
51 TH1* AliTRDrecoTask::fgProjector(NULL);
52 //_______________________________________________________
53 AliTRDrecoTask::AliTRDrecoTask()
75 ,fRunTerminate(kFALSE)
77 // Default constructor
78 snprintf(fNameId, 10, "no name");
81 //_______________________________________________________
82 AliTRDrecoTask::AliTRDrecoTask(const char *name, const char *title)
83 : AliAnalysisTaskSE(name)
104 ,fRunTerminate(kFALSE)
106 // Constructor for all derived performance tasks
109 snprintf(fNameId, 10, "no name");
110 DefineInput (1, TObjArray::Class()); // track list
111 DefineInput (2, AliTRDeventInfo::Class()); // event info object
112 DefineInput (3, TObjArray::Class()); // cluster list object
113 DefineOutput(1, TObjArray::Class()); // histogram list
116 //_______________________________________________________
117 AliTRDrecoTask::~AliTRDrecoTask()
120 // Generic task destructor
122 AliDebug(2, Form(" Ending task %s[%s]", GetName(), GetTitle()));
124 delete fgDebugStream;
125 fgDebugStream = NULL;
134 fPlotFuncList->Delete();
135 delete fPlotFuncList;
136 fPlotFuncList = NULL;
139 fDetFuncList->Delete();
145 if(fDets->IsOwner()) fDets->Delete();
149 if(fDetsV) delete fDetsV; fDetsV=NULL;
150 if(fTriggerList){fTriggerList->Delete(); delete fTriggerList;}
152 if(fContainer && !(AliAnalysisManager::GetAnalysisManager() && AliAnalysisManager::GetAnalysisManager()->IsProofMode())){
153 if(fContainer->IsOwner()) fContainer->Delete();
159 TFile::Open("TRD.PerformanceTrend.root", "UPDATE");
160 fgTrendPoint->Write();
167 //_______________________________________________________
168 Int_t AliTRDrecoTask::GetNRefFigures() const
170 if(!fNRefFigures) AliWarning("No reference plots available.");
174 //____________________________________________________________________
175 Int_t AliTRDrecoTask::GetPtBin(Float_t pt)
177 // Get significant (very low, low, medium, high, very high) pt bin
181 if(pt<fgPt[ipt]) break;
187 //_______________________________________________________
188 Bool_t AliTRDrecoTask::MakeMomSegmentation()
193 for(Int_t j(1); j<=fgNPt; j++) fgPt[j]=fgPt[j-1]+(TMath::Exp(j*j*2.e-3)-1.);
194 AliDebug(2, "Using debug momentum segmentation");
197 fgPt[0]=0.5; fgPt[1]=0.8; fgPt[2]=1.5; fgPt[3]=5.;
198 AliDebug(2, "Using default momentum segmentation");
201 AliError(Form("Momentum segmentation %d not supported.", fNpt));
208 //_______________________________________________________
209 void AliTRDrecoTask::UserCreateOutputObjects()
211 if(!HasFunctorList()) InitFunctorList();
212 if(DebugLevel()) fNpt = fgNPt;
214 MakeMomSegmentation();
216 fContainer = Histos();
217 PostData(1, fContainer);
220 //_______________________________________________________
221 void AliTRDrecoTask::UserExec(Option_t *)
223 // Loop over Plot functors published by particular tasks
225 fTracks = dynamic_cast<TObjArray *>(GetInputData(1));
226 fEvent = dynamic_cast<AliTRDeventInfo *>(GetInputData(2));
228 if(fTriggerList && fEvent){
229 for(Int_t itrig(0); itrig<fTriggerList->GetEntries(); itrig++){
230 if(!fEvent->GetFiredTriggerClasses().Contains(((TObjString*)(*fTriggerList)[itrig])->GetName())) continue;
231 //printf("\"%s\" selected\n", ((TObjString*)(*fTriggerList)[itrig])->GetName());
232 SETBIT(fTriggerSlot,itrig);
235 AliDebug(2, Form("Triggers[%s] not used for %s", fEvent->GetFiredTriggerClasses().Data(), GetName()));
239 fClusters = dynamic_cast<TObjArray*>(GetInputData(3));
242 AliWarning("No track functor list defined for the task");
245 if(!fEvent || !fTracks) return;
246 if(!fTracks->GetEntriesFast()) return;
247 else AliDebug(2, Form("Tracks[%d] for %s", fTracks->GetEntriesFast(), GetName()));
250 AliTRDtrackInfo *trackInfo(NULL);
251 TIter plotIter(fPlotFuncList);
252 TObjArrayIter trackIter(fTracks);
253 while((trackInfo = dynamic_cast<AliTRDtrackInfo*>(trackIter()))){
254 itrk++; fPt=-1; fEta=0.; fPhi=0.; fSpecies=-6;
255 fkMC = trackInfo->GetMCinfo();
256 fkESD = trackInfo->GetESDinfo();
257 if((fkTrack = trackInfo->GetTrack())){
258 // cache properties of the track at TRD entrance
259 // check input track status
260 AliExternalTrackParam *tin(NULL);
261 if(!(tin = fkTrack->GetTrackIn())) AliDebug(2, Form("Missing TRD track[%d] :: entry point.", itrk));
266 if(!tin->GetXYZ(xyz)) AliDebug(2, Form("Failed TRD track[%d] :: global track postion", itrk));
267 else fPhi = TMath::ATan2(xyz[1], xyz[0]);
268 fSpecies= fkTrack->Charge()*(AliTRDpidUtil::Mass2Pid(fkTrack->GetMass())+1);
270 } else AliDebug(2, Form("Missing TRD track[%d].", itrk));
272 TMethodCall *plot(NULL);
274 while((plot=dynamic_cast<TMethodCall*>(plotIter()))) plot->Execute(this);
276 if(!fClusters) return;
278 AliDebug(1, "No detector functor list defined for task");
281 TIter detIter(fDetFuncList);
282 for(Int_t idet(0); idet<AliTRDgeometry::kNdet; idet++){
283 if(!(fkClusters = (TObjArray*)fClusters->At(idet))) continue;
284 TMethodCall *det(NULL);
286 while((det=dynamic_cast<TMethodCall*>(detIter()))) det->Execute(this);
290 //_______________________________________________________
291 Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)
293 AliWarning("Retrieving reference figures not implemented.");
297 //_______________________________________________________
298 Bool_t AliTRDrecoTask::PutTrendValue(const Char_t *name, Double_t val, Double_t err)
300 // Generic publisher for trend values
302 AliTRDtrendingManager *tm = AliTRDtrendingManager::Instance();
304 AliError("Wrong usage of the trending functionality. Could not instantiate AliTRDtrendingManager singleton.");
307 tm->AddValue(Form("%s_%s", GetName(), name), val, err);
311 //_______________________________________________________
312 void AliTRDrecoTask::InitFunctorList()
314 // Initialize list of functors
316 TClass *c = this->IsA();
317 if(fPlotFuncList) fPlotFuncList->Clear();
318 if(fDetFuncList) fDetFuncList->Clear();
321 TIter methIter(c->GetListOfMethods());
322 while((m=dynamic_cast<TMethod*>(methIter()))){
323 TString name(m->GetName());
324 if(name.BeginsWith("Plot")){
325 if(!fPlotFuncList) fPlotFuncList = new TList();
326 fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));
327 } else if(name.BeginsWith("Det")){
328 if(!fDetFuncList) fDetFuncList = new TList();
329 fDetFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));
334 //_______________________________________________________
335 Bool_t AliTRDrecoTask::Load(const Char_t *file, const Char_t *dir)
337 // Generic container loader
339 if(!TFile::Open(file)){
340 AliWarning(Form("Couldn't open file %s.", file));
344 AliWarning(Form("Couldn't cd to %s in %s.", dir, file));
348 if(!(fContainer = (TObjArray*)gDirectory->Get(GetName()))){
349 AliWarning("Missing histogram container.");
357 //________________________________________________________
358 Bool_t AliTRDrecoTask::LoadDetectorMap(const Char_t *file, const Char_t *dir)
360 // Load detector map.
362 if(!TFile::Open(file)){
363 AliWarning(Form("Couldn't open file %s.", file));
367 AliWarning(Form("Couldn't cd to %s in %s.", dir, file));
371 TObjArray *info = NULL;
372 if(!(info = (TObjArray*)gDirectory->Get("TRDinfoGen"))){
373 AliWarning("Missing TRDinfoGen container.");
378 if(info->FindObject("Chambers Status"))
379 fDets = (TObjArray*)((TObjArray*)info->FindObject("Chambers Status"))->Clone();
382 if(!info->At(4) || strcmp("TObjArray", info->At(4)->IsA()->GetName())) AliError("Looking for old style chamber status map. Failed.");
384 AliWarning("Looking for old style chamber status map.");
385 fDetsV = (TObjArray*)((TObjArray*)info->At(4))->Clone();
389 info->Delete(); delete info;
394 //________________________________________________________
395 Bool_t AliTRDrecoTask::Save(TObjArray * const results){
397 // Store the output graphs in a ROOT file
398 // Input TObject array will not be written as Key to the file,
399 // only content itself
402 TDirectory *cwd = gDirectory;
403 if(!TFile::Open(Form("TRD.Result%s.root", GetName()), "RECREATE")) return kFALSE;
405 TIterator *iter = results->MakeIterator();
406 TObject *inObject = NULL, *outObject = NULL;
407 while((inObject = iter->Next())){
408 outObject = inObject->Clone();
409 outObject->Write(NULL, TObject::kSingleKey);
412 gFile->Close(); delete gFile;
417 //_______________________________________________________
418 Bool_t AliTRDrecoTask::PostProcess()
420 // To be implemented by particular tasks
422 AliWarning("Post processing of reference histograms not implemented.");
426 //_______________________________________________________
427 void AliTRDrecoTask::MakeDetectorPlot(Int_t ly, const Option_t *opt)
429 // Draw chamber boundaries in eta/phi plots with misalignments
430 // based on info collected by AliTRDinfoGen
433 AliWarning("NEW Detector map and status not available. Try OLD");
434 MakeDetectorPlotOLD(ly, opt);
437 AliTRDchmbInfo *ci(NULL);
438 for(Int_t idet(0); idet<fDets->GetEntriesFast(); idet++){
439 if(!(ci = (AliTRDchmbInfo*)fDets->At(idet))) continue;
440 if(AliTRDgeometry::GetLayer(ci->GetDetector()) != ly) continue;
445 //_______________________________________________________
446 void AliTRDrecoTask::MakeDetectorPlotOLD(Int_t ly, const Option_t *opt)
448 // Draw chamber boundaries in eta/phi plots with misalignments
449 // based on info collected by AliTRDinfoGen OLD data storage
452 AliError("OLD Detector map and status not available.");
455 if(!fDetsV->GetEntries()){
456 AliError("OLD Detector map and status not filled.");
460 Float_t xmin(0.), xmax(0.);
461 TBox *gdet = new TBox();
462 gdet->SetLineColor(kBlack);gdet->SetFillColor(kBlack);
463 Int_t style[] = {0, 3003};
464 for(Int_t idet(0); idet<540; idet++){
465 if(idet%6 != ly) continue;
466 TVectorF *det((TVectorF*)fDetsV->At(idet));
468 Int_t iopt = Int_t((*det)[4]);
469 if(strcmp(opt, "eta")==0){
470 xmin=(*det)[0]; xmax=(*det)[2];
471 } else if(strcmp(opt, "pad")==0){
472 Int_t stk(AliTRDgeometry::GetStack(idet));
473 xmin=-0.6+16*(4-stk)-(stk<2?4:0); xmax=xmin+(stk==2?12:16)-0.2;
475 AliDebug(2, Form("det[%03d] 0[%+4.1f(%+4.1f) %+4.1f] 1[%+4.1f(%+4.1f) %+4.1f] opt[%d]", idet, xmin, (*det)[0], (*det)[1], xmax, (*det)[2], (*det)[3], iopt));
477 gdet->SetFillStyle(style[1]);gdet->SetFillColor(kBlack);
478 gdet->DrawBox(xmin, (*det)[1], xmax, (*det)[3]);
480 gdet->SetFillStyle(style[0]);
481 gdet->DrawBox(xmin, (*det)[1], xmax, (*det)[3]);
483 gdet->SetFillStyle(style[1]);gdet->SetFillColor(kGreen);
484 gdet->DrawBox(xmin, (*det)[1], xmax, 0.5*((*det)[3]+(*det)[1]));
486 gdet->SetFillStyle(style[1]);gdet->SetFillColor(kRed);
487 gdet->DrawBox(xmin, 0.5*((*det)[3]+(*det)[1]), xmax, (*det)[3]);
488 } else if(iopt!=0) AliError(Form("Wrong chmb. status[%d] for det[%03d]", iopt, idet));
491 Float_t dsm = TMath::TwoPi()/AliTRDgeometry::kNsector;
493 if(strcmp(opt, "pad")==0) xmin=38.;
494 TLatex *sm = new TLatex(); sm->SetTextAlign(22);sm->SetTextColor(kBlack); sm->SetTextFont(32);sm->SetTextSize(0.03);
495 for(Int_t is(0); is<AliTRDgeometry::kNsector; is++) sm->DrawLatex(xmin, -TMath::Pi()+(is+0.5)*dsm, Form("%02d", is>=9?(is-9):(is+9)));
499 //_______________________________________________________
500 void AliTRDrecoTask::MakeSummary()
502 // To be implemented by particular tasks
503 AliWarning("Summary not available");
506 //_______________________________________________________
507 void AliTRDrecoTask::SetDebugLevel(Int_t level)
509 // Generic debug handler
511 AliAnalysisTaskSE::SetDebugLevel(level);
512 if(DebugLevel()>=1 && !fgDebugStream){
513 AliInfo(Form("Debug Level for Task %s set to %d", GetName(), level));
514 TDirectory *savedir = gDirectory;
515 fgDebugStream = new TTreeSRedirector("TRD.DebugPerformance.root", "RECREATE");
520 //____________________________________________________________________
521 void AliTRDrecoTask::Terminate(Option_t *)
528 delete fgDebugStream;
529 fgDebugStream = NULL;
531 fContainer = dynamic_cast<TObjArray *>(GetOutputData(1));
532 if(fContainer && fRunTerminate){
538 //________________________________________________________
539 Float_t AliTRDrecoTask::SetNormZ(TH2 *h2, Int_t bxmin, Int_t bxmax, Int_t bymin, Int_t bymax, Float_t thr)
541 // Normalize histo content to the mean value in the range specified by bin ranges
542 // [bxmin, bxmax] on the x axis and [bymin, bymax] on the y axis.
543 // Optionally a threshold "thr" can be specified to disregard entries with no meaning
545 Float_t s = 0., c=0.; Int_t is(0);
546 for(Int_t ix(bxmin); ix<=(bxmax>0?bxmax:(h2->GetXaxis()->GetNbins())); ix++){
547 for(Int_t iy(bymin); iy<=(bymax>0?bymax:(h2->GetYaxis()->GetNbins())); iy++){
548 if((c = h2->GetBinContent(ix, iy))<thr) continue;
553 for(Int_t ix(1); ix<=h2->GetXaxis()->GetNbins(); ix++){
554 for(Int_t iy(1); iy<=h2->GetYaxis()->GetNbins(); iy++){
555 if((c = h2->GetBinContent(ix, iy))<thr) h2->SetBinContent(ix, iy, thr-1000);
556 else h2->SetBinContent(ix, iy, 100.*(c/s-1.));
562 //________________________________________________________
563 void AliTRDrecoTask::SetRangeZ(TH2 *h2, Float_t min, Float_t max, Float_t thr)
565 // Set range on Z axis such to avoid outliers
567 Float_t c(0.), dz(1.e-3*(max-min));
568 for(Int_t ix(1); ix<=h2->GetXaxis()->GetNbins(); ix++){
569 for(Int_t iy(1); iy<=h2->GetYaxis()->GetNbins(); iy++){
570 if((c = h2->GetBinContent(ix, iy))<thr) continue;
571 if(c<=min) h2->SetBinContent(ix, iy, min+dz);
574 h2->GetZaxis()->SetRangeUser(min, max);
577 //________________________________________________________
578 Float_t AliTRDrecoTask::GetMeanStat(TH1 *h, Float_t cut, Int_t opt, Float_t *sigma)
580 // Return mean number of entries/bin of histogram "h".
581 // If optionally sigma is allocated than it is also filled with sigma paramter of the gauss fit
583 // Option "opt" is given the following values are accepted:
584 // -1 : consider only entries less than "cut"
585 // 1 : consider only entries greater than "cut"
586 // 0 : no "cut" [dafault]
588 // -999. : statistics too low [20]
589 // -998. : fit failed
591 const Int_t kvd(100000);
593 Int_t nbx(h->GetNbinsX()), nby(h->GetNbinsY()), nbz(h->GetNbinsZ());
594 Int_t nv(0); Float_t xmin(1.e5), xmax(-xmin);
595 for(Int_t ix(1); ix<=nbx; ix++){
596 for(Int_t iy(1); iy<=nby; iy++){
597 for(Int_t iz(1); iz<=nbz; iz++){
598 Float_t c = h->GetBinContent(ix, iy, iz);
599 if(opt*(c-cut)<0.) continue;
604 printf("W - AliTRDrecoTask::GetMeanStat() :: Unreliable results for %s[%s]. Statical allocation exceeded.\n", h->GetName(), h->GetTitle());
613 //printf("W - AliTRDrecoTask::GetMeanStat() :: Failed for %s[%s]. Statical undefined [%d].\n", h->GetName(), h->GetTitle(), nv);
616 if(fgProjector) delete fgProjector;
617 fgProjector = new TH1F("hProjector", "", 20, 0.5*(3*xmin-xmax), 0.5*(3*xmax - xmin));
618 for(Int_t iv(0); iv<nv; iv++) fgProjector->Fill(v[iv]);
619 TF1 f("f", "gaus", xmin, xmax);
620 f.SetParameter(0, fgProjector->Integral());
621 f.SetParameter(1, fgProjector->GetMean()); f.SetParLimits(1, xmin, xmax);
622 f.SetParameter(2, fgProjector->GetRMS());
623 if(fgProjector->Fit(&f, "WQ0", "goff")) return -998.;
624 if(sigma) *sigma = f.GetParameter(2);
625 return f.GetParameter(1);
628 //________________________________________________________
629 Int_t AliTRDrecoTask::Rebin(TH2 *h, Int_t n, Int_t rebinX[], Int_t rebinY[], Int_t nstat)
631 // Rebin histo "h" according to "rebinning" strategy "n" steps such to obtain mean statistics per bin over "nstat"
634 while(irebin<n && GetMeanStat(h, .5, 1)<nstat){
635 h->Rebin2D(rebinX[irebin], rebinY[irebin]);
641 //________________________________________________________
642 AliTRDrecoTask::AliTRDrecoProjection::AliTRDrecoProjection()
648 fRebin[0] = NULL;fRebin[1] = NULL;
649 memset(fAx, 0, 3*sizeof(Int_t));
650 memset(fRange, 0, 4*sizeof(Float_t));
653 //________________________________________________________
654 AliTRDrecoTask::AliTRDrecoProjection::~AliTRDrecoProjection()
658 if(fRebin[0]) delete [] fRebin[0];
659 if(fRebin[1]) delete [] fRebin[1];
662 //________________________________________________________
663 void AliTRDrecoTask::AliTRDrecoProjection::Build(const Char_t *n, const Char_t *t, Int_t ix, Int_t iy, Int_t iz, TAxis *aa[])
665 // check and build (if neccessary) projection determined by axis "ix", "iy" and "iz"
666 if(!aa[ix] || !aa[iy] || !aa[iz]) return;
667 TAxis *ax(aa[ix]), *ay(aa[iy]), *az(aa[iz]);
668 // check ax definiton to protect against older versions of the data
669 if(ax->GetNbins()<=0 || (ax->GetXmax()-ax->GetXmin())<=0.){
670 AliWarning(Form("Wrong definition of axis[%d] \"%s\"[%d](%f %f).", ix, ax->GetTitle(), ax->GetNbins(), ax->GetXmin(), ax->GetXmax()));
673 if(ay->GetNbins()<=0 || (ay->GetXmax()-ay->GetXmin())<=0.){
674 AliWarning(Form("Wrong definition of axis[%d] \"%s\"[%d](%f %f).", ix, ay->GetTitle(), ay->GetNbins(), ay->GetXmin(), ay->GetXmax()));
677 if(az->GetNbins()<=0 || (az->GetXmax()-az->GetXmin())<=0.){
678 AliWarning(Form("Wrong definition of axis[%d] \"%s\"[%d](%f %f).", ix, az->GetTitle(), az->GetNbins(), az->GetXmin(), az->GetXmax()));
682 fH = new TH3I(n, Form("%s;%s;%s;%s", t, ax->GetTitle(), ay->GetTitle(), az->GetTitle()),
683 ax->GetNbins(), ax->GetXmin(), ax->GetXmax(),
684 ay->GetNbins(), ay->GetXmin(), ay->GetXmax(),
685 az->GetNbins(), az->GetXmin(), az->GetXmax());
686 fAx[0] = ix; fAx[1] = iy; fAx[2] = iz;
687 fRange[0] = az->GetXmin()/3.; fRange[1] = az->GetXmax()/3.;
688 AliDebug(2, Form("H3(%s, %s) :: %s[%3d %4.2f %4.2f]%s[%3d %4.2f %4.2f]%s[%3d %4.2f %4.2f]", n, t,
689 ax->GetTitle(), ax->GetNbins(), ax->GetXmin(), ax->GetXmax(),
690 ay->GetTitle(), ay->GetNbins(), ay->GetXmin(), ay->GetXmax(),
691 az->GetTitle(), az->GetNbins(), az->GetXmin(), az->GetXmax()));
694 //________________________________________________________
695 AliTRDrecoTask::AliTRDrecoProjection& AliTRDrecoTask::AliTRDrecoProjection::operator=(const AliTRDrecoProjection& rhs)
698 if(this == &rhs) return *this;
700 TNamed::operator=(rhs);
701 if(fNrebin){fNrebin=0; delete [] fRebin[0]; delete [] fRebin[1];}
702 if(rhs.fNrebin) SetRebinStrategy(rhs.fNrebin, rhs.fRebin[0], rhs.fRebin[1]);
703 memcpy(fAx, rhs.fAx, 3*sizeof(Int_t));
704 memcpy(fRange, rhs.fRange, 4*sizeof(Float_t));
706 if(rhs.fH) fH=(TH3I*)rhs.fH->Clone(Form("%s_CLONE", rhs.fH->GetName()));
710 //________________________________________________________
711 AliTRDrecoTask::AliTRDrecoProjection& AliTRDrecoTask::AliTRDrecoProjection::operator+=(const AliTRDrecoProjection& other)
713 // increment projections
714 if(!fH || !other.fH) return *this;
715 AliDebug(2, Form("%s+=%s [%s+=%s]", GetName(), other.GetName(), fH->GetName(), (other.fH)->GetName()));
720 //________________________________________________________
721 void AliTRDrecoTask::AliTRDrecoProjection::Increment(Int_t bin[], Double_t v)
723 // increment bin with value "v" pointed by general coord in "bin"
725 AliDebug(4, Form(" %s[%2d]", fH->GetName(), Int_t(v)));
726 fH->AddBinContent(fH->GetBin(bin[fAx[0]],bin[fAx[1]],bin[fAx[2]]), Int_t(v));
729 //________________________________________________________
730 Double_t AliTRDrecoTask::AliTRDrecoProjection::GetTrendValue(const Int_t mid, Double_t *e, Double_t *s, Double_t *se) const
732 // Return result of fitting the main distribution (represented on the z axis) with the function selected
733 // "mid". Optionally return the Mean and RMS of the distribution pointing to "m" and "s"
736 AliDebug(1, Form("Missing 3D in %s", GetName()));
740 if(!(h1s = (TH1D*)fH->Project3D("z"))){
741 AliDebug(1, Form("Failed Project3D(\"z\") in %s", GetName()));
744 Int_t ne((Int_t)h1s->Integral());
746 AliDebug(1, Form("Statistics too low[%2d] in %s", ne, GetName()));
750 TAxis *az(h1s->GetXaxis());
751 Float_t mn(h1s->GetMean()), rms(h1s->GetRMS()),
752 v(mn), // main trending value (mean, mu, MPV)
753 ve(rms),// dispersion (RMS, sigma, landau 2nd param)
754 ev(h1s->GetMeanError()), // error on v
755 eve(h1s->GetRMSError());// error on ve
757 TF1 fg("fg", "gaus", az->GetXmin(), az->GetXmax());
758 fg.SetParameter(0, Float_t(ne)); fg.SetParameter(1, mn); fg.SetParameter(2, rms);
759 h1s->Fit(&fg, "WQ0");
760 v = fg.GetParameter(1); ev = fg.GetParError(1);
761 ve= fg.GetParameter(2); eve= fg.GetParError(2);
763 TF1 fl("fl", "landau", az->GetXmin(), az->GetXmax());
764 fl.SetParameter(0, Float_t(ne)); fl.SetParameter(1, mn); fl.SetParameter(2, rms);
765 h1s->Fit(&fl, "WQ0");
766 v = fl.GetMaximumX(); ev = fl.GetParError(1);
767 ve= fl.GetParameter(2);eve= fl.GetParError(2);
772 AliDebug(2, Form("[%d] %s(%4d) = M{%f+-%f} S{%f+-%f}", mid, fH->GetName(), (Int_t)h1s->Integral(), v, ev, ve, eve));
778 //________________________________________________________
779 TH2* AliTRDrecoTask::AliTRDrecoProjection::Projection2Dbin(Int_t bin, Bool_t mc)
781 // dumb 2D projection for bin including under/over flow. Default all [bin==-1]
783 TAxis *ax(fH->GetXaxis()), *ay(fH->GetYaxis()), *az(fH->GetZaxis());
784 Int_t nbins(az->GetNbins());
786 if(bin<0) h2 = new TH2F(Form("%s_2D", fH->GetName()),
787 Form("%s;%s;%s;Entries", fH->GetTitle(), ax->GetTitle(), ay->GetTitle()),
788 ax->GetNbins(), ax->GetXmin(), ax->GetXmax(),
789 ay->GetNbins(), ay->GetXmin(), ay->GetXmax());
790 else h2 = new TH2F(Form("%s%d_2D", fH->GetName(), bin),
791 Form("%s | #it{%4.2f<=p_{t}^{%s}[GeV/c]<%4.2f};%s;%s;Entries", fH->GetTitle(),
792 bin?fgPt[bin-1]:0., mc?"MC":"", bin>nbins?99.99:fgPt[bin], ax->GetTitle(), ay->GetTitle()),
793 ax->GetNbins(), ax->GetXmin(), ax->GetXmax(),
794 ay->GetNbins(), ay->GetXmin(), ay->GetXmax());
795 for(Int_t ix(1); ix<=ax->GetNbins(); ix++){
796 for(Int_t iy(1); iy<=ay->GetNbins(); iy++){
797 Int_t ibin = h2->GetBin(ix, iy);
798 for(Int_t iz(0); iz<=az->GetNbins()+1; iz++){
799 if(bin<0) h2->AddBinContent(ibin, fH->GetBinContent(ix, iy, iz));
801 h2->AddBinContent(ibin, fH->GetBinContent(ix, iy, iz));
810 //________________________________________________________
811 TH2* AliTRDrecoTask::AliTRDrecoProjection::Projection2D(const Int_t nstat, const Int_t ncol, const Int_t mid, Bool_t del)
813 // build the 2D projection and adjust binning
815 const Char_t *title[] = {"Mean", "#mu", "MPV"};
817 AliDebug(1, Form("Missing 3D in %s", GetName()));
820 TAxis *ax(fH->GetXaxis()), *ay(fH->GetYaxis()), *az(fH->GetZaxis());
821 TH2D *h2s(NULL), *hyx(NULL);
822 if(!(h2s = (TH2D*)fH->Project3D("yx"))){
823 AliDebug(1, Form("Failed Project3D(\"yx\") in %s", GetName()));
826 // save a copy of the original distribution
828 hyx = (TH2D*)h2s->Clone();
829 hyx->SetName(Form("%sEn", fH->GetName()));
831 Int_t irebin(Rebin(h2s, fNrebin, fRebin[0], fRebin[1], nstat)), dxBin(1), dyBin(1);
832 for(Int_t ir(0); ir<irebin; ir++){dxBin*=fRebin[0][ir]; dyBin*=fRebin[1][ir];}
833 Int_t nx(h2s->GetNbinsX()), ny(h2s->GetNbinsY());
835 if(mid<0) return NULL;
838 TH1 *h(NULL); Int_t n(0);
839 Float_t dz=(fRange[1]-fRange[1])/ncol;
840 TString titlez(az->GetTitle()); TObjArray *tokenTitle(titlez.Tokenize(" "));
841 Int_t nt(tokenTitle->GetEntriesFast());
843 if((h2 = (TH2*)gDirectory->Get(Form("%s_2D", fH->GetName())))) delete h2; // avoid ROOT warning messages
844 h2 = new TH2F(Form("%s_2D", fH->GetName()),
845 Form("%s;%s;%s;%s(%s) %s", fH->GetTitle(), ax->GetTitle(), ay->GetTitle(), title[mid], nt>0?(*tokenTitle)[0]->GetName():"", nt>1?(*tokenTitle)[1]->GetName():""),
846 nx, ax->GetXmin(), ax->GetXmax(), ny, ay->GetXmin(), ay->GetXmax());
847 tokenTitle->Delete(); delete tokenTitle;
848 h2->SetContour(ncol);
849 h2->GetZaxis()->CenterTitle();
850 h2->GetZaxis()->SetTitleOffset(1.4);
851 h2->GetZaxis()->SetRangeUser(fRange[0], fRange[1]);
852 AliDebug(2, Form("%s[%s] nx[%d] ny[%d]", h2->GetName(), h2->GetTitle(), nx, ny));
853 for(Int_t iy(0); iy<ny; iy++){
854 for(Int_t ix(0); ix<nx; ix++){
855 h = fH->ProjectionZ(Form("%s_z", h2->GetName()), ix*dxBin+1, (ix+1)*dxBin, iy*dyBin+1, (iy+1)*dyBin);
856 Int_t ne((Int_t)h->Integral());
857 //printf(" x[%2d %2d] y[%2d %2d] ne[%4d]\n", ix*dxBin+1, (ix+1)*dxBin, iy*dyBin+1, (iy+1)*dyBin, ne);
859 h2->SetBinContent(ix+1, iy+1, -999);
860 h2->SetBinError(ix+1, iy+1, 1.);
863 // redo the projection by adding 1 bin @ left and 1 bin @ right for smoothing
864 h = fH->ProjectionZ(Form("%s_z", h2->GetName()), ix*dxBin, (ix+1)*dxBin+1, iy*dyBin, (iy+1)*dyBin+1);
865 Float_t v(h->GetMean()), ve(h->GetRMS());
867 TF1 fg("fg", "gaus", az->GetXmin(), az->GetXmax());
868 fg.SetParameter(0, Float_t(ne)); fg.SetParameter(1, v); fg.SetParameter(2, ve);
870 v = fg.GetParameter(1); ve = fg.GetParameter(2);
872 TF1 fl("fl", "landau", az->GetXmin(), az->GetXmax());
873 fl.SetParameter(0, Float_t(ne)); fl.SetParameter(1, v); fl.SetParameter(2, ve);
875 v = fl.GetMaximumX(); ve = fl.GetParameter(2);
876 /* TF1 fgle("gle", "[0]*TMath::Landau(x, [1], [2], 1)*TMath::Exp(-[3]*x/[1])", az->GetXmin(), az->GetXmax());
877 fgle.SetParameter(0, fl.GetParameter(0));
878 fgle.SetParameter(1, fl.GetParameter(1));
879 fgle.SetParameter(2, fl.GetParameter(2));
880 fgle.SetParameter(3, 1.);fgle.SetParLimits(3, 0., 5.);
882 v = fgle.GetMaximumX(); ve = fgle.GetParameter(2);*/
884 if(v<fRange[0]) h2->SetBinContent(ix+1, iy+1, fRange[0]+0.1*dz);
885 else h2->SetBinContent(ix+1, iy+1, v);
886 h2->SetBinError(ix+1, iy+1, ve);
891 if(n==nx*ny){ // clean empty projections
892 AliDebug(1, Form("Empty projection in %s", GetName()));
898 //________________________________________________________
899 void AliTRDrecoTask::AliTRDrecoProjection::SetRebinStrategy(Int_t n, Int_t rebx[], Int_t reby[])
901 // define rebinning strategy for this projection
903 fRebin[0] = new Int_t[n]; memcpy(fRebin[0], rebx, n*sizeof(Int_t));
904 fRebin[1] = new Int_t[n]; memcpy(fRebin[1], reby, n*sizeof(Int_t));
907 //________________________________________________________
908 void AliTRDrecoTask::SetTriggerList(const Char_t *tl)
910 // Store list of triggers to be monitored
912 if(fTriggerList){ fTriggerList->Delete(); delete fTriggerList;}
913 TObjArray *atl = stl.Tokenize(" ");
914 fTriggerList = (TObjArray*)atl->Clone("");
915 atl->Delete(); delete atl;
916 AliInfo("Running only for triggers::");
917 fTriggerList->Print();