]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCCalibCE.h
Altro emulation
[u/mrichter/AliRoot.git] / TPC / AliTPCCalibCE.h
1 #ifndef ALITPCCALIBCE_H
2 #define ALITPCCALIBCE_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 ////////////////////////////////////////////////////////////////////////////////////////
7 //                                                                                    //
8 //             Implementation of the TPC Central Electrode calibration                //
9 //                                                                                    //
10 ////////////////////////////////////////////////////////////////////////////////////////
11
12 #include <TVectorT.h>
13 #include <THnSparse.h>
14
15 #include "AliTPCCalibRawBase.h"
16 class TH1S;
17 #include "TObjArray.h"
18 class TH2S;
19 class TH1F;
20 class TTreeSRedirector;
21 class AliTPCCalPad;
22 class AliTPCROC;
23 class AliTPCCalROC;
24 class AliTPCParam;
25 class AliRawReader;
26 class AliTPCRawStream;
27 class AliTPCRawStreamFast;
28 class TGraph;
29 class TMap;
30 class TCollection;
31
32 struct eventHeaderStruct;
33
34 class AliTPCCalibCE : public AliTPCCalibRawBase {
35   
36 public:
37   AliTPCCalibCE();
38   AliTPCCalibCE(const AliTPCCalibCE &sig);
39   AliTPCCalibCE(const TMap *config);
40   virtual ~AliTPCCalibCE();
41   
42   AliTPCCalibCE& operator = (const  AliTPCCalibCE &source);
43   
44   virtual Int_t Update(const Int_t isector, const Int_t iRow, const Int_t iPad,
45                        const Int_t iTimeBin, const Float_t signal);
46   virtual void ProcessBunch(const Int_t sector, const Int_t row, const Int_t pad,
47                             const Int_t length, const UInt_t startTimeBin, const UShort_t* signal);
48   
49   virtual void Analyse();
50   void AnalyseTrack();
51   
52     //
53   AliTPCCalROC* GetCalRocT0  (Int_t sector, Bool_t force=kFALSE);  // get calibration object - sector
54   AliTPCCalROC* GetCalRocT0Err(Int_t sector, Bool_t force=kFALSE);  // get calibration object - sector
55   AliTPCCalROC* GetCalRocQ   (Int_t sector, Bool_t force=kFALSE);  // get calibration object - sector
56   AliTPCCalROC* GetCalRocRMS(Int_t sector, Bool_t force=kFALSE);  // get calibration object - sector
57   AliTPCCalROC* GetCalRocOutliers(Int_t sector, Bool_t force=kFALSE);  // get calibration object - sector
58   
59   const TObjArray* GetCalPadT0()    const { return &fCalRocArrayT0; }      // get calibration object
60   const TObjArray* GetCalPadT0Err() const { return &fCalRocArrayT0Err; }      // get calibration object
61   const TObjArray* GetCalPadQ()     const { return &fCalRocArrayQ;  }      // get calibration object
62   const TObjArray* GetCalPadRMS()   const { return &fCalRocArrayRMS;}      // get calibration object
63   const TObjArray* GetCalPadOutliers() const { return &fCalRocArrayOutliers;}      // get calibration object
64   
65   TH2S* GetHistoQ  (Int_t sector, Bool_t force=kFALSE);           // get refernce histogram
66   TH2S* GetHistoT0 (Int_t sector, Bool_t force=kFALSE);           // get refernce histogram
67   TH2S* GetHistoRMS(Int_t sector, Bool_t force=kFALSE);           // get refernce histogram
68
69   Float_t GetMeanT0rms() const {return fMeanT0rms;}
70   Float_t GetMeanQrms() const {return fMeanQrms;}
71   Float_t GetMeanRMSrms() const {return fMeanRMSrms;}
72   
73   Int_t   GetPeakDetectionMinus() const {return fPeakDetMinus;}
74   Int_t   GetPeakDetectionPlus()  const {return fPeakDetPlus;}
75   Int_t   GetPeakIntRangeMinus() const {return fPeakIntMinus;}
76   Int_t   GetPeakIntRangePlus()  const {return fPeakIntPlus;}
77   Float_t GetNnoiseThresholdMax() const {return fNoiseThresholdMax;}
78   Float_t GetNnoiseThresholdSum() const {return fNoiseThresholdSum;}
79   
80   TH1S* GetHistoTmean(Int_t sector, Bool_t force=kFALSE);           // get refernce histogram
81   
82     //needed here to merge ClibCE objects
83   TObjArray* GetParamArrayPol1(Int_t sector, Bool_t force=kFALSE);
84   TObjArray* GetParamArrayPol2(Int_t sector, Bool_t force=kFALSE);
85   
86 //    TObjArray*  GetTMeanArrayEvent(){ return &fTMeanArrayEvent; }
87 //    TObjArray*  GetQMeanArrayEvent(){ return &fQMeanArrayEvent; }
88   TVectorF* GetTMeanEvents(Int_t sector, Bool_t force=kFALSE);
89   TVectorF* GetQMeanEvents(Int_t sector, Bool_t force=kFALSE);
90   
91   const TVectorD*   GetEventTimes()  const   { return &fVEventTime;      }
92   const TVectorD*   GetEventIds()    const   { return &fVEventNumber;    }
93   
94   //
95   void  SetRangeRefQ  (Int_t nBins, Float_t xMin, Float_t xMax){ fNbinsQ   = nBins; fXminQ   = xMin; fXmaxQ   = xMax; }   //Set range for Q reference histograms
96   void  SetRangeRefT0 (Int_t nBins, Float_t xMin, Float_t xMax){ fNbinsT0  = nBins; fXminT0  = xMin; fXmaxT0  = xMax; }   //Set range for T0 reference histograms
97   void  SetRangeRefRMS(Int_t nBins, Float_t xMin, Float_t xMax){ fNbinsRMS = nBins; fXminRMS = xMin; fXmaxRMS = xMax; }   //Set range for T0 reference histograms
98   //
99   void  SetRangePeakDetection(Int_t minus, Int_t plus) { fPeakDetMinus=minus; fPeakDetPlus=plus;}
100   void  SetRangePeakIntegral(Int_t minus, Int_t plus) { fPeakIntMinus=minus; fPeakIntPlus=plus;}
101   void  SetNnoiseThresholdMax(Float_t n) {fNoiseThresholdMax=n;}
102   void  SetNnoiseThresholdSum(Float_t n) {fNoiseThresholdSum=n;}
103   //
104   void  SetEventInfo(UInt_t runNumber,UInt_t timestamp, UInt_t eventId){ fRunNumber=runNumber; fTimeStamp=timestamp; fEventId=eventId;}
105   //
106   void  SetPedestalDatabase(AliTPCCalPad * const pedestalTPC, AliTPCCalPad * const padNoiseTPC) {fPedestalTPC = pedestalTPC; fPadNoiseTPC = padNoiseTPC;}
107   void  SetIsZeroSuppressed(Bool_t zs=kTRUE) { fIsZeroSuppressed=zs; }
108   void  SetSecRejectRatio(Float_t ratio) { fSecRejectRatio=ratio; }
109
110   void SetProcessOld(Bool_t process=kTRUE) {fProcessOld=process;}
111   void SetProcessNew(Bool_t process=kTRUE) {fProcessNew=process; if (process&&!fHnDrift) CreateDVhist(); }
112   //Getters
113   Int_t GetNeventsProcessed() const { return fNevents; }
114   
115   Bool_t GetIsZeroSuppressed() const { return fIsZeroSuppressed; }
116   
117   Float_t  GetSecRejectRatio() const { return fSecRejectRatio; }
118
119   const TVectorF *GetTime0Side(Int_t side=0) const {return (side==0)?&fVTime0SideA:&fVTime0SideC;}
120   Float_t GetPeakIntegralMinus() const {return fPeakIntMinus;}
121   Float_t GetPeakIntegralPlus() const {return fPeakIntPlus;}
122   
123   
124   void Merge(AliTPCCalibCE * const ce);
125   virtual Long64_t Merge(TCollection * const list);
126   
127   TGraph *MakeGraphTimeCE(Int_t sector, Int_t xVariable=0, Int_t fitType=0, Int_t fitParameter=0);
128
129   //
130   // New functions using also the laser tracks
131   //
132   Bool_t IsEdgePad(Int_t sector, Int_t row, Int_t pad) const;
133   
134   void FindLocalMaxima(TObjArray * const arrObj, Double_t timestamp, Int_t burst);
135   Int_t FindLaserTrackID(Int_t sector,Int_t row, const Double_t *peakpos,Double_t &mindist, const Double_t *peakposloc, Int_t &itrackMin2);
136   
137   const THnSparseI *GetHnDrift() const {return fHnDrift;}
138   const TObjArray& GetArrHnDrift() const {return fArrHnDrift;}
139   const TVectorD&  GetTimeBursts() const {return fTimeBursts;}
140   const TObjArray  *GetArrFitGraphs() const {return fArrFitGraphs;}
141
142   virtual void DumpToFile(const Char_t *filename, const Char_t *dir="", Bool_t append=kFALSE);
143   
144   static AliTPCCalibCE *ReadFromFile(const Char_t *filename);
145   
146 protected:
147   virtual void EndEvent();
148   virtual void ResetEvent();
149   
150 private:
151     // reference histogram ranges
152   Int_t   fNbinsT0;                 //  Number of bins for T0 reference histogram
153   Float_t fXminT0;                  //  xmin   of T0 reference histogram
154   Float_t fXmaxT0;                  //  xmax   of T0 reference histogram
155   Int_t   fNbinsQ;                  //  Number of bins for T0 reference histogram
156   Float_t fXminQ;                   //  xmin   of T0 reference histogram
157   Float_t fXmaxQ;                   //  xmax   of T0 reference histogram
158   Int_t   fNbinsRMS;                //  Number of bins for T0 reference histogram
159   Float_t fXminRMS;                 //  xmin   of T0 reference histogram
160   Float_t fXmaxRMS;                 //  xmax   of T0 reference histogram
161   Int_t   fPeakDetMinus;               //  Consecutive timebins on rising edge to be regarded as a signal
162   Int_t   fPeakDetPlus;                //  Consecutive timebins on falling edge to be regarded as a signal
163   Int_t   fPeakIntMinus;            //  Peak integral range for COG determination. Bins used before max bin
164   Int_t   fPeakIntPlus;             //  Peak integral range for COG determination. Bins used after max bin
165   Float_t fNoiseThresholdMax;       //  Analysis Treshold for signal finding: Max>fNoiseThresholdMax*PadNoise
166   Float_t fNoiseThresholdSum;       //  Analysis Treshold for signal finding: Sum>fNoiseThresholdSum*PadNoise
167   
168   Bool_t  fIsZeroSuppressed;        //  If data is Zero Suppressed -> Don't subtrakt pedestals!
169   
170   Int_t     fLastSector;            //! Last sector processed
171   
172   Float_t   fSecRejectRatio;        //! Needed percentage of signals in one chamber. Below it will be rejected
173                                       //  This is neede if we do not process a laser event
174   
175   AliTPCParam *fParam;              //! TPC information
176   
177   AliTPCCalPad *fPedestalTPC;       //! Pedestal Information whole TPC
178   AliTPCCalPad *fPadNoiseTPC;       //! Pad noise Information whole TPC
179   AliTPCCalROC *fPedestalROC;       //! Pedestal Information for current ROC
180   AliTPCCalROC *fPadNoiseROC;       //! Pad noise Information for current ROC
181   
182   TObjArray fCalRocArrayT0;         //  Array of AliTPCCalROC class for Time0 calibration
183   TObjArray fCalRocArrayT0Err;      //  Array of AliTPCCalROC class for the error (rms) of Time0 calibration
184   TObjArray fCalRocArrayQ;          //  Array of AliTPCCalROC class for Charge calibration
185   TObjArray fCalRocArrayRMS;        //  Array of AliTPCCalROC class for signal width calibration
186   TObjArray fCalRocArrayOutliers;   //  Array of AliTPCCalROC class for signal outliers
187   
188   TObjArray fHistoQArray;           //  Calibration histograms for Charge distribution
189   TObjArray fHistoT0Array;          //  Calibration histograms for Time0  distribution
190   TObjArray fHistoRMSArray;         //  Calibration histograms for signal width distribution
191   
192   Float_t   fMeanT0rms;             // mean of the rms of all pad T0  fits, used as error estimation of T0 results
193   Float_t   fMeanQrms;              // mean of the rms of all pad Q   fits, used as error estimation of Q results
194   Float_t   fMeanRMSrms;            // mean of the rms of all pad TMS fits, used as error estimation of RMS results
195   
196   TObjArray fHistoTmean;            //! Calibration histograms of the mean CE position for all sectors
197   
198   TObjArray fParamArrayEventPol1;   //  Store mean arrival time parameters for each sector event by event from global plane fit
199   TObjArray fParamArrayEventPol2;   //  Store mean arrival time parameters for each sector event by event from global parabola fit
200   TObjArray fTMeanArrayEvent;       //  Store mean arrival time for each sector event by event
201   TObjArray fQMeanArrayEvent;       //  Store mean arrival Charge for each sector event by event
202   TVectorD  fVEventTime;            //  Timestamps of the events
203   TVectorD  fVEventNumber;          //  Eventnumbers of the events
204   TVectorF  fVTime0SideA;           //  Mean Time0 for side A for all events
205   TVectorF  fVTime0SideC;           //  Mean Time0 for side C for all events
206   Double_t  fEventId;               //! Event Id of the current event
207   UInt_t  fOldRunNumber;          //! Old Run Number
208   
209   TObjArray fPadTimesArrayEvent;    //! Pad Times for the event, before mean Time0 corrections
210   TObjArray fPadQArrayEvent;        //! Charge for the event, only needed for debugging streamer
211   TObjArray fPadRMSArrayEvent;      //! Signal width for the event, only needed for debugging streamer
212   TObjArray fPadPedestalArrayEvent; //! Signal width for the event, only needed for debugging streamer
213   
214   Int_t     fCurrentChannel;        //! current channel processed
215   Int_t     fCurrentSector;         //! current sector processed
216   Int_t     fCurrentRow;            //! current row processed
217   Float_t   fMaxPadSignal;          //! maximum bin of current pad
218   Int_t     fMaxTimeBin;            //! time bin with maximum value
219   Float_t   fPadSignal[1024];       //! signal of current Pad
220   Float_t   fPadPedestal;           //! Pedestal Value of current pad
221   Float_t   fPadNoise;              //! Noise Value of current pad
222   
223   TVectorD  fVTime0Offset;          //!  Time0 Offset for each sector;
224   TVectorD  fVTime0OffsetCounter;   //!  Time0 Offset counter for each sector;
225   TVectorD  fVMeanQ;                //!  Mean Q for each sector;
226   TVectorD  fVMeanQCounter;         //!  Mean Q counter for each sector;
227   
228   Float_t   fCurrentCETimeRef;      //! Time refernce of the current sector
229   
230   // new part of the algorithm
231   Bool_t      fProcessOld;             // Whether to use the old algorithm
232   Bool_t      fProcessNew;             // Whether to use the new algorithm
233   Bool_t      fAnalyseNew;             //! Whether to analyse the new part of the algorithm.
234                                        //In the DA this needs to be switched off, in the Preprocessor on...
235   enum {kHnBinsDV=5};
236   THnSparseI *fHnDrift;                //! Histogram digits for each pad and timebin for several timestamps
237   TObjArray   fArrHnDrift;             // array of sparse histograms for each burst
238   TVectorD    fTimeBursts;             //  time stamps of bursts
239   UInt_t      fBinsLastAna[100];       // number of bin in the THnSparse during the last analysis
240   UShort_t    fPeaks[5];               //! Peak position: 4 laser layers and CE
241   UShort_t    fPeakWidths[5];          //! Peak window widths
242   TObjArray  *fArrFitGraphs;           // Fit resut graphs for each parameter
243   
244   
245   //
246   void   FindPedestal(Float_t part=.6);
247   void   UpdateCETimeRef(); //Get the time reference of the last valid measurement in sector
248   void   FindCESignal(TVectorD &param, Float_t &qSum, const TVectorF maxima);
249   void   FindLocalMaxima(TVectorF &maxima);
250   Bool_t IsPeak(Int_t pos, Int_t tminus, Int_t tplus) const;
251   
252   TH2S* GetHisto(Int_t sector, TObjArray *arr,
253                  Int_t nbinsY, Float_t ymin, Float_t ymax,
254                  const Char_t *type, Bool_t force);
255   TH1S* GetHisto(Int_t sector, TObjArray *arr,
256                  const Char_t *type, Bool_t force);
257   
258   AliTPCCalROC* GetCalRoc(Int_t sector, TObjArray* arr, Bool_t force) const;
259   
260   TVectorF* GetVectSector(Int_t sector, TObjArray *arr, UInt_t size, Bool_t force=kFALSE) const;
261   TVectorF* GetPadTimesEvent(Int_t sector, Bool_t force=kFALSE);
262   
263   TObjArray* GetParamArray(Int_t sector, TObjArray *arr, Bool_t force=kFALSE) const;
264   
265   void ResetPad();
266   void ProcessPad();
267
268   // new part of the algorithm
269   void CreateDVhist();
270   
271   void   FindLaserLayers();
272   Bool_t IsPeakInRange(UShort_t timebin) const;
273
274   TObjArray *SetupMeasured();
275   void ResetMeasured(TObjArray * const arr);
276   
277   void AddCEtoIdeal(TObjArray *arr);
278
279   void CalculateDV(TObjArray * const arrIdeal, TObjArray * const arrMeasured, Int_t burst);
280   Double_t SetBurstHnDrift();
281   //debug
282   TVectorF* GetPadQEvent(Int_t sector, Bool_t force=kFALSE);
283   TVectorF* GetPadRMSEvent(Int_t sector, Bool_t force=kFALSE);
284   TVectorF* GetPadPedestalEvent(Int_t sector, Bool_t force=kFALSE);
285   
286   ClassDef(AliTPCCalibCE,9)  //Implementation of the TPC Central Electrode calibration
287 };
288
289 //Inline functions
290 //_____________________________________________________________________
291 inline Bool_t AliTPCCalibCE::IsPeakInRange(UShort_t timebin) const
292 {
293   //
294   // Check whether timebin is in the range of a laser layer
295   //
296 //   return kTRUE;
297   if (fPeaks[4]<2) return kTRUE; //not determined yet
298   for (Int_t i=0; i<5; ++i){
299     if (TMath::Abs((Short_t)timebin-(Short_t)fPeaks[i])<(Short_t)fPeakWidths[i]) return kTRUE;
300   }
301   return kFALSE;
302 }
303
304 #endif