]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDigitMaker.cxx
a/ AliTRDCalibTask.cxx .h: one histo more to quantify the event selection if any...
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitMaker.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 /// \class AliMUONDigitMaker
20 /// MUON Digit maker from rawdata.
21 ///
22 /// Raw2Digits:
23 /// Using real mapping  for tracker
24 /// Indranil Das (Adapted for runloader: Ch. Finck) july 05
25 ///
26 /// Implemented non-constant buspatch numbers for tracking
27 /// with correct DDL id.
28 /// (Ch. Finck, dec 05)
29 ///
30 /// Add reader for scaler trigger events
31 /// Use memcpy instead of assignment elt by elt
32 /// (Ch. Finck, Jan 06)
33 ///
34 /// Using new interface with AliMUONRawStreamTracker(Trigger)
35 /// (New interface of AliMUONRawReader class)
36 /// (further details could be found in Alice-note)
37 /// (Ch. Finck, March 06)
38 ///
39 /// Add (S)Digit maker tracker (for free)
40 /// and for trigger. Create trigger inverse mapping.
41 ///
42 /// \author Ch. Finck, oct 06 
43 //-----------------------------------------------------------------------------
44
45 #include "AliMUONDigitMaker.h"
46
47 #include "AliMUONDDLTrigger.h"
48 #include "AliMUONDarcHeader.h"
49 #include "AliMUONVDigit.h"
50 #include "AliMUONVDigitStore.h"
51 #include "AliMUONGlobalTrigger.h"
52 #include "AliMUONLocalStruct.h"
53 #include "AliMUONLocalTrigger.h"
54 #include "AliMUONLogger.h"
55 #include "AliMUONRawStreamTrackerHP.h"
56 #include "AliMUONRawStreamTriggerHP.h"
57 #include "AliMUONRegHeader.h"
58 #include "AliMUONVTriggerStore.h"
59 #include "AliMpCDB.h"
60 #include "AliMpDetElement.h"
61 #include "AliMpTriggerCrate.h"
62 #include "AliMpLocalBoard.h"
63 #include "AliMpCathodType.h"
64 #include "AliMpDDLStore.h"
65 #include "AliMpDEManager.h"
66 #include "AliMpPad.h"
67 #include "AliMpSegmentation.h"
68 #include "AliMpVSegmentation.h"
69 #include "AliCodeTimer.h"
70 #include "AliLog.h"
71 #include "AliRawReader.h"
72 #include <TArrayS.h>
73
74 /// \cond CLASSIMP
75 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
76 /// \endcond
77
78 //__________________________________________________________________________
79 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger, Bool_t a, Bool_t b) :
80 TObject(),
81 fScalerEvent(kFALSE),
82 fMakeTriggerDigits(kFALSE),
83 fRawStreamTracker(new AliMUONRawStreamTrackerHP),
84 fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
85 fDigitStore(0x0),
86 fTriggerStore(0x0),
87 fLogger(new AliMUONLogger(10000)){
88   /// ctor 
89   
90   if  ( !a || !b ) AliFatal("no longer supported");
91   
92   AliDebug(1,"");
93   
94   // Standard Constructor
95   if (enableErrorLogger) 
96   {
97     fRawStreamTracker->EnabbleErrorLogger();
98     fRawStreamTrigger->EnabbleErrorLogger();
99   }
100   else
101   {
102     fRawStreamTracker->DisableWarnings();
103   }
104   
105   SetMakeTriggerDigits();
106   
107   // Load mapping
108   if ( ! AliMpCDB::LoadDDLStore() ) {
109     AliFatal("Could not access mapping from OCDB !");
110   }
111 }
112
113 //__________________________________________________________________________
114 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger) :
115 TObject(),
116     fScalerEvent(kFALSE),
117     fMakeTriggerDigits(kFALSE),
118     fRawStreamTracker(new AliMUONRawStreamTrackerHP),
119     fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
120     fDigitStore(0x0),
121     fTriggerStore(0x0),
122   fLogger(new AliMUONLogger(10000))
123 {
124   /// ctor 
125
126   AliDebug(1,"");
127   
128   // Standard Constructor
129   if (enableErrorLogger) 
130   {
131     fRawStreamTracker->EnabbleErrorLogger();
132     fRawStreamTrigger->EnabbleErrorLogger();
133   }
134   else
135   {
136     fRawStreamTracker->DisableWarnings();
137   }
138
139   SetMakeTriggerDigits();
140
141   // Load mapping
142   if ( ! AliMpCDB::LoadDDLStore() ) {
143     AliFatal("Could not access mapping from OCDB !");
144   }
145 }
146
147 //__________________________________________________________________________
148 AliMUONDigitMaker::~AliMUONDigitMaker()
149 {
150   /// clean up
151   /// and time processing measure
152
153   delete fRawStreamTracker;
154   delete fRawStreamTrigger;
155   delete fLogger;
156 }
157
158 //____________________________________________________________________
159 void
160 AliMUONDigitMaker::Print(Option_t*) const
161 {
162   /// Printout
163
164   cout << "RawStreamerTracker class=" << fRawStreamTracker->ClassName()
165        << " MakeTriggerDigits=" << fMakeTriggerDigits
166        << " ScalerEvent=" << fScalerEvent
167        << " DigitStore=" << fDigitStore
168        << " TriggerStore=" << fTriggerStore << endl;
169
170   if ( fLogger ) fLogger->Print();
171 }
172
173 //____________________________________________________________________
174 Int_t
175 AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader, 
176                               AliMUONVDigitStore* digitStore,
177                               AliMUONVTriggerStore* triggerStore,
178                               Bool_t sdigit)
179 {
180   /// Main method to creates digit
181   /// for tracker 
182   /// and trigger
183
184   AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
185                   rawReader,digitStore,triggerStore));
186   
187   fDigitStore = digitStore;
188   fTriggerStore = triggerStore;
189   
190   if (!fDigitStore && !fTriggerStore)
191   {
192     fLogger->Log("No digit or trigger store given. Nothing to do...");
193     return kTriggerBAD & kTrackerBAD;
194   }
195   
196   Int_t tracker(kOK);
197   Int_t trigger(kOK);
198   
199   if ( fDigitStore ) 
200   {
201     fDigitStore->Clear(); // insure we start with an empty container
202     tracker = ReadTrackerDDL(rawReader,sdigit);
203   }
204   
205   if ( fTriggerStore || fMakeTriggerDigits ) 
206   {
207     if ( fTriggerStore ) fTriggerStore->Clear();
208     if ( fMakeTriggerDigits && !fDigitStore ) 
209     {
210       fLogger->Log("Asking for trigger digits but digitStore is null");
211     }
212     else
213     {
214       trigger = ReadTriggerDDL(rawReader);
215     }
216   }
217   
218   return tracker | trigger;
219 }
220
221 //____________________________________________________________________
222 Int_t
223 AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader, Bool_t sdigit)
224 {
225   /// Reading tracker DDL
226   /// filling the fDigitStore container, which must not be null
227
228   AliDebug(1,"");
229   
230   AliCodeTimerAuto("",0);
231
232   // elex info
233   Int_t    buspatchId;
234   UChar_t  channelId;
235   UShort_t manuId;
236   UShort_t charge; 
237
238   fRawStreamTracker->SetReader(rawReader);
239   fRawStreamTracker->First();
240   
241   while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge,kTRUE) )
242   {    
243     // getting DE from buspatch
244     Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
245
246     AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
247
248     if (!de)
249       {
250         fLogger->Log(Form("DE %04d does not exist !", detElemId));
251         continue;
252       }
253
254     if (!de->IsConnectedChannel(manuId,channelId))
255       {
256         // non connected pad, do nothing (this is not an error !)
257         continue;
258       }
259
260     const AliMpVSegmentation* seg 
261       = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId, 
262                                                                       manuId);  
263
264     if (!seg)
265     {
266       fLogger->Log(Form("(DE,MANUID)=(%04d,%04d) is not valid",detElemId,manuId));
267       continue;
268     }
269     
270     AliMp::CathodType cathodeType = de->GetCathodType(seg->PlaneType());
271
272     AliMpPad pad = seg->PadByLocation(manuId,channelId,kFALSE);
273
274     if (!pad.IsValid())
275     {
276       fLogger->Log(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
277                     detElemId, manuId, channelId));
278       continue;
279     } 
280
281     AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
282                                             AliMUONVDigitStore::kDeny);
283
284     if (!digit)
285     {
286       fLogger->Log(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
287                     detElemId, manuId, channelId));
288       continue;
289     }
290     
291     digit->SetPadXY(pad.GetIx(),pad.GetIy());
292     
293     if ( sdigit ) 
294     {
295       digit->SetCharge(charge);
296     }
297     else
298     {
299       digit->SetADC(charge);
300     }
301   }
302   
303   if ( fRawStreamTracker->IsErrorMessage() ) 
304   {
305     return kTrackerBAD;
306   }
307   
308   return kOK;
309 }
310
311 //____________________________________________________________________
312 Int_t
313 AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
314 {
315   /// reading tracker DDL like ReadTriggerDDL but with fast decoder interface.
316   /// filling the fTriggerStore container, which must not be null
317
318   const AliMUONRawStreamTriggerHP::AliHeader*          darcHeader  = 0x0;
319   const AliMUONRawStreamTriggerHP::AliRegionalHeader*  regHeader   = 0x0;
320   const AliMUONRawStreamTriggerHP::AliLocalStruct*     localStruct = 0x0;
321
322   Int_t loCircuit;
323
324   fRawStreamTrigger->SetReader(rawReader);
325
326   while (fRawStreamTrigger->NextDDL())
327   {
328     darcHeader = fRawStreamTrigger->GetHeaders();
329     
330     // fill global trigger information
331     if (fTriggerStore) 
332     {
333       if (darcHeader->GetGlobalFlag()) 
334       {
335           AliMUONGlobalTrigger globalTrigger;
336           globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
337           globalTrigger.SetFromGlobalInput(darcHeader->GetGlobalHeader()->fInput);
338           fTriggerStore->SetGlobal(globalTrigger);
339       }
340     }
341     
342     Int_t nReg = fRawStreamTrigger->GetRegionalHeaderCount();
343     
344     for(Int_t iReg = 0; iReg < nReg ;iReg++)
345     {   //reg loop
346       
347
348       // crate info  
349       AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
350                                 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
351       
352       if (!crate) {
353         fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
354         continue;
355       }
356       
357       regHeader =  fRawStreamTrigger->GetRegionalHeader(iReg);
358       
359       Int_t nLocal = regHeader->GetLocalStructCount();
360       for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) 
361       {
362         
363         localStruct = regHeader->GetLocalStruct(iLocal);
364         
365         // if card exist
366         if (localStruct) {
367           
368           loCircuit = crate->GetLocalBoardId(localStruct->GetId());
369
370           if ( !loCircuit ) continue; // empty slot
371
372           AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, kTRUE);
373
374           // skip copy cards
375           if( !localBoard->IsNotified()) 
376              continue;
377           
378           if (fTriggerStore)
379           {
380             // fill local trigger
381             AliMUONLocalTrigger localTrigger;
382             localTrigger.SetLocalStruct(loCircuit, *localStruct);
383             fTriggerStore->Add(localTrigger);
384           }
385           
386           if ( fMakeTriggerDigits )
387           {
388             //FIXEME should find something better than a TArray
389             TArrayS xyPattern[2];
390             
391             localStruct->GetXPattern(xyPattern[0]);
392             localStruct->GetYPattern(xyPattern[1]);
393             
394             TriggerDigits(loCircuit, xyPattern, *fDigitStore);
395           }
396         } // if triggerY
397       } // iLocal
398     } // iReg
399   } // NextDDL
400   
401   return kOK;
402 }
403
404 //____________________________________________________________________
405 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard, 
406                                        const TArrayS* xyPattern,
407                                        AliMUONVDigitStore& digitStore) const
408 {
409   /// make digits for trigger from pattern, and add them to digitStore
410
411   AliCodeTimerAuto("",0);
412   
413   Int_t detElemId;
414
415   AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
416
417   Int_t n,b;
418
419   // loop over x1-4 and y1-4
420   for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
421   {
422     for (Int_t iCath = 0; iCath < 2; ++iCath)
423     {
424       Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber); 
425       if (!pattern) continue;
426       
427       // get detElemId
428       detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
429         
430         const AliMpVSegmentation* seg 
431           = AliMpSegmentation::Instance()
432           ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));  
433         
434         // loop over the 16 bits of pattern
435         for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy) 
436         {
437           if ((pattern >> ibitxy) & 0x1) 
438           {            
439             // not quite sure about this
440             Int_t offset = 0;
441             if (iCath && localBoard->GetSwitch(AliMpLocalBoard::kZeroAllYLSB)) offset = -8;
442             
443             AliMpPad pad = seg->PadByLocation(nBoard,ibitxy+offset,kTRUE);
444                         
445             if (!pad.IsValid()) 
446             {
447               fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
448                               detElemId, nBoard, ibitxy));
449               continue;
450             }
451
452             n = pad.GetLocalBoardId(0); // always take first location so that digits are not inserted several times
453             b = pad.GetLocalBoardChannel(0);
454
455             AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
456                             n,b,nBoard,ibitxy));
457
458             AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
459             
460             if (!digit)
461             {
462                 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
463                                  detElemId,nBoard,ibitxy,iCath));
464                 continue;
465             }
466             
467             Int_t padX = pad.GetIx();
468             Int_t padY = pad.GetIy();
469             
470             // fill digit
471             digit->SetPadXY(padX,padY);
472             digit->SetCharge(1.);
473           }// xyPattern
474         }// ibitxy
475     }// cath
476   } // ichamber
477   
478   return kTRUE;
479 }
480
481 //______________________________________________________________________________
482 Bool_t 
483 AliMUONDigitMaker::TriggerToDigitsStore(const AliMUONVTriggerStore& triggerStore,
484                                         AliMUONVDigitStore& digitStore) const
485 {
486   //
487   /// make (S)Digit for trigger
488   //
489   
490   digitStore.Clear();
491   
492   AliMUONLocalTrigger* locTrg;
493   TIter next(triggerStore.CreateLocalIterator());
494   
495   while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) ) 
496   {
497     if (locTrg->IsNull()) continue;
498    
499     TArrayS xyPattern[2];
500     locTrg->GetXPattern(xyPattern[0]);
501     locTrg->GetYPattern(xyPattern[1]);
502
503     Int_t nBoard = locTrg->LoCircuit();
504     TriggerDigits(nBoard, xyPattern, digitStore);
505   }
506   return kTRUE;
507 }
508
509 //______________________________________________________________________________
510 void 
511 AliMUONDigitMaker::SetTryRecover(Bool_t flag) 
512 {
513   /// Instruct the decoder to try to recover corrupted raw data.
514   /// Only use for specific cases for which you know it will work...
515   fRawStreamTracker->TryRecover(flag);
516 }