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