]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCdataQA.cxx
Missing protection - check the presence of array
[u/mrichter/AliRoot.git] / TPC / AliTPCdataQA.cxx
index 036e22bef3bbaed0babacc1d54b4229f794d8cfa..bfaf56c66a52400b7d10634db6ebae6b2ab7a8e5 100644 (file)
@@ -77,6 +77,7 @@ using namespace std;
 #include "AliRawReaderRoot.h"
 #include "AliRawReaderDate.h"
 #include "AliTPCRawStream.h"
+#include "AliTPCRawStreamV3.h"
 #include "AliTPCCalROC.h"
 #include "AliTPCROC.h"
 #include "AliMathBase.h"
@@ -111,6 +112,10 @@ AliTPCdataQA::AliTPCdataQA() : /*FOLD00*/
   fOverThreshold10(0),
   fOverThreshold20(0),
   fOverThreshold30(0),
+  fHistQVsTimeSideA(0),
+  fHistQVsTimeSideC(0),
+  fHistQMaxVsTimeSideA(0),
+  fHistQMaxVsTimeSideC(0),
   fEventCounter(0),
   fIsAnalysed(kFALSE),
   fAllBins(0),
@@ -144,6 +149,10 @@ fTimePosition(0),
 fOverThreshold10(0),
 fOverThreshold20(0),
 fOverThreshold30(0),
+fHistQVsTimeSideA(0),
+fHistQVsTimeSideC(0),
+fHistQMaxVsTimeSideA(0),
+fHistQMaxVsTimeSideC(0),
 fEventCounter(0),
 fIsAnalysed(kFALSE),
 fAllBins(0),
@@ -178,6 +187,10 @@ AliTPCdataQA::AliTPCdataQA(const AliTPCdataQA &ped) : /*FOLD00*/
   fOverThreshold10(0),
   fOverThreshold20(0),
   fOverThreshold30(0),
+  fHistQVsTimeSideA(0),
+  fHistQVsTimeSideC(0),
+  fHistQMaxVsTimeSideA(0),
+  fHistQMaxVsTimeSideC(0),
   fEventCounter(ped.GetEventCounter()),
   fIsAnalysed(ped.GetIsAnalysed()),
   fAllBins(0),
@@ -210,6 +223,22 @@ 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);
+  }
 }
 
 //_____________________________________________________________________
@@ -232,6 +261,10 @@ AliTPCdataQA::AliTPCdataQA(const TMap *config) : /*FOLD00*/
   fOverThreshold10(0),
   fOverThreshold20(0),
   fOverThreshold30(0),
+  fHistQVsTimeSideA(0),
+  fHistQVsTimeSideC(0),
+  fHistQMaxVsTimeSideA(0),
+  fHistQMaxVsTimeSideC(0),
   fEventCounter(0),
   fIsAnalysed(kFALSE),
   fAllBins(0),
@@ -284,6 +317,10 @@ AliTPCdataQA::~AliTPCdataQA() /*FOLD00*/
   delete fOverThreshold10;
   delete fOverThreshold20;
   delete fOverThreshold30;
+  delete fHistQVsTimeSideA;
+  delete fHistQVsTimeSideC;
+  delete fHistQMaxVsTimeSideA;
+  delete fHistQMaxVsTimeSideC;
 
   for (Int_t iRow = 0; iRow < fRowsMax; iRow++) {
     delete [] fAllBins[iRow];
@@ -293,6 +330,65 @@ AliTPCdataQA::~AliTPCdataQA() /*FOLD00*/
   delete [] fAllSigBins;
   delete [] fAllNSigBins;
 }
+//_____________________________________________________________________
+Bool_t AliTPCdataQA::ProcessEvent(AliTPCRawStreamV3 *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 *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
+  return res;
+}
 
 //_____________________________________________________________________
 Bool_t AliTPCdataQA::ProcessEventFast(AliTPCRawStreamFast *rawStreamFast)
@@ -305,33 +401,33 @@ 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;
@@ -342,13 +438,12 @@ Bool_t AliTPCdataQA::ProcessEventFast(AliRawReader *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;
 }
 
@@ -370,12 +465,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;
@@ -389,12 +484,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 *rawReader)
 {
   //
   //  Event processing loop - AliRawReader
@@ -419,9 +517,8 @@ Bool_t AliTPCdataQA::ProcessEvent(eventHeaderStruct *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;
 }
 
@@ -482,6 +579,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)
@@ -681,6 +795,13 @@ 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
   
@@ -792,9 +913,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;
   }
 }
@@ -855,3 +991,39 @@ Float_t AliTPCdataQA::GetQ(const Float_t* adcArray, const Int_t time,
   }
   return charge; 
 }
+
+//______________________________________________________________________________
+void AliTPCdataQA::Streamer(TBuffer &R__b)
+{
+  // Automatic schema evolution was first used from revision 4
+  // Code based on:
+  // http://root.cern.ch/root/roottalk/roottalk02/3207.html
+
+   UInt_t R__s, R__c;
+   if (R__b.IsReading()) {
+      Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
+      //we use the automatic algorithm for class version > 3
+      if (R__v > 3) {
+       AliTPCdataQA::Class()->ReadBuffer(R__b, this, R__v, R__s,
+                                         R__c);
+       return;
+      }
+      TH1F::Streamer(R__b);
+      R__b >> fFirstTimeBin;
+      R__b >> fLastTimeBin;
+      R__b >> fAdcMin;
+      R__b >> fAdcMax;
+      R__b >> fNLocalMaxima;
+      R__b >> fMaxCharge;
+      R__b >> fMeanCharge;
+      R__b >> fNoThreshold;
+      R__b >> fNTimeBins;
+      R__b >> fNPads;
+      R__b >> fTimePosition;
+      R__b >> fEventCounter;
+      R__b >> fIsAnalysed;
+      R__b.CheckByteCount(R__s, R__c, AliTPCdataQA::IsA());
+   } else {
+     AliTPCdataQA::Class()->WriteBuffer(R__b,this);
+   }
+}