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