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