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