3 /**************************************************************************
4 * This file is property of and copyright by the Experimental Nuclear *
5 * Physics Group, Dep. of Physics *
6 * University of Oslo, Norway, 2007 *
8 * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.*
9 * Contributors are mentioned in the code where appropriate. *
10 * Please report bugs to perthi@fys.uio.no *
12 * Permission to use, copy, modify and distribute this software and its *
13 * documentation strictly for non-commercial purposes is hereby granted *
14 * without fee, provided that the above copyright notice appears in all *
15 * copies and that both the copyright notice and this permission notice *
16 * appear in the supporting documentation. The authors make no claims *
17 * about the suitability of this software for any purpose. It is *
18 * provided "as is" without express or implied warranty. *
19 **************************************************************************/
21 #include "AliHLTPHOSRawAnalyzer.h"
22 #include "AliHLTPHOSRawAnalyzerComponent.h"
23 #include "AliHLTPHOSRcuCellEnergyDataStruct.h"
24 #include "AliHLTPHOSMapper.h"
25 #include "AliHLTPHOSSanityInspector.h"
28 #include "TClonesArray.h"
30 #include "AliAltroDecoder.h" // decoder for altro payload
31 #include "AliAltroData.h" // container for altro payload
32 #include "AliAltroBunch.h" // container for altro bunches
35 AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent():AliHLTPHOSRcuProcessor(),
37 fSendChannelData(kFALSE),
40 fSanityInspectorPtr(0),
41 fUseBaselineSubtraction(false),
45 fDoPushRawData(false),
48 fDigitContainerPtr(0),
49 fDoSelectiveReadOut(false),
50 fSelectedChannelsList(0),
51 fDoCheckDataSize(false),
54 //fRawMemoryReader(0), fPHOSRawStream(0)
57 fMapperPtr = new AliHLTPHOSMapper();
58 fAltroDataPtr = new AliAltroData();
59 fAltroBunchPtr = new AliAltroBunch();
60 fDecoderPtr = new AliAltroDecoder();
61 fSanityInspectorPtr = new AliHLTPHOSSanityInspector();
62 fSelectedChannelsList = new AliHLTUInt16_t[NXCOLUMNSRCU*NZROWSRCU*NGAINS];
66 AliHLTPHOSRawAnalyzerComponent::~AliHLTPHOSRawAnalyzerComponent()
74 AliHLTPHOSRawAnalyzerComponent::Deinit()
89 delete fAltroBunchPtr;
103 AliHLTPHOSRawAnalyzerComponent::GetComponentID()
106 return "AliPhosTestRaw";
111 AliHLTPHOSRawAnalyzerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
115 list.push_back( AliHLTPHOSDefinitions::fgkDDLPackedRawDataType | kAliHLTDataOriginPHOS);
118 AliHLTComponentDataType
119 AliHLTPHOSRawAnalyzerComponent::GetOutputDataType()
122 return kAliHLTMultipleDataType;
123 // return AliHLTPHOSDefinitions::fgkDigitDataType;
127 AliHLTPHOSRawAnalyzerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
130 // see header file for class documentation
132 tgtList.push_back(AliHLTPHOSDefinitions::fgkCellEnergyDataType);
133 tgtList.push_back(kAliHLTDataTypeHwAddr16);
134 return tgtList.size();
138 AliHLTPHOSRawAnalyzerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
149 AliHLTPHOSRawAnalyzerComponent::FillDataArray(UInt_t *data, const AliAltroData */*altrodataptr*/, const int /*channel*/)
151 ResetDataPtr(0, ALTROMAXSAMPLES);
152 bool islastbunch = true;
154 while( fAltroDataPtr->NextBunch(fAltroBunchPtr) == true)
156 const UInt_t *tmpdata = fAltroBunchPtr->GetData();
158 if(islastbunch == true)
160 data[0] = fAltroBunchPtr->GetEndTimeBin();
164 int tmpstartbin = fAltroBunchPtr->GetStartTimeBin();
165 int tmpendbin = fAltroBunchPtr->GetEndTimeBin();
166 int tmplength = tmpendbin - tmpstartbin;
168 for(int i = 0; i < tmplength ; i++)
170 data[i+tmpstartbin] = tmpdata[i];
176 cout <<__FILE__ <<" : " <<__LINE__ << "the resulting array is"<<endl;
178 for(int i=0; i< data[0]; i++)
180 if(i != 0 && i %16 == 0)
184 cout <<data[i] << "\t" ;
192 AliHLTPHOSRawAnalyzerComponent::GetFirstBunch(AliAltroData */*altrodata*/, AliAltroBunch */*altrobunch*/)
194 while( fAltroDataPtr->NextBunch(fAltroBunchPtr) == true)
202 AliHLTPHOSRawAnalyzerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& /*trigData*/,
203 AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
205 // cout << "Event" << fPhosEventCount << endl;
210 Float_t baseline = 0;
211 AliHLTUInt8_t* outBPtr;
213 const AliHLTComponentBlockData* iter = NULL;
215 Int_t *rawDataBufferPos = (Int_t *)outputPtr;
217 UInt_t specification = 0;
218 bool droppedRaw = true;
219 if(fDoPushRawData) {droppedRaw = false;}
221 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
224 if ( iter->fDataType != AliHLTPHOSDefinitions::fgkDDLPackedRawDataType )
229 Int_t tmpChannelCnt = 0;
233 mysize += sizeof(AliHLTPHOSRcuCellEnergyDataStruct);
238 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", tSize, size);
242 specification = specification|iter->fSpecification;
243 fDecoderPtr->SetMemory(reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize);
244 fDecoderPtr->Decode();
245 fOutPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)outBPtr;
246 fOutPtr->fRcuX = fRcuX;
247 fOutPtr->fRcuZ = fRcuZ;
248 fOutPtr->fModuleID =fModuleID;
250 rawDataBufferPos += (tSize)/sizeof(Int_t);
252 while( fDecoderPtr->NextChannel(fAltroDataPtr) == true )
254 FillDataArray(fTmpChannelData, fAltroDataPtr, tmpChannelCnt);
256 if( fAltroDataPtr->GetDataSize() != 0 )
258 GetFirstBunch(fAltroDataPtr, fAltroBunchPtr);
259 nSamples = fAltroBunchPtr->GetBunchSize();
260 // cout <<__FILE__ <<" : " <<__LINE__ << ", the size of the first bunch is " << nSamples <<endl;
261 crazyness = fSanityInspectorPtr->CheckInsanity((const UInt_t*)fAltroBunchPtr->GetData(), (const Int_t)(fAltroBunchPtr->GetBunchSize()));
262 fAnalyzerPtr->SetData(fAltroBunchPtr->GetData(), fAltroBunchPtr->GetBunchSize());
263 fAnalyzerPtr->Evaluate(0, fAltroBunchPtr->GetBunchSize());
264 fOutPtr->fValidData[tmpChannelCnt].fZ = fMapperPtr->fHw2geomapPtr[fAltroDataPtr->GetHadd()].fZRow;
265 fOutPtr->fValidData[tmpChannelCnt].fX = fMapperPtr->fHw2geomapPtr[fAltroDataPtr->GetHadd()].fXCol;
266 fOutPtr->fValidData[tmpChannelCnt].fGain = fMapperPtr->fHw2geomapPtr[fAltroDataPtr->GetHadd()].fGain;
268 if(fUseBaselineSubtraction)
270 baseline = fBaselines[fOutPtr->fValidData[tmpChannelCnt].fX][fOutPtr->fValidData[tmpChannelCnt].fZ][ fOutPtr->fValidData[tmpChannelCnt].fGain];
273 fOutPtr->fValidData[tmpChannelCnt].fEnergy = (float)fAnalyzerPtr->GetEnergy() - baseline;
274 fOutPtr->fValidData[tmpChannelCnt].fTime = (float)fAnalyzerPtr->GetTiming();
275 fOutPtr->fValidData[tmpChannelCnt].fCrazyness = (int)crazyness;
277 if(fDoPushRawData == true && droppedRaw == false)
279 int tmpsize = fTmpChannelData[0];
280 // cout << __FILE__ << ":" << __LINE__ << "channel = " << tmpChannelCnt << " size ="<< tmpsize << endl;
281 mysize += (tmpsize + 1)*sizeof(Int_t);
282 tSize += (tmpsize + 1)*sizeof(Int_t);;
286 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes. Dropping raw data.", tSize, size);
292 *rawDataBufferPos = tmpsize;
294 for(int sample = 0; sample < tmpsize; sample++)
297 *(rawDataBufferPos) = fTmpChannelData[sample];
307 if(fDoPushRawData && droppedRaw == false)
309 fOutPtr->fHasRawData = true;
313 fOutPtr->fHasRawData = false;
316 fOutPtr->fCnt = tmpChannelCnt;
317 fOutPtr->fSize = mysize;
318 AliHLTComponentBlockData bdCellEnergy;
319 FillBlockData( bdCellEnergy );
320 bdCellEnergy.fOffset = offset;
321 bdCellEnergy.fSize = mysize;
322 bdCellEnergy.fDataType = AliHLTPHOSDefinitions::fgkCellEnergyDataType;
323 bdCellEnergy.fSpecification = specification;
324 outputBlocks.push_back( bdCellEnergy );
329 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRawAnalyzerComponent::DoEvent", "Too much data",
330 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
337 // *rawDataBufferPos = 0;
345 AliHLTPHOSRawAnalyzerComponent::DoInit( int argc, const char** argv )
347 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
348 // fAnalyzerPtr->SetCorrectBaselineUsingFirstFiveSamples();
349 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
352 //See base class for documentation
353 fSendChannelData = kFALSE;
357 const int nSigmas = 3;
358 fMapperPtr = new AliHLTPHOSMapper();
360 if(fMapperPtr->GetIsInitializedMapping() == false)
362 Logging(kHLTLogFatal, __FILE__ , IntToChar( __LINE__ ) , "AliHLTPHOSMapper::Could not initial mapping from file %s, aborting", fMapperPtr->GetFilePath());
366 char tmpbaselinfile[256];
367 if(fUtilitiesPtr->ScanSingleNameArgument(argc, argv, "-baselinefile", tmpbaselinfile) == true )
369 HLTWarning("baseline file no longer supported");
371 // SetBaselines(tmpbaselinfile);
374 char tmpSelectiveThresholdfile[256];
375 if(fUtilitiesPtr->ScanSingleNameArgument(argc, argv, "-baselinefile", tmpSelectiveThresholdfile) == true )
377 fDoSelectiveReadOut = true;
378 SetSelectiveReadOutThresholds(tmpSelectiveThresholdfile, nSigmas);
381 //fDoSelectiveReadOut = fUtilitiesPtr->ScanSingleNameArgument(argc, argv, "-selectivereadout");
383 fDoPushRawData = fUtilitiesPtr->ScanSingleArgument(argc, argv, "-pushrawdata");
385 fDoCheckDataSize = fUtilitiesPtr->ScanSingleArgument(argc, argv, "-checkdatasize");
387 iResult = ScanArguments(argc, argv);
393 AliHLTPHOSRawAnalyzerComponent::Reset(AliHLTPHOSRcuCellEnergyDataStruct* /*cellDataPtr*/)
395 ResetDataPtr(0, ALTROMAXSAMPLES);
400 AliHLTPHOSRawAnalyzerComponent::ResetDataPtr(int startindex, int sampleCnt)
403 for(int i = startindex ; i< sampleCnt; i++)
405 fTmpChannelData[i] = 0;
411 AliHLTPHOSRawAnalyzerComponent::SetBaselines(const char* /*file*/)
414 // fUseBaselineSubtraction = true;
415 // AliHLTPHOSBaseline *baseline = 0;
416 // TFile *baselineFile = TFile::Open(file);
417 // TTree *baselineTree = (TTree*)baselineFile->Get("baselineTree");
418 // TClonesArray *baselineArray = new TClonesArray("AliHLTPHOSBaseline", 7168);
419 // baselineTree->SetBranchAddress("Baselines", &baselineArray);
420 // baselineTree->GetEntry(0);
421 // for(Int_t i = 0; i < baselineArray->GetEntriesFast(); i++)
423 // baseline = (AliHLTPHOSBaseline*)baselineArray->At(i);
424 // if((baseline->GetX() < (Int_t)((fRcuX + 1)*N_XCOLUMNS_RCU)) && (baseline->GetX() >= (Int_t)(fRcuX*N_XCOLUMNS_RCU)))
426 // if((baseline->GetZ() < (Int_t)((fRcuZ + 1)*N_ZROWS_RCU)) && (baseline->GetZ() >= (Int_t)(fRcuZ*N_ZROWS_RCU)))
428 // fBaselines[baseline->GetX() - fRcuX*N_XCOLUMNS_RCU][baseline->GetZ() - fRcuZ*N_ZROWS_RCU][baseline->GetGain()] = baseline->GetBaseline();
432 // baselineFile->Close();
433 // delete baselineFile;
438 AliHLTPHOSRawAnalyzerComponent::SetSelectiveReadOutThresholds(const char* filepath, Int_t nSigmas)
440 //See header file for documentation
441 TFile *histFile = new TFile(filepath);
442 TH2F *lgHist = (TH2F*)histFile->Get("RMSLGMapHist");
443 TH2F *hgHist = (TH2F*)histFile->Get("RMSHGMapHist");
445 for(int x = 0; x < NXCOLUMNSMOD; x++)
447 for(int z = 0; z < NZROWSMOD; z++)
449 fSelectiveReadOutThresholds[x][z][LOWGAIN] = lgHist->GetBinContent(x, z) * nSigmas;
450 fSelectiveReadOutThresholds[x][z][HIGHGAIN] = hgHist->GetBinContent(x, z) * nSigmas;