]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSOnlineSDDTP.cxx
SDD DA: possibility of excluding first and last time bin
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSDDTP.cxx
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 "AliITSOnlineSDDTP.h"
17 #include "AliLog.h"
18 #include <TH2F.h>
19 #include <TMath.h>
20
21
22 ///////////////////////////////////////////////////////////////////
23 //                                                               //
24 // Implemetation of the class SDD Test Pulse analysis            //
25 // Origin: F.Prino, Torino, prino@to.infn.it                     //
26 //                                                               //
27 ///////////////////////////////////////////////////////////////////
28
29
30 ClassImp(AliITSOnlineSDDTP)
31
32 //______________________________________________________________________
33 AliITSOnlineSDDTP::AliITSOnlineSDDTP():AliITSOnlineSDD(),fDAC(0.),fNSigmaGain(0.),fNSigmaNoise(0.)
34 {
35   // default constructor
36   Reset();
37   SetNSigmaGain();
38   SetNSigmaNoise();
39 }
40 //______________________________________________________________________
41 AliITSOnlineSDDTP::AliITSOnlineSDDTP(Int_t mod, Int_t sid, Float_t xDAC):AliITSOnlineSDD(mod,sid),fDAC(xDAC),fNSigmaGain(0.),fNSigmaNoise(0.)
42 {
43   // standard constructor
44   Reset();
45   SetNSigmaGain();
46   SetNSigmaNoise();
47 }
48 //______________________________________________________________________
49 AliITSOnlineSDDTP::~AliITSOnlineSDDTP(){
50   // Destructor
51 }
52 //______________________________________________________________________
53 void AliITSOnlineSDDTP::Reset(){
54   //
55   for(Int_t i=0;i<fgkNAnodes;i++){
56     fNEvents[i]=0;
57     fGoodAnode[i]=1;
58     fBaseline[i]=0.;
59     fCMN[i]=0.;
60     fRawNoise[i]=0.;
61     fCorrNoise[i]=0.;
62     fSumTPPeak[i]=0.;
63     fTPPos[i]=0.;
64   }
65   ReadBaselines();
66 }
67
68 //______________________________________________________________________
69 void AliITSOnlineSDDTP::AddEvent(TH2F* hrawd){
70   // 
71   for(Int_t ian=0;ian<fgkNAnodes;ian++){
72     Float_t auxmax=0.;
73     Int_t auxtb=0;
74     if(!fGoodAnode[ian]) continue;
75     for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
76       Float_t cnt=hrawd->GetBinContent(itb+1,ian+1);
77       if(cnt>auxmax){ 
78         auxmax=cnt;
79         auxtb=itb;
80       }
81     }
82     if(auxmax>fBaseline[ian]+fNSigmaNoise*fRawNoise[ian]){
83       fSumTPPeak[ian]+=auxmax-fBaseline[ian];
84       fTPPos[ian]+=auxtb;
85       fNEvents[ian]++;
86     }
87   }
88 }
89 //______________________________________________________________________
90 void AliITSOnlineSDDTP::ReadBaselines(){
91   // assume baselines and good anodes are taken from previous run
92   Char_t basfilnam[100];
93   sprintf(basfilnam,"SDDbase_step2_mod%03d_sid%d.data",fModuleId,fSide);
94   FILE* basf=fopen(basfilnam,"r");
95   if(basf==0){
96     AliWarning("Baselinefile not present, Set all baselines to 50\n");
97     for(Int_t ian=0;ian<fgkNAnodes;ian++){ 
98       fBaseline[ian]=50.;
99       fGoodAnode[ian]=1;
100     }
101     return;
102   }
103   Int_t n,ok;
104   Float_t base,rms,cmn,corrnoi;
105   for(Int_t ian=0;ian<fgkNAnodes;ian++){
106     fscanf(basf,"%d %d %f %f %f %f\n",&n,&ok,&base,&rms,&cmn,&corrnoi);
107     fBaseline[ian]=base;
108     fGoodAnode[ian]=ok;
109     fRawNoise[ian]=rms;
110     fCMN[ian]=cmn;
111     fCorrNoise[ian]=corrnoi;
112   }
113   fclose(basf);
114 }
115
116 //______________________________________________________________________
117 Bool_t AliITSOnlineSDDTP::IsModuleGood() const{
118   //
119   // Check if there is at least 1 good anode
120   //
121   for(Int_t ian=0;ian<fgkNAnodes;ian++){
122     if(fGoodAnode[ian]) return kTRUE;
123   }
124   return kFALSE;
125 }
126 //______________________________________________________________________
127 void AliITSOnlineSDDTP::ValidateAnodes(){
128   //
129   Float_t meang,rmsg;
130   StatGain(meang,rmsg);
131   Float_t lowlim=meang-fNSigmaGain*rmsg;
132   Float_t hilim=meang+fNSigmaGain*rmsg;
133
134   for(Int_t ian=0;ian<fgkNAnodes;ian++){
135     if(!fGoodAnode[ian]) continue;
136     if(GetChannelGain(ian)<lowlim||GetChannelGain(ian)>hilim) fGoodAnode[ian]=0;
137   }
138 }
139
140
141 //______________________________________________________________________
142 void AliITSOnlineSDDTP::StatGain(Float_t &mean, Float_t  &rms){
143   //
144   Float_t sum=0.,sumq=0.;
145   Int_t cnt=0;
146   for(Int_t ian=0;ian<fgkNAnodes;ian++){
147     if(!fGoodAnode[ian]) continue;
148     if(fNEvents[ian]==0) continue;
149     sum+=GetChannelGain(ian);
150     sumq+=TMath::Power(GetChannelGain(ian),2);
151     cnt++;
152   }
153   if(cnt>0){ 
154     mean=sum/(Float_t)cnt;
155     rms=TMath::Sqrt(sumq/(Float_t)cnt-mean*mean);
156   }else{ 
157     mean=0.;
158     rms=0.;
159   }
160   return;
161 }
162
163 //______________________________________________________________________
164 void AliITSOnlineSDDTP::WriteToASCII(){
165   //
166   Char_t outfilnam[100];
167   sprintf(outfilnam,"SDDbase_mod%03d_sid%d.data",fModuleId,fSide);
168   FILE* outf=fopen(outfilnam,"w");
169   fprintf(outf,"%d %d %d\n",fModuleId,fSide,IsModuleGood());
170   for(Int_t ian=0;ian<fgkNAnodes;ian++){
171     fprintf(outf,"%d %d %8.3f %8.3f %8.3f %8.3f %8.3f\n",ian,IsAnodeGood(ian),GetAnodeBaseline(ian),GetAnodeRawNoise(ian),GetAnodeCommonMode(ian),GetAnodeCorrNoise(ian),GetChannelGain(ian));
172   }
173   fclose(outf);  
174 }
175 //______________________________________________________________________
176 Bool_t AliITSOnlineSDDTP::WriteToROOT(TFile *fil){
177   //
178   if(fil==0){ 
179     AliWarning("Invalid pointer to ROOT file");
180     return kFALSE;    
181   }
182   Char_t hisnam[20];
183   fil->cd();
184   sprintf(hisnam,"hgood%03ds%d",fModuleId,fSide);
185   TH1F hgood(hisnam,"",256,-0.5,255.5);
186   sprintf(hisnam,"hbase%03ds%d",fModuleId,fSide);
187   TH1F hbase(hisnam,"",256,-0.5,255.5);
188   sprintf(hisnam,"hnois%03ds%d",fModuleId,fSide);
189   TH1F hnois(hisnam,"",256,-0.5,255.5);
190   sprintf(hisnam,"hcmn%03ds%d",fModuleId,fSide);
191   TH1F hcmn(hisnam,"",256,-0.5,255.5);
192   sprintf(hisnam,"hcorn%03ds%d",fModuleId,fSide);
193   TH1F hcorn(hisnam,"",256,-0.5,255.5);
194   sprintf(hisnam,"hgain%03ds%d",fModuleId,fSide);
195   TH1F hgain(hisnam,"",256,-0.5,255.5);
196   for(Int_t ian=0;ian<fgkNAnodes;ian++){
197     hgood.SetBinContent(ian+1,float(IsAnodeGood(ian)));
198     hbase.SetBinContent(ian+1,GetAnodeBaseline(ian));
199     hnois.SetBinContent(ian+1,GetAnodeRawNoise(ian));
200     hcmn.SetBinContent(ian+1,GetAnodeCommonMode(ian));
201     hcorn.SetBinContent(ian+1,GetAnodeCorrNoise(ian));
202     hgain.SetBinContent(ian+1,GetChannelGain(ian));
203   }
204   hgood.Write();
205   hbase.Write();
206   hnois.Write();
207   hcmn.Write();
208   hcorn.Write();
209   hgain.Write();
210   return kTRUE;
211 }
212