]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCHistogramHandlerComponent.cxx
TPC KrCF and Cluster property plotting (Kenneth & Gaute)
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCHistogramHandlerComponent.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   AliHLTTPCHistogramHandlerComponent.cxx
20     @author Kalliopi Kanaki
21     @date   
22     @brief  The Histogram Handler component
23 */
24
25 #if __GNUC__>= 3
26 using namespace std;
27 #endif
28 #include "AliHLTTPCHistogramHandlerComponent.h"
29 #include "AliHLTTPCDefinitions.h"
30 #include "AliCDBEntry.h"
31 #include "AliCDBManager.h"
32 #include "AliHLTTPCTransform.h"
33
34 #include <cstdlib>
35 #include <cerrno>
36 #include "TString.h"
37 #include "TFile.h"
38 #include "TObjArray.h"
39 #include "TObjString.h"
40 #include <sys/time.h>
41 #include "TH1.h"
42 #include "TH2.h"
43 #include "TLine.h"
44 #include "TMath.h"
45
46
47 AliHLTTPCHistogramHandlerComponent gAliHLTTPCHistogramHandlerComponent;
48
49 ClassImp(AliHLTTPCHistogramHandlerComponent) //ROOT macro for the implementation of ROOT specific class methods
50
51 AliHLTTPCHistogramHandlerComponent::AliHLTTPCHistogramHandlerComponent()
52     :    
53     fNoiseHistograms(0),
54     fKryptonHistograms(0),
55     fSlice(-99),
56     
57     fHistTH1Tmp(NULL),
58     fTotalClusterChargeIROCAll(NULL),
59     fTotalClusterChargeOROCAll(NULL),
60     fQMaxPartitionAll(NULL),
61     fPlotQmaxROCAll(NULL),
62     fNumberOfClusters(NULL),
63     
64     fHistTH2Tmp(NULL),
65     fHistTPCSideA(NULL),  
66     fHistTPCSideC(NULL)    
67 {
68   // see header file for class documentation
69   // or
70   // refer to README to build package
71   // or
72   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
73 }
74
75 AliHLTTPCHistogramHandlerComponent::~AliHLTTPCHistogramHandlerComponent() { 
76 // see header file for class documentation
77
78 }
79
80 // Public functions to implement AliHLTComponent's interface.
81 // These functions are required for the registration process
82
83 const char* AliHLTTPCHistogramHandlerComponent::GetComponentID() { 
84 // see header file for class documentation
85
86   return "TPCHistogramHandler";
87 }
88
89 void AliHLTTPCHistogramHandlerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) { 
90 // see header file for class documentation
91
92   list.clear(); 
93   list.push_back( kAliHLTDataTypeHistogram );
94 }
95
96 AliHLTComponentDataType AliHLTTPCHistogramHandlerComponent::GetOutputDataType() { 
97 // see header file for class documentation
98
99   return kAliHLTDataTypeHistogram;
100 }
101
102 int AliHLTTPCHistogramHandlerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) { 
103 // see header file for class documentation
104
105   tgtList.clear();
106   tgtList.push_back(kAliHLTDataTypeHistogram);
107   return tgtList.size();
108 }
109
110 void AliHLTTPCHistogramHandlerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) { 
111 // see header file for class documentation
112
113   constBase=0;
114   inputMultiplier=2.0;
115 }
116
117 AliHLTComponent* AliHLTTPCHistogramHandlerComponent::Spawn() { 
118 // see header file for class documentation
119
120   return new AliHLTTPCHistogramHandlerComponent();
121 }
122         
123 int AliHLTTPCHistogramHandlerComponent::DoInit( int argc, const char** argv ) { 
124 // see header file for class documentation
125
126   Int_t i = 0;
127   Char_t* cpErr;
128   
129   int iResult=0;
130   
131   TString configuration="";
132   TString argument="";
133   for (int i=0; i<argc && iResult>=0; i++) {
134     
135     argument=argv[i];
136     if (!configuration.IsNull()) configuration+=" ";
137     configuration+=argument;    
138   }
139    
140   if (!configuration.IsNull()) {
141     iResult=Configure(configuration.Data());
142   } else {
143     iResult=Reconfigure(NULL, NULL);
144   }
145
146  
147   while ( i < argc ) {      
148     if (!strcmp( argv[i], "-sum-noise-histograms")) {
149         fNoiseHistograms = strtoul( argv[i+1], &cpErr ,0);
150             
151     if ( *cpErr ) {
152         HLTError("Cannot convert sum-noise-histograms specifier '%s'.", argv[i+1]);
153         return EINVAL;
154     }
155       i+=2;
156       continue;
157     }
158     
159     if (!strcmp( argv[i], "-sum-krypton-histograms")) {
160         fKryptonHistograms = strtoul( argv[i+1], &cpErr ,0);
161             
162     if ( *cpErr ) {
163         HLTError("Cannot convert sum-krypton-histograms specifier '%s'.", argv[i+1]);
164         return EINVAL;
165     }
166       i+=2;
167       continue;
168     }    
169                   
170     Logging(kHLTLogError, "HLT::TPCHistogramHandler::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
171     return EINVAL;
172
173   } // end while
174   
175   return 0;
176 } // end DoInit()
177
178 int AliHLTTPCHistogramHandlerComponent::DoDeinit() { 
179 // see header file for class documentation 
180    
181    return 0;
182 }
183
184 int AliHLTTPCHistogramHandlerComponent::DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData){
185 // see header file for class documentation
186
187   HLTInfo("--- Entering DoEvent() in TPCHistogramHandler ---");
188   
189   if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )) return 0;
190  
191   fTotalClusterChargeIROCAll = new TH1F("fTotalClusterChargeIROCAll","Total Charge of clusters in all IROC",4000,0,4000);  
192   fTotalClusterChargeOROCAll = new TH1F("fTotalClusterChargeOROCAll","Total Charge of clusters in all OROC",4000,0,4000);
193   fQMaxPartitionAll          = new TH1F("fQMaxPartitionAll",         "QMax for All Partitions",             216,0,216);
194   fPlotQmaxROCAll            = new TH1F("fQMaxROCAll",               "QMax for All ROC",                    72,0,72);
195   fNumberOfClusters          = new TH1F("fNumberOfClusters",         "Total Number of Clusters",            100,0,100);
196     
197   fHistTH2Tmp = new TH2F("fHistTH2Tmp","fHistTH2Tmp",250,-250,250,250,-250,250);    
198   fHistTPCSideA = new TH2F("fHistTPCSideA","TPC side A (max signal)",250,-250,250,250,-250,250);
199   fHistTPCSideA->SetXTitle("global X (cm)"); fHistTPCSideA->SetYTitle("global Y (cm)");
200   fHistTPCSideC = new TH2F("fHistTPCSideC","TPC side C (max signal)",250,-250,250,250,-250,250);
201   fHistTPCSideC->SetXTitle("global X (cm)"); fHistTPCSideC->SetYTitle("global Y (cm)");
202   
203   const TObject *iter = NULL;  
204         
205   for(iter = GetFirstInputObject(kAliHLTDataTypeHistogram|kAliHLTDataOriginTPC); iter != NULL; iter = GetNextInputObject()){
206    
207 //      HLTInfo("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s", 
208 //               evtData.fEventID, evtData.fEventID,
209 //               DataType2Text(GetDataType(iter)).c_str(), 
210 //               DataType2Text(kAliHLTDataTypeHistogram | kAliHLTDataOriginTPC).c_str());
211    
212 //      if (GetDataType(iter) == (kAliHLTDataTypeHistogram | kAliHLTDataOriginTPC) && GetEventCount()<2){
213 //          HLTWarning("data type %s is depricated, use %s (kAliHLTDataTypeHistogram)!", 
214 //       DataType2Text(kAliHLTDataTypeHistogram).c_str(),
215 //          DataType2Text(kAliHLTDataTypeHistogram | kAliHLTDataOriginTPC).c_str());
216 //      }      
217      
218      if (GetDataType(iter) != (kAliHLTDataTypeHistogram | kAliHLTDataOriginTPC)) continue;
219          
220      // Summing the output histograms of the AliHLTTPCNoiseMapComponent (from partition to TPC sides)
221      if(fNoiseHistograms){  
222        
223         fHistTH2Tmp = (TH2F*)iter;
224         UInt_t minSlice     = AliHLTTPCDefinitions::GetMinSliceNr(GetSpecification(iter)); 
225         UInt_t maxSlice     = AliHLTTPCDefinitions::GetMaxSliceNr(GetSpecification(iter)); 
226         UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(GetSpecification(iter)); 
227         UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(GetSpecification(iter)); 
228        
229         if((minSlice!=maxSlice) || (minPartition!=maxPartition)){
230             HLTWarning("TPCHistogramHandler::The Noise Map component is not running on partition level!");
231         }
232
233         // minSlice=maxSlice, when the Noise Map component runs on partition level (as it should)
234         if(minSlice<18) fHistTPCSideA->Add(fHistTPCSideA,fHistTH2Tmp,1,1);
235         else            fHistTPCSideC->Add(fHistTPCSideC,fHistTH2Tmp,1,1);
236      } // endif fNoiseHistograms==kTRUE   
237      
238      
239      // Summing the output of AliHLTTPCClusterHistoComponent
240      if(fKryptonHistograms){
241        Int_t thisrow=-1,thissector=-1,row=-1;
242        
243        AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr(GetSpecification(iter));
244        AliHLTUInt8_t patch = AliHLTTPCDefinitions::GetMinPatchNr(GetSpecification(iter));
245        row = AliHLTTPCTransform::GetFirstRow(patch); 
246        AliHLTTPCTransform::Slice2Sector(slice,row,thissector,thisrow);
247        
248        fHistTH1Tmp = (TH1F*)iter;       
249        //cout << fHistTH1Tmp->GetName() << "\t" << fHistTH1Tmp->GetEntries() << endl;
250        
251         TString name = fHistTH1Tmp->GetName();
252                 
253         if(name=="fTotalClusterChargeIROCAll"){
254            fTotalClusterChargeIROCAll->Add(fTotalClusterChargeIROCAll,fHistTH1Tmp,1,1);
255         } 
256         else if(name=="fTotalClusterChargeOROCAll"){
257            fTotalClusterChargeOROCAll->Add(fTotalClusterChargeOROCAll,fHistTH1Tmp,1,1);
258         } 
259         else if(name=="fQMaxPartitionAll"){
260           AliHLTUInt8_t partitionNr=patch+slice*6;
261           //      if(fHistTH1Tmp->GetBinContent(partitionNr)>fQMaxPartitionAll->GetBinContent(partitionNr)){
262            fQMaxPartitionAll->SetBinContent(partitionNr,fHistTH1Tmp->GetBinContent(partitionNr));
263            //     }
264            fQMaxPartitionAll->Add(fQMaxPartitionAll,fHistTH1Tmp,1,1);
265         } 
266         else if(name=="fPlotQmaxROCAll"){
267           //      if(fHistTH1Tmp->GetBinContent(thissector)>fPlotQmaxROCAll->GetBinContent(thissector)){
268           //   fPlotQmaxROCAll->SetBinContent(thissector,fHistTH1Tmp->GetBinContent(thissector));
269             //    }
270           fPlotQmaxROCAll->Add(fPlotQmaxROCAll,fHistTH1Tmp,1,1);
271         }
272         else if(name=="fNumberOfClusters"){ 
273           //   fNumberOfClusters->Add(fNumberOfClusters,fHistTH1Tmp,1,1);
274         } else continue;     
275      } //endif fKryptonHistograms==kTRUE                         
276   } // end for loop over histogram blocks
277   
278   MakeHistosPublic();
279   return 0;
280 } // end DoEvent()
281
282 void AliHLTTPCHistogramHandlerComponent::MakeHistosPublic() {
283 // see header file for class documentation
284  
285   if(fNoiseHistograms){ 
286     PushBack((TObject*)fHistTPCSideA,kAliHLTDataTypeHistogram,AliHLTTPCDefinitions::EncodeDataSpecification( 0,17,0,5));
287     PushBack((TObject*)fHistTPCSideC,kAliHLTDataTypeHistogram,AliHLTTPCDefinitions::EncodeDataSpecification(18,35,0,5));
288     delete fHistTH2Tmp;
289     delete fHistTPCSideA;
290     delete fHistTPCSideC;
291   }  
292   
293   if(fKryptonHistograms){
294      PushBack((TObject*)fTotalClusterChargeIROCAll,kAliHLTDataTypeHistogram,AliHLTTPCDefinitions::EncodeDataSpecification(0,17,0,1));
295      PushBack((TObject*)fTotalClusterChargeOROCAll,kAliHLTDataTypeHistogram,AliHLTTPCDefinitions::EncodeDataSpecification(0,17,2,5));
296      PushBack((TObject*)fQMaxPartitionAll,         kAliHLTDataTypeHistogram,AliHLTTPCDefinitions::EncodeDataSpecification(0,35,0,5));
297      PushBack((TObject*)fPlotQmaxROCAll,           kAliHLTDataTypeHistogram,AliHLTTPCDefinitions::EncodeDataSpecification(0,35,0,5));
298      PushBack((TObject*)fNumberOfClusters,         kAliHLTDataTypeHistogram,AliHLTTPCDefinitions::EncodeDataSpecification(0,35,0,5));
299           
300      delete fTotalClusterChargeIROCAll;
301      delete fTotalClusterChargeOROCAll;
302      delete fQMaxPartitionAll;
303      delete fPlotQmaxROCAll;
304      delete fNumberOfClusters;
305   }
306  
307 //  TObjArray histos;
308    
309 //   if(fPlotSideA) histos.Add(fHistSideA);
310 //   if(fPlotSideC) histos.Add(fHistSideC);
311 //   if(fApplyNoiseMap) histos.Add(fHistCDBMap);
312 //   
313 //   TIter iterator(&histos);
314 //   while(TObject *pObj=iterator.Next()){
315 //   
316 //         PushBack(pObj, kAliHLTDataTypeHistogram|kAliHLTDataOriginTPC, fSpecification);
317 //   }
318 //   
319 //   
320 //   //PushBack( (TObject*) &histos, kAliHLTDataTypeHistogram, fSpecification);    
321 }
322
323 int AliHLTTPCHistogramHandlerComponent::Configure(const char* arguments) { 
324 // see header file for class documentation
325   
326   int iResult=0;
327   if (!arguments) return iResult;
328   HLTInfo("parsing configuration string \'%s\'", arguments);
329
330   TString allArgs=arguments;
331   TString argument;
332   int bMissingParam=0;
333
334   TObjArray* pTokens=allArgs.Tokenize(" ");
335   if (pTokens) {
336     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
337       argument=((TObjString*)pTokens->At(i))->GetString();
338       if (argument.IsNull()) continue;
339      
340       if (argument.CompareTo("-sum-noise-histograms")==0) {
341         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
342         HLTInfo("got \'-sum-noise-histograms\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
343         
344       } else if (argument.CompareTo("-sum-krypton-histograms")==0) {
345         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
346         HLTInfo("got \'-sum-krypton-histograms\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
347         
348       } 
349       else {
350         HLTError("unknown argument %s", argument.Data());
351         iResult=-EINVAL;
352         break;
353       }
354     } // end for
355   
356     delete pTokens;
357   
358   } // end if pTokens
359   
360   if (bMissingParam) {
361     HLTError("missing parameter for argument %s", argument.Data());
362     iResult=-EINVAL;
363   }
364   return iResult;
365 }
366
367 int AliHLTTPCHistogramHandlerComponent::Reconfigure(const char* cdbEntry, const char* chainId) { 
368 // see header file for class documentation
369
370   int iResult=0;
371   const char* path="HLT/ConfigTPC/TPCHistogramHandlerComponent";
372   const char* defaultNotify="";
373   if (cdbEntry) {
374       path=cdbEntry;
375       defaultNotify=" (default)";
376   }
377   
378   if (path) {
379     HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
380     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
381     if (pEntry) {
382       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
383       if (pString) {
384         HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
385         iResult=Configure(pString->GetString().Data());
386       } else {
387         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
388       }
389     } else {
390       HLTError("cannot fetch object \"%s\" from CDB", path);
391     }
392   }
393   return iResult;
394 }