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"
34 #include "AliGeomManager.h"
35 #include "AliCDBManager.h"
36 #include "AliESDEvent.h"
37 #include "AliMagFMaps.h"
38 #include "AliESDfriend.h"
40 #include "AliTRDcalibDB.h"
41 #include "AliTRDReconstructor.h"
42 #include "AliTRDtrackerV1.h"
43 #include "AliTRDrecoParam.h"
49 // this is a global object used for automatic component registration, do not use this
50 AliHLTTRDTrackerV1Component gAliHLTTRDTrackerV1Component;
52 ClassImp(AliHLTTRDTrackerV1Component);
54 AliHLTTRDTrackerV1Component::AliHLTTRDTrackerV1Component()
56 , fOutputPercentage(100) // By default we copy to the output exactly what we got as input
57 , fStrorageDBpath("local://$ALICE_ROOT")
60 , fGeometryFileName("")
65 // Default constructor
67 fGeometryFileName = getenv("ALICE_ROOT");
68 fGeometryFileName += "/HLT/TRD/geometry.root";
71 AliHLTTRDTrackerV1Component::~AliHLTTRDTrackerV1Component()
76 const char* AliHLTTRDTrackerV1Component::GetComponentID()
78 // Return the component ID const char *
79 return "TRDTrackerV1"; // The ID of this component
82 void AliHLTTRDTrackerV1Component::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
84 // Get the list of input data
85 list.clear(); // We do not have any requirements for our input data type(s).
86 list.push_back( AliHLTTRDDefinitions::fgkClusterDataType );
89 AliHLTComponent_DataType AliHLTTRDTrackerV1Component::GetOutputDataType()
91 // Get the output data type
92 return AliHLTTRDDefinitions::fgkClusterDataType;
95 void AliHLTTRDTrackerV1Component::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
97 // Get the output data size
99 inputMultiplier = ((double)fOutputPercentage)/100.0;
102 // Spawn function, return new instance of this class
103 AliHLTComponent* AliHLTTRDTrackerV1Component::Spawn()
105 return new AliHLTTRDTrackerV1Component;
108 int AliHLTTRDTrackerV1Component::DoInit( int argc, const char** argv )
110 // perform initialization. We check whether our relative output size is specified in the arguments.
111 fOutputPercentage = 100;
116 Int_t iRecoParamType = -1; // default will be the low flux
117 Int_t iNtimeBins = -1; // number of time bins for the tracker to use
118 Int_t iMagneticField = -1; // magnetic field: 0==OFF and 1==ON
119 Bool_t bHLTMode = kTRUE, bWriteClusters = kFALSE;
123 HLTDebug("argv[%d] == %s", i, argv[i] );
124 if ( !strcmp( argv[i], "output_percentage" ) )
128 HLTError("Missing output_percentage parameter");
131 HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
132 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
135 HLTError("Cannot convert output_percentage parameter '%s'", argv[i+1] );
138 HLTInfo("Output percentage set to %lu %%", fOutputPercentage );
143 else if ( !strcmp( argv[i], "-NTimeBins" ) )
147 HLTError("Missing -NTimeBins parameter");
150 HLTDebug("Arguments", "argv[%d+1] == %s", i, argv[i+1] );
151 iNtimeBins = strtoul( argv[i+1], &cpErr, 0 );
154 HLTError("Wrong Argument. Cannot convert -NTimeBins parameter '%s'", argv[i+1] );
161 else if ( strcmp( argv[i], "-cdb" ) == 0)
165 HLTError( "Missing -cdb argument");
168 fStrorageDBpath = argv[i+1];
169 HLTInfo("DB storage is %s", fStrorageDBpath.c_str() );
174 else if ( strcmp( argv[i], "-geometry" ) == 0)
178 HLTError("Missing -geometry argument");
181 fGeometryFileName = argv[i+1];
182 HLTInfo("GeomFile storage is %s",
183 fGeometryFileName.c_str() );
188 // the flux parametrizations
189 else if ( strcmp( argv[i], "-lowflux" ) == 0)
192 HLTDebug("Low flux reco selected.");
197 else if ( strcmp( argv[i], "-highflux" ) == 0)
200 HLTDebug("Low flux reco selected.");
204 else if ( strcmp( argv[i], "-cosmics" ) == 0)
207 HLTDebug("Cosmic test reco selected.");
211 else if ( strcmp( argv[i], "-magnetic_field_ON" ) == 0)
216 else if ( strcmp( argv[i], "-magnetic_field_OFF" ) == 0)
221 else if ( strcmp( argv[i], "-writeClusters" ) == 0)
223 bWriteClusters = kTRUE;
224 HLTDebug("input clusters are expected to be in a TTree.");
227 else if ( strcmp( argv[i], "-offlineMode" ) == 0)
230 HLTDebug("Using standard offline tracking.");
234 HLTError("Unknown option '%s'", argv[i] );
240 // THE "REAL" INIT COMES HERE
241 // offline condition data base
242 fCDB = AliCDBManager::Instance();
245 HLTError("Could not get CDB instance", "fCDB 0x%x", fCDB);
250 fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
251 fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
252 HLTDebug("CDB instance", "fCDB 0x%x", fCDB);
255 // check if the N of time bins make sense
258 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.");
262 if (iNtimeBins < 24 || iNtimeBins > 30)
264 HLTWarning("The number of time bins seems to be strange = %d. But okay. Let's try it...", iNtimeBins);
267 HLTDebug("The number of time bins = %d.", iNtimeBins);
268 AliTRDtrackerV1::SetNTimeBins(iNtimeBins);
270 // !!!! THIS IS IMPORTANT
271 // init alifield map - temporarly via parameter - should come from a DB or DCS ?
273 if (iMagneticField < 0)
276 HLTWarning("No magnetic field switch stated. Use -magnetic_field_ON or -magnetic_field_OFF flag. Defaulting to OFF = NO MAGNETIC FIELD");
279 if (iMagneticField == 0)
281 // magnetic field OFF
282 fField = new AliMagFMaps("Maps","Maps", 2, 0., 10., 1);
283 HLTDebug("Magnetic field is OFF.");
286 if (iMagneticField == 1)
289 fField = new AliMagFMaps("Maps","Maps", 2, 1., 10., 1);
290 HLTDebug("Magnetic field is ON.");
295 HLTError("Unable to init the field. Trouble at this point.");
299 // kTRUE sets the map uniform
300 AliTracker::SetFieldMap(fField,kTRUE);
302 // reconstruction parameters
303 if (iRecoParamType < 0 || iRecoParamType > 2)
305 HLTWarning("No reco param selected. Use -lowflux -highflux -cosmics flags. Defaulting to low flux.");
309 if (iRecoParamType == 0)
311 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
312 HLTDebug("Low flux params init.");
315 if (iRecoParamType == 1)
317 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
318 HLTDebug("High flux params init.");
321 if (iRecoParamType == 2)
323 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
324 HLTDebug("Cosmic Test params init.");
329 HLTError("No reco params initialized. Sniffing big trouble!");
333 fReconstructor = new AliTRDReconstructor();
334 // fRecoParam->SetChi2Y(.1);
335 // fRecoParam->SetChi2Z(5.);
336 fReconstructor->SetRecoParam(fRecoParam);
337 // write clusters [cw] = true
338 // track seeding (stand alone tracking) [sa] = true
339 // PID method in reconstruction (NN) [nn] = true
340 // write online tracklets [tw] = false
341 // drift gas [ar] = false
342 // sl_tr_0 = StreamLevel_task_Level
343 // fReconstructor->SetOption("sa,!cw,hlt,sl_tr_0");
344 TString recoOptions="sa,sl_cf_0";
348 recoOptions += ",cw";
352 recoOptions += ",!cw";
355 recoOptions += ",hlt";
357 fReconstructor->SetOption(recoOptions.Data());
358 HLTDebug("Reconstructor options are: %s",recoOptions.Data());
361 fGeometryFile = TFile::Open(fGeometryFileName.c_str());
364 AliGeomManager::LoadGeometry(fGeometryFileName.c_str());
368 HLTError("Unable to open file. FATAL!");
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
393 // fTracker->SetClustersOwner(kFALSE);
397 // We need to set clusters in Reconstructor to null to prevent from
398 // double deleting, since we delete TClonesArray by ourself in DoEvent.
399 fReconstructor->SetClusters(0x0);
400 delete fReconstructor;
401 fReconstructor = 0x0;
403 AliTRDcalibDB::Terminate();
407 fGeometryFile->Close();
408 delete fGeometryFile;
415 int AliHLTTRDTrackerV1Component::DoEvent( const AliHLTComponentEventData & evtData,
416 AliHLTComponentTriggerData & trigData )
419 Bool_t bWriteClusters = fReconstructor->IsWritingClusters();
421 HLTDebug("Output percentage set to %lu %%", fOutputPercentage );
422 HLTDebug("NofBlocks %lu", evtData.fBlockCnt );
424 AliHLTUInt32_t dBlockSpecification = 0;
427 //implement a usage of the following
428 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
429 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
430 // void *triggerData = trigData.fData;
431 HLTDebug("Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
433 AliHLTComponentBlockData *dblock = (AliHLTComponentBlockData *)GetFirstInputBlock( AliHLTTRDDefinitions::fgkClusterDataType );
436 AliHLTComponentDataType inputDataType = dblock->fDataType;
437 HLTDebug( "Event 0x%08LX (%Lu) received datatype: %s",
438 evtData.fEventID, evtData.fEventID,
439 DataType2Text(inputDataType).c_str());
440 dBlockSpecification = dblock->fSpecification;
444 HLTWarning("First Input Block not found! 0x%x", dblock);
450 TObject *tobjin = 0x0;
452 TTree *clusterTree = 0x0;
453 TClonesArray *clusterArray = 0x0;
455 tobjin = (TObject *)GetFirstInputObject( AliHLTTRDDefinitions::fgkClusterDataType, "TTree", ibForce);
456 HLTDebug("1stBLOCK; Pointer = 0x%x", tobjin);
457 clusterTree = (TTree*)tobjin;
459 // while (tobjin != 0)
463 HLTDebug("CLUSTERS; Pointer to TTree = 0x%x Name = %s", clusterTree, clusterTree->GetName());
464 HLTDebug("TTree of clusters: nbEntries = %i", clusterTree->GetEntriesFast());
465 fTracker->LoadClusters(clusterTree);
469 HLTError("First Input Block not a TTree 0x%x", tobjin);
473 tobjin = (TObject *)GetFirstInputObject( AliHLTTRDDefinitions::fgkClusterDataType, "TClonesArray", ibForce);
474 HLTDebug("1stBLOCK; Pointer = 0x%x", tobjin);
475 clusterArray = (TClonesArray*)tobjin;
478 HLTDebug("CLUSTERS; Pointer to TClonesArray = 0x%x Name = %s", clusterArray, clusterArray->GetName());
479 HLTDebug("TClonesArray of clusters: nbEntries = %i", clusterArray->GetEntriesFast());
480 Int_t nb = clusterArray->GetEntriesFast();
481 for (Int_t i=0; i<nb; i++){
482 AliTRDcluster * cluster = (AliTRDcluster* ) clusterArray->At(i);
483 //HLTDebug("Cluster[%i]: detector %i", i, cluster->GetDetector());
486 fTracker->LoadClusters(clusterArray);
490 HLTError("First Input Block not a TClonesArray 0x%x", tobjin);
494 // maybe it is not so smart to create it each event? clear is enough ?
495 AliESDEvent *esd = new AliESDEvent();
496 esd->CreateStdContent();
497 fTracker->Clusters2Tracks(esd);
499 //here transport the esd tracks further
500 Int_t nTracks = esd->GetNumberOfTracks();
501 Int_t nTRDTracks = esd->GetNumberOfTrdTracks();
502 HLTInfo("Number of tracks == %d == Number of TRD tracks %d", nTracks, nTRDTracks);
504 //PushBack(esd, AliHLTTRDDefinitions::fgkTRDSAEsdDataType);
506 // extract the friend ?
507 // AliESDfriend *esdFriend = new AliESDfriend();
508 // esd->GetESDfriend(esdFriend);
509 // PushBack(esdFriend, AliHLTTRDDefinitions::fgkTRDSAEsdDataType);
512 TClonesArray* trdTracks = fTracker->GetListOfTracks();
516 nTracks=trdTracks->GetEntriesFast();
519 HLTDebug("We have an output array: pointer to trdTracks = 0x%x, nbEntries = %i", trdTracks, nTracks);
520 HLTDebug("We have an output array: pointer to trdTracks = 0x%x, nbEntries = %i", trdTracks, nTracks);
522 trdTracks->BypassStreamer(kFALSE);
523 PushBack(trdTracks, AliHLTTRDDefinitions::fgkTRDSATracksDataType);
524 //trdTracks->Delete();
529 HLTDebug("Bad array trdTracks = 0x%x", trdTracks);
533 //here we are deleting clusters (but not the TClonesArray itself)
534 fTracker->UnloadClusters();
541 HLTDebug("Event done.");
545 ///////////////////////////////
547 consider transporting TRD tracks only as they might have signigicantly smaller size... on the other hand you will need to prodece ESDs at some point...
549 // this is for ESDtrack
550 // for (Int_t it = 0; it < nTracks; it++)
552 // AliESDtrack* track = esd->GetTrack(it);
553 // HLTInfo("Track %d 0x%x Pt %1.2f", it, track, track->Pt());
554 // //PushBack(track, AliHLTTRDDefinitions::fgkTRDSATracksDataType, ++dBlockSpecification);
555 // PushBack(track, AliHLTTRDDefinitions::fgkTRDSATracksDataType);
558 // one can do similar things with the TRDtrack
559 esd->GetNumberOfTrdTracks();
562 AliESDTrdTrack *trdtrack = esd->GetTrdTrack(i)