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 "AliCDBEntry.h"
41 #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
74 fgeometryFileName(""),
76 fSlowTracking(kFALSE),
79 // Default constructor
83 AliHLTTRDTrackerV1Component::~AliHLTTRDTrackerV1Component()
88 const char* AliHLTTRDTrackerV1Component::GetComponentID()
90 // Return the component ID const char *
91 return "TRDTrackerV1"; // The ID of this component
94 void AliHLTTRDTrackerV1Component::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
96 // Get the list of input data
97 list.clear(); // We do not have any requirements for our input data type(s).
98 list.push_back( AliHLTTRDDefinitions::fgkClusterDataType );
101 AliHLTComponent_DataType AliHLTTRDTrackerV1Component::GetOutputDataType()
103 // Get the output data type
104 //return AliHLTTRDDefinitions::fgkClusterDataType;
105 return kAliHLTDataTypeTrack | kAliHLTDataOriginTRD;
108 void AliHLTTRDTrackerV1Component::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
110 // Get the output data size
112 inputMultiplier = ((double)fOutputPercentage)/100.0;
115 // Spawn function, return new instance of this class
116 AliHLTComponent* AliHLTTRDTrackerV1Component::Spawn()
118 return new AliHLTTRDTrackerV1Component;
122 int AliHLTTRDTrackerV1Component::DoInit( int argc, const char** argv )
124 // perform initialization. We check whether our relative output size is specified in the arguments.
127 fReconstructor = new AliTRDReconstructor();
128 HLTDebug("TRDReconstructor at 0x%x", fReconstructor);
130 fESD = new AliESDEvent;
131 fESD->CreateStdContent();
133 TString configuration="";
135 for (int i=0; i<argc && iResult>=0; i++) {
137 if (!configuration.IsNull()) configuration+=" ";
138 configuration+=argument;
141 if (!configuration.IsNull()) {
142 iResult=Configure(configuration.Data());
144 iResult=Reconfigure(NULL, NULL);
147 fTracker = new AliTRDtrackerV1();
148 HLTDebug("TRDTracker at 0x%x", fTracker);
149 fTracker->SetReconstructor(fReconstructor);
154 int AliHLTTRDTrackerV1Component::DoDeinit()
156 // Deinitialization of the component
158 fTracker->SetClustersOwner(kFALSE);
162 // We need to set clusters in Reconstructor to null to prevent from
163 // double deleting, since we delete TClonesArray by ourself in DoEvent.
164 fReconstructor->SetClusters(0x0);
165 delete fReconstructor;
166 fReconstructor = 0x0;
170 AliTRDcalibDB::Terminate();
175 int AliHLTTRDTrackerV1Component::DoEvent( const AliHLTComponentEventData& evtData,
176 const AliHLTComponentBlockData* blocks,
177 AliHLTComponent_TriggerData& /*trigData*/,
178 AliHLTUInt8_t* outputPtr,
179 AliHLTUInt32_t& size,
180 vector<AliHLTComponent_BlockData>& outputBlocks )
184 if (evtData.fEventID == 1)
185 CALLGRIND_START_INSTRUMENTATION;
187 HLTDebug("NofBlocks %i", evtData.fBlockCnt );
190 //fESD->SetMagneticField(fSolenoidBz);
192 AliHLTUInt32_t totalSize = 0, offset = 0;
193 AliHLTUInt32_t dBlockSpecification = 0;
195 vector<AliHLTComponent_DataType> expectedDataTypes;
196 GetInputDataTypes(expectedDataTypes);
197 for ( unsigned long iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
199 const AliHLTComponentBlockData &block = blocks[iBlock];
200 AliHLTComponentDataType inputDataType = block.fDataType;
201 Bool_t correctDataType = kFALSE;
203 for(UInt_t i = 0; i < expectedDataTypes.size(); i++){
204 if( expectedDataTypes.at(i) == inputDataType)
205 correctDataType = kTRUE;
207 if (!correctDataType)
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 TClonesArray* clusterArray = new TClonesArray("AliTRDcluster"); // would be nice to allocate memory for all clusters here.
225 AliHLTTRDUtils::ReadClusters(clusterArray, block.fPtr, block.fSize);
226 HLTDebug("TClonesArray of clusters: nbEntries = %i", clusterArray->GetEntriesFast());
227 fTracker->LoadClusters(clusterArray);
229 fTracker->Clusters2Tracks(fESD);
231 Int_t nTracks = fESD->GetNumberOfTracks();
232 HLTInfo("Number of tracks == %d ==", nTracks);
234 TClonesArray* trdTracks = 0x0;
235 //trdTracks = fTracker->GetListOfTracks();
238 HLTDebug("We have an output ESDEvent: 0x%x with %i tracks", fESD, nTracks);
239 AliHLTUInt32_t addedSize = AliHLTTRDUtils::AddESDToOutput(fESD, (AliHLTUInt8_t*)(outputPtr+offset));
240 totalSize += addedSize;
243 AliHLTComponentBlockData bd;
245 //bd.fPtr = outputPtr;
247 bd.fSize = addedSize;
248 bd.fSpecification = dBlockSpecification;
249 bd.fDataType = kAliHLTDataTypeTrack | kAliHLTDataOriginTRD;
250 outputBlocks.push_back( bd );
251 HLTDebug("BD fPtr 0x%x, fOffset %i, fSize %i, fSpec 0x%x", bd.fPtr, bd.fOffset, bd.fSize, bd.fSpecification);
255 //Int_t nbTracks=trdTracks->GetEntriesFast();
257 HLTDebug("We have an output array: pointer to trdTracks = 0x%x, nbEntries = %i", trdTracks, trdTracks->GetEntriesFast());
259 addedSize = AliHLTTRDUtils::AddTracksToOutput(trdTracks, (AliHLTUInt8_t*)(outputPtr+offset));
260 totalSize += addedSize;
264 //bd.fPtr = outputPtr;
266 bd.fSize = addedSize;
267 bd.fSpecification = dBlockSpecification;
268 bd.fDataType = AliHLTTRDDefinitions::fgkTRDSATracksDataType;
269 outputBlocks.push_back( bd );
270 HLTDebug("BD fPtr 0x%x, fOffset %i, fSize %i, fSpec 0x%x", bd.fPtr, bd.fOffset, bd.fSize, bd.fSpecification);
277 // totalSize += TransportTracks(trdTracks, outputPtr, outputBlocks, offset, dBlockSpecification);
279 // HLTDebug("Bad array trdTracks = 0x%x", trdTracks);
282 HLTDebug("totalSize: %i", totalSize);
284 // if ( totalSize > allocSize )
286 // HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
287 // totalSize, size );
291 //here we are deleting clusters (but not the TClonesArray itself)
292 fTracker->UnloadClusters();
293 AliTRDReconstructor::SetClusters(0x0);
294 clusterArray->Delete();
300 HLTDebug("Event is done. size written to the output is %i", size);
304 int AliHLTTRDTrackerV1Component::Configure(const char* arguments){
306 if (!arguments) return iResult;
308 TString allArgs=arguments;
312 TObjArray* pTokens=allArgs.Tokenize(" ");
314 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
315 argument=((TObjString*)pTokens->At(i))->GetString();
316 if (argument.IsNull()) continue;
318 if (argument.CompareTo("-OFFLINE")==0) {
319 fOfflineMode = kTRUE;
320 HLTFatal("You have selected OFFLINE mode!");
321 HLTFatal("This program shall NOT run on the HLT cluster like this!");
324 else if (argument.CompareTo("output_percentage")==0) {
325 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
326 HLTInfo("Setting output percentage to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
327 fOutputPercentage=((TObjString*)pTokens->At(i))->GetString().Atoi();
330 else if (argument.CompareTo("-solenoidBz")==0) {
331 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
332 fieldStrength=((TObjString*)pTokens->At(i))->GetString().Atof();
333 HLTInfo("Setting Magnetic field to %.1f KGauss", fieldStrength);
336 else if (argument.CompareTo("-NTimeBins")==0) {
337 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
338 HLTInfo("Setting number of time bins to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
339 fNtimeBins=((TObjString*)pTokens->At(i))->GetString().Atoi();
342 else if (argument.CompareTo("-geometry")==0) {
343 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
344 HLTInfo("Setting geometry to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
345 fgeometryFileName=((TObjString*)pTokens->At(i))->GetString();
348 if (argument.CompareTo("-lowflux")==0) {
350 HLTInfo("Low flux reconstruction selected");
353 if (argument.CompareTo("-highflux")==0) {
355 HLTInfo("High flux reconstruction selected");
358 if (argument.CompareTo("-cosmics")==0) {
360 HLTInfo("Cosmics reconstruction selected");
363 if (argument.CompareTo("-magnetic_field_ON")==0) {
365 HLTInfo("Reconstructon with magnetic field");
368 if (argument.CompareTo("-magnetic_field_OFF")==0) {
370 HLTInfo("Reconstructon without magnetic field");
373 if (argument.CompareTo("-slowTracking")==0) {
374 fSlowTracking = kTRUE;
375 HLTInfo("Using slow tracking");
378 else if (argument.CompareTo("-PIDmethod")==0) {
379 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
380 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
381 if (toCompareTo.CompareTo("LH")==0){
382 HLTInfo("Setting PID method to: %s", toCompareTo.Data());
385 else if (toCompareTo.CompareTo("NN")==0){
386 HLTInfo("Setting PID method to: %s", toCompareTo.Data());
389 else if (toCompareTo.CompareTo("TM")==0){
390 HLTInfo("Setting PID method to: %s", toCompareTo.Data());
394 HLTError("unknown argument for PID method: %s", toCompareTo.Data());
402 HLTError("unknown argument: %s", argument.Data());
410 HLTError("missing parameter for argument %s", argument.Data());
414 if(fOfflineMode)SetOfflineParams();
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("Cannot 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 void AliHLTTRDTrackerV1Component::SetOfflineParams(){
532 HLTFatal("You have entered the OFFLINE configuration!");
533 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
534 HLTFatal("You are resetting the Default Storage of the CDBManager!");
535 HLTFatal("Let's hope that this program is NOT running on the HLT cluster!");
536 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
538 HLTError("DefaultStorage was already set!");
540 if(AliCDBManager::Instance()->GetRun()<0){
541 HLTFatal("You are resetting the CDB run number to 0!");
542 HLTFatal("Let's hope that this program is NOT running on the HLT cluster!");
543 AliCDBManager::Instance()->SetRun(0);
545 HLTError("Run Number was already set!");
549 int AliHLTTRDTrackerV1Component::ReconfigureField()
552 if(fieldStrength<-100){
553 const char* pathBField=kAliHLTCDBSolenoidBz;
556 HLTInfo("reconfigure B-Field from entry %s", pathBField);
557 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(pathBField/*,GetRunNo()*/);
559 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
561 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
562 TObjArray* pTokens=pString->GetString().Tokenize(" ");
566 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
567 argument=((TObjString*)pTokens->At(i))->GetString();
568 if (argument.IsNull()) continue;
570 if (argument.CompareTo("-solenoidBz")==0) {
571 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
572 HLTDebug("Magnetic field in CDB: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
573 fieldStrength=((TObjString*)pTokens->At(i))->GetString().Atof();
576 HLTError("unknown argument %s", argument.Data());
584 HLTError("configuration object \"%s\" has wrong type, required TObjString", pathBField);
587 HLTError("cannot fetch object \"%s\" from CDB", pathBField);
591 if(fieldStrength>=-100){
592 AliMagF* field = (AliMagF *) TGeoGlobalMagField::Instance()->GetField();
593 field->SetFactorSol(1);
594 Double_t initialFieldStrengh=field->SolenoidField();
595 HLTDebug("Magnetic field was: %f KGauss", initialFieldStrengh);
596 field->SetFactorSol(fieldStrength/initialFieldStrengh);
597 HLTDebug("Magnetic field reset to %f KGauss.", field->SolenoidField());
602 int AliHLTTRDTrackerV1Component::Reconfigure(const char* cdbEntry, const char* chainId)
604 // see header file for class documentation
607 const char* path="HLT/ConfigTRD/TrackerV1Component";
608 const char* defaultNotify="";
611 defaultNotify=" (default)";
614 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
615 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
617 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
619 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
620 iResult=Configure(pString->GetString().Data());
622 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
625 HLTError("cannot fetch object \"%s\" from CDB", path);
629 const char* pathBField=kAliHLTCDBSolenoidBz;
632 HLTInfo("reconfigure B-Field from entry %s, chain id %s", pathBField,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
633 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(pathBField/*,GetRunNo()*/);
635 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
637 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
638 iResult=Configure(pString->GetString().Data());
640 HLTError("configuration object \"%s\" has wrong type, required TObjString", pathBField);
643 HLTError("cannot fetch object \"%s\" from CDB", pathBField);
651 int AliHLTTRDTrackerV1Component::ReadPreprocessorValues(const char* modules)
653 // see header file for class documentation
656 TString str(modules);
657 if(str.Contains("HLT") || str.Contains("TRD") || str.Contains("GRP")){
659 const char* pathBField=kAliHLTCDBSolenoidBz;
662 HLTInfo("reconfigure B-Field from entry %s, modules %s", pathBField,(modules!=NULL && modules[0]!=0)?modules:"<none>");
663 //AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(pathBField/*,GetRunNo()*/);
665 AliCDBPath path(pathBField);
667 AliCDBStorage *stor = AliCDBManager::Instance()->GetDefaultStorage();
668 Int_t version = stor->GetLatestVersion(pathBField, GetRunNo());
669 Int_t subVersion = stor->GetLatestSubVersion(pathBField, GetRunNo(), version);
670 AliCDBEntry *pEntry = stor->Get(path,GetRunNo(), version, subVersion);
672 HLTImportant("RunNo %d, Version %d, subversion %d", GetRunNo(), version, subVersion);
675 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
677 HLTImportant("received configuration object string: \'%s\'", pString->GetString().Data());
678 iResult=Configure(pString->GetString().Data());
680 HLTError("configuration object \"%s\" has wrong type, required TObjString", pathBField);
683 HLTError("cannot fetch object \"%s\" from CDB", pathBField);