1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // class T0 walk correction Alla Maevskaya alla@inr.ru 20.11.2007 //
22 ///////////////////////////////////////////////////////////////////////////////
24 #include "AliT0CalibWalk.h"
27 #include <TObjArray.h>
33 #include <Riostream.h>
34 #include <TSpectrum.h>
38 ClassImp(AliT0CalibWalk)
40 //________________________________________________________________
41 AliT0CalibWalk::AliT0CalibWalk(): TNamed(),
50 //________________________________________________________________
51 AliT0CalibWalk::AliT0CalibWalk(const char* name):TNamed(),
53 fAmpLEDRec(0), fQTC(0),
57 TString namst = "Calib_";
59 SetName(namst.Data());
60 SetTitle(namst.Data());
64 //________________________________________________________________
65 AliT0CalibWalk::AliT0CalibWalk(const AliT0CalibWalk& calibda) :
74 SetName(calibda.GetName());
75 SetTitle(calibda.GetName());
80 //________________________________________________________________
81 AliT0CalibWalk &AliT0CalibWalk::operator =(const AliT0CalibWalk& calibda)
83 // assignment operator
84 SetName(calibda.GetName());
85 SetTitle(calibda.GetName());
90 //________________________________________________________________
91 AliT0CalibWalk::~AliT0CalibWalk()
95 //________________________________________________________________
96 void AliT0CalibWalk::SetWalk(Int_t ipmt)
98 //read QTC walk graph from external file
101 Int_t x[70000], y[70000], index[70000];
102 Float_t time[10000],amplitude[10000];
106 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-Amp.txt");
107 ifstream inFile(filename);
108 if(!inFile) AliError(Form("Cannot open file %s !",filename));
111 while(getline(inFile,buffer)){
118 // cout<<" number of data "<<i<<endl;
120 TMath::Sort(i, y, index,down);
121 Int_t amp=0, iin=0, isum=0, sum=0;
123 for (Int_t ii=0; ii<i; ii++)
134 time[isum] = Float_t (sum/(iin));
136 time[isum] =Float_t (x[ind]);
137 amplitude[isum] = Float_t (amp);
147 TGraph* gr = new TGraph(isum, amplitude, time);
148 fWalk.AddAtAndExpand(gr,ipmt);
150 //should be change to real
151 Double_t xq[10] = { 1220, 1370, 1542, 1697, 1860, 2023,2171,2331,2495,2684};
152 Double_t yq[10] = {1,2,3,4,5,6,7,8,9,10};
153 TGraph* gr1 = new TGraph(10, xq, yq);
154 fQTC.AddAtAndExpand(gr1,ipmt);
157 //________________________________________________________________
159 void AliT0CalibWalk::SetAmpLEDRec(Int_t ipmt)
161 // read LED walk from external file
163 Float_t x[100], y[100];
166 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-LED.txt");
167 ifstream inFile(filename);
168 if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
173 while(getline(inFile,buffer)){
179 Float_t y1[100], x1[100];
180 for (Int_t ir=0; ir<i; ir++){
181 y1[ir]=y[i-ir]; x1[ir]=x[i-ir];}
182 TGraph* gr = new TGraph(i,y1,x1);
183 fAmpLEDRec.AddAtAndExpand(gr,ipmt);
184 //should be change to real
185 Double_t xq[10] = { 411, 412,413,415,417,419,422,428,437,452};
186 Double_t yq[10] = {1,2,3,4,5,6,7,8,9,10};
187 TGraph* gr1 = new TGraph(10, xq, yq);
188 fAmpLED.AddAtAndExpand(gr1,ipmt);
192 //________________________________________________________________
194 void AliT0CalibWalk::MakeWalkCorrGraph(const char *laserFile)
196 //make walk corerction for preprocessor
198 gFile = TFile::Open(laserFile);
200 AliError("No input laser data found ");
206 Float_t x1[14], y1[14];
207 Float_t x2[14], y2[14];
209 Float_t mips[14] = {1.,2,3,4,5,6,7,8,9,10,20,30,40,50};
211 Float_t xx1[14],yy1[14], xx[14];
212 for (Int_t ii=0; ii<14; ii++)
213 { x1[ii]=0; y1[ii]=0; x2[ii]=0; y2[ii]=0; }
216 TH2F* hCFDvsQTC[24][14]; TH2F* hCFDvsLED[24][14];
218 for (Int_t i=0; i<24; i++)
220 for (Int_t im=0; im<nmips; im++)
222 TString qtc = Form("CFDvsQTC%i_%i",i+1,im+1);
223 TString led = Form("CFDvsLED%i_%i",i+1,im+1);
224 hCFDvsQTC[i][im] = (TH2F*) gFile->Get(qtc.Data()) ;
225 hCFDvsLED[i][im] = (TH2F*) gFile->Get(led.Data());
227 if(!hCFDvsQTC[i][im] || !hCFDvsLED[i][im])
228 AliWarning(Form(" no walk correction data in LASER DA for channel %i for amplitude %f MIPs",i,mips[im]));
232 x1[im] = hCFDvsQTC[i][im]->GetMean(1);
233 y1[im] = hCFDvsQTC[i][im]->GetMean(2);
235 if( hCFDvsLED[i][im]){
236 x2[im] = hCFDvsLED[i][im]->GetMean(1);
237 y2[im] = hCFDvsLED[i][im]->GetMean(2);
241 for (Int_t imi=0; imi<nmips; imi++)
243 yy1[imi] = Float_t (mips[nmips-imi-1]);
244 xx1[imi] = x2[nmips-imi-1];
246 if(i==0) cout<<"Making graphs..."<<endl;
248 TGraph *grwalkqtc = new TGraph (nmips,x1,y1);
249 TGraph *grwalkled = new TGraph (nmips,x2,y2);
250 fWalk.AddAtAndExpand(grwalkqtc,i);
251 fAmpLEDRec.AddAtAndExpand(grwalkled,i);
253 //fit amplitude graphs to make comparison wth new one
254 TGraph *grampled = new TGraph (nmips,xx1,yy1);
255 TGraph *grqtc = new TGraph (nmips,x1,xx);
256 fQTC.AddAtAndExpand(grqtc,i);
257 fAmpLED.AddAtAndExpand(grampled,i);
259 //fit amplitude graphs
260 Double_t parled [2], parqtc[2];
262 TF1 *fuled = new TF1("fuled","expo",x1[0],x1[nmips]);
263 TF1 *fuqtc = new TF1 ("fuqtc","pol1",x1[0],x1[nmips]);
264 grqtc->Fit("fuqtc","Q"," ",x1[0],x1[nmips]);
265 grampled->Fit("fuled","Q"," ",xx1[0],xx1[nmips]);
266 fuled->GetParameters(&parled[0]);
267 fuqtc->GetParameters(&parqtc[0]);
269 for(Int_t ipar=0; ipar<2; ipar++) {
270 SetQTCpar(i,ipar,parqtc[ipar]);
271 SetAmpLEDpar(i,ipar,parled[ipar]);
272 // cout<<" pars :::: "<<i<<" "<<ipar<<" qtc "<<parqtc[ipar]<<" led "<<parled[ipar]<<endl;
276 cout<<"Graphs created..."<<endl;