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 "AliESDEvent.h"
41 #include "AliESDfriend.h"
43 #include "AliTRDcalibDB.h"
44 #include "AliTRDReconstructor.h"
45 #include "AliTRDtrackerV1.h"
46 #include "AliTRDrecoParam.h"
52 #ifdef HAVE_VALGRIND_CALLGRIND_H
53 #include <valgrind/callgrind.h>
55 #define CALLGRIND_START_INSTRUMENTATION() do { } while (0)
56 #define CALLGRIND_STOP_INSTRUMENTATION() do { } while (0)
59 ClassImp(AliHLTTRDTrackerV1Component);
61 AliHLTTRDTrackerV1Component::AliHLTTRDTrackerV1Component():
63 fOutputPercentage(100), // By default we copy to the output exactly what we got as input
64 fStrorageDBpath("local://$ALICE_ROOT/OCDB"),
66 fGeometryFileName(""),
71 // Default constructor
73 fGeometryFileName = getenv("ALICE_ROOT");
74 fGeometryFileName += "/HLT/TRD/geometry.root";
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 AliHLTComponent_DataType AliHLTTRDTrackerV1Component::GetOutputDataType()
97 // Get the output data type
98 return AliHLTTRDDefinitions::fgkClusterDataType;
101 void AliHLTTRDTrackerV1Component::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
103 // Get the output data size
105 inputMultiplier = ((double)fOutputPercentage)/100.0;
108 // Spawn function, return new instance of this class
109 AliHLTComponent* AliHLTTRDTrackerV1Component::Spawn()
111 return new AliHLTTRDTrackerV1Component;
115 int AliHLTTRDTrackerV1Component::DoInit( int argc, const char** argv )
117 // perform initialization. We check whether our relative output size is specified in the arguments.
118 fOutputPercentage = 100;
123 Int_t iRecoParamType = -1; // default will be the low flux
124 Int_t iNtimeBins = -1; // number of time bins for the tracker to use
125 Int_t iMagneticField = -1; // magnetic field: 0==OFF and 1==ON
126 Bool_t bHLTMode = kTRUE, bWriteClusters = kFALSE;
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 %lu %%", fOutputPercentage );
150 else if ( !strcmp( argv[i], "-NTimeBins" ) )
154 HLTError("Missing -NTimeBins parameter");
157 HLTDebug("Arguments", "argv[%d+1] == %s", i, argv[i+1] );
158 iNtimeBins = strtoul( argv[i+1], &cpErr, 0 );
161 HLTError("Wrong Argument. Cannot convert -NTimeBins parameter '%s'", argv[i+1] );
168 else if ( strcmp( argv[i], "-cdb" ) == 0)
172 HLTError( "Missing -cdb argument");
175 fStrorageDBpath = argv[i+1];
176 HLTInfo("DB storage is %s", fStrorageDBpath.c_str() );
181 else if ( strcmp( argv[i], "-geometry" ) == 0)
185 HLTError("Missing -geometry argument");
188 fGeometryFileName = argv[i+1];
189 HLTInfo("GeomFile storage is %s",
190 fGeometryFileName.c_str() );
195 // the flux parametrizations
196 else if ( strcmp( argv[i], "-lowflux" ) == 0)
199 HLTDebug("Low flux reco selected.");
204 else if ( strcmp( argv[i], "-highflux" ) == 0)
207 HLTDebug("Low flux reco selected.");
211 else if ( strcmp( argv[i], "-cosmics" ) == 0)
214 HLTDebug("Cosmic test reco selected.");
218 else if ( strcmp( argv[i], "-magnetic_field_ON" ) == 0)
223 else if ( strcmp( argv[i], "-magnetic_field_OFF" ) == 0)
228 else if ( strcmp( argv[i], "-offlineMode" ) == 0)
231 HLTDebug("Using standard offline tracking.");
235 HLTError("Unknown option '%s'", argv[i] );
241 // THE "REAL" INIT COMES HERE
242 // offline condition data base
243 fCDB = AliCDBManager::Instance();
246 HLTError("Could not get CDB instance", "fCDB 0x%x", fCDB);
251 fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
252 fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
253 HLTDebug("CDB instance", "fCDB 0x%x", fCDB);
256 // check if the N of time bins make sense
259 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.");
263 if (iNtimeBins < 24 || iNtimeBins > 30)
265 HLTWarning("The number of time bins seems to be strange = %d. But okay. Let's try it...", iNtimeBins);
268 HLTDebug("The number of time bins = %d.", iNtimeBins);
269 AliTRDtrackerV1::SetNTimeBins(iNtimeBins);
271 // !!!! THIS IS IMPORTANT
272 // init alifield map - temporarly via parameter - should come from a DB or DCS ?
274 if (iMagneticField < 0)
277 HLTWarning("No magnetic field switch stated. Use -magnetic_field_ON or -magnetic_field_OFF flag. Defaulting to OFF = NO MAGNETIC FIELD");
280 if (!TGeoGlobalMagField::Instance()->IsLocked()) {
281 if (iMagneticField == 0)
283 // magnetic field OFF
284 AliMagF* field = new AliMagF("Maps","Maps",2,0.,0., 10.,AliMagF::k5kGUniform);
285 TGeoGlobalMagField::Instance()->SetField(field);
286 HLTDebug("Magnetic field is OFF.");
289 if (iMagneticField == 1)
292 AliMagF* field = new AliMagF("Maps","Maps",2,1.,1., 10.,AliMagF::k5kG);
293 TGeoGlobalMagField::Instance()->SetField(field);
294 HLTDebug("Magnetic field is ON.");
298 HLTError("Magnetic field is already set and locked, cannot redefine it." );
301 // reconstruction parameters
302 if (iRecoParamType < 0 || iRecoParamType > 2)
304 HLTWarning("No reco param selected. Use -lowflux -highflux -cosmics flags. Defaulting to low flux.");
308 if (iRecoParamType == 0)
310 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
311 HLTDebug("Low flux params init.");
314 if (iRecoParamType == 1)
316 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
317 HLTDebug("High flux params init.");
320 if (iRecoParamType == 2)
322 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
323 HLTDebug("Cosmic Test params init.");
328 HLTError("No reco params initialized. Sniffing big trouble!");
332 fReconstructor = new AliTRDReconstructor();
333 // fRecoParam->SetChi2Y(.1);
334 // fRecoParam->SetChi2Z(5.);
335 fReconstructor->SetRecoParam(fRecoParam);
336 // write clusters [cw] = true
337 // track seeding (stand alone tracking) [sa] = true
338 // PID method in reconstruction (NN) [nn] = true
339 // write online tracklets [tw] = false
340 // drift gas [ar] = false
341 // sl_tr_0 = StreamLevel_task_Level
342 // fReconstructor->SetOption("sa,!cw,hlt,sl_tr_0");
343 TString recoOptions="sa,sl_tr_0";
347 recoOptions += ",cw";
351 recoOptions += ",!cw";
354 recoOptions += ",hlt";
356 fReconstructor->SetOption(recoOptions.Data());
357 HLTDebug("Reconstructor options are: %s",recoOptions.Data());
359 if((AliGeomManager::GetGeometry()) == NULL){
361 if ( TFile::Open(fGeometryFileName.c_str())) {
362 AliGeomManager::LoadGeometry(fGeometryFileName.c_str());
365 HLTError("Cannot load geometry from file %s",fGeometryFileName.c_str());
370 HLTInfo("Geometry Already Loaded");
372 // create the tracker
373 fTracker = new AliTRDtrackerV1();
374 fTracker->SetReconstructor(fReconstructor);
375 HLTDebug("TRDTracker at 0x%x", fTracker);
379 HLTError("Unable to create the tracker!");
386 int AliHLTTRDTrackerV1Component::DoDeinit()
388 // Deinitialization of the component
390 fTracker->SetClustersOwner(kFALSE);
394 // We need to set clusters in Reconstructor to null to prevent from
395 // double deleting, since we delete TClonesArray by ourself in DoEvent.
396 fReconstructor->SetClusters(0x0);
397 delete fReconstructor;
398 fReconstructor = 0x0;
400 AliTRDcalibDB::Terminate();
405 int AliHLTTRDTrackerV1Component::DoEvent( const AliHLTComponentEventData& evtData,
406 const AliHLTComponentBlockData* blocks,
407 AliHLTComponent_TriggerData& /*trigData*/,
408 AliHLTUInt8_t* outputPtr,
409 AliHLTUInt32_t& size,
410 vector<AliHLTComponent_BlockData>& outputBlocks )
414 HLTDebug("NofBlocks %lu", evtData.fBlockCnt );
416 AliHLTUInt32_t totalSize = 0, offset = 0;
417 AliHLTUInt32_t dBlockSpecification = 0;
419 vector<AliHLTComponent_DataType> expectedDataTypes;
420 GetInputDataTypes(expectedDataTypes);
421 if (evtData.fEventID == 1)
422 CALLGRIND_START_INSTRUMENTATION();
423 for ( unsigned long iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
425 const AliHLTComponentBlockData &block = blocks[iBlock];
427 AliHLTComponentDataType inputDataType = block.fDataType;
428 Bool_t correctDataType = kFALSE;
430 for(UInt_t i = 0; i < expectedDataTypes.size(); i++)
431 if( expectedDataTypes.at(i) == inputDataType)
432 correctDataType = kTRUE;
433 if (!correctDataType)
435 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - Skipping",
436 iBlock, evtData.fBlockCnt-1,
437 evtData.fEventID, evtData.fEventID,
438 DataType2Text(inputDataType).c_str());
442 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s",
443 iBlock, evtData.fBlockCnt-1,
444 evtData.fEventID, evtData.fEventID,
445 DataType2Text(inputDataType).c_str());
448 TClonesArray* clusterArray = new TClonesArray("AliTRDcluster"); // would be nice to allocate memory for all clusters here.
449 AliHLTTRDUtils::ReadClusters(clusterArray, block.fPtr, block.fSize);
450 HLTDebug("TClonesArray of clusters: nbEntries = %i", clusterArray->GetEntriesFast());
451 fTracker->LoadClusters(clusterArray);
455 // maybe it is not so smart to create it each event? clear is enough ?
456 AliESDEvent *esd = new AliESDEvent();
457 esd->CreateStdContent();
458 fTracker->Clusters2Tracks(esd);
460 Int_t nTracks = esd->GetNumberOfTracks();
461 HLTInfo("Number of tracks == %d ==", nTracks);
463 TClonesArray* trdTracks = fTracker->GetListOfTracks();
466 totalSize += TransportTracks(trdTracks, outputPtr, outputBlocks, offset, dBlockSpecification);
468 HLTDebug("Bad array trdTracks = 0x%x", trdTracks);
469 HLTDebug("totalSize: %i", totalSize);
471 // if ( totalSize > allocSize )
473 // HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
474 // totalSize, size );
478 //here we are deleting clusters (but not the TClonesArray itself)
479 fTracker->UnloadClusters();
481 AliTRDReconstructor::SetClusters(0x0);
486 HLTDebug("Event is done. size written to the output is %i", size);
492 * Transport tracks to the next component
493 * Return Numbers of bytes written to the output
495 //============================================================================
496 AliHLTUInt32_t AliHLTTRDTrackerV1Component::TransportTracks(TClonesArray *inTracksArray, AliHLTUInt8_t* output,
497 vector<AliHLTComponent_BlockData>& outputBlocks, AliHLTUInt32_t inOffset, AliHLTUInt32_t inSpec)
499 Int_t nbTracks=inTracksArray->GetEntriesFast();
502 HLTDebug("We have an output array: pointer to inTracksArray = 0x%x, nbEntries = %i", inTracksArray, nbTracks);
504 // Using low-level interface
505 // with interface classes
506 AliHLTUInt32_t addedSize = AliHLTTRDUtils::AddTracksToOutput(inTracksArray, output);
509 AliHLTComponentBlockData bd;
513 bd.fOffset = inOffset;
514 bd.fSize = addedSize;
515 bd.fSpecification = inSpec;
516 bd.fDataType = AliHLTTRDDefinitions::fgkTRDSATracksDataType;
517 outputBlocks.push_back( bd );
518 HLTDebug("BD fPtr 0x%x, fOffset %i, fSize %i, fSpec 0x%x", bd.fPtr, bd.fOffset, bd.fSize, bd.fSpecification);