Major commit related to steering of the reco parameters: AliDAQ and trigger classes...
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDTrackerV1Component.cxx
CommitLineData
0e339ac7 1// $Id: AliHLTTRDTrackerV1Component.cxx 23618 2008-01-29 13:07:38Z hristov $
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line 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 AliHLTTRDTrackerV1Component.cxx
20 @author Timm Steinbeck, Matthias Richter
21 @date
22 @brief A TRDTrackerV1 processing component for the HLT. */
23
24#if __GNUC__ >= 3
25using namespace std;
26#endif
27
28#include "AliHLTTRDTrackerV1Component.h"
29#include "AliHLTTRDDefinitions.h"
30
31#include "TFile.h"
32#include "TChain.h"
33
34#include "AliCDBManager.h"
35#include "AliESDEvent.h"
36#include "AliMagFMaps.h"
37#include "AliESDfriend.h"
38
39#include "AliTRDReconstructor.h"
40#include "AliTRDtrackerV1.h"
41#include "AliTRDcluster.h"
42#include "AliTRDrecoParam.h"
43
44#include <cstdlib>
45#include <cerrno>
46#include <string>
47
48// this is a global object used for automatic component registration, do not use this
49AliHLTTRDTrackerV1Component gAliHLTTRDTrackerV1Component;
50
51ClassImp(AliHLTTRDTrackerV1Component);
52
53AliHLTTRDTrackerV1Component::AliHLTTRDTrackerV1Component()
54 : AliHLTProcessor()
55 , fOutputPercentage(100) // By default we copy to the output exactly what we got as input
56 , fStrorageDBpath("local://$ALICE_ROOT")
57 , fCDB(NULL)
58 , fField(NULL)
59 , fGeometryFileName("")
60 , fGeometryFile(NULL)
61 , fGeoManager(NULL)
62 , fTracker(NULL)
63 , fRecoParam(NULL)
64{
65 // Default constructor
66
67 fGeometryFileName = getenv("ALICE_ROOT");
68 fGeometryFileName += "/HLT/TRD/geometry.root";
69}
70
71AliHLTTRDTrackerV1Component::~AliHLTTRDTrackerV1Component()
72{
73 // Destructor
74}
75
76const char* AliHLTTRDTrackerV1Component::GetComponentID()
77{
78 // Return the component ID const char *
79 return "TRDTrackerV1"; // The ID of this component
80}
81
82void AliHLTTRDTrackerV1Component::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
83{
84 // Get the list of input data
85 list.clear(); // We do not have any requirements for our input data type(s).
86 list.push_back( AliHLTTRDDefinitions::fgkClusterDataType );
87}
88
89AliHLTComponent_DataType AliHLTTRDTrackerV1Component::GetOutputDataType()
90{
91 // Get the output data type
92 return AliHLTTRDDefinitions::fgkClusterDataType;
93}
94
95void AliHLTTRDTrackerV1Component::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
96{
97 // Get the output data size
98 constBase = 0;
99 inputMultiplier = ((double)fOutputPercentage)/100.0;
100}
101
102// Spawn function, return new instance of this class
103AliHLTComponent* AliHLTTRDTrackerV1Component::Spawn()
104{
105 // Spawn function, return new instance of this class
106 return new AliHLTTRDTrackerV1Component;
107};
108
109int AliHLTTRDTrackerV1Component::DoInit( int argc, const char** argv )
110{
111 // perform initialization. We check whether our relative output size is specified in the arguments.
112 fOutputPercentage = 100;
113 int i = 0;
114 char* cpErr;
115
116 Int_t iRecoParamType = -1; // default will be the low flux
117 Int_t iNtimeBins = -1; // number of time bins for the tracker to use
118 Int_t iMagneticField = -1; // magnetic field: 0==OFF and 1==ON
119
120 while ( i < argc )
121 {
122 Logging( kHLTLogDebug, "HLT::TRDTrackerV1::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
123 if ( !strcmp( argv[i], "output_percentage" ) )
124 {
125 if ( i+1>=argc )
126 {
127 Logging(kHLTLogError, "HLT::TRDTrackerV1::DoInit", "Missing Argument", "Missing output_percentage parameter");
128 return ENOTSUP;
129 }
130 Logging( kHLTLogDebug, "HLT::TRDTrackerV1::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
131 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
132 if ( *cpErr )
133 {
134 Logging(kHLTLogError, "HLT::TRDTrackerV1::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
135 return EINVAL;
136 }
137 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
138 i += 2;
139 continue;
140 }
141
142 if ( !strcmp( argv[i], "-NTimeBins" ) )
143 {
144 if ( i+1>=argc )
145 {
146 HLTError("Missing -NTimeBins parameter");
147 return ENOTSUP;
148 }
149 HLTDebug("Arguments", "argv[%d+1] == %s", i, argv[i+1] );
150 iNtimeBins = strtoul( argv[i+1], &cpErr, 0 );
151 if ( *cpErr )
152 {
153 HLTError("Wrong Argument. Cannot convert -NTimeBins parameter '%s'", argv[i+1] );
154 return EINVAL;
155 }
156 i += 2;
157 continue;
158 }
159
160 if ( strcmp( argv[i], "-cdb" ) == 0)
161 {
162 if ( i+1 >= argc )
163 {
164 Logging(kHLTLogError, "HLT::TRDTrackerV1::DoInit", "Missing Argument", "Missing -cdb argument");
165 return ENOTSUP;
166 }
167 fStrorageDBpath = argv[i+1];
168 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoInit", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );
169 i += 2;
170 continue;
171 }
172
173 if ( strcmp( argv[i], "-geometry" ) == 0)
174 {
175 if ( i+1 >= argc )
176 {
177 Logging(kHLTLogError, "HLT::TRDTrackerV1::DoInit", "Missing Argument", "Missing -geometry argument");
178 return ENOTSUP;
179 }
180 fGeometryFileName = argv[i+1];
181 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoInit", "GeomFile storage set", "GeomFile storage is %s",
182 fGeometryFileName.c_str() );
183 i += 2;
184 continue;
185 }
186
187 // the flux parametrizations
188 if ( strcmp( argv[i], "-lowflux" ) == 0)
189 {
190 iRecoParamType = 0;
191 HLTDebug("Low flux reco selected.");
192 i++;
193 continue;
194 }
195
196 if ( strcmp( argv[i], "-highflux" ) == 0)
197 {
198 iRecoParamType = 1;
199 HLTDebug("Low flux reco selected.");
200 i++;
201 continue;
202 }
203
204 if ( strcmp( argv[i], "-magnetic_field_ON" ) == 0)
205 {
206 iMagneticField = 1;
207 i++;
208 continue;
209 }
210
211 if ( strcmp( argv[i], "-magnetic_field_OFF" ) == 0)
212 {
213 iMagneticField = 0;
214 i++;
215 continue;
216 }
217
218 Logging(kHLTLogError, "HLT::TRDTrackerV1::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
219 return EINVAL;
220 }
221
222 // THE "REAL" INIT COMES HERE
223 // offline condition data base
224 fCDB = AliCDBManager::Instance();
225 if (!fCDB)
226 {
227 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Could not get CDB instance", "fCDB 0x%x", fCDB);
228 return -1;
229 }
230 else
231 {
232 fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
233 fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
234 Logging(kHLTLogDebug, "HLT::TRDCalibration::DoInit", "CDB instance", "fCDB 0x%x", fCDB);
235 }
236
237 // check if the N of time bins make sense
238 if (iNtimeBins <= 0)
239 {
240 HLTError("Sorry. Tracker needs number of time bins. At the moment you have to provide it with -NTimeBins <value>. The simulation always had 24 and the real data 30. Take your pick. Make sure the information is correct. Ask offline to implement how to propagate this information into clusters/cluster tree.");
241 return -1;
242 }
243
244 if (iNtimeBins < 24 || iNtimeBins > 30)
245 {
246 HLTWarning("The number of time bins seems to be strange = %d. But okay. Let's try it...", iNtimeBins);
247 }
248
249 HLTDebug("The number of time bins = %d.", iNtimeBins);
250 AliTRDtrackerV1::SetNTimeBins(iNtimeBins);
251
252 // !!!! THIS IS IMPORTANT
253 // init alifield map - temporarly via parameter - should come from a DB or DCS ?
254 // !!!!
255 if (iMagneticField < 0)
256 {
257 iMagneticField = 0;
258 HLTWarning("No magnetic field switch stated. Use -magnetic_field_ON or -magnetic_field_OFF flag. Defaulting to OFF = NO MAGNETIC FIELD");
259 }
260
261 if (iMagneticField == 0)
262 {
263 // magnetic field OFF
264 fField = new AliMagFMaps("Maps","Maps", 2, 0., 10., 1);
265 HLTDebug("Magnetic field is OFF.");
266 }
267
268 if (iMagneticField == 1)
269 {
270 // magnetic field ON
271 fField = new AliMagFMaps("Maps","Maps", 2, 1., 10., 1);
272 HLTDebug("Magnetic field is ON.");
273 }
274
275 if (fField == 0)
276 {
277 HLTError("Unable to init the field. Trouble at this point.");
278 return -1;
279 }
280
281 // kTRUE sets the map uniform
282 AliTracker::SetFieldMap(fField,kTRUE);
283
284 // reconstruction parameters
285 if (iRecoParamType < 0 || iRecoParamType > 1)
286 {
287 HLTWarning("No reco param selected. Use -lowflux or -highflux flag. Defaulting to low flux.");
288 iRecoParamType = 0;
289 }
290
291 if (iRecoParamType == 0)
292 {
293 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
294 HLTDebug("Low flux params init.");
295 }
296
297 if (iRecoParamType == 1)
298 {
299 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
300 HLTDebug("High flux params init.");
301 }
302
303 if (fRecoParam == 0)
304 {
305 HLTError("No reco params initialized. Sniffing big trouble!");
306 return -1;
307 }
308
9fa37a91 309 // this is important in case we want to ::PropagateBack - see the TrackerV1.cxx
21a78029 310 fRecoParam->SetSeeding(kTRUE);
9fa37a91 311 // no debug stream -> no debug files! on HLT
312 fRecoParam->SetStreamLevel(0);
313
7e88424f 314 AliTRDReconstructor reconstructor; reconstructor.SetRecoParam(fRecoParam);
0e339ac7 315
316 // geometry:
317 // for some unknown at this point reason (30th of April 2008)
318 // the TrackerV1 initializes new TRDgeometry in the constructor
319 // we avoid it here
320 fGeometryFile = 0;
321 // fGeometryFile = TFile::Open(fGeometryFileName.c_str());
322 // if (fGeometryFile)
323 // {
324 // fGeoManager = (TGeoManager *)fGeometryFile->Get("Geometry");
325 // // for the old tracker we would do this:
326 // fTracker = new AliTRDtracker(fGeometryFile);
327 // }
328 // else
329 // {
330 // Logging(kHLTLogError, "HLT::TRDTrackerV1::DoInit", "fGeometryFile", "Unable to open file. FATAL!");
331 // return -1;
332 // }
333
334 // create the tracker
335 fTracker = new AliTRDtrackerV1();
336 HLTDebug("TRDTracker at 0x%x", fTracker);
337
338 if (fTracker == 0)
339 {
340 HLTError("Unable to create the tracker!");
341 // do we want a smarter return value here? probably yes
342 // answering your own questions is stupid but maybe helpful... ;)
343 return -1;
344 }
345
0e339ac7 346 return 0;
347}
348
349int AliHLTTRDTrackerV1Component::DoDeinit()
350{
351 // Deinitialization of the component
352
353 delete fField;
354 fField = 0;
355
356 delete fTracker;
357 fTracker = 0;
358
359 if (fGeometryFile)
360 {
361 fGeometryFile->Close();
362 delete fGeometryFile;
363 fGeometryFile = 0;
364 }
365
366 return 0;
367}
368
369int AliHLTTRDTrackerV1Component::DoEvent( const AliHLTComponentEventData & evtData,
370 AliHLTComponentTriggerData & trigData )
371{
372 // Process an event
373
374 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
375 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "BLOCKS", "NofBlocks %lu", evtData.fBlockCnt );
376
377 AliHLTUInt32_t dBlockSpecification = 0;
378
379 //implement a usage of the following
380 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
381 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
382 // void *triggerData = trigData.fData;
383 Logging( kHLTLogDebug, "HLT::TRDTrackerV1::DoEvent", "Trigger data received",
384 "Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
385
386 AliHLTComponentBlockData *dblock = (AliHLTComponentBlockData *)GetFirstInputBlock( AliHLTTRDDefinitions::fgkClusterDataType );
387 if (dblock != 0)
388 {
389 dBlockSpecification = dblock->fSpecification;
390 }
391 else
392 {
393 Logging( kHLTLogWarning, "HLT::TRDTrackerV1::DoEvent", "DATAIN", "First Input Block not found! 0x%x", dblock);
394 return -1;
395 }
396
397 int ibForce = 0;
398
399 TObject *tobjin = (TObject *)GetFirstInputObject( AliHLTTRDDefinitions::fgkClusterDataType, "TTree", ibForce);
400 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "1stBLOCK", "Pointer = 0x%x", tobjin);
401
402 TTree *clusterTree = (TTree*)tobjin;
403 if (!clusterTree)
404 {
405 Logging( kHLTLogWarning, "HLT::TRDTrackerV1::DoEvent", "DATAIN", "First Input Block not a tree! 0x%x", tobjin);
406 return -1;
407 }
408
409 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "1stBLOCK", "Pointer = 0x%x Name = %s", clusterTree, clusterTree->GetName());
410
411 while (tobjin != 0)
412 {
413 if (clusterTree)
414 {
415 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "CLUSTERS", "Pointer = 0x%x Name = %s", clusterTree, clusterTree->GetName());
416 Int_t iNentries = clusterTree->GetEntries();
417 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "COUNT", "N of tree entries = %d", iNentries);
418 fTracker->LoadClusters(clusterTree);
419 }
420 else
421 {
422 Logging( kHLTLogError, "HLT::TRDTrackerV1::DoEvent", "CLUSTERS", "Tree Pointer = 0x%x", clusterTree);
423 }
424
425 tobjin = (TObject *)GetNextInputObject( ibForce );
426 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "nextBLOCK", "Pointer = 0x%x", tobjin);
427 clusterTree = (TTree*)tobjin;
428 }
429
430 // maybe it is not so smart to create it each event? clear is enough ?
431 AliESDEvent *esd = new AliESDEvent();
432 esd->CreateStdContent();
433
434 fTracker->Clusters2Tracks(esd);
435 // not necessary...
436 //fTracker->PropagateBack(esd);
437
438 //here transport the esd tracks further
439 Int_t nTracks = esd->GetNumberOfTracks();
440 Int_t nTRDTracks = esd->GetNumberOfTrdTracks();
441 HLTInfo("Number of tracks %d Number of TRD tracks %d", nTracks, nTRDTracks);
442 //esd->Print();
443 PushBack(esd, AliHLTTRDDefinitions::fgkTRDSAEsdDataType);
444
445 // extract the friend ?
446 // AliESDfriend *esdFriend = new AliESDfriend();
447 // esd->GetESDfriend(esdFriend);
448 // PushBack(esdFriend, AliHLTTRDDefinitions::fgkTRDSAEsdDataType);
449 // delete esdFriend;
450
451 //HLTInfo("now deleting");
452 delete esd;
453
454 delete clusterTree;
455 fTracker->UnloadClusters();
456
457 HLTDebug("Event done.");
458 return 0;
459}
460
461///////////////////////////////
462/*
463 consider transporting TRD tracks only as they might have signigicantly smaller size... on the other hand you will need to prodece ESDs at some point...
464
465// this is for ESDtrack
466// for (Int_t it = 0; it < nTracks; it++)
467// {
468// AliESDtrack* track = esd->GetTrack(it);
469// HLTInfo("Track %d 0x%x Pt %1.2f", it, track, track->Pt());
470// //PushBack(track, AliHLTTRDDefinitions::fgkTRDSATracksDataType, ++dBlockSpecification);
471// PushBack(track, AliHLTTRDDefinitions::fgkTRDSATracksDataType);
472// }
473
474// one can do similar things with the TRDtrack
475esd->GetNumberOfTrdTracks();
476and then
477for (i;;)
478AliESDTrdTrack *trdtrack = esd->GetTrdTrack(i)
479*/
480