]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDigitMaker.cxx
Rewritten using new VDigitStore, VDigit and VTriggerStore interfaces (Laurent)
[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 /// \class AliMUONDigitMaker
17 /// MUON Digit maker from rawdata.
18 ///
19 /// Raw2Digits:
20 /// Using real mapping  for tracker
21 /// Indranil Das (Adapted for runloader: Ch. Finck) july 05
22 ///
23 /// Implemented non-constant buspatch numbers for tracking
24 /// with correct DDL id.
25 /// (Ch. Finck, dec 05)
26 ///
27 /// Add reader for scaler trigger events
28 /// Use memcpy instead of assignment elt by elt
29 /// (Ch. Finck, Jan 06)
30 ///
31 /// Using new interface with AliMUONRawStreamTracker(Trigger)
32 /// (New interface of AliMUONRawReader class)
33 /// (further details could be found in Alice-note)
34 /// (Ch. Finck, March 06)
35 ///
36 /// Add (S)Digit maker tracker (for free)
37 /// and for trigger. Create trigger inverse mapping.
38 ///
39 /// \author Ch. Finck, oct 06 
40
41 #include "AliMUONDigitMaker.h"
42
43 #include "AliLog.h"
44 #include "AliMUONDDLTrigger.h"
45 #include "AliMUONDarcHeader.h"
46 #include "AliMUONVDigit.h"
47 #include "AliMUONVDigitStore.h"
48 #include "AliMUONGlobalTrigger.h"
49 #include "AliMUONLocalStruct.h"
50 #include "AliMUONLocalTrigger.h"
51 #include "AliMUONLocalTriggerBoard.h"
52 #include "AliMUONRawStreamTracker.h"
53 #include "AliMUONRawStreamTrigger.h"
54 #include "AliMUONRegHeader.h"
55 #include "AliMUONTriggerCircuit.h"
56 #include "AliMUONTriggerCrate.h"
57 #include "AliMUONTriggerCrateStore.h"
58 #include "AliMUONVTriggerStore.h"
59 #include "AliMpCathodType.h"
60 #include "AliMpDDLStore.h"
61 #include "AliMpDEManager.h"
62 #include "AliMpPad.h"
63 #include "AliMpSegmentation.h"
64 #include "AliMpVSegmentation.h"
65 #include "AliRawReader.h"
66 #include <TArrayS.h>
67
68 /// \cond CLASSIMP
69 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
70 /// \endcond
71
72 //__________________________________________________________________________
73 AliMUONDigitMaker::AliMUONDigitMaker()
74   : TObject(),
75     fScalerEvent(kFALSE),
76     fMakeTriggerDigits(kFALSE),
77     fRawStreamTracker(new AliMUONRawStreamTracker()),    
78     fRawStreamTrigger(new AliMUONRawStreamTrigger()),    
79     fCrateManager(0x0),
80     fTrackerTimer(),
81     fTriggerTimer(),
82     fMappingTimer(),
83     fDigitStore(0x0),
84     fTriggerStore(0x0)
85 {
86   /// ctor 
87
88   AliDebug(1,"");
89
90   // Standard Constructor
91
92   fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
93   fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
94   fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
95   
96   SetMakeTriggerDigits();
97
98 }
99
100 //__________________________________________________________________________
101 AliMUONDigitMaker::~AliMUONDigitMaker()
102 {
103   /// clean up
104   /// and time processing measure
105
106   delete fRawStreamTracker;
107   delete fRawStreamTrigger;
108
109   AliDebug(1, Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
110                fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
111   AliDebug(1, Form("   Execution time for MUON tracker (mapping calls part) "
112                ": R:%.2fs C:%.2fs",
113                fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
114   AliDebug(1, Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
115                fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
116
117 }
118
119 //____________________________________________________________________
120 Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader, 
121                                     AliMUONVDigitStore* digitStore,
122                                     AliMUONVTriggerStore* triggerStore)
123 {
124   /// Main method to creates digit
125   /// for tracker 
126   /// and trigger
127
128   AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
129                   rawReader,digitStore,triggerStore));
130   
131   fDigitStore = digitStore;
132   fTriggerStore = triggerStore;
133   
134   if (!fDigitStore && !fTriggerStore)
135   {
136     AliError("No digit or trigger store given. Nothing to do...");
137     return kFALSE;
138   }
139   
140   if ( fDigitStore ) 
141   {
142     fDigitStore->Clear(); // insure we start with an empty container
143     ReadTrackerDDL(rawReader);
144   }
145   
146   if ( fTriggerStore || fMakeTriggerDigits ) 
147   {
148     if ( fTriggerStore ) fTriggerStore->Clear();
149     if ( fMakeTriggerDigits && !fDigitStore ) 
150     {
151       AliError("Asking for trigger digits but digitStore is null");
152     }
153     else
154     {
155       ReadTriggerDDL(rawReader);
156     }
157   }
158   
159   return kTRUE;
160 }
161
162 //____________________________________________________________________
163 Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
164 {
165   /// Reading tracker DDL
166   /// filling the fDigitStore container, which must not be null
167
168   AliDebug(1,"");
169   
170   fTrackerTimer.Start(kFALSE);
171
172   // elex info
173   Int_t    buspatchId;
174   UChar_t  channelId;
175   UShort_t manuId;
176   UShort_t charge; 
177
178   fRawStreamTracker->SetReader(rawReader);
179   fRawStreamTracker->First();
180   
181   while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge) )
182   {    
183     // getting DE from buspatch
184     Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
185
186     const AliMpVSegmentation* seg 
187       = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId, 
188                                                                       manuId);  
189
190     AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId, 
191                                                               seg->PlaneType());
192
193     AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kFALSE);
194     
195     if (!pad.IsValid())
196     {
197       AliError(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
198                     detElemId, manuId, channelId));
199       continue;
200     } 
201     
202     AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
203                                             AliMUONVDigitStore::kDeny);
204     if (!digit)
205     {
206       AliError(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
207                     detElemId, manuId, channelId));
208       continue;
209     }
210     
211     digit->SetPadXY(pad.GetIndices().GetFirst(),
212                    pad.GetIndices().GetSecond());
213     
214           digit->SetADC(charge);
215
216   }
217   
218   fTrackerTimer.Stop();
219
220   return kTRUE;
221 }
222
223 //____________________________________________________________________
224 Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
225 {
226   /// reading tracker DDL
227   /// filling the fTriggerStore container, which must not be null
228
229   AliDebug(1,"");
230   
231   AliMUONDDLTrigger*       ddlTrigger      = 0x0;
232   AliMUONDarcHeader*       darcHeader      = 0x0;
233   AliMUONRegHeader*        regHeader       = 0x0;
234   AliMUONLocalStruct*      localStruct     = 0x0;
235
236   Int_t loCircuit;
237
238   fTriggerTimer.Start(kFALSE);
239
240   fRawStreamTrigger->SetReader(rawReader);
241
242   while (fRawStreamTrigger->NextDDL()) 
243   {
244     ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
245     darcHeader = ddlTrigger->GetDarcHeader();
246     
247     // fill global trigger information
248     if (fTriggerStore) 
249     {
250       if (darcHeader->GetGlobalFlag()) 
251       {
252           AliMUONGlobalTrigger globalTrigger;
253           globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
254           fTriggerStore->SetGlobal(globalTrigger);
255       }
256     }
257     
258     Int_t nReg = darcHeader->GetRegHeaderEntries();
259     
260     for(Int_t iReg = 0; iReg < nReg ;iReg++)
261     {   //reg loop
262       
263       // crate info
264       if (!fCrateManager) AliFatal("Crate Store not defined");
265       AliMUONTriggerCrate* crate = fCrateManager->Crate(fRawStreamTrigger->GetDDL(), iReg);
266       
267       if (!crate) 
268         AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
269       
270       TObjArray *boards  = crate->Boards();
271       
272       regHeader =  darcHeader->GetRegHeaderEntry(iReg);
273       
274       Int_t nLocal = regHeader->GetLocalEntries();
275       for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) 
276       {  
277         
278         localStruct = regHeader->GetLocalEntry(iLocal);
279         
280         // if card exist
281         if (localStruct) {
282           
283           AliMUONLocalTriggerBoard* localBoard = 
284           (AliMUONLocalTriggerBoard*)boards->At(localStruct->GetId()+1);
285           
286           // skip copy cards
287           if( !(loCircuit = localBoard->GetNumber()) )
288             continue;
289           
290           if (fTriggerStore) 
291           {
292             // fill local trigger
293             AliMUONLocalTrigger localTrigger;
294             localTrigger.SetLocalStruct(loCircuit, *localStruct);
295             fTriggerStore->Add(localTrigger);
296           } 
297           
298           if ( fMakeTriggerDigits )
299           {
300             //FIXEME should find something better than a TArray
301             TArrayS xyPattern[2];
302             xyPattern[0].Set(4);
303             xyPattern[1].Set(4);
304             
305             xyPattern[0].AddAt(localStruct->GetX1(),0);
306             xyPattern[0].AddAt(localStruct->GetX2(),1);
307             xyPattern[0].AddAt(localStruct->GetX3(),2);
308             xyPattern[0].AddAt(localStruct->GetX4(),3);
309             
310             xyPattern[1].AddAt(localStruct->GetY1(),0);
311             xyPattern[1].AddAt(localStruct->GetY2(),1);
312             xyPattern[1].AddAt(localStruct->GetY3(),2);
313             xyPattern[1].AddAt(localStruct->GetY4(),3);
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   // loop over x1-4 and y1-4
336   for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
337   {
338     for (Int_t iCath = 0; iCath < 2; ++iCath)
339     {
340       Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber); 
341       if (!pattern) continue;
342       
343       // get detElemId
344       AliMUONTriggerCircuit triggerCircuit;
345       AliMUONLocalTriggerBoard* localBoard = fCrateManager->LocalBoard(nBoard);
346       Int_t detElemId = triggerCircuit.DetElemId(iChamber+10, localBoard->GetName());//FIXME +/-10 (should be ok with new mapping)
347         
348         const AliMpVSegmentation* seg 
349           = AliMpSegmentation::Instance()
350           ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));  
351         
352         // loop over the 16 bits of pattern
353         for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy) 
354         {
355           if ((pattern >> ibitxy) & 0x1) 
356           {            
357             // not quite sure about this
358             Int_t offset = 0;
359             if (iCath && localBoard->GetSwitch(6)) offset = -8;
360             
361             AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE);
362                         
363             if (!pad.IsValid()) 
364             {
365               AliWarning(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
366                               detElemId, nBoard, ibitxy));
367               continue;
368             }
369             
370             AliMUONVDigit* digit = digitStore.Add(detElemId,nBoard,ibitxy,iCath,AliMUONVDigitStore::kDeny);
371             
372             if (!digit)
373             {
374               AliError(Form("Could not add digit DE %04d LocalBoard %03d ibitxy %02d cath %d",
375                             detElemId,nBoard,ibitxy,iCath));
376               continue;
377             }
378             
379             Int_t padX = pad.GetIndices().GetFirst();
380             Int_t padY = pad.GetIndices().GetSecond();
381             
382             // fill digit
383             digit->SetPadXY(padX,padY);
384             digit->SetCharge(1.);
385           }// xyPattern
386         }// ibitxy
387     }// cath
388   } // ichamber
389   
390   return kTRUE;
391
392 //____________________________________________________________________
393 void  
394 AliMUONDigitMaker::GetCrateName(Char_t* name, Int_t iDDL, Int_t iReg) const
395 {
396   /// set crate name from DDL & reg number
397   /// method same as in RawWriter, not so nice
398   /// should be put in AliMUONTriggerCrateStore
399
400       switch(iReg) {
401       case 0:
402       case 1:
403         sprintf(name,"%d", iReg+1);
404         break;
405       case 2:
406         strcpy(name, "2-3");
407         break;
408       case 3:
409       case 4:
410       case 5:
411       case 6:
412       case 7:
413         sprintf(name,"%d", iReg);
414         break;
415       }
416
417       // crate Right for first DDL
418       if (iDDL == 0)
419         strcat(name, "R");
420       else 
421         strcat(name, "L"); 
422 }