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