]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0CalibTimeEq.cxx
writing AmpLEd correction by preprocessor
[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 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include "AliT0CalibTimeEq.h"
25 #include "AliT0LookUpValue.h"
26 #include "AliLog.h"
27 #include "AliRun.h"
28
29 #include <TFile.h>
30 #include <TMath.h>
31 #include <TF1.h>
32 #include <TSystem.h>
33 #include <Riostream.h>
34 #include <TSpectrum.h>
35 #include <TVirtualFitter.h>
36 #include <TProfile.h>
37 #include <string>
38
39 ClassImp(AliT0CalibTimeEq)
40
41 //________________________________________________________________
42   AliT0CalibTimeEq::AliT0CalibTimeEq():TNamed()
43 {
44   //
45 }
46
47 //________________________________________________________________
48 AliT0CalibTimeEq::AliT0CalibTimeEq(const char* name):TNamed()
49 {
50   TString namst = "Calib_";
51   namst += name;
52   SetName(namst.Data());
53   SetTitle(namst.Data());
54 }
55
56 //________________________________________________________________
57 AliT0CalibTimeEq::AliT0CalibTimeEq(const AliT0CalibTimeEq& calibda):TNamed(calibda)             
58 {
59 // copy constructor
60   SetName(calibda.GetName());
61   SetTitle(calibda.GetName());
62
63
64 }
65
66 //________________________________________________________________
67 AliT0CalibTimeEq &AliT0CalibTimeEq::operator =(const AliT0CalibTimeEq& calibda)
68 {
69 // assignment operator
70   SetName(calibda.GetName());
71   SetTitle(calibda.GetName());
72  
73   return *this;
74 }
75
76 //________________________________________________________________
77 AliT0CalibTimeEq::~AliT0CalibTimeEq()
78 {
79   //
80 }
81 //________________________________________________________________
82 void AliT0CalibTimeEq::Reset()
83 {
84   memset(fCFDvalue,0,120*sizeof(Float_t));
85   memset(fTimeEq,1,24*sizeof(Float_t));
86 }
87
88
89 //________________________________________________________________
90 void  AliT0CalibTimeEq::Print(Option_t*) const
91 {
92
93   printf("\n    ----    PM Arrays       ----\n\n");
94   printf(" Time delay CFD \n");
95   for (Int_t i=0; i<24; i++) printf(" CFD  %f ",fTimeEq[i]);
96
97
98
99 //________________________________________________________________
100 void AliT0CalibTimeEq::ComputeOnlineParams(char* name1, Int_t npeaks, Double_t sigma, const char* filePhys)
101 {
102   TFile *gFile = TFile::Open(filePhys);
103   Bool_t down=false;
104   Int_t index[20];
105   Char_t buf1[15];
106   Char_t temp[10];
107   Float_t p[24][3]={0.,0.,0.};
108   for (Int_t i=0; i<24; i++)
109   {
110     sprintf(buf1,name1);
111     sprintf(temp,"%i",i+1);
112     strcat (buf1,temp);
113     //strcat (buf1,name2);
114     TH1F *cfd = (TH1F*) gFile->Get(buf1);
115     printf(" i = %d buf1 = %s\n", i, buf1);
116     TSpectrum *s = new TSpectrum(2*npeaks,1.);
117     printf(" buf1 = %s cfd = %x\n", buf1, cfd);
118     Int_t nfound = s->Search(cfd,sigma,"goff",0.2);
119     printf(" nfound = %d\n", nfound);
120     if(nfound!=0)
121     {
122       Float_t *xpeak = s->GetPositionX();
123       TMath::Sort(nfound, xpeak, index,down);
124       Float_t xp = xpeak[index[0]];
125       Float_t hmax = xp+3*sigma;
126       Float_t hmin = xp-3*sigma;
127       cfd->GetXaxis()->SetRange((Int_t)hmin-20,(Int_t)hmax+20);
128       TF1 *g1 = new TF1("g1", "gaus", hmin, hmax);
129       cfd->Fit("g1","IRQN");
130       for(Int_t j =0; j<3; j++)
131       {
132         p[i][j] = g1->GetParameter(j);
133         SetCFDvalue(i, j, p[i][j]);
134       }
135
136       SetCFDvalue(i, 3, hmin);
137       SetCFDvalue(i, 4, hmax);
138
139       if (i<12)
140       {
141         SetTimeEq(i,(p[i][2]-p[0][2]));
142       }
143       else
144       {
145         SetTimeEq(i,(p[i][2]-p[12][2]));
146       } 
147     } 
148   }
149   
150    gFile->Close();
151    delete gFile;
152
153    for(int i=0;i<5;i++)
154      {
155       for(int j=0;j<24;j++)
156         {
157                 printf("fCFDvalue[%d][%d]=%f\n",j,i,fCFDvalue[j][i]);
158         }
159      }
160    printf("\n\n");
161    for(int j=0;j<24;j++)
162    {
163                 printf("fTimeEq[%d]=%f\n",j,fTimeEq[j]);
164    }
165 }
166
167