adding some dijet plots
[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
3d1463c8 16// $Id$
17
18//-----------------------------------------------------------------------------
9265505b 19/// \class AliMUONDigitMaker
8c51a32f 20/// MUON Digit maker from rawdata.
a3283a4c 21///
22/// Raw2Digits:
23/// Using real mapping for tracker
24/// Indranil Das (Adapted for runloader: Ch. Finck) july 05
8c51a32f 25///
26/// Implemented non-constant buspatch numbers for tracking
27/// with correct DDL id.
28/// (Ch. Finck, dec 05)
29///
a3283a4c 30/// Add reader for scaler trigger events
31/// Use memcpy instead of assignment elt by elt
32/// (Ch. Finck, Jan 06)
8c51a32f 33///
34/// Using new interface with AliMUONRawStreamTracker(Trigger)
35/// (New interface of AliMUONRawReader class)
36/// (further details could be found in Alice-note)
37/// (Ch. Finck, March 06)
38///
39/// Add (S)Digit maker tracker (for free)
40/// and for trigger. Create trigger inverse mapping.
78649106 41///
42/// \author Ch. Finck, oct 06
3d1463c8 43//-----------------------------------------------------------------------------
a3283a4c 44
a3283a4c 45#include "AliMUONDigitMaker.h"
a3283a4c 46
a3283a4c 47#include "AliMUONDDLTrigger.h"
48#include "AliMUONDarcHeader.h"
40e382ae 49#include "AliMUONVDigit.h"
50#include "AliMUONVDigitStore.h"
51#include "AliMUONGlobalTrigger.h"
a3283a4c 52#include "AliMUONLocalStruct.h"
a3283a4c 53#include "AliMUONLocalTrigger.h"
0145e89a 54#include "AliMUONLogger.h"
e3a2b9c9 55#include "AliMUONRawStreamTrackerHP.h"
481d8064 56#include "AliMUONRawStreamTriggerHP.h"
40e382ae 57#include "AliMUONRegHeader.h"
be63c782 58#include "AliMUONVTriggerStore.h"
59#include "AliMpDetElement.h"
d9b1ecb0 60#include "AliMpTriggerCrate.h"
61#include "AliMpLocalBoard.h"
40e382ae 62#include "AliMpCathodType.h"
63#include "AliMpDDLStore.h"
64#include "AliMpDEManager.h"
65#include "AliMpPad.h"
9265505b 66#include "AliMpSegmentation.h"
a3283a4c 67#include "AliMpVSegmentation.h"
be63c782 68#include "AliCodeTimer.h"
69#include "AliLog.h"
9265505b 70#include "AliRawReader.h"
7771752e 71#include <TArrayS.h>
9265505b 72
9265505b 73/// \cond CLASSIMP
a3283a4c 74ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
9265505b 75/// \endcond
76
a3283a4c 77//__________________________________________________________________________
b6f591ae 78AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger, Bool_t a, Bool_t b) :
79TObject(),
80fScalerEvent(kFALSE),
81fMakeTriggerDigits(kFALSE),
82fRawStreamTracker(new AliMUONRawStreamTrackerHP),
83fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
84fDigitStore(0x0),
85fTriggerStore(0x0),
86fLogger(new AliMUONLogger(10000))
87{
88 /// ctor
89
90 if ( !a || !b ) AliFatal("no longer supported");
91
92 AliDebug(1,"");
93
94 // Standard Constructor
95 if (enableErrorLogger)
96 {
97 fRawStreamTracker->EnabbleErrorLogger();
98 fRawStreamTrigger->EnabbleErrorLogger();
99 }
100 else
101 {
102 fRawStreamTracker->DisableWarnings();
103 }
104
105 SetMakeTriggerDigits();
106
107}
108
109//__________________________________________________________________________
110AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger) :
111TObject(),
9f5dcca3 112 fScalerEvent(kFALSE),
40e382ae 113 fMakeTriggerDigits(kFALSE),
b6f591ae 114 fRawStreamTracker(new AliMUONRawStreamTrackerHP),
115 fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
40e382ae 116 fDigitStore(0x0),
0145e89a 117 fTriggerStore(0x0),
118 fLogger(new AliMUONLogger(10000))
a3283a4c 119{
40e382ae 120 /// ctor
a3283a4c 121
122 AliDebug(1,"");
e3a2b9c9 123
a3283a4c 124 // Standard Constructor
b6f591ae 125 if (enableErrorLogger)
126 {
3c7f5307 127 fRawStreamTracker->EnabbleErrorLogger();
128 fRawStreamTrigger->EnabbleErrorLogger();
129 }
b6f591ae 130 else
131 {
132 fRawStreamTracker->DisableWarnings();
133 }
a3283a4c 134
40e382ae 135 SetMakeTriggerDigits();
a3283a4c 136
137}
138
139//__________________________________________________________________________
9f5dcca3 140AliMUONDigitMaker::~AliMUONDigitMaker()
a3283a4c 141{
9265505b 142 /// clean up
143 /// and time processing measure
144
a3283a4c 145 delete fRawStreamTracker;
146 delete fRawStreamTrigger;
0145e89a 147 delete fLogger;
a3283a4c 148}
149
150//____________________________________________________________________
be63c782 151void
152AliMUONDigitMaker::Print(Option_t*) const
153{
154 /// Printout
155
156 cout << "RawStreamerTracker class=" << fRawStreamTracker->ClassName()
157 << " MakeTriggerDigits=" << fMakeTriggerDigits
158 << " ScalerEvent=" << fScalerEvent
159 << " DigitStore=" << fDigitStore
160 << " TriggerStore=" << fTriggerStore << endl;
161
162 if ( fLogger ) fLogger->Print();
163}
164
165//____________________________________________________________________
166Int_t
167AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
168 AliMUONVDigitStore* digitStore,
169 AliMUONVTriggerStore* triggerStore)
a3283a4c 170{
9265505b 171 /// Main method to creates digit
172 /// for tracker
173 /// and trigger
a3283a4c 174
40e382ae 175 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
176 rawReader,digitStore,triggerStore));
177
178 fDigitStore = digitStore;
179 fTriggerStore = triggerStore;
180
181 if (!fDigitStore && !fTriggerStore)
182 {
0145e89a 183 fLogger->Log("No digit or trigger store given. Nothing to do...");
be63c782 184 return kTriggerBAD & kTrackerBAD;
40e382ae 185 }
186
be63c782 187 Int_t tracker(kOK);
188 Int_t trigger(kOK);
189
40e382ae 190 if ( fDigitStore )
191 {
192 fDigitStore->Clear(); // insure we start with an empty container
be63c782 193 tracker = ReadTrackerDDL(rawReader);
40e382ae 194 }
195
196 if ( fTriggerStore || fMakeTriggerDigits )
197 {
198 if ( fTriggerStore ) fTriggerStore->Clear();
199 if ( fMakeTriggerDigits && !fDigitStore )
200 {
0145e89a 201 fLogger->Log("Asking for trigger digits but digitStore is null");
40e382ae 202 }
203 else
204 {
be63c782 205 trigger = ReadTriggerDDL(rawReader);
40e382ae 206 }
207 }
208
be63c782 209 return tracker | trigger;
a3283a4c 210}
211
212//____________________________________________________________________
be63c782 213Int_t
214AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
a3283a4c 215{
40e382ae 216 /// Reading tracker DDL
217 /// filling the fDigitStore container, which must not be null
a3283a4c 218
40e382ae 219 AliDebug(1,"");
220
99c136e1 221 AliCodeTimerAuto("",0);
a3283a4c 222
223 // elex info
224 Int_t buspatchId;
225 UChar_t channelId;
226 UShort_t manuId;
a3283a4c 227 UShort_t charge;
a3283a4c 228
a3283a4c 229 fRawStreamTracker->SetReader(rawReader);
1bc885f3 230 fRawStreamTracker->First();
231
b6f591ae 232 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge,kTRUE) )
1bc885f3 233 {
40e382ae 234 // getting DE from buspatch
235 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
a3283a4c 236
be63c782 237 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
238
239 if (!de)
240 {
241 fLogger->Log(Form("DE %04d does not exist !"));
242 continue;
243 }
244
245 if (!de->IsConnectedChannel(manuId,channelId))
246 {
247 // non connected pad, do nothing (this is not an error !)
248 continue;
249 }
250
40e382ae 251 const AliMpVSegmentation* seg
252 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
253 manuId);
a3283a4c 254
0145e89a 255 if (!seg)
256 {
257 fLogger->Log(Form("(DE,MANUID)=(%04d,%04d) is not valid",detElemId,manuId));
258 continue;
259 }
260
be63c782 261 AliMp::CathodType cathodeType = de->GetCathodType(seg->PlaneType());
1bc885f3 262
168e9c4d 263 AliMpPad pad = seg->PadByLocation(manuId,channelId,kFALSE);
be63c782 264
40e382ae 265 if (!pad.IsValid())
266 {
0145e89a 267 fLogger->Log(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
40e382ae 268 detElemId, manuId, channelId));
269 continue;
270 }
be63c782 271
40e382ae 272 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
273 AliMUONVDigitStore::kDeny);
be63c782 274
40e382ae 275 if (!digit)
276 {
0145e89a 277 fLogger->Log(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
40e382ae 278 detElemId, manuId, channelId));
279 continue;
280 }
281
168e9c4d 282 digit->SetPadXY(pad.GetIx(),pad.GetIy());
40e382ae 283
168e9c4d 284 digit->SetADC(charge);
9265505b 285
40e382ae 286 }
a3283a4c 287
be63c782 288 if ( fRawStreamTracker->IsErrorMessage() )
289 {
290 return kTrackerBAD;
291 }
292
293 return kOK;
a3283a4c 294}
295
296//____________________________________________________________________
be63c782 297Int_t
298AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
a3283a4c 299{
481d8064 300 /// reading tracker DDL like ReadTriggerDDL but with fast decoder interface.
301 /// filling the fTriggerStore container, which must not be null
302
303 const AliMUONRawStreamTriggerHP::AliHeader* darcHeader = 0x0;
304 const AliMUONRawStreamTriggerHP::AliRegionalHeader* regHeader = 0x0;
305 const AliMUONRawStreamTriggerHP::AliLocalStruct* localStruct = 0x0;
306
307 Int_t loCircuit;
308
309 fRawStreamTrigger->SetReader(rawReader);
481d8064 310
311 while (fRawStreamTrigger->NextDDL())
312 {
818aff28 313 darcHeader = fRawStreamTrigger->GetHeaders();
481d8064 314
315 // fill global trigger information
316 if (fTriggerStore)
317 {
318 if (darcHeader->GetGlobalFlag())
319 {
320 AliMUONGlobalTrigger globalTrigger;
321 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
a90f8830 322 globalTrigger.SetFromGlobalInput(darcHeader->GetGlobalHeader()->fInput);
481d8064 323 fTriggerStore->SetGlobal(globalTrigger);
324 }
325 }
326
818aff28 327 Int_t nReg = fRawStreamTrigger->GetRegionalHeaderCount();
481d8064 328
329 for(Int_t iReg = 0; iReg < nReg ;iReg++)
330 { //reg loop
331
332
333 // crate info
334 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
335 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
336
337 if (!crate)
338 fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
339
340
818aff28 341 regHeader = fRawStreamTrigger->GetRegionalHeader(iReg);
481d8064 342
343 Int_t nLocal = regHeader->GetLocalStructCount();
344 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
345 {
346
347 localStruct = regHeader->GetLocalStruct(iLocal);
348
349 // if card exist
350 if (localStruct) {
351
352 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
353
354 if ( !loCircuit ) continue; // empty slot
355
1ffbeb9d 356 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, kTRUE);
481d8064 357
358 // skip copy cards
359 if( !localBoard->IsNotified())
360 continue;
361
362 if (fTriggerStore)
363 {
364 // fill local trigger
365 AliMUONLocalTrigger localTrigger;
a026ce9e 366 localTrigger.SetLocalStruct(loCircuit, *localStruct);
481d8064 367 fTriggerStore->Add(localTrigger);
368 }
369
370 if ( fMakeTriggerDigits )
371 {
372 //FIXEME should find something better than a TArray
373 TArrayS xyPattern[2];
374
375 localStruct->GetXPattern(xyPattern[0]);
376 localStruct->GetYPattern(xyPattern[1]);
377
378 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
379 }
380 } // if triggerY
381 } // iLocal
382 } // iReg
383 } // NextDDL
384
385 return kOK;
386}
387
388//____________________________________________________________________
7771752e 389Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
40e382ae 390 TArrayS* xyPattern,
391 AliMUONVDigitStore& digitStore) const
d2d759cf 392{
40e382ae 393 /// make digits for trigger from pattern, and add them to digitStore
d2d759cf 394
99c136e1 395 AliCodeTimerAuto("",0);
0145e89a 396
d9b1ecb0 397 Int_t detElemId;
398
399 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
400
8c0b5e70 401 Int_t n,b;
402
d2d759cf 403 // loop over x1-4 and y1-4
40e382ae 404 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
405 {
406 for (Int_t iCath = 0; iCath < 2; ++iCath)
407 {
7771752e 408 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
409 if (!pattern) continue;
40e382ae 410
7771752e 411 // get detElemId
d9b1ecb0 412 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
40e382ae 413
414 const AliMpVSegmentation* seg
415 = AliMpSegmentation::Instance()
416 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
417
418 // loop over the 16 bits of pattern
419 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
420 {
421 if ((pattern >> ibitxy) & 0x1)
422 {
423 // not quite sure about this
424 Int_t offset = 0;
dc5d3949 425 if (iCath && localBoard->GetSwitch(AliMpLocalBoard::kZeroAllYLSB)) offset = -8;
40e382ae 426
168e9c4d 427 AliMpPad pad = seg->PadByLocation(nBoard,ibitxy+offset,kTRUE);
40e382ae 428
429 if (!pad.IsValid())
430 {
0145e89a 431 fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
40e382ae 432 detElemId, nBoard, ibitxy));
433 continue;
434 }
8c0b5e70 435
168e9c4d 436 n = pad.GetLocalBoardId(0); // always take first location so that digits are not inserted several times
437 b = pad.GetLocalBoardChannel(0);
8c0b5e70 438
439 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
440 n,b,nBoard,ibitxy));
441
442 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
40e382ae 443
444 if (!digit)
445 {
8c0b5e70 446 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
447 detElemId,nBoard,ibitxy,iCath));
448 continue;
40e382ae 449 }
450
168e9c4d 451 Int_t padX = pad.GetIx();
452 Int_t padY = pad.GetIy();
40e382ae 453
454 // fill digit
455 digit->SetPadXY(padX,padY);
456 digit->SetCharge(1.);
457 }// xyPattern
458 }// ibitxy
7771752e 459 }// cath
460 } // ichamber
40e382ae 461
d2d759cf 462 return kTRUE;
481d8064 463}
d61f56df 464
54355f2c 465//______________________________________________________________________________
466Bool_t
467AliMUONDigitMaker::TriggerToDigitsStore(const AliMUONVTriggerStore& triggerStore,
468 AliMUONVDigitStore& digitStore) const
469{
470 //
471 /// make (S)Digit for trigger
472 //
473
474 digitStore.Clear();
475
476 AliMUONLocalTrigger* locTrg;
477 TIter next(triggerStore.CreateLocalIterator());
478
479 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
480 {
481 if (locTrg->IsNull()) continue;
482
483 TArrayS xyPattern[2];
484 locTrg->GetXPattern(xyPattern[0]);
485 locTrg->GetYPattern(xyPattern[1]);
486
487 Int_t nBoard = locTrg->LoCircuit();
488 TriggerDigits(nBoard, xyPattern, digitStore);
489 }
490 return kTRUE;
491}