]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/OfflineInterface/AliHLTMUONESDMaker.cxx
Removing compilation warnings.
[u/mrichter/AliRoot.git] / HLT / MUON / OfflineInterface / AliHLTMUONESDMaker.cxx
1 /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        *
3  * All rights reserved.                                                   *
4  *                                                                        *
5  * Primary Authors:                                                       *
6  *   Artur Szostak <artursz@iafrica.com>                                  *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 /* $Id: $ */
18
19 ///
20 /// @file   AliHLTMUONESDMaker.cxx
21 /// @author Artur Szostak <artursz@iafrica.com>
22 /// @date   30 June 2008
23 /// @brief  Implementation of the AliHLTMUONESDMaker component.
24 ///
25 /// The ESD maker component converts dHLT raw internal reconstructed information
26 /// into AliESDEvent objects.
27 ///
28
29 #include "AliHLTMUONESDMaker.h"
30 #include "AliHLTMUONEvent.h"
31 #include "AliHLTMUONConstants.h"
32 #include "AliHLTMUONUtils.h"
33 #include "AliHLTMUONRecHit.h"
34 #include "AliHLTMUONTriggerRecord.h"
35 #include "AliHLTMUONMansoTrack.h"
36 #include "AliHLTMUONDecision.h"
37 #include "AliMUONConstants.h"
38 #include "AliMUONVCluster.h"
39 #include "AliESDEvent.h"
40 #include "AliESDRun.h"
41 #include "AliESDMuonTrack.h"
42 #include "AliESDMuonCluster.h"
43 #include "TClonesArray.h"
44 #include <cmath>
45 #include <cassert>
46
47
48 ClassImp(AliHLTMUONESDMaker);
49
50
51 AliHLTMUONESDMaker::AliHLTMUONESDMaker() :
52         AliHLTMUONProcessor(),
53         fWarnForUnexpecedBlock(false),
54         fMakeMinimalESD(false),
55         fAddCustomData(false)
56 {
57         /// Default constructor.
58 }
59
60
61 AliHLTMUONESDMaker::~AliHLTMUONESDMaker()
62 {
63         /// Default destructor.
64 }
65
66
67 bool AliHLTMUONESDMaker::IgnoreArgument(const char* arg) const
68 {
69         /// Return true if the argument is one of -cdbpath -run or -delaysetup
70         /// to prevent the parent class from parsing these arguments in DoInit.
71         
72         if (strcmp(arg, "-cdbpath") == 0 or strcmp(arg, "-run") == 0 or
73             strcmp(arg, "-delaysetup") == 0)
74         {
75                 return true;
76         }
77         else
78         {
79                 return false;
80         }
81 }
82
83
84 int AliHLTMUONESDMaker::DoInit(int argc, const char** argv)
85 {
86         /// Inherited from AliHLTComponent.
87         /// Parses the command line parameters and initialises the component.
88         
89         HLTInfo("Initialising dHLT ESD maker component.");
90
91         // Inherit the parents functionality.
92         int result = AliHLTMUONProcessor::DoInit(argc, argv);
93         if (result != 0) return result;
94         
95         fWarnForUnexpecedBlock = false;
96         fMakeMinimalESD = false;
97         
98         for (int i = 0; i < argc; i++)
99         {
100                 if (ArgumentAlreadyHandled(i, argv[i])) continue;
101
102                 if (strcmp(argv[i], "-make_minimal_esd") == 0)
103                 {
104                         fMakeMinimalESD = true;
105                         continue;
106                 }
107                 
108                 if (strcmp(argv[i], "-warn_on_unexpected_block") == 0)
109                 {
110                         fWarnForUnexpecedBlock = true;
111                         continue;
112                 }
113                 
114                 if (strcmp(argv[i], "-add_rootified_objects") == 0)
115                 {
116                         fAddCustomData = true;
117                         continue;
118                 }
119
120                 HLTError("Unknown option '%s'.", argv[i]);
121                 return -EINVAL;
122         }
123         
124         return 0;
125 }
126
127
128 int AliHLTMUONESDMaker::DoDeinit()
129 {
130         /// Inherited from AliHLTComponent. Performs a cleanup of the component.
131         
132         HLTInfo("Deinitialising dHLT ESD maker component.");
133         return 0;
134 }
135
136
137 const char* AliHLTMUONESDMaker::GetComponentID()
138 {
139         /// Inherited from AliHLTComponent. Returns the component ID.
140         
141         return AliHLTMUONConstants::ESDMakerId();
142 }
143
144
145 AliHLTComponentDataType AliHLTMUONESDMaker::GetOutputDataType()
146 {
147         /// Inherited from AliHLTComponent.
148         /// Returns the ESD object data type with MUON origin.
149         
150         return AliHLTMUONConstants::ESDDataType();
151 }
152
153
154 void AliHLTMUONESDMaker::GetInputDataTypes(AliHLTComponentDataTypeList& list)
155 {
156         /// Inherited from AliHLTProcessor.
157         /// Returns the list of expected input data types.
158         
159         list.push_back(AliHLTMUONConstants::TriggerRecordsBlockDataType());
160         list.push_back(AliHLTMUONConstants::MansoTracksBlockDataType());
161 }
162
163
164 void AliHLTMUONESDMaker::GetOutputDataSize(
165                 unsigned long& constBase, double& inputMultiplier
166         )
167 {
168         /// Inherited from AliHLTComponent.
169         /// Returns an estimate of the expected output data size.
170         
171         constBase = sizeof(AliESDEvent) + 1024*1024;  // The extra 1 MByte is for auxilary objects created in AliESDEvent.
172         inputMultiplier = 10;
173 }
174
175
176 AliHLTComponent* AliHLTMUONESDMaker::Spawn()
177 {
178         /// Inherited from AliHLTComponent. Creates a new object instance.
179         
180         return new AliHLTMUONESDMaker();
181 }
182
183
184 int AliHLTMUONESDMaker::DoEvent(
185                 const AliHLTComponentEventData& evtData,
186                 AliHLTComponentTriggerData& trigData
187         )
188 {
189         /// Inherited from AliHLTProcessor. Processes the new event data.
190         
191         AliESDEvent event;
192         AliHLTUInt32_t clusterIndex = 0;  // for the cluster unique ID.
193         
194         // Create and fill in the standard ESD objects or just create the muon
195         // tracks array if so requested.
196         if (fMakeMinimalESD)
197         {
198                 TClonesArray* muonTracks = new TClonesArray("AliESDMuonTrack",0);
199                 muonTracks->SetName("MuonTracks");
200                 event.AddObject(muonTracks);
201                 event.GetStdContent();
202         }
203         else
204         {
205                 event.CreateStdContent();
206                 event.SetRunNumber(GetRunNo());
207         }
208         
209         const AliHLTComponentBlockData* block = NULL;
210         AliHLTUInt32_t specification = 0;  // Contains the output data block spec bits.
211         std::vector<const AliHLTMUONTriggerRecordStruct*> triggerRecords;
212
213         // First process the blocks of trigger records. We simply mark each trigger
214         // record in the triggerRecords array.
215         for (int i = 0; i < GetNumberOfInputBlocks(); i++)
216         {
217                 block = GetInputBlock(i);
218                 assert( block != NULL );
219                 
220                 HLTDebug("Handling block: %u, with fDataType = '%s', fPtr = %p and fSize = %u bytes.",
221                         i, DataType2Text(block->fDataType).c_str(), block->fPtr, block->fSize
222                 );
223                 
224                 if (block->fDataType == AliHLTMUONConstants::TriggerRecordsBlockDataType())
225                 {
226                         specification |= block->fSpecification;
227                         AliHLTMUONTriggerRecordsBlockReader inblock(block->fPtr, block->fSize);
228                         if (not BlockStructureOk(inblock))
229                         {
230                                 if (DumpDataOnError()) DumpEvent(evtData, trigData);
231                                 continue;
232                         }
233                         
234                         for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
235                         {
236                                 triggerRecords.push_back(&inblock[n]);
237                         }
238                 }
239                 else if (block->fDataType == AliHLTMUONConstants::RootifiedEventDataType() and fAddCustomData)
240                 {
241                         // Do nothing for now, will handle this later.
242                 }
243                 else
244                 {
245                         if (block->fDataType != AliHLTMUONConstants::MansoTracksBlockDataType())
246                         {
247                                 // Log a message indicating that we got a data block that we
248                                 // do not know how to handle.
249                                 if (fWarnForUnexpecedBlock)
250                                         HLTWarning("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
251                                                 DataType2Text(block->fDataType).c_str(), block->fSpecification
252                                         );
253 #ifdef __DEBUG
254                                 else
255                                         HLTDebug("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
256                                                 DataType2Text(block->fDataType).c_str(), block->fSpecification
257                                         );
258 #endif
259                         }
260                 }
261         }
262         
263         // If we were requested to add all dHLT rootified data objects then do so.
264         if (fAddCustomData)
265         {
266                 const AliHLTComponentDataType& type = AliHLTMUONConstants::RootifiedEventDataType();
267                 const char* classname = AliHLTMUONEvent::Class_Name();
268                 const TObject* obj = NULL;
269                 for (obj = GetFirstInputObject(type, classname); obj != NULL; obj = GetNextInputObject())
270                 {
271                         // Clone the object since the ESD takes ownership of it.
272                         event.AddObject(obj->Clone());
273                 }
274         }
275         
276         // Now we can look for tracks to add. We needed the ROOT trigger records
277         // and reco hits created before we can create track objects.
278         for (block = GetFirstInputBlock(AliHLTMUONConstants::MansoTracksBlockDataType());
279              block != NULL;
280              block = GetNextInputBlock()
281             )
282         {
283                 specification |= block->fSpecification;
284                 AliHLTMUONMansoTracksBlockReader inblock(block->fPtr, block->fSize);
285                 if (not BlockStructureOk(inblock))
286                 {
287                         if (DumpDataOnError()) DumpEvent(evtData, trigData);
288                         continue;
289                 }
290                 
291                 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
292                 {
293                         const AliHLTMUONMansoTrackStruct& t = inblock[n];
294                         AliESDMuonTrack muTrack;
295                         
296                         AliHLTMUONParticleSign sign;
297                         bool hitset[4];
298                         AliHLTMUONUtils::UnpackMansoTrackFlags(
299                                         t.fFlags, sign, hitset
300                                 );
301                         
302                         double signVal = 0;
303                         switch (sign)
304                         {
305                         case kSignMinus:   signVal = +1.; break;
306                         case kSignUnknown: signVal =  0.; break;
307                         case kSignPlus:    signVal = -1.; break;
308                         default:
309                                 HLTWarning("Got a track with an invalid sign value: %d", int(sign));
310                         }
311                         
312                         TVector3 mom(t.fPx, t.fPy, t.fPz);
313                         if (mom.Mag() != 0)
314                                 muTrack.SetInverseBendingMomentum(signVal/mom.Mag());
315                         else
316                                 muTrack.SetInverseBendingMomentum(0.);
317                         muTrack.SetThetaX(atan2(t.fPx, t.fPz));
318                         muTrack.SetThetaY(atan2(t.fPy, t.fPz));
319                         muTrack.SetZ(0.);
320                         muTrack.SetBendingCoor(0.);
321                         muTrack.SetNonBendingCoor(0.);
322                         
323                         // The Manso algorithm assumes the information at the
324                         // Distance of Closest Approach and chamber 1 is the same
325                         // as the vertex.
326                         if (mom.Mag() != 0)
327                                 muTrack.SetInverseBendingMomentumAtDCA(1./mom.Mag());
328                         else
329                                 muTrack.SetInverseBendingMomentumAtDCA(0.);
330                         muTrack.SetThetaXAtDCA(atan2(t.fPx, t.fPz));
331                         muTrack.SetThetaYAtDCA(atan2(t.fPy, t.fPz));
332                         muTrack.SetBendingCoorAtDCA(0.);
333                         muTrack.SetNonBendingCoorAtDCA(0.);
334                         
335                         if (mom.Mag() != 0)
336                                 muTrack.SetInverseBendingMomentumUncorrected(1./mom.Mag());
337                         else
338                                 muTrack.SetInverseBendingMomentumUncorrected(0.);
339                         muTrack.SetThetaXUncorrected(atan2(t.fPx, t.fPz));
340                         muTrack.SetThetaYUncorrected(atan2(t.fPy, t.fPz));
341                         muTrack.SetZUncorrected(0.);
342                         muTrack.SetBendingCoorUncorrected(0.);
343                         muTrack.SetNonBendingCoorUncorrected(0.);
344                         
345                         muTrack.SetChi2(t.fChi2);
346                         
347                         // Fill in the track hit points.
348                         Int_t nHits = 0;
349                         for (int i = 0; i < 4; i++)
350                         {
351                                 if (not hitset[i]) continue;
352                                 
353                                 AliHLTUInt8_t chamber;
354                                 AliHLTUInt16_t detElemId;
355                                 AliHLTMUONUtils::UnpackRecHitFlags(t.fHit[i].fFlags, chamber, detElemId);
356                                 
357                                 AliESDMuonCluster cluster;
358                                 cluster.SetUniqueID(AliMUONVCluster::BuildUniqueID(chamber, detElemId, clusterIndex++));
359                                 cluster.SetXYZ(t.fHit[i].fX, t.fHit[i].fY, t.fHit[i].fZ);
360                                 cluster.SetErrXY(    // Use nominal values.
361                                                 AliHLTMUONConstants::DefaultBendingReso(),
362                                                 AliHLTMUONConstants::DefaultNonBendingReso()
363                                         );
364                                 cluster.SetCharge(-1.);   // Indicate no total charge calculated.
365                                 cluster.SetChi2(-1.);   // Indicate no fit made.
366                                 muTrack.AddCluster(cluster);
367                                 nHits++;
368                                 muTrack.AddInMuonClusterMap(i+6);
369                         }
370                         
371                         // Find the corresponding trigger record.
372                         const AliHLTMUONTriggerRecordStruct* trigrec = NULL;
373                         for (size_t k = 0; k < triggerRecords.size(); k++)
374                         {
375                                 if (triggerRecords[k]->fId == t.fTrigRec)
376                                 {
377                                         trigrec = triggerRecords[k];
378                                         break;
379                                 }
380                         }
381                         // If the trigger record was found then fill its hit information also.
382                         if (trigrec != NULL)
383                         {
384                                 AliHLTMUONParticleSign trsign;
385                                 bool trhitset[4];
386                                 AliHLTMUONUtils::UnpackTriggerRecordFlags(
387                                                 trigrec->fFlags, trsign, trhitset
388                                         );
389                                 
390                                 for (int i = 0; i < 4; i++)
391                                 {
392                                         if (not trhitset[i]) continue;
393                                         
394                                         AliHLTUInt8_t chamber;
395                                         AliHLTUInt16_t detElemId;
396                                         AliHLTMUONUtils::UnpackRecHitFlags(trigrec->fHit[i].fFlags, chamber, detElemId);
397                                 
398                                         AliESDMuonCluster cluster;
399                                         cluster.SetUniqueID(AliMUONVCluster::BuildUniqueID(chamber, detElemId, clusterIndex++));
400                                         cluster.SetXYZ(
401                                                         trigrec->fHit[i].fX,
402                                                         trigrec->fHit[i].fY,
403                                                         trigrec->fHit[i].fZ
404                                                 );
405                                         cluster.SetErrXY(    // Use nominal values.
406                                                         AliMUONConstants::TriggerNonBendingReso(),
407                                                         AliMUONConstants::TriggerBendingReso()
408                                                 );
409                                         cluster.SetCharge(-1.);   // Indicate no total charge calculated.
410                                         cluster.SetChi2(-1.);   // Indicate no fit made.
411                                         muTrack.AddCluster(cluster);
412                                         nHits++;
413                                         muTrack.AddInMuonClusterMap(i+10);
414                                 }
415                         }
416                         else
417                         {
418                                 HLTWarning("Trigger record (ID = %d) not found for track ID = %d.",
419                                         t.fTrigRec, t.fId
420                                 );
421                         }
422                         
423                         muTrack.SetNHit(nHits);
424                         event.AddMuonTrack(&muTrack);
425                 }
426         }
427         
428         PushBack(&event, AliHLTMUONConstants::ESDDataType(), specification);
429         
430         return 0;
431 }
432