]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSOnlineSPDscanAnalyzer.cxx
Add method to apply offline zero suppression to SDD raw data
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSPDscanAnalyzer.cxx
index f801c8befed72cf7a0eee40f6e80fc797c9c806c..eea2ce785ff8c9776b51320992a8a780d922f804 100644 (file)
@@ -32,6 +32,7 @@
 #include "AliITSRawStreamSPD.h"
 #include <TStyle.h>
 #include <TMath.h>
+#include <TLine.h>
 #include <TF1.h>
 #include <TGraph.h>
 #include <TH2F.h>
@@ -47,10 +48,17 @@ Double_t itsSpdErrorf(Double_t *x, Double_t *par){
 //Double_t itsSpdErrorfOrig(Double_t *x, Double_t *par){
 //  return 0.5+0.5*TMath::Erf((x[0]-par[0])/par[1]/sqrt(2.));
 //}
+//_________________________________________________________________________
+Double_t itsSpdScurveForMeanTh(Double_t *x, Double_t *par){
+  if (par[2]<0) par[2]=0;
+  Double_t val = 1.- par[2]*(1.-TMath::Erf((x[0]-par[0])/par[1]/sqrt(2.)));
+//  Double_t val = par[2]+(0.12*256*32-par[2])*(0.5+0.5*TMath::Erf((x[0]-par[0])/par[1]/sqrt(2.)));
+  return val;
+}
 
-
-AliITSOnlineSPDscanAnalyzer::AliITSOnlineSPDscanAnalyzer(const Char_t *fileName, AliITSOnlineCalibrationSPDhandler *handler) :
-  fType(99),fDacId(99),fFileName(fileName),fScanObj(NULL),fHandler(handler),fTriggers(NULL),
+//_________________________________________________________________________
+AliITSOnlineSPDscanAnalyzer::AliITSOnlineSPDscanAnalyzer(const Char_t *fileName, AliITSOnlineCalibrationSPDhandler *handler, Bool_t readFromGridFile) :
+  fType(99),fDacId(99),fFileName(fileName),fScanObj(NULL),fHandler(handler),fTriggers(NULL),fTPeff(0),fTPeffHS(NULL),fDeadPixel(0),fDeadPixelHS(NULL),fNoisyPixel(0),fNoisyPixelHS(NULL),
   fOverWrite(kFALSE),fNoiseThreshold(0.01),fNoiseMinimumEvents(100),
   fMinNrStepsBeforeIncrease(5),fMinIncreaseFromBaseLine(2),fStepDownDacSafe(5),fMaxBaseLineLevel(10)
 {
@@ -61,15 +69,21 @@ AliITSOnlineSPDscanAnalyzer::AliITSOnlineSPDscanAnalyzer(const Char_t *fileName,
       fHitEventEfficiency[hs][chipNr]=NULL;
     }
   }
+  for (UInt_t hs=0; hs<6; hs++) {
+    fTPeffChip[hs]=NULL;
+    fDeadPixelChip[hs]=NULL;
+    fNoisyPixelChip[hs]=NULL;
+  }
+
   for (UInt_t mod=0; mod<240; mod++) {
     fbModuleScanned[mod]=kFALSE;
   }
 
-  Init();
+  Init(readFromGridFile);
 }
-
+//_________________________________________________________________________
 AliITSOnlineSPDscanAnalyzer::AliITSOnlineSPDscanAnalyzer(const AliITSOnlineSPDscanAnalyzer& handle) :
-  fType(99),fDacId(99),fFileName("."),fScanObj(NULL),fHandler(NULL),fTriggers(NULL),
+  fType(99),fDacId(99),fFileName("."),fScanObj(NULL),fHandler(NULL),fTriggers(NULL),fTPeff(0),fTPeffHS(NULL),fDeadPixel(0),fDeadPixelHS(NULL),fNoisyPixel(0),fNoisyPixelHS(NULL),
   fOverWrite(kFALSE),fNoiseThreshold(0.01),fNoiseMinimumEvents(100),
   fMinNrStepsBeforeIncrease(5),fMinIncreaseFromBaseLine(2),fStepDownDacSafe(5),fMaxBaseLineLevel(10)
 {
@@ -89,29 +103,47 @@ AliITSOnlineSPDscanAnalyzer::AliITSOnlineSPDscanAnalyzer(const AliITSOnlineSPDsc
       fHitEventEfficiency[hs][chipNr]=NULL;
     }
   }
+  for (UInt_t hs=0; hs<6; hs++) {
+    fTPeffChip[hs]=NULL;
+    fDeadPixelChip[hs]=NULL;
+    fNoisyPixelChip[hs]=NULL;
+  }
+
   for (UInt_t mod=0; mod<240; mod++) {
     fbModuleScanned[mod]=kFALSE;
   }
 
   Init();
 }
-
+//_________________________________________________________________________
 AliITSOnlineSPDscanAnalyzer::~AliITSOnlineSPDscanAnalyzer() {
   // destructor
   for (UInt_t hs=0; hs<6; hs++) {
     for (UInt_t chipNr=0; chipNr<11; chipNr++) {
       if (fMeanMultiplicity[hs][chipNr]!=NULL) {
        delete fMeanMultiplicity[hs][chipNr];
+       fMeanMultiplicity[hs][chipNr]=NULL;
       }
       if (fHitEventEfficiency[hs][chipNr]!=NULL) {
        delete fHitEventEfficiency[hs][chipNr];
+       fHitEventEfficiency[hs][chipNr]=NULL;
       }
     }
   }
-  if (fTriggers!=NULL) delete fTriggers;
-  if (fScanObj!=NULL) delete fScanObj;
-}
 
+  if (fTriggers!=NULL) {
+    delete fTriggers;
+    fTriggers=NULL;
+  }
+
+  DeleteUniformityHistograms();
+
+  if (fScanObj!=NULL) {
+    delete fScanObj;
+    fScanObj=NULL;
+  }
+}
+//_________________________________________________________________________
 AliITSOnlineSPDscanAnalyzer& AliITSOnlineSPDscanAnalyzer::operator=(const AliITSOnlineSPDscanAnalyzer& handle) {
   // assignment operator, only copies the filename and params (not the processed data)
   if (this!=&handle) {
@@ -125,8 +157,17 @@ AliITSOnlineSPDscanAnalyzer& AliITSOnlineSPDscanAnalyzer::operator=(const AliITS
        }
       }
     }
-    if (fTriggers!=NULL) delete fTriggers;
-    if (fScanObj!=NULL) delete fScanObj;
+    if (fTriggers!=NULL) {
+      delete fTriggers;
+      fTriggers=NULL;
+    }
+
+    DeleteUniformityHistograms();
+
+    if (fScanObj!=NULL) {
+      delete fScanObj;
+      fScanObj=NULL;
+    }
    
     fFileName=handle.fFileName;
     fOverWrite=handle.fOverWrite;
@@ -146,10 +187,9 @@ AliITSOnlineSPDscanAnalyzer& AliITSOnlineSPDscanAnalyzer::operator=(const AliITS
     for (UInt_t mod=0; mod<240; mod++) {
       fbModuleScanned[mod]=kFALSE;
     }
-    fTriggers=NULL;
+
     fHandler=NULL;
     
-    fScanObj=NULL;
     fType=99;
     fDacId=99;
 
@@ -157,17 +197,20 @@ AliITSOnlineSPDscanAnalyzer& AliITSOnlineSPDscanAnalyzer::operator=(const AliITS
   }
   return *this;
 }
-
-void AliITSOnlineSPDscanAnalyzer::Init() {
+//_________________________________________________________________________
+void AliITSOnlineSPDscanAnalyzer::Init(Bool_t readFromGridFile) {
   // first checks type of container and then initializes container obj
-  FILE* fp0 = fopen(fFileName.Data(), "r");
-  if (fp0 == NULL) {
-    return;
-  }
-  else {
-    fclose(fp0);
+  if (!readFromGridFile) {
+    FILE* fp0 = fopen(fFileName.Data(), "r");
+    if (fp0 == NULL) {
+      return;
+    }
+    else {
+      fclose(fp0);
+    }
   }
-  fScanObj = new AliITSOnlineSPDscan(fFileName.Data());
+
+  fScanObj = new AliITSOnlineSPDscan(fFileName.Data(),readFromGridFile);
   fType = fScanObj->GetType();
   delete fScanObj;
 
@@ -175,16 +218,16 @@ void AliITSOnlineSPDscanAnalyzer::Init() {
   switch(fType) {
   case kUNIMA:
   case kNOISE:
-    fScanObj = new AliITSOnlineSPDscanSingle(fFileName.Data());
+    fScanObj = new AliITSOnlineSPDscanSingle(fFileName.Data(),readFromGridFile);
     break;
   case kMINTH:
   case kDAC:
   case kDELAY:
-    fScanObj = new AliITSOnlineSPDscanMultiple(fFileName.Data());
+    fScanObj = new AliITSOnlineSPDscanMultiple(fFileName.Data(),readFromGridFile);
     fDacId = ((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacId();
     break;
   case kMEANTH:
-    fScanObj = new AliITSOnlineSPDscanMeanTh(fFileName.Data());
+    fScanObj = new AliITSOnlineSPDscanMeanTh(fFileName.Data(),readFromGridFile);
     fDacId = ((AliITSOnlineSPDscanMeanTh*)fScanObj)->GetDacId();
     break;
   default:
@@ -195,7 +238,7 @@ void AliITSOnlineSPDscanAnalyzer::Init() {
   }
 
 }
-
+//_________________________________________________________________________
 void AliITSOnlineSPDscanAnalyzer::SetParam(const Char_t *pname, const Char_t *pval) {
   // set a parameter
   TString name = pname;
@@ -228,7 +271,7 @@ void AliITSOnlineSPDscanAnalyzer::SetParam(const Char_t *pname, const Char_t *pv
     Error("AliITSOnlineSPDscanAnalyzer::SetParam","Parameter %s in configuration file unknown.",name.Data());
   }
 }
-
+//_________________________________________________________________________
 void AliITSOnlineSPDscanAnalyzer::ReadParamsFromLocation(const Char_t *dirName) {
   // opens file (default name) in dir dirName and reads parameters from it
   TString paramsFileName = Form("%s/standal_params.txt",dirName);
@@ -250,15 +293,16 @@ void AliITSOnlineSPDscanAnalyzer::ReadParamsFromLocation(const Char_t *dirName)
     paramsFile.close();
   }
 }
-
-Bool_t AliITSOnlineSPDscanAnalyzer::IsModuleScanned(UInt_t module) const {
-  // is this module scanned?
-  if (module<240) {
-    return fbModuleScanned[module];
+//_________________________________________________________________________
+Bool_t AliITSOnlineSPDscanAnalyzer::IsChipPresent(UInt_t hs, UInt_t chipNr) {
+  // is the chip present?
+  if (fScanObj==NULL) {
+    Warning("AliITSOnlineSPDscanAnalyzer::IsChipPresent","No data!");
+    return kFALSE;
   }
-  return kFALSE;
+  return fScanObj->GetChipPresent(hs,chipNr);
 }
-
+//_________________________________________________________________________
 Bool_t AliITSOnlineSPDscanAnalyzer::ProcessDeadPixels(/*Char_t *oldcalibDir*/) {
   // process dead pixel data, for uniformity scan, 
   // NB: This will not be the general way of finding dead pixels.
@@ -283,13 +327,7 @@ Bool_t AliITSOnlineSPDscanAnalyzer::ProcessDeadPixels(/*Char_t *oldcalibDir*/) {
   for (UInt_t hs=0; hs<6; hs++) {
     for (UInt_t chipNr=0; chipNr<10; chipNr++) {
       if (fScanObj->GetChipPresent(hs,chipNr) && fScanObj->GetAverageMultiplicity(0,hs,chipNr)>0) { // check the status of the chippresent parameter in the mood header!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-       UInt_t module = AliITSRawStreamSPD::GetModuleNumber(routerNr,hs,chipNr);
-       if (!fbModuleScanned[module]) {
-         fbModuleScanned[module]=kTRUE;
-         //      fHandler[module]->SetFileLocation(oldcalibDir);
-         //      fHandler[module]->ReadFromFile(module);
-         if (fOverWrite) {fHandler->ResetDeadForChip(routerNr,hs,chipNr);}
-       }
+       if (fOverWrite) {fHandler->ResetDeadForChip(routerNr,hs,chipNr);}
        for (UInt_t col=0; col<32; col++) {
          for (UInt_t row=rowStart; row<=rowEnd; row++) {
            if (col!=1 && col!=9 && col!=17 && col!=25) { //exclude test columns!!!
@@ -304,9 +342,179 @@ Bool_t AliITSOnlineSPDscanAnalyzer::ProcessDeadPixels(/*Char_t *oldcalibDir*/) {
   }
   return kTRUE;
 }
+//_________________________________________________________________________
+Bool_t AliITSOnlineSPDscanAnalyzer::ProcessUniformity() {
+  // process uniformity scan data (thanks to Roberta Ferretti for providing this method)
+  if (fScanObj==NULL) {
+    Warning("AliITSOnlineSPDscanAnalyzer::ProcessUniformity","No data!");
+    return kFALSE;
+  }
+  // should be type kUNIMA
+  if (fType!=kUNIMA) {
+    Warning("AliITSOnlineSPDscanAnalyzer::ProcessUniformity","Only for scan type %d.",kUNIMA);
+    return kFALSE;
+  }
+
+  CreateUniformityHistograms(); // create all histograms that will be filled here
+
+  //  UInt_t routerNr = fScanObj->GetRouterNr();
+  UInt_t rowStart = fScanObj->GetRowStart();
+  UInt_t rowEnd   = fScanObj->GetRowEnd();
+  UInt_t nrTriggers = fScanObj->GetTriggers(0)/(rowEnd-rowStart+1);
+
+  Float_t pixel100=0;
+  Float_t zeri=0;
+  Float_t pixelN=0;
+  UInt_t numChipsActive=0;
 
+  for (UInt_t hs=0; hs<6; hs++) {
+    Float_t pixel100hs=0;
+    Float_t zerihs=0;
+    Float_t pixelNhs=0;
+    UInt_t numChipsActiveHS=0;
 
+    for (UInt_t chipNr=0; chipNr<10; chipNr++) {
+      Float_t pixel100chip=0;
+      Float_t zerichip=0;
+      Float_t pixelNchip=0;
 
+      if (fScanObj->GetChipPresent(hs,chipNr)) { // check the status of the chippresent parameter in the mood header!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+       numChipsActive++;
+       numChipsActiveHS++;
+
+       for (UInt_t col=0; col<32; col++) {
+         for (UInt_t row=rowStart; row<=rowEnd; row++) {
+           if (col!=1 && col!=9 && col!=17 && col!=25) { //exclude test columns!!!
+           
+             if (fScanObj->GetHits(0,hs,chipNr,col,row)==nrTriggers) {   
+                       pixel100++;
+                       pixel100hs++;
+                       pixel100chip++;
+             }
+             if (fScanObj->GetHits(0,hs,chipNr,col,row)==0) {
+                       zeri++;
+                       zerihs++;
+                       zerichip++;
+             }
+             if (fScanObj->GetHits(0,hs,chipNr,col,row)>nrTriggers) {    
+                       pixelN++;
+                       pixelNhs++;
+                       pixelNchip++;
+             }
+           }
+         }
+       }
+      
+       Float_t tPeffChip=(pixel100chip/(28*(rowEnd-rowStart+1)))*100;
+       fTPeffChip[hs]->Fill(chipNr,tPeffChip);
+       
+       Float_t deadPixelChip=(zerichip/(28*(rowEnd-rowStart+1)))*100;
+       fDeadPixelChip[hs]->Fill(chipNr,deadPixelChip);
+       
+       Float_t noisyPixelChip=(pixelNchip/(28*(rowEnd-rowStart+1)))*100;
+       fNoisyPixelChip[hs]->Fill(chipNr,noisyPixelChip);
+      }
+    }
+    
+    Float_t tPeffHS=(pixel100hs/(28*numChipsActiveHS*(rowEnd-rowStart+1)))*100;
+    fTPeffHS->Fill(hs,tPeffHS);
+    
+    Float_t deadPixelHS=(zerihs/(28*numChipsActiveHS*(rowEnd-rowStart+1)))*100;
+    fDeadPixelHS->Fill(hs,deadPixelHS);
+    
+    Float_t noisyPixelHS=(pixelNhs/(28*numChipsActiveHS*(rowEnd-rowStart+1)))*100;
+    fNoisyPixelHS->Fill(hs,noisyPixelHS);
+  }
+  
+  fTPeff=(pixel100/(28*numChipsActive*(rowEnd-rowStart+1)))*100;
+  fDeadPixel=(zeri/(28*numChipsActive*(rowEnd-rowStart+1)))*100;
+  fNoisyPixel=(pixelN/(28*numChipsActive*(rowEnd-rowStart+1)))*100;
+
+  return kTRUE;
+}
+//_________________________________________________________________________
+void AliITSOnlineSPDscanAnalyzer::CreateUniformityHistograms() {
+  // create uniformity histograms to be filled by "ProcessUniformity" method
+  DeleteUniformityHistograms(); // make sure no old histograms are lying around...
+  UInt_t eq = GetRouterNr();
+  TString label;
+
+  label = Form("Ratio of 'Good' Pixels Per HS (eq %d)",eq);
+  fTPeffHS = new TH1F(label.Data(),label.Data(),6,-0.5,5.5);
+  fTPeffHS->SetXTitle("hs");
+  fTPeffHS->SetYTitle("ratio [%]");
+  fTPeffHS->SetFillColor(kBlue);
+  fTPeffHS->SetStats(0);
+
+  label = Form("Ratio of 'Dead' Pixels Per HS (eq %d)",eq);
+  fDeadPixelHS = new TH1F(label.Data(),label.Data(),6,-0.5,5.5);
+  fDeadPixelHS->SetXTitle("hs");
+  fDeadPixelHS->SetYTitle("ratio [%]");
+  fDeadPixelHS->SetFillColor(kBlue);
+  fDeadPixelHS->SetStats(0);
+
+  label = Form("Ratio of 'Noisy' Pixels Per HS (eq %d)",eq);
+  fNoisyPixelHS = new TH1F(label.Data(),label.Data(),6,-0.5,5.5);
+  fNoisyPixelHS->SetXTitle("hs");
+  fNoisyPixelHS->SetYTitle("ratio [%]");
+  fNoisyPixelHS->SetFillColor(kBlue);
+  fNoisyPixelHS->SetStats(0);
+
+  for (UInt_t hs=0; hs<6; hs++) {
+    label = Form("Ratio of 'Good' Pixels Per Chip (eq %d, hs %d)",eq,hs);
+    fTPeffChip[hs] = new TH1F(label.Data(),label.Data(),10,-0.5,9.5);
+    fTPeffChip[hs]->SetXTitle("chip");
+    fTPeffChip[hs]->SetYTitle("ratio [%]");
+    fTPeffChip[hs]->SetFillColor(kBlue);
+    fTPeffChip[hs]->SetStats(0);
+
+    label = Form("Ratio of 'Dead' Pixels Per Chip (eq %d, hs %d)",eq,hs);
+    fDeadPixelChip[hs] = new TH1F(label.Data(),label.Data(),10,-0.5,9.5);
+    fDeadPixelChip[hs]->SetXTitle("chip");
+    fDeadPixelChip[hs]->SetYTitle("ratio [%]");
+    fDeadPixelChip[hs]->SetFillColor(kBlue);
+    fDeadPixelChip[hs]->SetStats(0);
+
+    label = Form("Ratio of 'Noisy' Pixels Per Chip (eq %d, hs %d)",eq,hs);
+    fNoisyPixelChip[hs] = new TH1F(label.Data(),label.Data(),10,-0.5,9.5);
+    fNoisyPixelChip[hs]->SetXTitle("chip");
+    fNoisyPixelChip[hs]->SetYTitle("ratio [%]");
+    fNoisyPixelChip[hs]->SetFillColor(kBlue);
+    fNoisyPixelChip[hs]->SetStats(0);
+  }
+
+}
+//_________________________________________________________________________
+void AliITSOnlineSPDscanAnalyzer::DeleteUniformityHistograms() {
+  // remove uniformity histograms if they are created
+  if (fTPeffHS!=NULL) {
+    delete fTPeffHS;
+    fTPeffHS=NULL;
+  }
+  if (fDeadPixelHS!=NULL) {
+    delete fDeadPixelHS;
+    fDeadPixelHS=NULL;
+  }
+  if (fNoisyPixelHS!=NULL) {
+    delete fNoisyPixelHS;
+    fNoisyPixelHS=NULL;
+  }
+  for (UInt_t hs=0; hs<6; hs++) {
+    if (fTPeffChip[hs]!=NULL) {
+      delete fTPeffChip[hs];
+      fTPeffChip[hs]=NULL;
+    }
+    if (fDeadPixelChip[hs]!=NULL) {
+      delete fDeadPixelChip[hs];
+      fDeadPixelChip[hs]=NULL;
+    }
+    if (fNoisyPixelChip[hs]!=NULL) {
+      delete fNoisyPixelChip[hs];
+      fNoisyPixelChip[hs]=NULL;
+    }
+  }
+}
+//_________________________________________________________________________
 Bool_t AliITSOnlineSPDscanAnalyzer::ProcessNoisyPixels(/*Char_t *oldcalibDir*/) {
   // process noisy pixel data
   if (fScanObj==NULL) {
@@ -333,11 +541,7 @@ Bool_t AliITSOnlineSPDscanAnalyzer::ProcessNoisyPixels(/*Char_t *oldcalibDir*/)
   for (UInt_t hs=0; hs<6; hs++) {
     for (UInt_t chipNr=0; chipNr<10; chipNr++) {
       if (fScanObj->GetChipPresent(hs,chipNr)) { // check the status of the chippresent parameter in the mood header!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-       UInt_t module = AliITSRawStreamSPD::GetModuleNumber(routerNr,hs,chipNr);
-       if (!fbModuleScanned[module]) {
-         fbModuleScanned[module]=kTRUE;
-         if (fOverWrite) {fHandler->ResetNoisyForChip(routerNr,hs,chipNr);}
-       }
+       if (fOverWrite) {fHandler->ResetNoisyForChip(routerNr,hs,chipNr);}
        for (UInt_t col=0; col<32; col++) {
          for (UInt_t row=0; row<256; row++) {
            if (fScanObj->GetHitsEfficiency(0,hs,chipNr,col,row)>fNoiseThreshold) {
@@ -350,7 +554,7 @@ Bool_t AliITSOnlineSPDscanAnalyzer::ProcessNoisyPixels(/*Char_t *oldcalibDir*/)
   }
   return kTRUE;
 }
-
+//_________________________________________________________________________
 Int_t AliITSOnlineSPDscanAnalyzer::GetDelay(UInt_t hs, UInt_t chipNr) {
   // get delay
   if (hs>=6 || chipNr>10) return -1;
@@ -389,8 +593,7 @@ Int_t AliITSOnlineSPDscanAnalyzer::GetDelay(UInt_t hs, UInt_t chipNr) {
   }
 
 }
-
-
+//_________________________________________________________________________
 Int_t AliITSOnlineSPDscanAnalyzer::GetNrNoisyUnima(UInt_t hs, UInt_t chipNr) {
   // in case of a uniformity scan, returns the nr of noisy pixels, (here > 200 hits)
   if (hs>=6 || chipNr>10) return -1;
@@ -423,7 +626,7 @@ Int_t AliITSOnlineSPDscanAnalyzer::GetNrNoisyUnima(UInt_t hs, UInt_t chipNr) {
   }
   return nrNoisy;
 }
-
+//_________________________________________________________________________
 Int_t AliITSOnlineSPDscanAnalyzer::FindLastMinThDac(UInt_t hs, UInt_t chipNr) {
   // returns dac value where fMinIncreaseFromBaseLine reached
   if (hs>=6 || chipNr>10) return -1;
@@ -455,7 +658,7 @@ Int_t AliITSOnlineSPDscanAnalyzer::FindClosestLowerStep(Float_t dacValueInput) {
   }
   return step;
 }
-
+//_________________________________________________________________________
 Float_t AliITSOnlineSPDscanAnalyzer::GetCompareLine(UInt_t step, UInt_t hs, UInt_t chipNr, Float_t basePar2) {
   // returns value to compare mean mult with (when finding min th)
   if (hs>=6 || chipNr>10) return -1;
@@ -550,9 +753,62 @@ Int_t AliITSOnlineSPDscanAnalyzer::GetMinTh(UInt_t hs, UInt_t chipNr) {
     return -1;
   }
 }
+//_________________________________________________________________________
+TArrayI AliITSOnlineSPDscanAnalyzer::GetMeanTh(UInt_t hs, UInt_t chipNr) {
+  // calculates and returns the mean threshold
+  TArrayI fitresults(4);
+  if (hs>=6 || chipNr>10) return fitresults;
+  if (fScanObj==NULL) {
+    Error("AliITSOnlineSPDscanAnalyzer::GetMeanTh","No data!");
+    return fitresults;
+  }
+  // should be type  kMEANTH  or  kDAC with id 39
+  if (fType!=kMEANTH && (fType!=kDAC || fDacId!=105)) {
+    Error("AliITSOnlineSPDscanAnalyzer::GetMeanTh","MeanTh only for scan type %d OR %d with dac_id 105.",kMEANTH,kDAC);
+    return fitresults;
+  }
+  if (fHitEventEfficiency[hs][chipNr]==NULL) {
+   printf("processing hit efficiency \n");
+    if (!ProcessHitEventEfficiency()) {
+      printf("...not processed!!\n");
+      return fitresults;
+    }
+  }
+  Double_t x,y;
+  fHitEventEfficiency[hs][chipNr]->GetPoint(fHitEventEfficiency[hs][chipNr]->GetN()-1,x,y);
+  Double_t min = x;
+  fHitEventEfficiency[hs][chipNr]->GetPoint(0,x,y);
+  Double_t max = x;
+
+  Double_t mean = 0.5*(min+max);
+  TString funcName = Form("Fit meanth func HS%d CHIP%d",hs,chipNr);
+  TF1 *minThFunc = new TF1(funcName.Data(),itsSpdScurveForMeanTh,min,max,3);
+  minThFunc->SetParameter(0,mean);
+  minThFunc->SetParameter(1,264); //  4 (mV) * 66 (el)
+  minThFunc->SetParLimits(1,100,1000); // minimum value is 1 mV (-> 100 in TPAmplitude)
+  minThFunc->SetParameter(2,0.4);
+  minThFunc->SetParName(0,"Mean");
+  minThFunc->SetParName(1,"Sigma");
+  minThFunc->SetParName(2,"Half");
+  minThFunc->SetLineWidth(1);
 
+  fHitEventEfficiency[hs][chipNr]->Fit(funcName,"Q","",min,max);
 
+  fitresults.AddAt((Int_t)minThFunc->GetParameter(0),0);
+  fitresults.AddAt((Int_t)minThFunc->GetParError(0),1);
+  fitresults.AddAt((Int_t)minThFunc->GetParameter(1),2);
+  fitresults.AddAt((Int_t)minThFunc->GetParError(1),3);
+  TLine *ly = new TLine((Double_t)min,0.5,(Double_t)fitresults.At(0),0.5); ly->SetLineStyle(6);
+  ly->Draw("same");
+  TLine *lx = new TLine((Double_t)fitresults.At(0),0.,(Double_t)fitresults.At(0),0.5);
+  lx->SetLineStyle(6);
+  lx->Draw("same");
+  delete minThFunc;
+  
+  return fitresults;
+}
 
+//_________________________________________________________________________
 Bool_t AliITSOnlineSPDscanAnalyzer::ProcessMeanMultiplicity() {
   // process mean multiplicity data
   if (fScanObj==NULL) {
@@ -582,7 +838,7 @@ Bool_t AliITSOnlineSPDscanAnalyzer::ProcessMeanMultiplicity() {
   }
   return kTRUE;
 }
-
+//_________________________________________________________________________
 TGraph* AliITSOnlineSPDscanAnalyzer::GetMeanMultiplicityG(UInt_t hs, UInt_t chipNr) {
   // returns mean multiplicity graph
   if (hs>=6 || chipNr>10) return NULL;
@@ -593,7 +849,7 @@ TGraph* AliITSOnlineSPDscanAnalyzer::GetMeanMultiplicityG(UInt_t hs, UInt_t chip
   }
   return fMeanMultiplicity[hs][chipNr];
 }
-
+//_________________________________________________________________________
 Bool_t AliITSOnlineSPDscanAnalyzer::ProcessHitEventEfficiency() {
   // process hit event efficiency
   if (fScanObj==NULL) {
@@ -611,10 +867,11 @@ Bool_t AliITSOnlineSPDscanAnalyzer::ProcessHitEventEfficiency() {
          fHitEventEfficiency[hs][chipNr] = new TGraph();
        }
        Float_t efficiency=fScanObj->GetHitEventsEfficiency(step,hs,chipNr);
-       if (fType==kMINTH || fType==kMEANTH || fType==kDAC || fType==kDELAY) {
+       if (fType==kMINTH || fType==kDAC || fType==kDELAY) {
          fHitEventEfficiency[hs][chipNr]->SetPoint(step,((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(step),efficiency);
-       }
-       else {
+       } else if(fType==kMEANTH){
+          fHitEventEfficiency[hs][chipNr]->SetPoint(step,((AliITSOnlineSPDscanMeanTh*)fScanObj)->GetTPAmp(step,hs),efficiency);
+        } else {
          fHitEventEfficiency[hs][chipNr]->SetPoint(step,0,efficiency);
        }
       }
@@ -623,7 +880,7 @@ Bool_t AliITSOnlineSPDscanAnalyzer::ProcessHitEventEfficiency() {
   }
   return kTRUE;
 }
-
+//_________________________________________________________________________
 TGraph* AliITSOnlineSPDscanAnalyzer::GetHitEventEfficiencyG(UInt_t hs, UInt_t chipNr) {
   // returns hit event efficiency graph
   if (hs>=6 || chipNr>10) return NULL;
@@ -634,8 +891,7 @@ TGraph* AliITSOnlineSPDscanAnalyzer::GetHitEventEfficiencyG(UInt_t hs, UInt_t ch
   }
   return fHitEventEfficiency[hs][chipNr];
 }
-
-
+//_________________________________________________________________________
 Bool_t AliITSOnlineSPDscanAnalyzer::ProcessNrTriggers() {
   // process nr of triggers data
   if (fScanObj==NULL) {
@@ -658,7 +914,7 @@ Bool_t AliITSOnlineSPDscanAnalyzer::ProcessNrTriggers() {
   }
   return kTRUE;
 }
-
+//_________________________________________________________________________
 TGraph* AliITSOnlineSPDscanAnalyzer::GetNrTriggersG() {
   // returns nr of triggers graph
   if (fTriggers==NULL) {
@@ -668,7 +924,7 @@ TGraph* AliITSOnlineSPDscanAnalyzer::GetNrTriggersG() {
   }
   return fTriggers;
 }
-
+//_________________________________________________________________________
 Bool_t AliITSOnlineSPDscanAnalyzer::GetHalfStavePresent(UInt_t hs) {
   // returns half stave present info
   if (hs<6 && fScanObj!=NULL) {
@@ -680,13 +936,13 @@ Bool_t AliITSOnlineSPDscanAnalyzer::GetHalfStavePresent(UInt_t hs) {
   }
   return kFALSE;
 }
-
+//_________________________________________________________________________
 UInt_t AliITSOnlineSPDscanAnalyzer::GetRouterNr() {
   // returns the router nr of scan obj
   if (fScanObj!=NULL) return fScanObj->GetRouterNr(); 
   else return 99;
 }
-
+//_________________________________________________________________________
 TH2F* AliITSOnlineSPDscanAnalyzer::GetHitMapTot(UInt_t step) {
   // creates and returns a pointer to a hitmap histo (half sector style a la spdmood)
   if (fScanObj==NULL) {
@@ -718,7 +974,45 @@ TH2F* AliITSOnlineSPDscanAnalyzer::GetHitMapTot(UInt_t step) {
   }
   return fHitMapTot;
 }
+//_________________________________________________________________________
+TH2F* AliITSOnlineSPDscanAnalyzer::GetPhysicalHitMapTot(UInt_t step) {
+  // creates and returns a pointer to a hitmap histo (-> 1 equpment opened up)
+
+  if (fScanObj==NULL) {
+    Error("AliITSOnlineSPDscanAnalyzer::GetHitMapTot","No data!");
+    return NULL;
+  }
+  TString histoname;
+  if (fType==kMINTH || fType==kMEANTH || fType==kDAC) {
+    histoname = Form("Router %d , DAC %d",GetRouterNr(),((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(step));
+  }
+  else {
+    histoname = Form("Router %d ",GetRouterNr());
+  }
+  TH2F* hPhysicalHitMapTot = new TH2F(histoname.Data(),histoname.Data(),32*10,-0.5,32*10-0.5,256*6,-0.5,256*6-0.5);
+  hPhysicalHitMapTot->SetNdivisions(-10,"X");
+  hPhysicalHitMapTot->SetNdivisions(-006,"Y");
+  hPhysicalHitMapTot->SetTickLength(0,"X");
+  hPhysicalHitMapTot->SetTickLength(0,"Y");
+  hPhysicalHitMapTot->GetXaxis()->SetLabelColor(gStyle->GetCanvasColor());
+  hPhysicalHitMapTot->GetYaxis()->SetLabelColor(gStyle->GetCanvasColor());
+  Int_t correctChip = -1;
+  for (UInt_t hs=0; hs<6; hs++) {
+    for (UInt_t chipNr=0; chipNr<10; chipNr++) {
+    if(GetRouterNr()<10) correctChip = 9-chipNr;
+    else correctChip=chipNr;
+      for (UInt_t col=0; col<32; col++) {
+       for (UInt_t row=0; row<256; row++) {
+          if(hs<2) hPhysicalHitMapTot->Fill(correctChip*32+col,(5-hs)*256+row,fScanObj->GetHits(step,hs,chipNr,col,row));
+         else hPhysicalHitMapTot->Fill(correctChip*32+(31-col),(5-hs)*256+row,fScanObj->GetHits(step,hs,chipNr,col,row));
+       }
+      }
+    }
+  }
+  return hPhysicalHitMapTot;
+}
 
+//_________________________________________________________________________
 TH2F* AliITSOnlineSPDscanAnalyzer::GetHitMapChip(UInt_t step, UInt_t hs, UInt_t chip) {
   // creates and returns a pointer to a hitmap histo (chip style a la spdmood)
   if (fScanObj==NULL) {
@@ -729,15 +1023,17 @@ TH2F* AliITSOnlineSPDscanAnalyzer::GetHitMapChip(UInt_t step, UInt_t hs, UInt_t
   TString histoName;
   TString histoTitle;
   histoName = Form("fChipHisto_%d_%d_%d", GetRouterNr(), hs, chip);
-  histoTitle = Form("Eq ID %d, Half Stave %d, Chip %d", GetRouterNr(), hs, chip);
+  histoTitle = Form("Eq ID %d, Half Stave %d, Chip %d ", GetRouterNr(), hs, chip);
 
   TH2F *returnHisto = new TH2F(histoName.Data(), histoTitle.Data(), 32, -0.5, 31.5, 256, -0.5, 255.5);
   returnHisto->SetMinimum(0);
   for (UInt_t col=0; col<32; col++) {
     for (UInt_t row=0; row<256; row++) {
-      returnHisto->Fill(col,row,fScanObj->GetHits(step,hs,chip,col,row));
+      if(hs<2) returnHisto->Fill(31-col,row,fScanObj->GetHits(step,hs,chip,col,row));
+      else returnHisto->Fill(col,row,fScanObj->GetHits(step,hs,chip,col,row));
     }
   }
 
   return returnHisto;
 }
+