Added two missing includes to allow macro compilation (thanks to Laurent for remarkin...
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSDDTP.cxx
index 54d4d35..a4efc27 100644 (file)
@@ -12,6 +12,7 @@
  * about the suitability of this software for any purpose. It is          *
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
+#include <TFile.h>
 #include "AliITSOnlineSDDTP.h"
 #include "AliLog.h"
 #include <TH2F.h>
 ClassImp(AliITSOnlineSDDTP)
 
 //______________________________________________________________________
-AliITSOnlineSDDTP::AliITSOnlineSDDTP():AliITSOnlineSDD(),fNEvents(0),fDAC(0.),fNSigmaGain(0.)
+AliITSOnlineSDDTP::AliITSOnlineSDDTP():AliITSOnlineSDD(),fDAC(0.),fLowThreshold(0),fHighThreshold(0),fNSigmaGain(0.),fNSigmaNoise(0.)
 {
   // default constructor
   Reset();
   SetNSigmaGain();
+  SetNSigmaNoise();
 }
 //______________________________________________________________________
-AliITSOnlineSDDTP::AliITSOnlineSDDTP(Int_t mod, Int_t sid, Float_t xDAC):AliITSOnlineSDD(mod,sid),fNEvents(0),fDAC(xDAC),fNSigmaGain(0.)
+AliITSOnlineSDDTP::AliITSOnlineSDDTP(Int_t nddl, Int_t ncarlos, Int_t sid, Float_t xDAC):AliITSOnlineSDD(nddl,ncarlos,sid),fDAC(xDAC),fLowThreshold(0),fHighThreshold(0),fNSigmaGain(0.),fNSigmaNoise(0.)
 {
   // standard constructor
   Reset();
   SetNSigmaGain();
+  SetNSigmaNoise();
 }
 //______________________________________________________________________
 AliITSOnlineSDDTP::~AliITSOnlineSDDTP(){
@@ -49,10 +52,13 @@ AliITSOnlineSDDTP::~AliITSOnlineSDDTP(){
 //______________________________________________________________________
 void AliITSOnlineSDDTP::Reset(){
   //
-  fNEvents=0;
   for(Int_t i=0;i<fgkNAnodes;i++){
+    fNEvents[i]=0;
     fGoodAnode[i]=1;
     fBaseline[i]=0.;
+    fCMN[i]=0.;
+    fRawNoise[i]=0.;
+    fCorrNoise[i]=0.;
     fSumTPPeak[i]=0.;
     fTPPos[i]=0.;
   }
@@ -62,48 +68,68 @@ void AliITSOnlineSDDTP::Reset(){
 //______________________________________________________________________
 void AliITSOnlineSDDTP::AddEvent(TH2F* hrawd){
   // 
-  fNEvents++;
-  Double_t tbmax=(Double_t)hrawd->GetNbinsX();
   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     Float_t auxmax=0.;
     Int_t auxtb=0;
     if(!fGoodAnode[ian]) continue;
-    for(Int_t itb=0;itb<tbmax;itb++){
+    for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
       Float_t cnt=hrawd->GetBinContent(itb+1,ian+1);
       if(cnt>auxmax){ 
        auxmax=cnt;
        auxtb=itb;
       }
     }
-    fSumTPPeak[ian]+=auxmax-fBaseline[ian];
-    fTPPos[ian]+=auxtb;
+    if(auxmax>fBaseline[ian]+fNSigmaNoise*fRawNoise[ian]){
+      fSumTPPeak[ian]+=auxmax-fBaseline[ian];
+      fTPPos[ian]+=auxtb;
+      fNEvents[ian]++;
+    }
   }
 }
 //______________________________________________________________________
 void AliITSOnlineSDDTP::ReadBaselines(){
   // assume baselines and good anodes are taken from previous run
   Char_t basfilnam[100];
-  sprintf(basfilnam,"SDDbase_step2_mod%03d_sid%d.data",fModuleId,fSide);
+  sprintf(basfilnam,"SDDbase_step2_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
   FILE* basf=fopen(basfilnam,"r");
   if(basf==0){
-    AliWarning("Baselinefile not present, Set all baselines to 50\n");
+    AliWarning(Form("Baseline file not present (ddl %d  carlos %d side %d, Set all baselines to 20",fDDL,fCarlos,fSide));
     for(Int_t ian=0;ian<fgkNAnodes;ian++){ 
-      fBaseline[ian]=50.;
+      fBaseline[ian]=20.;
+      fEqBaseline[ian]=20;
+      fOffsetBaseline[ian]=0;
       fGoodAnode[ian]=1;
     }
     return;
   }
-  Int_t n,ok;
+  fscanf(basf,"%d\n",&fHighThreshold);
+  fscanf(basf,"%d\n",&fLowThreshold);
+  Int_t n,ok,eqbase,offbase;
   Float_t base,rms,cmn,corrnoi;
   for(Int_t ian=0;ian<fgkNAnodes;ian++){
-    fscanf(basf,"%d %d %f %f %f %f\n",&n,&ok,&base,&rms,&cmn,&corrnoi);
+    fscanf(basf,"%d %d %f %d %d %f %f %f\n",&n,&ok,&base,&eqbase,&offbase,&rms,&cmn,&corrnoi);
     fBaseline[ian]=base;
+    fEqBaseline[ian]=eqbase;
+    fOffsetBaseline[ian]=offbase;
     fGoodAnode[ian]=ok;
+    fRawNoise[ian]=rms;
+    fCMN[ian]=cmn;
+    fCorrNoise[ian]=corrnoi;
   }
   fclose(basf);
 }
 
 //______________________________________________________________________
+Bool_t AliITSOnlineSDDTP::IsModuleGood() const{
+  //
+  // Check if there is at least 1 good anode
+  //
+  for(Int_t ian=0;ian<fgkNAnodes;ian++){
+    if(fGoodAnode[ian]) return kTRUE;
+  }
+  return kFALSE;
+}
+//______________________________________________________________________
 void AliITSOnlineSDDTP::ValidateAnodes(){
   //
   Float_t meang,rmsg;
@@ -125,13 +151,17 @@ void AliITSOnlineSDDTP::StatGain(Float_t &mean, Float_t  &rms){
   Int_t cnt=0;
   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     if(!fGoodAnode[ian]) continue;
-    sum+=GetChannelGain(ian);
-    sumq+=TMath::Power(GetChannelGain(ian),2);
+    if(fNEvents[ian]==0) continue;
+    Float_t chgain=GetChannelGain(ian);
+    sum+=chgain;
+    sumq+=chgain*chgain;
     cnt++;
   }
   if(cnt>0){ 
     mean=sum/(Float_t)cnt;
-    rms=TMath::Sqrt(sumq/(Float_t)cnt-mean*mean);
+    Float_t variance=sumq/(Float_t)cnt-mean*mean;
+    if(variance>0.) rms=TMath::Sqrt(variance);
+    else rms = 0;
   }else{ 
     mean=0.;
     rms=0.;
@@ -142,29 +172,122 @@ void AliITSOnlineSDDTP::StatGain(Float_t &mean, Float_t  &rms){
 //______________________________________________________________________
 void AliITSOnlineSDDTP::WriteToASCII(){
   //
-  Char_t basfilnam[100];
-  sprintf(basfilnam,"SDDbase_step2_mod%03d_sid%d.data",fModuleId,fSide);
-  FILE* basf=fopen(basfilnam,"r");
-  if(basf==0){
-    AliWarning("Baseline file not present, launch baseline analysis first\n");
-    return;
-  }
-  Int_t n,ok;
-  Float_t base,rms,cmn,corrnoi;
-  Float_t noise[fgkNAnodes],cmncoef[fgkNAnodes],corrnoise[fgkNAnodes];
-  for(Int_t ian=0;ian<fgkNAnodes;ian++){
-    fscanf(basf,"%d %d %f %f %f %f\n",&n,&ok,&base,&rms,&cmn,&corrnoi);
-    noise[ian]=rms;
-    cmncoef[ian]=cmn;
-    corrnoise[ian]=corrnoi;
-  }
-  fclose(basf);
   Char_t outfilnam[100];
-  sprintf(outfilnam,"SDDbase_mod%03d_sid%d.data",fModuleId,fSide);
+  sprintf(outfilnam,"SDDbase_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
   FILE* outf=fopen(outfilnam,"w");
+  fprintf(outf,"%d %d %d\n",fCarlos,fSide,IsModuleGood());
+  fprintf(outf,"%d\n",fHighThreshold);
+  fprintf(outf,"%d\n",fLowThreshold);
   for(Int_t ian=0;ian<fgkNAnodes;ian++){
-    fprintf(outf,"%d %d %8.3f %8.3f %8.3f %8.3f %8.3f\n",ian,IsAnodeGood(ian),fBaseline[ian], noise[ian],cmncoef[ian],corrnoise[ian],GetChannelGain(ian));
+    fprintf(outf,"%d %d %8.3f %d %d %8.3f %8.3f %8.3f %8.3f\n",ian,IsAnodeGood(ian),GetAnodeBaseline(ian),GetAnodeEqualizedBaseline(ian),GetAnodeBaselineOffset(ian),GetAnodeRawNoise(ian),GetAnodeCommonMode(ian),GetAnodeCorrNoise(ian),GetChannelGain(ian));
   }
   fclose(outf);  
 }
+//______________________________________________________________________
+TH1F* AliITSOnlineSDDTP::GetBaselineAnodeHisto() const {
+  //
+  Char_t hisnam[20];  
+  sprintf(hisnam,"hbase%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
+  for(Int_t ian=0;ian<fgkNAnodes;ian++){
+    h->SetBinContent(ian+1,GetAnodeBaseline(ian));
+  }
+  return h;
+}
+//______________________________________________________________________
+TH1F* AliITSOnlineSDDTP::GetRawNoiseAnodeHisto() const {
+  //
+  Char_t hisnam[20];  
+  sprintf(hisnam,"hnois%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
+  for(Int_t ian=0;ian<fgkNAnodes;ian++){
+    h->SetBinContent(ian+1,GetAnodeRawNoise(ian));
+  }
+  return h;
+}
+//______________________________________________________________________
+TH1F* AliITSOnlineSDDTP::GetCorrNoiseAnodeHisto() const {
+  //
+  Char_t hisnam[20];  
+  sprintf(hisnam,"hcorn%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
+  for(Int_t ian=0;ian<fgkNAnodes;ian++){
+    h->SetBinContent(ian+1,GetAnodeCorrNoise(ian));
+  }
+  return h;
+}
+//______________________________________________________________________
+TH1F* AliITSOnlineSDDTP::GetCMNCoefAnodeHisto() const {
+//
+  Char_t hisnam[20];  
+  sprintf(hisnam,"hcmn%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
+  for(Int_t ian=0;ian<fgkNAnodes;ian++){
+    h->SetBinContent(ian+1,GetAnodeCommonMode(ian));
+  }
+  return h;
+}
+//______________________________________________________________________
+TH1F* AliITSOnlineSDDTP::GetStatusAnodeHisto() const {
+//
+  Char_t hisnam[20];  
+  sprintf(hisnam,"hgood%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
+  for(Int_t ian=0;ian<fgkNAnodes;ian++){
+    h->SetBinContent(ian+1,float(IsAnodeGood(ian)));
+  }
+  return h;
+}
+//______________________________________________________________________
+TH1F* AliITSOnlineSDDTP::GetGainAnodeHisto() const {
+//
+  Char_t hisnam[20];  
+  sprintf(hisnam,"hgain%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
+  for(Int_t ian=0;ian<fgkNAnodes;ian++){
+    h->SetBinContent(ian+1,GetChannelGain(ian));
+  }
+  return h;
+}
+//______________________________________________________________________
+Bool_t AliITSOnlineSDDTP::WriteToROOT(TFile *fil){
+  //
+  if(fil==0){ 
+    AliWarning("Invalid pointer to ROOT file");
+    return kFALSE;    
+  }
+  Char_t hisnam[20];
+  fil->cd();
+  sprintf(hisnam,"hgood%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F hgood(hisnam,"",256,-0.5,255.5);
+  sprintf(hisnam,"hbase%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F hbase(hisnam,"",256,-0.5,255.5);
+  sprintf(hisnam,"hnois%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F hnois(hisnam,"",256,-0.5,255.5);
+  sprintf(hisnam,"hcmn%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F hcmn(hisnam,"",256,-0.5,255.5);
+  sprintf(hisnam,"hcorn%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F hcorn(hisnam,"",256,-0.5,255.5);
+  sprintf(hisnam,"hgain%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F hgain(hisnam,"",256,-0.5,255.5);
+  sprintf(hisnam,"htptb%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F htptb(hisnam,"",256,-0.5,255.5);
+  for(Int_t ian=0;ian<fgkNAnodes;ian++){
+    hgood.SetBinContent(ian+1,float(IsAnodeGood(ian)));
+    hbase.SetBinContent(ian+1,GetAnodeBaseline(ian));
+    hnois.SetBinContent(ian+1,GetAnodeRawNoise(ian));
+    hcmn.SetBinContent(ian+1,GetAnodeCommonMode(ian));
+    hcorn.SetBinContent(ian+1,GetAnodeCorrNoise(ian));
+    hgain.SetBinContent(ian+1,GetChannelGain(ian));
+    htptb.SetBinContent(ian+1,GetTimeBinTPPeak(ian));
+  }
+  hgood.Write();
+  hbase.Write();
+  hnois.Write();
+  hcmn.Write();
+  hcorn.Write();
+  hgain.Write();
+  htptb.Write();
+  return kTRUE;
+}