]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDmcmSim.h
5cddbed5bca918a571ec406f8682e64ed91770ca
[u/mrichter/AliRoot.git] / TRD / AliTRDmcmSim.h
1 #ifndef ALITRDMCMSIMNEW_H
2 #define ALITRDMCMSIMNEW_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 /* $Id$ */
7
8 ///////////////////////////////////////////////////////
9 //                                                   //
10 //  Multi Chip Module Simulation Class               //
11 //                                                   //
12 ///////////////////////////////////////////////////////
13
14 #include <TObject.h>
15 #include <TClonesArray.h>
16
17 class AliRunLoader;
18 class AliTRDfeeParam;
19 class AliTRDSimParam;
20 class AliTRDtrapConfig;
21 class AliTRDcalibDB;
22 class AliTRDgeometry;
23 class AliTRDpadPlane;
24 class AliTRDarrayADC;
25
26 class AliTRDmcmSim : public TObject {
27  public:
28                     AliTRDmcmSim();
29   virtual          ~AliTRDmcmSim();
30
31           void      Init( Int_t cha, Int_t rob, Int_t mcm, Bool_t newEvent = kFALSE );   // Initialize MCM by the position parameters
32           void      Reset();                                   // clears filter registers and internal data
33
34           Bool_t    LoadMCM(AliRunLoader *runloader, Int_t det, Int_t rob, Int_t mcm);
35           void      NoiseTest(Int_t nsamples, Int_t mean, Int_t sigma, Int_t inputGain = 1, Int_t inputTail = 2);
36
37           void      SetData(Int_t iadc, Int_t *adc);           // Set ADC data with array 
38           void      SetData(Int_t iadc, Int_t it, Int_t adc ); // Set ADC data
39           void      SetData(AliTRDarrayADC *adcArray);         // Set ADC data from adcArray
40           void      SetDataPedestal(Int_t iadc );              // Fill ADC data with pedestal values
41
42           Int_t     GetDetector() const  { return fDetector;  };     // Returns Chamber ID (0-539)
43           Int_t     GetRobPos() const { return fRobPos; };     // Returns ROB position (0-7)
44           Int_t     GetMcmPos() const { return fMcmPos; };     // Returns MCM position (0-17) (16,17 are mergers)
45           Int_t     GetRow() const    { return fRow;    };     // Returns Row number on chamber where the MCM is sitting
46           Int_t     GetCol( Int_t iadc );                      // Get corresponding column (0-143) from for ADC channel iadc = [0:20]
47           // for the ADC/Col mapping, see: http://wiki.kip.uni-heidelberg.de/ti/TRD/index.php/Image:ROB_MCM_numbering.pdf
48
49           void WriteData(AliTRDarrayADC *digits);
50
51           Int_t     ProduceRawStream( UInt_t *buf, Int_t bufsize, UInt_t iEv = 0 ); // Produce raw data stream - Read data format
52           Int_t     ProduceTrackletStream( UInt_t *buf, Int_t bufsize ); // produce the tracklet stream for this MCM
53                 
54           // different stages of processing in the TRAP
55           void      Filter();                                  // Apply digital filters for existing data (according to configuration)
56           void      ZSMapping();                               // Do ZS mapping for existing data
57           void      Tracklet();                                // Run tracklet preprocessor and perform tracklet fit
58
59           // apply individual filters to all channels and timebins
60           void      FilterPedestal();                   // Apply pedestal filter
61           void      FilterGain();                       // Apply gain filter
62           void      FilterTail();                       // Apply tail filter
63
64           // filter initialization (resets internal registers)
65           void      FilterPedestalInit();
66           void      FilterGainInit();
67           void      FilterTailInit(Int_t baseline); //??? automatic baseline??
68
69           // feed single sample to individual filter
70           // this changes the internal registers
71           // all filters operate on 12-bit values!
72           UShort_t  FilterPedestalNextSample(Int_t adc, Int_t timebin, UShort_t value);
73           UShort_t  FilterGainNextSample(Int_t adc, UShort_t value);
74           UShort_t  FilterTailNextSample(Int_t adc, UShort_t value);
75
76           // tracklet calculation
77           void      AddHitToFitreg(Int_t adc, UShort_t timebin, UShort_t qtot, Short_t ypos, Int_t label);
78           void      CalcFitreg();
79           void      TrackletSelection();
80           void      FitTracklet();
81
82           TClonesArray* GetTrackletArray() { return fTrackletArray; }
83
84           // data display
85           void      Print(Option_t* option="") const;   // print stored data to stdout
86           void      Draw(Option_t *option ="");         // draw data (ADC data, hits and tracklets)
87           void      DumpData( char *f, char *target );  // Dump data stored (only for debugging)
88
89  protected:
90           Bool_t    CheckInitialized();                 // Check whether the class is initialized
91           
92           Bool_t    fInitialized;                       // Status whether the class is initialized or not
93           Int_t     fMaxTracklets;                      // maximum number of tracklet-words submitted per mcm **new** //???
94           Int_t     fDetector;                             // Chamber ID
95           Int_t     fRobPos;                            // ROB Position on chamber 
96           Int_t     fMcmPos;                            // MCM Position on chamber 
97           Int_t     fRow;                               // Pad row number (0-11 or 0-15) of the MCM on chamber
98           Int_t     fNADC;                              // Number of ADC (usually 21) //??? static const
99           Int_t     fNTimeBin;                          // Number of Timebins (variable)  //??? why stored here? taken from TRAPconfig
100           Int_t   **fADCR;                              // Array with MCM ADC values (Raw, 12 bit)
101           Int_t   **fADCF;                              // Array with MCM ADC values (Filtered, 12 bit)
102           UInt_t   *fMCMT;                              // tracklet word for one mcm/trap-chip **new** //??? needed?
103           TClonesArray *fTrackletArray;                 // Array of AliTRDtrackletMCM which contains MC information in addition to the tracklet word
104           Int_t   **fZSM;                               // Zero suppression map
105           Int_t    *fZSM1Dim;                           // Zero suppression map (1 dimensional projection)
106
107           static const Int_t fgkAddDigits = 2;          // additional digits used for internal representation
108                                                         // all internal data as after data control block (i.e. 12 bit), s. TRAP manual
109           static const Int_t fgkNCPU = 4;               // Number of CPUs in the TRAP
110           Int_t     fFitPtr[fgkNCPU];                   // pointer to the tracklet to be calculated by CPU i
111           static const Int_t fgkNHitsMC = 100;          // maximum number of hits for which MC information is kept
112
113           // Parameter classes
114           AliTRDfeeParam    *fFeeParam;                 // FEE parameters
115           AliTRDtrapConfig  *fTrapConfig;               // TRAP config
116           AliTRDSimParam    *fSimParam;                 // Simulation parameters
117           AliTRDcalibDB     *fCal;                      // Calibration interface
118           AliTRDgeometry    *fGeo;                      // Geometry
119
120           // internal filter registers
121           UInt_t*   fPedAcc;                            // Accumulator for pedestal filter
122           UInt_t*   fGainCounterA;                      // Counter for values above FGTA in the gain filter
123           UInt_t*   fGainCounterB;                      // Counter for values above FGTB in the gain filter
124           UShort_t* fTailAmplLong;                      // Amplitude of the long component in the tail filter
125           UShort_t* fTailAmplShort;                     // Amplitude of the short component in the tail filter
126
127           // hit detection
128           // individual hits can be stored as MC info
129           struct Hit_t {
130             Int_t channel;
131             Int_t timebin;
132             Int_t qtot;
133             Int_t ypos;
134             Int_t label;
135           } fHits[fgkNHitsMC];                          // Array of detected hits (only available in MC)
136           Int_t fNHits;                                 // Number of detected hits
137
138           // tracklet calculation
139           struct FitReg_t {
140             Int_t   Nhits;
141             UInt_t Q0;
142             UInt_t Q1;
143             UInt_t SumX;
144             Int_t SumY;
145             UInt_t SumX2;
146             UInt_t SumY2;
147             Int_t SumXY;
148           } *fFitReg;                                   // pointer to the 18 fit registers 
149
150           //??? cleaning up
151           void Sort2(UShort_t  idx1i, UShort_t  idx2i, UShort_t  val1i, UShort_t  val2i, 
152                      UShort_t *idx1o, UShort_t *idx2o, UShort_t *val1o, UShort_t *val2o);
153           void Sort3(UShort_t  idx1i, UShort_t  idx2i, UShort_t  idx3i, 
154                      UShort_t  val1i, UShort_t  val2i, UShort_t  val3i, 
155                      UShort_t *idx1o, UShort_t *idx2o, UShort_t *idx3o, 
156                      UShort_t *val1o, UShort_t *val2o, UShort_t *val3o);
157           void Sort6To4(UShort_t  idx1i, UShort_t  idx2i, UShort_t  idx3i, UShort_t  idx4i, UShort_t  idx5i, UShort_t  idx6i, 
158                         UShort_t  val1i, UShort_t  val2i, UShort_t  val3i, UShort_t  val4i, UShort_t  val5i, UShort_t  val6i, 
159                         UShort_t *idx1o, UShort_t *idx2o, UShort_t *idx3o, UShort_t *idx4o, 
160                         UShort_t *val1o, UShort_t *val2o, UShort_t *val3o, UShort_t *val4o);
161           void Sort6To2Worst(UShort_t  idx1i, UShort_t  idx2i, UShort_t  idx3i, UShort_t  idx4i, UShort_t  idx5i, UShort_t  idx6i, 
162                              UShort_t  val1i, UShort_t  val2i, UShort_t  val3i, UShort_t  val4i, UShort_t  val5i, UShort_t  val6i, 
163                              UShort_t *idx5o, UShort_t *idx6o);
164
165           UInt_t AddUintClipping(UInt_t a, UInt_t b, UInt_t nbits);  // Add a and b (unsigned) with clipping to the maximum value representable by nbits
166
167  private:
168           AliTRDmcmSim(const AliTRDmcmSim &m);             // not implemented
169           AliTRDmcmSim &operator=(const AliTRDmcmSim &m);  // not implemented
170
171
172   ClassDef(AliTRDmcmSim,4)
173 };
174
175 #endif