]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONDigitizerV3.cxx
Optional geometry without CPV
[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
18#include "AliMUONDigitizerV3.h"
19
4ce497c4 20#include "AliMUON.h"
92aeef15 21#include "AliMUONCalibrationData.h"
92aeef15 22#include "AliMUONConstants.h"
23#include "AliMUONData.h"
4ce497c4 24#include "AliMUONDataIterator.h"
92aeef15 25#include "AliMUONDigit.h"
4ce497c4 26#include "AliMUONSegmentation.h"
4ce497c4 27#include "AliMUONTriggerEfficiencyCells.h"
4f8a3d8b 28#include "AliMUONTriggerElectronics.h"
05314992 29#include "AliMUONVCalibParam.h"
9265505b 30
4ce497c4 31#include "AliMpDEIterator.h"
92aeef15 32#include "AliMpDEManager.h"
4ce497c4 33#include "AliMpIntPair.h"
34#include "AliMpPad.h"
92aeef15 35#include "AliMpStationType.h"
9265505b 36#include "AliMpSegmentation.h"
4ce497c4 37#include "AliMpVSegmentation.h"
66f4c572 38#include "AliMpDEManager.h"
9265505b 39
92aeef15 40#include "AliRun.h"
41#include "AliRunDigitizer.h"
42#include "AliRunLoader.h"
9265505b 43#include "AliLog.h"
44
92aeef15 45#include "Riostream.h"
4ce497c4 46#include "TF1.h"
92aeef15 47#include "TRandom.h"
48#include "TString.h"
49
4ce497c4 50///
9265505b 51/// \class AliMUONDigitizerV3
4ce497c4 52/// The digitizer is performing the transformation to go from SDigits (digits
53/// w/o any electronic noise) to Digits (w/ electronic noise, and decalibration)
54///
55/// The decalibration is performed by doing the reverse operation of the
56/// calibration, that is we do (Signal+pedestal)/gain -> ADC
57///
58/// Note also that the digitizer takes care of merging sdigits that belongs
59/// to the same pad, either because we're merging several input sdigit files
60/// or with a single file because the sdigitizer does not merge sdigits itself
61/// (for performance reason mainly, and because anyway we know we have to do it
62/// here, at the digitization level).
63///
64
65namespace
66{
67 AliMUON* muon()
68 {
69 return static_cast<AliMUON*>(gAlice->GetModule("MUON"));
70 }
4ce497c4 71}
72
73const Double_t AliMUONDigitizerV3::fgkNSigmas=3;
74
9265505b 75/// \cond CLASSIMP
92aeef15 76ClassImp(AliMUONDigitizerV3)
9265505b 77/// \endcond
92aeef15 78
79//_____________________________________________________________________________
80AliMUONDigitizerV3::AliMUONDigitizerV3(AliRunDigitizer* manager,
4ce497c4 81 Bool_t generateNoisyDigits)
92aeef15 82: AliDigitizer(manager),
92aeef15 83fIsInitialized(kFALSE),
84fOutputData(0x0),
85fCalibrationData(0x0),
86fTriggerProcessor(0x0),
4ce497c4 87fTriggerEfficiency(0x0),
ccea41d4 88fFindDigitIndexTimer(),
89fGenerateNoisyDigitsTimer(),
90fExecTimer(),
4ce497c4 91fNoiseFunction(0x0),
92fGenerateNoisyDigits(generateNoisyDigits)
92aeef15 93{
9265505b 94 /// Ctor.
95
92aeef15 96 AliDebug(1,Form("AliRunDigitizer=%p",fManager));
4ce497c4 97 fGenerateNoisyDigitsTimer.Start(kTRUE); fGenerateNoisyDigitsTimer.Stop();
98 fExecTimer.Start(kTRUE); fExecTimer.Stop();
99 fFindDigitIndexTimer.Start(kTRUE); fFindDigitIndexTimer.Stop();
92aeef15 100}
101
102//_____________________________________________________________________________
103AliMUONDigitizerV3::~AliMUONDigitizerV3()
104{
9265505b 105 /// Dtor. Note we're the owner of some pointers.
106
92aeef15 107 AliDebug(1,"dtor");
4ce497c4 108
92aeef15 109 delete fOutputData;
110 delete fCalibrationData;
111 delete fTriggerProcessor;
4ce497c4 112 delete fNoiseFunction;
113
a7b01aa5 114 AliDebug(1, Form("Execution time for FindDigitIndex() : R:%.2fs C:%.2fs",
4ce497c4 115 fFindDigitIndexTimer.RealTime(),fFindDigitIndexTimer.CpuTime()));
116 if ( fGenerateNoisyDigits )
117 {
a7b01aa5 118 AliDebug(1, Form("Execution time for GenerateNoisyDigits() : R:%.2fs C:%.2fs",
4ce497c4 119 fGenerateNoisyDigitsTimer.RealTime(),
120 fGenerateNoisyDigitsTimer.CpuTime()));
121 }
a7b01aa5 122 AliDebug(1, Form("Execution time for Exec() : R:%.2fs C:%.2fs",
4ce497c4 123 fExecTimer.RealTime(),fExecTimer.CpuTime()));
124
92aeef15 125}
126
127//_____________________________________________________________________________
128void
4ce497c4 129AliMUONDigitizerV3::ApplyResponseToTrackerDigit(AliMUONDigit& digit, Bool_t addNoise)
92aeef15 130{
9265505b 131 /// For tracking digits, starting from an ideal digit's charge, we :
132 ///
133 /// - add some noise (thus leading to a realistic charge), if requested to do so
134 /// - divide by a gain (thus decalibrating the digit)
135 /// - add a pedestal (thus decalibrating the digit)
136 /// - sets the signal to zero if below 3*sigma of the noise
59b91539 137
4ce497c4 138 static const Int_t kMaxADC = (1<<12)-1; // We code the charge on a 12 bits ADC.
59b91539 139
4ce497c4 140 Float_t signal = digit.Signal();
59b91539 141
142 if ( !addNoise )
143 {
144 digit.SetADC(TMath::Nint(signal));
145 return;
146 }
92aeef15 147
4ce497c4 148 Int_t detElemId = digit.DetElemId();
92aeef15 149
150 Int_t manuId = digit.ManuId();
151 Int_t manuChannel = digit.ManuChannel();
152
4ce497c4 153 AliMUONVCalibParam* pedestal = fCalibrationData->Pedestals(detElemId,manuId);
92aeef15 154 if (!pedestal)
59b91539 155 {
156 AliFatal(Form("Could not get pedestal for DE=%d manuId=%d",
157 detElemId,manuId));
158 }
05314992 159 Float_t pedestalMean = pedestal->ValueAsFloat(manuChannel,0);
160 Float_t pedestalSigma = pedestal->ValueAsFloat(manuChannel,1);
59b91539 161
4ce497c4 162 AliMUONVCalibParam* gain = fCalibrationData->Gains(detElemId,manuId);
92aeef15 163 if (!gain)
59b91539 164 {
165 AliFatal(Form("Could not get gain for DE=%d manuId=%d",
166 detElemId,manuId));
167 }
05314992 168 Float_t gainMean = gain->ValueAsFloat(manuChannel,0);
4ce497c4 169
59b91539 170 Float_t adcNoise = gRandom->Gaus(0.0,pedestalSigma);
171
92aeef15 172 Int_t adc;
59b91539 173
05314992 174 if ( gainMean < 1E-6 )
92aeef15 175 {
59b91539 176 AliError(Form("Got a too small gain %e for DE=%d manuId=%d manuChannel=%d. "
177 "Setting signal to 0.",
178 gainMean,detElemId,manuId,manuChannel));
92aeef15 179 adc = 0;
180 }
59b91539 181 else
182 {
183 adc = TMath::Nint( signal / gainMean + pedestalMean + adcNoise);///
184
185 if ( adc <= pedestalMean + fgkNSigmas*pedestalSigma )
186 {
187 adc = 0;
188 }
189 }
190
05314992 191 // be sure we stick to 12 bits.
4ce497c4 192 if ( adc > kMaxADC )
59b91539 193 {
194 adc = kMaxADC;
195 }
196
92aeef15 197 digit.SetPhysicsSignal(TMath::Nint(signal));
198 digit.SetSignal(adc);
199 digit.SetADC(adc);
200}
201
4ce497c4 202//_____________________________________________________________________________
203void
204AliMUONDigitizerV3::ApplyResponseToTriggerDigit(AliMUONDigit& digit,
205 AliMUONData* data)
206{
9265505b 207 /// \todo add comment
208
4ce497c4 209 if ( !fTriggerEfficiency ) return;
210
211 AliMUONDigit* correspondingDigit = FindCorrespondingDigit(digit,data);
212
a0dc51a6 213 if(!correspondingDigit)return;//reject bad correspondences
214
4ce497c4 215 Int_t detElemId = digit.DetElemId();
9265505b 216
217 AliMpSegmentation* segmentation = AliMpSegmentation::Instance();
4ce497c4 218 const AliMpVSegmentation* segment[2] =
219 {
9265505b 220 segmentation->GetMpSegmentation(detElemId,digit.Cathode()),
221 segmentation->GetMpSegmentation(detElemId,correspondingDigit->Cathode())
4ce497c4 222 };
223
224 AliMpPad pad[2] =
225 {
226 segment[0]->PadByIndices(AliMpIntPair(digit.PadX(),digit.PadY()),kTRUE),
227 segment[1]->PadByIndices(AliMpIntPair(correspondingDigit->PadX(),correspondingDigit->PadY()),kTRUE)
228 };
229
081d3361 230 Int_t p0(1);
231 if (digit.Cathode()==0)p0=0;
232
233 AliMpIntPair location = pad[p0].GetLocation(0);
234 Int_t nboard = location.GetFirst();
4ce497c4 235
4ce497c4 236 Bool_t isTrig[2];
081d3361 237
238 fTriggerEfficiency->IsTriggered(detElemId, nboard-1,
4ce497c4 239 isTrig[0], isTrig[1]);
081d3361 240
4ce497c4 241 if (!isTrig[digit.Cathode()])
242 {
243 digit.SetSignal(0);
244 }
245
246 if ( &digit != correspondingDigit )
247 {
248 if (!isTrig[correspondingDigit->Cathode()])
249 {
250 correspondingDigit->SetSignal(0);
251 }
252 }
253}
254
92aeef15 255//_____________________________________________________________________________
256void
257AliMUONDigitizerV3::ApplyResponse()
258{
9265505b 259 /// Loop over all chamber digits, and apply the response to them
260 /// Note that this method may remove digits.
261
4ce497c4 262 const Bool_t kAddNoise = kTRUE;
263
92aeef15 264 for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich )
4ce497c4 265 {
92aeef15 266 TClonesArray* digits = fOutputData->Digits(ich);
267 Int_t n = digits->GetEntriesFast();
4ce497c4 268 Bool_t trackingChamber = ( ich < AliMUONConstants::NTrackingCh() );
92aeef15 269 for ( Int_t i = 0; i < n; ++i )
270 {
271 AliMUONDigit* d = static_cast<AliMUONDigit*>(digits->UncheckedAt(i));
4ce497c4 272 if ( trackingChamber )
273 {
274 ApplyResponseToTrackerDigit(*d,kAddNoise);
275 }
276 else
277 {
278 ApplyResponseToTriggerDigit(*d,fOutputData);
279 }
92aeef15 280 if ( d->Signal() <= 0 )
281 {
282 digits->RemoveAt(i);
283 }
284 }
05314992 285 digits->Compress();
92aeef15 286 }
4ce497c4 287
288// The version below, using iterator, does not yet work (as the iterator
289// assumes it is reading digits from the tree, while in this case it's
290// writing...)
291//
292// AliMUONDigit* digit(0x0);
293//
294// // First loop on tracker digits
295// AliMUONDataIterator tracker(fOutputData,"D",AliMUONDataIterator::kTrackingChambers);
296//
297// while ( ( digit = static_cast<AliMUONDigit*>(tracker.Next()) ) )
298// {
299// ApplyResponseToTrackerDigit(*digit);
300// if ( digit->Signal() <= 0 )
301// {
302// tracker.Remove();
303// }
304//
305// }
306//
307// // Then loop on trigger digits
308// AliMUONDataIterator trigger(fOutputData,"D",AliMUONDataIterator::kTriggerChambers);
309//
310// while ( ( digit = static_cast<AliMUONDigit*>(trigger.Next()) ) )
311// {
312// ApplyResponseToTriggerDigit(*digit,fOutputData);
313// if ( digit->Signal() <= 0 )
314// {
315// trigger.Remove();
316// }
317// }
92aeef15 318}
319
320//_____________________________________________________________________________
321void
322AliMUONDigitizerV3::AddOrUpdateDigit(TClonesArray& array,
323 const AliMUONDigit& digit)
324{
9265505b 325 /// Add or update a digit, depending on whether there's already a digit
326 /// for the corresponding channel.
327
92aeef15 328 Int_t ix = FindDigitIndex(array,digit);
329
330 if (ix>=0)
331 {
332 AliMUONDigit* d = static_cast<AliMUONDigit*>(array.UncheckedAt(ix));
333 Bool_t ok = MergeDigits(digit,*d);
334 if (!ok)
335 {
336 AliError("Digits are not mergeable !");
337 }
92aeef15 338 }
339 else
340 {
341 ix = array.GetLast() + 1;
342 new(array[ix]) AliMUONDigit(digit);
343 }
344
345}
346
347//_____________________________________________________________________________
348void
349AliMUONDigitizerV3::Exec(Option_t*)
350{
9265505b 351 /// Main method.
352 /// We first loop over input files, and merge the sdigits we found there.
353 /// Second, we digitize all the resulting sdigits
354 /// Then we generate noise-only digits (for tracker only)
355 /// And we finally generate the trigger outputs.
4ce497c4 356
92aeef15 357 AliDebug(1, "Running digitizer.");
358
359 if ( fManager->GetNinputs() == 0 )
360 {
361 AliWarning("No input set. Nothing to do.");
362 return;
363 }
364
365 if ( !fIsInitialized )
366 {
367 AliError("Not initialized. Cannot perform the work. Sorry");
368 return;
369 }
370
4ce497c4 371 fExecTimer.Start(kFALSE);
372
92aeef15 373 Int_t nInputFiles = fManager->GetNinputs();
374
375 if ( fOutputData->TreeD() == 0x0 )
376 {
377 AliDebug(1,"Calling MakeDigitsContainer");
378 fOutputData->GetLoader()->MakeDigitsContainer();
379 }
380 fOutputData->MakeBranch("D,GLT");
381 fOutputData->SetTreeAddress("D,GLT");
382
383 // Loop over all the input files, and merge the sdigits found in those
384 // files.
385 for ( Int_t iFile = 0; iFile < nInputFiles; ++iFile )
386 {
387 AliMUONData* inputData = GetDataAccess(fManager->GetInputFolderName(iFile));
388 if (!inputData)
389 {
390 AliFatal(Form("Could not get access to input file #%d",iFile));
391 }
05314992 392
92aeef15 393 inputData->GetLoader()->LoadSDigits("READ");
92aeef15 394 inputData->SetTreeAddress("S");
395 inputData->GetSDigits();
05314992 396
397 MergeWithSDigits(*fOutputData,*inputData,fManager->GetMask(iFile));
398
92aeef15 399 inputData->ResetSDigits();
400 inputData->GetLoader()->UnloadSDigits();
401 delete inputData;
402 }
403
404 // At this point, we do have digit arrays (one per chamber) which contains
405 // the merging of all the sdigits of the input file(s).
406 // We now massage them to apply the detector response, i.e. this
407 // is here that we do the "digitization" work.
408
409 ApplyResponse();
4ce497c4 410
411 if ( fGenerateNoisyDigits )
412 {
413 // Generate noise-only digits for tracker.
414 GenerateNoisyDigits();
415 }
416
92aeef15 417 // We generate the global and local trigger decisions.
418 fTriggerProcessor->ExecuteTask();
419
420 // Fill the output treeD
421 fOutputData->Fill("D,GLT");
422
423 // Write to the output tree(D).
424 // Please note that as GlobalTrigger, LocalTrigger and Digits are in the same
425 // tree (=TreeD) in different branches, this WriteDigits in fact writes all of
426 // the 3 branches.
427 fOutputData->GetLoader()->WriteDigits("OVERWRITE");
428
429 // Finally, we clean up after ourselves.
430 fOutputData->ResetDigits();
431 fOutputData->ResetTrigger();
432 fOutputData->GetLoader()->UnloadDigits();
4ce497c4 433
434 fExecTimer.Stop();
92aeef15 435}
436
4ce497c4 437//_____________________________________________________________________________
438AliMUONDigit*
439AliMUONDigitizerV3::FindCorrespondingDigit(AliMUONDigit& digit,
85fec35d 440 AliMUONData* data) const
4ce497c4 441{
9265505b 442 /// \todo add comment
443
a0dc51a6 444 AliMUONDataIterator it(data,"D",AliMUONDataIterator::kTriggerChambers);
4ce497c4 445 AliMUONDigit* cd;
a0dc51a6 446
447 for(;;){
448 cd = static_cast<AliMUONDigit*>(it.Next());
449 if(!cd)continue;
450 if (cd->DetElemId() == digit.DetElemId() &&
451 cd->PadX() == digit.PadX() &&
452 cd->PadY() == digit.PadY() &&
453 cd->Cathode() == digit.Cathode()){
454 break;
455 }
456 }
457 //The corresponding digit is searched only forward in the AliMUONData.
458 //In this way when the first digit of the couple is given, the second digit is found and the efficiency is applied to both.
459 //Afterwards, when the second digit of the couple is given the first one is not found and hence efficiency is not applied again
4ce497c4 460
461 while ( ( cd = static_cast<AliMUONDigit*>(it.Next()) ) )
462 {
a0dc51a6 463 if(!cd)continue;//avoid problems when 1 digit is removed
4ce497c4 464 if ( cd->DetElemId() == digit.DetElemId() &&
465 cd->Hit() == digit.Hit() &&
466 cd->Cathode() != digit.Cathode() )
467 {
468 return cd;
469 }
470 }
471 return 0x0;
472}
473
474
92aeef15 475//_____________________________________________________________________________
476Int_t
4ce497c4 477AliMUONDigitizerV3::FindDigitIndex(TClonesArray& array,
478 const AliMUONDigit& digit) const
92aeef15 479{
9265505b 480 /// Return the index of digit within array, if that digit is there,
481 /// otherwise returns -1
482 ///
483 /// \todo FIXME: this is of course not the best implementation you can think of.
484 /// Reconsider the use of hit/digit map... ? (but be sure it's needed!)
4ce497c4 485
486 fFindDigitIndexTimer.Start(kFALSE);
487
92aeef15 488 Int_t n = array.GetEntriesFast();
489 for ( Int_t i = 0; i < n; ++i )
490 {
491 AliMUONDigit* d = static_cast<AliMUONDigit*>(array.UncheckedAt(i));
492 if ( d->DetElemId() == digit.DetElemId() &&
493 d->PadX() == digit.PadX() &&
494 d->PadY() == digit.PadY() &&
495 d->Cathode() == digit.Cathode() )
496 {
4ce497c4 497 fFindDigitIndexTimer.Stop();
92aeef15 498 return i;
499 }
500 }
4ce497c4 501 fFindDigitIndexTimer.Stop();
92aeef15 502 return -1;
503}
504
4ce497c4 505//_____________________________________________________________________________
506void
507AliMUONDigitizerV3::GenerateNoisyDigits()
508{
9265505b 509 /// According to a given probability, generate digits that
510 /// have a signal above the noise cut (ped+n*sigma_ped), i.e. digits
511 /// that are "only noise".
4ce497c4 512
513 if ( !fNoiseFunction )
514 {
515 fNoiseFunction = new TF1("AliMUONDigitizerV3::fNoiseFunction","gaus",
516 fgkNSigmas,fgkNSigmas*10);
517
518 fNoiseFunction->SetParameters(1,0,1);
519 }
520
521 fGenerateNoisyDigitsTimer.Start(kFALSE);
522
523 for ( Int_t i = 0; i < AliMUONConstants::NTrackingCh(); ++i )
524 {
525 AliMpDEIterator it;
526
527 it.First(i);
528
529 while ( !it.IsDone() )
530 {
531 for ( Int_t cathode = 0; cathode < 2; ++cathode )
532 {
533 GenerateNoisyDigitsForOneCathode(it.CurrentDE(),cathode);
534 }
535 it.Next();
536 }
537 }
538
539 fGenerateNoisyDigitsTimer.Stop();
540}
541
542//_____________________________________________________________________________
543void
544AliMUONDigitizerV3::GenerateNoisyDigitsForOneCathode(Int_t detElemId, Int_t cathode)
545{
9265505b 546 /// Generate noise-only digits for one cathode of one detection element.
547 /// Called by GenerateNoisyDigits()
4ce497c4 548
66f4c572 549 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
550 TClonesArray* digits = fOutputData->Digits(chamberId);
4ce497c4 551
9265505b 552 const AliMpVSegmentation* seg
553 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,cathode);
4ce497c4 554 Int_t nofPads = seg->NofPads();
555
556 Int_t maxIx = seg->MaxPadIndexX();
557 Int_t maxIy = seg->MaxPadIndexY();
558
cdea095e 559 static const Double_t kProbToBeOutsideNsigmas = TMath::Erfc(fgkNSigmas/TMath::Sqrt(2.0)) / 2. ;
4ce497c4 560
84aac932 561 Int_t nofNoisyPads = TMath::Nint(kProbToBeOutsideNsigmas*nofPads);
4ce497c4 562 if ( !nofNoisyPads ) return;
563
564 nofNoisyPads =
565 TMath::Nint(gRandom->Gaus(nofNoisyPads,
566 nofNoisyPads/TMath::Sqrt(nofNoisyPads)));
567
568 AliDebug(3,Form("DE %d cath %d nofNoisyPads %d",detElemId,cathode,nofNoisyPads));
569
570 for ( Int_t i = 0; i < nofNoisyPads; ++i )
571 {
572 Int_t ix(-1);
573 Int_t iy(-1);
574 do {
575 ix = gRandom->Integer(maxIx+1);
576 iy = gRandom->Integer(maxIy+1);
577 } while ( !seg->HasPad(AliMpIntPair(ix,iy)) );
578 AliMUONDigit d;
579 d.SetDetElemId(detElemId);
580 d.SetCathode(cathode);
581 d.SetPadX(ix);
582 d.SetPadY(iy);
583 if ( FindDigitIndex(*digits,d) >= 0 )
584 {
585 // this digit is already there, and not noise-only, we simply skip it
586 continue;
587 }
588 AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy));
589 Int_t manuId = pad.GetLocation().GetFirst();
590 Int_t manuChannel = pad.GetLocation().GetSecond();
591
592 d.SetElectronics(manuId,manuChannel);
593
594 AliMUONVCalibParam* pedestals = fCalibrationData->Pedestals(detElemId,manuId);
595
596 Float_t pedestalMean = pedestals->ValueAsFloat(manuChannel,0);
597 Float_t pedestalSigma = pedestals->ValueAsFloat(manuChannel,1);
598
599 Double_t ped = fNoiseFunction->GetRandom()*pedestalSigma;
59b91539 600
4ce497c4 601 d.SetSignal(TMath::Nint(ped+pedestalMean+0.5));
59b91539 602 d.SetPhysicsSignal(0);
4ce497c4 603 d.NoiseOnly(kTRUE);
604 AliDebug(3,Form("Adding a pure noise digit :"));
605 StdoutToAliDebug(3,cout << "Before Response: " << endl;
606 d.Print(););
607 ApplyResponseToTrackerDigit(d,kFALSE);
608 if ( d.Signal() > 0 )
609 {
610 AddOrUpdateDigit(*digits,d);
611 }
612 else
613 {
614 AliError("Pure noise below threshold. This should not happen. Not adding "
615 "this digit.");
616 }
617 StdoutToAliDebug(3,cout << "After Response: " << endl;
618 d.Print(););
619 }
620}
621
92aeef15 622//_____________________________________________________________________________
623AliMUONData*
624AliMUONDigitizerV3::GetDataAccess(const TString& folderName)
625{
9265505b 626 /// Create an AliMUONData to deal with data found in folderName.
627
92aeef15 628 AliDebug(1,Form("Getting access to folder %s",folderName.Data()));
629 AliRunLoader* runLoader = AliRunLoader::GetRunLoader(folderName);
630 if (!runLoader)
631 {
632 AliError(Form("Could not get RunLoader from folder %s",folderName.Data()));
633 return 0x0;
634 }
635 AliLoader* loader = static_cast<AliLoader*>(runLoader->GetLoader("MUONLoader"));
636 if (!loader)
637 {
638 AliError(Form("Could not get MuonLoader from folder %s",folderName.Data()));
639 return 0x0;
640 }
641 AliMUONData* data = new AliMUONData(loader,"MUON","MUONDataForDigitOutput");
642 AliDebug(1,Form("AliMUONData=%p loader=%p",data,loader));
643 return data;
644}
645
646//_____________________________________________________________________________
647Bool_t
648AliMUONDigitizerV3::Init()
649{
9265505b 650 /// Initialization of the TTask :
651 /// a) set the outputData pointer
652 /// b) create the calibrationData, according to run number
653 /// c) create the trigger processing task
654
92aeef15 655 AliDebug(1,"");
656
657 if ( fIsInitialized )
658 {
659 AliError("Object already initialized.");
660 return kFALSE;
661 }
662
663 if (!fManager)
664 {
665 AliError("fManager is null !");
666 return kFALSE;
667 }
668
669 fOutputData = GetDataAccess(fManager->GetOutputFolderName());
670 if (!fOutputData)
671 {
672 AliError("Can not perform digitization. I'm sorry");
673 return kFALSE;
674 }
675 AliDebug(1,Form("fOutputData=%p",fOutputData));
676
677 AliRunLoader* runLoader = fOutputData->GetLoader()->GetRunLoader();
678 AliRun* galice = runLoader->GetAliRun();
679 Int_t runnumber = galice->GetRunNumber();
680
681 fCalibrationData = new AliMUONCalibrationData(runnumber);
682
eb5d708c 683 fTriggerProcessor = new AliMUONTriggerElectronics(fOutputData,fCalibrationData);
4ce497c4 684
afb3ccf0 685 if ( muon()->GetTriggerEffCells() )
4ce497c4 686 {
687 fTriggerEfficiency = fCalibrationData->TriggerEfficiency();
688 if ( fTriggerEfficiency )
689 {
a7b01aa5 690 AliDebug(1, "Will apply trigger efficiency");
4ce497c4 691 }
692 else
693 {
694 AliError("I was requested to apply trigger efficiency, but I could "
695 "not get it !");
696 }
697 }
698
699 if ( fGenerateNoisyDigits )
700 {
a7b01aa5 701 AliDebug(1, "Will generate noise-only digits for tracker");
4ce497c4 702 }
703
92aeef15 704 fIsInitialized = kTRUE;
705 return kTRUE;
706}
707
708//_____________________________________________________________________________
709Bool_t
05314992 710AliMUONDigitizerV3::MergeDigits(const AliMUONDigit& src,
711 AliMUONDigit& srcAndDest)
92aeef15 712{
9265505b 713 /// Merge 2 digits (src and srcAndDest) into srcAndDest.
714
92aeef15 715 AliDebug(1,"Merging the following digits:");
05314992 716 StdoutToAliDebug(1,src.Print("tracks"););
717 StdoutToAliDebug(1,srcAndDest.Print("tracks"););
92aeef15 718
719 Bool_t check = ( src.DetElemId() == srcAndDest.DetElemId() &&
720 src.PadX() == srcAndDest.PadX() &&
721 src.PadY() == srcAndDest.PadY() &&
722 src.Cathode() == srcAndDest.Cathode() );
723 if (!check)
724 {
725 return kFALSE;
726 }
727
92aeef15 728 srcAndDest.AddSignal(src.Signal());
729 srcAndDest.AddPhysicsSignal(src.Physics());
05314992 730 for ( Int_t i = 0; i < src.Ntracks(); ++i )
731 {
732 srcAndDest.AddTrack(src.Track(i),src.TrackCharge(i));
733 }
734 StdoutToAliDebug(1,cout << "result:"; srcAndDest.Print("tracks"););
92aeef15 735 return kTRUE;
736}
737
738//_____________________________________________________________________________
739void
740AliMUONDigitizerV3::MergeWithSDigits(AliMUONData& outputData,
05314992 741 const AliMUONData& inputData, Int_t mask)
92aeef15 742{
9265505b 743 /// Merge the sdigits in inputData with the digits already present in outputData
744
92aeef15 745 AliDebug(1,"");
746
747 for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich )
748 {
749 TClonesArray* iDigits = inputData.SDigits(ich);
750 TClonesArray* oDigits = outputData.Digits(ich);
751 if (!iDigits)
752 {
753 AliError(Form("Could not get sdigits for ich=%d",ich));
754 return;
755 }
756 Int_t nSDigits = iDigits->GetEntriesFast();
757 for ( Int_t k = 0; k < nSDigits; ++k )
758 {
759 AliMUONDigit* sdigit = static_cast<AliMUONDigit*>(iDigits->UncheckedAt(k));
92aeef15 760 if (!sdigit)
761 {
762 AliError(Form("Could not get sdigit for ich=%d and k=%d",ich,k));
763 }
764 else
765 {
05314992 766 // Update the track references using the mask.
767 // FIXME: this is dirty, for backward compatibility only.
768 // Should re-design all this way of keeping track of MC information...
769 if ( mask ) sdigit->PatchTracks(mask);
770 // Then add or update the digit to the output.
92aeef15 771 AddOrUpdateDigit(*oDigits,*sdigit);
772 }
9265505b 773 }
92aeef15 774 }
775}