3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* for The ALICE HLT Project. *
10 //* Permission to use, copy, modify and distribute this software and its *
11 //* documentation strictly for non-commercial purposes is hereby granted *
12 //* without fee, provided that the above copyright notice appears in all *
13 //* copies and that both the copyright notice and this permission notice *
14 //* appear in the supporting documentation. The authors make no claims *
15 //* about the suitability of this software for any purpose. It is *
16 //* provided "as is" without express or implied warranty. *
17 //**************************************************************************
19 /** @file AliHLTTPCEsdWriterComponent.cxx
20 @author Matthias Richter
22 @brief Writer component to store tracks of the HLT TPC conformal
23 mapping tracker in the AliESD format
26 // see header file for class documentation
28 // refer to README to build package
30 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
33 #include "AliHLTTPCEsdWriterComponent.h"
34 #include "AliESDEvent.h"
35 #include "AliESDtrack.h"
36 #include "AliCDBEntry.h"
37 #include "AliCDBManager.h"
40 #include "AliHLTTPCTrack.h"
41 #include "AliHLTTPCTrackArray.h"
42 #include "AliHLTTPCTrackletDataFormat.h"
43 #include "AliHLTTPCDefinitions.h"
44 #include "AliHLTTPCTransform.h"
45 #include "AliHLTExternalTrackParam.h"
46 #include "AliHLTGlobalBarrelTrack.h"
47 #include "AliHLTTrackMCLabel.h"
48 #include "TGeoGlobalMagField.h"
52 /** ROOT macro for the implementation of ROOT specific class methods */
53 ClassImp(AliHLTTPCEsdWriterComponent)
55 AliHLTTPCEsdWriterComponent::AliHLTTPCEsdWriterComponent()
59 // see header file for class documentation
61 // refer to README to build package
63 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
66 AliHLTTPCEsdWriterComponent::~AliHLTTPCEsdWriterComponent()
68 // see header file for class documentation
71 AliHLTTPCEsdWriterComponent::AliWriter::AliWriter()
75 fBase(new AliHLTTPCEsdWriterComponent)
77 // see header file for class documentation
79 // refer to README to build package
81 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
84 AliHLTTPCEsdWriterComponent::AliWriter::~AliWriter()
86 // see header file for class documentation
87 if (fBase) delete fBase;
91 void AliHLTTPCEsdWriterComponent::AliWriter::GetInputDataTypes(AliHLTComponentDataTypeList& list)
93 // see header file for class documentation
94 list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
95 list.push_back(AliHLTTPCDefinitions::fgkTracksDataType);
96 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
99 int AliHLTTPCEsdWriterComponent::AliWriter::InitWriter()
101 // see header file for class documentation
103 fESD = new AliESDEvent;
105 fESD->CreateStdContent();
106 fTree = new TTree("esdTree", "Tree with HLT ESD objects");
108 fTree->SetDirectory(0);
109 fESD->WriteToTree(fTree);
117 iResult=fBase->Reconfigure(NULL, NULL);
123 int AliHLTTPCEsdWriterComponent::AliWriter::CloseWriter()
125 // see header file for class documentation
128 // the esd structure is written to the user info and is
129 // needed in te ReadFromTree method to read all objects correctly
130 if (fESD) fTree->GetUserInfo()->Add(fESD);
131 WriteObject(kAliHLTVoidEventID, fTree);
132 fTree->GetUserInfo()->Clear();
137 HLTWarning("not initialized");
143 iResult=AliHLTRootFileWriterComponent::CloseWriter();
147 int AliHLTTPCEsdWriterComponent::AliWriter::DumpEvent( const AliHLTComponentEventData& evtData,
148 const AliHLTComponentBlockData* blocks,
149 AliHLTComponentTriggerData& /*trigData*/ )
151 // see header file for class documentation
155 if (pTree && fBase) {
157 AliESDEvent* pESD=fESD;
160 pESD->SetMagneticField(GetBz());
161 iResult=fBase->ProcessBlocks(pTree, pESD, blocks, (int)evtData.fBlockCnt);
170 int AliHLTTPCEsdWriterComponent::AliWriter::ScanArgument(int argc, const char** argv)
172 // see header file for class documentation
173 int iResult=AliHLTRootFileWriterComponent::ScanArgument(argc, argv);
177 int AliHLTTPCEsdWriterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD,
178 const AliHLTComponentBlockData* blocks,
179 int nBlocks, int* pMinSlice,
182 // see header file for class documentation
185 int iAddedDataBlocks=0;
187 if (pESD && blocks) {
188 const AliHLTComponentBlockData* iter = NULL;
191 // first read MC information (if present)
193 std::map<int,int> mcLabels;
195 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
197 if(iter->fDataType == (kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC) ) {
198 AliHLTTrackMCData* dataPtr = ( AliHLTTrackMCData* )( iter->fPtr );
199 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
200 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
201 mcLabels[lab.fTrackID] = lab.fMCLabel;
207 // do the conversion of tracks
209 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
212 if( iter->fDataType == ( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ) ){
213 AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) iter->fPtr;
214 int nTracks = dataPtr->fCount;
215 AliHLTExternalTrackParam* currOutTrack = dataPtr->fTracklets;
217 for( int itr=0; itr<nTracks; itr++ ){
218 AliHLTGlobalBarrelTrack t(*currOutTrack);
219 Float_t points[4] = {currOutTrack->fX, currOutTrack->fY, currOutTrack->fLastX, currOutTrack->fLastY };
222 if( mcLabels.find(currOutTrack->fTrackID)!=mcLabels.end() )
223 mcLabel = mcLabels[currOutTrack->fTrackID];
225 t.SetLabel( mcLabel );
228 iotrack.UpdateTrackParams( &t,AliESDtrack::kTPCin);
229 iotrack.SetTPCPoints(points);
230 pESD->AddTrack(&iotrack);
231 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currOutTrack->fNPoints * sizeof( unsigned int );
232 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
238 if ( (bIsTrackSegs=(iter->fDataType == AliHLTTPCDefinitions::fgkTrackSegmentsDataType))==1 ||
239 iter->fDataType == AliHLTTPCDefinitions::fgkTracksDataType ) {
240 Int_t minslice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
241 Int_t maxslice=AliHLTTPCDefinitions::GetMaxSliceNr(iter->fSpecification);
242 if (bIsTrackSegs==0) {
243 // slice parameter and data specification ignored, tracks already in global coordinates
246 if (pMinSlice) *pMinSlice=0;
247 if (pMaxSlice) *pMaxSlice=AliHLTTPCTransform::GetNSlice()-1;
249 if (pMinSlice && (*pMinSlice==-1 || *pMinSlice>minslice)) *pMinSlice=minslice;
250 if (pMaxSlice && (*pMaxSlice==-1 || *pMaxSlice<maxslice)) *pMaxSlice=maxslice;
252 //HLTDebug("dataspec %#x minslice %d", iter->fSpecification, minslice);
253 if (minslice >=-1 && minslice<AliHLTTPCTransform::GetNSlice()) {
254 if (minslice!=maxslice) {
255 HLTWarning("data from multiple sectors in one block: "
256 "possible mismatch in treatment of local coordinate system");
258 AliHLTTPCTrackArray tracks;
259 AliHLTTPCTrackletData* inPtr = (AliHLTTPCTrackletData*) iter->fPtr;
260 HLTDebug("reading block %d (slice %d): %d tracklets", ndx, minslice, inPtr->fTrackletCnt);
261 if ((iResult=tracks.FillTracksChecked(inPtr->fTracklets, inPtr->fTrackletCnt, iter->fSize, minslice, 0/*don't rotate*/))>=0) {
262 if ((iResult=Tracks2ESD(&tracks, pESD ))>=0) {
267 HLTError("invalid sector number");
273 if (iAddedDataBlocks>0 && pTree) {
280 if (iResult>=0) iResult=iAddedDataBlocks;
285 int AliHLTTPCEsdWriterComponent::Tracks2ESD(AliHLTTPCTrackArray* pTracks, AliESDEvent* pESD )
287 // see header file for class documentation
290 if (pTracks && pESD) {
292 for (int i=0; i<pTracks->GetNTracks() && iResult>=0; i++) {
293 AliHLTTPCTrack* pTrack=(*pTracks)[i];
296 if( pTrack->Convert2AliKalmanTrack() ){
297 HLTError("conversion to AliKalmanTrack failed for track %d of %d", i, pTracks->GetNTracks());
301 Float_t points[4] = {pTrack->GetFirstPointX(), pTrack->GetFirstPointY(), pTrack->GetLastPointX(), pTrack->GetLastPointY() };
303 if(pTrack->GetSector() == -1){ // Set first and last points for global tracks
304 Double_t s = TMath::Sin( pTrack->GetAlpha() );
305 Double_t c = TMath::Cos( pTrack->GetAlpha() );
306 points[0] = pTrack->GetFirstPointX()*c + pTrack->GetFirstPointY()*s;
307 points[1] = -pTrack->GetFirstPointX()*s + pTrack->GetFirstPointY()*c;
308 points[2] = pTrack->GetLastPointX() *c + pTrack->GetLastPointY() *s;
309 points[3] = -pTrack->GetLastPointX() *s + pTrack->GetLastPointY() *c;
313 iotrack.UpdateTrackParams(pTrack,AliESDtrack::kTPCin);
314 iotrack.SetTPCPoints(points);
316 pESD->AddTrack(&iotrack);
318 HLTError("internal mismatch in array");
329 int AliHLTTPCEsdWriterComponent::Configure(const char* arguments)
331 // see header file for class documentation
333 if (!arguments) return iResult;
336 if (!TGeoGlobalMagField::Instance()) {
337 HLTError("magnetic field not initialized, please set up TGeoGlobalMagField and AliMagF");
341 TString allArgs=arguments;
345 TObjArray* pTokens=allArgs.Tokenize(" ");
347 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
348 argument=((TObjString*)pTokens->At(i))->GetString();
349 if (argument.IsNull()) continue;
351 if (argument.CompareTo("-solenoidBz")==0) {
352 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
353 HLTWarning("parameter -solenoidBz deprecated, magnetic field handled by global AliMagF object and TGeoGlobalMagField");
356 HLTError("unknown argument %s", argument.Data());
364 HLTError("missing parameter for argument %s", argument.Data());
371 int AliHLTTPCEsdWriterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
373 // see header file for class documentation
375 const char* path=NULL;
376 const char* defaultNotify="";
379 defaultNotify=" (default)";
382 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
383 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
385 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
387 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
388 iResult=Configure(pString->GetString().Data());
390 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
393 HLTError("can not fetch object \"%s\" from CDB", path);
400 AliHLTTPCEsdWriterComponent::AliConverter::AliConverter()
403 fBase(new AliHLTTPCEsdWriterComponent),
406 // see header file for class documentation
408 // refer to README to build package
410 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
413 AliHLTTPCEsdWriterComponent::AliConverter::~AliConverter()
415 // see header file for class documentation
416 if (fBase) delete fBase;
419 if (fESD) delete fESD;
423 void AliHLTTPCEsdWriterComponent::AliConverter::GetInputDataTypes(AliHLTComponentDataTypeList& list)
425 // see header file for class documentation
426 list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
427 list.push_back(AliHLTTPCDefinitions::fgkTracksDataType);
428 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
431 AliHLTComponentDataType AliHLTTPCEsdWriterComponent::AliConverter::GetOutputDataType()
433 // see header file for class documentation
434 return kAliHLTDataTypeESDTree;
437 void AliHLTTPCEsdWriterComponent::AliConverter::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
439 // see header file for class documentation
441 inputMultiplier=10.0;
444 int AliHLTTPCEsdWriterComponent::AliConverter::DoInit(int argc, const char** argv)
446 // see header file for class documentation
450 for (int i=0; i<argc && iResult>=0; i++) {
452 if (argument.IsNull()) continue;
455 if (argument.CompareTo("-notree")==0) {
459 } else if (argument.CompareTo("-tree")==0) {
463 } else if (argument.CompareTo("-solenoidBz")==0) {
464 HLTWarning("parameter -solenoidBz deprecated, magnetic field handled by global AliMagF object and TGeoGlobalMagField");
466 HLTError("unknown argument %s", argument.Data());
471 HLTError("missing parameter for argument %s", argument.Data());
476 iResult=fBase->Reconfigure(NULL, NULL);
482 int AliHLTTPCEsdWriterComponent::AliConverter::DoDeinit()
484 // see header file for class documentation
488 int AliHLTTPCEsdWriterComponent::AliConverter::DoEvent(const AliHLTComponentEventData& evtData,
489 const AliHLTComponentBlockData* blocks,
490 AliHLTComponentTriggerData& /*trigData*/,
491 AliHLTUInt8_t* /*outputPtr*/,
492 AliHLTUInt32_t& size,
493 AliHLTComponentBlockDataList& /*outputBlocks*/ )
495 // see header file for class documentation
497 // no direct writing to the output buffer
502 fESD = new AliESDEvent;
504 fESD->CreateStdContent();
510 AliESDEvent* pESD = fESD;
515 // TODO: Matthias 06.12.2007
516 // Tried to write the ESD directly instead to a tree, but this did not work
517 // out. Information in the ESD is different, needs investigation.
520 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
523 pTree->SetDirectory(0);
527 pESD->SetMagneticField(GetBz());
528 if ((iResult=fBase->ProcessBlocks(pTree, pESD, blocks, (int)evtData.fBlockCnt))>0) {
529 // TODO: set the specification correctly
531 // the esd structure is written to the user info and is
532 // needed in te ReadFromTree method to read all objects correctly
533 pTree->GetUserInfo()->Add(pESD);
534 pESD->WriteToTree(pTree);
535 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginTPC, 0);
537 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC, 0);
541 // clear user info list to prevent objects from being deleted
542 pTree->GetUserInfo()->Clear();