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