]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDBaseDigitizer.cxx
Fixes for SDigit generation. First attempt at making SDigit->Digit
[u/mrichter/AliRoot.git] / FMD / AliFMDBaseDigitizer.cxx
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
199 #include <TMath.h>
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
217     
218 //====================================================================
219 ClassImp(AliFMDBaseDigitizer)
220 #if 0
221   ; // This is here to keep Emacs for indenting the next line
222 #endif
223
224 //____________________________________________________________________
225 AliFMDBaseDigitizer::AliFMDBaseDigitizer()  
226   : fRunLoader(0),
227     fEdep(AliFMDMap::kMaxDetectors, 
228           AliFMDMap::kMaxRings, 
229           AliFMDMap::kMaxSectors, 
230           AliFMDMap::kMaxStrips),
231     fShapingTime(6)
232 {
233   AliFMDDebug(1, ("Constructed"));
234   // Default ctor - don't use it
235 }
236
237 //____________________________________________________________________
238 AliFMDBaseDigitizer::AliFMDBaseDigitizer(AliRunDigitizer* manager) 
239   : AliDigitizer(manager, "AliFMDBaseDigitizer", "FMD Digitizer base class"), 
240     fRunLoader(0),
241     fEdep(AliFMDMap::kMaxDetectors, 
242           AliFMDMap::kMaxRings, 
243           AliFMDMap::kMaxSectors, 
244           AliFMDMap::kMaxStrips), 
245     fShapingTime(6)
246 {
247   // Normal CTOR
248   AliFMDDebug(1, ("Constructed"));
249   SetShapingTime();
250 }
251
252 //____________________________________________________________________
253 AliFMDBaseDigitizer::AliFMDBaseDigitizer(const Char_t* name, 
254                                          const Char_t* title) 
255   : AliDigitizer(name, title),
256     fRunLoader(0),
257     fEdep(AliFMDMap::kMaxDetectors, 
258           AliFMDMap::kMaxRings, 
259           AliFMDMap::kMaxSectors, 
260           AliFMDMap::kMaxStrips),
261     fShapingTime(6)
262 {
263   // Normal CTOR
264   AliFMDDebug(1, (" Constructed"));
265   SetShapingTime();
266 }
267
268 //____________________________________________________________________
269 AliFMDBaseDigitizer::~AliFMDBaseDigitizer()
270 {
271   // Destructor
272 }
273
274 //____________________________________________________________________
275 Bool_t 
276 AliFMDBaseDigitizer::Init()
277 {
278   // Initialization
279   AliFMDParameters::Instance()->Init();
280   if (AliLog::GetDebugLevel("FMD","") >= 10) 
281     AliFMDParameters::Instance()->Print("ALL");
282   return kTRUE;
283 }
284
285 //____________________________________________________________________
286 void
287 AliFMDBaseDigitizer::Exec(Option_t* /*option*/)
288 {
289   AliFMDDebug(1, ("Executing digitizer"));
290   AliFMD*    fmd = 0;
291   AliLoader* outFMD = 0;
292   if (!SetupLoaders(fmd, outFMD)) return;
293   if (!LoopOverInput(fmd)) return;
294
295   // Digitize the event 
296   DigitizeHits(fmd);
297   
298   // Make the output 
299   AliFMDDebug(5, ("Calling output tree"));
300   OutputTree(outFMD, fmd);  
301 }
302
303   
304 //____________________________________________________________________
305 Bool_t 
306 AliFMDBaseDigitizer::SetupLoaders(AliFMD*& fmd, AliLoader*& outFMD)
307 {
308   // Set-up input/output loaders. 
309   AliFMDDebug(5, ("Setting up run-loaders"));
310
311   // Get the output manager and the FMD output manager 
312   TString       outFolder(fManager->GetOutputFolderName());
313   AliRunLoader* out = AliRunLoader::GetRunLoader(outFolder.Data());
314   outFMD = out->GetLoader("FMDLoader");
315   if (!outFMD) { 
316     AliError("Cannot get the FMDLoader output folder");
317     return kFALSE;
318   }
319   
320   // Get the input loader 
321   TString inFolder(fManager->GetInputFolderName(0));
322   fRunLoader = AliRunLoader::GetRunLoader(inFolder.Data());
323   if (!fRunLoader) {
324     AliError("Can not find Run Loader for input stream 0");
325     return kFALSE;
326   }
327
328   // Get the AliRun object 
329   if (!fRunLoader->GetAliRun()) { 
330     AliWarning("Loading gAlice");
331     fRunLoader->LoadgAlice();
332   }
333   
334   // Get the AliRun object 
335   AliRun* run = fRunLoader->GetAliRun();
336   if (!run) { 
337     AliError("Can not get Run from Run Loader");
338     return kFALSE;
339   }
340
341   // Get the AliFMD object 
342   fmd = static_cast<AliFMD*>(run->GetDetector("FMD"));
343   if (!fmd) {
344     AliError("Can not get FMD from gAlice");
345     return kFALSE;
346   }
347   return kTRUE;
348 }
349
350 //____________________________________________________________________
351 Bool_t
352 AliFMDBaseDigitizer::LoopOverInput(AliFMD* fmd)
353 {
354   if (!fManager) { 
355     AliError("No digitisation manager defined");
356     return kFALSE;
357   }
358     
359   Int_t nFiles= fManager->GetNinputs();
360   AliFMDDebug(1, (" Digitizing event number %d, got %d inputs",
361                   fManager->GetOutputEventNr(), nFiles));
362   for (Int_t inputFile = 0; inputFile < nFiles; inputFile++) {
363     AliFMDDebug(5, ("Now reading input # %d", inputFile));
364     // Get the current loader 
365     fRunLoader = 
366       AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
367     if (!fRunLoader) { 
368       Error("Exec", Form("no run loader for input file # %d", inputFile));
369       return kFALSE;
370     }
371     // Cache contriutions 
372     AliFMDDebug(5, ("Now summing the contributions from input # %d",inputFile));
373     SumContributions(fmd);
374   }  
375   return kTRUE;
376 }
377
378
379 //____________________________________________________________________
380 UShort_t
381 AliFMDBaseDigitizer::MakePedestal(UShort_t, 
382                                   Char_t, 
383                                   UShort_t, 
384                                   UShort_t) const 
385
386   // Make a pedestal
387   return 0; 
388 }
389
390 //____________________________________________________________________
391 void
392 AliFMDBaseDigitizer::SumContributions(AliFMD* fmd) 
393 {
394   // Sum energy deposited contributions from each hit in a cache
395   // (fEdep).  
396   if (!fRunLoader) 
397     Fatal("SumContributions", "no run loader");
398   
399   // Clear array of deposited energies 
400   fEdep.Reset();
401   
402   // Get the FMD loader 
403   AliLoader* inFMD = fRunLoader->GetLoader("FMDLoader");
404   // And load the hits 
405   AliFMDDebug(5, ("Will read hits"));
406   inFMD->LoadHits("READ");
407   
408   // Get the tree of hits 
409   AliFMDDebug(5, ("Will get hit tree"));
410   TTree* hitsTree = inFMD->TreeH();
411   if (!hitsTree)  {
412     // Try again 
413     AliFMDDebug(5, ("First attempt failed, try again"));
414     inFMD->LoadHits("READ");
415     hitsTree = inFMD->TreeH();
416   }
417   
418   // Get the FMD branch 
419   AliFMDDebug(5, ("Will now get the branch"));
420   TBranch* hitsBranch = hitsTree->GetBranch("FMD");
421   if (hitsBranch) fmd->SetHitsAddressBranch(hitsBranch);
422   else            AliFatal("Branch FMD hit not found");
423   
424   // Get a list of hits from the FMD manager 
425   AliFMDDebug(5, ("Get array of FMD hits"));
426   TClonesArray *fmdHits = fmd->Hits();
427   
428   // Get number of entries in the tree 
429   AliFMDDebug(5, ("Get # of tracks"));
430   Int_t ntracks  = Int_t(hitsTree->GetEntries());
431   AliFMDDebug(5, ("We got %d tracks", ntracks));
432   
433   AliFMDParameters* param = AliFMDParameters::Instance();
434   Int_t read = 0;
435   // Loop over the tracks in the 
436   for (Int_t track = 0; track < ntracks; track++)  {
437     // Read in entry number `track' 
438     read += hitsBranch->GetEntry(track);
439     
440     // Get the number of hits 
441     Int_t nhits = fmdHits->GetEntries ();
442     for (Int_t hit = 0; hit < nhits; hit++) {
443       // Get the hit number `hit'
444       AliFMDHit* fmdHit = 
445         static_cast<AliFMDHit*>(fmdHits->UncheckedAt(hit));
446       
447       // Extract parameters 
448       UShort_t detector = fmdHit->Detector();
449       Char_t   ring     = fmdHit->Ring();
450       UShort_t sector   = fmdHit->Sector();
451       UShort_t strip    = fmdHit->Strip();
452       Float_t  edep     = fmdHit->Edep();
453       AliFMDDebug(10, ("Hit in FMD%d%c[%2d,%3d]=%f",
454                       detector, ring, sector, strip, edep));
455       // Check if strip is `dead' 
456       if (param->IsDead(detector, ring, sector, strip)) { 
457         AliFMDDebug(1, ("FMD%d%c[%2d,%3d] is marked as dead", 
458                          detector, ring, sector, strip));
459         continue;
460       }
461       // UShort_t minstrip = param->GetMinStrip(detector, ring, sector, strip);
462       // UShort_t maxstrip = param->GetMaxStrip(detector, ring, sector, strip);
463       // Check if strip is out-side read-out range 
464       // if (strip < minstrip || strip > maxstrip) {
465       //   AliFMDDebug(5, ("FMD%d%c[%2d,%3d] is outside range [%3d,%3d]", 
466       //                    detector,ring,sector,strip,minstrip,maxstrip));
467       //   continue;
468       // }
469         
470       // Give warning in case of double hit 
471       if (fEdep(detector, ring, sector, strip).fEdep != 0)
472         AliFMDDebug(5, ("Double hit in %d%c(%d,%d)", 
473                          detector, ring, sector, strip));
474       
475       // Sum energy deposition
476       fEdep(detector, ring, sector, strip).fEdep  += edep;
477       fEdep(detector, ring, sector, strip).fN     += 1;
478       // Add this to the energy deposited for this strip
479     }  // hit loop
480   } // track loop
481   AliFMDDebug(5, ("Size of cache: %d bytes, read %d bytes", 
482                    sizeof(fEdep), read));
483   inFMD->UnloadHits();
484 }
485
486 //____________________________________________________________________
487 void
488 AliFMDBaseDigitizer::DigitizeHits(AliFMD* fmd) const
489 {
490   // For the stored energy contributions in the cache (fEdep), convert
491   // the energy signal to ADC counts, and store the created digit in
492   // the digits array (AliFMD::fDigits)
493   //
494   AliFMDDebug(5, ("Will now digitize all the summed signals"));
495   AliFMDGeometry* geometry = AliFMDGeometry::Instance();
496   
497   TArrayI counts(4);
498   for (UShort_t detector=1; detector <= 3; detector++) {
499     AliFMDDebug(5, ("Processing hits in FMD%d", detector));
500     // Get pointer to subdetector 
501     AliFMDDetector* det = geometry->GetDetector(detector);
502     if (!det) continue;
503     for (UShort_t ringi = 0; ringi <= 1; ringi++) {
504       Char_t ring = ringi == 0 ? 'I' : 'O';
505       AliFMDDebug(5, (" Processing hits in FMD%d%c", detector,ring));
506       // Get pointer to Ring
507       AliFMDRing* r = det->GetRing(ring);
508       if (!r) continue;
509       
510       // Get number of sectors 
511       UShort_t nSectors = UShort_t(360. / r->GetTheta());
512       // Loop over the number of sectors 
513       for (UShort_t sector = 0; sector < nSectors; sector++) {
514         AliFMDDebug(5, ("  Processing hits in FMD%d%c[%2d]", 
515                         detector,ring,sector));
516         // Get number of strips 
517         UShort_t nStrips = r->GetNStrips();
518         // Loop over the stips 
519         Float_t last = 0;
520         for (UShort_t strip = 0; strip < nStrips; strip++) {
521           // Reset the counter array to the invalid value -1 
522           counts.Reset(-1);
523           // Reset the last `ADC' value when we've get to the end of a
524           // VA1_ALICE channel. 
525           if (strip % 128 == 0) last = 0;
526           
527           Float_t edep = fEdep(detector, ring, sector, strip).fEdep;
528           ConvertToCount(edep, last, detector, ring, sector, strip, counts);
529           last = edep;
530           
531           // The following line was introduced - wrongly - by Peter
532           // Hristov.  It _will_ break the digitisation and the
533           // following reconstruction.  The behviour of the
534           // digitisation models exactly the front-end as it should
535           // (no matter what memory concuption it may entail).  The
536           // check should be on zero suppression, since that's what
537           // models the front-end - if zero suppression is turned on
538           // in the front-end, then we can suppress empty digits -
539           // otherwise we shoud never do that.  Note, that the line
540           // affects _both_ normal digitisation and digitisation for
541           // summable digits, since the condition is on the energy
542           // deposition and not on the actual number of counts.  If
543           // this line should go anywhere, it should be in the
544           // possible overloaded AliFMDSDigitizer::AddDigit - not
545           // here. 
546           // 
547           //   if (edep<=0) continue;
548           AddDigit(fmd, detector, ring, sector, strip, edep, 
549                    UShort_t(counts[0]), Short_t(counts[1]), 
550                    Short_t(counts[2]), Short_t(counts[3]));
551           AliFMDDebug(10, ("   Adding digit in FMD%d%c[%2d,%3d]=%d", 
552                           detector,ring,sector,strip,counts[0]));
553 #if 0
554           // This checks if the digit created will give the `right'
555           // number of particles when reconstructed, using a naiive
556           // approach.  It's here only as a quality check - nothing
557           // else. 
558           CheckDigit(digit, fEdep(detector, ring, sector, strip).fN,
559                      counts);
560 #endif
561         } // Strip
562       } // Sector 
563     } // Ring 
564   } // Detector 
565 }
566
567 //____________________________________________________________________
568 void
569 AliFMDBaseDigitizer::ConvertToCount(Float_t   edep, 
570                                     Float_t   last,
571                                     UShort_t  detector, 
572                                     Char_t    ring, 
573                                     UShort_t  sector, 
574                                     UShort_t  strip,
575                                     TArrayI&  counts) const
576 {
577   // Convert the total energy deposited to a (set of) ADC count(s). 
578   // 
579   // This is done by 
580   // 
581   //               Energy_Deposited      ALTRO_Channel_Size
582   //    ADC = -------------------------- ------------------- + pedestal
583   //          Energy_Deposition_Of_1_MIP VA1_ALICE_MIP_Range
584   //
585   //               Energy_Deposited             fAltroChannelSize
586   //        = --------------------------------- ----------------- + pedestal 
587   //          1.664 * Si_Thickness * Si_Density   fVA1MipRange   
588   //          
589   // 
590   //        = Energy_Deposited * ConversionFactor + pedestal
591   // 
592   // However, this is modified by the response function of the
593   // VA1_ALICE pre-amp. chip in case we are doing oversampling of the
594   // VA1_ALICE output. 
595   // 
596   // In that case, we get N=fSampleRate values of the ADC, and the
597   // `EnergyDeposited' is a function of which sample where are
598   // calculating the ADC for 
599   // 
600   //     ADC_i = f(EnergyDeposited, i/N, Last) * ConversionFactor + pedestal 
601   // 
602   // where Last is the Energy deposited in the previous strip. 
603   // 
604   // Here, f is the shaping function of the VA1_ALICE.   This is given
605   // by 
606   //                       
607   //                    |   (E - l) * (1 - exp(-B * t) + l   if E > l
608   //       f(E, t, l) = <
609   //                    |   (l - E) * exp(-B * t) + E        otherwise
610   //                       
611   // 
612   //                  = E + (l - E) * ext(-B * t)
613   // 
614   AliFMDParameters* param = AliFMDParameters::Instance();
615   Float_t  convF          = 1./param->GetPulseGain(detector,ring,sector,strip);
616   Int_t    ped            = MakePedestal(detector,ring,sector,strip);
617   Int_t    maxAdc         = param->GetAltroChannelSize()-1;
618   if (maxAdc < 0) {
619     AliWarning(Form("Maximum ADC is %d < 0, forcing it to 1023", maxAdc));
620     maxAdc = 1023;
621   }
622   UShort_t rate           = param->GetSampleRate(detector,ring,sector,strip);
623   if (rate < 1 || rate > 4) rate = 1;
624   
625   // In case we don't oversample, just return the end value. 
626   if (rate == 1) {
627     Float_t    a = edep * convF + ped;
628     if (a < 0) a = 0;
629     counts[0]    = UShort_t(TMath::Min(a, Float_t(maxAdc)));
630     AliFMDDebug(10, ("FMD%d%c[%2d,%3d]: converting ELoss %f to "
631                      "ADC %4d (%f,%d)",
632                      detector,ring,sector,strip,edep,counts[0],convF,ped));
633     return;
634   }
635   
636   // Create a pedestal 
637   Float_t b = fShapingTime;
638   for (Ssiz_t i = 0; i < rate;  i++) {
639     Float_t t  = Float_t(i) / rate + 1./rate;
640     Float_t s  = edep + (last - edep) * TMath::Exp(-b * t);
641     Float_t a  = Int_t(s * convF + ped);
642     if (a < 0) a = 0;
643     counts[i]  = UShort_t(TMath::Min(a, Float_t(maxAdc)));
644   }
645 }
646
647
648
649 //____________________________________________________________________
650 //
651 // EOF
652 // 
653
654
655
656