1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 ////////////////////////////////////
18 // MUON Raw Data generator in ALICE-MUON
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 ////////////////////////////////////
30 #include <TClonesArray.h>
31 #include "AliMUONRawData.h"
32 #include "AliMUONDigit.h"
34 #include "AliMUONConstants.h"
35 #include "AliMUONData.h"
36 #include "AliLoader.h"
37 #include "AliBitPacking.h"
39 #include "AliMUONSubEventTrigger.h"
40 #include "AliMUONDDLTracker.h"
41 #include "AliMUONDDLTrigger.h"
43 #include "AliMUONLocalTrigger.h"
44 #include "AliMUONGlobalTrigger.h"
47 const Int_t AliMUONRawData::fgkDefaultPrintLevel = 0;
49 ClassImp(AliMUONRawData) // Class implementation in ROOT context
51 //__________________________________________________________________________
52 AliMUONRawData::AliMUONRawData(AliLoader* loader)
56 // Standard Constructor
58 fPrintLevel = fgkDefaultPrintLevel;
60 // initialize loader's
63 // initialize container
64 fMUONData = new AliMUONData(fLoader,"MUON","MUON");
67 fSubEventArray[0] = new TClonesArray("AliMUONSubEventTracker",1000);
68 fSubEventArray[1] = new TClonesArray("AliMUONSubEventTracker",1000);
70 // initialize array not used for the moment
71 fSubEventTrigArray[0] = new TClonesArray("AliMUONSubEventTrigger",1000);
72 fSubEventTrigArray[1] = new TClonesArray("AliMUONSubEventTrigger",1000);
75 fDDLTracker = new AliMUONDDLTracker();
76 fDDLTrigger = new AliMUONDDLTrigger();
79 //__________________________________________________________________________
80 AliMUONRawData::AliMUONRawData()
83 fPrintLevel(fgkDefaultPrintLevel),
87 // Default Constructor
90 //_______________________________________________________________________
91 AliMUONRawData::AliMUONRawData (const AliMUONRawData& rhs)
94 // Protected copy constructor
96 AliFatal("Not implemented.");
99 //_______________________________________________________________________
101 AliMUONRawData::operator=(const AliMUONRawData& rhs)
103 // Protected assignement operator
105 if (this == &rhs) return *this;
107 AliFatal("Not implemented.");
112 //__________________________________________________________________________
113 AliMUONRawData::~AliMUONRawData(void)
117 if (fSubEventArray[0])
118 fSubEventArray[0]->Delete(); //using delete cos allocating memory in copy ctor.
119 if (fSubEventArray[1])
120 fSubEventArray[1]->Delete();
122 if (fSubEventTrigArray[0])
123 fSubEventTrigArray[0]->Delete();
124 if (fSubEventTrigArray[1])
125 fSubEventTrigArray[1]->Delete();
134 //____________________________________________________________________
135 Int_t AliMUONRawData::WriteRawData()
137 // convert digits of the current event to raw data
142 fLoader->LoadDigits("READ");
144 fMUONData->SetTreeAddress("D,GLT");
149 for (Int_t ich = 0; ich < AliMUONConstants::NTrackingCh(); ich++) {
152 idDDL = ich * 2 + 0x900;
153 sprintf(name, "MUON_%d.ddl",idDDL);
154 fFile1 = fopen(name,"w");
156 idDDL = (ich * 2) + 1 + 0x900;
157 sprintf(name, "MUON_%d.ddl",idDDL);
158 fFile2 = fopen(name,"w");
160 WriteTrackerDDL(ich);
165 fMUONData->ResetDigits();
172 sprintf(name, "MUTR_%d.ddl",idDDL);
173 fFile1 = fopen(name,"w");
176 sprintf(name, "MUTR_%d.ddl",idDDL);
177 fFile2 = fopen(name,"w");
184 fMUONData->ResetTrigger();
186 fLoader->UnloadDigits();
190 //____________________________________________________________________
191 Int_t AliMUONRawData::WriteTrackerDDL(Int_t iCh)
194 TClonesArray* muonDigits = 0;
195 fSubEventArray[0]->Clear();
196 fSubEventArray[1]->Clear();
201 nbInBus[0].Set(5000);
202 nbInBus[1].Set(5000);
208 AliRawDataHeader header = fDDLTracker->GetHeader();
209 Int_t headerSize = fDDLTracker->GetHeaderSize();
211 // DDL event one per half chamber
212 AliMUONSubEventTracker* subEvent;
217 UChar_t channelId = 0;
219 Int_t busPatchId = 0;
229 const AliMUONDigit* digit;
231 if (fPrintLevel == 1)
232 printf("WriteDDL chamber %d\n", iCh+1);
234 for (Int_t iCath = 0; iCath < 2; iCath++) {
236 fMUONData->ResetDigits();
237 fMUONData->GetCathode(iCath);
238 muonDigits = fMUONData->Digits(iCh);
240 nDigits = muonDigits->GetEntriesFast();
241 if (fPrintLevel == 2)
242 printf("ndigits = %d\n",nDigits);
244 // open DDL file, on per 1/2 chamber
246 for (Int_t idig = 0; idig < nDigits; idig++) {
248 digit = (AliMUONDigit*) muonDigits->UncheckedAt(idig);
251 GetDummyMapping(iCh, iCath, digit, busPatchId, manuId, channelId, charge);
254 AliBitPacking::PackWord((UInt_t)parity,word,29,31);
255 AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
256 AliBitPacking::PackWord((UInt_t)channelId,word,12,17);
257 AliBitPacking::PackWord((UInt_t)charge,word,0,11);
260 subEvent = new AliMUONSubEventTracker();
261 subEvent->AddData(word);
262 subEvent->SetBusPatchId(busPatchId);
263 if (digit->PadX() > 0) {
264 nbInBus[0][busPatchId]++;
267 nbInBus[1][busPatchId]++;
273 fSubEventArray[0]->Sort();
274 fSubEventArray[1]->Sort();
276 // gather datas from same bus patch
277 for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
278 nEntries = fSubEventArray[iDDL]->GetEntriesFast();
280 for (Int_t i = 0; i < nEntries; i++) {
281 AliMUONSubEventTracker* temp = (AliMUONSubEventTracker*)fSubEventArray[iDDL]->At(i);
282 busPatchId = temp->GetBusPatchId();
284 // add bus patch header, length and total length managed by subevent class
285 temp->SetTriggerWord(0xdeadbeef);
286 for (Int_t j = 0; j < nbInBus[iDDL][busPatchId]-1; j++) {
287 AliMUONSubEventTracker* temp1 = (AliMUONSubEventTracker*)fSubEventArray[iDDL]->At(++i);
288 temp->AddData(temp1->GetData(0));
289 fSubEventArray[iDDL]->RemoveAt(i) ;
292 fSubEventArray[iDDL]->Compress();
294 if (fPrintLevel == 3) {
295 nEntries = fSubEventArray[iDDL]->GetEntriesFast();
296 for (Int_t i = 0; i < nEntries; i++) {
297 AliMUONSubEventTracker* temp = (AliMUONSubEventTracker*)fSubEventArray[iDDL]->At(i);
298 printf("busPatchid back %d\n",temp->GetBusPatchId());
299 for (Int_t j = 0; j < temp->GetLength(); j++) {
300 printf("manuId back %d, ",temp->GetManuId(j));
301 printf("channelId back %d, ",temp->GetChannelId(j));
302 printf("charge back %d\n",temp->GetCharge(j));
314 for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
318 nEntries = fSubEventArray[iDDL]->GetEntriesFast();
319 buffer = new Int_t [(2048+24)*50]; // 24 words in average for one buspatch and 2048 manu info at most
327 for (Int_t iBlock = 0; iBlock < 2; iBlock++) {
330 // fDDLTracker->SetTotalBlkLength(0xFFFFFFFF);
331 length = fDDLTracker->GetBlkHeaderLength();
332 memcpy(&buffer[index],fDDLTracker->GetBlkHeader(),length*4);
336 for (Int_t iDsp = 0; iDsp < 5; iDsp++) {
339 // fDDLTracker->SetTotalDspLength(0xEEEEEEEE);
340 length = fDDLTracker->GetDspHeaderLength();
341 memcpy(&buffer[index],fDDLTracker->GetDspHeader(),length*4);
345 for (Int_t i = 0; i < 5; i++) {
347 iBusPatch = i + iBlock*25 + iDsp*5 + 50*(2*iCh + iDDL);
349 AliMUONSubEventTracker* temp = (AliMUONSubEventTracker*)fSubEventArray[iDDL]->At(iEntries);
351 busPatchId = temp->GetBusPatchId();
355 if (busPatchId == iBusPatch) {
356 // add bus patch structure
357 length = temp->GetHeaderLength();
358 memcpy(&buffer[index],temp->GetAddress(),length*4);
360 for (Int_t j = 0; j < temp->GetLength(); j++)
361 buffer[index++] = temp->GetData(j);
362 if (iEntries < nEntries-1)
365 buffer[index++] = 4; // total length
366 buffer[index++] = 0; // raw data length
367 buffer[index++] = iBusPatch; // bus patch
368 buffer[index++] = 0xdeadbeef; // trigger word
371 buffer[indexDsp] = index - indexDsp; // dsp length
372 buffer[indexDsp+1] = index - indexDsp - fDDLTracker->GetDspHeaderLength();
373 if ((index - indexDsp) % 2 == 0)
374 buffer[indexDsp+7] = 0;
376 buffer[indexDsp+7] = 1;
378 buffer[indexBlk] = index - indexBlk; // block length
379 buffer[indexBlk+1] = index - indexBlk - fDDLTracker->GetBlkHeaderLength();
383 header.fSize = index + headerSize;// total length in word
384 fwrite((char*)(&header),headerSize*4,1,fFile1);
385 fwrite(buffer,sizeof(int),index,fFile1);
389 header.fSize = index + headerSize;// total length in word
390 fwrite((char*)(&header),headerSize*4,1,fFile2);
391 fwrite(buffer,sizeof(int),index,fFile2);
398 //____________________________________________________________________
399 Int_t AliMUONRawData::WriteTriggerDDL()
402 // DDL event one per half chamber
403 AliMUONSubEventTrigger* subEvent = 0x0;
406 // stored local id number
407 TArrayI isFired(256);
412 AliRawDataHeader header = fDDLTrigger->GetHeader();
413 Int_t headerSize = fDDLTrigger->GetHeaderSize();
415 TClonesArray* localTrigger;
416 TClonesArray* globalTrigger;
417 AliMUONGlobalTrigger* gloTrg;
418 AliMUONLocalTrigger* locTrg = 0x0;
420 fMUONData->GetTriggerD();
422 // global trigger for trigger pattern
423 globalTrigger = fMUONData->GlobalTrigger();
424 gloTrg = (AliMUONGlobalTrigger*)globalTrigger->UncheckedAt(0);
425 Int_t gloTrigPat = GetGlobalTriggerPattern(gloTrg);
428 localTrigger = fMUONData->LocalTrigger();
434 Int_t iLocCard, locCard;
435 Char_t locDec, trigY, posY, devX, posX,regOut;
436 Int_t version = 1; // software version
437 Int_t eventType = 1; // trigger type: 1 for physics ?
438 Int_t serialNb = 0xF; // serial nb of card: all bits on for the moment
439 Int_t globalFlag = 1; // set to 2 if global info present in DDL else set to 1
441 Int_t nEntries = (Int_t) (localTrigger->GetEntries());// 234 local cards
442 // stored the local card id that's fired
443 for (Int_t i = 0; i < nEntries; i++) {
444 locTrg = (AliMUONLocalTrigger*)localTrigger->At(i);
445 isFired[locTrg->LoCircuit()] = 1;
449 AliError("No Trigger information available");
451 buffer = new Int_t [672]; // [16(local)*5 words + 3 words]*8(reg) + 8 words = 672
453 for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
457 // DDL enhanced header
459 AliBitPacking::PackWord((UInt_t)iDDL+1,word,28,31); //see AliMUONDDLTrigger.h for details
460 AliBitPacking::PackWord((UInt_t)serialNb,word,24,27);
461 AliBitPacking::PackWord((UInt_t)version,word,16,23);
462 AliBitPacking::PackWord((UInt_t)eventType,word,12,15);
464 if (iDDL == 0) // suppose global info in DDL one
468 AliBitPacking::PackWord((UInt_t)globalFlag,word,8,11);
469 fDDLTrigger->SetDDLWord(word);
472 fDDLTrigger->SetGlobalOutput(gloTrigPat);// no global input for the moment....
474 fDDLTrigger->SetGlobalOutput(0);
475 length = fDDLTrigger->GetHeaderLength();
476 memcpy(&buffer[index],fDDLTrigger->GetEnhancedHeader(),length*4);
479 for (Int_t iReg = 0; iReg < 8; iReg++) {
481 subEvent = new AliMUONSubEventTrigger();
483 // Regional card header
486 AliBitPacking::PackWord((UInt_t)serialNb,word,24,28); //see AliMUONSubEventTrigger.h for details
487 AliBitPacking::PackWord((UInt_t)version,word,16,23);
488 AliBitPacking::PackWord((UInt_t)iReg,word,12,15);
489 AliBitPacking::PackWord((UInt_t)regOut,word,0,7); // whenever regional output will be implemented
491 subEvent->SetRegWord(word);
492 memcpy(&buffer[index++],subEvent->GetAddress(),4);
494 buffer[index++] = 0;// 2 words of regional input
497 for (Int_t iLoc = 0; iLoc < 16; iLoc++) {
499 iLocCard = iLoc + iReg*16 + iDDL*128;
501 if (isFired[iLocCard]) {
502 locTrg = (AliMUONLocalTrigger*)localTrigger->At(iEntries);
503 locCard = locTrg->LoCircuit();
504 locDec = locTrg->GetLoDecision();
506 posY = locTrg->LoStripY();
507 posX = locTrg->LoStripX();
508 devX = locTrg->LoDev();
509 if (fPrintLevel == 4)
510 printf("loctrg %d, posX %d, posY %d, devX %d\n",
511 locTrg-> LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev());
512 } else { //no trigger (see PRR chpt 3.4)
523 AliBitPacking::PackWord((UInt_t)(iLocCard % 16),word,19,22); //card id number in crate
524 AliBitPacking::PackWord((UInt_t)locDec,word,15,18);
525 AliBitPacking::PackWord((UInt_t)trigY,word,14,14);
526 AliBitPacking::PackWord((UInt_t)posY,word,10,13);
527 AliBitPacking::PackWord((UInt_t)devX,word,5,9);
528 AliBitPacking::PackWord((UInt_t)posX,word,0,4);
530 if (locCard == iLocCard) {
531 // add local cards structure
532 buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16));
533 buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16));
534 buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16));
535 buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16));
536 buffer[index++] = (Int_t)word; // data word
537 if (iEntries < nEntries-1)
540 buffer[index++] = 0; // 4 words for x1, x2, y1, y2
544 buffer[index++] = (Int_t)word; // data word
553 buffer[index++] = fDDLTrigger->GetEoD(); // End of DDL word
554 buffer[index++] = fDDLTrigger->GetEoD(); // End of DDL word for 64 bits transfer purpose
559 header.fSize = index + headerSize;// total length in word
560 fwrite((char*)(&header),headerSize*4,1,fFile1);
561 fwrite(buffer,sizeof(int),index,fFile1);
565 header.fSize = index + headerSize;// total length in word
566 fwrite((char*)(&header),headerSize*4,1,fFile2);
567 fwrite(buffer,sizeof(int),index,fFile2);
574 //____________________________________________________________________
575 void AliMUONRawData::GetDummyMapping(Int_t iCh, Int_t iCath, const AliMUONDigit* digit,
576 Int_t &busPatchId, UShort_t &manuId, UChar_t &channelId, UShort_t &charge)
578 // Dummy mapping for tracker
580 Int_t offsetX = 0; // offet row
581 Int_t offsetY = 0; // offset columns
582 Int_t offsetCath = 0; //offset from one cathod to the other
583 Int_t maxChannel = 0; // maximum nb of channel in 1/2 chamber
593 maxChannel = (offsetY * offsetX + 2* offsetY + offsetCath);
604 maxChannel = (256 * offsetX + offsetX + offsetCath);
608 // manu Id directly from a matrix 8*8, same segmentation for B and NB
609 // 50 buspatches for 1/2 chamber
611 id = (TMath::Abs(digit->PadX()) * offsetX + digit->PadY() + offsetY +
613 Int_t chPerBus = maxChannel/50;
614 busPatchId = id/chPerBus; // start at zero
615 if (digit->PadX() > 0)
616 busPatchId += 50*iCh*2;
618 busPatchId += 50*(2*iCh+1);
619 // 64 manu cards for one buspatch
620 manuId = (id % chPerBus)/64; //start at zero
621 manuId &= 0x7FF; // 11 bits
624 channelId = (id % chPerBus) % 64; //start at zero
625 channelId &= 0x3F; // 6 bits
627 if (fPrintLevel == 2)
628 printf("id: %d, busPatchId %d, manuId: %d, channelId: %d, maxchannel: %d, chPerBus %d\n",
629 id, busPatchId, manuId, channelId, maxChannel, chPerBus);
631 charge = digit->Signal();
634 if (fPrintLevel == 2)
635 printf("id: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d, charge %d\n",
636 id, busPatchId, manuId, channelId, digit->PadX(), digit->PadY(), digit->Signal());
640 //____________________________________________________________________
641 Int_t AliMUONRawData::GetGlobalTriggerPattern(const AliMUONGlobalTrigger* gloTrg)
643 // global trigger pattern calculation
645 Int_t gloTrigPat = 0;
647 if (gloTrg->SinglePlusLpt()) gloTrigPat|= 0x1;
648 if (gloTrg->SinglePlusHpt()) gloTrigPat|= 0x2;
649 if (gloTrg->SinglePlusApt()) gloTrigPat|= 0x4;
651 if (gloTrg->SingleMinusLpt()) gloTrigPat|= 0x8;
652 if (gloTrg->SingleMinusHpt()) gloTrigPat|= 0x10;
653 if (gloTrg->SingleMinusApt()) gloTrigPat|= 0x20;
655 if (gloTrg->SingleUndefLpt()) gloTrigPat|= 0x40;
656 if (gloTrg->SingleUndefHpt()) gloTrigPat|= 0x80;
657 if (gloTrg->SingleUndefApt()) gloTrigPat|= 0x100;
659 if (gloTrg->PairUnlikeLpt()) gloTrigPat|= 0x200;
660 if (gloTrg->PairUnlikeHpt()) gloTrigPat|= 0x400;
661 if (gloTrg->PairUnlikeApt()) gloTrigPat|= 0x800;
663 if (gloTrg->PairLikeLpt()) gloTrigPat|= 0x1000;
664 if (gloTrg->PairLikeHpt()) gloTrigPat|= 0x2000;
665 if (gloTrg->PairLikeApt()) gloTrigPat|= 0x4000;