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