New class for common mode noise correction
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSDDTP.cxx
CommitLineData
348f80b7 1/**************************************************************************
2 * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15#include "AliITSOnlineSDDTP.h"
7f347565 16#include "AliLog.h"
348f80b7 17#include <TH2F.h>
18#include <TMath.h>
19
20
21///////////////////////////////////////////////////////////////////
22// //
23// Implemetation of the class SDD Test Pulse analysis //
24// Origin: F.Prino, Torino, prino@to.infn.it //
25// //
26///////////////////////////////////////////////////////////////////
27
28
29ClassImp(AliITSOnlineSDDTP)
30
31//______________________________________________________________________
32AliITSOnlineSDDTP::AliITSOnlineSDDTP():AliITSOnlineSDD(),fNEvents(0),fDAQ(0.),fNSigmaGain(0.)
33{
34 // default constructor
35 Reset();
36 SetNSigmaGain();
37}
38//______________________________________________________________________
39AliITSOnlineSDDTP::AliITSOnlineSDDTP(Int_t mod, Int_t sid, Float_t xDAQ):AliITSOnlineSDD(mod,sid),fNEvents(0),fDAQ(xDAQ),fNSigmaGain(0.)
40{
41 // standard constructor
42 Reset();
43 SetNSigmaGain();
44}
45//______________________________________________________________________
46AliITSOnlineSDDTP::~AliITSOnlineSDDTP(){
47 // Destructor
48}
49//______________________________________________________________________
50void AliITSOnlineSDDTP::Reset(){
51 fNEvents=0;
52 for(Int_t i=0;i<fgkNAnodes;i++){
53 fGoodAnode[i]=1;
54 fBaseline[i]=0.;
55 fSumTPPeak[i]=0.;
56 fTPPos[i]=0.;
57 }
58 ReadBaselines();
59}
60
61//______________________________________________________________________
62void AliITSOnlineSDDTP::AddEvent(TH2F* hrawd){
63 //
64 fNEvents++;
65 Double_t tbmax=(Double_t)hrawd->GetNbinsX();
66 for(Int_t ian=0;ian<fgkNAnodes;ian++){
67 Float_t auxmax=0.;
68 Int_t auxtb=0;
69 if(!fGoodAnode[ian]) continue;
70 for(Int_t itb=0;itb<tbmax;itb++){
71 Float_t cnt=hrawd->GetBinContent(itb+1,ian+1);
72 if(cnt>auxmax){
73 auxmax=cnt;
74 auxtb=itb;
75 }
76 }
77 fSumTPPeak[ian]+=auxmax-fBaseline[ian];
78 fTPPos[ian]+=auxtb;
79 }
80}
81//______________________________________________________________________
82void AliITSOnlineSDDTP::ReadBaselines(){
83 // assume baselines and good anodes are taken from previous run
84 Char_t basfilnam[100];
7f347565 85 sprintf(basfilnam,"SDDbase_step2_mod%03d_sid%d.data",fModuleId,fSide);
348f80b7 86 FILE* basf=fopen(basfilnam,"r");
87 if(basf==0){
7f347565 88 AliWarning("Baselinefile not present, Set all baselines to 50\n");
348f80b7 89 for(Int_t ian=0;ian<fgkNAnodes;ian++){
90 fBaseline[ian]=50.;
91 fGoodAnode[ian]=1;
92 }
93 return;
94 }
95 Int_t n,ok;
96 Float_t base,rms,cmn,corrnoi;
97 for(Int_t ian=0;ian<fgkNAnodes;ian++){
98 fscanf(basf,"%d %d %f %f %f %f\n",&n,&ok,&base,&rms,&cmn,&corrnoi);
99 fBaseline[ian]=base;
100 fGoodAnode[ian]=ok;
101 }
102 fclose(basf);
103}
104
105//______________________________________________________________________
106void AliITSOnlineSDDTP::ValidateAnodes(){
107 Float_t meang,rmsg;
108 StatGain(meang,rmsg);
348f80b7 109 Float_t lowlim=meang-fNSigmaGain*rmsg;
110 Float_t hilim=meang+fNSigmaGain*rmsg;
111
112 for(Int_t ian=0;ian<fgkNAnodes;ian++){
113 if(!fGoodAnode[ian]) continue;
114 if(GetChannelGain(ian)<lowlim||GetChannelGain(ian)>hilim) fGoodAnode[ian]=0;
115 }
116}
117
118
119//______________________________________________________________________
120void AliITSOnlineSDDTP::StatGain(Float_t &mean, Float_t &rms){
121 Float_t sum=0.,sumq=0.;
122 Int_t cnt=0;
123 for(Int_t ian=0;ian<fgkNAnodes;ian++){
124 if(!fGoodAnode[ian]) continue;
125 sum+=GetChannelGain(ian);
126 sumq+=TMath::Power(GetChannelGain(ian),2);
127 cnt++;
128 }
129 if(cnt>0){
130 mean=sum/(Float_t)cnt;
131 rms=TMath::Sqrt(sumq/(Float_t)cnt-mean*mean);
132 }else{
133 mean=0.;
134 rms=0.;
135 }
136 return;
137}
138
139//______________________________________________________________________
140void AliITSOnlineSDDTP::WriteToFXS(){
141 //
142 Char_t basfilnam[100];
7f347565 143 sprintf(basfilnam,"SDDbase_step2_mod%03d_sid%d.data",fModuleId,fSide);
348f80b7 144 FILE* basf=fopen(basfilnam,"r");
7f347565 145 if(basf==0){
146 AliWarning("Baseline file not present, launch baseline analysis first\n");
147 return;
148 }
348f80b7 149 Int_t n,ok;
150 Float_t base,rms,cmn,corrnoi;
151 Float_t noise[fgkNAnodes],cmncoef[fgkNAnodes],corrnoise[fgkNAnodes];
152 for(Int_t ian=0;ian<fgkNAnodes;ian++){
153 fscanf(basf,"%d %d %f %f %f %f\n",&n,&ok,&base,&rms,&cmn,&corrnoi);
154 noise[ian]=rms;
155 cmncoef[ian]=cmn;
156 corrnoise[ian]=corrnoi;
157 }
158 fclose(basf);
348f80b7 159 Char_t outfilnam[100];
160 sprintf(outfilnam,"SDDbase_mod%03d_sid%d.data",fModuleId,fSide);
161 FILE* outf=fopen(outfilnam,"w");
162 for(Int_t ian=0;ian<fgkNAnodes;ian++){
163 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));
164 }
165 fclose(outf);
166}
167