]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliCaloCalibSignal.cxx
fix error during merging (https://savannah.cern.ch/bugs/index.php?70729)
[u/mrichter/AliRoot.git] / EMCAL / AliCaloCalibSignal.cxx
index eef6e0b071ddbed010443a95d83161c2dd45e320..51d867073a0b5f5219c9569101d4bbeeacb2ba4a 100644 (file)
@@ -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),
@@ -145,6 +147,8 @@ AliCaloCalibSignal::AliCaloCalibSignal(const AliCaloCalibSignal &sig) :
   fAmpCut(sig.GetAmpCut()),
   fReqFractionAboveAmpCutVal(sig.GetReqFractionAboveAmpCutVal()),
   fReqFractionAboveAmp(sig.GetReqFractionAboveAmp()),
+  fAmpCutLEDRef(sig.GetAmpCutLEDRef()),
+  fReqLEDRefAboveAmpCutVal(sig.GetReqLEDRefAboveAmpCutVal()),
   fHour(sig.GetHour()),
   fLatestHour(sig.GetLatestHour()),
   fUseAverage(sig.GetUseAverage()),
@@ -207,7 +211,7 @@ void AliCaloCalibSignal::CreateTrees()
 
 //_____________________________________________________________________
 void AliCaloCalibSignal::ResetInfo()
-{
+{ // reset trees and counters
   Zero(); // set all counters to 0
   DeleteTrees(); // delete previous stuff
   CreateTrees(); // and create some new ones
@@ -233,19 +237,19 @@ void AliCaloCalibSignal::Zero()
 }
 
 //_____________________________________________________________________
-Bool_t AliCaloCalibSignal::CheckFractionAboveAmp(int *AmpVal, 
+Bool_t AliCaloCalibSignal::CheckFractionAboveAmp(const int *iAmpVal, 
                                                 int resultArray[])
-{
+{ // check fraction of towers, per column, that are above amplitude cut
   Bool_t returnCode = false;
     
-  int TowerNum = 0;
+  int iTowerNum = 0;
   double fraction = 0;
   for (int i = 0; i<fModules; i++) {
     for (int j = 0; j<fColumns; j++) {
       int nAbove = 0;
       for (int k = 0; k<fRows; k++) {
-       TowerNum = GetTowerNum(i,j,k);
-       if (AmpVal[TowerNum] > fAmpCut) { 
+       iTowerNum = GetTowerNum(i,j,k);
+       if (iAmpVal[iTowerNum] > fAmpCut) { 
          nAbove++;
        }
       }
@@ -267,10 +271,40 @@ Bool_t AliCaloCalibSignal::CheckFractionAboveAmp(int *AmpVal,
   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)
-{
+{ // set parameters from file
   static const string delimitor("::");
        
   // open, check input file
@@ -296,36 +330,37 @@ void AliCaloCalibSignal::SetParametersFromFile(const char *parameterFile)
                
     while ( ( s.rdstate() & ios::failbit ) == 0 ) {
                        
-      string key_value; 
-      s >> key_value;
+      string keyValue; 
+      s >> keyValue;
       
       // check stream status
       if( s.rdstate() & ios::failbit ) break;
                        
       // skip rest of line if comments found
-      if( key_value.substr( 0, 2 ) == "//" ) break;
+      if( keyValue.substr( 0, 2 ) == "//" ) break;
                        
-      // look for "::" in key_value pair
-      size_t position = key_value.find( delimitor );
+      // look for "::" in keyValue pair
+      size_t position = keyValue.find( delimitor );
       if( position == string::npos ) {
-       printf("wrong format for key::value pair: %s\n", key_value.c_str());
+       printf("wrong format for key::value pair: %s\n", keyValue.c_str());
       }
                                
-      // split key_value pair
-      string key( key_value.substr( 0, position ) );
-      string value( key_value.substr( position+delimitor.size(), 
-                                     key_value.size()-delimitor.size() ) );
+      // 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", key_value.c_str());
+       printf("wrong format for key::value pair: %s\n", keyValue.c_str());
       }
       
       // debug: check key value pair
       // 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 +370,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,18 +382,18 @@ void AliCaloCalibSignal::SetParametersFromFile(const char *parameterFile)
   }
 
   in.close();
-  return;
-       
+  return;      
 }
 
 //_____________________________________________________________________
 void AliCaloCalibSignal::WriteParametersToFile(const char *parameterFile)
-{
+{ // write parameters to file
   static const string delimitor("::");
   ofstream out( parameterFile );
   out << "// " << parameterFile << endl;
   out << "fAmpCut" << "::" << fAmpCut << endl;
   out << "fReqFractionAboveAmpCutVal" << "::" << fReqFractionAboveAmpCutVal << endl;
+  out << "fAmpCutLEDRef" << "::" << fAmpCutLEDRef << endl;
   out << "fSecInAverage" << "::" << fSecInAverage << endl;
 
   out.close();
@@ -431,8 +469,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() );
 }
 
@@ -445,24 +485,25 @@ Bool_t AliCaloCalibSignal::ProcessEvent(AliCaloRawStreamV3 *in, UInt_t Timestamp
   fNEvents++; // one more event
 
   // use maximum numbers to set array sizes
-  int AmpValHighGain[fgkMaxTowers];
-  int AmpValLowGain[fgkMaxTowers];
-  memset(AmpValHighGain, 0, sizeof(AmpValHighGain));
-  memset(AmpValLowGain, 0, sizeof(AmpValLowGain));
+  int iAmpValHighGain[fgkMaxTowers];
+  int iAmpValLowGain[fgkMaxTowers];
+  memset(iAmpValHighGain, 0, sizeof(iAmpValHighGain));
+  memset(iAmpValLowGain, 0, sizeof(iAmpValLowGain));
 
   // also for LED reference
-  int LEDAmpVal[fgkMaxRefs * 2]; // factor 2 is for the two gain values
-  memset(LEDAmpVal, 0, sizeof(LEDAmpVal));
+  int iLEDAmpVal[fgkMaxRefs * 2]; // factor 2 is for the two gain values
+  memset(iLEDAmpVal, 0, sizeof(iLEDAmpVal));
 
   int sample; // 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 TowerNum = 0; // array index for regular towers
-  int RefNum = 0; // array index for LED references
+  int iTowerNum = 0; // array index for regular towers
+  int iRefNum = 0; // array index for LED references
 
   // loop first to get the fraction of channels with amplitudes above cut
 
@@ -510,23 +551,24 @@ Bool_t AliCaloCalibSignal::ProcessEvent(AliCaloRawStreamV3 *in, UInt_t Timestamp
 
       if ( in->IsHighGain() || in->IsLowGain() ) { // regular tower
        // get tower number for AmpVal array
-       TowerNum = GetTowerNum(arrayPos, in->GetColumn(), in->GetRow()); 
+       iTowerNum = GetTowerNum(arrayPos, in->GetColumn(), in->GetRow()); 
 
        if (gain == 0) {
          // fill amplitude into the array         
-         AmpValLowGain[TowerNum] = max - min;
+         iAmpValLowGain[iTowerNum] = max - min;
          nLowChan++;
        } 
        else if (gain==1) {//fill the high gain ones
          // fill amplitude into the array
-         AmpValHighGain[TowerNum] = max - min;
+         iAmpValHighGain[iTowerNum] = max - min;
          nHighChan++;
        }//end if gain
       } // regular tower
       else if ( in->IsLEDMonData() ) { // LED ref.; 
        // strip # is coded is 'column' in the channel maps 
-       RefNum = GetRefNum(arrayPos, in->GetColumn(), gain); 
-       LEDAmpVal[RefNum] = max - min;
+       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,18 +578,30 @@ 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) { 
-      ok = CheckFractionAboveAmp(AmpValHighGain, checkResultArray); 
+      ok = CheckFractionAboveAmp(iAmpValHighGain, checkResultArray); 
+    }
+    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
   }
@@ -564,49 +618,51 @@ 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++){
        
-       TowerNum = GetTowerNum(i, j, k); 
+       iTowerNum = GetTowerNum(i, j, k); 
 
-       if(AmpValHighGain[TowerNum]) {
-         fAmp = AmpValHighGain[TowerNum];
+       if(iAmpValHighGain[iTowerNum]) {
+         fAmp = iAmpValHighGain[iTowerNum];
          fChannelNum = GetChannelNum(i,j,k,1);
-         fTreeAmpVsTime->Fill();//fChannelNum,fHour,AmpValHighGain[TowerNum]);
-         fNHighGain[TowerNum]++;
+         fTreeAmpVsTime->Fill();//fChannelNum,fHour,AmpValHighGain[iTowerNum]);
+         fNHighGain[iTowerNum]++;
        }
-       if(AmpValLowGain[TowerNum]) {
-         fAmp = AmpValLowGain[TowerNum];
+       if(iAmpValLowGain[iTowerNum]) {
+         fAmp = iAmpValLowGain[iTowerNum];
          fChannelNum = GetChannelNum(i,j,k,0);
-         fTreeAmpVsTime->Fill();//fChannelNum,fHour,AmpValLowGain[TowerNum]);
-         fNLowGain[TowerNum]++;
+         fTreeAmpVsTime->Fill();//fChannelNum,fHour,AmpValLowGain[iTowerNum]);
+         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 (LEDAmpVal[fRefNum]) {
-         fAmp = LEDAmpVal[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
@@ -670,22 +726,22 @@ Bool_t AliCaloCalibSignal::Analyze()
   memset(profile, 0, sizeof(profile));
 
   char name[200]; // for profile id and title
-  int TowerNum = 0;
+  int iTowerNum = 0;
 
   for (int i = 0; i<fModules; i++) {
     for (int ic=0; ic<fColumns; ic++){
       for (int ir=0; ir<fRows; ir++) {
 
-       TowerNum = GetTowerNum(i, ic, ir);
+       iTowerNum = GetTowerNum(i, ic, ir);
        // high gain
-       if (fNHighGain[TowerNum] > 0) {
+       if (fNHighGain[iTowerNum] > 0) {
          fChannelNum = GetChannelNum(i, ic, ir, 1); 
          sprintf(name, "profileChan%d", fChannelNum);
          profile[fChannelNum] = new TProfile(name, name, numProfBins, timeMin, timeMax, "s");
        }
 
        // same for low gain
-       if (fNLowGain[TowerNum] > 0) {
+       if (fNLowGain[iTowerNum] > 0) {
          fChannelNum = GetChannelNum(i, ic, ir, 0); 
          sprintf(name, "profileChan%d", fChannelNum);
          profile[fChannelNum] = new TProfile(name, name, numProfBins, timeMin, timeMax, "s");
@@ -790,3 +846,24 @@ Bool_t AliCaloCalibSignal::Analyze()
 
   return kTRUE;
 }
+
+//_____________________________________________________________________
+Bool_t AliCaloCalibSignal::DecodeChannelNum(const int chanId, 
+                                           int *imod, int *icol, int *irow, int *igain) const  
+{ // return the module, column, row, and gain for a given channel number
+  *igain = chanId/(fModules*fColumns*fRows);
+  *imod = (chanId/(fColumns*fRows)) % fModules;
+  *icol = (chanId/fRows) % fColumns;
+  *irow = chanId % fRows;
+  return kTRUE;
+} 
+
+//_____________________________________________________________________
+Bool_t AliCaloCalibSignal::DecodeRefNum(const int refId, 
+                                       int *imod, int *istripMod, int *igain) const 
+{ // return the module, stripModule, and gain for a given reference number
+  *igain = refId/(fModules*fLEDRefs);
+  *imod = (refId/(fLEDRefs)) % fModules;
+  *istripMod = refId % fLEDRefs;
+  return kTRUE;
+}