]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0CalibTimeEq.cxx
Fixing unused parameter warning
[u/mrichter/AliRoot.git] / T0 / AliT0CalibTimeEq.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 // class for T0 calibration                       TM-AC-AM_6-02-2006  
22 // equalize time shift for each time CFD channel
23 //                                                                           //
24 ///////////////////////////////////////////////////////////////////////////////
25
26 #include "AliT0CalibTimeEq.h"
27 #include "AliLog.h"
28 #include <TFile.h>
29 #include <TMath.h>
30 #include <TF1.h>
31 #include <TSpectrum.h>
32 #include <TProfile.h>
33 #include <iostream>
34
35 ClassImp(AliT0CalibTimeEq)
36
37 //________________________________________________________________
38   AliT0CalibTimeEq::AliT0CalibTimeEq():TNamed(),
39                                        fMeanVertex(0),        
40                                        fRmsVertex(0)      
41 {
42   //
43
44 }
45
46 //________________________________________________________________
47 AliT0CalibTimeEq::AliT0CalibTimeEq(const char* name):TNamed(),
48                                        fMeanVertex(0),        
49                                        fRmsVertex(0)      
50 {
51   //constructor
52
53   TString namst = "Calib_";
54   namst += name;
55   SetName(namst.Data());
56   SetTitle(namst.Data());
57 }
58
59 //________________________________________________________________
60 AliT0CalibTimeEq::AliT0CalibTimeEq(const AliT0CalibTimeEq& calibda):TNamed(calibda),            
61                                        fMeanVertex(0),        
62                                        fRmsVertex(0)      
63 {
64 // copy constructor
65   SetName(calibda.GetName());
66   SetTitle(calibda.GetName());
67
68
69 }
70
71 //________________________________________________________________
72 AliT0CalibTimeEq &AliT0CalibTimeEq::operator =(const AliT0CalibTimeEq& calibda)
73 {
74 // assignment operator
75   SetName(calibda.GetName());
76   SetTitle(calibda.GetName());
77  
78   return *this;
79 }
80
81 //________________________________________________________________
82 AliT0CalibTimeEq::~AliT0CalibTimeEq()
83 {
84   //
85   // destrictor
86 }
87 //________________________________________________________________
88 void AliT0CalibTimeEq::Reset()
89 {
90   //reset values
91
92   memset(fCFDvalue,0,120*sizeof(Float_t));
93   memset(fTimeEq,1,24*sizeof(Float_t));
94 }
95
96
97 //________________________________________________________________
98 void  AliT0CalibTimeEq::Print(Option_t*) const
99 {
100   // print time values
101
102   printf("\n    ----    PM Arrays       ----\n\n");
103   printf(" Time delay CFD \n");
104   for (Int_t i=0; i<24; i++) printf(" CFD  %f ",fTimeEq[i]);
105   printf("\n Mean Vertex %f \n", fMeanVertex);
106
107
108
109 //________________________________________________________________
110 Bool_t AliT0CalibTimeEq::ComputeOnlineParams(const char* filePhys)
111 {
112   // compute online equalized time
113   Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
114   meandiff = sigmadiff =  meanver = meancfdtime = sigmacfdtime =0;
115   Double_t rmsver=0;
116   Int_t nent=0;
117   Int_t okdiff=0;
118   Int_t oktime=0;
119   Bool_t ok=false;
120   gFile = TFile::Open(filePhys);
121   if(!gFile) {
122     AliError("No input PHYS data found ");
123   }
124   else
125     {
126       ok=true;
127       for (Int_t i=0; i<24; i++)
128         {
129
130           meandiff = sigmadiff =  meanver = meancfdtime = sigmacfdtime =0;
131           TH1F *cfd = (TH1F*) gFile->Get(Form("CFD1minCFD%d",i+1));
132           TH1F *cfdtime = (TH1F*) gFile->Get(Form("CFD%d",i+1));
133           if(!cfd) {
134             AliWarning(Form("no Diff histograms collected by PHYS DA for channel %i", i));
135             okdiff++;
136             if(okdiff<4) {
137               meandiff = 0;
138               sigmadiff = 0;
139             }
140             else
141               ok = false; 
142           }
143           if(!cfdtime) {
144             AliWarning(Form("no CFD histograms collected by PHYS DA for channel %i", i));
145             oktime++;
146             if(oktime<4) {
147               meancfdtime = 0;
148             }
149             else
150               ok = false; 
151           }
152           if(cfd) {
153             nent = Int_t(cfd->GetEntries());
154             if( nent<=50 || cfd->GetRMS() == 0 || cfd->GetMean() ) {
155               okdiff++;
156               if(okdiff<4) {
157                 meandiff = 0;
158                 sigmadiff = 0;
159               }
160               else
161                 {
162                   AliWarning(Form(" Not  enouph data in PMT %i- PMT1:  %i ", i, nent));
163                   ok = false; 
164                 }
165             }
166             if(nent>50)  { 
167               if(cfd->GetRMS()>1.5 )
168                 GetMeanAndSigma(cfd, meandiff, sigmadiff);
169               if(cfd->GetRMS()<=1.5) 
170                 {
171                   meandiff = cfd->GetMean();
172                   sigmadiff=cfd->GetRMS();
173                 }
174               Int_t   maxBin = cfd->GetMaximumBin(); 
175               Double_t  meanEstimate = cfd->GetBinCenter( maxBin); 
176               if(TMath::Abs(meanEstimate - meandiff) > 20 ) meandiff = meanEstimate; 
177             }
178           }
179           
180           if(cfdtime) {
181             nent = Int_t(cfdtime->GetEntries());
182             if( nent<=50 || cfdtime->GetRMS() == 0 || cfdtime->GetMean() ) {
183               oktime++;
184               if(oktime<4) {
185                 meancfdtime = 0;
186               }
187               else
188                 {
189                   AliWarning(Form(" Not  enouph data in PMT %i:  %i ", i, nent));
190                   ok = false; 
191                 }
192             }
193             if(nent > 50 )  { //!!!!!!!!!!
194               if(cfdtime->GetRMS()>1.5 )
195                 GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
196               if(cfdtime->GetRMS()<=1.5) 
197                 {
198                   meancfdtime = cfdtime->GetMean();
199                   sigmacfdtime = cfdtime->GetRMS();
200                 }
201               Int_t   maxBin = cfdtime->GetMaximumBin(); 
202               Double_t  meanEstimate = cfdtime->GetBinCenter( maxBin); 
203               if(TMath::Abs(meanEstimate - meancfdtime) > 20 ) meancfdtime = meanEstimate; 
204             }
205           }
206           SetTimeEq(i,meandiff);
207           SetTimeEqRms(i,sigmadiff);
208           SetCFDvalue(i,0,meancfdtime);
209           if (cfd) delete cfd;
210           if (cfdtime) delete cfdtime;
211         }
212       TH1F *ver = (TH1F*) gFile->Get("hVertex");
213       if(ver) {
214         meanver = ver->GetMean();
215         rmsver = ver->GetRMS();
216       }
217       SetMeanVertex(meanver);
218       SetRmsVertex(rmsver);
219       
220       gFile->Close();
221       delete gFile;
222       
223     }
224     return ok; 
225 }
226
227 //________________________________________________________________
228   Int_t AliT0CalibTimeEq::ComputeOfflineParams(const char* filePhys, Float_t *timecdb, Float_t *cfdvalue, Int_t badpmt)
229 {
230   // fStatus implementation:
231   //ok means
232   // 1000  - can not open file 
233   // for timediff
234   // 1-24  no histograms with time diff for more than okdiff channenls
235   // 100 >3 histos are empty
236   // - 1 if less 3 channels are empty ;for these channels OCDB value will be written back WARNING
237   // -2  low statistics in few channels; for these channels OCDB value will be written back WARNING
238   // for cfd
239   // 200 >3 histos are empty 
240   // -11 if less 3 channels are empty ;for these channels OCDB value will be written back WARNING
241   // -22  low statistics in few channels; for these channels OCDB value will be written back WARNING
242    //
243   // compute offline equalized time
244   Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
245   meandiff = sigmadiff =  meanver = meancfdtime = sigmacfdtime =0;
246   Int_t nent=0;
247   Int_t ok = 0;
248   Int_t okdiff=0;
249   Int_t okcfd=0;
250   TH1F *cfddiff = NULL; 
251   TH1F *cfdtime = NULL;
252   TObjArray * TzeroObj = NULL;
253
254   gFile = TFile::Open(filePhys);
255   if(!gFile) {
256     AliError("No input PHYS data found ");
257     ok = 1000;
258     return ok;
259   }
260   else
261     {
262       meandiff = sigmadiff =  meanver = meancfdtime = sigmacfdtime =0;
263       TDirectory *dr = (TDirectory*) gFile->Get("T0Calib");
264       if (dr)   TzeroObj = (TObjArray*) dr->Get("T0Calib");
265       for (Int_t i=0; i<24; i++)
266         {
267           if (i != badpmt) {
268             if(TzeroObj) {
269               cfddiff = (TH1F*)TzeroObj->FindObject(Form("CFD1minCFD%d",i+1));
270               cfdtime = (TH1F*)TzeroObj->FindObject(Form("CFD%d",i+1));
271             }
272             else
273               {
274                 cfddiff = (TH1F*)gFile->Get(Form("CFD1minCFD%d",i+1));
275                 cfdtime = (TH1F*)gFile->Get(Form("CFD%d",i+1));
276                 
277               }
278             if(!cfddiff ) {
279               AliWarning(Form("no  histograms collected by pass0 for diff channel %i", i));    
280               okdiff++;
281               if(okdiff<4) {
282                 meandiff = timecdb[i];
283                 sigmadiff = 0;
284                 ok = -1;
285               }
286               else
287                 return 100+okdiff; 
288             }
289             if(cfddiff) {
290               nent = Int_t(cfddiff->GetEntries());
291               if ( nent == 0) {
292                 okdiff++;
293                 if(okdiff<4) {
294                   meandiff = timecdb[i];
295                   sigmadiff = 0;
296                   ok = - 1;
297                 }
298                 else
299                   return 100; 
300               }       
301               if(nent<100 && nent>0) { //!!!!!
302                 AliWarning(Form(" Not  enouph data in PMT %i- PMT1:  %i ", i, nent));
303                 ok=-2;
304                 meandiff = timecdb[i];
305                 sigmadiff = 0; 
306               }
307               if(nent>100 )  { //!!!!!
308                 {
309                   if(cfddiff->GetRMS()>1.5 )
310                     GetMeanAndSigma(cfddiff, meandiff, sigmadiff);
311                   if(cfddiff->GetRMS()<=1.5) 
312                     {
313                       meandiff = cfddiff->GetMean();
314                       sigmadiff = cfddiff->GetRMS();
315                     }
316                   Int_t   maxBin = cfddiff->GetMaximumBin(); 
317                   Double_t  meanEstimate = cfddiff->GetBinCenter( maxBin); 
318                   if(TMath::Abs(meanEstimate - meandiff) > 20 ) meandiff = meanEstimate; 
319                 }
320               }     
321             }
322             if(!cfdtime ) {
323               AliWarning(Form("no  histograms collected by pass0 for time channel %i", i));
324               meancfdtime = cfdvalue[i];
325               okcfd++;
326               if(okcfd<4) {
327                 meancfdtime = cfdvalue[i];
328                 ok = -11;
329               }
330               else {
331                 AliError(Form("no  histograms collected by pass0 for time %i channels ", okcfd));
332                 return 200; 
333               }
334             }
335             if(cfdtime) {
336               nent = Int_t(cfdtime->GetEntries());
337               if (nent == 0 || 
338                   (cfdtime->GetRMS() == 0 || cfdtime->GetMean() ==0 ) ) 
339                 {
340                   okcfd++;
341                   if(okcfd<4) {
342                     meancfdtime = cfdvalue[i];
343                     ok = -11;
344                     printf("!!!!bad data:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
345                            i, nent, cfdtime->GetRMS(), cfdtime->GetMean(),  fCFDvalue[i][0]);
346                   }
347                   else
348                     {
349                     printf("!!!!fatal data:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
350                            i, nent, cfdtime->GetRMS(), cfdtime->GetMean(),  fCFDvalue[i][0]);
351                       AliError(Form(" histograms collected by pass0 for time %i channels are empty", okcfd));
352                       return 200; 
353                     }
354                 }
355               
356                   
357               if(nent<100 && nent>0 ) 
358                 {
359                 AliWarning(Form(" Not  enouph data in PMT in CFD peak %i - %i ", i, nent));
360                 if(okcfd<4) {
361                   meancfdtime = cfdvalue[i];
362                   ok = -22;
363                   printf("!!!!low statstics:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
364                          i, nent, cfdtime->GetRMS(), cfdtime->GetMean(),  fCFDvalue[i][0]);
365                 }
366                 else {
367                   printf("!!!!low fatal statstics:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
368                          i, nent, cfdtime->GetRMS(), cfdtime->GetMean(),  fCFDvalue[i][0]);
369
370                   AliError(Form(" Not  enouph data in PMT in CFD peak %i in channels ", okcfd));
371                   return 200; 
372                 }
373
374               }
375
376               if( nent>100 && cfdtime->GetRMS() != 0 )    { //!!!!!
377                 if(cfdtime->GetRMS()>1.5 )
378                   GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
379                 if(cfdtime->GetRMS()<=1.5) 
380                   {
381                     meancfdtime = cfdtime->GetMean();
382                     sigmacfdtime=cfdtime->GetRMS();
383                   }
384                 Int_t   maxBin = cfdtime->GetMaximumBin(); 
385                 Double_t  meanEstimate = cfdtime->GetBinCenter( maxBin); 
386                 if(TMath::Abs(meanEstimate - meancfdtime) > 20 ) meancfdtime = meanEstimate; 
387             }
388           }
389           
390           SetTimeEq(i,meandiff);
391           SetTimeEqRms(i,sigmadiff);
392           SetCFDvalue(i,0, meancfdtime );
393           printf(" pmt %i diff %f sigma %f meancfdtime %f cdbtime %f \n",i, meandiff, sigmadiff, meancfdtime, fCFDvalue[i][0]);
394           if (cfddiff) cfddiff->Reset();
395           if (cfdtime) cfdtime->Reset();
396           } //bad pmt
397         }
398       
399       gFile->Close();
400       delete gFile;
401
402     }
403     return ok; 
404    }
405
406 //________________________________________________________________________
407 void AliT0CalibTimeEq::GetMeanAndSigma(TH1F* hist,  Float_t &mean, Float_t &sigma) {
408   
409   const double window = 2.;  //fit window 
410   
411   double meanEstimate, sigmaEstimate; 
412   int maxBin;
413   maxBin        =  hist->GetMaximumBin(); //position of maximum
414   meanEstimate  =  hist->GetBinCenter( maxBin); // mean of gaussian sitting in maximum
415   // sigmaEstimate = hist->GetRMS();
416   sigmaEstimate = 10;
417   TF1* fit= new TF1("fit","gaus", meanEstimate - window*sigmaEstimate, meanEstimate + window*sigmaEstimate);
418   fit->SetParameters(hist->GetBinContent(maxBin), meanEstimate, sigmaEstimate);
419   hist->Fit("fit","RQ","Q");
420
421   mean  = (Float_t) fit->GetParameter(1);
422   sigma = (Float_t) fit->GetParameter(2);
423
424   delete fit;
425 }
426
427