]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliCaloCalibSignal.cxx
avoid warnings with modern compilers due to unused variables or wrong comparison...
[u/mrichter/AliRoot.git] / EMCAL / AliCaloCalibSignal.cxx
index e27c7e481fbebe6b0c7f8bb87fa1bf205381006e..b3c115e7cb831f7e8fee78ea0d4c1668494177d0 100644 (file)
 #include "AliRawReader.h"
 #include "AliCaloRawStreamV3.h"
 
+#include "AliCaloConstants.h"
+#include "AliCaloBunchInfo.h"
+#include "AliCaloFitResults.h"
+#include "AliCaloRawAnalyzer.h"
+#include "AliCaloRawAnalyzerFactory.h"
+
 //The include file
 #include "AliCaloCalibSignal.h"
 
@@ -65,6 +71,8 @@ AliCaloCalibSignal::AliCaloCalibSignal(kDetType detectorType) :
   fModules(0),
   fCaloString(),
   fMapping(NULL),
+  fFittingAlgorithm(0),  
+  fRawAnalyzer(0),
   fRunNumber(-1),
   fStartTime(0),
   fAmpCut(40), // min. 40 ADC counts as default
@@ -76,6 +84,7 @@ AliCaloCalibSignal::AliCaloCalibSignal(kDetType detectorType) :
   fLatestHour(0),
   fUseAverage(kTRUE),
   fSecInAverage(1800), 
+  fDownscale(10), 
   fNEvents(0),
   fNAcceptedEvents(0),
   fTreeAmpVsTime(NULL),
@@ -103,7 +112,7 @@ AliCaloCalibSignal::AliCaloCalibSignal(kDetType detectorType) :
   }
 
   fDetType = detectorType;
-
+  SetFittingAlgorithm(Algo::kStandard);
   ResetInfo(); // trees and counters
 } 
 
@@ -133,56 +142,57 @@ void AliCaloCalibSignal::DeleteTrees()
 
 // copy ctor
 //_____________________________________________________________________
-AliCaloCalibSignal::AliCaloCalibSignal(const AliCaloCalibSignal &sig) :
-  TObject(sig),
-  fDetType(sig.GetDetectorType()),
-  fColumns(sig.GetColumns()),
-  fRows(sig.GetRows()),
-  fLEDRefs(sig.GetLEDRefs()),
-  fModules(sig.GetModules()),
-  fCaloString(sig.GetCaloString()),
-  fMapping(), //! note that we are not copying the map info
-  fRunNumber(sig.GetRunNumber()),
-  fStartTime(sig.GetStartTime()),
-  fAmpCut(sig.GetAmpCut()),
-  fReqFractionAboveAmpCutVal(sig.GetReqFractionAboveAmpCutVal()),
-  fReqFractionAboveAmp(sig.GetReqFractionAboveAmp()),
-  fAmpCutLEDRef(sig.GetAmpCutLEDRef()),
-  fReqLEDRefAboveAmpCutVal(sig.GetReqLEDRefAboveAmpCutVal()),
-  fHour(sig.GetHour()),
-  fLatestHour(sig.GetLatestHour()),
-  fUseAverage(sig.GetUseAverage()),
-  fSecInAverage(sig.GetSecInAverage()),
-  fNEvents(sig.GetNEvents()),
-  fNAcceptedEvents(sig.GetNAcceptedEvents()),
-  fTreeAmpVsTime(),
-  fTreeAvgAmpVsTime(),
-  fTreeLEDAmpVsTime(),
-  fTreeLEDAvgAmpVsTime()
-{
-  // also the TTree contents
-  AddInfo(&sig);
-  for (Int_t i = 0; i<fgkMaxTowers; i++) {
-      fNHighGain[i] = sig.fNHighGain[i];
-      fNLowGain[i]  = sig.fNLowGain[i]; 
-  }
-  for (Int_t i = 0; i<(2*fgkMaxRefs); i++) {
-    fNRef[i] = sig.fNRef[i]; 
-  }
-  
-  
-}
-
+//AliCaloCalibSignal::AliCaloCalibSignal(const AliCaloCalibSignal &sig) :
+//  TObject(sig),
+//  fDetType(sig.GetDetectorType()),
+//  fColumns(sig.GetColumns()),
+//  fRows(sig.GetRows()),
+//  fLEDRefs(sig.GetLEDRefs()),
+//  fModules(sig.GetModules()),
+//  fCaloString(sig.GetCaloString()),
+//  fMapping(), //! note that we are not copying the map info
+//  fRunNumber(sig.GetRunNumber()),
+//  fStartTime(sig.GetStartTime()),
+//  fAmpCut(sig.GetAmpCut()),
+//  fReqFractionAboveAmpCutVal(sig.GetReqFractionAboveAmpCutVal()),
+//  fReqFractionAboveAmp(sig.GetReqFractionAboveAmp()),
+//  fAmpCutLEDRef(sig.GetAmpCutLEDRef()),
+//  fReqLEDRefAboveAmpCutVal(sig.GetReqLEDRefAboveAmpCutVal()),
+//  fHour(sig.GetHour()),
+//  fLatestHour(sig.GetLatestHour()),
+//  fUseAverage(sig.GetUseAverage()),
+//  fSecInAverage(sig.GetSecInAverage()),
+//  fDownscale(sig.GetDownscale()),
+//  fNEvents(sig.GetNEvents()),
+//  fNAcceptedEvents(sig.GetNAcceptedEvents()),
+//  fTreeAmpVsTime(),
+//  fTreeAvgAmpVsTime(),
+//  fTreeLEDAmpVsTime(),
+//  fTreeLEDAvgAmpVsTime()
+//{
+//  // also the TTree contents
+//  AddInfo(&sig);
+//  for (Int_t i = 0; i<fgkMaxTowers; i++) {
+//      fNHighGain[i] = sig.fNHighGain[i];
+//      fNLowGain[i]  = sig.fNLowGain[i]; 
+//  }
+//  for (Int_t i = 0; i<(2*fgkMaxRefs); i++) {
+//    fNRef[i] = sig.fNRef[i]; 
+//  }
+//  
+//  
+//}
+//
 // assignment operator; use copy ctor to make life easy..
 //_____________________________________________________________________
-AliCaloCalibSignal& AliCaloCalibSignal::operator = (const AliCaloCalibSignal &source)
-{
-  // assignment operator; use copy ctor
-  if (&source == this) return *this;
-
-  new (this) AliCaloCalibSignal(source);
-  return *this;
-}
+//AliCaloCalibSignal& AliCaloCalibSignal::operator = (const AliCaloCalibSignal &source)
+//{
+//  // assignment operator; use copy ctor
+//  if (&source == this) return *this;
+//
+//  new (this) AliCaloCalibSignal(source);
+//  return *this;
+//}
 
 //_____________________________________________________________________
 void AliCaloCalibSignal::CreateTrees()
@@ -247,7 +257,7 @@ void AliCaloCalibSignal::Zero()
 
 //_____________________________________________________________________
 Bool_t AliCaloCalibSignal::CheckFractionAboveAmp(const int *iAmpVal, 
-                                                int resultArray[])
+                                                int resultArray[]) const
 { // check fraction of towers, per column, that are above amplitude cut
   Bool_t returnCode = false;
     
@@ -283,7 +293,7 @@ Bool_t AliCaloCalibSignal::CheckFractionAboveAmp(const int *iAmpVal,
 
 //_____________________________________________________________________
 Bool_t AliCaloCalibSignal::CheckLEDRefAboveAmp(const int *iAmpVal, 
-                                              int resultArray[])
+                                              int resultArray[]) const
 { // check which LEDRef/Mon strips are above amplitude cut
   Bool_t returnCode = false;
     
@@ -369,7 +379,8 @@ void AliCaloCalibSignal::SetParametersFromFile(const char *parameterFile)
 
       // if the key matches with something we expect, we assign the new value
       if ( (key == "fAmpCut") || (key == "fReqFractionAboveAmpCutVal") ||
-          (key == "fAmpCutLEDRef") || (key == "fSecInAverage") ) {
+          (key == "fAmpCutLEDRef") || (key == "fSecInAverage") || 
+          (key == "fFittingAlgorithm") || (key == "fDownscale") ) {
        istringstream iss(value);
        printf("AliCaloCalibSignal::SetParametersFromFile - key %s value %s\n", key.c_str(), value.c_str());
 
@@ -385,6 +396,13 @@ void AliCaloCalibSignal::SetParametersFromFile(const char *parameterFile)
        else if (key == "fSecInAverage") { 
          iss >> fSecInAverage; 
        }
+       else if (key == "fFittingAlgorithm") { 
+         iss >> fFittingAlgorithm;
+         SetFittingAlgorithm( fFittingAlgorithm );
+       }
+       else if (key == "fDownscale") { 
+         iss >> fDownscale; 
+       }
       } // some match found/expected
 
     }          
@@ -404,14 +422,25 @@ void AliCaloCalibSignal::WriteParametersToFile(const char *parameterFile)
   out << "fReqFractionAboveAmpCutVal" << "::" << fReqFractionAboveAmpCutVal << endl;
   out << "fAmpCutLEDRef" << "::" << fAmpCutLEDRef << endl;
   out << "fSecInAverage" << "::" << fSecInAverage << endl;
+  out << "fFittingAlgorithm" << "::" << fFittingAlgorithm << endl;
+  out << "fDownscale" << "::" << fDownscale << endl;
 
   out.close();
   return;
 }
 
+//_____________________________________________________________________
+void AliCaloCalibSignal::SetFittingAlgorithm(Int_t fitAlgo)              
+{ // select which fitting algo should be used
+  fFittingAlgorithm = fitAlgo;
+  delete fRawAnalyzer; // delete doesn't do anything if the pointer is 0x0
+  fRawAnalyzer = AliCaloRawAnalyzerFactory::CreateAnalyzer( fitAlgo );
+  fRawAnalyzer->SetIsZeroSuppressed(true); // TMP - should use stream->IsZeroSuppressed(), or altro cfg registers later
+}
+
 //_____________________________________________________________________
 Bool_t AliCaloCalibSignal::AddInfo(const AliCaloCalibSignal *sig)
-{
+{ 
   // note/FIXME: we are not yet adding correctly the info for fN{HighGain,LowGain,Ref} here - but consider this a feature for now (20080905): we'll do Analyze() unless entries were found for a tower in this original object.
 
   // add info from sig's TTrees to ours..
@@ -470,6 +499,24 @@ Bool_t AliCaloCalibSignal::AddInfo(const AliCaloCalibSignal *sig)
     fTreeLEDAvgAmpVsTime->Fill();
   }
 
+  // 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.
+  fRunNumber = sig->GetRunNumber();
+  fStartTime = sig->GetStartTime();
+  fAmpCut = sig->GetAmpCut();
+  fReqFractionAboveAmpCutVal = sig->GetReqFractionAboveAmpCutVal();
+  fReqFractionAboveAmp = sig->GetReqFractionAboveAmp();
+  fAmpCutLEDRef = sig->GetAmpCutLEDRef();
+  fReqLEDRefAboveAmpCutVal = sig->GetReqLEDRefAboveAmpCutVal();
+  fHour = sig->GetHour();
+  fLatestHour = sig->GetLatestHour();
+  fUseAverage = sig->GetUseAverage();
+  fSecInAverage = sig->GetSecInAverage();
+  fDownscale = sig->GetDownscale();
+  fNEvents = sig->GetNEvents();
+  fNAcceptedEvents = sig->GetNAcceptedEvents();
 
   return kTRUE;//We hopefully succesfully added info from the supplied object
 }
@@ -482,6 +529,7 @@ Bool_t AliCaloCalibSignal::ProcessEvent(AliRawReader *rawReader)
   if (fDetType == kEmCal) {
     rawReader->Select("EMCAL", 0, AliEMCALGeoParams::fgkLastAltroDDL) ; //select EMCAL DDL range 
   }
+
   return ProcessEvent( &rawStream, rawReader->GetTimestamp() );
 }
 
@@ -493,6 +541,8 @@ Bool_t AliCaloCalibSignal::ProcessEvent(AliCaloRawStreamV3 *in, UInt_t Timestamp
   
   fNEvents++; // one more event
 
+  if ( (fNEvents%fDownscale)!=0 ) return kFALSE; // mechanism to skip some of the input events, if we want
+
   // use maximum numbers to set array sizes
   int iAmpValHighGain[fgkMaxTowers];
   int iAmpValLowGain[fgkMaxTowers];
@@ -503,7 +553,6 @@ Bool_t AliCaloCalibSignal::ProcessEvent(AliCaloRawStreamV3 *in, UInt_t Timestamp
   int iLEDAmpVal[fgkMaxRefs * 2]; // factor 2 is for the two gain values
   memset(iLEDAmpVal, 0, sizeof(iLEDAmpVal));
 
-  int sample = 0; // temporary value
   int gain = 0; // high or low gain
   
   // Number of Low and High gain, and LED Ref, channels for this event:
@@ -519,24 +568,11 @@ Bool_t AliCaloCalibSignal::ProcessEvent(AliCaloRawStreamV3 *in, UInt_t Timestamp
   while (in->NextDDL()) {
     while (in->NextChannel()) {
 
-      // counters
-      int max = AliEMCALGeoParams::fgkSampleMin, min = AliEMCALGeoParams::fgkSampleMax; // min and max sample values
-      int nsamples = 0;
-
+      vector<AliCaloBunchInfo> bunchlist; 
       while (in->NextBunch()) {
-       const UShort_t *sig = in->GetSignals();
-       nsamples += in->GetBunchLength();
-       for (Int_t i = 0; i < in->GetBunchLength(); i++) {
-         sample = sig[i];
-
-         // check if it's a min or max value
-         if (sample < min) min = sample;
-         if (sample > max) max = sample;
-
-       } // 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
+       bunchlist.push_back( AliCaloBunchInfo(in->GetStartTimeBin(), in->GetBunchLength(), in->GetSignals() ) );
+      } 
+      if (bunchlist.size() == 0) continue;
 
       gain = -1; // init to not valid value
       //If we're here then we're done with this tower
@@ -549,6 +585,7 @@ Bool_t AliCaloCalibSignal::ProcessEvent(AliCaloRawStreamV3 *in, UInt_t Timestamp
       else if ( in->IsLEDMonData() ) {
        gain = in->GetRow(); // gain coded in (in RCU/Altro mapping) as Row info for LED refs..
       }
+      else { continue; } // don't try to fit TRU..
 
       // it should be enough to check the SuperModule info for each DDL really, but let's keep it here for now
       int arrayPos = in->GetModule(); //The modules are numbered starting from 0
@@ -558,29 +595,29 @@ Bool_t AliCaloCalibSignal::ProcessEvent(AliCaloRawStreamV3 *in, UInt_t Timestamp
        return kFALSE;
       }
 
+      AliCaloFitResults res =  fRawAnalyzer->Evaluate( bunchlist, in->GetAltroCFG1(), in->GetAltroCFG2());  
       if ( in->IsHighGain() || in->IsLowGain() ) { // regular tower
        // get tower number for AmpVal array
        iTowerNum = GetTowerNum(arrayPos, in->GetColumn(), in->GetRow()); 
 
        if (gain == 0) {
          // fill amplitude into the array         
-         iAmpValLowGain[iTowerNum] = max - min;
+         iAmpValLowGain[iTowerNum]  = (int) res.GetAmp();
          nLowChan++;
        } 
        else if (gain==1) {//fill the high gain ones
          // fill amplitude into the array
-         iAmpValHighGain[iTowerNum] = max - min;
+         iAmpValHighGain[iTowerNum] = (int) res.GetAmp();
          nHighChan++;
        }//end if gain
       } // regular tower
       else if ( in->IsLEDMonData() ) { // LED ref.; 
        // strip # is coded is 'column' in the channel maps 
        iRefNum = GetRefNum(arrayPos, in->GetColumn(), gain); 
-       iLEDAmpVal[iRefNum] = max - min;
+       iLEDAmpVal[iRefNum] = (int) res.GetAmp();
        nLEDRefChan++;
       } // end of LED ref
 
-      } // 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