]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliHLTGlobalCompareFlatComponent.cxx
added getter for number of ITS clusters in AliESDTrack, fixed bug in SetFromESD funct...
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalCompareFlatComponent.cxx
1 //-*- Mode: C++ -*-
2 // $Id: AliHLTGlobalCompareFlatComponent.cxx $
3 /**************************************************************************
4  * This file is property of and copyright by the ALICE HLT Project        * 
5  * ALICE Experiment at CERN, All rights reserved.                         *
6  *                                                                        *
7  * Primary Authors: Steffen Weber                                         *
8  *                                                                        *
9  * Permission to use, copy, modify and distribute this software and its   *
10  * documentation strictly for non-commercial purposes is hereby granted   *
11  * without fee, provided that the above copyright notice appears in all   *
12  * copies and that both the copyright notice and this permission notice   *
13  * appear in the supporting documentation. The authors make no claims     *
14  * about the suitability of this software for any purpose. It is          *
15  * provided "as is" without express or implied warranty.                  *
16  **************************************************************************/
17
18 /** @file    AliHLTGlobalCompareFlatComponent.cxx
19     @author  Steffen Weber
20     @brief   Compare flat events from different inputs
21 */
22
23 #include "TMap.h"
24 #include "TSystem.h"
25 #include "TTimeStamp.h"
26 #include "TObjString.h"
27 #include "TList.h"
28 #include "THnSparse.h"
29 #include "AliESDEvent.h"
30 #include "AliFlatESDEvent.h"
31 #include "AliFlatESDTrigger.h"
32 #include "AliFlatESDV0.h"
33 #include "AliFlatESDVertex.h"
34 #include "AliHLTErrorGuard.h"
35 #include "AliHLTDataTypes.h"
36 #include "AliHLTGlobalCompareFlatComponent.h"
37 #include "AliHLTITSClusterDataFormat.h"
38 #include "AliHLTTPCDefinitions.h"
39 #include "TTree.h"
40 #include "AliCDBEntry.h"
41 #include "AliCDBManager.h"
42
43 using namespace std;
44
45 /** ROOT macro for the implementation of ROOT specific class methods */
46 ClassImp(AliHLTGlobalCompareFlatComponent)
47
48 void AliHLTGlobalCompareFlatComponent::printDiff( string name, double val1, double val2){
49         double relDiff = ( val1 != 0 || val2!=0 ) ? (val1-val2)/(fabs(val1) + fabs(val2)): 0;
50         int diff = 0;
51         if (relDiff > 1e-6) diff = 1;
52         else if(relDiff < -1e-6) diff = -1;
53         outFile<<name<<"\t" << val1 << "\t" << val2 <<"\t" << diff << "\n";
54 }
55 void AliHLTGlobalCompareFlatComponent::printDiff( string name, TString val1, TString val2){
56         outFile << name << "\t" << "\t\"" << val1 <<"\"\t\"" << val2 <<"\"\t" << (val1.EqualTo(val2) ?0:1)<<"\n";
57 }
58
59 /*
60  * ---------------------------------------------------------------------------------
61  *                            Constructor / Destructor
62  * ---------------------------------------------------------------------------------
63  */
64
65 // #################################################################################
66 AliHLTGlobalCompareFlatComponent::AliHLTGlobalCompareFlatComponent() :
67   AliHLTProcessor()
68   {
69   // an example component which implements the ALICE HLT processor
70   // interface and does some analysis on the input raw data
71   //
72   // see header file for class documentation
73   // or
74   // refer to README to build package
75   // or
76   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
77   //
78   // NOTE: all helper classes should be instantiated in DoInit()
79 }
80
81 // #################################################################################
82 AliHLTGlobalCompareFlatComponent::~AliHLTGlobalCompareFlatComponent() {
83   // see header file for class documentation
84
85         
86         
87 }
88
89 /*
90  * ---------------------------------------------------------------------------------
91  * Public functions to implement AliHLTComponent's interface.
92  * These functions are required for the registration process
93  * ---------------------------------------------------------------------------------
94  */
95
96 // #################################################################################
97 const Char_t* AliHLTGlobalCompareFlatComponent::GetComponentID() { 
98   // see header file for class documentation
99   return "GlobalCompareFlat";
100 }
101
102 // #################################################################################
103 void AliHLTGlobalCompareFlatComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
104   // see header file for class documentation
105         list.push_back(kAliHLTDataTypeFlatESD|kAliHLTDataOriginOut );
106 }
107
108 // #################################################################################
109 AliHLTComponentDataType AliHLTGlobalCompareFlatComponent::GetOutputDataType() {
110   // see header file for class documentation
111   return kAliHLTDataTypeTObject|kAliHLTDataOriginOut;
112 }
113
114 // #################################################################################
115 void AliHLTGlobalCompareFlatComponent::GetOutputDataSize( ULong_t& constBase, Double_t& inputMultiplier ) {
116   // see header file for class documentation
117   constBase = 100000;
118   inputMultiplier = 10.0;
119 }
120
121
122 // #################################################################################
123 AliHLTComponent* AliHLTGlobalCompareFlatComponent::Spawn() {
124   // see header file for class documentation
125   return new AliHLTGlobalCompareFlatComponent;
126 }
127
128 /*
129  * ---------------------------------------------------------------------------------
130  * Protected functions to implement AliHLTComponent's interface.
131  * These functions provide initialization as well as the actual processing
132  * capabilities of the component. 
133  * ---------------------------------------------------------------------------------
134  */
135
136 // #################################################################################
137 Int_t AliHLTGlobalCompareFlatComponent::DoInit( Int_t argc, const Char_t** argv ) {
138   // see header file for class documentation
139   printf("AliHLTGlobalCompareFlatComponent::DoInit\n");
140   // see header file for class documentation
141   int iResult=0;
142
143 /*
144         
145                 Int_t bins[fDim] = {3};
146                 Double_t mins[fDim] = {0};
147                 Double_t maxs[fDim] = {2};
148                 fhDiff = new THnSparseD("Differences","Differences",fDim,bins,mins,maxs);
149                 
150                 
151                 Int_t tmp = 0;
152                 
153                 fhDiff->GetAxis(tmp)->SetName("Overall");
154                 fhDiff->GetAxis(tmp)->SetBinLabel(1,"no differences");
155                 fhDiff->GetAxis(tmp)->SetBinLabel(2,"sizes differ");
156                 fhDiff->GetAxis(tmp)->SetBinLabel(3,"other differences");
157                 
158                 fhDiff->GetAxis(++tmp)->SetName("GetSize");
159                 fhDiff->GetAxis(++tmp)->SetName("GetMagneticField");
160                 fhDiff->GetAxis(++tmp)->SetName("GetPeriodNumber");
161                 fhDiff->GetAxis(++tmp)->SetName("GetRunNumber");
162                 fhDiff->GetAxis(++tmp)->SetName("GetOrbitNumber");
163                 fhDiff->GetAxis(++tmp)->SetName("GetBunchCrossNumber");
164                 fhDiff->GetAxis(++tmp)->SetName("GetTriggerMask");
165                 fhDiff->GetAxis(++tmp)->SetName("GetTriggerMaskNext50");
166                 fhDiff->GetAxis(++tmp)->SetName("GetFiredTriggerClasses");
167                 fhDiff->GetAxis(++tmp)->SetName("GetNumberOfTracks");
168                 fhDiff->GetAxis(++tmp)->SetName("GetNumberOfV0s");
169                 fhDiff->GetAxis(++tmp)->SetName("GetTimeStamp");
170                 fhDiff->GetAxis(++tmp)->SetName("GetEventSpecie");
171         */
172
173
174
175                 
176                 
177   return iResult;
178 }
179
180
181
182 // #################################################################################
183 Int_t AliHLTGlobalCompareFlatComponent::DoDeinit() {
184   // see header file for class documentation
185   printf("AliHLTGlobalCompareFlatComponent::DoDeInit\n");
186
187         Int_t iResult = 0;
188         /*
189         TFile * f = TFile::Open("histograms.root","RECREATE");
190         f->Add(fhDiff);
191         f->Write();
192         f->Close();
193         */
194   //delete fhDiff;
195         
196   return iResult;
197 }
198
199 // #################################################################################
200 Int_t AliHLTGlobalCompareFlatComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
201                                                     const AliHLTComponentBlockData* /*blocks*/, 
202                                                     AliHLTComponentTriggerData& /*trigData*/,
203                                                     AliHLTUInt8_t* /*outputPtr*/, 
204                                                     AliHLTUInt32_t& /*size*/,
205                                                     AliHLTComponentBlockDataList& /*outputBlocks*/) {
206   // see header file for class documentation
207
208   printf("AliHLTGlobalCompareFlatComponent::DoEvent\n");
209   Int_t iResult=0;
210         
211         
212   // -- Only use data event
213  if (!IsDataEvent()) 
214    return 0;
215
216  AliFlatESDEvent *flatEsd[2] ;
217         
218   printf("search for input onbjects\n");
219         {
220          int i=0;
221         for ( const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeFlatESD|kAliHLTDataOriginOut);
222     pBlock!=NULL && i<2; pBlock = GetNextInputBlock(),i++ ) {
223                         flatEsd[i] = reinterpret_cast<AliFlatESDEvent*>( pBlock->fPtr );
224   }
225         }
226  cout<<"size event 1: "<<flatEsd[0]->GetSize()<<endl;
227  cout<<"size event 2: "<<flatEsd[1]->GetSize()<<endl;
228
229
230  cout<<"nTracks event 1: "<<flatEsd[0]->GetNumberOfTracks()<<endl;
231  cout<<"nTracks event 2: "<<flatEsd[1]->GetNumberOfTracks()<<endl;
232  
233  outFile.open("comparison.txt",ios::app);
234  
235  // Compare Event variables
236  
237  outFile<<"\n\n------------------\nnew AliFlatESDEvent\n------------------\n";
238  printDiff( "AliFlatESDEvent::GetSize" ,flatEsd[0]->GetSize(), flatEsd[1]->GetSize() ) ;
239         printDiff( "AliFlatESDEvent::GetMagneticField",flatEsd[0]->GetMagneticField(),flatEsd[1]->GetMagneticField() );
240         printDiff( "AliFlatESDEvent::GetPeriodNumber",flatEsd[0]->GetPeriodNumber(),flatEsd[1]->GetPeriodNumber() );
241         printDiff( "AliFlatESDEvent::GetRunNumber",flatEsd[0]->GetRunNumber(),  flatEsd[1]->GetRunNumber() );
242         printDiff( "AliFlatESDEvent::GetOrbitNumber",flatEsd[0]->GetOrbitNumber(),flatEsd[1]->GetOrbitNumber() );
243         printDiff( "AliFlatESDEvent::GetBunchCrossNumber",flatEsd[0]->GetBunchCrossNumber(),flatEsd[1]->GetBunchCrossNumber() );
244         printDiff( "AliFlatESDEvent::GetTriggerMask",flatEsd[0]->GetTriggerMask(),flatEsd[1]->GetTriggerMask() );
245         printDiff( "AliFlatESDEvent::GetTriggerMaskNext50",flatEsd[0]->GetTriggerMaskNext50(),flatEsd[1]->GetTriggerMaskNext50() );
246         printDiff( "AliFlatESDEvent::GetFiredTriggerClasses",flatEsd[0]->GetFiredTriggerClasses() ,flatEsd[1]->GetFiredTriggerClasses() );
247         printDiff( "AliFlatESDEvent::GetNumberOfTracks",flatEsd[0]->GetNumberOfTracks(),        flatEsd[1]->GetNumberOfTracks() );
248         printDiff( "AliFlatESDEvent::GetNumberOfV0s",flatEsd[0]->GetNumberOfV0s(),flatEsd[1]->GetNumberOfV0s() );
249         printDiff( "AliFlatESDEvent::GetTimeStamp",flatEsd[0]->GetTimeStamp(),flatEsd[1]->GetTimeStamp() );
250         printDiff( "AliFlatESDEvent::GetEventSpecie",flatEsd[0]->GetEventSpecie(),flatEsd[1]->GetEventSpecie() ); 
251         printDiff( "AliFlatESDEvent::GetNumberOfTriggerClasses",flatEsd[0]->GetNumberOfTriggerClasses(),flatEsd[1]->GetNumberOfTriggerClasses() ); 
252         
253  const AliFlatESDVertex * vertexTracks[2] = {flatEsd[0]->GetFlatPrimaryVertexTracks(), flatEsd[1]->GetFlatPrimaryVertexTracks()};
254         printDiff("AliFlatESDEvent::GetFlatPrimaryVertexTracks", (vertexTracks[0] ? 1:0), (vertexTracks[1] ? 1:0) );
255         
256  const AliFlatESDVertex * vertexSPD[2] = {flatEsd[0]->GetFlatPrimaryVertexSPD(), flatEsd[1]->GetFlatPrimaryVertexSPD()};
257         printDiff("AliFlatESDEvent::GetFlatPrimaryVertexSPD", (vertexSPD[0] ? 1:0), (vertexSPD[1] ? 1:0) );
258         
259  // Compare primary vertices
260         
261         if(vertexTracks[0] && vertexTracks[1]){
262       outFile<<"\nnew AliFlatESDVertexTracks\n";
263                         printDiff( "AliFlatESDVertexTracks::GetSize",vertexTracks[0]->GetSize(),vertexTracks[1]->GetSize() ); 
264                         printDiff( "AliFlatESDVertexTracks::GetX",vertexTracks[0]->GetX(),vertexTracks[1]->GetX() ); 
265                         printDiff( "AliFlatESDVertexTracks::GetY",vertexTracks[0]->GetY(),vertexTracks[1]->GetY() ); 
266                         printDiff( "AliFlatESDVertexTracks::GetZ",vertexTracks[0]->GetZ(),vertexTracks[1]->GetZ() ); 
267         }
268  
269         if(vertexSPD[0] && vertexSPD[1]){
270       outFile<<"\nnew AliFlatESDVertexSPD\n";
271                         printDiff( "AliFlatESDVertexSPD::GetSize",vertexSPD[0]->GetSize(),vertexSPD[1]->GetSize() ); 
272                         printDiff( "AliFlatESDVertexSPD::GetX",vertexSPD[0]->GetX(),vertexSPD[1]->GetX() ); 
273                         printDiff( "AliFlatESDVertexSPD::GetY",vertexSPD[0]->GetY(),vertexSPD[1]->GetY() ); 
274                         printDiff( "AliFlatESDVertexSPD::GetZ",vertexSPD[0]->GetZ(),vertexSPD[1]->GetZ() ); 
275         }
276  
277  
278  // Compare triggers
279         
280         if(flatEsd[0]->GetNumberOfTriggerClasses()  && flatEsd[1]->GetNumberOfTriggerClasses() ){
281                 outFile<<"------------------\ntriggers\n------------------\n";
282     AliFlatESDTrigger * trigger[2] = { const_cast<AliFlatESDTrigger*>(flatEsd[0]->GetTriggerClasses() ) , const_cast<AliFlatESDTrigger*>(flatEsd[1]->GetTriggerClasses() ) };
283     for( Int_t i = 0; i < flatEsd[0]->GetNumberOfTriggerClasses()  && i < flatEsd[1]->GetNumberOfTriggerClasses()  ; i++ ){
284       outFile<<"\nnew AliFlatESDTrigger\n";
285                         printDiff( "AliFlatESDTrigger::GetSize",trigger[0]->GetSize(),trigger[1]->GetSize() ); 
286                         printDiff( "AliFlatESDTrigger::GetTriggerIndex",trigger[0]->GetTriggerIndex(),trigger[1]->GetTriggerIndex() ); 
287                         printDiff( "AliFlatESDTrigger::GetTriggerClassName",trigger[0]->GetTriggerClassName(),trigger[1]->GetTriggerClassName() ); 
288                         
289       trigger[0] = trigger[0]->GetNextTriggerNonConst();
290                         trigger[1] = trigger[1]->GetNextTriggerNonConst();
291     }
292         }
293         
294  // Compare v0s
295         
296         if(flatEsd[0]->GetNumberOfV0s()  && flatEsd[1]->GetNumberOfV0s() ){
297                 outFile<<"------------------\nv0s\n------------------\n";
298                 
299     AliFlatESDV0 * v0[2] = { const_cast<AliFlatESDV0*>(flatEsd[0]->GetV0s() ) , const_cast<AliFlatESDV0*>(flatEsd[1]->GetV0s() ) };
300     for( Int_t i = 0; i < flatEsd[0]->GetNumberOfV0s()  && i < flatEsd[1]->GetNumberOfV0s()  ; i++ ){
301       outFile<<"\nnew AliFlatESDV0\n";
302                         printDiff( "AliFlatESDV0::GetSize",v0[0]->GetSize(),v0[1]->GetSize() ); 
303                         printDiff( "AliFlatESDV0::GetNegTrackID",v0[0]->GetNegTrackID(),v0[1]->GetNegTrackID() ); 
304                         printDiff( "AliFlatESDV0::GetPosTrackID",v0[0]->GetPosTrackID(),v0[1]->GetPosTrackID() ); 
305                         
306       v0[0] = v0[0]->GetNextV0NonConst();
307                         v0[1] = v0[1]->GetNextV0NonConst();
308     }
309         }
310         
311  // Compare tracks
312         
313         if(flatEsd[0]->GetNumberOfTracks()  && flatEsd[1]->GetNumberOfTracks() ){
314                 outFile<<"------------------\ntracks\n------------------\n";
315                 
316     AliFlatESDTrack * track[2] = { const_cast<AliFlatESDTrack*>(flatEsd[0]->GetTracks() ) , const_cast<AliFlatESDTrack*>(flatEsd[1]->GetTracks() ) };
317     for( Int_t t = 0; t < flatEsd[0]->GetNumberOfTracks()  && t < flatEsd[1]->GetNumberOfTracks()  ; t++ ){
318       outFile<<"\nnew AliFlatESDTrack\n";
319                         printDiff( "AliFlatESDTrack::GetSize",track[0]->GetSize(),track[1]->GetSize() ); 
320                         printDiff( "AliFlatESDTrack::GetNumberOfTPCClusters",track[0]->GetNumberOfTPCClusters(),track[1]->GetNumberOfTPCClusters() ); 
321                         printDiff( "AliFlatESDTrack::GetNumberOfITSClusters",track[0]->GetNumberOfITSClusters(),track[1]->GetNumberOfITSClusters() ); 
322                         
323                         const char* pNames[7] = {"", "Refitted", "Ip", "TPCInner", "Op", "Cp", "ITSOUT"};
324                         
325                         const AliFlatExternalTrackParam * p[7][2] = {
326                                 {track[0]->GetFlatTrackParam(), track[1]->GetFlatTrackParam()},
327                                 {track[0]->GetFlatTrackParamRefitted(), track[1]->GetFlatTrackParamRefitted()},
328                                 {track[0]->GetFlatTrackParamIp(), track[1]->GetFlatTrackParamIp()},
329                                 {track[0]->GetFlatTrackParamTPCInner(), track[1]->GetFlatTrackParamTPCInner()},
330                                 {track[0]->GetFlatTrackParamOp(), track[1]->GetFlatTrackParamOp()},
331                                 {track[0]->GetFlatTrackParamCp(), track[1]->GetFlatTrackParamCp()},
332                                 {track[0]->GetFlatTrackParamITSOut(), track[1]->GetFlatTrackParamITSOut()}
333                         };
334                         
335                         for(int i = 0 ; i<7; i++){
336                                 printDiff( Form("AliFlatESDTrack::GetFlatTrackParam%s",pNames[i]), (p[i][0] ? 1:0), (p[i][1] ? 1:0) );
337                         }
338
339                         for(int i = 0 ; i<7; i++){
340                                 if(p[i][0] && p[i][1] ){
341                                         outFile<<"\nnew AliFlatExternalTrackParam" << pNames[i] << "\n";
342                                         printDiff( Form("AliFlatExternalTrackParam%s::GetAlpha",pNames[i]),p[i][0]->GetAlpha(),p[i][1]->GetAlpha() ); 
343                                         printDiff( Form("AliFlatExternalTrackParam%s::GetX",pNames[i]),p[i][0]->GetX(),p[i][1]->GetX() ); 
344                                         printDiff( Form("AliFlatExternalTrackParam%s::GetY",pNames[i]),p[i][0]->GetY(),p[i][1]->GetY() ); 
345                                         printDiff( Form("AliFlatExternalTrackParam%s::GetZ",pNames[i]),p[i][0]->GetZ(),p[i][1]->GetZ() ); 
346                                         printDiff( Form("AliFlatExternalTrackParam%s::GetSnp",pNames[i]),p[i][0]->GetSnp(),p[i][1]->GetSnp() ); 
347                                         printDiff( Form("AliFlatExternalTrackParam%s::GetTgl",pNames[i]),p[i][0]->GetTgl(),p[i][1]->GetTgl() ); 
348                                         printDiff( Form("AliFlatExternalTrackParam%s::GetSigned1Pt",pNames[i]),p[i][0]->GetSigned1Pt(),p[i][1]->GetSigned1Pt() ); 
349                                         
350                                         for(int j=0; j<15; j++){
351                                                 printDiff( Form("AliFlatExternalTrackParam%s::GetCovEntry(%d)",pNames[i],j),p[i][0]->GetCovEntry(j),p[i][1]->GetCovEntry(j) ); 
352                                         }
353                                 
354                                 }
355                         }
356                         
357                         
358                         
359                         
360       track[0] = track[0]->GetNextTrackNonConst();
361                         track[1] = track[1]->GetNextTrackNonConst();
362                         
363                         
364                         
365                         
366                         
367                         
368                         
369                         
370                         
371     }
372         }
373         
374         
375  outFile.close();
376  
377  
378   return iResult;
379 }
380
381
382 // #################################################################################
383 Int_t AliHLTGlobalCompareFlatComponent::ReadPreprocessorValues(const Char_t* /*modules*/) {
384   // see header file for class documentation
385   ALIHLTERRORGUARD(5, "ReadPreProcessorValues not implemented for this component");
386   return 0;
387 }
388
389
390 int AliHLTGlobalCompareFlatComponent::Configure(const char*/* arguments*/)
391 {
392   // see header file for class documentation
393   int iResult=0;
394
395   return iResult;
396 }
397
398 int AliHLTGlobalCompareFlatComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/)
399 {
400   // see header file for class documentation
401   int iResult=0;
402   
403   return iResult;
404 }
405
406