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