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