]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/src/AliRoot/MicrodHLT.cxx
Also dropping references to AliMUONTriggerCircuit which are depricated. This is a...
[u/mrichter/AliRoot.git] / HLT / MUON / src / AliRoot / MicrodHLT.cxx
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Author: Artur Szostak
4 // Email:  artur@alice.phy.uct.ac.za | artursz@iafrica.com
5 //
6 ////////////////////////////////////////////////////////////////////////////////
7
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
10    properly.
11    To run the dHLT with the default Manso algorithm one performs the following
12    steps (Assuming we have an initialise AliMUONDataInterface object called
13    data):
14
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;
21
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);
27
28      // And finally run the algorithm.
29      dhlt.Run();
30  */
31
32 #include "AliRoot/MicrodHLT.hpp"
33
34 #include "TMethodCall.h"
35
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"
45
46 #include "AliHLTMUONUtils.h"
47 #include "AliHLTMUONOutOfMemory.h"
48
49
50 namespace  // AliMicroFramework should be hidden.
51 {
52
53
54 class AliMicroFramework : public AliHLTMUONCoreTrackerCallback
55 {
56 public:
57
58         AliMicroFramework();
59         virtual ~AliMicroFramework() {}
60
61         virtual void RequestClusters(
62                         AliHLTMUONCoreTracker* tracker,
63                         Float /*left*/, Float /*right*/, Float /*bottom*/, Float /*top*/,
64                         AliHLTMUONCoreChamberID chamber, const void* tag
65                 );
66
67         virtual void EndOfClusterRequests(AliHLTMUONCoreTracker* /*tracker*/)
68         {
69                 DebugMsg(2, "EndOfClusterRequests");
70                 // We can ignore this. Nothing special to do here.
71         }
72
73         
74         virtual void FoundTrack(AliHLTMUONCoreTracker* tracker);
75         
76         virtual void NoTrackFound(AliHLTMUONCoreTracker* /*tracker*/)
77         {
78                 DebugMsg(2, "NoTrackFound");
79                 // Again nothing special to do here. The allocated memory is released
80                 // in the Run method.
81         }
82
83
84         void Run(
85                         const AliHLTMUONTriggerSource* triggersource,
86                         const AliHLTMUONClusterSource* clustersource,
87                         AliHLTMUONTrackSink* tracksink,
88                         AliHLTMUONCoreTracker* tracker
89                 );
90
91         void Run(
92                         const AliHLTMUONTriggerSource* triggersource,
93                         const AliHLTMUONClusterSource* clustersource,
94                         AliHLTMUONTrackSink* tracksink,
95                         AliHLTMUONCoreTracker* tracker, const Int eventnumber
96                 );
97
98 private:
99
100         // Do not allow copying
101         AliMicroFramework(const AliMicroFramework& /*object*/)
102                 : AliHLTMUONCoreTrackerCallback(), fTrackOutput(NULL), fCurrentTriggerNumber(0)
103         {}
104         
105         AliMicroFramework& operator = (const AliMicroFramework& /*object*/) { return *this; }
106
107
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);
112         
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.
117 };
118
119 //-----------------------------------------------------------------------------
120
121 AliMicroFramework::AliMicroFramework() :
122         AliHLTMUONCoreTrackerCallback(), fTrackOutput(NULL), fCurrentTriggerNumber(0)
123 {
124 // Default constructor.
125
126         for (Int_t i = 0; i < 10; i++)
127         {
128                 fClusterCount[i] = 0;
129                 fClusters[i] = NULL;
130         }
131         fTrackOutput = NULL;
132         fCurrentTriggerNumber = 0;
133 }
134
135
136 void AliMicroFramework::RequestClusters(
137                 AliHLTMUONCoreTracker* tracker,
138                 Float /*left*/, Float /*right*/, Float /*bottom*/, Float /*top*/,
139                 AliHLTMUONCoreChamberID chamber, const void* tag
140         )
141 {
142 // We return the clusters requested by the tracker.
143
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);
150 }
151
152
153 void AliMicroFramework::FoundTrack(AliHLTMUONCoreTracker* tracker)
154 {
155 // Callback method for the tracker.
156 // We need to add the found track to the track sink.
157
158         DebugMsg(2, "FoundTrack");
159         
160         // Fetch the track data from the tracker.
161         AliHLTMUONCoreTrack newtrack;
162         tracker->FillTrackData(newtrack);
163         
164         // Don't forget to fill the trigger ID number, this is not done by the tracker.
165         newtrack.fTriggerid = fCurrentTriggerNumber;
166
167         *fTrackOutput->AddTrack() = AliHLTMUONConvert(newtrack);
168 }
169         
170
171 void AliMicroFramework::Run(
172                 const AliHLTMUONTriggerSource* triggersource,
173                 const AliHLTMUONClusterSource* clustersource,
174                 AliHLTMUONTrackSink* tracksink,
175                 AliHLTMUONCoreTracker* tracker
176         )
177 {
178 // Run the micro dHLT chain.
179
180         if ( ! triggersource->GetFirstEvent()) return;
181         while (triggersource->MoreEvents())
182         {
183                 Run(triggersource, clustersource, tracksink, tracker, triggersource->CurrentEvent());
184                 triggersource->GetNextEvent();
185         }
186 }
187
188
189 void AliMicroFramework::Run(
190                 const AliHLTMUONTriggerSource* triggersource,
191                 const AliHLTMUONClusterSource* clustersource,
192                 AliHLTMUONTrackSink* tracksink,
193                 AliHLTMUONCoreTracker* tracker, const Int eventnumber
194         )
195 {
196 // Process a particlar event from the trigger and cluster source.
197
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.
202         
203         CreateClusterBlocks(clustersource, eventnumber);
204         try
205         {
206                 fTrackOutput->AddEvent(eventnumber);
207                 fTrackOutput->AddBlock();
208                 ProcessTriggers(triggersource, tracker);
209         }
210         finally
211         (
212                 FreeClusterBlocks();
213         );
214 }
215
216
217 void AliMicroFramework::CountClusterPoints(const AliHLTMUONClusterSource* cs)
218 {
219 // Count the number of clusters on each chamber in the cluster source.
220
221         for (Int i = 0; i < 10; i++)
222                 fClusterCount[i] = 0;
223
224         cs->GetFirstBlock();
225         while (cs->MoreBlocks())
226         {
227                 Int chamber = cs->Chamber();
228                 if (0 <= chamber && chamber < 10)
229                 {
230                         fClusterCount[chamber] += cs->NumberOfClusters();
231                 }
232                 cs->GetNextBlock();
233         }
234 }
235         
236
237 void AliMicroFramework::CreateClusterBlocks(
238                 const AliHLTMUONClusterSource* cs, Int eventnumber
239         )
240 {
241 // Fill the fClusters buffers from cluster source.
242
243         // Must select the proper event before counting or filling the arrays.
244         if ( ! cs->GetEvent(eventnumber) ) return;
245         
246         CountClusterPoints(cs);
247         
248         UInt currentcount[10];
249         for (Int i = 0; i < 10; i++)
250         {
251                 // Initialise currentcount.
252                 currentcount[i] = 0;
253
254                 // Allocate arrays.
255                 if (fClusterCount[i] > 0)
256                         fClusters[i] = new AliHLTMUONCoreClusterPoint[ fClusterCount[i] ];
257                 else
258                         fClusters[i] = NULL;
259         }
260
261         // Copy all the cluster data into arrays.
262         cs->GetFirstBlock();
263         while (cs->MoreBlocks())
264         {
265                 Int chamber = cs->Chamber();
266                 if (0 <= chamber && chamber < 10)
267                 {
268                         cs->GetFirstCluster();
269                         while (cs->MoreClusters())
270                         {
271                                 AliHLTMUONCoreClusterPoint newpoint;
272                                 cs->FetchCluster(newpoint.X(), newpoint.Y());
273                                 fClusters[chamber][currentcount[chamber]++] = newpoint;
274                                 cs->GetNextCluster();
275                         }
276                 }
277                 cs->GetNextBlock();
278         }
279 }
280
281
282 void AliMicroFramework::FreeClusterBlocks()
283 {
284 // Release the fClusters buffers.
285
286         for (Int i = 0; i < 10; i++)
287         {
288                 if (fClusters[i] != NULL)
289                 {
290                         delete [] fClusters[i];
291                         fClusters[i] = NULL;
292                 }
293         }
294 }
295         
296         
297 void AliMicroFramework::ProcessTriggers(
298                 const AliHLTMUONTriggerSource* ts, AliHLTMUONCoreTracker* tracker
299         )
300 {
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.
304         
305         ts->GetFirstBlock();
306         while (ts->MoreBlocks())
307         {
308                 ts->GetFirstTrigger();
309                 while (ts->MoreTriggers())
310                 {
311                         const AliHLTMUONTriggerRecord* trigdata = ts->GetTrigger();
312                         Assert( trigdata != NULL );
313                         fCurrentTriggerNumber = (UInt)trigdata->TriggerNumber();
314
315                         AliHLTMUONCoreTriggerRecord trigger = AliHLTMUONConvert(*trigdata);
316
317                         DebugMsg(2, "Finding track:");
318                         tracker->FindTrack(trigger);
319
320                         DebugMsg(2, "Reset tracker.");
321                         tracker->Reset();
322                         
323                         ts->GetNextTrigger();
324                 }
325                 ts->GetNextBlock();
326         }
327 }
328
329
330 } // end of namespace
331
332
333 ////////////////////////////////////////////////////////////////////////////////
334
335
336 ClassImp(AliHLTMUONMicrodHLT)
337
338
339 TString AliHLTMUONVersion()
340 {
341         TString str = dHLT::VersionString();
342         return str;
343 }
344
345 UInt_t AliHLTMUONMajorVersion()
346 {
347         return dHLT::MajorVersion();
348 }
349
350 UInt_t AliHLTMUONMinorVersion()
351 {
352         return dHLT::MinorVersion();
353 }
354
355 UInt_t AliHLTMUONBuildNumber()
356 {
357         return dHLT::BuildNumber();
358 }
359
360
361 AliHLTMUONMicrodHLT::AliHLTMUONMicrodHLT() :
362         TObject(),
363         fTriggerSource(NULL), fClusterSource(NULL), fTrackSink(NULL),
364         fClusterFinder(NULL), fTracker(NULL)
365 {
366 // Default constructor
367
368         fTriggerSource = NULL;
369         fClusterSource = NULL;
370         fTrackSink = NULL;
371         fClusterFinder = NULL;
372         fTracker = NULL;
373 }
374
375
376 AliHLTMUONMicrodHLT::~AliHLTMUONMicrodHLT()
377 {
378         // Nothing to do here.
379 }
380
381
382 void AliHLTMUONMicrodHLT::SetTriggerSource(const AliHLTMUONTriggerSource* source)
383 {
384         fTriggerSource = const_cast<AliHLTMUONTriggerSource*>( source );
385 }
386
387 void AliHLTMUONMicrodHLT::SetClusterSource(const AliHLTMUONClusterSource* source)
388 {
389         fClusterSource = const_cast<AliHLTMUONClusterSource*>( source );
390 }
391
392
393 void AliHLTMUONMicrodHLT::Run()
394 {
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.
398
399         DebugMsg(1, "Run");
400
401         //AliHLTMUONCoreClusterFinder* clusterfinder;
402         //dHLT::Decision::DecisionMaker* decisionmaker;
403         //AliHLTMUONCoreTracker* tracker;
404         
405         if (fTriggerSource == NULL)
406         {
407                 Error("Run", "The trigger source was not set.");
408                 return;
409         }
410         if (fClusterSource == NULL)
411         {
412                 Error("Run", "The cluster source was not set.");
413                 return;
414         }
415         if (fTrackSink == NULL)
416         {
417                 Error("Run", "The track output sink was not set.");
418                 return;
419         }
420         
421         if (fTriggerSource->FileName() != fClusterSource->FileName() ||
422             fTriggerSource->FolderName() != fClusterSource->FolderName())
423         {
424                 Warning("Run", "The file and folder names of the trigger source and cluster source do not correspond.");
425         }
426
427         AliHLTMUONCoreClusterFinder* clusterfinder = NULL;
428         AliHLTMUONCoreTracker* tracker = NULL;
429         try
430         {
431                 // Assign the dHLT cluster finder object. If the fClusterFinder field is
432                 // not set then use the default CenterOfGravityFinder.
433                 if (fClusterFinder == NULL)
434                 {
435                         clusterfinder = new AliHLTMUONCoreCenterOfGravityFinder();
436                 }
437                 else
438                 {
439                         AliHLTMUONClusterFinderProxy* clusterfinderproxy
440                                 = new AliHLTMUONClusterFinderProxy(fClusterFinder);
441                         fClusterFinder->SetCallback(clusterfinderproxy);
442                         clusterfinder = clusterfinderproxy;
443                 }
444
445                 // Assign the dHLT tracker object. If the fTracker field was not set just
446                 // use the default MansoTracker implementation.
447                 if (fTracker == NULL)
448                 {
449                         tracker = new AliHLTMUONCoreMansoTracker();
450                 }
451                 else
452                 {
453                         AliHLTMUONTrackerProxy* trackerproxy = new AliHLTMUONTrackerProxy(fTracker);
454                         fTracker->SetCallback(trackerproxy);
455                         tracker = trackerproxy;
456                 }
457
458                 AliMicroFramework framework;
459                 framework.Run(fTriggerSource, fClusterSource, fTrackSink, tracker);
460         }
461         finally
462         (
463                 if (tracker != NULL) delete tracker;
464                 if (clusterfinder != NULL) delete clusterfinder;
465         );
466 }
467
468
469 #ifdef DEBUG
470 void AliHLTMUONMicrodHLT::DebugLevel(Int_t value)
471 {
472         gAliHLTMUONDebugLevel = value;
473 }
474 #else // DEBUG
475 void AliHLTMUONMicrodHLT::DebugLevel(Int_t /*value*/) {}
476 #endif // DEBUG
477
478
479 Int_t AliHLTMUONMicrodHLT::DebugLevel()
480 {
481 // Returns the debug level for the dHLT module.
482
483 #ifdef DEBUG
484         return gAliHLTMUONDebugLevel;
485 #else // DEBUG
486         return -1;
487 #endif // DEBUG
488 }