1 /**************************************************************************
2 * Copyright(c) 2004, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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
22 //////////////////////////////////////////////////////////////////////////////
24 // This class contains the procedures simulation ADC signal for the
25 // Forward Multiplicity detector : Hits->Digits and Hits->SDigits
32 // - ADC count in this channel
39 // - Total energy deposited in the strip
40 // - ADC count in this channel
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.
46 // +---------------------+
47 // | AliFMDBaseDigitizer |
48 // +---------------------+
51 // +----------+---------+
53 // +-----------------+ +------------------+
54 // | AliFMDDigitizer | | AliFMDSDigitizer |
55 // +-----------------+ +------------------+
57 // These classes has several paramters:
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).
67 // The dymamic MIP range of the VA1_ALICE pre-amplifier chip
70 // The largest number plus one that can be stored in one
71 // channel in one time step in the ALTRO ADC chip.
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
84 // The shaping function of the VA1_ALICE is generally given by
86 // f(x) = A(1 - exp(-Bx))
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.
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.
95 // That results in the following algorithm:
98 // FOR charge IN pre-amp. charge train DO
99 // IF last < charge THEN
100 // f(t) = (charge - last) * (1 - exp(-B * t)) + last
102 // f(t) = (last - charge) * exp(-B * t) + charge)
104 // FOR i IN # samples DO
105 // adc_i = f(i / (# samples))
112 // pre-amp. charge train
113 // is a series of 128 charges read from the VA1_ALICE chip
116 // is the number of times the ALTRO ADC samples each of the 128
117 // charges from the pre-amp.
119 // Where Q is the total charge collected by the VA1_ALICE
120 // pre-amplifier. Q is then given by
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).
131 // The energy deposited per MIP is given by
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.
138 // The final ADC count is given by
142 // where P is the (randomized) pedestal (see MakePedestal)
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
148 // typedef AliFMDMap<std::pair<Float_t, UShort_t> > AliFMDEdepMap;
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.
160 // Latest changes by Christian Holm Christensen
162 //////////////////////////////////////////////////////////////////////////////
165 // | A(-1 + B + exp(-B))
166 // | f(x) dx = ------------------- = 1
170 // and B is the a parameter defined by the shaping time (fShapingTime).
172 // Solving the above equation, for A gives
175 // A = ----------------
178 // So, if we define the function g: [0,1] -> [0:1] by
181 // | Bu + exp(-Bu) - Bv - exp(-Bv)
182 // g(u,v) = | f(x) dx = -A -----------------------------
186 // we can evaluate the ALTRO sample of the VA1_ALICE pre-amp between
187 // any two times (u, v), by
190 // B Bu + exp(-Bu) - Bv - exp(-Bv)
191 // C = Q g(u,v) = - Q ---------------- -----------------------------
192 // -1 + B + exp(-B) B
194 // Bu + exp(-Bu) - Bv - exp(-Bv)
195 // = - Q -----------------------------
199 #include <TTree.h> // ROOT_TTree
200 //#include <TRandom.h> // ROOT_TRandom
201 #include <AliLog.h> // ALILOG_H
202 #include "AliFMDBaseDigitizer.h" // ALIFMDDIGITIZER_H
203 #include "AliFMD.h" // ALIFMD_H
204 #include "AliFMDGeometry.h" // ALIFMDGEOMETRY_H
205 #include "AliFMDDetector.h" // ALIFMDDETECTOR_H
206 #include "AliFMDRing.h" // ALIFMDRING_H
207 #include "AliFMDHit.h" // ALIFMDHIT_H
208 // #include "AliFMDDigit.h" // ALIFMDDIGIT_H
209 #include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
210 // #include <AliRunDigitizer.h> // ALIRUNDIGITIZER_H
211 //#include <AliRun.h> // ALIRUN_H
212 #include <AliLoader.h> // ALILOADER_H
213 #include <AliRunLoader.h> // ALIRUNLOADER_H
215 //====================================================================
216 ClassImp(AliFMDBaseDigitizer)
218 ; // This is here to keep Emacs for indenting the next line
221 //____________________________________________________________________
222 AliFMDBaseDigitizer::AliFMDBaseDigitizer()
225 // Default ctor - don't use it
228 //____________________________________________________________________
229 AliFMDBaseDigitizer::AliFMDBaseDigitizer(AliRunDigitizer* manager)
230 : AliDigitizer(manager, "AliFMDBaseDigitizer", "FMD Digitizer base class"),
232 fEdep(AliFMDMap::kMaxDetectors,
233 AliFMDMap::kMaxRings,
234 AliFMDMap::kMaxSectors,
235 AliFMDMap::kMaxStrips)
238 AliDebug(1," processed");
242 //____________________________________________________________________
243 AliFMDBaseDigitizer::AliFMDBaseDigitizer(const Char_t* name,
245 : AliDigitizer(name, title),
247 fEdep(AliFMDMap::kMaxDetectors,
248 AliFMDMap::kMaxRings,
249 AliFMDMap::kMaxSectors,
250 AliFMDMap::kMaxStrips)
253 AliDebug(1," processed");
257 //____________________________________________________________________
258 AliFMDBaseDigitizer::~AliFMDBaseDigitizer()
263 //____________________________________________________________________
265 AliFMDBaseDigitizer::Init()
268 AliFMDParameters::Instance()->Init();
273 //____________________________________________________________________
275 AliFMDBaseDigitizer::MakePedestal(UShort_t,
284 //____________________________________________________________________
286 AliFMDBaseDigitizer::SumContributions(AliFMD* fmd)
288 // Sum energy deposited contributions from each hit in a cache
291 Fatal("SumContributions", "no run loader");
293 // Clear array of deposited energies
296 // Get the FMD loader
297 AliLoader* inFMD = fRunLoader->GetLoader("FMDLoader");
299 inFMD->LoadHits("READ");
301 // Get the tree of hits
302 TTree* hitsTree = inFMD->TreeH();
305 inFMD->LoadHits("READ");
306 hitsTree = inFMD->TreeH();
309 // Get the FMD branch
310 TBranch* hitsBranch = hitsTree->GetBranch("FMD");
311 if (hitsBranch) fmd->SetHitsAddressBranch(hitsBranch);
312 else AliFatal("Branch FMD hit not found");
314 // Get a list of hits from the FMD manager
315 TClonesArray *fmdHits = fmd->Hits();
317 // Get number of entries in the tree
318 Int_t ntracks = Int_t(hitsTree->GetEntries());
320 AliFMDParameters* param = AliFMDParameters::Instance();
322 // Loop over the tracks in the
323 for (Int_t track = 0; track < ntracks; track++) {
324 // Read in entry number `track'
325 read += hitsBranch->GetEntry(track);
327 // Get the number of hits
328 Int_t nhits = fmdHits->GetEntries ();
329 for (Int_t hit = 0; hit < nhits; hit++) {
330 // Get the hit number `hit'
332 static_cast<AliFMDHit*>(fmdHits->UncheckedAt(hit));
334 // Extract parameters
335 UShort_t detector = fmdHit->Detector();
336 Char_t ring = fmdHit->Ring();
337 UShort_t sector = fmdHit->Sector();
338 UShort_t strip = fmdHit->Strip();
339 Float_t edep = fmdHit->Edep();
340 // UShort_t minstrip = param->GetMinStrip(detector, ring, sector, strip);
341 // UShort_t maxstrip = param->GetMaxStrip(detector, ring, sector, strip);
342 // Check if strip is `dead'
343 if (param->IsDead(detector, ring, sector, strip)) {
344 AliDebug(5, Form("FMD%d%c[%2d,%3d] is marked as dead",
345 detector, ring, sector, strip));
348 // Check if strip is out-side read-out range
349 // if (strip < minstrip || strip > maxstrip) {
350 // AliDebug(5, Form("FMD%d%c[%2d,%3d] is outside range [%3d,%3d]",
351 // detector,ring,sector,strip,minstrip,maxstrip));
355 // Give warning in case of double hit
356 if (fEdep(detector, ring, sector, strip).fEdep != 0)
357 AliDebug(5, Form("Double hit in %d%c(%d,%d)",
358 detector, ring, sector, strip));
360 // Sum energy deposition
361 fEdep(detector, ring, sector, strip).fEdep += edep;
362 fEdep(detector, ring, sector, strip).fN += 1;
363 // Add this to the energy deposited for this strip
366 AliDebug(1, Form("Size of cache: %d bytes, read %d bytes",
367 sizeof(fEdep), read));
370 //____________________________________________________________________
372 AliFMDBaseDigitizer::DigitizeHits(AliFMD* fmd) const
374 // For the stored energy contributions in the cache (fEdep), convert
375 // the energy signal to ADC counts, and store the created digit in
376 // the digits array (AliFMD::fDigits)
378 AliFMDGeometry* geometry = AliFMDGeometry::Instance();
381 for (UShort_t detector=1; detector <= 3; detector++) {
382 // Get pointer to subdetector
383 AliFMDDetector* det = geometry->GetDetector(detector);
385 for (UShort_t ringi = 0; ringi <= 1; ringi++) {
386 Char_t ring = ringi == 0 ? 'I' : 'O';
387 // Get pointer to Ring
388 AliFMDRing* r = det->GetRing(ring);
391 // Get number of sectors
392 UShort_t nSectors = UShort_t(360. / r->GetTheta());
393 // Loop over the number of sectors
394 for (UShort_t sector = 0; sector < nSectors; sector++) {
395 // Get number of strips
396 UShort_t nStrips = r->GetNStrips();
397 // Loop over the stips
399 for (UShort_t strip = 0; strip < nStrips; strip++) {
400 // Reset the counter array to the invalid value -1
402 // Reset the last `ADC' value when we've get to the end of a
403 // VA1_ALICE channel.
404 if (strip % 128 == 0) last = 0;
406 Float_t edep = fEdep(detector, ring, sector, strip).fEdep;
407 ConvertToCount(edep, last, detector, ring, sector, strip, counts);
409 AddDigit(fmd, detector, ring, sector, strip, edep,
410 UShort_t(counts[0]), Short_t(counts[1]),
413 // This checks if the digit created will give the `right'
414 // number of particles when reconstructed, using a naiive
415 // approach. It's here only as a quality check - nothing
417 CheckDigit(digit, fEdep(detector, ring, sector, strip).fN,
426 //____________________________________________________________________
428 AliFMDBaseDigitizer::ConvertToCount(Float_t edep,
434 TArrayI& counts) const
436 // Convert the total energy deposited to a (set of) ADC count(s).
440 // Energy_Deposited ALTRO_Channel_Size
441 // ADC = -------------------------- ------------------- + pedestal
442 // Energy_Deposition_Of_1_MIP VA1_ALICE_MIP_Range
444 // Energy_Deposited fAltroChannelSize
445 // = --------------------------------- ----------------- + pedestal
446 // 1.664 * Si_Thickness * Si_Density fVA1MipRange
449 // = Energy_Deposited * ConversionFactor + pedestal
451 // However, this is modified by the response function of the
452 // VA1_ALICE pre-amp. chip in case we are doing oversampling of the
455 // In that case, we get N=fSampleRate values of the ADC, and the
456 // `EnergyDeposited' is a function of which sample where are
457 // calculating the ADC for
459 // ADC_i = f(EnergyDeposited, i/N, Last) * ConversionFactor + pedestal
461 // where Last is the Energy deposited in the previous strip.
463 // Here, f is the shaping function of the VA1_ALICE. This is given
466 // | (E - l) * (1 - exp(-B * t) + l if E > l
468 // | (l - E) * exp(-B * t) + E otherwise
471 // = E + (l - E) * ext(-B * t)
473 AliFMDParameters* param = AliFMDParameters::Instance();
474 Float_t convF = 1/param->GetPulseGain(detector,ring,sector,strip);
475 UShort_t ped = MakePedestal(detector,ring,sector,strip);
476 UInt_t maxAdc = param->GetAltroChannelSize()-1;
477 UShort_t rate = param->GetSampleRate(detector,ring,sector,strip);
479 // In case we don't oversample, just return the end value.
481 counts[0] = UShort_t(TMath::Min(edep * convF + ped, Float_t(maxAdc)));
482 AliDebug(2, Form("FMD%d%c[%2d,%3d]: converting ELoss %f to ADC %d (%f)",
483 detector,ring,sector,strip,edep,counts[0],convF));
488 Float_t b = fShapingTime;
489 for (Ssiz_t i = 0; i < rate; i++) {
490 Float_t t = Float_t(i) / rate;
491 Float_t s = edep + (last - edep) * TMath::Exp(-b * t);
492 counts[i] = UShort_t(TMath::Min(s * convF + ped, Float_t(maxAdc)));
498 //____________________________________________________________________