1 #if !defined(__CINT__) || defined(__MAKECINT__)
4 #include "AliTRDtracker.h"
5 #include "AliTRDclusterMI.h"
8 #include "AliTRDgeometry.h"
9 #include "AliTRDgeometryDetail.h"
10 #include "AliTRDparameter.h"
11 #include "AliTRDclusterCorrection.h"
14 #include "TStopwatch.h"
18 #include "AliRunLoader.h"
21 #include "AliTrackReference.h"
23 #include "AliTRDclusterErrors.h"
26 AliTRDclusterCorrection * gCorrection;
28 void ReadCorrection(){
29 TFile f("TRDcorrection.root");
30 gCorrection= (AliTRDclusterCorrection *)f.Get("TRDcorrection");
32 printf("Correction not found");
37 class AliTRDExactPoint: public TObject {
40 Float_t fTX; //x in rotated coordinate in the center of time bin
43 Float_t fTAY; //angle y
44 Float_t fTAZ; //angle z
49 void SetReference(AliTrackReference *ref);
54 Int_t fDetector; // detector (chamber)
55 Int_t fLocalTimeBin; // local time bin
56 Int_t fPlane; // plane (layer)
57 Int_t fSector; // segment
63 ClassDef(AliTRDExactPoint,1)
66 class AliTRDCI: public TObject {
69 virtual ~AliTRDCI(){;}
89 class AliTRDClusterErrAnal: public TObject{
91 AliTRDClusterErrAnal(Char_t *chloader = "galice.root");
92 void SetIO(Int_t event);
93 Int_t Analyze(Int_t trackmax);
95 void MakeExactPoints(Int_t trackmax);
96 void SortReferences();
97 AliTrackReference * FindNearestReference(Int_t lab, Float_t pos[3], Float_t dmax=10.);
99 AliRunLoader * fRunLoader;
100 AliLoader * fTRDLoader;
101 AliTRDparameter *fParam;
102 AliTRDgeometry *fGeometry;
104 TTree * fClusterTree;
105 TTree * fReferenceTree;
110 AliTRDtracker *fTracker;
112 TObjArray fClusters[12][100][18]; //first plane, second time bin
113 TObjArray fExactPoints;
114 TObjArray *fReferences;
116 ClassDef(AliTRDClusterErrAnal,1)
120 class AliTRDClusterErrDraw: public TObject{
123 AliTRDclusterCorrection* MakeCorrection(TTree * tree, Float_t offset);
124 static TH1F * ResDyVsAmp(TTree* tree, const char* selection, Float_t t0, Float_t ampmin=10, Float_t ampmax=300);
125 static TH1F * ResDyVsRelPos(TTree* tree, const char* selection, Float_t t0, Float_t min=-0.5, Float_t max=0.5);
126 static TH1F * ResDyVsAngleY(TTree* tree, const char* selection, Float_t t0, Float_t min=-1., Float_t max=1.);
127 static void AliLabelAxes(TH1* histo, const char* xAxisTitle, const char* yAxisTitle);
128 static TH1F* CreateEffHisto(TH1F* hGen, TH1F* hRec);
129 static TH1F* CreateResHisto(TH2F* hRes2, Bool_t draw = kTRUE, Bool_t drawBinFits = kTRUE,
130 Bool_t overflowBinFits = kFALSE);
131 ClassDef(AliTRDClusterErrDraw,1)
137 AliTRDExactPoint::AliTRDExactPoint()
139 fTX=fTY=fTZ=fTAZ=fTAY=fGx=fGy=fGz=fTRefAngleY=0;
140 fRefPos[0]=fRefPos[1]=fRefPos[2]=fRefMom[0]=fRefMom[1]=fRefMom[2]=0;
141 fDetector=fLocalTimeBin=fPlane=fSector=fPlaneMI=0;
145 void AliTRDExactPoint::SetReference(AliTrackReference *ref){
146 fRefPos[0] = ref->X();
147 fRefPos[1] = ref->Y();
148 fRefPos[2] = ref->Z();
150 fRefMom[0] = ref->Px();
151 fRefMom[1] = ref->Py();
152 fRefMom[2] = ref->Pz();
156 void AliTRDCI::Update()
161 fCharge = fP.GetPDG()->Charge();
162 fIsPrim = (fP.GetMother(0)>0)? kFALSE :kTRUE;
163 fCorrection = gCorrection->GetCorrection(fEp.fPlane,fCl.fTimeBin,fEp.fTAY);
171 .L AliTRDclusterErrors.C+
172 gCorrection = AliTRDclusterCorrection::GetCorrection();
173 AliTRDClusterErrAnal ana;
174 ana.Analyze(10000000)
179 .L AliTRDclusterErrors.C+
180 TFile f("trdclusteranal.root");
181 TTree* tree = (TTree*)f.Get("trdcl");
182 AliComparisonDraw comp;
186 tree->SetAlias("shapef","(1.-(0.8+0.06*(6-fEp.fPlane))*(fCl.fSigmaY2/(0.17+0.027*abs(fEp.fTAY))))");
187 tree->SetAlias("shapes","0.08+0.3/sqrt(fCl.fQ)");
188 tree->SetAlias("sfactor","shapef/shapes");
190 tree->SetAlias("shapen","(fCl.fNPads-2.7-0.9*abs(fEp.fTAY))");
192 tree->SetAlias("gshape","sfactor>-2&&fCl.fNPads<6&&shapen<1");
195 tree->SetAlias("dy" , "fEp.fTY-fCl.fY-fDYtilt");
196 tree->SetAlias("angle","abs(fEp.fTAY)");
197 TCut cbase("cbase","(abs(fP.fPdgCode)!=11||fPt>0.2)&&fPt>0.1&&angle<2");
199 tree->SetAlias("erry0","(0.028+0.07*angle)");
200 tree->SetAlias("erry1","erry0*(0.9+15./fCl.fQ)");
201 tree->SetAlias("erry2","erry1*(0.8+0.5*max(-sfactor,0))");
206 TH1F his("resy","resy",100,-0.2,0.2);
207 comp->fTree->Draw("dy:0.028*fEp.fTAY","fStatus==0 && abs(dy)<1.0&&fNTracks<2&&angle<2&&gshape","")
208 comp->DrawXY("sqrt(fCl.fQ)","dy","fStatus==0"+cbase,"gshape",10,0,20,-0.7,0.7);
210 comp->DrawXY("angle","dy/erry1","fStatus==0"+cbase,"gshape",10,0,2,-5.7,5.7);
211 comp->DrawXY("sqrt(cl->fQ)","dy/err1","fStatus==0"+cbase,"gshape",10,2,20,-5.7,5.7);
215 AliTRDClusterErrDraw::ResDyVsAmp(tree,"abs(dy)<0.4&&abs(fEp.fTAY)<0.2&&fNTracks<2&&fPt>0.1"+cbase,-0.03);
216 AliTRDClusterErrDraw::ResDyVsRelPos(tree,"abs(dy)<0.4&&abs(fEp.fTAY)<0.2&&fNTracks<2&&fPt>0.2"+cbase,-0.03);
217 AliTRDClusterErrDraw::ResDyVsAngleY(tree,"abs(fEp.fTY-fCl.fY+fDYtilt)<0.4",0.);
219 AliTRDclusterCorrection * cor = AliTRDClusterErrDraw::MakeCorrection(tree,0.134);
220 tree->Draw("sqrt(fCl.fRmsY)","fStatus==0&&abs(fEp.fTY-fCl.fY+fDYtilt)<0.4&&abs(fEp.fTAY)<0.2&&fNTracks<2&&fPt>0.2&&fCl.fNPads==0");
222 tree->Draw("fEp.fTY-fCl.fY+fDYtilt:fCl.fTimeBin","fStatus==0&&abs(fEp.fTY-fCl.fY+fDYtilt)<0.5&&abs(fEp.fTAY)<0.3&&fEp.fTAY>0.13","prof")
229 ClassImp(AliTRDExactPoint)
230 ClassImp(AliTRDClusterErrAnal)
231 ClassImp(AliTRDClusterErrDraw)
235 AliTRDClusterErrAnal::AliTRDClusterErrAnal(Char_t *chloader )
240 delete gAlice->GetRunLoader();
244 fRunLoader = AliRunLoader::Open(chloader);
245 if (fRunLoader == 0x0){
246 cerr<<"Can not open session"<<endl;
249 fTRDLoader = fRunLoader->GetLoader("TRDLoader");
250 if (fTRDLoader == 0x0){
251 cerr<<"Can not get TRD Loader"<<endl;
254 if (fRunLoader->LoadgAlice()){
255 cerr<<"Error occured while l"<<endl;
258 fRunLoader->CdGAFile();
259 fTracker = new AliTRDtracker(gFile);
260 fParam = (AliTRDparameter*) gFile->Get("TRDparameter");
261 fGeometry = new AliTRDgeometryDetail();
262 fTRD = (AliTRDv1*) gAlice->GetDetector("TRD");
264 AliTRDCI * clinfo = new AliTRDCI();
265 fFileA = new TFile("trdclusteranal.root","recreate");
267 fTreeA = new TTree("trdcl","trdcl");
268 fTreeA->Branch("trdcl","AliTRDCI",&clinfo);
272 void AliTRDClusterErrAnal::SetIO(Int_t event)
275 //set input output for given event
276 fRunLoader->SetEventNumber(event);
277 fRunLoader->LoadHeader();
278 fRunLoader->LoadKinematics();
279 fRunLoader->LoadTrackRefs();
280 fTRDLoader->LoadHits();
281 fTRDLoader->LoadRecPoints("read");
283 fStack = fRunLoader->Stack();
284 fHitTree = fTRDLoader->TreeH();
285 fClusterTree = fTRDLoader->TreeR();
286 fReferenceTree = fRunLoader->TreeTR();
287 fTracker->LoadClusters(fClusterTree);
291 void AliTRDClusterErrAnal::LoadClusters()
296 TObjArray *ClusterArray = new TObjArray(400);
297 TObjArray carray(2000);
298 TBranch *branch=fClusterTree->GetBranch("TRDcluster");
300 Error("ReadClusters","Can't get the branch !");
306 branch->SetAddress(&ClusterArray);
307 Int_t nentries = (Int_t)fClusterTree->GetEntries();
308 for (Int_t i=0;i<nentries;i++){
309 fClusterTree->GetEvent(i);
310 Int_t nCluster = ClusterArray->GetEntriesFast();
311 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
312 AliTRDcluster* c = (AliTRDcluster*)ClusterArray->UncheckedAt(iCluster);
314 ClusterArray->RemoveAt(iCluster);
315 if (c->GetQ()>5) over5++;
316 if (c->GetQ()>10) over10++;
319 Int_t nClusters = carray.GetEntriesFast();
320 printf("Total number of clusters %d\t%d\t%d\n", nClusters,over5,over10);
326 for (Int_t i=0;i<nClusters;i++){
327 AliTRDcluster *cl = (AliTRDcluster *) carray.UncheckedAt(i);
328 Int_t plane = fGeometry->GetPlane(cl->GetDetector());
329 if (plane>=12) continue;
330 Int_t time = cl->GetLocalTimeBin();
331 if (time>=100) continue;
332 Int_t sector = fGeometry->GetSector(cl->GetDetector());
334 printf("problem1\n");
337 fClusters[plane][time][sector].AddLast(cl);
342 void AliTRDClusterErrAnal::SortReferences()
347 printf("Sorting references\n");
348 fReferences = new TObjArray;
349 Int_t ntracks = fStack->GetNtrack();
350 fReferences->Expand(ntracks);
351 Int_t nentries = (Int_t)fReferenceTree->GetEntries();
352 TClonesArray * arr = new TClonesArray("AliTrackReference");
353 TBranch * br = fReferenceTree->GetBranch("TRD");
354 br->SetAddress(&arr);
356 TClonesArray *labarr=0;
359 for (Int_t iprim=0;iprim<nentries;iprim++){
360 if (br->GetEntry(iprim)){
361 for (Int_t iref=0;iref<arr->GetEntriesFast();iref++){
362 AliTrackReference *ref =(AliTrackReference*)arr->At(iref);
364 Int_t lab = ref->GetTrack();
365 if ( (lab<0) || (lab>ntracks)) continue;
367 if (fReferences->At(lab)==0) {
368 labarr = new TClonesArray("AliTrackReference");
369 fReferences->AddAt(labarr,lab);
372 TClonesArray &larr = *labarr;
373 new(larr[larr.GetEntriesFast()]) AliTrackReference(*ref);
378 printf("Total number of references = \t%d\n", nreferences);
379 printf("Total number of tracks with references = \t%d\n", nreftracks);
380 printf("End - Sorting references\n");
384 AliTrackReference * AliTRDClusterErrAnal::FindNearestReference(Int_t lab, Float_t pos[3], Float_t dmax)
389 if (fReferences->At(lab)==0) return 0;
390 AliTrackReference *nearest=0;
391 TClonesArray * arr = (TClonesArray *)fReferences->At(lab);
392 for (Int_t iref =0;iref<arr->GetEntriesFast();iref++){
393 AliTrackReference * ref = ( AliTrackReference *)arr->UncheckedAt(iref);
395 Float_t delta = (pos[0]-ref->X())*(pos[0]-ref->X());
396 delta += (pos[1]-ref->Y())*(pos[1]-ref->Y());
397 delta += (pos[2]-ref->Z())*(pos[2]-ref->Z());
398 delta = TMath::Sqrt(delta);
407 void AliTRDClusterErrAnal::MakeExactPoints(Int_t trackmax)
410 //make exact points:-)
414 fExactPoints.Delete();
415 fExactPoints.Expand(fStack->GetNtrack());
426 Int_t entries = Int_t(fHitTree->GetEntries());
427 printf("Number of primary entries\t%d\n",entries);
428 entries = TMath::Min(trackmax,entries);
429 Int_t nallpoints = 0;
432 Int_t pointspertrack =0;
434 for (Int_t entry=0;entry<entries; entry++){
436 fHitTree->GetEvent(entry);
437 Int_t lastlabel = -1;
438 Int_t lastdetector = -1;
439 Int_t lasttimebin = -1;
442 for(AliTRDhit *hit = (AliTRDhit *) fTRD->FirstHit(-1); hit;
443 hit = (AliTRDhit *) fTRD->NextHit()) {
445 Int_t label = hit->Track();
446 TParticle * particle = fStack->Particle(label);
447 if (!particle) continue;
448 if (particle->Pt()<0.05) continue;
449 Int_t detector = hit->GetDetector();
450 Int_t plane = fGeometry->GetPlane(detector);
453 if (hit->GetCharge()==0) continue;
454 Float_t pos[3] = {hit->X(),hit->Y(),hit->Z()};
456 fGeometry->Global2Detector(pos,indexes,fParam);
459 fGeometry->Rotate(detector,pos,rot);
464 Float_t time0 = fParam->GetTime0(plane);
465 Int_t timebin = Int_t(TMath::Nint(((time0 - rot[0])/fParam->GetTimeBinSize())+ fParam->GetTimeBefore())+0.1);
466 if (timebin<0) continue;
469 if (label!=lastlabel || detector != lastdetector || lasttimebin !=timebin){
471 if (label!=lastlabel){
472 fExactPoints.AddAt(new TClonesArray("AliTRDExactPoint",0),label);
473 //printf("new particle\t%d\n",label);
475 // printf("particle\t%d- hits\t%d\n",lastlabel, pointspertrack);
479 if ( (fSum>1) && lasttimebin>=0 && lasttimebin<fParam->GetTimeMax() ){
480 //if we have enough info for given layer time bin - store it
481 AliTrackReference * ref = FindNearestReference(lastlabel,lastpos,4.);
486 Float_t mom[3] = {ref->Px(),ref->Py(),ref->Pz()};
487 Float_t refpos[3] = {ref->X(),ref->Y(),ref->Z()};
488 fGeometry->Rotate(detector,mom,rotmom);
489 fGeometry->Rotate(detector,refpos,rotpos);
490 refangle = rotmom[1]/rotmom[0];
494 Double_t ay,by,az,bz;
495 Double_t det = fSum*fSumX2-fSumX*fSumX;
496 if (TMath::Abs(det)> 0.000000000000001) {
497 by = (fSum*fSumXY-fSumX*fSumY)/det;
498 ay = (fSumX2*fSumY-fSumX*fSumXY)/det;
504 if (TMath::Abs(det)> 0.000000000000001) {
505 bz = (fSum*fSumXZ-fSumX*fSumZ)/det;
506 az = (fSumX2*fSumZ-fSumX*fSumXZ)/det;
512 Float_t lastplane = fGeometry->GetPlane(lastdetector);
513 Float_t time0 = fParam->GetTime0(lastplane);
514 Float_t xcenter0 = time0 - (lasttimebin - fParam->GetTimeBefore()+0.5)*fParam->GetTimeBinSize();
515 Float_t xcenter = fTracker->GetX(0,lastplane,lasttimebin);
516 if (TMath::Abs(xcenter-xcenter0)>0.001){
520 Float_t ty = ay + by * xcenter;
521 Float_t tz = az + bz * xcenter;
524 TClonesArray * arr = (TClonesArray *) fExactPoints.At(label);
525 TClonesArray & larr= *arr;
526 Int_t arrent = arr->GetEntriesFast();
527 AliTRDExactPoint * point = new (larr[arrent]) AliTRDExactPoint;
531 point->SetReference(ref);
532 point->fTRefAngleY = rotmom[1]/rotmom[0];
534 point->fTX = xcenter;
540 point->fGx = lastpos[0];
541 point->fGy = lastpos[1];
542 point->fGz = lastpos[2];
545 point->fDetector = lastdetector;
546 point->fLocalTimeBin = lasttimebin;
547 point->fPlane = fGeometry->GetPlane(lastdetector);
548 point->fSector = fGeometry->GetSector(lastdetector);
549 point->fPlaneMI = indexes[0];
551 point->fTPrim = fSum;
555 lastdetector = detector;
557 lasttimebin = timebin;
558 fSum=fSumQ=fSumX=fSumX2=fSumXY=fSumXZ=fSumY=fSumZ=0.;
561 lastpos[0] = hit->X();
562 lastpos[1] = hit->Y();
563 lastpos[2] = hit->Z();
565 fSumQ +=hit->GetCharge();
567 fSumX2 +=rot[0]*rot[0];
568 fSumXY +=rot[0]*rot[1];
569 fSumXZ +=rot[0]*rot[2];
576 printf("Found %d exact points\n",nallpoints);
584 Int_t AliTRDClusterErrAnal::Analyze(Int_t trackmax) {
587 // comparison works with both cluster types MI and old also
588 //dummy cluster to be fill if not cluster info
589 AliTRDclusterMI clmi;
590 TClass * classmi = clmi.IsA();
593 AliTRDCI * clinfo = new AliTRDCI();
594 TBranch * clbr = fTreeA->GetBranch("trdcl");
595 clbr->SetAddress(&clinfo);
599 MakeExactPoints(trackmax);
602 trackmax = fStack->GetNtrack();
604 // Get the number of entries in the hit tree
605 // (Number of primary particles creating a hit somewhere)
606 Int_t nTrack = (Int_t)fExactPoints.GetEntries();
607 printf("Found %d charged in TRD in first %d particles", nTrack, trackmax);
610 for (Int_t itrack = 0; itrack<trackmax; itrack++){
611 TClonesArray *arrpoints = (TClonesArray*)fExactPoints.At(itrack);
613 if (!arrpoints) continue;
614 //printf("new particle\t%d\n",itrack);
615 TParticle * particle = fStack->Particle(itrack);
616 if (!particle) continue;
617 //printf("founded in kine tree \t%d\n",itrack);
618 Int_t npoints = arrpoints->GetEntriesFast();
619 if (npoints<10) continue;
620 //printf("have enough points \t%d\t%d\n",itrack,npoints);
622 for (Int_t ipoint=0;ipoint<npoints;ipoint++){
623 AliTRDExactPoint * point = (AliTRDExactPoint*)arrpoints->UncheckedAt(ipoint);
624 if (!point) continue;
626 Int_t sec = fGeometry->GetSector(point->fDetector);
628 printf("problem2\n");
630 TObjArray & cllocal = fClusters[point->fPlane][point->fLocalTimeBin][sec];
631 Int_t nclusters = cllocal.GetEntriesFast();
632 Float_t maxdist = 10;
633 AliTRDcluster * nearestcluster =0;
634 clinfo->fNClusters=0;
635 //find nearest cluster to hit with given label
636 for (Int_t icluster =0; icluster<nclusters; icluster++){
637 AliTRDcluster * cluster = (AliTRDcluster*)cllocal.UncheckedAt(icluster);
638 if (!cluster) continue;
639 if ( (cluster->GetLabel(0)!= itrack) && (cluster->GetLabel(1)!= itrack)&&(cluster->GetLabel(2)!= itrack))
641 Float_t dist = TMath::Abs(cluster->GetY()-point->fTY);
642 if (TMath::Abs(cluster->GetZ()-point->fTZ)>5.5 || dist>3.) continue;
643 clinfo->fNClusters++;
646 nearestcluster = cluster;
650 clinfo->fEp = *point;
651 clinfo->fP = *particle;
652 if (!nearestcluster) {
658 if (nearestcluster->IsA()==classmi){
659 clinfo->fCl =*((AliTRDclusterMI*)nearestcluster);
662 clinfo->fCl = *nearestcluster;
665 Float_t dz = clinfo->fCl.GetZ()-point->fTZ;
666 Double_t h01 = sin(TMath::Pi() / 180.0 * fParam->GetTiltingAngle());
667 clinfo->fTDistZ = dz;
668 clinfo->fDYtilt = h01*dz*((point->fPlane%2)*2.-1.);
671 if (nearestcluster->GetLabel(1)>=0) clinfo->fNTracks++;
672 if (nearestcluster->GetLabel(2)>=0) clinfo->fNTracks++;
687 AliTRDclusterCorrection* AliTRDClusterErrDraw::MakeCorrection(TTree * tree, Float_t offset)
692 AliTRDclusterCorrection * cor = new AliTRDclusterCorrection;
693 cor->SetOffsetAngle(offset);
694 for (Int_t iplane=0;iplane<6;iplane++)
695 for (Int_t itime=0;itime<15;itime++)
696 for (Int_t iangle=0; iangle<20;iangle++){
697 Float_t angle = cor->GetAngle(iangle);
698 TH1F delta("delta","delta",30,-0.3,0.3);
699 char selection[100]="fStatus==0&&fNTracks<2";
700 char selectionall[1000];
701 sprintf(selectionall,"%s&&abs(fEp.fTAY-%f)<0.2&&fEp.fPlane==%d&&fCl.fTimeBin==%d&&fCl.fQ>20",
702 selection,angle,iplane,itime);
703 printf("\n%s",selectionall);
704 tree->Draw("fEp.fTY-fCl.fY+fDYtilt>>delta",selectionall);
706 printf("\nplane\t%d\ttime%d\tangle%f",iplane,itime,angle);
707 printf("\tentries%f\tmean\t%f\t%f",delta.GetEntries(),delta.GetMean(),delta.GetRMS());
708 cor->SetCorrection(iplane,itime,angle,delta.GetMean(),delta.GetRMS());
710 TFile * f = new TFile("TRDcorrection.root","new");
711 if (!f) f = new TFile("TRDcorrection.root","recreate");
713 cor->Write("TRDcorrection");
718 TH1F * AliTRDClusterErrDraw::ResDyVsAmp(TTree* tree, const char* selection, Float_t t0, Float_t ampmin, Float_t ampmax)
722 TH2F hisdy("resy","resy",10,ampmin,ampmax,30,-0.3,0.3);
723 char expression[1000];
724 sprintf(expression,"fEp.fTY-fCl.fY+fDYtilt+%.4f*fEp.fTAY:fCl.fQ>>resy",t0);
725 char selectionall[1000];
726 sprintf(selectionall,"fStatus==0&&%s",selection);
727 printf("%s\n",expression);
728 printf("%s\n",selectionall);
729 tree->Draw(expression,selectionall);
730 return CreateResHisto(&hisdy);
734 TH1F * AliTRDClusterErrDraw::ResDyVsRelPos(TTree* tree, const char* selection, Float_t t0, Float_t min, Float_t max)
740 TH2F hisdy("resy","resy",10,min,max,30,-0.3,0.3);
741 char expression[1000];
742 sprintf(expression,"fEp.fTY-fCl.fY+fDYtilt+%.4f*fEp.fTAY:fCl.fRelPos>>resy",t0);
743 char selectionall[1000];
744 sprintf(selectionall,"fStatus==0&&%s",selection);
745 printf("%s\n",expression);
746 printf("%s\n",selectionall);
747 tree->Draw(expression,selectionall);
748 return CreateResHisto(&hisdy);
752 TH1F * AliTRDClusterErrDraw::ResDyVsAngleY(TTree* tree, const char* selection, Float_t t0, Float_t min, Float_t max)
756 TH2F hisdy("resy","resy",10,min,max,30,-0.3,0.3);
758 char expression[1000];
759 sprintf(expression,"fEp.fTY-fCl.fY+fDYtilt+%f*fEp.fTAY:fEp.fTAY>>resy",t0);
760 char selectionall[1000];
761 sprintf(selectionall,"fStatus==0&&%s",selection);
763 tree->Draw(expression,selectionall);
764 return CreateResHisto(&hisdy);
767 void AliTRDClusterErrDraw::AliLabelAxes(TH1* histo, const char* xAxisTitle, const char* yAxisTitle)
769 histo->GetXaxis()->SetTitle(xAxisTitle);
770 histo->GetYaxis()->SetTitle(yAxisTitle);
774 TH1F* AliTRDClusterErrDraw::CreateEffHisto(TH1F* hGen, TH1F* hRec)
776 Int_t nBins = hGen->GetNbinsX();
777 TH1F* hEff = (TH1F*) hGen->Clone("hEff");
779 hEff->SetStats(kFALSE);
780 hEff->SetMinimum(0.);
781 hEff->SetMaximum(110.);
783 for (Int_t iBin = 0; iBin <= nBins; iBin++) {
784 Double_t nGen = hGen->GetBinContent(iBin);
785 Double_t nRec = hRec->GetBinContent(iBin);
787 Double_t eff = nRec/nGen;
788 hEff->SetBinContent(iBin, 100. * eff);
789 Double_t error = sqrt((eff*(1.-eff)+0.01) / nGen);
790 // if (error == 0) error = sqrt(0.1/nGen);
792 if (error == 0) error = 0.0001;
793 hEff->SetBinError(iBin, 100. * error);
795 hEff->SetBinContent(iBin, 100. * 0.5);
796 hEff->SetBinError(iBin, 100. * 0.5);
805 TH1F* AliTRDClusterErrDraw::CreateResHisto(TH2F* hRes2, Bool_t draw, Bool_t drawBinFits,
806 Bool_t overflowBinFits)
808 TVirtualPad* currentPad = gPad;
809 TAxis* axis = hRes2->GetXaxis();
810 Int_t nBins = axis->GetNbins();
812 if (axis->GetXbins()->GetSize()){
813 hRes = new TH1F("hRes", "", nBins, axis->GetXbins()->GetArray());
814 hMean = new TH1F("hMean", "", nBins, axis->GetXbins()->GetArray());
817 hRes = new TH1F("hRes", "", nBins, axis->GetXmin(), axis->GetXmax());
818 hMean = new TH1F("hMean", "", nBins, axis->GetXmin(), axis->GetXmax());
821 hRes->SetStats(false);
822 hRes->SetOption("E");
823 hRes->SetMinimum(0.);
825 hMean->SetStats(false);
826 hMean->SetOption("E");
828 // create the fit function
829 //TKFitGaus* fitFunc = new TKFitGaus("resFunc");
830 TF1 * fitFunc = new TF1("G","[3]+[0]*exp(-(x-[1])*(x-[1])/(2.*[2]*[2]))",-3,3);
832 fitFunc->SetLineWidth(2);
833 fitFunc->SetFillStyle(0);
834 // create canvas for fits
835 TCanvas* canBinFits = NULL;
836 Int_t nPads = (overflowBinFits) ? nBins+2 : nBins;
837 Int_t nx = Int_t(sqrt(nPads-1.));// + 1;
838 Int_t ny = (nPads-1) / nx + 1;
840 canBinFits = (TCanvas*)gROOT->FindObject("canBinFits");
841 if (canBinFits) delete canBinFits;
842 canBinFits = new TCanvas("canBinFits", "fits of bins", 200, 100, 500, 700);
843 canBinFits->Divide(nx, ny);
846 // loop over x bins and fit projection
847 Int_t dBin = ((overflowBinFits) ? 1 : 0);
848 for (Int_t bin = 1-dBin; bin <= nBins+dBin; bin++) {
849 if (drawBinFits) canBinFits->cd(bin + dBin);
850 TH1D* hBin = hRes2->ProjectionY("hBin", bin, bin);
852 if (hBin->GetEntries() > 10) {
853 fitFunc->SetParameters(hBin->GetMaximum(),hBin->GetMean(),hBin->GetRMS(),0.02*hBin->GetMaximum());
854 hBin->Fit(fitFunc,"s");
855 Double_t sigma = TMath::Abs(fitFunc->GetParameter(2));
858 hRes->SetBinContent(bin, TMath::Abs(fitFunc->GetParameter(2)));
859 hMean->SetBinContent(bin, fitFunc->GetParameter(1));
862 hRes->SetBinContent(bin, 0.);
863 hMean->SetBinContent(bin,0);
865 hRes->SetBinError(bin, fitFunc->GetParError(2));
866 hMean->SetBinError(bin, fitFunc->GetParError(1));
872 hRes->SetBinContent(bin, 0.);
873 hRes->SetBinError(bin, 0.);
874 hMean->SetBinContent(bin, 0.);
875 hMean->SetBinError(bin, 0.);
882 sprintf(name, "%s < %.4g", axis->GetTitle(), axis->GetBinUpEdge(bin));
883 } else if (bin == nBins+1) {
884 sprintf(name, "%.4g < %s", axis->GetBinLowEdge(bin), axis->GetTitle());
886 sprintf(name, "%.4g < %s < %.4g", axis->GetBinLowEdge(bin),
887 axis->GetTitle(), axis->GetBinUpEdge(bin));
889 canBinFits->cd(bin + dBin);
890 hBin->SetTitle(name);
891 hBin->SetStats(kTRUE);
893 canBinFits->Update();
894 canBinFits->Modified();
895 canBinFits->Update();
904 currentPad->Divide(1,2);