#include <fstream>
#include <sstream>
#include <iostream>
+#include <stdexcept>
#include <cmath>
#include "AliRawReader.h"
fRowMultiplier = 1;
}
fDetType = detectorType;
-
+
+ // ValidateProfiles(); // not to be done in ctor; info from Axel N.
+}
+
+//_____________________________________________________________________
+void AliCaloCalibPedestal::ValidateProfiles()
+{
+ //Make sure the basic histos exist
+ if (!fPedestalLowGain.IsEmpty()) return; //The profiles already exist. We just check one, because they're all created at
+ //the same time
+
//Then, loop for the requested number of modules
TString title, name;
for (int i = 0; i < fModules; i++) {
fRows, fRowMin, fRowMax));
}//end for nModules create the histograms
-
+
+ CompressAndSetOwner();
+}
+
+//_____________________________________________________________________
+void AliCaloCalibPedestal::CompressAndSetOwner()
+{
//Compress the arrays, in order to remove the empty objects (a 16 slot array is created by default)
fPedestalLowGain.Compress();
fPedestalHighGain.Compress();
fPeakMinusPedHighGainHisto.Compress();
fDeadMap.Compress();
+ // set owner ship for everyone
+ fPedestalLowGain.SetOwner(kTRUE);
+ fPedestalHighGain.SetOwner(kTRUE);
+ fPedestalLEDRefLowGain.SetOwner(kTRUE);
+ fPedestalLEDRefHighGain.SetOwner(kTRUE);
+ fPeakMinusPedLowGain.SetOwner(kTRUE);
+ fPeakMinusPedHighGain.SetOwner(kTRUE);
+ fPeakMinusPedHighGainHisto.SetOwner(kTRUE);
+ fPedestalLowGainDiff.SetOwner(kTRUE);
+ fPedestalHighGainDiff.SetOwner(kTRUE);
+ fPedestalLEDRefLowGainDiff.SetOwner(kTRUE);
+ fPedestalLEDRefHighGainDiff.SetOwner(kTRUE);
+ fPeakMinusPedLowGainDiff.SetOwner(kTRUE);
+ fPeakMinusPedHighGainDiff.SetOwner(kTRUE);
+ fPedestalLowGainRatio.SetOwner(kTRUE);
+ fPedestalHighGainRatio.SetOwner(kTRUE);
+ fPedestalLEDRefLowGainRatio.SetOwner(kTRUE);
+ fPedestalLEDRefHighGainRatio.SetOwner(kTRUE);
+ fPeakMinusPedLowGainRatio.SetOwner(kTRUE);
+ fPeakMinusPedHighGainRatio.SetOwner(kTRUE);
+ fDeadMap.SetOwner(kTRUE);
}
// dtor
//_____________________________________________________________________
AliCaloCalibPedestal::~AliCaloCalibPedestal()
{
+ //dtor
+
if (fReference) delete fReference;//Delete the reference object, if it has been loaded
- //TObjArray will delete the histos/profiles when it is deleted.
+
+ // delete also TObjArray's
+ fPedestalLowGain.Delete();
+ fPedestalHighGain.Delete();
+ fPedestalLEDRefLowGain.Delete();
+ fPedestalLEDRefHighGain.Delete();
+ fPeakMinusPedLowGain.Delete();
+ fPeakMinusPedHighGain.Delete();
+ fPeakMinusPedHighGainHisto.Delete();
+ fPedestalLowGainDiff.Delete();
+ fPedestalHighGainDiff.Delete();
+ fPedestalLEDRefLowGainDiff.Delete();
+ fPedestalLEDRefHighGainDiff.Delete();
+ fPeakMinusPedLowGainDiff.Delete();
+ fPeakMinusPedHighGainDiff.Delete();
+ fPedestalLowGainRatio.Delete();
+ fPedestalHighGainRatio.Delete();
+ fPedestalLEDRefLowGainRatio.Delete();
+ fPedestalLEDRefHighGainRatio.Delete();
+ fPeakMinusPedLowGainRatio.Delete();
+ fPeakMinusPedHighGainRatio.Delete();
+ fDeadMap.Delete();
+
}
// copy ctor
//_____________________________________________________________________
-AliCaloCalibPedestal::AliCaloCalibPedestal(const AliCaloCalibPedestal &ped) :
+AliCaloCalibPedestal::AliCaloCalibPedestal(AliCaloCalibPedestal &ped) :
TObject(ped),
fPedestalLowGain(),
fPedestalHighGain(),
fDeadMap.Add( ped.GetDeadMap(i) );
}//end for nModules
- //Compress the arrays, in order to remove the empty objects (a 16 slot array is created by default)
- fPedestalLowGain.Compress();
- fPedestalHighGain.Compress();
- fPedestalLEDRefLowGain.Compress();
- fPedestalLEDRefHighGain.Compress();
- fPeakMinusPedLowGain.Compress();
- fPeakMinusPedHighGain.Compress();
- fPeakMinusPedHighGainHisto.Compress();
-
- fDeadMap.Compress();
+ CompressAndSetOwner();
}
// assignment operator; use copy ctor to make life easy..
//_____________________________________________________________________
-AliCaloCalibPedestal& AliCaloCalibPedestal::operator = (const AliCaloCalibPedestal &source)
+AliCaloCalibPedestal& AliCaloCalibPedestal::operator = (AliCaloCalibPedestal &source)
{
// assignment operator; use copy ctor
if (&source == this) return *this;
//_____________________________________________________________________
void AliCaloCalibPedestal::Reset()
{
+ ValidateProfiles(); // make sure histos/profiles exist
// Reset all arrays/histograms
for (int i = 0; i < fModules; i++) {
GetPedProfileLowGain(i)->Reset();
s >> keyValue;
// check stream status
- if( s.rdstate() & ios::failbit ) break;
+ if( ( s.rdstate() & ios::failbit ) == ios::failbit) break;
// skip rest of line if comments found
if( keyValue.substr( 0, 2 ) == "//" ) break;
}
//_____________________________________________________________________
-Bool_t AliCaloCalibPedestal::AddInfo(const AliCaloCalibPedestal *ped)
+Bool_t AliCaloCalibPedestal::AddInfo(AliCaloCalibPedestal *ped)
{
+ ValidateProfiles(); // make sure histos/profiles exist
// just do this for the basic histograms/profiles that get filled in ProcessEvent
// may not have data for all modules, but let's just Add everything..
for (int i = 0; i < fModules; i++) {
GetPedProfileLowGain(i)->Add( ped->GetPedProfileLowGain(i) );
GetPedProfileHighGain(i)->Add( ped->GetPedProfileHighGain(i) );
+ GetPedLEDRefProfileLowGain(i)->Add( ped->GetPedLEDRefProfileLowGain(i) );
+ GetPedLEDRefProfileHighGain(i)->Add( ped->GetPedLEDRefProfileHighGain(i) );
GetPeakProfileLowGain(i)->Add( ped->GetPeakProfileLowGain(i) );
GetPeakProfileHighGain(i)->Add( ped->GetPeakProfileHighGain(i) );
GetPeakHighGainHisto(i)->Add( ped->GetPeakHighGainHisto(i) );
{
// Method to process=analyze one event in the data stream
if (!in) return kFALSE; //Return right away if there's a null pointer
+ in->Reset(); // just in case the next customer forgets to check if the stream was reset..
+
fNEvents++; // one more event
+
+ if (fNEvents==1) ValidateProfiles(); // 1st event, make sure histos/profiles exist
// indices for the reading
int sample = 0;
}// end while over channel
}//end while over DDL's, of input stream
- in->Reset(); // just in case the next customer forgets to check if the stream was reset..
return kTRUE;
}
Bool_t AliCaloCalibPedestal::SaveHistograms(TString fileName, Bool_t saveEmptyHistos)
{
//Saves all the histograms (or profiles, to be accurate) to the designated file
-
+ ValidateProfiles(); // make sure histos/profiles exist
TFile destFile(fileName, "recreate");
if (destFile.IsZombie()) {
return kTRUE;//We succesfully loaded the object
}
+
+//_____________________________________________________________________
+Bool_t AliCaloCalibPedestal::SetReference(AliCaloCalibPedestal *ref)
+{
+ if (fReference) delete fReference;//Delete the reference object, if it already exists
+ fReference = 0;
+
+ fReference = ref;
+
+ if (!fReference || (fReference->GetDetectorType() != fDetType)) {
+ if (fReference) delete fReference;//Delete the object, in case we had an object of the wrong type
+ fReference = 0;
+ return kFALSE;
+ }
+
+ return kTRUE;//We succesfully loaded the object
+}
+
//_____________________________________________________________________
void AliCaloCalibPedestal::ValidateComparisonProfiles()
{
fRows, fRowMin, fRowMax,"s"));
//LED Ref/Mon pedestals, low gain
- name = "hPedestalLEDReflowgain";
+ name = "hPedestalLEDReflowgainRatio";
name += i;
title = "Pedestal ratio LEDRef, low gain, module ";
title += i;
void AliCaloCalibPedestal::ComputeDiffAndRatio()
{
// calculate differences and ratios relative to a reference
+ ValidateProfiles(); // make sure histos/profiles exist
ValidateComparisonProfiles();//Make sure the comparison histos exist
if (!fReference) {
//_____________________________________________________________________
void AliCaloCalibPedestal::ComputeHotAndWarningTowers(const char * hotMapFile)
{ // look for hot/noisy towers
+ ValidateProfiles(); // make sure histos/profiles exist
ofstream * fout = 0;
char name[512];//Quite a long temp buffer, just in case the filename includes a path
}
}
- //...and then we fit it
- hPeakFit->Fit("gaus", "OQ", "", hPeakFit->GetMean() - 3*hPeakFit->GetRMS(),
- hPeakFit->GetMean() + 3*hPeakFit->GetRMS());
+ //...and then we try to fit it
+ double mean = hPeakFit->GetMean();
+ double sigma = hPeakFit->GetRMS();
+ try {
+ hPeakFit->Fit("gaus", "OQ", "", mean - 3*sigma, mean + 3*sigma);
+ mean = hPeakFit->GetFunction("gaus")->GetParameter(1);
+ sigma = hPeakFit->GetFunction("gaus")->GetParameter(2);
+ }
+ catch (const std::exception & e) {
+ printf("AliCaloCalibPedestal: TH1D PeakFit exception %s", e.what());
+ }
//hPeakFit->Draw();
- double mean = hPeakFit->GetFunction("gaus")->GetParameter(1);
- double sigma = hPeakFit->GetFunction("gaus")->GetParameter(2);
delete hPeakFit;
//_____________________________________________________________________
void AliCaloCalibPedestal::ComputeDeadTowers(const char * deadMapFile)
{
+ ValidateProfiles(); // make sure histos/profiles exist
//Computes the number of dead towers etc etc into memory, after this you can call the GetDead... -functions
int countTot = 0;
int countNew = 0;
}
if (!diff->is_open()) {
delete diff;
- fout = 0;//Set the pointer to empty if the file was not opened
+ diff = 0;//Set the pointer to empty if the file was not opened
}
}
//_____________________________________________________________________
Bool_t AliCaloCalibPedestal::IsBadChannel(int imod, int icol, int irow) const
{
+ // Check if status info histo exists
+ if (!fDeadMap[imod]) {
+ return kFALSE;
+ }
+
//Check if channel is dead or hot.
Int_t status = (Int_t) ( ((TH2D*)fDeadMap[imod])->GetBinContent(icol,irow) );
if(status == kAlive)
//_____________________________________________________________________
void AliCaloCalibPedestal::SetChannelStatus(int imod, int icol, int irow, int status)
{
+ ValidateProfiles(); // make sure histos/profiles exist
//Set status of channel dead, hot, alive ...
((TH2D*)fDeadMap[imod])->SetBinContent(icol, irow, status);
}