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