]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDmcmSim.h
Few updates (Jochen) and inclusion of on-line PID Simulation (Uwe)
[u/mrichter/AliRoot.git] / TRD / AliTRDmcmSim.h
1 #ifndef ALITRDMCMSIM_H
2 #define ALITRDMCMSIM_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 <iostream>
15
16 class TObject;
17 class TClonesArray;
18 class TH2F;
19
20 class AliRunLoader;
21 class AliTRDfeeParam;
22 class AliTRDtrapConfig;
23 class AliTRDarrayADC;
24 class AliTRDarrayDictionary;
25 class AliTRDdigitsManager;
26
27 class AliTRDmcmSim : public TObject {
28  public:
29                     AliTRDmcmSim();
30   virtual          ~AliTRDmcmSim();
31
32           void      Init(Int_t det, Int_t rob, Int_t mcm, Bool_t newEvent = kFALSE);   
33           // Initialize MCM by the position parameters
34
35           void      Reset();                                                             
36           // clears filter registers and internal data
37
38           Bool_t    LoadMCM(AliRunLoader* const runloader, Int_t det, Int_t rob, Int_t mcm);
39
40           void      NoiseTest(Int_t nsamples, Int_t mean, Int_t sigma, Int_t inputGain = 1, Int_t inputTail = 2);
41
42           Int_t     GetDataRaw(Int_t iadc, Int_t timebin)      const { return (fADCR[iadc][timebin] >> 2); } 
43           // Get unfiltered ADC data 
44           Int_t     GetDataFiltered(Int_t iadc, Int_t timebin) const { return (fADCF[iadc][timebin] >> 2); } 
45           // Get filtered ADC data
46
47           void      SetData(Int_t iadc, Int_t *adc);           // Set ADC data with array 
48           void      SetData(Int_t iadc, Int_t it, Int_t adc); // Set ADC data
49           void      SetData(AliTRDarrayADC *adcArray, 
50                             AliTRDdigitsManager *digitsManager = 0x0);         // Set ADC data from adcArray
51           void      SetDataByPad(AliTRDarrayADC *adcArray, 
52                                  AliTRDdigitsManager *digitsManager = 0x0);    // Set ADC data from adcArray
53           void      SetDataPedestal(Int_t iadc);              // Fill ADC data with pedestal values
54
55   static  Bool_t    GetApplyCut() { return fgApplyCut; }
56   static  void      SetApplyCut(Bool_t applyCut) { fgApplyCut = applyCut; }
57
58   static  Int_t     GetAddBaseline() { return fgAddBaseline; }                   
59   static  void      SetAddBaseline(Int_t baseline) { fgAddBaseline = baseline; } 
60   // Additional baseline which is added for the processing 
61   // in the TRAP and removed when writing back the data. 
62   // This is needed to run with TRAP parameters set for a 
63   // different baseline but it will not change the baseline 
64   // of the output. 
65
66           Int_t     GetDetector() const  { return fDetector;  };     // Returns Chamber ID (0-539)
67           Int_t     GetRobPos() const { return fRobPos; };           // Returns ROB position (0-7)
68           Int_t     GetMcmPos() const { return fMcmPos; };           // Returns MCM position (0-17) (16,17 are mergers)
69           Int_t     GetRow() const    { return fRow;    };           // Returns Row number on chamber where the MCM is sitting
70           Int_t     GetCol( Int_t iadc );                            // Get corresponding column (0-143) from for ADC channel iadc = [0:20]
71           // for the ADC/Col mapping, see: http://wiki.kip.uni-heidelberg.de/ti/TRD/index.php/Image:ROB_MCM_numbering.pdf
72
73           void      WriteData(AliTRDarrayADC *digits);
74           Bool_t    StoreTracklets();                          // Stores tracklets via runloader
75
76           Int_t     ProduceRawStream( UInt_t *buf, Int_t bufsize, UInt_t iEv = 0 ) const; // Produce raw data stream - Real data format
77           Int_t     ProduceTrackletStream( UInt_t *buf, Int_t bufsize ); // produce the tracklet stream for this MCM
78                 
79           // different stages of processing in the TRAP
80           void      Filter();                                  // Apply digital filters for existing data (according to configuration)
81           void      ZSMapping();                               // Do ZS mapping for existing data
82           void      Tracklet();                                // Run tracklet preprocessor and perform tracklet fit
83
84           // apply individual filters to all channels and timebins
85           void      FilterPedestal();                   // Apply pedestal filter
86           void      FilterGain();                       // Apply gain filter
87           void      FilterTail();                       // Apply tail filter
88
89           // filter initialization (resets internal registers)
90           void      FilterPedestalInit(Int_t baseline = 10);
91           void      FilterGainInit();
92           void      FilterTailInit(Int_t baseline = -1); 
93
94           // feed single sample to individual filter
95           // this changes the internal registers
96           // all filters operate on (10+2)-bit values!
97           UShort_t  FilterPedestalNextSample(Int_t adc, Int_t timebin, UShort_t value);
98           UShort_t  FilterGainNextSample(Int_t adc, UShort_t value);
99           UShort_t  FilterTailNextSample(Int_t adc, UShort_t value);
100
101           // tracklet calculation
102           void      AddHitToFitreg(Int_t adc, UShort_t timebin, UShort_t qtot, Short_t ypos, Int_t label);
103           void      CalcFitreg();
104           void      TrackletSelection();
105           void      FitTracklet();
106
107           Int_t         GetNHits() const { return fNHits; }
108           Bool_t        GetHit(Int_t index, Int_t &channel, Int_t &timebin, Int_t &qtot, Int_t &ypos, Float_t &y, Int_t &label) const;
109           TClonesArray* GetTrackletArray() const { return fTrackletArray; }
110
111           // data display
112           void      Print(Option_t* const option="") const;   // print stored data to stdout
113           void      Draw(Option_t* const option ="");         // draw data (ADC data, hits and tracklets)
114
115   friend  std::ostream& operator<<(std::ostream &os, const AliTRDmcmSim &mcm); // data output using ostream (e.g. cout << mcm;)
116   static  ostream&  Cfdat(ostream &os);                       // manipulator to activate cfdat output
117   static  ostream&  Raw  (ostream &os);                       // manipulator to activate raw output
118   static  ostream&  Text (ostream &os);                       // manipulator to activate text output
119
120           // PID
121           Int_t GetPID(Int_t q0, Int_t q1);
122           void PrintPidLutHuman();
123           void PrintPidLutDatx(ostream& os) const;
124           void SetPIDLutScaleDMEM();
125           void SetPIDLut(TH2F *lut);
126           void SetPIDLut(Int_t *lut, Int_t nbinsq0, Int_t nbinsq1);
127
128           // I/O
129           void PrintFitRegXml(ostream& os) const;
130           void PrintTrackletsXml(ostream& os) const;
131           void PrintAdcDatHuman(ostream& os) const;
132           void PrintAdcDatXml(ostream& os) const;
133           void PrintAdcDatDatx(ostream& os, Bool_t broadcast=kFALSE) const;
134
135  protected:
136           Bool_t    CheckInitialized() const;           // Check whether the class is initialized
137           
138           void      SetNTimebins(Int_t ntimebins);      // allocate data arrays corr. to the no. of timebins
139
140  static const Int_t fgkFormatIndex;                     // index for format settings in stream
141
142  static const Int_t fgkNADC;                            // Number of ADC 
143  static const Int_t fgkMaxTracklets = 4;                // maximum number of tracklet-words submitted per MCM (one per CPU)
144  static const Int_t fgkAddDigits = 2;                   // additional digits used for internal representation of ADC data
145                                                         // all internal data as after data control block (i.e. 12 bit), s. TRAP manual
146  static const Int_t fgkNCPU = 4;                        // Number of CPUs in the TRAP
147  static const Int_t fgkNHitsMC = 100;                   // maximum number of hits for which MC information is kept
148
149  static const UShort_t fgkFPshifts[4];                  // shifts for pedestal filter
150
151
152           Bool_t    fInitialized;                       // memory is allocated if initialized
153           Int_t     fDetector;                          // Chamber ID
154           Int_t     fRobPos;                            // ROB Position on chamber 
155           Int_t     fMcmPos;                            // MCM Position on chamber 
156           Int_t     fRow;                               // Pad row number (0-11 or 0-15) of the MCM on chamber
157           Int_t     fNTimeBin;                          // Number of timebins currently allocated
158           Int_t   **fADCR;                              // Array with MCM ADC values (Raw, 12 bit)
159           Int_t   **fADCF;                              // Array with MCM ADC values (Filtered, 12 bit)
160           UInt_t   *fMCMT;                              // tracklet word for one mcm/trap-chip 
161           TClonesArray *fTrackletArray;                 // Array of AliTRDtrackletMCM which contains MC information in addition to the tracklet word
162           Int_t    *fZSMap;                             // Zero suppression map (1 dimensional projection)
163
164           Int_t     fFitPtr[fgkNCPU];                   // pointer to the tracklet to be calculated by CPU i
165
166           // Parameter classes
167           AliTRDfeeParam    *fFeeParam;                 // FEE parameters
168           AliTRDtrapConfig  *fTrapConfig;               // TRAP config
169
170           AliTRDdigitsManager *fDigitsManager;          // pointer to digits manager used for MC label calculation
171           AliTRDarrayDictionary* fDict[3];              // pointers to label dictionaries
172
173
174           // internal filter registers
175           UInt_t*   fPedAcc;                            // Accumulator for pedestal filter
176           UInt_t*   fGainCounterA;                      // Counter for values above FGTA in the gain filter
177           UInt_t*   fGainCounterB;                      // Counter for values above FGTB in the gain filter
178           UShort_t* fTailAmplLong;                      // Amplitude of the long component in the tail filter
179           UShort_t* fTailAmplShort;                     // Amplitude of the short component in the tail filter
180
181           // hit detection
182           // individual hits can be stored as MC info
183           struct Hit_t {                                // Array of detected hits (only available in MC)
184             Int_t fChannel;                             // ADC channel of the hit
185             Int_t fTimebin;                             // timebin of the hit
186             Int_t fQtot;                                // total charge of the hit
187             Int_t fYpos;                                // calculated y-position
188             Int_t fLabel;                               // label (only in MC)
189           } fHits[fgkNHitsMC];
190           Int_t fNHits;                                 // Number of detected hits
191
192           // tracklet calculation
193           struct FitReg_t {                             // pointer to the 18 fit registers 
194             Int_t  fNhits;                              // number of hits
195             UInt_t fQ0;                                 // charge accumulated in first window
196             UInt_t fQ1;                                 // charge accumulated in second window
197             UInt_t fSumX;                               // sum x
198             Int_t  fSumY;                               // sum y 
199             UInt_t fSumX2;                              // sum x**2
200             UInt_t fSumY2;                              // sum y**2
201             Int_t  fSumXY;                              // sum x*y
202           } *fFitReg;
203
204           // Sort functions as in TRAP
205           void Sort2(UShort_t  idx1i, UShort_t  idx2i, UShort_t  val1i, UShort_t  val2i, 
206                      UShort_t *idx1o, UShort_t *idx2o, UShort_t *val1o, UShort_t *val2o) const;
207           void Sort3(UShort_t  idx1i, UShort_t  idx2i, UShort_t  idx3i, 
208                      UShort_t  val1i, UShort_t  val2i, UShort_t  val3i, 
209                      UShort_t *idx1o, UShort_t *idx2o, UShort_t *idx3o, 
210                      UShort_t *val1o, UShort_t *val2o, UShort_t *val3o);
211           void Sort6To4(UShort_t  idx1i, UShort_t  idx2i, UShort_t  idx3i, UShort_t  idx4i, UShort_t  idx5i, UShort_t  idx6i, 
212                         UShort_t  val1i, UShort_t  val2i, UShort_t  val3i, UShort_t  val4i, UShort_t  val5i, UShort_t  val6i, 
213                         UShort_t *idx1o, UShort_t *idx2o, UShort_t *idx3o, UShort_t *idx4o, 
214                         UShort_t *val1o, UShort_t *val2o, UShort_t *val3o, UShort_t *val4o);
215           void Sort6To2Worst(UShort_t  idx1i, UShort_t  idx2i, UShort_t  idx3i, UShort_t  idx4i, UShort_t  idx5i, UShort_t  idx6i, 
216                              UShort_t  val1i, UShort_t  val2i, UShort_t  val3i, UShort_t  val4i, UShort_t  val5i, UShort_t  val6i, 
217                              UShort_t *idx5o, UShort_t *idx6o);
218
219           UInt_t AddUintClipping(UInt_t a, UInt_t b, UInt_t nbits) const;  
220           // Add a and b (unsigned) with clipping to the maximum value representable by nbits
221
222  private:
223           AliTRDmcmSim(const AliTRDmcmSim &m);             // not implemented
224           AliTRDmcmSim &operator=(const AliTRDmcmSim &m);  // not implemented
225
226   static Bool_t fgApplyCut;               // apply cut on deflection length
227
228   static Int_t fgAddBaseline;             // add baseline to the ADC values 
229
230   ClassDef(AliTRDmcmSim,6)
231 };
232
233 std::ostream& operator<<(std::ostream& os, const AliTRDmcmSim& mcm);
234
235 #endif