]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/FlatESDConverter.C
8be3570f6444c34cab7850619bef450076b4331d
[u/mrichter/AliRoot.git] / HLT / global / FlatESDConverter.C
1 /**
2  * >> Testing Macro to fill FlatESDEvent from ALiESDEvent <<
3  **
4  * Primary Authors : Sergey Gorbunov, Jochen Thaeder, Chiara Zampolli
5  *
6  * Usage:
7  *  aliroot -b -l -q LoadLibs.C FlatESDConverter.C++
8  *
9  **************************************************************************/
10
11 #if !defined(__CINT__) || defined(__MAKECINT__)
12 #include "AliESDEvent.h"
13 #include "AliESD.h"
14 #include "AliESDfriend.h"
15 #include "AliESDfriendTrack.h"
16 #include "../TPC/Rec/AliTPCseed.h"
17 #include <TFile.h>
18 #include <TTree.h>
19 #include <TSystem.h>
20 #include "./AliFlatESDEvent.h"
21 #include "./AliFlatESDTrack.h"
22 #include "./AliFlatTPCCluster.h"
23 #include "./AliFlatExternalTrackParam.h"
24 #include "Riostream.h"
25 #include "AliSysInfo.h"
26 #endif   
27
28 void FlatESDConverter(const char* filename="AliESDs.root", const char* filenameFriends="AliESDfriends.root",const char* filenameOut="out.dat", Bool_t useESDFriends = kTRUE, Bool_t useHLTtree = kFALSE,Int_t verbose = 0) {
29   // -- Convert AliESDEvent to AliFlatESDEvent
30
31   ofstream outFile(Form("%s",filenameOut), std::ifstream::binary | std::ifstream::out);
32   //ofstream outFile("outFlatESD.dat");
33
34   TFile *file    = new TFile(Form("%s", filename));
35         
36         TTree *esdTree = useHLTtree? dynamic_cast<TTree*>(file->Get("HLTesdTree")) : dynamic_cast<TTree*>(file->Get("esdTree"));
37
38   
39   // -- Connect ESD
40   AliESDEvent *esd = new AliESDEvent;
41   esd->ReadFromTree(esdTree);
42   
43   // -- Connect ESD friend
44   AliESDfriend *esdFriend = NULL; 
45   if (useESDFriends && !esdTree->FindBranch("ESDfriend.")) {
46     esdTree->AddFriend("esdFriendTree", Form("%s", filenameFriends));
47     esdTree->SetBranchStatus("ESDfriend.", 1);
48
49     esdFriend = dynamic_cast<AliESDfriend*>((const_cast<AliESDEvent*>(esd))->FindListObject("AliESDfriend"));
50     if (esdFriend)
51       esdTree->SetBranchAddress("ESDfriend.", &esdFriend);
52   } // if (!esdTree->FindBranch("ESDfriend.")) {
53   
54   AliFlatESDEvent *flatEsd = NULL;
55
56   // -- Event Loop
57   for (Int_t idxEvent = 0; idxEvent < esdTree->GetEntries(); idxEvent++) {
58   
59   AliSysInfo::AddStamp("getEntry",0,0,idxEvent);
60     esdTree->GetEntry(idxEvent);
61     // -- Book memory for AliFlatESDEvent
62    // -- TEST >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
63
64     Byte_t *mem = new Byte_t[AliFlatESDEvent::EstimateSize(esd, useESDFriends)];
65     
66 AliSysInfo::AddStamp("DoEvent.Start",0,0,idxEvent);
67     flatEsd = reinterpret_cast<AliFlatESDEvent*>(mem);    
68         new (flatEsd) AliFlatESDEvent(1);
69
70     // -- Fill AliFlatESDEvent
71     flatEsd->Fill(esd, useESDFriends);  
72     
73     
74 AliSysInfo::AddStamp("DoEvent.Stop",0,flatEsd->GetSize(),idxEvent);
75 if(verbose){
76      Printf("TEST: Event %d || Tracks %d | FRIEND Tracks %d || estimated size %llu || sizeof(AliFlatESDEvent) %llu", 
77            idxEvent, esd->GetNumberOfTracks(), esdFriend->GetNumberOfTracks(), 
78            AliFlatESDEvent::EstimateSize(esd, useESDFriends), flatEsd->GetSize());
79
80
81     AliFlatESDTrack *track = flatEsd->GetTracks();
82     for (Int_t idxTrack = 0; idxTrack < flatEsd->GetNumberOfTracks(); ++idxTrack) {      
83        AliESDtrack *esdTrack = esd->GetTrack(idxTrack);      
84        AliESDfriendTrack *friendTrack = esdFriend->GetTrack(idxTrack) ;
85        
86        if (track && !esdTrack) {
87          Printf("ERROR THIS SHOULD NOT HAPPEN AT ALL !!! TRACK %d HAS NO ESD TRACK!!!", idxTrack);
88          return;
89        }
90
91       if (track ) {
92         
93         /*
94         AliFlatExternalTrackParam* exp1 = track->GetTrackParamCp();
95         AliFlatExternalTrackParam* exp2 = track->GetTrackParamIp();
96         AliFlatExternalTrackParam* exp3 = track->GetTrackParamTPCInner();
97         AliFlatExternalTrackParam* exp4 = track->GetTrackParamOp();
98
99         Float_t alphaFLAT[4] = {0., 0., 0., 0.};
100         if (exp1) alphaFLAT[0] = exp1->GetAlpha();
101         if (exp2) alphaFLAT[1] = exp2->GetAlpha();
102         if (exp3) alphaFLAT[2] = exp3->GetAlpha();
103         if (exp4) alphaFLAT[3] = exp4->GetAlpha();
104         
105         Float_t alphaOLD[4]  = {0., 0., 0., 0.};
106         if (esdTrack->GetConstrainedParam())  alphaOLD[0] = esdTrack->GetConstrainedParam()->GetAlpha();
107         if (esdTrack->GetInnerParam())        alphaOLD[1] = esdTrack->GetInnerParam()->GetAlpha();
108         if (esdTrack->GetTPCInnerParam())     alphaOLD[2] = esdTrack->GetTPCInnerParam()->GetAlpha();
109         if (esdTrack->GetOuterParam())        alphaOLD[3] = esdTrack->GetOuterParam()->GetAlpha();
110
111         Printf("  TEST: FlatTrack %d > FlatExternalTrackParam > %p %p %p %p", idxTrack, exp1, exp2, exp3, exp4);
112         Printf("  TEST: FlatTrack %d > Alpha %f %f %f %f", idxTrack, alphaFLAT[0], alphaFLAT[1], alphaFLAT[2], alphaFLAT[3]);
113         Printf("  TEST: Old Track %d > Alpha %f %f %f %f", idxTrack, alphaOLD[0], alphaOLD[1], alphaOLD[2], alphaOLD[3]);
114         Printf("  TEST: Diff      %d > Alpha %f %f %f %f", idxTrack, 
115                alphaFLAT[0]-alphaOLD[0], alphaFLAT[1]-alphaOLD[1], alphaFLAT[2]-alphaOLD[2], alphaFLAT[3]-alphaOLD[3]);
116 */
117
118 Int_t nCl = track->GetNumberOfTPCClusters();
119         Printf("  TEST: FlatTrack %d has %d FlatClusters", idxTrack,  nCl );
120         if(nCl && verbose > 1){
121         
122           TObject* calibObject = NULL;
123     AliTPCseed* seed = NULL;
124
125     for (Int_t idx = 0; (calibObject = friendTrack->GetCalibObject(idx)); ++idx) {
126       if ((seed = dynamic_cast<AliTPCseed*>(calibObject))) break;
127     }
128
129     // -- Fill cluster
130     if (seed) {
131     
132     Int_t idxRow2=0;
133       for (Int_t idxRow = 0; idxRow <  nCl; idxRow++){
134       AliFlatTPCCluster * cl = track->GetTPCCluster(idxRow);
135       
136
137                                 cout<<" idx fX fY fZ  fSigmaY2 fSigmaZ2 fCharge fQMax fPadRow" <<endl;
138                                 cout<< idxRow <<" "<< cl->GetX()<<" "<< cl->GetY()<<" "<< cl->GetZ()<<" "<< cl->GetSigmaY2()<<" "<< cl->GetSigmaZ2()<<" "<< cl->GetCharge()<<" "<< cl->GetQMax() <<" "<< cl->GetPadRow()<<endl;
139                                 
140                                 AliTPCclusterMI* cl2 = NULL; 
141       while(!cl2 && idxRow2<160){
142         cl2 = seed->GetClusterPointer(idxRow2++);
143       }
144         if (cl2) {
145           //cout<<" normalCl fX fY fZ fPadRow fSigmaY2 fSigmaZ2 fCharge fQMax" <<endl;
146                                 cout<< idxRow <<" "<< cl2->GetX()<<" "<< cl2->GetY()<<" "<< cl2->GetZ()<<" "<< cl2->GetSigmaY2()<<" "<< cl2->GetSigmaZ2()<<" "<< cl2->GetQ()<<" "<< cl2->GetMax()<<" "<< cl2->GetRow() <<endl<<endl;
147         }
148                 else
149                         cout<<idxRow<<"---------------------------------"<<endl<<endl;  
150       }
151     }
152         }
153         
154       }
155       track = track->GetNextTrack();
156     }
157 }
158
159     outFile.write(reinterpret_cast<char*>(mem), flatEsd->GetSize());
160
161     delete[] mem; 
162
163   } // for (Int_t idxEvent = 1; idxEvent < 2; idxEvent++) {
164
165   outFile.close();
166
167   return;
168 }