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