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