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