1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////
20 Origin: marian.ivanov@cern.ch
22 Macro to generate comples MC information - used for Comparison later on
25 .L $ALICE_ROOT/STEER/AliGenInfo.C+
26 AliGenInfoMaker *t = new AliGenInfoMaker("galice.root","genTracks.root",1,0)
31 #if !defined(__CINT__) || defined(__MAKECINT__)
41 #include "TBenchmark.h"
42 #include "TStopwatch.h"
43 #include "TParticle.h"
53 #include "TGeometry.h"
54 #include "TPolyLine3D.h"
59 #include "AliSimDigits.h"
60 #include "AliTPCParam.h"
62 #include "AliTPCLoader.h"
63 #include "AliDetector.h"
64 #include "AliTrackReference.h"
65 #include "AliTPCParamSR.h"
66 #include "AliTracker.h"
69 #include "AliPoints.h"
72 #include "AliGenInfo.h"
76 AliTPCParam * GetTPCParam(){
77 AliTPCParamSR * par = new AliTPCParamSR;
83 //_____________________________________________________________________________
84 Float_t TPCBetheBloch(Float_t bg)
87 // Bethe-Bloch energy loss formula
89 const Double_t kp1=0.76176e-1;
90 const Double_t kp2=10.632;
91 const Double_t kp3=0.13279e-4;
92 const Double_t kp4=1.8631;
93 const Double_t kp5=1.9479;
95 Double_t dbg = (Double_t) bg;
97 Double_t beta = dbg/TMath::Sqrt(1.+dbg*dbg);
99 Double_t aa = TMath::Power(beta,kp4);
100 Double_t bb = TMath::Power(1./dbg,kp5);
102 bb=TMath::Log(kp3+bb);
104 return ((Float_t)((kp2-aa-bb)*kp1/aa));
107 AliPointsMI::AliPointsMI(){
118 AliPointsMI::AliPointsMI(Int_t n, Float_t *x,Float_t *y, Float_t *z){
122 fCapacity = 1000+2*n;
126 memcpy(fX,x,n*sizeof(Float_t));
127 memcpy(fY,y,n*sizeof(Float_t));
128 memcpy(fZ,z,n*sizeof(Float_t));
133 void AliPointsMI::Reset()
138 void AliPointsMI::Reset(AliDetector * det, Int_t particle){
140 // write points from detector points
144 TObjArray *array = det->Points();
146 for (Int_t i=0;i<array->GetEntriesFast();i++){
147 AliPoints * points = (AliPoints*) array->At(i);
148 if (!points) continue;
149 if (points->GetIndex()!=particle) continue;
150 Int_t npoints = points->GetN();
151 if (npoints<2) continue;
152 Int_t delta = npoints/100;
153 if (delta<1) delta=1;
154 if (delta>10) delta=10;
155 Int_t mypoints = npoints/delta;
159 fCapacity = 1000+2*fN;
163 fX = new Float_t[fCapacity];
164 fY = new Float_t[fCapacity];
165 fZ = new Float_t[fCapacity];
167 Float_t *xyz = points->GetP();
168 for (Int_t ipoint=0;ipoint<mypoints;ipoint++){
169 Int_t index = 3*ipoint*delta;
173 if (index+2<npoints*3){
174 fX[ipoint] = xyz[index];
175 fY[ipoint] = xyz[index+1];
176 fZ[ipoint] = xyz[index+2];
184 AliPointsMI::~AliPointsMI(){
197 ////////////////////////////////////////////////////////////////////////
198 AliMCInfo::AliMCInfo()
200 fTPCReferences = new TClonesArray("AliTrackReference",10);
201 fITSReferences = new TClonesArray("AliTrackReference",10);
202 fTRDReferences = new TClonesArray("AliTrackReference",10);
203 fTOFReferences = new TClonesArray("AliTrackReference",10);
204 fTRdecay.SetTrack(-1);
207 AliMCInfo::~AliMCInfo()
209 if (fTPCReferences) {
210 delete fTPCReferences;
213 delete fITSReferences;
216 delete fTRDReferences;
219 delete fTOFReferences;
226 void AliMCInfo::Update()
231 if (!fTPCReferences) {
237 fNTPCRef = fTPCReferences->GetEntriesFast();
238 fNITSRef = fITSReferences->GetEntriesFast();
239 fNTRDRef = fTRDReferences->GetEntriesFast();
240 fNTOFRef = fTOFReferences->GetEntriesFast();
242 for (Int_t iref =0;iref<fTPCReferences->GetEntriesFast();iref++){
243 AliTrackReference * ref = (AliTrackReference *) fTPCReferences->At(iref);
244 //Float_t r = (ref->X()*ref->X()+ref->Y()*ref->Y());
245 Float_t newdirection = ref->X()*ref->Px()+ref->Y()*ref->Py(); //inside or outside
246 if (iref==0) direction = newdirection;
247 if ( newdirection*direction<0){
249 direction = newdirection;
257 if (fTRdecay.GetTrack()>0){
258 fDecayCoord[0] = fTRdecay.X();
259 fDecayCoord[1] = fTRdecay.Y();
260 fDecayCoord[2] = fTRdecay.Z();
261 if ( (fTRdecay.R()<250)&&(fTRdecay.R()>85) && (TMath::Abs(fTRdecay.Z())<250) ){
272 //digits information update
273 fRowsWithDigits = fTPCRow.RowsOn();
274 fRowsWithDigitsInn = fTPCRow.RowsOn(63); // 63 = number of inner rows
275 fRowsTrackLength = fTPCRow.Last() - fTPCRow.First();
278 // calculate primary ionization per cm
279 if (fParticle.GetPDG()){
280 fMass = fParticle.GetMass();
281 fCharge = fParticle.GetPDG()->Charge();
282 if (fTPCReferences->GetEntriesFast()>0){
283 fTrackRef = *((AliTrackReference*)fTPCReferences->At(0));
286 Float_t p = TMath::Sqrt(fTrackRef.Px()*fTrackRef.Px()+
287 fTrackRef.Py()*fTrackRef.Py()+
288 fTrackRef.Pz()*fTrackRef.Pz());
290 Float_t betagama = p /fMass;
291 fPrim = TPCBetheBloch(betagama);
300 /////////////////////////////////////////////////////////////////////////////////
302 void AliGenV0Info::Update()
304 fMCPd[0] = fMCd.fParticle.Px();
305 fMCPd[1] = fMCd.fParticle.Py();
306 fMCPd[2] = fMCd.fParticle.Pz();
307 fMCPd[3] = fMCd.fParticle.P();
309 fMCX[0] = fMCd.fParticle.Vx();
310 fMCX[1] = fMCd.fParticle.Vy();
311 fMCX[2] = fMCd.fParticle.Vz();
312 fMCR = TMath::Sqrt( fMCX[0]*fMCX[0]+fMCX[1]*fMCX[1]);
314 fPdg[0] = fMCd.fParticle.GetPdgCode();
315 fPdg[1] = fMCm.fParticle.GetPdgCode();
317 fLab[0] = fMCd.fParticle.GetUniqueID();
318 fLab[1] = fMCm.fParticle.GetUniqueID();
323 void AliGenV0Info::Update(Float_t vertex[3])
325 fMCPd[0] = fMCd.fParticle.Px();
326 fMCPd[1] = fMCd.fParticle.Py();
327 fMCPd[2] = fMCd.fParticle.Pz();
328 fMCPd[3] = fMCd.fParticle.P();
330 fMCX[0] = fMCd.fParticle.Vx();
331 fMCX[1] = fMCd.fParticle.Vy();
332 fMCX[2] = fMCd.fParticle.Vz();
333 fMCR = TMath::Sqrt( fMCX[0]*fMCX[0]+fMCX[1]*fMCX[1]);
335 fPdg[0] = fMCd.fParticle.GetPdgCode();
336 fPdg[1] = fMCm.fParticle.GetPdgCode();
338 fLab[0] = fMCd.fParticle.GetUniqueID();
339 fLab[1] = fMCm.fParticle.GetUniqueID();
343 Double_t x1[3],p1[3];
344 TParticle & pdaughter = fMCd.fParticle;
345 x1[0] = pdaughter.Vx();
346 x1[1] = pdaughter.Vy();
347 x1[2] = pdaughter.Vz();
348 p1[0] = pdaughter.Px();
349 p1[1] = pdaughter.Py();
350 p1[2] = pdaughter.Pz();
351 Double_t sign = (pdaughter.GetPDG()->Charge()>0)? -1:1;
352 AliHelix dhelix1(x1,p1,sign);
355 Double_t x2[3],p2[3];
357 TParticle & pmother = fMCm.fParticle;
358 x2[0] = pmother.Vx();
359 x2[1] = pmother.Vy();
360 x2[2] = pmother.Vz();
361 p2[0] = pmother.Px();
362 p2[1] = pmother.Py();
363 p2[2] = pmother.Pz();
366 sign = (pmother.GetPDG()->Charge()>0) ? -1:1;
367 AliHelix mhelix(x2,p2,sign);
372 //find intersection linear
374 Double_t distance1, distance2;
375 Double_t phase[2][2],radius[2];
376 Int_t points = dhelix1.GetRPHIintersections(mhelix, phase, radius);
377 Double_t delta1=10000,delta2=10000;
379 dhelix1.LinearDCA(mhelix,phase[0][0],phase[0][1],radius[0],delta1);
380 dhelix1.LinearDCA(mhelix,phase[0][0],phase[0][1],radius[0],delta1);
381 dhelix1.LinearDCA(mhelix,phase[0][0],phase[0][1],radius[0],delta1);
388 dhelix1.LinearDCA(mhelix,phase[1][0],phase[1][1],radius[1],delta2);
389 dhelix1.LinearDCA(mhelix,phase[1][0],phase[1][1],radius[1],delta2);
390 dhelix1.LinearDCA(mhelix,phase[1][0],phase[1][1],radius[1],delta2);
392 distance1 = TMath::Min(delta1,delta2);
394 //find intersection parabolic
396 points = dhelix1.GetRPHIintersections(mhelix, phase, radius);
397 delta1=10000,delta2=10000;
400 dhelix1.ParabolicDCA(mhelix,phase[0][0],phase[0][1],radius[0],delta1);
403 dhelix1.ParabolicDCA(mhelix,phase[1][0],phase[1][1],radius[1],delta2);
406 distance2 = TMath::Min(delta1,delta2);
410 dhelix1.Evaluate(phase[0][0],fMCXr);
411 dhelix1.GetMomentum(phase[0][0],fMCPdr);
412 mhelix.GetMomentum(phase[0][1],fMCPm);
413 dhelix1.GetAngle(phase[0][0],mhelix,phase[0][1],fMCAngle);
414 fMCRr = TMath::Sqrt(radius[0]);
417 dhelix1.Evaluate(phase[1][0],fMCXr);
418 dhelix1.GetMomentum(phase[1][0],fMCPdr);
419 mhelix.GetMomentum(phase[1][1],fMCPm);
420 dhelix1.GetAngle(phase[1][0],mhelix,phase[1][1],fMCAngle);
421 fMCRr = TMath::Sqrt(radius[1]);
425 fMCDist1 = TMath::Sqrt(distance1);
426 fMCDist2 = TMath::Sqrt(distance2);
430 Float_t v[3] = {fMCXr[0]-vertex[0],fMCXr[1]-vertex[1],fMCXr[2]-vertex[2]};
431 //Float_t v[3] = {fMCXr[0],fMCXr[1],fMCXr[2]};
432 Float_t p[3] = {fMCPdr[0]+fMCPm[0], fMCPdr[1]+fMCPm[1],fMCPdr[2]+fMCPm[2]};
433 Float_t vnorm2 = v[0]*v[0]+v[1]*v[1];
434 Float_t vnorm3 = TMath::Sqrt(v[2]*v[2]+vnorm2);
435 vnorm2 = TMath::Sqrt(vnorm2);
436 Float_t pnorm2 = p[0]*p[0]+p[1]*p[1];
437 Float_t pnorm3 = TMath::Sqrt(p[2]*p[2]+pnorm2);
438 pnorm2 = TMath::Sqrt(pnorm2);
440 fPointAngleFi = (v[0]*p[0]+v[1]*p[1])/(vnorm2*pnorm2);
441 fPointAngleTh = (v[2]*p[2]+vnorm2*pnorm2)/(vnorm3*pnorm3);
442 fPointAngle = (v[0]*p[0]+v[1]*p[1]+v[2]*p[2])/(vnorm3*pnorm3);
443 Float_t mass1 = fMCd.fMass;
444 Float_t mass2 = fMCm.fMass;
447 Float_t e1 = TMath::Sqrt(mass1*mass1+
450 fMCPdr[2]*fMCPdr[2]);
451 Float_t e2 = TMath::Sqrt(mass2*mass2+
457 (fMCPm[0]+fMCPdr[0])*(fMCPm[0]+fMCPdr[0])+
458 (fMCPm[1]+fMCPdr[1])*(fMCPm[1]+fMCPdr[1])+
459 (fMCPm[2]+fMCPdr[2])*(fMCPm[2]+fMCPdr[2]);
461 // fInvMass = TMath::Sqrt((e1+e2)*(e1+e2)-fInvMass);
462 fInvMass = (e1+e2)*(e1+e2)-fInvMass;
463 if (fInvMass>0) fInvMass = TMath::Sqrt(fInvMass);
472 /////////////////////////////////////////////////////////////////////////////////
473 void AliGenKinkInfo::Update()
475 fMCPd[0] = fMCd.fParticle.Px();
476 fMCPd[1] = fMCd.fParticle.Py();
477 fMCPd[2] = fMCd.fParticle.Pz();
478 fMCPd[3] = fMCd.fParticle.P();
480 fMCX[0] = fMCd.fParticle.Vx();
481 fMCX[1] = fMCd.fParticle.Vy();
482 fMCX[2] = fMCd.fParticle.Vz();
483 fMCR = TMath::Sqrt( fMCX[0]*fMCX[0]+fMCX[1]*fMCX[1]);
485 fPdg[0] = fMCd.fParticle.GetPdgCode();
486 fPdg[1] = fMCm.fParticle.GetPdgCode();
488 fLab[0] = fMCd.fParticle.GetUniqueID();
489 fLab[1] = fMCm.fParticle.GetUniqueID();
493 Double_t x1[3],p1[3];
494 TParticle & pdaughter = fMCd.fParticle;
495 x1[0] = pdaughter.Vx();
496 x1[1] = pdaughter.Vy();
497 x1[2] = pdaughter.Vz();
498 p1[0] = pdaughter.Px();
499 p1[1] = pdaughter.Py();
500 p1[2] = pdaughter.Pz();
501 Double_t sign = (pdaughter.GetPDG()->Charge()>0)? -1:1;
502 AliHelix dhelix1(x1,p1,sign);
505 Double_t x2[3],p2[3];
507 TParticle & pmother = fMCm.fParticle;
508 x2[0] = pmother.Vx();
509 x2[1] = pmother.Vy();
510 x2[2] = pmother.Vz();
511 p2[0] = pmother.Px();
512 p2[1] = pmother.Py();
513 p2[2] = pmother.Pz();
515 AliTrackReference & pdecay = fMCm.fTRdecay;
523 sign = (pmother.GetPDG()->Charge()>0) ? -1:1;
524 AliHelix mhelix(x2,p2,sign);
529 //find intersection linear
531 Double_t distance1, distance2;
532 Double_t phase[2][2],radius[2];
533 Int_t points = dhelix1.GetRPHIintersections(mhelix, phase, radius);
534 Double_t delta1=10000,delta2=10000;
536 dhelix1.LinearDCA(mhelix,phase[0][0],phase[0][1],radius[0],delta1);
537 dhelix1.LinearDCA(mhelix,phase[0][0],phase[0][1],radius[0],delta1);
538 dhelix1.LinearDCA(mhelix,phase[0][0],phase[0][1],radius[0],delta1);
541 dhelix1.LinearDCA(mhelix,phase[1][0],phase[1][1],radius[1],delta2);
542 dhelix1.LinearDCA(mhelix,phase[1][0],phase[1][1],radius[1],delta2);
543 dhelix1.LinearDCA(mhelix,phase[1][0],phase[1][1],radius[1],delta2);
545 distance1 = TMath::Min(delta1,delta2);
547 //find intersection parabolic
549 points = dhelix1.GetRPHIintersections(mhelix, phase, radius);
550 delta1=10000,delta2=10000;
553 dhelix1.ParabolicDCA(mhelix,phase[0][0],phase[0][1],radius[0],delta1);
556 dhelix1.ParabolicDCA(mhelix,phase[1][0],phase[1][1],radius[1],delta2);
559 distance2 = TMath::Min(delta1,delta2);
563 dhelix1.Evaluate(phase[0][0],fMCXr);
564 dhelix1.GetMomentum(phase[0][0],fMCPdr);
565 mhelix.GetMomentum(phase[0][1],fMCPm);
566 dhelix1.GetAngle(phase[0][0],mhelix,phase[0][1],fMCAngle);
567 fMCRr = TMath::Sqrt(radius[0]);
570 dhelix1.Evaluate(phase[1][0],fMCXr);
571 dhelix1.GetMomentum(phase[1][0],fMCPdr);
572 mhelix.GetMomentum(phase[1][1],fMCPm);
573 dhelix1.GetAngle(phase[1][0],mhelix,phase[1][1],fMCAngle);
574 fMCRr = TMath::Sqrt(radius[1]);
578 fMCDist1 = TMath::Sqrt(distance1);
579 fMCDist2 = TMath::Sqrt(distance2);
584 Float_t AliGenKinkInfo::GetQt(){
587 Float_t momentumd = TMath::Sqrt(fMCPd[0]*fMCPd[0]+fMCPd[1]*fMCPd[1]+fMCPd[2]*fMCPd[2]);
588 return TMath::Sin(fMCAngle[2])*momentumd;
594 ////////////////////////////////////////////////////////////////////////
596 ////////////////////////////////////////////////////////////////////////
598 // End of implementation of the class AliMCInfo
600 ////////////////////////////////////////////////////////////////////////
604 ////////////////////////////////////////////////////////////////////////
609 ////////////////////////////////////////////////////////////////////////
610 digitRow & digitRow::operator=(const digitRow &digOld)
612 for (Int_t i = 0; i<kgRowBytes; i++) fDig[i] = digOld.fDig[i];
615 ////////////////////////////////////////////////////////////////////////
616 void digitRow::SetRow(Int_t row)
618 if (row >= 8*kgRowBytes) {
619 cerr<<"digitRow::SetRow: index "<<row<<" out of bounds."<<endl;
627 ////////////////////////////////////////////////////////////////////////
628 Bool_t digitRow::TestRow(Int_t row)
631 // return kTRUE if row is on
635 return TESTBIT(fDig[iC],iB);
637 ////////////////////////////////////////////////////////////////////////
638 Int_t digitRow::RowsOn(Int_t upto)
641 // returns number of rows with a digit
642 // count only rows less equal row number upto
645 for (Int_t i = 0; i<kgRowBytes; i++) {
646 for (Int_t j = 0; j < 8; j++) {
647 if (i*8+j > upto) return total;
648 if (TESTBIT(fDig[i],j)) total++;
653 ////////////////////////////////////////////////////////////////////////
654 void digitRow::Reset()
657 // resets all rows to zero
659 for (Int_t i = 0; i<kgRowBytes; i++) {
663 ////////////////////////////////////////////////////////////////////////
664 Int_t digitRow::Last()
667 // returns the last row number with a digit
668 // returns -1 if now digits
670 for (Int_t i = kgRowBytes-1; i>=0; i--) {
671 for (Int_t j = 7; j >= 0; j--) {
672 if TESTBIT(fDig[i],j) return i*8+j;
677 ////////////////////////////////////////////////////////////////////////
678 Int_t digitRow::First()
681 // returns the first row number with a digit
682 // returns -1 if now digits
684 for (Int_t i = 0; i<kgRowBytes; i++) {
685 for (Int_t j = 0; j < 8; j++) {
686 if (TESTBIT(fDig[i],j)) return i*8+j;
692 ////////////////////////////////////////////////////////////////////////
694 // end of implementation of a class digitRow
696 ////////////////////////////////////////////////////////////////////////
698 ////////////////////////////////////////////////////////////////////////
699 AliGenInfoMaker::AliGenInfoMaker()
704 ////////////////////////////////////////////////////////////////////////
705 AliGenInfoMaker::AliGenInfoMaker(const char * fnGalice, const char* fnRes,
706 Int_t nEvents, Int_t firstEvent)
709 fFirstEventNr = firstEvent;
710 fEventNr = firstEvent;
713 sprintf(fFnRes,"%s",fnRes);
715 fLoader = AliRunLoader::Open(fnGalice);
717 delete gAlice->GetRunLoader();
721 if (fLoader->LoadgAlice()){
722 cerr<<"Error occured while l"<<endl;
724 Int_t nall = fLoader->GetNumberOfEvents();
732 cerr<<"no events available"<<endl;
736 if (firstEvent+nEvents>nall) {
737 fEventNr = nall-firstEvent;
738 cerr<<"restricted number of events availaible"<<endl;
740 AliMagF * magf = gAlice->Field();
741 AliTracker::SetFieldMap(magf);
745 AliMCInfo * AliGenInfoMaker::MakeInfo(UInt_t i)
749 if (fGenInfo[i]) return fGenInfo[i];
750 fGenInfo[i] = new AliMCInfo;
758 ////////////////////////////////////////////////////////////////////////
759 void AliGenInfoMaker::Reset()
775 ////////////////////////////////////////////////////////////////////////
776 AliGenInfoMaker::~AliGenInfoMaker()
780 fLoader->UnloadgAlice();
786 Int_t AliGenInfoMaker::SetIO()
790 CreateTreeGenTracks();
791 if (!fTreeGenTracks) return 1;
792 // AliTracker::SetFieldFactor();
794 fParamTPC = GetTPCParam();
799 ////////////////////////////////////////////////////////////////////////
800 Int_t AliGenInfoMaker::SetIO(Int_t eventNr)
805 fLoader->SetEventNumber(eventNr);
807 fLoader->LoadHeader();
808 fLoader->LoadKinematics();
809 fStack = fLoader->Stack();
811 fLoader->LoadTrackRefs();
813 fTreeTR = fLoader->TreeTR();
815 AliTPCLoader * tpcl = (AliTPCLoader*)fLoader->GetLoader("TPCLoader");
817 fTreeD = tpcl->TreeD();
821 Int_t AliGenInfoMaker::CloseIOEvent()
823 fLoader->UnloadHeader();
824 fLoader->UnloadKinematics();
825 fLoader->UnloadTrackRefs();
826 AliTPCLoader * tpcl = (AliTPCLoader*)fLoader->GetLoader("TPCLoader");
827 tpcl->UnloadDigits();
831 Int_t AliGenInfoMaker::CloseIO()
833 fLoader->UnloadgAlice();
839 ////////////////////////////////////////////////////////////////////////
840 Int_t AliGenInfoMaker::Exec(Int_t nEvents, Int_t firstEventNr)
843 fFirstEventNr = firstEventNr;
847 ////////////////////////////////////////////////////////////////////////
848 Int_t AliGenInfoMaker::Exec()
852 Int_t status =SetIO();
853 if (status>0) return status;
856 for (fEventNr = fFirstEventNr; fEventNr < fFirstEventNr+fNEvents;
859 fNParticles = fStack->GetNtrack();
861 fGenInfo = new AliMCInfo*[fNParticles];
862 for (UInt_t i = 0; i<fNParticles; i++) {
866 cout<<"Start to process event "<<fEventNr<<endl;
867 cout<<"\tfNParticles = "<<fNParticles<<endl;
868 if (fDebug>2) cout<<"\n\n\n\tStart loop over TreeTR"<<endl;
869 if (TreeTRLoop()>0) return 1;
871 if (fDebug>2) cout<<"\n\n\n\tStart loop over TreeD"<<endl;
872 if (TreeDLoop()>0) return 1;
874 if (fDebug>2) cout<<"\n\n\n\tStart loop over TreeK"<<endl;
875 if (TreeKLoop()>0) return 1;
876 if (fDebug>2) cout<<"\tEnd loop over TreeK"<<endl;
878 if (BuildKinkInfo()>0) return 1;
879 if (BuildV0Info()>0) return 1;
880 //if (BuildHitLines()>0) return 1;
881 if (fDebug>2) cout<<"\tEnd loop over TreeK"<<endl;
883 for (UInt_t i = 0; i<fNParticles; i++) {
884 if (fGenInfo[i]) delete fGenInfo[i];
893 cerr<<"Exec finished"<<endl;
899 ////////////////////////////////////////////////////////////////////////
900 void AliGenInfoMaker::CreateTreeGenTracks()
902 fFileGenTracks = TFile::Open(fFnRes,"RECREATE");
903 if (!fFileGenTracks) {
904 cerr<<"Error in CreateTreeGenTracks: cannot open file "<<fFnRes<<endl;
907 fTreeGenTracks = new TTree("genTracksTree","genTracksTree");
908 AliMCInfo * info = new AliMCInfo;
909 fTreeGenTracks->Branch("MC","AliMCInfo",&info);
912 AliGenKinkInfo *kinkinfo = new AliGenKinkInfo;
913 fTreeKinks = new TTree("genKinksTree","genKinksTree");
914 fTreeKinks->Branch("MC","AliGenKinkInfo",&kinkinfo);
917 AliGenV0Info *v0info = new AliGenV0Info;
918 fTreeV0 = new TTree("genV0Tree","genV0Tree");
919 fTreeV0->Branch("MC","AliGenV0Info",&v0info);
923 AliPointsMI * points0 = new AliPointsMI;
924 AliPointsMI * points1 = new AliPointsMI;
925 AliPointsMI * points2 = new AliPointsMI;
926 fTreeHitLines = new TTree("HitLines","HitLines");
927 fTreeHitLines->Branch("TPC.","AliPointsMI",&points0,32000,10);
928 fTreeHitLines->Branch("TRD.","AliPointsMI",&points1,32000,10);
929 fTreeHitLines->Branch("ITS.","AliPointsMI",&points2,32000,10);
931 fTreeHitLines->Branch("Label",&label,"label/I");
933 fTreeGenTracks->AutoSave();
934 fTreeKinks->AutoSave();
936 fTreeHitLines->AutoSave();
938 ////////////////////////////////////////////////////////////////////////
939 void AliGenInfoMaker::CloseOutputFile()
941 if (!fFileGenTracks) {
942 cerr<<"File "<<fFnRes<<" not found as an open file."<<endl;
945 fFileGenTracks->cd();
946 fTreeGenTracks->Write();
947 delete fTreeGenTracks;
953 fFileGenTracks->Close();
954 delete fFileGenTracks;
958 ////////////////////////////////////////////////////////////////////////
959 Int_t AliGenInfoMaker::TreeKLoop()
962 // open the file with treeK
963 // loop over all entries there and save information about some tracks
966 AliStack * stack = fStack;
967 if (!stack) {cerr<<"Stack was not found!\n"; return 1;}
970 cout<<"There are "<<fNParticles<<" primary and secondary particles in event "
974 TParticlePDG *ppdg = 0;
975 // not all generators give primary vertex position. Take the vertex
976 // of the particle 0 as primary vertex.
977 TDatabasePDG pdg; //get pdg table
978 //thank you very much root for this
979 TBranch * br = fTreeGenTracks->GetBranch("MC");
980 TParticle *particle = stack->ParticleFromTreeK(0);
981 fVPrim[0] = particle->Vx();
982 fVPrim[1] = particle->Vy();
983 fVPrim[2] = particle->Vz();
984 for (UInt_t iParticle = 0; iParticle < fNParticles; iParticle++) {
985 // load only particles with TR
986 AliMCInfo * info = GetInfo(iParticle);
988 //////////////////////////////////////////////////////////////////////
989 info->fLabel = iParticle;
991 info->fParticle = *(stack->Particle(iParticle));
992 info->fVDist[0] = info->fParticle.Vx()-fVPrim[0];
993 info->fVDist[1] = info->fParticle.Vy()-fVPrim[1];
994 info->fVDist[2] = info->fParticle.Vz()-fVPrim[2];
995 info->fVDist[3] = TMath::Sqrt(info->fVDist[0]*info->fVDist[0]+
996 info->fVDist[1]*info->fVDist[1]+info->fVDist[2]*info->fVDist[2]);
999 ipdg = info->fParticle.GetPdgCode();
1001 ppdg = pdg.GetParticle(ipdg);
1002 info->fEventNr = fEventNr;
1004 //////////////////////////////////////////////////////////////////////
1005 br->SetAddress(&info);
1006 fTreeGenTracks->Fill();
1008 fTreeGenTracks->AutoSave();
1009 if (fDebug > 2) cerr<<"end of TreeKLoop"<<endl;
1014 ////////////////////////////////////////////////////////////////////////////////////
1015 Int_t AliGenInfoMaker::BuildKinkInfo()
1018 // Build tree with Kink Information
1020 AliStack * stack = fStack;
1021 if (!stack) {cerr<<"Stack was not found!\n"; return 1;}
1024 cout<<"There are "<<fNParticles<<" primary and secondary particles in event "
1028 //TParticlePDG *ppdg = 0;
1029 // not all generators give primary vertex position. Take the vertex
1030 // of the particle 0 as primary vertex.
1031 TDatabasePDG pdg; //get pdg table
1032 //thank you very much root for this
1033 TBranch * br = fTreeKinks->GetBranch("MC");
1035 AliGenKinkInfo * kinkinfo = new AliGenKinkInfo;
1037 for (UInt_t iParticle = 0; iParticle < fNParticles; iParticle++) {
1038 // load only particles with TR
1039 AliMCInfo * info = GetInfo(iParticle);
1040 if (!info) continue;
1041 if (info->fCharge==0) continue;
1042 if (info->fTRdecay.P()<0.13) continue; //momenta cut
1043 if (info->fTRdecay.R()>500) continue; //R cut - decay outside barrel
1044 TParticle & particle = info->fParticle;
1045 Int_t first = particle.GetDaughter(0);
1046 if (first ==0) continue;
1048 Int_t last = particle.GetDaughter(1);
1049 if (last ==0) last=first;
1050 AliMCInfo * info2 = 0;
1051 AliMCInfo * dinfo = 0;
1053 for (Int_t id2=first;id2<=last;id2++){
1054 info2 = GetInfo(id2);
1055 if (!info2) continue;
1056 TParticle &p2 = info2->fParticle;
1057 Double_t r = TMath::Sqrt(p2.Vx()*p2.Vx()+p2.Vy()*p2.Vy());
1058 if ( TMath::Abs(info->fTRdecay.R()-r)>0.01) continue;
1059 if (!(p2.GetPDG())) continue;
1062 kinkinfo->fMCm = (*info);
1063 kinkinfo->fMCd = (*dinfo);
1064 if (kinkinfo->fMCm.fParticle.GetPDG()==0 || kinkinfo->fMCd.fParticle.GetPDG()==0) continue;
1066 br->SetAddress(&kinkinfo);
1071 kinkinfo->fMCm = (*info);
1072 kinkinfo->fMCd = (*dinfo);
1074 br->SetAddress(&kinkinfo);
1079 fTreeGenTracks->AutoSave();
1080 if (fDebug > 2) cerr<<"end of Kink Loop"<<endl;
1085 ////////////////////////////////////////////////////////////////////////////////////
1086 Int_t AliGenInfoMaker::BuildV0Info()
1089 // Build tree with V0 Information
1091 AliStack * stack = fStack;
1092 if (!stack) {cerr<<"Stack was not found!\n"; return 1;}
1095 cout<<"There are "<<fNParticles<<" primary and secondary particles in event "
1099 //TParticlePDG *ppdg = 0;
1100 // not all generators give primary vertex position. Take the vertex
1101 // of the particle 0 as primary vertex.
1102 TDatabasePDG pdg; //get pdg table
1103 //thank you very much root for this
1104 TBranch * br = fTreeV0->GetBranch("MC");
1106 AliGenV0Info * v0info = new AliGenV0Info;
1109 for (UInt_t iParticle = 0; iParticle < fNParticles; iParticle++) {
1110 // load only particles with TR
1111 AliMCInfo * info = GetInfo(iParticle);
1112 if (!info) continue;
1113 if (info->fCharge==0) continue;
1116 TParticle & particle = info->fParticle;
1117 Int_t mother = particle.GetMother(0);
1118 if (mother <=0) continue;
1120 TParticle * motherparticle = stack->Particle(mother);
1121 if (!motherparticle) continue;
1123 Int_t last = motherparticle->GetDaughter(1);
1124 if (last==(int)iParticle) continue;
1125 AliMCInfo * info2 = info;
1126 AliMCInfo * dinfo = GetInfo(last);
1127 if (!dinfo) continue;
1128 if (!dinfo->fParticle.GetPDG()) continue;
1129 if (!info2->fParticle.GetPDG()) continue;
1131 v0info->fMCm = (*info);
1132 v0info->fMCd = (*dinfo);
1133 v0info->Update(fVPrim);
1134 br->SetAddress(&v0info);
1138 fTreeV0->AutoSave();
1139 if (fDebug > 2) cerr<<"end of V0 Loop"<<endl;
1146 ////////////////////////////////////////////////////////////////////////
1147 Int_t AliGenInfoMaker::BuildHitLines()
1151 // open the file with treeK
1152 // loop over all entries there and save information about some tracks
1155 AliStack * stack = fStack;
1156 if (!stack) {cerr<<"Stack was not found!\n"; return 1;}
1159 cout<<"There are "<<fNParticles<<" primary and secondary particles in event "
1163 // TParticlePDG *ppdg = 0;
1164 // not all generators give primary vertex position. Take the vertex
1165 // of the particle 0 as primary vertex.
1166 TDatabasePDG pdg; //get pdg table
1167 //thank you very much root for this
1168 AliPointsMI *tpcp = new AliPointsMI;
1169 AliPointsMI *trdp = new AliPointsMI;
1170 AliPointsMI *itsp = new AliPointsMI;
1173 TBranch * brtpc = fTreeHitLines->GetBranch("TPC.");
1174 TBranch * brtrd = fTreeHitLines->GetBranch("TRD.");
1175 TBranch * brits = fTreeHitLines->GetBranch("ITS.");
1176 TBranch * brlabel = fTreeHitLines->GetBranch("Label");
1177 brlabel->SetAddress(&label);
1178 brtpc->SetAddress(&tpcp);
1179 brtrd->SetAddress(&trdp);
1180 brits->SetAddress(&itsp);
1182 AliDetector *dtpc = gAlice->GetDetector("TPC");
1183 AliDetector *dtrd = gAlice->GetDetector("TRD");
1184 AliDetector *dits = gAlice->GetDetector("ITS");
1186 for (UInt_t iParticle = 0; iParticle < fNParticles; iParticle++) {
1187 // load only particles with TR
1188 AliMCInfo * info = GetInfo(iParticle);
1189 if (!info) continue;
1190 Int_t primpart = info->fPrimPart;
1191 ipdg = info->fParticle.GetPdgCode();
1194 gAlice->ResetHits();
1198 tpcp->fLabel1 = ipdg;
1199 trdp->fLabel1 = ipdg;
1200 itsp->fLabel1 = ipdg;
1201 if (dtpc->TreeH()->GetEvent(primpart)){
1202 dtpc->LoadPoints(primpart);
1203 tpcp->Reset(dtpc,iParticle);
1205 if (dtrd->TreeH()->GetEvent(primpart)){
1206 dtrd->LoadPoints(primpart);
1207 trdp->Reset(dtrd,iParticle);
1209 if (dits->TreeH()->GetEvent(primpart)){
1210 dits->LoadPoints(primpart);
1211 itsp->Reset(dits,iParticle);
1214 fTreeHitLines->Fill();
1215 dtpc->ResetPoints();
1216 dtrd->ResetPoints();
1217 dits->ResetPoints();
1222 fTreeHitLines->AutoSave();
1223 if (fDebug > 2) cerr<<"end of TreeKLoop"<<endl;
1228 ////////////////////////////////////////////////////////////////////////
1229 Int_t AliGenInfoMaker::TreeDLoop()
1232 // open the file with treeD
1233 // loop over all entries there and save information about some tracks
1236 Int_t nInnerSector = fParamTPC->GetNInnerSector();
1238 Int_t zero=fParamTPC->GetZeroSup()+6;
1241 AliSimDigits digitsAddress, *digits=&digitsAddress;
1242 fTreeD->GetBranch("Segment")->SetAddress(&digits);
1244 Int_t sectorsByRows=(Int_t)fTreeD->GetEntries();
1245 if (fDebug > 1) cout<<"\tsectorsByRows = "<<sectorsByRows<<endl;
1246 for (Int_t i=0; i<sectorsByRows; i++) {
1247 if (!fTreeD->GetEvent(i)) continue;
1249 fParamTPC->AdjustSectorRow(digits->GetID(),sec,row);
1250 if (fDebug > 1) cout<<sec<<' '<<row<<" \r";
1251 // here I expect that upper sectors follow lower sectors
1252 if (sec > nInnerSector) rowShift = fParamTPC->GetNRowLow();
1254 digits->ExpandTrackBuffer();
1257 Int_t iRow=digits->CurrentRow();
1258 Int_t iColumn=digits->CurrentColumn();
1259 Short_t digitValue = digits->CurrentDigit();
1260 if (digitValue >= zero) {
1262 for (Int_t j = 0; j<3; j++) {
1263 // label = digits->GetTrackID(iRow,iColumn,j);
1264 label = digits->GetTrackIDFast(iRow,iColumn,j)-2;
1265 if (label >= (Int_t)fNParticles) { //don't label from bakground event
1268 if (label >= 0 && label <= (Int_t)fNParticles) {
1270 cout<<"Inner loop: sector, iRow, iColumn, label, value, row "
1272 <<iRow<<" "<<iColumn<<" "<<label<<" "<<digitValue
1275 AliMCInfo * info = GetInfo(label);
1277 info->fTPCRow.SetRow(row+rowShift);
1282 } while (digits->Next());
1285 if (fDebug > 2) cerr<<"end of TreeDLoop"<<endl;
1290 ////////////////////////////////////////////////////////////////////////
1291 Int_t AliGenInfoMaker::TreeTRLoop()
1294 // loop over TrackReferences and store the first one for each track
1296 TTree * treeTR = fTreeTR;
1297 Int_t nPrimaries = (Int_t) treeTR->GetEntries();
1298 if (fDebug > 1) cout<<"There are "<<nPrimaries<<" entries in TreeTR"<<endl;
1301 //track references for TPC
1302 TClonesArray* TPCArrayTR = new TClonesArray("AliTrackReference");
1303 TClonesArray* ITSArrayTR = new TClonesArray("AliTrackReference");
1304 TClonesArray* TRDArrayTR = new TClonesArray("AliTrackReference");
1305 TClonesArray* TOFArrayTR = new TClonesArray("AliTrackReference");
1306 TClonesArray* RunArrayTR = new TClonesArray("AliTrackReference");
1308 if (treeTR->GetBranch("TPC")) treeTR->GetBranch("TPC")->SetAddress(&TPCArrayTR);
1309 if (treeTR->GetBranch("ITS")) treeTR->GetBranch("ITS")->SetAddress(&ITSArrayTR);
1310 if (treeTR->GetBranch("TRD")) treeTR->GetBranch("TRD")->SetAddress(&TRDArrayTR);
1311 if (treeTR->GetBranch("TOF")) treeTR->GetBranch("TOF")->SetAddress(&TOFArrayTR);
1312 if (treeTR->GetBranch("AliRun")) treeTR->GetBranch("AliRun")->SetAddress(&RunArrayTR);
1316 for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++) {
1317 treeTR->GetEntry(iPrimPart);
1319 // Loop over TPC references
1321 for (Int_t iTrackRef = 0; iTrackRef < TPCArrayTR->GetEntriesFast(); iTrackRef++) {
1322 AliTrackReference *trackRef = (AliTrackReference*)TPCArrayTR->At(iTrackRef);
1324 if (trackRef->TestBit(BIT(2))){
1326 if (trackRef->P()<fgTPCPtCut) continue;
1327 Int_t label = trackRef->GetTrack();
1328 AliMCInfo * info = GetInfo(label);
1329 if (!info) info = MakeInfo(label);
1330 info->fTRdecay = *trackRef;
1333 if (trackRef->P()<fgTPCPtCut) continue;
1334 Int_t label = trackRef->GetTrack();
1335 AliMCInfo * info = GetInfo(label);
1336 if (!info) info = MakeInfo(label);
1337 if (!info) continue;
1338 info->fPrimPart = iPrimPart;
1339 TClonesArray & arr = *(info->fTPCReferences);
1340 new (arr[arr.GetEntriesFast()]) AliTrackReference(*trackRef);
1343 // Loop over ITS references
1345 for (Int_t iTrackRef = 0; iTrackRef < ITSArrayTR->GetEntriesFast(); iTrackRef++) {
1346 AliTrackReference *trackRef = (AliTrackReference*)ITSArrayTR->At(iTrackRef);
1349 if (trackRef->P()<fgTPCPtCut) continue;
1350 Int_t label = trackRef->GetTrack();
1351 AliMCInfo * info = GetInfo(label);
1352 if ( (!info) && trackRef->Pt()<fgITSPtCut) continue;
1353 if (!info) info = MakeInfo(label);
1354 if (!info) continue;
1355 info->fPrimPart = iPrimPart;
1356 TClonesArray & arr = *(info->fITSReferences);
1357 new (arr[arr.GetEntriesFast()]) AliTrackReference(*trackRef);
1360 // Loop over TRD references
1362 for (Int_t iTrackRef = 0; iTrackRef < TRDArrayTR->GetEntriesFast(); iTrackRef++) {
1363 AliTrackReference *trackRef = (AliTrackReference*)TRDArrayTR->At(iTrackRef);
1365 if (trackRef->P()<fgTPCPtCut) continue;
1366 Int_t label = trackRef->GetTrack();
1367 AliMCInfo * info = GetInfo(label);
1368 if ( (!info) && trackRef->Pt()<fgTRDPtCut) continue;
1369 if (!info) info = MakeInfo(label);
1370 if (!info) continue;
1371 info->fPrimPart = iPrimPart;
1372 TClonesArray & arr = *(info->fTRDReferences);
1373 new (arr[arr.GetEntriesFast()]) AliTrackReference(*trackRef);
1376 // Loop over TOF references
1378 for (Int_t iTrackRef = 0; iTrackRef < TOFArrayTR->GetEntriesFast(); iTrackRef++) {
1379 AliTrackReference *trackRef = (AliTrackReference*)TOFArrayTR->At(iTrackRef);
1380 Int_t label = trackRef->GetTrack();
1381 AliMCInfo * info = GetInfo(label);
1383 if (trackRef->Pt()<fgTPCPtCut) continue;
1384 if ( (!info) && trackRef->Pt()<fgTOFPtCut) continue;
1386 if (!info) info = MakeInfo(label);
1387 if (!info) continue;
1388 info->fPrimPart = iPrimPart;
1389 TClonesArray & arr = *(info->fTOFReferences);
1390 new (arr[arr.GetEntriesFast()]) AliTrackReference(*trackRef);
1393 // get dacay position
1394 for (Int_t iTrackRef = 0; iTrackRef < RunArrayTR->GetEntriesFast(); iTrackRef++) {
1395 AliTrackReference *trackRef = (AliTrackReference*)RunArrayTR->At(iTrackRef);
1397 Int_t label = trackRef->GetTrack();
1398 AliMCInfo * info = GetInfo(label);
1399 if (!info) continue;
1400 if (!trackRef->TestBit(BIT(2))) continue; //if not decay
1401 // if (TMath::Abs(trackRef.X());
1402 info->fTRdecay = *trackRef;
1406 TPCArrayTR->Delete();
1408 TRDArrayTR->Delete();
1410 TOFArrayTR->Delete();
1413 ITSArrayTR->Delete();
1415 RunArrayTR->Delete();
1421 ////////////////////////////////////////////////////////////////////////
1422 Float_t AliGenInfoMaker::TR2LocalX(AliTrackReference *trackRef,
1423 AliTPCParam *paramTPC) {
1425 Float_t x[3] = { trackRef->X(),trackRef->Y(),trackRef->Z()};
1427 paramTPC->Transform0to1(x,index);
1428 paramTPC->Transform1to2(x,index);
1431 ////////////////////////////////////////////////////////////////////////
1435 TH1F * AliComparisonDraw::DrawXY(const char * chx, const char *chy, const char* selection,
1436 const char * quality, Int_t nbins, Float_t minx, Float_t maxx, Float_t miny, Float_t maxy, Int_t nBinsRes)
1439 Double_t* bins = CreateLogBins(nbins, minx, maxx);
1440 TH2F* hRes2 = new TH2F("hRes2", "residuals", nbins, minx, maxx, nBinsRes, miny, maxy);
1442 sprintf(cut,"%s&&%s",selection,quality);
1443 char expression[1000];
1444 sprintf(expression,"%s:%s>>hRes2",chy,chx);
1445 fTree->Draw(expression, cut, "groff");
1447 TH1F* hRes = CreateResHisto(hRes2, &hMean);
1448 AliLabelAxes(hRes, chx, chy);
1457 TH1F * AliComparisonDraw::DrawLogXY(const char * chx, const char *chy, const char* selection,
1458 const char * quality, Int_t nbins, Float_t minx, Float_t maxx, Float_t miny, Float_t maxy)
1461 Double_t* bins = CreateLogBins(nbins, minx, maxx);
1462 Int_t nBinsRes = 30;
1463 TH2F* hRes2 = new TH2F("hRes2", "residuals", nbins, bins, nBinsRes, miny, maxy);
1465 sprintf(cut,"%s&&%s",selection,quality);
1466 char expression[1000];
1467 sprintf(expression,"%s:%s>>hRes2",chy,chx);
1468 fTree->Draw(expression, cut, "groff");
1470 TH1F* hRes = CreateResHisto(hRes2, &hMean);
1471 AliLabelAxes(hRes, chx, chy);
1480 ///////////////////////////////////////////////////////////////////////////////////
1481 ///////////////////////////////////////////////////////////////////////////////////
1482 TH1F * AliComparisonDraw::Eff(const char *variable, const char* selection, const char * quality,
1483 Int_t nbins, Float_t min, Float_t max)
1487 TH1F* hGen = new TH1F("hGen", "gen. tracks", nbins, min, max);
1488 TH1F* hRec = new TH1F("hRec", "rec. tracks", nbins, min, max);
1489 char inputGen[1000];
1490 sprintf(inputGen,"%s>>hGen", variable);
1491 fTree->Draw(inputGen, selection, "groff");
1492 char selectionRec[256];
1493 sprintf(selectionRec, "%s && %s", selection, quality);
1494 char inputRec[1000];
1495 sprintf(inputRec,"%s>>hRec", variable);
1496 fTree->Draw(inputRec, selectionRec, "groff");
1498 TH1F* hEff = CreateEffHisto(hGen, hRec);
1499 AliLabelAxes(hEff, variable, "#epsilon [%]");
1508 ///////////////////////////////////////////////////////////////////////////////////
1509 ///////////////////////////////////////////////////////////////////////////////////
1510 TH1F * AliComparisonDraw::EffLog(const char *variable, const char* selection, const char * quality,
1511 Int_t nbins, Float_t min, Float_t max)
1515 Double_t* bins = CreateLogBins(nbins, min, max);
1516 TH1F* hGen = new TH1F("hGen", "gen. tracks", nbins, bins);
1517 TH1F* hRec = new TH1F("hRec", "rec. tracks", nbins, bins);
1518 char inputGen[1000];
1519 sprintf(inputGen,"%s>>hGen", variable);
1520 fTree->Draw(inputGen, selection, "groff");
1521 char selectionRec[256];
1522 sprintf(selectionRec, "%s && %s", selection, quality);
1523 char inputRec[1000];
1524 sprintf(inputRec,"%s>>hRec", variable);
1525 fTree->Draw(inputRec, selectionRec, "groff");
1527 TH1F* hEff = CreateEffHisto(hGen, hRec);
1528 AliLabelAxes(hEff, variable, "#epsilon [%]");
1537 ///////////////////////////////////////////////////////////////////////////////////
1538 ///////////////////////////////////////////////////////////////////////////////////
1540 Double_t* AliComparisonDraw::CreateLogBins(Int_t nBins, Double_t xMin, Double_t xMax)
1542 Double_t* bins = new Double_t[nBins+1];
1544 Double_t factor = pow(xMax/xMin, 1./nBins);
1545 for (Int_t i = 1; i <= nBins; i++)
1546 bins[i] = factor * bins[i-1];
1553 void AliComparisonDraw::AliLabelAxes(TH1* histo, const char* xAxisTitle, const char* yAxisTitle)
1556 histo->GetXaxis()->SetTitle(xAxisTitle);
1557 histo->GetYaxis()->SetTitle(yAxisTitle);
1561 TH1F* AliComparisonDraw::CreateEffHisto(TH1F* hGen, TH1F* hRec)
1564 Int_t nBins = hGen->GetNbinsX();
1565 TH1F* hEff = (TH1F*) hGen->Clone("hEff");
1567 hEff->SetStats(kFALSE);
1568 hEff->SetMinimum(0.);
1569 hEff->SetMaximum(110.);
1571 for (Int_t iBin = 0; iBin <= nBins; iBin++) {
1572 Double_t nGen = hGen->GetBinContent(iBin);
1573 Double_t nRec = hRec->GetBinContent(iBin);
1575 Double_t eff = nRec/nGen;
1576 hEff->SetBinContent(iBin, 100. * eff);
1577 Double_t error = sqrt((eff*(1.-eff)+0.01) / nGen);
1578 // if (error == 0) error = sqrt(0.1/nGen);
1580 if (error == 0) error = 0.0001;
1581 hEff->SetBinError(iBin, 100. * error);
1583 hEff->SetBinContent(iBin, 100. * 0.5);
1584 hEff->SetBinError(iBin, 100. * 0.5);
1592 TH1F* AliComparisonDraw::CreateResHisto(TH2F* hRes2, TH1F **phMean, Bool_t drawBinFits,
1593 Bool_t overflowBinFits)
1595 TVirtualPad* currentPad = gPad;
1596 TAxis* axis = hRes2->GetXaxis();
1597 Int_t nBins = axis->GetNbins();
1599 if (axis->GetXbins()->GetSize()){
1600 hRes = new TH1F("hRes", "", nBins, axis->GetXbins()->GetArray());
1601 hMean = new TH1F("hMean", "", nBins, axis->GetXbins()->GetArray());
1604 hRes = new TH1F("hRes", "", nBins, axis->GetXmin(), axis->GetXmax());
1605 hMean = new TH1F("hMean", "", nBins, axis->GetXmin(), axis->GetXmax());
1608 hRes->SetStats(false);
1609 hRes->SetOption("E");
1610 hRes->SetMinimum(0.);
1612 hMean->SetStats(false);
1613 hMean->SetOption("E");
1615 // create the fit function
1616 //TKFitGaus* fitFunc = new TKFitGaus("resFunc");
1617 // TF1 * fitFunc = new TF1("G","[3]+[0]*exp(-(x-[1])*(x-[1])/(2.*[2]*[2]))",-3,3);
1618 TF1 * fitFunc = new TF1("G","[0]*exp(-(x-[1])*(x-[1])/(2.*[2]*[2]))",-3,3);
1620 fitFunc->SetLineWidth(2);
1621 fitFunc->SetFillStyle(0);
1622 // create canvas for fits
1623 TCanvas* canBinFits = NULL;
1624 Int_t nPads = (overflowBinFits) ? nBins+2 : nBins;
1625 Int_t nx = Int_t(sqrt(nPads-1.));// + 1;
1626 Int_t ny = (nPads-1) / nx + 1;
1628 canBinFits = (TCanvas*)gROOT->FindObject("canBinFits");
1629 if (canBinFits) delete canBinFits;
1630 canBinFits = new TCanvas("canBinFits", "fits of bins", 200, 100, 500, 700);
1631 canBinFits->Divide(nx, ny);
1634 // loop over x bins and fit projection
1635 Int_t dBin = ((overflowBinFits) ? 1 : 0);
1636 for (Int_t bin = 1-dBin; bin <= nBins+dBin; bin++) {
1637 if (drawBinFits) canBinFits->cd(bin + dBin);
1638 TH1D* hBin = hRes2->ProjectionY("hBin", bin, bin);
1640 if (hBin->GetEntries() > 5) {
1641 fitFunc->SetParameters(hBin->GetMaximum(),hBin->GetMean(),hBin->GetRMS());
1642 hBin->Fit(fitFunc,"s");
1643 Double_t sigma = TMath::Abs(fitFunc->GetParameter(2));
1646 hRes->SetBinContent(bin, TMath::Abs(fitFunc->GetParameter(2)));
1647 hMean->SetBinContent(bin, fitFunc->GetParameter(1));
1650 hRes->SetBinContent(bin, 0.);
1651 hMean->SetBinContent(bin,0);
1653 hRes->SetBinError(bin, fitFunc->GetParError(2));
1654 hMean->SetBinError(bin, fitFunc->GetParError(1));
1660 hRes->SetBinContent(bin, 0.);
1661 hRes->SetBinError(bin, 0.);
1662 hMean->SetBinContent(bin, 0.);
1663 hMean->SetBinError(bin, 0.);
1670 sprintf(name, "%s < %.4g", axis->GetTitle(), axis->GetBinUpEdge(bin));
1671 } else if (bin == nBins+1) {
1672 sprintf(name, "%.4g < %s", axis->GetBinLowEdge(bin), axis->GetTitle());
1674 sprintf(name, "%.4g < %s < %.4g", axis->GetBinLowEdge(bin),
1675 axis->GetTitle(), axis->GetBinUpEdge(bin));
1677 canBinFits->cd(bin + dBin);
1678 hBin->SetTitle(name);
1679 hBin->SetStats(kTRUE);
1680 hBin->DrawCopy("E");
1681 canBinFits->Update();
1682 canBinFits->Modified();
1683 canBinFits->Update();
1696 void AliComparisonDraw::DrawFriend2D(const char * chx, const char *chy, const char* selection, TTree * tfriend)
1702 void AliComparisonDraw::GetPoints3D(const char * label, const char * chpoints, const char* selection, TTree * tpoints, Int_t color,Float_t rmin){
1705 if (!fPoints) fPoints = new TObjArray;
1706 if (tpoints->GetIndex()==0) tpoints->BuildIndex("Label","Label");
1707 AliPointsMI * points = new AliPointsMI;
1708 TBranch * br = tpoints->GetBranch(chpoints);
1709 br->SetAddress(&points);
1710 Int_t npoints = fTree->Draw(label,selection);
1713 for (Int_t i=0;i<npoints;i++){
1714 Int_t index = (Int_t)fTree->GetV1()[i];
1715 tpoints->GetEntryWithIndex(index,index);
1716 if (points->fN<2) continue;
1718 for (Int_t i=0;i<points->fN; i++){
1719 xyz[goodpoints*3] = points->fX[i];
1720 xyz[goodpoints*3+1] = points->fY[i];
1721 xyz[goodpoints*3+2] = points->fZ[i];
1722 if ( points->fX[i]*points->fX[i]+points->fY[i]*points->fY[i]>rmin) goodpoints++;
1724 TPolyMarker3D * marker = new TPolyMarker3D(goodpoints,xyz);
1725 // marker->SeWidth(1);
1726 marker->SetMarkerColor(color);
1727 marker->SetMarkerStyle(1);
1728 fPoints->AddLast(marker);
1732 void AliComparisonDraw::Draw3D(Int_t min, Int_t max){
1733 if (!fPoints) return;
1734 Int_t npoints = fPoints->GetEntriesFast();
1735 max = TMath::Min(npoints,max);
1736 min = TMath::Min(npoints,min);
1738 for (Int_t i =min; i<max;i++){
1739 TObject * obj = fPoints->At(i);
1740 if (obj) obj->Draw();
1744 void AliComparisonDraw:: SavePoints(const char* name)
1747 sprintf(fname,"TH_%s.root",name);
1748 TFile f(fname,"new");
1749 fPoints->Write("Tracks",TObject::kSingleKey);
1751 sprintf(fname,"TH%s.gif",name);
1752 fCanvas->SaveAs(fname);
1755 void AliComparisonDraw::InitView(){
1758 AliRunLoader* rl = AliRunLoader::Open();
1762 fCanvas = new TCanvas("cdisplay", "Cluster display",0,0,700,730);
1763 fView = new TView(1);
1764 fView->SetRange(-330,-360,-330, 360,360, 330);
1766 fCanvas->SetFillColor(1);
1767 fCanvas->SetTheta(90.);
1768 fCanvas->SetPhi(0.);
1770 TGeometry *geom =(TGeometry*)gDirectory->Get("AliceGeom");