#include "AliPHOSPulseGenerator.h"
#include "AliRunLoader.h"
#include "AliStack.h"
-#include "AliCaloRawStream.h"
+#include "AliPHOSRawDecoder.h"
#include "AliRawReaderFile.h"
#include "AliLog.h"
#include "AliCDBLocal.h"
// Reimplemented by Boris Polichtchouk (Jul 2006)
// to make it working with the Jul-Aug 2006 beam test data.
- AliCaloRawStream in(rawReader,"PHOS");
- in.SetOldRCUFormat(isOldRCUFormat);
-
- // Create a shaper pulse object
- AliPHOSPulseGenerator pulse;
- TF1 * signalF = new TF1("signal", AliPHOSPulseGenerator::RawResponseFunction, 0, pulse.GetRawFormatTimeMax(), 4);
- signalF->SetParNames("Charge", "Gain", "Amplitude", "TimeZero") ;
+ //Create raw decoder.
+
+ AliPHOSRawDecoder dc(rawReader);
+ dc.SetOldRCUFormat(isOldRCUFormat);
+ dc.SubtractPedestals(kTRUE);
Int_t relId[4], absId =0;
Bool_t lowGainFlag = kFALSE ;
TClonesArray * digits = Digits() ;
digits->Clear() ;
- Int_t iBin = 0;
Int_t iDigit = 0 ;
- Double_t energyHG = 0. ;
- Double_t energyLG = 0. ;
- Double_t startTime= 0. ;
Double_t time = 0. ;
Int_t iOldDigit;
Bool_t seen;
- TH1F* hLowGain = 0;
- TH1F* hHighGain = 0;
- while ( in.Next() ) { // PHOS entries loop
+ while (dc.NextDigit()) {
- lowGainFlag = in.IsLowGain();
+ lowGainFlag = dc.IsLowGain();
+ time = dc.GetTime();
- // (Re)create histograms to store samples
+ relId[0] = dc.GetModule();
+ relId[1] = 0;
+ relId[2] = dc.GetRow();
+ relId[3] = dc.GetColumn();
- if (lowGainFlag) {
- if(!hLowGain)
- hLowGain = new TH1F("hLowGain","Low gain",in.GetTimeLength(),0,in.GetTimeLength());
- else
- if(hLowGain->GetNbinsX() != in.GetTimeLength()) {
- delete hLowGain;
- hLowGain = new TH1F("hLowGain","Low gain",in.GetTimeLength(),0,in.GetTimeLength());
- }
- } else {
- if(!hHighGain)
- hHighGain = new TH1F("hHighGain","High gain",in.GetTimeLength(),0,in.GetTimeLength());
- else
- if(hHighGain->GetNbinsX() != in.GetTimeLength()) {
- delete hHighGain;
- hHighGain = new TH1F("hHighGain","High gain",in.GetTimeLength(),0,in.GetTimeLength());
- }
- }
+ if(!PHOSGeometry()) AliFatal("Couldn't find PHOSGeometry!");
+ PHOSGeometry()->RelToAbsNumbering(relId, absId);
+ AliDebug(2,Form("relId=(mod,row,col)=(%d,%d,%d), absId=%d\n\n",
+ relId[0],relId[2],relId[3],absId));
- // Fill histograms with samples
- if(lowGainFlag)
- hLowGain ->SetBinContent(in.GetTimeLength()-iBin-1,in.GetSignal());
- else {
- hHighGain->SetBinContent(in.GetTimeLength()-iBin-1,in.GetSignal());
- }
+ // Add low gain digit only
+ //if the high gain digit does not exist in the digits array
- iBin++;
-
- // Fit the full sample
- if(iBin==in.GetTimeLength()) {
- iBin=0;
-
- // Temporarily we do not fit the sample graph, but
- // take the energy from the graph maximum, and the pedestal from the 0th point
- // 30 Aug 2006
-
- //FitRaw(lowGainFlag, hLowGain, hHighGain, signalF, energy, time);
-
- // Time is not evaluated for the moment (12.01.2007).
- // Take is as a first time bin multiplied by the sample tick time
- time = pulse.GetRawFormatTimeTrigger() * in.GetTime();
-
- if(lowGainFlag) {
- energyLG = hLowGain ->GetMaximum(); // "digit amplitude"
-// energyLG -= hLowGain ->GetBinContent(0); // "pedestal subtraction"
- energyLG *= pulse.GetRawFormatHighLowGainFactor(); // *16
- if(AliLog::GetGlobalDebugLevel()>3) {
- AliDebug(4,Form("----Printing hLowGain: ----\n")) ;
- hLowGain ->Print("all");
+ seen = kFALSE;
+
+ if(lowGainFlag) {
+ for (iOldDigit=iDigit-1; iOldDigit>=0; iOldDigit--) {
+ if ((dynamic_cast<AliPHOSDigit*>(digits->At(iOldDigit)))->GetId() == absId) {
+ seen = kTRUE;
+ break;
}
- if(AliLog::GetGlobalDebugLevel()>2)
- AliDebug(2,Form("(mod,col,row)=(%d,%d,%d), low gain energy=%f, time=%g\n\n",
- in.GetModule(),in.GetColumn(),in.GetRow(),energyLG,time));
}
-
- else {
- energyHG = hHighGain->GetMaximum(); // "digit amplitude"
-// energyHG -= hHighGain->GetBinContent(0); // "pedestal subtraction"
- if(AliLog::GetGlobalDebugLevel()>3) {
- AliDebug(4,Form("----Printing hHighGain: ----\n"));
- hHighGain->Print("all");
- }
- if(AliLog::GetGlobalDebugLevel()>2)
- AliDebug(2,Form("(mod,col,row)=(%d,%d,%d), high gain energy=%f, time=%g\n\n",
- in.GetModule(),in.GetColumn(),in.GetRow(),energyHG,time));
+ if (!seen) {
+ new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)dc.GetEnergy(),time);
+ iDigit++;
}
+ }
- relId[0] = in.GetModule()+1;
- relId[1] = 0;
- relId[2] = in.GetRow() +1;
- relId[3] = in.GetColumn()+1;
- if(!PHOSGeometry()) AliFatal("Couldn't find PHOSGeometry!");
- PHOSGeometry()->RelToAbsNumbering(relId, absId);
-
- AliDebug(2,Form("relId=(mod,row,col)=(%d,%d,%d), absId=%d\n\n",
- relId[0],relId[2],relId[3],absId));
-
- // Add low gain digit only if the high gain digit does not exist in the digits array
- seen = kFALSE;
- if(lowGainFlag) {
- for (iOldDigit=iDigit-1; iOldDigit>=0; iOldDigit--) {
- if ((dynamic_cast<AliPHOSDigit*>(digits->At(iOldDigit)))->GetId() == absId) {
- seen = kTRUE;
- break;
- }
- }
- if (!seen) {
- new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)energyLG,time);
- iDigit++;
+ // Add high gain digit only if it is not saturated;
+ // replace low gain digit by a high gain one
+ else {
+ if (dc.GetEnergy() >= 1023) continue;
+ for (iOldDigit=iDigit-1; iOldDigit>=0; iOldDigit--) {
+ if ((dynamic_cast<AliPHOSDigit*>(digits->At(iOldDigit)))->GetId() == absId) {
+ digits->RemoveAt(iOldDigit);
+ new((*digits)[iOldDigit]) AliPHOSDigit(-1,absId,(Float_t)dc.GetEnergy(),time);
+ seen = kTRUE;
+ break;
}
- energyLG = 0. ;
}
- // Add high gain digit only if it is not saturated;
- // replace low gain digit by a high gain one
- else {
- if (energyHG >= 1023) continue;
- for (iOldDigit=iDigit-1; iOldDigit>=0; iOldDigit--) {
- if ((dynamic_cast<AliPHOSDigit*>(digits->At(iOldDigit)))->GetId() == absId) {
- digits->RemoveAt(iOldDigit);
- new((*digits)[iOldDigit]) AliPHOSDigit(-1,absId,(Float_t)energyHG,time);
- seen = kTRUE;
- break;
- }
- }
- if (!seen) {
- new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)energyHG,time);
- iDigit++;
- }
- energyHG = 0. ;
+ if (!seen) {
+ new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)dc.GetEnergy(),time);
+ iDigit++;
}
}
+
+
}
-
- // PHOS entries loop
-
+
digits->Compress() ;
digits->Sort() ;
AliDebug(1,Form("Digit with max. energy: modMax %d colMax %d rowMax %d eMax %f\n\n",
modMax,colMax,rowMax,eMax));
- delete signalF ;
- delete hHighGain;
- delete hLowGain;
-
return digits->GetEntriesFast() ;
}
--- /dev/null
+/**************************************************************************
+ * Copyright(c) 2007, ALICE Experiment at CERN, All rights reserved. *
+ * *
+ * Author: The ALICE Off-line Project. *
+ * Contributors are mentioned in the code where appropriate. *
+ * *
+ * Permission to use, copy, modify and distribute this software and its *
+ * documentation strictly for non-commercial purposes is hereby granted *
+ * without fee, provided that the above copyright notice appears in all *
+ * copies and that both the copyright notice and this permission notice *
+ * appear in the supporting documentation. The authors make no claims *
+ * about the suitability of this software for any purpose. It is *
+ * provided "as is" without express or implied warranty. *
+ **************************************************************************/
+
+// This class decodes the stream of ALTRO samples to extract
+// the PHOS "digits" of current event.
+//
+// Typical use case:
+// AliRawReader* rf = new AliRawReaderDate("2006run2211.raw");
+// while (rf->NextEvent()) {
+// AliPHOSRawDecoder dc(rf);
+// dc.SetOldRCUFormat(kTRUE);
+// dc.SubtractPedestals(kTRUE);
+// while ( dc.NextDigit() ) {
+// Int_t module = dc.GetModule();
+// Int_t column = dc.GetColumn();
+// Int_t row = dc.GetRow();
+// Double_t amplitude = dc.GetEnergy();
+// Double_t time = dc.GetTime();
+// Bool_t IsLowGain = dc.IsLowGain();
+// ..........
+// }
+// }
+
+// Author: Boris Polichtchouk
+
+// --- ROOT system ---
+#include "TH1.h"
+
+// --- AliRoot header files ---
+#include "AliPHOSRawDecoder.h"
+#include "AliPHOSPulseGenerator.h"
+
+ClassImp(AliPHOSRawDecoder)
+
+//-----------------------------------------------------------------------------
+AliPHOSRawDecoder::AliPHOSRawDecoder():
+ fRawReader(0),fCaloStream(0),fPedSubtract(kFALSE),fEnergy(-111),fTime(-111),fModule(-1),fColumn(-1),fRow(-1)
+{
+ //Default constructor.
+}
+
+//-----------------------------------------------------------------------------
+AliPHOSRawDecoder::AliPHOSRawDecoder(AliRawReader* rawReader):
+ fRawReader(0),fCaloStream(0),fPedSubtract(kFALSE),fEnergy(-111),fTime(-111),fModule(-1),fColumn(-1),fRow(-1)
+{
+ //Construct a decoder object.
+ //Is is user responsibility to provide next raw event
+ //using AliRawReader::NextEvent().
+
+ fRawReader = rawReader;
+ fCaloStream = new AliCaloRawStream(rawReader,"PHOS");
+ fCaloStream->SetOldRCUFormat(kFALSE);
+}
+
+//-----------------------------------------------------------------------------
+AliPHOSRawDecoder::~AliPHOSRawDecoder()
+{
+ //Destructor.
+
+ if(fCaloStream) delete fCaloStream;
+}
+
+//-----------------------------------------------------------------------------
+AliPHOSRawDecoder::AliPHOSRawDecoder(const AliPHOSRawDecoder &phosDecoder ):
+ fRawReader(phosDecoder.fRawReader),fCaloStream(phosDecoder.fCaloStream),
+ fPedSubtract(phosDecoder.fPedSubtract),
+ fEnergy(phosDecoder.fEnergy),fTime(phosDecoder.fTime),
+ fModule(phosDecoder.fModule),fColumn(phosDecoder.fColumn),
+ fRow(phosDecoder.fRow)
+{
+ //Copy constructor.
+}
+
+//-----------------------------------------------------------------------------
+AliPHOSRawDecoder& AliPHOSRawDecoder::operator = (const AliPHOSRawDecoder &phosDecode)
+{
+ if(this != &phosDecode) {
+ fRawReader = phosDecode.fRawReader;
+
+ if(fCaloStream) delete fCaloStream;
+ fCaloStream = phosDecode.fCaloStream;
+
+ fEnergy = phosDecode.fEnergy;
+ fTime = phosDecode.fTime;
+ fModule = phosDecode.fModule;
+ fColumn = phosDecode.fColumn;
+ fRow = phosDecode.fRow;
+ }
+
+ return *this;
+}
+
+//-----------------------------------------------------------------------------
+
+Bool_t AliPHOSRawDecoder::NextDigit()
+{
+ //Extract an energy deposited in the crystal,
+ //crystal' position (module,column,row),
+ //time and gain (high or low).
+
+ AliCaloRawStream* in = fCaloStream;
+
+ // Create a shaper pulse object
+ AliPHOSPulseGenerator pulse;
+
+ Bool_t lowGainFlag = kFALSE ;
+ Int_t iBin = 0;
+
+ // Create histogram to store samples
+ TH1F hSamples("hSamples","ALTRO samples",in->GetTimeLength(),0,in->GetTimeLength());
+
+ while ( in->Next() ) {
+
+ lowGainFlag = in->IsLowGain();
+ // Fill histograms with samples
+ hSamples.SetBinContent(in->GetTimeLength()-iBin-1,in->GetSignal());
+ iBin++;
+
+ // Fit the full sample
+ if(iBin==in->GetTimeLength()) {
+ iBin=0;
+
+ // Temporarily we do not fit the sample graph, but
+ // take the energy from the graph maximum, and the pedestal
+ // from the 0th point (30 Aug 2006).
+ // Time is not evaluated for the moment (12.01.2007).
+ // Take is as a first time bin multiplied by the sample tick time
+
+ fTime = pulse.GetRawFormatTimeTrigger() * in->GetTime();
+
+ fModule = in->GetModule()+1;
+ fRow = in->GetRow() +1;
+ fColumn = in->GetColumn()+1;
+
+ fEnergy = hSamples.GetMaximum(); // "digit amplitude"
+ if(fPedSubtract)
+ fEnergy-= hSamples.GetBinContent(0); // "pedestal subtraction"
+
+ if(lowGainFlag)
+ fEnergy *= pulse.GetRawFormatHighLowGainFactor(); // *16
+
+ return kTRUE;
+ }
+
+ } // in.Next()
+
+
+ return kFALSE;
+}
--- /dev/null
+#ifndef ALIPHOSRAWDECODER_H
+#define ALIPHOSRAWDECODER_H
+/* Copyright(c) 2007, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice */
+
+// This class extracts the PHOS "digits" of current event
+// (amplitude,time, position,gain) from the raw stream
+// provided by AliRawReader. See cxx source for use case.
+
+#include "AliRawReader.h"
+#include "AliCaloRawStream.h"
+
+class AliPHOSRawDecoder {
+
+public:
+
+ AliPHOSRawDecoder();
+ AliPHOSRawDecoder(AliRawReader* rawReader);
+ AliPHOSRawDecoder(const AliPHOSRawDecoder& rawDecoder);
+ AliPHOSRawDecoder& operator = (const AliPHOSRawDecoder& rawDecoder);
+ virtual ~AliPHOSRawDecoder();
+
+ virtual Bool_t NextDigit();
+
+ void SetOldRCUFormat(Bool_t isOldRCU) {fCaloStream->SetOldRCUFormat(isOldRCU);}
+ void SubtractPedestals(Bool_t subtract) {fPedSubtract=subtract;}
+
+ Double_t GetEnergy() { return fEnergy; }
+ Double_t GetTime() { return fTime; }
+ Int_t GetModule() { return fModule; }
+ Int_t GetColumn() { return fColumn; }
+ Int_t GetRow() { return fRow; }
+ Bool_t IsLowGain() { return fCaloStream->IsLowGain(); }
+
+protected:
+
+ AliRawReader* fRawReader;
+ AliCaloRawStream* fCaloStream;
+ Bool_t fPedSubtract;
+
+private:
+
+ Double_t fEnergy;
+ Double_t fTime;
+ Int_t fModule;
+ Int_t fColumn;
+ Int_t fRow;
+
+ ClassDef(AliPHOSRawDecoder,1)
+};
+
+#endif