]>
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" |
92aeef15 | 23 | #include "AliMUONConstants.h" |
92aeef15 | 24 | #include "AliMUONDigit.h" |
ad26d4f6 | 25 | #include "AliMUONLogger.h" |
4f8a3d8b | 26 | #include "AliMUONTriggerElectronics.h" |
40e382ae | 27 | #include "AliMUONTriggerStoreV1.h" |
05314992 | 28 | #include "AliMUONVCalibParam.h" |
40e382ae | 29 | #include "AliMUONVDigitStore.h" |
331a617a | 30 | #include "AliMUONGeometryTransformer.h" //ADDED for trigger noise |
31 | ||
88544f7e | 32 | #include "AliMpCDB.h" |
331a617a | 33 | #include "AliMpSegmentation.h" |
40e382ae | 34 | #include "AliMpCathodType.h" |
35 | #include "AliMpConstants.h" | |
4ce497c4 | 36 | #include "AliMpDEIterator.h" |
92aeef15 | 37 | #include "AliMpDEManager.h" |
4ce497c4 | 38 | #include "AliMpPad.h" |
40e382ae | 39 | #include "AliMpStationType.h" |
4ce497c4 | 40 | #include "AliMpVSegmentation.h" |
331a617a | 41 | |
42 | #include "AliCDBManager.h" | |
43 | #include "AliCodeTimer.h" | |
44 | #include "AliLog.h" | |
92aeef15 | 45 | #include "AliRun.h" |
46 | #include "AliRunDigitizer.h" | |
47 | #include "AliRunLoader.h" | |
331a617a | 48 | |
866c3232 | 49 | #include <Riostream.h> |
50 | #include <TF1.h> | |
40e382ae | 51 | #include <TFile.h> |
866c3232 | 52 | #include <TMath.h> |
53 | #include <TRandom.h> | |
54 | #include <TString.h> | |
40e382ae | 55 | #include <TSystem.h> |
56 | ||
3d1463c8 | 57 | //----------------------------------------------------------------------------- |
9265505b | 58 | /// \class AliMUONDigitizerV3 |
4ce497c4 | 59 | /// The digitizer is performing the transformation to go from SDigits (digits |
60 | /// w/o any electronic noise) to Digits (w/ electronic noise, and decalibration) | |
61 | /// | |
62 | /// The decalibration is performed by doing the reverse operation of the | |
63 | /// calibration, that is we do (Signal+pedestal)/gain -> ADC | |
64 | /// | |
65 | /// Note also that the digitizer takes care of merging sdigits that belongs | |
66 | /// to the same pad, either because we're merging several input sdigit files | |
67 | /// or with a single file because the sdigitizer does not merge sdigits itself | |
68 | /// (for performance reason mainly, and because anyway we know we have to do it | |
69 | /// here, at the digitization level). | |
70 | /// | |
c4ee792d | 71 | /// \author Laurent Aphecetche |
3d1463c8 | 72 | //----------------------------------------------------------------------------- |
4ce497c4 | 73 | |
74 | namespace | |
75 | { | |
76 | AliMUON* muon() | |
77 | { | |
78 | return static_cast<AliMUON*>(gAlice->GetModule("MUON")); | |
79 | } | |
8c0b5e70 | 80 | |
81 | //ADDED for trigger noise | |
82 | const AliMUONGeometryTransformer* GetTransformer() | |
83 | { | |
84 | return muon()->GetGeometryTransformer(); | |
85 | } | |
4ce497c4 | 86 | } |
87 | ||
88 | const Double_t AliMUONDigitizerV3::fgkNSigmas=3; | |
89 | ||
9265505b | 90 | /// \cond CLASSIMP |
92aeef15 | 91 | ClassImp(AliMUONDigitizerV3) |
9265505b | 92 | /// \endcond |
92aeef15 | 93 | |
94 | //_____________________________________________________________________________ | |
95 | AliMUONDigitizerV3::AliMUONDigitizerV3(AliRunDigitizer* manager, | |
8c0b5e70 | 96 | Int_t generateNoisyDigits) |
92aeef15 | 97 | : AliDigitizer(manager), |
92aeef15 | 98 | fIsInitialized(kFALSE), |
92aeef15 | 99 | fCalibrationData(0x0), |
100 | fTriggerProcessor(0x0), | |
8c0b5e70 | 101 | fNoiseFunctionTrig(0x0), |
ec9acc85 | 102 | fGenerateNoisyDigits(generateNoisyDigits), |
103 | fLogger(new AliMUONLogger(1000)), | |
40e382ae | 104 | fTriggerStore(new AliMUONTriggerStoreV1), |
105 | fDigitStore(0x0), | |
9ec6a948 | 106 | fOutputDigitStore(0x0), |
107 | fInputDigitStore(0x0) | |
92aeef15 | 108 | { |
9265505b | 109 | /// Ctor. |
110 | ||
92aeef15 | 111 | AliDebug(1,Form("AliRunDigitizer=%p",fManager)); |
ec9acc85 | 112 | |
92aeef15 | 113 | } |
114 | ||
115 | //_____________________________________________________________________________ | |
116 | AliMUONDigitizerV3::~AliMUONDigitizerV3() | |
117 | { | |
9265505b | 118 | /// Dtor. Note we're the owner of some pointers. |
119 | ||
92aeef15 | 120 | AliDebug(1,"dtor"); |
4ce497c4 | 121 | |
92c23b09 | 122 | // delete fCalibrationData; |
92aeef15 | 123 | delete fTriggerProcessor; |
8c0b5e70 | 124 | delete fNoiseFunctionTrig; |
40e382ae | 125 | delete fTriggerStore; |
126 | delete fDigitStore; | |
127 | delete fOutputDigitStore; | |
9ec6a948 | 128 | delete fInputDigitStore; |
129 | ||
ad26d4f6 | 130 | AliInfo("Summary of messages"); |
131 | fLogger->Print(); | |
4ce497c4 | 132 | |
ad26d4f6 | 133 | delete fLogger; |
92aeef15 | 134 | } |
135 | ||
136 | //_____________________________________________________________________________ | |
137 | void | |
40e382ae | 138 | AliMUONDigitizerV3::ApplyResponseToTrackerDigit(AliMUONVDigit& digit, Bool_t addNoise) |
92aeef15 | 139 | { |
9265505b | 140 | /// For tracking digits, starting from an ideal digit's charge, we : |
141 | /// | |
cf27231a | 142 | /// - "divide" by a gain (thus decalibrating the digit) |
9265505b | 143 | /// - add a pedestal (thus decalibrating the digit) |
b74ca120 | 144 | /// - add some electronics noise (thus leading to a realistic adc), if requested to do so |
9265505b | 145 | /// - sets the signal to zero if below 3*sigma of the noise |
59b91539 | 146 | |
cf27231a | 147 | Float_t charge = digit.Charge(); |
148 | ||
149 | // We set the charge to 0, as the only relevant piece of information | |
150 | // after Digitization is the ADC value. | |
151 | digit.SetCharge(0); | |
b74ca120 | 152 | |
4ce497c4 | 153 | Int_t detElemId = digit.DetElemId(); |
92aeef15 | 154 | Int_t manuId = digit.ManuId(); |
92aeef15 | 155 | |
4ce497c4 | 156 | AliMUONVCalibParam* pedestal = fCalibrationData->Pedestals(detElemId,manuId); |
92aeef15 | 157 | if (!pedestal) |
ad26d4f6 | 158 | { |
159 | fLogger->Log(Form("%s:%d:Could not get pedestal for DE=%4d manuId=%4d. Disabling.", | |
160 | __FILE__,__LINE__, | |
161 | detElemId,manuId)); | |
ad26d4f6 | 162 | digit.SetADC(0); |
163 | return; | |
164 | } | |
59b91539 | 165 | |
627ba19f | 166 | Int_t manuChannel = digit.ManuChannel(); |
167 | ||
168 | if ( pedestal->ValueAsFloat(manuChannel,0) == AliMUONVCalibParam::InvalidFloatValue() || | |
169 | pedestal->ValueAsFloat(manuChannel,1) == AliMUONVCalibParam::InvalidFloatValue() ) | |
170 | { | |
171 | // protection against invalid pedestal value | |
172 | digit.SetADC(0); | |
173 | return; | |
174 | } | |
175 | ||
4ce497c4 | 176 | AliMUONVCalibParam* gain = fCalibrationData->Gains(detElemId,manuId); |
92aeef15 | 177 | if (!gain) |
ad26d4f6 | 178 | { |
179 | fLogger->Log(Form("%s:%d:Could not get gain for DE=%4d manuId=%4d. Disabling.", | |
180 | __FILE__,__LINE__, | |
181 | detElemId,manuId)); | |
ad26d4f6 | 182 | digit.SetADC(0); |
183 | return; | |
184 | } | |
cf27231a | 185 | |
ec9acc85 | 186 | Int_t adc = DecalibrateTrackerDigit(*pedestal,*gain,manuChannel,charge,addNoise, |
187 | digit.IsNoiseOnly()); | |
59b91539 | 188 | |
92aeef15 | 189 | digit.SetADC(adc); |
190 | } | |
191 | ||
192 | //_____________________________________________________________________________ | |
193 | void | |
40e382ae | 194 | AliMUONDigitizerV3::ApplyResponse(const AliMUONVDigitStore& store, |
195 | AliMUONVDigitStore& filteredStore) | |
92aeef15 | 196 | { |
9265505b | 197 | /// Loop over all chamber digits, and apply the response to them |
198 | /// Note that this method may remove digits. | |
199 | ||
40e382ae | 200 | filteredStore.Clear(); |
201 | ||
4ce497c4 | 202 | const Bool_t kAddNoise = kTRUE; |
203 | ||
40e382ae | 204 | TIter next(store.CreateIterator()); |
205 | AliMUONVDigit* digit; | |
206 | ||
207 | while ( ( digit = static_cast<AliMUONVDigit*>(next()) ) ) | |
4ce497c4 | 208 | { |
40e382ae | 209 | AliMp::StationType stationType = AliMpDEManager::GetStationType(digit->DetElemId()); |
210 | ||
211 | if ( stationType != AliMp::kStationTrigger ) | |
92aeef15 | 212 | { |
40e382ae | 213 | ApplyResponseToTrackerDigit(*digit,kAddNoise); |
92aeef15 | 214 | } |
7d7d22a6 | 215 | |
cf27231a | 216 | if ( digit->ADC() > 0 || digit->Charge() > 0 ) |
40e382ae | 217 | { |
218 | filteredStore.Add(*digit,AliMUONVDigitStore::kIgnore); | |
92aeef15 | 219 | } |
92aeef15 | 220 | } |
40e382ae | 221 | } |
92aeef15 | 222 | |
b74ca120 | 223 | //_____________________________________________________________________________ |
224 | Int_t | |
225 | AliMUONDigitizerV3::DecalibrateTrackerDigit(const AliMUONVCalibParam& pedestals, | |
226 | const AliMUONVCalibParam& gains, | |
227 | Int_t channel, | |
228 | Float_t charge, | |
ec9acc85 | 229 | Bool_t addNoise, |
230 | Bool_t noiseOnly) | |
b74ca120 | 231 | { |
232 | /// Decalibrate (i.e. go from charge to adc) a tracker digit, given its | |
233 | /// pedestal and gain parameters. | |
234 | /// Must insure before calling that channel is valid (i.e. between 0 and | |
235 | /// pedestals or gains->GetSize()-1, but also corresponding to a valid channel | |
236 | /// otherwise results are not predictible...) | |
237 | ||
238 | static const Int_t kMaxADC = (1<<12)-1; // We code the charge on a 12 bits ADC. | |
239 | ||
240 | Float_t pedestalMean = pedestals.ValueAsFloat(channel,0); | |
241 | Float_t pedestalSigma = pedestals.ValueAsFloat(channel,1); | |
242 | ||
ec9acc85 | 243 | AliDebugClass(1,Form("DE %04d MANU %04d CH %02d PEDMEAN %7.2f PEDSIGMA %7.2f", |
244 | pedestals.ID0(),pedestals.ID1(),channel,pedestalMean,pedestalSigma)); | |
245 | ||
b74ca120 | 246 | Float_t a0 = gains.ValueAsFloat(channel,0); |
247 | Float_t a1 = gains.ValueAsFloat(channel,1); | |
248 | Int_t thres = gains.ValueAsInt(channel,2); | |
249 | Int_t qual = gains.ValueAsInt(channel,3); | |
250 | if ( qual <= 0 ) return 0; | |
251 | ||
252 | Float_t chargeThres = a0*thres; | |
253 | ||
254 | Float_t padc(0); // (adc - ped) value | |
255 | ||
256 | if ( charge <= chargeThres || TMath::Abs(a1) < 1E-12 ) | |
257 | { | |
258 | // linear part only | |
259 | ||
260 | if ( TMath::Abs(a0) > 1E-12 ) | |
261 | { | |
262 | padc = charge/a0; | |
263 | } | |
264 | } | |
265 | else | |
266 | { | |
267 | // linear + parabolic part | |
268 | Double_t qt = chargeThres - charge; | |
269 | Double_t delta = a0*a0-4*a1*qt; | |
270 | if ( delta < 0 ) | |
271 | { | |
272 | AliErrorClass(Form("delta=%e DE %d Manu %d Channel %d " | |
273 | " charge %e a0 %e a1 %e thres %d ped %e pedsig %e", | |
274 | delta,pedestals.ID0(),pedestals.ID1(), | |
275 | channel, charge, a0, a1, thres, pedestalMean, | |
276 | pedestalSigma)); | |
277 | } | |
278 | else | |
279 | { | |
280 | delta = TMath::Sqrt(delta); | |
281 | ||
282 | padc = ( ( -a0 + delta ) > 0 ? ( -a0 + delta ) : ( -a0 - delta ) ); | |
283 | ||
284 | padc /= 2*a1; | |
285 | ||
286 | if ( padc < 0 ) | |
287 | { | |
288 | if ( TMath::Abs(padc) > 1E-3) | |
289 | { | |
290 | // this is more than a precision problem : let's signal it ! | |
291 | AliErrorClass(Form("padc=%e DE %d Manu %d Channel %d " | |
292 | " charge %e a0 %e a1 %e thres %d ped %e pedsig %e delta %e", | |
293 | padc,pedestals.ID0(),pedestals.ID1(), | |
294 | channel, charge, a0, a1, thres, pedestalMean, | |
295 | pedestalSigma,delta)); | |
296 | } | |
297 | ||
298 | // ok. consider we're just at thres, let it be zero. | |
299 | padc = 0; | |
300 | } | |
301 | ||
302 | padc += thres; | |
303 | ||
304 | } | |
305 | } | |
306 | ||
307 | Int_t adc(0); | |
308 | ||
ec9acc85 | 309 | Float_t adcNoise = 0.0; |
b74ca120 | 310 | |
ec9acc85 | 311 | if ( addNoise ) |
312 | { | |
313 | if ( noiseOnly ) | |
314 | { | |
315 | adcNoise = NoiseFunction()->GetRandom()*pedestalSigma; | |
316 | } | |
317 | else | |
318 | { | |
319 | adcNoise = gRandom->Gaus(0.0,pedestalSigma); | |
320 | } | |
321 | } | |
b74ca120 | 322 | |
ec9acc85 | 323 | adc = TMath::Nint(padc + pedestalMean + adcNoise + 0.5); |
324 | ||
325 | if ( adc < TMath::Nint(pedestalMean + fgkNSigmas*pedestalSigma + 0.5) ) | |
326 | { | |
327 | adc = 0; | |
b74ca120 | 328 | } |
329 | ||
330 | // be sure we stick to 12 bits. | |
331 | if ( adc > kMaxADC ) | |
332 | { | |
333 | adc = kMaxADC; | |
334 | } | |
335 | ||
336 | return adc; | |
337 | } | |
338 | ||
9ec6a948 | 339 | //_____________________________________________________________________________ |
340 | void | |
341 | AliMUONDigitizerV3::CreateInputDigitStore() | |
342 | { | |
343 | /// Create an input digit store, and check that all input files | |
344 | /// actually contains the same type of AliMUONVDigitStore | |
345 | ||
346 | fInputDigitStore = 0x0; | |
347 | ||
348 | for ( Int_t iFile = 0; iFile < fManager->GetNinputs(); ++iFile ) | |
349 | { | |
350 | AliLoader* inputLoader = GetLoader(fManager->GetInputFolderName(iFile)); | |
351 | ||
352 | inputLoader->LoadSDigits("READ"); | |
353 | ||
354 | TTree* iTreeS = inputLoader->TreeS(); | |
355 | if (!iTreeS) | |
356 | { | |
357 | AliFatal(Form("Could not get access to input file #%d",iFile)); | |
358 | } | |
359 | ||
360 | AliMUONVDigitStore* inputStore = AliMUONVDigitStore::Create(*iTreeS); | |
361 | ||
362 | if (!fInputDigitStore) | |
363 | { | |
364 | fInputDigitStore = inputStore; | |
365 | } | |
366 | else | |
367 | { | |
368 | if ( inputStore->IsA() != fInputDigitStore->IsA() ) | |
369 | { | |
370 | AliFatal("Got different types of AliMUONVDigitStore here. Please implement me."); | |
371 | } | |
372 | } | |
373 | } | |
374 | } | |
375 | ||
92aeef15 | 376 | //_____________________________________________________________________________ |
377 | void | |
378 | AliMUONDigitizerV3::Exec(Option_t*) | |
379 | { | |
9265505b | 380 | /// Main method. |
381 | /// We first loop over input files, and merge the sdigits we found there. | |
382 | /// Second, we digitize all the resulting sdigits | |
383 | /// Then we generate noise-only digits (for tracker only) | |
384 | /// And we finally generate the trigger outputs. | |
4ce497c4 | 385 | |
99c136e1 | 386 | AliCodeTimerAuto("",0) |
b74ca120 | 387 | |
92aeef15 | 388 | AliDebug(1, "Running digitizer."); |
389 | ||
390 | if ( fManager->GetNinputs() == 0 ) | |
391 | { | |
392 | AliWarning("No input set. Nothing to do."); | |
393 | return; | |
394 | } | |
395 | ||
396 | if ( !fIsInitialized ) | |
397 | { | |
398 | AliError("Not initialized. Cannot perform the work. Sorry"); | |
399 | return; | |
400 | } | |
401 | ||
402 | Int_t nInputFiles = fManager->GetNinputs(); | |
403 | ||
40e382ae | 404 | AliLoader* outputLoader = GetLoader(fManager->GetOutputFolderName()); |
405 | ||
406 | outputLoader->MakeDigitsContainer(); | |
407 | ||
408 | TTree* oTreeD = outputLoader->TreeD(); | |
409 | ||
410 | if (!oTreeD) | |
92aeef15 | 411 | { |
40e382ae | 412 | AliFatal("Cannot create output TreeD"); |
92aeef15 | 413 | } |
40e382ae | 414 | |
92aeef15 | 415 | // Loop over all the input files, and merge the sdigits found in those |
416 | // files. | |
40e382ae | 417 | |
92aeef15 | 418 | for ( Int_t iFile = 0; iFile < nInputFiles; ++iFile ) |
419 | { | |
40e382ae | 420 | AliLoader* inputLoader = GetLoader(fManager->GetInputFolderName(iFile)); |
421 | ||
422 | inputLoader->LoadSDigits("READ"); | |
423 | ||
424 | TTree* iTreeS = inputLoader->TreeS(); | |
425 | if (!iTreeS) | |
92aeef15 | 426 | { |
427 | AliFatal(Form("Could not get access to input file #%d",iFile)); | |
428 | } | |
9ec6a948 | 429 | |
430 | if (!fInputDigitStore) | |
431 | { | |
432 | CreateInputDigitStore(); | |
433 | } | |
434 | fInputDigitStore->Connect(*iTreeS); | |
40e382ae | 435 | |
436 | iTreeS->GetEvent(0); | |
437 | ||
9ec6a948 | 438 | MergeWithSDigits(fDigitStore,*fInputDigitStore,fManager->GetMask(iFile)); |
05314992 | 439 | |
40e382ae | 440 | inputLoader->UnloadSDigits(); |
05314992 | 441 | |
9ec6a948 | 442 | fInputDigitStore->Clear(); |
92aeef15 | 443 | } |
444 | ||
445 | // At this point, we do have digit arrays (one per chamber) which contains | |
446 | // the merging of all the sdigits of the input file(s). | |
447 | // We now massage them to apply the detector response, i.e. this | |
448 | // is here that we do the "digitization" work. | |
449 | ||
40e382ae | 450 | if (!fOutputDigitStore) |
451 | { | |
452 | fOutputDigitStore = fDigitStore->Create(); | |
453 | } | |
454 | ||
8c0b5e70 | 455 | if ( fGenerateNoisyDigits>=2 ) |
456 | { | |
457 | // Generate noise-only digits for trigger. | |
458 | GenerateNoisyDigitsForTrigger(*fDigitStore); | |
459 | } | |
460 | ||
40e382ae | 461 | ApplyResponse(*fDigitStore,*fOutputDigitStore); |
4ce497c4 | 462 | |
463 | if ( fGenerateNoisyDigits ) | |
464 | { | |
465 | // Generate noise-only digits for tracker. | |
40e382ae | 466 | GenerateNoisyDigits(*fOutputDigitStore); |
4ce497c4 | 467 | } |
468 | ||
92aeef15 | 469 | // We generate the global and local trigger decisions. |
40e382ae | 470 | fTriggerProcessor->Digits2Trigger(*fOutputDigitStore,*fTriggerStore); |
471 | ||
472 | // Prepare output tree | |
473 | Bool_t okD = fOutputDigitStore->Connect(*oTreeD,kFALSE); | |
474 | Bool_t okT = fTriggerStore->Connect(*oTreeD,kFALSE); | |
475 | if (!okD || !okT) | |
476 | { | |
477 | AliError(Form("Could not make branch : Digit %d Trigger %d",okD,okT)); | |
478 | return; | |
479 | } | |
92aeef15 | 480 | |
481 | // Fill the output treeD | |
40e382ae | 482 | oTreeD->Fill(); |
92aeef15 | 483 | |
484 | // Write to the output tree(D). | |
485 | // Please note that as GlobalTrigger, LocalTrigger and Digits are in the same | |
486 | // tree (=TreeD) in different branches, this WriteDigits in fact writes all of | |
487 | // the 3 branches. | |
40e382ae | 488 | outputLoader->WriteDigits("OVERWRITE"); |
92aeef15 | 489 | |
40e382ae | 490 | outputLoader->UnloadDigits(); |
4ce497c4 | 491 | |
40e382ae | 492 | // Finally, we clean up after ourselves. |
493 | fTriggerStore->Clear(); | |
494 | fDigitStore->Clear(); | |
495 | fOutputDigitStore->Clear(); | |
92aeef15 | 496 | } |
497 | ||
4ce497c4 | 498 | |
4ce497c4 | 499 | //_____________________________________________________________________________ |
500 | void | |
40e382ae | 501 | AliMUONDigitizerV3::GenerateNoisyDigits(AliMUONVDigitStore& digitStore) |
4ce497c4 | 502 | { |
9265505b | 503 | /// According to a given probability, generate digits that |
504 | /// have a signal above the noise cut (ped+n*sigma_ped), i.e. digits | |
505 | /// that are "only noise". | |
4ce497c4 | 506 | |
99c136e1 | 507 | AliCodeTimerAuto("",0) |
b74ca120 | 508 | |
4ce497c4 | 509 | for ( Int_t i = 0; i < AliMUONConstants::NTrackingCh(); ++i ) |
510 | { | |
511 | AliMpDEIterator it; | |
512 | ||
513 | it.First(i); | |
514 | ||
515 | while ( !it.IsDone() ) | |
516 | { | |
517 | for ( Int_t cathode = 0; cathode < 2; ++cathode ) | |
518 | { | |
40e382ae | 519 | GenerateNoisyDigitsForOneCathode(digitStore,it.CurrentDEId(),cathode); |
4ce497c4 | 520 | } |
521 | it.Next(); | |
522 | } | |
523 | } | |
4ce497c4 | 524 | } |
525 | ||
526 | //_____________________________________________________________________________ | |
527 | void | |
40e382ae | 528 | AliMUONDigitizerV3::GenerateNoisyDigitsForOneCathode(AliMUONVDigitStore& digitStore, |
529 | Int_t detElemId, Int_t cathode) | |
4ce497c4 | 530 | { |
9265505b | 531 | /// Generate noise-only digits for one cathode of one detection element. |
532 | /// Called by GenerateNoisyDigits() | |
4ce497c4 | 533 | |
9265505b | 534 | const AliMpVSegmentation* seg |
866c3232 | 535 | = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode)); |
4ce497c4 | 536 | Int_t nofPads = seg->NofPads(); |
537 | ||
538 | Int_t maxIx = seg->MaxPadIndexX(); | |
539 | Int_t maxIy = seg->MaxPadIndexY(); | |
540 | ||
cdea095e | 541 | static const Double_t kProbToBeOutsideNsigmas = TMath::Erfc(fgkNSigmas/TMath::Sqrt(2.0)) / 2. ; |
4ce497c4 | 542 | |
84aac932 | 543 | Int_t nofNoisyPads = TMath::Nint(kProbToBeOutsideNsigmas*nofPads); |
4ce497c4 | 544 | if ( !nofNoisyPads ) return; |
545 | ||
546 | nofNoisyPads = | |
547 | TMath::Nint(gRandom->Gaus(nofNoisyPads, | |
548 | nofNoisyPads/TMath::Sqrt(nofNoisyPads))); | |
549 | ||
550 | AliDebug(3,Form("DE %d cath %d nofNoisyPads %d",detElemId,cathode,nofNoisyPads)); | |
551 | ||
40e382ae | 552 | for ( Int_t i = 0; i < nofNoisyPads; ++i ) |
4ce497c4 | 553 | { |
554 | Int_t ix(-1); | |
555 | Int_t iy(-1); | |
40e382ae | 556 | AliMpPad pad; |
557 | ||
4ce497c4 | 558 | do { |
559 | ix = gRandom->Integer(maxIx+1); | |
560 | iy = gRandom->Integer(maxIy+1); | |
168e9c4d | 561 | pad = seg->PadByIndices(ix,iy,kFALSE); |
40e382ae | 562 | } while ( !pad.IsValid() ); |
563 | ||
168e9c4d | 564 | Int_t manuId = pad.GetManuId(); |
565 | Int_t manuChannel = pad.GetManuChannel(); | |
40e382ae | 566 | |
4ce497c4 | 567 | AliMUONVCalibParam* pedestals = fCalibrationData->Pedestals(detElemId,manuId); |
568 | ||
ad26d4f6 | 569 | if (!pedestals) |
570 | { | |
571 | // no pedestal available for this channel, simply give up | |
40e382ae | 572 | continue; |
ad26d4f6 | 573 | } |
574 | ||
40e382ae | 575 | AliMUONVDigit* d = digitStore.CreateDigit(detElemId,manuId,manuChannel,cathode); |
576 | ||
577 | d->SetPadXY(ix,iy); | |
578 | ||
ec9acc85 | 579 | d->SetCharge(0.0); // charge is zero, the ApplyResponseToTrackerDigit will add the noise |
40e382ae | 580 | d->NoiseOnly(kTRUE); |
ec9acc85 | 581 | ApplyResponseToTrackerDigit(*d,kTRUE); |
cf27231a | 582 | if ( d->ADC() > 0 ) |
4ce497c4 | 583 | { |
40e382ae | 584 | Bool_t ok = digitStore.Add(*d,AliMUONVDigitStore::kDeny); |
585 | // this can happen (that we randomly chose a digit that is | |
586 | // already there). We simply ignore this, but log the occurence | |
587 | // to cross-check that it's not too frequent. | |
588 | if (!ok) | |
589 | { | |
590 | fLogger->Log("Collision while adding noiseOnly digit"); | |
591 | } | |
592 | else | |
593 | { | |
594 | fLogger->Log("Added noiseOnly digit"); | |
595 | } | |
4ce497c4 | 596 | } |
40e382ae | 597 | delete d; |
4ce497c4 | 598 | } |
599 | } | |
600 | ||
8c0b5e70 | 601 | |
602 | //_____________________________________________________________________________ | |
603 | void | |
604 | AliMUONDigitizerV3::GenerateNoisyDigitsForTrigger(AliMUONVDigitStore& digitStore) | |
605 | { | |
606 | /// Generate noise-only digits for one cathode of one detection element. | |
607 | /// Called by GenerateNoisyDigits() | |
608 | ||
609 | if ( !fNoiseFunctionTrig ) | |
610 | { | |
611 | fNoiseFunctionTrig = new TF1("AliMUONDigitizerV3::fNoiseFunctionTrig","landau", | |
612 | 50.,270.); | |
613 | ||
614 | fNoiseFunctionTrig->SetParameters(3.91070e+02, 9.85026, 9.35881e-02); | |
615 | } | |
616 | ||
617 | AliMpPad pad[2]; | |
618 | AliMUONVDigit *d[2]={0x0}; | |
619 | ||
620 | for ( Int_t chamberId = AliMUONConstants::NTrackingCh(); chamberId < AliMUONConstants::NCh(); ++chamberId ) | |
621 | { | |
622 | ||
623 | Int_t nofNoisyPads = 50; | |
624 | ||
625 | Float_t r=-1, fi = 0., gx, gy, x, y, z, xg01, yg01, zg, xg02, yg02; | |
626 | AliMpDEIterator it; | |
627 | ||
628 | AliDebug(3,Form("Chamber %d nofNoisyPads %d",chamberId,nofNoisyPads)); | |
629 | ||
630 | for ( Int_t i = 0; i < nofNoisyPads; ++i ) | |
631 | { | |
632 | //printf("Generating noise %i\n",i); | |
633 | Int_t ix(-1); | |
634 | Int_t iy(-1); | |
635 | Bool_t isOk = kFALSE; | |
636 | Int_t detElemId = -1; | |
637 | do { | |
638 | //r = gRandom->Landau(9.85026, 9.35881e-02); | |
639 | r = fNoiseFunctionTrig->GetRandom(); | |
640 | fi = 2. * TMath::Pi() * gRandom->Rndm(); | |
641 | //printf("r = %f\tfi = %f\n", r, fi); | |
642 | gx = r * TMath::Cos(fi); | |
643 | gy = r * TMath::Sin(fi); | |
644 | ||
645 | for ( it.First(chamberId); ! it.IsDone(); it.Next() ){ | |
646 | Int_t currDetElemId = it.CurrentDEId(); | |
647 | const AliMpVSegmentation* seg | |
648 | = AliMpSegmentation::Instance()->GetMpSegmentation(currDetElemId,AliMp::GetCathodType(0)); | |
649 | if (!seg) continue; | |
6e97fbb8 | 650 | Float_t deltax = seg->GetDimensionX(); |
651 | Float_t deltay = seg->GetDimensionY(); | |
8c0b5e70 | 652 | GetTransformer()->Local2Global(currDetElemId, -deltax, -deltay, 0, xg01, yg01, zg); |
653 | GetTransformer()->Local2Global(currDetElemId, deltax, deltay, 0, xg02, yg02, zg); | |
654 | Float_t xg1 = xg01, xg2 = xg02, yg1 = yg01, yg2 = yg02; | |
655 | if(xg01>xg02){ | |
656 | xg1 = xg02; | |
657 | xg2 = xg01; | |
658 | } | |
659 | if(yg01>yg02){ | |
660 | yg1 = yg02; | |
661 | yg2 = yg01; | |
662 | } | |
663 | if(gx>=xg1 && gx<=xg2 && gy>=yg1 && gy<=yg2){ | |
664 | detElemId = currDetElemId; | |
665 | GetTransformer()->Global2Local(detElemId, gx, gy, 0, x, y, z); | |
6e97fbb8 | 666 | pad[0] = seg->PadByPosition(x,y,kFALSE); |
8c0b5e70 | 667 | if(!pad[0].IsValid()) continue; |
668 | isOk = kTRUE; | |
669 | break; | |
670 | } | |
671 | } // loop on slats | |
672 | } while ( !isOk ); | |
673 | ||
674 | const AliMpVSegmentation* seg1 | |
675 | = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(1)); | |
6e97fbb8 | 676 | pad[1] = seg1->PadByPosition(x,y,kFALSE); |
8c0b5e70 | 677 | |
678 | for ( Int_t cathode = 0; cathode < 2; ++cathode ){ | |
168e9c4d | 679 | Int_t manuId = pad[cathode].GetLocalBoardId(0); |
680 | Int_t manuChannel = pad[cathode].GetLocalBoardChannel(0); | |
8c0b5e70 | 681 | d[cathode] = digitStore.CreateDigit(detElemId,manuId,manuChannel,cathode); |
168e9c4d | 682 | ix = pad[cathode].GetIx(); |
683 | iy = pad[cathode].GetIy(); | |
8c0b5e70 | 684 | d[cathode]->SetPadXY(ix,iy); |
685 | //d[cathode].SetSignal(1); | |
686 | //d[cathode].SetPhysicsSignal(0); | |
687 | d[cathode]->SetCharge(1); | |
688 | d[cathode]->NoiseOnly(kTRUE); | |
689 | AliDebug(3,Form("Adding a pure noise digit :")); | |
690 | ||
691 | Bool_t ok = digitStore.Add(*d[cathode],AliMUONVDigitStore::kDeny); | |
692 | if (!ok) | |
693 | { | |
694 | fLogger->Log("Collision while adding TriggerNoise digit"); | |
695 | } | |
696 | else | |
697 | { | |
698 | fLogger->Log("Added triggerNoise digit"); | |
699 | } | |
700 | } //loop on cathodes | |
701 | } // loop on noisy pads | |
702 | } // loop on chambers | |
703 | } | |
704 | ||
705 | ||
92aeef15 | 706 | //_____________________________________________________________________________ |
40e382ae | 707 | AliLoader* |
708 | AliMUONDigitizerV3::GetLoader(const TString& folderName) | |
92aeef15 | 709 | { |
40e382ae | 710 | /// Get a MUON loader |
9265505b | 711 | |
ad26d4f6 | 712 | AliDebug(2,Form("Getting access to folder %s",folderName.Data())); |
40e382ae | 713 | AliLoader* loader = AliRunLoader::GetDetectorLoader("MUON",folderName.Data()); |
92aeef15 | 714 | if (!loader) |
715 | { | |
716 | AliError(Form("Could not get MuonLoader from folder %s",folderName.Data())); | |
717 | return 0x0; | |
718 | } | |
40e382ae | 719 | return loader; |
92aeef15 | 720 | } |
721 | ||
722 | //_____________________________________________________________________________ | |
723 | Bool_t | |
724 | AliMUONDigitizerV3::Init() | |
725 | { | |
9265505b | 726 | /// Initialization of the TTask : |
40e382ae | 727 | /// a) create the calibrationData, according to run number |
728 | /// b) create the trigger processing task | |
9265505b | 729 | |
ad26d4f6 | 730 | AliDebug(2,""); |
92aeef15 | 731 | |
732 | if ( fIsInitialized ) | |
733 | { | |
734 | AliError("Object already initialized."); | |
735 | return kFALSE; | |
736 | } | |
737 | ||
738 | if (!fManager) | |
739 | { | |
740 | AliError("fManager is null !"); | |
741 | return kFALSE; | |
742 | } | |
743 | ||
331a617a | 744 | // Load mapping |
745 | if ( ! AliMpCDB::LoadDDLStore() ) { | |
88544f7e | 746 | AliFatal("Could not access mapping from OCDB !"); |
747 | } | |
748 | ||
92c23b09 | 749 | if (!fCalibrationData) |
750 | AliFatal("Calibration data object not defined"); | |
751 | ||
ad26d4f6 | 752 | if ( !fCalibrationData->Pedestals() ) |
753 | { | |
754 | AliFatal("Could not access pedestals from OCDB !"); | |
755 | } | |
756 | if ( !fCalibrationData->Gains() ) | |
757 | { | |
758 | AliFatal("Could not access gains from OCDB !"); | |
759 | } | |
92c23b09 | 760 | |
761 | ||
762 | AliInfo("Using trigger configuration from CDB"); | |
763 | ||
40e382ae | 764 | fTriggerProcessor = new AliMUONTriggerElectronics(fCalibrationData); |
4ce497c4 | 765 | |
ad26d4f6 | 766 | AliDebug(1, Form("Will %s generate noise-only digits for tracker", |
767 | (fGenerateNoisyDigits ? "":"NOT"))); | |
768 | ||
92aeef15 | 769 | fIsInitialized = kTRUE; |
770 | return kTRUE; | |
771 | } | |
772 | ||
92aeef15 | 773 | //_____________________________________________________________________________ |
774 | void | |
40e382ae | 775 | AliMUONDigitizerV3::MergeWithSDigits(AliMUONVDigitStore*& outputStore, |
776 | const AliMUONVDigitStore& input, | |
777 | Int_t mask) | |
92aeef15 | 778 | { |
9265505b | 779 | /// Merge the sdigits in inputData with the digits already present in outputData |
92aeef15 | 780 | |
40e382ae | 781 | if ( !outputStore ) outputStore = input.Create(); |
782 | ||
783 | TIter next(input.CreateIterator()); | |
784 | AliMUONVDigit* sdigit; | |
785 | ||
786 | while ( ( sdigit = static_cast<AliMUONVDigit*>(next()) ) ) | |
787 | { | |
788 | // Update the track references using the mask. | |
789 | // FIXME: this is dirty, for backward compatibility only. | |
790 | // Should re-design all this way of keeping track of MC information... | |
791 | if ( mask ) sdigit->PatchTracks(mask); | |
792 | // Then add or update the digit to the output. | |
793 | AliMUONVDigit* added = outputStore->Add(*sdigit,AliMUONVDigitStore::kMerge); | |
794 | if (!added) | |
92aeef15 | 795 | { |
40e382ae | 796 | AliError("Could not add digit in merge mode"); |
92aeef15 | 797 | } |
92aeef15 | 798 | } |
799 | } | |
ec9acc85 | 800 | |
801 | //_____________________________________________________________________________ | |
802 | TF1* | |
803 | AliMUONDigitizerV3::NoiseFunction() | |
804 | { | |
805 | /// Return noise function | |
806 | static TF1* f = 0x0; | |
807 | if (!f) | |
808 | { | |
809 | f = new TF1("AliMUONDigitizerV3::NoiseFunction","gaus",fgkNSigmas,fgkNSigmas*10); | |
810 | f->SetParameters(1,0,1); | |
811 | } | |
812 | return f; | |
813 | } | |
814 |