1 // $Id: AliHLTTRDTrackerV1Component.cxx 23618 2008-01-29 13:07:38Z hristov $
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
8 //* for The ALICE HLT 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
22 @brief A TRDTrackerV1 processing component for the HLT.
29 #include "AliHLTTRDTrackerV1Component.h"
30 #include "AliHLTTRDDefinitions.h"
31 #include "AliHLTTRDTrack.h"
32 #include "AliHLTTRDUtils.h"
37 #include "AliGeomManager.h"
38 #include "AliCDBManager.h"
39 #include "AliCDBStorage.h"
40 #include "AliCDBEntry.h"
41 #include "AliESDEvent.h"
42 #include "AliESDfriend.h"
44 #include "AliTRDcalibDB.h"
45 #include "AliTRDReconstructor.h"
46 #include "AliTRDtrackerV1.h"
47 #include "AliTRDrecoParam.h"
53 ClassImp(AliHLTTRDTrackerV1Component)
55 AliHLTTRDTrackerV1Component::AliHLTTRDTrackerV1Component():
57 fOutputPercentage(100), // By default we copy to the output exactly what we got as input
66 fgeometryFileName(""),
68 fOutputV1Tracks(kTRUE),
69 fHighLevelOutput(kFALSE),
70 fEmulateHLTTracks(kFALSE),
71 fImproveTracklets(kTRUE)
73 // Default constructor
77 AliHLTTRDTrackerV1Component::~AliHLTTRDTrackerV1Component()
82 const char* AliHLTTRDTrackerV1Component::GetComponentID()
84 // Return the component ID const char *
85 return "TRDTrackerV1"; // The ID of this component
88 void AliHLTTRDTrackerV1Component::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
90 // Get the list of input data
91 list.clear(); // We do not have any requirements for our input data type(s).
92 list.push_back(AliHLTTRDDefinitions::fgkClusterDataType);
95 AliHLTComponentDataType AliHLTTRDTrackerV1Component::GetOutputDataType()
97 // Get the output data type
98 return kAliHLTMultipleDataType;
101 int AliHLTTRDTrackerV1Component::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
103 // Get the output data types
105 tgtList.push_back(kAliHLTDataTypeTrack | kAliHLTDataOriginTRD);
106 tgtList.push_back(AliHLTTRDDefinitions::fgkTracksDataType);
107 return tgtList.size();
110 void AliHLTTRDTrackerV1Component::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
112 // Get the output data size
114 inputMultiplier = fOutputV1Tracks ? 2*((double)fOutputPercentage)/100.0 : 0.5*((double)fOutputPercentage)/100.0;
117 // Spawn function, return new instance of this class
118 AliHLTComponent* AliHLTTRDTrackerV1Component::Spawn()
120 return new AliHLTTRDTrackerV1Component;
124 int AliHLTTRDTrackerV1Component::DoInit( int argc, const char** argv )
126 // perform initialization. We check whether our relative output size is specified in the arguments.
129 fReconstructor = new AliTRDReconstructor();
130 HLTDebug("TRDReconstructor at 0x%x", fReconstructor);
132 fESD = new AliESDEvent;
133 fESD->CreateStdContent();
135 TString configuration="";
137 for (int i=0; i<argc && iResult>=0; i++) {
139 if (!configuration.IsNull()) configuration+=" ";
140 configuration+=argument;
143 if (!configuration.IsNull()) {
144 iResult=Configure(configuration.Data());
146 iResult=Reconfigure(NULL, NULL);
149 if(iResult<0) return iResult;
151 fTracker = new AliTRDtrackerV1();
152 HLTDebug("TRDTracker at 0x%x", fTracker);
153 fTracker->SetReconstructor(fReconstructor);
155 fClusterArray = new TClonesArray("AliTRDcluster"); // would be nice to allocate memory for all clusters here.
160 int AliHLTTRDTrackerV1Component::DoDeinit()
162 // Deinitialization of the component
164 fTracker->SetClustersOwner(kFALSE);
168 fClusterArray->Delete();
169 delete fClusterArray;
170 fClusterArray = NULL;
172 // We need to set clusters in Reconstructor to null to prevent from
173 // double deleting, since we delete TClonesArray by ourself.
174 fReconstructor->SetClusters(0x0);
175 delete fReconstructor;
176 fReconstructor = NULL;
180 AliTRDcalibDB::Terminate();
185 int AliHLTTRDTrackerV1Component::DoEvent( const AliHLTComponentEventData& evtData,
186 const AliHLTComponentBlockData* blocks,
187 AliHLTComponent_TriggerData& /*trigData*/,
188 AliHLTUInt8_t* outputPtr,
189 AliHLTUInt32_t& size,
190 vector<AliHLTComponent_BlockData>& outputBlocks )
194 HLTDebug("NofBlocks %i", evtData.fBlockCnt );
197 //fESD->SetMagneticField(GetBz());
199 AliHLTUInt32_t totalSize = 0, offset = 0;
201 AliHLTComponentDataType expectedDataType = AliHLTTRDDefinitions::fgkClusterDataType;
202 for ( unsigned long iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
204 const AliHLTComponentBlockData &block = blocks[iBlock];
205 AliHLTComponentDataType inputDataType = block.fDataType;
207 if(inputDataType != expectedDataType)
209 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - Skipping",
210 iBlock, evtData.fBlockCnt-1,
211 evtData.fEventID, evtData.fEventID,
212 DataType2Text(inputDataType).c_str());
216 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
217 iBlock, evtData.fBlockCnt-1,
218 evtData.fEventID, evtData.fEventID,
219 DataType2Text(inputDataType).c_str(),
224 unsigned long constBase;
225 double inputMultiplier;
226 GetOutputDataSize(constBase,inputMultiplier);
227 if(size<(constBase+block.fSize*inputMultiplier)){
228 HLTWarning("Memory Block given might be too small: %i < %i; Event %Lu", size, constBase+block.fSize*inputMultiplier, evtData.fEventID);
232 AliHLTTRDUtils::ReadClusters(fClusterArray, block.fPtr, block.fSize, &fNtimeBins);
233 HLTDebug("Reading number of time bins from input block. Setting number of timebins to %d", fNtimeBins);
234 AliTRDtrackerV1::SetNTimeBins(fNtimeBins);
236 HLTDebug("TClonesArray of clusters: nbEntries = %i", fClusterArray->GetEntriesFast());
237 fTracker->LoadClusters(fClusterArray);
239 fTracker->Clusters2Tracks(fESD);
241 Int_t nTracks = fESD->GetNumberOfTracks();
242 HLTInfo("Number of tracks == %d ==", nTracks);
244 TClonesArray* trdTracks;
245 trdTracks = fTracker->GetListOfTracks();
247 if(fHighLevelOutput){
248 if(fEmulateHLTTracks && trdTracks){
249 // TClonesArray* oldArr = trdTracks;
250 trdTracks = new TClonesArray(*trdTracks);
251 AliHLTTRDUtils::EmulateHLTTracks(trdTracks);
252 // if(oldArr->At(0)){
253 // HLTInfo("Old Track:");
254 // ((AliTRDtrackV1*)oldArr->At(0))->Print("a");
255 // HLTInfo("\nNew Track:");
256 // ((AliTRDtrackV1*)trdTracks->At(0))->Print("a");
261 strg.String() += fNtimeBins;
262 PushBack(trdTracks, AliHLTTRDDefinitions::fgkHiLvlTracksDataType, 0);
263 PushBack(&strg, AliHLTTRDDefinitions::fgkHiLvlTracksDataType, 0);
265 if(fEmulateHLTTracks && trdTracks){
271 HLTDebug("We have an output ESDEvent: 0x%x with %i tracks", fESD, nTracks);
272 AliHLTUInt32_t addedSize = AliHLTTRDUtils::AddESDToOutput(fESD, outputPtr+offset);
273 totalSize += addedSize;
276 AliHLTComponentBlockData bd;
278 //bd.fPtr = outputPtr;
280 bd.fSize = addedSize;
281 bd.fSpecification = block.fSpecification;
282 bd.fDataType = kAliHLTDataTypeTrack | kAliHLTDataOriginTRD;
283 outputBlocks.push_back( bd );
284 HLTDebug("BD ptr 0x%x, offset %i, size %i, datav1Type %s, spec 0x%x ", bd.fPtr, bd.fOffset, bd.fSize, DataType2Text(bd.fDataType).c_str(), bd.fSpecification);
287 if (fOutputV1Tracks && trdTracks){
288 HLTDebug("We have an output array: pointer to trdTracks = 0x%x, nbEntries = %i", trdTracks, trdTracks->GetEntriesFast());
290 addedSize = AliHLTTRDUtils::AddTracksToOutput(trdTracks, outputPtr+offset, fNtimeBins);
291 totalSize += addedSize;
295 //bd.fPtr = outputPtr;
297 bd.fSize = addedSize;
298 bd.fSpecification = block.fSpecification;
299 bd.fDataType = AliHLTTRDDefinitions::fgkTracksDataType;
300 outputBlocks.push_back( bd );
301 HLTDebug("BD ptr 0x%x, offset %i, size %i, dataType %s, spec 0x%x ", bd.fPtr, bd.fOffset, bd.fSize, DataType2Text(bd.fDataType).c_str(), bd.fSpecification);
306 HLTDebug("totalSize: %i", totalSize);
308 // if ( totalSize > allocSize )
310 // HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
311 // totalSize, size );
315 //here we are deleting clusters (but not the TClonesArray itself)
316 fTracker->UnloadClusters();
317 AliTRDReconstructor::SetClusters(0x0);
318 fClusterArray->Delete();
323 HLTDebug("Event is done. size written to the output is %i", size);
327 int AliHLTTRDTrackerV1Component::Configure(const char* arguments){
329 if (!arguments) return iResult;
331 TString allArgs=arguments;
335 TObjArray* pTokens=allArgs.Tokenize(" ");
337 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
338 argument=((TObjString*)pTokens->At(i))->GetString();
339 if (argument.IsNull()) continue;
341 if (argument.CompareTo("output_percentage")==0) {
342 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
343 HLTInfo("Setting output percentage to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
344 fOutputPercentage=((TObjString*)pTokens->At(i))->GetString().Atoi();
347 else if (argument.CompareTo("-solenoidBz")==0) {
348 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
349 HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
352 else if (argument.CompareTo("-geometry")==0) {
353 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
354 HLTInfo("Setting geometry to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
355 fgeometryFileName=((TObjString*)pTokens->At(i))->GetString();
358 else if (argument.CompareTo("-lowflux")==0) {
360 HLTInfo("Low flux reconstruction selected");
363 else if (argument.CompareTo("-highflux")==0) {
365 HLTInfo("High flux reconstruction selected");
368 else if (argument.CompareTo("-cosmics")==0) {
370 HLTInfo("Cosmics reconstruction selected");
373 else if (argument.CompareTo("-HLTflag")==0) {
374 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
375 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
376 if (toCompareTo.CompareTo("yes")==0){
377 HLTInfo("Setting HLTflag to: %s", toCompareTo.Data());
380 else if (toCompareTo.CompareTo("no")==0){
381 HLTInfo("Setting HLTflag to: %s", toCompareTo.Data());
385 HLTError("unknown argument for HLTflag: %s", toCompareTo.Data());
391 else if (argument.CompareTo("-outputV1Tracks")==0) {
392 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
393 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
394 if (toCompareTo.CompareTo("yes")==0){
395 HLTInfo("Setting OutputV1Tracks to: %s", toCompareTo.Data());
396 fOutputV1Tracks=kTRUE;
398 else if (toCompareTo.CompareTo("no")==0){
399 HLTInfo("Setting OutputV1Tracks to: %s", toCompareTo.Data());
400 fOutputV1Tracks=kFALSE;
403 HLTError("unknown argument for OutputV1Tracks: %s", toCompareTo.Data());
409 else if (argument.CompareTo("-highLevelOutput")==0) {
410 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
411 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
412 if (toCompareTo.CompareTo("yes")==0){
413 HLTWarning("Setting highLevelOutput to: %s", toCompareTo.Data());
414 fHighLevelOutput=kTRUE;
416 else if (toCompareTo.CompareTo("no")==0){
417 HLTInfo("Setting highLevelOutput to: %s", toCompareTo.Data());
418 fHighLevelOutput=kFALSE;
421 HLTError("unknown argument for highLevelOutput: %s", toCompareTo.Data());
427 else if (argument.CompareTo("-emulateHLTTracks")==0) {
428 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
429 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
430 if (toCompareTo.CompareTo("yes")==0){
431 HLTWarning("Setting emulateHLTTracks to: %s", toCompareTo.Data());
432 fEmulateHLTTracks=kTRUE;
434 else if (toCompareTo.CompareTo("no")==0){
435 HLTInfo("Setting emulateHLTTracks to: %s", toCompareTo.Data());
436 fEmulateHLTTracks=kFALSE;
439 HLTError("unknown argument for emulateHLTTracks: %s", toCompareTo.Data());
445 else if (argument.CompareTo("-PIDmethod")==0) {
446 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
447 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
448 if (toCompareTo.CompareTo("LH")==0){
449 HLTInfo("Setting PID method to: %s", toCompareTo.Data());
452 else if (toCompareTo.CompareTo("NN")==0){
453 HLTInfo("Setting PID method to: %s", toCompareTo.Data());
456 else if (toCompareTo.CompareTo("TM")==0){
457 HLTInfo("Setting PID method to: %s", toCompareTo.Data());
461 HLTError("unknown argument for PID method: %s", toCompareTo.Data());
469 HLTError("unknown argument: %s", argument.Data());
477 HLTError("missing parameter for argument %s", argument.Data());
486 int AliHLTTRDTrackerV1Component::SetParams()
489 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
490 HLTError("DefaultStorage is not set in CDBManager");
493 if(AliCDBManager::Instance()->GetRun()<0){
494 HLTError("Run Number is not set in CDBManager");
497 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
499 if(!AliGeomManager::GetGeometry()){
500 if(fgeometryFileName.CompareTo("")==0 || !TFile::Open(fgeometryFileName.Data())){
501 HLTInfo("Loading standard geometry file");
502 AliGeomManager::LoadGeometry();
504 HLTWarning("Loading NON-standard geometry file");
505 AliGeomManager::LoadGeometry(fgeometryFileName.Data());
507 if(!AliGeomManager::GetGeometry()){
508 HLTError("Could not load geometry");
511 HLTInfo("Applying Alignment from CDB object");
512 AliGeomManager::ApplyAlignObjsFromCDB("TRD");
515 HLTInfo("Geometry Already Loaded!");
518 if(fReconstructor->GetRecoParam()){
519 fRecoParam = new AliTRDrecoParam(*fReconstructor->GetRecoParam());
520 HLTInfo("RecoParam already set!");
522 if(fRecoParamType == 0){
523 HLTDebug("Low flux params init.");
524 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
526 if(fRecoParamType == 1){
527 HLTDebug("High flux params init.");
528 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
530 if(fRecoParamType == 2){
531 HLTDebug("Cosmic Test params init.");
532 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
538 HLTError("No reco params initialized. Sniffing big trouble!");
542 // backward compatibility to AliTRDrecoParam < r34995
543 # ifndef HAVE_NOT_ALITRDRECOPARAM_r34995
544 # define AliTRDRecoParamSetPIDNeuralNetwork(b) fRecoParam->SetPIDNeuralNetwork(b)
546 # define AliTRDRecoParamSetPIDNeuralNetwork(b) fRecoParam->SetPIDNeuralNetwork()
550 case 0: AliTRDRecoParamSetPIDNeuralNetwork(kFALSE); break;
551 case 1: AliTRDRecoParamSetPIDNeuralNetwork(kTRUE); break;
552 case 2: AliTRDRecoParamSetPIDNeuralNetwork(kFALSE); break;
555 fRecoParam->SetImproveTracklets(fImproveTracklets);
557 fRecoParam->SetStreamLevel(AliTRDrecoParam::kTracker, 0);
558 fReconstructor->SetRecoParam(fRecoParam);
560 TString recoOptions="sa,!cw";
563 recoOptions += ",hlt";
565 HLTDebug("Reconstructor options are: %s",recoOptions.Data());
566 fReconstructor->SetOption(recoOptions.Data());
571 int AliHLTTRDTrackerV1Component::Reconfigure(const char* cdbEntry, const char* chainId)
573 // see header file for class documentation
576 const char* path="HLT/ConfigTRD/TrackerV1Component";
577 const char* defaultNotify="";
580 defaultNotify=" (default)";
583 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
584 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
586 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
588 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
589 iResult=Configure(pString->GetString().Data());
591 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
594 HLTError("cannot fetch object \"%s\" from CDB", path);
602 int AliHLTTRDTrackerV1Component::ReadPreprocessorValues(const char* modules)
604 // see header file for class documentation
607 TString str(modules);
608 if(str.Contains("HLT") || str.Contains("TRD") || str.Contains("GRP")){