]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDfeeParam.cxx
Reduce memory consumption
[u/mrichter/AliRoot.git] / TRD / AliTRDfeeParam.cxx
1
2 /**************************************************************************
3  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  *                                                                        *
5  * Author: The ALICE Off-line Project.                                    *
6  * Contributors are mentioned in the code where appropriate.              *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 /* $Id$ */
18
19 ////////////////////////////////////////////////////////////////////////////
20 //                                                                        //
21 //  TRD front end electronics parameters class                            //
22 //  Contains all FEE (MCM, TRAP, PASA) related                            //
23 //  parameters, constants, and mapping.                                   //
24 //                                                                        //
25 //  New release on 2007/08/17:                                            //
26 //   The default raw data version (now fRAWversion ) is set to 3          //
27 //   in the constructor because version 3 raw data read and write         //
28 //   are fully debugged.                                                  //
29 //                                                                        //
30 //  Author:                                                               //
31 //    Ken Oyama (oyama@physi.uni-heidelberg.de)                           //
32 //                                                                        //
33 ////////////////////////////////////////////////////////////////////////////
34
35 //#include <TMath.h>
36
37 #include "AliLog.h"
38
39 #include "AliTRDfeeParam.h"
40 //#include "AliTRDgeometry.h"
41 #include "AliTRDCommonParam.h"
42
43 ClassImp(AliTRDfeeParam)
44
45 AliTRDfeeParam *AliTRDfeeParam::fgInstance   = 0;
46 Bool_t          AliTRDfeeParam::fgTerminated = kFALSE;
47 Bool_t          AliTRDfeeParam::fgTracklet = kFALSE;
48
49 //_____________________________________________________________________________
50 AliTRDfeeParam* AliTRDfeeParam::Instance()
51 {
52   //
53   // Instance constructor
54   //
55
56   if (fgTerminated != kFALSE) {
57     return 0;
58   }
59
60   if (fgInstance == 0) {
61     fgInstance = new AliTRDfeeParam();
62   }  
63
64   return fgInstance;
65
66 }
67
68 //_____________________________________________________________________________
69 void AliTRDfeeParam::Terminate()
70 {
71   //
72   // Terminate the class and release memory
73   //
74   
75   fgTerminated = kTRUE;
76
77   if (fgInstance != 0) {
78     delete fgInstance;
79     fgInstance = 0;
80   }
81
82 }
83
84 //_____________________________________________________________________________
85 AliTRDfeeParam::AliTRDfeeParam()
86   :TObject()
87   ,fCP(0)
88   ,fTFnExp(1)
89   ,fTFr1(0)
90   ,fTFr2(0)
91   ,fTFc1(0)
92   ,fTFc2(0)
93   ,fEBsglIndThr(5)
94   ,fEBsumIndThr(5)
95   ,fEBindLUT(0xF0)
96   ,fEBignoreNeighbour(0)
97   ,fRAWversion(3)
98   ,fRAWstoreRaw(kTRUE)
99 {
100   //
101   // Default constructor
102   //
103   
104   // PASA V.4
105   if      (fTFnExp == 1) {
106     fTFr1 = 1.1563;
107     fTFr2 = 0.1299;
108     fTFc1 = 0.0657;
109     fTFc2 = 0.0000;
110   }
111   else if (fTFnExp == 2) {
112     fTFr1 = 1.1563;
113     fTFr2 = 0.1299;
114     fTFc1 = 0.1141;
115     fTFc2 = 0.6241;
116   }
117
118   fCP  = AliTRDCommonParam::Instance();
119
120 }
121
122 //_____________________________________________________________________________
123 AliTRDfeeParam::AliTRDfeeParam(TRootIoCtor *)
124   :TObject()
125   ,fCP(0)
126   ,fTFnExp(1)
127   ,fTFr1(0)
128   ,fTFr2(0)
129   ,fTFc1(0)
130   ,fTFc2(0)
131   ,fEBsglIndThr(0)
132   ,fEBsumIndThr(0)
133   ,fEBindLUT(0)
134   ,fEBignoreNeighbour(0)
135   ,fRAWversion(0)
136   ,fRAWstoreRaw(0)
137 {
138   //
139   // IO constructor
140   //
141
142 }
143
144 //_____________________________________________________________________________
145 AliTRDfeeParam::AliTRDfeeParam(const AliTRDfeeParam &p)
146   :TObject(p)
147   ,fCP(p.fCP)
148   ,fTFnExp(p.fTFnExp)
149   ,fTFr1(p.fTFr1)
150   ,fTFr2(p.fTFr2)
151   ,fTFc1(p.fTFc1)
152   ,fTFc2(p.fTFc2)
153   ,fEBsglIndThr(p.fEBsglIndThr)
154   ,fEBsumIndThr(p.fEBsumIndThr)
155   ,fEBindLUT(p.fEBindLUT)
156   ,fEBignoreNeighbour (p.fEBignoreNeighbour)
157   ,fRAWversion(p.fRAWversion)
158   ,fRAWstoreRaw(p.fRAWstoreRaw)
159 {
160   //
161   // AliTRDfeeParam copy constructor
162   //
163
164 }
165
166 //_____________________________________________________________________________
167 AliTRDfeeParam::~AliTRDfeeParam()
168 {
169   //
170   // AliTRDfeeParam destructor
171   //
172
173 }
174
175 //_____________________________________________________________________________
176 AliTRDfeeParam &AliTRDfeeParam::operator=(const AliTRDfeeParam &p)
177 {
178   //
179   // Assignment operator
180   //
181
182   if (this != &p) {
183     ((AliTRDfeeParam &) p).Copy(*this);
184   }
185
186   return *this;
187
188 }
189
190 //_____________________________________________________________________________
191 void AliTRDfeeParam::Copy(TObject &p) const
192 {
193   //
194   // Copy function
195   //
196
197   ((AliTRDfeeParam &) p).fCP          = fCP;
198   ((AliTRDfeeParam &) p).fTFnExp      = fTFnExp;
199   ((AliTRDfeeParam &) p).fTFr1        = fTFr1;
200   ((AliTRDfeeParam &) p).fTFr2        = fTFr2;
201   ((AliTRDfeeParam &) p).fTFc1        = fTFc1;
202   ((AliTRDfeeParam &) p).fTFc2        = fTFc2;
203   ((AliTRDfeeParam &) p).fEBsglIndThr = fEBsglIndThr;
204   ((AliTRDfeeParam &) p).fEBsumIndThr = fEBsumIndThr;
205   ((AliTRDfeeParam &) p).fEBindLUT    = fEBindLUT;
206   ((AliTRDfeeParam &) p).fEBignoreNeighbour = fEBignoreNeighbour;
207   ((AliTRDfeeParam &) p).fRAWversion  = fRAWversion;
208   ((AliTRDfeeParam &) p).fRAWstoreRaw = fRAWstoreRaw;
209   
210   TObject::Copy(p);
211
212 }
213
214 //_____________________________________________________________________________
215 Int_t AliTRDfeeParam::GetPadRowFromMCM(Int_t irob, Int_t imcm) const
216 {
217   //
218   // Return on which pad row this mcm sits
219   //
220   
221   return fgkNmcmRobInRow*(irob/2) + imcm/fgkNmcmRobInCol;
222
223 }
224
225 //_____________________________________________________________________________
226 Int_t AliTRDfeeParam::GetPadColFromADC(Int_t irob, Int_t imcm, Int_t iadc) const
227 {
228   //
229   // Return which pad is connected to this adc channel.
230   //
231   // Return virtual pad number even if ADC is outside chamber
232   // to keep compatibility of data processing at the edge MCM.
233   // User has to check that this is in the chamber if it is essential.
234   // Return -100 if iadc is invalid.
235   //
236   // Caution: ADC ordering in the online data is opposite to the pad column ordering.
237   // And it is not one-by-one correspondence. Precise drawing can be found in:
238   // http://wiki.kip.uni-heidelberg.de/ti/TRD/index.php/Image:ROB_MCM_numbering.pdf
239   //
240
241   if (iadc < 0 || iadc > fgkNadcMcm ) return -100;
242   Int_t mcmcol = imcm%fgkNmcmRobInCol + GetRobSide(irob)*fgkNmcmRobInCol;  // MCM column number on ROC [0..7]
243   Int_t padcol = mcmcol*fgkNcolMcm + fgkNcolMcm + 1 - iadc;
244   if( padcol < 0 || padcol >= fgkNcol ) return -1;   // this is commented because of reason above OK
245
246   return padcol;
247
248 }
249
250 //_____________________________________________________________________________
251 Int_t AliTRDfeeParam::GetExtendedPadColFromADC(Int_t irob, Int_t imcm, Int_t iadc) const
252 {     
253   //
254   // Return which pad coresponds to the extended digit container pad numbering
255   // Extended digit container is designed to store all pad data including shared pad, 
256   // so we have to introduce new virtual pad numbering scheme for this purpose. 
257   //
258     
259   if (iadc < 0 || iadc > fgkNadcMcm ) return -100;
260   Int_t mcmcol = imcm%fgkNmcmRobInCol + GetRobSide(irob)*fgkNmcmRobInCol;  // MCM column number on ROC [0..7]
261   Int_t padcol = mcmcol*fgkNadcMcm + fgkNcolMcm + 2 - iadc;
262
263   return padcol;
264
265 }
266
267 //_____________________________________________________________________________
268 Int_t AliTRDfeeParam::GetMCMfromPad(Int_t irow, Int_t icol) const
269 {
270   //
271   // Return on which MCM this pad is directry connected.
272   // Return -1 for error.
273   //
274
275   if ( irow < 0 || icol < 0 || irow > fgkNrowC1 || icol > fgkNcol ) return -1;
276
277   return (icol%(fgkNcol/2))/fgkNcolMcm + fgkNmcmRobInCol*(irow%fgkNmcmRobInRow);
278
279 }
280
281 //_____________________________________________________________________________
282 Int_t AliTRDfeeParam::GetMCMfromSharedPad(Int_t irow, Int_t icol) const
283 {
284   //
285   // Return on which MCM this pad is directry connected.
286   // Return -1 for error.
287   //
288   
289   if ( irow < 0 || icol < 0 || irow > fgkNrowC1 || icol > fgkNcol+8*3 ) return -1;
290
291   Int_t adc = 20 - (icol%18) -1;
292   switch(adc) {
293     case 2:  icol += 5; break;
294     case 18: icol -= 5; break;
295     case 19: icol -= 5; break;
296     default: icol += 0; break;
297   }
298
299   return (icol%(fgkNcol/2))/fgkNcolMcm + fgkNmcmRobInCol*(irow%fgkNmcmRobInRow);
300
301 }
302
303 //_____________________________________________________________________________
304 Int_t AliTRDfeeParam::GetROBfromPad(Int_t irow, Int_t icol) const
305 {
306   //
307   // Return on which rob this pad is
308   //
309
310   return (irow/fgkNmcmRobInRow)*2 + GetColSide(icol);
311
312 }
313
314 //_____________________________________________________________________________
315 Int_t AliTRDfeeParam::GetROBfromSharedPad(Int_t irow, Int_t icol) const
316 {
317   //
318   // Return on which rob this pad is for shared pads
319   //
320
321   if(icol<72) return (irow/fgkNmcmRobInRow)*2 + GetColSide(icol+5);
322   else return (irow/fgkNmcmRobInRow)*2 + GetColSide(icol-5);
323
324 }
325
326 //_____________________________________________________________________________
327 Int_t AliTRDfeeParam::GetRobSide(Int_t irob) const
328 {
329   //
330   // Return on which side this rob sits (A side = 0, B side = 1)
331   //
332
333   if ( irob < 0 || irob >= fgkNrobC1 ) return -1;
334
335   return irob%2;
336
337 }
338
339 //_____________________________________________________________________________
340 Int_t AliTRDfeeParam::GetColSide(Int_t icol) const
341 {
342   //
343   // Return on which side this column sits (A side = 0, B side = 1)
344   //
345
346   if ( icol < 0 || icol >= fgkNcol ) return -1;
347
348   return icol/(fgkNcol/2);
349
350 }
351
352
353
354 UInt_t AliTRDfeeParam::AliToExtAli(Int_t rob, Int_t aliid)
355 {
356    if(aliid!= 127)
357       return ( (1 << 10) | (rob << 7) | aliid);
358
359    return 127;
360 }
361
362
363 Int_t AliTRDfeeParam::ExtAliToAli(UInt_t dest, UShort_t linkpair, UShort_t rocType, Int_t *mcmList, Int_t listSize)
364 {
365    // Converts an extended ALICE ID which identifies a single MCM or a group of MCMs to
366    // the corresponding list of MCMs. Only broadcasts (127) are encoded as 127 
367    // The return value is the number of MCMs in the list
368
369   mcmList[0]=-1;
370
371   Short_t nmcm = 0;
372   UInt_t mcm, rob, robAB;
373   UInt_t cmA = 0, cmB = 0;  // Chipmask for each A and B side
374   
375   // Default chipmask for 4 linkpairs (each bit correponds each alice-mcm)
376   static const UInt_t gkChipmaskDefLp[4] = { 0x1FFFF, 0x1FFFF, 0x3FFFF, 0x1FFFF };
377   
378   rob = dest >> 7;                              // Extract ROB pattern from dest.
379   mcm = dest & 0x07F;                           // Extract MCM pattern from dest.
380   robAB = GetRobAB( rob, linkpair ); // Get which ROB sides are selected.
381   
382   // Abort if no ROB is selected
383   if( robAB == 0 ) {
384     return 0;
385   }
386   
387   // Special case
388   if( mcm == 127 ) {
389     if( robAB == 3 ) {      // This is very special 127 can stay only if two ROBs are selected
390       mcmList[0]=127;      // broadcase to ALL
391       mcmList[1]=-1;
392       return 1;
393     }
394     cmA = cmB = 0x3FFFF;
395   } else if( (mcm & 0x40) != 0 ) { // If top bit is 1 but not 127, this is chip group.
396     if( (mcm & 0x01) != 0 )                  { cmA |= 0x04444; cmB |= 0x04444; } // chip_cmrg
397     if( (mcm & 0x02) != 0 )                  { cmA |= 0x10000; cmB |= 0x10000; } // chip_bmrg
398     if( (mcm & 0x04) != 0 && rocType == 0 ) { cmA |= 0x20000; cmB |= 0x20000; } // chip_hm3
399     if( (mcm & 0x08) != 0 && rocType == 1 ) { cmA |= 0x20000; cmB |= 0x20000; } // chip_hm4
400     if( (mcm & 0x10) != 0 )                  { cmA |= 0x01111; cmB |= 0x08888; } // chip_edge
401     if( (mcm & 0x20) != 0 )                  { cmA |= 0x0aaaa; cmB |= 0x03333; } // chip_norm
402   } else { // Otherwise, this is normal chip ID, turn on only one chip.
403     cmA = 1 << mcm;
404     cmB = 1 << mcm;
405   }
406   
407   // Mask non-existing MCMs
408   cmA &= gkChipmaskDefLp[linkpair];
409   cmB &= gkChipmaskDefLp[linkpair];
410   // Remove if only one side is selected
411   if( robAB == 1 ) 
412     cmB = 0;
413   if( robAB == 2 ) 
414     cmA = 0;
415   if( robAB == 4 && linkpair != 2 ) 
416     cmA = cmB = 0; // Restrict to only T3A and T3B
417   
418   // Finally convert chipmask to list of slaves
419   nmcm = ChipmaskToMCMlist( cmA, cmB, linkpair, mcmList, listSize);
420   
421   return nmcm;
422 }
423
424
425 Short_t AliTRDfeeParam::GetRobAB( UShort_t robsel, UShort_t linkpair )
426 {
427   // Converts the ROB part of the extended ALICE ID to robs
428
429   if( (robsel & 0x8) != 0 ) { // 1000 .. direct ROB selection. Only one of the 8 ROBs are used.
430     robsel = robsel & 7;
431     if( (robsel % 2) == 0 && (robsel / 2) == linkpair ) 
432       return 1;  // Even means A side (position 0,2,4,6)
433     if( (robsel % 2) == 1 && (robsel / 2) == linkpair ) 
434       return 2;  // Odd  means B side (position 1,3,5,7)
435     return 0;
436   }
437   
438   // ROB group
439   if( robsel == 0 ) { return 3; } // Both   ROB
440   if( robsel == 1 ) { return 1; } // A-side ROB
441   if( robsel == 2 ) { return 2; } // B-side ROB
442   if( robsel == 3 ) { return 3; } // Both   ROB
443   if( robsel == 4 ) { return 4; } // Only T3A and T3B
444   // Other number 5 to 7 are ignored (not defined) 
445   
446   return 0;
447 }
448
449
450 Short_t AliTRDfeeParam::ChipmaskToMCMlist( UInt_t cmA, UInt_t cmB, UShort_t linkpair, Int_t *mcmList, Int_t listSize )
451 {
452   // Converts the chipmask to a list of MCMs 
453   
454   Short_t nmcm = 0;
455   Short_t i;
456   for( i = 0 ; i < listSize ; i++ ) {
457      if( (cmA & (1 << i)) != 0 ) {
458         mcmList[nmcm] = ((linkpair*2) << 7) | i;
459         ++nmcm;
460     }
461     if( (cmB & (1 << i)) != 0 ) {
462        mcmList[nmcm] = ((linkpair*2+1) << 7) | i;
463        ++nmcm;
464     }
465   }
466
467   mcmList[nmcm]=-1;
468   return nmcm;
469 }
470
471
472
473
474 //_____________________________________________________________________________
475 //void AliTRDfeeParam::GetFilterParam( Float_t &r1, Float_t &r2, Float_t &c1
476 //                                   , Float_t &c2, Float_t &ped ) const
477 //{
478   //
479   // Return current filter parameter
480   //
481
482   //  r1            = fR1;
483   //r2            = fR2;
484   //c1            = fC1;
485   //c2            = fC2;
486   //ped           = fPedestal;
487 //};
488
489 //_____________________________________________________________________________
490 void AliTRDfeeParam::SetEBsglIndThr(Int_t val)
491 {
492   //
493   // Set Event Buffer Sngle Indicator Threshold (EBIS in TRAP conf).
494   // Timebin is indicated if ADC value >= val.
495   //
496
497   if( val >= 0 && val <= 1023 ) { 
498     fEBsglIndThr = val;
499   } else {
500     AliError(Form("EBsglIndThr value %d is out of range, keep previously set value (%d).",
501                   val, fEBsglIndThr));
502   }
503
504 }
505
506 //_____________________________________________________________________________
507 void AliTRDfeeParam::SetEBsumIndThr(Int_t val)
508 {
509   //
510   // Set Event Buffer Sum Indicator Threshold (EBIT in TRAP conf).
511   // Timebin is indicated if ADC sum value >= val.
512   //
513
514   if( val >= 0 && val <= 4095 ) { 
515     fEBsumIndThr = val;
516   } 
517   else {
518     AliError(Form("EBsumIndThr value %d is out of range, keep previously set value (%d).",
519                   val, fEBsumIndThr));
520   }
521
522 }
523
524 //_____________________________________________________________________________
525 void AliTRDfeeParam::SetEBindLUT(Int_t val)
526 {
527   //
528   // Set Event Buffer Indicator Look-Up Table (EBIL in TRAP conf).
529   // 8 bits value forms lookup table for combination of three criterions.
530   //
531
532   if( val >= 0 && val <= 255 ) {
533     fEBindLUT = val;
534   } 
535   else {
536     AliError(Form("EBindLUT value %d is out of range, keep previously set value (%d).",
537                   val, fEBindLUT));
538   }
539
540 }
541
542 //_____________________________________________________________________________
543 void AliTRDfeeParam::SetEBignoreNeighbour(Int_t val)
544 {
545   //
546   // Set Event Buffer Indicator Neighbor Sensitivity. (EBIN in TRAP conf).
547   // If 0, take account of neigbor's values.
548   //
549
550   if( val >= 0 && val <= 1 ) {
551     fEBignoreNeighbour = val;
552   } 
553   else {
554     AliError(Form("EBignoreNeighbour value %d is out of range, keep previously set value (%d).",
555                   val, fEBignoreNeighbour));
556   }
557 }
558
559 //_____________________________________________________________________________
560 void AliTRDfeeParam::SetRAWversion( Int_t rawver )
561 {
562   //
563   // Set raw data version (major number only)
564   // Maximum available number is preset in fgkMaxRAWversion
565   //
566
567   if( rawver >= 0 && rawver <= fgkMaxRAWversion ) {
568     fRAWversion = rawver;
569   } 
570   else {
571     AliError(Form("Raw version is out of range: %d",rawver));
572   }
573
574 }
575
576 //_____________________________________________________________________________
577 void AliTRDfeeParam::SetXenon()
578 {
579   //
580   // Sets the filter parameters for the Xenon gas mixture
581   //
582
583   fTFnExp = 1;
584   fTFr1   = 1.1563;
585   fTFr2   = 0.1299;
586   fTFc1   = 0.0657;
587   fTFc2   = 0.0000;
588
589 }
590
591 //_____________________________________________________________________________
592 void AliTRDfeeParam::SetArgon()
593 {
594   //
595   // Sets the filter parameters for the Argon gas mixture
596   //
597
598   fTFnExp = 2;
599   fTFr1   = 6.0;
600   fTFr2   = 0.62;
601   fTFc1   = 0.0087;
602   fTFc2   = 0.07;
603
604 }
605
606