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