]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCCalibPulser.cxx
Histogram ranges changed to cut off saturation peak and noise
[u/mrichter/AliRoot.git] / TPC / AliTPCCalibPulser.cxx
index 1c88353712bc682cfb5a4e0690b112f87d87955e..c1893835f634f7ecd1463245ae99baa2a27eefd3 100644 (file)
 #include "AliRawReaderRoot.h"
 #include "AliRawReaderDate.h"
 #include "AliTPCRawStream.h"
+#include "AliTPCRawStreamFast.h"
 #include "AliTPCCalROC.h"
 #include "AliTPCCalPad.h"
 #include "AliTPCROC.h"
 #include "AliTPCCalibPulser.h"
 #include "AliTPCcalibDB.h"
 #include "AliMathBase.h"
+#include "AliLog.h"
 #include "TTreeStream.h"
 
 //date
@@ -214,9 +216,11 @@ AliTPCCalibPulser::AliTPCCalibPulser() :
     fLastSector(-1),
     fOldRCUformat(kTRUE),
     fROC(AliTPCROC::Instance()),
+    fMapping(NULL),
     fParam(new AliTPCParam),
     fPedestalTPC(0x0),
     fPadNoiseTPC(0x0),
+    fOutliers(0x0),
     fPedestalROC(0x0),
     fPadNoiseROC(0x0),
     fCalRocArrayT0(72),
@@ -266,9 +270,11 @@ AliTPCCalibPulser::AliTPCCalibPulser(const AliTPCCalibPulser &sig) :
     fLastSector(-1),
     fOldRCUformat(kTRUE),
     fROC(AliTPCROC::Instance()),
+    fMapping(NULL),
     fParam(new AliTPCParam),
     fPedestalTPC(0x0),
     fPadNoiseTPC(0x0),
+    fOutliers(0x0),
     fPedestalROC(0x0),
     fPadNoiseROC(0x0),
     fCalRocArrayT0(72),
@@ -351,6 +357,17 @@ AliTPCCalibPulser::~AliTPCCalibPulser()
     // destructor
     //
 
+    Reset();
+
+    if ( fDebugStreamer) delete fDebugStreamer;
+    delete fROC;
+    delete fParam;
+}
+void AliTPCCalibPulser::Reset()
+{
+    //
+    // Delete all information: Arrays, Histograms, CalRoc objects
+    //
     fCalRocArrayT0.Delete();
     fCalRocArrayQ.Delete();
     fCalRocArrayRMS.Delete();
@@ -364,10 +381,6 @@ AliTPCCalibPulser::~AliTPCCalibPulser()
     fPadQArrayEvent.Delete();
     fPadRMSArrayEvent.Delete();
     fPadPedestalArrayEvent.Delete();
-
-    if ( fDebugStreamer) delete fDebugStreamer;
-    delete fROC;
-    delete fParam;
 }
 //_____________________________________________________________________
 Int_t AliTPCCalibPulser::Update(const Int_t icsector,
@@ -381,8 +394,17 @@ Int_t AliTPCCalibPulser::Update(const Int_t icsector,
     // no extra analysis necessary. Assumes knowledge of the signal shape!
     // assumes that it is looped over consecutive time bins of one pad
     //
+
+   if (icRow<0) return 0;
+   if (icPad<0) return 0;
+   if (icTimeBin<0) return 0;
     if ( (icTimeBin>fLastTimeBin) || (icTimeBin<fFirstTimeBin)   ) return 0;
 
+    if ( icRow<0 || icPad<0 ){
+       AliWarning("Wrong Pad or Row number, skipping!");
+       return 0;
+    }
+
     Int_t iChannel  = fROC->GetRowIndexes(icsector)[icRow]+icPad; //  global pad position in sector
 
     //init first pad and sector in this event
@@ -466,6 +488,7 @@ void AliTPCCalibPulser::FindPedestal(Float_t part)
        }
        // truncated mean
        //
+        // what if by chance histo[median] == 0 ?!?
        Float_t count=histo[median] ,mean=histo[median]*median,  rms=histo[median]*median*median ;
        //
        for (Int_t idelta=1; idelta<10; ++idelta){
@@ -501,12 +524,18 @@ void AliTPCCalibPulser::FindPulserSignal(TVectorD &param, Float_t &qSum)
 
     Float_t ceQmax  =0, ceQsum=0, ceTime=0, ceRMS=0;
     Int_t   cemaxpos       = fMaxTimeBin;
-    Float_t ceSumThreshold = 8.*fPadNoise;  // threshold for the signal sum
+    Float_t ceSumThreshold = 10.*TMath::Max(fPadNoise,Float_t(1.));  // threshold for the signal sum
+    Float_t ceMaxThreshold = 5.*TMath::Max(fPadNoise,Float_t(1.));  // threshold for the signal max
     const Int_t    kCemin  = 2;             // range for the analysis of the ce signal +- channels from the peak
     const Int_t    kCemax  = 7;
+    param[0] = ceQmax;
+    param[1] = ceTime;
+    param[2] = ceRMS;
+    qSum     = ceQsum;
 
-    if (cemaxpos!=0){
-        ceQmax = fPadSignal.GetMatrixArray()[cemaxpos]-fPadPedestal;
+    if (cemaxpos>0){
+       ceQmax = fPadSignal.GetMatrixArray()[cemaxpos]-fPadPedestal;
+        if ( ceQmax<ceMaxThreshold ) return;
        for (Int_t i=cemaxpos-kCemin; i<cemaxpos+kCemax; ++i){
             Float_t signal = fPadSignal.GetMatrixArray()[i]-fPadPedestal;
            if ( (i>fFirstTimeBin) && (i<fLastTimeBin) && (signal>0) ){
@@ -516,11 +545,19 @@ void AliTPCCalibPulser::FindPulserSignal(TVectorD &param, Float_t &qSum)
            }
        }
     }
-    if (ceQmax&&ceQsum>ceSumThreshold) {
+    if (ceQsum>ceSumThreshold) {
        ceTime/=ceQsum;
        ceRMS  = TMath::Sqrt(TMath::Abs(ceRMS/ceQsum-ceTime*ceTime));
-       fVTime0Offset.GetMatrixArray()[fCurrentSector]+=ceTime;   // mean time for each sector
-       fVTime0OffsetCounter.GetMatrixArray()[fCurrentSector]++;
+        //only fill the Time0Offset if pad was not marked as an outlier!
+       if ( !fOutliers ){
+           fVTime0Offset.GetMatrixArray()[fCurrentSector]+=ceTime;   // mean time for each sector
+           fVTime0OffsetCounter.GetMatrixArray()[fCurrentSector]++;
+       } else {
+           if ( !(fOutliers->GetCalROC(fCurrentSector)->GetValue(fCurrentChannel)) ){
+               fVTime0Offset.GetMatrixArray()[fCurrentSector]+=ceTime;   // mean time for each sector
+               fVTime0OffsetCounter.GetMatrixArray()[fCurrentSector]++;
+           }
+       }
 
        //Normalise Q to the pad area
        Float_t norm = fParam->GetPadPitchWidth(fCurrentSector)*fParam->GetPadPitchLength(fCurrentSector,fCurrentRow);
@@ -552,6 +589,7 @@ void AliTPCCalibPulser::ProcessPad()
     Double_t meanT  = param[1];
     Double_t sigmaT = param[2];
 
+
     //Fill Event T0 counter
     (*GetPadTimesEvent(fCurrentSector,kTRUE)).GetMatrixArray()[fCurrentChannel] = meanT;
 
@@ -583,13 +621,13 @@ void AliTPCCalibPulser::EndEvent()
     //loop over all ROCs, fill Time0 histogram corrected for the mean Time0 of each ROC
     for ( Int_t iSec = 0; iSec<72; ++iSec ){
        TVectorF *vTimes = GetPadTimesEvent(iSec);
-        if ( !vTimes ) continue;
-
+        if ( !vTimes || fVTime0OffsetCounter[iSec]==0 ) continue;
+       Float_t time0 = fVTime0Offset[iSec]/fVTime0OffsetCounter[iSec];
        for ( UInt_t iChannel=0; iChannel<fROC->GetNChannels(iSec); ++iChannel ){
-           Float_t time0 = fVTime0Offset[iSec]/fVTime0OffsetCounter[iSec];
            Float_t time  = (*vTimes).GetMatrixArray()[iChannel];
 
             GetHistoT0(iSec,kTRUE)->Fill( time-time0,iChannel );
+            //GetHistoT0(iSec,kTRUE)->Fill( time,iChannel );
 
 
            //Debug start
@@ -641,10 +679,51 @@ void AliTPCCalibPulser::EndEvent()
                delete h1;
            }
            //Debug end
-
        }
     }
+}
+//_____________________________________________________________________
+Bool_t AliTPCCalibPulser::ProcessEventFast(AliTPCRawStreamFast *rawStreamFast)
+{
+  //
+  // Event Processing loop - AliTPCRawStream
+  //
+  ResetEvent();
 
+  Bool_t withInput = kFALSE;
+
+  while ( rawStreamFast->NextDDL() ){
+      while ( rawStreamFast->NextChannel() ){
+         Int_t isector  = rawStreamFast->GetSector();                       //  current sector
+         Int_t iRow     = rawStreamFast->GetRow();                          //  current row
+         Int_t iPad     = rawStreamFast->GetPad();                          //  current pad
+
+         while ( rawStreamFast->NextBunch() ){
+             Int_t startTbin = (Int_t)rawStreamFast->GetStartTimeBin();
+              Int_t endTbin = (Int_t)rawStreamFast->GetEndTimeBin();
+             for (Int_t iTimeBin = startTbin; iTimeBin < endTbin; iTimeBin++){
+                 Float_t signal=(Float_t)rawStreamFast->GetSignals()[iTimeBin-startTbin];
+                 Update(isector,iRow,iPad,iTimeBin+1,signal);
+                 withInput = kTRUE;
+             }
+         }
+      }
+  }
+  if (withInput){
+      EndEvent();
+  }
+  return withInput;
+}
+//_____________________________________________________________________
+Bool_t AliTPCCalibPulser::ProcessEventFast(AliRawReader *rawReader)
+{
+  //
+  //  Event processing loop - AliRawReader
+  //
+  AliTPCRawStreamFast *rawStreamFast = new AliTPCRawStreamFast(rawReader, (AliAltroMapping**)fMapping);
+  Bool_t res=ProcessEventFast(rawStreamFast);
+  delete rawStreamFast;
+  return res;
 }
 //_____________________________________________________________________
 Bool_t AliTPCCalibPulser::ProcessEvent(AliTPCRawStream *rawStream)
@@ -660,7 +739,6 @@ Bool_t AliTPCCalibPulser::ProcessEvent(AliTPCRawStream *rawStream)
   Bool_t withInput = kFALSE;
 
   while (rawStream->Next()) {
-
       Int_t isector  = rawStream->GetSector();                       //  current sector
       Int_t iRow     = rawStream->GetRow();                          //  current row
       Int_t iPad     = rawStream->GetPad();                          //  current pad
@@ -670,11 +748,9 @@ Bool_t AliTPCCalibPulser::ProcessEvent(AliTPCRawStream *rawStream)
       Update(isector,iRow,iPad,iTimeBin,signal);
       withInput = kTRUE;
   }
-
   if (withInput){
       EndEvent();
   }
-
   return withInput;
 }
 //_____________________________________________________________________
@@ -685,7 +761,7 @@ Bool_t AliTPCCalibPulser::ProcessEvent(AliRawReader *rawReader)
   //
 
 
-  AliTPCRawStream rawStream(rawReader);
+  AliTPCRawStream rawStream(rawReader, (AliAltroMapping**)fMapping);
 
   rawReader->Select("TPC");
 
@@ -998,17 +1074,14 @@ void AliTPCCalibPulser::Analyse()
 
        for (UInt_t iChannel=0; iChannel<nChannels; ++iChannel){
 
-
            Float_t cogTime0 = -1000;
            Float_t cogQ     = -1000;
            Float_t cogRMS   = -1000;
             Float_t cogOut   = 0;
 
-
            Int_t offsetQ = (fNbinsQ+2)*(iChannel+1)+1;
            Int_t offsetT0 = (fNbinsT0+2)*(iChannel+1)+1;
            Int_t offsetRMS = (fNbinsRMS+2)*(iChannel+1)+1;
-
 /*
            AliMathBase::FitGaus(arrayhQ+offsetQ,fNbinsQ,fXminQ,fXmaxQ,&paramQ,&dummy);
            AliMathBase::FitGaus(arrayhT0+offsetT0,fNbinsT0,fXminT0,fXmaxT0,&paramT0,&dummy);
@@ -1021,8 +1094,6 @@ void AliTPCCalibPulser::Analyse()
            cogTime0 = AliMathBase::GetCOG(arrayhT0+offsetT0,fNbinsT0,fXminT0,fXmaxT0);
             cogRMS   = AliMathBase::GetCOG(arrayhRMS+offsetRMS,fNbinsRMS,fXminRMS,fXmaxRMS);
 
-
-
            /*
            if ( (cogQ < ??) && (cogTime0 > ??) && (cogTime0<??) && ( cogRMS>??) ){
                cogOut = 1;
@@ -1062,9 +1133,7 @@ void AliTPCCalibPulser::Analyse()
                    "\n";
            }
            //! debug
-
        }
-
     }
     delete fDebugStreamer;
     fDebugStreamer = 0x0;