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"
44 #include "AliESDfriend.h"
46 #include "AliTRDcalibDB.h"
47 #include "AliTRDReconstructor.h"
48 #include "AliTRDtrackerV1.h"
49 #include "AliTRDrecoParam.h"
55 #ifdef HAVE_VALGRIND_CALLGRIND_H
56 #include <valgrind/callgrind.h>
58 #define CALLGRIND_START_INSTRUMENTATION do { } while (0)
59 #define CALLGRIND_STOP_INSTRUMENTATION do { } while (0)
62 ClassImp(AliHLTTRDTrackerV1Component)
64 AliHLTTRDTrackerV1Component::AliHLTTRDTrackerV1Component():
66 fOutputPercentage(100), // By default we copy to the output exactly what we got as input
76 fgeometryFileName(""),
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 AliHLTComponent_DataType AliHLTTRDTrackerV1Component::GetOutputDataType()
104 // Get the output data type
105 //return AliHLTTRDDefinitions::fgkClusterDataType;
106 return kAliHLTDataTypeTrack | kAliHLTDataOriginTRD;
109 void AliHLTTRDTrackerV1Component::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
111 // Get the output data size
113 inputMultiplier = ((double)fOutputPercentage)/100.0;
116 // Spawn function, return new instance of this class
117 AliHLTComponent* AliHLTTRDTrackerV1Component::Spawn()
119 return new AliHLTTRDTrackerV1Component;
123 int AliHLTTRDTrackerV1Component::DoInit( int argc, const char** argv )
125 // perform initialization. We check whether our relative output size is specified in the arguments.
128 fReconstructor = new AliTRDReconstructor();
129 HLTDebug("TRDReconstructor at 0x%x", fReconstructor);
131 fESD = new AliESDEvent;
132 fESD->CreateStdContent();
134 TString configuration="";
136 for (int i=0; i<argc && iResult>=0; i++) {
138 if (!configuration.IsNull()) configuration+=" ";
139 configuration+=argument;
142 if (!configuration.IsNull()) {
143 iResult=Configure(configuration.Data());
145 iResult=Reconfigure(NULL, NULL);
148 if(iResult<0) return iResult;
150 fTracker = new AliTRDtrackerV1();
151 HLTDebug("TRDTracker at 0x%x", fTracker);
152 fTracker->SetReconstructor(fReconstructor);
154 fClusterArray = new TClonesArray("AliTRDcluster"); // would be nice to allocate memory for all clusters here.
159 int AliHLTTRDTrackerV1Component::DoDeinit()
161 // Deinitialization of the component
163 fTracker->SetClustersOwner(kFALSE);
167 fClusterArray->Delete();
168 delete fClusterArray;
170 // We need to set clusters in Reconstructor to null to prevent from
171 // double deleting, since we delete TClonesArray by ourself in DoEvent.
172 fReconstructor->SetClusters(0x0);
173 delete fReconstructor;
174 fReconstructor = 0x0;
178 AliTRDcalibDB::Terminate();
183 int AliHLTTRDTrackerV1Component::DoEvent( const AliHLTComponentEventData& evtData,
184 const AliHLTComponentBlockData* blocks,
185 AliHLTComponent_TriggerData& /*trigData*/,
186 AliHLTUInt8_t* outputPtr,
187 AliHLTUInt32_t& size,
188 vector<AliHLTComponent_BlockData>& outputBlocks )
192 if (evtData.fEventID == 1)
193 CALLGRIND_START_INSTRUMENTATION;
195 HLTDebug("NofBlocks %i", evtData.fBlockCnt );
198 //fESD->SetMagneticField(fSolenoidBz);
200 AliHLTUInt32_t totalSize = 0, offset = 0;
201 AliHLTUInt32_t dBlockSpecification = 0;
203 vector<AliHLTComponent_DataType> expectedDataTypes;
204 GetInputDataTypes(expectedDataTypes);
205 for ( unsigned long iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
207 const AliHLTComponentBlockData &block = blocks[iBlock];
208 AliHLTComponentDataType inputDataType = block.fDataType;
209 Bool_t correctDataType = kFALSE;
211 for(UInt_t i = 0; i < expectedDataTypes.size(); i++){
212 if( expectedDataTypes.at(i) == inputDataType)
213 correctDataType = kTRUE;
215 if (!correctDataType)
217 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - Skipping",
218 iBlock, evtData.fBlockCnt-1,
219 evtData.fEventID, evtData.fEventID,
220 DataType2Text(inputDataType).c_str());
224 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
225 iBlock, evtData.fBlockCnt-1,
226 evtData.fEventID, evtData.fEventID,
227 DataType2Text(inputDataType).c_str(),
232 unsigned long constBase;
233 double inputMultiplier;
234 GetOutputDataSize(constBase,inputMultiplier);
235 if(size<(constBase+block.fSize*inputMultiplier)){
236 HLTWarning("Memory Block given might be too small: %i < %i; Event %Lu", size, constBase+block.fSize*inputMultiplier, evtData.fEventID);
240 AliHLTTRDUtils::ReadClusters(fClusterArray, block.fPtr, block.fSize);
241 HLTDebug("TClonesArray of clusters: nbEntries = %i", fClusterArray->GetEntriesFast());
242 fTracker->LoadClusters(fClusterArray);
244 fTracker->Clusters2Tracks(fESD);
246 Int_t nTracks = fESD->GetNumberOfTracks();
247 HLTInfo("Number of tracks == %d ==", nTracks);
249 TClonesArray* trdTracks = 0x0;
250 //trdTracks = fTracker->GetListOfTracks();
253 HLTDebug("We have an output ESDEvent: 0x%x with %i tracks", fESD, nTracks);
254 AliHLTUInt32_t addedSize = AliHLTTRDUtils::AddESDToOutput(fESD, outputPtr+offset);
255 totalSize += addedSize;
258 AliHLTComponentBlockData bd;
260 //bd.fPtr = outputPtr;
262 bd.fSize = addedSize;
263 bd.fSpecification = block.fSpecification;
264 bd.fDataType = kAliHLTDataTypeTrack | kAliHLTDataOriginTRD;
265 outputBlocks.push_back( bd );
266 HLTDebug("BD fPtr 0x%x, fOffset %i, fSize %i, fSpec 0x%x", bd.fPtr, bd.fOffset, bd.fSize, bd.fSpecification);
270 //Int_t nbTracks=trdTracks->GetEntriesFast();
272 HLTDebug("We have an output array: pointer to trdTracks = 0x%x, nbEntries = %i", trdTracks, trdTracks->GetEntriesFast());
274 addedSize = AliHLTTRDUtils::AddTracksToOutput(trdTracks, outputPtr+offset);
275 totalSize += addedSize;
279 //bd.fPtr = outputPtr;
281 bd.fSize = addedSize;
282 bd.fSpecification = block.fSpecification;
283 bd.fDataType = AliHLTTRDDefinitions::fgkTRDSATracksDataType;
284 outputBlocks.push_back( bd );
285 HLTDebug("BD fPtr 0x%x, fOffset %i, fSize %i, fSpec 0x%x", bd.fPtr, bd.fOffset, bd.fSize, bd.fSpecification);
290 HLTDebug("totalSize: %i", totalSize);
292 // if ( totalSize > allocSize )
294 // HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
295 // totalSize, size );
299 //here we are deleting clusters (but not the TClonesArray itself)
300 fTracker->UnloadClusters();
301 AliTRDReconstructor::SetClusters(0x0);
302 fClusterArray->Delete();
307 HLTDebug("Event is done. size written to the output is %i", size);
311 int AliHLTTRDTrackerV1Component::Configure(const char* arguments){
313 if (!arguments) return iResult;
315 TString allArgs=arguments;
319 TObjArray* pTokens=allArgs.Tokenize(" ");
321 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
322 argument=((TObjString*)pTokens->At(i))->GetString();
323 if (argument.IsNull()) continue;
325 if (argument.CompareTo("output_percentage")==0) {
326 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
327 HLTInfo("Setting output percentage to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
328 fOutputPercentage=((TObjString*)pTokens->At(i))->GetString().Atoi();
331 else if (argument.CompareTo("-solenoidBz")==0) {
332 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
333 fieldStrength=((TObjString*)pTokens->At(i))->GetString().Atof();
334 HLTInfo("Setting Magnetic field to %.1f KGauss", fieldStrength);
337 else if (argument.CompareTo("-NTimeBins")==0) {
338 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
339 HLTInfo("Setting number of time bins to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
340 fNtimeBins=((TObjString*)pTokens->At(i))->GetString().Atoi();
343 else if (argument.CompareTo("-geometry")==0) {
344 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
345 HLTInfo("Setting geometry to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
346 fgeometryFileName=((TObjString*)pTokens->At(i))->GetString();
349 if (argument.CompareTo("-lowflux")==0) {
351 HLTInfo("Low flux reconstruction selected");
354 if (argument.CompareTo("-highflux")==0) {
356 HLTInfo("High flux reconstruction selected");
359 if (argument.CompareTo("-cosmics")==0) {
361 HLTInfo("Cosmics reconstruction selected");
364 if (argument.CompareTo("-magnetic_field_ON")==0) {
366 HLTInfo("Reconstructon with magnetic field");
369 if (argument.CompareTo("-magnetic_field_OFF")==0) {
371 HLTInfo("Reconstructon without magnetic field");
374 if (argument.CompareTo("-slowTracking")==0) {
375 fSlowTracking = kTRUE;
376 HLTInfo("Using slow tracking");
379 else if (argument.CompareTo("-PIDmethod")==0) {
380 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
381 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
382 if (toCompareTo.CompareTo("LH")==0){
383 HLTInfo("Setting PID method to: %s", toCompareTo.Data());
386 else if (toCompareTo.CompareTo("NN")==0){
387 HLTInfo("Setting PID method to: %s", toCompareTo.Data());
390 else if (toCompareTo.CompareTo("TM")==0){
391 HLTInfo("Setting PID method to: %s", toCompareTo.Data());
395 HLTError("unknown argument for PID method: %s", toCompareTo.Data());
403 HLTError("unknown argument: %s", argument.Data());
411 HLTError("missing parameter for argument %s", argument.Data());
420 int AliHLTTRDTrackerV1Component::SetParams()
423 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
424 HLTError("DefaultStorage is not set in CDBManager");
427 if(AliCDBManager::Instance()->GetRun()<0){
428 HLTError("Run Number is not set in CDBManager");
431 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
433 if(!AliGeomManager::GetGeometry()){
434 if(fgeometryFileName.CompareTo("")==0 || !TFile::Open(fgeometryFileName.Data())){
435 HLTInfo("Loading standard geometry file");
436 AliGeomManager::LoadGeometry();
438 HLTWarning("Loading NON-standard geometry file");
439 AliGeomManager::LoadGeometry(fgeometryFileName.Data());
441 if(!AliGeomManager::GetGeometry()){
442 HLTError("Could not load geometry");
447 HLTInfo("Geometry Already Loaded!");
452 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.");
455 if (fNtimeBins < 24 || fNtimeBins > 30)
457 HLTWarning("The number of time bins seems to be strange = %d. But okay. Let's try it...", fNtimeBins);
459 if (fNtimeBins != 24)
461 HLTWarning("All PID methods eagerly await 24 time bins, so PID will NOT work!", fNtimeBins);
463 HLTDebug("Setting number of time bins of the tracker to: %i", fNtimeBins);
464 AliTRDtrackerV1::SetNTimeBins(fNtimeBins);
466 TString recoOptions="sa,sl_tr_0,!cw";
469 recoOptions += ",hlt";
472 case 0: recoOptions += ",!nn"; break;
473 case 1: recoOptions += ",nn"; break;
474 case 2: recoOptions += ",!nn"; break;
477 if (fRecoParamType == 0)
479 HLTDebug("Low flux params init.");
480 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
483 if (fRecoParamType == 1)
485 HLTDebug("High flux params init.");
486 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
489 if (fRecoParamType == 2)
491 HLTDebug("Cosmic Test params init.");
492 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
497 HLTError("No reco params initialized. Sniffing big trouble!");
501 fReconstructor->SetRecoParam(fRecoParam);
503 HLTDebug("Reconstructor options are: %s",recoOptions.Data());
504 fReconstructor->SetOption(recoOptions.Data());
506 if (fMagneticField >= 0)
508 HLTWarning("Setting magnetic field by hand!");
510 if (!TGeoGlobalMagField::Instance()->IsLocked()) {
512 if (fMagneticField == 0){
513 // magnetic field OFF
514 field = new AliMagF("Maps","Maps",2,0.,0., 10.,AliMagF::k5kGUniform);
515 TGeoGlobalMagField::Instance()->SetField(field);
516 HLTDebug("Magnetic field is OFF.");
519 field = new AliMagF("Maps","Maps",2,1.,1., 10.,AliMagF::k5kG);
520 TGeoGlobalMagField::Instance()->SetField(field);
521 HLTDebug("Magnetic field is ON.");
522 if( fMagneticField < 0 )
523 iResult=ReconfigureField();
526 HLTError("Magnetic field is already set and locked, cannot redefine it." );
531 int AliHLTTRDTrackerV1Component::ReconfigureField()
534 if(fieldStrength<-100){
535 const char* pathBField=kAliHLTCDBSolenoidBz;
538 HLTInfo("reconfigure B-Field from entry %s", pathBField);
539 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(pathBField/*,GetRunNo()*/);
541 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
543 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
544 TObjArray* pTokens=pString->GetString().Tokenize(" ");
548 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
549 argument=((TObjString*)pTokens->At(i))->GetString();
550 if (argument.IsNull()) continue;
552 if (argument.CompareTo("-solenoidBz")==0) {
553 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
554 HLTDebug("Magnetic field in CDB: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
555 fieldStrength=((TObjString*)pTokens->At(i))->GetString().Atof();
558 HLTError("unknown argument %s", argument.Data());
566 HLTError("configuration object \"%s\" has wrong type, required TObjString", pathBField);
569 HLTError("cannot fetch object \"%s\" from CDB", pathBField);
574 if(fieldStrength>=-100){
575 AliMagF* field = (AliMagF *) TGeoGlobalMagField::Instance()->GetField();
576 HLTDebug("Magnetic field before change: %f KGauss", field->SolenoidField());
577 field->SetFactorSol(1);
578 Double_t initialFieldStrengh=field->SolenoidField();
579 field->SetFactorSol(fieldStrength/initialFieldStrengh);
580 HLTDebug("Magnetic field was changed to %f KGauss.", field->SolenoidField());
585 int AliHLTTRDTrackerV1Component::Reconfigure(const char* cdbEntry, const char* chainId)
587 // see header file for class documentation
590 const char* path="HLT/ConfigTRD/TrackerV1Component";
591 const char* defaultNotify="";
594 defaultNotify=" (default)";
597 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
598 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
600 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
602 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
603 iResult=Configure(pString->GetString().Data());
605 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
608 HLTError("cannot fetch object \"%s\" from CDB", path);
612 const char* pathBField=kAliHLTCDBSolenoidBz;
615 HLTInfo("reconfigure B-Field from entry %s, chain id %s", pathBField,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
616 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(pathBField/*,GetRunNo()*/);
618 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
620 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
621 iResult=Configure(pString->GetString().Data());
623 HLTError("configuration object \"%s\" has wrong type, required TObjString", pathBField);
626 HLTError("cannot fetch object \"%s\" from CDB", pathBField);
634 int AliHLTTRDTrackerV1Component::ReadPreprocessorValues(const char* modules)
636 // see header file for class documentation
639 TString str(modules);
640 if(str.Contains("HLT") || str.Contains("TRD") || str.Contains("GRP")){
642 const char* pathBField=kAliHLTCDBSolenoidBz;
645 HLTInfo("reconfigure B-Field from entry %s, modules %s", pathBField,(modules!=NULL && modules[0]!=0)?modules:"<none>");
646 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(pathBField/*,GetRunNo()*/);
648 // AliCDBPath path(pathBField);
650 // AliCDBStorage *stor = AliCDBManager::Instance()->GetDefaultStorage();
651 // Int_t version = stor->GetLatestVersion(pathBField, GetRunNo());
652 // Int_t subVersion = stor->GetLatestSubVersion(pathBField, GetRunNo(), version);
653 // AliCDBEntry *pEntry = stor->Get(path,GetRunNo(), version, subVersion);
655 // HLTInfo("RunNo %d, Version %d, subversion %d", GetRunNo(), version, subVersion);
658 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
660 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
661 iResult=Configure(pString->GetString().Data());
663 HLTError("configuration object \"%s\" has wrong type, required TObjString", pathBField);
666 HLTError("cannot fetch object \"%s\" from CDB", pathBField);