]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDBaseDigitizer.cxx
for non-miscalibrated digits, set an ad-hoc conversion factor fAdC->fToT to have...
[u/mrichter/AliRoot.git] / FMD / AliFMDBaseDigitizer.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 AliFMDBaseDigitizer.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
090026bf 199#include <TMath.h>
02a27b50 200#include <TTree.h> // ROOT_TTree
201//#include <TRandom.h> // ROOT_TRandom
202#include <AliLog.h> // ALILOG_H
203#include "AliFMDBaseDigitizer.h" // ALIFMDDIGITIZER_H
204#include "AliFMD.h" // ALIFMD_H
205#include "AliFMDGeometry.h" // ALIFMDGEOMETRY_H
206#include "AliFMDDetector.h" // ALIFMDDETECTOR_H
207#include "AliFMDRing.h" // ALIFMDRING_H
208#include "AliFMDHit.h" // ALIFMDHIT_H
6169f936 209// #include "AliFMDDigit.h" // ALIFMDDIGIT_H
02a27b50 210#include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
6169f936 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(AliFMDBaseDigitizer)
218#if 0
219 ; // This is here to keep Emacs for indenting the next line
220#endif
221
222//____________________________________________________________________
223AliFMDBaseDigitizer::AliFMDBaseDigitizer()
b5ee4425 224 : fRunLoader(0),
225 fEdep(AliFMDMap::kMaxDetectors,
226 AliFMDMap::kMaxRings,
227 AliFMDMap::kMaxSectors,
228 AliFMDMap::kMaxStrips),
229 fShapingTime(0)
02a27b50 230{
231 // Default ctor - don't use it
232}
233
234//____________________________________________________________________
235AliFMDBaseDigitizer::AliFMDBaseDigitizer(AliRunDigitizer* manager)
236 : AliDigitizer(manager, "AliFMDBaseDigitizer", "FMD Digitizer base class"),
237 fRunLoader(0),
238 fEdep(AliFMDMap::kMaxDetectors,
239 AliFMDMap::kMaxRings,
240 AliFMDMap::kMaxSectors,
b5ee4425 241 AliFMDMap::kMaxStrips),
242 fShapingTime(0)
02a27b50 243{
244 // Normal CTOR
245 AliDebug(1," processed");
246 SetShapingTime();
247}
248
249//____________________________________________________________________
250AliFMDBaseDigitizer::AliFMDBaseDigitizer(const Char_t* name,
251 const Char_t* title)
252 : AliDigitizer(name, title),
253 fRunLoader(0),
254 fEdep(AliFMDMap::kMaxDetectors,
255 AliFMDMap::kMaxRings,
256 AliFMDMap::kMaxSectors,
257 AliFMDMap::kMaxStrips)
258{
259 // Normal CTOR
260 AliDebug(1," processed");
261 SetShapingTime();
262}
263
264//____________________________________________________________________
265AliFMDBaseDigitizer::~AliFMDBaseDigitizer()
266{
267 // Destructor
268}
269
270//____________________________________________________________________
271Bool_t
272AliFMDBaseDigitizer::Init()
273{
274 // Initialization
275 AliFMDParameters::Instance()->Init();
276 return kTRUE;
277}
278
279
280//____________________________________________________________________
281UShort_t
282AliFMDBaseDigitizer::MakePedestal(UShort_t,
283 Char_t,
284 UShort_t,
285 UShort_t) const
286{
287 // Make a pedestal
288 return 0;
289}
290
291//____________________________________________________________________
292void
293AliFMDBaseDigitizer::SumContributions(AliFMD* fmd)
294{
295 // Sum energy deposited contributions from each hit in a cache
296 // (fEdep).
297 if (!fRunLoader)
298 Fatal("SumContributions", "no run loader");
299
300 // Clear array of deposited energies
301 fEdep.Reset();
302
303 // Get the FMD loader
304 AliLoader* inFMD = fRunLoader->GetLoader("FMDLoader");
305 // And load the hits
306 inFMD->LoadHits("READ");
307
308 // Get the tree of hits
309 TTree* hitsTree = inFMD->TreeH();
310 if (!hitsTree) {
311 // Try again
312 inFMD->LoadHits("READ");
313 hitsTree = inFMD->TreeH();
314 }
315
316 // Get the FMD branch
317 TBranch* hitsBranch = hitsTree->GetBranch("FMD");
318 if (hitsBranch) fmd->SetHitsAddressBranch(hitsBranch);
319 else AliFatal("Branch FMD hit not found");
320
321 // Get a list of hits from the FMD manager
322 TClonesArray *fmdHits = fmd->Hits();
323
324 // Get number of entries in the tree
325 Int_t ntracks = Int_t(hitsTree->GetEntries());
326
327 AliFMDParameters* param = AliFMDParameters::Instance();
328 Int_t read = 0;
329 // Loop over the tracks in the
330 for (Int_t track = 0; track < ntracks; track++) {
331 // Read in entry number `track'
332 read += hitsBranch->GetEntry(track);
333
334 // Get the number of hits
335 Int_t nhits = fmdHits->GetEntries ();
336 for (Int_t hit = 0; hit < nhits; hit++) {
337 // Get the hit number `hit'
338 AliFMDHit* fmdHit =
339 static_cast<AliFMDHit*>(fmdHits->UncheckedAt(hit));
340
341 // Extract parameters
342 UShort_t detector = fmdHit->Detector();
343 Char_t ring = fmdHit->Ring();
344 UShort_t sector = fmdHit->Sector();
345 UShort_t strip = fmdHit->Strip();
346 Float_t edep = fmdHit->Edep();
15b17c89 347 // UShort_t minstrip = param->GetMinStrip(detector, ring, sector, strip);
348 // UShort_t maxstrip = param->GetMaxStrip(detector, ring, sector, strip);
02a27b50 349 // Check if strip is `dead'
350 if (param->IsDead(detector, ring, sector, strip)) {
351 AliDebug(5, Form("FMD%d%c[%2d,%3d] is marked as dead",
352 detector, ring, sector, strip));
353 continue;
354 }
355 // Check if strip is out-side read-out range
15b17c89 356 // if (strip < minstrip || strip > maxstrip) {
357 // AliDebug(5, Form("FMD%d%c[%2d,%3d] is outside range [%3d,%3d]",
358 // detector,ring,sector,strip,minstrip,maxstrip));
359 // continue;
360 // }
02a27b50 361
362 // Give warning in case of double hit
363 if (fEdep(detector, ring, sector, strip).fEdep != 0)
364 AliDebug(5, Form("Double hit in %d%c(%d,%d)",
365 detector, ring, sector, strip));
366
367 // Sum energy deposition
368 fEdep(detector, ring, sector, strip).fEdep += edep;
369 fEdep(detector, ring, sector, strip).fN += 1;
370 // Add this to the energy deposited for this strip
371 } // hit loop
372 } // track loop
373 AliDebug(1, Form("Size of cache: %d bytes, read %d bytes",
374 sizeof(fEdep), read));
375}
376
377//____________________________________________________________________
378void
379AliFMDBaseDigitizer::DigitizeHits(AliFMD* fmd) const
380{
381 // For the stored energy contributions in the cache (fEdep), convert
382 // the energy signal to ADC counts, and store the created digit in
383 // the digits array (AliFMD::fDigits)
384 //
385 AliFMDGeometry* geometry = AliFMDGeometry::Instance();
386
387 TArrayI counts(3);
388 for (UShort_t detector=1; detector <= 3; detector++) {
389 // Get pointer to subdetector
390 AliFMDDetector* det = geometry->GetDetector(detector);
391 if (!det) continue;
392 for (UShort_t ringi = 0; ringi <= 1; ringi++) {
393 Char_t ring = ringi == 0 ? 'I' : 'O';
394 // Get pointer to Ring
395 AliFMDRing* r = det->GetRing(ring);
396 if (!r) continue;
397
398 // Get number of sectors
399 UShort_t nSectors = UShort_t(360. / r->GetTheta());
400 // Loop over the number of sectors
401 for (UShort_t sector = 0; sector < nSectors; sector++) {
402 // Get number of strips
403 UShort_t nStrips = r->GetNStrips();
404 // Loop over the stips
405 Float_t last = 0;
406 for (UShort_t strip = 0; strip < nStrips; strip++) {
407 // Reset the counter array to the invalid value -1
408 counts.Reset(-1);
409 // Reset the last `ADC' value when we've get to the end of a
410 // VA1_ALICE channel.
411 if (strip % 128 == 0) last = 0;
412
413 Float_t edep = fEdep(detector, ring, sector, strip).fEdep;
414 ConvertToCount(edep, last, detector, ring, sector, strip, counts);
415 last = edep;
416 AddDigit(fmd, detector, ring, sector, strip, edep,
417 UShort_t(counts[0]), Short_t(counts[1]),
418 Short_t(counts[2]));
419#if 0
420 // This checks if the digit created will give the `right'
421 // number of particles when reconstructed, using a naiive
422 // approach. It's here only as a quality check - nothing
423 // else.
424 CheckDigit(digit, fEdep(detector, ring, sector, strip).fN,
425 counts);
426#endif
427 } // Strip
428 } // Sector
429 } // Ring
430 } // Detector
431}
432
433//____________________________________________________________________
434void
435AliFMDBaseDigitizer::ConvertToCount(Float_t edep,
436 Float_t last,
437 UShort_t detector,
438 Char_t ring,
439 UShort_t sector,
440 UShort_t strip,
441 TArrayI& counts) const
442{
443 // Convert the total energy deposited to a (set of) ADC count(s).
444 //
445 // This is done by
446 //
447 // Energy_Deposited ALTRO_Channel_Size
448 // ADC = -------------------------- ------------------- + pedestal
449 // Energy_Deposition_Of_1_MIP VA1_ALICE_MIP_Range
450 //
451 // Energy_Deposited fAltroChannelSize
452 // = --------------------------------- ----------------- + pedestal
453 // 1.664 * Si_Thickness * Si_Density fVA1MipRange
454 //
455 //
456 // = Energy_Deposited * ConversionFactor + pedestal
457 //
458 // However, this is modified by the response function of the
459 // VA1_ALICE pre-amp. chip in case we are doing oversampling of the
460 // VA1_ALICE output.
461 //
462 // In that case, we get N=fSampleRate values of the ADC, and the
463 // `EnergyDeposited' is a function of which sample where are
464 // calculating the ADC for
465 //
466 // ADC_i = f(EnergyDeposited, i/N, Last) * ConversionFactor + pedestal
467 //
468 // where Last is the Energy deposited in the previous strip.
469 //
470 // Here, f is the shaping function of the VA1_ALICE. This is given
471 // by
472 //
473 // | (E - l) * (1 - exp(-B * t) + l if E > l
474 // f(E, t, l) = <
475 // | (l - E) * exp(-B * t) + E otherwise
476 //
477 //
478 // = E + (l - E) * ext(-B * t)
479 //
480 AliFMDParameters* param = AliFMDParameters::Instance();
a9579262 481 Float_t convF = 1./param->GetPulseGain(detector,ring,sector,strip);
482 Int_t ped = MakePedestal(detector,ring,sector,strip);
483 Int_t maxAdc = param->GetAltroChannelSize()-1;
484 if (maxAdc < 0) {
485 AliWarning(Form("Maximum ADC is %d < 0, forcing it to 1023", maxAdc));
486 maxAdc = 1023;
487 }
02a27b50 488 UShort_t rate = param->GetSampleRate(detector,ring,sector,strip);
a9579262 489 if (rate < 1 || rate > 3) rate = 1;
02a27b50 490
491 // In case we don't oversample, just return the end value.
492 if (rate == 1) {
a9579262 493 Float_t a = edep * convF + ped;
494 if (a < 0) a = 0;
495 counts[0] = UShort_t(TMath::Min(a, Float_t(maxAdc)));
496 AliDebug(2, Form("FMD%d%c[%2d,%3d]: converting ELoss %f to "
497 "ADC %4d (%f,%d)",
498 detector,ring,sector,strip,edep,counts[0],convF,ped));
02a27b50 499 return;
500 }
501
502 // Create a pedestal
503 Float_t b = fShapingTime;
504 for (Ssiz_t i = 0; i < rate; i++) {
a9579262 505 Float_t t = Float_t(i) / rate;
506 Float_t s = edep + (last - edep) * TMath::Exp(-b * t);
507 Float_t a = Int_t(s * convF + ped);
508 if (a < 0) a = 0;
509 counts[i] = UShort_t(TMath::Min(a, Float_t(maxAdc)));
02a27b50 510 }
511}
512
513
514
515//____________________________________________________________________
516//
517// EOF
518//
519
520
521
522