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