]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0CalibWalk.cxx
448792e1d223c7fea4bec2103894df7a18191488
[u/mrichter/AliRoot.git] / T0 / AliT0CalibWalk.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 T0 walk correction      Alla Maevskaya alla@inr.ru 20.11.2007        //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include "AliT0CalibWalk.h"
25 #include "AliT0LookUpValue.h"
26 #include "AliLog.h"
27 #include "AliRun.h"
28
29 #include <TObjArray.h>
30 #include <TGraph.h>
31 #include <TFile.h>
32 #include <TAxis.h>
33 #include <TH2F.h> 
34 #include <TMath.h>
35 #include <TSystem.h>
36 #include <Riostream.h>
37 #include <TSpectrum.h>
38 #include <TVirtualFitter.h>
39 #include <TProfile.h>
40
41 #include <string>
42
43 ClassImp(AliT0CalibWalk)
44
45 //________________________________________________________________
46   AliT0CalibWalk::AliT0CalibWalk():   TNamed(),
47                                       fWalk(0),
48                                       fAmpLEDRec(0)
49 {
50   //
51 }
52
53 //________________________________________________________________
54 AliT0CalibWalk::AliT0CalibWalk(const char* name):TNamed(),
55                                       fWalk(0),
56                                       fAmpLEDRec(0)                                   
57 {
58   TString namst = "Calib_";
59   namst += name;
60   SetName(namst.Data());
61   SetTitle(namst.Data());
62
63 }
64
65 //________________________________________________________________
66 AliT0CalibWalk::AliT0CalibWalk(const AliT0CalibWalk& calibda) :
67   TNamed(calibda),              
68   fWalk(0),
69   fAmpLEDRec(0)
70
71 {
72 // copy constructor
73   SetName(calibda.GetName());
74   SetTitle(calibda.GetName());
75
76
77 }
78
79 //________________________________________________________________
80 AliT0CalibWalk &AliT0CalibWalk::operator =(const AliT0CalibWalk& calibda)
81 {
82 // assignment operator
83   SetName(calibda.GetName());
84   SetTitle(calibda.GetName());
85  
86   return *this;
87 }
88
89 //________________________________________________________________
90 AliT0CalibWalk::~AliT0CalibWalk()
91 {
92   //
93 }
94 //________________________________________________________________
95 void AliT0CalibWalk::SetWalk(Int_t ipmt)
96 {
97
98   Int_t mv, ps; 
99   Int_t x[70000], y[70000], index[70000];
100   Float_t time[10000],amplitude[10000];
101   string buffer;
102   Bool_t down=false;
103   
104   const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-Amp.txt");
105   ifstream inFile(filename);
106   if(!inFile) AliError(Form("Cannot open file %s !",filename));
107   
108   Int_t i=0;
109   while(getline(inFile,buffer)){
110     inFile >> ps >> mv;
111
112     x[i]=ps; y[i]=mv;
113     i++;
114   }
115   inFile.close();
116   cout<<" number of data "<<i<<endl;
117  
118   TMath::Sort(i, y, index,down);
119   Int_t amp=0, iin=0, isum=0, sum=0;
120   Int_t ind=0;
121   for (Int_t ii=0; ii<i; ii++)
122     {
123       ind=index[ii];
124       if(y[ind] == amp)
125         {
126           sum +=x[ind];
127           iin++;
128         }
129       else
130         {
131           if(iin>0)
132             time[isum] = Float_t (sum/(iin));
133           else
134             time[isum] =Float_t (x[ind]);
135           amplitude[isum] = Float_t (amp);
136           amp=y[ind];
137           iin=0;
138           isum++;
139           sum=0;
140         }
141     }
142
143   inFile.close();
144
145   TGraph* gr = new TGraph(isum, amplitude, time);
146   fWalk.AddAtAndExpand(gr,ipmt);
147 }
148
149 //________________________________________________________________
150
151 void AliT0CalibWalk::SetAmpLEDRec(Int_t ipmt)
152 {
153   Float_t mv, ps; 
154   Float_t x[100], y[100];
155   string buffer;
156   
157   const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-LED.txt");
158    ifstream inFile(filename);
159   if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
160   
161   inFile >> mv>>ps;
162   Int_t i=0;
163   
164   while(getline(inFile,buffer)){
165     x[i]=mv; y[i]=ps;   
166     inFile >> mv >> ps;
167     i++;
168   }
169   inFile.close();
170   Float_t y1[100], x1[100];
171   for (Int_t ir=0; ir<i; ir++){
172     y1[ir]=y[i-ir]; x1[ir]=x[i-ir];}
173   TGraph* gr = new TGraph(i,y1,x1);
174   fAmpLEDRec.AddAtAndExpand(gr,ipmt);
175   
176 }
177
178 //________________________________________________________________
179
180 void AliT0CalibWalk::MakeWalkCorrGraph(const char *laserFile)
181 {
182   TFile *gFile = TFile::Open(laserFile);
183   gSystem->Load("libSpectrum");
184   TGraph *gr[24];
185   Int_t npeaks = 20;
186   Int_t sigma=3;
187   Bool_t down=false;
188
189   Int_t index[20];
190   Char_t buf1[10], buf2[10],title[10];
191
192   for (Int_t i=0; i<24; i++)
193   {
194     sprintf(buf1,"T0_C_%i_CFD",i+1);
195     sprintf(buf2,"CFD_QTC%i",i+1);
196     // cout<<buf1<<" "<<buf2<<endl;
197     TH2F *qtc_cfd = (TH2F*) gFile->Get(buf2);
198     TH1F *cfd = (TH1F*) gFile->Get(buf1);
199     TSpectrum *s = new TSpectrum(2*npeaks,1.);
200     Int_t nfound = s->Search(cfd,sigma," ",0.05);
201     // cout<<"Found "<<nfound<<" peaks sigma "<<sigma<<endl;
202     if(nfound!=0)
203     {
204       Float_t *xpeak = s->GetPositionX();
205       TMath::Sort(nfound, xpeak, index,down);
206       Float_t xp = xpeak[index[0]];
207       Float_t hmax = xp+10*sigma;
208       Float_t hmin = xp-10*sigma;
209       Int_t nbins= qtc_cfd->GetXaxis()->GetNbins();
210       TProfile *pr_y = qtc_cfd->ProfileX();
211       pr_y->SetMaximum(hmax);
212       pr_y->SetMinimum(hmin);
213       Int_t np=nbins/20;
214       Double_t *xx = new Double_t[np];
215       Double_t *yy = new Double_t[np];
216       Int_t ng=0;
217       Double_t yg=0;
218       for (Int_t ip=1; ip<nbins; ip++)
219       {
220         if(ip%20 != 0 )
221         {
222           if (pr_y->GetBinContent(ip) !=0)
223           {
224             yg +=pr_y->GetBinContent(ip);
225           }
226           ng++;
227         }
228         else
229         {
230           xx[ip/20] = Float_t (pr_y->GetBinCenter(ip));
231           yy[ip/20] = yg/ng;
232           yg=0;
233           ng=0;
234         }
235       }
236       sprintf(title,"Walk %i",i+1);
237       gr[i] = new TGraph(np,xx,yy);
238       gr[i]->SetTitle(title);
239       gr[i]->SetMinimum(hmin);
240       gr[i]->SetMaximum(hmax);
241       gr[i]->SetMarkerStyle(7);
242       fWalk.AddAtAndExpand(gr[i],i);      
243        delete [] xx;
244       delete [] yy;
245       delete gr[i];
246     }
247   }
248
249   gFile->Close();
250   delete gFile;
251 }
252