]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerCircuitNew.cxx
Geometry builder classes moved from base to sim.
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerCircuitNew.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 // --------------------
19 // Class AliMUONTriggerCircuitNew
20 // --------------------
21 // Contains as data members the Y positions of the X declusturized strips and 
22 // the X positions of the (doubled or not) Y strips.
23 // This is used to associate the global positions to the fired strips of the 
24 // local trigger output (see AliMUONTrackReconstructor::MakeTriggerTrack)
25
26 #include <TMath.h>
27 #include "AliMUONTriggerCircuitNew.h"
28 #include "AliRun.h"
29 #include "AliMUON.h"
30 #include "AliMUONTriggerConstants.h"
31 #include "AliMUONGeometrySegmentation.h"
32 #include "AliMUONSegmentation.h"
33 #include "AliMUONConstants.h"
34 #include "AliLog.h"
35 #include "AliMUONLocalTriggerBoard.h"
36 #include "AliMUONTriggerCrateStore.h"
37 #include "AliMUONTriggerCrate.h"
38 #include "AliMpTriggerSegmentation.h"
39 #include "AliMpTrigger.h"
40 #include "AliMpSlat.h"
41 #include "AliMpPCB.h"
42 #include "AliMpVSegmentation.h"
43 #include "AliMUONGeometryTransformer.h"
44
45 ClassImp(AliMUONTriggerCircuitNew)
46
47 //----------------------------------------------------------------------
48 AliMUONTriggerCircuitNew::AliMUONTriggerCircuitNew()
49 : TObject(),
50 fILocalBoard(0)
51 {
52   // Constructor
53   
54   Int_t i;  
55   for (i=0; i<16; i++) { fXpos11[i]=0.; }
56   for (i=0; i<31; i++) { fYpos11[i]=0.; }
57   for (i=0; i<63; i++) { fYpos21[i]=0.; }
58 }
59
60 //----------------------------------------------------------------------
61 AliMUONTriggerCircuitNew::AliMUONTriggerCircuitNew(const AliMUONTriggerCircuitNew& theMUONTriggerCircuit)
62 : TObject(theMUONTriggerCircuit)
63 {
64   // Protected copy constructor
65   
66   AliFatal("Not implemented.");
67 }
68
69 //----------------------------------------------------------------------
70 AliMUONTriggerCircuitNew & 
71 AliMUONTriggerCircuitNew::operator=(const AliMUONTriggerCircuitNew& rhs)
72 {
73   // Protected assignement operator
74   
75   if (this == &rhs) return *this;
76   
77   AliFatal("Not implemented.");
78   
79   return *this;  
80 }
81
82 //----------------------------------------------------------------------
83 void AliMUONTriggerCircuitNew::Init(Int_t iCircuit, const AliMUONTriggerCrateStore& crates) 
84 {
85   // initialize circuit characteristics
86   fILocalBoard=iCircuit+1;//AliMUONTriggerConstants::CircuitId(iCircuit);
87   
88   LoadXPos(crates);
89   LoadYPos(crates);
90   
91 }
92
93 //---------------------------------------------------------------------
94 void AliMUONTriggerCircuitNew::LoadYPos(const AliMUONTriggerCrateStore& crates)
95 {
96   // fill fYpos11 and fYpos21 -> y position of X declusterized strips
97   
98   const AliMUONLocalTriggerBoard* localBoard = crates.LocalBoard(fILocalBoard);
99   
100   if (!localBoard)
101   {
102     AliError(Form("Did not get localboard %d",fILocalBoard));
103     return;
104   }
105   StdoutToAliDebug(1,localBoard->Print("CONF"););
106   
107   Int_t ichamber = 0;
108   Int_t icathode = 0;    
109   
110   AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON"); 
111   const AliMpVSegmentation* seg;
112   const AliMUONGeometryTransformer* kGeomTransformer 
113     = pMUON->GetGeometryTransformer();
114   
115   Int_t zeroDown = localBoard->GetSwitch(AliMUONLocalTriggerBoard::kZeroDown);
116   Int_t zeroUp = localBoard->GetSwitch(AliMUONLocalTriggerBoard::kZeroUp);
117   
118   //--- first plane 
119   ichamber = 11;
120   
121   char side;
122   Int_t iline, icol;
123   DecodeBoardName(localBoard->GetName(),side,iline,icol);
124   
125   Int_t detElemId = DetElemId(ichamber,side,iline);
126   seg = pMUON->GetSegmentation()->GetMpSegmentation(detElemId,icathode);  
127   
128   Int_t iFirstStrip = FirstStrip(localBoard->GetName());
129   Int_t iLastStrip = iFirstStrip + 16;    
130   Int_t iStripCircuit = 0;
131   FillXstrips(kGeomTransformer,seg,detElemId,icol, 
132               iFirstStrip,iLastStrip,iStripCircuit,fYpos11);
133   
134   //--- second plane 
135   ichamber = 13;
136   
137   detElemId = DetElemId(ichamber,side,iline);
138   seg = pMUON->GetSegmentation()->GetMpSegmentation(detElemId,icathode);
139   
140   // second plane middle part
141   Int_t iFirstStripMiddle = FirstStrip(localBoard->GetName());
142   Int_t iLastStripMiddle = iFirstStrip + 16;
143   iStripCircuit=8;
144   FillXstrips(kGeomTransformer,seg,detElemId,icol, 
145               iFirstStripMiddle,iLastStripMiddle,iStripCircuit,fYpos21);
146   
147   // second plane upper part
148   if (zeroUp == 0) { // something up
149     Int_t iFirstStripUp;
150     Int_t iLastStripUp;
151     Int_t icolUp=icol;
152     // check if we need to move to another detElemId
153     AliMpPad pad = seg->PadByIndices(AliMpIntPair(icol-1,iLastStripMiddle+1),kFALSE);
154     if (pad.IsValid()) { // upper strips within same detElemId
155             iFirstStripUp = iLastStripMiddle;
156             iLastStripUp = iFirstStripUp + 8;
157       //            icolUp = icol;
158     } else {             // upper strips in another detElemId
159             detElemId = DetElemId(ichamber,side,iline+1); // get detElemId
160             seg = pMUON->GetSegmentation()->GetMpSegmentation(detElemId,icathode);  
161             iFirstStripUp = 0;
162             iLastStripUp = iFirstStripUp + 8;
163             if (iline == 4) icolUp = icol - 1; // special case
164             if (iline == 5) icolUp = icol + 1; // special case
165     }
166     
167     iStripCircuit=24;
168     FillXstrips(kGeomTransformer,seg,detElemId,icolUp, 
169                 iFirstStripUp,iLastStripUp,iStripCircuit,fYpos21);
170     
171     // fill strip between middle and upper part
172     fYpos21[47]=(fYpos21[46]+fYpos21[48])/2.;
173   } // end of something up
174   
175   // restore current detElemId & segmentation
176   detElemId = DetElemId(ichamber,side,iline); 
177   seg = pMUON->GetSegmentation()->GetMpSegmentation(detElemId,icathode);  
178   
179   // second plane lower part
180   if (zeroDown == 0) { // something down
181     Int_t iFirstStripDo;
182     Int_t iLastStripDo;
183     Int_t icolDo=icol;
184     
185     // check if we need to move to another detElemId      
186     AliMpPad pad = seg->PadByIndices(AliMpIntPair(icol-1,iFirstStripMiddle-1),kFALSE);
187     if (pad.IsValid()) { // lower strips within same detElemId
188             iFirstStripDo = iFirstStripMiddle - 8;
189             iLastStripDo = iFirstStripDo + 8;         
190       //            icolDo = icol;
191     } else {             // lower strips in another detElemId 
192             detElemId = DetElemId(ichamber,side,iline-1); // get detElemId
193             seg = pMUON->GetSegmentation()->GetMpSegmentation(detElemId,icathode);  
194       
195       // get iFirstStrip in this module 
196             const AliMpTriggerSegmentation* trig = (AliMpTriggerSegmentation*)(seg);
197             const AliMpTrigger* t = trig->Slat();
198             const AliMpSlat* slat = t->GetLayer(0);
199             if (iline == 5) icolDo = icol + 1; // special case
200             if (iline == 6) icolDo = icol - 1; // special case      
201             const AliMpPCB* pcb = slat->GetPCB(icolDo-1);
202             iFirstStripDo = (pcb->Iymax() + 1) - 8;
203             iLastStripDo =  iFirstStripDo + 8;
204     }  
205     
206     iStripCircuit=0;
207     FillXstrips(kGeomTransformer,seg,detElemId,icolDo, 
208                 iFirstStripDo,iLastStripDo,iStripCircuit,fYpos21);
209     
210     // fill strip between middle and upper part
211     fYpos21[15]=(fYpos21[14]+fYpos21[16])/2.;
212   } // end of something down
213   
214 }
215
216 //----------------------------------------------------------------------
217 void AliMUONTriggerCircuitNew::LoadXPos(const AliMUONTriggerCrateStore& crates)
218 {
219   // fill fXpos11 -> x position of Y strips for the first plane only
220   // fXpos11 contains the x position of Y strip for the current circuit
221   // taking into account whether or nor not part(s) of the circuit
222   // (middle, up or down) has(have) 16 strips (handdled by means of switchs)
223   
224   const AliMUONLocalTriggerBoard* localBoard = crates.LocalBoard(fILocalBoard);
225   
226   if (!localBoard)
227   {
228     AliError(Form("Did not get localboard %d",fILocalBoard));
229     return;
230   }
231   StdoutToAliDebug(1,localBoard->Print("CONF"););
232   
233   Int_t ichamber = 11;
234   Int_t icathode = 1;
235   
236   Int_t x2u = localBoard->GetSwitch(AliMUONLocalTriggerBoard::kX2u);
237   Int_t x2m = localBoard->GetSwitch(AliMUONLocalTriggerBoard::kX2m);
238   Int_t x2d = localBoard->GetSwitch(AliMUONLocalTriggerBoard::kX2d);
239   Int_t zeroAllYLSB = localBoard->GetSwitch(AliMUONLocalTriggerBoard::kZeroAllYLSB);
240   Int_t iStripCircuit = 0;
241   Int_t iFirstStrip = 0;
242   Int_t iLastStrip = 0;
243   Bool_t doubling = kFALSE;
244   
245   AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON"); 
246   const AliMpVSegmentation* seg;
247   const AliMUONGeometryTransformer* kGeomTransformer 
248     = pMUON->GetGeometryTransformer();
249   
250   char side;
251   Int_t iline, icol;
252   
253   DecodeBoardName(localBoard->GetName(),side,iline,icol);
254   
255   Int_t detElemId=DetElemId(ichamber,side,iline); // get detElemId
256   seg = pMUON->GetSegmentation()->GetMpSegmentation(detElemId,icathode);
257   
258   // check if one needs a strip doubling or not
259   if ( (x2u == 1 || x2m == 1 || x2d == 1) && x2m == 1) doubling = kTRUE;
260   
261   // check if one starts at strip = 0 or 8 (boards 26-29 and 143-146)
262   if (zeroAllYLSB == 1) iStripCircuit = 8;
263   
264   // get iFirstStrip in this module 
265   const AliMpTriggerSegmentation* trig = (AliMpTriggerSegmentation*)(seg);
266   const AliMpTrigger* t = trig->Slat();
267   const AliMpSlat* slat = t->GetLayer(0);
268   
269   const AliMpPCB* pcb = slat->GetPCB(icol-1);
270   iFirstStrip = pcb->Ixmin();
271   
272   if (doubling) iLastStrip = iFirstStrip + 8;
273   else iLastStrip = iFirstStrip + 16;
274   
275   FillYstrips(kGeomTransformer,seg,detElemId, 
276               iFirstStrip,iLastStrip,iStripCircuit,doubling);  
277 }
278
279 //----------------------------------------------------------------------
280 void AliMUONTriggerCircuitNew::FillYstrips(
281                                            const AliMUONGeometryTransformer* kGeomTransformer,
282                                            const AliMpVSegmentation* seg,
283                                            const Int_t detElemId, 
284                                            const Int_t iFirstStrip, const Int_t iLastStrip, Int_t liStripCircuit,
285                                            const Bool_t doubling)
286 {    
287   // fill
288   Double_t xyGlobal[4]={0.,0.,0.,0.};
289   for (Int_t istrip=iFirstStrip; istrip<iLastStrip; istrip++) {
290     AliMpPad pad = seg->PadByIndices(AliMpIntPair(istrip,0),kTRUE);
291     if ( !pad.IsValid() )
292     {
293             StdoutToAliError(cout << "Pad not found in seg " << endl;
294                        seg->Print();
295                        cout << " ix,iy=" << istrip << "," << 0 << endl;
296                        );
297     }
298     XYGlobal(kGeomTransformer,detElemId,pad,xyGlobal);
299     
300     if (!doubling) {        
301             fXpos11[liStripCircuit]=xyGlobal[0];
302     } else if (doubling) {          
303             fXpos11[2*liStripCircuit]=TMath::Sign(1.,xyGlobal[0]) * 
304       (TMath::Abs(xyGlobal[0]) - xyGlobal[2]/2.);
305             fXpos11[2*liStripCircuit+1]=TMath::Sign(1.,xyGlobal[0]) *
306         (TMath::Abs(fXpos11[2*liStripCircuit]) + xyGlobal[2]); 
307     }   
308     liStripCircuit++;
309   }    
310 }
311
312 //----------------------------------------------------------------------
313 void AliMUONTriggerCircuitNew::FillXstrips(
314                                            const AliMUONGeometryTransformer* kGeomTransformer,
315                                            const AliMpVSegmentation* seg,
316                                            const Int_t detElemId, const Int_t icol, 
317                                            const Int_t iFirstStrip, const Int_t iLastStrip, 
318                                            Int_t liStripCircuit, Float_t *tab)
319 {    
320   // fill 
321   Double_t xyGlobal[4]={0.,0.,0.,0.};
322   for (Int_t istrip=iFirstStrip; istrip<iLastStrip; istrip++) {
323     AliMpPad pad = seg->PadByIndices(AliMpIntPair(icol-1,istrip),kTRUE);
324     if ( !pad.IsValid() )
325     {
326             StdoutToAliError(cout << "Pad not found in seg " << endl;
327                        seg->Print();
328                        cout << " ix,iy=" << icol-1 << "," << istrip << endl;
329                        );
330     }
331     
332     XYGlobal(kGeomTransformer,detElemId,pad,xyGlobal);
333     
334     tab[2*liStripCircuit]=xyGlobal[1];
335     if (istrip!=(iLastStrip-1)) tab[2*liStripCircuit+1]=xyGlobal[1]+xyGlobal[3];
336     liStripCircuit++;
337   }    
338 }
339
340 //----------------------------------------------------------------------
341 //--- methods which return member data related info
342 //----------------------------------------------------------------------
343 Float_t AliMUONTriggerCircuitNew::GetY11Pos(Int_t istrip) const {
344   // returns Y position of X strip istrip in MC11
345   return fYpos11[istrip];
346 }
347 //----------------------------------------------------------------------
348 Float_t AliMUONTriggerCircuitNew::GetY21Pos(Int_t istrip) const {
349   // returns Y position of X strip istrip in MC21
350   return fYpos21[istrip];
351 }
352 //----------------------------------------------------------------------
353 Float_t AliMUONTriggerCircuitNew::GetX11Pos(Int_t istrip) const {
354   // returns X position of Y strip istrip in MC11
355   return fXpos11[istrip];
356 }
357 //----------------------------------------------------------------------
358 //--- end of methods which return member data related info
359 //----------------------------------------------------------------------
360 /* removed tmp
361 void AliMUONTriggerCircuitNew::dump(const char* what, const Float_t* array, Int_t size)
362 {
363   cout << what << " " << endl;
364   for ( Int_t i = 0; i < size; ++i )
365   {
366     cout << array[i] << " , ";
367   }
368   cout << endl;
369 }
370
371 void AliMUONTriggerCircuitNew::dump(const char* what, const Int_t* array, Int_t size)
372 {
373   cout << what << " " << endl;
374   for ( Int_t i = 0; i < size; ++i )
375   {
376     cout << array[i] << " , ";
377   }
378   cout << endl;
379 }
380
381 //_____________________________________________________________________________
382 void AliMUONTriggerCircuitNew::Print(Option_t* ) const
383 {
384   cout << "IdCircuit " << fILocalBoard << " X2m,X2ud=" << fX2m << ","
385   << fX2ud;
386   for ( Int_t i = 0; i < 2; ++i )
387   {
388     cout << " OrMud[" << i << "]=" << fOrMud[i];
389   }
390   cout << endl;
391   dump("Xpos11",fXpos11,16);
392   dump("Ypos11",fYpos11,31);
393   dump("Ypos21",fYpos21,63);
394   for ( Int_t i = 0; i < 4; ++i )
395   {
396     char s[80];
397     sprintf(s,"Xcode[%d]",i);
398     dump(s,fXcode[i],32);
399     sprintf(s,"Ycode[%d]",i);
400     dump(s,fYcode[i],32);
401   }
402   // Int_t fILocalBoard;            // circuit Id number
403   //  Int_t fX2m;                  // internal info needed by TriggerDecision
404   //  Int_t fX2ud;                 // internal info needed by TriggerDecision
405   //  Int_t fOrMud[2];             // internal info needed by TriggerDecision
406   //  Int_t fXcode[4][32];         // code of X strips
407   //  Int_t fYcode[4][32];         // code of Y strips 
408   //  Float_t fXpos11[16];         // X position of Y strips in MC11
409   //  Float_t fYpos11[31];         // Y position of X strips in MC11
410   //  Float_t fYpos21[63];         // Y position of X strips in MC21
411   
412 }
413 removed tmp*/
414
415 //----------------------------------------------------------------------
416 Int_t AliMUONTriggerCircuitNew::DetElemId(Int_t ichamber, char side, Int_t iline)
417 {
418   // returns detection element Id for chamber iChamber, side side and line iline
419   Int_t itmp=0;    
420   if ( side == 'R' ) {         // right side 
421     switch (iline) // (from 1 to 9, from bottom to top)
422     {
423       case 1:
424         itmp = 14;
425         break;  
426       case 2:
427         itmp = 15;
428         break;          
429       case 3:
430         itmp = 16;
431         break;
432       case 4:
433         itmp = 17;
434         break;      
435       case 5:
436         itmp = 0;
437         break;          
438       case 6:
439         itmp = 1;
440         break;          
441       case 7:
442         itmp = 2;
443         break;          
444       case 8:
445         itmp = 3;
446         break;          
447       case 9:
448         itmp = 4;
449         break;
450     }   
451   } else if ( side == 'L' ) { // left side          
452     switch (iline) // (from 1 to 9, from bottom to top)
453     {
454       case 1:
455         itmp = 13;
456         break;          
457       case 2:
458         itmp = 12;
459         break;          
460       case 3:
461         itmp = 11;
462         break;          
463       case 4:
464         itmp = 10;
465         break;          
466       case 5:
467         itmp = 9;
468         break;          
469       case 6:
470         itmp = 8;
471         break;          
472       case 7:
473         itmp = 7;
474         break;          
475       case 8:
476         itmp = 6;
477         break;
478       case 9:
479         itmp = 5;
480         break;          
481     }
482   }    
483   return (ichamber*100)+itmp;      
484 }
485
486 //----------------------------------------------------------------------
487 Int_t
488 AliMUONTriggerCircuitNew::DetElemId(Int_t iChamber, const char* boardName)
489 {
490   // returns detection element Id for chamber iChamber and board boardName
491   char side = boardName[5];
492   Int_t iline = boardName[4] - '0';
493   return DetElemId(iChamber,side,iline);
494 }
495
496 //----------------------------------------------------------------------
497 void
498 AliMUONTriggerCircuitNew::DecodeBoardName(const char* boardName,
499                                           char& side,
500                                           Int_t& iLine,
501                                           Int_t& iCol)
502 {
503   // get side, line and col from board boardName
504   // note: icol = icol -1 for iline = 5 w.r.t other ilines
505   side = boardName[0];
506   iLine = boardName[4] - '0';
507   iCol = boardName[2] - '0';
508   if ( iLine == 5 ) --iCol;
509 }
510
511 //----------------------------------------------------------------------
512 Int_t
513 AliMUONTriggerCircuitNew::FirstStrip(const char* boardName)
514 {
515   // returns the first strip from mapping for board boardName
516   // take care of special case for boards RC1L6B12 & LC1L6B12
517   Int_t iFirstStrip = -1;
518   Int_t boardNumber = atoi(boardName+6);
519   char side;
520   Int_t iline, icol;
521   DecodeBoardName(boardName,side,iline,icol);
522   switch (boardNumber)
523   {
524     case 12:
525       iFirstStrip = 0;
526       break;            
527     case 34:
528       iFirstStrip = 16;
529       break;            
530     case 56:
531       iFirstStrip = 32;
532       break;            
533     case 78:
534       iFirstStrip = 48;
535       break;            
536   }
537   if (icol == 1 && iline == 6) iFirstStrip = iFirstStrip + 16; // special case
538   return iFirstStrip;
539 }
540
541 //----------------------------------------------------------------------
542 void AliMUONTriggerCircuitNew::XYGlobal(
543                                         const AliMUONGeometryTransformer* kGeomTransformer,
544                                         Int_t detElemId, const AliMpPad& pad,
545                                         Double_t xyGlobal[4])
546 {
547   // returns pad x & y positions and x & y pad dimensions in global coordinates
548   // note: no need for transformation for pad dimensions
549   
550   // get the pad position and dimensions
551   Double_t xl1 = pad.Position().X();
552   Double_t yl1 = pad.Position().Y();
553   xyGlobal[2] = pad.Dimensions().X(); // half size!
554   xyGlobal[3] = pad.Dimensions().Y(); // half size! 
555   Double_t zg1=0;
556   
557   // positions from local to global 
558   kGeomTransformer->Local2Global(detElemId, xl1, yl1, 0, 
559                                  xyGlobal[0], xyGlobal[1], zg1);
560 }