2de42a1160840bdeaa9225cbac4ca78d70ede17d
[u/mrichter/AliRoot.git] / TPC / AliTPCSavePID.C
1 /// \file AliTPCSavePID.C
2 /// 
3 /// \author Dubna, 22 Jan 2003
4
5 Int_t AliTPCSavePID(Int_t emax=3) {
6 ///////////////////////////////////////
7 #include<fstream.h>
8 TFile *inkin = TFile::Open("galice.root");
9 if (!inkin->IsOpen()) {
10   cerr<<"Can't open galice.root !\n";
11 }                                                                                        
12 gAlice = (AliRun*)inkin->Get("gAlice");
13 cout<<"AliRun object found on file "<<gAlice<<endl;
14 cout<<"!!!! field ="<<gAlice->Field()->SolenoidField()<<endl;
15 AliKalmanTrack::SetFieldMap(gAlice->Field());
16 inkin->Close();                                  
17  cout<<" Convconst="<<AliKalmanTrack::GetConvConst()<<endl;
18 /////////////////////////////////////// 
19 AliTPCtrack *iotrack=0; 
20 TFile *tf=TFile::Open("AliTPCtracks.root");
21    if (!tf->IsOpen()) {cerr<<"Can't open AliTPCtracks.root !\n"; return 3;}
22                                         
23 AliTPCPid pid;
24 AliTPCtrackPid pidtmp;                                                                
25 AliTPCtrackPid *outpid=&pidtmp;
26 TFile fpid("AliTPCtracksPid.root","recreate");
27
28  Int_t nentr=0,i=0;
29  for(int je=0;je<emax;je++){
30    char tname[100]; sprintf(tname,"TreeT_TPC_%d",je);
31    TTree *tracktree=(TTree*)tf->Get(tname);
32    if (!tracktree) {cerr<<"Can't get a tree with TPC tracks !\n"; return 4;}
33
34    TBranch *tbranch=tracktree->GetBranch("tracks");
35    nentr=(Int_t)tracktree->GetEntries();
36    cout<<nentr<<" "<<" tracks in track tree "<<tname<<"."<<endl;
37
38     char tpname[100]; sprintf(tpname,"TreeT%d",je);
39     TTree *ptree = new  TTree(tpname,"Tree with PID"); 
40     ptree->Branch("pids","AliTPCtrackPid",&outpid,32000,1); 
41
42    for (i=0; i<nentr; i++) {
43        iotrack=new AliTPCtrack;
44        tbranch->SetAddress(&iotrack);
45        tracktree->GetEvent(i);
46       Double_t par[5],xx;xx=85.1951;
47       iotrack->PropagateTo(xx); 
48       iotrack->GetExternalParameters(xx,par);
49       //cout<<" par="<<par[0]<<" "<<par[1]<<" "<<par[2]<<" "<<par[3]<<" "<<par[4]<<endl;
50       Float_t phi=TMath::ASin(par[2]) + iotrack->GetAlpha();
51       if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
52       if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
53       Float_t lam=TMath::ATan(par[3]); 
54       Float_t pt_1=TMath::Abs(par[4]);
55       //cout<<"pt_1,lam="<<pt_1<<" "<<lam<<endl;
56     if(pt_1!=0.){
57       Float_t mom=1./(pt_1*TMath::Cos(lam));
58       Float_t dedx=iotrack->GetdEdx();
59       Int_t pcode=pid.GetPcode(dedx/50.,mom);
60        pidtmp.fPcode=pcode;
61        pidtmp.fSignal=dedx;
62        pidtmp.fMom=mom;
63        pidtmp.fPhi=phi;
64        pidtmp.fLam=lam;
65        pidtmp.fWpi=pid.fWpi;
66        pidtmp.fWk=pid.fWk;
67        pidtmp.fWp=pid.fWp;
68        pidtmp.fLabel=TMath::Abs(iotrack->GetLabel());
69        cout<<"tlab,dedx,mom,pcode="<<pidtmp.fLabel<<" "<<dedx<<" "<<mom<<" "<<pcode<<endl;      
70        ptree->Fill();
71      }//if(pt...
72    }//for(i...
73   cout<<"Event "<<je+1<<" ok."<<endl;      
74    delete tracktree; 
75  }//End for(je...)   
76 tf->Close();
77 fpid.Write();
78 cout<<"File AliTPCtracksPid.root written"<<endl;
79 return 0;
80 }