]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliCaloCalibSignal.cxx
1st draft for pass0
[u/mrichter/AliRoot.git] / EMCAL / AliCaloCalibSignal.cxx
index 906c46a12372b8eac973fea0bdd4b03750b7da15..41e2644f2e20a6c2c15dfbd400a2eaa97f449b73 100644 (file)
@@ -48,11 +48,11 @@ ClassImp(AliCaloCalibSignal)
 using namespace std;
 
 // variables for TTree filling; not sure if they should be static or not
-static int fChannelNum; // for regular towers
-static int fRefNum; // for LED
-static double fAmp;
-static double fAvgAmp;
-static double fRMS;
+static int fChannelNum = 0; // for regular towers
+static int fRefNum = 0; // for LED
+static double fAmp = 0;
+static double fAvgAmp = 0;
+static double fRMS = 0;
 
 // ctor; initialize everything in order to avoid compiler warnings
 // put some reasonable defaults
@@ -70,6 +70,8 @@ AliCaloCalibSignal::AliCaloCalibSignal(kDetType detectorType) :
   fAmpCut(40), // min. 40 ADC counts as default
   fReqFractionAboveAmpCutVal(0.6), // 60% in a strip, per default
   fReqFractionAboveAmp(kTRUE),
+  fAmpCutLEDRef(100), // min. 100 ADC counts as default
+  fReqLEDRefAboveAmpCutVal(kTRUE),
   fHour(0),
   fLatestHour(0),
   fUseAverage(kTRUE),
@@ -131,45 +133,56 @@ 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(NULL), //! note that we are not copying the map info
-  fRunNumber(sig.GetRunNumber()),
-  fStartTime(sig.GetStartTime()),
-  fAmpCut(sig.GetAmpCut()),
-  fReqFractionAboveAmpCutVal(sig.GetReqFractionAboveAmpCutVal()),
-  fReqFractionAboveAmp(sig.GetReqFractionAboveAmp()),
-  fHour(sig.GetHour()),
-  fLatestHour(sig.GetLatestHour()),
-  fUseAverage(sig.GetUseAverage()),
-  fSecInAverage(sig.GetSecInAverage()),
-  fNEvents(sig.GetNEvents()),
-  fNAcceptedEvents(sig.GetNAcceptedEvents()),
-  fTreeAmpVsTime(NULL),
-  fTreeAvgAmpVsTime(NULL),
-  fTreeLEDAmpVsTime(NULL),
-  fTreeLEDAvgAmpVsTime(NULL)
-{
-  // also the TTree contents
-  AddInfo(&sig);
-}
-
+//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]; 
+//  }
+//  
+//  
+//}
+//
 // 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()
@@ -267,6 +280,36 @@ Bool_t AliCaloCalibSignal::CheckFractionAboveAmp(const int *iAmpVal,
   return returnCode;
 }
 
+
+//_____________________________________________________________________
+Bool_t AliCaloCalibSignal::CheckLEDRefAboveAmp(const int *iAmpVal, 
+                                              int resultArray[])
+{ // check which LEDRef/Mon strips are above amplitude cut
+  Bool_t returnCode = false;
+    
+  int iRefNum = 0;
+  int gain = 1; // look at high gain; this should be rather saturated usually..
+  for (int i = 0; i<fModules; i++) {
+    for (int j = 0; j<fLEDRefs; j++) {
+      iRefNum = GetRefNum(i, j, gain);
+      if (iAmpVal[iRefNum] > fAmpCutLEDRef) { 
+       resultArray[i*fLEDRefs +j] = 1; // enough signal
+       returnCode = true;
+      }
+      else {
+       resultArray[i*fLEDRefs +j] = 0; // not enough signal
+      }
+      
+      /*
+      printf("DS mod %d LEDRef %d ampVal %d\n",
+            i, j, iAmpVal[iRefNum]);
+      */
+    } // LEDRefs
+  } // modules loop
+  
+  return returnCode;
+}
+
 // Parameter/cut handling
 //_____________________________________________________________________
 void AliCaloCalibSignal::SetParametersFromFile(const char *parameterFile)
@@ -300,7 +343,7 @@ void AliCaloCalibSignal::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;
@@ -325,7 +368,8 @@ void AliCaloCalibSignal::SetParametersFromFile(const char *parameterFile)
       // printf("AliCaloCalibSignal::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
-      if ( (key == "fAmpCut") || (key == "fReqFractionAboveAmpCutVal") || (key == "fSecInAverage") ) {
+      if ( (key == "fAmpCut") || (key == "fReqFractionAboveAmpCutVal") ||
+          (key == "fAmpCutLEDRef") || (key == "fSecInAverage") ) {
        istringstream iss(value);
        printf("AliCaloCalibSignal::SetParametersFromFile - key %s value %s\n", key.c_str(), value.c_str());
 
@@ -335,6 +379,9 @@ void AliCaloCalibSignal::SetParametersFromFile(const char *parameterFile)
        else if (key == "fReqFractionAboveAmpCutVal") { 
          iss >> fReqFractionAboveAmpCutVal; 
        }
+       else if (key == "fAmpCutLEDRef") { 
+         iss >> fAmpCutLEDRef; 
+       }
        else if (key == "fSecInAverage") { 
          iss >> fSecInAverage; 
        }
@@ -344,8 +391,7 @@ void AliCaloCalibSignal::SetParametersFromFile(const char *parameterFile)
   }
 
   in.close();
-  return;
-       
+  return;      
 }
 
 //_____________________________________________________________________
@@ -356,6 +402,7 @@ void AliCaloCalibSignal::WriteParametersToFile(const char *parameterFile)
   out << "// " << parameterFile << endl;
   out << "fAmpCut" << "::" << fAmpCut << endl;
   out << "fReqFractionAboveAmpCutVal" << "::" << fReqFractionAboveAmpCutVal << endl;
+  out << "fAmpCutLEDRef" << "::" << fAmpCutLEDRef << endl;
   out << "fSecInAverage" << "::" << fSecInAverage << endl;
 
   out.close();
@@ -431,8 +478,10 @@ Bool_t AliCaloCalibSignal::AddInfo(const AliCaloCalibSignal *sig)
 Bool_t AliCaloCalibSignal::ProcessEvent(AliRawReader *rawReader)
 {
   // if fMapping is NULL the rawstream will crate its own mapping
-  AliCaloRawStreamV3 rawStream(rawReader, fCaloString, (AliAltroMapping**)fMapping);
-
+  AliCaloRawStreamV3 rawStream(rawReader, fCaloString, (AliAltroMapping**)fMapping);  
+  if (fDetType == kEmCal) {
+    rawReader->Select("EMCAL", 0, AliEMCALGeoParams::fgkLastAltroDDL) ; //select EMCAL DDL range 
+  }
   return ProcessEvent( &rawStream, rawReader->GetTimestamp() );
 }
 
@@ -454,12 +503,13 @@ 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; // temporary value
+  int sample = 0; // temporary value
   int gain = 0; // high or low gain
   
-  // Number of Low and High gain channels for this event:
+  // Number of Low and High gain, and LED Ref, channels for this event:
   int nLowChan = 0; 
   int nHighChan = 0; 
+  int nLEDRefChan = 0;
 
   int iTowerNum = 0; // array index for regular towers
   int iRefNum = 0; // array index for LED references
@@ -527,6 +577,7 @@ Bool_t AliCaloCalibSignal::ProcessEvent(AliCaloRawStreamV3 *in, UInt_t Timestamp
        // strip # is coded is 'column' in the channel maps 
        iRefNum = GetRefNum(arrayPos, in->GetColumn(), gain); 
        iLEDAmpVal[iRefNum] = max - min;
+       nLEDRefChan++;
       } // end of LED ref
 
       } // nsamples>0 check, some data found for this channel; not only trailer/header      
@@ -536,14 +587,13 @@ Bool_t AliCaloCalibSignal::ProcessEvent(AliCaloRawStreamV3 *in, UInt_t Timestamp
   
   in->Reset(); // just in case the next customer forgets to check if the stream was reset..
 
-  // now check if it was a led event, only use high gain (that should be sufficient)
+  // now check if it was an LED event, using the LED Reference info per strip
 
   // by default all columns are accepted (init check to > 0)
   int checkResultArray[AliEMCALGeoParams::fgkEMCALModules * AliEMCALGeoParams::fgkEMCALCols];
   for (int ia=0; ia<(AliEMCALGeoParams::fgkEMCALModules * AliEMCALGeoParams::fgkEMCALCols); ia++) { 
     checkResultArray[ia] = 1; 
   }
-
   if (fReqFractionAboveAmp) {
     bool ok = false;
     if (nHighChan > 0) { 
@@ -552,6 +602,19 @@ Bool_t AliCaloCalibSignal::ProcessEvent(AliCaloRawStreamV3 *in, UInt_t Timestamp
     if (!ok) return false; // skip event
   }
 
+  // by default all columns are accepted (init check to > 0)
+  int checkResultArrayLEDRef[AliEMCALGeoParams::fgkEMCALModules * AliEMCALGeoParams::fgkEMCALLEDRefs];
+  for (int ia=0; ia<(AliEMCALGeoParams::fgkEMCALModules * AliEMCALGeoParams::fgkEMCALLEDRefs); ia++) { 
+    checkResultArrayLEDRef[ia] = 1; 
+  }
+  if (fReqLEDRefAboveAmpCutVal) {
+    bool ok = false;
+    if (nLEDRefChan > 0) { 
+      ok = CheckLEDRefAboveAmp(iLEDAmpVal, checkResultArrayLEDRef); 
+    }
+    if (!ok) return false; // skip event
+  }
+
   fNAcceptedEvents++; // one more event accepted
 
   if (fStartTime == 0) { // if start-timestamp wasn't set,we'll pick it up from the first event we encounter
@@ -564,9 +627,17 @@ Bool_t AliCaloCalibSignal::ProcessEvent(AliCaloRawStreamV3 *in, UInt_t Timestamp
   }
   
   // it is a led event, now fill TTree
+  // We also do the activity check for LEDRefs/Strips, but need to translate between column
+  // and strip indices for that; based on these relations: 
+  // iStrip = AliEMCALGeoParams::GetStripModule(iSM, iCol);
+  // iStrip = (iSM%2==0) ? iCol/2 : AliEMCALGeoParams::fgkEMCALLEDRefs - 1 - iCol/2;
+  // which leads to
+  // iColFirst = (iSM%2==0) ? iStrip*2 : (AliEMCALGeoParams::fgkEMCALLEDRefs - 1 - iStrip)*2;
+
   for(int i=0; i<fModules; i++){
-    for(int j=0; j<fColumns; j++){
-      if (checkResultArray[i*fColumns + j] > 0) { // column passed check 
+    for(int j=0; j<fColumns; j++) {
+      int iStrip = (i%2==0) ? j/2 : AliEMCALGeoParams::fgkEMCALLEDRefs - 1 - j/2;
+      if (checkResultArray[i*fColumns + j]>0  && checkResultArrayLEDRef[i*fLEDRefs + iStrip]>0) { // column passed check 
       for(int k=0; k<fRows; k++){
        
        iTowerNum = GetTowerNum(i, j, k); 
@@ -584,29 +655,23 @@ Bool_t AliCaloCalibSignal::ProcessEvent(AliCaloRawStreamV3 *in, UInt_t Timestamp
          fNLowGain[iTowerNum]++;
        }
       } // rows
-      } // column passed check
+      } // column passed check, and LED Ref for strip passed check (if any)
     } // columns
 
-    // We also do the activity check for LEDRefs/Strips, but need to translate between column
-    // and strip indices for that; based on these relations: 
-    // iStrip = AliEMCALGeoParams::GetStripModule(iSM, iCol);
-    // iStrip = (iSM%2==0) ? iCol/2 : AliEMCALGeoParams::fgkEMCALLEDRefs - 1 - iCol/2;
-    // which leads to
-    // iColFirst = (iSM%2==0) ? iStrip*2 : (AliEMCALGeoParams::fgkEMCALLEDRefs - 1 - iStrip)*2;
-
     // also LED refs
     for(int j=0; j<fLEDRefs; j++){
       int iColFirst = (i%2==0) ? j*2 : (AliEMCALGeoParams::fgkEMCALLEDRefs - 1 - j)*2; //CHECKME!!!
-      if ( (checkResultArray[i*fColumns + iColFirst]>0) || (checkResultArray[i*fColumns + iColFirst + 1]>0) ) { // at least one column in strip passed check 
-      for (gain=0; gain<2; gain++) {
-       fRefNum = GetRefNum(i, j, gain); 
-       if (iLEDAmpVal[fRefNum]) {
-         fAmp = iLEDAmpVal[fRefNum];
-         fTreeLEDAmpVsTime->Fill();//fRefNum,fHour,fAmp);
-         fNRef[fRefNum]++;
-       }
-      } // gain
-      } // at least one column in strip passed check 
+      if ( ((checkResultArray[i*fColumns + iColFirst]>0) || (checkResultArray[i*fColumns + iColFirst + 1]>0)) && // at least one column in strip passed check 
+          (checkResultArrayLEDRef[i*fLEDRefs + j]>0) ) { // and LED Ref passed checks
+       for (gain=0; gain<2; gain++) {
+         fRefNum = GetRefNum(i, j, gain); 
+         if (iLEDAmpVal[fRefNum]) {
+           fAmp = iLEDAmpVal[fRefNum];
+           fTreeLEDAmpVsTime->Fill();//fRefNum,fHour,fAmp);
+           fNRef[fRefNum]++;
+         }
+       } // gain
+      } // at least one column in strip passed check, and LED Ref passed check (if any) 
     }
 
   } // modules
@@ -668,8 +733,8 @@ Bool_t AliCaloCalibSignal::Analyze()
   //1: set up TProfiles for the towers that had data
   TProfile * profile[fgkMaxTowers*2]; // *2 is since we include both high and low gains
   memset(profile, 0, sizeof(profile));
-
-  char name[200]; // for profile id and title
+  const Int_t buffersize = 200;
+  char name[buffersize]; // for profile id and title
   int iTowerNum = 0;
 
   for (int i = 0; i<fModules; i++) {
@@ -680,14 +745,14 @@ Bool_t AliCaloCalibSignal::Analyze()
        // high gain
        if (fNHighGain[iTowerNum] > 0) {
          fChannelNum = GetChannelNum(i, ic, ir, 1); 
-         sprintf(name, "profileChan%d", fChannelNum);
+         snprintf(name,buffersize,"profileChan%d", fChannelNum);
          profile[fChannelNum] = new TProfile(name, name, numProfBins, timeMin, timeMax, "s");
        }
 
        // same for low gain
        if (fNLowGain[iTowerNum] > 0) {
          fChannelNum = GetChannelNum(i, ic, ir, 0); 
-         sprintf(name, "profileChan%d", fChannelNum);
+         snprintf(name,buffersize,"profileChan%d", fChannelNum);
          profile[fChannelNum] = new TProfile(name, name, numProfBins, timeMin, timeMax, "s");
        }
 
@@ -743,7 +808,7 @@ Bool_t AliCaloCalibSignal::Analyze()
       for (int gain=0; gain<2; gain++) {
        fRefNum = GetRefNum(i, j, gain);
        if (fNRef[fRefNum] > 0) { 
-         sprintf(name, "profileLEDRef%d", fRefNum);
+         snprintf(name, buffersize, "profileLEDRef%d", fRefNum);
          profileLED[fRefNum] = new TProfile(name, name, numProfBins, timeMin, timeMax, "s");
        } 
       }// gain