1 // $Id: AliHLTTRDTrackerV1Component.cxx 23618 2008-01-29 13:07:38Z hristov $
3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line Project. *
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 **************************************************************************/
19 /** @file AliHLTTRDTrackerV1Component.cxx
20 @author Timm Steinbeck, Matthias Richter
22 @brief A TRDTrackerV1 processing component for the HLT. */
28 #include "AliHLTTRDTrackerV1Component.h"
29 #include "AliHLTTRDDefinitions.h"
30 #include "AliHLTTRDCluster.h"
31 #include "AliHLTTRDTrack.h"
32 #include "AliHLTTRDUtils.h"
37 #include "AliGeomManager.h"
38 #include "AliCDBManager.h"
39 #include "AliCDBStorage.h"
40 #include "AliESDEvent.h"
42 #include "AliESDfriend.h"
44 #include "AliTRDcalibDB.h"
45 #include "AliTRDReconstructor.h"
46 #include "AliTRDtrackerV1.h"
47 #include "AliTRDrecoParam.h"
53 #ifdef HAVE_VALGRIND_CALLGRIND_H
54 #include <valgrind/callgrind.h>
56 #define CALLGRIND_START_INSTRUMENTATION do { } while (0)
57 #define CALLGRIND_STOP_INSTRUMENTATION do { } while (0)
60 ClassImp(AliHLTTRDTrackerV1Component)
62 AliHLTTRDTrackerV1Component::AliHLTTRDTrackerV1Component():
64 fOutputPercentage(100), // By default we copy to the output exactly what we got as input
70 // Default constructor
74 AliHLTTRDTrackerV1Component::~AliHLTTRDTrackerV1Component()
79 const char* AliHLTTRDTrackerV1Component::GetComponentID()
81 // Return the component ID const char *
82 return "TRDTrackerV1"; // The ID of this component
85 void AliHLTTRDTrackerV1Component::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
87 // Get the list of input data
88 list.clear(); // We do not have any requirements for our input data type(s).
89 list.push_back( AliHLTTRDDefinitions::fgkClusterDataType );
92 AliHLTComponent_DataType AliHLTTRDTrackerV1Component::GetOutputDataType()
94 // Get the output data type
95 //return AliHLTTRDDefinitions::fgkClusterDataType;
96 return kAliHLTDataTypeTrack | kAliHLTDataOriginTRD;
99 void AliHLTTRDTrackerV1Component::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
101 // Get the output data size
103 inputMultiplier = ((double)fOutputPercentage)/100.0;
106 // Spawn function, return new instance of this class
107 AliHLTComponent* AliHLTTRDTrackerV1Component::Spawn()
109 return new AliHLTTRDTrackerV1Component;
113 int AliHLTTRDTrackerV1Component::DoInit( int argc, const char** argv )
115 // perform initialization. We check whether our relative output size is specified in the arguments.
116 fOutputPercentage = 100;
121 Int_t iRecoParamType = -1; // default will be the low flux
122 Int_t iNtimeBins = -1; // number of time bins for the tracker to use
123 Int_t iMagneticField = -1; // magnetic field: 0==OFF and 1==ON
124 Int_t iPIDmethod = 1; // 0=LikelyHood(LH) 1=NeuronalNetwork(NN) 2=TruncatedMean(TM)
125 Bool_t bHLTMode = kTRUE, bWriteClusters = kFALSE;
126 string geometryFileName = "";
130 HLTDebug("argv[%d] == %s", i, argv[i] );
131 if ( !strcmp( argv[i], "output_percentage" ) )
135 HLTError("Missing output_percentage parameter");
138 HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
139 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
142 HLTError("Cannot convert output_percentage parameter '%s'", argv[i+1] );
145 HLTInfo("Output percentage set to %i %%", fOutputPercentage );
148 else if ( !strcmp( argv[i], "-NTimeBins" ) )
152 HLTError("Missing -NTimeBins parameter");
155 HLTDebug("Arguments", "argv[%d+1] == %s", i, argv[i+1] );
156 iNtimeBins = strtoul( argv[i+1], &cpErr, 0 );
159 HLTError("Wrong Argument. Cannot convert -NTimeBins parameter '%s'", argv[i+1] );
164 else if ( strcmp( argv[i], "-geometry" ) == 0)
168 HLTError("Missing -geometry argument");
171 geometryFileName = argv[i+1];
172 HLTInfo("GeomFile storage is %s",
173 geometryFileName.c_str() );
176 // the flux parametrizations
177 else if ( strcmp( argv[i], "-lowflux" ) == 0)
180 HLTDebug("Low flux reco selected.");
183 else if ( strcmp( argv[i], "-highflux" ) == 0)
186 HLTDebug("Low flux reco selected.");
189 else if ( strcmp( argv[i], "-cosmics" ) == 0)
192 HLTDebug("Cosmic test reco selected.");
195 else if ( strcmp( argv[i], "-magnetic_field_ON" ) == 0)
200 else if ( strcmp( argv[i], "-magnetic_field_OFF" ) == 0)
205 else if ( strcmp( argv[i], "-offlineMode" ) == 0)
208 HLTDebug("Using standard offline tracking.");
211 else if ( strcmp( argv[i], "-PIDmethod" ) == 0)
215 HLTError("Missing -PIDmethod argument");
218 if( strcmp(argv[i], "LH") )
220 else if( strcmp(argv[i], "NN") )
222 else if( strcmp(argv[i], "TM") )
225 HLTError("Unknown -PIDmethod argument");
232 HLTError("Unknown option '%s'", argv[i] );
238 // THE "REAL" INIT COMES HERE
239 // offline condition data base
241 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
242 HLTError("DefaultStorage is not Set in CDBManager");
245 if(AliCDBManager::Instance()->GetRun()<0){
246 AliCDBManager *cdb = AliCDBManager::Instance();
250 HLTWarning("Setting CDB Runnumber to 0. CDB instance 0x%x", cdb);
254 HLTError("Could not get CDB instance", "cdb 0x%x", cdb);
258 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
260 if(!AliGeomManager::GetGeometry()){
261 if(!TFile::Open(geometryFileName.c_str())){
262 HLTInfo("Loading standard geometry file");
263 AliGeomManager::LoadGeometry();
265 HLTWarning("Loading non-standard geometry file");
266 AliGeomManager::LoadGeometry(geometryFileName.c_str());
268 if(!AliGeomManager::GetGeometry()){
269 HLTError("Cannot load geometry");
274 HLTInfo("Geometry Already Loaded");
277 // check if the N of time bins make sense
280 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.");
284 if (iNtimeBins < 24 || iNtimeBins > 30)
286 HLTWarning("The number of time bins seems to be strange = %d. But okay. Let's try it...", iNtimeBins);
289 HLTDebug("The number of time bins = %d.", iNtimeBins);
290 AliTRDtrackerV1::SetNTimeBins(iNtimeBins);
292 // !!!! THIS IS IMPORTANT
293 // init alifield map - temporarly via parameter - should come from a DB or DCS ?
295 if (iMagneticField < 0)
298 HLTWarning("No magnetic field switch stated. Use -magnetic_field_ON or -magnetic_field_OFF flag. Defaulting to OFF = NO MAGNETIC FIELD");
301 if (!TGeoGlobalMagField::Instance()->IsLocked()) {
302 if (iMagneticField == 0)
304 // magnetic field OFF
305 AliMagF* field = new AliMagF("Maps","Maps",2,0.,0., 10.,AliMagF::k5kGUniform);
306 TGeoGlobalMagField::Instance()->SetField(field);
307 HLTDebug("Magnetic field is OFF.");
310 if (iMagneticField == 1)
313 AliMagF* field = new AliMagF("Maps","Maps",2,1.,1., 10.,AliMagF::k5kG);
314 TGeoGlobalMagField::Instance()->SetField(field);
315 HLTDebug("Magnetic field is ON.");
319 HLTError("Magnetic field is already set and locked, cannot redefine it." );
322 // reconstruction parameters
323 if (iRecoParamType < 0 || iRecoParamType > 2)
325 HLTWarning("No reco param selected. Use -lowflux -highflux -cosmics flags. Defaulting to low flux.");
329 if (iRecoParamType == 0)
331 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
332 HLTDebug("Low flux params init.");
335 if (iRecoParamType == 1)
337 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
338 HLTDebug("High flux params init.");
341 if (iRecoParamType == 2)
343 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
344 HLTDebug("Cosmic Test params init.");
349 HLTError("No reco params initialized. Sniffing big trouble!");
353 fReconstructor = new AliTRDReconstructor();
354 // fRecoParam->SetChi2Y(.1);
355 // fRecoParam->SetChi2Z(5.);
356 fReconstructor->SetRecoParam(fRecoParam);
357 // write clusters [cw] = true
358 // track seeding (stand alone tracking) [sa] = true
359 // PID method in reconstruction (NN) [nn] = true
360 // write online tracklets [tw] = false
361 // drift gas [ar] = false
362 // sl_tr_0 = StreamLevel_task_Level
363 // fReconstructor->SetOption("sa,!cw,hlt,sl_tr_0");
364 TString recoOptions="sa,sl_tr_0";
368 recoOptions += ",cw";
372 recoOptions += ",!cw";
375 recoOptions += ",hlt";
378 case 0: recoOptions += ",!nn"; break;
379 case 1: recoOptions += ",nn"; break;
380 case 2: recoOptions += ",!nn"; break;
383 fReconstructor->SetOption(recoOptions.Data());
384 HLTDebug("Reconstructor options are: %s",recoOptions.Data());
386 // create the tracker
387 fTracker = new AliTRDtrackerV1();
388 HLTDebug("TRDTracker at 0x%x", fTracker);
389 fTracker->SetReconstructor(fReconstructor);
391 fESD = new AliESDEvent;
392 fESD->CreateStdContent();
397 int AliHLTTRDTrackerV1Component::DoDeinit()
399 // Deinitialization of the component
401 fTracker->SetClustersOwner(kFALSE);
405 // We need to set clusters in Reconstructor to null to prevent from
406 // double deleting, since we delete TClonesArray by ourself in DoEvent.
407 fReconstructor->SetClusters(0x0);
408 delete fReconstructor;
409 fReconstructor = 0x0;
413 AliTRDcalibDB::Terminate();
418 int AliHLTTRDTrackerV1Component::DoEvent( const AliHLTComponentEventData& evtData,
419 const AliHLTComponentBlockData* blocks,
420 AliHLTComponent_TriggerData& /*trigData*/,
421 AliHLTUInt8_t* outputPtr,
422 AliHLTUInt32_t& size,
423 vector<AliHLTComponent_BlockData>& outputBlocks )
427 if (evtData.fEventID == 1)
428 CALLGRIND_START_INSTRUMENTATION;
430 HLTDebug("NofBlocks %i", evtData.fBlockCnt );
433 //fESD->SetMagneticField(fSolenoidBz);
435 AliHLTUInt32_t totalSize = 0, offset = 0;
436 AliHLTUInt32_t dBlockSpecification = 0;
438 vector<AliHLTComponent_DataType> expectedDataTypes;
439 GetInputDataTypes(expectedDataTypes);
440 for ( unsigned long iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
442 const AliHLTComponentBlockData &block = blocks[iBlock];
443 AliHLTComponentDataType inputDataType = block.fDataType;
444 Bool_t correctDataType = kFALSE;
446 for(UInt_t i = 0; i < expectedDataTypes.size(); i++){
447 if( expectedDataTypes.at(i) == inputDataType)
448 correctDataType = kTRUE;
450 if (!correctDataType)
452 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - Skipping",
453 iBlock, evtData.fBlockCnt-1,
454 evtData.fEventID, evtData.fEventID,
455 DataType2Text(inputDataType).c_str());
459 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
460 iBlock, evtData.fBlockCnt-1,
461 evtData.fEventID, evtData.fEventID,
462 DataType2Text(inputDataType).c_str(),
467 TClonesArray* clusterArray = new TClonesArray("AliTRDcluster"); // would be nice to allocate memory for all clusters here.
468 AliHLTTRDUtils::ReadClusters(clusterArray, block.fPtr, block.fSize);
469 HLTDebug("TClonesArray of clusters: nbEntries = %i", clusterArray->GetEntriesFast());
470 fTracker->LoadClusters(clusterArray);
472 fTracker->Clusters2Tracks(fESD);
474 Int_t nTracks = fESD->GetNumberOfTracks();
475 HLTInfo("Number of tracks == %d ==", nTracks);
477 TClonesArray* trdTracks = 0x0;
478 //trdTracks = fTracker->GetListOfTracks();
481 HLTDebug("We have an output ESDEvent: 0x%x with %i tracks", fESD, nTracks);
482 AliHLTUInt32_t addedSize = AliHLTTRDUtils::AddESDToOutput(fESD, (AliHLTUInt8_t*)(outputPtr+offset));
483 totalSize += addedSize;
486 AliHLTComponentBlockData bd;
488 //bd.fPtr = outputPtr;
490 bd.fSize = addedSize;
491 bd.fSpecification = dBlockSpecification;
492 bd.fDataType = kAliHLTDataTypeTrack | kAliHLTDataOriginTRD;
493 outputBlocks.push_back( bd );
494 HLTDebug("BD fPtr 0x%x, fOffset %i, fSize %i, fSpec 0x%x", bd.fPtr, bd.fOffset, bd.fSize, bd.fSpecification);
498 //Int_t nbTracks=trdTracks->GetEntriesFast();
500 HLTDebug("We have an output array: pointer to trdTracks = 0x%x, nbEntries = %i", trdTracks, trdTracks->GetEntriesFast());
502 AliHLTUInt32_t addedSize = AliHLTTRDUtils::AddTracksToOutput(trdTracks, (AliHLTUInt8_t*)(outputPtr+offset));
503 totalSize += addedSize;
506 AliHLTComponentBlockData bd;
508 //bd.fPtr = outputPtr;
510 bd.fSize = addedSize;
511 bd.fSpecification = dBlockSpecification;
512 bd.fDataType = AliHLTTRDDefinitions::fgkTRDSATracksDataType;
513 outputBlocks.push_back( bd );
514 HLTDebug("BD fPtr 0x%x, fOffset %i, fSize %i, fSpec 0x%x", bd.fPtr, bd.fOffset, bd.fSize, bd.fSpecification);
521 // totalSize += TransportTracks(trdTracks, outputPtr, outputBlocks, offset, dBlockSpecification);
523 // HLTDebug("Bad array trdTracks = 0x%x", trdTracks);
526 HLTDebug("totalSize: %i", totalSize);
528 // if ( totalSize > allocSize )
530 // HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
531 // totalSize, size );
535 //here we are deleting clusters (but not the TClonesArray itself)
536 fTracker->UnloadClusters();
537 AliTRDReconstructor::SetClusters(0x0);
538 clusterArray->Delete();
544 HLTDebug("Event is done. size written to the output is %i", size);