]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/global/FlatESDConverter.C
fix AliHLTGlobalEsdConverterComponent
[u/mrichter/AliRoot.git] / HLT / global / FlatESDConverter.C
CommitLineData
251a2c81 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"
6eb01754 15#include "AliESDfriendTrack.h"
16#include "../TPC/Rec/AliTPCseed.h"
251a2c81 17#include <TFile.h>
18#include <TTree.h>
19#include <TSystem.h>
20#include "./AliFlatESDEvent.h"
21#include "./AliFlatESDTrack.h"
5ec8009a 22#include "./AliFlatESDTrigger.h"
251a2c81 23#include "./AliFlatTPCCluster.h"
24#include "./AliFlatExternalTrackParam.h"
25#include "Riostream.h"
d3b8c07f 26#include "AliSysInfo.h"
251a2c81 27#endif
28
6eb01754 29void 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) {
aeea6e3d 30
5ec8009a 31 if(useESDFriends) Printf("using friends");
32 if(useHLTtree) Printf("using HLT tree");
33
34
251a2c81 35 // -- Convert AliESDEvent to AliFlatESDEvent
5ec8009a 36/*
37 if ( access( filename, F_OK ) == -1 ){
38 Printf("input file not readable!");
39 return;
40 }
41*/
251a2c81 42
5ec8009a 43 TFile *file = new TFile(Form("%s", filename));
44
45
d5b8cffe 46 ofstream outFile(Form("%s",filenameOut), std::ifstream::binary | std::ifstream::out);
251a2c81 47 //ofstream outFile("outFlatESD.dat");
48
5ec8009a 49
aeea6e3d 50 TTree *esdTree = useHLTtree? dynamic_cast<TTree*>(file->Get("HLTesdTree")) : dynamic_cast<TTree*>(file->Get("esdTree"));
251a2c81 51
52 // -- Connect ESD
53 AliESDEvent *esd = new AliESDEvent;
54 esd->ReadFromTree(esdTree);
55
56 // -- Connect ESD friend
57 AliESDfriend *esdFriend = NULL;
58 if (useESDFriends && !esdTree->FindBranch("ESDfriend.")) {
d5b8cffe 59 esdTree->AddFriend("esdFriendTree", Form("%s", filenameFriends));
251a2c81 60 esdTree->SetBranchStatus("ESDfriend.", 1);
5ec8009a 61 esdFriend = (AliESDfriend*)esd->FindListObject("AliESDfriend");
251a2c81 62 if (esdFriend)
63 esdTree->SetBranchAddress("ESDfriend.", &esdFriend);
64 } // if (!esdTree->FindBranch("ESDfriend.")) {
5ec8009a 65 ;
251a2c81 66 AliFlatESDEvent *flatEsd = NULL;
67
68 // -- Event Loop
8f658767 69 for (Int_t idxEvent = 0; idxEvent < esdTree->GetEntries(); idxEvent++) {
aeea6e3d 70 Printf("Processing event nr %d", idxEvent);
5ec8009a 71 // esd->SaveAs("esdTemp.root");
72 // TFile fTmp = TFile("esdTemp.root");
73 Int_t sizeIn = 1;//fTmp.GetSize();
aeea6e3d 74
75 AliSysInfo::AddStamp("getEntry",0,0,idxEvent);
76
251a2c81 77 esdTree->GetEntry(idxEvent);
78 // -- Book memory for AliFlatESDEvent
aeea6e3d 79 // -- TEST >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
251a2c81 80
5ec8009a 81 Int_t size = AliFlatESDEvent::EstimateSize(esd, kTRUE);
82 Byte_t *mem = new Byte_t[size];
f009a562 83
f009a562 84 flatEsd = reinterpret_cast<AliFlatESDEvent*>(mem);
aeea6e3d 85 new (flatEsd) AliFlatESDEvent;
5ec8009a 86
87
88
aeea6e3d 89 AliSysInfo::AddStamp("DoEvent.Start",0,0,idxEvent);
251a2c81 90 // -- Fill AliFlatESDEvent
8f658767 91
5ec8009a 92 Int_t err= flatEsd->SetFromESD( size, esd, kTRUE );
93
94 if(err) Printf("!!! Error while filling flatESD event %d!!!", err);
95 Printf("trigger classes: %d size: %d , = %d",flatEsd->GetNumberOfTriggerClasses(), sizeof(AliFlatESDTrigger) , flatEsd->GetNumberOfTriggerClasses() *sizeof(AliFlatESDTrigger) );
aeea6e3d 96 AliSysInfo::AddStamp("DoEvent.Stop",sizeIn,flatEsd->GetSize(),idxEvent);
97
5ec8009a 98 if(useESDFriends){
99 Printf("ESD : Event %d || V0s %d || Tracks %d | FRIEND Tracks %d || estimated size %llu",
100 idxEvent, esd->GetNumberOfV0s(),esd->GetNumberOfTracks(), esdFriend->GetNumberOfTracks(),
101 AliFlatESDEvent::EstimateSize(esd, useESDFriends));
102 Printf("FLAT: Event %d || V0s %d || Tracks %d | FRIEND Tracks %d || estimated size %llu",
103 idxEvent, flatEsd->GetNumberOfV0s(),flatEsd->GetNumberOfTracks(), esdFriend->GetNumberOfTracks(), flatEsd->GetSize());
104 }
105 else{
106 Printf("ESD : Event %d || V0s %d || Tracks %d || estimated size %llu ",
107 idxEvent,esd->GetNumberOfV0s(), esd->GetNumberOfTracks(),
108 AliFlatESDEvent::EstimateSize(esd, useESDFriends) );
109 Printf("FLAT: Event %d || V0s %d || Tracks %d || estimated size %llu ",
110 idxEvent, flatEsd->GetNumberOfV0s(),flatEsd->GetNumberOfTracks(), flatEsd->GetSize());
111 }
112 AliFlatESDTrack *track = const_cast<AliFlatESDTrack*> (flatEsd->GetTracks());
aeea6e3d 113 for (Int_t idxTrack = 0; idxTrack < flatEsd->GetNumberOfTracks(); ++idxTrack) {
114 AliESDtrack *esdTrack = esd->GetTrack(idxTrack);
5ec8009a 115 AliESDfriendTrack *friendTrack = useESDFriends ? esdFriend->GetTrack(idxTrack) :NULL;
aeea6e3d 116 if (track && !esdTrack) {
117 Printf("ERROR THIS SHOULD NOT HAPPEN AT ALL !!! TRACK %d HAS NO ESD TRACK!!!", idxTrack);
118 return;
6eb01754 119 }
5ec8009a 120 if (verbose) {
aeea6e3d 121 if (track) {
5ec8009a 122 const AliFlatExternalTrackParam* exp1 = track->GetFlatTrackParamCp();
123 const AliFlatExternalTrackParam* exp2 = track->GetFlatTrackParamIp();
124 const AliFlatExternalTrackParam* exp3 = track->GetFlatTrackParamTPCInner();
125 const AliFlatExternalTrackParam* exp4 = track->GetFlatTrackParamOp();
aeea6e3d 126
127 Float_t alphaFLAT[4] = {0., 0., 0., 0.};
128 if (exp1) alphaFLAT[0] = exp1->GetAlpha();
129 if (exp2) alphaFLAT[1] = exp2->GetAlpha();
130 if (exp3) alphaFLAT[2] = exp3->GetAlpha();
131 if (exp4) alphaFLAT[3] = exp4->GetAlpha();
132
133 Float_t alphaOLD[4] = {0., 0., 0., 0.};
134 if (esdTrack->GetConstrainedParam()) alphaOLD[0] = esdTrack->GetConstrainedParam()->GetAlpha();
135 if (esdTrack->GetInnerParam()) alphaOLD[1] = esdTrack->GetInnerParam()->GetAlpha();
136 if (esdTrack->GetTPCInnerParam()) alphaOLD[2] = esdTrack->GetTPCInnerParam()->GetAlpha();
137 if (esdTrack->GetOuterParam()) alphaOLD[3] = esdTrack->GetOuterParam()->GetAlpha();
138
139 Printf("TEST: FlatTrack %d > FlatExternalTrackParam > %p %p %p %p", idxTrack, exp1, exp2, exp3, exp4);
140 Printf("TEST: FlatTrack %d > Alpha %f %f %f %f", idxTrack, alphaFLAT[0], alphaFLAT[1], alphaFLAT[2], alphaFLAT[3]);
141 Printf("TEST: Old Track %d > Alpha %f %f %f %f", idxTrack, alphaOLD[0], alphaOLD[1], alphaOLD[2], alphaOLD[3]);
142 Printf("TEST: Diff %d > Alpha %f %f %f %f", idxTrack,
143 alphaFLAT[0]-alphaOLD[0], alphaFLAT[1]-alphaOLD[1], alphaFLAT[2]-alphaOLD[2], alphaFLAT[3]-alphaOLD[3]);
144
145 Int_t nCl = track->GetNumberOfTPCClusters();
146 Printf("TEST: FlatTrack %d has %d FlatClusters", idxTrack, nCl);
5ec8009a 147
148#if 0
aeea6e3d 149 if(nCl && useESDFriends && verbose > 1){
150 TObject* calibObject = NULL;
151 AliTPCseed* seed = NULL;
152 for (Int_t idx = 0; (calibObject = friendTrack->GetCalibObject(idx)); ++idx) {
153 if ((seed = dynamic_cast<AliTPCseed*>(calibObject))) break;
154 }
155 // -- Fill cluster
156 if (seed) {
157 Int_t idxRow2=0;
158 for (Int_t idxRow = 0; idxRow < nCl; idxRow++){
159 AliFlatTPCCluster * cl = track->GetTPCCluster(idxRow);
160 cout << " idx fX fY fZ fSigmaY2 fSigmaZ2 fCharge fQMax fPadRow" << endl;
161 if(cl){
162 cout << idxRow << " " << cl->GetX() << " " << cl->GetY() << " " << cl->GetZ() << " " << cl->GetSigmaY2() << " " << cl->GetSigmaZ2() << " " << cl->GetCharge() << " " << cl->GetQMax() << " " << cl->GetPadRow() << endl;
163 }
164 else{
165 cout << idxRow << "---------------------------------" << endl << endl;
166 }
167 AliTPCclusterMI* cl2 = NULL;
168 while(!cl2 && idxRow2<160){
169 cl2 = seed->GetClusterPointer(idxRow2++);
170 }
171 if (cl2) {
172 //cout<<" normalCl fX fY fZ fPadRow fSigmaY2 fSigmaZ2 fCharge fQMax" <<endl;
173 cout << idxRow << " " << cl2->GetX() << " " << cl2->GetY() << " " << cl2->GetZ() << " " << cl2->GetSigmaY2() << " " << cl2->GetSigmaZ2() << " " << cl2->GetQ() << " " << cl2->GetMax() << " " << cl2->GetRow() << endl << endl;
174 }
6eb01754 175 else
aeea6e3d 176 cout << idxRow << "---------------------------------" << endl << endl;
177 }
178 }
179 }
5ec8009a 180#endif
181
aeea6e3d 182 }
5ec8009a 183 track = const_cast<AliFlatESDTrack*> (track->GetNextTrack() );
251a2c81 184 }
251a2c81 185 }
251a2c81 186
187 outFile.write(reinterpret_cast<char*>(mem), flatEsd->GetSize());
251a2c81 188 delete[] mem;
189
190 } // for (Int_t idxEvent = 1; idxEvent < 2; idxEvent++) {
191
192 outFile.close();
193
194 return;
195}