]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDigitMaker.cxx
New class AliMUONRecoParamto handle reconstruction parameters
[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 "AliLog.h"
48 #include "AliMUONDDLTrigger.h"
49 #include "AliMUONDarcHeader.h"
50 #include "AliMUONVDigit.h"
51 #include "AliMUONVDigitStore.h"
52 #include "AliMUONGlobalTrigger.h"
53 #include "AliMUONLocalStruct.h"
54 #include "AliMUONLocalTrigger.h"
55 #include "AliMUONRawStreamTracker.h"
56 #include "AliMUONRawStreamTrigger.h"
57 #include "AliMUONRegHeader.h"
58 #include "AliMUONTriggerCircuit.h"
59 #include "AliMpTriggerCrate.h"
60 #include "AliMpLocalBoard.h"
61 #include "AliMUONVTriggerStore.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 "AliRawReader.h"
69 #include <TArrayS.h>
70
71 /// \cond CLASSIMP
72 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
73 /// \endcond
74
75 //__________________________________________________________________________
76 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger)
77   : TObject(),
78     fScalerEvent(kFALSE),
79     fMakeTriggerDigits(kFALSE),
80     fRawStreamTracker(new AliMUONRawStreamTracker()),    
81     fRawStreamTrigger(new AliMUONRawStreamTrigger()),    
82     fTrackerTimer(),
83     fTriggerTimer(),
84     fMappingTimer(),
85     fDigitStore(0x0),
86     fTriggerStore(0x0)
87 {
88   /// ctor 
89
90   AliDebug(1,"");
91
92   // Standard Constructor
93   if (enableErrorLogger) {
94     fRawStreamTracker->EnabbleErrorLogger();
95     fRawStreamTrigger->EnabbleErrorLogger();
96   }
97
98   fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
99   fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
100   fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
101   
102   SetMakeTriggerDigits();
103
104 }
105
106 //__________________________________________________________________________
107 AliMUONDigitMaker::~AliMUONDigitMaker()
108 {
109   /// clean up
110   /// and time processing measure
111
112   delete fRawStreamTracker;
113   delete fRawStreamTrigger;
114
115   AliDebug(1, Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
116                fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
117   AliDebug(1, Form("   Execution time for MUON tracker (mapping calls part) "
118                ": R:%.2fs C:%.2fs",
119                fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
120   AliDebug(1, Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
121                fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
122
123 }
124
125 //____________________________________________________________________
126 Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader, 
127                                     AliMUONVDigitStore* digitStore,
128                                     AliMUONVTriggerStore* triggerStore)
129 {
130   /// Main method to creates digit
131   /// for tracker 
132   /// and trigger
133
134   AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
135                   rawReader,digitStore,triggerStore));
136   
137   fDigitStore = digitStore;
138   fTriggerStore = triggerStore;
139   
140   if (!fDigitStore && !fTriggerStore)
141   {
142     AliError("No digit or trigger store given. Nothing to do...");
143     return kFALSE;
144   }
145   
146   if ( fDigitStore ) 
147   {
148     fDigitStore->Clear(); // insure we start with an empty container
149     ReadTrackerDDL(rawReader);
150   }
151   
152   if ( fTriggerStore || fMakeTriggerDigits ) 
153   {
154     if ( fTriggerStore ) fTriggerStore->Clear();
155     if ( fMakeTriggerDigits && !fDigitStore ) 
156     {
157       AliError("Asking for trigger digits but digitStore is null");
158     }
159     else
160     {
161       ReadTriggerDDL(rawReader);
162     }
163   }
164   
165   return kTRUE;
166 }
167
168 //____________________________________________________________________
169 Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
170 {
171   /// Reading tracker DDL
172   /// filling the fDigitStore container, which must not be null
173
174   AliDebug(1,"");
175   
176   fTrackerTimer.Start(kFALSE);
177
178   // elex info
179   Int_t    buspatchId;
180   UChar_t  channelId;
181   UShort_t manuId;
182   UShort_t charge; 
183
184   fRawStreamTracker->SetReader(rawReader);
185   fRawStreamTracker->First();
186   
187   while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge) )
188   {    
189     // getting DE from buspatch
190     Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
191
192     const AliMpVSegmentation* seg 
193       = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId, 
194                                                                       manuId);  
195
196     AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId, 
197                                                               seg->PlaneType());
198
199     AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kFALSE);
200     
201     if (!pad.IsValid())
202     {
203       AliError(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
204                     detElemId, manuId, channelId));
205       continue;
206     } 
207     
208     AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
209                                             AliMUONVDigitStore::kDeny);
210     if (!digit)
211     {
212       AliError(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
213                     detElemId, manuId, channelId));
214       continue;
215     }
216     
217     digit->SetPadXY(pad.GetIndices().GetFirst(),
218                    pad.GetIndices().GetSecond());
219     
220           digit->SetADC(charge);
221
222   }
223   
224   fTrackerTimer.Stop();
225
226   return kTRUE;
227 }
228
229 //____________________________________________________________________
230 Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
231 {
232   /// reading tracker DDL
233   /// filling the fTriggerStore container, which must not be null
234
235   AliDebug(1,"");
236   
237   AliMUONDDLTrigger*       ddlTrigger      = 0x0;
238   AliMUONDarcHeader*       darcHeader      = 0x0;
239   AliMUONRegHeader*        regHeader       = 0x0;
240   AliMUONLocalStruct*      localStruct     = 0x0;
241
242   Int_t loCircuit;
243
244   fTriggerTimer.Start(kFALSE);
245
246   fRawStreamTrigger->SetReader(rawReader);
247
248   while (fRawStreamTrigger->NextDDL()) 
249   {
250     ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
251     darcHeader = ddlTrigger->GetDarcHeader();
252     
253     // fill global trigger information
254     if (fTriggerStore) 
255     {
256       if (darcHeader->GetGlobalFlag()) 
257       {
258           AliMUONGlobalTrigger globalTrigger;
259           globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
260           fTriggerStore->SetGlobal(globalTrigger);
261       }
262     }
263     
264     Int_t nReg = darcHeader->GetRegHeaderEntries();
265     
266     for(Int_t iReg = 0; iReg < nReg ;iReg++)
267     {   //reg loop
268       
269
270       // crate info  
271       AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
272                                 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
273       
274       if (!crate) 
275         AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
276      
277       
278       regHeader =  darcHeader->GetRegHeaderEntry(iReg);
279       
280       Int_t nLocal = regHeader->GetLocalEntries();
281       for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) 
282       {  
283         
284         localStruct = regHeader->GetLocalEntry(iLocal);
285         
286         // if card exist
287         if (localStruct) {
288           
289           loCircuit = crate->GetLocalBoardId(localStruct->GetId());
290
291           if ( !loCircuit ) continue; // empty slot
292
293           AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
294
295           // skip copy cards
296           if( !localBoard->IsNotified()) 
297              continue;
298           
299           if (fTriggerStore) 
300           {
301             // fill local trigger
302             AliMUONLocalTrigger localTrigger;
303             localTrigger.SetLocalStruct(loCircuit, *localStruct);
304             fTriggerStore->Add(localTrigger);
305           } 
306           
307           if ( fMakeTriggerDigits )
308           {
309             //FIXEME should find something better than a TArray
310             TArrayS xyPattern[2];
311             
312             localStruct->GetXPattern(xyPattern[0]);
313             localStruct->GetYPattern(xyPattern[1]);
314             
315             TriggerDigits(loCircuit, xyPattern, *fDigitStore);
316           }          
317         } // if triggerY
318       } // iLocal
319     } // iReg
320   } // NextDDL
321   
322   fTriggerTimer.Stop();
323
324   return kTRUE;
325
326 }
327
328 //____________________________________________________________________
329 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard, 
330                                        TArrayS* xyPattern,
331                                        AliMUONVDigitStore& digitStore) const
332 {
333   /// make digits for trigger from pattern, and add them to digitStore
334
335   Int_t detElemId;
336
337   AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
338
339   Int_t n,b;
340
341   // loop over x1-4 and y1-4
342   for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
343   {
344     for (Int_t iCath = 0; iCath < 2; ++iCath)
345     {
346       Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber); 
347       if (!pattern) continue;
348       
349       // get detElemId
350       detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
351         
352         const AliMpVSegmentation* seg 
353           = AliMpSegmentation::Instance()
354           ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));  
355         
356         // loop over the 16 bits of pattern
357         for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy) 
358         {
359           if ((pattern >> ibitxy) & 0x1) 
360           {            
361             // not quite sure about this
362             Int_t offset = 0;
363             if (iCath && localBoard->GetSwitch(6)) offset = -8;
364             
365             AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE);
366                         
367             if (!pad.IsValid()) 
368             {
369               AliWarning(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
370                               detElemId, nBoard, ibitxy));
371               continue;
372             }
373
374             n = pad.GetLocation(0).GetFirst(); // always take first location so that digits are not inserted several times
375             b = pad.GetLocation(0).GetSecond();
376
377             AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
378                             n,b,nBoard,ibitxy));
379
380             AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
381             
382             if (!digit)
383             {
384                 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
385                                  detElemId,nBoard,ibitxy,iCath));
386                 continue;
387             }
388             
389             Int_t padX = pad.GetIndices().GetFirst();
390             Int_t padY = pad.GetIndices().GetSecond();
391             
392             // fill digit
393             digit->SetPadXY(padX,padY);
394             digit->SetCharge(1.);
395           }// xyPattern
396         }// ibitxy
397     }// cath
398   } // ichamber
399   
400   return kTRUE;
401