]>
Commit | Line | Data |
---|---|---|
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 | /// (Ch. Finck, oct 06) | |
39 | ||
40 | #include "AliMUONDigitMaker.h" | |
41 | #include "AliMUONDigit.h" | |
42 | ||
43 | #include "AliMUONConstants.h" | |
44 | #include "AliMUONData.h" | |
45 | ||
46 | #include "AliMUONRawStreamTracker.h" | |
47 | #include "AliMUONDDLTracker.h" | |
48 | #include "AliMUONDspHeader.h" | |
49 | #include "AliMUONBlockHeader.h" | |
50 | #include "AliMUONBusStruct.h" | |
51 | ||
52 | #include "AliMUONRawStreamTrigger.h" | |
53 | #include "AliMUONDDLTrigger.h" | |
54 | #include "AliMUONDarcHeader.h" | |
55 | #include "AliMUONRegHeader.h" | |
56 | #include "AliMUONLocalStruct.h" | |
57 | ||
58 | #include "AliMUONTriggerCrateStore.h" | |
59 | #include "AliMUONTriggerCrate.h" | |
60 | #include "AliMUONLocalTriggerBoard.h" | |
61 | #include "AliMUONLocalTrigger.h" | |
62 | #include "AliMUONGlobalTrigger.h" | |
63 | #include "AliMUONTriggerCircuit.h" | |
64 | ||
65 | #include "AliMpSegmentation.h" | |
66 | #include "AliMpVSegmentation.h" | |
67 | #include "AliMpPad.h" | |
68 | #include "AliMpDEManager.h" | |
69 | #include "AliMpDDLStore.h" | |
70 | #include "AliMpCathodType.h" | |
71 | ||
72 | #include "AliRawReader.h" | |
73 | #include "AliRawDataHeader.h" | |
74 | #include "AliLog.h" | |
75 | #include "AliRun.h" | |
76 | ||
77 | #include <TList.h> | |
78 | ||
79 | ||
80 | /// \cond CLASSIMP | |
81 | ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context | |
82 | /// \endcond | |
83 | ||
84 | //__________________________________________________________________________ | |
85 | AliMUONDigitMaker::AliMUONDigitMaker(Bool_t flag) | |
86 | : TObject(), | |
87 | fMUONData(0x0), | |
88 | fScalerEvent(kFALSE), | |
89 | fDigitFlag(flag), | |
90 | fRawStreamTracker(new AliMUONRawStreamTracker()), | |
91 | fRawStreamTrigger(new AliMUONRawStreamTrigger()), | |
92 | fDigit(new AliMUONDigit()), | |
93 | fLocalTrigger(new AliMUONLocalTrigger()), | |
94 | fGlobalTrigger(new AliMUONGlobalTrigger()), | |
95 | fCrateManager(0x0), | |
96 | fTrackerTimer(), | |
97 | fTriggerTimer(), | |
98 | fMappingTimer() | |
99 | { | |
100 | /// ctor with AliMUONData as argument | |
101 | /// for reconstruction | |
102 | ||
103 | AliDebug(1,""); | |
104 | ||
105 | // Standard Constructor | |
106 | ||
107 | fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop(); | |
108 | fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop(); | |
109 | fMappingTimer.Start(kTRUE); fMappingTimer.Stop(); | |
110 | ||
111 | } | |
112 | ||
113 | //__________________________________________________________________________ | |
114 | AliMUONDigitMaker::~AliMUONDigitMaker() | |
115 | { | |
116 | /// clean up | |
117 | /// and time processing measure | |
118 | ||
119 | delete fRawStreamTracker; | |
120 | delete fRawStreamTrigger; | |
121 | ||
122 | delete fDigit; | |
123 | delete fLocalTrigger; | |
124 | delete fGlobalTrigger; | |
125 | ||
126 | AliDebug(1, Form("Execution time for MUON tracker : R:%.2fs C:%.2fs", | |
127 | fTrackerTimer.RealTime(),fTrackerTimer.CpuTime())); | |
128 | AliDebug(1, Form(" Execution time for MUON tracker (mapping calls part) " | |
129 | ": R:%.2fs C:%.2fs", | |
130 | fMappingTimer.RealTime(),fMappingTimer.CpuTime())); | |
131 | AliDebug(1, Form("Execution time for MUON trigger : R:%.2fs C:%.2fs", | |
132 | fTriggerTimer.RealTime(),fTriggerTimer.CpuTime())); | |
133 | ||
134 | return; | |
135 | } | |
136 | ||
137 | //____________________________________________________________________ | |
138 | Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader) | |
139 | { | |
140 | /// Main method to creates digit | |
141 | /// for tracker | |
142 | /// and trigger | |
143 | ||
144 | // generate digits | |
145 | ReadTrackerDDL(rawReader); | |
146 | ||
147 | // generate trigger | |
148 | ReadTriggerDDL(rawReader); | |
149 | ||
150 | return kTRUE; | |
151 | ||
152 | } | |
153 | ||
154 | //____________________________________________________________________ | |
155 | Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader) | |
156 | { | |
157 | ||
158 | /// reading tracker DDL | |
159 | /// filling the TClonesArray in MUONData | |
160 | ||
161 | fTrackerTimer.Start(kFALSE); | |
162 | ||
163 | // elex info | |
164 | Int_t buspatchId; | |
165 | UChar_t channelId; | |
166 | UShort_t manuId; | |
167 | Char_t parity; | |
168 | UShort_t charge; | |
169 | Int_t dataSize; | |
170 | ||
171 | Int_t iChamber; | |
172 | ||
173 | AliMUONDDLTracker* ddlTracker = 0x0; | |
174 | AliMUONBlockHeader* blkHeader = 0x0; | |
175 | AliMUONDspHeader* dspHeader = 0x0; | |
176 | AliMUONBusStruct* busStruct = 0x0; | |
177 | ||
178 | ||
179 | fRawStreamTracker->SetReader(rawReader); | |
180 | ||
181 | while(fRawStreamTracker->NextDDL()) { | |
182 | ||
183 | ddlTracker = fRawStreamTracker->GetDDLTracker(); | |
184 | ||
185 | Int_t nBlock = ddlTracker->GetBlkHeaderEntries(); | |
186 | for(Int_t iBlock = 0; iBlock < nBlock ;iBlock++){ | |
187 | ||
188 | blkHeader = ddlTracker->GetBlkHeaderEntry(iBlock); | |
189 | ||
190 | Int_t nDsp = blkHeader->GetDspHeaderEntries(); | |
191 | ||
192 | for(Int_t iDsp = 0; iDsp < nDsp ;iDsp++){ //DSP loop | |
193 | ||
194 | dspHeader = blkHeader->GetDspHeaderEntry(iDsp); | |
195 | ||
196 | Int_t nBusPatch = dspHeader->GetBusPatchEntries(); | |
197 | ||
198 | for(Int_t iBusPatch = 0; iBusPatch < nBusPatch; iBusPatch++) { | |
199 | ||
200 | busStruct = dspHeader->GetBusPatchEntry(iBusPatch); | |
201 | ||
202 | dataSize = busStruct->GetLength(); | |
203 | buspatchId = busStruct->GetBusPatchId(); | |
204 | ||
205 | for (Int_t iData = 0; iData < dataSize; iData++) { | |
206 | ||
207 | // digits info | |
208 | parity = busStruct->GetParity(iData); // test later for parity | |
209 | manuId = busStruct->GetManuId(iData); | |
210 | channelId = busStruct->GetChannelId(iData); | |
211 | charge = busStruct->GetCharge(iData); | |
212 | // set charge | |
213 | fDigit->SetSignal(charge); | |
214 | fDigit->SetPhysicsSignal(charge); | |
215 | fDigit->SetADC(charge); | |
216 | ||
217 | // Get Back the hits at pads | |
218 | Int_t error = GetMapping(buspatchId,manuId,channelId,fDigit); | |
219 | if (error) { | |
220 | AliWarning("Mapping Error\n"); | |
221 | continue; | |
222 | } | |
223 | // debugging | |
224 | if (AliLog::GetGlobalDebugLevel() == 3) { | |
225 | Int_t padX = fDigit->PadX(); | |
226 | Int_t padY = fDigit->PadY(); | |
227 | Int_t iCath = fDigit->Cathode(); | |
228 | Int_t idDE = fDigit->DetElemId(); | |
229 | ||
230 | AliDebug(1,Form("output IdDE %d busPatchid %d PadX %d PadY %d iCath %d \n", | |
231 | idDE, buspatchId, padX, padY, iCath)); | |
232 | ||
233 | AliDebug(3,Form("idDE %d Padx %d Pady %d, Cath %d, charge %d", | |
234 | idDE, padX, padY, iCath, charge)); | |
235 | } | |
236 | ||
237 | // fill digits | |
238 | iChamber = AliMpDEManager::GetChamberId(fDigit->DetElemId()); | |
239 | ||
240 | if (fDigitFlag) | |
241 | fMUONData->AddDigit(iChamber, *fDigit); | |
242 | else | |
243 | fMUONData->AddSDigit(iChamber, *fDigit); | |
244 | ||
245 | ||
246 | } // iData | |
247 | } // iBusPatch | |
248 | } // iDsp | |
249 | } // iBlock | |
250 | } // NextDDL | |
251 | ||
252 | fTrackerTimer.Stop(); | |
253 | ||
254 | return kTRUE; | |
255 | } | |
256 | //____________________________________________________________________ | |
257 | Int_t AliMUONDigitMaker::GetMapping(Int_t busPatchId, UShort_t manuId, | |
258 | UChar_t channelId, AliMUONDigit* digit ) | |
259 | { | |
260 | /// mapping for tracker | |
261 | ||
262 | fMappingTimer.Start(kFALSE); | |
263 | ||
264 | // getting DE from buspatch | |
265 | Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId); | |
266 | AliDebug(3,Form("detElemId: %d busPatchId %d\n", detElemId, busPatchId)); | |
267 | ||
268 | const AliMpVSegmentation* seg | |
269 | = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId, manuId); | |
270 | AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kTRUE); | |
271 | ||
272 | if (!pad.IsValid()) | |
273 | { | |
274 | AliWarning(Form("No pad for detElemId: %d, busPatchId %d, manuId: %d, channelId: %d\n", | |
275 | detElemId, busPatchId, manuId, channelId)); | |
276 | fMappingTimer.Stop(); | |
277 | return kTRUE; | |
278 | } // return error | |
279 | ||
280 | // Getting padX, padY and cathode number. | |
281 | Int_t padX = pad.GetIndices().GetFirst(); | |
282 | Int_t padY = pad.GetIndices().GetSecond(); | |
283 | Int_t iCath = AliMpDEManager::GetCathod(detElemId,seg->PlaneType()); | |
284 | ||
285 | // storing into digits | |
286 | digit->SetPadX(padX); | |
287 | digit->SetPadY(padY); | |
288 | digit->SetCathode(iCath); | |
289 | digit->SetDetElemId(detElemId); | |
290 | digit->SetElectronics(manuId,channelId); | |
291 | ||
292 | AliDebug(3,Form("detElemId: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d\n", | |
293 | detElemId, busPatchId, manuId, channelId, padX, padY)); | |
294 | StdoutToAliDebug(3,digit->Print();); | |
295 | ||
296 | fMappingTimer.Stop(); | |
297 | return kFALSE; | |
298 | } | |
299 | ||
300 | //____________________________________________________________________ | |
301 | Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader) | |
302 | { | |
303 | /// reading tracker DDL | |
304 | /// filling the TClonesArray in MUONData | |
305 | ||
306 | AliMUONDDLTrigger* ddlTrigger = 0x0; | |
307 | AliMUONDarcHeader* darcHeader = 0x0; | |
308 | AliMUONRegHeader* regHeader = 0x0; | |
309 | AliMUONLocalStruct* localStruct = 0x0; | |
310 | ||
311 | Int_t loCircuit; | |
312 | TList digitList; | |
313 | ||
314 | ||
315 | fTriggerTimer.Start(kFALSE); | |
316 | ||
317 | fRawStreamTrigger->SetReader(rawReader); | |
318 | ||
319 | while(fRawStreamTrigger->NextDDL()) { | |
320 | ||
321 | ddlTrigger = fRawStreamTrigger->GetDDLTrigger(); | |
322 | darcHeader = ddlTrigger->GetDarcHeader(); | |
323 | ||
324 | // fill global trigger information in Digit Tree | |
325 | if (fDigitFlag) { | |
326 | if (darcHeader->GetGlobalFlag()) { | |
327 | fGlobalTrigger->SetFromGlobalResponse(darcHeader->GetGlobalOutput()); | |
328 | fMUONData->AddGlobalTrigger(*fGlobalTrigger); | |
329 | } | |
330 | } | |
331 | ||
332 | Int_t nReg = darcHeader->GetRegHeaderEntries(); | |
333 | ||
334 | for(Int_t iReg = 0; iReg < nReg ;iReg++){ //reg loop | |
335 | ||
336 | // crate info | |
337 | if (!fCrateManager) AliFatal("Crate Store not defined"); | |
338 | AliMUONTriggerCrate* crate = fCrateManager->Crate(fRawStreamTrigger->GetDDL(), iReg); | |
339 | ||
340 | if (!crate) | |
341 | AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL())); | |
342 | ||
343 | TObjArray *boards = crate->Boards(); | |
344 | ||
345 | ||
346 | regHeader = darcHeader->GetRegHeaderEntry(iReg); | |
347 | ||
348 | Int_t nLocal = regHeader->GetLocalEntries(); | |
349 | for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) { | |
350 | ||
351 | localStruct = regHeader->GetLocalEntry(iLocal); | |
352 | ||
353 | // if card has triggered | |
354 | if (!localStruct->GetTriggerY() || !localStruct->GetTriggerX()) { | |
355 | ||
356 | ||
357 | AliMUONLocalTriggerBoard* localBoard = | |
358 | (AliMUONLocalTriggerBoard*)boards->At(localStruct->GetId()+1); | |
359 | ||
360 | loCircuit = localBoard->GetNumber(); | |
361 | ||
362 | if (fDigitFlag) { | |
363 | // fill local trigger | |
364 | fLocalTrigger->SetLocalStruct(loCircuit, *localStruct); | |
365 | ||
366 | fMUONData->AddLocalTrigger(*fLocalTrigger); | |
367 | ||
368 | } else { | |
369 | // Make SDigit | |
370 | ||
371 | digitList.Clear(); | |
372 | ||
373 | if( TriggerDigits(localBoard, localStruct, digitList) ) { | |
374 | ||
375 | for (Int_t iEntry = 0; iEntry < digitList.GetEntries(); iEntry++) { | |
376 | ||
377 | AliMUONDigit* digit = (AliMUONDigit*)digitList.At(iEntry); | |
378 | ||
379 | // filling S container | |
380 | Int_t iChamber = AliMpDEManager::GetChamberId(digit->DetElemId()); | |
381 | fMUONData->AddSDigit(iChamber, *digit); | |
382 | ||
383 | } | |
384 | ||
385 | } // trigger digits | |
386 | } // S flag | |
387 | ||
388 | } // if triggerY | |
389 | } // iLocal | |
390 | } // iReg | |
391 | } // NextDDL | |
392 | ||
393 | fTriggerTimer.Stop(); | |
394 | ||
395 | return kTRUE; | |
396 | ||
397 | } | |
398 | //____________________________________________________________________ | |
399 | void AliMUONDigitMaker::GetTriggerChamber(AliMUONLocalStruct* localStruct, Int_t& xyPattern, | |
400 | Int_t& iChamber, Int_t& iCath, Int_t icase) | |
401 | { | |
402 | /// get chamber & cathode number, (chamber starts at 0 !) | |
403 | ||
404 | switch(icase) { | |
405 | case 0: | |
406 | xyPattern = localStruct->GetX1(); | |
407 | iCath = 0; | |
408 | iChamber = 10; | |
409 | break; | |
410 | case 1: | |
411 | xyPattern = localStruct->GetX2(); | |
412 | iCath = 0; | |
413 | iChamber = 11; | |
414 | break; | |
415 | case 2: | |
416 | xyPattern = localStruct->GetX3(); | |
417 | iCath = 0; | |
418 | iChamber = 12; | |
419 | break; | |
420 | case 3: | |
421 | xyPattern = localStruct->GetX4(); | |
422 | iCath = 0; | |
423 | iChamber = 13; | |
424 | break; | |
425 | case 4: | |
426 | xyPattern = localStruct->GetY1(); | |
427 | iCath = 1; | |
428 | iChamber = 10; | |
429 | break; | |
430 | case 5: | |
431 | xyPattern = localStruct->GetY2(); | |
432 | iCath = 1; | |
433 | iChamber = 11; | |
434 | break; | |
435 | case 6: | |
436 | xyPattern = localStruct->GetY3(); | |
437 | iCath = 1; | |
438 | iChamber = 12; | |
439 | break; | |
440 | case 7: | |
441 | xyPattern = localStruct->GetY4(); | |
442 | iCath = 1; | |
443 | iChamber = 13; | |
444 | break; | |
445 | } | |
446 | } | |
447 | //____________________________________________________________________ | |
448 | Int_t AliMUONDigitMaker::TriggerDigits(AliMUONLocalTriggerBoard* localBoard, | |
449 | AliMUONLocalStruct* localStruct, | |
450 | TList& digitList) | |
451 | { | |
452 | /// make (S)Digit for trigger | |
453 | ||
454 | Int_t detElemId; | |
455 | Int_t nBoard; | |
456 | Int_t iCath = -1; | |
457 | Int_t iChamber = 0; | |
458 | Int_t xyPattern = 0; | |
459 | ||
460 | // loop over x1-4 and y1-4 | |
461 | for (Int_t icase = 0; icase < 8; icase++) { | |
462 | ||
463 | // get chamber, cathode and associated trigger response pattern | |
464 | GetTriggerChamber(localStruct, xyPattern, iChamber, iCath, icase); | |
465 | ||
466 | if (!xyPattern) continue; | |
467 | ||
468 | // get detElemId | |
469 | AliMUONTriggerCircuit triggerCircuit; | |
470 | detElemId = triggerCircuit.DetElemId(iChamber, localBoard->GetName()); | |
471 | nBoard = localBoard->GetNumber(); | |
472 | ||
473 | const AliMpVSegmentation* seg | |
474 | = AliMpSegmentation::Instance() | |
475 | ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath)); | |
476 | ||
477 | // loop over the 16 bits of pattern | |
478 | for (Int_t ibitxy = 0; ibitxy < 16; ibitxy++) { | |
479 | ||
480 | if ((xyPattern >> ibitxy) & 0x1) { | |
481 | ||
482 | // not quite sure about this | |
483 | Int_t offset = 0; | |
484 | if (iCath && localBoard->GetSwitch(6)) offset = -8; | |
485 | ||
486 | AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE); | |
487 | ||
488 | AliMUONDigit* digit = new AliMUONDigit(); | |
489 | if (!pad.IsValid()) { | |
490 | AliWarning(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n", | |
491 | detElemId, nBoard, ibitxy)); | |
492 | continue; | |
493 | } // | |
494 | ||
495 | Int_t padX = pad.GetIndices().GetFirst(); | |
496 | Int_t padY = pad.GetIndices().GetSecond(); | |
497 | ||
498 | // file digit | |
499 | digit->SetPadX(padX); | |
500 | digit->SetPadY(padY); | |
501 | digit->SetCathode(iCath); | |
502 | digit->SetDetElemId(detElemId); | |
503 | digit->SetElectronics(nBoard, ibitxy); | |
504 | digitList.Add(digit); | |
505 | ||
506 | }// xyPattern | |
507 | }// ibitxy | |
508 | }// case | |
509 | ||
510 | return kTRUE; | |
511 | } | |
512 | //____________________________________________________________________ | |
513 | void AliMUONDigitMaker::GetCrateName(Char_t* name, Int_t iDDL, Int_t iReg) const | |
514 | { | |
515 | /// set crate name from DDL & reg number | |
516 | /// method same as in RawWriter, not so nice | |
517 | /// should be put in AliMUONTriggerCrateStore | |
518 | ||
519 | switch(iReg) { | |
520 | case 0: | |
521 | case 1: | |
522 | sprintf(name,"%d", iReg+1); | |
523 | break; | |
524 | case 2: | |
525 | strcpy(name, "2-3"); | |
526 | break; | |
527 | case 3: | |
528 | case 4: | |
529 | case 5: | |
530 | case 6: | |
531 | case 7: | |
532 | sprintf(name,"%d", iReg); | |
533 | break; | |
534 | } | |
535 | ||
536 | // crate Right for first DDL | |
537 | if (iDDL == 0) | |
538 | strcat(name, "R"); | |
539 | else | |
540 | strcat(name, "L"); | |
541 | } |