Previous commit had the bad side-effect of changing the behaviour of Raw QA to comput...
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerCircuit.cxx
CommitLineData
8ff54bb6 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/* $Id$ */
17
3d1463c8 18//-----------------------------------------------------------------------------
8ff54bb6 19/// \class AliMUONTriggerCircuit
20/// Contains as data members the Y positions of the X declusturized strips and
21/// the X positions of the (doubled or not) Y strips.
22/// This is used to associate the global positions to the fired strips of the
23/// local trigger output (see AliMUONTrackReconstructor::MakeTriggerTrack)
78649106 24///
25/// \author Philippe Crochet (LPCCFd)
3d1463c8 26//-----------------------------------------------------------------------------
8ff54bb6 27
28#include "AliMUONTriggerCircuit.h"
afeb2b33 29#include "AliMUONConstants.h"
da142235 30#include "AliMUONGeometryTransformer.h"
8ff54bb6 31
8ff54bb6 32#include "AliMpTrigger.h"
33#include "AliMpSlat.h"
34#include "AliMpPCB.h"
35#include "AliMpSegmentation.h"
36#include "AliMpVSegmentation.h"
866c3232 37#include "AliMpCathodType.h"
7103ac2d 38#include "AliMpDDLStore.h"
39#include "AliMpLocalBoard.h"
40#include "AliMpConstants.h"
da142235 41#include "AliMpPad.h"
168e9c4d 42#include "AliMpEncodePair.h"
8ff54bb6 43
44#include "AliRun.h"
45#include "AliLog.h"
46
47#include <TMath.h>
9de45220 48#include <Riostream.h>
8ff54bb6 49
50/// \cond CLASSIMP
51ClassImp(AliMUONTriggerCircuit)
52/// \endcond
53
54//----------------------------------------------------------------------
7103ac2d 55AliMUONTriggerCircuit::AliMUONTriggerCircuit(const AliMUONGeometryTransformer* transformer)
56 : TObject(),
da142235 57 fkTransformer(transformer),
58 fkCurrentSeg(0x0),
7103ac2d 59 fCurrentDetElem(0x0),
60 fCurrentLocalBoard(0x0)
8ff54bb6 61{
62/// Constructor
63
7103ac2d 64 for (Int_t i = 1; i < AliMpConstants::NofLocalBoards()+1; ++i) {
65 fXpos11[i].Set(16);
66 fYpos11[i].Set(31);
67 fYpos21[i].Set(63);
68 }
69
70 for (Int_t i = 1; i < AliMpConstants::NofLocalBoards()+1; ++i) { // board begins at 1
71
72 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(i);
73
74 if (!localBoard)
75 {
76 AliError(Form("Did not get localboard %d",i));
77 continue;
78 }
79
80 LoadXPos(localBoard);
81 LoadYPos(localBoard);
82
83 }
84
8ff54bb6 85}
86
87//----------------------------------------------------------------------
88AliMUONTriggerCircuit::~AliMUONTriggerCircuit()
89{
90/// Destructor
7103ac2d 91 for (Int_t i = 1; i < AliMpConstants::NofLocalBoards()+1; ++i) {
92 fXpos11[i].Reset();
93 fYpos11[i].Reset();
94 fYpos21[i].Reset();
95 }
96
8ff54bb6 97}
98
99//----------------------------------------------------------------------
100AliMUONTriggerCircuit::AliMUONTriggerCircuit(const AliMUONTriggerCircuit& circuit)
7103ac2d 101 : TObject(circuit),
da142235 102 fkTransformer(circuit.fkTransformer), // do not copy, just pointed to
103 fkCurrentSeg(circuit.fkCurrentSeg),
7103ac2d 104 fCurrentDetElem(circuit.fCurrentDetElem),
105 fCurrentLocalBoard(circuit.fCurrentLocalBoard)
8ff54bb6 106{
107/// Copy constructor
108
7103ac2d 109 for (Int_t i = 1; i < AliMpConstants::NofLocalBoards()+1; ++i) {
110 fXpos11[i] = circuit.fXpos11[i];
111 fYpos11[i] = circuit.fYpos11[i];
112 fYpos21[i] = circuit.fYpos21[i];
113 }
8ff54bb6 114
115}
116//----------------------------------------------------------------------
117AliMUONTriggerCircuit& AliMUONTriggerCircuit::operator=(const AliMUONTriggerCircuit& circuit)
118{
119/// Assignment operator
120
121 if (this == &circuit) return *this;
122
da142235 123 fkTransformer = circuit.fkTransformer;
124 fkCurrentSeg = circuit.fkCurrentSeg;
7103ac2d 125 fCurrentDetElem = circuit.fCurrentDetElem;
126 fCurrentLocalBoard = circuit.fCurrentLocalBoard;
8ff54bb6 127
7103ac2d 128 for (Int_t i = 1; i < AliMpConstants::NofLocalBoards()+1; ++i) {
8ff54bb6 129 fXpos11[i] = circuit.fXpos11[i];
8ff54bb6 130 fYpos11[i] = circuit.fYpos11[i];
8ff54bb6 131 fYpos21[i] = circuit.fYpos21[i];
7103ac2d 132 }
8ff54bb6 133
134 return *this;
135
136}
8ff54bb6 137
138//---------------------------------------------------------------------
da142235 139void AliMUONTriggerCircuit::LoadYPos(AliMpLocalBoard* const localBoard)
8ff54bb6 140{
141/// fill fYpos11 and fYpos21 -> y position of X declusterized strips
142
7103ac2d 143 fCurrentLocalBoard = localBoard->GetId();
8ff54bb6 144 Int_t ichamber = 0;
145 Int_t icathode = 0;
7103ac2d 146
147 Int_t zeroDown = localBoard->GetSwitch(AliMpLocalBoard::kZeroDown);
148 Int_t zeroUp = localBoard->GetSwitch(AliMpLocalBoard::kZeroUp);
149
168e9c4d 150 Int_t iline = AliMp::PairFirst(localBoard->GetPosition());
151 Int_t icol = AliMp::PairSecond(localBoard->GetPosition());
7103ac2d 152 if ( iline == 5 ) --icol;
153
8ff54bb6 154 //--- first plane
155 ichamber = 10;
7103ac2d 156 fCurrentDetElem = AliMpDDLStore::Instance()->GetDEfromLocalBoard(fCurrentLocalBoard, ichamber);
8ff54bb6 157
da142235 158 fkCurrentSeg = AliMpSegmentation::Instance()
7103ac2d 159 ->GetMpSegmentation(fCurrentDetElem, AliMp::GetCathodType(icathode));
160
161 Int_t iFirstStrip = FirstStrip(localBoard);
162 Int_t iLastStrip = iFirstStrip + 16;
8ff54bb6 163 Int_t iStripCircuit = 0;
7103ac2d 164
165 FillXstrips(icol, iFirstStrip, iLastStrip,
166 iStripCircuit, fYpos11[fCurrentLocalBoard]);
8ff54bb6 167
168 //--- second plane
169 ichamber = 12;
7103ac2d 170 fCurrentDetElem = AliMpDDLStore::Instance()->GetDEfromLocalBoard(fCurrentLocalBoard, ichamber);
171
da142235 172 fkCurrentSeg = AliMpSegmentation::Instance()
7103ac2d 173 ->GetMpSegmentation(fCurrentDetElem, AliMp::GetCathodType(icathode));
8ff54bb6 174
175 // second plane middle part
7103ac2d 176 Int_t iFirstStripMiddle = FirstStrip(localBoard);
177 Int_t iLastStripMiddle = iFirstStrip + 16;
178 iStripCircuit = 8;
179
180 FillXstrips(icol, iFirstStripMiddle, iLastStripMiddle,
181 iStripCircuit, fYpos21[fCurrentLocalBoard]);
8ff54bb6 182
183 // second plane upper part
184 if (zeroUp == 0) { // something up
185 Int_t iFirstStripUp;
186 Int_t iLastStripUp;
7103ac2d 187 Int_t icolUp = icol;
188
8ff54bb6 189 // check if we need to move to another detElemId
168e9c4d 190 AliMpPad pad = fkCurrentSeg->PadByIndices(icol-1,iLastStripMiddle+1,kFALSE);
7103ac2d 191
8ff54bb6 192 if (pad.IsValid()) { // upper strips within same detElemId
193 iFirstStripUp = iLastStripMiddle;
7103ac2d 194 iLastStripUp = iFirstStripUp + 8;
195
8ff54bb6 196 } else { // upper strips in another detElemId
7103ac2d 197 fCurrentDetElem = AliMpDDLStore::Instance()->
198 GetNextDEfromLocalBoard(fCurrentLocalBoard, ichamber);
199
da142235 200 fkCurrentSeg = AliMpSegmentation::Instance()
7103ac2d 201 ->GetMpSegmentation(fCurrentDetElem, AliMp::GetCathodType(icathode));
8ff54bb6 202
203 iFirstStripUp = 0;
7103ac2d 204 iLastStripUp = iFirstStripUp + 8;
8ff54bb6 205 if (iline == 4) icolUp = icol - 1; // special case
206 if (iline == 5) icolUp = icol + 1; // special case
207 }
208
7103ac2d 209 iStripCircuit = 24;
210 FillXstrips(icolUp, iFirstStripUp, iLastStripUp,
211 iStripCircuit, fYpos21[fCurrentLocalBoard]);
8ff54bb6 212
213 // fill strip between middle and upper part
7103ac2d 214 fYpos21[fCurrentLocalBoard][47] = (fYpos21[fCurrentLocalBoard][46] +
215 fYpos21[fCurrentLocalBoard][48])/2.;
8ff54bb6 216 } // end of something up
217
218 // restore current detElemId & segmentation
7103ac2d 219 fCurrentDetElem = AliMpDDLStore::Instance()->GetDEfromLocalBoard(fCurrentLocalBoard, ichamber);
da142235 220 fkCurrentSeg = AliMpSegmentation::Instance()
7103ac2d 221 ->GetMpSegmentation(fCurrentDetElem, AliMp::GetCathodType(icathode));
8ff54bb6 222
223 // second plane lower part
224 if (zeroDown == 0) { // something down
225 Int_t iFirstStripDo;
226 Int_t iLastStripDo;
7103ac2d 227 Int_t icolDo = icol;
8ff54bb6 228
229 // check if we need to move to another detElemId
168e9c4d 230 AliMpPad pad = fkCurrentSeg->PadByIndices(icol-1,iFirstStripMiddle-1,kFALSE);
8ff54bb6 231 if (pad.IsValid()) { // lower strips within same detElemId
232 iFirstStripDo = iFirstStripMiddle - 8;
7103ac2d 233 iLastStripDo = iFirstStripDo + 8;
234
8ff54bb6 235 } else { // lower strips in another detElemId
7103ac2d 236 fCurrentDetElem = AliMpDDLStore::Instance()
237 ->GetPreviousDEfromLocalBoard(fCurrentLocalBoard, ichamber);
238
da142235 239 fkCurrentSeg = AliMpSegmentation::Instance()
7103ac2d 240 ->GetMpSegmentation(fCurrentDetElem, AliMp::GetCathodType(icathode));
8ff54bb6 241
242 // get iFirstStrip in this module
da142235 243 const AliMpTrigger* t = AliMpSegmentation::Instance()->GetTrigger(fkCurrentSeg);
8ff54bb6 244 const AliMpSlat* slat = t->GetLayer(0);
7103ac2d 245
8ff54bb6 246 if (iline == 5) icolDo = icol + 1; // special case
7103ac2d 247 if (iline == 6) icolDo = icol - 1; // special case
248
8ff54bb6 249 const AliMpPCB* pcb = slat->GetPCB(icolDo-1);
250 iFirstStripDo = (pcb->Iymax() + 1) - 8;
251 iLastStripDo = iFirstStripDo + 8;
252 }
253
7103ac2d 254 iStripCircuit = 0;
255 FillXstrips(icolDo, iFirstStripDo, iLastStripDo,
256 iStripCircuit, fYpos21[fCurrentLocalBoard]);
8ff54bb6 257
258 // fill strip between middle and upper part
7103ac2d 259 fYpos21[fCurrentLocalBoard][15] = (fYpos21[fCurrentLocalBoard][14] +
260 fYpos21[fCurrentLocalBoard][16])/2.;
8ff54bb6 261 } // end of something down
262
263}
264
265//----------------------------------------------------------------------
7103ac2d 266void AliMUONTriggerCircuit::FillXstrips(const Int_t icol,
267 const Int_t iFirstStrip, const Int_t iLastStrip,
268 Int_t liStripCircuit, TArrayF& ypos)
269{
270/// fill
271 Double_t xyGlobal[2] = {0.};
272 for (Int_t istrip = iFirstStrip; istrip < iLastStrip; ++istrip) {
273
168e9c4d 274 AliMpPad pad = fkCurrentSeg->PadByIndices(icol-1,istrip,kTRUE);
7103ac2d 275 if ( !pad.IsValid() ) {
276 StdoutToAliError(cout << "Pad not found in seg " << endl;
da142235 277 fkCurrentSeg->Print();
7103ac2d 278 cout << " ix,iy=" << icol-1 << "," << istrip << endl;
279 );
280 }
6e97fbb8 281 Float_t yDim = pad.GetDimensionY(); // half size!
7103ac2d 282
283 XYGlobal(pad,xyGlobal);
284
285 ypos[2*liStripCircuit] = xyGlobal[1];
286 if (istrip != (iLastStrip - 1)) ypos[2*liStripCircuit+1] = xyGlobal[1] + yDim;
287 liStripCircuit++;
288 }
289}
290
291
292//----------------------------------------------------------------------
da142235 293void AliMUONTriggerCircuit::LoadXPos(AliMpLocalBoard* const localBoard)
8ff54bb6 294{
295/// fill fXpos11 -> x position of Y strips for the first plane only
296/// fXpos11 contains the x position of Y strip for the current circuit
297/// taking into account whether or nor not part(s) of the circuit
298/// (middle, up or down) has(have) 16 strips (handdled by means of switchs)
7103ac2d 299
300 fCurrentLocalBoard = localBoard->GetId();
301
8ff54bb6 302 Int_t ichamber = 10;
303 Int_t icathode = 1;
304
7103ac2d 305 Int_t x2u = localBoard->GetSwitch(AliMpLocalBoard::kX2u);
306 Int_t x2m = localBoard->GetSwitch(AliMpLocalBoard::kX2m);
307 Int_t x2d = localBoard->GetSwitch(AliMpLocalBoard::kX2d);
308 Int_t zeroAllYLSB = localBoard->GetSwitch(AliMpLocalBoard::kZeroAllYLSB);
309
310 Int_t iStripCircuit = 0;
311 Int_t iFirstStrip = 0;
312 Int_t iLastStrip = 0;
313 Bool_t doubling = kFALSE;
8ff54bb6 314
168e9c4d 315 Int_t iline = AliMp::PairFirst(localBoard->GetPosition());
316 Int_t icol = AliMp::PairSecond(localBoard->GetPosition());
7103ac2d 317 if ( iline == 5 ) --icol;
8ff54bb6 318
7103ac2d 319 fCurrentDetElem = AliMpDDLStore::Instance()->GetDEfromLocalBoard(fCurrentLocalBoard, ichamber);
320
da142235 321 fkCurrentSeg = AliMpSegmentation::Instance()
7103ac2d 322 ->GetMpSegmentation(fCurrentDetElem, AliMp::GetCathodType(icathode));
8ff54bb6 323
324 // check if one needs a strip doubling or not
7103ac2d 325 if ( (x2u || x2m || x2d ) && x2m ) doubling = kTRUE;
326
0d528e1f 327
8ff54bb6 328 // check if one starts at strip = 0 or 8 (boards 26-29 and 143-146)
7103ac2d 329 if (zeroAllYLSB) iStripCircuit = 8;
8ff54bb6 330
331 // get iFirstStrip in this module
da142235 332 const AliMpTrigger* t = AliMpSegmentation::Instance()->GetTrigger(fkCurrentSeg);
8ff54bb6 333 const AliMpSlat* slat = t->GetLayer(0);
334
335 const AliMpPCB* pcb = slat->GetPCB(icol-1);
336 iFirstStrip = pcb->Ixmin();
337
7103ac2d 338
0d528e1f 339 if (doubling || zeroAllYLSB == 1) iLastStrip = iFirstStrip + 8;
8ff54bb6 340 else iLastStrip = iFirstStrip + 16;
341
7103ac2d 342 FillYstrips(iFirstStrip, iLastStrip, iStripCircuit, doubling);
8ff54bb6 343}
344
345//----------------------------------------------------------------------
7103ac2d 346void AliMUONTriggerCircuit::FillYstrips(const Int_t iFirstStrip, const Int_t iLastStrip,
347 Int_t liStripCircuit,
348 const Bool_t doubling)
8ff54bb6 349{
350/// fill
7103ac2d 351 Double_t xyGlobal[2] = {0.};
352
353 for (Int_t istrip = iFirstStrip; istrip < iLastStrip; ++istrip) {
0d528e1f 354
168e9c4d 355 AliMpPad pad = fkCurrentSeg->PadByIndices(istrip,0,kTRUE);
0d528e1f 356
8ff54bb6 357 if ( !pad.IsValid() )
358 {
359 StdoutToAliError(cout << "Pad not found in seg " << endl;
da142235 360 fkCurrentSeg->Print();
8ff54bb6 361 cout << " ix,iy=" << istrip << "," << 0 << endl;
362 );
363 }
6e97fbb8 364 Float_t xDim = pad.GetDimensionX(); // half size!
8ff54bb6 365
7103ac2d 366 XYGlobal(pad,xyGlobal);
8ff54bb6 367
7103ac2d 368 if (!doubling) {
369 fXpos11[fCurrentLocalBoard].AddAt(xyGlobal[0], liStripCircuit);
370 } else if (doubling) {
371
372 fXpos11[fCurrentLocalBoard].AddAt(TMath::Sign(1.,xyGlobal[0]) *
373 (TMath::Abs(xyGlobal[0]) - xDim/2.), 2*liStripCircuit);
374
375 fXpos11[fCurrentLocalBoard].AddAt(TMath::Sign(1.,xyGlobal[0]) *
376 (TMath::Abs(fXpos11[fCurrentLocalBoard][2*liStripCircuit]) + xDim),
377 2*liStripCircuit + 1);
378 }
379
8ff54bb6 380 liStripCircuit++;
381 }
382}
383
384//----------------------------------------------------------------------
7103ac2d 385void AliMUONTriggerCircuit::XYGlobal(const AliMpPad& pad,
386 Double_t* xyGlobal)
8ff54bb6 387{
7103ac2d 388/// returns pad x & y positions and x & y pad dimensions in global coordinates
389/// note: no need for transformation for pad dimensions
8ff54bb6 390
7103ac2d 391 // get the pad position and dimensions
6e97fbb8 392 Double_t xl1 = pad.GetPositionX();
393 Double_t yl1 = pad.GetPositionY();
7103ac2d 394 Double_t zg1 = 0;
395
396 // positions from local to global
da142235 397 fkTransformer->Local2Global(fCurrentDetElem, xl1, yl1, 0,
7103ac2d 398 xyGlobal[0], xyGlobal[1], zg1);
8ff54bb6 399}
7103ac2d 400
8ff54bb6 401
402//----------------------------------------------------------------------
7103ac2d 403//--- methods which return member data related info
404//----------------------------------------------------------------------
405Float_t AliMUONTriggerCircuit::GetY11Pos(Int_t localBoardId, Int_t istrip) const
8ff54bb6 406{
7103ac2d 407/// returns Y position of X strip istrip in MC11
408 return fYpos11[localBoardId][istrip];
8ff54bb6 409}
8ff54bb6 410//----------------------------------------------------------------------
7103ac2d 411Float_t AliMUONTriggerCircuit::GetY21Pos(Int_t localBoardId, Int_t istrip) const
8ff54bb6 412{
7103ac2d 413/// returns Y position of X strip istrip in MC21
414 return fYpos21[localBoardId][istrip];
8ff54bb6 415}
8ff54bb6 416//----------------------------------------------------------------------
7103ac2d 417Float_t AliMUONTriggerCircuit::GetX11Pos(Int_t localBoardId, Int_t istrip) const
8ff54bb6 418{
7103ac2d 419/// returns X position of Y strip istrip in MC11
420 return fXpos11[localBoardId][istrip];
8ff54bb6 421}
422
423//----------------------------------------------------------------------
7103ac2d 424Int_t AliMUONTriggerCircuit::FirstStrip(AliMpLocalBoard* localBoard)
8ff54bb6 425{
426/// returns the first strip from mapping for board boardName
427/// take care of special case for boards RC1L6B12 & LC1L6B12
428 Int_t iFirstStrip = -1;
7103ac2d 429 Int_t boardNumber = atoi(localBoard->GetName()+6);
430
168e9c4d 431 Int_t iline = AliMp::PairFirst(localBoard->GetPosition());
432 Int_t icol = AliMp::PairSecond(localBoard->GetPosition());
7103ac2d 433 if ( iline == 5 ) --icol;
434
8ff54bb6 435 switch (boardNumber)
436 {
437 case 12:
438 iFirstStrip = 0;
439 break;
440 case 34:
441 iFirstStrip = 16;
442 break;
443 case 56:
444 iFirstStrip = 32;
445 break;
446 case 78:
447 iFirstStrip = 48;
448 break;
449 }
7103ac2d 450 if (icol == 1 && iline == 6) iFirstStrip += 16; // special case
8ff54bb6 451 return iFirstStrip;
452}
453
afeb2b33 454//----------------------------------------------------------------------
455Float_t AliMUONTriggerCircuit::PtCal(Int_t localBoardId, Int_t istripX, Int_t idev, Int_t istripY) const{
456/// returns calculated pt for circuit/istripX/idev/istripY according
457/// to the formula of the TRD. Note : idev (input) is in [0+30]
458
459 // Int_t jdev = idev - 15; // jdev in [-15+15]
460 Int_t istripX2=istripX+idev+1; // find istripX2 using istripX and idev
461
462 Float_t yPosX1=fYpos11[localBoardId][istripX];
463 Float_t yPosX2=fYpos21[localBoardId][istripX2];
464 Float_t xPosY1=fXpos11[localBoardId][istripY];
465
466// Z distance between IP and center of dipole
467 Float_t zf= TMath::Abs(0.5 *(AliMUONConstants::CoilZ() + AliMUONConstants::YokeZ()));
468 Float_t z1=AliMUONConstants::DefaultChamberZ(10);
469 Float_t z2=AliMUONConstants::DefaultChamberZ(12);
470 Float_t thetaDev=(1./zf)*(yPosX1*z2-yPosX2*z1)/(z2-z1);
471 Float_t xf=xPosY1*zf/z1;
472 Float_t yf=yPosX2-((yPosX2-yPosX1)*(z2-zf))/(z2-z1);
473 return (3.*0.3/TMath::Abs(thetaDev)) * TMath::Sqrt(xf*xf+yf*yf)/zf;
474}