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 "AliHLTTRDCluster.h"
32 #include "AliHLTTRDTrack.h"
33 #include "AliHLTTRDUtils.h"
38 #include "AliGeomManager.h"
39 #include "AliCDBManager.h"
40 #include "AliCDBStorage.h"
41 #include "AliCDBEntry.h"
42 #include "AliESDEvent.h"
43 #include "AliESDfriend.h"
45 #include "AliTRDcalibDB.h"
46 #include "AliTRDReconstructor.h"
47 #include "AliTRDtrackerV1.h"
48 #include "AliTRDrecoParam.h"
54 #ifdef HAVE_VALGRIND_CALLGRIND_H
55 #include <valgrind/callgrind.h>
57 #define CALLGRIND_START_INSTRUMENTATION do { } while (0)
58 #define CALLGRIND_STOP_INSTRUMENTATION do { } while (0)
61 ClassImp(AliHLTTRDTrackerV1Component)
63 AliHLTTRDTrackerV1Component::AliHLTTRDTrackerV1Component():
65 fOutputPercentage(100), // By default we copy to the output exactly what we got as input
75 fgeometryFileName(""),
77 fSlowTracking(kFALSE),
78 fOutputV1Tracks(kTRUE)
80 // Default constructor
84 AliHLTTRDTrackerV1Component::~AliHLTTRDTrackerV1Component()
89 const char* AliHLTTRDTrackerV1Component::GetComponentID()
91 // Return the component ID const char *
92 return "TRDTrackerV1"; // The ID of this component
95 void AliHLTTRDTrackerV1Component::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
97 // Get the list of input data
98 list.clear(); // We do not have any requirements for our input data type(s).
99 list.push_back(AliHLTTRDDefinitions::fgkClusterDataType);
102 AliHLTComponentDataType AliHLTTRDTrackerV1Component::GetOutputDataType()
104 // Get the output data type
105 return kAliHLTMultipleDataType;
108 int AliHLTTRDTrackerV1Component::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
110 // Get the output data types
112 //tgtList.push_back(AliHLTTRDDefinitions::fgkTimeBinPropagationDataType);
113 tgtList.push_back(kAliHLTDataTypeTrack | kAliHLTDataOriginTRD);
114 tgtList.push_back(AliHLTTRDDefinitions::fgkTRDSATracksDataType);
115 return tgtList.size();
118 void AliHLTTRDTrackerV1Component::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
120 // Get the output data size
122 inputMultiplier = fOutputV1Tracks ? 2*((double)fOutputPercentage)/100.0 : 0.5*((double)fOutputPercentage)/100.0;
125 // Spawn function, return new instance of this class
126 AliHLTComponent* AliHLTTRDTrackerV1Component::Spawn()
128 return new AliHLTTRDTrackerV1Component;
132 int AliHLTTRDTrackerV1Component::DoInit( int argc, const char** argv )
134 // perform initialization. We check whether our relative output size is specified in the arguments.
137 fReconstructor = new AliTRDReconstructor();
138 HLTDebug("TRDReconstructor at 0x%x", fReconstructor);
140 fESD = new AliESDEvent;
141 fESD->CreateStdContent();
143 TString configuration="";
145 for (int i=0; i<argc && iResult>=0; i++) {
147 if (!configuration.IsNull()) configuration+=" ";
148 configuration+=argument;
151 if (!configuration.IsNull()) {
152 iResult=Configure(configuration.Data());
154 iResult=Reconfigure(NULL, NULL);
157 if(iResult<0) return iResult;
159 fTracker = new AliTRDtrackerV1();
160 HLTDebug("TRDTracker at 0x%x", fTracker);
161 fTracker->SetReconstructor(fReconstructor);
163 fClusterArray = new TClonesArray("AliTRDcluster"); // would be nice to allocate memory for all clusters here.
168 int AliHLTTRDTrackerV1Component::DoDeinit()
170 // Deinitialization of the component
172 fTracker->SetClustersOwner(kFALSE);
176 fClusterArray->Delete();
177 delete fClusterArray;
178 fClusterArray = NULL;
180 // We need to set clusters in Reconstructor to null to prevent from
181 // double deleting, since we delete TClonesArray by ourself.
182 fReconstructor->SetClusters(0x0);
183 delete fReconstructor;
184 fReconstructor = NULL;
188 AliTRDcalibDB::Terminate();
193 int AliHLTTRDTrackerV1Component::DoEvent( const AliHLTComponentEventData& evtData,
194 const AliHLTComponentBlockData* blocks,
195 AliHLTComponent_TriggerData& /*trigData*/,
196 AliHLTUInt8_t* outputPtr,
197 AliHLTUInt32_t& size,
198 vector<AliHLTComponent_BlockData>& outputBlocks )
202 if (evtData.fEventID == 1)
203 CALLGRIND_START_INSTRUMENTATION;
205 HLTDebug("NofBlocks %i", evtData.fBlockCnt );
208 //fESD->SetMagneticField(GetBz());
210 AliHLTUInt32_t totalSize = 0, offset = 0;
212 vector<AliHLTComponent_DataType> expectedDataTypes;
213 GetInputDataTypes(expectedDataTypes);
214 for ( unsigned long iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
216 const AliHLTComponentBlockData &block = blocks[iBlock];
217 AliHLTComponentDataType inputDataType = block.fDataType;
218 Bool_t correctDataType = kFALSE;
220 for(UInt_t i = 0; i < expectedDataTypes.size(); i++){
221 if( expectedDataTypes.at(i) == inputDataType)
222 correctDataType = kTRUE;
224 if (!correctDataType)
226 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - Skipping",
227 iBlock, evtData.fBlockCnt-1,
228 evtData.fEventID, evtData.fEventID,
229 DataType2Text(inputDataType).c_str());
233 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
234 iBlock, evtData.fBlockCnt-1,
235 evtData.fEventID, evtData.fEventID,
236 DataType2Text(inputDataType).c_str(),
241 unsigned long constBase;
242 double inputMultiplier;
243 GetOutputDataSize(constBase,inputMultiplier);
244 if(size<(constBase+block.fSize*inputMultiplier)){
245 HLTWarning("Memory Block given might be too small: %i < %i; Event %Lu", size, constBase+block.fSize*inputMultiplier, evtData.fEventID);
249 AliHLTTRDUtils::ReadClusters(fClusterArray, block.fPtr, block.fSize, &fNtimeBins);
250 HLTDebug("Reading number of time bins from input block. Setting number of timebins to %d", fNtimeBins);
251 AliTRDtrackerV1::SetNTimeBins(fNtimeBins);
253 HLTDebug("TClonesArray of clusters: nbEntries = %i", fClusterArray->GetEntriesFast());
254 fTracker->LoadClusters(fClusterArray);
256 fTracker->Clusters2Tracks(fESD);
258 Int_t nTracks = fESD->GetNumberOfTracks();
259 HLTInfo("Number of tracks == %d ==", nTracks);
261 TClonesArray* trdTracks;
262 trdTracks = fTracker->GetListOfTracks();
265 HLTDebug("We have an output ESDEvent: 0x%x with %i tracks", fESD, nTracks);
266 AliHLTUInt32_t addedSize = AliHLTTRDUtils::AddESDToOutput(fESD, outputPtr+offset);
267 totalSize += addedSize;
270 AliHLTComponentBlockData bd;
272 //bd.fPtr = outputPtr;
274 bd.fSize = addedSize;
275 bd.fSpecification = block.fSpecification;
276 bd.fDataType = kAliHLTDataTypeTrack | kAliHLTDataOriginTRD;
277 outputBlocks.push_back( bd );
278 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);
281 if (fOutputV1Tracks && trdTracks){
282 HLTDebug("We have an output array: pointer to trdTracks = 0x%x, nbEntries = %i", trdTracks, trdTracks->GetEntriesFast());
284 addedSize = AliHLTTRDUtils::AddTracksToOutput(trdTracks, outputPtr+offset, fNtimeBins);
285 totalSize += addedSize;
289 //bd.fPtr = outputPtr;
291 bd.fSize = addedSize;
292 bd.fSpecification = block.fSpecification;
293 bd.fDataType = AliHLTTRDDefinitions::fgkTRDSATracksDataType;
294 outputBlocks.push_back( bd );
295 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);
300 HLTDebug("totalSize: %i", totalSize);
302 // if ( totalSize > allocSize )
304 // HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
305 // totalSize, size );
309 //here we are deleting clusters (but not the TClonesArray itself)
310 fTracker->UnloadClusters();
311 AliTRDReconstructor::SetClusters(0x0);
312 fClusterArray->Delete();
317 HLTDebug("Event is done. size written to the output is %i", size);
321 int AliHLTTRDTrackerV1Component::Configure(const char* arguments){
323 if (!arguments) return iResult;
325 TString allArgs=arguments;
329 TObjArray* pTokens=allArgs.Tokenize(" ");
331 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
332 argument=((TObjString*)pTokens->At(i))->GetString();
333 if (argument.IsNull()) continue;
335 if (argument.CompareTo("output_percentage")==0) {
336 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
337 HLTInfo("Setting output percentage to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
338 fOutputPercentage=((TObjString*)pTokens->At(i))->GetString().Atoi();
341 else if (argument.CompareTo("-solenoidBz")==0) {
342 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
343 HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
346 else if (argument.CompareTo("-NTimeBins")==0) {
347 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
348 HLTInfo("Option depreceated");
351 else if (argument.CompareTo("-geometry")==0) {
352 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
353 HLTInfo("Setting geometry to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
354 fgeometryFileName=((TObjString*)pTokens->At(i))->GetString();
357 else if (argument.CompareTo("-lowflux")==0) {
359 HLTInfo("Low flux reconstruction selected");
362 else if (argument.CompareTo("-highflux")==0) {
364 HLTInfo("High flux reconstruction selected");
367 else if (argument.CompareTo("-cosmics")==0) {
369 HLTInfo("Cosmics reconstruction selected");
372 else if (argument.CompareTo("-magnetic_field_ON")==0) {
374 HLTInfo("Reconstructon with magnetic field");
377 else if (argument.CompareTo("-magnetic_field_OFF")==0) {
379 HLTInfo("Reconstructon without magnetic field");
382 else if (argument.CompareTo("-slowTracking")==0) {
383 fSlowTracking = kTRUE;
384 HLTInfo("Using slow tracking");
387 else if (argument.CompareTo("-outputV1Tracks")==0) {
388 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
389 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
390 if (toCompareTo.CompareTo("yes")==0){
391 HLTInfo("Setting OutputV1Tracks to: %s", toCompareTo.Data());
392 fOutputV1Tracks=kTRUE;
394 else if (toCompareTo.CompareTo("no")==0){
395 HLTInfo("Setting OutputV1Tracks to: %s", toCompareTo.Data());
396 fOutputV1Tracks=kFALSE;
399 HLTError("unknown argument for OutputV1Tracks: %s", toCompareTo.Data());
405 else if (argument.CompareTo("-PIDmethod")==0) {
406 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
407 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
408 if (toCompareTo.CompareTo("LH")==0){
409 HLTInfo("Setting PID method to: %s", toCompareTo.Data());
412 else if (toCompareTo.CompareTo("NN")==0){
413 HLTInfo("Setting PID method to: %s", toCompareTo.Data());
416 else if (toCompareTo.CompareTo("TM")==0){
417 HLTInfo("Setting PID method to: %s", toCompareTo.Data());
421 HLTError("unknown argument for PID method: %s", toCompareTo.Data());
429 HLTError("unknown argument: %s", argument.Data());
437 HLTError("missing parameter for argument %s", argument.Data());
446 int AliHLTTRDTrackerV1Component::SetParams()
449 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
450 HLTError("DefaultStorage is not set in CDBManager");
453 if(AliCDBManager::Instance()->GetRun()<0){
454 HLTError("Run Number is not set in CDBManager");
457 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
459 if(!AliGeomManager::GetGeometry()){
460 if(fgeometryFileName.CompareTo("")==0 || !TFile::Open(fgeometryFileName.Data())){
461 HLTInfo("Loading standard geometry file");
462 AliGeomManager::LoadGeometry();
464 HLTWarning("Loading NON-standard geometry file");
465 AliGeomManager::LoadGeometry(fgeometryFileName.Data());
467 if(!AliGeomManager::GetGeometry()){
468 HLTError("Could not load geometry");
471 HLTInfo("Applying Alignment from CDB object");
472 AliGeomManager::ApplyAlignObjsFromCDB("TRD");
475 HLTInfo("Geometry Already Loaded!");
478 if (fRecoParamType == 0)
480 HLTDebug("Low flux params init.");
481 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
484 if (fRecoParamType == 1)
486 HLTDebug("High flux params init.");
487 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
490 if (fRecoParamType == 2)
492 HLTDebug("Cosmic Test params init.");
493 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
498 HLTError("No reco params initialized. Sniffing big trouble!");
502 // backward compatibility to AliTRDrecoParam < r34995
503 # ifndef HAVE_NOT_ALITRDRECOPARAM_r34995
504 # define AliTRDRecoParamSetPIDNeuralNetwork(b) fRecoParam->SetPIDNeuralNetwork(b)
506 # define AliTRDRecoParamSetPIDNeuralNetwork(b) fRecoParam->SetPIDNeuralNetwork()
510 case 0: AliTRDRecoParamSetPIDNeuralNetwork(kFALSE); break;
511 case 1: AliTRDRecoParamSetPIDNeuralNetwork(kTRUE); break;
512 case 2: AliTRDRecoParamSetPIDNeuralNetwork(kFALSE); break;
515 fRecoParam->SetStreamLevel(AliTRDrecoParam::kTracker, 0);
516 fReconstructor->SetRecoParam(fRecoParam);
518 TString recoOptions="sa,!cw";
521 recoOptions += ",hlt";
523 HLTDebug("Reconstructor options are: %s",recoOptions.Data());
524 fReconstructor->SetOption(recoOptions.Data());
529 int AliHLTTRDTrackerV1Component::Reconfigure(const char* cdbEntry, const char* chainId)
531 // see header file for class documentation
534 const char* path="HLT/ConfigTRD/TrackerV1Component";
535 const char* defaultNotify="";
538 defaultNotify=" (default)";
541 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
542 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
544 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
546 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
547 iResult=Configure(pString->GetString().Data());
549 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
552 HLTError("cannot fetch object \"%s\" from CDB", path);
560 int AliHLTTRDTrackerV1Component::ReadPreprocessorValues(const char* modules)
562 // see header file for class documentation
565 TString str(modules);
566 if(str.Contains("HLT") || str.Contains("TRD") || str.Contains("GRP")){