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