]>
Commit | Line | Data |
---|---|---|
1 | /************************************************************************** | |
2 | * Copyright(c) 1998-1999, 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 | ||
16 | /* $Id$ */ | |
17 | ||
18 | //////////////////////////////////////////////////////////////////////////// | |
19 | // // | |
20 | // Creates and handles digits from TRD hits // | |
21 | // // | |
22 | // Authors: C. Blume (blume@ikf.uni-frankfurt.de) // | |
23 | // C. Lippmann // | |
24 | // B. Vulpescu // | |
25 | // // | |
26 | // The following effects are included: // | |
27 | // - Diffusion // | |
28 | // - ExB effects // | |
29 | // - Gas gain including fluctuations // | |
30 | // - Pad-response (simple Gaussian approximation) // | |
31 | // - Time-response // | |
32 | // - Electronics noise // | |
33 | // - Electronics gain // | |
34 | // - Digitization // | |
35 | // - Zero suppression // | |
36 | // // | |
37 | //////////////////////////////////////////////////////////////////////////// | |
38 | ||
39 | #include <TGeoManager.h> | |
40 | #include <TList.h> | |
41 | #include <TMath.h> | |
42 | #include <TRandom.h> | |
43 | #include <TTree.h> | |
44 | ||
45 | #include "AliRun.h" | |
46 | #include "AliMC.h" | |
47 | #include "AliRunLoader.h" | |
48 | #include "AliLoader.h" | |
49 | #include "AliConfig.h" | |
50 | #include "AliRunDigitizer.h" | |
51 | #include "AliRunLoader.h" | |
52 | #include "AliLoader.h" | |
53 | #include "AliLog.h" | |
54 | ||
55 | #include "AliTRD.h" | |
56 | #include "AliTRDhit.h" | |
57 | #include "AliTRDdigitizer.h" | |
58 | #include "AliTRDarrayDictionary.h" | |
59 | #include "AliTRDarrayADC.h" | |
60 | #include "AliTRDarraySignal.h" | |
61 | #include "AliTRDdigitsManager.h" | |
62 | #include "AliTRDgeometry.h" | |
63 | #include "AliTRDpadPlane.h" | |
64 | #include "AliTRDcalibDB.h" | |
65 | #include "AliTRDSimParam.h" | |
66 | #include "AliTRDCommonParam.h" | |
67 | #include "AliTRDfeeParam.h" | |
68 | #include "AliTRDmcmSim.h" | |
69 | #include "AliTRDdigitsParam.h" | |
70 | ||
71 | #include "Cal/AliTRDCalROC.h" | |
72 | #include "Cal/AliTRDCalDet.h" | |
73 | ||
74 | ClassImp(AliTRDdigitizer) | |
75 | ||
76 | //_____________________________________________________________________________ | |
77 | AliTRDdigitizer::AliTRDdigitizer() | |
78 | :AliDigitizer() | |
79 | ,fRunLoader(0) | |
80 | ,fDigitsManager(0) | |
81 | ,fSDigitsManager(0) | |
82 | ,fSDigitsManagerList(0) | |
83 | ,fTRD(0) | |
84 | ,fGeo(0) | |
85 | ,fEvent(0) | |
86 | ,fMasks(0) | |
87 | ,fCompress(kTRUE) | |
88 | ,fSDigits(kFALSE) | |
89 | ,fMergeSignalOnly(kFALSE) | |
90 | { | |
91 | // | |
92 | // AliTRDdigitizer default constructor | |
93 | // | |
94 | ||
95 | } | |
96 | ||
97 | //_____________________________________________________________________________ | |
98 | AliTRDdigitizer::AliTRDdigitizer(const Text_t *name, const Text_t *title) | |
99 | :AliDigitizer(name,title) | |
100 | ,fRunLoader(0) | |
101 | ,fDigitsManager(0) | |
102 | ,fSDigitsManager(0) | |
103 | ,fSDigitsManagerList(0) | |
104 | ,fTRD(0) | |
105 | ,fGeo(0) | |
106 | ,fEvent(0) | |
107 | ,fMasks(0) | |
108 | ,fCompress(kTRUE) | |
109 | ,fSDigits(kFALSE) | |
110 | ,fMergeSignalOnly(kFALSE) | |
111 | { | |
112 | // | |
113 | // AliTRDdigitizer constructor | |
114 | // | |
115 | ||
116 | } | |
117 | ||
118 | //_____________________________________________________________________________ | |
119 | AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager | |
120 | , const Text_t *name, const Text_t *title) | |
121 | :AliDigitizer(manager,name,title) | |
122 | ,fRunLoader(0) | |
123 | ,fDigitsManager(0) | |
124 | ,fSDigitsManager(0) | |
125 | ,fSDigitsManagerList(0) | |
126 | ,fTRD(0) | |
127 | ,fGeo(0) | |
128 | ,fEvent(0) | |
129 | ,fMasks(0) | |
130 | ,fCompress(kTRUE) | |
131 | ,fSDigits(kFALSE) | |
132 | ,fMergeSignalOnly(kFALSE) | |
133 | { | |
134 | // | |
135 | // AliTRDdigitizer constructor | |
136 | // | |
137 | ||
138 | } | |
139 | ||
140 | //_____________________________________________________________________________ | |
141 | AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager) | |
142 | :AliDigitizer(manager,"AliTRDdigitizer","TRD digitizer") | |
143 | ,fRunLoader(0) | |
144 | ,fDigitsManager(0) | |
145 | ,fSDigitsManager(0) | |
146 | ,fSDigitsManagerList(0) | |
147 | ,fTRD(0) | |
148 | ,fGeo(0) | |
149 | ,fEvent(0) | |
150 | ,fMasks(0) | |
151 | ,fCompress(kTRUE) | |
152 | ,fSDigits(kFALSE) | |
153 | ,fMergeSignalOnly(kFALSE) | |
154 | { | |
155 | // | |
156 | // AliTRDdigitizer constructor | |
157 | // | |
158 | ||
159 | } | |
160 | ||
161 | //_____________________________________________________________________________ | |
162 | AliTRDdigitizer::AliTRDdigitizer(const AliTRDdigitizer &d) | |
163 | :AliDigitizer(d) | |
164 | ,fRunLoader(0) | |
165 | ,fDigitsManager(0) | |
166 | ,fSDigitsManager(0) | |
167 | ,fSDigitsManagerList(0) | |
168 | ,fTRD(0) | |
169 | ,fGeo(0) | |
170 | ,fEvent(0) | |
171 | ,fMasks(0) | |
172 | ,fCompress(d.fCompress) | |
173 | ,fSDigits(d.fSDigits) | |
174 | ,fMergeSignalOnly(d.fMergeSignalOnly) | |
175 | { | |
176 | // | |
177 | // AliTRDdigitizer copy constructor | |
178 | // | |
179 | ||
180 | } | |
181 | ||
182 | //_____________________________________________________________________________ | |
183 | AliTRDdigitizer::~AliTRDdigitizer() | |
184 | { | |
185 | // | |
186 | // AliTRDdigitizer destructor | |
187 | // | |
188 | ||
189 | if (fDigitsManager) { | |
190 | delete fDigitsManager; | |
191 | fDigitsManager = 0; | |
192 | } | |
193 | ||
194 | if (fSDigitsManager) { | |
195 | // s-digitsmanager will be deleted via list | |
196 | fSDigitsManager = 0; | |
197 | } | |
198 | ||
199 | if (fSDigitsManagerList) { | |
200 | fSDigitsManagerList->Delete(); | |
201 | delete fSDigitsManagerList; | |
202 | fSDigitsManagerList = 0; | |
203 | } | |
204 | ||
205 | if (fMasks) { | |
206 | delete [] fMasks; | |
207 | fMasks = 0; | |
208 | } | |
209 | ||
210 | if (fGeo) { | |
211 | delete fGeo; | |
212 | fGeo = 0; | |
213 | } | |
214 | ||
215 | } | |
216 | ||
217 | //_____________________________________________________________________________ | |
218 | AliTRDdigitizer &AliTRDdigitizer::operator=(const AliTRDdigitizer &d) | |
219 | { | |
220 | // | |
221 | // Assignment operator | |
222 | // | |
223 | ||
224 | if (this != &d) { | |
225 | ((AliTRDdigitizer &) d).Copy(*this); | |
226 | } | |
227 | ||
228 | return *this; | |
229 | ||
230 | } | |
231 | ||
232 | //_____________________________________________________________________________ | |
233 | void AliTRDdigitizer::Copy(TObject &d) const | |
234 | { | |
235 | // | |
236 | // Copy function | |
237 | // | |
238 | ||
239 | ((AliTRDdigitizer &) d).fRunLoader = 0; | |
240 | ((AliTRDdigitizer &) d).fDigitsManager = 0; | |
241 | ((AliTRDdigitizer &) d).fSDigitsManager = 0; | |
242 | ((AliTRDdigitizer &) d).fSDigitsManagerList = 0; | |
243 | ((AliTRDdigitizer &) d).fTRD = 0; | |
244 | ((AliTRDdigitizer &) d).fGeo = 0; | |
245 | ((AliTRDdigitizer &) d).fEvent = 0; | |
246 | ((AliTRDdigitizer &) d).fMasks = 0; | |
247 | ((AliTRDdigitizer &) d).fCompress = fCompress; | |
248 | ((AliTRDdigitizer &) d).fSDigits = fSDigits; | |
249 | ((AliTRDdigitizer &) d).fMergeSignalOnly = fMergeSignalOnly; | |
250 | ||
251 | } | |
252 | ||
253 | //_____________________________________________________________________________ | |
254 | void AliTRDdigitizer::Exec(const Option_t * const option) | |
255 | { | |
256 | // | |
257 | // Executes the merging | |
258 | // | |
259 | ||
260 | Int_t iInput; | |
261 | ||
262 | AliTRDdigitsManager *sdigitsManager; | |
263 | ||
264 | TString optionString = option; | |
265 | if (optionString.Contains("deb")) { | |
266 | AliLog::SetClassDebugLevel("AliTRDdigitizer",1); | |
267 | AliInfo("Called with debug option"); | |
268 | } | |
269 | ||
270 | // The AliRoot file is already connected by the manager | |
271 | AliRunLoader *inrl = 0x0; | |
272 | ||
273 | if (gAlice) { | |
274 | AliDebug(1,"AliRun object found on file."); | |
275 | } | |
276 | else { | |
277 | inrl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0)); | |
278 | inrl->LoadgAlice(); | |
279 | gAlice = inrl->GetAliRun(); | |
280 | if (!gAlice) { | |
281 | AliError("Could not find AliRun object.") | |
282 | return; | |
283 | } | |
284 | } | |
285 | ||
286 | Int_t nInput = fManager->GetNinputs(); | |
287 | fMasks = new Int_t[nInput]; | |
288 | for (iInput = 0; iInput < nInput; iInput++) { | |
289 | fMasks[iInput] = fManager->GetMask(iInput); | |
290 | } | |
291 | ||
292 | // | |
293 | // Initialization | |
294 | // | |
295 | ||
296 | AliRunLoader *orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName()); | |
297 | ||
298 | if (InitDetector()) { | |
299 | ||
300 | AliLoader *ogime = orl->GetLoader("TRDLoader"); | |
301 | ||
302 | TTree *tree = 0; | |
303 | if (fSDigits) { | |
304 | // If we produce SDigits | |
305 | tree = ogime->TreeS(); | |
306 | if (!tree) { | |
307 | ogime->MakeTree("S"); | |
308 | tree = ogime->TreeS(); | |
309 | } | |
310 | } | |
311 | else { | |
312 | // If we produce Digits | |
313 | tree = ogime->TreeD(); | |
314 | if (!tree) { | |
315 | ogime->MakeTree("D"); | |
316 | tree = ogime->TreeD(); | |
317 | } | |
318 | } | |
319 | ||
320 | MakeBranch(tree); | |
321 | ||
322 | } | |
323 | ||
324 | for (iInput = 0; iInput < nInput; iInput++) { | |
325 | ||
326 | AliDebug(1,Form("Add input stream %d",iInput)); | |
327 | ||
328 | // Check if the input tree exists | |
329 | inrl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput)); | |
330 | AliLoader *gime = inrl->GetLoader("TRDLoader"); | |
331 | ||
332 | TTree *treees = gime->TreeS(); | |
333 | if (treees == 0x0) { | |
334 | if (gime->LoadSDigits()) { | |
335 | AliError(Form("Error Occured while loading S. Digits for input %d.",iInput)); | |
336 | return; | |
337 | } | |
338 | treees = gime->TreeS(); | |
339 | } | |
340 | ||
341 | if (treees == 0x0) { | |
342 | AliError(Form("Input stream %d does not exist",iInput)); | |
343 | return; | |
344 | } | |
345 | ||
346 | // Read the s-digits via digits manager | |
347 | sdigitsManager = new AliTRDdigitsManager(); | |
348 | sdigitsManager->SetSDigits(kTRUE); | |
349 | ||
350 | AliRunLoader *rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput)); | |
351 | AliLoader *gimme = rl->GetLoader("TRDLoader"); | |
352 | if (!gimme->TreeS()) | |
353 | { | |
354 | gimme->LoadSDigits(); | |
355 | } | |
356 | ||
357 | sdigitsManager->ReadDigits(gimme->TreeS()); | |
358 | ||
359 | // Add the s-digits to the input list | |
360 | AddSDigitsManager(sdigitsManager); | |
361 | ||
362 | } | |
363 | ||
364 | // Convert the s-digits to normal digits | |
365 | AliDebug(1,"Do the conversion"); | |
366 | SDigits2Digits(); | |
367 | ||
368 | // Store the digits | |
369 | AliDebug(1,"Write the digits"); | |
370 | fDigitsManager->WriteDigits(); | |
371 | ||
372 | // Write parameters | |
373 | orl->CdGAFile(); | |
374 | ||
375 | // Clean up | |
376 | DeleteSDigitsManager(); | |
377 | ||
378 | AliDebug(1,"Done"); | |
379 | ||
380 | } | |
381 | ||
382 | //_____________________________________________________________________________ | |
383 | Bool_t AliTRDdigitizer::Open(const Char_t *file, Int_t nEvent) | |
384 | { | |
385 | // | |
386 | // Opens a ROOT-file with TRD-hits and reads in the hit-tree | |
387 | // | |
388 | // Connect the AliRoot file containing Geometry, Kine, and Hits | |
389 | // | |
390 | ||
391 | TString evfoldname = AliConfig::GetDefaultEventFolderName(); | |
392 | ||
393 | fRunLoader = AliRunLoader::GetRunLoader(evfoldname); | |
394 | if (!fRunLoader) { | |
395 | fRunLoader = AliRunLoader::Open(file,evfoldname,"UPDATE"); | |
396 | } | |
397 | if (!fRunLoader) { | |
398 | AliError(Form("Can not open session for file %s.",file)); | |
399 | return kFALSE; | |
400 | } | |
401 | ||
402 | if (!fRunLoader->GetAliRun()) { | |
403 | fRunLoader->LoadgAlice(); | |
404 | } | |
405 | gAlice = fRunLoader->GetAliRun(); | |
406 | ||
407 | if (gAlice) { | |
408 | AliDebug(1,"AliRun object found on file."); | |
409 | } | |
410 | else { | |
411 | AliError("Could not find AliRun object."); | |
412 | return kFALSE; | |
413 | } | |
414 | ||
415 | fEvent = nEvent; | |
416 | ||
417 | AliLoader *loader = fRunLoader->GetLoader("TRDLoader"); | |
418 | if (!loader) { | |
419 | AliError("Can not get TRD loader from Run Loader"); | |
420 | return kFALSE; | |
421 | } | |
422 | ||
423 | if (InitDetector()) { | |
424 | TTree *tree = 0; | |
425 | if (fSDigits) { | |
426 | // If we produce SDigits | |
427 | tree = loader->TreeS(); | |
428 | if (!tree) { | |
429 | loader->MakeTree("S"); | |
430 | tree = loader->TreeS(); | |
431 | } | |
432 | } | |
433 | else { | |
434 | // If we produce Digits | |
435 | tree = loader->TreeD(); | |
436 | if (!tree) { | |
437 | loader->MakeTree("D"); | |
438 | tree = loader->TreeD(); | |
439 | } | |
440 | } | |
441 | return MakeBranch(tree); | |
442 | } | |
443 | else { | |
444 | return kFALSE; | |
445 | } | |
446 | ||
447 | } | |
448 | ||
449 | //_____________________________________________________________________________ | |
450 | Bool_t AliTRDdigitizer::Open(AliRunLoader * const runLoader, Int_t nEvent) | |
451 | { | |
452 | // | |
453 | // Opens a ROOT-file with TRD-hits and reads in the hit-tree | |
454 | // | |
455 | // Connect the AliRoot file containing Geometry, Kine, and Hits | |
456 | // | |
457 | ||
458 | fRunLoader = runLoader; | |
459 | if (!fRunLoader) { | |
460 | AliError("RunLoader does not exist"); | |
461 | return kFALSE; | |
462 | } | |
463 | ||
464 | if (!fRunLoader->GetAliRun()) { | |
465 | fRunLoader->LoadgAlice(); | |
466 | } | |
467 | gAlice = fRunLoader->GetAliRun(); | |
468 | ||
469 | if (gAlice) { | |
470 | AliDebug(1,"AliRun object found on file."); | |
471 | } | |
472 | else { | |
473 | AliError("Could not find AliRun object."); | |
474 | return kFALSE; | |
475 | } | |
476 | ||
477 | fEvent = nEvent; | |
478 | ||
479 | AliLoader *loader = fRunLoader->GetLoader("TRDLoader"); | |
480 | if (!loader) { | |
481 | AliError("Can not get TRD loader from Run Loader"); | |
482 | return kFALSE; | |
483 | } | |
484 | ||
485 | if (InitDetector()) { | |
486 | TTree *tree = 0; | |
487 | if (fSDigits) { | |
488 | // If we produce SDigits | |
489 | tree = loader->TreeS(); | |
490 | if (!tree) { | |
491 | loader->MakeTree("S"); | |
492 | tree = loader->TreeS(); | |
493 | } | |
494 | } | |
495 | else { | |
496 | // If we produce Digits | |
497 | tree = loader->TreeD(); | |
498 | if (!tree) { | |
499 | loader->MakeTree("D"); | |
500 | tree = loader->TreeD(); | |
501 | } | |
502 | } | |
503 | return MakeBranch(tree); | |
504 | } | |
505 | else { | |
506 | return kFALSE; | |
507 | } | |
508 | ||
509 | } | |
510 | ||
511 | //_____________________________________________________________________________ | |
512 | Bool_t AliTRDdigitizer::InitDetector() | |
513 | { | |
514 | // | |
515 | // Sets the pointer to the TRD detector and the geometry | |
516 | // | |
517 | ||
518 | // Get the pointer to the detector class and check for version 1 | |
519 | fTRD = (AliTRD *) gAlice->GetDetector("TRD"); | |
520 | if (!fTRD) { | |
521 | AliFatal("No TRD module found"); | |
522 | exit(1); | |
523 | } | |
524 | if (fTRD->IsVersion() != 1) { | |
525 | AliFatal("TRD must be version 1 (slow simulator)"); | |
526 | exit(1); | |
527 | } | |
528 | ||
529 | // Get the geometry | |
530 | fGeo = new AliTRDgeometry(); | |
531 | ||
532 | // Create a digits manager | |
533 | if (fDigitsManager) { | |
534 | delete fDigitsManager; | |
535 | } | |
536 | fDigitsManager = new AliTRDdigitsManager(); | |
537 | fDigitsManager->SetSDigits(fSDigits); | |
538 | fDigitsManager->CreateArrays(); | |
539 | fDigitsManager->SetEvent(fEvent); | |
540 | ||
541 | // The list for the input s-digits manager to be merged | |
542 | if (fSDigitsManagerList) { | |
543 | fSDigitsManagerList->Delete(); | |
544 | } | |
545 | else { | |
546 | fSDigitsManagerList = new TList(); | |
547 | } | |
548 | ||
549 | return kTRUE; | |
550 | ||
551 | } | |
552 | //_____________________________________________________________________________ | |
553 | Bool_t AliTRDdigitizer::MakeBranch(TTree *tree) const | |
554 | { | |
555 | // | |
556 | // Create the branches for the digits array | |
557 | // | |
558 | ||
559 | return fDigitsManager->MakeBranch(tree); | |
560 | ||
561 | } | |
562 | ||
563 | //_____________________________________________________________________________ | |
564 | void AliTRDdigitizer::AddSDigitsManager(AliTRDdigitsManager *man) | |
565 | { | |
566 | // | |
567 | // Add a digits manager for s-digits to the input list. | |
568 | // | |
569 | ||
570 | fSDigitsManagerList->Add(man); | |
571 | ||
572 | } | |
573 | ||
574 | //_____________________________________________________________________________ | |
575 | void AliTRDdigitizer::DeleteSDigitsManager() | |
576 | { | |
577 | // | |
578 | // Removes digits manager from the input list. | |
579 | // | |
580 | ||
581 | fSDigitsManagerList->Delete(); | |
582 | ||
583 | } | |
584 | ||
585 | //_____________________________________________________________________________ | |
586 | Bool_t AliTRDdigitizer::MakeDigits() | |
587 | { | |
588 | // | |
589 | // Creates digits. | |
590 | // | |
591 | ||
592 | AliDebug(1,"Start creating digits"); | |
593 | ||
594 | if (!fGeo) { | |
595 | AliError("No geometry defined"); | |
596 | return kFALSE; | |
597 | } | |
598 | ||
599 | AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); | |
600 | if (!calibration) { | |
601 | AliFatal("Could not get calibration object"); | |
602 | return kFALSE; | |
603 | } | |
604 | ||
605 | const Int_t kNdet = AliTRDgeometry::Ndet(); | |
606 | ||
607 | Float_t **hits = new Float_t*[kNdet]; | |
608 | Int_t *nhit = new Int_t[kNdet]; | |
609 | ||
610 | AliTRDarraySignal *signals = 0x0; | |
611 | ||
612 | // | |
613 | if (calibration->GetNumberOfTimeBinsDCS() != AliTRDSimParam::Instance()->GetNTimeBins()) { | |
614 | AliWarning(Form("Number of time bins is different to OCDB value [SIM=%d, OCDB=%d]" | |
615 | ,AliTRDSimParam::Instance()->GetNTimeBins() | |
616 | ,calibration->GetNumberOfTimeBinsDCS())); | |
617 | } | |
618 | ||
619 | // Sort all hits according to detector number | |
620 | if (!SortHits(hits,nhit)) { | |
621 | AliError("Sorting hits failed"); | |
622 | return kFALSE; | |
623 | } | |
624 | ||
625 | // Loop through all detectors | |
626 | for (Int_t det = 0; det < kNdet; det++) { | |
627 | ||
628 | // Detectors that are switched off, not installed, etc. | |
629 | if (( calibration->IsChamberInstalled(det)) && | |
630 | (!calibration->IsChamberMasked(det)) && | |
631 | ( fGeo->ChamberInGeometry(det)) && | |
632 | (nhit[det] > 0)) { | |
633 | ||
634 | signals = new AliTRDarraySignal(); | |
635 | ||
636 | // Convert the hits of the current detector to detector signals | |
637 | if (!ConvertHits(det,hits[det],nhit[det],signals)) { | |
638 | AliError(Form("Conversion of hits failed for detector=%d",det)); | |
639 | return kFALSE; | |
640 | } | |
641 | // Convert the detector signals to digits or s-digits | |
642 | if (!ConvertSignals(det,signals)) { | |
643 | AliError(Form("Conversion of signals failed for detector=%d",det)); | |
644 | return kFALSE; | |
645 | } | |
646 | ||
647 | // Delete the signals array | |
648 | delete signals; | |
649 | signals = 0x0; | |
650 | ||
651 | } // if: detector status | |
652 | ||
653 | delete [] hits[det]; | |
654 | ||
655 | } // for: detector | |
656 | ||
657 | delete [] hits; | |
658 | delete [] nhit; | |
659 | ||
660 | // Save the values for the raw data headers | |
661 | fDigitsManager->GetDigitsParam()->SetNTimeBins(AliTRDSimParam::Instance()->GetNTimeBins()); | |
662 | fDigitsManager->GetDigitsParam()->SetADCbaseline(AliTRDSimParam::Instance()->GetADCbaseline()); | |
663 | ||
664 | return kTRUE; | |
665 | ||
666 | } | |
667 | ||
668 | //_____________________________________________________________________________ | |
669 | Bool_t AliTRDdigitizer::SortHits(Float_t **hits, Int_t *nhit) | |
670 | { | |
671 | // | |
672 | // Read all the hits and sorts them according to detector number | |
673 | // in the output array <hits>. | |
674 | // | |
675 | ||
676 | AliDebug(1,"Start sorting hits"); | |
677 | ||
678 | const Int_t kNdet = AliTRDgeometry::Ndet(); | |
679 | // Size of the hit vector | |
680 | const Int_t kNhit = 6; | |
681 | ||
682 | Float_t *xyz = 0; | |
683 | Int_t nhitTrk = 0; | |
684 | ||
685 | Int_t *lhit = new Int_t[kNdet]; | |
686 | ||
687 | for (Int_t det = 0; det < kNdet; det++) { | |
688 | lhit[det] = 0; | |
689 | nhit[det] = 0; | |
690 | hits[det] = 0; | |
691 | } | |
692 | ||
693 | AliLoader *gimme = fRunLoader->GetLoader("TRDLoader"); | |
694 | if (!gimme->TreeH()) { | |
695 | gimme->LoadHits(); | |
696 | } | |
697 | TTree *hitTree = gimme->TreeH(); | |
698 | if (hitTree == 0x0) { | |
699 | AliError("Can not get TreeH"); | |
700 | return kFALSE; | |
701 | } | |
702 | fTRD->SetTreeAddress(); | |
703 | ||
704 | // Get the number of entries in the hit tree | |
705 | // (Number of primary particles creating a hit somewhere) | |
706 | Int_t nTrk = (Int_t) hitTree->GetEntries(); | |
707 | AliDebug(1,Form("Found %d tracks",nTrk)); | |
708 | ||
709 | // Loop through all the tracks in the tree | |
710 | for (Int_t iTrk = 0; iTrk < nTrk; iTrk++) { | |
711 | ||
712 | gAlice->GetMCApp()->ResetHits(); | |
713 | hitTree->GetEvent(iTrk); | |
714 | ||
715 | if (!fTRD->Hits()) { | |
716 | AliError(Form("No hits array for track = %d",iTrk)); | |
717 | continue; | |
718 | } | |
719 | ||
720 | // Number of hits for this track | |
721 | nhitTrk = fTRD->Hits()->GetEntriesFast(); | |
722 | ||
723 | Int_t hitCnt = 0; | |
724 | // Loop through the TRD hits | |
725 | AliTRDhit *hit = (AliTRDhit *) fTRD->FirstHit(-1); | |
726 | while (hit) { | |
727 | ||
728 | hitCnt++; | |
729 | ||
730 | // Don't analyze test hits | |
731 | if (((Int_t) hit->GetCharge()) != 0) { | |
732 | ||
733 | Int_t trk = hit->Track(); | |
734 | Int_t det = hit->GetDetector(); | |
735 | Int_t q = hit->GetCharge(); | |
736 | Float_t x = hit->X(); | |
737 | Float_t y = hit->Y(); | |
738 | Float_t z = hit->Z(); | |
739 | Float_t time = hit->GetTime(); | |
740 | ||
741 | if (nhit[det] == lhit[det]) { | |
742 | // Inititialization of new detector | |
743 | xyz = new Float_t[kNhit*(nhitTrk+lhit[det])]; | |
744 | if (hits[det]) { | |
745 | memcpy(xyz,hits[det],sizeof(Float_t)*kNhit*lhit[det]); | |
746 | delete [] hits[det]; | |
747 | } | |
748 | lhit[det] += nhitTrk; | |
749 | hits[det] = xyz; | |
750 | } | |
751 | else { | |
752 | xyz = hits[det]; | |
753 | } | |
754 | xyz[nhit[det]*kNhit+0] = x; | |
755 | xyz[nhit[det]*kNhit+1] = y; | |
756 | xyz[nhit[det]*kNhit+2] = z; | |
757 | xyz[nhit[det]*kNhit+3] = q; | |
758 | xyz[nhit[det]*kNhit+4] = trk; | |
759 | xyz[nhit[det]*kNhit+5] = time; | |
760 | nhit[det]++; | |
761 | ||
762 | } // if: charge != 0 | |
763 | ||
764 | hit = (AliTRDhit *) fTRD->NextHit(); | |
765 | ||
766 | } // for: hits of one track | |
767 | ||
768 | } // for: tracks | |
769 | ||
770 | delete [] lhit; | |
771 | ||
772 | return kTRUE; | |
773 | ||
774 | } | |
775 | ||
776 | //_____________________________________________________________________________ | |
777 | Bool_t AliTRDdigitizer::ConvertHits(Int_t det | |
778 | , const Float_t * const hits | |
779 | , Int_t nhit | |
780 | , AliTRDarraySignal *signals) | |
781 | { | |
782 | // | |
783 | // Converts the detectorwise sorted hits to detector signals | |
784 | // | |
785 | ||
786 | AliDebug(1,Form("Start converting hits for detector=%d (nhits=%d)",det,nhit)); | |
787 | ||
788 | // Number of pads included in the pad response | |
789 | const Int_t kNpad = 3; | |
790 | // Number of track dictionary arrays | |
791 | const Int_t kNdict = AliTRDdigitsManager::kNDict; | |
792 | // Size of the hit vector | |
793 | const Int_t kNhit = 6; | |
794 | ||
795 | // Width of the amplification region | |
796 | const Float_t kAmWidth = AliTRDgeometry::AmThick(); | |
797 | // Width of the drift region | |
798 | const Float_t kDrWidth = AliTRDgeometry::DrThick(); | |
799 | // Drift + amplification region | |
800 | const Float_t kDrMin = - 0.5 * kAmWidth; | |
801 | const Float_t kDrMax = kDrWidth + 0.5 * kAmWidth; | |
802 | ||
803 | Int_t iPad = 0; | |
804 | Int_t dict = 0; | |
805 | Int_t timeBinTRFend = 1; | |
806 | ||
807 | Double_t pos[3]; | |
808 | Double_t loc[3]; | |
809 | Double_t padSignal[kNpad]; | |
810 | Double_t signalOld[kNpad]; | |
811 | ||
812 | AliTRDarrayDictionary *dictionary[kNdict]; | |
813 | ||
814 | AliTRDSimParam *simParam = AliTRDSimParam::Instance(); | |
815 | AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance(); | |
816 | AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); | |
817 | ||
818 | if (!commonParam) { | |
819 | AliFatal("Could not get common parameterss"); | |
820 | return kFALSE; | |
821 | } | |
822 | if (!simParam) { | |
823 | AliFatal("Could not get simulation parameters"); | |
824 | return kFALSE; | |
825 | } | |
826 | if (!calibration) { | |
827 | AliFatal("Could not get calibration object"); | |
828 | return kFALSE; | |
829 | } | |
830 | ||
831 | // Get the detector wise calibration objects | |
832 | AliTRDCalROC *calVdriftROC = 0; | |
833 | Float_t calVdriftDetValue = 0.0; | |
834 | const AliTRDCalDet *calVdriftDet = calibration->GetVdriftDet(); | |
835 | AliTRDCalROC *calT0ROC = 0; | |
836 | Float_t calT0DetValue = 0.0; | |
837 | const AliTRDCalDet *calT0Det = calibration->GetT0Det(); | |
838 | ||
839 | if (simParam->TRFOn()) { | |
840 | timeBinTRFend = ((Int_t) (simParam->GetTRFhi() | |
841 | * commonParam->GetSamplingFrequency())) - 1; | |
842 | } | |
843 | ||
844 | Int_t nTimeTotal = simParam->GetNTimeBins(); | |
845 | Float_t samplingRate = commonParam->GetSamplingFrequency(); | |
846 | Float_t elAttachProp = simParam->GetElAttachProp() / 100.0; | |
847 | ||
848 | AliTRDpadPlane *padPlane = fGeo->GetPadPlane(det); | |
849 | Int_t layer = fGeo->GetLayer(det); //update | |
850 | Float_t row0 = padPlane->GetRow0ROC(); | |
851 | Int_t nRowMax = padPlane->GetNrows(); | |
852 | Int_t nColMax = padPlane->GetNcols(); | |
853 | ||
854 | // Create a new array for the signals | |
855 | signals->Allocate(nRowMax,nColMax,nTimeTotal); | |
856 | ||
857 | // Create a new array for the dictionary | |
858 | for (dict = 0; dict < kNdict; dict++) { | |
859 | dictionary[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict); | |
860 | dictionary[dict]->Allocate(nRowMax,nColMax,nTimeTotal); | |
861 | } | |
862 | ||
863 | // Loop through the hits in this detector | |
864 | for (Int_t hit = 0; hit < nhit; hit++) { | |
865 | ||
866 | pos[0] = hits[hit*kNhit+0]; | |
867 | pos[1] = hits[hit*kNhit+1]; | |
868 | pos[2] = hits[hit*kNhit+2]; | |
869 | Float_t q = hits[hit*kNhit+3]; | |
870 | Float_t hittime = hits[hit*kNhit+5]; | |
871 | Int_t track = ((Int_t) hits[hit*kNhit+4]); | |
872 | ||
873 | Int_t inDrift = 1; | |
874 | ||
875 | // Find the current volume with the geo manager | |
876 | gGeoManager->SetCurrentPoint(pos); | |
877 | gGeoManager->FindNode(); | |
878 | if (strstr(gGeoManager->GetPath(),"/UK")) { | |
879 | inDrift = 0; | |
880 | } | |
881 | ||
882 | // Get the calibration objects | |
883 | calVdriftROC = calibration->GetVdriftROC(det); | |
884 | calVdriftDetValue = calVdriftDet->GetValue(det); | |
885 | calT0ROC = calibration->GetT0ROC(det); | |
886 | calT0DetValue = calT0Det->GetValue(det); | |
887 | ||
888 | // Go to the local coordinate system: | |
889 | // loc[0] - col direction in amplification or driftvolume | |
890 | // loc[1] - row direction in amplification or driftvolume | |
891 | // loc[2] - time direction in amplification or driftvolume | |
892 | gGeoManager->MasterToLocal(pos,loc); | |
893 | if (inDrift) { | |
894 | // Relative to middle of amplification region | |
895 | loc[2] = loc[2] - kDrWidth/2.0 - kAmWidth/2.0; | |
896 | } | |
897 | ||
898 | // The driftlength [cm] (w/o diffusion yet !). | |
899 | // It is negative if the hit is between pad plane and anode wires. | |
900 | Double_t driftlength = -1.0 * loc[2]; | |
901 | ||
902 | // Stupid patch to take care of TR photons that are absorbed | |
903 | // outside the chamber volume. A real fix would actually need | |
904 | // a more clever implementation of the TR hit generation | |
905 | if (q < 0.0) { | |
906 | if ((loc[1] < padPlane->GetRowEndROC()) || | |
907 | (loc[1] > padPlane->GetRow0ROC())) { | |
908 | continue; | |
909 | } | |
910 | if ((driftlength < kDrMin) || | |
911 | (driftlength > kDrMax)) { | |
912 | continue; | |
913 | } | |
914 | } | |
915 | ||
916 | // Get row and col of unsmeared electron to retrieve drift velocity | |
917 | // The pad row (z-direction) | |
918 | Int_t rowE = padPlane->GetPadRowNumberROC(loc[1]); | |
919 | if (rowE < 0) { | |
920 | continue; | |
921 | } | |
922 | Double_t rowOffset = padPlane->GetPadRowOffsetROC(rowE,loc[1]); | |
923 | // The pad column (rphi-direction) | |
924 | Double_t offsetTilt = padPlane->GetTiltOffset(rowOffset); | |
925 | Int_t colE = padPlane->GetPadColNumber(loc[0]+offsetTilt); | |
926 | if (colE < 0) { | |
927 | continue; | |
928 | } | |
929 | Double_t colOffset = 0.0; | |
930 | ||
931 | // Normalized drift length | |
932 | Float_t driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE); | |
933 | Double_t absdriftlength = TMath::Abs(driftlength); | |
934 | if (commonParam->ExBOn()) { | |
935 | absdriftlength /= TMath::Sqrt(GetLorentzFactor(driftvelocity)); | |
936 | } | |
937 | ||
938 | // Loop over all electrons of this hit | |
939 | // TR photons produce hits with negative charge | |
940 | Int_t nEl = ((Int_t) TMath::Abs(q)); | |
941 | for (Int_t iEl = 0; iEl < nEl; iEl++) { | |
942 | ||
943 | // Now the real local coordinate system of the ROC | |
944 | // column direction: locC | |
945 | // row direction: locR | |
946 | // time direction: locT | |
947 | // locR and locC are identical to the coordinates of the corresponding | |
948 | // volumina of the drift or amplification region. | |
949 | // locT is defined relative to the wire plane (i.e. middle of amplification | |
950 | // region), meaning locT = 0, and is negative for hits coming from the | |
951 | // drift region. | |
952 | Double_t locC = loc[0]; | |
953 | Double_t locR = loc[1]; | |
954 | Double_t locT = loc[2]; | |
955 | ||
956 | // Electron attachment | |
957 | if (simParam->ElAttachOn()) { | |
958 | if (gRandom->Rndm() < (absdriftlength * elAttachProp)) { | |
959 | continue; | |
960 | } | |
961 | } | |
962 | ||
963 | // Apply the diffusion smearing | |
964 | if (simParam->DiffusionOn()) { | |
965 | if (!(Diffusion(driftvelocity,absdriftlength,locR,locC,locT))) { | |
966 | continue; | |
967 | } | |
968 | } | |
969 | ||
970 | // Apply E x B effects (depends on drift direction) | |
971 | if (commonParam->ExBOn()) { | |
972 | if (!(ExB(driftvelocity,driftlength,locC))) { | |
973 | continue; | |
974 | } | |
975 | } | |
976 | ||
977 | // The electron position after diffusion and ExB in pad coordinates. | |
978 | // The pad row (z-direction) | |
979 | rowE = padPlane->GetPadRowNumberROC(locR); | |
980 | if (rowE < 0) continue; | |
981 | rowOffset = padPlane->GetPadRowOffsetROC(rowE,locR); | |
982 | ||
983 | // The pad column (rphi-direction) | |
984 | offsetTilt = padPlane->GetTiltOffset(rowOffset); | |
985 | colE = padPlane->GetPadColNumber(locC+offsetTilt); | |
986 | if (colE < 0) continue; | |
987 | colOffset = padPlane->GetPadColOffset(colE,locC+offsetTilt); | |
988 | ||
989 | // Also re-retrieve drift velocity because col and row may have changed | |
990 | driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE); | |
991 | Float_t t0 = calT0DetValue + calT0ROC->GetValue(colE,rowE); | |
992 | ||
993 | // Convert the position to drift time [mus], using either constant drift velocity or | |
994 | // time structure of drift cells (non-isochronity, GARFIELD calculation). | |
995 | // Also add absolute time of hits to take pile-up events into account properly | |
996 | Double_t drifttime; | |
997 | if (simParam->TimeStructOn()) { | |
998 | // Get z-position with respect to anode wire | |
999 | Double_t zz = row0 - locR + padPlane->GetAnodeWireOffset(); | |
1000 | zz -= ((Int_t)(2 * zz)) / 2.0; | |
1001 | if (zz > 0.25) { | |
1002 | zz = 0.5 - zz; | |
1003 | } | |
1004 | // Use drift time map (GARFIELD) | |
1005 | drifttime = commonParam->TimeStruct(driftvelocity,0.5*kAmWidth-1.0*locT,zz) | |
1006 | + hittime; | |
1007 | } | |
1008 | else { | |
1009 | // Use constant drift velocity | |
1010 | drifttime = TMath::Abs(locT) / driftvelocity | |
1011 | + hittime; | |
1012 | } | |
1013 | ||
1014 | // Apply the gas gain including fluctuations | |
1015 | Double_t ggRndm = 0.0; | |
1016 | do { | |
1017 | ggRndm = gRandom->Rndm(); | |
1018 | } while (ggRndm <= 0); | |
1019 | Double_t signal = -(simParam->GetGasGain()) * TMath::Log(ggRndm); | |
1020 | ||
1021 | // Apply the pad response | |
1022 | if (simParam->PRFOn()) { | |
1023 | // The distance of the electron to the center of the pad | |
1024 | // in units of pad width | |
1025 | Double_t dist = (colOffset - 0.5*padPlane->GetColSize(colE)) | |
1026 | / padPlane->GetColSize(colE); | |
1027 | // This is a fixed parametrization, i.e. not dependent on | |
1028 | // calibration values ! | |
1029 | if (!(calibration->PadResponse(signal,dist,layer,padSignal))) continue; | |
1030 | } | |
1031 | else { | |
1032 | padSignal[0] = 0.0; | |
1033 | padSignal[1] = signal; | |
1034 | padSignal[2] = 0.0; | |
1035 | } | |
1036 | ||
1037 | // The time bin (always positive), with t0 distortion | |
1038 | Double_t timeBinIdeal = drifttime * samplingRate + t0; | |
1039 | // Protection | |
1040 | if (TMath::Abs(timeBinIdeal) > 2*nTimeTotal) { | |
1041 | timeBinIdeal = 2 * nTimeTotal; | |
1042 | } | |
1043 | Int_t timeBinTruncated = ((Int_t) timeBinIdeal); | |
1044 | // The distance of the position to the middle of the timebin | |
1045 | Double_t timeOffset = ((Float_t) timeBinTruncated | |
1046 | + 0.5 - timeBinIdeal) / samplingRate; | |
1047 | ||
1048 | // Sample the time response inside the drift region | |
1049 | // + additional time bins before and after. | |
1050 | // The sampling is done always in the middle of the time bin | |
1051 | for (Int_t iTimeBin = TMath::Max(timeBinTruncated,0) | |
1052 | ;iTimeBin < TMath::Min(timeBinTruncated+timeBinTRFend,nTimeTotal) | |
1053 | ;iTimeBin++) { | |
1054 | ||
1055 | // Apply the time response | |
1056 | Double_t timeResponse = 1.0; | |
1057 | Double_t crossTalk = 0.0; | |
1058 | Double_t time = (iTimeBin - timeBinTruncated) / samplingRate + timeOffset; | |
1059 | ||
1060 | if (simParam->TRFOn()) { | |
1061 | timeResponse = simParam->TimeResponse(time); | |
1062 | } | |
1063 | if (simParam->CTOn()) { | |
1064 | crossTalk = simParam->CrossTalk(time); | |
1065 | } | |
1066 | ||
1067 | signalOld[0] = 0.0; | |
1068 | signalOld[1] = 0.0; | |
1069 | signalOld[2] = 0.0; | |
1070 | ||
1071 | for (iPad = 0; iPad < kNpad; iPad++) { | |
1072 | ||
1073 | Int_t colPos = colE + iPad - 1; | |
1074 | if (colPos < 0) continue; | |
1075 | if (colPos >= nColMax) break; | |
1076 | ||
1077 | // Add the signals | |
1078 | signalOld[iPad] = signals->GetData(rowE,colPos,iTimeBin); | |
1079 | ||
1080 | if (colPos != colE) { | |
1081 | // Cross talk added to non-central pads | |
1082 | signalOld[iPad] += padSignal[iPad] | |
1083 | * (timeResponse + crossTalk); | |
1084 | } | |
1085 | else { | |
1086 | // W/o cross talk at central pad | |
1087 | signalOld[iPad] += padSignal[iPad] | |
1088 | * timeResponse; | |
1089 | } | |
1090 | ||
1091 | signals->SetData(rowE,colPos,iTimeBin,signalOld[iPad]); | |
1092 | ||
1093 | // Store the track index in the dictionary | |
1094 | // Note: We store index+1 in order to allow the array to be compressed | |
1095 | // Note2: Taking out the +1 in track | |
1096 | if (signalOld[iPad] > 0.0) { | |
1097 | for (dict = 0; dict < kNdict; dict++) { | |
1098 | Int_t oldTrack = dictionary[dict]->GetData(rowE,colPos,iTimeBin); | |
1099 | if (oldTrack == track) break; | |
1100 | if (oldTrack == -1 ) { | |
1101 | dictionary[dict]->SetData(rowE,colPos,iTimeBin,track); | |
1102 | break; | |
1103 | } | |
1104 | } | |
1105 | } | |
1106 | ||
1107 | } // Loop: pads | |
1108 | ||
1109 | } // Loop: time bins | |
1110 | ||
1111 | } // Loop: electrons of a single hit | |
1112 | ||
1113 | } // Loop: hits | |
1114 | ||
1115 | AliDebug(2,Form("Finished analyzing %d hits",nhit)); | |
1116 | ||
1117 | return kTRUE; | |
1118 | ||
1119 | } | |
1120 | ||
1121 | //_____________________________________________________________________________ | |
1122 | Bool_t AliTRDdigitizer::ConvertSignals(Int_t det, AliTRDarraySignal *signals) | |
1123 | { | |
1124 | // | |
1125 | // Convert signals to digits | |
1126 | // | |
1127 | ||
1128 | AliDebug(1,Form("Start converting the signals for detector %d",det)); | |
1129 | ||
1130 | if (fSDigits) { | |
1131 | // Convert the signal array to s-digits | |
1132 | if (!Signal2SDigits(det,signals)) { | |
1133 | return kFALSE; | |
1134 | } | |
1135 | } | |
1136 | else { | |
1137 | // Convert the signal array to digits | |
1138 | if (!Signal2ADC(det,signals)) { | |
1139 | return kFALSE; | |
1140 | } | |
1141 | // Run digital processing for digits | |
1142 | RunDigitalProcessing(det); | |
1143 | } | |
1144 | ||
1145 | // Compress the arrays | |
1146 | CompressOutputArrays(det); | |
1147 | ||
1148 | return kTRUE; | |
1149 | ||
1150 | } | |
1151 | ||
1152 | //_____________________________________________________________________________ | |
1153 | Bool_t AliTRDdigitizer::Signal2ADC(Int_t det, AliTRDarraySignal *signals) | |
1154 | { | |
1155 | // | |
1156 | // Converts the sampled electron signals to ADC values for a given chamber | |
1157 | // | |
1158 | ||
1159 | AliDebug(1,Form("Start converting signals to ADC values for detector=%d",det)); | |
1160 | ||
1161 | AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); | |
1162 | if (!calibration) { | |
1163 | AliFatal("Could not get calibration object"); | |
1164 | return kFALSE; | |
1165 | } | |
1166 | ||
1167 | AliTRDSimParam *simParam = AliTRDSimParam::Instance(); | |
1168 | if (!simParam) { | |
1169 | AliFatal("Could not get simulation parameters"); | |
1170 | return kFALSE; | |
1171 | } | |
1172 | ||
1173 | // Converts number of electrons to fC | |
1174 | const Double_t kEl2fC = 1.602e-19 * 1.0e15; | |
1175 | ||
1176 | // Coupling factor | |
1177 | Double_t coupling = simParam->GetPadCoupling() | |
1178 | * simParam->GetTimeCoupling(); | |
1179 | // Electronics conversion factor | |
1180 | Double_t convert = kEl2fC | |
1181 | * simParam->GetChipGain(); | |
1182 | // ADC conversion factor | |
1183 | Double_t adcConvert = simParam->GetADCoutRange() | |
1184 | / simParam->GetADCinRange(); | |
1185 | // The electronics baseline in mV | |
1186 | Double_t baseline = simParam->GetADCbaseline() | |
1187 | / adcConvert; | |
1188 | // The electronics baseline in electrons | |
1189 | Double_t baselineEl = baseline | |
1190 | / convert; | |
1191 | ||
1192 | Int_t row = 0; | |
1193 | Int_t col = 0; | |
1194 | Int_t time = 0; | |
1195 | ||
1196 | Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows(); | |
1197 | Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols(); | |
1198 | Int_t nTimeTotal = simParam->GetNTimeBins(); | |
1199 | ||
1200 | // The gainfactor calibration objects | |
1201 | const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet(); | |
1202 | AliTRDCalROC *calGainFactorROC = 0; | |
1203 | Float_t calGainFactorDetValue = 0.0; | |
1204 | ||
1205 | AliTRDarrayADC *digits = 0x0; | |
1206 | ||
1207 | if (!signals) { | |
1208 | AliError(Form("Signals array for detector %d does not exist\n",det)); | |
1209 | return kFALSE; | |
1210 | } | |
1211 | if (signals->HasData()) { | |
1212 | // Expand the container if neccessary | |
1213 | signals->Expand(); | |
1214 | } | |
1215 | else { | |
1216 | // Create missing containers | |
1217 | signals->Allocate(nRowMax,nColMax,nTimeTotal); | |
1218 | } | |
1219 | ||
1220 | // Get the container for the digits of this detector | |
1221 | if (fDigitsManager->HasSDigits()) { | |
1222 | AliError("Digits manager has s-digits"); | |
1223 | return kFALSE; | |
1224 | } | |
1225 | ||
1226 | digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det); | |
1227 | // Allocate memory space for the digits buffer | |
1228 | if (!digits->HasData()) { | |
1229 | digits->Allocate(nRowMax,nColMax,nTimeTotal); | |
1230 | } | |
1231 | ||
1232 | // Get the calibration objects | |
1233 | calGainFactorROC = calibration->GetGainFactorROC(det); | |
1234 | calGainFactorDetValue = calGainFactorDet->GetValue(det); | |
1235 | ||
1236 | // Create the digits for this chamber | |
1237 | for (row = 0; row < nRowMax; row++ ) { | |
1238 | for (col = 0; col < nColMax; col++ ) { | |
1239 | ||
1240 | // Check whether pad is masked | |
1241 | // Bridged pads are not considered yet!!! | |
1242 | if (calibration->IsPadMasked(det,col,row)) { | |
1243 | continue; | |
1244 | } | |
1245 | ||
1246 | // The gain factors | |
1247 | Float_t padgain = calGainFactorDetValue | |
1248 | * calGainFactorROC->GetValue(col,row); | |
1249 | if (padgain <= 0) { | |
1250 | AliError(Form("Not a valid gain %f, %d %d %d",padgain,det,col,row)); | |
1251 | } | |
1252 | ||
1253 | for (time = 0; time < nTimeTotal; time++) { | |
1254 | ||
1255 | // Get the signal amplitude | |
1256 | Float_t signalAmp = signals->GetData(row,col,time); | |
1257 | // Pad and time coupling | |
1258 | signalAmp *= coupling; | |
1259 | // Gain factors | |
1260 | signalAmp *= padgain; | |
1261 | ||
1262 | // Add the noise, starting from minus ADC baseline in electrons | |
1263 | signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,simParam->GetNoise()) | |
1264 | ,-baselineEl); | |
1265 | ||
1266 | // Convert to mV | |
1267 | signalAmp *= convert; | |
1268 | // Add ADC baseline in mV | |
1269 | signalAmp += baseline; | |
1270 | ||
1271 | // Convert to ADC counts. Set the overflow-bit fADCoutRange if the | |
1272 | // signal is larger than fADCinRange | |
1273 | Short_t adc = 0; | |
1274 | if (signalAmp >= simParam->GetADCinRange()) { | |
1275 | adc = ((Short_t) simParam->GetADCoutRange()); | |
1276 | } | |
1277 | else { | |
1278 | adc = TMath::Nint(signalAmp * adcConvert); | |
1279 | } | |
1280 | ||
1281 | // Saving all digits | |
1282 | digits->SetData(row,col,time,adc); | |
1283 | ||
1284 | } // for: time | |
1285 | ||
1286 | } // for: col | |
1287 | } // for: row | |
1288 | ||
1289 | return kTRUE; | |
1290 | ||
1291 | } | |
1292 | ||
1293 | //_____________________________________________________________________________ | |
1294 | Bool_t AliTRDdigitizer::Signal2SDigits(Int_t det, AliTRDarraySignal *signals) | |
1295 | { | |
1296 | // | |
1297 | // Converts the sampled electron signals to s-digits | |
1298 | // | |
1299 | ||
1300 | AliDebug(1,Form("Start converting signals to s-digits for detector=%d",det)); | |
1301 | ||
1302 | AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); | |
1303 | if (!calibration) { | |
1304 | AliFatal("Could not get calibration object"); | |
1305 | return kFALSE; | |
1306 | } | |
1307 | ||
1308 | Int_t row = 0; | |
1309 | Int_t col = 0; | |
1310 | Int_t time = 0; | |
1311 | ||
1312 | Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows(); | |
1313 | Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols(); | |
1314 | Int_t nTimeTotal = AliTRDSimParam::Instance()->GetNTimeBins(); | |
1315 | ||
1316 | // Get the container for the digits of this detector | |
1317 | ||
1318 | if (!fDigitsManager->HasSDigits()) { | |
1319 | AliError("Digits manager has no s-digits"); | |
1320 | return kFALSE; | |
1321 | } | |
1322 | ||
1323 | AliTRDarraySignal *digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det); | |
1324 | // Allocate memory space for the digits buffer | |
1325 | if (!digits->HasData()) { | |
1326 | digits->Allocate(nRowMax,nColMax,nTimeTotal); | |
1327 | } | |
1328 | ||
1329 | // Create the sdigits for this chamber | |
1330 | for (row = 0; row < nRowMax; row++ ) { | |
1331 | for (col = 0; col < nColMax; col++ ) { | |
1332 | for (time = 0; time < nTimeTotal; time++) { | |
1333 | digits->SetData(row,col,time,signals->GetData(row,col,time)); | |
1334 | } // for: time | |
1335 | } // for: col | |
1336 | } // for: row | |
1337 | ||
1338 | return kTRUE; | |
1339 | ||
1340 | } | |
1341 | ||
1342 | //_____________________________________________________________________________ | |
1343 | Bool_t AliTRDdigitizer::Digits2SDigits(AliTRDdigitsManager * const manDig | |
1344 | , AliTRDdigitsManager * const manSDig) | |
1345 | { | |
1346 | // | |
1347 | // Converts digits into s-digits. Needed for embedding into real data. | |
1348 | // | |
1349 | ||
1350 | AliDebug(1,"Start converting digits to s-digits"); | |
1351 | ||
1352 | if (!fGeo) { | |
1353 | fGeo = new AliTRDgeometry(); | |
1354 | } | |
1355 | ||
1356 | AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); | |
1357 | if (!calibration) { | |
1358 | AliFatal("Could not get calibration object"); | |
1359 | return kFALSE; | |
1360 | } | |
1361 | ||
1362 | AliTRDSimParam *simParam = AliTRDSimParam::Instance(); | |
1363 | if (!simParam) { | |
1364 | AliFatal("Could not get simulation parameters"); | |
1365 | return kFALSE; | |
1366 | } | |
1367 | ||
1368 | // Converts number of electrons to fC | |
1369 | const Double_t kEl2fC = 1.602e-19 * 1.0e15; | |
1370 | ||
1371 | // Coupling factor | |
1372 | Double_t coupling = simParam->GetPadCoupling() | |
1373 | * simParam->GetTimeCoupling(); | |
1374 | // Electronics conversion factor | |
1375 | Double_t convert = kEl2fC | |
1376 | * simParam->GetChipGain(); | |
1377 | // ADC conversion factor | |
1378 | Double_t adcConvert = simParam->GetADCoutRange() | |
1379 | / simParam->GetADCinRange(); | |
1380 | // The electronics baseline in mV | |
1381 | Double_t baseline = simParam->GetADCbaseline() | |
1382 | / adcConvert; | |
1383 | // The electronics baseline in electrons | |
1384 | //Double_t baselineEl = baseline | |
1385 | // / convert; | |
1386 | ||
1387 | // The gainfactor calibration objects | |
1388 | //const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet(); | |
1389 | //AliTRDCalROC *calGainFactorROC = 0; | |
1390 | //Float_t calGainFactorDetValue = 0.0; | |
1391 | ||
1392 | Int_t row = 0; | |
1393 | Int_t col = 0; | |
1394 | Int_t time = 0; | |
1395 | ||
1396 | for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) { | |
1397 | ||
1398 | Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows(); | |
1399 | Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols(); | |
1400 | Int_t nTimeTotal = manDig->GetDigitsParam()->GetNTimeBins(); | |
1401 | ||
1402 | // Get the calibration objects | |
1403 | //calGainFactorROC = calibration->GetGainFactorROC(det); | |
1404 | //calGainFactorDetValue = calGainFactorDet->GetValue(det); | |
1405 | ||
1406 | // Get the digits | |
1407 | AliTRDarrayADC *digits = (AliTRDarrayADC *) manDig->GetDigits(det); | |
1408 | ||
1409 | if (!manSDig->HasSDigits()) { | |
1410 | AliError("SDigits manager has no s-digits"); | |
1411 | return kFALSE; | |
1412 | } | |
1413 | // Get the s-digits | |
1414 | AliTRDarraySignal *sdigits = (AliTRDarraySignal *) manSDig->GetSDigits(det); | |
1415 | AliTRDarrayDictionary *tracks0 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,0); | |
1416 | AliTRDarrayDictionary *tracks1 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,1); | |
1417 | AliTRDarrayDictionary *tracks2 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,2); | |
1418 | // Allocate memory space for the digits buffer | |
1419 | sdigits->Allocate(nRowMax,nColMax,nTimeTotal); | |
1420 | tracks0->Allocate(nRowMax,nColMax,nTimeTotal); | |
1421 | tracks1->Allocate(nRowMax,nColMax,nTimeTotal); | |
1422 | tracks2->Allocate(nRowMax,nColMax,nTimeTotal); | |
1423 | ||
1424 | // Keep the digits param | |
1425 | manSDig->GetDigitsParam()->SetNTimeBins(manDig->GetDigitsParam()->GetNTimeBins()); | |
1426 | manSDig->GetDigitsParam()->SetADCbaseline(manDig->GetDigitsParam()->GetADCbaseline()); | |
1427 | ||
1428 | if (digits->HasData()) { | |
1429 | ||
1430 | digits->Expand(); | |
1431 | ||
1432 | // Create the sdigits for this chamber | |
1433 | for (row = 0; row < nRowMax; row++ ) { | |
1434 | for (col = 0; col < nColMax; col++ ) { | |
1435 | ||
1436 | // The gain factors | |
1437 | //Float_t padgain = calGainFactorDetValue | |
1438 | // * calGainFactorROC->GetValue(col,row); | |
1439 | ||
1440 | for (time = 0; time < nTimeTotal; time++) { | |
1441 | ||
1442 | Short_t adcVal = digits->GetData(row,col,time); | |
1443 | Double_t signal = (Double_t) adcVal; | |
1444 | // ADC -> signal in mV | |
1445 | signal /= adcConvert; | |
1446 | // Subtract baseline in mV | |
1447 | signal -= baseline; | |
1448 | // Signal in mV -> signal in #electrons | |
1449 | signal /= convert; | |
1450 | // Gain factor | |
1451 | //signal /= padgain; // Not needed for real data | |
1452 | // Pad and time coupling | |
1453 | signal /= coupling; | |
1454 | ||
1455 | sdigits->SetData(row,col,time,signal); | |
1456 | tracks0->SetData(row,col,time,0); | |
1457 | tracks1->SetData(row,col,time,0); | |
1458 | tracks2->SetData(row,col,time,0); | |
1459 | ||
1460 | } // for: time | |
1461 | ||
1462 | } // for: col | |
1463 | } // for: row | |
1464 | ||
1465 | } // if: has data | |
1466 | ||
1467 | sdigits->Compress(0); | |
1468 | tracks0->Compress(); | |
1469 | tracks1->Compress(); | |
1470 | tracks2->Compress(); | |
1471 | ||
1472 | // No compress just remove | |
1473 | manDig->RemoveDigits(det); | |
1474 | manDig->RemoveDictionaries(det); | |
1475 | ||
1476 | } // for: det | |
1477 | ||
1478 | return kTRUE; | |
1479 | ||
1480 | } | |
1481 | ||
1482 | //_____________________________________________________________________________ | |
1483 | Bool_t AliTRDdigitizer::SDigits2Digits() | |
1484 | { | |
1485 | // | |
1486 | // Merges the input s-digits and converts them to normal digits | |
1487 | // | |
1488 | ||
1489 | if (!MergeSDigits()) { | |
1490 | return kFALSE; | |
1491 | } | |
1492 | ||
1493 | return ConvertSDigits(); | |
1494 | ||
1495 | } | |
1496 | ||
1497 | //_____________________________________________________________________________ | |
1498 | Bool_t AliTRDdigitizer::MergeSDigits() | |
1499 | { | |
1500 | // | |
1501 | // Merges the input s-digits: | |
1502 | // - The amplitude of the different inputs are summed up. | |
1503 | // - Of the track IDs from the input dictionaries only one is | |
1504 | // kept for each input. This works for maximal 3 different merged inputs. | |
1505 | // | |
1506 | ||
1507 | // Number of track dictionary arrays | |
1508 | const Int_t kNDict = AliTRDdigitsManager::kNDict; | |
1509 | ||
1510 | AliTRDSimParam *simParam = AliTRDSimParam::Instance(); | |
1511 | if (!simParam) { | |
1512 | AliFatal("Could not get simulation parameters"); | |
1513 | return kFALSE; | |
1514 | } | |
1515 | ||
1516 | AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); | |
1517 | if (!calibration) { | |
1518 | AliFatal("Could not get calibration object"); | |
1519 | return kFALSE; | |
1520 | } | |
1521 | ||
1522 | Int_t iDict = 0; | |
1523 | Int_t jDict = 0; | |
1524 | ||
1525 | AliTRDarraySignal *digitsA; | |
1526 | AliTRDarraySignal *digitsB; | |
1527 | AliTRDarrayDictionary *dictionaryA[kNDict]; | |
1528 | AliTRDarrayDictionary *dictionaryB[kNDict]; | |
1529 | ||
1530 | AliTRDdigitsManager *mergeSDigitsManager = 0x0; | |
1531 | // Get the first s-digits | |
1532 | fSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->First(); | |
1533 | if (!fSDigitsManager) { | |
1534 | AliError("No SDigits manager"); | |
1535 | return kFALSE; | |
1536 | } | |
1537 | ||
1538 | // Loop through the other sets of s-digits | |
1539 | mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(fSDigitsManager); | |
1540 | ||
1541 | if (mergeSDigitsManager) { | |
1542 | AliDebug(1,Form("Merge %d input files.",fSDigitsManagerList->GetSize())); | |
1543 | } | |
1544 | else { | |
1545 | AliDebug(1,"Only one input file."); | |
1546 | } | |
1547 | ||
1548 | Int_t nTimeTotal = fSDigitsManager->GetDigitsParam()->GetNTimeBins(); | |
1549 | Int_t iMerge = 0; | |
1550 | ||
1551 | while (mergeSDigitsManager) { | |
1552 | ||
1553 | if (mergeSDigitsManager->GetDigitsParam()->GetNTimeBins() != nTimeTotal) { | |
1554 | AliError(Form("Mismatch in the number of time bins [%d,%d]" | |
1555 | ,nTimeTotal | |
1556 | ,mergeSDigitsManager->GetDigitsParam()->GetNTimeBins())); | |
1557 | return kFALSE; | |
1558 | } | |
1559 | ||
1560 | iMerge++; | |
1561 | ||
1562 | // Loop through the detectors | |
1563 | for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) { | |
1564 | ||
1565 | Int_t nRowMax = fGeo->GetPadPlane(iDet)->GetNrows(); | |
1566 | Int_t nColMax = fGeo->GetPadPlane(iDet)->GetNcols(); | |
1567 | ||
1568 | // Loop through the pixels of one detector and add the signals | |
1569 | digitsA = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(iDet); | |
1570 | digitsB = (AliTRDarraySignal *) mergeSDigitsManager->GetSDigits(iDet); | |
1571 | digitsA->Expand(); | |
1572 | if (!digitsA->HasData()) continue; | |
1573 | digitsB->Expand(); | |
1574 | if (!digitsB->HasData()) continue; | |
1575 | ||
1576 | for (iDict = 0; iDict < kNDict; iDict++) { | |
1577 | dictionaryA[iDict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(iDet,iDict); | |
1578 | dictionaryB[iDict] = (AliTRDarrayDictionary *) mergeSDigitsManager->GetDictionary(iDet,iDict); | |
1579 | dictionaryA[iDict]->Expand(); | |
1580 | dictionaryB[iDict]->Expand(); | |
1581 | } | |
1582 | ||
1583 | // Merge only detectors that contain a signal | |
1584 | Bool_t doMerge = kTRUE; | |
1585 | if (fMergeSignalOnly) { | |
1586 | if (digitsA->GetOverThreshold(0) == 0) { | |
1587 | doMerge = kFALSE; | |
1588 | } | |
1589 | } | |
1590 | ||
1591 | if (doMerge) { | |
1592 | ||
1593 | AliDebug(1,Form("Merge detector %d of input no.%d",iDet,iMerge+1)); | |
1594 | ||
1595 | for (Int_t iRow = 0; iRow < nRowMax; iRow++ ) { | |
1596 | for (Int_t iCol = 0; iCol < nColMax; iCol++ ) { | |
1597 | for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) { | |
1598 | ||
1599 | // Add the amplitudes of the summable digits | |
1600 | Float_t ampA = digitsA->GetData(iRow,iCol,iTime); | |
1601 | Float_t ampB = digitsB->GetData(iRow,iCol,iTime); | |
1602 | ampA += ampB; | |
1603 | digitsA->SetData(iRow,iCol,iTime,ampA); | |
1604 | ||
1605 | // Add the mask to the track id if defined. | |
1606 | for (iDict = 0; iDict < kNDict; iDict++) { | |
1607 | Int_t trackB = dictionaryB[iDict]->GetData(iRow,iCol,iTime); | |
1608 | if ((fMasks) && (trackB > 0)) { | |
1609 | for (jDict = 0; jDict < kNDict; jDict++) { | |
1610 | Int_t trackA = dictionaryA[iDict]->GetData(iRow,iCol,iTime); | |
1611 | if (trackA == 0) { | |
1612 | trackA = trackB + fMasks[iMerge]; | |
1613 | dictionaryA[iDict]->SetData(iRow,iCol,iTime,trackA); | |
1614 | } // if: track A == 0 | |
1615 | } // for: jDict | |
1616 | } // if: fMasks and trackB > 0 | |
1617 | } // for: iDict | |
1618 | ||
1619 | } // for: iTime | |
1620 | } // for: iCol | |
1621 | } // for: iRow | |
1622 | ||
1623 | } // if: doMerge | |
1624 | ||
1625 | mergeSDigitsManager->RemoveDigits(iDet); | |
1626 | mergeSDigitsManager->RemoveDictionaries(iDet); | |
1627 | ||
1628 | if (fCompress) { | |
1629 | digitsA->Compress(0); | |
1630 | for (iDict = 0; iDict < kNDict; iDict++) { | |
1631 | dictionaryA[iDict]->Compress(); | |
1632 | } | |
1633 | } | |
1634 | ||
1635 | } // for: detectors | |
1636 | ||
1637 | // The next set of s-digits | |
1638 | mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(mergeSDigitsManager); | |
1639 | ||
1640 | } // while: mergeDigitsManagers | |
1641 | ||
1642 | return kTRUE; | |
1643 | ||
1644 | } | |
1645 | ||
1646 | //_____________________________________________________________________________ | |
1647 | Bool_t AliTRDdigitizer::ConvertSDigits() | |
1648 | { | |
1649 | // | |
1650 | // Converts s-digits to normal digits | |
1651 | // | |
1652 | ||
1653 | AliTRDarraySignal *digitsIn = 0x0; | |
1654 | ||
1655 | if (!fSDigitsManager->HasSDigits()) { | |
1656 | AliError("No s-digits in digits manager"); | |
1657 | return kFALSE; | |
1658 | } | |
1659 | ||
1660 | // Loop through the detectors | |
1661 | for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) { | |
1662 | ||
1663 | // Get the merged s-digits (signals) | |
1664 | digitsIn = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(det); | |
1665 | if (!digitsIn->HasData()) { | |
1666 | AliDebug(2,Form("No digits for det=%d",det)); | |
1667 | continue; | |
1668 | } | |
1669 | ||
1670 | // Convert the merged sdigits to digits | |
1671 | if (!Signal2ADC(det,digitsIn)) { | |
1672 | continue; | |
1673 | } | |
1674 | ||
1675 | // Copy the dictionary information to the output array | |
1676 | if (!CopyDictionary(det)) { | |
1677 | continue; | |
1678 | } | |
1679 | ||
1680 | // Delete | |
1681 | fSDigitsManager->RemoveDigits(det); | |
1682 | fSDigitsManager->RemoveDictionaries(det); | |
1683 | ||
1684 | // Run digital processing | |
1685 | RunDigitalProcessing(det); | |
1686 | ||
1687 | // Compress the arrays | |
1688 | CompressOutputArrays(det); | |
1689 | ||
1690 | } // for: detector numbers | |
1691 | ||
1692 | // Save the values for the raw data headers | |
1693 | fDigitsManager->GetDigitsParam()->SetNTimeBins(AliTRDSimParam::Instance()->GetNTimeBins()); | |
1694 | fDigitsManager->GetDigitsParam()->SetADCbaseline(AliTRDSimParam::Instance()->GetADCbaseline()); | |
1695 | ||
1696 | return kTRUE; | |
1697 | ||
1698 | } | |
1699 | ||
1700 | //_____________________________________________________________________________ | |
1701 | Bool_t AliTRDdigitizer::CopyDictionary(Int_t det) | |
1702 | { | |
1703 | // | |
1704 | // Copies the dictionary information from the s-digits arrays | |
1705 | // to the output arrays | |
1706 | // | |
1707 | ||
1708 | AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); | |
1709 | if (!calibration) { | |
1710 | AliFatal("Could not get calibration object"); | |
1711 | return kFALSE; | |
1712 | } | |
1713 | ||
1714 | AliDebug(1,Form("Start copying dictionaries for detector=%d",det)); | |
1715 | ||
1716 | const Int_t kNDict = AliTRDdigitsManager::kNDict; | |
1717 | AliTRDarrayDictionary *dictionaryIn[kNDict]; | |
1718 | AliTRDarrayDictionary *dictionaryOut[kNDict]; | |
1719 | ||
1720 | Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows(); | |
1721 | Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols(); | |
1722 | Int_t nTimeTotal = AliTRDSimParam::Instance()->GetNTimeBins(); | |
1723 | ||
1724 | Int_t row = 0; | |
1725 | Int_t col = 0; | |
1726 | Int_t time = 0; | |
1727 | Int_t dict = 0; | |
1728 | ||
1729 | for (dict = 0; dict < kNDict; dict++) { | |
1730 | ||
1731 | dictionaryIn[dict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(det,dict); | |
1732 | dictionaryIn[dict]->Expand(); | |
1733 | dictionaryOut[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict); | |
1734 | dictionaryOut[dict]->Allocate(nRowMax,nColMax,nTimeTotal); | |
1735 | ||
1736 | for (row = 0; row < nRowMax; row++) { | |
1737 | for (col = 0; col < nColMax; col++) { | |
1738 | for (time = 0; time < nTimeTotal; time++) { | |
1739 | Int_t track = dictionaryIn[dict]->GetData(row,col,time); | |
1740 | dictionaryOut[dict]->SetData(row,col,time,track); | |
1741 | } // for: time | |
1742 | } // for: col | |
1743 | } // for: row | |
1744 | ||
1745 | } // for: dictionaries | |
1746 | ||
1747 | return kTRUE; | |
1748 | ||
1749 | } | |
1750 | ||
1751 | //_____________________________________________________________________________ | |
1752 | void AliTRDdigitizer::CompressOutputArrays(Int_t det) | |
1753 | { | |
1754 | // | |
1755 | // Compress the output arrays | |
1756 | // | |
1757 | ||
1758 | const Int_t kNDict = AliTRDdigitsManager::kNDict; | |
1759 | AliTRDarrayDictionary *dictionary = 0x0; | |
1760 | ||
1761 | if (fCompress) { | |
1762 | ||
1763 | if (!fSDigits) { | |
1764 | AliTRDarrayADC *digits = 0x0; | |
1765 | digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det); | |
1766 | digits->Compress(); | |
1767 | } | |
1768 | ||
1769 | if (fSDigits) { | |
1770 | AliTRDarraySignal *digits = 0x0; | |
1771 | digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det); | |
1772 | digits->Compress(0); | |
1773 | } | |
1774 | ||
1775 | for (Int_t dict = 0; dict < kNDict; dict++) { | |
1776 | dictionary = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict); | |
1777 | dictionary->Compress(); | |
1778 | } | |
1779 | ||
1780 | } | |
1781 | ||
1782 | } | |
1783 | ||
1784 | //_____________________________________________________________________________ | |
1785 | Bool_t AliTRDdigitizer::WriteDigits() const | |
1786 | { | |
1787 | // | |
1788 | // Writes out the TRD-digits and the dictionaries | |
1789 | // | |
1790 | ||
1791 | // Write parameters | |
1792 | fRunLoader->CdGAFile(); | |
1793 | ||
1794 | // Store the digits and the dictionary in the tree | |
1795 | return fDigitsManager->WriteDigits(); | |
1796 | ||
1797 | } | |
1798 | ||
1799 | //_____________________________________________________________________________ | |
1800 | void AliTRDdigitizer::InitOutput(Int_t iEvent) | |
1801 | { | |
1802 | // | |
1803 | // Initializes the output branches | |
1804 | // | |
1805 | ||
1806 | fEvent = iEvent; | |
1807 | ||
1808 | if (!fRunLoader) { | |
1809 | AliError("Run Loader is NULL"); | |
1810 | return; | |
1811 | } | |
1812 | ||
1813 | AliLoader *loader = fRunLoader->GetLoader("TRDLoader"); | |
1814 | if (!loader) { | |
1815 | AliError("Can not get TRD loader from Run Loader"); | |
1816 | return; | |
1817 | } | |
1818 | ||
1819 | TTree *tree = 0; | |
1820 | ||
1821 | if (fSDigits) { | |
1822 | // If we produce SDigits | |
1823 | tree = loader->TreeS(); | |
1824 | if (!tree) { | |
1825 | loader->MakeTree("S"); | |
1826 | tree = loader->TreeS(); | |
1827 | } | |
1828 | } | |
1829 | else { | |
1830 | // If we produce Digits | |
1831 | tree = loader->TreeD(); | |
1832 | if (!tree) { | |
1833 | loader->MakeTree("D"); | |
1834 | tree = loader->TreeD(); | |
1835 | } | |
1836 | } | |
1837 | fDigitsManager->SetEvent(iEvent); | |
1838 | fDigitsManager->MakeBranch(tree); | |
1839 | ||
1840 | } | |
1841 | ||
1842 | //_____________________________________________________________________________ | |
1843 | Int_t AliTRDdigitizer::Diffusion(Float_t vdrift, Double_t absdriftlength | |
1844 | , Double_t &lRow, Double_t &lCol, Double_t &lTime) | |
1845 | { | |
1846 | // | |
1847 | // Applies the diffusion smearing to the position of a single electron. | |
1848 | // Depends on absolute drift length. | |
1849 | // | |
1850 | ||
1851 | Float_t diffL = 0.0; | |
1852 | Float_t diffT = 0.0; | |
1853 | ||
1854 | if (AliTRDCommonParam::Instance()->GetDiffCoeff(diffL,diffT,vdrift)) { | |
1855 | ||
1856 | Float_t driftSqrt = TMath::Sqrt(absdriftlength); | |
1857 | Float_t sigmaT = driftSqrt * diffT; | |
1858 | Float_t sigmaL = driftSqrt * diffL; | |
1859 | lRow = gRandom->Gaus(lRow ,sigmaT); | |
1860 | lCol = gRandom->Gaus(lCol ,sigmaT * GetLorentzFactor(vdrift)); | |
1861 | lTime = gRandom->Gaus(lTime,sigmaL * GetLorentzFactor(vdrift)); | |
1862 | ||
1863 | return 1; | |
1864 | ||
1865 | } | |
1866 | else { | |
1867 | ||
1868 | return 0; | |
1869 | ||
1870 | } | |
1871 | ||
1872 | } | |
1873 | ||
1874 | //_____________________________________________________________________________ | |
1875 | Float_t AliTRDdigitizer::GetLorentzFactor(Float_t vd) | |
1876 | { | |
1877 | // | |
1878 | // Returns the Lorentz factor | |
1879 | // | |
1880 | ||
1881 | Double_t omegaTau = AliTRDCommonParam::Instance()->GetOmegaTau(vd); | |
1882 | Double_t lorentzFactor = 1.0; | |
1883 | if (AliTRDCommonParam::Instance()->ExBOn()) { | |
1884 | lorentzFactor = 1.0 / (1.0 + omegaTau*omegaTau); | |
1885 | } | |
1886 | ||
1887 | return lorentzFactor; | |
1888 | ||
1889 | } | |
1890 | ||
1891 | //_____________________________________________________________________________ | |
1892 | Int_t AliTRDdigitizer::ExB(Float_t vdrift, Double_t driftlength, Double_t &lCol) | |
1893 | { | |
1894 | // | |
1895 | // Applies E x B effects to the position of a single electron. | |
1896 | // Depends on signed drift length. | |
1897 | // | |
1898 | ||
1899 | lCol = lCol | |
1900 | + AliTRDCommonParam::Instance()->GetOmegaTau(vdrift) | |
1901 | * driftlength; | |
1902 | ||
1903 | return 1; | |
1904 | ||
1905 | } | |
1906 | ||
1907 | //_____________________________________________________________________________ | |
1908 | void AliTRDdigitizer::RunDigitalProcessing(Int_t det) | |
1909 | { | |
1910 | // | |
1911 | // Run the digital processing in the TRAP | |
1912 | // | |
1913 | ||
1914 | AliTRDfeeParam *feeParam = AliTRDfeeParam::Instance(); | |
1915 | ||
1916 | //Create and initialize the mcm object | |
1917 | AliTRDmcmSim* mcmfast = new AliTRDmcmSim(); | |
1918 | ||
1919 | AliTRDarrayADC *digits = fDigitsManager->GetDigits(det); | |
1920 | if (!digits) | |
1921 | return; | |
1922 | ||
1923 | //Call the methods in the mcm class using the temporary array as input | |
1924 | for(Int_t rob = 0; rob < digits->GetNrow() / 2; rob++) | |
1925 | { | |
1926 | for(Int_t mcm = 0; mcm < 16; mcm++) | |
1927 | { | |
1928 | mcmfast->Init(det, rob, mcm); | |
1929 | mcmfast->SetData(digits, fDigitsManager); | |
1930 | mcmfast->Filter(); | |
1931 | if (feeParam->GetTracklet()) { | |
1932 | mcmfast->Tracklet(); | |
1933 | mcmfast->StoreTracklets(); | |
1934 | } | |
1935 | mcmfast->ZSMapping(); | |
1936 | mcmfast->WriteData(digits); | |
1937 | } | |
1938 | } | |
1939 | ||
1940 | delete mcmfast; | |
1941 | ||
1942 | } |