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