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