]>
Commit | Line | Data |
---|---|---|
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 AliFMDDigitizer.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 : SDigits->Digits | |
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 | // +-------------------+ | |
58 | // | AliFMDSSDigitizer | | |
59 | // +-------------------+ | |
60 | // | |
61 | // These classes has several paramters: | |
62 | // | |
63 | // fPedestal | |
64 | // fPedestalWidth | |
65 | // (Only AliFMDDigitizer) | |
66 | // Mean and width of the pedestal. The pedestal is simulated | |
67 | // by a Guassian, but derived classes my override MakePedestal | |
68 | // to simulate it differently (or pick it up from a database). | |
69 | // | |
70 | // fVA1MipRange | |
71 | // The dymamic MIP range of the VA1_ALICE pre-amplifier chip | |
72 | // | |
73 | // fAltroChannelSize | |
74 | // The largest number plus one that can be stored in one | |
75 | // channel in one time step in the ALTRO ADC chip. | |
76 | // | |
77 | // fSampleRate | |
78 | // How many times the ALTRO ADC chip samples the VA1_ALICE | |
79 | // pre-amplifier signal. The VA1_ALICE chip is read-out at | |
80 | // 10MHz, while it's possible to drive the ALTRO chip at | |
81 | // 25MHz. That means, that the ALTRO chip can have time to | |
82 | // sample each VA1_ALICE signal up to 2 times. Although it's | |
83 | // not certain this feature will be used in the production, | |
84 | // we'd like have the option, and so it should be reflected in | |
85 | // the code. | |
86 | // | |
87 | // | |
88 | // The shaping function of the VA1_ALICE is generally given by | |
89 | // | |
90 | // f(x) = A(1 - exp(-Bx)) | |
91 | // | |
92 | // where A is the total charge collected in the pre-amp., and B is a | |
93 | // paramter that depends on the shaping time of the VA1_ALICE circut. | |
94 | // | |
95 | // When simulating the shaping function of the VA1_ALICe | |
96 | // pre-amp. chip, we have to take into account, that the shaping | |
97 | // function depends on the previous value of read from the pre-amp. | |
98 | // | |
99 | // That results in the following algorithm: | |
100 | // | |
101 | // last = 0; | |
102 | // FOR charge IN pre-amp. charge train DO | |
103 | // IF last < charge THEN | |
104 | // f(t) = (charge - last) * (1 - exp(-B * t)) + last | |
105 | // ELSE | |
106 | // f(t) = (last - charge) * exp(-B * t) + charge) | |
107 | // ENDIF | |
108 | // FOR i IN # samples DO | |
109 | // adc_i = f(i / (# samples)) | |
110 | // DONE | |
111 | // last = charge | |
112 | // DONE | |
113 | // | |
114 | // Here, | |
115 | // | |
116 | // pre-amp. charge train | |
117 | // is a series of 128 charges read from the VA1_ALICE chip | |
118 | // | |
119 | // # samples | |
120 | // is the number of times the ALTRO ADC samples each of the 128 | |
121 | // charges from the pre-amp. | |
122 | // | |
123 | // Where Q is the total charge collected by the VA1_ALICE | |
124 | // pre-amplifier. Q is then given by | |
125 | // | |
126 | // E S | |
127 | // Q = - - | |
128 | // e R | |
129 | // | |
130 | // where E is the total energy deposited in a silicon strip, R is the | |
131 | // dynamic range of the VA1_ALICE pre-amp (fVA1MipRange), e is the | |
132 | // energy deposited by a single MIP, and S ALTRO channel size in each | |
133 | // time step (fAltroChannelSize). | |
134 | // | |
135 | // The energy deposited per MIP is given by | |
136 | // | |
137 | // e = M * rho * w | |
138 | // | |
139 | // where M is the universal number 1.664, rho is the density of | |
140 | // silicon, and w is the depth of the silicon sensor. | |
141 | // | |
142 | // The final ADC count is given by | |
143 | // | |
144 | // C' = C + P | |
145 | // | |
146 | // where P is the (randomized) pedestal (see MakePedestal) | |
147 | // | |
148 | // This class uses the class template AliFMDMap<Type> to make an | |
149 | // internal cache of the energy deposted of the hits. The class | |
150 | // template is instantasized as | |
151 | // | |
152 | // typedef AliFMDMap<std::pair<Float_t, UShort_t> > AliFMDEdepMap; | |
153 | // | |
154 | // The first member of the values is the summed energy deposition in a | |
155 | // given strip, while the second member of the values is the number of | |
156 | // hits in a given strip. Using the second member, it's possible to | |
157 | // do some checks on just how many times a strip got hit, and what | |
158 | // kind of error we get in our reconstructed hits. Note, that this | |
159 | // information is currently not written to the digits tree. I think a | |
160 | // QA (Quality Assurance) digit tree is better suited for that task. | |
161 | // However, the information is there to be used in the future. | |
162 | // | |
163 | // | |
164 | // Latest changes by Christian Holm Christensen | |
165 | // | |
166 | ////////////////////////////////////////////////////////////////////////////// | |
167 | ||
168 | // /1 | |
169 | // | A(-1 + B + exp(-B)) | |
170 | // | f(x) dx = ------------------- = 1 | |
171 | // | B | |
172 | // / 0 | |
173 | // | |
174 | // and B is the a parameter defined by the shaping time (fShapingTime). | |
175 | // | |
176 | // Solving the above equation, for A gives | |
177 | // | |
178 | // B | |
179 | // A = ---------------- | |
180 | // -1 + B + exp(-B) | |
181 | // | |
182 | // So, if we define the function g: [0,1] -> [0:1] by | |
183 | // | |
184 | // / v | |
185 | // | Bu + exp(-Bu) - Bv - exp(-Bv) | |
186 | // g(u,v) = | f(x) dx = -A ----------------------------- | |
187 | // | B | |
188 | // / u | |
189 | // | |
190 | // we can evaluate the ALTRO sample of the VA1_ALICE pre-amp between | |
191 | // any two times (u, v), by | |
192 | // | |
193 | // | |
194 | // B Bu + exp(-Bu) - Bv - exp(-Bv) | |
195 | // C = Q g(u,v) = - Q ---------------- ----------------------------- | |
196 | // -1 + B + exp(-B) B | |
197 | // | |
198 | // Bu + exp(-Bu) - Bv - exp(-Bv) | |
199 | // = - Q ----------------------------- | |
200 | // -1 + B + exp(-B) | |
201 | // | |
202 | ||
203 | #include <TTree.h> // ROOT_TTree | |
204 | #include <TFile.h> | |
205 | #include "AliFMDDebug.h" // Better debug macros | |
206 | #include "AliFMDDigitizer.h" // ALIFMDSSDIGITIZER_H | |
207 | #include "AliFMD.h" // ALIFMD_H | |
208 | #include "AliFMDSDigit.h" // ALIFMDDIGIT_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 | |
215 | ||
216 | //==================================================================== | |
217 | ClassImp(AliFMDDigitizer) | |
218 | #if 0 | |
219 | ; | |
220 | #endif | |
221 | ||
222 | //____________________________________________________________________ | |
223 | Bool_t | |
224 | AliFMDDigitizer::Init() | |
225 | { | |
226 | // Initialisation | |
227 | if (!AliFMDBaseDigitizer::Init()) return kFALSE; | |
228 | ||
229 | #if 0 | |
230 | // Get the AliRun object | |
231 | AliRun* run = fRunLoader->GetAliRun(); | |
232 | if (!run) { | |
233 | AliWarning("Loading gAlice"); | |
234 | fRunLoader->LoadgAlice(); | |
235 | if (!run) { | |
236 | AliError("Can not get Run from Run Loader"); | |
237 | return kFALSE; | |
238 | } | |
239 | } | |
240 | ||
241 | // Get the AliFMD object | |
242 | fFMD = static_cast<AliFMD*>(run->GetDetector("FMD")); | |
243 | if (!fFMD) { | |
244 | AliError("Can not get FMD from gAlice"); | |
245 | return kFALSE; | |
246 | } | |
247 | #endif | |
248 | return kTRUE; | |
249 | } | |
250 | ||
251 | ||
252 | //____________________________________________________________________ | |
253 | void | |
254 | AliFMDDigitizer::Exec(Option_t*) | |
255 | { | |
256 | if (!fManager) { | |
257 | AliError("No digitisation manager defined"); | |
258 | return; | |
259 | } | |
260 | ||
261 | // Clear array of deposited energies | |
262 | fEdep.Reset(); | |
263 | ||
264 | AliRunLoader* runLoader = 0; | |
265 | if (!gAlice) { | |
266 | TString folderName(fManager->GetInputFolderName(0)); | |
267 | runLoader = AliRunLoader::GetRunLoader(folderName.Data()); | |
268 | if (!runLoader) { | |
269 | AliError(Form("Failed at getting run loader from %s", | |
270 | folderName.Data())); | |
271 | return; | |
272 | } | |
273 | if (!runLoader->GetAliRun()) runLoader->LoadgAlice(); | |
274 | runLoader->GetAliRun(); | |
275 | } | |
276 | if (!gAlice) { | |
277 | AliError("Can not get Run from Run Loader"); | |
278 | return; | |
279 | } | |
280 | ||
281 | // Get the AliFMD object | |
282 | fFMD = static_cast<AliFMD*>(gAlice->GetDetector("FMD")); | |
283 | if (!fFMD) { | |
284 | AliError("Can not get FMD from gAlice"); | |
285 | return; | |
286 | } | |
287 | ||
288 | ||
289 | // Loop over input files | |
290 | Int_t nFiles= fManager->GetNinputs(); | |
291 | AliFMDDebug(1, (" Digitizing event number %d, got %d inputs", | |
292 | fManager->GetOutputEventNr(), nFiles)); | |
293 | for (Int_t inputFile = 0; inputFile < nFiles; inputFile++) { | |
294 | AliFMDDebug(5, ("Now reading input # %d", inputFile)); | |
295 | // Get the current loader | |
296 | AliRunLoader* currentLoader = | |
297 | AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile)); | |
298 | if (!currentLoader) { | |
299 | Error("Exec", Form("no run loader for input file # %d", inputFile)); | |
300 | continue; | |
301 | } | |
302 | ||
303 | // Cache contriutions | |
304 | AliFMDDebug(5, ("Now summing the contributions from input # %d",inputFile)); | |
305 | ||
306 | // Get the FMD loader | |
307 | AliLoader* inFMD = currentLoader->GetLoader("FMDLoader"); | |
308 | // And load the summable digits | |
309 | inFMD->LoadSDigits("READ"); | |
310 | ||
311 | // Get the tree of summable digits | |
312 | TTree* sdigitsTree = inFMD->TreeS(); | |
313 | if (!sdigitsTree) { | |
314 | AliError("No sdigit tree from manager"); | |
315 | continue; | |
316 | } | |
317 | if (AliLog::GetDebugLevel("FMD","") >= 10) { | |
318 | TFile* file = sdigitsTree->GetCurrentFile(); | |
319 | if (!file) { | |
320 | AliWarning("Input tree has no file!"); | |
321 | } | |
322 | else { | |
323 | AliFMDDebug(10, ("Input tree file %s content:", file->GetName())); | |
324 | file->ls(); | |
325 | } | |
326 | // AliFMDDebug(5, ("Input tree %s file structure:", | |
327 | // sdigitsTree->GetName())); | |
328 | // sdigitsTree->Print(); | |
329 | } | |
330 | ||
331 | // Get the FMD branch | |
332 | TBranch* sdigitsBranch = sdigitsTree->GetBranch("FMD"); | |
333 | if (!sdigitsBranch) { | |
334 | AliError("Failed to get sdigit branch"); | |
335 | return; | |
336 | } | |
337 | ||
338 | // Set the branch addresses | |
339 | fFMD->SetTreeAddress(); | |
340 | ||
341 | // Sum contributions from the sdigits | |
342 | AliFMDDebug(3, ("Will now sum contributions from SDigits")); | |
343 | SumContributions(sdigitsBranch); | |
344 | ||
345 | // Unload the sdigits | |
346 | inFMD->UnloadSDigits(); | |
347 | } | |
348 | ||
349 | TString outFolder(fManager->GetOutputFolderName()); | |
350 | AliRunLoader* out = AliRunLoader::GetRunLoader(outFolder.Data()); | |
351 | AliLoader* outFMD = out->GetLoader("FMDLoader"); | |
352 | if (!outFMD) { | |
353 | AliError("Cannot get the FMDLoader output folder"); | |
354 | return; | |
355 | } | |
356 | TTree* outTree = MakeOutputTree(outFMD); | |
357 | if (!outTree) { | |
358 | AliError("Failed to get output tree"); | |
359 | return; | |
360 | } | |
361 | // Set the branch address | |
362 | fFMD->SetTreeAddress(); | |
363 | ||
364 | // And digitize the cached data | |
365 | DigitizeHits(); | |
366 | ||
367 | // Fill the tree | |
368 | Int_t write = outTree->Fill(); | |
369 | AliFMDDebug(5, ("Wrote %d bytes to digit tree", write)); | |
370 | ||
371 | // Store the digits | |
372 | StoreDigits(outFMD); | |
373 | } | |
374 | ||
375 | //____________________________________________________________________ | |
376 | void | |
377 | AliFMDDigitizer::SumContributions(TBranch* sdigitsBranch) | |
378 | { | |
379 | // Sum energy deposited contributions from each sdigits in a cache | |
380 | // (fEdep). | |
381 | AliFMDDebug(3, ("Runnin our version of SumContributions")); | |
382 | ||
383 | // Get a list of hits from the FMD manager | |
384 | TClonesArray *fmdSDigits = fFMD->SDigits(); | |
385 | ||
386 | // Get number of entries in the tree | |
387 | Int_t nevents = Int_t(sdigitsBranch->GetEntries()); | |
388 | ||
389 | Int_t read = 0; | |
390 | // Loop over the events in the | |
391 | for (Int_t event = 0; event < nevents; event++) { | |
392 | // Read in entry number `event' | |
393 | read += sdigitsBranch->GetEntry(event); | |
394 | ||
395 | // Get the number of sdigits | |
396 | Int_t nsdigits = fmdSDigits->GetEntries (); | |
397 | AliFMDDebug(3, ("Got %5d SDigits", nsdigits)); | |
398 | for (Int_t sdigit = 0; sdigit < nsdigits; sdigit++) { | |
399 | // Get the sdigit number `sdigit' | |
400 | AliFMDSDigit* fmdSDigit = | |
401 | static_cast<AliFMDSDigit*>(fmdSDigits->UncheckedAt(sdigit)); | |
402 | ||
403 | AliFMDDebug(5, ("Adding contribution of %d tracks", | |
404 | fmdSDigit->GetNTrack())); | |
405 | AliFMDDebug(15, ("Contrib from FMD%d%c[%2d,%3d] (%s) from track %d", | |
406 | fmdSDigit->Detector(), | |
407 | fmdSDigit->Ring(), | |
408 | fmdSDigit->Sector(), | |
409 | fmdSDigit->Strip(), | |
410 | fmdSDigit->GetName(), | |
411 | fmdSDigit->GetTrack(0))); | |
412 | ||
413 | // Extract parameters | |
414 | AddContribution(fmdSDigit->Detector(), | |
415 | fmdSDigit->Ring(), | |
416 | fmdSDigit->Sector(), | |
417 | fmdSDigit->Strip(), | |
418 | fmdSDigit->Edep(), | |
419 | kTRUE, | |
420 | fmdSDigit->GetNTrack(), | |
421 | fmdSDigit->GetTracks()); | |
422 | } // sdigit loop | |
423 | } // event loop | |
424 | ||
425 | ||
426 | AliFMDDebug(3, ("Size of cache: %d bytes, read %d bytes", | |
427 | sizeof(fEdep), read)); | |
428 | } | |
429 | ||
430 | //____________________________________________________________________ | |
431 | // | |
432 | // EOF | |
433 | // | |
434 | ||
435 | ||
436 | ||
437 |