4347b38f |
1 | /************************************************************************** |
2 | * Copyright(c) 2004, ALICE Experiment at CERN, All rights reserved. * |
66d2ede1 |
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 | **************************************************************************/ |
4347b38f |
15 | /* $Id$ */ |
c2fc1258 |
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 |
02a27b50 |
20 | @ingroup FMD_sim |
c2fc1258 |
21 | */ |
4347b38f |
22 | ////////////////////////////////////////////////////////////////////////////// |
23 | // |
24 | // This class contains the procedures simulation ADC signal for the |
ef8e8623 |
25 | // Forward Multiplicity detector : SDigits->Digits |
4347b38f |
26 | // |
27 | // Digits consists of |
28 | // - Detector # |
29 | // - Ring ID |
30 | // - Sector # |
31 | // - Strip # |
32 | // - ADC count in this channel |
33 | // |
ef8e8623 |
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 | // |
4347b38f |
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 | // +-----------------+ +------------------+ |
ef8e8623 |
56 | // | |
57 | // +-------------------+ |
58 | // | AliFMDSSDigitizer | |
59 | // +-------------------+ |
4347b38f |
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 | // |
4347b38f |
87 | // |
e802be3e |
88 | // The shaping function of the VA1_ALICE is generally given by |
4347b38f |
89 | // |
e802be3e |
90 | // f(x) = A(1 - exp(-Bx)) |
4347b38f |
91 | // |
e802be3e |
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. |
4347b38f |
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 | |
e802be3e |
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 | |
56b1929b |
203 | #include <TTree.h> // ROOT_TTree |
ef8e8623 |
204 | #include <TFile.h> |
205 | #include "AliFMDDebug.h" // Better debug macros |
206 | #include "AliFMDDigitizer.h" // ALIFMDSSDIGITIZER_H |
e802be3e |
207 | #include "AliFMD.h" // ALIFMD_H |
ef8e8623 |
208 | #include "AliFMDSDigit.h" // ALIFMDDIGIT_H |
e802be3e |
209 | #include "AliFMDDigit.h" // ALIFMDDIGIT_H |
8f6ee336 |
210 | #include "AliFMDParameters.h" // ALIFMDPARAMETERS_H |
56b1929b |
211 | #include <AliRunDigitizer.h> // ALIRUNDIGITIZER_H |
212 | #include <AliRun.h> // ALIRUN_H |
213 | #include <AliLoader.h> // ALILOADER_H |
214 | #include <AliRunLoader.h> // ALIRUNLOADER_H |
4347b38f |
215 | |
4347b38f |
216 | //==================================================================== |
925e6570 |
217 | ClassImp(AliFMDDigitizer) |
ef8e8623 |
218 | #if 0 |
219 | ; |
220 | #endif |
66d2ede1 |
221 | |
4347b38f |
222 | //____________________________________________________________________ |
ef8e8623 |
223 | Bool_t |
224 | AliFMDDigitizer::Init() |
4347b38f |
225 | { |
ef8e8623 |
226 | // Initialisation |
227 | if (!AliFMDBaseDigitizer::Init()) return kFALSE; |
42f1b2f5 |
228 | |
ef8e8623 |
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 | } |
42f1b2f5 |
239 | } |
66d2ede1 |
240 | |
ef8e8623 |
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; |
4347b38f |
249 | } |
3d44ce66 |
250 | |
88cb7938 |
251 | |
4347b38f |
252 | //____________________________________________________________________ |
253 | void |
ef8e8623 |
254 | AliFMDDigitizer::Exec(Option_t*) |
4347b38f |
255 | { |
ef8e8623 |
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 | } |
faf80567 |
273 | if (!runLoader->GetAliRun()) runLoader->LoadgAlice(); |
ef8e8623 |
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 |
faf80567 |
342 | AliFMDDebug(3, ("Will now sum contributions from SDigits")); |
ef8e8623 |
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(); |
83ad576a |
369 | AliFMDDebug(5, ("Wrote %d bytes to digit tree", write)); |
ef8e8623 |
370 | |
371 | // Store the digits |
372 | StoreDigits(outFMD); |
4347b38f |
373 | } |
3d44ce66 |
374 | |
4347b38f |
375 | //____________________________________________________________________ |
376 | void |
ef8e8623 |
377 | AliFMDDigitizer::SumContributions(TBranch* sdigitsBranch) |
4347b38f |
378 | { |
ef8e8623 |
379 | // Sum energy deposited contributions from each sdigits in a cache |
380 | // (fEdep). |
83ad576a |
381 | AliFMDDebug(3, ("Runnin our version of SumContributions")); |
ef8e8623 |
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()); |
4347b38f |
388 | |
ef8e8623 |
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 (); |
83ad576a |
397 | AliFMDDebug(3, ("Got %5d SDigits", nsdigits)); |
ef8e8623 |
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)); |
faf80567 |
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))); |
ef8e8623 |
412 | |
413 | // Extract parameters |
414 | AddContribution(fmdSDigit->Detector(), |
415 | fmdSDigit->Ring(), |
416 | fmdSDigit->Sector(), |
417 | fmdSDigit->Strip(), |
83ad576a |
418 | fmdSDigit->Edep(), |
b2e6f0b0 |
419 | kTRUE, |
faf80567 |
420 | fmdSDigit->GetNTrack(), |
421 | fmdSDigit->GetTracks()); |
ef8e8623 |
422 | } // sdigit loop |
423 | } // event loop |
424 | |
425 | |
426 | AliFMDDebug(3, ("Size of cache: %d bytes, read %d bytes", |
427 | sizeof(fEdep), read)); |
4347b38f |
428 | } |
66d2ede1 |
429 | |
4347b38f |
430 | //____________________________________________________________________ |
431 | // |
432 | // EOF |
433 | // |
88cb7938 |
434 | |
435 | |
436 | |
66d2ede1 |
437 | |