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