]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONRawData.cxx
Unique material names (R.Grosso)
[u/mrichter/AliRoot.git] / MUON / AliMUONRawData.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 ////////////////////////////////////
17 //
18 // MUON Raw Data generator in ALICE-MUON
19 //
20 // This class version 1 (further details could be found in Alice-note coming soon right in our direction)
21 // Generates raw data for MUON tracker and finally for trigger
22 // * a simple mapping is used (see below)
23 // * the bus patch id is calculated with an absolute number 0 - 999
24 // * one DDL per 1/2 chamber is created for both cathode.
25 // For trigger there is no mapping (mapping could be found in AliMUONTriggerCircuit)
26 // don't need for digits2raw but needed in raw2Reco
27 // the position are given per local card
28 ////////////////////////////////////
29
30 #include <TClonesArray.h>
31 #include "AliMUONRawData.h"
32 #include "AliMUONDigit.h"
33
34 #include "AliMUON.h"
35 #include "AliMUONChamber.h"
36 #include "AliMUONConstants.h"
37 #include "AliMUONData.h"
38 #include "AliLoader.h"
39 #include "AliBitPacking.h" 
40
41 #include "AliMUONSubEventTrigger.h"
42 #include "AliMUONDDLTracker.h"
43 #include "AliMUONDDLTrigger.h"
44
45 #include "AliMUONLocalTrigger.h"
46 #include "AliMUONGlobalTrigger.h"
47
48 #include "AliMUONGeometrySegmentation.h"
49 #include "AliMUONSegmentManuIndex.h"
50 #include "AliLog.h"
51 #include "AliRun.h"
52
53 const Int_t AliMUONRawData::fgkDefaultPrintLevel = 0;
54
55 ClassImp(AliMUONRawData) // Class implementation in ROOT context
56
57 //__________________________________________________________________________
58 AliMUONRawData::AliMUONRawData(AliLoader* loader)
59   : TObject(),
60     fDebug(0)
61 {
62   // Standard Constructor
63  
64   fPrintLevel = fgkDefaultPrintLevel;
65
66   // initialize loader's
67   fLoader = loader;
68
69   // initialize container
70   fMUONData  = new AliMUONData(fLoader,"MUON","MUON");
71
72   // initialize array
73   fSubEventArray[0] = new TClonesArray("AliMUONSubEventTracker",1000);
74   fSubEventArray[1] = new TClonesArray("AliMUONSubEventTracker",1000);
75
76   // initialize array not used for the moment
77   fSubEventTrigArray[0] = new TClonesArray("AliMUONSubEventTrigger",1000);
78   fSubEventTrigArray[1] = new TClonesArray("AliMUONSubEventTrigger",1000);
79
80   // ddl pointer
81   fDDLTracker = new AliMUONDDLTracker();
82   fDDLTrigger = new  AliMUONDDLTrigger();
83 }
84
85 //__________________________________________________________________________
86 AliMUONRawData::AliMUONRawData()
87   : TObject(),
88     fMUONData(0),
89     fPrintLevel(fgkDefaultPrintLevel),
90     fDebug(0),
91     fLoader(0)
92 {
93   // Default Constructor
94 }
95
96 //_______________________________________________________________________
97 AliMUONRawData::AliMUONRawData (const AliMUONRawData& rhs)
98   : TObject(rhs)
99 {
100 // Protected copy constructor
101
102   AliFatal("Not implemented.");
103 }
104
105 //_______________________________________________________________________
106 AliMUONRawData & 
107 AliMUONRawData::operator=(const AliMUONRawData& rhs)
108 {
109 // Protected assignement operator
110
111   if (this == &rhs) return *this;
112
113   AliFatal("Not implemented.");
114     
115   return *this;  
116 }
117
118 //__________________________________________________________________________
119 AliMUONRawData::~AliMUONRawData(void)
120 {
121   if (fMUONData)
122     delete fMUONData;
123   if (fSubEventArray[0])
124     fSubEventArray[0]->Delete(); //using delete cos allocating memory in copy ctor.
125   if (fSubEventArray[1])
126     fSubEventArray[1]->Delete();
127
128   if (fSubEventTrigArray[0])
129     fSubEventTrigArray[0]->Delete();
130   if (fSubEventTrigArray[1])
131     fSubEventTrigArray[1]->Delete();
132
133   if (fDDLTracker)
134     delete fDDLTracker;
135   if (fDDLTrigger)
136     delete fDDLTrigger;
137
138   return;
139 }
140 //____________________________________________________________________
141 Int_t AliMUONRawData::WriteRawData()
142 {
143  // convert digits of the current event to raw data
144
145   Int_t idDDL;
146   Char_t name[20];
147
148   fLoader->LoadDigits("READ");
149
150   fMUONData->SetTreeAddress("D,GLT");
151
152
153   // tracking chambers
154
155   for (Int_t ich = 0; ich < AliMUONConstants::NTrackingCh(); ich++) {
156  
157     // open files
158     idDDL = ich * 2  + 0x900;
159     sprintf(name, "MUON_%d.ddl",idDDL);
160     fFile1 = fopen(name,"w");
161
162     idDDL = (ich * 2) + 1 + 0x900;
163     sprintf(name, "MUON_%d.ddl",idDDL);
164     fFile2 = fopen(name,"w");
165
166     WriteTrackerDDL(ich);
167   
168     // reset and close
169     fclose(fFile1);
170     fclose(fFile2);
171     fMUONData->ResetDigits();
172   }
173  
174   // trigger chambers
175  
176   // open files
177   idDDL = 0xA00;
178   sprintf(name, "MUTR_%d.ddl",idDDL);
179   fFile1 = fopen(name,"w");
180
181   idDDL = 0xA00 + 1;
182   sprintf(name, "MUTR_%d.ddl",idDDL);
183   fFile2 = fopen(name,"w");
184
185   WriteTriggerDDL();
186   
187   // reset and close
188   fclose(fFile1);
189   fclose(fFile2);
190   fMUONData->ResetTrigger();
191   
192   fLoader->UnloadDigits();
193
194   return kTRUE;
195 }
196 //____________________________________________________________________
197 Int_t AliMUONRawData::WriteTrackerDDL(Int_t iCh)
198 {
199   // resets
200   TClonesArray* muonDigits = 0;
201   fSubEventArray[0]->Clear();
202   fSubEventArray[1]->Clear();
203
204   //
205   TArrayI nbInBus[2];
206
207   nbInBus[0].Set(5000);
208   nbInBus[1].Set(5000);
209
210   nbInBus[0].Reset();
211   nbInBus[1].Reset();
212
213   // DDL header
214   AliRawDataHeader header = fDDLTracker->GetHeader();
215   Int_t headerSize = fDDLTracker->GetHeaderSize();
216
217   // DDL event one per half chamber
218   AliMUONSubEventTracker* subEvent;
219
220   // data format
221   Char_t parity = 0x4;
222   UShort_t manuId = 0;
223   UChar_t channelId = 0;
224   UShort_t charge = 0;
225   Int_t busPatchId = 0;
226
227   UInt_t word;
228   Int_t nEntries = 0;
229   Int_t* buffer = 0;
230   Int_t index;
231   Int_t indexDsp;
232   Int_t indexBlk;
233   Int_t padX;
234   Int_t padY;
235   Int_t cathode = 0;
236   Int_t detElemId;
237   Int_t nDigits;
238   const AliMUONDigit* digit;
239
240   AliMUON *pMUON;
241   AliMUONChamber* iChamber = 0x0;
242   AliMUONGeometrySegmentation* segmentation2[2];
243
244   segmentation2[0]=iChamber->SegmentationModel2(1); // cathode 0
245   segmentation2[1]=iChamber->SegmentationModel2(2); // cathode 1
246
247    pMUON = (AliMUON*) gAlice->GetModule("MUON");
248    iChamber =  &(pMUON->Chamber(iCh));
249
250
251    AliDebug(1, Form("WriteDDL chamber %d\n", iCh+1));
252
253    for (Int_t iCath = 0; iCath < 2; iCath++) {
254
255     fMUONData->ResetDigits();
256     fMUONData->GetCathode(iCath);
257     muonDigits = fMUONData->Digits(iCh);
258
259     nDigits = muonDigits->GetEntriesFast();
260     if (fPrintLevel == 2)
261       printf("ndigits = %d\n",nDigits);
262
263     // open DDL file, on per 1/2 chamber
264  
265     for (Int_t idig = 0; idig < nDigits; idig++) {
266
267       digit = (AliMUONDigit*) muonDigits->UncheckedAt(idig);
268
269       padX = digit->PadX();
270       padY = digit->PadY();
271       charge = digit->Signal();
272       charge &= 0xFFF;
273       cathode = digit->Cathode();
274       detElemId = digit->DetElemId();
275
276       // mapping
277       if (detElemId == 0) {
278         AliWarning("\ndetElemId = 0, old segmentation !\n");
279         GetDummyMapping(iCh, iCath, digit, busPatchId, manuId, channelId);
280       } else {
281       // mapping (not far from real one)
282         AliMUONSegmentManuIndex* connect = segmentation2[iCath]->GetMpConnection(detElemId, padX, padY);
283         if (connect != 0x0) {
284           busPatchId = connect->GetBusPatchId(); 
285           manuId     = connect->GetManuId();
286           channelId  = connect->GetManuChannelId();
287           AliDebug(3,Form("busPatchId %d, manuId: %d, channelId: %d\n", busPatchId, manuId, channelId));
288         } else {
289           busPatchId = 0; 
290           manuId     = 0;
291           channelId  = 0;
292         }
293
294       }
295       //packing word
296       AliBitPacking::PackWord((UInt_t)parity,word,29,31);
297       AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
298       AliBitPacking::PackWord((UInt_t)channelId,word,12,17);
299       AliBitPacking::PackWord((UInt_t)charge,word,0,11);
300
301       // set sub Event
302       subEvent = new AliMUONSubEventTracker();
303       subEvent->AddData(word);
304       subEvent->SetBusPatchId(busPatchId);
305       if (digit->PadX() > 0) {
306         nbInBus[0][busPatchId]++;
307         AddData1(subEvent);
308       } else {
309         nbInBus[1][busPatchId]++;
310         AddData2(subEvent);
311       }
312       delete subEvent;
313     }
314   }
315   fSubEventArray[0]->Sort();
316   fSubEventArray[1]->Sort();
317
318   // gather datas from same bus patch
319    for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
320     nEntries = fSubEventArray[iDDL]->GetEntriesFast();
321
322     for (Int_t i = 0; i < nEntries; i++) {
323       AliMUONSubEventTracker* temp = (AliMUONSubEventTracker*)fSubEventArray[iDDL]->At(i);
324       busPatchId = temp->GetBusPatchId();
325
326       // add bus patch header, length and total length managed by subevent class
327       temp->SetTriggerWord(0xdeadbeef);
328       for (Int_t j = 0; j < nbInBus[iDDL][busPatchId]-1; j++) {
329         AliMUONSubEventTracker* temp1 =  (AliMUONSubEventTracker*)fSubEventArray[iDDL]->At(++i);
330         temp->AddData(temp1->GetData(0));
331         fSubEventArray[iDDL]->RemoveAt(i) ;
332       }
333     }
334     fSubEventArray[iDDL]->Compress();
335
336     if (fPrintLevel == 3) {
337       nEntries = fSubEventArray[iDDL]->GetEntriesFast();
338       for (Int_t i = 0; i < nEntries; i++) {
339         AliMUONSubEventTracker* temp =  (AliMUONSubEventTracker*)fSubEventArray[iDDL]->At(i);
340         printf("busPatchid back %d\n",temp->GetBusPatchId());
341         for (Int_t j = 0; j < temp->GetLength(); j++) {
342           printf("manuId back %d, ",temp->GetManuId(j));
343           printf("channelId back %d, ",temp->GetChannelId(j));
344           printf("charge back %d\n",temp->GetCharge(j));
345         }
346       }
347       printf("\n");
348     }
349   
350   }
351   
352   Int_t iBusPatch;
353   Int_t iEntries;
354   Int_t length;
355
356   for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
357  
358
359     // filling buffer
360     nEntries = fSubEventArray[iDDL]->GetEntriesFast();
361     buffer = new Int_t [(2048+24)*50]; // 24 words in average for one buspatch and 2048 manu info at most
362
363     indexBlk = 0;
364     indexDsp = 0;
365     index = 0;
366     iBusPatch = 0;
367     iEntries = 0;
368
369     for (Int_t iBlock = 0; iBlock < 2; iBlock++) {
370
371       // block header
372       //    fDDLTracker->SetTotalBlkLength(0xFFFFFFFF);
373       length = fDDLTracker->GetBlkHeaderLength();
374       memcpy(&buffer[index],fDDLTracker->GetBlkHeader(),length*4);
375       indexBlk = index;
376       index += length; 
377
378       for (Int_t iDsp = 0; iDsp < 5; iDsp++) {
379
380         // DSP header
381         //      fDDLTracker->SetTotalDspLength(0xEEEEEEEE);
382         length = fDDLTracker->GetDspHeaderLength();
383         memcpy(&buffer[index],fDDLTracker->GetDspHeader(),length*4);
384         indexDsp = index;
385         index += length; 
386
387         for (Int_t i = 0; i < 5; i++) {
388
389           iBusPatch = i + iBlock*25 + iDsp*5 + 50*(2*iCh + iDDL);
390
391           AliMUONSubEventTracker* temp = (AliMUONSubEventTracker*)fSubEventArray[iDDL]->At(iEntries);
392           if (nEntries > 0) 
393             busPatchId = temp->GetBusPatchId();
394            else
395             busPatchId = -1;
396
397           if (busPatchId == iBusPatch) {
398             // add bus patch structure
399             length = temp->GetHeaderLength();
400             memcpy(&buffer[index],temp->GetAddress(),length*4);
401             index += length;
402             for (Int_t j = 0; j < temp->GetLength(); j++) 
403               buffer[index++] =  temp->GetData(j);
404             if (iEntries < nEntries-1)
405               iEntries++;
406           } else {
407             buffer[index++] = 4; // total length
408             buffer[index++] = 0; // raw data length
409             buffer[index++] = iBusPatch; // bus patch
410             buffer[index++] = 0xdeadbeef; // trigger word
411           }
412         } // bus patch
413         buffer[indexDsp] = index - indexDsp; // dsp length
414         buffer[indexDsp+1] = index - indexDsp - fDDLTracker->GetDspHeaderLength();
415         if ((index - indexDsp) % 2 == 0)
416           buffer[indexDsp+7] = 0;
417         else
418           buffer[indexDsp+7] = 1;
419       } // dsp
420       buffer[indexBlk] = index - indexBlk; // block length
421       buffer[indexBlk+1] = index - indexBlk - fDDLTracker->GetBlkHeaderLength();
422     }
423     if (iDDL == 0) {
424       // write DDL 1
425       header.fSize = (index + headerSize) * 4;// total length in bytes
426       fwrite((char*)(&header),headerSize*4,1,fFile1);
427       fwrite(buffer,sizeof(int),index,fFile1);
428     } 
429     if (iDDL == 1) {
430       // write DDL 2
431       header.fSize = (index + headerSize) * 4;// total length in bytes
432       fwrite((char*)(&header),headerSize*4,1,fFile2);
433       fwrite(buffer,sizeof(int),index,fFile2);
434     }
435     delete[] buffer;
436   }
437
438   return kTRUE;
439 }
440 //____________________________________________________________________
441 Int_t AliMUONRawData::WriteTriggerDDL()
442 {
443
444  // DDL event one per half chamber
445   AliMUONSubEventTrigger* subEvent = 0x0;
446
447
448   // stored local id number 
449   TArrayI isFired(256);
450   isFired.Reset();
451
452
453  // DDL header
454   AliRawDataHeader header = fDDLTrigger->GetHeader();
455   Int_t headerSize = fDDLTrigger->GetHeaderSize();
456   Int_t length;
457   TClonesArray* localTrigger;
458   TClonesArray* globalTrigger;
459   AliMUONGlobalTrigger* gloTrg;
460   AliMUONLocalTrigger* locTrg = 0x0;
461
462   fMUONData->GetTriggerD();
463
464   // global trigger for trigger pattern
465   globalTrigger = fMUONData->GlobalTrigger(); 
466   gloTrg = (AliMUONGlobalTrigger*)globalTrigger->UncheckedAt(0);
467   Int_t gloTrigPat = GetGlobalTriggerPattern(gloTrg);
468
469   // local trigger 
470   localTrigger = fMUONData->LocalTrigger();    
471
472   UInt_t word;
473   Int_t* buffer = 0;
474   Int_t index;
475   Int_t iEntries = 0;
476   Int_t iLocCard, locCard;
477   Char_t locDec, trigY, posY, devX, posX,regOut;
478   Int_t version = 1; // software version
479   Int_t eventType = 1; // trigger type: 1 for physics ?
480   Int_t serialNb = 0xF; // serial nb of card: all bits on for the moment
481   Int_t globalFlag = 1; // set to 2 if global info present in DDL else set to 1
482
483   Int_t nEntries = (Int_t) (localTrigger->GetEntries());// 234 local cards
484   // stored the local card id that's fired
485   for (Int_t i = 0; i <  nEntries; i++) {
486     locTrg = (AliMUONLocalTrigger*)localTrigger->At(i);
487     isFired[locTrg->LoCircuit()] = 1;
488   }
489
490   if (!nEntries)
491     AliError("No Trigger information available");
492
493   buffer = new Int_t [672]; // [16(local)*5 words + 3 words]*8(reg) + 8 words = 672
494
495   for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
496     
497     index = 0; 
498
499     // DDL enhanced header
500     word = 0;
501     AliBitPacking::PackWord((UInt_t)iDDL+1,word,28,31); //see AliMUONDDLTrigger.h for details
502     AliBitPacking::PackWord((UInt_t)serialNb,word,24,27);
503     AliBitPacking::PackWord((UInt_t)version,word,16,23);
504     AliBitPacking::PackWord((UInt_t)eventType,word,12,15);
505
506     if (iDDL == 0) // suppose global info in DDL one
507       globalFlag = 2;
508     else 
509       globalFlag = 1;
510     AliBitPacking::PackWord((UInt_t)globalFlag,word,8,11);
511     fDDLTrigger->SetDDLWord(word);
512
513     if (iDDL == 0)
514       fDDLTrigger->SetGlobalOutput(gloTrigPat);// no global input for the moment....
515     else 
516       fDDLTrigger->SetGlobalOutput(0);
517     length = fDDLTrigger->GetHeaderLength(); 
518     memcpy(&buffer[index],fDDLTrigger->GetEnhancedHeader(),length*4);
519     index += length; 
520
521     for (Int_t iReg = 0; iReg < 8; iReg++) {
522
523       subEvent = new AliMUONSubEventTrigger();
524
525       // Regional card header
526       word = 0;
527       regOut  = 0;
528       AliBitPacking::PackWord((UInt_t)serialNb,word,24,28); //see  AliMUONSubEventTrigger.h for details
529       AliBitPacking::PackWord((UInt_t)version,word,16,23);
530       AliBitPacking::PackWord((UInt_t)iReg,word,12,15);
531       AliBitPacking::PackWord((UInt_t)regOut,word,0,7); // whenever regional output will be implemented
532
533       subEvent->SetRegWord(word);
534       memcpy(&buffer[index++],subEvent->GetAddress(),4);
535
536       buffer[index++] = 0;// 2 words of regional input
537       buffer[index++] = 0;
538
539       for (Int_t iLoc = 0; iLoc < 16; iLoc++) {
540
541         iLocCard = iLoc + iReg*16 + iDDL*128;
542
543         if (isFired[iLocCard]) {
544           locTrg = (AliMUONLocalTrigger*)localTrigger->At(iEntries);
545           locCard = locTrg->LoCircuit();
546           locDec = locTrg->GetLoDecision();
547           trigY = 0;
548           posY = locTrg->LoStripY();
549           posX = locTrg->LoStripX();
550           devX = locTrg->LoDev();
551           if (fPrintLevel == 4) 
552             printf("loctrg %d, posX %d, posY %d, devX %d\n", 
553                    locTrg-> LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev());
554         } else { //no trigger (see PRR chpt 3.4)
555           locCard = -1;
556           locDec = 0;
557           trigY = 1;
558           posY = 15;
559           posX = 0;
560           devX = 0x8000;
561         }
562
563         //packing word
564         word = 0;
565         AliBitPacking::PackWord((UInt_t)(iLocCard % 16),word,19,22); //card id number in crate
566         AliBitPacking::PackWord((UInt_t)locDec,word,15,18);
567         AliBitPacking::PackWord((UInt_t)trigY,word,14,14);
568         AliBitPacking::PackWord((UInt_t)posY,word,10,13);
569         AliBitPacking::PackWord((UInt_t)devX,word,5,9);
570         AliBitPacking::PackWord((UInt_t)posX,word,0,4);
571
572         if (locCard == iLocCard) {
573           // add local cards structure
574           buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16));
575           buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16));
576           buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16));
577           buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16));
578           buffer[index++] = (Int_t)word; // data word
579           if (iEntries < nEntries-1)
580             iEntries++;
581         } else {
582           buffer[index++] = 0; // 4 words for x1, x2, y1, y2
583           buffer[index++] = 0; 
584           buffer[index++] = 0; 
585           buffer[index++] = 0; 
586           buffer[index++] = (Int_t)word; // data word
587
588         }
589       } // local card 
590
591       delete subEvent;  
592
593     } // Regional card
594     
595     buffer[index++] = fDDLTrigger->GetEoD(); // End of DDL word
596     buffer[index++] = fDDLTrigger->GetEoD(); // End of DDL word for 64 bits transfer purpose
597
598     
599     if (iDDL == 0) {
600       // write DDL 1
601       header.fSize = (index + headerSize) * 4;// total length in bytes
602       fwrite((char*)(&header),headerSize*4,1,fFile1);
603       fwrite(buffer,sizeof(int),index,fFile1);
604     } 
605     if (iDDL == 1) {
606       // write DDL 2
607       header.fSize = (index + headerSize) * 4;// total length in bytes
608       fwrite((char*)(&header),headerSize*4,1,fFile2);
609       fwrite(buffer,sizeof(int),index,fFile2);
610     }
611   }
612   delete[] buffer;
613
614   return kTRUE;
615 }
616 //____________________________________________________________________
617 void AliMUONRawData::GetDummyMapping(Int_t iCh, Int_t iCath, const AliMUONDigit* digit,
618                                      Int_t &busPatchId, UShort_t &manuId, UChar_t &channelId)
619 {
620 // Dummy mapping for tracker
621
622   Int_t offsetX = 0; // offet row
623   Int_t offsetY = 0; // offset columns
624   Int_t offsetCath = 0; //offset from one cathod to the other
625   Int_t maxChannel = 0; // maximum nb of channel in 1/2 chamber
626   Int_t id;
627       switch (iCh+1) {
628       case 1:
629       case 2:
630       case 3:
631       case 4:
632         offsetX = 512;
633         offsetY = 256;
634         offsetCath = 65536;
635         maxChannel = (offsetY * offsetX + 2* offsetY + offsetCath);
636         break;
637       case 5:
638       case 6:
639       case 7:
640       case 8:
641       case 9:
642       case 10:
643         offsetX = 1024;
644         offsetY = 0;
645         offsetCath = 65536;
646         maxChannel = (256 * offsetX + offsetX + offsetCath);
647         break;
648       }
649       // dummy mapping
650       // manu Id directly from a matrix 8*8, same segmentation for B and NB
651       // 50 buspatches for 1/2 chamber
652
653       id =  (TMath::Abs(digit->PadX()) * offsetX + digit->PadY() + offsetY +
654              offsetCath * iCath);
655       Int_t chPerBus = maxChannel/50;
656       busPatchId = id/chPerBus; // start at zero 
657       if (digit->PadX() > 0)
658         busPatchId += 50*iCh*2;
659       else 
660         busPatchId += 50*(2*iCh+1);
661       // 64 manu cards for one buspatch
662       manuId = (id % chPerBus)/64; //start at zero 
663       manuId &= 0x7FF; // 11 bits 
664
665       // channel id
666       channelId = (id % chPerBus) % 64; //start at zero 
667       channelId &= 0x3F; // 6 bits
668
669      
670       AliDebug(2,Form("id: %d, busPatchId %d, manuId: %d, channelId: %d, maxchannel: %d, chPerBus %d\n",
671                       id, busPatchId, manuId, channelId, maxChannel, chPerBus));
672
673       AliDebug(2,Form("id: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d, charge %d\n",
674                       id, busPatchId, manuId, channelId, digit->PadX(), digit->PadY(), digit->Signal()));
675
676 }
677
678 //____________________________________________________________________
679 Int_t AliMUONRawData::GetGlobalTriggerPattern(const AliMUONGlobalTrigger* gloTrg)
680 {
681   // global trigger pattern calculation
682
683   Int_t gloTrigPat = 0;
684
685   if (gloTrg->SinglePlusLpt())  gloTrigPat|= 0x1;
686   if (gloTrg->SinglePlusHpt())  gloTrigPat|= 0x2;
687   if (gloTrg->SinglePlusApt())  gloTrigPat|= 0x4;
688  
689   if (gloTrg->SingleMinusLpt()) gloTrigPat|= 0x8;
690   if (gloTrg->SingleMinusHpt()) gloTrigPat|= 0x10;
691   if (gloTrg->SingleMinusApt()) gloTrigPat|= 0x20;
692  
693   if (gloTrg->SingleUndefLpt()) gloTrigPat|= 0x40;
694   if (gloTrg->SingleUndefHpt()) gloTrigPat|= 0x80;
695   if (gloTrg->SingleUndefApt()) gloTrigPat|= 0x100;
696  
697   if (gloTrg->PairUnlikeLpt())  gloTrigPat|= 0x200;
698   if (gloTrg->PairUnlikeHpt())  gloTrigPat|= 0x400;
699   if (gloTrg->PairUnlikeApt())  gloTrigPat|= 0x800;
700
701   if (gloTrg->PairLikeLpt())    gloTrigPat|= 0x1000;
702   if (gloTrg->PairLikeHpt())    gloTrigPat|= 0x2000;
703   if (gloTrg->PairLikeApt())    gloTrigPat|= 0x4000;
704
705   return gloTrigPat;
706 }