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 AliHLTTPCNoiseMapComponent.cxx
20 @author Kalliopi Kanaki
22 @brief The TPC Noise Map component
29 #include "AliHLTTPCNoiseMapComponent.h"
30 #include "AliHLTTPCDigitReaderDecoder.h"
31 //#include "AliHLTTPCDigitReaderPacked.h"
32 #include "AliHLTTPCTransform.h"
33 #include "AliHLTTPCDefinitions.h"
35 #include "AliCDBEntry.h"
36 #include "AliCDBManager.h"
37 #include "AliCDBStorage.h"
38 #include "AliHLTTPCNoiseMap.h"
40 #include "AliTPCCalPad.h"
41 #include "AliTPCROC.h"
42 #include "AliTPCCalROC.h"
48 #include "TObjArray.h"
49 #include "TObjString.h"
54 ClassImp(AliHLTTPCNoiseMapComponent) //ROOT macro for the implementation of ROOT specific class methods
56 AliHLTTPCNoiseMapComponent::AliHLTTPCNoiseMapComponent()
66 fCurrentPartition(-99),
76 // see header file for class documentation
78 // refer to README to build package
80 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
83 AliHLTTPCNoiseMapComponent::~AliHLTTPCNoiseMapComponent() {
84 // see header file for class documentation
88 // Public functions to implement AliHLTComponent's interface.
89 // These functions are required for the registration process
91 const char* AliHLTTPCNoiseMapComponent::GetComponentID() {
92 // see header file for class documentation
97 void AliHLTTPCNoiseMapComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
98 // see header file for class documentation
101 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
104 AliHLTComponentDataType AliHLTTPCNoiseMapComponent::GetOutputDataType() {
105 // see header file for class documentation
107 return kAliHLTDataTypeHistogram;
110 int AliHLTTPCNoiseMapComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) {
111 // see header file for class documentation
114 tgtList.push_back(kAliHLTDataTypeHistogram);
115 return tgtList.size();
118 void AliHLTTPCNoiseMapComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
119 // see header file for class documentation
125 AliHLTComponent* AliHLTTPCNoiseMapComponent::Spawn() {
126 // see header file for class documentation
128 return new AliHLTTPCNoiseMapComponent();
131 int AliHLTTPCNoiseMapComponent::DoInit( int argc, const char** argv ) {
132 // see header file for class documentation
139 TString configuration="";
141 for (int j=0; j<argc && iResult>=0; j++) {
144 if (!configuration.IsNull()) configuration+=" ";
145 configuration+=argument;
148 if (!configuration.IsNull()) {
149 iResult=Configure(configuration.Data());
151 iResult=Reconfigure(NULL, NULL);
156 if (!strcmp( argv[i], "-apply-noisemap")) {
157 fApplyNoiseMap = strtoul( argv[i+1], &cpErr ,0);
160 HLTError("Cannot convert apply-noisemap specifier '%s'.", argv[i+1]);
167 if (!strcmp( argv[i], "-plot-side-a")) {
168 fPlotSideA = strtoul( argv[i+1], &cpErr ,0);
171 HLTError("Cannot convert plot-side-a specifier '%s'.", argv[i+1]);
178 if (!strcmp( argv[i], "-plot-side-c")) {
179 fPlotSideC = strtoul( argv[i+1], &cpErr ,0);
182 HLTError("Cannot convert plot-side-c specifier '%s'.", argv[i+1]);
189 if (!strcmp( argv[i], "-reset-histograms")) {
190 fResetHistograms = strtoul( argv[i+1], &cpErr ,0);
193 HLTError("Cannot convert reset-histograms specifier '%s'.", argv[i+1]);
200 Logging(kHLTLogError, "HLT::TPCNoiseMap::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
206 AliHLTTPCNoiseMap *nm = AliHLTTPCNoiseMap::Instance();
208 HLTWarning("AliHLTTPCNoiseMap instance not existent.");
211 AliTPCCalPad *noisePad = nm->ReadNoiseMap(GetRunNo());
213 fHistCDBMap = noisePad->MakeHisto2D(1);
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
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)");
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)");
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);
240 //fHistSignal = new TH1F("fHistSignal", "signal distribution per pad",1024,0,1024);
242 // HLTDebug("using AliHLTTPCDigitReaderDecoder");
243 // pDigitReader = new AliHLTTPCDigitReaderDecoder(); // double-loop
244 // pDigitReader = new AliHLTTPCDigitReaderPacked();
250 int AliHLTTPCNoiseMapComponent::DoDeinit() {
251 // see header file for class documentation
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;
262 int AliHLTTPCNoiseMapComponent::DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& /*trigData*/){
263 // see header file for class documentation
265 //HLTInfo("--- Entering DoEvent() in TPCNoiseMap ---");
267 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )) return 0;
269 const AliHLTComponentBlockData *iter = NULL;
272 Int_t thissector, thisrow;
274 for(iter = GetFirstInputBlock(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC); iter != NULL; iter = GetNextInputBlock()){
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());
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());
287 if (iter->fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC)) continue;
289 UInt_t slice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
290 UInt_t partition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
292 fSpecification = iter->fSpecification;
294 AliHLTTPCDigitReader *pDigitReader = new AliHLTTPCDigitReaderDecoder;
296 pDigitReader->InitBlock(iter->fPtr,iter->fSize,partition,slice);
297 if(!pDigitReader) break;
299 //sprintf(name,"hMaxSignal_slice%d_partition%d", slice, partition);
300 //fHistMaxSignal = new TH2F(name,name,250,-250,250,250,-250,250);
302 while(pDigitReader->Next()){
303 //while( pDigitReader->NextChannel()) { // pad loop
305 fCurrentRow = pDigitReader->GetRow();
306 fCurrentRow += pDigitReader->GetRowOffset();
308 AliHLTTPCTransform::Slice2Sector(slice,fCurrentRow,thissector,thisrow);
309 AliHLTTPCTransform::Raw2Local(xyz,thissector,thisrow,pDigitReader->GetPad(),0);
311 if(slice>17) xyz[1] = (-1.0)*xyz[1];
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.
318 //AliHLTTPCTransform::Raw2Global(xyz,thissector,thisrow,pDigitReader->GetPad(),0);
319 // transformation from pad-row coordinates to global ones
320 // time info is not taken into account
322 // AliTPCCalROC *calRoc = noisePad->GetCalROC(thissector);
323 // calRoc->GetValue(thisrow,pDigitReader->GetPad());
325 //while( pDigitReader->NextBunch()) {
327 const UInt_t *bunchData = pDigitReader->GetSignals();
328 Float_t maxSignal = 0.;
329 Float_t totalSignal = 0.;
330 Float_t squaredSignal = 0.;
333 //fHistSignal = new TH1F("fHistSignal", "signal distribution per pad",1024,0,1024);
335 //fHistSignal->Reset();
336 Int_t time = pDigitReader->GetTime();
338 for(Int_t i=0;i<pDigitReader->GetBunchSize();i++){
340 if((Float_t)(bunchData[i])>maxSignal){ maxSignal = (Float_t)(bunchData[i]); }
341 totalSignal += (Float_t)bunchData[i];
342 squaredSignal += (Float_t)bunchData[i]*(Float_t)bunchData[i];
343 //fHistSignal->Fill(time+i, bunchData[i]);
344 } // end for loop over bunches
345 rms = TMath::Sqrt(squaredSignal/pDigitReader->GetBunchSize());
347 //} // end of inner while loop
349 fHistMaxSignal->Fill(xyz[0],xyz[1],maxSignal);
350 fHistTotSignal->Fill(xyz[0],xyz[1],totalSignal);
352 fHistPadRMS->Fill(xyz[0],xyz[1],rms);
354 //fHistPadRMS->Fill(xyz[0],xyz[1],fHistSignal->GetRMS());
355 //delete fHistSignal; fHistSignal = NULL;
357 if(fPlotSideA || fPlotSideC){
358 if(slice<18) fHistSideA->Fill(xyz[0],xyz[1],maxSignal);
359 else fHistSideC->Fill(xyz[0],xyz[1],maxSignal);
360 } // end if plotting sides
361 } // end of while loop over pads
363 pDigitReader->Reset();
365 } // end of for loop over data blocks
367 if(fResetHistograms) ResetHistograms();
374 void AliHLTTPCNoiseMapComponent::MakeHistosPublic() {
375 // see header file for class documentation
377 // TFile *outputfile = new TFile("test.root","RECREATE");
378 // fHistSignal->Write();
379 // outputfile->Save();
380 // outputfile->Close();
383 histos.Add(fHistMaxSignal);
384 histos.Add(fHistTotSignal);
385 histos.Add(fHistPadRMS);
386 histos.Add(fHistCDBMap);
387 //histos.Add(fHistSignal);
388 if(fPlotSideA) histos.Add(fHistSideA);
389 if(fPlotSideC) histos.Add(fHistSideC);
391 TIter iterator(&histos);
392 while(TObject *pObj=iterator.Next()){ PushBack(pObj, kAliHLTDataTypeHistogram|kAliHLTDataOriginTPC, fSpecification); }
394 //PushBack( (TObject*) &histos, kAliHLTDataTypeHistogram, fSpecification);
396 // if(fHistMaxSignal) delete fHistMaxSignal; fHistMaxSignal = NULL;
397 // if(fHistTotSignal) delete fHistTotSignal; fHistTotSignal = NULL;
398 // if(fHistPadRMS) delete fHistPadRMS; fHistPadRMS = NULL;
399 // if(fHistSideA) delete fHistSideA; fHistSideA = NULL;
400 // if(fHistSideC) delete fHistSideC; fHistSideC = NULL;
404 void AliHLTTPCNoiseMapComponent::ResetHistograms(){
405 // see header file for class documentation
407 //if(fHistPartition) fHistPartition->Reset();
408 if(fHistMaxSignal) fHistMaxSignal->Reset();
409 if(fHistTotSignal) fHistTotSignal->Reset();
410 if(fHistPadRMS) fHistPadRMS->Reset();
412 if(fHistSideA) fHistSideA->Reset();
413 if(fHistSideC) fHistSideC->Reset();
416 int AliHLTTPCNoiseMapComponent::Configure(const char* arguments) {
417 // see header file for class documentation
420 if (!arguments) return iResult;
421 HLTInfo("parsing configuration string \'%s\'", arguments);
423 TString allArgs=arguments;
427 TObjArray* pTokens=allArgs.Tokenize(" ");
429 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
430 argument=((TObjString*)pTokens->At(i))->GetString();
431 if (argument.IsNull()) continue;
433 if (argument.CompareTo("-apply-noisemap")==0) {
434 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
435 HLTInfo("got \'-apply-noisemap\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
438 else if (argument.CompareTo("-plot-side-c")==0) {
439 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
440 HLTInfo("got \'-plot-side-c\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
443 else if (argument.CompareTo("-plot-side-a")==0) {
444 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
445 HLTInfo("got \'-plot-side-a\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
448 else if(argument.CompareTo("-reset-histograms")==0){
449 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
450 HLTInfo("got \'-reset-histograms\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
454 HLTError("unknown argument %s", argument.Data());
465 HLTError("missing parameter for argument %s", argument.Data());
471 int AliHLTTPCNoiseMapComponent::Reconfigure(const char* cdbEntry, const char* chainId) {
472 // see header file for class documentation
474 const char* path="HLT/ConfigTPC/TPCNoiseMapComponent";
475 const char* defaultNotify="";
478 defaultNotify = "(manual operator entry)";
482 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>" );
484 AliCDBPath argumentPath(path);
485 AliCDBStorage *stor = AliCDBManager::Instance()->GetDefaultStorage();
488 Int_t version = stor->GetLatestVersion(path, GetRunNo());
489 Int_t subVersion = stor->GetLatestSubVersion(path, GetRunNo(), version);
490 AliCDBEntry *pEntry = stor->Get(argumentPath,GetRunNo(), version, subVersion);
493 TObjString* pString = dynamic_cast<TObjString*>(pEntry->GetObject());
495 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
496 iResult = Configure(pString->GetString().Data());
497 } // if pString is valid
499 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
501 } // if pEntry is valid
503 HLTError("cannot fetch object \"%s\" from CDB", path);
505 } // if stor is valid
506 } // if path is valid