1 /**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
6 * Artur Szostak <artursz@iafrica.com> *
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 **************************************************************************/
20 /// @file AliHLTMUONESDMaker.cxx
21 /// @author Artur Szostak <artursz@iafrica.com>
22 /// @date 30 June 2008
23 /// @brief Implementation of the AliHLTMUONESDMaker component.
25 /// The ESD maker component converts dHLT raw internal reconstructed information
26 /// into AliESDEvent objects.
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"
48 ClassImp(AliHLTMUONESDMaker);
51 AliHLTMUONESDMaker::AliHLTMUONESDMaker() :
52 AliHLTMUONProcessor(),
53 fWarnForUnexpecedBlock(false),
54 fMakeMinimalESD(false),
57 /// Default constructor.
61 AliHLTMUONESDMaker::~AliHLTMUONESDMaker()
63 /// Default destructor.
67 bool AliHLTMUONESDMaker::IgnoreArgument(const char* arg) const
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.
72 if (strcmp(arg, "-cdbpath") == 0 or strcmp(arg, "-run") == 0 or
73 strcmp(arg, "-delaysetup") == 0)
84 int AliHLTMUONESDMaker::DoInit(int argc, const char** argv)
86 /// Inherited from AliHLTComponent.
87 /// Parses the command line parameters and initialises the component.
89 HLTInfo("Initialising dHLT ESD maker component.");
91 // Inherit the parents functionality.
92 int result = AliHLTMUONProcessor::DoInit(argc, argv);
93 if (result != 0) return result;
95 fWarnForUnexpecedBlock = false;
96 fMakeMinimalESD = false;
98 for (int i = 0; i < argc; i++)
100 if (ArgumentAlreadyHandled(i, argv[i])) continue;
102 if (strcmp(argv[i], "-make_minimal_esd") == 0)
104 fMakeMinimalESD = true;
108 if (strcmp(argv[i], "-warn_on_unexpected_block") == 0)
110 fWarnForUnexpecedBlock = true;
114 if (strcmp(argv[i], "-add_rootified_objects") == 0)
116 fAddCustomData = true;
120 HLTError("Unknown option '%s'.", argv[i]);
128 int AliHLTMUONESDMaker::DoDeinit()
130 /// Inherited from AliHLTComponent. Performs a cleanup of the component.
132 HLTInfo("Deinitialising dHLT ESD maker component.");
137 const char* AliHLTMUONESDMaker::GetComponentID()
139 /// Inherited from AliHLTComponent. Returns the component ID.
141 return AliHLTMUONConstants::ESDMakerId();
145 AliHLTComponentDataType AliHLTMUONESDMaker::GetOutputDataType()
147 /// Inherited from AliHLTComponent.
148 /// Returns the ESD object data type with MUON origin.
150 return AliHLTMUONConstants::ESDDataType();
154 void AliHLTMUONESDMaker::GetInputDataTypes(AliHLTComponentDataTypeList& list)
156 /// Inherited from AliHLTProcessor.
157 /// Returns the list of expected input data types.
159 list.push_back(AliHLTMUONConstants::TriggerRecordsBlockDataType());
160 list.push_back(AliHLTMUONConstants::MansoTracksBlockDataType());
164 void AliHLTMUONESDMaker::GetOutputDataSize(
165 unsigned long& constBase, double& inputMultiplier
168 /// Inherited from AliHLTComponent.
169 /// Returns an estimate of the expected output data size.
171 constBase = sizeof(AliESDEvent) + 1024*1024; // The extra 1 MByte is for auxilary objects created in AliESDEvent.
172 inputMultiplier = 10;
176 AliHLTComponent* AliHLTMUONESDMaker::Spawn()
178 /// Inherited from AliHLTComponent. Creates a new object instance.
180 return new AliHLTMUONESDMaker();
184 int AliHLTMUONESDMaker::DoEvent(
185 const AliHLTComponentEventData& evtData,
186 AliHLTComponentTriggerData& trigData
189 /// Inherited from AliHLTProcessor. Processes the new event data.
192 AliHLTUInt32_t clusterIndex = 0; // for the cluster unique ID.
194 // Create and fill in the standard ESD objects or just create the muon
195 // tracks array if so requested.
198 TClonesArray* muonTracks = new TClonesArray("AliESDMuonTrack",0);
199 muonTracks->SetName("MuonTracks");
200 event.AddObject(muonTracks);
201 event.GetStdContent();
205 event.CreateStdContent();
206 event.SetRunNumber(GetRunNo());
209 const AliHLTComponentBlockData* block = NULL;
210 AliHLTUInt32_t specification = 0; // Contains the output data block spec bits.
211 std::vector<const AliHLTMUONTriggerRecordStruct*> triggerRecords;
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++)
217 block = GetInputBlock(i);
218 assert( block != NULL );
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
224 if (block->fDataType == AliHLTMUONConstants::TriggerRecordsBlockDataType())
226 specification |= block->fSpecification;
227 AliHLTMUONTriggerRecordsBlockReader inblock(block->fPtr, block->fSize);
228 if (not BlockStructureOk(inblock))
230 if (DumpDataOnError()) DumpEvent(evtData, trigData);
234 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
236 triggerRecords.push_back(&inblock[n]);
239 else if (block->fDataType == AliHLTMUONConstants::RootifiedEventDataType() and fAddCustomData)
241 // Do nothing for now, will handle this later.
245 if (block->fDataType != AliHLTMUONConstants::MansoTracksBlockDataType())
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
255 HLTDebug("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
256 DataType2Text(block->fDataType).c_str(), block->fSpecification
263 // If we were requested to add all dHLT rootified data objects then do so.
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())
271 // Clone the object since the ESD takes ownership of it.
272 event.AddObject(obj->Clone());
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());
280 block = GetNextInputBlock()
283 specification |= block->fSpecification;
284 AliHLTMUONMansoTracksBlockReader inblock(block->fPtr, block->fSize);
285 if (not BlockStructureOk(inblock))
287 if (DumpDataOnError()) DumpEvent(evtData, trigData);
291 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
293 const AliHLTMUONMansoTrackStruct& t = inblock[n];
294 AliESDMuonTrack muTrack;
296 AliHLTMUONParticleSign sign;
298 AliHLTMUONUtils::UnpackMansoTrackFlags(
299 t.fFlags, sign, hitset
305 case kSignMinus: signVal = +1.; break;
306 case kSignUnknown: signVal = 0.; break;
307 case kSignPlus: signVal = -1.; break;
309 HLTWarning("Got a track with an invalid sign value: %d", int(sign));
312 TVector3 mom(t.fPx, t.fPy, t.fPz);
314 muTrack.SetInverseBendingMomentum(signVal/mom.Mag());
316 muTrack.SetInverseBendingMomentum(0.);
317 muTrack.SetThetaX(atan2(t.fPx, t.fPz));
318 muTrack.SetThetaY(atan2(t.fPy, t.fPz));
320 muTrack.SetBendingCoor(0.);
321 muTrack.SetNonBendingCoor(0.);
323 // The Manso algorithm assumes the information at the
324 // Distance of Closest Approach and chamber 1 is the same
327 muTrack.SetInverseBendingMomentumAtDCA(1./mom.Mag());
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.);
336 muTrack.SetInverseBendingMomentumUncorrected(1./mom.Mag());
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.);
345 muTrack.SetChi2(t.fChi2);
347 // Fill in the track hit points.
349 for (int i = 0; i < 4; i++)
351 if (not hitset[i]) continue;
353 AliHLTUInt8_t chamber;
354 AliHLTUInt16_t detElemId;
355 AliHLTMUONUtils::UnpackRecHitFlags(t.fHit[i].fFlags, chamber, detElemId);
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()
364 cluster.SetCharge(-1.); // Indicate no total charge calculated.
365 cluster.SetChi2(-1.); // Indicate no fit made.
366 muTrack.AddCluster(cluster);
368 muTrack.AddInMuonClusterMap(i+6);
371 // Find the corresponding trigger record.
372 const AliHLTMUONTriggerRecordStruct* trigrec = NULL;
373 for (size_t k = 0; k < triggerRecords.size(); k++)
375 if (triggerRecords[k]->fId == t.fTrigRec)
377 trigrec = triggerRecords[k];
381 // If the trigger record was found then fill its hit information also.
384 AliHLTMUONParticleSign trsign;
386 AliHLTMUONUtils::UnpackTriggerRecordFlags(
387 trigrec->fFlags, trsign, trhitset
390 for (int i = 0; i < 4; i++)
392 if (not trhitset[i]) continue;
394 AliHLTUInt8_t chamber;
395 AliHLTUInt16_t detElemId;
396 AliHLTMUONUtils::UnpackRecHitFlags(trigrec->fHit[i].fFlags, chamber, detElemId);
398 AliESDMuonCluster cluster;
399 cluster.SetUniqueID(AliMUONVCluster::BuildUniqueID(chamber, detElemId, clusterIndex++));
405 cluster.SetErrXY( // Use nominal values.
406 AliMUONConstants::TriggerNonBendingReso(),
407 AliMUONConstants::TriggerBendingReso()
409 cluster.SetCharge(-1.); // Indicate no total charge calculated.
410 cluster.SetChi2(-1.); // Indicate no fit made.
411 muTrack.AddCluster(cluster);
413 muTrack.AddInMuonClusterMap(i+10);
418 HLTWarning("Trigger record (ID = %d) not found for track ID = %d.",
423 muTrack.SetNHit(nHits);
424 event.AddMuonTrack(&muTrack);
428 PushBack(&event, AliHLTMUONConstants::ESDDataType(), specification);