]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCdataQA.cxx
Method added.
[u/mrichter/AliRoot.git] / TPC / AliTPCdataQA.cxx
index de7243e9817cedb1636243675db6ce821120e936..b9bd5e430f1d6c5f508f474d487a047b5a46a710 100644 (file)
@@ -66,16 +66,17 @@ using namespace std;
 #include <TH2F.h>
 #include <TString.h>
 #include <TMath.h>
-#include <TF1.h>
-#include <TRandom.h>
 #include <TDirectory.h>
 #include <TFile.h>
 #include <TError.h>
+#include <TMap.h>
+#include <TProfile.h>
 //AliRoot includes
 #include "AliRawReader.h"
 #include "AliRawReaderRoot.h"
 #include "AliRawReaderDate.h"
 #include "AliTPCRawStream.h"
+#include "AliTPCRawStreamV3.h"
 #include "AliTPCCalROC.h"
 #include "AliTPCROC.h"
 #include "AliMathBase.h"
@@ -89,16 +90,15 @@ using namespace std;
 
 //header file
 #include "AliTPCdataQA.h"
+#include "AliLog.h"
 
 ClassImp(AliTPCdataQA)
 
 AliTPCdataQA::AliTPCdataQA() : /*FOLD00*/  
-  TH1F("TPCRAW","TPCRAW",100,0,100),
   fFirstTimeBin(60),
   fLastTimeBin(1000),
   fAdcMin(1),
   fAdcMax(100),
-  fOldRCUformat(kTRUE),
   fMapping(NULL),
   fPedestal(0),
   fNoise(0),
@@ -106,14 +106,24 @@ AliTPCdataQA::AliTPCdataQA() : /*FOLD00*/
   fMaxCharge(0),
   fMeanCharge(0),
   fNoThreshold(0),
-  fOverThreshold10(0),
-  fOverThreshold20(0),
-  fOverThreshold30(0),
   fNTimeBins(0),
   fNPads(0),
   fTimePosition(0),
+  fOverThreshold10(0),
+  fOverThreshold20(0),
+  fOverThreshold30(0),
+  fHistQVsTimeSideA(0),
+  fHistQVsTimeSideC(0),
+  fHistQMaxVsTimeSideA(0),
+  fHistQMaxVsTimeSideC(0),
+  fHistOccupancyVsEvent(0),
+  fHistNclustersVsEvent(0),
   fEventCounter(0),
   fIsAnalysed(kFALSE),
+  fMaxEvents(500000),           // Max events for event histograms
+  fEventsPerBin(1000),          // Events per bin for event histograms
+  fSignalCounter(0),            // Signal counter
+  fClusterCounter(0),           // Cluster counter
   fAllBins(0),
   fAllSigBins(0),
   fAllNSigBins(0),
@@ -126,6 +136,48 @@ AliTPCdataQA::AliTPCdataQA() : /*FOLD00*/
   //
 }
 
+//_____________________________________________________________________
+AliTPCdataQA::AliTPCdataQA(AliRecoParam::EventSpecie_t es) :
+fFirstTimeBin(60),
+fLastTimeBin(1000),
+fAdcMin(1),
+fAdcMax(100),
+fMapping(NULL),
+fPedestal(0),
+fNoise(0),
+fNLocalMaxima(0),
+fMaxCharge(0),
+fMeanCharge(0),
+fNoThreshold(0),
+fNTimeBins(0),
+fNPads(0),
+fTimePosition(0),
+fOverThreshold10(0),
+fOverThreshold20(0),
+fOverThreshold30(0),
+fHistQVsTimeSideA(0),
+fHistQVsTimeSideC(0),
+fHistQMaxVsTimeSideA(0),
+fHistQMaxVsTimeSideC(0),
+fHistOccupancyVsEvent(0),
+fHistNclustersVsEvent(0),
+fEventCounter(0),
+fIsAnalysed(kFALSE),
+fMaxEvents(500000),
+fEventsPerBin(1000),
+fSignalCounter(0),
+fClusterCounter(0),
+fAllBins(0),
+fAllSigBins(0),
+fAllNSigBins(0),
+fRowsMax(0),
+fPadsMax(0),
+fTimeBinsMax(0)
+{
+// ctor creating the histogram
+  char *  name = Form("TPCRAW_%s", AliRecoParam::GetEventSpecieName(es)) ; 
+  TH1F(name, name,100,0,100) ; 
+}
 
 //_____________________________________________________________________
 AliTPCdataQA::AliTPCdataQA(const AliTPCdataQA &ped) : /*FOLD00*/
@@ -134,7 +186,6 @@ AliTPCdataQA::AliTPCdataQA(const AliTPCdataQA &ped) : /*FOLD00*/
   fLastTimeBin(ped.GetLastTimeBin()),
   fAdcMin(ped.GetAdcMin()),
   fAdcMax(ped.GetAdcMax()),
-  fOldRCUformat(ped.GetOldRCUformat()),
   fMapping(NULL),
   fPedestal(0),
   fNoise(0),
@@ -142,14 +193,24 @@ AliTPCdataQA::AliTPCdataQA(const AliTPCdataQA &ped) : /*FOLD00*/
   fMaxCharge(0),
   fMeanCharge(0),
   fNoThreshold(0),
-  fOverThreshold10(0),
-  fOverThreshold20(0),
-  fOverThreshold30(0),
   fNTimeBins(0),
   fNPads(0),
   fTimePosition(0),
+  fOverThreshold10(0),
+  fOverThreshold20(0),
+  fOverThreshold30(0),
+  fHistQVsTimeSideA(0),
+  fHistQVsTimeSideC(0),
+  fHistQMaxVsTimeSideA(0),
+  fHistQMaxVsTimeSideC(0),
+  fHistOccupancyVsEvent(0),
+  fHistNclustersVsEvent(0),
   fEventCounter(ped.GetEventCounter()),
   fIsAnalysed(ped.GetIsAnalysed()),
+  fMaxEvents(ped.GetMaxEvents()),
+  fEventsPerBin(ped.GetEventsPerBin()),
+  fSignalCounter(ped.GetSignalCounter()),
+  fClusterCounter(ped.GetClusterCounter()),
   fAllBins(0),
   fAllSigBins(0),
   fAllNSigBins(0),
@@ -180,8 +241,81 @@ AliTPCdataQA::AliTPCdataQA(const AliTPCdataQA &ped) : /*FOLD00*/
     fOverThreshold20  = new AliTPCCalPad(*ped.GetOverThreshold20());
   if(ped.GetOverThreshold30())
     fOverThreshold30  = new AliTPCCalPad(*ped.GetOverThreshold30());
+  if(ped.GetHistQVsTimeSideA()) {
+    fHistQVsTimeSideA = new TProfile(*ped.GetHistQVsTimeSideA());
+    fHistQVsTimeSideA->SetDirectory(0);
+  }
+  if(ped.GetHistQVsTimeSideC()) {
+    fHistQVsTimeSideC = new TProfile(*ped.GetHistQVsTimeSideC());
+    fHistQVsTimeSideC->SetDirectory(0);
+  }
+  if(ped.GetHistQMaxVsTimeSideA()) {
+    fHistQMaxVsTimeSideA = new TProfile(*ped.GetHistQMaxVsTimeSideA());
+    fHistQMaxVsTimeSideA->SetDirectory(0);
+  }
+  if(ped.GetHistQMaxVsTimeSideC()) {
+    fHistQMaxVsTimeSideC = new TProfile(*ped.GetHistQMaxVsTimeSideC());
+    fHistQMaxVsTimeSideC->SetDirectory(0);
+  }
+  if(ped.GetHistOccupancyVsEventConst()) {
+    fHistOccupancyVsEvent  = new TH1F(*ped.GetHistOccupancyVsEventConst());
+    fHistOccupancyVsEvent->SetDirectory(0);
+  }
+  if(ped.GetHistNclustersVsEventConst()) {
+    fHistNclustersVsEvent  = new TH1F(*ped.GetHistNclustersVsEventConst());
+    fHistNclustersVsEvent->SetDirectory(0);
+  }
 }
 
+//_____________________________________________________________________
+AliTPCdataQA::AliTPCdataQA(const TMap *config) : /*FOLD00*/  
+  TH1F("TPCRAW","TPCRAW",100,0,100),
+  fFirstTimeBin(60),
+  fLastTimeBin(1000),
+  fAdcMin(1),
+  fAdcMax(100),
+  fMapping(NULL),
+  fPedestal(0),
+  fNoise(0),
+  fNLocalMaxima(0),
+  fMaxCharge(0),
+  fMeanCharge(0),
+  fNoThreshold(0),
+  fNTimeBins(0),
+  fNPads(0),
+  fTimePosition(0),
+  fOverThreshold10(0),
+  fOverThreshold20(0),
+  fOverThreshold30(0),
+  fHistQVsTimeSideA(0),
+  fHistQVsTimeSideC(0),
+  fHistQMaxVsTimeSideA(0),
+  fHistQMaxVsTimeSideC(0),
+  fHistOccupancyVsEvent(0),
+  fHistNclustersVsEvent(0),
+  fEventCounter(0),
+  fIsAnalysed(kFALSE),
+  fMaxEvents(500000),
+  fEventsPerBin(1000),
+  fSignalCounter(0),
+  fClusterCounter(0),
+  fAllBins(0),
+  fAllSigBins(0),
+  fAllNSigBins(0),
+  fRowsMax(0),
+  fPadsMax(0),
+  fTimeBinsMax(0)
+{
+  //
+  // default constructor
+  //
+  if (config->GetValue("FirstTimeBin")) fFirstTimeBin = ((TObjString*)config->GetValue("FirstTimeBin"))->GetString().Atoi();
+  if (config->GetValue("LastTimeBin"))  fLastTimeBin = ((TObjString*)config->GetValue("LastTimeBin"))->GetString().Atoi();
+  if (config->GetValue("AdcMin"))       fAdcMin = ((TObjString*)config->GetValue("AdcMin"))->GetString().Atoi();
+  if (config->GetValue("AdcMax"))       fAdcMax = ((TObjString*)config->GetValue("AdcMax"))->GetString().Atoi();
+  if (config->GetValue("MaxEvents"))    fMaxEvents = ((TObjString*)config->GetValue("MaxEvents"))->GetString().Atoi();
+  if (config->GetValue("EventsPerBin")) fAdcMax = ((TObjString*)config->GetValue("EventsPerBin"))->GetString().Atoi();
+}
 
 //_____________________________________________________________________
 AliTPCdataQA& AliTPCdataQA::operator = (const  AliTPCdataQA &source)
@@ -217,6 +351,12 @@ AliTPCdataQA::~AliTPCdataQA() /*FOLD00*/
   delete fOverThreshold10;
   delete fOverThreshold20;
   delete fOverThreshold30;
+  delete fHistQVsTimeSideA;
+  delete fHistQVsTimeSideC;
+  delete fHistQMaxVsTimeSideA;
+  delete fHistQMaxVsTimeSideC;
+  delete fHistOccupancyVsEvent;
+  delete fHistNclustersVsEvent;
 
   for (Int_t iRow = 0; iRow < fRowsMax; iRow++) {
     delete [] fAllBins[iRow];
@@ -228,7 +368,159 @@ AliTPCdataQA::~AliTPCdataQA() /*FOLD00*/
 }
 
 //_____________________________________________________________________
-Bool_t AliTPCdataQA::ProcessEventFast(AliTPCRawStreamFast *rawStreamFast)
+TH1F* AliTPCdataQA::GetHistOccupancyVsEvent()
+{
+  //
+  // Create Occupancy vs event histogram
+  // (we create this histogram differently then the other histograms
+  //  because this we want to be able to access and copy
+  //  from AliTPCQAMakerRec before it normally would be created)
+  //
+  if(!fHistOccupancyVsEvent) {
+
+    Int_t nBins = fMaxEvents/fEventsPerBin;
+    fHistOccupancyVsEvent = new TH1F("hOccupancyVsEvent", "Occupancy vs event number (~time); Event number; Occupancy", nBins, 0, nBins*fEventsPerBin);
+    fHistOccupancyVsEvent->SetDirectory(0);
+    fHistOccupancyVsEvent->GetXaxis()->SetRange(0, 10);
+  }
+  
+  return fHistOccupancyVsEvent;
+}
+
+//_____________________________________________________________________
+TH1F* AliTPCdataQA::GetHistNclustersVsEvent()
+{
+  //
+  // Create Nclusters vs event histogram
+  // (we create this histogram differently then the other histograms
+  //  because this we want to be able to access and copy
+  //  from AliTPCQAMakerRec before it normally would be created)
+  //
+  if(!fHistNclustersVsEvent) {
+
+    Int_t nBins = fMaxEvents/fEventsPerBin;
+    fHistNclustersVsEvent = new TH1F("hNclustersVsEvent", "Nclusters vs event number (~time); Event number; Nclusters per event", nBins, 0, nBins*fEventsPerBin);
+    fHistNclustersVsEvent->SetDirectory(0);
+    fHistNclustersVsEvent->GetXaxis()->SetRange(0, 10);
+  }
+  
+  return fHistNclustersVsEvent;
+}
+
+//_____________________________________________________________________
+void AliTPCdataQA::UpdateEventHistograms()
+{
+  // Update histograms that display occupancy and 
+  // number of clusters as a function of number of 
+  // events
+  if (!fHistOccupancyVsEvent)
+    GetHistOccupancyVsEvent();
+  if (!fHistNclustersVsEvent)
+    GetHistNclustersVsEvent();
+  
+  Float_t averageOccupancy =
+    Float_t(fSignalCounter)/fEventsPerBin/(fLastTimeBin - fFirstTimeBin +1.0)
+    / 570132; // 570,132 is number of pads
+  if(fEventCounter<=fMaxEvents) 
+    UpdateEventHisto(fHistOccupancyVsEvent, averageOccupancy);
+  fSignalCounter = 0;
+  
+  Float_t averageNclusters =
+    Float_t(fClusterCounter)/fEventsPerBin;
+  if(fEventCounter<=fMaxEvents) 
+    UpdateEventHisto(fHistNclustersVsEvent, averageNclusters);
+  fClusterCounter = 0;
+}
+
+//_____________________________________________________________________
+void AliTPCdataQA::UpdateEventHisto(TH1F* hist, Float_t average)
+{
+  // Do the actually updating of each histogram and 
+  // change the visible range if needed
+  
+  // in case someone would have overwritten the value here
+  // (not so pretty  but OK for this I think)
+  fEventsPerBin = hist->GetXaxis()->GetBinWidth(1);
+  Int_t bin = TMath::Nint(Float_t(fEventCounter)/fEventsPerBin);
+  
+  if (hist->GetBinContent(bin)>0) { 
+    AliError("Bin already filled. This should not happen.");
+  } else {
+    hist->SetBinContent(bin, average);
+  }
+  
+  // expand the visible range of the histogram if needed
+  if(hist->GetXaxis()->GetLast()<= bin) {
+    hist->GetXaxis()->SetRange(0, Int_t(1.3*bin));
+  }
+}
+
+//_____________________________________________________________________
+Bool_t AliTPCdataQA::ProcessEvent(AliTPCRawStreamV3 *const rawStreamV3)
+{
+  //
+  // Event Processing loop - AliTPCRawStreamV3
+  //
+  Bool_t withInput = kFALSE;
+  Int_t nSignals = 0;
+  Int_t lastSector = -1;
+  
+  while ( rawStreamV3->NextDDL() ){
+    while ( rawStreamV3->NextChannel() ){
+      Int_t iSector = rawStreamV3->GetSector(); //  current sector
+      Int_t iRow    = rawStreamV3->GetRow();    //  current row
+      Int_t iPad    = rawStreamV3->GetPad();    //  current pad
+      if (iRow<0 || iPad<0) continue;
+      // Call local maxima finder if the data is in a new sector
+      if(iSector != lastSector) {
+        
+        if(nSignals>0)
+          FindLocalMaxima(lastSector);
+        
+        CleanArrays();
+        lastSector = iSector;
+        nSignals = 0;
+      }
+      
+      while ( rawStreamV3->NextBunch() ){
+        Int_t  startTbin    = (Int_t)rawStreamV3->GetStartTimeBin();
+        Int_t  bunchlength  = (Int_t)rawStreamV3->GetBunchLength();
+        const UShort_t *sig = rawStreamV3->GetSignals();
+        
+        for (Int_t iTimeBin = 0; iTimeBin<bunchlength; iTimeBin++){
+          Float_t signal=(Float_t)sig[iTimeBin];
+          nSignals += Update(iSector,iRow,iPad,startTbin--,signal);
+          withInput = kTRUE;
+        }
+      }
+    }
+  }
+  
+  if (lastSector>=0&&nSignals>0)
+    FindLocalMaxima(lastSector);
+  
+  return withInput;
+}
+
+//_____________________________________________________________________
+Bool_t AliTPCdataQA::ProcessEvent(AliRawReader *const rawReader)
+{
+  //
+  //  Event processing loop - AliRawReader
+  //
+  AliTPCRawStreamV3 rawStreamV3(rawReader, (AliAltroMapping**)fMapping);
+  Bool_t res=ProcessEvent(&rawStreamV3);
+  if(res) {
+    fEventCounter++; // only increment event counter if there is TPC data
+
+    if(fEventCounter%fEventsPerBin==0)
+      UpdateEventHistograms();
+  }
+  return res;
+}
+
+//_____________________________________________________________________
+Bool_t AliTPCdataQA::ProcessEventFast(AliTPCRawStreamFast *const rawStreamFast)
 {
   //
   // Event Processing loop - AliTPCRawStream
@@ -238,62 +530,59 @@ Bool_t AliTPCdataQA::ProcessEventFast(AliTPCRawStreamFast *rawStreamFast)
   Int_t lastSector = -1;
 
   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
-       // Call local maxima finder if the data is in a new sector
-       if(iSector != lastSector) {
-         
-         if(nSignals>0)
-           FindLocalMaxima(lastSector);
-         
-         CleanArrays();
-         lastSector = iSector;
-         nSignals = 0;
-       }
-       
-       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 = rawStreamFast->GetSignals()[iTimeBin-startTbin];
-           nSignals += Update(iSector,iRow,iPad,iTimeBin+1,signal);
-           withInput = kTRUE;
-         }
-       }
+    while ( rawStreamFast->NextChannel() ){
+      
+      Int_t iSector  = rawStreamFast->GetSector(); //  current sector
+      Int_t iRow     = rawStreamFast->GetRow();    //  current row
+      Int_t iPad     = rawStreamFast->GetPad();    //  current pad
+  // Call local maxima finder if the data is in a new sector
+      if(iSector != lastSector) {
+        
+        if(nSignals>0)
+          FindLocalMaxima(lastSector);
+        
+        CleanArrays();
+        lastSector = iSector;
+        nSignals = 0;
       }
+      
+      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 = rawStreamFast->GetSignals()[iTimeBin-startTbin];
+          nSignals += Update(iSector,iRow,iPad,iTimeBin+1,signal);
+          withInput = kTRUE;
+        }
+      }
+    }
   }
   
   return withInput;
 }
 //_____________________________________________________________________
-Bool_t AliTPCdataQA::ProcessEventFast(AliRawReader *rawReader)
+Bool_t AliTPCdataQA::ProcessEventFast(AliRawReader *const rawReader)
 {
   //
   //  Event processing loop - AliRawReader
   //
-  AliTPCRawStreamFast *rawStreamFast = new AliTPCRawStreamFast(rawReader, (AliAltroMapping**)fMapping);
-  Bool_t res=ProcessEventFast(rawStreamFast);
+  AliTPCRawStreamFast rawStreamFast(rawReader, (AliAltroMapping**)fMapping);
+  Bool_t res=ProcessEventFast(&rawStreamFast);
   if(res)
     fEventCounter++; // only increment event counter if there is TPC data
                      // otherwise Analyse (called in QA) fails
 
-  delete rawStreamFast;
   return res;
 }
 
 //_____________________________________________________________________
-Bool_t AliTPCdataQA::ProcessEvent(AliTPCRawStream *rawStream)
+Bool_t AliTPCdataQA::ProcessEvent(AliTPCRawStream *const rawStream)
 {
   //
   // Event Processing loop - AliTPCRawStream
   //
 
-  rawStream->SetOldRCUFormat(fOldRCUformat);
-
   Bool_t withInput = kFALSE;
   Int_t nSignals = 0;
   Int_t lastSector = -1;
@@ -305,12 +594,12 @@ Bool_t AliTPCdataQA::ProcessEvent(AliTPCRawStream *rawStream)
     Int_t iPad     = rawStream->GetPad();         //  current pad
     Int_t iTimeBin = rawStream->GetTime();        //  current time bin
     Float_t signal = rawStream->GetSignal();      //  current ADC signal
-
+    
     // Call local maxima finder if the data is in a new sector
     if(iSector != lastSector) {
       
       if(nSignals>0)
-       FindLocalMaxima(lastSector);
+        FindLocalMaxima(lastSector);
       
       CleanArrays();
       lastSector = iSector;
@@ -324,12 +613,15 @@ Bool_t AliTPCdataQA::ProcessEvent(AliTPCRawStream *rawStream)
     }
   }
 
+  if (lastSector>=0&&nSignals>0)
+    FindLocalMaxima(lastSector);
+  
   return withInput;
 }
 
 
 //_____________________________________________________________________
-Bool_t AliTPCdataQA::ProcessEvent(AliRawReader *rawReader)
+Bool_t AliTPCdataQA::ProcessEventOld(AliRawReader *const rawReader)
 {
   //
   //  Event processing loop - AliRawReader
@@ -348,15 +640,14 @@ Bool_t AliTPCdataQA::ProcessEvent(AliRawReader *rawReader)
 
 
 //_____________________________________________________________________
-Bool_t AliTPCdataQA::ProcessEvent(eventHeaderStruct *event)
+Bool_t AliTPCdataQA::ProcessEvent(eventHeaderStruct *const event)
 {
   //
   //  process date event
   //
 
-  AliRawReader *rawReader = new AliRawReaderDate((void*)event);
-  Bool_t result=ProcessEvent(rawReader);
-  delete rawReader;
+  AliRawReaderDate rawReader((void*)event);
+  Bool_t result=ProcessEvent(&rawReader);
   return result;
 }
 
@@ -417,6 +708,23 @@ Int_t AliTPCdataQA::Update(const Int_t iSector, /*FOLD00*/
   if (!fOverThreshold10) fOverThreshold10 = new AliTPCCalPad("OverThreshold10","OverThreshold10");
   if (!fOverThreshold20) fOverThreshold20 = new AliTPCCalPad("OverThreshold20","OverThreshold20");
   if (!fOverThreshold30) fOverThreshold30 = new AliTPCCalPad("OverThreshold30","OverThreshold30");
+  if (!fHistQVsTimeSideA) {
+    fHistQVsTimeSideA  = new TProfile("hQVsTimeSideA", "Q vs time (side A); Time [Timebin]; Q [ADC ch]", 100, 0, 1000);
+    fHistQVsTimeSideA->SetDirectory(0);
+  }
+  if (!fHistQVsTimeSideC) {
+    fHistQVsTimeSideC  = new TProfile("hQVsTimeSideC", "Q vs time (side C); Time [Timebin]; Q [ADC ch]", 100, 0, 1000);
+    fHistQVsTimeSideC->SetDirectory(0);
+  }
+  if (!fHistQMaxVsTimeSideA) {
+    fHistQMaxVsTimeSideA  = new TProfile("hQMaxVsTimeSideA", "Q_{MAX} vs time (side A); Time [Timebin]; Q_{MAX} [ADC ch]", 100, 0, 1000);
+    fHistQMaxVsTimeSideA->SetDirectory(0);
+  }
+  if (!fHistQMaxVsTimeSideC) {
+    fHistQMaxVsTimeSideC  = new TProfile("hQMaxVsTimeSideC", "Q_{MAX} vs time (side C); Time [Timebin]; Q_{MAX} [ADC ch]", 100, 0, 1000);
+    fHistQMaxVsTimeSideC->SetDirectory(0);
+  }
+
   // Make the arrays for expanding the data
 
   if (!fAllBins)
@@ -478,6 +786,8 @@ Int_t AliTPCdataQA::Update(const Int_t iSector, /*FOLD00*/
   //
 
   SetExpandDigit(iRow, iPad, iTimeBin, signal);
+
+  fSignalCounter++;
   
   return 1; // signal was accepted
 }
@@ -591,9 +901,9 @@ void AliTPCdataQA::FindLocalMaxima(const Int_t iSector)
          if(i==0 && j==0)
            continue;
          
-         Float_t charge = GetQ(b, i, j, maxTimeBin, minT, maxT, minP, maxP);
-         qTot += charge;
-         if(charge>0) {
+         Float_t charge1 = GetQ(b, i, j, maxTimeBin, minT, maxT, minP, maxP);
+         qTot += charge1;
+         if(charge1>0) {
            // see if the next neighbor is also above threshold
            if(i*j==0) {
              qTot += GetQ(b, 2*i, 2*j, maxTimeBin, minT, maxT, minP, maxP); 
@@ -616,10 +926,18 @@ void AliTPCdataQA::FindLocalMaxima(const Int_t iSector)
       count = fNPads->GetCalROC(iSector)->GetValue(iRow, iPad);
       fNPads->GetCalROC(iSector)->SetValue(iRow, iPad, count + maxP-minP+1);
       
+      if((iSector%36)<18) { // A side
+       fHistQVsTimeSideA->Fill(iTimeBin, qTot);
+       fHistQMaxVsTimeSideA->Fill(iTimeBin, qMax);
+      } else {
+       fHistQVsTimeSideC->Fill(iTimeBin, qTot);
+       fHistQMaxVsTimeSideC->Fill(iTimeBin, qMax);      
+      }
     } // end loop over signals
   } // end loop over rows
   
   //  cout << "Number of local maximas found: " << nLocalMaxima << endl;
+  fClusterCounter += nLocalMaxima;
 }
 
 //_____________________________________________________________________
@@ -661,7 +979,7 @@ void AliTPCdataQA::Analyse()
 
 
 //_____________________________________________________________________
-void AliTPCdataQA::MakeTree(const char *fname){
+void AliTPCdataQA::MakeTree(const char *fname) const {
   //
   // Export result to the tree -located in the file
   // This file can be analyzed using AliTPCCalibViewer
@@ -727,9 +1045,24 @@ void AliTPCdataQA::CleanArrays(){
   //
 
   for (Int_t iRow = 0; iRow < fRowsMax; iRow++) {
-    //
-    Int_t maxBin = (fTimeBinsMax+4)*(fPadsMax+4); 
-    memset(fAllBins[iRow],0,sizeof(Float_t)*maxBin);
+
+    // To speed up the performance by a factor 2 on cosmic data (and
+    // presumably pp data as well) where the ocupancy is low, the
+    // memset is only called if there is more than 1000 signals for a
+    // row (of the order 1% occupancy)
+    if(fAllNSigBins[iRow]<1000) {
+      
+      Float_t* allBins = fAllBins[iRow];
+      Int_t* sigBins   = fAllSigBins[iRow];
+      const Int_t nSignals = fAllNSigBins[iRow];
+      for(Int_t i = 0; i < nSignals; i++)
+       allBins[sigBins[i]]=0;      
+    } else {
+
+      Int_t maxBin = (fTimeBinsMax+4)*(fPadsMax+4); 
+      memset(fAllBins[iRow],0,sizeof(Float_t)*maxBin);
+    }
+
     fAllNSigBins[iRow]=0;
   }
 }
@@ -776,7 +1109,7 @@ void AliTPCdataQA::SetExpandDigit(const Int_t iRow, Int_t iPad,
 Float_t AliTPCdataQA::GetQ(const Float_t* adcArray, const Int_t time, 
                           const Int_t pad, const Int_t maxTimeBins, 
                           Int_t& timeMin, Int_t& timeMax, 
-                          Int_t& padMin,  Int_t& padMax) 
+                          Int_t& padMin,  Int_t& padMax) const
 {
   //
   // This methods return the charge in the bin time+pad*maxTimeBins
@@ -790,3 +1123,39 @@ Float_t AliTPCdataQA::GetQ(const Float_t* adcArray, const Int_t time,
   }
   return charge; 
 }
+
+//______________________________________________________________________________
+void AliTPCdataQA::Streamer(TBuffer &xRuub)
+{
+  // Automatic schema evolution was first used from revision 4
+  // Code based on:
+  // http://root.cern.ch/root/roottalk/roottalk02/3207.html
+
+   UInt_t xRuus, xRuuc;
+   if (xRuub.IsReading()) {
+      Version_t xRuuv = xRuub.ReadVersion(&xRuus, &xRuuc);
+      //we use the automatic algorithm for class version > 3
+      if (xRuuv > 3) {
+       AliTPCdataQA::Class()->ReadBuffer(xRuub, this, xRuuv, xRuus,
+                                         xRuuc);
+       return;
+      }
+      TH1F::Streamer(xRuub);
+      xRuub >> fFirstTimeBin;
+      xRuub >> fLastTimeBin;
+      xRuub >> fAdcMin;
+      xRuub >> fAdcMax;
+      xRuub >> fNLocalMaxima;
+      xRuub >> fMaxCharge;
+      xRuub >> fMeanCharge;
+      xRuub >> fNoThreshold;
+      xRuub >> fNTimeBins;
+      xRuub >> fNPads;
+      xRuub >> fTimePosition;
+      xRuub >> fEventCounter;
+      xRuub >> fIsAnalysed;
+      xRuub.CheckByteCount(xRuus, xRuuc, AliTPCdataQA::IsA());
+   } else {
+     AliTPCdataQA::Class()->WriteBuffer(xRuub,this);
+   }
+}