]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - ITS/AliITSOnlineSDDCMN.cxx
Code cleanup in AliITSDetTypeRec and vertexers + minor bug fix in AliITSVertexer3D...
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSDDCMN.cxx
... / ...
CommitLineData
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 <TFile.h>
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//______________________________________________________________________
33 AliITSOnlineSDDCMN::AliITSOnlineSDDCMN():AliITSOnlineSDD(),fNEvents(0),fLowThreshold(0),fHighThreshold(0),fMinCorrNoise(0.),fMaxCorrNoise(0.),fNSigmaNoise(0.)
34{
35 // default constructor
36 Reset();
37 SetMinNoise();
38 SetMaxNoise();
39 SetNSigmaNoise();
40}
41//______________________________________________________________________
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.)
43{
44 // default constructor
45 Reset();
46 SetMinNoise();
47 SetMaxNoise();
48 SetNSigmaNoise();
49}
50//______________________________________________________________________
51AliITSOnlineSDDCMN::~AliITSOnlineSDDCMN(){
52 // Destructor
53}
54//______________________________________________________________________
55void AliITSOnlineSDDCMN::Reset(){
56 //
57 fNEvents=0;
58 for(Int_t i=0;i<fgkNAnodes;i++){
59 fGoodAnode[i]=1;
60 fBaseline[i]=0.;
61 fRawNoise[i]=0.;
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];
71 sprintf(basfilnam,"SDDbase_step1_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
72 FILE* basf=fopen(basfilnam,"r");
73 if(basf==0){
74 AliWarning(Form("Baseline file not present (ddl %d carlos %d side %d, Set all baselines to 50\n",fDDL,fCarlos,fSide));
75 for(Int_t ian=0;ian<fgkNAnodes;ian++){
76 fBaseline[ian]=50.;
77 fEqBaseline[ian]=50;
78 fOffsetBaseline[ian]=0;
79 fGoodAnode[ian]=1;
80 }
81 return;
82 }
83 fscanf(basf,"%d\n",&fHighThreshold);
84 fscanf(basf,"%d\n",&fLowThreshold);
85 Int_t n,ok,eqbase,offbase;
86 Float_t base,rms,cmn,corrnoi;
87 for(Int_t ian=0;ian<fgkNAnodes;ian++){
88 fscanf(basf,"%d %d %f %d %d %f %f %f\n",&n,&ok,&base,&eqbase,&offbase,&rms,&cmn,&corrnoi);
89 fGoodAnode[ian]=ok;
90 fBaseline[ian]=base;
91 fEqBaseline[ian]=eqbase;
92 fOffsetBaseline[ian]=offbase;
93 fRawNoise[ian]=rms;
94 fCMN[ian]=cmn;
95 }
96 fclose(basf);
97}
98//______________________________________________________________________
99void AliITSOnlineSDDCMN::ValidateAnodes(){
100 //
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//______________________________________________________________________
109void AliITSOnlineSDDCMN::AddEvent(TH2F* hrawd){
110 //
111 fNEvents++;
112 const Int_t kTimeBins=fLastGoodTB+1;
113 TH2F* hcorrd=new TH2F("hcorrd","",hrawd->GetNbinsX(),hrawd->GetXaxis()->GetXmin(),hrawd->GetXaxis()->GetXmax(),hrawd->GetNbinsY(),hrawd->GetYaxis()->GetXmin(),hrawd->GetYaxis()->GetXmax());
114 for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
115 Float_t sumEven=0., sumOdd=0.;
116 Int_t countEven=0, countOdd=0;
117 for(Int_t ian=0;ian<fgkNAnodes;ian+=2){
118 if(!fGoodAnode[ian]) continue;
119 sumEven+=hrawd->GetBinContent(itb+1,ian+1)-fBaseline[ian];
120 countEven++;
121 }
122 for(Int_t ian=1;ian<fgkNAnodes;ian+=2){
123 if(!fGoodAnode[ian]) continue;
124 sumOdd+=hrawd->GetBinContent(itb+1,ian+1)-fBaseline[ian];
125 countOdd++;
126 }
127 for(Int_t ian=0;ian<fgkNAnodes;ian++){
128 if(!fGoodAnode[ian]) continue;
129 Float_t meanN;
130 if(ian%2==0) meanN=sumEven/(Float_t)countEven;
131 else meanN=sumOdd/(Float_t)countOdd;
132 Float_t cntCorr=hrawd->GetBinContent(itb+1,ian+1)-fCMN[ian]*meanN;
133 hcorrd->SetBinContent(itb+1,ian+1,cntCorr);
134 }
135 }
136
137 for(Int_t ian=0;ian<fgkNAnodes;ian++){
138 if(!fGoodAnode[ian]) continue;
139 Float_t sumQ=0.;
140 for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
141 sumQ+=TMath::Power(hcorrd->GetBinContent(itb+1,ian+1)-fBaseline[ian],2);
142 }
143 fSumCorrNoise[ian]+=TMath::Sqrt(sumQ/(Float_t)kTimeBins);
144 }
145 delete hcorrd;
146}
147//______________________________________________________________________
148Float_t AliITSOnlineSDDCMN::CalcMeanNoise() const{
149 //
150 Float_t meanns=0.;
151 Int_t cnt=0;
152 for(Int_t ian=0;ian<fgkNAnodes;ian++){
153 if(!fGoodAnode[ian]) continue;
154 meanns+=GetAnodeCorrNoise(ian);
155 cnt++;
156 }
157 if(cnt>0) meanns/=(Float_t)cnt;
158 return meanns;
159}
160//______________________________________________________________________
161void AliITSOnlineSDDCMN::WriteToASCII(){
162 //
163 Char_t outfilnam[100];
164 sprintf(outfilnam,"SDDbase_step2_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
165 FILE* outf=fopen(outfilnam,"w");
166 fprintf(outf,"%d\n",fHighThreshold);
167 fprintf(outf,"%d\n",fLowThreshold);
168 for(Int_t ian=0;ian<fgkNAnodes;ian++){
169 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));
170 }
171 fclose(outf);
172}
173
174//______________________________________________________________________
175TH1F* AliITSOnlineSDDCMN::GetBaselineAnodeHisto() const {
176 //
177 Char_t hisnam[20];
178 sprintf(hisnam,"hbd%02dc%02ds%d",fDDL,fCarlos,fSide);
179 TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
180 for(Int_t ian=0;ian<fgkNAnodes;ian++){
181 h->SetBinContent(ian+1,GetAnodeBaseline(ian));
182 }
183 return h;
184}
185//______________________________________________________________________
186TH1F* AliITSOnlineSDDCMN::GetRawNoiseAnodeHisto() const {
187 //
188 Char_t hisnam[20];
189 sprintf(hisnam,"hnd%02dc%02ds%d",fDDL,fCarlos,fSide);
190 TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
191 for(Int_t ian=0;ian<fgkNAnodes;ian++){
192 h->SetBinContent(ian+1,GetAnodeRawNoise(ian));
193 }
194 return h;
195}
196//______________________________________________________________________
197TH1F* AliITSOnlineSDDCMN::GetCorrNoiseAnodeHisto() const {
198 //
199 Char_t hisnam[20];
200 sprintf(hisnam,"hcd%02dc%02ds%d",fDDL,fCarlos,fSide);
201 TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
202 for(Int_t ian=0;ian<fgkNAnodes;ian++){
203 h->SetBinContent(ian+1,GetAnodeCorrNoise(ian));
204 }
205 return h;
206}
207//______________________________________________________________________
208TH1F* AliITSOnlineSDDCMN::GetBaselineHisto() const {
209 //
210 Char_t hisnam[20];
211 sprintf(hisnam,"hdbd%02dc%02ds%d",fDDL,fCarlos,fSide);
212 TH1F* h=new TH1F(hisnam,"",100,0.,150.);
213 for(Int_t ian=0;ian<fgkNAnodes;ian++){
214 h->Fill(GetAnodeBaseline(ian));
215 }
216 return h;
217}
218//______________________________________________________________________
219TH1F* AliITSOnlineSDDCMN::GetRawNoiseHisto() const {
220 //
221 Char_t hisnam[20];
222 sprintf(hisnam,"hdnd%02dc%02ds%d",fDDL,fCarlos,fSide);
223 TH1F* h=new TH1F(hisnam,"",100,0.,8.);
224 for(Int_t ian=0;ian<fgkNAnodes;ian++){
225 h->Fill(GetAnodeRawNoise(ian));
226 }
227 return h;
228}
229//______________________________________________________________________
230TH1F* AliITSOnlineSDDCMN::GetCorrNoiseHisto() const {
231 //
232 Char_t hisnam[20];
233 sprintf(hisnam,"hdcd%02dc%02ds%d",fDDL,fCarlos,fSide);
234 TH1F* h=new TH1F(hisnam,"",100,0.,8.);
235 for(Int_t ian=0;ian<fgkNAnodes;ian++){
236 h->Fill(GetAnodeCorrNoise(ian));
237 }
238 return h;
239}
240//______________________________________________________________________
241Bool_t AliITSOnlineSDDCMN::WriteToROOT(TFile *fil){
242 //
243 if(fil==0){
244 AliWarning("Invalid pointer to ROOT file");
245 return kFALSE;
246 }
247 Char_t hisnam[20];
248 fil->cd();
249 sprintf(hisnam,"hgood%02dc%02ds%d",fDDL,fCarlos,fSide);
250 TH1F hgood(hisnam,"",256,-0.5,255.5);
251 sprintf(hisnam,"hbase%02dc%02ds%d",fDDL,fCarlos,fSide);
252 TH1F hbase(hisnam,"",256,-0.5,255.5);
253 sprintf(hisnam,"hnois%02dc%02ds%d",fDDL,fCarlos,fSide);
254 TH1F hnois(hisnam,"",256,-0.5,255.5);
255 sprintf(hisnam,"hcmn%02dc%02ds%d",fDDL,fCarlos,fSide);
256 TH1F hcmn(hisnam,"",256,-0.5,255.5);
257 sprintf(hisnam,"hcorn%02dc%02ds%d",fDDL,fCarlos,fSide);
258 TH1F hcorn(hisnam,"",256,-0.5,255.5);
259 for(Int_t ian=0;ian<fgkNAnodes;ian++){
260 hgood.SetBinContent(ian+1,float(IsAnodeGood(ian)));
261 hbase.SetBinContent(ian+1,GetAnodeBaseline(ian));
262 hnois.SetBinContent(ian+1,GetAnodeRawNoise(ian));
263 hcmn.SetBinContent(ian+1,GetAnodeCommonMode(ian));
264 hcorn.SetBinContent(ian+1,GetAnodeCorrNoise(ian));
265 }
266 hgood.Write();
267 hbase.Write();
268 hnois.Write();
269 hcmn.Write();
270 hcorn.Write();
271 return kTRUE;
272}