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