Small patch for file copying for special outputs in proof mode (M.Vala)
[u/mrichter/AliRoot.git] / FMD / AliFMDDigitizer.cxx
... / ...
CommitLineData
1/**************************************************************************
2 * Copyright(c) 2004, 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/* $Id$ */
16/** @file AliFMDDigitizer.cxx
17 @author Christian Holm Christensen <cholm@nbi.dk>
18 @date Mon Mar 27 12:38:26 2006
19 @brief FMD Digitizers implementation
20 @ingroup FMD_sim
21*/
22//////////////////////////////////////////////////////////////////////////////
23//
24// This class contains the procedures simulation ADC signal for the
25// Forward Multiplicity detector : Hits->Digits
26//
27// Digits consists of
28// - Detector #
29// - Ring ID
30// - Sector #
31// - Strip #
32// - ADC count in this channel
33//
34// As the Digits and SDigits have so much in common, the classes
35// AliFMDDigitizer and AliFMDSDigitizer are implemented via a base
36// class AliFMDBaseDigitizer.
37//
38// +---------------------+
39// | AliFMDBaseDigitizer |
40// +---------------------+
41// ^
42// |
43// +----------+---------+
44// | |
45// +-----------------+ +------------------+
46// | AliFMDDigitizer | | AliFMDSDigitizer |
47// +-----------------+ +------------------+
48//
49// These classes has several paramters:
50//
51// fPedestal
52// fPedestalWidth
53// (Only AliFMDDigitizer)
54// Mean and width of the pedestal. The pedestal is simulated
55// by a Guassian, but derived classes my override MakePedestal
56// to simulate it differently (or pick it up from a database).
57//
58// fVA1MipRange
59// The dymamic MIP range of the VA1_ALICE pre-amplifier chip
60//
61// fAltroChannelSize
62// The largest number plus one that can be stored in one
63// channel in one time step in the ALTRO ADC chip.
64//
65// fSampleRate
66// How many times the ALTRO ADC chip samples the VA1_ALICE
67// pre-amplifier signal. The VA1_ALICE chip is read-out at
68// 10MHz, while it's possible to drive the ALTRO chip at
69// 25MHz. That means, that the ALTRO chip can have time to
70// sample each VA1_ALICE signal up to 2 times. Although it's
71// not certain this feature will be used in the production,
72// we'd like have the option, and so it should be reflected in
73// the code.
74//
75// These parameters are fetched from OCDB via the mananger AliFMDParameters.
76//
77// The shaping function of the VA1_ALICE is generally given by
78//
79// f(x) = A(1 - exp(-Bx))
80//
81// where A is the total charge collected in the pre-amp., and B is a
82// paramter that depends on the shaping time of the VA1_ALICE circut.
83//
84// When simulating the shaping function of the VA1_ALICe
85// pre-amp. chip, we have to take into account, that the shaping
86// function depends on the previous value of read from the pre-amp.
87//
88// That results in the following algorithm:
89//
90// last = 0;
91// FOR charge IN pre-amp. charge train DO
92// IF last < charge THEN
93// f(t) = (charge - last) * (1 - exp(-B * t)) + last
94// ELSE
95// f(t) = (last - charge) * exp(-B * t) + charge)
96// ENDIF
97// FOR i IN # samples DO
98// adc_i = f(i / (# samples))
99// DONE
100// last = charge
101// DONE
102//
103// Here,
104//
105// pre-amp. charge train
106// is a series of 128 charges read from the VA1_ALICE chip
107//
108// # samples
109// is the number of times the ALTRO ADC samples each of the 128
110// charges from the pre-amp.
111//
112// Where Q is the total charge collected by the VA1_ALICE
113// pre-amplifier. Q is then given by
114//
115// E S
116// Q = - -
117// e R
118//
119// where E is the total energy deposited in a silicon strip, R is the
120// dynamic range of the VA1_ALICE pre-amp (fVA1MipRange), e is the
121// energy deposited by a single MIP, and S ALTRO channel size in each
122// time step (fAltroChannelSize).
123//
124// The energy deposited per MIP is given by
125//
126// e = M * rho * w
127//
128// where M is the universal number 1.664, rho is the density of
129// silicon, and w is the depth of the silicon sensor.
130//
131// The final ADC count is given by
132//
133// C' = C + P
134//
135// where P is the (randomized) pedestal (see MakePedestal)
136//
137// This class uses the class template AliFMDMap<Type> to make an
138// internal cache of the energy deposted of the hits. The class
139// template is instantasized as
140//
141// typedef AliFMDMap<std::pair<Float_t, UShort_t> > AliFMDEdepMap;
142//
143// The first member of the values is the summed energy deposition in a
144// given strip, while the second member of the values is the number of
145// hits in a given strip. Using the second member, it's possible to
146// do some checks on just how many times a strip got hit, and what
147// kind of error we get in our reconstructed hits. Note, that this
148// information is currently not written to the digits tree. I think a
149// QA (Quality Assurance) digit tree is better suited for that task.
150// However, the information is there to be used in the future.
151//
152//
153// Latest changes by Christian Holm Christensen
154//
155//////////////////////////////////////////////////////////////////////////////
156
157// /1
158// | A(-1 + B + exp(-B))
159// | f(x) dx = ------------------- = 1
160// | B
161// / 0
162//
163// and B is the a parameter defined by the shaping time (fShapingTime).
164//
165// Solving the above equation, for A gives
166//
167// B
168// A = ----------------
169// -1 + B + exp(-B)
170//
171// So, if we define the function g: [0,1] -> [0:1] by
172//
173// / v
174// | Bu + exp(-Bu) - Bv - exp(-Bv)
175// g(u,v) = | f(x) dx = -A -----------------------------
176// | B
177// / u
178//
179// we can evaluate the ALTRO sample of the VA1_ALICE pre-amp between
180// any two times (u, v), by
181//
182//
183// B Bu + exp(-Bu) - Bv - exp(-Bv)
184// C = Q g(u,v) = - Q ---------------- -----------------------------
185// -1 + B + exp(-B) B
186//
187// Bu + exp(-Bu) - Bv - exp(-Bv)
188// = - Q -----------------------------
189// -1 + B + exp(-B)
190//
191
192#include <TTree.h> // ROOT_TTree
193#include <TRandom.h> // ROOT_TRandom
194#include "AliFMDDebug.h" // Better debug macros
195#include "AliFMDDigitizer.h" // ALIFMDDIGITIZER_H
196#include "AliFMD.h" // ALIFMD_H
197#include "AliFMDDigit.h" // ALIFMDDIGIT_H
198#include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
199#include <AliRunDigitizer.h> // ALIRUNDIGITIZER_H
200#include <AliRun.h> // ALIRUN_H
201#include <AliLoader.h> // ALILOADER_H
202#include <AliRunLoader.h> // ALIRUNLOADER_H
203
204//====================================================================
205ClassImp(AliFMDDigitizer)
206
207//____________________________________________________________________
208void
209AliFMDDigitizer::OutputTree(AliLoader* outFMD, AliFMD* fmd)
210{
211 // Load digits from the tree
212 outFMD->LoadDigits("update");
213
214 // Get the tree of digits
215 TTree* digitTree = outFMD->TreeD();
216 if (!digitTree) {
217 outFMD->MakeTree("D");
218 digitTree = outFMD->TreeD();
219 }
220 digitTree->Reset();
221
222 // Get the digits
223 TClonesArray* digits = fmd->Digits();
224 if (!digits) {
225 AliError("Failed to get digits");
226 return;
227 }
228 AliFMDDebug(1, ("Got a total of %5d digits", digits->GetEntries()));
229
230 // Make a branch in the tree
231 fmd->MakeBranchInTree(digitTree, fmd->GetName(), &(digits), 4000, 0);
232 // TBranch* digitBranch = digitTree->GetBranch(fmd->GetName());
233 // Fill the tree
234 Int_t write = 0;
235 write = digitTree->Fill();
236 AliFMDDebug(1, ("Wrote %d bytes to digit tree", write));
237
238 // Write the digits to disk
239 outFMD->WriteDigits("OVERWRITE");
240 outFMD->UnloadHits();
241 outFMD->UnloadDigits();
242
243 // Reset the digits in the AliFMD object
244 fmd->ResetDigits();
245}
246
247//____________________________________________________________________
248UShort_t
249AliFMDDigitizer::MakePedestal(UShort_t detector,
250 Char_t ring,
251 UShort_t sector,
252 UShort_t strip) const
253{
254 // Make a pedestal
255 AliFMDParameters* param =AliFMDParameters::Instance();
256 Float_t mean =param->GetPedestal(detector,ring,sector,strip);
257 Float_t width =param->GetPedestalWidth(detector,ring,sector,strip);
258 return UShort_t(TMath::Max(gRandom->Gaus(mean, width), 0.));
259}
260
261//____________________________________________________________________
262void
263AliFMDDigitizer::AddDigit(AliFMD* fmd,
264 UShort_t detector,
265 Char_t ring,
266 UShort_t sector,
267 UShort_t strip,
268 Float_t /* edep */,
269 UShort_t count1,
270 Short_t count2,
271 Short_t count3,
272 Short_t count4) const
273{
274 // Add a digit
275 fmd->AddDigitByFields(detector, ring, sector, strip,
276 count1, count2, count3, count4);
277}
278
279//____________________________________________________________________
280void
281AliFMDDigitizer::CheckDigit(AliFMDDigit* digit,
282 UShort_t nhits,
283 const TArrayI& counts)
284{
285 // Check that digit is consistent
286 AliFMDParameters* param = AliFMDParameters::Instance();
287 UShort_t det = digit->Detector();
288 Char_t ring = digit->Ring();
289 UShort_t sec = digit->Sector();
290 UShort_t str = digit->Strip();
291 Float_t mean = param->GetPedestal(det,ring,sec,str);
292 Float_t width = param->GetPedestalWidth(det,ring,sec,str);
293 UShort_t range = param->GetVA1MipRange();
294 UShort_t size = param->GetAltroChannelSize();
295 Int_t integral = counts[0];
296 if (counts[1] >= 0) integral += counts[1];
297 if (counts[2] >= 0) integral += counts[2];
298 if (counts[3] >= 0) integral += counts[3];
299 integral -= Int_t(mean + 2 * width);
300 if (integral < 0) integral = 0;
301
302 Float_t convF = Float_t(range) / size;
303 Float_t mips = integral * convF;
304 if (mips > Float_t(nhits) + .5 || mips < Float_t(nhits) - .5)
305 Warning("CheckDigit", "Digit -> %4.2f MIPS != %d +/- .5 hits",
306 mips, nhits);
307}
308
309//____________________________________________________________________
310//
311// EOF
312//
313
314
315
316