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