]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCNoiseMapComponent.cxx
added cutoff parameter in z direction to ignore clusters of large z (Gaute)
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCNoiseMapComponent.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   AliHLTTPCNoiseMapComponent.cxx
20     @author Kalliopi Kanaki
21     @date   
22     @brief  The TPC Noise Map component
23 */
24
25 #if __GNUC__>= 3
26 using namespace std;
27 #endif
28
29 #include "AliHLTTPCNoiseMapComponent.h"
30 #include "AliHLTTPCDigitReaderDecoder.h"
31 //#include "AliHLTTPCDigitReaderPacked.h"
32 #include "AliHLTTPCTransform.h"
33 #include "AliHLTTPCDefinitions.h"
34
35 #include "AliCDBEntry.h"
36 #include "AliCDBManager.h"
37 #include "AliHLTTPCNoiseMap.h"
38
39 #include "AliTPCCalPad.h"
40 #include "AliTPCROC.h"
41 #include "AliTPCCalROC.h"
42
43 #include <cstdlib>
44 #include <cerrno>
45 #include "TString.h"
46 #include "TFile.h"
47 #include "TObjArray.h"
48 #include "TObjString.h"
49 #include <sys/time.h>
50 #include "TH2.h"
51
52 ClassImp(AliHLTTPCNoiseMapComponent) //ROOT macro for the implementation of ROOT specific class methods
53
54 AliHLTTPCNoiseMapComponent::AliHLTTPCNoiseMapComponent()
55     :    
56     fSpecification(0),
57     fPlotSideA(0),
58     fPlotSideC(0),    
59     fApplyNoiseMap(0),
60     fResetHistograms(0),
61     fIsPacked(0),
62     fIsUnpacked(0),
63     fCurrentSlice(-99),
64     fCurrentPartition(-99),
65     fCurrentRow(-99),
66     fHistSignal(NULL),
67     fHistMaxSignal(NULL),
68     fHistTotSignal(NULL),
69     fHistPadRMS(NULL),
70     fHistCDBMap(NULL),    
71     fHistSideA(NULL),  
72     fHistSideC(NULL)
73 {
74   // see header file for class documentation
75   // or
76   // refer to README to build package
77   // or
78   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
79 }
80
81 AliHLTTPCNoiseMapComponent::~AliHLTTPCNoiseMapComponent() { 
82 // see header file for class documentation
83
84 }
85
86 // Public functions to implement AliHLTComponent's interface.
87 // These functions are required for the registration process
88
89 const char* AliHLTTPCNoiseMapComponent::GetComponentID() { 
90 // see header file for class documentation
91
92   return "TPCNoiseMap";
93 }
94
95 void AliHLTTPCNoiseMapComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) { 
96 // see header file for class documentation
97
98   list.clear(); 
99   list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
100 }
101
102 AliHLTComponentDataType AliHLTTPCNoiseMapComponent::GetOutputDataType() { 
103 // see header file for class documentation
104
105   return kAliHLTDataTypeHistogram;
106 }
107
108 int AliHLTTPCNoiseMapComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) { 
109 // see header file for class documentation
110
111   tgtList.clear();
112   tgtList.push_back(kAliHLTDataTypeHistogram);
113   return tgtList.size();
114 }
115
116 void AliHLTTPCNoiseMapComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) { 
117 // see header file for class documentation
118
119   constBase=800000;
120   inputMultiplier=0.0;
121 }
122
123 AliHLTComponent* AliHLTTPCNoiseMapComponent::Spawn() { 
124 // see header file for class documentation
125
126   return new AliHLTTPCNoiseMapComponent();
127 }
128         
129 int AliHLTTPCNoiseMapComponent::DoInit( int argc, const char** argv ) { 
130 // see header file for class documentation
131  
132   Int_t i = 0;
133   Char_t* cpErr;
134   
135   int iResult=0;
136   
137   TString configuration="";
138   TString argument="";
139   for (int j=0; j<argc && iResult>=0; j++) {
140     
141     argument=argv[j];
142     if (!configuration.IsNull()) configuration+=" ";
143     configuration+=argument;    
144   }
145    
146   if (!configuration.IsNull()) {
147     iResult=Configure(configuration.Data());
148   } else {
149     iResult=Reconfigure(NULL, NULL);
150   }
151
152  
153   while ( i < argc ) {      
154     if (!strcmp( argv[i], "-apply-noisemap")) {
155         fApplyNoiseMap = strtoul( argv[i+1], &cpErr ,0);
156             
157     if ( *cpErr ) {
158         HLTError("Cannot convert apply-noisemap specifier '%s'.", argv[i+1]);
159         return EINVAL;
160     }
161       i+=2;
162       continue;
163     }
164     
165     if (!strcmp( argv[i], "-plot-side-a")) {
166         fPlotSideA = strtoul( argv[i+1], &cpErr ,0);
167             
168     if ( *cpErr ) {
169         HLTError("Cannot convert plot-side-a specifier '%s'.", argv[i+1]);
170         return EINVAL;
171     }
172       i+=2;
173       continue;
174     }
175     
176     if (!strcmp( argv[i], "-plot-side-c")) {
177         fPlotSideC = strtoul( argv[i+1], &cpErr ,0);
178     
179     if ( *cpErr ) {
180         HLTError("Cannot convert plot-side-c specifier '%s'.", argv[i+1]);
181         return EINVAL;
182     }
183       i+=2;
184       continue;
185     }
186
187     if (!strcmp( argv[i], "-reset-histograms")) {
188         fResetHistograms = strtoul( argv[i+1], &cpErr ,0);
189     
190     if ( *cpErr ) {
191         HLTError("Cannot convert reset-histograms specifier '%s'.", argv[i+1]);
192         return EINVAL;
193     }
194       i+=2;
195       continue;
196     }
197                    
198     Logging(kHLTLogError, "HLT::TPCNoiseMap::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
199     return EINVAL;
200
201   } // end while
202   
203   if(fApplyNoiseMap){
204      AliHLTTPCNoiseMap *nm = AliHLTTPCNoiseMap::Instance();
205      AliTPCCalPad *noisePad = nm->ReadNoiseMap();
206      fHistCDBMap = noisePad->MakeHisto2D(1);
207   }
208
209 //   if(fApplyNoiseMap){
210 //     //TFile *f = TFile::Open("/scratch/noiseComp/Run3398_4000_v0_s72.root");
211 //     TFile *f = TFile::Open("/home/kanaki/noiseComp/Run3398_4000_v0_s72.root");
212 //     AliCDBEntry *pEntry = (AliCDBEntry*)f->Get("AliCDBEntry"); 
213 //     noisePad = (AliTPCCalPad*)pEntry->GetObject();
214 //     //fHistCDBMap = noisePad->MakeHisto2D(1); //side C
215 //   }
216    
217  
218 //   HLTDebug("using AliHLTTPCDigitReaderDecoder");
219 //   pDigitReader = new AliHLTTPCDigitReaderDecoder(); // double-loop
220 //   pDigitReader = new AliHLTTPCDigitReaderPacked();
221   
222   return 0;
223
224 } // end DoInit()
225
226 int AliHLTTPCNoiseMapComponent::DoDeinit() { 
227 // see header file for class documentation       
228     return 0;
229 }
230
231 int AliHLTTPCNoiseMapComponent::DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& /*trigData*/){
232 // see header file for class documentation
233  
234   HLTInfo("--- Entering DoEvent() in TPCNoiseMap ---");
235  
236   if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )) return 0;
237   
238   if(fPlotSideA){
239      fHistSideA = new TH2F("fHistSideA","TPC Side A",250,-250,250,250,-250,250);                
240      fHistSideA->SetXTitle("global X (cm)"); fHistSideA->SetYTitle("global Y (cm)");
241   }   
242   
243   if(fPlotSideC){    
244      fHistSideC = new TH2F("fHistSideC","TPC Side C",250,-250,250,250,-250,250);
245      fHistSideC->SetXTitle("global X (cm)"); fHistSideC->SetYTitle("global Y (cm)");
246   }
247   
248   const AliHLTComponentBlockData *iter = NULL;
249
250   Float_t xyz[3]; 
251   Int_t thissector, thisrow;
252
253   fHistMaxSignal = new TH2F("fHistMaxSignal","maximum signal",   250,-250,250,250,-250,250);
254   fHistTotSignal = new TH2F("fHistTotSignal","total signal",     250,-250,250,250,-250,250);
255   fHistPadRMS    = new TH2F("fHistPadRMS",   "RMS",              250,-250,250,250,-250,250);
256   
257   for(iter = GetFirstInputBlock(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC); iter != NULL; iter = GetNextInputBlock()){
258       
259      HLTInfo("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s", 
260               evtData.fEventID, evtData.fEventID,
261               DataType2Text(iter->fDataType).c_str(), 
262               DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
263
264      if (iter->fDataType == AliHLTTPCDefinitions::fgkDDLPackedRawDataType && GetEventCount()<2){
265          HLTWarning("data type %s is depricated, use %s (kAliHLTDataTypeDDLRaw)!", 
266          DataType2Text(AliHLTTPCDefinitions::fgkDDLPackedRawDataType).c_str(),
267          DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
268      }      
269      
270      if (iter->fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC)) continue;
271       
272      UInt_t slice     = AliHLTTPCDefinitions::GetMinSliceNr(*iter); 
273      UInt_t partition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
274      
275      fSpecification = iter->fSpecification;
276      
277      AliHLTTPCDigitReader *pDigitReader = new AliHLTTPCDigitReaderDecoder;
278
279      pDigitReader->InitBlock(iter->fPtr,iter->fSize,partition,slice);
280      if(!pDigitReader) break;
281        
282      //sprintf(name,"hMaxSignal_slice%d_partition%d", slice, partition);
283      //fHistMaxSignal = new TH2F(name,name,250,-250,250,250,-250,250);
284             
285      while(pDigitReader->Next()){ 
286      //while( pDigitReader->NextChannel()) { // pad loop 
287       
288       fCurrentRow  = pDigitReader->GetRow();  
289       fCurrentRow += pDigitReader->GetRowOffset();
290
291       AliHLTTPCTransform::Slice2Sector(slice,fCurrentRow,thissector,thisrow);
292       AliHLTTPCTransform::Raw2Local(xyz,thissector,thisrow,pDigitReader->GetPad(),0);
293       
294       if(slice>17) xyz[1] = (-1.0)*xyz[1];
295       else continue;
296       
297       AliHLTTPCTransform::Local2Global(xyz,slice);
298       // temporarily the transformation Raw2Global will be broken down to 2 steps,
299       // as there is a correction necessary at the y coordinate of the local xyz.
300       
301       //AliHLTTPCTransform::Raw2Global(xyz,thissector,thisrow,pDigitReader->GetPad(),0);
302       // transformation from pad-row coordinates to global ones
303       // time info is not taken into account
304       
305 //       AliTPCCalROC *calRoc = noisePad->GetCalROC(thissector);
306 //       calRoc->GetValue(thisrow,pDigitReader->GetPad());
307       
308       //while( pDigitReader->NextBunch()) {
309     
310       const UInt_t *bunchData = pDigitReader->GetSignals();
311       Float_t maxSignal   = 0.;
312       Float_t totalSignal = 0.;
313       
314       fHistSignal = new TH1F("fHistSignal", "signal distribution per pad",1024,0,1024);
315
316       for(Int_t i=0;i<pDigitReader->GetBunchSize();i++){
317           
318           if((Float_t)(bunchData[i])>maxSignal){ maxSignal = (Float_t)(bunchData[i]); }
319           totalSignal += bunchData[i];    
320           fHistSignal->Fill(bunchData[i]);
321       } // end for loop over bunches
322       
323       //} // end of inner while loop
324            
325       fHistMaxSignal->Fill(xyz[0],xyz[1],maxSignal);
326       fHistTotSignal->Fill(xyz[0],xyz[1],totalSignal);
327       fHistPadRMS->Fill(xyz[0],xyz[1],fHistSignal->GetRMS());
328       delete fHistSignal;
329       
330       
331       if(fPlotSideA || fPlotSideC){
332          if(slice<18) fHistSideA->Fill(xyz[0],xyz[1],maxSignal);
333          else         fHistSideC->Fill(xyz[0],xyz[1],maxSignal);                             
334       } // end if plotting sides            
335      } // end of while loop over pads
336      delete pDigitReader;
337   } // end of for loop over data blocks
338  
339   if(fResetHistograms) ResetHistograms();
340   MakeHistosPublic();
341
342   return 0;
343 } // end DoEvent()
344
345
346 void AliHLTTPCNoiseMapComponent::MakeHistosPublic() {
347 // see header file for class documentation
348   
349 //   TFile *outputfile = new TFile("test.root","RECREATE");
350 //   fHistSideC->Write();
351 //   fHistPartition->Write();
352 //   fHistCDBMap->Write();
353 //   outputfile->Save();
354 //   outputfile->Close();
355
356   TObjArray histos;
357   histos.Add(fHistMaxSignal);
358   histos.Add(fHistTotSignal);
359   histos.Add(fHistPadRMS);
360   histos.Add(fHistCDBMap);
361   if(fPlotSideA) histos.Add(fHistSideA);
362   if(fPlotSideC) histos.Add(fHistSideC);
363   
364   TIter iterator(&histos);
365   while(TObject *pObj=iterator.Next()){ PushBack(pObj, kAliHLTDataTypeHistogram|kAliHLTDataOriginTPC, fSpecification); }
366     
367   //PushBack( (TObject*) &histos, kAliHLTDataTypeHistogram, fSpecification);    
368  
369   if(fHistSignal)    delete fHistSignal;    fHistSignal    = NULL;
370   if(fHistMaxSignal) delete fHistMaxSignal; fHistMaxSignal = NULL;
371   if(fHistTotSignal) delete fHistTotSignal; fHistTotSignal = NULL;
372   if(fHistPadRMS)    delete fHistPadRMS;    fHistPadRMS    = NULL;
373   if(fHistSideA)     delete fHistSideA;     fHistSideA     = NULL;
374   if(fHistSideC)     delete fHistSideC;     fHistSideC     = NULL;
375   
376 }
377
378 void AliHLTTPCNoiseMapComponent::ResetHistograms(){
379 // see header file for class documentation
380
381   //if(fHistPartition) fHistPartition->Reset();  
382   if(fHistMaxSignal) fHistMaxSignal->Reset();
383   if(fHistTotSignal) fHistTotSignal->Reset();
384   if(fHistPadRMS)    fHistPadRMS->Reset();
385
386   if(fHistSideA) fHistSideA->Reset();
387   if(fHistSideC) fHistSideC->Reset();
388 }
389
390 int AliHLTTPCNoiseMapComponent::Configure(const char* arguments) { 
391 // see header file for class documentation
392   
393   int iResult=0;
394   if (!arguments) return iResult;
395   HLTInfo("parsing configuration string \'%s\'", arguments);
396
397   TString allArgs=arguments;
398   TString argument;
399   int bMissingParam=0;
400
401   TObjArray* pTokens=allArgs.Tokenize(" ");
402   if (pTokens) {
403     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
404       argument=((TObjString*)pTokens->At(i))->GetString();
405       if (argument.IsNull()) continue;
406      
407       if (argument.CompareTo("-apply-noisemap")==0) {
408         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
409         HLTInfo("got \'-apply-noisemap\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
410         
411       } 
412       else if (argument.CompareTo("-plot-side-c")==0) {
413         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
414         HLTInfo("got \'-plot-side-c\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
415         
416       } 
417       else if (argument.CompareTo("-plot-side-a")==0) {
418         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
419         HLTInfo("got \'-plot-side-a\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
420         
421       }       
422       else if(argument.CompareTo("-reset-histograms")==0){
423         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
424         HLTInfo("got \'-reset-histograms\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
425         
426       } 
427       else {
428         HLTError("unknown argument %s", argument.Data());
429         iResult=-EINVAL;
430         break;
431       }
432     } // end for
433   
434     delete pTokens;
435   
436   } // end if pTokens
437   
438   if (bMissingParam) {
439     HLTError("missing parameter for argument %s", argument.Data());
440     iResult=-EINVAL;
441   }
442   return iResult;  
443 }
444
445 int AliHLTTPCNoiseMapComponent::Reconfigure(const char* cdbEntry, const char* chainId) { 
446 // see header file for class documentation
447   int iResult=0;
448   const char* path="HLT/ConfigTPC/TPCNoiseMapComponent";
449   const char* defaultNotify="";
450   if (cdbEntry) {
451       path=cdbEntry;
452       defaultNotify=" (default)";
453   }
454   
455   if (path) {
456     HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
457     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
458     if (pEntry) {
459       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
460       if (pString) {
461         HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
462         iResult=Configure(pString->GetString().Data());
463       } else {
464         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
465       }
466     } else {
467       HLTError("cannot fetch object \"%s\" from CDB", path);
468     }
469   }
470   
471   return iResult;
472 }