]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONSt1ResponseParameter.cxx
Improved response simulation for station 1.
[u/mrichter/AliRoot.git] / MUON / AliMUONSt1ResponseParameter.cxx
CommitLineData
ba030c0e 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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
16/*
17$Log$
18*/
19
20// Authors: David Guez, Ivana Hrivnacova, Marion MacCormick; IPN Orsay
21//
22// Class AliMUONSt1ResponseParameter
23// ---------------------------------
24// Describes a set of filters to be applied to a digital value
25// in order to simulate electronics characteristics
26// (pedestal, noise, sticky bits, etc....)
27// Threshold levels for the MANU zero supression algorithm are included.
28
29#include <fstream>
30#include <TRandom.h>
31#include "AliMUONSt1ResponseParameter.h"
32
33ClassImp(AliMUONSt1ResponseParameter);
34
35//_________________________________________________________________________
36AliMUONSt1ResponseParameter::AliMUONSt1ResponseParameter()
37 :TNamed()
38{
39// default constructor
40 fPedestalMode = kNone;
41 fNoiseMode = kNone;
42 fState=1;
43 fNofSigma=3;
44 fStickyOn=fStickyOff=0;
45}
46
47//_________________________________________________________________________
48AliMUONSt1ResponseParameter::AliMUONSt1ResponseParameter(const TString& name,const TString& title)
49:TNamed(name,title)
50{
51// normal constructor
52 fPedestalMode = kNone;
53 fNoiseMode = kNone;
54 fState=1;
55 fNofSigma=3;
56 fStickyOn=fStickyOff=0;
57}
58
59//_________________________________________________________________________
60AliMUONSt1ResponseParameter::~AliMUONSt1ResponseParameter()
61{
62// destructor
63}
64
65//_________________________________________________________________________
66void AliMUONSt1ResponseParameter::SetState(Bool_t state)
67{
68// If set to off, no information will be available from the electronics
69// ---
70
71 fState=state;
72}
73
74//_________________________________________________________________________
75void AliMUONSt1ResponseParameter::SetPedestal(Double_t val)
76{
77// Set pedestal values to a constant
78// ---
79
80 fPedestalMode = kValue;
81 fPedestalParam.value = val;
82}
83
84//_________________________________________________________________________
85void AliMUONSt1ResponseParameter::SetPedestal(Double_t mean,Double_t sigma)
86{
87// Set pedestal values to a parameterized gaussian
88// ---
89
90 fPedestalMode = kGauss;
91 fPedestalParam.gauss.mean = mean;
92 fPedestalParam.gauss.sigma = sigma;
93}
94//_________________________________________________________________________
95void AliMUONSt1ResponseParameter::SetPedestal(const TString& fileName)
96{
97// Set pedestal values to those given in a file
98// ---
99
100 ifstream file(fileName.Data());
101 if (file.good()){
102 fPedestalMode = kFile;
103 for (Int_t ch=0;ch<fgkNofChannels;ch++) {
104 Float_t value;
105 file>>value;
106 fPedestalParam.values[ch] = value;
107 //cout<<"Pedestal["<<i<<"]["<<ch<<"]="<<value<<endl;
108 }
109 file.close();
110 } else {
111 Warning("SetPedestal",Form("Can't read file %s",fileName.Data()));
112 SetPedestal(150.,10.);
113 }
114}
115
116//_________________________________________________________________________
117void AliMUONSt1ResponseParameter::UnSetPedestal()
118{
119// Set pedestal values to 0.
120// ---
121
122 fPedestalMode=kNone;
123}
124
125//_________________________________________________________________________
126void AliMUONSt1ResponseParameter::SetNoise(Double_t val)
127{
128// Set Noise values to a constant value
129// ---
130
131 fNoiseMode = kValue;
132 fNoiseParam.value = val;
133}
134
135//_________________________________________________________________________
136void AliMUONSt1ResponseParameter::SetNoise(Double_t mean,Double_t sigma)
137{
138// Set Noise values to a parameterized gaussian
139// ---
140
141 fNoiseMode = kGauss;
142 fNoiseParam.gauss.mean = mean;
143 fNoiseParam.gauss.sigma = sigma;
144}
145
146//_________________________________________________________________________
147void AliMUONSt1ResponseParameter::SetNoise(const TString& fileName)
148{
149// Set Noise values to those given in a file
150// ---
151
152 ifstream file(fileName.Data());
153 if (file.good()){
154 fNoiseMode = kFile;
155 for (Int_t ch=0;ch<fgkNofChannels;ch++) {
156 Float_t value;
157 file>>value;
158 fNoiseParam.values[ch] = value;
159 //cout<<"Noise["<<i<<"]["<<ch<<"]="<<value<<endl;
160 }
161 file.close();
162 } else {
163 Warning("SetNoise",Form("Can't read file %s",fileName.Data()));
164 SetNoise(150.,10.);
165 }
166}
167
168//_________________________________________________________________________
169void AliMUONSt1ResponseParameter::SetNofSigma(Int_t nofSigma)
170{
171// set Number of sigmas to be applied as threshold (for zero suppression)
172// ---
173
174 fNofSigma = nofSigma;
175}
176
177//_________________________________________________________________________
178void AliMUONSt1ResponseParameter::SetStickyBitOn (Int_t bit,Int_t val)
179{
180// In the response, this bit will always be set to 1 (unless <State> is off)
181// ---
182
183 if (val)
184 fStickyOn |= (1<<bit);
185 else
186 fStickyOn &= ~(1<<bit);
187}
188
189//_________________________________________________________________________
190void AliMUONSt1ResponseParameter::SetStickyBitOff(Int_t bit,Int_t val)
191{
192// In the response, this bit will always be set to 0
193// ---
194
195 if (val)
196 fStickyOff |= (1<<bit);
197 else
198 fStickyOff &= ~(1<<bit);
199}
200
201//_________________________________________________________________________
202Int_t AliMUONSt1ResponseParameter::ApplyPedestal(Int_t base,Int_t GC) const
203{
204// calculate the response to <base>, with respect to the current pedestal
205// parameters
206// --
207 Double_t ped = Choose(fPedestalMode,fPedestalParam,GC);
208 Double_t nse = Choose(fNoiseMode,fNoiseParam,GC);
209 Double_t noise = gRandom->Gaus(0, nse);
210 base+=(Int_t)(noise + ped);
211 if (base-ped-noise*fNofSigma<0) base=0;
212
213 return base;
214}
215//_________________________________________________________________________
216Int_t AliMUONSt1ResponseParameter::ApplyStickyBits(Int_t base) const
217{
218// set the response to <base>, with respect to the current stickyBits
219// parameters
220// --
221 base |= fStickyOn;
222 base &= (~fStickyOff);
223 return base;
224}
225//////////////////// Privates methods
226//_________________________________________________________________________
227
228Double_t AliMUONSt1ResponseParameter::Choose(TMode mode,TParam param,Int_t GC) const
229{
230// Choose a (pedestal/noise) value to be applied following the parameterization rule
231// ---
232
233 switch (mode){
234 case kNone : return 0;
235 case kValue : return param.value;
236 case kGauss : return gRandom->Gaus(param.gauss.mean,param.gauss.sigma);
237 case kFile : return param.values[GC];
238 }
239 Fatal("Choose","No mode is given");
240 return 0;
241}