]>
Commit | Line | Data |
---|---|---|
e75b3800 | 1 | /** |
2 | * >> Testing Macro to compare FlatESDEvents from output files << | |
3 | ** | |
4 | * Primary Authors : Steffen Weber | |
5 | * | |
6 | * Usage: | |
7 | * aliroot -b -l -q LoadLibs.C CompareFlatESDs.C++ | |
8 | * | |
9 | **************************************************************************/ | |
10 | ||
11 | #if !defined(__CINT__) || defined(__MAKECINT__) | |
12 | #include "AliESDEvent.h" | |
13 | #include "AliESD.h" | |
14 | #include "AliESDfriend.h" | |
15 | #include <TFile.h> | |
16 | #include <TTree.h> | |
17 | #include <TSystem.h> | |
18 | #include "./AliFlatESDEvent.h" | |
19 | #include "./AliFlatESDTrack.h" | |
20 | #include "./AliFlatTPCCluster.h" | |
21 | #include "./AliFlatExternalTrackParam.h" | |
22 | #include "Riostream.h" | |
e48021f9 | 23 | #include "THnSparse.h" |
e75b3800 | 24 | #endif |
e48021f9 | 25 | Double_t printDiff(string name, double val1, double val2); |
26 | Double_t printDiff(string name, TString val1, TString val2); | |
488e1434 | 27 | void CompareFlatESDs(const char* filename1="outFlatESD1.dat",const char* filename2="outFlatESD2.dat", Bool_t verbose=kFALSE) { |
e75b3800 | 28 | // Create output histograms |
29 | ||
e75b3800 | 30 | |
31 | TString outputFilename = "$PWD/compare.root"; | |
e75b3800 | 32 | |
e48021f9 | 33 | cout<< "creating histograms"<<endl; |
34 | THnSparse * hDiff; | |
35 | const Int_t nDim = 12; | |
36 | ||
37 | Int_t bins[nDim] = {2}; | |
38 | Double_t mins[nDim] = {0}; | |
a2e57ab1 | 39 | Double_t maxs[nDim] = {1}; |
e48021f9 | 40 | hDiff = new THnSparseD("Differences","Differences",nDim,bins,mins,maxs); |
41 | ||
e75b3800 | 42 | |
43 | ||
44 | ifstream is1(filename1, std::ifstream::binary | std::ifstream::in); | |
45 | ifstream is2(filename2, std::ifstream::binary | std::ifstream::in); | |
46 | if (is1 && is2 ){ | |
47 | is1.seekg (0, is1.end); | |
48 | int length1 = is1.tellg(); | |
49 | is1.seekg (0, is1.beg); | |
50 | char * buffer1 = new char [length1]; | |
51 | ||
52 | std::cout << "Reading " << length1 << " characters... "; | |
53 | ||
54 | is1.read (buffer1,length1); | |
55 | if (is1) | |
56 | std::cout << "all characters read successfully." << endl; | |
57 | else | |
58 | std::cout << "error: only " << is1.gcount() << " could be read"; | |
59 | is1.close(); | |
60 | ||
61 | ||
62 | is2.seekg (0, is2.end); | |
63 | int length2 = is2.tellg(); | |
64 | is2.seekg (0, is2.beg); | |
65 | char * buffer2 = new char [length2]; | |
66 | ||
67 | std::cout << "Reading " << length2 << " characters... "; | |
68 | ||
69 | is2.read (buffer2,length2); | |
70 | if (is2) | |
71 | std::cout << "all characters read successfully." << endl; | |
72 | else | |
73 | std::cout << "error: only " << is2.gcount() << " could be read"; | |
74 | is2.close(); | |
75 | ||
76 | ||
77 | ||
78 | // ...buffer contains the entire file... | |
79 | ||
80 | char *curr1 = buffer1; | |
81 | char *endBuff1 = buffer1+length1; | |
82 | ||
83 | char *curr2 = buffer2; | |
84 | char *endBuff2 = buffer2+length2; | |
85 | ||
86 | int iEvent = 0; | |
488e1434 | 87 | static const int nExt = 4; |
e75b3800 | 88 | |
89 | while( curr1 < endBuff1 && curr2 < endBuff2 ){ | |
488e1434 | 90 | //cout<<" curr1 endBuff1 curr2 endBuff2 "<< static_cast<void*> (curr1)<<" "<<static_cast<void*> (endBuff1)<<" "<<static_cast<void*> (curr2)<<" "<<static_cast<void*> (endBuff2)<<endl; |
91 | ||
e75b3800 | 92 | AliFlatESDEvent *flatEsd1 = reinterpret_cast<AliFlatESDEvent *>(curr1); |
93 | AliFlatESDEvent *flatEsd2 = reinterpret_cast<AliFlatESDEvent *>(curr2); | |
e75b3800 | 94 | |
5ec8009a | 95 | flatEsd1->Reinitialize(); |
96 | flatEsd2->Reinitialize(); | |
97 | ||
e48021f9 | 98 | cout<<endl<<"________________________________________________________________________"<<endl; |
99 | cout<<endl<<"Reading event "<<iEvent<<":\t file1 | file 2\t|\t abs. diff\t|\t rel. diff"<<endl; | |
100 | ||
101 | Double_t diffs[nDim] ={ | |
102 | printDiff("GetMagneticField", flatEsd1->GetMagneticField(), flatEsd2->GetMagneticField()), | |
103 | printDiff("GetPeriodNumber", flatEsd1->GetPeriodNumber(), flatEsd2->GetPeriodNumber()), | |
104 | printDiff("GetRunNumber", flatEsd1->GetRunNumber(), flatEsd2->GetRunNumber()), | |
105 | printDiff("GetOrbitNumber", flatEsd1->GetOrbitNumber(), flatEsd2->GetOrbitNumber()), | |
106 | printDiff("GetBunchCrossNumber",flatEsd1->GetBunchCrossNumber(),flatEsd2->GetBunchCrossNumber()), | |
107 | printDiff("GetTriggerMask", flatEsd1->GetTriggerMask(), flatEsd2->GetTriggerMask()), | |
108 | printDiff("GetTriggerMaskNext50",flatEsd1->GetTriggerMaskNext50(), flatEsd2->GetTriggerMaskNext50()), | |
109 | printDiff("GetFiredTriggerClasses", flatEsd1->GetFiredTriggerClasses(), flatEsd2->GetFiredTriggerClasses()), | |
110 | printDiff("GetNumberOfTracks", flatEsd1->GetNumberOfTracks(), flatEsd2->GetNumberOfTracks()), | |
111 | printDiff("GetNumberOfV0s", flatEsd1->GetNumberOfV0s(), flatEsd2->GetNumberOfV0s()), | |
112 | printDiff("GetTimeStamp", flatEsd1->GetTimeStamp(), flatEsd2->GetTimeStamp()), | |
113 | printDiff("GetEventSpecie", flatEsd1->GetEventSpecie(), flatEsd2->GetEventSpecie()) | |
114 | ||
115 | }; | |
116 | ||
117 | hDiff->Fill(diffs); | |
5ec8009a | 118 | |
119 | ||
120 | /* | |
121 | ||
122 | if( (Bool_t) flatEsd1->GetFlatPrimaryVertexTracks() != (Bool_t) flatEsd2->GetFlatPrimaryVertexTracks() ){ | |
123 | cout<<"\t\tDIFFERENCE!: "<<endl; | |
488e1434 | 124 | diff[2] =1; |
125 | } | |
126 | ||
127 | ||
5ec8009a | 128 | cout<<"vtx tracks:\t"<<(Bool_t) flatEsd1->GetFlatPrimaryVertexTracks()<< " | " << (Bool_t) flatEsd2->GetFlatPrimaryVertexTracks()<<endl; |
129 | //hVtxTr->Fill( (Bool_t) flatEsd1->GetFlatPrimaryVertexTracks(), (Bool_t) flatEsd2->GetFlatPrimaryVertexTracks()); | |
488e1434 | 130 | |
e75b3800 | 131 | |
e75b3800 | 132 | |
5ec8009a | 133 | if( (Bool_t) flatEsd1->GetFlatPrimaryVertexSPD() != (Bool_t) flatEsd2->GetFlatPrimaryVertexSPD() ){ |
134 | cout<<"\t\tDIFFERENCE!: "<<endl; | |
488e1434 | 135 | diff[3] =1; |
136 | } | |
5ec8009a | 137 | cout<<"vtx SPD:\t"<<(Bool_t) flatEsd1->GetFlatPrimaryVertexSPD() << " | " << (Bool_t) flatEsd2->GetFlatPrimaryVertexSPD()<<endl; |
138 | //hVtxSPD->Fill( (Bool_t) flatEsd1->GetFlatPrimaryVertexSPD(), (Bool_t) flatEsd2->GetFlatPrimaryVertexSPD()); | |
488e1434 | 139 | |
5ec8009a | 140 | |
141 | ||
142 | if((Bool_t)flatEsd1->GetFlatPrimaryVertexTracks() && (Bool_t)flatEsd2->GetFlatPrimaryVertexTracks() ){ | |
143 | cout<<endl<<"vtx tracks -> X,Y,Z:\t" | |
144 | << flatEsd1->GetFlatPrimaryVertexTracks()->GetX() | |
145 | <<","<< flatEsd1->GetFlatPrimaryVertexTracks()->GetY() | |
146 | <<","<< flatEsd1->GetFlatPrimaryVertexTracks()->GetZ() | |
147 | <<" | " <<flatEsd2->GetFlatPrimaryVertexTracks()->GetX() | |
148 | <<","<< flatEsd2->GetFlatPrimaryVertexTracks()->GetY() | |
149 | <<","<< flatEsd2->GetFlatPrimaryVertexTracks()->GetZ()<<endl; | |
488e1434 | 150 | } |
151 | */ | |
e75b3800 | 152 | |
153 | // compare tracks | |
5ec8009a | 154 | if(verbose){ |
155 | AliFlatESDTrack *track1 = const_cast<AliFlatESDTrack*> (flatEsd1->GetTracks()); | |
156 | AliFlatESDTrack *track2 = const_cast<AliFlatESDTrack*> (flatEsd2->GetTracks()); | |
488e1434 | 157 | for (Int_t idxTrack = 0; idxTrack < flatEsd1->GetNumberOfTracks() && track1 && track2; ++idxTrack) { |
e75b3800 | 158 | |
5ec8009a | 159 | //track2->Reinitialize(); |
160 | const AliFlatExternalTrackParam* ext[2][nExt] ={ | |
488e1434 | 161 | { |
5ec8009a | 162 | track1->GetFlatTrackParamRefitted(), |
163 | track1->GetFlatTrackParamIp(), | |
164 | track1->GetFlatTrackParamTPCInner(), | |
165 | track1->GetFlatTrackParamOp(), | |
166 | // track1->GetFlatTrackParamCp(), | |
167 | // track1->GetFlatTrackParamITSOut() | |
488e1434 | 168 | }, |
169 | { | |
5ec8009a | 170 | track2->GetFlatTrackParamRefitted(), |
171 | track2->GetFlatTrackParamIp(), | |
172 | track2->GetFlatTrackParamTPCInner(), | |
173 | track2->GetFlatTrackParamOp(), | |
174 | // track2->GetFlatTrackParamCp(), | |
175 | // track2->GetFlatTrackParamITSOut() | |
488e1434 | 176 | } |
177 | }; | |
e75b3800 | 178 | |
488e1434 | 179 | //Printf(" TEST: FlatTrack1 %d > FlatExternalTrackParam1 > %p %p %p %p", idxTrack, exp11, exp21, exp31, exp41); |
180 | //Printf(" TEST: FlatTrack2 %d > FlatExternalTrackParam2 > %p %p %p %p", idxTrack, exp12, exp22, exp32, exp42); | |
181 | ||
182 | ||
183 | for(int iExt=0; iExt<nExt; ++iExt){ | |
488e1434 | 184 | if(!ext[0][iExt] && !ext[1][iExt]) continue; |
185 | if(!ext[0][iExt] && ext[1][iExt]){ | |
186 | // cout<<"DIFFERENCE!: "; | |
187 | cout<<" ext"<<iExt<<" not set in "<<filename1<<endl; | |
188 | } | |
189 | if(ext[0][iExt] && !ext[1][iExt]){ | |
190 | // cout<<"DIFFERENCE!: "; | |
191 | cout<<" ext"<<iExt<<" not set in "<<filename2<<endl; | |
192 | } | |
193 | ||
194 | ||
195 | if( (!ext[0][iExt] || !ext[1][iExt])|| ext[0][iExt]->GetAlpha() != ext[1][iExt]->GetAlpha() ) { | |
5ec8009a | 196 | cout<<"\t\tDIFFERENCE!: "<<endl; |
488e1434 | 197 | //cout<<" alpha"<<iExt<<" :" << (ext[0][iExt] ? ext[0][iExt]->GetAlpha() : -99.) << "\t\t" << (ext[1][iExt] ? ext[1][iExt]->GetAlpha(): -99.)<<endl; |
5ec8009a | 198 | } cout<<" alpha"<<iExt<<" :\t" << (ext[0][iExt] ? ext[0][iExt]->GetAlpha() : -99.) << " | " << (ext[1][iExt] ? ext[1][iExt]->GetAlpha(): -99.)<<endl; |
488e1434 | 199 | |
200 | ||
201 | if( (!ext[0][iExt] || !ext[1][iExt])||ext[0][iExt]->GetX() != ext[1][iExt]->GetX() ) { | |
5ec8009a | 202 | cout<<"\t\tDIFFERENCE!: "<<endl; |
488e1434 | 203 | //cout<<" GetX"<<iExt<<" :" << (ext[0][iExt] ? ext[0][iExt]->GetX(): -99.) << " | " << (ext[1][iExt] ? ext[1][iExt]->GetX(): -99.)<<endl; |
488e1434 | 204 | } |
5ec8009a | 205 | cout<<" GetX"<<iExt<<" :\t" << (ext[0][iExt] ? ext[0][iExt]->GetX(): -99.) << " | " << (ext[1][iExt] ? ext[1][iExt]->GetX(): -99.)<<endl; |
488e1434 | 206 | |
207 | ||
208 | if( (!ext[0][iExt] || !ext[1][iExt])||ext[0][iExt]->GetSigned1Pt() != ext[0][iExt]->GetSigned1Pt() ) { | |
5ec8009a | 209 | cout<<"\t\tDIFFERENCE!: "<<endl; |
488e1434 | 210 | //cout<<" 1/pt"<<iExt<<" :" << (ext[0][iExt] ? ext[0][iExt]->GetSigned1Pt(): -99.) << " | " << (ext[1][iExt] ? ext[1][iExt]->GetSigned1Pt(): -99.)<<endl; |
488e1434 | 211 | } |
5ec8009a | 212 | cout<<" 1/pt"<<iExt<<" :\t" << (ext[0][iExt] ? ext[0][iExt]->GetSigned1Pt(): -99.) << " | " << (ext[1][iExt] ? ext[1][iExt]->GetSigned1Pt(): -99.)<<endl; |
488e1434 | 213 | |
214 | ||
215 | } | |
e75b3800 | 216 | |
e75b3800 | 217 | |
488e1434 | 218 | /* |
219 | if( track1->GetNumberOfTPCClusters() != track2->GetNumberOfTPCClusters() ){ | |
220 | cout<<"DIFFERENCE!: "; | |
221 | cout<<" nTPCclusters: "<<track1->GetNumberOfTPCClusters()<< " | " <<track2->GetNumberOfTPCClusters()<< endl; | |
222 | diff[4]=1; | |
223 | } | |
224 | if( track1->GetNumberOfITSClusters() != track2->GetNumberOfITSClusters() ){ | |
225 | cout<<"DIFFERENCE!: "; | |
226 | cout<<" nITSclusters: "<<track1->GetNumberOfITSClusters()<< " | " <<track2->GetNumberOfITSClusters()<< endl; | |
227 | diff[4]=1; | |
228 | } | |
229 | */ | |
5ec8009a | 230 | |
231 | #if 0 | |
488e1434 | 232 | |
233 | // compare clusters | |
234 | if( verbose && track1->GetNumberOfTPCClusters() == track2->GetNumberOfTPCClusters()){ | |
235 | for (Int_t idxCluster = 0; idxCluster < track1->GetNumberOfTPCClusters(); ++idxCluster){ | |
236 | AliFlatTPCCluster * cl1 = track1->GetTPCCluster(idxCluster); | |
237 | AliFlatTPCCluster * cl2 = track2->GetTPCCluster(idxCluster); | |
e75b3800 | 238 | /* |
488e1434 | 239 | if( cl1->GetX()&& cl2->GetX() && cl1->GetX() != cl2->GetX() ){ |
240 | cout<<"DIFFERENCE!: "; | |
241 | cout<<" cluster: "<<idxCluster<<" GetX :"<<cl1->GetX()<< " | " <<cl2->GetX()<< endl; | |
242 | diff=kTRUE; | |
243 | } | |
244 | cout<<" cluster: "<<idxCluster<<" GetX :"<<cl1->GetX()<< " | " <<cl2->GetX()<< endl; | |
245 | cout<<" cluster: "<<idxCluster<<" GetY :"<<cl1->GetY()<< " | " <<cl2->GetY()<< endl; | |
e75b3800 | 246 | |
488e1434 | 247 | if( cl1 && cl2 && cl1->GetY() != cl2->GetY() ){ |
248 | cout<<"DIFFERENCE!: "; | |
249 | cout<<" cluster: "<<idxCluster<<" GetY :"<<cl1->GetY()<< " | " <<cl2->GetY()<< endl; | |
250 | diff=kTRUE; | |
251 | } | |
252 | if( cl1->GetZ()&& cl2->GetZ() && cl1->GetZ() != cl2->GetZ() ){ | |
253 | cout<<"DIFFERENCE!: "; | |
254 | cout<<" cluster: "<<idxCluster<<" GetZ :"<<cl1->GetZ()<< " | " <<cl2->GetZ()<< endl; | |
255 | diff=kTRUE; | |
256 | } | |
257 | */ | |
258 | if( cl1->GetPadRow()&& cl2->GetPadRow() && cl1->GetPadRow() != cl2->GetPadRow() ){ | |
259 | cout<<"DIFFERENCE!: "; | |
260 | cout<<" cluster: "<<idxCluster<<" GetPadRow :"<<cl1->GetPadRow()<< " | " <<cl2->GetPadRow()<< endl; | |
261 | diff[5]=1; | |
262 | } | |
263 | ||
264 | } | |
e75b3800 | 265 | } |
5ec8009a | 266 | |
267 | #endif | |
268 | track1 = const_cast<AliFlatESDTrack*> (track1->GetNextTrack()); | |
269 | track2 = const_cast<AliFlatESDTrack*> (track2->GetNextTrack()); | |
e75b3800 | 270 | |
271 | ||
488e1434 | 272 | } |
5ec8009a | 273 | } |
274 | ||
275 | /* | |
276 | // hStat->Fill(0); | |
488e1434 | 277 | Bool_t diffs=kFALSE; |
278 | for(int iDiff=0; iDiff<5;++iDiff){ | |
279 | if(diff[iDiff]){ | |
5ec8009a | 280 | // hStat->Fill(iDiff+2); |
488e1434 | 281 | diffs = kTRUE; |
282 | } | |
e75b3800 | 283 | } |
488e1434 | 284 | if(!diffs) hStat->Fill(1); |
5ec8009a | 285 | */ |
488e1434 | 286 | |
e75b3800 | 287 | curr1=curr1+ flatEsd1->GetSize(); |
288 | curr2=curr2+ flatEsd2->GetSize(); | |
289 | iEvent++; | |
290 | } | |
291 | ||
292 | delete[] buffer1; | |
293 | delete[] buffer2; | |
294 | } | |
295 | else { | |
296 | cout << "File could not be read" << endl; | |
297 | } | |
488e1434 | 298 | |
488e1434 | 299 | |
e75b3800 | 300 | TList histosList; |
e48021f9 | 301 | histosList.Add(hDiff); |
e75b3800 | 302 | histosList.SaveAs(outputFilename); |
e48021f9 | 303 | |
e75b3800 | 304 | return; |
305 | } | |
e48021f9 | 306 | |
307 | Double_t printDiff(string name, double val1, double val2){ | |
308 | double relDiff = ( val1 != 0 || val2!=0 ) ? fabs(val1-val2)/(fabs(val1) + fabs(val2)): 0; | |
309 | cout<<name<<":\t"<<val1<<" | " << val2 <<"\t|\t"<<(val1-val2)<<"\t|\t"<<relDiff<<endl; | |
310 | return relDiff > 1e-6 ? 1:0; | |
311 | } | |
312 | Double_t printDiff(string name, TString val1, TString val2){ | |
313 | cout<<name<<":"<<endl<<"\t"<<val1<<endl<<"\t"<< val2 <<endl; | |
314 | return val1.EqualTo(val2) ?0:1; | |
315 | } |