Added missing pragma's
[u/mrichter/AliRoot.git] / FMD / AliFMDSDigitizer.cxx
CommitLineData
02a27b50 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 AliFMDSDigitizer.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 and Hits->SDigits
26//
27// Digits consists of
28// - Detector #
29// - Ring ID
30// - Sector #
31// - Strip #
32// - ADC count in this channel
33//
34// Digits consists of
35// - Detector #
36// - Ring ID
37// - Sector #
38// - Strip #
39// - Total energy deposited in the strip
40// - ADC count in this channel
41//
42// As the Digits and SDigits have so much in common, the classes
43// AliFMDDigitizer and AliFMDSDigitizer are implemented via a base
44// class AliFMDBaseDigitizer.
45//
46// +---------------------+
47// | AliFMDBaseDigitizer |
48// +---------------------+
49// ^
50// |
51// +----------+---------+
52// | |
53// +-----------------+ +------------------+
54// | AliFMDDigitizer | | AliFMDSDigitizer |
55// +-----------------+ +------------------+
56//
57// These classes has several paramters:
58//
59// fPedestal
60// fPedestalWidth
61// (Only AliFMDDigitizer)
62// Mean and width of the pedestal. The pedestal is simulated
63// by a Guassian, but derived classes my override MakePedestal
64// to simulate it differently (or pick it up from a database).
65//
66// fVA1MipRange
67// The dymamic MIP range of the VA1_ALICE pre-amplifier chip
68//
69// fAltroChannelSize
70// The largest number plus one that can be stored in one
71// channel in one time step in the ALTRO ADC chip.
72//
73// fSampleRate
74// How many times the ALTRO ADC chip samples the VA1_ALICE
75// pre-amplifier signal. The VA1_ALICE chip is read-out at
76// 10MHz, while it's possible to drive the ALTRO chip at
77// 25MHz. That means, that the ALTRO chip can have time to
78// sample each VA1_ALICE signal up to 2 times. Although it's
79// not certain this feature will be used in the production,
80// we'd like have the option, and so it should be reflected in
81// the code.
82//
83//
84// The shaping function of the VA1_ALICE is generally given by
85//
86// f(x) = A(1 - exp(-Bx))
87//
88// where A is the total charge collected in the pre-amp., and B is a
89// paramter that depends on the shaping time of the VA1_ALICE circut.
90//
91// When simulating the shaping function of the VA1_ALICe
92// pre-amp. chip, we have to take into account, that the shaping
93// function depends on the previous value of read from the pre-amp.
94//
95// That results in the following algorithm:
96//
97// last = 0;
98// FOR charge IN pre-amp. charge train DO
99// IF last < charge THEN
100// f(t) = (charge - last) * (1 - exp(-B * t)) + last
101// ELSE
102// f(t) = (last - charge) * exp(-B * t) + charge)
103// ENDIF
104// FOR i IN # samples DO
105// adc_i = f(i / (# samples))
106// DONE
107// last = charge
108// DONE
109//
110// Here,
111//
112// pre-amp. charge train
113// is a series of 128 charges read from the VA1_ALICE chip
114//
115// # samples
116// is the number of times the ALTRO ADC samples each of the 128
117// charges from the pre-amp.
118//
119// Where Q is the total charge collected by the VA1_ALICE
120// pre-amplifier. Q is then given by
121//
122// E S
123// Q = - -
124// e R
125//
126// where E is the total energy deposited in a silicon strip, R is the
127// dynamic range of the VA1_ALICE pre-amp (fVA1MipRange), e is the
128// energy deposited by a single MIP, and S ALTRO channel size in each
129// time step (fAltroChannelSize).
130//
131// The energy deposited per MIP is given by
132//
133// e = M * rho * w
134//
135// where M is the universal number 1.664, rho is the density of
136// silicon, and w is the depth of the silicon sensor.
137//
138// The final ADC count is given by
139//
140// C' = C + P
141//
142// where P is the (randomized) pedestal (see MakePedestal)
143//
144// This class uses the class template AliFMDMap<Type> to make an
145// internal cache of the energy deposted of the hits. The class
146// template is instantasized as
147//
148// typedef AliFMDMap<std::pair<Float_t, UShort_t> > AliFMDEdepMap;
149//
150// The first member of the values is the summed energy deposition in a
151// given strip, while the second member of the values is the number of
152// hits in a given strip. Using the second member, it's possible to
153// do some checks on just how many times a strip got hit, and what
154// kind of error we get in our reconstructed hits. Note, that this
155// information is currently not written to the digits tree. I think a
156// QA (Quality Assurance) digit tree is better suited for that task.
157// However, the information is there to be used in the future.
158//
159//
160// Latest changes by Christian Holm Christensen
161//
162//////////////////////////////////////////////////////////////////////////////
163
164// /1
165// | A(-1 + B + exp(-B))
166// | f(x) dx = ------------------- = 1
167// | B
168// / 0
169//
170// and B is the a parameter defined by the shaping time (fShapingTime).
171//
172// Solving the above equation, for A gives
173//
174// B
175// A = ----------------
176// -1 + B + exp(-B)
177//
178// So, if we define the function g: [0,1] -> [0:1] by
179//
180// / v
181// | Bu + exp(-Bu) - Bv - exp(-Bv)
182// g(u,v) = | f(x) dx = -A -----------------------------
183// | B
184// / u
185//
186// we can evaluate the ALTRO sample of the VA1_ALICE pre-amp between
187// any two times (u, v), by
188//
189//
190// B Bu + exp(-Bu) - Bv - exp(-Bv)
191// C = Q g(u,v) = - Q ---------------- -----------------------------
192// -1 + B + exp(-B) B
193//
194// Bu + exp(-Bu) - Bv - exp(-Bv)
195// = - Q -----------------------------
196// -1 + B + exp(-B)
197//
198
6169f936 199// #include <TTree.h> // ROOT_TTree
02a27b50 200//#include <TRandom.h> // ROOT_TRandom
f95a63c4 201// #include <AliLog.h> // ALILOG_H
202#include "AliFMDDebug.h" // Better debug macros
02a27b50 203#include "AliFMDSDigitizer.h" // ALIFMDDIGITIZER_H
204#include "AliFMD.h" // ALIFMD_H
6169f936 205// #include "AliFMDGeometry.h" // ALIFMDGEOMETRY_H
206// #include "AliFMDDetector.h" // ALIFMDDETECTOR_H
207// #include "AliFMDRing.h" // ALIFMDRING_H
02a27b50 208#include "AliFMDHit.h" // ALIFMDHIT_H
6169f936 209// #include "AliFMDDigit.h" // ALIFMDDIGIT_H
210// #include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
211// #include <AliRunDigitizer.h> // ALIRUNDIGITIZER_H
02a27b50 212#include <AliRun.h> // ALIRUN_H
213#include <AliLoader.h> // ALILOADER_H
214#include <AliRunLoader.h> // ALIRUNLOADER_H
215
216//====================================================================
217ClassImp(AliFMDSDigitizer)
218
219//____________________________________________________________________
220AliFMDSDigitizer::AliFMDSDigitizer()
221{
222 // Default ctor - don't use it
223}
224
225//____________________________________________________________________
226AliFMDSDigitizer::AliFMDSDigitizer(const Char_t* headerFile,
227 const Char_t* /* sdigfile */)
228 : AliFMDBaseDigitizer("FMDSDigitizer", "FMD SDigitizer")
229{
230 // Normal CTOR
f95a63c4 231 AliFMDDebug(1, (" processed"));
02a27b50 232
233 fRunLoader = AliRunLoader::GetRunLoader(); // Open(headerFile);
234 if (!fRunLoader)
235 Fatal("AliFMDSDigitizer", "cannot open session, header file '%s'",
236 headerFile);
237 AliLoader* loader = fRunLoader->GetLoader("FMDLoader");
238 if (!loader)
239 Fatal("AliFMDSDigitizer", "cannot find FMD loader in specified event");
240
241 // Add task to tasks folder
242 loader->PostSDigitizer(this);
243
244}
245
246//____________________________________________________________________
247AliFMDSDigitizer::~AliFMDSDigitizer()
248{
249 // Destructor
250 AliLoader* loader = fRunLoader->GetLoader("FMDLoader");
251 loader->CleanSDigitizer();
252}
253
254//____________________________________________________________________
255void
256AliFMDSDigitizer::Exec(Option_t*)
257{
258 // Get the output manager
259 if (!fRunLoader) {
260 Error("Exec", "Run loader is not set");
261 return;
262 }
263 if (!fRunLoader->GetAliRun()) fRunLoader->LoadgAlice();
264 if (!fRunLoader->TreeE()) fRunLoader->LoadHeader();
265
266 AliLoader* fmdLoader = fRunLoader->GetLoader("FMDLoader");
267 if (!fmdLoader) Fatal("Exec", "no FMD loader");
268
269 // Get the AliFMD object
270 AliFMD* fmd =
271 static_cast<AliFMD*>(fRunLoader->GetAliRun()->GetDetector("FMD"));
272 if (!fmd) {
273 AliError("Can not get FMD from gAlice");
274 return;
275 }
276
277 Int_t nEvents = Int_t(fRunLoader->TreeE()->GetEntries());
278 for (Int_t event = 0; event < nEvents; event++) {
f95a63c4 279 AliFMDDebug(1, (" Digitizing event number %d", event));
02a27b50 280 // Get the current loader
281 fRunLoader->GetEvent(event);
282
283 if (!fmdLoader->TreeS()) fmdLoader->MakeTree("S");
284 // Make a branch
285 fmd->MakeBranch("S");
286
287 // Cache contriutions
288 SumContributions(fmd);
289
290 // Digitize the event
291 DigitizeHits(fmd);
292
293 fmdLoader->TreeS()->Reset();
294 fmdLoader->TreeS()->Fill();
295 fmdLoader->WriteSDigits("OVERWRITE");
296 }
297}
298
299//____________________________________________________________________
300void
301AliFMDSDigitizer::AddDigit(AliFMD* fmd,
302 UShort_t detector,
303 Char_t ring,
304 UShort_t sector,
305 UShort_t strip,
306 Float_t edep,
307 UShort_t count1,
308 Short_t count2,
2aeec17d 309 Short_t count3,
310 Short_t count4) const
02a27b50 311{
312 // Add a summable digit
e7594bad 313 if (count1 == 0 && count1 === count2 && count2 == count3 && count3 == count4)
314 return;
02a27b50 315 fmd->AddSDigitByFields(detector, ring, sector, strip, edep,
2aeec17d 316 count1, count2, count3, count4);
02a27b50 317}
318
319
320
321//____________________________________________________________________
322//
323// EOF
324//
325
326
327
328