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: Kalliopi Kanaki <Kalliopi.Kanaki@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 AliHLTTPCCalibTracksComponent.cxx
20 @author Kalliopi Kanaki
22 @brief A calibration component for the TPC.
25 // see header file for class documentation
27 // refer to README to build package
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
35 #include "AliHLTTPCCalibTracksComponent.h"
37 #include "AliHLTTPCLogging.h"
38 #include "AliHLTTPCTransform.h"
39 #include "AliHLTTPCClusterDataFormat.h"
40 #include "AliHLTTPCTrackletDataFormat.h"
41 #include "AliHLTTPCOfflineCluster.h"
43 #include "AliTPCcalibDB.h"
44 #include "AliTPCClusterParam.h"
45 #include "AliTPCcalibTracksCuts.h"
46 #include "AliTPCcalibTracksGain.h"
47 #include "AliTPCcalibTracks.h"
48 #include "AliTPCcalibAlign.h"
50 #include "AliTPCclusterMI.h"
51 #include "AliTPCseed.h"
53 #include "AliCDBEntry.h"
54 #include "AliCDBManager.h"
60 //AliHLTTPCCalibTracksComponent gAliHLTTPCCalibTracksComponent;
62 /** ROOT macro for the implementation of ROOT specific class methods */
63 ClassImp(AliHLTTPCCalibTracksComponent)
65 AliHLTTPCCalibTracksComponent::AliHLTTPCCalibTracksComponent()
69 fCalibTracksGain(NULL),
75 fEnableAnalysis(kFALSE),
84 // see header file for class documentation
86 // refer to README to build package
88 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
91 AliHLTTPCCalibTracksComponent::~AliHLTTPCCalibTracksComponent(){
92 // see header file for class documentation
95 const char* AliHLTTPCCalibTracksComponent::GetComponentID(){
96 // see header file for class documentation
97 return "TPCCalibTracks";
100 void AliHLTTPCCalibTracksComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list){
101 // see header file for class documentation
104 list.push_back(AliHLTTPCDefinitions::fgkClustersDataType);
105 list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
106 list.push_back(AliHLTTPCDefinitions::fgkTracksDataType);
109 AliHLTComponentDataType AliHLTTPCCalibTracksComponent::GetOutputDataType(){
110 // see header file for class documentation
112 return kAliHLTMultipleDataType;
115 int AliHLTTPCCalibTracksComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList){
116 // create output data type
119 tgtList.push_back(AliHLTTPCDefinitions::fgkOfflineCalibAlignDataType);
120 tgtList.push_back(AliHLTTPCDefinitions::fgkOfflineCalibTracksDataType);
121 tgtList.push_back(AliHLTTPCDefinitions::fgkOfflineCalibTracksGainDataType);
123 return tgtList.size();
126 void AliHLTTPCCalibTracksComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier){
127 // see header file for class documentation
129 constBase = 30000000;
133 AliHLTComponent* AliHLTTPCCalibTracksComponent::Spawn(){
134 // see header file for class documentation
136 return new AliHLTTPCCalibTracksComponent();
140 Int_t AliHLTTPCCalibTracksComponent::ScanArgument(Int_t argc, const char** argv){
141 // see header file for class documentation
144 TString argument = "";
145 TString parameter = "";
147 if(!argc) return -EINVAL;
148 argument = argv[iResult];
150 if(argument.IsNull()) return -EINVAL;
153 // if ( argument.CompareTo("-rcuformat") == 0 ) {
155 // if ( ++iResult >= argc ) {
156 // iResult = -EPROTO;
159 // parameter = argv[1];
160 // if ( parameter.CompareTo("old") == 0 ) {
161 // HLTInfo( "RCU Format is set to old." );
163 // else if ( parameter.CompareTo("new") == 0 ) {
164 // HLTInfo( "RCU Format is set to new." );
167 // HLTError( "Cannot convert rcu format specifier '%s'.", argv[1] );
168 // iResult = -EPROTO;
174 if(argument.CompareTo("-enable-analysis") == 0) {
176 HLTInfo( "Enable analysis before shipping data to FXS." );
177 fEnableAnalysis = kTRUE;
178 //cout << "fEnableAnalysis: " << fEnableAnalysis << endl;
180 else if(argument.CompareTo("-read-slice-tracks") == 0){
181 HLTInfo( "Reading slice tracks..." );
182 fReadSliceTracks = kTRUE;
183 //cout << "fReadSliceTracks: " << fReadSliceTracks << endl;
185 else if(argument.CompareTo("-read-merged-tracks") == 0){
186 HLTInfo( "Reading merged tracks..." );
187 fReadMergedTracks = kTRUE;
188 //cout << "fReadMergedTracks: " << fReadMergedTracks << endl;
198 //---------------------------------
207 // TString configuration = "";
208 // TString argument = "";
209 // for(int j=0; j<argc && iResult>=0; j++){
212 // if (!configuration.IsNull()) configuration+=" ";
213 // configuration+=argument;
216 // if (!configuration.IsNull()) {
217 // iResult = Configure(configuration.Data());
219 // iResult = Reconfigure(NULL, NULL);
222 // while ( i < argc ) {
223 // if (!strcmp( argv[i], "-enable-analysis")) {
224 // fEnableAnalysis = strtoul( argv[i+1], &cpErr ,0);
227 // HLTError("Cannot convert enable-analysis specifier '%s'.", argv[i+1]);
234 // if (!strcmp( argv[i], "-read-merged-tracks")) {
235 // fReadMergedTracks = strtoul( argv[i+1], &cpErr ,0);
238 // HLTError("Cannot convert read-merged-tracks specifier '%s'.", argv[i+1]);
245 // if (!strcmp( argv[i], "-read-slice-tracks")) {
246 // fReadSliceTracks = strtoul( argv[i+1], &cpErr ,0);
249 // HLTError("Cannot convert read-slice-tracks specifier '%s'.", argv[i+1]);
256 // Logging(kHLTLogError, "HLT::TPCCalibTracks::ScanArgument", "Unknown Option", "Unknown option '%s'", argv[i] );
264 Int_t AliHLTTPCCalibTracksComponent::InitCalibration(){
265 // see header file for class documentation
267 HLTInfo("init calibration component");
270 if(fCalibTracksGain) return EINPROGRESS;
271 fCalibTracksGain = new AliTPCcalibTracksGain();
273 if(fCalibAlign) return EINPROGRESS;
274 fCalibAlign = new AliTPCcalibAlign();
276 if(fCalibTracks) return EINPROGRESS;
277 fCalibTracks = new AliTPCcalibTracks();
280 // // Init parameters and cuts
281 // fClustParam = AliTPCcalibDB::Instance()->GetClusterParam();
282 // fTrackCuts = new AliTPCcalibTracksCuts(20, 0.4, 0.5, 0.13, 0.018);
284 // // Init calibration componenets
285 // fCalibAlign = new AliTPCcalibAlign("TPCcalibAlign","TPCcalibAlign");
286 // fCalibTracksGain = new AliTPCcalibTracksGain("TPCcalibTracksGain","TPCcalibTracksGain",fTrackCuts);
287 // fCalibTracks = new AliTPCcalibTracks("TPCcalibTracks","TPCcalibTracks",fClustParam,fTrackCuts);
289 // if (!fTrackCuts || !fClustParam || !fCalibAlign || !fCalibTracksGain || !fCalibTracks) {
290 // HLTError("failed creating internal objects");
297 Int_t AliHLTTPCCalibTracksComponent::DeinitCalibration(){
298 // see header file for class documentation
300 if(fClustParam) delete fClustParam; fClustParam = 0;
301 if(fTrackCuts) delete fTrackCuts; fTrackCuts = 0;
303 if(fCalibTracksGain) delete fCalibTracksGain; fCalibTracksGain = NULL;
304 if(fCalibAlign) delete fCalibAlign; fCalibAlign = NULL;
305 //if(fCalibTracks) delete fCalibTracks; fCalibTracks = NULL;
310 Int_t AliHLTTPCCalibTracksComponent::ProcessCalibration(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/){
311 // see header file for class documentation
314 const AliHLTComponentBlockData *iter = NULL;
315 //AliHLTUInt8_t slice = 0;
316 //AliHLTUInt8_t patch = 0;
318 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR)) return 0;
320 Int_t TotalTrack = 0;
322 //if(fReadMergedTracks){ //Reading Merged Tracks
323 for(iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkTracksDataType); iter != NULL; iter = GetNextInputBlock()){
324 if(iter->fDataType != AliHLTTPCDefinitions::fgkTracksDataType) continue;
325 ReadTracks(iter,TotalTrack);
327 //} // end if reading merged tracks
330 //if(fReadSliceTracks){ //Reading Tracks from slice
331 for(iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkTrackSegmentsDataType); iter != NULL; iter = GetNextInputBlock()){
332 if(iter->fDataType != AliHLTTPCDefinitions::fgkTrackSegmentsDataType) continue;
333 ReadTracks(iter,TotalTrack);
335 //} // end if reading slice tracks
337 //else HLTError("No input preference (merged/slice tracks) specified!");
339 //int TotalSpacePoint = 0;
340 //Int_t nClustersUsed = 0;
343 for(iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkClustersDataType); iter != NULL; iter = GetNextInputBlock()){
344 if(iter->fDataType!=AliHLTTPCDefinitions::fgkClustersDataType) continue;
346 //AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
347 //AliHLTUInt8_t patch = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
349 const AliHLTTPCClusterData *clusterData = (const AliHLTTPCClusterData*)iter->fPtr;
350 Int_t nSpacepoint = (Int_t)clusterData->fSpacePointCnt;
352 //cout << "nSpacepoint: " << nSpacepoint << endl;
353 //TotalSpacePoint += nSpacepoint;
355 AliHLTTPCSpacePointData *clusters = (AliHLTTPCSpacePointData*)clusterData->fSpacePoints;
357 Int_t thissector, thisrow = -99;
358 pConv = new AliHLTTPCOfflineCluster();
360 for(Int_t i=0; i<nSpacepoint; i++){
362 UInt_t idCluster = clusters[i].fID;
363 Int_t sliceCl = (idCluster>>25) & 0x7f;
364 Int_t patchCl = (idCluster>>22) & 0x7;
365 UInt_t pos = idCluster&0x3fffff;
367 //cout << idCluster <<"\t"<< patchCl << "\t"<< pos << endl;
368 //cout << fTrackClusterID[sliceCl][patchCl].size()<< endl;
370 for(UInt_t id=0; id<fTrackClusterID[sliceCl][patchCl].size(); id++){
371 //cout << "HELLOOOOOOOOOOOOO" << endl;
373 if(fTrackClusterID[sliceCl][patchCl][id]==pos){
374 clusters[i].fUsed = kTRUE;
375 AliHLTTPCTransform::Slice2Sector(sliceCl,(Int_t)clusters[i].fPadRow,thissector,thisrow);
376 //AliHLTTPCTransform::Slice2Sector(fCurrentslice,fCurrentRow,thissector,thisrow);
379 //cout << (Int_t)clusters[i].fPadRow << endl;
382 AliTPCclusterMI *offClus = pConv->ConvertHLTToOffline(clusters[i]);
383 offClus->SetDetector(thissector);
384 //offClus->IsUsed(1);
385 fOffArray.Add(pConv->ConvertHLTToOffline(clusters[i]));
389 } // end if setting used clusters
390 } //end for loop over cluster id
391 } // end for loop over spacepoints
393 //----- turn TObjArray of AliTPCclusterMI to AliTPCseed -----
396 for(Int_t k=0; k<fOffArray.GetSize(); k++) delete fOffArray.At(k);
400 //fCalibTracksGain->Process(fSeed);
401 //fCalibAlign->Process(fSeed);
402 //fCalibTracks->Process(fSeed);
403 } // end for loop over cluster data type
405 //fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, fMinPatch, fMaxPatch );
407 //PushBack((TObject*)fCalibTracksGain, AliHLTTPCDefinitions::fgkOfflineCalibTracksGainDataType, fSpecification);
408 //PushBack((TObject*)fCalibAlign, AliHLTTPCDefinitions::fgkOfflineCalibAlignDataType, fSpecification);
409 //PushBack((TObject*)fCalibTracks, AliHLTTPCDefinitions::fgkOfflineCalibTracksDataType, fSpecification);
415 } // end ProcessCalibration
418 Int_t AliHLTTPCCalibTracksComponent::ShipDataToFXS(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/){
419 // see header file for class documentation
422 fCalibTracksGain->Analyze();
423 fCalibAlign->Analyze();
424 fCalibTracks->Analyze();
427 PushToFXS((TObject*)fCalibAlign, "TPC", "TPCcalibAlign");
428 PushToFXS((TObject*)fCalibTracksGain, "TPC", "TPCcalibTracksGain");
429 PushToFXS((TObject*)fCalibTracks, "TPC", "TPCcalibTracks");
432 } // end ShipDataToFXS
435 void AliHLTTPCCalibTracksComponent::ReadTracks(const AliHLTComponentBlockData *iter, Int_t &tt){
437 AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
438 AliHLTUInt8_t patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
439 HLTDebug("Input Data - TPC cluster - Slice/Patch: %d/%d.", slice, patch);
442 const AliHLTTPCTrackletData *trackData = (const AliHLTTPCTrackletData*)iter->fPtr;
443 AliHLTUInt32_t nTracks = trackData->fTrackletCnt;
447 //cout << "=============================================================================" << endl;
448 //cout << "=============================================================================" << endl;
449 //cout << nTracks << endl;
451 AliHLTTPCTrackSegmentData *tracks = (AliHLTTPCTrackSegmentData*)trackData->fTracklets;
453 for(AliHLTUInt32_t i=0;i<nTracks;i++){
455 fTracks.push_back(tracks[i]);
456 UInt_t nHits = tracks->fNPoints;
457 const UInt_t *hitnum = tracks->fPointIDs;
459 for(UInt_t h=0; h<nHits; h++){
461 UInt_t idTrack = hitnum[h];
462 Int_t sliceTrack = (idTrack>>25) & 0x7f;
463 Int_t patchTrack = (idTrack>>22) & 0x7;
464 UInt_t pos = idTrack&0x3fffff;
465 fTrackClusterID[sliceTrack][patchTrack].push_back(pos);
466 } // end for loop over hits
468 UChar_t *tmpP = (UChar_t*)tracks;
469 tmpP += sizeof(AliHLTTPCTrackSegmentData)+tracks->fNPoints*sizeof(UInt_t);
470 tracks = (AliHLTTPCTrackSegmentData*)tmpP;
471 } // end for loop over tracks
472 } // end ReadTracks()
475 Int_t AliHLTTPCCalibTracksComponent::Configure(const char* arguments){
476 // see header file for class documentation
479 if (!arguments) return iResult;
480 HLTInfo("parsing configuration string \'%s\'", arguments);
482 TString allArgs = arguments;
484 int bMissingParam = 0;
486 TObjArray* pTokens=allArgs.Tokenize(" ");
488 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
489 argument=((TObjString*)pTokens->At(i))->GetString();
490 if (argument.IsNull()) continue;
492 if (argument.CompareTo("-enable-analysis")==0) {
493 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
494 HLTInfo("got \'-enable-analysis\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
497 else if (argument.CompareTo("-read-merged-tracks")==0) {
498 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
499 HLTInfo("got \'-read-merged-tracks\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
502 else if (argument.CompareTo("-read-slice-tracks")==0) {
503 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
504 HLTInfo("got \'-read-slice-tracks\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
508 HLTError("unknown argument %s", argument.Data());
519 HLTError("missing parameter for argument %s", argument.Data());
525 int AliHLTTPCCalibTracksComponent::Reconfigure(const char* cdbEntry, const char* chainId){
526 // see header file for class documentation
529 const char* path = "HLT/ConfigTPC/TPCCalibTracksComponent";
530 const char* defaultNotify="";
533 defaultNotify = " (default)";
537 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
538 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
540 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
542 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
543 iResult=Configure(pString->GetString().Data());
545 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
548 HLTError("cannot fetch object \"%s\" from CDB", path);