1 /**************************************************************************
2 * This file is property of and copyright by the Experimental Nuclear *
3 * Physics Group, Dep. of Physics *
4 * University of Oslo, Norway, 2007 *
6 * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.*
7 * Contributors are mentioned in the code where appropriate. *
8 * Please report bugs to perthi@fys.uio.no *
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 #include "AliHLTPHOSRawAnalyzer.h"
20 #include "AliHLTPHOSRawAnalyzerComponent.h"
21 #include "AliHLTPHOSRcuCellEnergyDataStruct.h"
22 #include "AliHLTPHOSMapper.h"
23 #include "AliHLTPHOSSanityInspector.h"
24 #include "AliHLTPHOSBaseline.h"
27 #include "TClonesArray.h"
29 #include "AliAltroDecoder.h" // decoder for altro payload
30 #include "AliAltroData.h" // container for altro payload
31 #include "AliAltroBunch.h" // container for altro bunches
34 AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent():AliHLTPHOSRcuProcessor(),
36 fSendChannelData(kFALSE),
39 fSanityInspectorPtr(0),
40 fUseBaselineSubtraction(false),
45 fDoPushRawData(false),
49 fDigitContainerPtr(0),
50 fDoSelectiveReadOut(false),
51 fSelectedChannelsList(0),
52 fDoCheckDataSize(false),
55 //fRawMemoryReader(0), fPHOSRawStream(0)
58 fMapperPtr = new AliHLTPHOSMapper();
59 fAltroDataPtr = new AliAltroData();
60 fAltroBunchPtr = new AliAltroBunch();
61 fDecoderPtr = new AliAltroDecoder();
62 fSanityInspectorPtr = new AliHLTPHOSSanityInspector();
63 fSelectedChannelsList = new AliHLTUInt16_t[N_XCOLUMNS_RCU*N_ZROWS_RCU*N_GAINS];
67 AliHLTPHOSRawAnalyzerComponent::~AliHLTPHOSRawAnalyzerComponent()
75 AliHLTPHOSRawAnalyzerComponent::Deinit()
90 delete fAltroBunchPtr;
98 Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSRawAnalyzerComponen Deinit");
104 AliHLTPHOSRawAnalyzerComponent::GetComponentID()
107 return "AliPhosTestRaw";
112 AliHLTPHOSRawAnalyzerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
116 list.push_back( AliHLTPHOSDefinitions::fgkDDLPackedRawDataType | kAliHLTDataOriginPHOS);
119 AliHLTComponentDataType
120 AliHLTPHOSRawAnalyzerComponent::GetOutputDataType()
123 return kAliHLTMultipleDataType;
124 // return AliHLTPHOSDefinitions::fgkDigitDataType;
128 AliHLTPHOSRawAnalyzerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
131 // see header file for class documentation
133 tgtList.push_back(AliHLTPHOSDefinitions::fgkCellEnergyDataType);
134 tgtList.push_back(kAliHLTDataTypeHwAddr16);
135 return tgtList.size();
139 AliHLTPHOSRawAnalyzerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
150 AliHLTPHOSRawAnalyzerComponent::FillDataArray(UInt_t *data, const AliAltroData * /*altrodataptr */, const int /* channel */)
152 ResetDataPtr(0, ALTRO_MAX_SAMPLES);
153 bool islastbunch = true;
155 while( fAltroDataPtr->NextBunch(fAltroBunchPtr) == true)
157 const UInt_t *tmpdata = fAltroBunchPtr->GetData();
159 if(islastbunch == true)
161 data[0] = fAltroBunchPtr->GetEndTimeBin();
165 int tmpstartbin = fAltroBunchPtr->GetStartTimeBin();
166 int tmpendbin = fAltroBunchPtr->GetEndTimeBin();
167 int tmplength = tmpendbin - tmpstartbin;
169 for(int i = 0; i < tmplength ; i++)
171 data[i+tmpstartbin] = tmpdata[i];
177 cout <<__FILE__ <<" : " <<__LINE__ << "the resulting array is"<<endl;
179 for(int i=0; i< data[0]; i++)
181 if(i != 0 && i %16 == 0)
185 cout <<data[i] << "\t" ;
193 AliHLTPHOSRawAnalyzerComponent::GetFirstBunch(AliAltroData * /*altrodata */, AliAltroBunch * /*altrobunch */)
195 while( fAltroDataPtr->NextBunch(fAltroBunchPtr) == true)
203 AliHLTPHOSRawAnalyzerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& /*trigData*/,
204 AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
206 // cout << "Event" << fPhosEventCount << endl;
211 Float_t baseline = 0;
212 AliHLTUInt8_t* outBPtr;
214 const AliHLTComponentBlockData* iter = NULL;
216 Int_t *rawDataBufferPos = (Int_t *)outputPtr;
218 UInt_t specification = 0;
219 bool droppedRaw = true;
220 if(fDoPushRawData) {droppedRaw = false;}
222 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
225 if ( iter->fDataType != AliHLTPHOSDefinitions::fgkDDLPackedRawDataType )
230 Int_t tmpChannelCnt = 0;
234 mysize += sizeof(AliHLTPHOSRcuCellEnergyDataStruct);
239 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", tSize, size);
243 specification = specification|iter->fSpecification;
244 fDecoderPtr->SetMemory(reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize);
245 fDecoderPtr->Decode();
246 fOutPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)outBPtr;
247 fOutPtr->fRcuX = fRcuX;
248 fOutPtr->fRcuZ = fRcuZ;
249 fOutPtr->fModuleID =fModuleID;
251 rawDataBufferPos += (tSize)/sizeof(Int_t);
253 while( fDecoderPtr->NextChannel(fAltroDataPtr) == true )
255 FillDataArray(fTmpChannelData, fAltroDataPtr, tmpChannelCnt);
257 if( fAltroDataPtr->GetDataSize() != 0 )
259 GetFirstBunch(fAltroDataPtr, fAltroBunchPtr);
260 nSamples = fAltroBunchPtr->GetBunchSize();
261 // cout <<__FILE__ <<" : " <<__LINE__ << ", the size of the first bunch is " << nSamples <<endl;
262 crazyness = fSanityInspectorPtr->CheckInsanity((const UInt_t*)fAltroBunchPtr->GetData(), (const Int_t)(fAltroBunchPtr->GetBunchSize()));
263 fAnalyzerPtr->SetData(fAltroBunchPtr->GetData(), fAltroBunchPtr->GetBunchSize());
264 fAnalyzerPtr->Evaluate(0, fAltroBunchPtr->GetBunchSize());
265 fOutPtr->fValidData[tmpChannelCnt].fZ = fMapperPtr->fHw2geomapPtr[fAltroDataPtr->GetHadd()].fZRow;
266 fOutPtr->fValidData[tmpChannelCnt].fX = fMapperPtr->fHw2geomapPtr[fAltroDataPtr->GetHadd()].fXCol;
267 fOutPtr->fValidData[tmpChannelCnt].fGain = fMapperPtr->fHw2geomapPtr[fAltroDataPtr->GetHadd()].fGain;
269 if(fUseBaselineSubtraction)
271 baseline = fBaselines[fOutPtr->fValidData[tmpChannelCnt].fX][fOutPtr->fValidData[tmpChannelCnt].fZ][ fOutPtr->fValidData[tmpChannelCnt].fGain];
274 fOutPtr->fValidData[tmpChannelCnt].fEnergy = (float)fAnalyzerPtr->GetEnergy() - baseline;
275 fOutPtr->fValidData[tmpChannelCnt].fTime = (float)fAnalyzerPtr->GetTiming();
276 fOutPtr->fValidData[tmpChannelCnt].fCrazyness = (int)crazyness;
278 if(fDoPushRawData == true && droppedRaw == false)
280 int tmpsize = fTmpChannelData[0];
281 // cout << __FILE__ << ":" << __LINE__ << "channel = " << tmpChannelCnt << " size ="<< tmpsize << endl;
282 mysize += (tmpsize + 1)*sizeof(Int_t);
283 tSize += (tmpsize + 1)*sizeof(Int_t);;
287 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes. Dropping raw data.", tSize, size);
293 *rawDataBufferPos = tmpsize;
295 for(int sample = 0; sample < tmpsize; sample++)
298 *(rawDataBufferPos) = fTmpChannelData[sample];
308 if(fDoPushRawData && droppedRaw == false)
310 fOutPtr->fHasRawData = true;
314 fOutPtr->fHasRawData = false;
317 fOutPtr->fCnt = tmpChannelCnt;
318 fOutPtr->fSize = mysize;
319 AliHLTComponentBlockData bdCellEnergy;
320 FillBlockData( bdCellEnergy );
321 bdCellEnergy.fOffset = offset;
322 bdCellEnergy.fSize = mysize;
323 bdCellEnergy.fDataType = AliHLTPHOSDefinitions::fgkCellEnergyDataType;
324 bdCellEnergy.fSpecification = specification;
325 outputBlocks.push_back( bdCellEnergy );
330 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRawAnalyzerComponent::DoEvent", "Too much data",
331 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
338 // *rawDataBufferPos = 0;
346 AliHLTPHOSRawAnalyzerComponent::DoInit( int argc, const char** argv )
348 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
349 // fAnalyzerPtr->SetCorrectBaselineUsingFirstFiveSamples();
350 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
353 //See base class for documentation
354 fSendChannelData = kFALSE;
358 const int nSigmas = 3;
359 fMapperPtr = new AliHLTPHOSMapper();
361 if(fMapperPtr->GetIsInitializedMapping() == false)
363 Logging(kHLTLogFatal, __FILE__ , IntToChar( __LINE__ ) , "AliHLTPHOSMapper::Could not initial mapping from file %s, aborting", fMapperPtr->GetFilePath());
367 char tmpbaselinfile[256];
368 if(fUtilitiesPtr->ScanSingleNameArgument(argc, argv, "-baselinefile", tmpbaselinfile) == true )
370 SetBaselines(tmpbaselinfile);
373 char tmpSelectiveThresholdfile[256];
374 if(fUtilitiesPtr->ScanSingleNameArgument(argc, argv, "-baselinefile", tmpSelectiveThresholdfile) == true )
376 fDoSelectiveReadOut = true;
377 SetSelectiveReadOutThresholds(tmpSelectiveThresholdfile, nSigmas);
380 //fDoSelectiveReadOut = fUtilitiesPtr->ScanSingleNameArgument(argc, argv, "-selectivereadout");
382 fDoPushRawData = fUtilitiesPtr->ScanSingleArgument(argc, argv, "-pushrawdata");
384 fDoCheckDataSize = fUtilitiesPtr->ScanSingleArgument(argc, argv, "-checkdatasize");
386 iResult = ScanArguments(argc, argv);
392 AliHLTPHOSRawAnalyzerComponent::Reset(AliHLTPHOSRcuCellEnergyDataStruct* /* cellDataPtr */)
394 ResetDataPtr(0, ALTRO_MAX_SAMPLES);
399 AliHLTPHOSRawAnalyzerComponent::ResetDataPtr(int startindex, int sampleCnt)
402 for(int i = startindex ; i< sampleCnt; i++)
404 fTmpChannelData[i] = 0;
410 AliHLTPHOSRawAnalyzerComponent::SetBaselines(const char* file)
413 fUseBaselineSubtraction = true;
414 AliHLTPHOSBaseline *baseline = 0;
415 TFile *baselineFile = TFile::Open(file);
416 TTree *baselineTree = (TTree*)baselineFile->Get("baselineTree");
417 TClonesArray *baselineArray = new TClonesArray("AliHLTPHOSBaseline", 7168);
418 baselineTree->SetBranchAddress("Baselines", &baselineArray);
419 baselineTree->GetEntry(0);
420 for(Int_t i = 0; i < baselineArray->GetEntriesFast(); i++)
422 baseline = (AliHLTPHOSBaseline*)baselineArray->At(i);
423 if((baseline->GetX() < (Int_t)((fRcuX + 1)*N_XCOLUMNS_RCU)) && (baseline->GetX() >= (Int_t)(fRcuX*N_XCOLUMNS_RCU)))
425 if((baseline->GetZ() < (Int_t)((fRcuZ + 1)*N_ZROWS_RCU)) && (baseline->GetZ() >= (Int_t)(fRcuZ*N_ZROWS_RCU)))
427 fBaselines[baseline->GetX() - fRcuX*N_XCOLUMNS_RCU][baseline->GetZ() - fRcuZ*N_ZROWS_RCU][baseline->GetGain()] = baseline->GetBaseline();
431 baselineFile->Close();
437 AliHLTPHOSRawAnalyzerComponent::SetSelectiveReadOutThresholds(const char* filepath, Int_t nSigmas)
439 //See header file for documentation
440 TFile *histFile = new TFile(filepath);
441 TH2F *lgHist = (TH2F*)histFile->Get("RMSLGMapHist");
442 TH2F *hgHist = (TH2F*)histFile->Get("RMSHGMapHist");
444 for(int x = 0; x < N_XCOLUMNS_MOD; x++)
446 for(int z = 0; z < N_ZROWS_MOD; z++)
448 fSelectiveReadOutThresholds[x][z][LOW_GAIN] = lgHist->GetBinContent(x, z) * nSigmas;
449 fSelectiveReadOutThresholds[x][z][HIGH_GAIN] = hgHist->GetBinContent(x, z) * nSigmas;