X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=TPC%2FAliTPCComparison.C;h=d9dd6b32c480eed6bd44453989a01a623df66a24;hb=ed7122711e1d6a15da49eac3a752f3b4da36ee4a;hp=a1fbc786df504d524d1cf7a8c782f966a4b34ef1;hpb=2d343a94d99615a078f8a8cf8f44b36e3dc715f3;p=u%2Fmrichter%2FAliRoot.git diff --git a/TPC/AliTPCComparison.C b/TPC/AliTPCComparison.C index a1fbc786df5..d9dd6b32c48 100644 --- a/TPC/AliTPCComparison.C +++ b/TPC/AliTPCComparison.C @@ -17,22 +17,21 @@ #include #include #include - #include #include #include #include #include #include - #include + #include #include #include "AliStack.h" #include "AliHeader.h" #include "AliTrackReference.h" #include "AliRunLoader.h" - #include "AliMagF.h" #include "AliRun.h" - #include "AliESD.h" + #include "AliESDEvent.h" + #include "AliESDtrack.h" #include "AliSimDigits.h" #include "AliTPC.h" @@ -43,89 +42,23 @@ #include "AliTPCLoader.h" #endif -struct GoodTrackTPC { - Int_t lab; - Int_t code; - Float_t px,py,pz; - Float_t x,y,z; -}; - -Int_t good_tracks_tpc(GoodTrackTPC *gt, const Int_t max, -const char* evfoldname=AliConfig::fgkDefaultEventFolderName); +Int_t GoodTracksTPC(const Char_t *dir="."); extern AliRun *gAlice; extern TBenchmark *gBenchmark; extern TROOT *gROOT; -Int_t AliTPCComparison(Float_t ptcutl=0.2, Float_t ptcuth=10., const Char_t *dir=".") { +static Int_t allgood=0; +static Int_t allselected=0; +static Int_t allfound=0; + +Int_t AliTPCComparison +(Float_t ptcutl=0.2, Float_t ptcuth=10., const Char_t *dir=".") { gBenchmark->Start("AliTPCComparison"); ::Info("AliTPCComparison.C","Doing comparison..."); - if (gAlice) { - delete gAlice->GetRunLoader(); - delete gAlice;//if everything was OK here it is already NULL - gAlice = 0x0; - } - Char_t fname[100]; - sprintf(fname,"%s/galice.root",dir); - - AliRunLoader *rl = AliRunLoader::Open(fname,"COMPARISON"); - if (!rl) { - ::Fatal("AliTPCComparison.C","Can't start session !"); - } - - /* Generate a list of "good" tracks */ - const Int_t MAX=20000; - GoodTrackTPC gt[MAX]; - Int_t ngood=0; - sprintf(fname,"%s/good_tracks_tpc",dir); - ifstream in(fname); - if (in) { - ::Info("AliTPCComparison.C","Reading good tracks..."); - while (in>>gt[ngood].lab>>gt[ngood].code>> - gt[ngood].px>>gt[ngood].py>>gt[ngood].pz>> - gt[ngood].x >>gt[ngood].y >>gt[ngood].z) { - ngood++; - if (ngood==MAX) { - ::Warning("AliTPCComparison.C","Too many good tracks !"); - break; - } - } - if (!in.eof()) - ::Fatal("AliTPCComparison.C","Read error (good_tracks_tpc) !"); - } else { - ::Info - ("AliTPCComparison","Marking good tracks (this will take a while)..."); - ngood=good_tracks_tpc(gt,MAX,"COMPARISON"); - ofstream out(fname); - if (out) { - for (Int_t ngd=0; ngdIsOpen())) { - sprintf(fname,"%s/AliESDtpc.root",dir); - ef=TFile::Open(fname); - if ((!ef)||(!ef->IsOpen())) - ::Fatal("AliTPCComparison.C","Can't open AliESDtpc.root !"); - } - TKey *key=0; - TIter next(ef->GetListOfKeys()); - if ((key=(TKey*)next())!=0) event=(AliESD*)key->ReadObj(); - ef->Close(); - } - Int_t nentr=event->GetNumberOfTracks(); TH1F *hp=(TH1F*)gROOT->FindObject("hp"); if (!hp) hp=new TH1F("hp","PHI resolution",50,-20.,20.); @@ -172,106 +105,191 @@ Int_t AliTPCComparison(Float_t ptcutl=0.2, Float_t ptcuth=10., const Char_t *dir hep->SetMarkerStyle(8); hep->SetMarkerSize(0.4); - //MI change - Int_t mingood=ngood; - Int_t track_notfound[MAX], itrack_notfound=0; - Int_t track_fake[MAX], itrack_fake=0; - Int_t track_multifound[MAX], track_multifound_n[MAX], itrack_multifound=0; - - Int_t i; - while (ngood--) { - Int_t lab=gt[ngood].lab,tlab=-1; - Float_t ptg= - TMath::Sqrt(gt[ngood].px*gt[ngood].px + gt[ngood].py*gt[ngood].py); - - if (ptg<1e-33) continue; // for those not crossing 0 pad row - if (ptgptcuth) continue; - hgood->Fill(ptg); - - AliESDtrack *track=0; - for (i=0; iGetTrack(i); - tlab=track->GetLabel(); - if (lab==TMath::Abs(tlab)) break; - } - if (i==nentr) { - track_notfound[itrack_notfound++]=lab; - continue; - } - - //MI change - addition - Int_t micount=0; - Int_t mi; - AliESDtrack * mitrack; - for (mi=0; miGetTrack(mi); - if (lab==TMath::Abs(mitrack->GetLabel())) micount++; - } - if (micount>1) { - track_multifound[itrack_multifound]=lab; - track_multifound_n[itrack_multifound]=micount; - itrack_multifound++; + + Char_t fname[100]; + sprintf(fname,"%s/GoodTracksTPC.root",dir); + + TFile *refFile=TFile::Open(fname,"old"); + if (!refFile || !refFile->IsOpen()) { + ::Info("AliTPCComparison.C","Marking good tracks (will take a while)..."); + if (GoodTracksTPC(dir)) { + ::Error("AliTPCComparison.C","Can't generate the reference file !"); + return 1; + } + } + refFile=TFile::Open(fname,"old"); + if (!refFile || !refFile->IsOpen()) { + ::Error("AliTPCComparison.C","Can't open the reference file !"); + return 2; + } + + TTree *tpcTree=(TTree*)refFile->Get("tpcTree"); + if (!tpcTree) { + ::Error("AliTPCComparison.C","Can't get the reference tree !"); + return 3; + } + TBranch *branch=tpcTree->GetBranch("TPC"); + if (!branch) { + ::Error("AliTPCComparison.C","Can't get the TPC branch !"); + return 4; + } + TClonesArray dummy("AliTrackReference",1000), *refs=&dummy; + branch->SetAddress(&refs); + + + sprintf(fname,"%s/AliESDs.root",dir); + TFile *ef=TFile::Open(fname); + if ((!ef)||(!ef->IsOpen())) { + sprintf(fname,"%s/AliESDtpc.root",dir); + ef=TFile::Open(fname); + if ((!ef)||(!ef->IsOpen())) { + ::Error("AliTPCComparison.C","Can't open AliESDtpc.root !"); + return 5; } - - if (lab==tlab) hfound->Fill(ptg); - else { - track_fake[itrack_fake++]=lab; - hfake->Fill(ptg); + } + AliESDEvent* event = new AliESDEvent(); + TTree* esdTree = (TTree*) ef->Get("esdTree"); + if (!esdTree) { + ::Error("AliTPCComparison.C", "no ESD tree found"); + return 6; + } + event->ReadFromTree(esdTree); + + + //******* Loop over events ********* + Int_t e=0; + while (esdTree->GetEvent(e)) { + cout<GetNumberOfTracks(); + allfound+=nentr; + + if (tpcTree->GetEvent(e++)==0) { + cerr<<"No reconstructable tracks !\n"; + continue; } - Double_t pxpypz[3]; track->GetInnerPxPyPz(pxpypz); - Float_t phi=TMath::ATan2(pxpypz[1],pxpypz[0]); - if (phi<-TMath::Pi()) phi+=2*TMath::Pi(); - if (phi>=TMath::Pi()) phi-=2*TMath::Pi(); - Double_t pt=TMath::Sqrt(pxpypz[0]*pxpypz[0]+pxpypz[1]*pxpypz[1]); - Float_t lam=TMath::ATan2(pxpypz[2],pt); - Float_t pt_1=1/pt; + Int_t ngood=refs->GetEntriesFast(); + allgood+=ngood; - if (TMath::Abs(gt[ngood].code)==11 && ptg>4.) { - hmpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.); - } else { - Float_t phig=TMath::ATan2(gt[ngood].py,gt[ngood].px); - hp->Fill((phi - phig)*1000.); + const Int_t MAX=15000; + //MI change + Int_t track_notfound[MAX], itrack_notfound=0; + Int_t track_fake[MAX], itrack_fake=0; + Int_t track_multifound[MAX],track_multifound_n[MAX],itrack_multifound=0; - Float_t lamg=TMath::ATan2(gt[ngood].pz,ptg); - hl->Fill((lam - lamg)*1000.); + Int_t i; + for (Int_t k=0; kUncheckedAt(k); + Int_t lab=ref->Label(), tlab=-1; + Float_t ptg=TMath::Sqrt(ref->Px()*ref->Px() + ref->Py()*ref->Py()); - hpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.); + if (ptg<1e-33) continue; // for those not crossing 0 pad row + + if (ptgptcuth) continue; + + allselected++; + + hgood->Fill(ptg); + + AliESDtrack *track=0; + for (i=0; iGetTrack(i); + tlab=track->GetTPCLabel(); + if (lab==TMath::Abs(tlab)) break; + } + if (i==nentr) { + track_notfound[itrack_notfound++]=lab; + continue; + } + + //MI change - addition + Int_t micount=0; + Int_t mi; + AliESDtrack * mitrack; + for (mi=0; miGetTrack(mi); + if (lab==TMath::Abs(mitrack->GetTPCLabel())) micount++; + } + if (micount>1) { + track_multifound[itrack_multifound]=lab; + track_multifound_n[itrack_multifound]=micount; + itrack_multifound++; + } + if ((track->GetStatus()&AliESDtrack::kTPCrefit)==0) continue; + if (lab==tlab) hfound->Fill(ptg); + else { + track_fake[itrack_fake++]=lab; + hfake->Fill(ptg); + } + + Double_t pxpypz[3]; track->GetInnerPxPyPz(pxpypz); + Float_t phi=TMath::ATan2(pxpypz[1],pxpypz[0]); + if (phi<-TMath::Pi()) phi+=2*TMath::Pi(); + if (phi>=TMath::Pi()) phi-=2*TMath::Pi(); + Double_t pt=TMath::Sqrt(pxpypz[0]*pxpypz[0]+pxpypz[1]*pxpypz[1]); + Float_t lam=TMath::ATan2(pxpypz[2],pt); + Float_t pt_1=1/pt; + + Int_t pdg=(Int_t)ref->GetLength(); //this is particle's PDG ! + + if (TMath::Abs(pdg)==11 && ptg>4.) {//high momentum electrons + hmpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.); + } else { + Float_t phig=TMath::ATan2(ref->Py(),ref->Px()); + hp->Fill((phi - phig)*1000.); + + Float_t lamg=TMath::ATan2(ref->Pz(),ptg); + hl->Fill((lam - lamg)*1000.); + + hpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.); + } + + Float_t mom=pt/TMath::Cos(lam); + Float_t dedx=track->GetTPCsignal(); + hep->Fill(mom,dedx,1.); + if (TMath::Abs(pdg)==211) //pions + if (mom>0.4 && mom<0.5) { + he->Fill(dedx,1.); + } } - Float_t mom=pt/TMath::Cos(lam); - Float_t dedx=track->GetTPCsignal(); - hep->Fill(mom,dedx,1.); - if (TMath::Abs(gt[ngood].code)==211) - if (mom>0.4 && mom<0.5) { - he->Fill(dedx,1.); - } + cout<<"\nList of Not found tracks :\n"; + for ( i = 0; i< itrack_notfound; i++){ + cout<Clear(); + }// ***** End of the loop over events - Stat_t ng=hgood->GetEntries(), nf=hfound->GetEntries(); - if (ng!=0) cerr<<"\n\nIntegral efficiency is about "<Close(); + delete tpcTree; + refFile->Close(); + + Stat_t ng=hgood->GetEntries(), nf=hfound->GetEntries(); + if (ng!=0) cout<<"\n\nIntegral efficiency is about "<SetYTitle("dE/dX (Arb. Units)"); hep->Draw(); c1->cd(); - gBenchmark->Stop("AliTPCComparison"); - gBenchmark->Show("AliTPCComparison"); - TFile fc("AliTPCComparison.root","RECREATE"); c1->Write(); c2->Write(); fc.Close(); - delete rl; + gBenchmark->Stop("AliTPCComparison"); + gBenchmark->Show("AliTPCComparison"); + return 0; } -Int_t -good_tracks_tpc(GoodTrackTPC *gt, const Int_t max, const char* evfoldname) { - Int_t nt=0; +Int_t GoodTracksTPC(const Char_t *dir) { + if (gAlice) { + delete gAlice->GetRunLoader(); + delete gAlice;//if everything was OK here it is already NULL + gAlice = 0x0; + } + + Char_t fname[100]; + sprintf(fname,"%s/galice.root",dir); - AliRunLoader *rl = AliRunLoader::GetRunLoader(evfoldname); - if (rl == 0x0) { - ::Fatal("AliTPCComparison.C::good_tracks_tpc", - "Can not find Run Loader in Folder Named %s", - evfoldname); + AliRunLoader *rl = AliRunLoader::Open(fname,"COMPARISON"); + if (!rl) { + ::Error("GoodTracksTPC","Can't start session !"); + return 1; } + + rl->LoadgAlice(); + rl->LoadHeader(); + rl->LoadKinematics(); + rl->LoadTrackRefs(); + AliTPCLoader *tpcl = (AliTPCLoader *)rl->GetLoader("TPCLoader"); if (tpcl == 0x0) { - ::Fatal("AliTPCHits2Digits.C","Can not find TPCLoader !"); + ::Error("GoodTracksTPC","Can not find TPCLoader !"); + delete rl; + return 2; } - - rl->LoadgAlice(); - + AliTPC *TPC=(AliTPC*)rl->GetAliRun()->GetDetector("TPC"); Int_t ver = TPC->IsVersion(); - cerr<<"TPC version "<LoadRecPoints(); + else if (ver==2) tpcl->LoadDigits(); + else { + ::Error("GoodTracksTPC","Wrong TPC version !"); + delete rl; + return 3; + } rl->CdGAFile(); AliTPCParamSR *digp=(AliTPCParamSR*)gDirectory->Get("75x40_100x60_150x60"); if (!digp) { - ::Fatal("AliTPCHits2Digits.C","TPC parameters have not been found !"); + ::Error("AliTPCHits2Digits.C","TPC parameters have not been found !"); + delete rl; + return 4; } TPC->SetParam(digp); - rl->LoadHeader(); - - Int_t np = rl->GetHeader()->GetNtrack(); - - Int_t nrow_up=digp->GetNRowUp(); Int_t nrows=digp->GetNRowLow()+nrow_up; Int_t zero=digp->GetZeroSup(); Int_t gap=Int_t(0.125*nrows), shift=Int_t(0.5*gap); Int_t good_number=Int_t(0.4*nrows); - Int_t *good=new Int_t[np]; - Int_t i; - for (i=0; iLoadRecPoints(); - AliTPCClustersArray *pca=new AliTPCClustersArray, &ca=*pca; - ca.Setup(digp); - ca.SetClusterType("AliTPCcluster"); - ca.ConnectTree(tpcl->TreeR()); - Int_t nrows=Int_t(ca.GetTree()->GetEntries()); - for (Int_t n=0; nGetNumberOfEvents(); + ::Info("GoodTracksTPC","Number of events : %d\n",nev); + + + sprintf(fname,"%s/GoodTracksTPC.root",dir); + TFile *file=TFile::Open(fname,"recreate"); + + TClonesArray dummy("AliTrackReference",1000), *refs=&dummy; + TTree tpcTree("tpcTree","Tree with info about the reconstructable TPC tracks"); + tpcTree.Branch("TPC",&refs); + + //******** Loop over generated events + for (Int_t e=0; eClear(); + + Int_t i; + + rl->GetEvent(e); file->cd(); + + Int_t np = rl->GetHeader()->GetNtrack(); + cout<<"Event "<TreeR()); + Int_t nrows=Int_t(ca.GetTree()->GetEntries()); + for (Int_t n=0; nAdjustSectorRow(s->GetID(),sec,row); @@ -433,29 +484,27 @@ good_tracks_tpc(GoodTrackTPC *gt, const Int_t max, const char* evfoldname) { good[lab]++; } ca.ClearRow(sec,row); - } - delete pca; - tpcl->UnloadRecPoints(); - } - break; - case 2: - { - tpcl->LoadDigits(); - TTree *TD=tpcl->TreeD(); + } + delete pca; + } + break; + case 2: + { + TTree *TD=tpcl->TreeD(); - AliSimDigits da, *digits=&da; - TD->GetBranch("Segment")->SetAddress(&digits); + AliSimDigits da, *digits=&da; + TD->GetBranch("Segment")->SetAddress(&digits); - Int_t *count = new Int_t[np]; - Int_t i; - for (i=0; iGetEntries(); - for (i=0; iGetEntries(); + for (i=0; iGetEvent(i)) continue; Int_t sec,row; digp->AdjustSectorRow(digits->GetID(),sec,row); - //PH cerr<First(); do { //Many thanks to J.Chudoba who noticed this Int_t it=digits->CurrentRow(), ip=digits->CurrentColumn(); @@ -482,102 +531,93 @@ good_tracks_tpc(GoodTrackTPC *gt, const Int_t max, const char* evfoldname) { } count[j]=0; } - } - delete[] count; - tpcl->UnloadDigits(); + } + delete[] count; + } + break; } - break; - default: - ::Fatal("AliTPCComparison.C","Invalid TPC version !"); - } - rl->LoadKinematics(); - AliStack* stack = rl->Stack(); - /** select tracks which are "good" enough **/ - for (i=0; iParticle(i); - if (p == 0x0) - { + + //****** select tracks which are "good" enough + AliStack* stack = rl->Stack(); + for (i=0; iParticle(i); + if (p == 0x0) { cerr<<"Can not get particle "<Pt()<0.100) continue; - if (TMath::Abs(p->Pz()/p->Pt())>0.999) continue; - - Double_t vx=p->Vx(),vy=p->Vy(); - if (TMath::Sqrt(vx*vx+vy*vy)>3.5) continue; - - /* - Int_t j=p->GetFirstMother(); - if (j>=0) { - TParticle *pp = (TParticle*)stack->Particle(j); - if (pp == 0x0) - { - cerr<<"Can not get particle "<GetFirstMother()>=0) continue;//only one decay is allowed - // for cascade hyperons only - Int_t jj=pp->GetFirstMother(); - if (jj>=0) { - TParticle *ppp = (TParticle*)stack->Particle(jj); - if (ppp->GetFirstMother()>=0) continue;//two decays are allowed } + if (p->Pt()<0.100) continue; + if (TMath::Abs(p->Pz()/p->Pt())>0.999) continue; - } - */ - - gt[nt].lab=i; - gt[nt].code=p->GetPdgCode(); - gt[nt].px=0.; gt[nt].py=0.; gt[nt].pz=0.; - gt[nt].x=0.; gt[nt].y=0.; gt[nt].z=0.; - nt++; - if (nt==max) {cerr<<"Too many good tracks !\n"; break;} - // cerr<UnloadKinematics(); + Double_t vx=p->Vx(),vy=p->Vy(),vz=p->Vz(); + if (TMath::Sqrt(vx*vx+vy*vy)>3.5) continue; + if (TMath::Abs(vz) > 50.) continue; - /** check if there is also information at the entrance of the TPC **/ - - rl->LoadTrackRefs(); - TTree *TR=rl->TreeTR(); - TBranch *branch=TR->GetBranch("TPC"); - if (branch==0) { - ::Fatal("AliTPCComparison.C::good_tracks_tpc","No track references !"); - } - TClonesArray *references=new TClonesArray("AliTrackReference",1000); - branch->SetAddress(&references); - np=(Int_t)TR->GetEntries(); - for (i=0; iClear(); - TR->GetEvent(i); - Int_t nref=references->GetEntriesFast(); - if (nref==0) continue; - AliTrackReference *ref=(AliTrackReference*)references->UncheckedAt(0); - - Int_t j, lab=ref->Label(); - for (j=0; jPx(); gt[j].py=ref->Py(); gt[j].pz=ref->Pz(); - gt[j].x = ref->LocalX(); - gt[j].y = ref->LocalY(); - gt[j].z = ref->Z(); - } + AliTrackReference *ref=new((*refs)[nt]) AliTrackReference(); + + ref->SetLabel(i); + Int_t pdg=p->GetPdgCode(); + ref->SetLength(pdg); //This will the particle's PDG ! + ref->SetMomentum(0.,0.,0.); + ref->SetPosition(0.,0.,0.); + + nt++; + } + + //**** check if there is also information at the entrance of the TPC + TTree *TR=rl->TreeTR(); + TBranch *branch=TR->GetBranch("TrackReferences"); + if (branch==0) { + ::Error("GoodTracksTPC","No track references !"); + delete rl; + return 5; + } + TClonesArray tpcdummy("AliTrackReference",1000), *tpcRefs=&tpcdummy; + branch->SetAddress(&tpcRefs); + Int_t nr=(Int_t)TR->GetEntries(); + for (Int_t r=0; rGetEvent(r); + + Int_t nref = tpcRefs->GetEntriesFast(); + if (!nref) continue; + AliTrackReference *tpcRef= 0x0; + for (Int_t iref=0; irefUncheckedAt(iref); + if (tpcRef->DetectorId() == AliTrackReference::kTPC) break; + tpcRef = 0x0; + } + + if (!tpcRef) continue; + + Int_t j; + AliTrackReference *ref=0; + for (j=0; jUncheckedAt(j); + if (ref->Label()==tpcRef->Label()) break; + ref=0; + } + if (ref==0) continue; + + ref->SetMomentum(tpcRef->Px(),tpcRef->Py(),tpcRef->Pz()); + ref->SetPosition(tpcRef->LocalX(),tpcRef->LocalY(),tpcRef->Z()); + + tpcRefs->Clear(); + } + + tpcTree.Fill(); + + delete[] good; + } //****** end of the loop over generated events - delete references; - delete[] good; - tpcl->UnloadHits(); - rl->UnloadTrackRefs(); - rl->UnloadgAlice(); + tpcTree.Write(); + file->Close(); - gBenchmark->Stop("AliTPCComparison"); - gBenchmark->Show("AliTPCComparison"); - return nt; + delete rl; + return 0; }