]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliCaloCalibPedestal.cxx
put back previous default value, although decission needs to be made to which one...
[u/mrichter/AliRoot.git] / EMCAL / AliCaloCalibPedestal.cxx
index 8311741ce4cb38d61099cf4a89e688bac4a03424..fc1609c999d57e38472cbbc7cf2bc3b911f092f4 100644 (file)
@@ -127,7 +127,17 @@ AliCaloCalibPedestal::AliCaloCalibPedestal(kDetType detectorType) :
     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++) {
@@ -200,7 +210,13 @@ AliCaloCalibPedestal::AliCaloCalibPedestal(kDetType detectorType) :
                          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();
@@ -211,19 +227,64 @@ AliCaloCalibPedestal::AliCaloCalibPedestal(kDetType detectorType) :
   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(),
@@ -284,21 +345,12 @@ AliCaloCalibPedestal::AliCaloCalibPedestal(const AliCaloCalibPedestal &ped) :
     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;
@@ -309,8 +361,8 @@ AliCaloCalibPedestal& AliCaloCalibPedestal::operator = (const AliCaloCalibPedest
 
 //_____________________________________________________________________
 void AliCaloCalibPedestal::Reset()
-{
-  // Reset all arrays/histograms
+{   // Reset all arrays/histograms
+  ValidateProfiles(); // make sure histos/profiles exist
   for (int i = 0; i < fModules; i++) {
     GetPedProfileLowGain(i)->Reset();
     GetPedProfileHighGain(i)->Reset();
@@ -382,7 +434,7 @@ void AliCaloCalibPedestal::SetParametersFromFile(const char *parameterFile)
       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;
@@ -461,19 +513,40 @@ void AliCaloCalibPedestal::WriteParametersToFile(const char *parameterFile)
 }
 
 //_____________________________________________________________________
-Bool_t AliCaloCalibPedestal::AddInfo(const AliCaloCalibPedestal *ped)
+Bool_t AliCaloCalibPedestal::AddInfo(AliCaloCalibPedestal *ped)
 {
   // 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..
+  ValidateProfiles(); // make sure histos/profiles exist
+
   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) );
-
   }//end for nModules 
 
+  // We should also copy other pieces of info: counters and parameters 
+  // (not number of columns and rows etc which should be the same)
+  // note that I just assign them here rather than Add them, but we
+  // normally just Add (e.g. in Preprocessor) one object so this should be fine.
+  fNEvents = ped->GetNEvents();
+  fNChanFills = ped->GetNChanFills();
+  fDeadTowers = ped->GetDeadTowerCount();
+  fNewDeadTowers = ped->GetDeadTowerNew();
+  fResurrectedTowers = ped->GetDeadTowerResurrected();
+  fRunNumber = ped->GetRunNumber();
+  fSelectPedestalSamples = ped->GetSelectPedestalSamples();
+  fFirstPedestalSample = ped->GetFirstPedestalSample();
+  fLastPedestalSample = ped->GetLastPedestalSample();
+  fDeadThreshold = ped->GetDeadThreshold();
+  fWarningThreshold = ped->GetWarningThreshold();
+  fWarningFraction = ped->GetWarningFraction();
+  fHotSigma = ped->GetHotSigma();
+
   // DeadMap; Diff profiles etc would need to be redone after this operation
 
   return kTRUE;//We succesfully added info from the supplied object
@@ -495,7 +568,11 @@ Bool_t AliCaloCalibPedestal::ProcessEvent(AliCaloRawStreamV3 *in)
 { 
   // 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;
@@ -596,7 +673,6 @@ Bool_t AliCaloCalibPedestal::ProcessEvent(AliCaloRawStreamV3 *in)
     }// 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;
 }
@@ -605,7 +681,7 @@ Bool_t AliCaloCalibPedestal::ProcessEvent(AliCaloRawStreamV3 *in)
 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()) {
@@ -676,6 +752,24 @@ Bool_t AliCaloCalibPedestal::LoadReferenceCalib(TString fileName, TString object
   return kTRUE;//We succesfully loaded the object
 }
 
+
+//_____________________________________________________________________
+Bool_t AliCaloCalibPedestal::SetReference(AliCaloCalibPedestal *ref)
+{ // set reference object
+  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()
 {
@@ -758,7 +852,7 @@ 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; 
@@ -796,8 +890,8 @@ void AliCaloCalibPedestal::ValidateComparisonProfiles()
 
 //_____________________________________________________________________
 void AliCaloCalibPedestal::ComputeDiffAndRatio()
-{
-  // calculate differences and ratios relative to a reference
+{ // calculate differences and ratios relative to a reference
+  ValidateProfiles(); // make sure histos/profiles exist
   ValidateComparisonProfiles();//Make sure the comparison histos exist
  
   if (!fReference) {
@@ -884,6 +978,7 @@ void AliCaloCalibPedestal::ComputeDiffAndRatio()
 //_____________________________________________________________________
 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
 
@@ -970,6 +1065,7 @@ void AliCaloCalibPedestal::ComputeHotAndWarningTowers(const char * hotMapFile)
 //_____________________________________________________________________
 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;
@@ -989,7 +1085,7 @@ void AliCaloCalibPedestal::ComputeDeadTowers(const char * deadMapFile)
     }
     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
     }
   }
  
@@ -1060,6 +1156,11 @@ void AliCaloCalibPedestal::ComputeDeadTowers(const char * deadMapFile)
 //_____________________________________________________________________
 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)
@@ -1072,6 +1173,7 @@ Bool_t AliCaloCalibPedestal::IsBadChannel(int imod, int icol, int irow) const
 //_____________________________________________________________________
 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);  
 }