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 -----------------------------
200 #include <TTree.h> // ROOT_TTree
201 //#include <TRandom.h> // ROOT_TRandom
202 // #include <AliLog.h> // ALILOG_H
203 #include "AliFMDDebug.h" // Better debug macros
204 #include "AliFMDBaseDigitizer.h" // ALIFMDDIGITIZER_H
205 #include "AliFMD.h" // ALIFMD_H
206 #include "AliFMDGeometry.h" // ALIFMDGEOMETRY_H
207 #include "AliFMDDetector.h" // ALIFMDDETECTOR_H
208 #include "AliFMDRing.h" // ALIFMDRING_H
209 #include "AliFMDHit.h" // ALIFMDHIT_H
210 // #include "AliFMDDigit.h" // ALIFMDDIGIT_H
211 #include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
212 // #include <AliRunDigitizer.h> // ALIRUNDIGITIZER_H
213 //#include <AliRun.h> // ALIRUN_H
214 #include <AliLoader.h> // ALILOADER_H
215 #include <AliRun.h> // ALILOADER_H
216 #include <AliRunLoader.h> // ALIRUNLOADER_H
219 //====================================================================
220 ClassImp(AliFMDBaseDigitizer)
222 ; // This is here to keep Emacs for indenting the next line
225 //____________________________________________________________________
226 AliFMDBaseDigitizer::AliFMDBaseDigitizer()
229 fEdep(AliFMDMap::kMaxDetectors,
230 AliFMDMap::kMaxRings,
231 AliFMDMap::kMaxSectors,
232 AliFMDMap::kMaxStrips),
235 AliFMDDebug(1, ("Constructed"));
236 // Default ctor - don't use it
239 //____________________________________________________________________
240 AliFMDBaseDigitizer::AliFMDBaseDigitizer(AliRunDigitizer* manager)
241 : AliDigitizer(manager, "AliFMDBaseDigitizer", "FMD Digitizer base class"),
244 fEdep(AliFMDMap::kMaxDetectors,
245 AliFMDMap::kMaxRings,
246 AliFMDMap::kMaxSectors,
247 AliFMDMap::kMaxStrips),
251 AliFMDDebug(1, ("Constructed"));
255 //____________________________________________________________________
256 AliFMDBaseDigitizer::AliFMDBaseDigitizer(const Char_t* name,
258 : AliDigitizer(name, title),
261 fEdep(AliFMDMap::kMaxDetectors,
262 AliFMDMap::kMaxRings,
263 AliFMDMap::kMaxSectors,
264 AliFMDMap::kMaxStrips),
268 AliFMDDebug(1, (" Constructed"));
272 //____________________________________________________________________
273 AliFMDBaseDigitizer::~AliFMDBaseDigitizer()
278 //____________________________________________________________________
280 AliFMDBaseDigitizer::Init()
282 // Initialization. Get a pointer to the parameter manager, and
284 AliFMDParameters::Instance()->Init();
285 if (AliLog::GetDebugLevel("FMD","") >= 15)
286 AliFMDParameters::Instance()->Print("");
290 //____________________________________________________________________
292 AliFMDBaseDigitizer::MakePedestal(UShort_t detector,
295 UShort_t strip) const
297 // Make a pedestal. The pedestal value is drawn from a Gaussian
298 // distribution. The mean of the distribution is the measured
299 // pedestal, and the width is the measured noise.
300 AliFMDParameters* param =AliFMDParameters::Instance();
301 Float_t mean =param->GetPedestal(detector,ring,sector,strip);
302 Float_t width =param->GetPedestalWidth(detector,ring,sector,strip);
303 return UShort_t(TMath::Max(gRandom->Gaus(mean, width), 0.));
306 //____________________________________________________________________
308 AliFMDBaseDigitizer::AddContribution(UShort_t detector,
314 // Add edep contribution from (detector,ring,sector,strip) to cache
315 AliFMDParameters* param = AliFMDParameters::Instance();
317 // Check if strip is `dead'
318 if (param->IsDead(detector, ring, sector, strip)) {
319 AliFMDDebug(5, ("FMD%d%c[%2d,%3d] is marked as dead",
320 detector, ring, sector, strip));
323 // Check if strip is out-side read-out range
324 // if (strip < minstrip || strip > maxstrip) {
325 // AliFMDDebug(5, ("FMD%d%c[%2d,%3d] is outside range [%3d,%3d]",
326 // detector,ring,sector,strip,minstrip,maxstrip));
330 // Give warning in case of double sdigit
331 if (fEdep(detector, ring, sector, strip).fEdep != 0)
332 AliFMDDebug(5, ("Double digit in %d%c(%d,%d)",
333 detector, ring, sector, strip));
335 // Sum energy deposition
336 fEdep(detector, ring, sector, strip).fEdep += edep;
337 fEdep(detector, ring, sector, strip).fN += 1;
340 //____________________________________________________________________
342 AliFMDBaseDigitizer::DigitizeHits() const
344 // For the stored energy contributions in the cache (fEdep), convert
345 // the energy signal to ADC counts, and store the created digit in
346 // the digits array (AliFMD::fDigits)
348 AliFMDDebug(5, ("Will now digitize all the summed signals"));
349 AliFMDGeometry* geometry = AliFMDGeometry::Instance();
352 for (UShort_t detector=1; detector <= 3; detector++) {
353 AliFMDDebug(10, ("Processing hits in FMD%d", detector));
354 // Get pointer to subdetector
355 AliFMDDetector* det = geometry->GetDetector(detector);
357 for (UShort_t ringi = 0; ringi <= 1; ringi++) {
358 Char_t ring = ringi == 0 ? 'I' : 'O';
359 AliFMDDebug(10, (" Processing hits in FMD%d%c", detector,ring));
360 // Get pointer to Ring
361 AliFMDRing* r = det->GetRing(ring);
364 // Get number of sectors
365 UShort_t nSectors = UShort_t(360. / r->GetTheta());
366 // Loop over the number of sectors
367 for (UShort_t sector = 0; sector < nSectors; sector++) {
368 AliFMDDebug(10, (" Processing hits in FMD%d%c[%2d]",
369 detector,ring,sector));
370 // Get number of strips
371 UShort_t nStrips = r->GetNStrips();
372 // Loop over the stips
374 for (UShort_t strip = 0; strip < nStrips; strip++) {
375 // Reset the counter array to the invalid value -1
377 // Reset the last `ADC' value when we've get to the end of a
378 // VA1_ALICE channel.
379 if (strip % 128 == 0) last = 0;
381 Float_t edep = fEdep(detector, ring, sector, strip).fEdep;
382 ConvertToCount(edep, last, detector, ring, sector, strip, counts);
385 // The following line was introduced - wrongly - by Peter
386 // Hristov. It _will_ break the digitisation and the
387 // following reconstruction. The behviour of the
388 // digitisation models exactly the front-end as it should
389 // (no matter what memory concuption it may entail). The
390 // check should be on zero suppression, since that's what
391 // models the front-end - if zero suppression is turned on
392 // in the front-end, then we can suppress empty digits -
393 // otherwise we shoud never do that. Note, that the line
394 // affects _both_ normal digitisation and digitisation for
395 // summable digits, since the condition is on the energy
396 // deposition and not on the actual number of counts. If
397 // this line should go anywhere, it should be in the
398 // possible overloaded AliFMDSDigitizer::AddDigit - not
401 // if (edep<=0) continue;
402 AddDigit(detector, ring, sector, strip, edep,
403 UShort_t(counts[0]), Short_t(counts[1]),
404 Short_t(counts[2]), Short_t(counts[3]));
405 AliFMDDebug(15, (" Adding digit in FMD%d%c[%2d,%3d]=%d",
406 detector,ring,sector,strip,counts[0]));
408 // This checks if the digit created will give the `right'
409 // number of particles when reconstructed, using a naiive
410 // approach. It's here only as a quality check - nothing
412 CheckDigit(digit, fEdep(detector, ring, sector, strip).fN,
421 //____________________________________________________________________
423 AliFMDBaseDigitizer::ConvertToCount(Float_t edep,
429 TArrayI& counts) const
431 // Convert the total energy deposited to a (set of) ADC count(s).
435 // Energy_Deposited ALTRO_Channel_Size
436 // ADC = -------------------------- ------------------- + pedestal
437 // Energy_Deposition_Of_1_MIP VA1_ALICE_MIP_Range
439 // Energy_Deposited fAltroChannelSize
440 // = --------------------------------- ----------------- + pedestal
441 // 1.664 * Si_Thickness * Si_Density fVA1MipRange
444 // = Energy_Deposited * ConversionFactor + pedestal
446 // However, this is modified by the response function of the
447 // VA1_ALICE pre-amp. chip in case we are doing oversampling of the
450 // In that case, we get N=fSampleRate values of the ADC, and the
451 // `EnergyDeposited' is a function of which sample where are
452 // calculating the ADC for
454 // ADC_i = f(EnergyDeposited, i/N, Last) * ConversionFactor + pedestal
456 // where Last is the Energy deposited in the previous strip.
458 // Here, f is the shaping function of the VA1_ALICE. This is given
461 // | (E - l) * (1 - exp(-B * t) + l if E > l
463 // | (l - E) * exp(-B * t) + E otherwise
466 // = E + (l - E) * ext(-B * t)
468 AliFMDParameters* param = AliFMDParameters::Instance();
469 Float_t convF = param->GetDACPerMIP()*param->GetPulseGain(detector,ring,sector,strip);
470 Int_t ped = MakePedestal(detector,ring,sector,strip);
471 Int_t maxAdc = param->GetAltroChannelSize()-1;
473 AliWarning(Form("Maximum ADC is %d < 0, forcing it to 1023", maxAdc));
476 UShort_t rate = param->GetSampleRate(detector,ring,sector,strip);
477 AliFMDDebug(15, ("Sample rate for FMD%d%c[%2d,%3d] = %d",
478 detector, ring, sector, strip, rate));
479 if (rate < 1 || rate > 4) {
480 AliWarning(Form("Invalid sample rate for for FMD%d%c[%2d,%3d] = %d",
481 detector, ring, sector, strip, rate));
485 // In case we don't oversample, just return the end value.
487 Float_t a = edep * convF + ped;
489 counts[0] = UShort_t(TMath::Min(a, Float_t(maxAdc)));
490 AliFMDDebug(15, ("FMD%d%c[%2d,%3d]: converting ELoss %f to "
492 detector,ring,sector,strip,edep,counts[0],convF,ped));
497 Float_t b = fShapingTime;
498 for (Ssiz_t i = 0; i < rate; i++) {
499 Float_t t = Float_t(i) / rate + 1./rate;
500 Float_t s = edep + (last - edep) * TMath::Exp(-b * t);
501 Float_t a = Int_t(s * convF + ped);
503 counts[i] = UShort_t(TMath::Min(a, Float_t(maxAdc)));
507 //____________________________________________________________________
509 AliFMDBaseDigitizer::AddDigit(UShort_t detector,
517 Short_t count4) const
519 // Add a digit or summable digit
521 fFMD->AddDigitByFields(detector, ring, sector, strip,
522 count1, count2, count3, count4);
525 //____________________________________________________________________
527 AliFMDBaseDigitizer::MakeOutputTree(AliLoader* loader)
529 // Create output tree using loader. If the passed loader differs
530 // from the currently set loader in the FMD object, reset the FMD
531 // loader to be the passed loader. This is for the cases wher the
532 // output is different from the output.
533 AliFMDDebug(5, ("Making digits tree"));
534 loader->LoadDigits("UPDATE"); // "RECREATE");
535 TTree* out = loader->TreeD();
536 if (!out) loader->MakeTree("D");
537 out = loader->TreeD();
540 if (loader != fFMD->GetLoader())
541 fFMD->SetLoader(loader);
542 fFMD->MakeBranch("D");
547 //____________________________________________________________________
549 AliFMDBaseDigitizer::StoreDigits(AliLoader* loader)
551 // Write the digits to disk
552 AliFMDDebug(5, ("Storing %d digits", fFMD->Digits()->GetEntries()));
553 loader->WriteDigits("OVERWRITE");
554 loader->UnloadDigits();
555 // Reset the digits in the AliFMD object
559 //____________________________________________________________________