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