]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONDigitizerV3.cxx
A few fixes
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitizerV3.cxx
CommitLineData
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
74namespace
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
5c083cba 88Double_t AliMUONDigitizerV3::fgNSigmas = 4.0;
4ce497c4 89
9265505b 90/// \cond CLASSIMP
92aeef15 91ClassImp(AliMUONDigitizerV3)
9265505b 92/// \endcond
92aeef15 93
94//_____________________________________________________________________________
95AliMUONDigitizerV3::AliMUONDigitizerV3(AliRunDigitizer* manager,
8c0b5e70 96 Int_t generateNoisyDigits)
92aeef15 97: AliDigitizer(manager),
92aeef15 98fIsInitialized(kFALSE),
92aeef15 99fCalibrationData(0x0),
100fTriggerProcessor(0x0),
8c0b5e70 101fNoiseFunctionTrig(0x0),
ec9acc85 102fGenerateNoisyDigits(generateNoisyDigits),
103fLogger(new AliMUONLogger(1000)),
40e382ae 104fTriggerStore(new AliMUONTriggerStoreV1),
105fDigitStore(0x0),
9ec6a948 106fOutputDigitStore(0x0),
ca8c8223 107fInputDigitStores(0x0)
92aeef15 108{
9265505b 109 /// Ctor.
110
92aeef15 111 AliDebug(1,Form("AliRunDigitizer=%p",fManager));
ec9acc85 112
92aeef15 113}
114
115//_____________________________________________________________________________
116AliMUONDigitizerV3::~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;
ca8c8223 128 delete fInputDigitStores;
9ec6a948 129
ad26d4f6 130 AliInfo("Summary of messages");
131 fLogger->Print();
4ce497c4 132
ad26d4f6 133 delete fLogger;
92aeef15 134}
135
136//_____________________________________________________________________________
137void
40e382ae 138AliMUONDigitizerV3::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
5d950f54 147 Float_t charge = digit.IsChargeInFC() ? digit.Charge()*AliMUONConstants::FC2ADC() : digit.Charge();
cf27231a 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//_____________________________________________________________________________
193void
40e382ae 194AliMUONDigitizerV3::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 {
ac6411cf 213 Bool_t addNoise = kAddNoise;
214 if (digit->IsConverted()) addNoise = kFALSE; // No need to add extra noise to a converted real digit
215 ApplyResponseToTrackerDigit(*digit,addNoise);
92aeef15 216 }
7d7d22a6 217
cf27231a 218 if ( digit->ADC() > 0 || digit->Charge() > 0 )
40e382ae 219 {
220 filteredStore.Add(*digit,AliMUONVDigitStore::kIgnore);
92aeef15 221 }
92aeef15 222 }
40e382ae 223}
92aeef15 224
b74ca120 225//_____________________________________________________________________________
226Int_t
227AliMUONDigitizerV3::DecalibrateTrackerDigit(const AliMUONVCalibParam& pedestals,
228 const AliMUONVCalibParam& gains,
229 Int_t channel,
230 Float_t charge,
ec9acc85 231 Bool_t addNoise,
232 Bool_t noiseOnly)
b74ca120 233{
234 /// Decalibrate (i.e. go from charge to adc) a tracker digit, given its
235 /// pedestal and gain parameters.
236 /// Must insure before calling that channel is valid (i.e. between 0 and
237 /// pedestals or gains->GetSize()-1, but also corresponding to a valid channel
238 /// otherwise results are not predictible...)
239
240 static const Int_t kMaxADC = (1<<12)-1; // We code the charge on a 12 bits ADC.
241
242 Float_t pedestalMean = pedestals.ValueAsFloat(channel,0);
243 Float_t pedestalSigma = pedestals.ValueAsFloat(channel,1);
244
ec9acc85 245 AliDebugClass(1,Form("DE %04d MANU %04d CH %02d PEDMEAN %7.2f PEDSIGMA %7.2f",
5d950f54 246 pedestals.ID0(),pedestals.ID1(),channel,pedestalMean,pedestalSigma));
ec9acc85 247
b74ca120 248 Float_t a0 = gains.ValueAsFloat(channel,0);
249 Float_t a1 = gains.ValueAsFloat(channel,1);
250 Int_t thres = gains.ValueAsInt(channel,2);
251 Int_t qual = gains.ValueAsInt(channel,3);
5d950f54 252
b74ca120 253 if ( qual <= 0 ) return 0;
254
255 Float_t chargeThres = a0*thres;
256
257 Float_t padc(0); // (adc - ped) value
258
259 if ( charge <= chargeThres || TMath::Abs(a1) < 1E-12 )
260 {
261 // linear part only
262
263 if ( TMath::Abs(a0) > 1E-12 )
264 {
265 padc = charge/a0;
266 }
267 }
268 else
269 {
270 // linear + parabolic part
271 Double_t qt = chargeThres - charge;
272 Double_t delta = a0*a0-4*a1*qt;
273 if ( delta < 0 )
274 {
275 AliErrorClass(Form("delta=%e DE %d Manu %d Channel %d "
276 " charge %e a0 %e a1 %e thres %d ped %e pedsig %e",
277 delta,pedestals.ID0(),pedestals.ID1(),
278 channel, charge, a0, a1, thres, pedestalMean,
279 pedestalSigma));
280 }
281 else
282 {
283 delta = TMath::Sqrt(delta);
284
285 padc = ( ( -a0 + delta ) > 0 ? ( -a0 + delta ) : ( -a0 - delta ) );
286
287 padc /= 2*a1;
288
289 if ( padc < 0 )
290 {
291 if ( TMath::Abs(padc) > 1E-3)
292 {
293 // this is more than a precision problem : let's signal it !
294 AliErrorClass(Form("padc=%e DE %d Manu %d Channel %d "
295 " charge %e a0 %e a1 %e thres %d ped %e pedsig %e delta %e",
296 padc,pedestals.ID0(),pedestals.ID1(),
297 channel, charge, a0, a1, thres, pedestalMean,
298 pedestalSigma,delta));
299 }
300
301 // ok. consider we're just at thres, let it be zero.
302 padc = 0;
303 }
304
305 padc += thres;
306
307 }
308 }
309
310 Int_t adc(0);
311
ec9acc85 312 Float_t adcNoise = 0.0;
b74ca120 313
ec9acc85 314 if ( addNoise )
315 {
316 if ( noiseOnly )
317 {
318 adcNoise = NoiseFunction()->GetRandom()*pedestalSigma;
319 }
320 else
321 {
322 adcNoise = gRandom->Gaus(0.0,pedestalSigma);
323 }
324 }
b74ca120 325
ec9acc85 326 adc = TMath::Nint(padc + pedestalMean + adcNoise + 0.5);
327
5c083cba 328 if ( adc < TMath::Nint(pedestalMean + fgNSigmas*pedestalSigma + 0.5) )
ec9acc85 329 {
d537c8e4 330 // this is an error only in specific cases
331 if ( !addNoise || (addNoise && noiseOnly) )
332 {
333 AliErrorClass(Form(" DE %04d Manu %04d Channel %02d "
334 " a0 %7.2f a1 %7.2f thres %04d ped %7.2f pedsig %7.2f adcNoise %7.2f "
335 " charge=%7.2f padc=%7.2f adc=%04d ZS=%04d fgNSigmas=%e addNoise %d noiseOnly %d ",
336 pedestals.ID0(),pedestals.ID1(),channel,
337 a0, a1, thres, pedestalMean, pedestalSigma, adcNoise,
338 charge, padc, adc,
339 TMath::Nint(pedestalMean + fgNSigmas*pedestalSigma + 0.5),
340 fgNSigmas,addNoise,noiseOnly));
341 }
342
ec9acc85 343 adc = 0;
b74ca120 344 }
345
346 // be sure we stick to 12 bits.
347 if ( adc > kMaxADC )
348 {
349 adc = kMaxADC;
350 }
351
352 return adc;
353}
354
9ec6a948 355//_____________________________________________________________________________
356void
ca8c8223 357AliMUONDigitizerV3::CreateInputDigitStores()
9ec6a948 358{
ca8c8223 359 /// Create input digit stores
360 ///
9ec6a948 361
ca8c8223 362 if (fInputDigitStores)
363 {
364 AliFatal("Should be called only once !");
365 }
366
367 fInputDigitStores = new TObjArray;
368
369 fInputDigitStores->SetOwner(kTRUE);
9ec6a948 370
371 for ( Int_t iFile = 0; iFile < fManager->GetNinputs(); ++iFile )
372 {
373 AliLoader* inputLoader = GetLoader(fManager->GetInputFolderName(iFile));
374
375 inputLoader->LoadSDigits("READ");
376
377 TTree* iTreeS = inputLoader->TreeS();
378 if (!iTreeS)
379 {
380 AliFatal(Form("Could not get access to input file #%d",iFile));
381 }
382
ca8c8223 383 fInputDigitStores->AddAt(AliMUONVDigitStore::Create(*iTreeS),iFile);
9ec6a948 384 }
385}
386
92aeef15 387//_____________________________________________________________________________
388void
389AliMUONDigitizerV3::Exec(Option_t*)
390{
9265505b 391 /// Main method.
392 /// We first loop over input files, and merge the sdigits we found there.
393 /// Second, we digitize all the resulting sdigits
394 /// Then we generate noise-only digits (for tracker only)
395 /// And we finally generate the trigger outputs.
4ce497c4 396
99c136e1 397 AliCodeTimerAuto("",0)
b74ca120 398
92aeef15 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
411 Int_t nInputFiles = fManager->GetNinputs();
412
40e382ae 413 AliLoader* outputLoader = GetLoader(fManager->GetOutputFolderName());
414
415 outputLoader->MakeDigitsContainer();
416
417 TTree* oTreeD = outputLoader->TreeD();
418
419 if (!oTreeD)
92aeef15 420 {
40e382ae 421 AliFatal("Cannot create output TreeD");
92aeef15 422 }
40e382ae 423
92aeef15 424 // Loop over all the input files, and merge the sdigits found in those
425 // files.
40e382ae 426
92aeef15 427 for ( Int_t iFile = 0; iFile < nInputFiles; ++iFile )
5d950f54 428 {
40e382ae 429 AliLoader* inputLoader = GetLoader(fManager->GetInputFolderName(iFile));
430
431 inputLoader->LoadSDigits("READ");
432
433 TTree* iTreeS = inputLoader->TreeS();
434 if (!iTreeS)
92aeef15 435 {
436 AliFatal(Form("Could not get access to input file #%d",iFile));
437 }
9ec6a948 438
ca8c8223 439 if (!fInputDigitStores)
9ec6a948 440 {
ca8c8223 441 CreateInputDigitStores();
9ec6a948 442 }
40e382ae 443
ca8c8223 444 AliMUONVDigitStore* dstore = static_cast<AliMUONVDigitStore*>(fInputDigitStores->At(iFile));
445
446 dstore->Connect(*iTreeS);
40e382ae 447
ca8c8223 448 iTreeS->GetEvent(0);
449
450 MergeWithSDigits(fDigitStore,*dstore,fManager->GetMask(iFile));
05314992 451
40e382ae 452 inputLoader->UnloadSDigits();
05314992 453
ca8c8223 454 dstore->Clear();
92aeef15 455 }
5d950f54 456
92aeef15 457
458 // At this point, we do have digit arrays (one per chamber) which contains
459 // the merging of all the sdigits of the input file(s).
460 // We now massage them to apply the detector response, i.e. this
461 // is here that we do the "digitization" work.
462
40e382ae 463 if (!fOutputDigitStore)
464 {
465 fOutputDigitStore = fDigitStore->Create();
466 }
467
8c0b5e70 468 if ( fGenerateNoisyDigits>=2 )
469 {
470 // Generate noise-only digits for trigger.
471 GenerateNoisyDigitsForTrigger(*fDigitStore);
472 }
40e382ae 473 ApplyResponse(*fDigitStore,*fOutputDigitStore);
5d950f54 474
4ce497c4 475 if ( fGenerateNoisyDigits )
476 {
477 // Generate noise-only digits for tracker.
40e382ae 478 GenerateNoisyDigits(*fOutputDigitStore);
4ce497c4 479 }
480
92aeef15 481 // We generate the global and local trigger decisions.
40e382ae 482 fTriggerProcessor->Digits2Trigger(*fOutputDigitStore,*fTriggerStore);
483
484 // Prepare output tree
485 Bool_t okD = fOutputDigitStore->Connect(*oTreeD,kFALSE);
486 Bool_t okT = fTriggerStore->Connect(*oTreeD,kFALSE);
487 if (!okD || !okT)
488 {
489 AliError(Form("Could not make branch : Digit %d Trigger %d",okD,okT));
490 return;
491 }
92aeef15 492
493 // Fill the output treeD
40e382ae 494 oTreeD->Fill();
92aeef15 495
496 // Write to the output tree(D).
497 // Please note that as GlobalTrigger, LocalTrigger and Digits are in the same
498 // tree (=TreeD) in different branches, this WriteDigits in fact writes all of
499 // the 3 branches.
40e382ae 500 outputLoader->WriteDigits("OVERWRITE");
92aeef15 501
40e382ae 502 outputLoader->UnloadDigits();
4ce497c4 503
40e382ae 504 // Finally, we clean up after ourselves.
505 fTriggerStore->Clear();
506 fDigitStore->Clear();
507 fOutputDigitStore->Clear();
92aeef15 508}
509
4ce497c4 510
4ce497c4 511//_____________________________________________________________________________
512void
40e382ae 513AliMUONDigitizerV3::GenerateNoisyDigits(AliMUONVDigitStore& digitStore)
4ce497c4 514{
9265505b 515 /// According to a given probability, generate digits that
516 /// have a signal above the noise cut (ped+n*sigma_ped), i.e. digits
517 /// that are "only noise".
4ce497c4 518
99c136e1 519 AliCodeTimerAuto("",0)
b74ca120 520
4ce497c4 521 for ( Int_t i = 0; i < AliMUONConstants::NTrackingCh(); ++i )
522 {
523 AliMpDEIterator it;
524
525 it.First(i);
526
527 while ( !it.IsDone() )
528 {
529 for ( Int_t cathode = 0; cathode < 2; ++cathode )
530 {
40e382ae 531 GenerateNoisyDigitsForOneCathode(digitStore,it.CurrentDEId(),cathode);
4ce497c4 532 }
533 it.Next();
534 }
535 }
4ce497c4 536}
537
538//_____________________________________________________________________________
539void
40e382ae 540AliMUONDigitizerV3::GenerateNoisyDigitsForOneCathode(AliMUONVDigitStore& digitStore,
541 Int_t detElemId, Int_t cathode)
4ce497c4 542{
9265505b 543 /// Generate noise-only digits for one cathode of one detection element.
544 /// Called by GenerateNoisyDigits()
4ce497c4 545
9265505b 546 const AliMpVSegmentation* seg
866c3232 547 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
4ce497c4 548 Int_t nofPads = seg->NofPads();
549
550 Int_t maxIx = seg->MaxPadIndexX();
551 Int_t maxIy = seg->MaxPadIndexY();
552
5c083cba 553 static const Double_t kProbToBeOutsideNsigmas = TMath::Erfc(fgNSigmas/TMath::Sqrt(2.0)) / 2. ;
4ce497c4 554
84aac932 555 Int_t nofNoisyPads = TMath::Nint(kProbToBeOutsideNsigmas*nofPads);
4ce497c4 556 if ( !nofNoisyPads ) return;
557
558 nofNoisyPads =
559 TMath::Nint(gRandom->Gaus(nofNoisyPads,
560 nofNoisyPads/TMath::Sqrt(nofNoisyPads)));
561
562 AliDebug(3,Form("DE %d cath %d nofNoisyPads %d",detElemId,cathode,nofNoisyPads));
563
40e382ae 564 for ( Int_t i = 0; i < nofNoisyPads; ++i )
4ce497c4 565 {
566 Int_t ix(-1);
567 Int_t iy(-1);
40e382ae 568 AliMpPad pad;
569
4ce497c4 570 do {
571 ix = gRandom->Integer(maxIx+1);
572 iy = gRandom->Integer(maxIy+1);
168e9c4d 573 pad = seg->PadByIndices(ix,iy,kFALSE);
40e382ae 574 } while ( !pad.IsValid() );
575
168e9c4d 576 Int_t manuId = pad.GetManuId();
577 Int_t manuChannel = pad.GetManuChannel();
40e382ae 578
4ce497c4 579 AliMUONVCalibParam* pedestals = fCalibrationData->Pedestals(detElemId,manuId);
580
ad26d4f6 581 if (!pedestals)
582 {
583 // no pedestal available for this channel, simply give up
40e382ae 584 continue;
ad26d4f6 585 }
586
40e382ae 587 AliMUONVDigit* d = digitStore.CreateDigit(detElemId,manuId,manuChannel,cathode);
588
589 d->SetPadXY(ix,iy);
590
ec9acc85 591 d->SetCharge(0.0); // charge is zero, the ApplyResponseToTrackerDigit will add the noise
40e382ae 592 d->NoiseOnly(kTRUE);
ec9acc85 593 ApplyResponseToTrackerDigit(*d,kTRUE);
cf27231a 594 if ( d->ADC() > 0 )
4ce497c4 595 {
40e382ae 596 Bool_t ok = digitStore.Add(*d,AliMUONVDigitStore::kDeny);
597 // this can happen (that we randomly chose a digit that is
598 // already there). We simply ignore this, but log the occurence
599 // to cross-check that it's not too frequent.
600 if (!ok)
601 {
602 fLogger->Log("Collision while adding noiseOnly digit");
603 }
604 else
605 {
606 fLogger->Log("Added noiseOnly digit");
607 }
4ce497c4 608 }
40e382ae 609 delete d;
4ce497c4 610 }
611}
612
8c0b5e70 613
614//_____________________________________________________________________________
615void
616AliMUONDigitizerV3::GenerateNoisyDigitsForTrigger(AliMUONVDigitStore& digitStore)
617{
618 /// Generate noise-only digits for one cathode of one detection element.
619 /// Called by GenerateNoisyDigits()
620
621 if ( !fNoiseFunctionTrig )
622 {
623 fNoiseFunctionTrig = new TF1("AliMUONDigitizerV3::fNoiseFunctionTrig","landau",
624 50.,270.);
625
626 fNoiseFunctionTrig->SetParameters(3.91070e+02, 9.85026, 9.35881e-02);
627 }
628
629 AliMpPad pad[2];
630 AliMUONVDigit *d[2]={0x0};
631
632 for ( Int_t chamberId = AliMUONConstants::NTrackingCh(); chamberId < AliMUONConstants::NCh(); ++chamberId )
633 {
634
635 Int_t nofNoisyPads = 50;
636
637 Float_t r=-1, fi = 0., gx, gy, x, y, z, xg01, yg01, zg, xg02, yg02;
638 AliMpDEIterator it;
639
640 AliDebug(3,Form("Chamber %d nofNoisyPads %d",chamberId,nofNoisyPads));
641
642 for ( Int_t i = 0; i < nofNoisyPads; ++i )
643 {
644 //printf("Generating noise %i\n",i);
645 Int_t ix(-1);
646 Int_t iy(-1);
647 Bool_t isOk = kFALSE;
648 Int_t detElemId = -1;
649 do {
650 //r = gRandom->Landau(9.85026, 9.35881e-02);
651 r = fNoiseFunctionTrig->GetRandom();
652 fi = 2. * TMath::Pi() * gRandom->Rndm();
653 //printf("r = %f\tfi = %f\n", r, fi);
654 gx = r * TMath::Cos(fi);
655 gy = r * TMath::Sin(fi);
656
657 for ( it.First(chamberId); ! it.IsDone(); it.Next() ){
658 Int_t currDetElemId = it.CurrentDEId();
659 const AliMpVSegmentation* seg
660 = AliMpSegmentation::Instance()->GetMpSegmentation(currDetElemId,AliMp::GetCathodType(0));
661 if (!seg) continue;
6e97fbb8 662 Float_t deltax = seg->GetDimensionX();
663 Float_t deltay = seg->GetDimensionY();
8c0b5e70 664 GetTransformer()->Local2Global(currDetElemId, -deltax, -deltay, 0, xg01, yg01, zg);
665 GetTransformer()->Local2Global(currDetElemId, deltax, deltay, 0, xg02, yg02, zg);
666 Float_t xg1 = xg01, xg2 = xg02, yg1 = yg01, yg2 = yg02;
667 if(xg01>xg02){
668 xg1 = xg02;
669 xg2 = xg01;
670 }
671 if(yg01>yg02){
672 yg1 = yg02;
673 yg2 = yg01;
674 }
675 if(gx>=xg1 && gx<=xg2 && gy>=yg1 && gy<=yg2){
676 detElemId = currDetElemId;
677 GetTransformer()->Global2Local(detElemId, gx, gy, 0, x, y, z);
6e97fbb8 678 pad[0] = seg->PadByPosition(x,y,kFALSE);
8c0b5e70 679 if(!pad[0].IsValid()) continue;
680 isOk = kTRUE;
681 break;
682 }
683 } // loop on slats
684 } while ( !isOk );
685
686 const AliMpVSegmentation* seg1
687 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(1));
6e97fbb8 688 pad[1] = seg1->PadByPosition(x,y,kFALSE);
8c0b5e70 689
690 for ( Int_t cathode = 0; cathode < 2; ++cathode ){
168e9c4d 691 Int_t manuId = pad[cathode].GetLocalBoardId(0);
692 Int_t manuChannel = pad[cathode].GetLocalBoardChannel(0);
8c0b5e70 693 d[cathode] = digitStore.CreateDigit(detElemId,manuId,manuChannel,cathode);
168e9c4d 694 ix = pad[cathode].GetIx();
695 iy = pad[cathode].GetIy();
8c0b5e70 696 d[cathode]->SetPadXY(ix,iy);
697 //d[cathode].SetSignal(1);
698 //d[cathode].SetPhysicsSignal(0);
699 d[cathode]->SetCharge(1);
700 d[cathode]->NoiseOnly(kTRUE);
701 AliDebug(3,Form("Adding a pure noise digit :"));
702
703 Bool_t ok = digitStore.Add(*d[cathode],AliMUONVDigitStore::kDeny);
704 if (!ok)
705 {
706 fLogger->Log("Collision while adding TriggerNoise digit");
707 }
708 else
709 {
710 fLogger->Log("Added triggerNoise digit");
711 }
712 } //loop on cathodes
713 } // loop on noisy pads
714 } // loop on chambers
715}
716
717
92aeef15 718//_____________________________________________________________________________
40e382ae 719AliLoader*
720AliMUONDigitizerV3::GetLoader(const TString& folderName)
92aeef15 721{
40e382ae 722 /// Get a MUON loader
9265505b 723
ad26d4f6 724 AliDebug(2,Form("Getting access to folder %s",folderName.Data()));
40e382ae 725 AliLoader* loader = AliRunLoader::GetDetectorLoader("MUON",folderName.Data());
92aeef15 726 if (!loader)
727 {
728 AliError(Form("Could not get MuonLoader from folder %s",folderName.Data()));
729 return 0x0;
730 }
40e382ae 731 return loader;
92aeef15 732}
733
734//_____________________________________________________________________________
735Bool_t
736AliMUONDigitizerV3::Init()
737{
9265505b 738 /// Initialization of the TTask :
40e382ae 739 /// a) create the calibrationData, according to run number
740 /// b) create the trigger processing task
9265505b 741
ad26d4f6 742 AliDebug(2,"");
92aeef15 743
744 if ( fIsInitialized )
745 {
746 AliError("Object already initialized.");
747 return kFALSE;
748 }
749
750 if (!fManager)
751 {
752 AliError("fManager is null !");
753 return kFALSE;
754 }
755
331a617a 756 // Load mapping
757 if ( ! AliMpCDB::LoadDDLStore() ) {
88544f7e 758 AliFatal("Could not access mapping from OCDB !");
759 }
760
92c23b09 761 if (!fCalibrationData)
762 AliFatal("Calibration data object not defined");
763
ad26d4f6 764 if ( !fCalibrationData->Pedestals() )
765 {
766 AliFatal("Could not access pedestals from OCDB !");
767 }
768 if ( !fCalibrationData->Gains() )
769 {
770 AliFatal("Could not access gains from OCDB !");
771 }
92c23b09 772
773
774 AliInfo("Using trigger configuration from CDB");
775
40e382ae 776 fTriggerProcessor = new AliMUONTriggerElectronics(fCalibrationData);
4ce497c4 777
ad26d4f6 778 AliDebug(1, Form("Will %s generate noise-only digits for tracker",
779 (fGenerateNoisyDigits ? "":"NOT")));
780
92aeef15 781 fIsInitialized = kTRUE;
782 return kTRUE;
783}
784
92aeef15 785//_____________________________________________________________________________
786void
40e382ae 787AliMUONDigitizerV3::MergeWithSDigits(AliMUONVDigitStore*& outputStore,
788 const AliMUONVDigitStore& input,
789 Int_t mask)
92aeef15 790{
9265505b 791 /// Merge the sdigits in inputData with the digits already present in outputData
92aeef15 792
40e382ae 793 if ( !outputStore ) outputStore = input.Create();
794
795 TIter next(input.CreateIterator());
796 AliMUONVDigit* sdigit;
797
798 while ( ( sdigit = static_cast<AliMUONVDigit*>(next()) ) )
799 {
800 // Update the track references using the mask.
801 // FIXME: this is dirty, for backward compatibility only.
802 // Should re-design all this way of keeping track of MC information...
803 if ( mask ) sdigit->PatchTracks(mask);
804 // Then add or update the digit to the output.
805 AliMUONVDigit* added = outputStore->Add(*sdigit,AliMUONVDigitStore::kMerge);
806 if (!added)
92aeef15 807 {
40e382ae 808 AliError("Could not add digit in merge mode");
92aeef15 809 }
92aeef15 810 }
811}
ec9acc85 812
813//_____________________________________________________________________________
814TF1*
815AliMUONDigitizerV3::NoiseFunction()
816{
817 /// Return noise function
818 static TF1* f = 0x0;
819 if (!f)
820 {
5c083cba 821 f = new TF1("AliMUONDigitizerV3::NoiseFunction","gaus",fgNSigmas,fgNSigmas*10);
ec9acc85 822 f->SetParameters(1,0,1);
823 }
824 return f;
825}
826