New class for common mode noise correction
authormasera <masera@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 1 Jun 2007 15:50:01 +0000 (15:50 +0000)
committermasera <masera@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 1 Jun 2007 15:50:01 +0000 (15:50 +0000)
ITS/AliITSOnlineSDDBase.cxx
ITS/AliITSOnlineSDDCMN.cxx [new file with mode: 0644]
ITS/AliITSOnlineSDDCMN.h [new file with mode: 0644]
ITS/AliITSOnlineSDDTP.cxx
ITS/ITSrecLinkDef.h
ITS/libITSrec.pkg

index c317890..785652a 100644 (file)
@@ -149,7 +149,7 @@ void AliITSOnlineSDDBase::WriteToFXS(){
   FILE* outf=fopen(outfilnam,"w");
   Float_t corrnoise=2.;
   for(Int_t ian=0;ian<fgkNAnodes;ian++){
-    fprintf(outf,"%d %d %8.3f %8.3f %8.3f %8.3f\n",ian,IsAnodeGood(ian),GetAnodeBaseline(ian),GetAnodeRawNoise(ian),GetAnodeCommonMode(ian),corrnoise);
+    fprintf(outf,"%d %d %11.6f %11.6f %11.6f %11.6f\n",ian,IsAnodeGood(ian),GetAnodeBaseline(ian),GetAnodeRawNoise(ian),GetAnodeCommonMode(ian),corrnoise);
   }
   fclose(outf);  
 }
diff --git a/ITS/AliITSOnlineSDDCMN.cxx b/ITS/AliITSOnlineSDDCMN.cxx
new file mode 100644 (file)
index 0000000..a87f71d
--- /dev/null
@@ -0,0 +1,160 @@
+/**************************************************************************
+ * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+#include "AliITSOnlineSDDCMN.h"
+#include "AliLog.h"
+#include <TH2F.h>
+#include <TMath.h>
+
+
+///////////////////////////////////////////////////////////////////
+//                                                               //
+// Implementation of the class used for analysis of SDD noise    //
+// corrected for common mode                                     //
+// Origin: F.Prino, Torino, prino@to.infn.it                     //
+//                                                               //
+///////////////////////////////////////////////////////////////////
+
+
+ClassImp(AliITSOnlineSDDCMN)
+//______________________________________________________________________
+  AliITSOnlineSDDCMN::AliITSOnlineSDDCMN():AliITSOnlineSDD(),fNEvents(0),fMinCorrNoise(0.),fMaxCorrNoise(0.),fNSigmaNoise(0.)
+{
+  // default constructor
+  Reset();
+  SetMinNoise();
+  SetMaxNoise();
+  SetNSigmaNoise();
+}
+//______________________________________________________________________
+  AliITSOnlineSDDCMN::AliITSOnlineSDDCMN(Int_t mod, Int_t sid):AliITSOnlineSDD(mod,sid),fNEvents(0),fMinCorrNoise(0.),fMaxCorrNoise(0.),fNSigmaNoise(0.)
+{
+  // default constructor
+  Reset();
+  SetMinNoise();
+  SetMaxNoise();
+  SetNSigmaNoise();
+}
+//______________________________________________________________________
+AliITSOnlineSDDCMN::~AliITSOnlineSDDCMN(){
+  // Destructor
+}
+//______________________________________________________________________
+void AliITSOnlineSDDCMN::Reset(){
+  fNEvents=0;
+  for(Int_t i=0;i<fgkNAnodes;i++){
+    fGoodAnode[i]=1;
+    fBaseline[i]=0.;
+    fCMN[i]=0.;
+    fSumCorrNoise[i]=0.;
+  }
+  ReadBaselines();
+}
+//______________________________________________________________________
+void AliITSOnlineSDDCMN::ReadBaselines(){
+  // assume baselines and good anodes are taken from previous run
+  Char_t basfilnam[100];
+  sprintf(basfilnam,"SDDbase_step1_mod%03d_sid%d.data",fModuleId,fSide);
+  FILE* basf=fopen(basfilnam,"r");
+  if(basf==0){
+    AliWarning("Baselinefile not present, Set all baselines to 50\n");
+    for(Int_t ian=0;ian<fgkNAnodes;ian++){ 
+      fBaseline[ian]=50.;
+      fGoodAnode[ian]=1;
+    }
+    return;
+  }
+  Int_t n,ok;
+  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);
+    fGoodAnode[ian]=ok;
+    fBaseline[ian]=base;
+    fRawNoise[ian]=rms;
+    fCMN[ian]=cmn;
+  }
+  fclose(basf);
+}
+//______________________________________________________________________
+void  AliITSOnlineSDDCMN::ValidateAnodes(){
+  for(Int_t ian=0;ian<fgkNAnodes;ian++){
+    if(!fGoodAnode[ian]) continue;
+    if(GetAnodeCorrNoise(ian)>fMaxCorrNoise || GetAnodeCorrNoise(ian)<fMinCorrNoise) fGoodAnode[ian]=0;
+    if(GetAnodeCorrNoise(ian)>fNSigmaNoise*CalcMeanNoise()) fGoodAnode[ian]=0;
+  }
+}
+
+//______________________________________________________________________
+void AliITSOnlineSDDCMN::AddEvent(TH2F* hrawd){
+  // 
+  fNEvents++;
+  Float_t tbmax=(Float_t)hrawd->GetNbinsX();
+  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=0;itb<tbmax;itb++){
+    Float_t sumEven=0., sumOdd=0.;
+    Int_t countEven=0, countOdd=0;
+    for(Int_t ian=0;ian<fgkNAnodes;ian+=2){
+      if(!fGoodAnode[ian]) continue;
+      sumEven+=hrawd->GetBinContent(itb+1,ian+1)-fBaseline[ian];
+      countEven++;
+    }
+    for(Int_t ian=1;ian<fgkNAnodes;ian+=2){
+      if(!fGoodAnode[ian]) continue;
+      sumOdd+=hrawd->GetBinContent(itb+1,ian+1)-fBaseline[ian];
+      countOdd++;
+    }
+    for(Int_t ian=0;ian<fgkNAnodes;ian++){
+      if(!fGoodAnode[ian]) continue;
+      Float_t meanN;
+      if(ian%2==0) meanN=sumEven/(Float_t)countEven;
+      else meanN=sumOdd/(Float_t)countOdd;
+      Float_t cntCorr=hrawd->GetBinContent(itb+1,ian+1)-fCMN[ian]*meanN;
+      hcorrd->SetBinContent(itb+1,ian+1,cntCorr);
+    }
+  }
+
+  for(Int_t ian=0;ian<fgkNAnodes;ian++){
+    if(!fGoodAnode[ian]) continue;
+    Float_t sumQ=0.;
+     for(Int_t itb=0;itb<tbmax;itb++){
+      sumQ+=TMath::Power(hcorrd->GetBinContent(itb+1,ian+1)-fBaseline[ian],2);      
+    }
+    fSumCorrNoise[ian]+=TMath::Sqrt(sumQ/tbmax);
+  }
+  delete hcorrd;
+}
+//______________________________________________________________________
+Float_t AliITSOnlineSDDCMN::CalcMeanNoise(){
+  //
+  Float_t meanns=0.;
+  Int_t cnt=0;
+  for(Int_t ian=0;ian<fgkNAnodes;ian++){
+    if(!fGoodAnode[ian]) continue;  
+    meanns+=GetAnodeCorrNoise(ian);
+    cnt++;
+  }
+  if(cnt>0) meanns/=(Float_t)cnt;
+  return meanns;
+}
+//______________________________________________________________________
+void AliITSOnlineSDDCMN::WriteToFXS(){
+  //
+  Char_t outfilnam[100];
+  sprintf(outfilnam,"SDDbase_step2_mod%03d_sid%d.data",fModuleId,fSide);
+  FILE* outf=fopen(outfilnam,"w");
+  for(Int_t ian=0;ian<fgkNAnodes;ian++){
+    fprintf(outf,"%d %d %8.3f %8.3f %8.3f %8.3f\n",ian,IsAnodeGood(ian),GetAnodeBaseline(ian),GetAnodeRawNoise(ian),GetAnodeCommonMode(ian),GetAnodeCorrNoise(ian));
+  }
+  fclose(outf);  
+}
diff --git a/ITS/AliITSOnlineSDDCMN.h b/ITS/AliITSOnlineSDDCMN.h
new file mode 100644 (file)
index 0000000..607d958
--- /dev/null
@@ -0,0 +1,57 @@
+#ifndef ALIITSONLINESDDCMN_H
+#define ALIITSONLINESDDCMN_H
+
+///////////////////////////////////////////////////////////////////
+//                                                               //
+// Class used for SDD noise corrected for common mode analysis   //
+// Origin: F.Prino, Torino, prino@to.infn.it                     //
+//                                                               //
+///////////////////////////////////////////////////////////////////
+#include "AliITSOnlineSDD.h"
+
+class TH2F;
+class TGraph;
+class AliITSOnlineSDDCMN : public AliITSOnlineSDD {
+
+ public:
+  AliITSOnlineSDDCMN();
+  AliITSOnlineSDDCMN(Int_t mod, Int_t sid);
+  virtual ~AliITSOnlineSDDCMN();
+  void Reset();
+  void AddEvent(TH2F* hrawd);
+  void ValidateAnodes();
+  void ReadBaselines();
+
+  void SetMinNoise(Float_t ns=0.001){fMinCorrNoise=ns;}
+  void SetMaxNoise(Float_t ns=9.){fMaxCorrNoise=ns;}
+  void SetNSigmaNoise(Float_t ns=4.){fNSigmaNoise=ns;}
+
+  Bool_t IsAnodeGood(Int_t iAnode)const{ return fGoodAnode[iAnode];}
+  Float_t GetAnodeBaseline(Int_t iAnode) const{ return fBaseline[iAnode];}
+  Float_t GetAnodeRawNoise(Int_t iAnode) const{ return fRawNoise[iAnode];}
+  Float_t GetAnodeCommonMode(Int_t iAnode) const{ return fCMN[iAnode];}
+  Float_t GetAnodeCorrNoise(Int_t iAnode) const{
+    if(fNEvents>0) return fSumCorrNoise[iAnode]/fNEvents;
+    else return 0;
+  }
+
+  Float_t CalcMeanNoise();
+  Int_t GetNEvents() const {return fNEvents;}
+  void WriteToFXS();
+
+ protected:
+
+ private:
+  Int_t fNEvents;
+  Bool_t fGoodAnode[fgkNAnodes];
+  Float_t fBaseline[fgkNAnodes];
+  Float_t fRawNoise[fgkNAnodes];
+  Float_t fSumCorrNoise[fgkNAnodes];
+  Float_t fCMN[fgkNAnodes];
+  Float_t fMinCorrNoise;
+  Float_t fMaxCorrNoise;
+  Float_t fNSigmaNoise;
+
+  ClassDef(AliITSOnlineSDDCMN,1);
+};
+#endif
index 4b66f52..f23f3c3 100644 (file)
@@ -13,6 +13,7 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 #include "AliITSOnlineSDDTP.h"
+#include "AliLog.h"
 #include <TH2F.h>
 #include <TMath.h>
 
@@ -81,10 +82,10 @@ void AliITSOnlineSDDTP::AddEvent(TH2F* hrawd){
 void AliITSOnlineSDDTP::ReadBaselines(){
   // assume baselines and good anodes are taken from previous run
   Char_t basfilnam[100];
-  sprintf(basfilnam,"SDDbase_step1_mod%03d_sid%d.data",fModuleId,fSide);
+  sprintf(basfilnam,"SDDbase_step2_mod%03d_sid%d.data",fModuleId,fSide);
   FILE* basf=fopen(basfilnam,"r");
   if(basf==0){
-    printf("Baselinefile not present, Set all baselines to 50\n");
+    AliWarning("Baselinefile not present, Set all baselines to 50\n");
     for(Int_t ian=0;ian<fgkNAnodes;ian++){ 
       fBaseline[ian]=50.;
       fGoodAnode[ian]=1;
@@ -105,7 +106,6 @@ void AliITSOnlineSDDTP::ReadBaselines(){
 void AliITSOnlineSDDTP::ValidateAnodes(){
   Float_t meang,rmsg;
   StatGain(meang,rmsg);
-  printf("<gain>=%f,rms=%f\n",meang,rmsg);
   Float_t lowlim=meang-fNSigmaGain*rmsg;
   Float_t hilim=meang+fNSigmaGain*rmsg;
 
@@ -140,8 +140,12 @@ void AliITSOnlineSDDTP::StatGain(Float_t &mean, Float_t  &rms){
 void AliITSOnlineSDDTP::WriteToFXS(){
   //
   Char_t basfilnam[100];
-  sprintf(basfilnam,"SDDbase_step1_mod%03d_sid%d.data",fModuleId,fSide);
+  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];
@@ -152,7 +156,6 @@ void AliITSOnlineSDDTP::WriteToFXS(){
     corrnoise[ian]=corrnoi;
   }
   fclose(basf);
-  printf("Read All******************\n");
   Char_t outfilnam[100];
   sprintf(outfilnam,"SDDbase_mod%03d_sid%d.data",fModuleId,fSide);
   FILE* outf=fopen(outfilnam,"w");
index 30b8f19..f89df81 100644 (file)
 #pragma link C++ class AliITSOnlineSDDBase+;
 #pragma link C++ class AliITSOnlineSDDTP+;
 #pragma link C++ class AliITSOnlineSDDBTP+;
+#pragma link C++ class AliITSOnlineSDDCMN+;
 #pragma link C++ class AliITSOnlineSDDInjectors+;
 
 #endif
index 1f949d6..394775c 100644 (file)
@@ -73,7 +73,8 @@ SRCS =        AliITSDetTypeRec.cxx \
                AliITSOnlineSDDBase.cxx \
                AliITSOnlineSDDTP.cxx \
                AliITSOnlineSDDBTP.cxx \
-               AliITSOnlineSDDInjectors.cxx
+               AliITSOnlineSDDInjectors.cxx \
+                AliITSOnlineSDDCMN.cxx 
 
 HDRS:=  $(SRCS:.cxx=.h)