1 ////////////////////////////////////////////////////////////////////////////////
3 // Author: Artur Szostak
4 // Email: artur@alice.phy.uct.ac.za | artursz@iafrica.com
6 ////////////////////////////////////////////////////////////////////////////////
8 /* AliHLTMUONMicrodHLT is a minimalist framework for the dHLT tracking algorithm
9 to run in. It integrates all the internal components to execute the algorithm
11 To run the dHLT with the default Manso algorithm one performs the following
12 steps (Assuming we have an initialise AliMUONDataInterface object called
15 // Create a trigger source for the track seeds and populate it with data.
16 AliHLTMUONTriggerSource ts(data);
17 // We also need the cluster points.
18 AliHLTMUONClusterSource cs(data);
19 // Need a track sink to store the output data.
20 AliHLTMUONTrackSink output;
22 // Now we need the framework created and hook up the input and output.
23 AliHLTMUONMicrodHLT dhlt;
24 dhlt.SetTriggerSource(&ts);
25 dhlt.SetClusterSource(&ts);
26 dhlt.SetTrackSink(&output);
28 // And finally run the algorithm.
32 #include "AliRoot/MicrodHLT.hpp"
34 #include "TMethodCall.h"
36 #include "Version/Version.hpp"
37 #include "Clustering/ClusterFinder.hpp"
38 #include "Clustering/CenterOfGravityFinder.hpp"
39 #include "Tracking/Tracker.hpp"
40 #include "Tracking/MansoTracker.hpp"
41 #include "Decision/DecisionMaker.hpp"
42 #include "AliRoot/convert.hpp"
43 #include "AliRoot/ClusterFinderProxy.hpp"
44 #include "AliRoot/TrackerProxy.hpp"
46 #include "AliHLTMUONUtils.h"
47 #include "AliHLTMUONOutOfMemory.h"
50 namespace // AliMicroFramework should be hidden.
54 class AliMicroFramework : public AliHLTMUONCoreTrackerCallback
59 virtual ~AliMicroFramework() {}
61 virtual void RequestClusters(
62 AliHLTMUONCoreTracker* tracker,
63 Float /*left*/, Float /*right*/, Float /*bottom*/, Float /*top*/,
64 AliHLTMUONCoreChamberID chamber, const void* tag
67 virtual void EndOfClusterRequests(AliHLTMUONCoreTracker* /*tracker*/)
69 DebugMsg(2, "EndOfClusterRequests");
70 // We can ignore this. Nothing special to do here.
74 virtual void FoundTrack(AliHLTMUONCoreTracker* tracker);
76 virtual void NoTrackFound(AliHLTMUONCoreTracker* /*tracker*/)
78 DebugMsg(2, "NoTrackFound");
79 // Again nothing special to do here. The allocated memory is released
85 const AliHLTMUONTriggerSource* triggersource,
86 const AliHLTMUONClusterSource* clustersource,
87 AliHLTMUONTrackSink* tracksink,
88 AliHLTMUONCoreTracker* tracker
92 const AliHLTMUONTriggerSource* triggersource,
93 const AliHLTMUONClusterSource* clustersource,
94 AliHLTMUONTrackSink* tracksink,
95 AliHLTMUONCoreTracker* tracker, const Int eventnumber
100 // Do not allow copying
101 AliMicroFramework(const AliMicroFramework& /*object*/)
102 : AliHLTMUONCoreTrackerCallback(), fTrackOutput(NULL), fCurrentTriggerNumber(0)
105 AliMicroFramework& operator = (const AliMicroFramework& /*object*/) { return *this; }
108 void CountClusterPoints(const AliHLTMUONClusterSource* cs);
109 void CreateClusterBlocks(const AliHLTMUONClusterSource* cs, Int eventnumber);
110 void FreeClusterBlocks();
111 void ProcessTriggers(const AliHLTMUONTriggerSource* ts, AliHLTMUONCoreTracker* tracker);
113 UInt fClusterCount[10]; // Number of clusters in fClusters.
114 AliHLTMUONCoreClusterPoint* fClusters[10]; // Buffers for cluster points received.
115 AliHLTMUONTrackSink* fTrackOutput; // The current track output object.
116 UInt fCurrentTriggerNumber; // The current trigger, trigger number to use.
119 //-----------------------------------------------------------------------------
121 AliMicroFramework::AliMicroFramework() :
122 AliHLTMUONCoreTrackerCallback(), fTrackOutput(NULL), fCurrentTriggerNumber(0)
124 // Default constructor.
126 for (Int_t i = 0; i < 10; i++)
128 fClusterCount[i] = 0;
132 fCurrentTriggerNumber = 0;
136 void AliMicroFramework::RequestClusters(
137 AliHLTMUONCoreTracker* tracker,
138 Float /*left*/, Float /*right*/, Float /*bottom*/, Float /*top*/,
139 AliHLTMUONCoreChamberID chamber, const void* tag
142 // We return the clusters requested by the tracker.
144 Assert( 0 <= chamber && chamber <= 10 );
145 DebugMsg(2, "RequestClusters: tag = " << tag);
146 register void* ctag = const_cast<void*>(tag); // We never modify tag so this is OK.
147 if (fClusters[chamber] != NULL)
148 tracker->ReturnClusters(ctag, fClusters[chamber], fClusterCount[chamber]);
149 tracker->EndOfClusters(ctag);
153 void AliMicroFramework::FoundTrack(AliHLTMUONCoreTracker* tracker)
155 // Callback method for the tracker.
156 // We need to add the found track to the track sink.
158 DebugMsg(2, "FoundTrack");
160 // Fetch the track data from the tracker.
161 AliHLTMUONCoreTrack newtrack;
162 tracker->FillTrackData(newtrack);
164 // Don't forget to fill the trigger ID number, this is not done by the tracker.
165 newtrack.fTriggerid = fCurrentTriggerNumber;
167 *fTrackOutput->AddTrack() = AliHLTMUONConvert(newtrack);
171 void AliMicroFramework::Run(
172 const AliHLTMUONTriggerSource* triggersource,
173 const AliHLTMUONClusterSource* clustersource,
174 AliHLTMUONTrackSink* tracksink,
175 AliHLTMUONCoreTracker* tracker
178 // Run the micro dHLT chain.
180 if ( ! triggersource->GetFirstEvent()) return;
181 while (triggersource->MoreEvents())
183 Run(triggersource, clustersource, tracksink, tracker, triggersource->CurrentEvent());
184 triggersource->GetNextEvent();
189 void AliMicroFramework::Run(
190 const AliHLTMUONTriggerSource* triggersource,
191 const AliHLTMUONClusterSource* clustersource,
192 AliHLTMUONTrackSink* tracksink,
193 AliHLTMUONCoreTracker* tracker, const Int eventnumber
196 // Process a particlar event from the trigger and cluster source.
198 // Tell the tracker to make callbacks to this framework object.
199 tracker->SetCallback(this);
200 fTrackOutput = tracksink;
201 fTrackOutput->SetNames(triggersource); // Want the file and folder names to correspond.
203 CreateClusterBlocks(clustersource, eventnumber);
206 fTrackOutput->AddEvent(eventnumber);
207 fTrackOutput->AddBlock();
208 ProcessTriggers(triggersource, tracker);
217 void AliMicroFramework::CountClusterPoints(const AliHLTMUONClusterSource* cs)
219 // Count the number of clusters on each chamber in the cluster source.
221 for (Int i = 0; i < 10; i++)
222 fClusterCount[i] = 0;
225 while (cs->MoreBlocks())
227 Int chamber = cs->Chamber();
228 if (0 <= chamber && chamber < 10)
230 fClusterCount[chamber] += cs->NumberOfClusters();
237 void AliMicroFramework::CreateClusterBlocks(
238 const AliHLTMUONClusterSource* cs, Int eventnumber
241 // Fill the fClusters buffers from cluster source.
243 // Must select the proper event before counting or filling the arrays.
244 if ( ! cs->GetEvent(eventnumber) ) return;
246 CountClusterPoints(cs);
248 UInt currentcount[10];
249 for (Int i = 0; i < 10; i++)
251 // Initialise currentcount.
255 if (fClusterCount[i] > 0)
256 fClusters[i] = new AliHLTMUONCoreClusterPoint[ fClusterCount[i] ];
261 // Copy all the cluster data into arrays.
263 while (cs->MoreBlocks())
265 Int chamber = cs->Chamber();
266 if (0 <= chamber && chamber < 10)
268 cs->GetFirstCluster();
269 while (cs->MoreClusters())
271 AliHLTMUONCoreClusterPoint newpoint;
272 cs->FetchCluster(newpoint.X(), newpoint.Y());
273 fClusters[chamber][currentcount[chamber]++] = newpoint;
274 cs->GetNextCluster();
282 void AliMicroFramework::FreeClusterBlocks()
284 // Release the fClusters buffers.
286 for (Int i = 0; i < 10; i++)
288 if (fClusters[i] != NULL)
290 delete [] fClusters[i];
297 void AliMicroFramework::ProcessTriggers(
298 const AliHLTMUONTriggerSource* ts, AliHLTMUONCoreTracker* tracker
301 // Go through the list of triggers and have tracker try find the track using
302 // the trigger as a seed.
303 // Note: The proper event must be selected before calling this method.
306 while (ts->MoreBlocks())
308 ts->GetFirstTrigger();
309 while (ts->MoreTriggers())
311 const AliHLTMUONTriggerRecord* trigdata = ts->GetTrigger();
312 Assert( trigdata != NULL );
313 fCurrentTriggerNumber = (UInt)trigdata->TriggerNumber();
315 AliHLTMUONCoreTriggerRecord trigger = AliHLTMUONConvert(*trigdata);
317 DebugMsg(2, "Finding track:");
318 tracker->FindTrack(trigger);
320 DebugMsg(2, "Reset tracker.");
323 ts->GetNextTrigger();
330 } // end of namespace
333 ////////////////////////////////////////////////////////////////////////////////
336 ClassImp(AliHLTMUONMicrodHLT)
339 TString AliHLTMUONVersion()
341 TString str = dHLT::VersionString();
345 UInt_t AliHLTMUONMajorVersion()
347 return dHLT::MajorVersion();
350 UInt_t AliHLTMUONMinorVersion()
352 return dHLT::MinorVersion();
355 UInt_t AliHLTMUONBuildNumber()
357 return dHLT::BuildNumber();
361 AliHLTMUONMicrodHLT::AliHLTMUONMicrodHLT() :
363 fTriggerSource(NULL), fClusterSource(NULL), fTrackSink(NULL),
364 fClusterFinder(NULL), fTracker(NULL)
366 // Default constructor
368 fTriggerSource = NULL;
369 fClusterSource = NULL;
371 fClusterFinder = NULL;
376 AliHLTMUONMicrodHLT::~AliHLTMUONMicrodHLT()
378 // Nothing to do here.
382 void AliHLTMUONMicrodHLT::SetTriggerSource(const AliHLTMUONTriggerSource* source)
384 fTriggerSource = const_cast<AliHLTMUONTriggerSource*>( source );
387 void AliHLTMUONMicrodHLT::SetClusterSource(const AliHLTMUONClusterSource* source)
389 fClusterSource = const_cast<AliHLTMUONClusterSource*>( source );
393 void AliHLTMUONMicrodHLT::Run()
395 // The entry point routine for the dHLT algorithm in the micro format.
396 // To run the dHLT set the input and output objects with the set methods
397 // provided and then call this Run method.
401 //AliHLTMUONCoreClusterFinder* clusterfinder;
402 //dHLT::Decision::DecisionMaker* decisionmaker;
403 //AliHLTMUONCoreTracker* tracker;
405 if (fTriggerSource == NULL)
407 Error("Run", "The trigger source was not set.");
410 if (fClusterSource == NULL)
412 Error("Run", "The cluster source was not set.");
415 if (fTrackSink == NULL)
417 Error("Run", "The track output sink was not set.");
421 if (fTriggerSource->FileName() != fClusterSource->FileName() ||
422 fTriggerSource->FolderName() != fClusterSource->FolderName())
424 Warning("Run", "The file and folder names of the trigger source and cluster source do not correspond.");
427 AliHLTMUONCoreClusterFinder* clusterfinder = NULL;
428 AliHLTMUONCoreTracker* tracker = NULL;
431 // Assign the dHLT cluster finder object. If the fClusterFinder field is
432 // not set then use the default CenterOfGravityFinder.
433 if (fClusterFinder == NULL)
435 clusterfinder = new AliHLTMUONCoreCenterOfGravityFinder();
439 AliHLTMUONClusterFinderProxy* clusterfinderproxy
440 = new AliHLTMUONClusterFinderProxy(fClusterFinder);
441 fClusterFinder->SetCallback(clusterfinderproxy);
442 clusterfinder = clusterfinderproxy;
445 // Assign the dHLT tracker object. If the fTracker field was not set just
446 // use the default MansoTracker implementation.
447 if (fTracker == NULL)
449 tracker = new AliHLTMUONCoreMansoTracker();
453 AliHLTMUONTrackerProxy* trackerproxy = new AliHLTMUONTrackerProxy(fTracker);
454 fTracker->SetCallback(trackerproxy);
455 tracker = trackerproxy;
458 AliMicroFramework framework;
459 framework.Run(fTriggerSource, fClusterSource, fTrackSink, tracker);
463 if (tracker != NULL) delete tracker;
464 if (clusterfinder != NULL) delete clusterfinder;
470 void AliHLTMUONMicrodHLT::DebugLevel(Int_t value)
472 gAliHLTMUONDebugLevel = value;
475 void AliHLTMUONMicrodHLT::DebugLevel(Int_t /*value*/) {}
479 Int_t AliHLTMUONMicrodHLT::DebugLevel()
481 // Returns the debug level for the dHLT module.
484 return gAliHLTMUONDebugLevel;