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