* about the suitability of this software for any purpose. It is *
* provided "as is" without express or implied warranty. *
**************************************************************************/
-
+
/* $Id$ */
///////////////////////////////////////////////////////////////////////////////
#include <Riostream.h>
#include <TSpectrum.h>
#include <TProfile.h>
-
+#include <TF1.h>
ClassImp(AliT0CalibWalk)
//________________________________________________________________
AliT0CalibWalk::AliT0CalibWalk(): TNamed(),
fWalk(0),
- fAmpLEDRec(0)
+ fAmpLEDRec(0),
+ fQTC(0),
+ fAmpLED(0)
{
//
}
//________________________________________________________________
AliT0CalibWalk::AliT0CalibWalk(const char* name):TNamed(),
fWalk(0),
- fAmpLEDRec(0)
+ fAmpLEDRec(0), fQTC(0),
+ fAmpLED(0)
+
{
TString namst = "Calib_";
namst += name;
AliT0CalibWalk::AliT0CalibWalk(const AliT0CalibWalk& calibda) :
TNamed(calibda),
fWalk(0),
- fAmpLEDRec(0)
-
+ fAmpLEDRec(0),
+ fQTC(0),
+ fAmpLED(0)
+
{
// copy constructor
SetName(calibda.GetName());
{
//
}
-//________________________________________________________________
-void AliT0CalibWalk::SetWalk(Int_t ipmt)
-{
- //read QTC walk graph from external file
+//________________________________________________________________
- Int_t mv, ps;
- Int_t x[70000], y[70000], index[70000];
- Float_t time[10000],amplitude[10000];
- string buffer;
- Bool_t down=false;
-
- const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-Amp.txt");
- ifstream inFile(filename);
- if(!inFile) AliError(Form("Cannot open file %s !",filename));
-
- Int_t i=0;
- while(getline(inFile,buffer)){
- inFile >> ps >> mv;
-
- x[i]=ps; y[i]=mv;
- i++;
- }
- inFile.close();
- cout<<" number of data "<<i<<endl;
-
- TMath::Sort(i, y, index,down);
- Int_t amp=0, iin=0, isum=0, sum=0;
- Int_t ind=0;
- for (Int_t ii=0; ii<i; ii++)
- {
- ind=index[ii];
- if(y[ind] == amp)
- {
- sum +=x[ind];
- iin++;
- }
- else
- {
- if(iin>0)
- time[isum] = Float_t (sum/(iin));
- else
- time[isum] =Float_t (x[ind]);
- amplitude[isum] = Float_t (amp);
- amp=y[ind];
- iin=0;
- isum++;
- sum=0;
- }
- }
-
- inFile.close();
-
- TGraph* gr = new TGraph(isum, amplitude, time);
- fWalk.AddAtAndExpand(gr,ipmt);
-}
-
-//________________________________________________________________
-
-void AliT0CalibWalk::SetAmpLEDRec(Int_t ipmt)
-{
- // read LED walk from external file
- Float_t mv, ps;
- Float_t x[100], y[100];
- string buffer;
-
- const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-LED.txt");
- ifstream inFile(filename);
- if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
-
- inFile >> mv>>ps;
- Int_t i=0;
-
- while(getline(inFile,buffer)){
- x[i]=mv; y[i]=ps;
- inFile >> mv >> ps;
- i++;
- }
- inFile.close();
- Float_t y1[100], x1[100];
- for (Int_t ir=0; ir<i; ir++){
- y1[ir]=y[i-ir]; x1[ir]=x[i-ir];}
- TGraph* gr = new TGraph(i,y1,x1);
- fAmpLEDRec.AddAtAndExpand(gr,ipmt);
-
-}
-
-//________________________________________________________________
-
-void AliT0CalibWalk::MakeWalkCorrGraph(const char *laserFile)
+Bool_t AliT0CalibWalk::MakeWalkCorrGraph(const char *laserFile)
{
//make walk corerction for preprocessor
-
- TFile *gFile = TFile::Open(laserFile);
-
Int_t npeaks = 20;
- Double_t sigma=3.;
- Bool_t down = false;
-
+ Int_t sigma=3.;
+ Bool_t down=false;
Int_t index[20];
- Char_t buf1[20], buf2[20],buf3[20];
-
+ Bool_t ok=true;
+ Float_t mips[20];
+ Int_t nfound=0;
- for (Int_t i=0; i<24; i++)
+ gFile = TFile::Open(laserFile);
+ if(!gFile) {
+ AliError("No input laser data found ");
+ }
+ else
{
- if(i>11) { sprintf(buf1,"T0_A_%i_CFD",i+1-12); }
-
- if(i<12) { sprintf(buf1,"T0_C_%i_CFD",i+1); }
-
- sprintf(buf2,"CFDvsQTC%i",i+1);
- sprintf(buf3,"CFDvsLED%i",i+1);
- // cout<<buf1<<" "<<buf2<<" "<<buf3<<endl;
- TH2F *qtcVScfd = (TH2F*) gFile->Get(buf2);
- // qtcVScfd->Print();
- TH2F *ledVScfd = (TH2F*) gFile->Get(buf3);
- TH1F *cfd = (TH1F*) gFile->Get(buf1);
-
- TSpectrum *s = new TSpectrum(2*npeaks,1);
- Int_t nfound = s->Search(cfd,sigma,"goff",0.1);
- // cout<<"Found "<<nfound<<" peaks sigma "<<sigma<<endl;;
- if(nfound!=0){
- Float_t *xpeak = s->GetPositionX();
- TMath::Sort(nfound, xpeak, index,down);
- Float_t xp = xpeak[index[0]];
- Int_t xbin = cfd->GetXaxis()->FindBin(xp);
- Float_t yp = cfd->GetBinContent(xbin);
- // cout<<"xbin = "<<xbin<<"\txpeak = "<<xpeak[1]<<"\typeak = "<<yp<<endl;
- Float_t hmax = xp+20*sigma;
- Float_t hmin = xp-20*sigma;
- }
- //QTC
- Int_t nbins= qtcVScfd->GetXaxis()->GetNbins();
- TProfile *prY = qtcVScfd->ProfileX();
- Float_t hmin = qtcVScfd->GetYaxis()->GetXmin();
- Float_t hmax = qtcVScfd->GetYaxis()->GetXmax();
- prY->SetMaximum(hmax);
- prY->SetMinimum(hmin);
- Int_t np=0; //=nbins/5;
- Double_t *xx = new Double_t[nbins];
- Double_t *yy = new Double_t[nbins];
- Int_t ng=0;
- Double_t yg=0;
- for (Int_t ip=1; ip<nbins; ip++)
- {
-
- if(ip%5 != 0 )
- {
- // if (prY->GetBinContent(ip) !=0)
- if (prY->GetBinContent(ip) >hmin && prY->GetBinContent(ip)<hmax){
- yg +=prY->GetBinContent(ip);
- ng++;
- // cout<<" ip "<<ip<<" Y "<<yg<<endl;
- }
- }
- else {
- if (/*prY->GetBinContent(ip) >hmin && prY->GetBinContent(ip)<hmax &&*/ ng>0){
- // xx[ip/5] = Float_t (prY->GetBinCenter(ip));
- // yy[ip/5] = yg/ng;
- xx[np] = Float_t (prY->GetBinCenter(ip));
- yy[np] = yg/ng;
- yg=0;
- ng=0;
- // cout<<" ip "<<ip<<" np "<<np<<" XX "<<xx[np]<<" YY "<<yy[np]<<endl;
- np++;
+ // gFile->ls();
+ TH1F* hAmp = (TH1F*) gFile->Get("hAmpLaser");
+ Int_t nmips=0;
+ for (Int_t ibin=0; ibin<1000; ibin++) {
+ Float_t bincont = hAmp->GetBinContent(ibin);
+ if(bincont>0){
+ mips[nmips] = hAmp->GetXaxis()->GetBinCenter(ibin);
+ cout<<ibin<<" bincont "<<bincont<<" amp "<< mips[nmips]<<endl;
+ nmips++;
+ }
+ }
+
+ if (nmips<15) ok=false;
+
+ Float_t x1[50], y1[50];
+ Float_t x2[50], xx2[50],y2[50];
+ Float_t xx1[50],yy1[50], xx[50];
+
+ Float_t cfd0[24];
+ Int_t startim = 0;
+
+ for (Int_t ii=0; ii<nmips; ii++)
+ x1[ii] = y1[ii] = x2[ii] = y2[ii] = 0;
+
+ for (Int_t i=0; i<24; i++)
+ {
+ for (Int_t im=startim; im<nmips; im++)
+ {
+ TString cfd = Form("hCFD%i_%i",i+1,im+1);
+ TString qtc = Form("hQTC%i_%i",i+1,im+1);
+ TString led = Form("hLED%i_%i",i+1,im+1);
+
+ TH1F *hCFD = (TH1F*) gFile->Get(cfd.Data()) ;
+ TH1F *hLED = (TH1F*) gFile->Get(led.Data());
+ TH1F *hQTC = (TH1F*) gFile->Get(qtc.Data()) ;
+ hCFD->SetDirectory(0);
+ hQTC->SetDirectory(0);
+ hLED->SetDirectory(0);
+ if(!hCFD )
+ AliWarning(Form(" no CFD data in LASER DA for channel %i for amplitude %f MIPs",i,mips[im]));
+ if(!hQTC )
+ AliWarning(Form(" no QTC correction data in LASER DA for channel %i for amplitude %f MIPs",i,mips[im]));
+ if(!hLED)
+ AliWarning(Form(" no LED correction data in LASER DA for channel %i for amplitude %f MIPs",i,mips[im]));
+
+ if(hCFD ) {
+ TSpectrum *s = new TSpectrum(2*npeaks,1);
+ nfound = s->Search(hCFD,sigma," ",0.1);
+ if(nfound!=0){
+ Float_t *xpeak = s->GetPositionX();
+ TMath::Sort(nfound, xpeak, index,down);
+ Float_t xp = xpeak[index[0]];
+ Double_t hmax = xp+3*sigma;
+ Double_t hmin = xp-3*sigma;
+ hCFD->GetXaxis()->SetRangeUser(hmin-10,hmax+10);
+ }
+ else
+ {
+ hCFD->Rebin(2);
+ TSpectrum *s1 = new TSpectrum(2*npeaks,1);
+ nfound = s1->Search(hCFD,sigma," ",0.1);
+ if(nfound!=0){
+ Float_t *xpeak = s1->GetPositionX();
+ TMath::Sort(nfound, xpeak, index,down);
+ Float_t xp = xpeak[index[0]];
+ Double_t hmax = xp+3*sigma;
+ Double_t hmin = xp-3*sigma;
+ hCFD->GetXaxis()->SetRangeUser(hmin-10,hmax+10);
+ }
+ else
+ ok=false;
+ }
+
+ if (im == 0) cfd0[i] = hCFD->GetMean();
+ y1[im] = hCFD->GetMean() - cfd0[i];
}
+ if( hQTC) x1[im] = hQTC->GetMean();
+
+ if( hLED){
+ TSpectrum *s = new TSpectrum(2*npeaks,1);
+ nfound = s->Search(hLED,sigma," ",0.1);
+ if(nfound!=0){
+ Float_t *xpeak = s->GetPositionX();
+ TMath::Sort(nfound, xpeak, index,down);
+ Float_t xp = xpeak[index[0]];
+ Double_t hmax = xp+10*sigma;
+ Double_t hmin = xp-10*sigma;
+ hLED->GetXaxis()->SetRangeUser(hmin-10,hmax+10);
+ }
+ else
+ ok=false;
+ x2[im] = hLED->GetMean();
+ xx2[im] = x2[nmips-im-1];
+ }
+ xx[im]=mips[im];
+
+ if (hQTC) delete hQTC;
+ if (hCFD) delete hCFD;
+ if (hLED) delete hLED;
}
- }
- TGraph *gr = new TGraph(np,xx,yy);
- gr->SetMinimum(hmin);
- gr->SetMaximum(hmax);
- fWalk.AddAtAndExpand(gr,i);
-
- //LED
- Int_t nbinsled= ledVScfd->GetXaxis()->GetNbins();
- cout<<" nbins led "<<nbinsled<<endl;
- TProfile *prledY = ledVScfd->ProfileX();
-
- Int_t npled = 0; //nbinsled/5;
- Double_t *xxled = new Double_t[nbinsled];
- Double_t *yyled = new Double_t[nbinsled];
- Int_t ngled=0;
- Double_t ygled=0;
- for (Int_t ip=1; ip<nbinsled; ip++)
- {
- if(ip%5 != 0 ) {
- if (prledY->GetBinContent(ip) !=0)
- ygled +=prledY->GetBinContent(ip);
- ngled++;}
- else {
- xxled[npled] = Float_t (prledY->GetBinCenter(ip));
- yyled[npled] = ygled/ngled;
- ygled=0;
- ngled=0;
- npled++;
+ for (Int_t imi=0; imi<nmips; imi++)
+ {
+ yy1[imi] = Float_t (mips[nmips-imi-1]);
+ xx1[imi] = x2[nmips-imi-1];
+ // cout<<" LED rev "<<i<<" "<<imi<<" "<<xx1[imi]<<" "<< yy1[imi]<<"nmips-imi-1 = "<< nmips-imi-1<<endl;
}
- }
-
- TGraph *grled = new TGraph(npled,xxled,yyled);
- grled->SetMinimum(hmin);
- grled->SetMaximum(hmax);
- fAmpLEDRec.AddAtAndExpand(grled,i);
-
- delete [] xx;
- delete [] yy;
- delete [] xxled;
- delete [] yyled;
- delete prY;
- delete prledY;
-
- // }
- delete cfd;
- delete qtcVScfd;
- delete ledVScfd;
- }
-
+
+ if(i==0) cout<<"Making graphs..."<<endl;
+
+ TGraph *grwalkqtc = new TGraph (nmips,x1,y1);
+ grwalkqtc->SetTitle(Form("PMT%i",i));
+ TGraph *grwalkled = new TGraph (nmips,x2,y1);
+ grwalkled->SetTitle(Form("PMT%i",i));
+ fWalk.AddAtAndExpand(grwalkqtc,i);
+ fAmpLEDRec.AddAtAndExpand(grwalkled,i);
+ // cout<<" add walk "<<i<<endl;
+
+ //fit amplitude graphs to make comparison wth new one
+ TGraph *grampled = new TGraph (nmips,xx1,yy1);
+ TGraph *grqtc = new TGraph (nmips,x1,xx);
+ fQTC.AddAtAndExpand(grqtc,i);
+ fAmpLED.AddAtAndExpand(grampled,i);
+ // cout<<" add amp "<<i<<endl;
+
+ if(i==23)
+ cout<<"Graphs created..."<<endl;
+ }
+ } //if gFile exits
+ return ok;
}
+
+
+