]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0CalibTimeEq.cxx
Changes in QA to be able to process separately different triggers (Ruben)
[u/mrichter/AliRoot.git] / T0 / AliT0CalibTimeEq.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 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 // class for T0 calibration                       TM-AC-AM_6-02-2006  
21 // equalize time shift for each time CFD channel
22 //                                                                           //
23 ///////////////////////////////////////////////////////////////////////////////
24
25 #include "AliT0CalibTimeEq.h"
26 #include "AliLog.h"
27 #include <TFile.h>
28 #include <TMath.h>
29 #include <TF1.h>
30 #include <TSpectrum.h>
31 #include <TProfile.h>
32 #include <iostream>
33
34 ClassImp(AliT0CalibTimeEq)
35
36 //________________________________________________________________
37   AliT0CalibTimeEq::AliT0CalibTimeEq():TNamed(),
38                                        fMeanVertex(0),        
39                                        fRmsVertex(0)      
40 {
41   //
42
43 }
44
45 //________________________________________________________________
46 AliT0CalibTimeEq::AliT0CalibTimeEq(const char* name):TNamed(),
47                                        fMeanVertex(0),        
48                                        fRmsVertex(0)      
49 {
50   //constructor
51
52   TString namst = "Calib_";
53   namst += name;
54   SetName(namst.Data());
55   SetTitle(namst.Data());
56 }
57
58 //________________________________________________________________
59 AliT0CalibTimeEq::AliT0CalibTimeEq(const AliT0CalibTimeEq& calibda):TNamed(calibda),            
60                                        fMeanVertex(0),        
61                                        fRmsVertex(0)      
62 {
63 // copy constructor
64   SetName(calibda.GetName());
65   SetTitle(calibda.GetName());
66
67
68 }
69
70 //________________________________________________________________
71 AliT0CalibTimeEq &AliT0CalibTimeEq::operator =(const AliT0CalibTimeEq& calibda)
72 {
73 // assignment operator
74   SetName(calibda.GetName());
75   SetTitle(calibda.GetName());
76  
77   return *this;
78 }
79
80 //________________________________________________________________
81 AliT0CalibTimeEq::~AliT0CalibTimeEq()
82 {
83   //
84   // destrictor
85 }
86 //________________________________________________________________
87 void AliT0CalibTimeEq::Reset()
88 {
89   //reset values
90
91   memset(fCFDvalue,0,120*sizeof(Float_t));
92   memset(fTimeEq,1,24*sizeof(Float_t));
93 }
94
95
96 //________________________________________________________________
97 void  AliT0CalibTimeEq::Print(Option_t*) const
98 {
99   // print time values
100
101   printf("\n    ----    PM Arrays       ----\n\n");
102   printf(" Time delay CFD \n");
103   for (Int_t i=0; i<24; i++) printf(" CFD  %f ",fTimeEq[i]);
104   printf("\n Mean Vertex %f \n", fMeanVertex);
105
106
107
108 //________________________________________________________________
109 Bool_t AliT0CalibTimeEq::ComputeOnlineParams(const char* filePhys)
110 {
111   // compute online equalized time
112   Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
113   meandiff = sigmadiff =  meanver = meancfdtime = sigmacfdtime =0;
114   Double_t rmsver=0;
115   Int_t nent=0;
116   Bool_t ok=false;
117   gFile = TFile::Open(filePhys);
118   if(!gFile) {
119     AliError("No input PHYS data found ");
120   }
121   else
122     {
123       ok=true;
124       for (Int_t i=0; i<24; i++)
125         {
126           meandiff = sigmadiff =  meanver = meancfdtime = sigmacfdtime =0;
127           TH1F *cfd = (TH1F*) gFile->Get(Form("CFD1minCFD%d",i+1));
128           TH1F *cfdtime = (TH1F*) gFile->Get(Form("CFD%d",i+1));
129           if(!cfd) AliWarning(Form("no Diff histograms collected by PHYS DA for channel %i", i));
130           if(!cfdtime) AliWarning(Form("no CFD histograms collected by PHYS DA for channel %i", i));
131           if(cfd) {
132             nent = Int_t(cfd->GetEntries());
133             if(nent>500)  { 
134               if(cfd->GetRMS()>1.5 )
135                 GetMeanAndSigma(cfd, meandiff, sigmadiff);
136               if(cfd->GetRMS()<=1.5) 
137                 {
138                   meandiff = cfd->GetMean();
139                   sigmadiff=cfd->GetRMS();
140                 }
141                 Int_t   maxBin = cfd->GetMaximumBin(); 
142                 Double_t  meanEstimate = cfd->GetBinCenter( maxBin); 
143                 if(TMath::Abs(meanEstimate - meandiff) > 20 ) meandiff = meanEstimate; 
144             }
145             else 
146               {
147                 ok=false;
148                 AliWarning(Form(" Not  enouph data in PMT %i- PMT1:  %i ", i, nent));
149               }
150             if(!cfd) AliWarning(Form("no CFD histograms collected by PHYS DA for channel %i", i));
151           }
152           //      printf(" i = %d buf1 = %s\n", i, buf1);
153           if(cfdtime) {
154             nent = Int_t(cfdtime->GetEntries());
155             if(nent > 500 )  { //!!!!!!!!!!
156               if(cfdtime->GetRMS()>1.5 )
157                 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
158               if(cfdtime->GetRMS()<=1.5) 
159                 {
160                   meancfdtime = cfdtime->GetMean();
161                   sigmacfdtime = cfdtime->GetRMS();
162                 }
163                 Int_t   maxBin = cfdtime->GetMaximumBin(); 
164                 Double_t  meanEstimate = cfdtime->GetBinCenter( maxBin); 
165                 if(TMath::Abs(meanEstimate - meancfdtime) > 20 ) meancfdtime = meanEstimate; 
166             }
167           }
168           else 
169             {
170               ok=false;
171               AliWarning(Form(" Not  enouph data in PMT in CFD peak %i - %i ", i, nent));
172             }
173           SetTimeEq(i,meandiff);
174           SetTimeEqRms(i,sigmadiff);
175           SetCFDvalue(i,0,meancfdtime);
176           if (cfd) delete cfd;
177           if (cfdtime) delete cfdtime;
178
179         }
180       TH1F *ver = (TH1F*) gFile->Get("hVertex");
181       if(!ver) AliWarning("no T0 histogram collected by PHYS DA ");
182       if(ver) {
183         meanver = ver->GetMean();
184         rmsver = ver->GetRMS();
185       }
186       SetMeanVertex(meanver);
187       SetRmsVertex(rmsver);
188       
189       gFile->Close();
190       delete gFile;
191
192     }
193     return ok; 
194 }
195
196 //________________________________________________________________
197 Bool_t AliT0CalibTimeEq::ComputeOfflineParams(const char* filePhys, Float_t *timecdb, Float_t *cfdvalue, Int_t badpmt)
198 {
199   // compute online equalized time
200   Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
201   meandiff = sigmadiff =  meanver = meancfdtime = sigmacfdtime =0;
202   Int_t nent=0;
203   Bool_t ok=false;
204   TH1F *cfddiff = NULL; 
205   TH1F *cfdtime = NULL;
206
207   gFile = TFile::Open(filePhys);
208   if(!gFile) {
209     AliError("No input PHYS data found ");
210     return ok;
211   }
212   else
213     {
214       meandiff = sigmadiff =  meanver = meancfdtime = sigmacfdtime =0;
215       ok=true;
216       TDirectory *dr = (TDirectory*) gFile->Get("T0Calib");
217       if (!dr ) { AliError("No input T0calib found "); 
218         return ok;
219       }
220       TObjArray * TzeroObj = (TObjArray*) dr->Get("T0Calib");
221
222       for (Int_t i=0; i<24; i++)
223         {
224           if (i != badpmt) {
225             if(TzeroObj) {
226               cfddiff = (TH1F*)TzeroObj->FindObject(Form("CFD1minCFD%d",i+1));
227               cfdtime = (TH1F*)TzeroObj->FindObject(Form("CFD1minCFD%d",i+1));
228             }
229             else
230               {
231                 cfddiff = (TH1F*)dr->Get(Form("CFD1minCFD%d",i+1));
232                 cfdtime = (TH1F*)dr->Get(Form("CFD1minCFD%d",i+1));
233               }
234             if(!cfddiff) AliWarning(Form("no Diff histograms collected by pass0 for channel %i", i));
235             if(!cfdtime) AliWarning(Form("no CFD histograms collected by pass0 %i", i));
236           if(cfddiff) {
237             nent = Int_t(cfddiff->GetEntries());
238             if(nent>500 )  { //!!!!!
239               if(cfddiff->GetRMS()>1.5 )
240                 GetMeanAndSigma(cfddiff, meandiff, sigmadiff);
241               if(cfddiff->GetRMS()<=1.5) 
242                 {
243                   meandiff = cfddiff->GetMean();
244                   sigmadiff = cfddiff->GetRMS();
245                 }
246                 Int_t   maxBin = cfddiff->GetMaximumBin(); 
247                 Double_t  meanEstimate = cfddiff->GetBinCenter( maxBin); 
248                 if(TMath::Abs(meanEstimate - meandiff) > 20 ) meandiff = meanEstimate; 
249               
250             }
251             else 
252               {
253                 ok=false;
254                 AliWarning(Form(" Not  enouph data in PMT %i- PMT1:  %i ", i, nent));
255               }
256           }         
257           
258           if(cfdtime) {
259             nent = Int_t(cfdtime->GetEntries());
260             if(nent>500 )  { //!!!!!
261               if(cfdtime->GetRMS()>1.5 )
262                 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
263               if(cfdtime->GetRMS()<=1.5) 
264                 {
265                   meancfdtime = cfdtime->GetMean();
266                   sigmacfdtime=cfdtime->GetRMS();
267                 }
268                 Int_t   maxBin = cfdtime->GetMaximumBin(); 
269                 Double_t  meanEstimate = cfdtime->GetBinCenter( maxBin); 
270                 if(TMath::Abs(meanEstimate - meancfdtime) > 20 ) meancfdtime = meanEstimate; 
271             }
272             else 
273               {
274                 ok=false;
275                 AliWarning(Form(" Not  enouph data in PMT in CFD peak %i - %i ", i, nent));
276               }
277           }
278           
279           SetTimeEq(i,timecdb[i] + meandiff);
280           SetTimeEqRms(i,sigmadiff);
281           SetCFDvalue(i,0,cfdvalue[i] );
282           if (cfddiff) cfddiff->Reset();
283           if (cfdtime) cfdtime->Reset();
284           } //bad pmt
285         }
286       
287       gFile->Close();
288       delete gFile;
289
290     }
291     return ok; 
292    }
293
294 //________________________________________________________________________
295 void AliT0CalibTimeEq::GetMeanAndSigma(TH1F* hist,  Float_t &mean, Float_t &sigma) {
296   
297   const double window = 2.;  //fit window 
298   
299   double meanEstimate, sigmaEstimate; 
300   int maxBin;
301   maxBin        =  hist->GetMaximumBin(); //position of maximum
302   meanEstimate  =  hist->GetBinCenter( maxBin); // mean of gaussian sitting in maximum
303   sigmaEstimate = hist->GetRMS();
304   TF1* fit= new TF1("fit","gaus", meanEstimate - window*sigmaEstimate, meanEstimate + window*sigmaEstimate);
305   fit->SetParameters(hist->GetBinContent(maxBin), meanEstimate, sigmaEstimate);
306   hist->Fit("fit","RQ","Q");
307
308   mean  = (Float_t) fit->GetParameter(1);
309   sigma = (Float_t) fit->GetParameter(2);
310
311   delete fit;
312 }
313
314