Line data Source code
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 :
31 116 : ClassImp(AliITSOnlineSDDCMN)
32 : //______________________________________________________________________
33 0 : AliITSOnlineSDDCMN::AliITSOnlineSDDCMN():AliITSOnlineSDD(),fNEvents(0),fLowThreshold(0),fHighThreshold(0),fMinCorrNoise(0.),fMaxCorrNoise(0.),fNSigmaNoise(0.),fMinNumGoodAnForGoodMod(0),fMinClusterOfGoodAn(0)
34 0 : {
35 : // default constructor
36 0 : Reset();
37 0 : SetMinNoise();
38 0 : SetMaxNoise();
39 0 : SetNSigmaNoise();
40 0 : SetMinNumGoodAnForGoodMod();
41 0 : SetCutOnGoodAnodeClusterSize();
42 0 : }
43 : //______________________________________________________________________
44 0 : 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.),fMinNumGoodAnForGoodMod(0),fMinClusterOfGoodAn(0)
45 0 : {
46 : // default constructor
47 0 : Reset();
48 0 : SetMinNoise();
49 0 : SetMaxNoise();
50 0 : SetNSigmaNoise();
51 0 : SetMinNumGoodAnForGoodMod();
52 0 : SetCutOnGoodAnodeClusterSize();
53 0 : }
54 : //______________________________________________________________________
55 0 : AliITSOnlineSDDCMN::~AliITSOnlineSDDCMN(){
56 : // Destructor
57 0 : }
58 : //______________________________________________________________________
59 : void AliITSOnlineSDDCMN::Reset(){
60 : // Reset counters
61 0 : fNEvents=0;
62 0 : for(Int_t i=0;i<fgkNAnodes;i++){
63 0 : fGoodAnode[i]=1;
64 0 : fBaseline[i]=0.;
65 0 : fRawNoise[i]=0.;
66 0 : fCMN[i]=0.;
67 0 : fSumCorrNoise[i]=0.;
68 : }
69 0 : ReadBaselines();
70 0 : }
71 : //______________________________________________________________________
72 : void AliITSOnlineSDDCMN::ReadBaselines(){
73 : // assume baselines and good anodes are taken from previous run
74 0 : TString basfilnam;
75 0 : basfilnam.Form("SDDbase_step1_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
76 0 : FILE* basf=fopen(basfilnam.Data(),"r");
77 0 : if(basf==0){
78 0 : AliWarning(Form("Baseline file not present (ddl %d carlos %d side %d, Set all baselines to 50\n",fDDL,fCarlos,fSide));
79 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++){
80 0 : fBaseline[ian]=50.;
81 0 : fEqBaseline[ian]=50;
82 0 : fOffsetBaseline[ian]=0;
83 0 : fGoodAnode[ian]=1;
84 : }
85 0 : return;
86 : }
87 0 : Int_t check = fscanf(basf,"%d\n",&fHighThreshold);
88 0 : if(check<1)AliError("Error while reading file with baselines");
89 0 : check = fscanf(basf,"%d\n",&fLowThreshold);
90 0 : if(check<1)AliError("Error while reading file with baselines");
91 0 : Int_t n,ok,eqbase,offbase;
92 0 : Float_t base,rms,cmn,corrnoi;
93 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++){
94 0 : check = fscanf(basf,"%d %d %f %d %d %f %f %f\n",&n,&ok,&base,&eqbase,&offbase,&rms,&cmn,&corrnoi);
95 0 : if(check<1)AliError("Error while reading file with baselines");
96 0 : fGoodAnode[ian]=ok;
97 0 : fBaseline[ian]=base;
98 0 : fEqBaseline[ian]=eqbase;
99 0 : fOffsetBaseline[ian]=offbase;
100 0 : fRawNoise[ian]=rms;
101 0 : fCMN[ian]=cmn;
102 : }
103 0 : fclose(basf);
104 0 : }
105 : //______________________________________________________________________
106 : void AliITSOnlineSDDCMN::ValidateAnodes(){
107 : // Tag good/bad anodes
108 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++){
109 0 : if(!fGoodAnode[ian]) continue;
110 0 : if(GetAnodeCorrNoise(ian)>fMaxCorrNoise || GetAnodeCorrNoise(ian)<fMinCorrNoise) fGoodAnode[ian]=0;
111 0 : if(GetAnodeCorrNoise(ian)>fNSigmaNoise*CalcMeanNoise()) fGoodAnode[ian]=0;
112 : }
113 0 : ValidateModule();
114 0 : }
115 : //______________________________________________________________________
116 : void AliITSOnlineSDDCMN::ValidateModule(){
117 : // check if there are enough good channels or a cluster og good channels
118 :
119 0 : Int_t nGoodAnodes=CountGoodAnodes();
120 0 : if(nGoodAnodes==0) fHighThreshold=255;
121 0 : else if(nGoodAnodes<fMinNumGoodAnForGoodMod){
122 : Bool_t inCluster=kFALSE;
123 : Int_t nAnCluster=0;
124 : Int_t largerCluster=0;
125 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++){
126 0 : if(!inCluster && IsAnodeGood(ian)){
127 : inCluster=kTRUE;
128 : nAnCluster=0;
129 0 : }
130 0 : if(inCluster && IsAnodeGood(ian)==0){
131 : inCluster=kFALSE;
132 0 : if(nAnCluster>largerCluster) largerCluster=nAnCluster;
133 : }
134 0 : if(inCluster && IsAnodeGood(ian)) nAnCluster++;
135 : }
136 0 : if(largerCluster<fMinClusterOfGoodAn){
137 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++) fGoodAnode[ian]=kFALSE;
138 0 : fHighThreshold=255;
139 0 : }
140 0 : }
141 0 : }
142 :
143 : //______________________________________________________________________
144 : TH2F* AliITSOnlineSDDCMN::GetCleanEvent(const TH2F* hrawd) const {
145 : // Fills an histogram with counts corrected for common mode noise
146 :
147 0 : TH2F* hcorrd=new TH2F("hcorrd","",hrawd->GetNbinsX(),hrawd->GetXaxis()->GetXmin(),hrawd->GetXaxis()->GetXmax(),hrawd->GetNbinsY(),hrawd->GetYaxis()->GetXmin(),hrawd->GetYaxis()->GetXmax());
148 0 : for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
149 : Float_t sumEven=0., sumOdd=0.;
150 : Int_t countEven=0, countOdd=0;
151 0 : for(Int_t ian=0;ian<fgkNAnodes;ian+=2){
152 0 : if(!fGoodAnode[ian]) continue;
153 0 : sumEven+=hrawd->GetBinContent(itb+1,ian+1)-fBaseline[ian];
154 0 : countEven++;
155 0 : }
156 0 : for(Int_t ian=1;ian<fgkNAnodes;ian+=2){
157 0 : if(!fGoodAnode[ian]) continue;
158 0 : sumOdd+=hrawd->GetBinContent(itb+1,ian+1)-fBaseline[ian];
159 0 : countOdd++;
160 0 : }
161 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++){
162 0 : if(!fGoodAnode[ian]) continue;
163 : Float_t meanN;
164 0 : if(ian%2==0) meanN=sumEven/(Float_t)countEven;
165 0 : else meanN=sumOdd/(Float_t)countOdd;
166 0 : Float_t cntCorr=hrawd->GetBinContent(itb+1,ian+1)-fCMN[ian]*meanN;
167 0 : hcorrd->SetBinContent(itb+1,ian+1,cntCorr);
168 0 : }
169 : }
170 0 : return hcorrd;
171 0 : }
172 : //______________________________________________________________________
173 : void AliITSOnlineSDDCMN::AddEvent(TH2F* hrawd){
174 : // analyzes one event and adds its ontribution to the various counters
175 :
176 0 : fNEvents++;
177 0 : TH2F* hcorrd=GetCleanEvent(hrawd);
178 :
179 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++){
180 0 : if(!fGoodAnode[ian]) continue;
181 : Float_t sumQ=0.;
182 : Int_t cnt=0;
183 0 : for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
184 0 : Float_t cntdiff=hcorrd->GetBinContent(itb+1,ian+1)-fBaseline[ian];
185 0 : sumQ+=cntdiff*cntdiff;
186 0 : cnt++;
187 : }
188 0 : if(cnt != 0)fSumCorrNoise[ian]+=TMath::Sqrt(sumQ/(Float_t)cnt);
189 0 : }
190 0 : delete hcorrd;
191 0 : }
192 : //______________________________________________________________________
193 : Float_t AliITSOnlineSDDCMN::CalcMeanNoise() const{
194 : // compute average noise
195 :
196 : Float_t meanns=0.;
197 : Int_t cnt=0;
198 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++){
199 0 : if(!fGoodAnode[ian]) continue;
200 0 : meanns+=GetAnodeCorrNoise(ian);
201 0 : cnt++;
202 0 : }
203 0 : if(cnt>0) meanns/=(Float_t)cnt;
204 0 : return meanns;
205 : }
206 : //______________________________________________________________________
207 : void AliITSOnlineSDDCMN::WriteToASCII(){
208 : // writes parameters of each channel into an ASCII file
209 : // to be then read by the PULSER DA (AliITSOnlineSDDTP)
210 :
211 0 : TString outfilnam;
212 0 : outfilnam.Form("SDDbase_step2_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
213 0 : FILE* outf=fopen(outfilnam.Data(),"w");
214 0 : fprintf(outf,"%d\n",fHighThreshold);
215 0 : fprintf(outf,"%d\n",fLowThreshold);
216 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++){
217 0 : 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));
218 : }
219 0 : fclose(outf);
220 0 : }
221 :
222 : //______________________________________________________________________
223 : TH1F* AliITSOnlineSDDCMN::GetBaselineAnodeHisto() const {
224 : // produce histogram with baseline vs. anode number
225 0 : TString hisnam;
226 0 : hisnam.Form("hbase%02dc%02ds%d",fDDL,fCarlos,fSide);
227 0 : TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
228 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++){
229 0 : h->SetBinContent(ian+1,GetAnodeBaseline(ian));
230 : }
231 : return h;
232 0 : }
233 : //______________________________________________________________________
234 : TH1F* AliITSOnlineSDDCMN::GetRawNoiseAnodeHisto() const {
235 : // produce histogram with raw noise vs. anode number
236 0 : TString hisnam;
237 0 : hisnam.Form("hnois%02dc%02ds%d",fDDL,fCarlos,fSide);
238 0 : TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
239 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++){
240 0 : h->SetBinContent(ian+1,GetAnodeRawNoise(ian));
241 : }
242 : return h;
243 0 : }
244 : //______________________________________________________________________
245 : TH1F* AliITSOnlineSDDCMN::GetCorrNoiseAnodeHisto() const {
246 : // produce histogram with corrected noise vs. anode number
247 0 : TString hisnam;
248 0 : hisnam.Form("hcorn%02dc%02ds%d",fDDL,fCarlos,fSide);
249 0 : TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
250 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++){
251 0 : h->SetBinContent(ian+1,GetAnodeCorrNoise(ian));
252 : }
253 : return h;
254 0 : }
255 : //______________________________________________________________________
256 : TH1F* AliITSOnlineSDDCMN::GetCMNCoefAnodeHisto() const {
257 : // produce histogram with coefficients for common mode noise subtraction
258 0 : TString hisnam;
259 0 : hisnam.Form("hcmn%02dc%02ds%d",fDDL,fCarlos,fSide);
260 0 : TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
261 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++){
262 0 : h->SetBinContent(ian+1,GetAnodeCommonMode(ian));
263 : }
264 : return h;
265 0 : }
266 : //______________________________________________________________________
267 : TH1F* AliITSOnlineSDDCMN::GetStatusAnodeHisto() const {
268 : // produce histogram with status bit of each anode
269 0 : TString hisnam;
270 0 : hisnam.Form("hgood%02dc%02ds%d",fDDL,fCarlos,fSide);
271 0 : TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
272 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++){
273 0 : h->SetBinContent(ian+1,float(IsAnodeGood(ian)));
274 : }
275 : return h;
276 0 : }
277 : //______________________________________________________________________
278 : TH1F* AliITSOnlineSDDCMN::GetBaselineHisto() const {
279 : // produce histogram with baseline distribution
280 0 : TString hisnam;
281 0 : hisnam.Form("hdbd%02dc%02ds%d",fDDL,fCarlos,fSide);
282 0 : TH1F* h=new TH1F(hisnam.Data(),"",100,0.,150.);
283 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++){
284 0 : h->Fill(GetAnodeBaseline(ian));
285 : }
286 : return h;
287 0 : }
288 : //______________________________________________________________________
289 : TH1F* AliITSOnlineSDDCMN::GetRawNoiseHisto() const {
290 : // produce histogram with raw noise distribution
291 0 : TString hisnam;
292 0 : hisnam.Form("hdnd%02dc%02ds%d",fDDL,fCarlos,fSide);
293 0 : TH1F* h=new TH1F(hisnam.Data(),"",100,0.,8.);
294 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++){
295 0 : h->Fill(GetAnodeRawNoise(ian));
296 : }
297 : return h;
298 0 : }
299 : //______________________________________________________________________
300 : TH1F* AliITSOnlineSDDCMN::GetCorrNoiseHisto() const {
301 : // produce histogram with corrected noise distribution
302 0 : TString hisnam;
303 0 : hisnam.Form("hdcd%02dc%02ds%d",fDDL,fCarlos,fSide);
304 0 : TH1F* h=new TH1F(hisnam.Data(),"",100,0.,8.);
305 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++){
306 0 : h->Fill(GetAnodeCorrNoise(ian));
307 : }
308 : return h;
309 0 : }
310 : //______________________________________________________________________
311 : Bool_t AliITSOnlineSDDCMN::WriteToROOT(TFile *fil){
312 : // writes output into a root file
313 0 : if(fil==0){
314 0 : AliWarning("Invalid pointer to ROOT file");
315 0 : return kFALSE;
316 : }
317 0 : TString hisnam;
318 0 : fil->cd();
319 0 : hisnam.Form("hgood%02dc%02ds%d",fDDL,fCarlos,fSide);
320 0 : TH1F hgood(hisnam.Data(),"",256,-0.5,255.5);
321 0 : hisnam.Form("hbase%02dc%02ds%d",fDDL,fCarlos,fSide);
322 0 : TH1F hbase(hisnam.Data(),"",256,-0.5,255.5);
323 0 : hisnam.Form("hnois%02dc%02ds%d",fDDL,fCarlos,fSide);
324 0 : TH1F hnois(hisnam.Data(),"",256,-0.5,255.5);
325 0 : hisnam.Form("hcmn%02dc%02ds%d",fDDL,fCarlos,fSide);
326 0 : TH1F hcmn(hisnam.Data(),"",256,-0.5,255.5);
327 0 : hisnam.Form("hcorn%02dc%02ds%d",fDDL,fCarlos,fSide);
328 0 : TH1F hcorn(hisnam.Data(),"",256,-0.5,255.5);
329 0 : for(Int_t ian=0;ian<fgkNAnodes;ian++){
330 0 : hgood.SetBinContent(ian+1,float(IsAnodeGood(ian)));
331 0 : hbase.SetBinContent(ian+1,GetAnodeBaseline(ian));
332 0 : hnois.SetBinContent(ian+1,GetAnodeRawNoise(ian));
333 0 : hcmn.SetBinContent(ian+1,GetAnodeCommonMode(ian));
334 0 : hcorn.SetBinContent(ian+1,GetAnodeCorrNoise(ian));
335 : }
336 0 : hgood.Write();
337 0 : hbase.Write();
338 0 : hnois.Write();
339 0 : hcmn.Write();
340 0 : hcorn.Write();
341 : return kTRUE;
342 0 : }
|