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 "AliHLTKalmanTrack.h"
47 #include "AliHLTTrackMCLabel.h"
51 /** ROOT macro for the implementation of ROOT specific class methods */
52 ClassImp(AliHLTTPCEsdWriterComponent)
54 AliHLTTPCEsdWriterComponent::AliHLTTPCEsdWriterComponent()
58 // see header file for class documentation
60 // refer to README to build package
62 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
65 AliHLTTPCEsdWriterComponent::~AliHLTTPCEsdWriterComponent()
67 // see header file for class documentation
70 AliHLTTPCEsdWriterComponent::AliWriter::AliWriter()
74 fBase(new AliHLTTPCEsdWriterComponent)
76 // see header file for class documentation
78 // refer to README to build package
80 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
83 AliHLTTPCEsdWriterComponent::AliWriter::~AliWriter()
85 // see header file for class documentation
86 if (fBase) delete fBase;
90 void AliHLTTPCEsdWriterComponent::AliWriter::GetInputDataTypes(AliHLTComponentDataTypeList& list)
92 // see header file for class documentation
93 list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
94 list.push_back(AliHLTTPCDefinitions::fgkTracksDataType);
95 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
98 int AliHLTTPCEsdWriterComponent::AliWriter::InitWriter()
100 // see header file for class documentation
102 fESD = new AliESDEvent;
104 fESD->CreateStdContent();
105 fTree = new TTree("esdTree", "Tree with HLT ESD objects");
107 fTree->SetDirectory(0);
108 fESD->WriteToTree(fTree);
116 iResult=fBase->Reconfigure(NULL, NULL);
122 int AliHLTTPCEsdWriterComponent::AliWriter::CloseWriter()
124 // see header file for class documentation
127 // the esd structure is written to the user info and is
128 // needed in te ReadFromTree method to read all objects correctly
129 if (fESD) fTree->GetUserInfo()->Add(fESD);
130 WriteObject(kAliHLTVoidEventID, fTree);
131 fTree->GetUserInfo()->Clear();
136 HLTWarning("not initialized");
142 iResult=AliHLTRootFileWriterComponent::CloseWriter();
146 int AliHLTTPCEsdWriterComponent::AliWriter::DumpEvent( const AliHLTComponentEventData& evtData,
147 const AliHLTComponentBlockData* blocks,
148 AliHLTComponentTriggerData& /*trigData*/ )
150 // see header file for class documentation
154 if (pTree && fBase) {
156 AliESDEvent* pESD=fESD;
158 iResult=fBase->ProcessBlocks(pTree, pESD, blocks, (int)evtData.fBlockCnt);
167 int AliHLTTPCEsdWriterComponent::AliWriter::ScanArgument(int argc, const char** argv)
169 // see header file for class documentation
170 int iResult=AliHLTRootFileWriterComponent::ScanArgument(argc, argv);
174 int AliHLTTPCEsdWriterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD,
175 const AliHLTComponentBlockData* blocks,
176 int nBlocks, int* pMinSlice,
179 // see header file for class documentation
182 int iAddedDataBlocks=0;
184 if (pESD && blocks) {
186 pESD->SetMagneticField(fSolenoidBz);
187 const AliHLTComponentBlockData* iter = NULL;
190 // first read MC information (if present)
192 std::map<int,int> mcLabels;
194 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
196 if(iter->fDataType == (kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC) ) {
197 AliHLTTrackMCData* dataPtr = ( AliHLTTrackMCData* )( iter->fPtr );
198 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
199 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
200 mcLabels[lab.fTrackID] = lab.fMCLabel;
206 // do the conversion of tracks
208 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
211 if( iter->fDataType == ( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ) ){
212 AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) iter->fPtr;
213 int nTracks = dataPtr->fCount;
214 AliHLTExternalTrackParam* currOutTrack = dataPtr->fTracklets;
216 for( int itr=0; itr<nTracks; itr++ ){
217 AliHLTKalmanTrack t(*currOutTrack);
218 Float_t points[4] = {currOutTrack->fX, currOutTrack->fY, currOutTrack->fLastX, currOutTrack->fLastY };
221 if( mcLabels.find(currOutTrack->fTrackID)!=mcLabels.end() )
222 mcLabel = mcLabels[currOutTrack->fTrackID];
224 t.SetLabel( mcLabel );
227 iotrack.UpdateTrackParams( &t,AliESDtrack::kTPCin);
228 iotrack.SetTPCPoints(points);
229 pESD->AddTrack(&iotrack);
230 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currOutTrack->fNPoints * sizeof( unsigned int );
231 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
237 if ( (bIsTrackSegs=(iter->fDataType == AliHLTTPCDefinitions::fgkTrackSegmentsDataType))==1 ||
238 iter->fDataType == AliHLTTPCDefinitions::fgkTracksDataType ) {
239 Int_t minslice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
240 Int_t maxslice=AliHLTTPCDefinitions::GetMaxSliceNr(iter->fSpecification);
241 if (bIsTrackSegs==0) {
242 // slice parameter and data specification ignored, tracks already in global coordinates
245 if (pMinSlice) *pMinSlice=0;
246 if (pMaxSlice) *pMaxSlice=AliHLTTPCTransform::GetNSlice()-1;
248 if (pMinSlice && (*pMinSlice==-1 || *pMinSlice>minslice)) *pMinSlice=minslice;
249 if (pMaxSlice && (*pMaxSlice==-1 || *pMaxSlice<maxslice)) *pMaxSlice=maxslice;
251 //HLTDebug("dataspec %#x minslice %d", iter->fSpecification, minslice);
252 if (minslice >=-1 && minslice<AliHLTTPCTransform::GetNSlice()) {
253 if (minslice!=maxslice) {
254 HLTWarning("data from multiple sectors in one block: "
255 "possible mismatch in treatment of local coordinate system");
257 AliHLTTPCTrackArray tracks;
258 AliHLTTPCTrackletData* inPtr = (AliHLTTPCTrackletData*) iter->fPtr;
259 HLTDebug("reading block %d (slice %d): %d tracklets", ndx, minslice, inPtr->fTrackletCnt);
260 if ((iResult=tracks.FillTracksChecked(inPtr->fTracklets, inPtr->fTrackletCnt, iter->fSize, minslice, 0/*don't rotate*/))>=0) {
261 if ((iResult=Tracks2ESD(&tracks, pESD ))>=0) {
266 HLTError("invalid sector number");
272 if (iAddedDataBlocks>0 && pTree) {
279 if (iResult>=0) iResult=iAddedDataBlocks;
284 int AliHLTTPCEsdWriterComponent::Tracks2ESD(AliHLTTPCTrackArray* pTracks, AliESDEvent* pESD )
286 // see header file for class documentation
289 if (pTracks && pESD) {
291 for (int i=0; i<pTracks->GetNTracks() && iResult>=0; i++) {
292 AliHLTTPCTrack* pTrack=(*pTracks)[i];
295 if( pTrack->Convert2AliKalmanTrack() ){
296 HLTError("conversion to AliKalmanTrack failed for track %d of %d", i, pTracks->GetNTracks());
300 Float_t points[4] = {pTrack->GetFirstPointX(), pTrack->GetFirstPointY(), pTrack->GetLastPointX(), pTrack->GetLastPointY() };
302 if(pTrack->GetSector() == -1){ // Set first and last points for global tracks
303 Double_t s = TMath::Sin( pTrack->GetAlpha() );
304 Double_t c = TMath::Cos( pTrack->GetAlpha() );
305 points[0] = pTrack->GetFirstPointX()*c + pTrack->GetFirstPointY()*s;
306 points[1] = -pTrack->GetFirstPointX()*s + pTrack->GetFirstPointY()*c;
307 points[2] = pTrack->GetLastPointX() *c + pTrack->GetLastPointY() *s;
308 points[3] = -pTrack->GetLastPointX() *s + pTrack->GetLastPointY() *c;
312 iotrack.UpdateTrackParams(pTrack,AliESDtrack::kTPCin);
313 iotrack.SetTPCPoints(points);
315 pESD->AddTrack(&iotrack);
317 HLTError("internal mismatch in array");
328 int AliHLTTPCEsdWriterComponent::Configure(const char* arguments)
330 // see header file for class documentation
332 if (!arguments) return iResult;
334 TString allArgs=arguments;
338 TObjArray* pTokens=allArgs.Tokenize(" ");
340 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
341 argument=((TObjString*)pTokens->At(i))->GetString();
342 if (argument.IsNull()) continue;
344 if (argument.CompareTo("-solenoidBz")==0) {
345 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
346 HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
347 fSolenoidBz=((TObjString*)pTokens->At(i))->GetString().Atof();
350 HLTError("unknown argument %s", argument.Data());
358 HLTError("missing parameter for argument %s", argument.Data());
365 int AliHLTTPCEsdWriterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
367 // see header file for class documentation
369 const char* path=kAliHLTCDBSolenoidBz;
370 const char* defaultNotify="";
373 defaultNotify=" (default)";
376 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
377 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
379 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
381 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
382 iResult=Configure(pString->GetString().Data());
384 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
387 HLTError("can not fetch object \"%s\" from CDB", path);
394 AliHLTTPCEsdWriterComponent::AliConverter::AliConverter()
397 fBase(new AliHLTTPCEsdWriterComponent),
400 // see header file for class documentation
402 // refer to README to build package
404 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
407 AliHLTTPCEsdWriterComponent::AliConverter::~AliConverter()
409 // see header file for class documentation
410 if (fBase) delete fBase;
413 if (fESD) delete fESD;
417 void AliHLTTPCEsdWriterComponent::AliConverter::GetInputDataTypes(AliHLTComponentDataTypeList& list)
419 // see header file for class documentation
420 list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
421 list.push_back(AliHLTTPCDefinitions::fgkTracksDataType);
422 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
425 AliHLTComponentDataType AliHLTTPCEsdWriterComponent::AliConverter::GetOutputDataType()
427 // see header file for class documentation
428 return kAliHLTDataTypeESDTree;
431 void AliHLTTPCEsdWriterComponent::AliConverter::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
433 // see header file for class documentation
435 inputMultiplier=10.0;
438 int AliHLTTPCEsdWriterComponent::AliConverter::DoInit(int argc, const char** argv)
440 // see header file for class documentation
444 for (int i=0; i<argc && iResult>=0; i++) {
446 if (argument.IsNull()) continue;
449 if (argument.CompareTo("-notree")==0) {
453 } else if (argument.CompareTo("-tree")==0) {
457 } else if (argument.CompareTo("-solenoidBz")==0) {
458 TString tmp="-solenoidBz ";
460 fBase->Configure(tmp.Data());
462 HLTError("unknown argument %s", argument.Data());
467 HLTError("missing parameter for argument %s", argument.Data());
472 iResult=fBase->Reconfigure(NULL, NULL);
478 int AliHLTTPCEsdWriterComponent::AliConverter::DoDeinit()
480 // see header file for class documentation
484 int AliHLTTPCEsdWriterComponent::AliConverter::DoEvent(const AliHLTComponentEventData& evtData,
485 const AliHLTComponentBlockData* blocks,
486 AliHLTComponentTriggerData& /*trigData*/,
487 AliHLTUInt8_t* /*outputPtr*/,
488 AliHLTUInt32_t& size,
489 AliHLTComponentBlockDataList& /*outputBlocks*/ )
491 // see header file for class documentation
493 // no direct writing to the output buffer
498 fESD = new AliESDEvent;
500 fESD->CreateStdContent();
506 AliESDEvent* pESD = fESD;
511 // TODO: Matthias 06.12.2007
512 // Tried to write the ESD directly instead to a tree, but this did not work
513 // out. Information in the ESD is different, needs investigation.
516 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
519 pTree->SetDirectory(0);
522 if ((iResult=fBase->ProcessBlocks(pTree, pESD, blocks, (int)evtData.fBlockCnt))>0) {
523 // TODO: set the specification correctly
525 // the esd structure is written to the user info and is
526 // needed in te ReadFromTree method to read all objects correctly
527 pTree->GetUserInfo()->Add(pESD);
528 pESD->WriteToTree(pTree);
529 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginTPC, 0);
531 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC, 0);
535 // clear user info list to prevent objects from being deleted
536 pTree->GetUserInfo()->Clear();