]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliCaloCalibPedestal.cxx
Implementing the skeleton for HLT QA for type kESDs (reconstruction)
[u/mrichter/AliRoot.git] / EMCAL / AliCaloCalibPedestal.cxx
index 264e427062c4971c8ecaeb98a80daaede660271d..ed6c369aabda33b097a23dc16bc49d63200b5a4d 100644 (file)
@@ -37,6 +37,7 @@
 #include "TH1.h"
 #include "TFile.h"
 #include <fstream>
+#include <sstream>
 #include <iostream>
 #include <cmath>
 
@@ -307,6 +308,101 @@ void AliCaloCalibPedestal::Reset()
   //To think about: should fReference be deleted too?... let's not do it this time, at least...
 }
 
+// Parameter/cut handling
+//_____________________________________________________________________
+void AliCaloCalibPedestal::SetParametersFromFile(const char *parameterFile)
+{  
+  // Note: this method is a bit more complicated than it really has to be
+  // - allowing for multiple entries per line, arbitrary order of the
+  // different variables etc. But I wanted to try and do this in as
+  // correct a C++ way as I could (as an exercise).
+
+  static const string delimitor("::");
+       
+  // open, check input file
+  ifstream in( parameterFile );
+  if( !in ) {
+    printf("in AliCaloCalibPedestal::SetParametersFromFile - Using default/run_time parameters.\n");
+    return;
+  } 
+
+
+  // read in
+  char readline[1024];
+  while ((in.rdstate() & ios::failbit) == 0 ) {
+    
+    // Read into the raw char array and then construct a string
+    // to do the searching
+    in.getline(readline, 1024);
+    istringstream s(readline);         
+               
+    while ( ( s.rdstate() & ios::failbit ) == 0 ) {
+                       
+      string keyValue; 
+      s >> keyValue;
+      
+      // check stream status
+      if( s.rdstate() & ios::failbit ) break;
+                       
+      // skip rest of line if comments found
+      if( keyValue.substr( 0, 2 ) == "//" ) break;
+                       
+      // look for "::" in keyValue pair
+      size_t position = keyValue.find( delimitor );
+      if( position == string::npos ) {
+       printf("wrong format for key::value pair: %s\n", keyValue.c_str());
+      }
+                               
+      // split keyValue pair
+      string key( keyValue.substr( 0, position ) );
+      string value( keyValue.substr( position+delimitor.size(), 
+                                     keyValue.size()-delimitor.size() ) );
+                       
+      // check value does not contain a new delimitor
+      if( value.find( delimitor ) != string::npos ) {
+       printf("wrong format for key::value pair: %s\n", keyValue.c_str());
+      }
+      
+      // debug: check key value pair
+      // printf("AliCaloCalibPedestal::SetParametersFromFile - key %s value %s\n", key.c_str(), value.c_str());
+
+      // if the key matches with something we expect, we assign the new value
+      istringstream iss(value);
+      // the comparison strings defined at the beginning of this method
+      if ( (key == "fFirstPedestalSample") || (key == "fLastPedestalSample") ) {
+       printf("AliCaloCalibPedestal::SetParametersFromFile - key %s value %s\n", key.c_str(), value.c_str());
+
+       if (key == "fFirstPedestalSample") { 
+         iss >> fFirstPedestalSample; 
+       }
+       else if (key == "fLastPedestalSample") { 
+         iss >> fLastPedestalSample; 
+       }
+      } // some match
+
+    }          
+  }
+
+  in.close();
+  return;
+       
+}
+
+//_____________________________________________________________________
+void AliCaloCalibPedestal::WriteParametersToFile(const char *parameterFile)
+{
+  //Write parameters in file.
+       
+  static const string delimitor("::");
+  ofstream out( parameterFile );
+  out << "// " << parameterFile << endl;
+  out << "fFirstPedestalSample" << "::" << fFirstPedestalSample << endl;
+  out << "fLastPedestalSample" << "::" << fLastPedestalSample << endl;
+
+  out.close();
+  return;
+}
+
 //_____________________________________________________________________
 Bool_t AliCaloCalibPedestal::AddInfo(const AliCaloCalibPedestal *ped)
 {
@@ -352,7 +448,8 @@ Bool_t AliCaloCalibPedestal::ProcessEvent(AliCaloRawStreamV3 *in)
 
       // counters
       int max = AliEMCALGeoParams::fgkSampleMin, min = AliEMCALGeoParams::fgkSampleMax; // min and max sample values
-      
+      int nsamples = 0;
+
       // for the pedestal calculation
       int sampleSum = 0; // sum of samples
       int squaredSampleSum = 0; // sum of samples squared
@@ -363,6 +460,7 @@ Bool_t AliCaloCalibPedestal::ProcessEvent(AliCaloRawStreamV3 *in)
       while (in->NextBunch()) {
        const UShort_t *sig = in->GetSignals();
        startBin = in->GetStartTimeBin();
+       nsamples += in->GetBunchLength();
        for (i = 0; i < in->GetBunchLength(); i++) {
          sample = sig[i];
          time = startBin--;
@@ -382,6 +480,8 @@ Bool_t AliCaloCalibPedestal::ProcessEvent(AliCaloRawStreamV3 *in)
        } // loop over samples in bunch
       } // loop over bunches
 
+      if (nsamples > 0) { // this check is needed for when we have zero-supp. on, but not sparse readout
+
       // calculate pedesstal estimate: mean of possibly selected samples
       if (nSum > 0) {
        mean = sampleSum / (1.0 * nSum);
@@ -434,7 +534,7 @@ Bool_t AliCaloCalibPedestal::ProcessEvent(AliCaloRawStreamV3 *in)
        }
       }//end if valid gain
 
-    
+      } // nsamples>0 check, some data found for this channel; not only trailer/header
     }// end while over channel   
   }//end while over DDL's, of input stream 
 
@@ -734,3 +834,24 @@ void AliCaloCalibPedestal::ComputeDeadTowers(int threshold, const char * deadMap
  fResurrectedTowers = countRes;
 }
 
+//_____________________________________________________________________
+Bool_t AliCaloCalibPedestal::IsBadChannel(int imod, int icol, int irow) const
+{
+       //Check if channel is dead or hot.
+       
+       Int_t status =  ((TH2D*)fDeadMap[imod])->GetBinContent(icol,irow);
+       if(status == kAlive)
+               return kFALSE;
+       else 
+               return kTRUE;
+       
+}
+
+//_____________________________________________________________________
+void AliCaloCalibPedestal::SetChannelStatus(int imod, int icol, int irow, int status)
+{
+       //Set status of channel dead, hot, alive ...
+       
+       ((TH2D*)fDeadMap[imod])->SetBinContent(icol,irow, status);
+       
+}