Update master to aliroot
[u/mrichter/AliRoot.git] / TPC / macros / AliEveTree.C
1 /// \file AliEveTree.C
2 ///
3 /// ~~~{.cpp}
4 /// .L $ALICE_ROOT/TPC/macros/AliEveTree.C+
5 /// MakeEveTree();
6 /// 
7 /// TFile fesd("AliESDs.root");
8 /// TTree * treeESD = (TTree*)fesd.Get("esdTree");
9 ///
10 /// TFile ftpc("TPCdebug.root");
11 /// TFile fits("ITSdebug.root");
12 /// TTree * treeTPC = (TTree*)ftpc.Get("Transform");
13 /// TTree * treeITS = (TTree*)fits.Get("Clusters");
14 ///   
15 /// treeTPC->Draw("gx2/sqrt(gx0^2+gx1^2):sqrt(gx0^2+gx1^2)>>his(100,0,200,100,-1,1)","event==4","")
16 /// treeITS->Draw("gz/sqrt(gx^2+gy^2):sqrt(gx^2+gy^2)>>his(100,0,200,100,-1,1)","event==4","same")
17 /// 
18 /// treeTPC->Draw("atan2(gx1,gx0):sqrt(gx0^2+gx1^2)>>his(100,0,200,100,-1,1)","event==4","*")
19 /// treeITS->Draw("atan2(gy,gx):sqrt(gx^2+gy^2)>>his(100,0,200,100,-1,1)","event==4","same*");
20 /// ~~~
21
22 #include "TFile.h"
23 #include "TTree.h"
24 #include "TTreeStream.h"
25 #include "TPolyMarker3D.h"
26 #include "TVectorD.h"
27
28 #include "AliESDEvent.h"
29 #include "AliESDtrack.h"
30 #include "AliESDfriendTrack.h"
31 #include "AliTrackPointArray.h"
32
33
34 AliTrackPointArray* MakeArray(TPolyMarker3D *pol);
35 void MakeESDTree(AliESDEvent*esd, TTreeSRedirector &cstream);
36
37 void MakeEveTree(){
38   TFile fesd("AliESDs.root");
39   TTree * esdTree = (TTree*)fesd.Get("esdTree");
40   AliESDEvent cesd; 
41   esdTree->SetBranchStatus("*",kTRUE);
42   cesd.ReadFromTree(esdTree);
43   TTreeSRedirector cstream("eveTree.root");
44   for (Int_t ievent=0; ievent<esdTree->GetEntries();ievent++) {
45     //cout<<endl<<endl<<"********* Processing event number: "<<event<<"*******\n";
46     esdTree->GetEvent(ievent);
47     AliESDfriend *fESDfriend =  (AliESDfriend*)cesd.FindListObject("AliESDfriend");
48     cesd.SetESDfriend(fESDfriend);
49     MakeESDTree(&cesd,cstream);
50   }
51 }
52
53
54 void MakeESDTree(AliESDEvent*esd, TTreeSRedirector &cstream){
55   ///
56
57   Float_t bz = esd->GetMagneticField();
58   //AliTPCseed dummyTPC;
59   //AliTPCseed dummyTRD;
60   for (Int_t i=0;i<esd->GetNumberOfTracks(); i++){
61     AliESDtrack * track = esd->GetTrack(i);
62     if (!track) continue;
63     TPolyMarker3D polA;
64     TPolyMarker3D polV;
65     TPolyMarker3D polI;
66     TPolyMarker3D polO;
67     //
68     AliTrackPointArray * arrayA=0;
69     AliTrackPointArray * arrayV=0;
70     AliTrackPointArray * arrayI=0;
71     AliTrackPointArray * arrayO=0;
72     //
73     if (track->GetInnerParam()) {
74       ((AliExternalTrackParam*)track->GetInnerParam())->FillPolymarker(&polA,bz,0,350,1);}
75     else{
76       track->FillPolymarker(&polA,bz,0,300,5);
77     }
78     arrayA=MakeArray(&polA);
79     track->FillPolymarker(&polV,bz,0,60,1);
80     arrayV=MakeArray(&polV);
81     if (track->GetInnerParam()) {
82       ((AliExternalTrackParam*)track->GetInnerParam())->FillPolymarker(&polI,bz,60,170,1);
83       arrayI = MakeArray(&polI);
84     }
85     if (track->GetOuterParam()) {
86       ((AliExternalTrackParam*)track->GetOuterParam())->FillPolymarker(&polO,bz,170,350,1);    
87       arrayO=MakeArray(&polO);
88     }
89     static  AliTrackPointArray cldummy(5);
90     AliTrackPointArray *clarray= &cldummy;
91     const AliESDfriendTrack *ftrack = track->GetFriendTrack();
92     if (ftrack && ftrack->GetTrackPointArray()) {
93       clarray=(AliTrackPointArray *)ftrack->GetTrackPointArray();
94     }
95     Int_t event = esd->GetEventNumberInFile();
96     Int_t id = track->GetID();
97     cstream<<"Tracks"<<
98       "eventNr="<<event<<
99       "trackNr="<<id<<
100       "Tr.="<<track<<
101       "Cl.="<<clarray<<
102       //
103       "pA.="<<&polA<<
104       "pV.="<<&polV<<
105       "pI.="<<&polI<<
106       "pO.="<<&polO<<
107       //
108       "aA.="<<arrayA<<
109       "aV.="<<arrayV<<
110       "aI.="<<arrayI<<
111       "aO.="<<arrayO<<
112       "\n";
113   }
114 }
115
116
117
118 AliTrackPointArray *MakeArray(TPolyMarker3D *pol){
119   /// Make a aray of  points with errors
120
121   Int_t entries = pol->GetN();
122   AliTrackPointArray * array = new AliTrackPointArray(entries);
123   for (Int_t i=0;i<entries;i++){
124     Double_t xyz[3]={0,0,0};
125     pol->GetPoint(i,xyz[0],xyz[1],xyz[2]);
126     ((Float_t*)array->GetX())[i]=xyz[0];
127     ((Float_t*)array->GetY())[i]=xyz[1];
128     ((Float_t*)array->GetZ())[i]=xyz[2];
129   }
130   return array;
131 }
132