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