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
254 HLTDebug("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
255 DataType2Text(block->fDataType).c_str(), block->fSpecification
261 // If we were requested to add all dHLT rootified data objects then do so.
264 const AliHLTComponentDataType& type = AliHLTMUONConstants::RootifiedEventDataType();
265 const char* classname = AliHLTMUONEvent::Class_Name();
266 const TObject* obj = NULL;
267 for (obj = GetFirstInputObject(type, classname); obj != NULL; obj = GetNextInputObject())
269 // Clone the object since the ESD takes ownership of it.
270 event.AddObject(obj->Clone());
274 // Now we can look for tracks to add. We needed the ROOT trigger records
275 // and reco hits created before we can create track objects.
276 for (block = GetFirstInputBlock(AliHLTMUONConstants::MansoTracksBlockDataType());
278 block = GetNextInputBlock()
281 specification |= block->fSpecification;
282 AliHLTMUONMansoTracksBlockReader inblock(block->fPtr, block->fSize);
283 if (not BlockStructureOk(inblock))
285 if (DumpDataOnError()) DumpEvent(evtData, trigData);
289 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
291 const AliHLTMUONMansoTrackStruct& t = inblock[n];
292 AliESDMuonTrack muTrack;
294 AliHLTMUONParticleSign sign;
296 AliHLTMUONUtils::UnpackMansoTrackFlags(
297 t.fFlags, sign, hitset
303 case kSignMinus: signVal = +1.; break;
304 case kSignUnknown: signVal = 0.; break;
305 case kSignPlus: signVal = -1.; break;
307 HLTWarning("Got a track with an invalid sign value: %d", int(sign));
310 TVector3 mom(t.fPx, t.fPy, t.fPz);
312 muTrack.SetInverseBendingMomentum(signVal/mom.Mag());
314 muTrack.SetInverseBendingMomentum(0.);
315 muTrack.SetThetaX(atan2(t.fPx, t.fPz));
316 muTrack.SetThetaY(atan2(t.fPy, t.fPz));
318 muTrack.SetBendingCoor(0.);
319 muTrack.SetNonBendingCoor(0.);
321 // The Manso algorithm assumes the information at the
322 // Distance of Closest Approach and chamber 1 is the same
325 muTrack.SetInverseBendingMomentumAtDCA(1./mom.Mag());
327 muTrack.SetInverseBendingMomentumAtDCA(0.);
328 muTrack.SetThetaXAtDCA(atan2(t.fPx, t.fPz));
329 muTrack.SetThetaYAtDCA(atan2(t.fPy, t.fPz));
330 muTrack.SetBendingCoorAtDCA(0.);
331 muTrack.SetNonBendingCoorAtDCA(0.);
334 muTrack.SetInverseBendingMomentumUncorrected(1./mom.Mag());
336 muTrack.SetInverseBendingMomentumUncorrected(0.);
337 muTrack.SetThetaXUncorrected(atan2(t.fPx, t.fPz));
338 muTrack.SetThetaYUncorrected(atan2(t.fPy, t.fPz));
339 muTrack.SetZUncorrected(0.);
340 muTrack.SetBendingCoorUncorrected(0.);
341 muTrack.SetNonBendingCoorUncorrected(0.);
343 muTrack.SetChi2(t.fChi2);
345 // Fill in the track hit points.
347 for (int i = 0; i < 4; i++)
349 if (not hitset[i]) continue;
351 AliHLTUInt8_t chamber;
352 AliHLTUInt16_t detElemId;
353 AliHLTMUONUtils::UnpackRecHitFlags(t.fHit[i].fFlags, chamber, detElemId);
355 AliESDMuonCluster cluster;
356 cluster.SetUniqueID(AliMUONVCluster::BuildUniqueID(chamber, detElemId, clusterIndex++));
357 cluster.SetXYZ(t.fHit[i].fX, t.fHit[i].fY, t.fHit[i].fZ);
358 cluster.SetErrXY( // Use nominal values.
359 AliHLTMUONConstants::DefaultBendingReso(),
360 AliHLTMUONConstants::DefaultNonBendingReso()
362 cluster.SetCharge(-1.); // Indicate no total charge calculated.
363 cluster.SetChi2(-1.); // Indicate no fit made.
364 muTrack.AddCluster(cluster);
366 muTrack.AddInMuonClusterMap(i+6);
369 // Find the corresponding trigger record.
370 const AliHLTMUONTriggerRecordStruct* trigrec = NULL;
371 for (size_t k = 0; k < triggerRecords.size(); k++)
373 if (triggerRecords[k]->fId == t.fTrigRec)
375 trigrec = triggerRecords[k];
379 // If the trigger record was found then fill its hit information also.
382 AliHLTMUONParticleSign trsign;
384 AliHLTMUONUtils::UnpackTriggerRecordFlags(
385 trigrec->fFlags, trsign, trhitset
388 for (int i = 0; i < 4; i++)
390 if (not trhitset[i]) continue;
392 AliHLTUInt8_t chamber;
393 AliHLTUInt16_t detElemId;
394 AliHLTMUONUtils::UnpackRecHitFlags(trigrec->fHit[i].fFlags, chamber, detElemId);
396 AliESDMuonCluster cluster;
397 cluster.SetUniqueID(AliMUONVCluster::BuildUniqueID(chamber, detElemId, clusterIndex++));
403 cluster.SetErrXY( // Use nominal values.
404 AliMUONConstants::TriggerNonBendingReso(),
405 AliMUONConstants::TriggerBendingReso()
407 cluster.SetCharge(-1.); // Indicate no total charge calculated.
408 cluster.SetChi2(-1.); // Indicate no fit made.
409 muTrack.AddCluster(cluster);
411 muTrack.AddInMuonClusterMap(i+10);
416 HLTWarning("Trigger record (ID = %d) not found for track ID = %d.",
421 muTrack.SetNHit(nHits);
422 event.AddMuonTrack(&muTrack);
426 PushBack(&event, AliHLTMUONConstants::ESDDataType(), specification);