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 AliFMDDigitizer.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 "AliFMDDebug.h" // Better debug macros
203 #include "AliFMDDigitizer.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
209 #include "AliFMDDigit.h" // ALIFMDDIGIT_H
210 #include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
211 #include <AliRunDigitizer.h> // ALIRUNDIGITIZER_H
212 #include <AliRun.h> // ALIRUN_H
213 #include <AliLoader.h> // ALILOADER_H
214 #include <AliRunLoader.h> // ALIRUNLOADER_H
216 //====================================================================
217 ClassImp(AliFMDDigitizer)
219 //____________________________________________________________________
220 AliFMDDigitizer::AliFMDDigitizer()
221 : AliFMDBaseDigitizer()
223 // Default ctor - don't use it
226 //____________________________________________________________________
227 AliFMDDigitizer::AliFMDDigitizer(AliRunDigitizer* manager)
228 : AliFMDBaseDigitizer(manager)
231 AliFMDDebug(1, (" processed"));
234 //____________________________________________________________________
236 AliFMDDigitizer::Exec(Option_t*)
238 // Get the output manager
239 TString outFolder(fManager->GetOutputFolderName());
241 AliRunLoader::GetRunLoader(outFolder.Data());
242 // Get the FMD output manager
243 AliLoader* outFMD = out->GetLoader("FMDLoader");
245 // Get the input loader
246 TString inFolder(fManager->GetInputFolderName(0));
248 AliRunLoader::GetRunLoader(inFolder.Data());
250 AliError("Can not find Run Loader for input stream 0");
253 // Get the AliRun object
254 if (!fRunLoader->GetAliRun()) fRunLoader->LoadgAlice();
256 // Get the AliFMD object
258 static_cast<AliFMD*>(fRunLoader->GetAliRun()->GetDetector("FMD"));
260 AliError("Can not get FMD from gAlice");
264 Int_t nFiles= fManager->GetNinputs();
265 for (Int_t inputFile = 0; inputFile < nFiles; inputFile++) {
266 AliFMDDebug(1, (" Digitizing event number %d",
267 fManager->GetOutputEventNr()));
268 // Get the current loader
270 AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
271 if (!fRunLoader) Fatal("Exec", "no run loader");
272 // Cache contriutions
273 SumContributions(fmd);
275 // Digitize the event
278 // Load digits from the tree
279 outFMD->LoadDigits("update");
280 // Get the tree of digits
281 TTree* digitTree = outFMD->TreeD();
283 outFMD->MakeTree("D");
284 digitTree = outFMD->TreeD();
287 // Make a branch in the tree
288 TClonesArray* digits = fmd->Digits();
289 fmd->MakeBranchInTree(digitTree, fmd->GetName(), &(digits), 4000, 0);
290 // TBranch* digitBranch = digitTree->GetBranch(fmd->GetName());
293 write = digitTree->Fill();
294 AliFMDDebug(1, ("Wrote %d bytes to digit tree", write));
296 // Write the digits to disk
297 outFMD->WriteDigits("OVERWRITE");
298 outFMD->UnloadHits();
299 outFMD->UnloadDigits();
301 // Reset the digits in the AliFMD object
306 //____________________________________________________________________
308 AliFMDDigitizer::MakePedestal(UShort_t detector,
311 UShort_t strip) const
314 AliFMDParameters* param =AliFMDParameters::Instance();
315 Float_t mean =param->GetPedestal(detector,ring,sector,strip);
316 Float_t width =param->GetPedestalWidth(detector,ring,sector,strip);
317 return UShort_t(TMath::Max(gRandom->Gaus(mean, width), 0.));
320 //____________________________________________________________________
322 AliFMDDigitizer::AddDigit(AliFMD* fmd,
331 Short_t count4) const
334 fmd->AddDigitByFields(detector, ring, sector, strip,
335 count1, count2, count3, count4);
338 //____________________________________________________________________
340 AliFMDDigitizer::CheckDigit(AliFMDDigit* digit,
342 const TArrayI& counts)
344 // Check that digit is consistent
345 AliFMDParameters* param = AliFMDParameters::Instance();
346 UShort_t det = digit->Detector();
347 Char_t ring = digit->Ring();
348 UShort_t sec = digit->Sector();
349 UShort_t str = digit->Strip();
350 Float_t mean = param->GetPedestal(det,ring,sec,str);
351 Float_t width = param->GetPedestalWidth(det,ring,sec,str);
352 UShort_t range = param->GetVA1MipRange();
353 UShort_t size = param->GetAltroChannelSize();
354 Int_t integral = counts[0];
355 if (counts[1] >= 0) integral += counts[1];
356 if (counts[2] >= 0) integral += counts[2];
357 if (counts[3] >= 0) integral += counts[3];
358 integral -= Int_t(mean + 2 * width);
359 if (integral < 0) integral = 0;
361 Float_t convF = Float_t(range) / size;
362 Float_t mips = integral * convF;
363 if (mips > Float_t(nhits) + .5 || mips < Float_t(nhits) - .5)
364 Warning("CheckDigit", "Digit -> %4.2f MIPS != %d +/- .5 hits",
368 //____________________________________________________________________