]>
Commit | Line | Data |
---|---|---|
92aeef15 | 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 | #include "AliMUONDigitizerV3.h" | |
19 | ||
20 | #include "AliLog.h" | |
4ce497c4 | 21 | #include "AliMUON.h" |
92aeef15 | 22 | #include "AliMUONCalibrationData.h" |
92aeef15 | 23 | #include "AliMUONConstants.h" |
24 | #include "AliMUONData.h" | |
4ce497c4 | 25 | #include "AliMUONDataIterator.h" |
92aeef15 | 26 | #include "AliMUONDigit.h" |
4ce497c4 | 27 | #include "AliMUONSegmentation.h" |
92aeef15 | 28 | #include "AliMUONTriggerDecisionV1.h" |
4ce497c4 | 29 | #include "AliMUONTriggerEfficiencyCells.h" |
4f8a3d8b | 30 | #include "AliMUONTriggerElectronics.h" |
05314992 | 31 | #include "AliMUONVCalibParam.h" |
4ce497c4 | 32 | #include "AliMpDEIterator.h" |
92aeef15 | 33 | #include "AliMpDEManager.h" |
4ce497c4 | 34 | #include "AliMpIntPair.h" |
35 | #include "AliMpPad.h" | |
92aeef15 | 36 | #include "AliMpStationType.h" |
4ce497c4 | 37 | #include "AliMpVSegmentation.h" |
92aeef15 | 38 | #include "AliRun.h" |
39 | #include "AliRunDigitizer.h" | |
40 | #include "AliRunLoader.h" | |
41 | #include "Riostream.h" | |
4ce497c4 | 42 | #include "TF1.h" |
92aeef15 | 43 | #include "TRandom.h" |
44 | #include "TString.h" | |
45 | ||
4ce497c4 | 46 | /// |
47 | /// The digitizer is performing the transformation to go from SDigits (digits | |
48 | /// w/o any electronic noise) to Digits (w/ electronic noise, and decalibration) | |
49 | /// | |
50 | /// The decalibration is performed by doing the reverse operation of the | |
51 | /// calibration, that is we do (Signal+pedestal)/gain -> ADC | |
52 | /// | |
53 | /// Note also that the digitizer takes care of merging sdigits that belongs | |
54 | /// to the same pad, either because we're merging several input sdigit files | |
55 | /// or with a single file because the sdigitizer does not merge sdigits itself | |
56 | /// (for performance reason mainly, and because anyway we know we have to do it | |
57 | /// here, at the digitization level). | |
58 | /// | |
59 | ||
60 | namespace | |
61 | { | |
62 | AliMUON* muon() | |
63 | { | |
64 | return static_cast<AliMUON*>(gAlice->GetModule("MUON")); | |
65 | } | |
66 | ||
67 | AliMUONSegmentation* Segmentation() | |
68 | { | |
69 | static AliMUONSegmentation* segmentation = muon()->GetSegmentation(); | |
70 | return segmentation; | |
71 | } | |
72 | } | |
73 | ||
74 | const Double_t AliMUONDigitizerV3::fgkNSigmas=3; | |
75 | ||
92aeef15 | 76 | ClassImp(AliMUONDigitizerV3) |
77 | ||
78 | //_____________________________________________________________________________ | |
79 | AliMUONDigitizerV3::AliMUONDigitizerV3(AliRunDigitizer* manager, | |
4ce497c4 | 80 | ETriggerCodeVersion triggerCodeVersion, |
81 | Bool_t useTriggerEfficiency, | |
82 | Bool_t generateNoisyDigits) | |
92aeef15 | 83 | : AliDigitizer(manager), |
92aeef15 | 84 | fIsInitialized(kFALSE), |
85 | fOutputData(0x0), | |
86 | fCalibrationData(0x0), | |
87 | fTriggerProcessor(0x0), | |
4ce497c4 | 88 | fTriggerCodeVersion(triggerCodeVersion), |
89 | fUseTriggerEfficiency(useTriggerEfficiency), | |
90 | fTriggerEfficiency(0x0), | |
91 | fNoiseFunction(0x0), | |
92 | fGenerateNoisyDigits(generateNoisyDigits) | |
92aeef15 | 93 | { |
05314992 | 94 | // |
95 | // Ctor. | |
96 | // | |
92aeef15 | 97 | AliDebug(1,Form("AliRunDigitizer=%p",fManager)); |
4ce497c4 | 98 | fGenerateNoisyDigitsTimer.Start(kTRUE); fGenerateNoisyDigitsTimer.Stop(); |
99 | fExecTimer.Start(kTRUE); fExecTimer.Stop(); | |
100 | fFindDigitIndexTimer.Start(kTRUE); fFindDigitIndexTimer.Stop(); | |
92aeef15 | 101 | } |
102 | ||
884a73f1 | 103 | //______________________________________________________________________________ |
104 | AliMUONDigitizerV3::AliMUONDigitizerV3(const AliMUONDigitizerV3& right) | |
105 | : AliDigitizer(right) | |
106 | { | |
107 | /// Protected copy constructor (not implemented) | |
108 | ||
109 | AliFatal("Copy constructor not provided."); | |
110 | } | |
111 | ||
92aeef15 | 112 | //_____________________________________________________________________________ |
113 | AliMUONDigitizerV3::~AliMUONDigitizerV3() | |
114 | { | |
05314992 | 115 | // |
116 | // Dtor. Note we're the owner of some pointers. | |
117 | // | |
92aeef15 | 118 | AliDebug(1,"dtor"); |
4ce497c4 | 119 | |
92aeef15 | 120 | delete fOutputData; |
121 | delete fCalibrationData; | |
122 | delete fTriggerProcessor; | |
4ce497c4 | 123 | delete fNoiseFunction; |
124 | ||
125 | AliInfo(Form("Execution time for FindDigitIndex() : R:%.2fs C:%.2fs", | |
126 | fFindDigitIndexTimer.RealTime(),fFindDigitIndexTimer.CpuTime())); | |
127 | if ( fGenerateNoisyDigits ) | |
128 | { | |
129 | AliInfo(Form("Execution time for GenerateNoisyDigits() : R:%.2fs C:%.2fs", | |
130 | fGenerateNoisyDigitsTimer.RealTime(), | |
131 | fGenerateNoisyDigitsTimer.CpuTime())); | |
132 | } | |
133 | AliInfo(Form("Execution time for Exec() : R:%.2fs C:%.2fs", | |
134 | fExecTimer.RealTime(),fExecTimer.CpuTime())); | |
135 | ||
92aeef15 | 136 | } |
137 | ||
884a73f1 | 138 | //______________________________________________________________________________ |
139 | AliMUONDigitizerV3& | |
140 | AliMUONDigitizerV3::operator=(const AliMUONDigitizerV3& right) | |
141 | { | |
142 | /// Protected assignement operator (not implemented) | |
143 | ||
144 | // check assignement to self | |
145 | if (this == &right) return *this; | |
146 | ||
147 | AliFatal("Assignement operator not provided."); | |
148 | ||
149 | return *this; | |
150 | } | |
151 | ||
92aeef15 | 152 | //_____________________________________________________________________________ |
153 | void | |
4ce497c4 | 154 | AliMUONDigitizerV3::ApplyResponseToTrackerDigit(AliMUONDigit& digit, Bool_t addNoise) |
92aeef15 | 155 | { |
92aeef15 | 156 | // For tracking digits, starting from an ideal digit's charge, we : |
157 | // | |
4ce497c4 | 158 | // - add some noise (thus leading to a realistic charge), if requested to do so |
92aeef15 | 159 | // - divide by a gain (thus decalibrating the digit) |
160 | // - add a pedestal (thus decalibrating the digit) | |
05314992 | 161 | // - sets the signal to zero if below 3*sigma of the noise |
92aeef15 | 162 | // |
59b91539 | 163 | |
4ce497c4 | 164 | static const Int_t kMaxADC = (1<<12)-1; // We code the charge on a 12 bits ADC. |
59b91539 | 165 | |
4ce497c4 | 166 | Float_t signal = digit.Signal(); |
59b91539 | 167 | |
168 | if ( !addNoise ) | |
169 | { | |
170 | digit.SetADC(TMath::Nint(signal)); | |
171 | return; | |
172 | } | |
92aeef15 | 173 | |
4ce497c4 | 174 | Int_t detElemId = digit.DetElemId(); |
92aeef15 | 175 | |
176 | Int_t manuId = digit.ManuId(); | |
177 | Int_t manuChannel = digit.ManuChannel(); | |
178 | ||
4ce497c4 | 179 | AliMUONVCalibParam* pedestal = fCalibrationData->Pedestals(detElemId,manuId); |
92aeef15 | 180 | if (!pedestal) |
59b91539 | 181 | { |
182 | AliFatal(Form("Could not get pedestal for DE=%d manuId=%d", | |
183 | detElemId,manuId)); | |
184 | } | |
05314992 | 185 | Float_t pedestalMean = pedestal->ValueAsFloat(manuChannel,0); |
186 | Float_t pedestalSigma = pedestal->ValueAsFloat(manuChannel,1); | |
59b91539 | 187 | |
4ce497c4 | 188 | AliMUONVCalibParam* gain = fCalibrationData->Gains(detElemId,manuId); |
92aeef15 | 189 | if (!gain) |
59b91539 | 190 | { |
191 | AliFatal(Form("Could not get gain for DE=%d manuId=%d", | |
192 | detElemId,manuId)); | |
193 | } | |
05314992 | 194 | Float_t gainMean = gain->ValueAsFloat(manuChannel,0); |
4ce497c4 | 195 | |
59b91539 | 196 | Float_t adcNoise = gRandom->Gaus(0.0,pedestalSigma); |
197 | ||
92aeef15 | 198 | Int_t adc; |
59b91539 | 199 | |
05314992 | 200 | if ( gainMean < 1E-6 ) |
92aeef15 | 201 | { |
59b91539 | 202 | AliError(Form("Got a too small gain %e for DE=%d manuId=%d manuChannel=%d. " |
203 | "Setting signal to 0.", | |
204 | gainMean,detElemId,manuId,manuChannel)); | |
92aeef15 | 205 | adc = 0; |
206 | } | |
59b91539 | 207 | else |
208 | { | |
209 | adc = TMath::Nint( signal / gainMean + pedestalMean + adcNoise);/// | |
210 | ||
211 | if ( adc <= pedestalMean + fgkNSigmas*pedestalSigma ) | |
212 | { | |
213 | adc = 0; | |
214 | } | |
215 | } | |
216 | ||
05314992 | 217 | // be sure we stick to 12 bits. |
4ce497c4 | 218 | if ( adc > kMaxADC ) |
59b91539 | 219 | { |
220 | adc = kMaxADC; | |
221 | } | |
222 | ||
92aeef15 | 223 | digit.SetPhysicsSignal(TMath::Nint(signal)); |
224 | digit.SetSignal(adc); | |
225 | digit.SetADC(adc); | |
226 | } | |
227 | ||
4ce497c4 | 228 | //_____________________________________________________________________________ |
229 | void | |
230 | AliMUONDigitizerV3::ApplyResponseToTriggerDigit(AliMUONDigit& digit, | |
231 | AliMUONData* data) | |
232 | { | |
233 | if ( !fTriggerEfficiency ) return; | |
234 | ||
235 | AliMUONDigit* correspondingDigit = FindCorrespondingDigit(digit,data); | |
236 | ||
237 | Int_t detElemId = digit.DetElemId(); | |
238 | ||
239 | const AliMpVSegmentation* segment[2] = | |
240 | { | |
241 | Segmentation()->GetMpSegmentation(detElemId,digit.Cathode()), | |
242 | Segmentation()->GetMpSegmentation(detElemId,correspondingDigit->Cathode()) | |
243 | }; | |
244 | ||
245 | AliMpPad pad[2] = | |
246 | { | |
247 | segment[0]->PadByIndices(AliMpIntPair(digit.PadX(),digit.PadY()),kTRUE), | |
248 | segment[1]->PadByIndices(AliMpIntPair(correspondingDigit->PadX(),correspondingDigit->PadY()),kTRUE) | |
249 | }; | |
250 | ||
251 | Int_t ix(0); | |
252 | Int_t iy(1); | |
253 | ||
254 | if (digit.Cathode()==0) | |
255 | { | |
256 | ix=1; | |
257 | iy=0; | |
258 | } | |
259 | ||
260 | Float_t x = pad[ix].Position().X(); | |
261 | Float_t y = pad[iy].Position().Y(); | |
262 | if ( x==-1 && y==-1 ) | |
263 | { | |
264 | x=-9999.; | |
265 | y=-9999.; | |
266 | AliError(Form("Got an unknown position for a digit in DE %d at (ix,iy)=(%d,%d)", | |
267 | detElemId,pad[ix].GetIndices().GetFirst(),pad[iy].GetIndices().GetSecond())); | |
268 | } | |
269 | Float_t x0 = segment[0]->Dimensions().X(); | |
270 | Float_t y0 = segment[1]->Dimensions().Y(); | |
271 | TVector2 newCoord = fTriggerEfficiency->ChangeReferenceFrame(x, y, x0, y0); | |
272 | ||
273 | Bool_t isTrig[2]; | |
274 | fTriggerEfficiency->IsTriggered(detElemId, newCoord.Px(), newCoord.Py(), | |
275 | isTrig[0], isTrig[1]); | |
276 | ||
277 | if (!isTrig[digit.Cathode()]) | |
278 | { | |
279 | digit.SetSignal(0); | |
280 | } | |
281 | ||
282 | if ( &digit != correspondingDigit ) | |
283 | { | |
284 | if (!isTrig[correspondingDigit->Cathode()]) | |
285 | { | |
286 | correspondingDigit->SetSignal(0); | |
287 | } | |
288 | } | |
289 | } | |
290 | ||
92aeef15 | 291 | //_____________________________________________________________________________ |
292 | void | |
293 | AliMUONDigitizerV3::ApplyResponse() | |
294 | { | |
05314992 | 295 | // |
296 | // Loop over all chamber digits, and apply the response to them | |
297 | // Note that this method may remove digits. | |
298 | // | |
4ce497c4 | 299 | const Bool_t kAddNoise = kTRUE; |
300 | ||
92aeef15 | 301 | for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich ) |
4ce497c4 | 302 | { |
92aeef15 | 303 | TClonesArray* digits = fOutputData->Digits(ich); |
304 | Int_t n = digits->GetEntriesFast(); | |
4ce497c4 | 305 | Bool_t trackingChamber = ( ich < AliMUONConstants::NTrackingCh() ); |
92aeef15 | 306 | for ( Int_t i = 0; i < n; ++i ) |
307 | { | |
308 | AliMUONDigit* d = static_cast<AliMUONDigit*>(digits->UncheckedAt(i)); | |
4ce497c4 | 309 | if ( trackingChamber ) |
310 | { | |
311 | ApplyResponseToTrackerDigit(*d,kAddNoise); | |
312 | } | |
313 | else | |
314 | { | |
315 | ApplyResponseToTriggerDigit(*d,fOutputData); | |
316 | } | |
92aeef15 | 317 | if ( d->Signal() <= 0 ) |
318 | { | |
319 | digits->RemoveAt(i); | |
320 | } | |
321 | } | |
05314992 | 322 | digits->Compress(); |
92aeef15 | 323 | } |
4ce497c4 | 324 | |
325 | // The version below, using iterator, does not yet work (as the iterator | |
326 | // assumes it is reading digits from the tree, while in this case it's | |
327 | // writing...) | |
328 | // | |
329 | // AliMUONDigit* digit(0x0); | |
330 | // | |
331 | // // First loop on tracker digits | |
332 | // AliMUONDataIterator tracker(fOutputData,"D",AliMUONDataIterator::kTrackingChambers); | |
333 | // | |
334 | // while ( ( digit = static_cast<AliMUONDigit*>(tracker.Next()) ) ) | |
335 | // { | |
336 | // ApplyResponseToTrackerDigit(*digit); | |
337 | // if ( digit->Signal() <= 0 ) | |
338 | // { | |
339 | // tracker.Remove(); | |
340 | // } | |
341 | // | |
342 | // } | |
343 | // | |
344 | // // Then loop on trigger digits | |
345 | // AliMUONDataIterator trigger(fOutputData,"D",AliMUONDataIterator::kTriggerChambers); | |
346 | // | |
347 | // while ( ( digit = static_cast<AliMUONDigit*>(trigger.Next()) ) ) | |
348 | // { | |
349 | // ApplyResponseToTriggerDigit(*digit,fOutputData); | |
350 | // if ( digit->Signal() <= 0 ) | |
351 | // { | |
352 | // trigger.Remove(); | |
353 | // } | |
354 | // } | |
92aeef15 | 355 | } |
356 | ||
357 | //_____________________________________________________________________________ | |
358 | void | |
359 | AliMUONDigitizerV3::AddOrUpdateDigit(TClonesArray& array, | |
360 | const AliMUONDigit& digit) | |
361 | { | |
05314992 | 362 | // |
363 | // Add or update a digit, depending on whether there's already a digit | |
364 | // for the corresponding channel. | |
365 | // | |
92aeef15 | 366 | Int_t ix = FindDigitIndex(array,digit); |
367 | ||
368 | if (ix>=0) | |
369 | { | |
370 | AliMUONDigit* d = static_cast<AliMUONDigit*>(array.UncheckedAt(ix)); | |
371 | Bool_t ok = MergeDigits(digit,*d); | |
372 | if (!ok) | |
373 | { | |
374 | AliError("Digits are not mergeable !"); | |
375 | } | |
92aeef15 | 376 | } |
377 | else | |
378 | { | |
379 | ix = array.GetLast() + 1; | |
380 | new(array[ix]) AliMUONDigit(digit); | |
381 | } | |
382 | ||
383 | } | |
384 | ||
385 | //_____________________________________________________________________________ | |
386 | void | |
387 | AliMUONDigitizerV3::Exec(Option_t*) | |
388 | { | |
05314992 | 389 | // |
390 | // Main method. | |
391 | // We first loop over input files, and merge the sdigits we found there. | |
4ce497c4 | 392 | // Second, we digitize all the resulting sdigits |
393 | // Then we generate noise-only digits (for tracker only) | |
05314992 | 394 | // And we finally generate the trigger outputs. |
395 | // | |
4ce497c4 | 396 | |
92aeef15 | 397 | AliDebug(1, "Running digitizer."); |
398 | ||
399 | if ( fManager->GetNinputs() == 0 ) | |
400 | { | |
401 | AliWarning("No input set. Nothing to do."); | |
402 | return; | |
403 | } | |
404 | ||
405 | if ( !fIsInitialized ) | |
406 | { | |
407 | AliError("Not initialized. Cannot perform the work. Sorry"); | |
408 | return; | |
409 | } | |
410 | ||
4ce497c4 | 411 | fExecTimer.Start(kFALSE); |
412 | ||
92aeef15 | 413 | Int_t nInputFiles = fManager->GetNinputs(); |
414 | ||
415 | if ( fOutputData->TreeD() == 0x0 ) | |
416 | { | |
417 | AliDebug(1,"Calling MakeDigitsContainer"); | |
418 | fOutputData->GetLoader()->MakeDigitsContainer(); | |
419 | } | |
420 | fOutputData->MakeBranch("D,GLT"); | |
421 | fOutputData->SetTreeAddress("D,GLT"); | |
422 | ||
423 | // Loop over all the input files, and merge the sdigits found in those | |
424 | // files. | |
425 | for ( Int_t iFile = 0; iFile < nInputFiles; ++iFile ) | |
426 | { | |
427 | AliMUONData* inputData = GetDataAccess(fManager->GetInputFolderName(iFile)); | |
428 | if (!inputData) | |
429 | { | |
430 | AliFatal(Form("Could not get access to input file #%d",iFile)); | |
431 | } | |
05314992 | 432 | |
92aeef15 | 433 | inputData->GetLoader()->LoadSDigits("READ"); |
92aeef15 | 434 | inputData->SetTreeAddress("S"); |
435 | inputData->GetSDigits(); | |
05314992 | 436 | |
437 | MergeWithSDigits(*fOutputData,*inputData,fManager->GetMask(iFile)); | |
438 | ||
92aeef15 | 439 | inputData->ResetSDigits(); |
440 | inputData->GetLoader()->UnloadSDigits(); | |
441 | delete inputData; | |
442 | } | |
443 | ||
444 | // At this point, we do have digit arrays (one per chamber) which contains | |
445 | // the merging of all the sdigits of the input file(s). | |
446 | // We now massage them to apply the detector response, i.e. this | |
447 | // is here that we do the "digitization" work. | |
448 | ||
449 | ApplyResponse(); | |
4ce497c4 | 450 | |
451 | if ( fGenerateNoisyDigits ) | |
452 | { | |
453 | // Generate noise-only digits for tracker. | |
454 | GenerateNoisyDigits(); | |
455 | } | |
456 | ||
92aeef15 | 457 | // We generate the global and local trigger decisions. |
458 | fTriggerProcessor->ExecuteTask(); | |
459 | ||
460 | // Fill the output treeD | |
461 | fOutputData->Fill("D,GLT"); | |
462 | ||
463 | // Write to the output tree(D). | |
464 | // Please note that as GlobalTrigger, LocalTrigger and Digits are in the same | |
465 | // tree (=TreeD) in different branches, this WriteDigits in fact writes all of | |
466 | // the 3 branches. | |
467 | fOutputData->GetLoader()->WriteDigits("OVERWRITE"); | |
468 | ||
469 | // Finally, we clean up after ourselves. | |
470 | fOutputData->ResetDigits(); | |
471 | fOutputData->ResetTrigger(); | |
472 | fOutputData->GetLoader()->UnloadDigits(); | |
4ce497c4 | 473 | |
474 | fExecTimer.Stop(); | |
92aeef15 | 475 | } |
476 | ||
4ce497c4 | 477 | //_____________________________________________________________________________ |
478 | AliMUONDigit* | |
479 | AliMUONDigitizerV3::FindCorrespondingDigit(AliMUONDigit& digit, | |
480 | AliMUONData* data) | |
481 | { | |
482 | AliMUONDataIterator it(data,"D",AliMUONDataIterator::kAllChambers); | |
483 | AliMUONDigit* cd; | |
484 | ||
485 | while ( ( cd = static_cast<AliMUONDigit*>(it.Next()) ) ) | |
486 | { | |
487 | if ( cd->DetElemId() == digit.DetElemId() && | |
488 | cd->Hit() == digit.Hit() && | |
489 | cd->Cathode() != digit.Cathode() ) | |
490 | { | |
491 | return cd; | |
492 | } | |
493 | } | |
494 | return 0x0; | |
495 | } | |
496 | ||
497 | ||
92aeef15 | 498 | //_____________________________________________________________________________ |
499 | Int_t | |
4ce497c4 | 500 | AliMUONDigitizerV3::FindDigitIndex(TClonesArray& array, |
501 | const AliMUONDigit& digit) const | |
92aeef15 | 502 | { |
05314992 | 503 | // |
504 | // Return the index of digit within array, if that digit is there, | |
505 | // otherwise returns -1 | |
506 | // | |
92aeef15 | 507 | // FIXME: this is of course not the best implementation you can think of. |
05314992 | 508 | // Reconsider the use of hit/digit map... ? (but be sure it's needed!) |
509 | // | |
4ce497c4 | 510 | |
511 | fFindDigitIndexTimer.Start(kFALSE); | |
512 | ||
92aeef15 | 513 | Int_t n = array.GetEntriesFast(); |
514 | for ( Int_t i = 0; i < n; ++i ) | |
515 | { | |
516 | AliMUONDigit* d = static_cast<AliMUONDigit*>(array.UncheckedAt(i)); | |
517 | if ( d->DetElemId() == digit.DetElemId() && | |
518 | d->PadX() == digit.PadX() && | |
519 | d->PadY() == digit.PadY() && | |
520 | d->Cathode() == digit.Cathode() ) | |
521 | { | |
4ce497c4 | 522 | fFindDigitIndexTimer.Stop(); |
92aeef15 | 523 | return i; |
524 | } | |
525 | } | |
4ce497c4 | 526 | fFindDigitIndexTimer.Stop(); |
92aeef15 | 527 | return -1; |
528 | } | |
529 | ||
4ce497c4 | 530 | //_____________________________________________________________________________ |
531 | void | |
532 | AliMUONDigitizerV3::GenerateNoisyDigits() | |
533 | { | |
534 | // | |
535 | // According to a given probability, generate digits that | |
536 | // have a signal above the noise cut (ped+n*sigma_ped), i.e. digits | |
537 | // that are "only noise". | |
538 | // | |
539 | ||
540 | if ( !fNoiseFunction ) | |
541 | { | |
542 | fNoiseFunction = new TF1("AliMUONDigitizerV3::fNoiseFunction","gaus", | |
543 | fgkNSigmas,fgkNSigmas*10); | |
544 | ||
545 | fNoiseFunction->SetParameters(1,0,1); | |
546 | } | |
547 | ||
548 | fGenerateNoisyDigitsTimer.Start(kFALSE); | |
549 | ||
550 | for ( Int_t i = 0; i < AliMUONConstants::NTrackingCh(); ++i ) | |
551 | { | |
552 | AliMpDEIterator it; | |
553 | ||
554 | it.First(i); | |
555 | ||
556 | while ( !it.IsDone() ) | |
557 | { | |
558 | for ( Int_t cathode = 0; cathode < 2; ++cathode ) | |
559 | { | |
560 | GenerateNoisyDigitsForOneCathode(it.CurrentDE(),cathode); | |
561 | } | |
562 | it.Next(); | |
563 | } | |
564 | } | |
565 | ||
566 | fGenerateNoisyDigitsTimer.Stop(); | |
567 | } | |
568 | ||
569 | //_____________________________________________________________________________ | |
570 | void | |
571 | AliMUONDigitizerV3::GenerateNoisyDigitsForOneCathode(Int_t detElemId, Int_t cathode) | |
572 | { | |
573 | // | |
574 | // Generate noise-only digits for one cathode of one detection element. | |
575 | // Called by GenerateNoisyDigits() | |
576 | // | |
577 | ||
578 | TClonesArray* digits = fOutputData->Digits(detElemId/100-1); | |
579 | ||
580 | const AliMpVSegmentation* seg = Segmentation()->GetMpSegmentation(detElemId,cathode); | |
581 | Int_t nofPads = seg->NofPads(); | |
582 | ||
583 | Int_t maxIx = seg->MaxPadIndexX(); | |
584 | Int_t maxIy = seg->MaxPadIndexY(); | |
585 | ||
586 | static const Double_t probToBeOutsideNsigmas = 1 - TMath::Erf(fgkNSigmas/TMath::Sqrt(2.0)); | |
587 | ||
588 | Int_t nofNoisyPads = TMath::Nint(probToBeOutsideNsigmas*nofPads); | |
589 | if ( !nofNoisyPads ) return; | |
590 | ||
591 | nofNoisyPads = | |
592 | TMath::Nint(gRandom->Gaus(nofNoisyPads, | |
593 | nofNoisyPads/TMath::Sqrt(nofNoisyPads))); | |
594 | ||
595 | AliDebug(3,Form("DE %d cath %d nofNoisyPads %d",detElemId,cathode,nofNoisyPads)); | |
596 | ||
597 | for ( Int_t i = 0; i < nofNoisyPads; ++i ) | |
598 | { | |
599 | Int_t ix(-1); | |
600 | Int_t iy(-1); | |
601 | do { | |
602 | ix = gRandom->Integer(maxIx+1); | |
603 | iy = gRandom->Integer(maxIy+1); | |
604 | } while ( !seg->HasPad(AliMpIntPair(ix,iy)) ); | |
605 | AliMUONDigit d; | |
606 | d.SetDetElemId(detElemId); | |
607 | d.SetCathode(cathode); | |
608 | d.SetPadX(ix); | |
609 | d.SetPadY(iy); | |
610 | if ( FindDigitIndex(*digits,d) >= 0 ) | |
611 | { | |
612 | // this digit is already there, and not noise-only, we simply skip it | |
613 | continue; | |
614 | } | |
615 | AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy)); | |
616 | Int_t manuId = pad.GetLocation().GetFirst(); | |
617 | Int_t manuChannel = pad.GetLocation().GetSecond(); | |
618 | ||
619 | d.SetElectronics(manuId,manuChannel); | |
620 | ||
621 | AliMUONVCalibParam* pedestals = fCalibrationData->Pedestals(detElemId,manuId); | |
622 | ||
623 | Float_t pedestalMean = pedestals->ValueAsFloat(manuChannel,0); | |
624 | Float_t pedestalSigma = pedestals->ValueAsFloat(manuChannel,1); | |
625 | ||
626 | Double_t ped = fNoiseFunction->GetRandom()*pedestalSigma; | |
59b91539 | 627 | |
4ce497c4 | 628 | d.SetSignal(TMath::Nint(ped+pedestalMean+0.5)); |
59b91539 | 629 | d.SetPhysicsSignal(0); |
4ce497c4 | 630 | d.NoiseOnly(kTRUE); |
631 | AliDebug(3,Form("Adding a pure noise digit :")); | |
632 | StdoutToAliDebug(3,cout << "Before Response: " << endl; | |
633 | d.Print();); | |
634 | ApplyResponseToTrackerDigit(d,kFALSE); | |
635 | if ( d.Signal() > 0 ) | |
636 | { | |
637 | AddOrUpdateDigit(*digits,d); | |
638 | } | |
639 | else | |
640 | { | |
641 | AliError("Pure noise below threshold. This should not happen. Not adding " | |
642 | "this digit."); | |
643 | } | |
644 | StdoutToAliDebug(3,cout << "After Response: " << endl; | |
645 | d.Print();); | |
646 | } | |
647 | } | |
648 | ||
92aeef15 | 649 | //_____________________________________________________________________________ |
650 | AliMUONData* | |
651 | AliMUONDigitizerV3::GetDataAccess(const TString& folderName) | |
652 | { | |
05314992 | 653 | // |
654 | // Create an AliMUONData to deal with data found in folderName. | |
655 | // | |
92aeef15 | 656 | AliDebug(1,Form("Getting access to folder %s",folderName.Data())); |
657 | AliRunLoader* runLoader = AliRunLoader::GetRunLoader(folderName); | |
658 | if (!runLoader) | |
659 | { | |
660 | AliError(Form("Could not get RunLoader from folder %s",folderName.Data())); | |
661 | return 0x0; | |
662 | } | |
663 | AliLoader* loader = static_cast<AliLoader*>(runLoader->GetLoader("MUONLoader")); | |
664 | if (!loader) | |
665 | { | |
666 | AliError(Form("Could not get MuonLoader from folder %s",folderName.Data())); | |
667 | return 0x0; | |
668 | } | |
669 | AliMUONData* data = new AliMUONData(loader,"MUON","MUONDataForDigitOutput"); | |
670 | AliDebug(1,Form("AliMUONData=%p loader=%p",data,loader)); | |
671 | return data; | |
672 | } | |
673 | ||
674 | //_____________________________________________________________________________ | |
675 | Bool_t | |
676 | AliMUONDigitizerV3::Init() | |
677 | { | |
05314992 | 678 | // |
679 | // Initialization of the TTask : | |
680 | // a) set the outputData pointer | |
681 | // b) create the calibrationData, according to run number | |
682 | // c) create the trigger processing task | |
683 | // | |
92aeef15 | 684 | AliDebug(1,""); |
685 | ||
686 | if ( fIsInitialized ) | |
687 | { | |
688 | AliError("Object already initialized."); | |
689 | return kFALSE; | |
690 | } | |
691 | ||
692 | if (!fManager) | |
693 | { | |
694 | AliError("fManager is null !"); | |
695 | return kFALSE; | |
696 | } | |
697 | ||
698 | fOutputData = GetDataAccess(fManager->GetOutputFolderName()); | |
699 | if (!fOutputData) | |
700 | { | |
701 | AliError("Can not perform digitization. I'm sorry"); | |
702 | return kFALSE; | |
703 | } | |
704 | AliDebug(1,Form("fOutputData=%p",fOutputData)); | |
705 | ||
706 | AliRunLoader* runLoader = fOutputData->GetLoader()->GetRunLoader(); | |
707 | AliRun* galice = runLoader->GetAliRun(); | |
708 | Int_t runnumber = galice->GetRunNumber(); | |
709 | ||
710 | fCalibrationData = new AliMUONCalibrationData(runnumber); | |
711 | ||
712 | switch (fTriggerCodeVersion) | |
713 | { | |
714 | case kTriggerDecision: | |
715 | fTriggerProcessor = new AliMUONTriggerDecisionV1(fOutputData); | |
716 | break; | |
717 | case kTriggerElectronics: | |
4ce497c4 | 718 | fTriggerProcessor = new AliMUONTriggerElectronics(fOutputData,fCalibrationData); |
92aeef15 | 719 | break; |
720 | default: | |
721 | AliFatal("Unknown trigger processor type"); | |
722 | break; | |
723 | } | |
4f8a3d8b | 724 | AliDebug(1,Form("Using the following trigger code %s - %s", |
725 | fTriggerProcessor->GetName(),fTriggerProcessor->GetTitle())); | |
4ce497c4 | 726 | |
727 | if ( fUseTriggerEfficiency ) | |
728 | { | |
729 | fTriggerEfficiency = fCalibrationData->TriggerEfficiency(); | |
730 | if ( fTriggerEfficiency ) | |
731 | { | |
732 | AliInfo("Will apply trigger efficiency"); | |
733 | } | |
734 | else | |
735 | { | |
736 | AliError("I was requested to apply trigger efficiency, but I could " | |
737 | "not get it !"); | |
738 | } | |
739 | } | |
740 | ||
741 | if ( fGenerateNoisyDigits ) | |
742 | { | |
743 | AliInfo("Will generate noise-only digits for tracker"); | |
744 | } | |
745 | ||
92aeef15 | 746 | fIsInitialized = kTRUE; |
747 | return kTRUE; | |
748 | } | |
749 | ||
750 | //_____________________________________________________________________________ | |
751 | Bool_t | |
05314992 | 752 | AliMUONDigitizerV3::MergeDigits(const AliMUONDigit& src, |
753 | AliMUONDigit& srcAndDest) | |
92aeef15 | 754 | { |
05314992 | 755 | // |
756 | // Merge 2 digits (src and srcAndDest) into srcAndDest. | |
757 | // | |
92aeef15 | 758 | AliDebug(1,"Merging the following digits:"); |
05314992 | 759 | StdoutToAliDebug(1,src.Print("tracks");); |
760 | StdoutToAliDebug(1,srcAndDest.Print("tracks");); | |
92aeef15 | 761 | |
762 | Bool_t check = ( src.DetElemId() == srcAndDest.DetElemId() && | |
763 | src.PadX() == srcAndDest.PadX() && | |
764 | src.PadY() == srcAndDest.PadY() && | |
765 | src.Cathode() == srcAndDest.Cathode() ); | |
766 | if (!check) | |
767 | { | |
768 | return kFALSE; | |
769 | } | |
770 | ||
92aeef15 | 771 | srcAndDest.AddSignal(src.Signal()); |
772 | srcAndDest.AddPhysicsSignal(src.Physics()); | |
05314992 | 773 | for ( Int_t i = 0; i < src.Ntracks(); ++i ) |
774 | { | |
775 | srcAndDest.AddTrack(src.Track(i),src.TrackCharge(i)); | |
776 | } | |
777 | StdoutToAliDebug(1,cout << "result:"; srcAndDest.Print("tracks");); | |
92aeef15 | 778 | return kTRUE; |
779 | } | |
780 | ||
781 | //_____________________________________________________________________________ | |
782 | void | |
783 | AliMUONDigitizerV3::MergeWithSDigits(AliMUONData& outputData, | |
05314992 | 784 | const AliMUONData& inputData, Int_t mask) |
92aeef15 | 785 | { |
05314992 | 786 | // |
787 | // Merge the sdigits in inputData with the digits already present in outputData | |
788 | // | |
92aeef15 | 789 | AliDebug(1,""); |
790 | ||
791 | for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich ) | |
792 | { | |
793 | TClonesArray* iDigits = inputData.SDigits(ich); | |
794 | TClonesArray* oDigits = outputData.Digits(ich); | |
795 | if (!iDigits) | |
796 | { | |
797 | AliError(Form("Could not get sdigits for ich=%d",ich)); | |
798 | return; | |
799 | } | |
800 | Int_t nSDigits = iDigits->GetEntriesFast(); | |
801 | for ( Int_t k = 0; k < nSDigits; ++k ) | |
802 | { | |
803 | AliMUONDigit* sdigit = static_cast<AliMUONDigit*>(iDigits->UncheckedAt(k)); | |
92aeef15 | 804 | if (!sdigit) |
805 | { | |
806 | AliError(Form("Could not get sdigit for ich=%d and k=%d",ich,k)); | |
807 | } | |
808 | else | |
809 | { | |
05314992 | 810 | // Update the track references using the mask. |
811 | // FIXME: this is dirty, for backward compatibility only. | |
812 | // Should re-design all this way of keeping track of MC information... | |
813 | if ( mask ) sdigit->PatchTracks(mask); | |
814 | // Then add or update the digit to the output. | |
92aeef15 | 815 | AddOrUpdateDigit(*oDigits,*sdigit); |
816 | } | |
817 | } | |
818 | } | |
819 | } |