]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSOnlineSDDCMN.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSDDCMN.cxx
index f31d5e95126e6b42a79eaac5b8e99c766dbbb069..eefaa879c981a868bbd2584fcbf71fa23f3dc181 100644 (file)
@@ -53,7 +53,7 @@ AliITSOnlineSDDCMN::~AliITSOnlineSDDCMN(){
 }
 //______________________________________________________________________
 void AliITSOnlineSDDCMN::Reset(){
-  //
+  // Reset counters
   fNEvents=0;
   for(Int_t i=0;i<fgkNAnodes;i++){
     fGoodAnode[i]=1;
@@ -67,9 +67,9 @@ void AliITSOnlineSDDCMN::Reset(){
 //______________________________________________________________________
 void AliITSOnlineSDDCMN::ReadBaselines(){
   // assume baselines and good anodes are taken from previous run
-  Char_t basfilnam[100];
-  sprintf(basfilnam,"SDDbase_step1_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
-  FILE* basf=fopen(basfilnam,"r");
+  TString basfilnam;
+  basfilnam.Form("SDDbase_step1_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
+  FILE* basf=fopen(basfilnam.Data(),"r");
   if(basf==0){
     AliWarning(Form("Baseline file not present (ddl %d  carlos %d side %d, Set all baselines to 50\n",fDDL,fCarlos,fSide));
     for(Int_t ian=0;ian<fgkNAnodes;ian++){ 
@@ -80,12 +80,15 @@ void AliITSOnlineSDDCMN::ReadBaselines(){
     }
     return;
   }
-  fscanf(basf,"%d\n",&fHighThreshold);
-  fscanf(basf,"%d\n",&fLowThreshold);
+  Int_t check = fscanf(basf,"%d\n",&fHighThreshold);
+  if(check<1)AliError("Error while reading file with baselines");
+  check = fscanf(basf,"%d\n",&fLowThreshold);
+  if(check<1)AliError("Error while reading file with baselines");
   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 %d %d %f %f %f\n",&n,&ok,&base,&eqbase,&offbase,&rms,&cmn,&corrnoi);
+    check = fscanf(basf,"%d %d %f %d %d %f %f %f\n",&n,&ok,&base,&eqbase,&offbase,&rms,&cmn,&corrnoi);
+    if(check<1)AliError("Error while reading file with baselines");
     fGoodAnode[ian]=ok;
     fBaseline[ian]=base;
     fEqBaseline[ian]=eqbase;
@@ -97,7 +100,7 @@ void AliITSOnlineSDDCMN::ReadBaselines(){
 }
 //______________________________________________________________________
 void  AliITSOnlineSDDCMN::ValidateAnodes(){
-  //
+  // Tag good/bad anodes
   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     if(!fGoodAnode[ian]) continue;
     if(GetAnodeCorrNoise(ian)>fMaxCorrNoise || GetAnodeCorrNoise(ian)<fMinCorrNoise) fGoodAnode[ian]=0;
@@ -106,10 +109,9 @@ void  AliITSOnlineSDDCMN::ValidateAnodes(){
 }
 
 //______________________________________________________________________
-void AliITSOnlineSDDCMN::AddEvent(TH2F* hrawd){
-  // 
-  fNEvents++;
-  const Int_t kTimeBins=fLastGoodTB-fFirstGoodTB+1;
+TH2F* AliITSOnlineSDDCMN::GetCleanEvent(const TH2F* hrawd) const {
+  // Fills an histogram with counts corrected for common mode noise
+
   TH2F* hcorrd=new TH2F("hcorrd","",hrawd->GetNbinsX(),hrawd->GetXaxis()->GetXmin(),hrawd->GetXaxis()->GetXmax(),hrawd->GetNbinsY(),hrawd->GetYaxis()->GetXmin(),hrawd->GetYaxis()->GetXmax());
   for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
     Float_t sumEven=0., sumOdd=0.;
@@ -133,20 +135,32 @@ void AliITSOnlineSDDCMN::AddEvent(TH2F* hrawd){
       hcorrd->SetBinContent(itb+1,ian+1,cntCorr);
     }
   }
+  return hcorrd;
+}
+//______________________________________________________________________
+void AliITSOnlineSDDCMN::AddEvent(TH2F* hrawd){
+  // analyzes one event and adds its ontribution to the various counters
+
+  fNEvents++;
+  TH2F* hcorrd=GetCleanEvent(hrawd);
 
   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     if(!fGoodAnode[ian]) continue;
     Float_t sumQ=0.;
+    Int_t cnt=0;
     for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
-      sumQ+=TMath::Power(hcorrd->GetBinContent(itb+1,ian+1)-fBaseline[ian],2);      
+      Float_t cntdiff=hcorrd->GetBinContent(itb+1,ian+1)-fBaseline[ian];
+      sumQ+=cntdiff*cntdiff;
+      cnt++;    
     }
-    fSumCorrNoise[ian]+=TMath::Sqrt(sumQ/(Float_t)kTimeBins);
+    if(cnt != 0)fSumCorrNoise[ian]+=TMath::Sqrt(sumQ/(Float_t)cnt);
   }
   delete hcorrd;
 }
 //______________________________________________________________________
 Float_t AliITSOnlineSDDCMN::CalcMeanNoise() const{
-  //
+  // compute average noise
+
   Float_t meanns=0.;
   Int_t cnt=0;
   for(Int_t ian=0;ian<fgkNAnodes;ian++){
@@ -159,10 +173,12 @@ Float_t AliITSOnlineSDDCMN::CalcMeanNoise() const{
 }
 //______________________________________________________________________
 void AliITSOnlineSDDCMN::WriteToASCII(){
-  //
-  Char_t outfilnam[100];
-  sprintf(outfilnam,"SDDbase_step2_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
-  FILE* outf=fopen(outfilnam,"w");
+  // writes parameters of each channel into an ASCII file 
+  // to be then read by the PULSER DA (AliITSOnlineSDDTP)
+
+  TString outfilnam;
+  outfilnam.Form("SDDbase_step2_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
+  FILE* outf=fopen(outfilnam.Data(),"w");
   fprintf(outf,"%d\n",fHighThreshold);
   fprintf(outf,"%d\n",fLowThreshold);
   for(Int_t ian=0;ian<fgkNAnodes;ian++){
@@ -173,10 +189,10 @@ void AliITSOnlineSDDCMN::WriteToASCII(){
 
 //______________________________________________________________________
 TH1F* AliITSOnlineSDDCMN::GetBaselineAnodeHisto() const {
-  //
-  Char_t hisnam[20];  
-  sprintf(hisnam,"hbd%02dc%02ds%d",fDDL,fCarlos,fSide);
-  TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
+  // produce histogram with baseline vs. anode number
+  TString hisnam;  
+  hisnam.Form("hbase%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     h->SetBinContent(ian+1,GetAnodeBaseline(ian));
   }
@@ -184,10 +200,10 @@ TH1F* AliITSOnlineSDDCMN::GetBaselineAnodeHisto() const {
 }
 //______________________________________________________________________
 TH1F* AliITSOnlineSDDCMN::GetRawNoiseAnodeHisto() const {
-  //
-  Char_t hisnam[20];  
-  sprintf(hisnam,"hnd%02dc%02ds%d",fDDL,fCarlos,fSide);
-  TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
+  // produce histogram with raw noise vs. anode number
+  TString hisnam;  
+  hisnam.Form("hnois%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     h->SetBinContent(ian+1,GetAnodeRawNoise(ian));
   }
@@ -195,21 +211,43 @@ TH1F* AliITSOnlineSDDCMN::GetRawNoiseAnodeHisto() const {
 }
 //______________________________________________________________________
 TH1F* AliITSOnlineSDDCMN::GetCorrNoiseAnodeHisto() const {
-  //
-  Char_t hisnam[20];  
-  sprintf(hisnam,"hcd%02dc%02ds%d",fDDL,fCarlos,fSide);
-  TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
+  // produce histogram with corrected noise vs. anode number
+  TString hisnam;  
+  hisnam.Form("hcorn%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     h->SetBinContent(ian+1,GetAnodeCorrNoise(ian));
   }
   return h;
 }
 //______________________________________________________________________
+TH1F* AliITSOnlineSDDCMN::GetCMNCoefAnodeHisto() const {
+  // produce histogram with coefficients for common mode noise subtraction
+  TString hisnam;  
+  hisnam.Form("hcmn%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
+  for(Int_t ian=0;ian<fgkNAnodes;ian++){
+    h->SetBinContent(ian+1,GetAnodeCommonMode(ian));
+  }
+  return h;
+}
+//______________________________________________________________________
+TH1F* AliITSOnlineSDDCMN::GetStatusAnodeHisto() const {
+  // produce histogram with status bit of each anode
+  TString hisnam;  
+  hisnam.Form("hgood%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
+  for(Int_t ian=0;ian<fgkNAnodes;ian++){
+    h->SetBinContent(ian+1,float(IsAnodeGood(ian)));
+  }
+  return h;
+}
+//______________________________________________________________________
 TH1F* AliITSOnlineSDDCMN::GetBaselineHisto() const {
-  //
-  Char_t hisnam[20];  
-  sprintf(hisnam,"hdbd%02dc%02ds%d",fDDL,fCarlos,fSide);
-  TH1F* h=new TH1F(hisnam,"",100,0.,150.);
+  // produce histogram with baseline distribution
+  TString hisnam;  
+  hisnam.Form("hdbd%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F* h=new TH1F(hisnam.Data(),"",100,0.,150.);
   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     h->Fill(GetAnodeBaseline(ian));
   }
@@ -217,10 +255,10 @@ TH1F* AliITSOnlineSDDCMN::GetBaselineHisto() const {
 }
 //______________________________________________________________________
 TH1F* AliITSOnlineSDDCMN::GetRawNoiseHisto() const {
-  //
-  Char_t hisnam[20];  
-  sprintf(hisnam,"hdnd%02dc%02ds%d",fDDL,fCarlos,fSide);
-  TH1F* h=new TH1F(hisnam,"",100,0.,8.);
+  // produce histogram with raw noise distribution
+  TString hisnam;  
+  hisnam.Form("hdnd%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F* h=new TH1F(hisnam.Data(),"",100,0.,8.);
   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     h->Fill(GetAnodeRawNoise(ian));
   }
@@ -228,10 +266,10 @@ TH1F* AliITSOnlineSDDCMN::GetRawNoiseHisto() const {
 }
 //______________________________________________________________________
 TH1F* AliITSOnlineSDDCMN::GetCorrNoiseHisto() const {
-  //
-  Char_t hisnam[20];  
-  sprintf(hisnam,"hdcd%02dc%02ds%d",fDDL,fCarlos,fSide);
-  TH1F* h=new TH1F(hisnam,"",100,0.,8.);
+  // produce histogram with corrected noise distribution
+  TString hisnam;  
+  hisnam.Form("hdcd%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F* h=new TH1F(hisnam.Data(),"",100,0.,8.);
   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     h->Fill(GetAnodeCorrNoise(ian));
   }
@@ -239,23 +277,23 @@ TH1F* AliITSOnlineSDDCMN::GetCorrNoiseHisto() const {
 }
 //______________________________________________________________________
 Bool_t AliITSOnlineSDDCMN::WriteToROOT(TFile *fil){
-  //
+  // writes output into a root file
   if(fil==0){ 
     AliWarning("Invalid pointer to ROOT file");
     return kFALSE;    
   }
-  Char_t hisnam[20];
+  TString hisnam;
   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);
+  hisnam.Form("hgood%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F hgood(hisnam.Data(),"",256,-0.5,255.5);
+  hisnam.Form("hbase%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F hbase(hisnam.Data(),"",256,-0.5,255.5);
+  hisnam.Form("hnois%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F hnois(hisnam.Data(),"",256,-0.5,255.5);
+  hisnam.Form("hcmn%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F hcmn(hisnam.Data(),"",256,-0.5,255.5);
+  hisnam.Form("hcorn%02dc%02ds%d",fDDL,fCarlos,fSide);
+  TH1F hcorn(hisnam.Data(),"",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));