]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSOnlineSDDCMN.cxx
New condtion for definition of bad anodes in SDD pedestal DA
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSDDCMN.cxx
CommitLineData
7f347565 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 **************************************************************************/
e44f571c 15#include <TFile.h>
7f347565 16#include "AliITSOnlineSDDCMN.h"
17#include "AliLog.h"
18#include <TH2F.h>
19#include <TMath.h>
20
21
22///////////////////////////////////////////////////////////////////
23// //
24// Implementation of the class used for analysis of SDD noise //
25// corrected for common mode //
26// Origin: F.Prino, Torino, prino@to.infn.it //
27// //
28///////////////////////////////////////////////////////////////////
29
30
31ClassImp(AliITSOnlineSDDCMN)
32//______________________________________________________________________
e7610d19 33 AliITSOnlineSDDCMN::AliITSOnlineSDDCMN():AliITSOnlineSDD(),fNEvents(0),fLowThreshold(0),fHighThreshold(0),fMinCorrNoise(0.),fMaxCorrNoise(0.),fNSigmaNoise(0.)
7f347565 34{
35 // default constructor
36 Reset();
37 SetMinNoise();
38 SetMaxNoise();
39 SetNSigmaNoise();
40}
41//______________________________________________________________________
e7610d19 42 AliITSOnlineSDDCMN::AliITSOnlineSDDCMN(Int_t nddl, Int_t ncarlos, Int_t sid):AliITSOnlineSDD(nddl,ncarlos,sid),fNEvents(0),fLowThreshold(0),fHighThreshold(0),fMinCorrNoise(0.),fMaxCorrNoise(0.),fNSigmaNoise(0.)
7f347565 43{
44 // default constructor
45 Reset();
46 SetMinNoise();
47 SetMaxNoise();
48 SetNSigmaNoise();
49}
50//______________________________________________________________________
51AliITSOnlineSDDCMN::~AliITSOnlineSDDCMN(){
52 // Destructor
53}
54//______________________________________________________________________
55void AliITSOnlineSDDCMN::Reset(){
beb262b4 56 //
7f347565 57 fNEvents=0;
58 for(Int_t i=0;i<fgkNAnodes;i++){
59 fGoodAnode[i]=1;
60 fBaseline[i]=0.;
3083967f 61 fRawNoise[i]=0.;
7f347565 62 fCMN[i]=0.;
63 fSumCorrNoise[i]=0.;
64 }
65 ReadBaselines();
66}
67//______________________________________________________________________
68void AliITSOnlineSDDCMN::ReadBaselines(){
69 // assume baselines and good anodes are taken from previous run
70 Char_t basfilnam[100];
979b5a5f 71 sprintf(basfilnam,"SDDbase_step1_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
7f347565 72 FILE* basf=fopen(basfilnam,"r");
73 if(basf==0){
e7610d19 74 AliWarning(Form("Baseline file not present (ddl %d carlos %d side %d, Set all baselines to 50\n",fDDL,fCarlos,fSide));
7f347565 75 for(Int_t ian=0;ian<fgkNAnodes;ian++){
76 fBaseline[ian]=50.;
d8303ac8 77 fEqBaseline[ian]=50;
78 fOffsetBaseline[ian]=0;
7f347565 79 fGoodAnode[ian]=1;
80 }
81 return;
82 }
e7610d19 83 fscanf(basf,"%d\n",&fHighThreshold);
84 fscanf(basf,"%d\n",&fLowThreshold);
d8303ac8 85 Int_t n,ok,eqbase,offbase;
7f347565 86 Float_t base,rms,cmn,corrnoi;
87 for(Int_t ian=0;ian<fgkNAnodes;ian++){
d8303ac8 88 fscanf(basf,"%d %d %f %d %d %f %f %f\n",&n,&ok,&base,&eqbase,&offbase,&rms,&cmn,&corrnoi);
7f347565 89 fGoodAnode[ian]=ok;
90 fBaseline[ian]=base;
d8303ac8 91 fEqBaseline[ian]=eqbase;
92 fOffsetBaseline[ian]=offbase;
7f347565 93 fRawNoise[ian]=rms;
94 fCMN[ian]=cmn;
95 }
96 fclose(basf);
97}
98//______________________________________________________________________
99void AliITSOnlineSDDCMN::ValidateAnodes(){
beb262b4 100 //
7f347565 101 for(Int_t ian=0;ian<fgkNAnodes;ian++){
102 if(!fGoodAnode[ian]) continue;
103 if(GetAnodeCorrNoise(ian)>fMaxCorrNoise || GetAnodeCorrNoise(ian)<fMinCorrNoise) fGoodAnode[ian]=0;
104 if(GetAnodeCorrNoise(ian)>fNSigmaNoise*CalcMeanNoise()) fGoodAnode[ian]=0;
105 }
106}
107
108//______________________________________________________________________
b255f56d 109TH2F* AliITSOnlineSDDCMN::GetCleanEvent(TH2F* hrawd) const {
7f347565 110 //
7f347565 111 TH2F* hcorrd=new TH2F("hcorrd","",hrawd->GetNbinsX(),hrawd->GetXaxis()->GetXmin(),hrawd->GetXaxis()->GetXmax(),hrawd->GetNbinsY(),hrawd->GetYaxis()->GetXmin(),hrawd->GetYaxis()->GetXmax());
750296dd 112 for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
7f347565 113 Float_t sumEven=0., sumOdd=0.;
114 Int_t countEven=0, countOdd=0;
115 for(Int_t ian=0;ian<fgkNAnodes;ian+=2){
116 if(!fGoodAnode[ian]) continue;
117 sumEven+=hrawd->GetBinContent(itb+1,ian+1)-fBaseline[ian];
118 countEven++;
119 }
120 for(Int_t ian=1;ian<fgkNAnodes;ian+=2){
121 if(!fGoodAnode[ian]) continue;
122 sumOdd+=hrawd->GetBinContent(itb+1,ian+1)-fBaseline[ian];
123 countOdd++;
124 }
125 for(Int_t ian=0;ian<fgkNAnodes;ian++){
126 if(!fGoodAnode[ian]) continue;
127 Float_t meanN;
128 if(ian%2==0) meanN=sumEven/(Float_t)countEven;
129 else meanN=sumOdd/(Float_t)countOdd;
130 Float_t cntCorr=hrawd->GetBinContent(itb+1,ian+1)-fCMN[ian]*meanN;
131 hcorrd->SetBinContent(itb+1,ian+1,cntCorr);
132 }
133 }
b255f56d 134 return hcorrd;
135}
136//______________________________________________________________________
137void AliITSOnlineSDDCMN::AddEvent(TH2F* hrawd){
138 //
139 fNEvents++;
140 TH2F* hcorrd=GetCleanEvent(hrawd);
7f347565 141
142 for(Int_t ian=0;ian<fgkNAnodes;ian++){
143 if(!fGoodAnode[ian]) continue;
144 Float_t sumQ=0.;
b255f56d 145 Int_t cnt=0;
750296dd 146 for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
a8cd2ab2 147 Float_t cntdiff=hcorrd->GetBinContent(itb+1,ian+1)-fBaseline[ian];
148 sumQ+=cntdiff*cntdiff;
b255f56d 149 cnt++;
7f347565 150 }
b255f56d 151 fSumCorrNoise[ian]+=TMath::Sqrt(sumQ/(Float_t)cnt);
7f347565 152 }
153 delete hcorrd;
154}
155//______________________________________________________________________
beb262b4 156Float_t AliITSOnlineSDDCMN::CalcMeanNoise() const{
7f347565 157 //
158 Float_t meanns=0.;
159 Int_t cnt=0;
160 for(Int_t ian=0;ian<fgkNAnodes;ian++){
161 if(!fGoodAnode[ian]) continue;
162 meanns+=GetAnodeCorrNoise(ian);
163 cnt++;
164 }
165 if(cnt>0) meanns/=(Float_t)cnt;
166 return meanns;
167}
168//______________________________________________________________________
e44f571c 169void AliITSOnlineSDDCMN::WriteToASCII(){
7f347565 170 //
171 Char_t outfilnam[100];
979b5a5f 172 sprintf(outfilnam,"SDDbase_step2_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
7f347565 173 FILE* outf=fopen(outfilnam,"w");
e7610d19 174 fprintf(outf,"%d\n",fHighThreshold);
175 fprintf(outf,"%d\n",fLowThreshold);
7f347565 176 for(Int_t ian=0;ian<fgkNAnodes;ian++){
d8303ac8 177 fprintf(outf,"%d %d %8.3f %d %d %8.3f %8.3f %8.3f\n",ian,IsAnodeGood(ian),GetAnodeBaseline(ian),GetAnodeEqualizedBaseline(ian),GetAnodeBaselineOffset(ian),GetAnodeRawNoise(ian),GetAnodeCommonMode(ian),GetAnodeCorrNoise(ian));
7f347565 178 }
179 fclose(outf);
180}
4ff6aa93 181
182//______________________________________________________________________
183TH1F* AliITSOnlineSDDCMN::GetBaselineAnodeHisto() const {
184 //
185 Char_t hisnam[20];
e5b2f7f2 186 sprintf(hisnam,"hbase%02dc%02ds%d",fDDL,fCarlos,fSide);
4ff6aa93 187 TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
188 for(Int_t ian=0;ian<fgkNAnodes;ian++){
189 h->SetBinContent(ian+1,GetAnodeBaseline(ian));
190 }
191 return h;
192}
193//______________________________________________________________________
194TH1F* AliITSOnlineSDDCMN::GetRawNoiseAnodeHisto() const {
195 //
196 Char_t hisnam[20];
e5b2f7f2 197 sprintf(hisnam,"hnois%02dc%02ds%d",fDDL,fCarlos,fSide);
4ff6aa93 198 TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
199 for(Int_t ian=0;ian<fgkNAnodes;ian++){
200 h->SetBinContent(ian+1,GetAnodeRawNoise(ian));
201 }
202 return h;
203}
204//______________________________________________________________________
205TH1F* AliITSOnlineSDDCMN::GetCorrNoiseAnodeHisto() const {
206 //
207 Char_t hisnam[20];
e5b2f7f2 208 sprintf(hisnam,"hcorn%02dc%02ds%d",fDDL,fCarlos,fSide);
4ff6aa93 209 TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
210 for(Int_t ian=0;ian<fgkNAnodes;ian++){
211 h->SetBinContent(ian+1,GetAnodeCorrNoise(ian));
212 }
213 return h;
214}
215//______________________________________________________________________
e5b2f7f2 216TH1F* AliITSOnlineSDDCMN::GetCMNCoefAnodeHisto() const {
217//
218 Char_t hisnam[20];
219 sprintf(hisnam,"hcmn%02dc%02ds%d",fDDL,fCarlos,fSide);
220 TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
221 for(Int_t ian=0;ian<fgkNAnodes;ian++){
222 h->SetBinContent(ian+1,GetAnodeCommonMode(ian));
223 }
224 return h;
225}
226//______________________________________________________________________
227TH1F* AliITSOnlineSDDCMN::GetStatusAnodeHisto() const {
228//
229 Char_t hisnam[20];
230 sprintf(hisnam,"hgood%02dc%02ds%d",fDDL,fCarlos,fSide);
231 TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
232 for(Int_t ian=0;ian<fgkNAnodes;ian++){
233 h->SetBinContent(ian+1,float(IsAnodeGood(ian)));
234 }
235 return h;
236}
237//______________________________________________________________________
4ff6aa93 238TH1F* AliITSOnlineSDDCMN::GetBaselineHisto() const {
239 //
240 Char_t hisnam[20];
979b5a5f 241 sprintf(hisnam,"hdbd%02dc%02ds%d",fDDL,fCarlos,fSide);
4ff6aa93 242 TH1F* h=new TH1F(hisnam,"",100,0.,150.);
243 for(Int_t ian=0;ian<fgkNAnodes;ian++){
244 h->Fill(GetAnodeBaseline(ian));
245 }
246 return h;
247}
248//______________________________________________________________________
249TH1F* AliITSOnlineSDDCMN::GetRawNoiseHisto() const {
250 //
251 Char_t hisnam[20];
979b5a5f 252 sprintf(hisnam,"hdnd%02dc%02ds%d",fDDL,fCarlos,fSide);
4ff6aa93 253 TH1F* h=new TH1F(hisnam,"",100,0.,8.);
254 for(Int_t ian=0;ian<fgkNAnodes;ian++){
255 h->Fill(GetAnodeRawNoise(ian));
256 }
257 return h;
258}
259//______________________________________________________________________
260TH1F* AliITSOnlineSDDCMN::GetCorrNoiseHisto() const {
261 //
262 Char_t hisnam[20];
979b5a5f 263 sprintf(hisnam,"hdcd%02dc%02ds%d",fDDL,fCarlos,fSide);
4ff6aa93 264 TH1F* h=new TH1F(hisnam,"",100,0.,8.);
265 for(Int_t ian=0;ian<fgkNAnodes;ian++){
266 h->Fill(GetAnodeCorrNoise(ian));
267 }
268 return h;
269}
e44f571c 270//______________________________________________________________________
271Bool_t AliITSOnlineSDDCMN::WriteToROOT(TFile *fil){
3083967f 272 //
e44f571c 273 if(fil==0){
274 AliWarning("Invalid pointer to ROOT file");
275 return kFALSE;
276 }
277 Char_t hisnam[20];
278 fil->cd();
979b5a5f 279 sprintf(hisnam,"hgood%02dc%02ds%d",fDDL,fCarlos,fSide);
e44f571c 280 TH1F hgood(hisnam,"",256,-0.5,255.5);
979b5a5f 281 sprintf(hisnam,"hbase%02dc%02ds%d",fDDL,fCarlos,fSide);
e44f571c 282 TH1F hbase(hisnam,"",256,-0.5,255.5);
979b5a5f 283 sprintf(hisnam,"hnois%02dc%02ds%d",fDDL,fCarlos,fSide);
e44f571c 284 TH1F hnois(hisnam,"",256,-0.5,255.5);
979b5a5f 285 sprintf(hisnam,"hcmn%02dc%02ds%d",fDDL,fCarlos,fSide);
e44f571c 286 TH1F hcmn(hisnam,"",256,-0.5,255.5);
979b5a5f 287 sprintf(hisnam,"hcorn%02dc%02ds%d",fDDL,fCarlos,fSide);
e44f571c 288 TH1F hcorn(hisnam,"",256,-0.5,255.5);
289 for(Int_t ian=0;ian<fgkNAnodes;ian++){
290 hgood.SetBinContent(ian+1,float(IsAnodeGood(ian)));
291 hbase.SetBinContent(ian+1,GetAnodeBaseline(ian));
292 hnois.SetBinContent(ian+1,GetAnodeRawNoise(ian));
293 hcmn.SetBinContent(ian+1,GetAnodeCommonMode(ian));
294 hcorn.SetBinContent(ian+1,GetAnodeCorrNoise(ian));
295 }
296 hgood.Write();
297 hbase.Write();
298 hnois.Write();
299 hcmn.Write();
300 hcorn.Write();
301 return kTRUE;
302}