]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONRawReader.cxx
Adding misalignment with gaussian distribution
[u/mrichter/AliRoot.git] / MUON / AliMUONRawReader.cxx
CommitLineData
a19e2543 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//
ced309a5 18// MUON Raw Data reader in ALICE-MUON
19// Class version 3 (further details could be found in Alice-note)
a19e2543 20//
21// Implemented non-constant buspatch numbers for tracking
22// with correct DDL id (first guess)
23// (Ch. Finck, dec 2005)
24//
a19e2543 25//
26// Raw2Digits:
27// Using real mapping for tracker
28// Indranil Das (Adapted for runloader: Ch. Finck) july 05
ced309a5 29// Add reader for scaler trigger events
30// Use memcpy instead of assignment elt by elt
31// (Ch. Finck, Jan 06)
a19e2543 32//
33////////////////////////////////////
34
35#include <fstream>
36#include <string>
37
38#include <TClonesArray.h>
39
a19e2543 40#include "AliBitPacking.h"
41#include "AliRawReader.h"
42#include "AliLog.h"
43#include "AliRun.h"
44
2cbb173f 45#include "AliMpBusPatch.h"
46
a19e2543 47#include "AliMUON.h"
48#include "AliMUONRawReader.h"
49#include "AliMUONDigit.h"
50
51#include "AliMUONConstants.h"
52#include "AliMUONData.h"
53
54#include "AliMUONSubEventTracker.h"
ced309a5 55#include "AliMUONScalerEventTrigger.h"
a19e2543 56#include "AliMUONSubEventTrigger.h"
57#include "AliMUONDDLTracker.h"
58#include "AliMUONDDLTrigger.h"
59
60#include "AliMUONLocalTrigger.h"
61#include "AliMUONGlobalTrigger.h"
62
63#include "AliMUONGeometrySegmentation.h"
64#include "AliMUONGeometryModule.h"
65#include "AliMUONGeometryStore.h"
66#include "AliMpSegFactory.h"
67#include "AliMpPlaneType.h"
68#include "AliMpVSegmentation.h"
69#include "AliMpHelper.h"
70#include "AliMpPad.h"
2cbb173f 71#include "AliMpDEManager.h"
a19e2543 72
73ClassImp(AliMUONRawReader) // Class implementation in ROOT context
74//__________________________________________________________________________
2cbb173f 75AliMUONRawReader::AliMUONRawReader(AliMUONData* data)
76: TObject(),
77 fScalerEvent(kFALSE)
a19e2543 78{
2cbb173f 79 AliDebug(1,"");
80
a19e2543 81 // Standard Constructor
82
a19e2543 83 // initialize segmentation factory
84 fSegFactory = new AliMpSegFactory();
85
86 // initialize container
87 fMUONData = data;
88
89 // ddl pointer
90 fDDLTracker = new AliMUONDDLTracker();
91 fDDLTrigger = new AliMUONDDLTrigger();
92
93 fBusPatchManager = new AliMpBusPatch();
94 fBusPatchManager->ReadBusPatchFile();
95
2cbb173f 96 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
97 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
98 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
a19e2543 99}
100
101//__________________________________________________________________________
102AliMUONRawReader::AliMUONRawReader()
103 : TObject(),
104 fMUONData(0),
a19e2543 105 fSegFactory(0),
106 fDDLTracker(0),
ced309a5 107 fDDLTrigger(0),
108 fBusPatchManager(0),
109 fScalerEvent(kFALSE)
a19e2543 110{
111 // Default Constructor
2cbb173f 112 AliDebug(1,"");
113 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
114 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
115 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
a19e2543 116}
117
118//_______________________________________________________________________
119AliMUONRawReader::AliMUONRawReader (const AliMUONRawReader& rhs)
120 : TObject(rhs)
121{
122// Protected copy constructor
123
124 AliFatal("Not implemented.");
125}
126
127//_______________________________________________________________________
128AliMUONRawReader &
129AliMUONRawReader::operator=(const AliMUONRawReader& rhs)
130{
131// Protected assignement operator
132
133 if (this == &rhs) return *this;
134
135 AliFatal("Not implemented.");
136
137 return *this;
138}
139
140//__________________________________________________________________________
2cbb173f 141AliMUONRawReader::~AliMUONRawReader()
a19e2543 142{
a19e2543 143 delete fSegFactory;
144
2cbb173f 145 delete fDDLTracker;
146 delete fDDLTrigger;
a19e2543 147
2cbb173f 148 delete fBusPatchManager;
149
150 AliInfo(Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
151 fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
152 AliInfo(Form(" Execution time for MUON tracker (mapping calls part) "
153 ": R:%.2fs C:%.2fs",
154 fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
155 AliInfo(Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
156 fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
a19e2543 157
a19e2543 158}
159
160//____________________________________________________________________
161Int_t AliMUONRawReader::Raw2Digits(AliRawReader* rawReader)
162{
163
164 // generate digits
165 ReadTrackerDDL(rawReader);
166
167 // generate trigger
168 ReadTriggerDDL(rawReader);
169
170 return kTRUE;
171
172}
173
174//____________________________________________________________________
175Int_t AliMUONRawReader::ReadTrackerDDL(AliRawReader* rawReader)
176{
177 // reading tracker DDL
178 // filling the TClonesArray in MUONData
179 //
2cbb173f 180 fTrackerTimer.Start(kFALSE);
181
a19e2543 182 AliMUONSubEventTracker* subEventTracker = new AliMUONSubEventTracker();
183 AliMUONDigit* digit = new AliMUONDigit();
184
185
ced309a5 186 //Read Header Size of DDL,Block,DSP and BusPatch (put k before constant imb'cile)
a19e2543 187
ced309a5 188 Int_t kDDLHeaderSize = fDDLTracker->GetHeaderSize();
189 Int_t kBlockHeaderSize = fDDLTracker->GetBlkHeaderLength();
190 Int_t kDspHeaderSize = fDDLTracker->GetDspHeaderLength();
191 Int_t kBusPatchHeaderSize = subEventTracker->GetHeaderLength();
a19e2543 192
193 Int_t totalDDLSize, totalBlockSize, totalDspSize , totalBusPatchSize, dataSize;
194
195
196 Int_t iBusPerDSP[5];//number of bus patches per DSP
197 Int_t iDspMax; //number max of DSP per block
198
199 // minimum data size (only header's)
200 Int_t blankDDLSize;
201 Int_t blankBlockSize;
202 Int_t blankDspSize;
203
204 for(Int_t iDDL = 0; iDDL < 20; iDDL++) { // DDL loop
205
206 AliDebug(3, Form("Chamber %d\n", iDDL/2 +1 ));
207
208 // getting DSP info
209 fBusPatchManager->GetDspInfo(iDDL/2, iDspMax, iBusPerDSP);
210
211 // Each DDL is made with 2 Blocks each of which consists of 5 DSP's at most and each of DSP has at most 5 buspatches.
212 // This information is used to calculate the size of headers (DDL,Block and DSP) which has no interesting data.
ced309a5 213 blankDDLSize = kDDLHeaderSize + 2*kBlockHeaderSize + 2*iDspMax*kDspHeaderSize;
214 blankBlockSize = kBlockHeaderSize + iDspMax*kDspHeaderSize;
a19e2543 215
216 for (Int_t i = 0; i < iDspMax; i++) {
ced309a5 217 blankDDLSize += 2*iBusPerDSP[i]*kBusPatchHeaderSize;
218 blankBlockSize += iBusPerDSP[i]*kBusPatchHeaderSize;
a19e2543 219 }
c837da58 220 rawReader->Reset();
a19e2543 221 rawReader->Select(0X9, iDDL, iDDL); //Select the DDL file to be read
222
223 rawReader->ReadHeader();
224
225 totalDDLSize = (rawReader->GetDataSize() + sizeof(AliRawDataHeader))/4; // 4 is multiplied to convert byte 2 words
226
227 if(totalDDLSize > blankDDLSize) { // Compare the DDL header with an empty DDL header size to read the file
228
ced309a5 229 Int_t totalDataWord = rawReader->GetDataSize(); // in bytes
230 UInt_t *buffer = new UInt_t[totalDataWord/4];
c837da58 231
ced309a5 232 rawReader->ReadNext((UChar_t*)buffer, totalDataWord);
a19e2543 233
234 // elex info
235 Int_t buspatchId;
236 UChar_t channelId;
237 UShort_t manuId;
238 Char_t parity;
239 UShort_t charge;
240
241 // indexes
242 Int_t indexDsp;
243 Int_t indexBusPatch;
244 Int_t index = 0;
245
246 for(Int_t iBlock = 0; iBlock < 2 ;iBlock++){ // loop over 2 blocks
247 totalBlockSize = buffer[index];
248
249 if(totalBlockSize > blankBlockSize) { // compare block header
ced309a5 250 index += kBlockHeaderSize;
a19e2543 251
252 for(Int_t iDsp = 0; iDsp < iDspMax ;iDsp++){ //DSP loop
253
254 totalDspSize = buffer[index];
255 indexDsp = index;
256
ced309a5 257 blankDspSize = kDspHeaderSize + iBusPerDSP[iDsp]*kBusPatchHeaderSize; // no data just header
a19e2543 258
259 if(totalDspSize > blankDspSize) { // Compare DSP Header
ced309a5 260 index += kDspHeaderSize;
a19e2543 261
262 for(Int_t iBusPatch = 0; iBusPatch < iBusPerDSP[iDsp]; iBusPatch++) {
263
ced309a5 264 //copy buffer into header structure
265 memcpy(subEventTracker->GetBusPatchHeader(), &buffer[index], kBusPatchHeaderSize*4);
266
267 totalBusPatchSize = subEventTracker->GetTotalLength();
268 buspatchId = subEventTracker->GetBusPatchId();
a19e2543 269 indexBusPatch = index;
ced309a5 270
a19e2543 271
ced309a5 272 if(totalBusPatchSize > kBusPatchHeaderSize) { //Check Buspatch header, not empty events
a19e2543 273
ced309a5 274 index += kBusPatchHeaderSize;
275 dataSize = subEventTracker->GetLength();
27b09716 276 Int_t bufSize = subEventTracker->GetBufSize();
a19e2543 277
278 if(dataSize>0) { // check data present
27b09716 279 if (dataSize > bufSize) subEventTracker->SetAlloc(dataSize);
a19e2543 280
ced309a5 281 //copy buffer into data structure
282 memcpy(subEventTracker->GetData(), &buffer[index], dataSize*4);
283 index += dataSize;
284
a19e2543 285 for(Int_t iData = 0; iData < dataSize; iData++) {
286
a19e2543 287 // digits info
288 parity = subEventTracker->GetParity(iData); // test later for parity
289 manuId = subEventTracker->GetManuId(iData);
290 channelId = subEventTracker->GetChannelId(iData);
291 charge = subEventTracker->GetCharge(iData);
27b09716 292
a19e2543 293 // set charge
294 digit->SetSignal(charge);
2cbb173f 295 digit->SetPhysicsSignal(charge);
296 digit->SetADC(charge);
a19e2543 297 Int_t error = GetMapping(buspatchId,manuId,channelId,digit); // Get Back the hits at pads
298 if (error) continue;
299
300 // debugging
301 if (AliLog::GetGlobalDebugLevel() == 3) {
302 Int_t padX = digit->PadX();
303 Int_t padY = digit->PadY();
304 Int_t iCath = digit->Cathode();
2cbb173f 305 Int_t detElemId = digit->DetElemId();
a19e2543 306
2cbb173f 307 AliDebug(1,Form("output detElemId %d busPatchid %d PadX %d PadY %d iCath %d \n",
308 detElemId, buspatchId, padX, padY, iCath));
a19e2543 309
2cbb173f 310 AliDebug(3,Form("detElemId %d Padx %d Pady %d, Cath %d, charge %d",detElemId, padX, padY, iCath, charge));
a19e2543 311 }
312
313 // fill digits
314 fMUONData->AddDigit(iDDL/2, *digit);
315
316 } // data loop
317 } // dataSize test
318 } // testing buspatch
319
320 index = indexBusPatch + totalBusPatchSize;
321
322 } //buspatch loop
323
324 } // dsp test
325
326 index = indexDsp + totalDspSize;
327
328 } // dsp loop
329
330 } //block test
331
332 index = totalBlockSize;
333
334 } //block loop
335
336 delete[] buffer;
337 } //loop checking the header size of DDL
338
339 //delete rawReader;
340 } // DDL loop
341
342
343 delete subEventTracker;
344 delete digit;
345
2cbb173f 346 fTrackerTimer.Stop();
347
a19e2543 348 return kTRUE;
349}
350
351//____________________________________________________________________
352Int_t AliMUONRawReader::GetMapping(Int_t busPatchId, UShort_t manuId,
353 UChar_t channelId, AliMUONDigit* digit )
354{
355
356 // mapping for tracker
357
2cbb173f 358 fMappingTimer.Start(kFALSE);
359
a19e2543 360 // getting DE from buspatch
2cbb173f 361 Int_t detElemId = fBusPatchManager->GetDEfromBus(busPatchId);
362 AliDebug(3,Form("detElemId: %d busPatchId %d\n", detElemId, busPatchId));
a19e2543 363
2cbb173f 364 AliMpVSegmentation* seg = fSegFactory->CreateMpSegmentationByElectronics(detElemId, manuId);
365 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kTRUE);
a19e2543 366
2cbb173f 367 if (!pad.IsValid())
368 {
369 AliWarning(Form("No pad for detElemId: %d, busPatchId %d, manuId: %d, channelId: %d\n",
370 detElemId, busPatchId, manuId, channelId));
371 fMappingTimer.Stop();
a19e2543 372 return kTRUE;
373 } // return error
374
2cbb173f 375 // Getting padX, padY and cathode number.
a19e2543 376 Int_t padX = pad.GetIndices().GetFirst();
a19e2543 377 Int_t padY = pad.GetIndices().GetSecond();
2cbb173f 378 Int_t iCath = AliMpDEManager::GetCathod(detElemId,seg->PlaneType());
379
a19e2543 380 // storing into digits
381 digit->SetPadX(padX);
382 digit->SetPadY(padY);
383 digit->SetCathode(iCath);
2cbb173f 384 digit->SetDetElemId(detElemId);
385 digit->SetElectronics(manuId,channelId);
386
387 AliDebug(3,Form("detElemId: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d\n",
388 detElemId, busPatchId, manuId, channelId, padX, padY));
389 StdoutToAliDebug(3,digit->Print(););
390
391 fMappingTimer.Stop();
a19e2543 392 return kFALSE;
393}
394
395//____________________________________________________________________
396Int_t AliMUONRawReader::ReadTriggerDDL(AliRawReader* rawReader)
397{
398
399 // reading DDL for trigger
400
2cbb173f 401 fTriggerTimer.Start(kFALSE);
402
a19e2543 403 AliMUONSubEventTrigger* subEventTrigger = new AliMUONSubEventTrigger();
ced309a5 404 AliMUONScalerEventTrigger* scalerEvent = 0x0;
405
a19e2543 406 AliMUONGlobalTrigger* globalTrigger = 0x0;
407 AliMUONLocalTrigger* localTrigger = new AliMUONLocalTrigger();
408
409
ced309a5 410 //Int_t kDDLHeaderSize = fDDLTrigger->GetHeaderSize();
a19e2543 411 // we dont need this, as size of ddl data is same for triger and no trigger
412
ced309a5 413 Int_t kDDLEnhanceHeaderSize = fDDLTrigger->GetHeaderLength();
414 Int_t kRegHeaderSize = subEventTrigger->GetRegHeaderLength() ;
a19e2543 415
416 Int_t loCircuit, loStripX, loDev, loStripY, loLpt, loHpt;
417 Char_t loDecision;
418
419 UShort_t x1Pattern, x2Pattern, x3Pattern, x4Pattern;
420 UShort_t y1Pattern, y2Pattern, y3Pattern, y4Pattern;
421
a19e2543 422 // loop over the two ddl's
423 for(Int_t iDDL = 0; iDDL < 2; iDDL++) { //DDL loop
424
c837da58 425 rawReader->Reset();
a19e2543 426 rawReader->Select(0XA,iDDL,iDDL); //Select the DDL file to be read
427
428 rawReader->ReadHeader();
429
ced309a5 430 Int_t totalDataWord = rawReader->GetDataSize(); // in bytes
431 UInt_t *buffer = new UInt_t[totalDataWord/4];
a19e2543 432
ced309a5 433 rawReader->ReadNext((UChar_t*)buffer, totalDataWord);
a19e2543 434
435 Int_t index = 0;
ced309a5 436 fDDLTrigger->SetDDLWord(buffer[index++]);
437
438 if(fDDLTrigger->GetEventType() == 2) {
439 fScalerEvent = kTRUE;
440 scalerEvent = new AliMUONScalerEventTrigger();
441 } else
442 fScalerEvent = kFALSE;
443
444 if(fScalerEvent) {
445 // 6 DARC scaler words
446 memcpy(scalerEvent->GetDarcScalers(), &buffer[index], scalerEvent->GetDarcScalerLength()*4);
447 index += scalerEvent->GetDarcScalerLength();
448 }
449
450 // 4 words of global board input + Global board output
451 memcpy(fDDLTrigger->GetGlobalInput(), &buffer[index], (kDDLEnhanceHeaderSize-1)*4);
452 index += kDDLEnhanceHeaderSize - 1; // kind tricky cos scaler info in-between Darc header
a19e2543 453
ced309a5 454 if(fScalerEvent) {
455 // 10 Global scaler words
456 memcpy(scalerEvent->GetGlobalScalers(), &buffer[index], scalerEvent->GetGlobalScalerLength()*4);
457 index += scalerEvent->GetGlobalScalerLength();
458 }
a19e2543 459
460 // fill global trigger information
461 globalTrigger = GetGlobalTriggerPattern(fDDLTrigger->GetGlobalOuput());
462 fMUONData->AddGlobalTrigger(*globalTrigger);
ced309a5 463
a19e2543 464 // 8 regional boards
465 for (Int_t iReg = 0; iReg < 8; iReg++) { //loop over regeonal card
466
ced309a5 467 memcpy(subEventTrigger->GetRegHeader(), &buffer[index], kRegHeaderSize*4);
468 index += kRegHeaderSize;
a19e2543 469
ced309a5 470 // 11 regional scaler word
471 if(fScalerEvent) {
472 memcpy(scalerEvent->GetRegScalers(), &buffer[index], scalerEvent->GetRegScalerLength()*4);
473 index += scalerEvent->GetRegScalerLength();
474 }
a19e2543 475
476 // 16 local cards per regional board
477 for (Int_t iLoc = 0; iLoc < 16; iLoc++) { //loop over local card
478
479 Int_t iLocIndex = index;
480
481 // 5 word trigger information
482 for(Int_t iData = 0; iData < 5 ;iData++ ){
483 subEventTrigger->SetLocalData(buffer[index++],5*iLoc+iData); //read local data
484 }
485
486 if(buffer[iLocIndex] > 0) {
487
488 loCircuit = (Int_t)subEventTrigger->GetLocalId(iLoc)+ 16*iReg + 128*iDDL;
ced309a5 489 loStripX = (Int_t)subEventTrigger->GetXPos(iLoc);
490 loStripY = (Int_t)subEventTrigger->GetYPos(iLoc);
491 loDev = (Int_t)subEventTrigger->GetXDev(iLoc);
a19e2543 492
493 // fill local trigger
494 localTrigger->SetLoCircuit(loCircuit);
495 localTrigger->SetLoStripX(loStripX );
496 localTrigger->SetLoStripY(loStripY);
497 localTrigger->SetLoDev(loDev);
498
499 loDecision = subEventTrigger->GetLocalDec(iLoc);
500 loLpt = loDecision & 0x3;
501 loHpt = (loDecision >> 2) & 0x3;
502
503 // fill local trigger
504 localTrigger->SetLoLpt(loLpt);
505 localTrigger->SetLoHpt(loHpt);
506
507 //getting pattern from subvent
508 x1Pattern = subEventTrigger->GetX1(iLoc);
509 x2Pattern = subEventTrigger->GetX2(iLoc);
510 x3Pattern = subEventTrigger->GetX3(iLoc);
511 x4Pattern = subEventTrigger->GetX4(iLoc);
512
513 y1Pattern = subEventTrigger->GetY1(iLoc);
514 y2Pattern = subEventTrigger->GetY2(iLoc);
515 y3Pattern = subEventTrigger->GetY3(iLoc);
516 y4Pattern = subEventTrigger->GetY4(iLoc);
517
518 // fill local trigger
519 localTrigger->SetX1Pattern(x1Pattern);
520 localTrigger->SetX2Pattern(x2Pattern);
521 localTrigger->SetX3Pattern(x3Pattern);
522 localTrigger->SetX4Pattern(x4Pattern);
523
524 localTrigger->SetY1Pattern(y1Pattern);
525 localTrigger->SetY2Pattern(y2Pattern);
526 localTrigger->SetY3Pattern(y3Pattern);
527 localTrigger->SetY4Pattern(y4Pattern);
528 fMUONData->AddLocalTrigger(*localTrigger);
529
ced309a5 530 } // if buffer[] > 0
531
532 // 45 regional scaler word
533 if(fScalerEvent) {
534 memcpy(scalerEvent->GetLocalScalers(), &buffer[index], scalerEvent->GetLocalScalerLength()*4);
535 index += scalerEvent->GetLocalScalerLength();
a19e2543 536 }
537
538 } // local card loop
539
540 } // regional card loop
541
542 delete [] buffer;
543 } // DDL loop
544
545 delete subEventTrigger;
546 delete globalTrigger;
547 delete localTrigger;
548
2cbb173f 549 delete scalerEvent;
ced309a5 550
2cbb173f 551 fTriggerTimer.Stop();
a19e2543 552 return kTRUE;
553
554}
555//____________________________________________________________________
556AliMUONGlobalTrigger* AliMUONRawReader::GetGlobalTriggerPattern(Int_t gloTrigPat) const
557{
558 // global trigger pattern calculation
559
560 Int_t globalSinglePlus[3]; // tot num of single plus
561 Int_t globalSingleMinus[3]; // tot num of single minus
562 Int_t globalSingleUndef[3]; // tot num of single undefined
563 Int_t globalPairUnlike[3]; // tot num of unlike-sign pairs
564 Int_t globalPairLike[3]; // tot num of like-sign pairs
565
566
567 for (Int_t i = 0; i < 3; i++) {
c14da03e 568
569 globalSinglePlus[i] = (gloTrigPat >> i) & 0x1;
570 globalSingleMinus[i] = (gloTrigPat >> (i+3)) & 0x1;
571 globalSingleUndef[i] = (gloTrigPat >> (i+6)) & 0x1;
572 globalPairUnlike[i] = (gloTrigPat >> (i+9)) & 0x1;
573 globalPairLike[i] = (gloTrigPat >> (i+12)) & 0x1;
a19e2543 574 }
575
576 return (new AliMUONGlobalTrigger(globalSinglePlus, globalSingleMinus,
577 globalSingleUndef, globalPairUnlike,
578 globalPairLike));
579
580}
581