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