]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCEventStatisticsProducerComponent.cxx
get rid of coding violations and warnings (Jochen)
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCEventStatisticsProducerComponent.cxx
1 //-*- Mode: C++ -*-
2 // $Id$
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: Jochen Thaeder <thaeder@kip.uni-heidelberg.de>        *
8  *                  for The ALICE HLT Project.                            *
9  *                                                                        *
10  * Permission to use, copy, modify and distribute this software and its   *
11  * documentation strictly for non-commercial purposes is hereby granted   *
12  * without fee, provided that the above copyright notice appears in all   *
13  * copies and that both the copyright notice and this permission notice   *
14  * appear in the supporting documentation. The authors make no claims     *
15  * about the suitability of this software for any purpose. It is          *
16  * provided "as is" without express or implied warranty.                  *
17  **************************************************************************/
18
19 /** @file   AliHLTTPCEventStatisticsProducerComponent.cxx
20     @author Jochen Thaeder
21     @date   
22     @brief  Component for the @see AliHLTTPCEventStatisticsProducer class
23 */
24
25 // see header file for class documentation
26 // or
27 // refer to README to build package
28 // or
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt   
30
31 #if __GNUC__ >= 3
32 using namespace std;
33 #endif
34
35 #include "AliHLTTPCEventStatisticsProducerComponent.h"
36
37 #include "AliHLTTPCDefinitions.h"
38 #include "AliHLTTPCClusterDataFormat.h"
39 #include "AliHLTTPCTrackSegmentData.h"
40 #include "AliHLTTPCTrackletDataFormat.h"
41 #include "AliHLTTPCTrack.h"
42
43 #include "TMath.h"
44
45 #include <cerrno>
46
47 // ** This is a global object used for automatic component registration, do not use this
48 AliHLTTPCEventStatisticsProducerComponent gAliHLTTPCEventStatisticsProducerComponent;
49
50 ClassImp(AliHLTTPCEventStatisticsProducerComponent)
51     
52 // ------------------------------------------------------------------------------------------
53 AliHLTTPCEventStatisticsProducerComponent::AliHLTTPCEventStatisticsProducerComponent() : 
54   fClusterThreshold(0),
55   fEvStat(NULL),
56   fNTracksPerSlice(),
57   fTracks(NULL),
58   fGlobalTracks(kFALSE),
59   fNSlice(0) {
60   // see header file for class documentation
61   // or
62   // refer to README to build package
63   // or
64   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
65 }
66
67 // ------------------------------------------------------------------------------------------
68 AliHLTTPCEventStatisticsProducerComponent::~AliHLTTPCEventStatisticsProducerComponent() {
69   // see header file for class documentation
70 }
71
72 // ------------------------------------------------------------------------------------------
73 const char* AliHLTTPCEventStatisticsProducerComponent::GetComponentID() {
74   // see header file for class documentation
75   return "TPCEventStatisticsProducer"; 
76 }
77
78 // ------------------------------------------------------------------------------------------
79 void AliHLTTPCEventStatisticsProducerComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list) {
80   // see header file for class documentation
81
82   list.clear(); 
83   list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
84   list.push_back( AliHLTTPCDefinitions::fgkTracksDataType );
85   list.push_back( AliHLTTPCDefinitions::fgkTrackSegmentsDataType );
86 }
87
88 // ------------------------------------------------------------------------------------------
89 AliHLTComponentDataType AliHLTTPCEventStatisticsProducerComponent::GetOutputDataType() {
90   // see header file for class documentation
91
92   return kAliHLTDataTypeEventStatistics|kAliHLTDataOriginTPC;
93 }
94
95 // ------------------------------------------------------------------------------------------
96 void AliHLTTPCEventStatisticsProducerComponent::GetOutputDataSize( unsigned long& constBase, 
97                                                                    double& inputMultiplier ) {
98   // see header file for class documentation
99
100   constBase = sizeof( AliHLTTPCEventStatistics );
101   inputMultiplier = 0.0;
102 }
103
104 // ------------------------------------------------------------------------------------------
105 // Spawn function, return new instance of this class
106 AliHLTComponent* AliHLTTPCEventStatisticsProducerComponent::Spawn() {
107   // see header file for class documentation
108
109   return new AliHLTTPCEventStatisticsProducerComponent;
110 }
111
112
113 // ------------------------------------------------------------------------------------------
114 Int_t AliHLTTPCEventStatisticsProducerComponent::DoInit( int argc, const char** argv ) {
115   // see header file for class documentation
116
117   Int_t iResult = 0;
118   
119   // ** Defaults
120
121   Int_t threshold = 0;
122   
123   // ** Argument handling
124
125   TString argument = "";
126   TString parameter = "";
127   Int_t bMissingParam=0;
128   
129   for ( Int_t ii=0; ii<argc && iResult>=0; ii++ ) {
130   
131     argument = argv[ii];
132
133     if ( argument.IsNull() ) continue;
134
135     // -detector
136     if ( ! argument.CompareTo("-clusterThreshold") ) {
137
138       if ( ( bMissingParam=( ++ii >= argc ) ) ) break;
139
140       parameter = argv[ii];  
141       parameter.Remove( TString::kLeading, ' ' );
142       
143       if  (parameter.IsDigit() ) {
144         threshold = (Int_t) parameter.Atoi();
145         HLTInfo( "Threshold of clusters for long tracks is set to %d.", threshold );
146       } 
147       else {
148         HLTError( "Cannot convert clusterThreshold  specifier '%s'.", parameter.Data() );
149         iResult = -EINVAL;
150         break;
151       }
152       
153     } // if ( ! argument.CompareTo("-clusterThreshold") ) {
154     
155     // - unknow parameter
156     else {
157       iResult = -EINVAL;
158       HLTError("Unknown argument '%s'", argument.Data() );
159     }
160
161   } // for ( Int_t ii=0; ii<argc && iResult>=0; ii++ ) {
162
163   if ( bMissingParam ) {
164     HLTError( "Missing parameter for argument '%s'.", argument.Data() );
165     iResult = -EPROTO;
166   }
167
168   // set members
169   
170   fClusterThreshold =  threshold; 
171
172   return iResult;
173 }
174
175 // ------------------------------------------------------------------------------------------
176 Int_t AliHLTTPCEventStatisticsProducerComponent::DoDeinit() {
177   // see header file for class documentation
178
179   if ( fEvStat )
180     delete fEvStat;
181   fEvStat = NULL;
182
183   if ( fTracks ) 
184     delete fTracks; 
185   fTracks = NULL;
186
187   return 0;
188 }
189
190 // ------------------------------------------------------------------------------------------
191 Int_t AliHLTTPCEventStatisticsProducerComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/ ) {
192   // see header file for class documentation
193
194   const AliHLTComponentBlockData* iter = NULL;
195
196   // ** No readout list for SOR and EOR event
197   if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) )
198     return 0;
199   
200   //
201   // ** Setup for new Event
202   //
203   InitializeEvent();
204   
205   //
206   // ** Read in cluster from ClusterFinder
207   //
208   
209   // ** Loop over all input blocks and specify which data format should be read
210   for ( iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkClustersDataType); iter != NULL; iter = GetNextInputBlock() ) {
211     
212     AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
213     AliHLTUInt8_t patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
214
215     HLTDebug ( "Input Data - TPC cluster - Slice/Patch: %d/%d.", slice, patch );
216
217     AddClusters( iter->fPtr, (Int_t) slice, (Int_t) patch );
218   } // for ( iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkClustersDataType); iter != NULL; iter = GetNextInputBlock() ) {
219   
220
221   //
222   // ** Read in track segments from Tracker
223   //
224
225   iter = NULL;
226
227   // ** Loop over all input blocks and specify which data format should be read
228   for ( iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkTrackSegmentsDataType); iter != NULL; iter = GetNextInputBlock() ) {
229     
230     AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
231     HLTDebug ( "Input Data - TPC track segments - Slice: %d.", slice );
232
233     AddTracks( iter->fPtr, (Int_t) slice );
234   } //   for ( iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkTrackSegmentsDataType); iter != NULL; iter = GetNextInputBlock() ) {
235   
236   //
237   // ** Read in tracks from GlobalMerger
238   //
239
240   iter = NULL;
241
242   // ** Loop over all input blocks and specify which data format should be read
243   for ( iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkTracksDataType); iter != NULL; iter = GetNextInputBlock() ) {
244     
245     HLTDebug ( "Input Data - TPC track segments." );
246
247     AddTracks( iter->fPtr );
248   } //   for ( iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkTracksDataType); iter != NULL; iter = GetNextInputBlock() ) {
249   
250
251   //
252   // ** Produce event statistics
253   //
254   
255   ProcessEvent();
256   
257   PushBack ( (TObject*) GetEventStatistics(), sizeof(AliHLTTPCEventStatistics), kAliHLTDataTypeEventStatistics|kAliHLTDataOriginTPC, (AliHLTUInt32_t) 0 );
258
259   return 0;
260 }
261
262 // -- **********************************************************************************************
263 // -- *******************************   Processing Functions  **************************************
264 // -- **********************************************************************************************
265
266 // -- **********************************************************************************************
267 void AliHLTTPCEventStatisticsProducerComponent::InitializeEvent() {
268   // see header file for class documentation
269   
270   if ( fEvStat )
271     delete fEvStat;
272
273   fEvStat = new AliHLTTPCEventStatistics();
274   fEvStat->SetClusterThreshold( fClusterThreshold );
275
276   // ** Initialize arrays to 0 
277   memset( fNTracksPerSlice, -1, 36*sizeof(Int_t) ); 
278
279   // ** New AliHLTTPCTrackArray
280   if ( fTracks ) 
281     delete fTracks; 
282   fTracks = new AliHLTTPCTrackArray;
283   
284   fGlobalTracks = kFALSE;
285   fNSlice = 0;
286 }
287
288 // -- **********************************************************************************************
289 void AliHLTTPCEventStatisticsProducerComponent::AddClusters( void* ptr, Int_t slice, Int_t patch ) {
290   // see header file for class documentation
291
292   const AliHLTTPCClusterData* clusterData = (const AliHLTTPCClusterData*) ptr;
293
294   // these 2 variables have been introduced to avoid warning: unused variable in production compile
295   Int_t sliceAntiWarning = slice;
296   Int_t patchAntiWarning = patch;
297
298   Int_t nSpacepoint = (Int_t) clusterData->fSpacePointCnt;
299   HLTDebug( "%d Clusters found for slice %u - patch %u\n", nSpacepoint, sliceAntiWarning, patchAntiWarning );
300
301   sliceAntiWarning = 0;
302   patchAntiWarning = 0;
303
304   // ** Add to event statistics
305   fEvStat->AddNTotalCluster( nSpacepoint );
306
307 }
308
309 // -- **********************************************************************************************
310 void AliHLTTPCEventStatisticsProducerComponent::AddTracks( void* ptr, Int_t slice ) {
311   // see header file for class documentation
312
313   const AliHLTTPCTrackletData* trackData = (const AliHLTTPCTrackletData*) ptr;
314
315   Int_t nTracks = (Int_t) trackData->fTrackletCnt;
316
317   AliHLTTPCTrackSegmentData* segmentData = (AliHLTTPCTrackSegmentData*) &( trackData->fTracklets[0] );
318
319   // ** Tracks which are not from GlobalMerger have to be transformed to global Coordinates ( bTransform=1, else 0 )
320   Int_t bTransform;
321
322   
323   // ** Global tracks
324   if ( slice == -1 ) {
325     HLTDebug( "%d tracks found for event.", nTracks );
326   
327     bTransform = 0;
328     fGlobalTracks = kTRUE;
329   } 
330   else { 
331     HLTDebug( "%d tracks found for slice %u.", nTracks, slice );
332
333     // ** Fill number if tracks per slice
334     fNTracksPerSlice[slice] = (Int_t) trackData->fTrackletCnt;
335     fNSlice++;
336
337     bTransform = 1;
338   }
339   
340   fTracks->FillTracks( nTracks, segmentData, slice, bTransform );
341
342 }
343
344 // -- **********************************************************************************************
345 void AliHLTTPCEventStatisticsProducerComponent::ProcessEvent() { 
346   // see header file for class documentation
347
348   // ** Total number of tracks -- Add to event statistics
349   fEvStat->SetNTotalTracks( fTracks->GetNTracks() ) ;
350
351   // ** Loop over all tracks
352   for( Int_t trackNdx=0; trackNdx < fTracks->GetNTracks(); trackNdx++ ) {
353
354     AliHLTTPCTrack *track = fTracks->GetCheckedTrack( trackNdx ); 
355     if( !track ) continue;
356
357     // ** Used cluster -- Add to event statistics
358     fEvStat->AddNUsedCluster( track->GetNHits() );
359
360     // ** If is long track -- Add to event statistics
361     if ( track->GetNHits() >= fClusterThreshold )
362       fEvStat->AddNTracksAboveClusterThreshold();
363   }
364
365   // ** Average of ( number of clusters per track ), floored -- Add to event statistics
366   //    N used cluster / N tracks
367   if (  fEvStat->GetNTotalTracks() > 0 ) {
368     fEvStat->SetAvgClusterPerTrack( (Int_t) TMath::FloorNint( (Double_t) fEvStat->GetNUsedCluster() / (Double_t) fEvStat->GetNTotalTracks()  ) );
369   }
370   fEvStat->SetAvgClusterPerTrack( 0 );
371
372   if ( fGlobalTracks ) FillTracksPerSlice();
373
374   // ** Average  of ( tracks per slice )
375   if ( fNSlice > 0 )
376     fEvStat->SetNAvgTracksPerSector( (Int_t) TMath::FloorNint( (Double_t) fEvStat->GetNTotalTracks() / (Double_t) fNSlice ) );
377   else
378     fEvStat->SetNAvgTracksPerSector( 0 );
379
380   // ** Max and Min of Tracks per slice 
381   for ( Int_t ii=0; ii < 36; ii++ ) {
382
383     if ( fNTracksPerSlice[ii] == -1 ) continue;
384
385     if ( fNTracksPerSlice[ii] > fEvStat->GetNMaxTracksPerSector() ) 
386       fEvStat->SetNMaxTracksPerSector( fNTracksPerSlice[ii] );
387
388     if ( fNTracksPerSlice[ii] < fEvStat->GetNMinTracksPerSector() ) 
389       fEvStat->SetNMinTracksPerSector( fNTracksPerSlice[ii] );
390   }
391
392   // ** Info prints
393
394   HLTInfo( "Total N Tracks : %d", fEvStat->GetNTotalTracks() );
395   HLTInfo( "Total N Tracks with more than %d cluster : %d",  fEvStat->GetClusterThreshold(), fEvStat->GetNTracksAboveClusterThreshold() );
396   HLTInfo( "Min N Tracks per slice : %d", fEvStat->GetNMinTracksPerSector() );
397   HLTInfo( "Max N Tracks per slice : %d", fEvStat->GetNMaxTracksPerSector() );
398   HLTInfo( "Avg N Tracks per slice : %d", fEvStat->GetNAvgTracksPerSector() );
399
400   HLTInfo( "Total N Cluster : %d", fEvStat->GetNTotalCluster() );
401   HLTInfo( "Used N Cluster : %d", fEvStat->GetNUsedCluster() );
402   HLTInfo( "Average (Cluster per track) : %d", fEvStat->GetAvgClusterPerTrack() );
403 }
404
405 // -- **********************************************************************************************
406 void AliHLTTPCEventStatisticsProducerComponent::FillTracksPerSlice() { 
407   // see header file for class documentation
408
409   // fill fNTracksPerSlice[36];   
410   // fill fNSlice
411 }