]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/calibration/AliHLTTPCCalibTracksComponent.cxx
Update master to aliroot
[u/mrichter/AliRoot.git] / HLT / TPCLib / calibration / AliHLTTPCCalibTracksComponent.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project        *
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Kalliopi Kanaki <Kalliopi.Kanaki@ift.uib.no>          *
8 //*                  for The ALICE HLT Project.                            *
9 //*                                                                        *
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 //**************************************************************************
18
19 /** @file   AliHLTTPCCalibTracksComponent.cxx
20     @author Kalliopi Kanaki
21     @date   
22     @brief  A calibration component for the TPC.
23 */
24
25 // see header file for class documentation
26 // or
27 // refer to README to build package
28 // or
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt   
30
31 #include "AliHLTTPCCalibTracksComponent.h"
32
33 #include "AliHLTTPCLogging.h"
34 #include "AliHLTTPCTransform.h"
35 #include "AliHLTTPCClusterDataFormat.h"
36 #include "AliHLTTPCTrackletDataFormat.h"
37 #include "AliHLTTPCOfflineCluster.h"
38
39 #include "AliTPCcalibDB.h"
40 #include "AliTPCClusterParam.h"
41 #include "AliTPCcalibTracksCuts.h"
42 #include "AliTPCcalibTracksGain.h"
43 #include "AliTPCcalibTracks.h"
44 #include "AliTPCcalibAlign.h"
45
46 #include "AliTPCclusterMI.h"
47 #include "AliTPCseed.h"
48
49 #include "AliCDBEntry.h"
50 #include "AliCDBManager.h"
51
52 #include <stdlib.h>
53 #include <errno.h>
54 #include "TString.h"
55
56 using namespace std;
57
58 //AliHLTTPCCalibTracksComponent gAliHLTTPCCalibTracksComponent;
59
60 /** ROOT macro for the implementation of ROOT specific class methods */
61 ClassImp(AliHLTTPCCalibTracksComponent)
62
63 AliHLTTPCCalibTracksComponent::AliHLTTPCCalibTracksComponent()
64   :
65   fClustParam(0),
66   fTrackCuts(0),
67   fCalibTracksGain(NULL),
68   fCalibAlign(NULL),
69   fCalibTracks(NULL),
70   fMinPatch(5),
71   fMaxPatch(0),
72   fSpecification(0),
73   fEnableAnalysis(kFALSE),
74   fSeed(0),
75   fClusters(),
76   fTracks(),
77   pConv(NULL),
78   fOffArray(),
79   fReadMergedTracks(0),
80   fReadSliceTracks(0)
81 {
82   // see header file for class documentation
83   // or
84   // refer to README to build package
85   // or
86   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
87 }
88
89 AliHLTTPCCalibTracksComponent::~AliHLTTPCCalibTracksComponent(){
90 // see header file for class documentation
91 }
92
93 const char* AliHLTTPCCalibTracksComponent::GetComponentID(){
94 // see header file for class documentation
95   return "TPCCalibTracks";
96 }
97
98 void AliHLTTPCCalibTracksComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list){
99 // see header file for class documentation
100
101   list.clear(); 
102   list.push_back(AliHLTTPCDefinitions::fgkClustersDataType);
103   list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
104   list.push_back(AliHLTTPCDefinitions::fgkTracksDataType);
105 }
106
107 AliHLTComponentDataType AliHLTTPCCalibTracksComponent::GetOutputDataType(){
108 // see header file for class documentation
109
110   return kAliHLTMultipleDataType;
111 }
112
113 int AliHLTTPCCalibTracksComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList){
114 // create output data type
115
116   tgtList.clear();
117   tgtList.push_back(AliHLTTPCDefinitions::fgkOfflineCalibAlignDataType);
118   tgtList.push_back(AliHLTTPCDefinitions::fgkOfflineCalibTracksDataType);
119   tgtList.push_back(AliHLTTPCDefinitions::fgkOfflineCalibTracksGainDataType);
120
121   return tgtList.size();
122 }
123
124 void AliHLTTPCCalibTracksComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier){
125 // see header file for class documentation
126
127   constBase = 30000000;
128   inputMultiplier = 1;
129 }
130
131 AliHLTComponent* AliHLTTPCCalibTracksComponent::Spawn(){
132 // see header file for class documentation
133   
134   return new AliHLTTPCCalibTracksComponent();
135 }  
136
137
138 Int_t AliHLTTPCCalibTracksComponent::ScanArgument(Int_t argc, const char** argv){
139 // see header file for class documentation
140
141   Int_t iResult = 0;
142   TString argument = "";
143   TString parameter = "";
144
145   if(!argc) return -EINVAL;
146   argument = argv[iResult];
147   
148   if(argument.IsNull()) return -EINVAL;
149
150 //   // -rcuformat
151 //   if ( argument.CompareTo("-rcuformat") == 0 ) {
152 // 
153 //     if ( ++iResult >= argc  ) {
154 //       iResult = -EPROTO;
155 //     }
156 //     else {
157 //       parameter = argv[1];
158 //       if ( parameter.CompareTo("old") == 0 ) {
159 //         HLTInfo( "RCU Format is set to old." );
160 //       }
161 //       else if ( parameter.CompareTo("new") == 0 ) {
162 //         HLTInfo( "RCU Format is set to new." );
163 //       }
164 //       else {
165 //      HLTError( "Cannot convert rcu format specifier '%s'.", argv[1] );
166 //      iResult = -EPROTO;
167 //       }
168 //     } 
169 //   }
170
171
172   if(argument.CompareTo("-enable-analysis") == 0) {   
173   
174     HLTInfo( "Enable analysis before shipping data to FXS." );
175     fEnableAnalysis = kTRUE;
176     //cout << "fEnableAnalysis: " << fEnableAnalysis << endl;
177   }
178   else if(argument.CompareTo("-read-slice-tracks") == 0){
179     HLTInfo( "Reading slice tracks..." );
180     fReadSliceTracks = kTRUE;  
181     //cout << "fReadSliceTracks: " << fReadSliceTracks << endl;
182   }
183   else if(argument.CompareTo("-read-merged-tracks") == 0){
184     HLTInfo( "Reading merged tracks..." );
185     fReadMergedTracks = kTRUE; 
186     //cout << "fReadMergedTracks: " << fReadMergedTracks << endl;
187   }
188   else {
189     iResult = -EINVAL;
190   }
191   
192   return iResult;
193
194
195
196 //---------------------------------
197
198
199  
200 //   Int_t i = 0;
201 //   Char_t* cpErr;
202 //   
203 //   int iResult = 0;
204 //   
205 //   TString configuration = "";
206 //   TString argument = "";
207 //   for(int j=0; j<argc && iResult>=0; j++){
208 //     
209 //     argument=argv[j];
210 //     if (!configuration.IsNull()) configuration+=" ";
211 //     configuration+=argument;    
212 //   }
213 //    
214 //   if (!configuration.IsNull()) {
215 //     iResult = Configure(configuration.Data());
216 //   } else {
217 //     iResult = Reconfigure(NULL, NULL);
218 //   }
219 //  
220 //   while ( i < argc ) {      
221 //     if (!strcmp( argv[i], "-enable-analysis")) {
222 //         fEnableAnalysis = strtoul( argv[i+1], &cpErr ,0);
223 //             
224 //     if ( *cpErr ) {
225 //         HLTError("Cannot convert enable-analysis specifier '%s'.", argv[i+1]);
226 //         return EINVAL;
227 //     }
228 //       i+=2;
229 //       continue;
230 //     }
231 //     
232 //     if (!strcmp( argv[i], "-read-merged-tracks")) {
233 //         fReadMergedTracks = strtoul( argv[i+1], &cpErr ,0);
234 //             
235 //     if ( *cpErr ) {
236 //         HLTError("Cannot convert read-merged-tracks specifier '%s'.", argv[i+1]);
237 //         return EINVAL;
238 //     }
239 //       i+=2;
240 //       continue;
241 //     }
242 //     
243 //     if (!strcmp( argv[i], "-read-slice-tracks")) {
244 //         fReadSliceTracks = strtoul( argv[i+1], &cpErr ,0);
245 //     
246 //     if ( *cpErr ) {
247 //         HLTError("Cannot convert read-slice-tracks specifier '%s'.", argv[i+1]);
248 //         return EINVAL;
249 //     }
250 //       i+=2;
251 //       continue;
252 //     }
253 // 
254 //     Logging(kHLTLogError, "HLT::TPCCalibTracks::ScanArgument", "Unknown Option", "Unknown option '%s'", argv[i] );
255 //     return EINVAL;
256 // 
257 //   } // end while
258 //   
259 //   return 0;
260 }
261
262 Int_t AliHLTTPCCalibTracksComponent::InitCalibration(){
263 // see header file for class documentation
264   
265   HLTInfo("init calibration component");
266   int iResult=0;
267
268   if(fCalibTracksGain) return EINPROGRESS; 
269   fCalibTracksGain = new AliTPCcalibTracksGain();
270   
271   if(fCalibAlign) return EINPROGRESS;  
272   fCalibAlign = new AliTPCcalibAlign();
273  
274   if(fCalibTracks) return EINPROGRESS;  
275   fCalibTracks = new AliTPCcalibTracks();
276
277   
278 //   // Init parameters and cuts
279 //   fClustParam = AliTPCcalibDB::Instance()->GetClusterParam();
280 //   fTrackCuts = new AliTPCcalibTracksCuts(20, 0.4, 0.5, 0.13, 0.018);
281 // 
282 //   // Init calibration componenets
283 //   fCalibAlign           = new AliTPCcalibAlign("TPCcalibAlign","TPCcalibAlign");
284 //   fCalibTracksGain = new AliTPCcalibTracksGain("TPCcalibTracksGain","TPCcalibTracksGain",fTrackCuts);
285 //   fCalibTracks     = new AliTPCcalibTracks("TPCcalibTracks","TPCcalibTracks",fClustParam,fTrackCuts);
286 // 
287 //   if (!fTrackCuts || !fClustParam ||  !fCalibAlign || !fCalibTracksGain || !fCalibTracks) {
288 //     HLTError("failed creating internal objects");
289 //     iResult=-ENOMEM;
290 //   }
291   return iResult;  
292
293 }
294
295 Int_t AliHLTTPCCalibTracksComponent::DeinitCalibration(){
296 // see header file for class documentation
297    
298    if(fClustParam) delete fClustParam; fClustParam = 0; 
299    if(fTrackCuts)  delete fTrackCuts;  fTrackCuts  = 0; 
300
301    if(fCalibTracksGain) delete fCalibTracksGain; fCalibTracksGain = NULL;
302    if(fCalibAlign)      delete fCalibAlign;      fCalibAlign      = NULL;
303    //if(fCalibTracks)     delete fCalibTracks;   fCalibTracks     = NULL;
304    
305   return 0;
306 }
307
308 Int_t AliHLTTPCCalibTracksComponent::ProcessCalibration(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/){
309 // see header file for class documentation
310   
311   
312   const AliHLTComponentBlockData *iter = NULL;
313   //AliHLTUInt8_t slice = 0;
314   //AliHLTUInt8_t patch = 0;
315       
316   if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR)) return 0;
317
318   Int_t TotalTrack = 0;
319
320   //if(fReadMergedTracks){ //Reading Merged Tracks 
321      for(iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkTracksDataType); iter != NULL; iter = GetNextInputBlock()){
322          if(iter->fDataType != AliHLTTPCDefinitions::fgkTracksDataType) continue; 
323          ReadTracks(iter,TotalTrack);  
324      }  
325   //} // end if reading merged tracks
326
327   //else 
328   //if(fReadSliceTracks){ //Reading Tracks from slice 
329      for(iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkTrackSegmentsDataType); iter != NULL; iter = GetNextInputBlock()){
330          if(iter->fDataType != AliHLTTPCDefinitions::fgkTrackSegmentsDataType) continue; 
331          ReadTracks(iter,TotalTrack);
332      }
333   //} // end if reading slice tracks
334           
335   //else HLTError("No input preference (merged/slice tracks) specified!");
336  
337   //int TotalSpacePoint = 0;
338   //Int_t nClustersUsed = 0;
339   //fOffArray.Clear();
340   
341   for(iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkClustersDataType); iter != NULL; iter = GetNextInputBlock()){
342       if(iter->fDataType!=AliHLTTPCDefinitions::fgkClustersDataType) continue;
343
344       //AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
345       //AliHLTUInt8_t patch = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
346
347       const AliHLTTPCClusterData *clusterData = (const AliHLTTPCClusterData*)iter->fPtr;
348       Int_t nSpacepoint = (Int_t)clusterData->fSpacePointCnt;   
349       
350       //cout << "nSpacepoint: " << nSpacepoint << endl;      
351       //TotalSpacePoint += nSpacepoint;
352       
353       AliHLTTPCSpacePointData *clusters = (AliHLTTPCSpacePointData*)clusterData->fSpacePoints;
354      
355       Int_t thissector, thisrow = -99;
356       pConv = new AliHLTTPCOfflineCluster();
357       
358       for(Int_t i=0; i<nSpacepoint; i++){
359        
360           UInt_t idCluster = clusters[i].fID;
361           Int_t  sliceCl   = AliHLTTPCSpacePointData::GetSlice(idCluster);
362           Int_t  patchCl   = AliHLTTPCSpacePointData::GetPatch(idCluster);
363           UInt_t pos       = AliHLTTPCSpacePointData::GetNumber(idCluster);
364
365           //cout << idCluster <<"\t"<< patchCl << "\t"<< pos << endl;
366           //cout << fTrackClusterID[sliceCl][patchCl].size()<< endl;
367               
368           for(UInt_t id=0; id<fTrackClusterID[sliceCl][patchCl].size(); id++){
369             //cout << "HELLOOOOOOOOOOOOO" << endl;
370               
371               if(fTrackClusterID[sliceCl][patchCl][id]==pos){
372                  clusters[i].fUsed = kTRUE;
373                  AliHLTTPCTransform::Slice2Sector(sliceCl,(Int_t)clusters[i].fPadRow,thissector,thisrow);
374                  //AliHLTTPCTransform::Slice2Sector(fCurrentslice,fCurrentRow,thissector,thisrow);
375                  //nClustersUsed++;     
376                  
377                  //cout <<  (Int_t)clusters[i].fPadRow << endl; 
378               
379                  
380                  AliTPCclusterMI *offClus = pConv->ConvertHLTToOffline(clusters[i]);
381                  offClus->SetDetector(thissector);
382                  //offClus->IsUsed(1);
383                  fOffArray.Add(pConv->ConvertHLTToOffline(clusters[i]));
384                  //delete pConv;
385                  //delete offClus;
386
387              } // end if setting used clusters
388           } //end for loop over cluster id       
389       } // end for loop over spacepoints
390       
391       //----- turn TObjArray of AliTPCclusterMI to AliTPCseed -----
392      
393       delete pConv;
394       for(Int_t k=0; k<fOffArray.GetSize(); k++) delete fOffArray.At(k);
395       
396       fOffArray.Clear();
397      
398       //fCalibTracksGain->Process(fSeed);
399       //fCalibAlign->Process(fSeed);
400       //fCalibTracks->Process(fSeed);
401   } // end for loop over cluster data type
402     
403   //fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, fMinPatch, fMaxPatch );
404
405   //PushBack((TObject*)fCalibTracksGain, AliHLTTPCDefinitions::fgkOfflineCalibTracksGainDataType, fSpecification);
406   //PushBack((TObject*)fCalibAlign,      AliHLTTPCDefinitions::fgkOfflineCalibAlignDataType,    fSpecification);
407   //PushBack((TObject*)fCalibTracks,     AliHLTTPCDefinitions::fgkOfflineCalibTracksDataType,   fSpecification);
408   
409   //fClusters.clear();
410   //fTracks.clear();
411
412   return 0;
413 } // end ProcessCalibration
414
415
416 Int_t AliHLTTPCCalibTracksComponent::ShipDataToFXS(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/){
417 // see header file for class documentation
418     
419   if(fEnableAnalysis){
420      fCalibTracksGain->Analyze();
421      fCalibAlign->Analyze();
422      fCalibTracks->Analyze();
423   }
424   
425   PushToFXS((TObject*)fCalibAlign,      "TPC", "TPCcalibAlign"); 
426   PushToFXS((TObject*)fCalibTracksGain, "TPC", "TPCcalibTracksGain");
427   PushToFXS((TObject*)fCalibTracks,     "TPC", "TPCcalibTracks");
428   
429   return 0;
430 } // end ShipDataToFXS
431
432
433 void AliHLTTPCCalibTracksComponent::ReadTracks(const AliHLTComponentBlockData *iter, Int_t &tt){
434
435   HLTDebug("Input Data - TPC cluster - Slice/Patch: %d/%d.", 
436            AliHLTTPCDefinitions::GetMinSliceNr( *iter ), 
437            AliHLTTPCDefinitions::GetMinPatchNr( *iter ));
438  
439
440   const AliHLTTPCTrackletData *trackData = (const AliHLTTPCTrackletData*)iter->fPtr;
441   AliHLTUInt32_t nTracks = trackData->fTrackletCnt;
442
443   tt += nTracks;
444  
445   //cout << "=============================================================================" << endl;
446   //cout << "=============================================================================" << endl;
447   //cout << nTracks << endl;
448  
449   AliHLTTPCTrackSegmentData *tracks = (AliHLTTPCTrackSegmentData*)trackData->fTracklets;
450   
451   for(AliHLTUInt32_t i=0;i<nTracks;i++){
452      
453       fTracks.push_back(tracks[i]);
454       UInt_t nHits = tracks->fNPoints;
455       const UInt_t *hitnum = tracks->fPointIDs;
456       
457       for(UInt_t h=0; h<nHits; h++){
458           
459           UInt_t idTrack = hitnum[h];
460           Int_t sliceTrack = AliHLTTPCSpacePointData::GetSlice(idTrack);
461           Int_t patchTrack = AliHLTTPCSpacePointData::GetPatch(idTrack);
462           UInt_t pos = AliHLTTPCSpacePointData::GetNumber(idTrack);
463           fTrackClusterID[sliceTrack][patchTrack].push_back(pos);
464       } // end for loop over hits
465        
466       UChar_t *tmpP = (UChar_t*)tracks;
467       tmpP += sizeof(AliHLTTPCTrackSegmentData)+tracks->fNPoints*sizeof(UInt_t);
468       tracks = (AliHLTTPCTrackSegmentData*)tmpP;
469   } // end for loop over tracks
470 } // end ReadTracks()
471
472
473 Int_t AliHLTTPCCalibTracksComponent::Configure(const char* arguments){ 
474 // see header file for class documentation
475   
476   Int_t iResult=0;
477   if (!arguments) return iResult;
478   HLTInfo("parsing configuration string \'%s\'", arguments);
479
480   TString allArgs = arguments;
481   TString argument;
482   int bMissingParam = 0;
483
484   TObjArray* pTokens=allArgs.Tokenize(" ");
485   if (pTokens) {
486     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
487       argument=((TObjString*)pTokens->At(i))->GetString();
488       if (argument.IsNull()) continue;
489      
490       if (argument.CompareTo("-enable-analysis")==0) {
491         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
492         HLTInfo("got \'-enable-analysis\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
493         
494       } 
495       else if (argument.CompareTo("-read-merged-tracks")==0) {
496         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
497         HLTInfo("got \'-read-merged-tracks\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
498         
499       } 
500       else if (argument.CompareTo("-read-slice-tracks")==0) {
501         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
502         HLTInfo("got \'-read-slice-tracks\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
503         
504       } 
505       else {
506         HLTError("unknown argument %s", argument.Data());
507         iResult=-EINVAL;
508         break;
509       }
510     } // end for
511   
512     delete pTokens;
513   
514   } // end if pTokens
515   
516   if (bMissingParam) {
517     HLTError("missing parameter for argument %s", argument.Data());
518     iResult=-EINVAL;
519   }
520   return iResult;  
521 }
522
523 int AliHLTTPCCalibTracksComponent::Reconfigure(const char* cdbEntry, const char* chainId){ 
524 // see header file for class documentation
525  
526   int iResult=0;
527   const char* path = "HLT/ConfigTPC/TPCCalibTracksComponent";
528   const char* defaultNotify="";
529   if (cdbEntry) {
530       path=cdbEntry;
531       defaultNotify = " (default)";
532   }
533   
534   if (path) {
535     HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
536     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
537     if (pEntry) {
538       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
539       if (pString) {
540         HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
541         iResult=Configure(pString->GetString().Data());
542       } else {
543         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
544       }
545     } else {
546       HLTError("cannot fetch object \"%s\" from CDB", path);
547     }
548   }
549   return iResult;
550 }
551