]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0CalibWalk.cxx
K0s analysis update (Matt Steinpreis)
[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 "AliLog.h"
26
27 #include <TObjArray.h>
28 #include <TGraph.h>
29 #include <TFile.h>
30 #include <TH2F.h> 
31 #include <TMath.h>
32 #include <TSystem.h>
33 #include <Riostream.h>
34 #include <TSpectrum.h>
35 #include <TProfile.h>
36 #include <TF1.h>
37
38 using std::cout;
39 using std::endl;
40 ClassImp(AliT0CalibWalk)
41
42 //________________________________________________________________
43   AliT0CalibWalk::AliT0CalibWalk():   TNamed(),
44                                       fWalk(0),
45                                       fAmpLEDRec(0),
46                                       fQTC(0),
47                                       fAmpLED(0)
48 {
49   //
50 }
51
52 //________________________________________________________________
53 AliT0CalibWalk::AliT0CalibWalk(const char* name):TNamed(),
54                                       fWalk(0),
55                                       fAmpLEDRec(0),                                                                  fQTC(0),
56                                       fAmpLED(0)
57     
58 {
59   TString namst = "Calib_";
60   namst += name;
61   SetName(namst.Data());
62   SetTitle(namst.Data());
63
64 }
65
66 //________________________________________________________________
67 AliT0CalibWalk::AliT0CalibWalk(const AliT0CalibWalk& calibda) :
68   TNamed(calibda),              
69   fWalk(0),
70   fAmpLEDRec(0),
71   fQTC(0),
72   fAmpLED(0)
73  
74 {
75 // copy constructor
76   SetName(calibda.GetName());
77   SetTitle(calibda.GetName());
78
79
80 }
81
82 //________________________________________________________________
83 AliT0CalibWalk &AliT0CalibWalk::operator =(const AliT0CalibWalk& calibda)
84 {
85 // assignment operator
86   SetName(calibda.GetName());
87   SetTitle(calibda.GetName());
88  
89   return *this;
90 }
91
92 //________________________________________________________________
93 AliT0CalibWalk::~AliT0CalibWalk()
94 {
95   //
96 }
97 //________________________________________________________________  
98
99 Bool_t AliT0CalibWalk::MakeWalkCorrGraph(const char *laserFile)
100 {
101   //make walk corerction for preprocessor
102   Float_t sigma,cfdmean, qtmean, ledmean;
103   Bool_t ok=true;
104   Float_t   mips[50];
105   
106   gFile = TFile::Open(laserFile);
107   if(!gFile) {
108     AliError("No input laser data found ");
109   }
110   else
111     {
112       //      gFile->ls();
113       TH1F* hAmp = (TH1F*) gFile->Get("hAmpLaser");
114       Int_t nmips=0;
115       for (Int_t ibin=0; ibin<2000; ibin++) {
116         Float_t bincont = hAmp->GetBinContent(ibin);
117         if(bincont>0){ 
118           mips[nmips] = hAmp->GetXaxis()->GetBinCenter(ibin);
119           cout<<ibin<<" bincont "<<bincont<<" amp "<< mips[nmips]<<endl;
120           nmips++;
121         }       
122       }    
123       
124       if (nmips<17) {
125         ok=false;
126         return ok;
127       } 
128        
129       Float_t x1[50], y1[50]; 
130       Float_t x2[50], xx2[50],y2[50];
131       Float_t xx1[50],yy1[50], xx[50];
132       
133       Float_t cfd0 = 0;
134       
135       for (Int_t ii=0; ii<nmips; ii++)
136         x1[ii] = y1[ii] = x2[ii] = y2[ii] = 0; 
137       
138       for (Int_t i=0; i<24; i++)
139         {
140           cfd0 = 0;
141           for (Int_t im=0; im<nmips; im++)
142             {         
143               TString cfd = Form("hCFD%i_%i",i+1,im+1);
144               TString qtc = Form("hQTC%i_%i",i+1,im+1);
145               TString led = Form("hLED%i_%i",i+1,im+1);
146               
147               TH1F *hCFD = (TH1F*) gFile->Get(cfd.Data()) ;
148               TH1F *hLED = (TH1F*) gFile->Get(led.Data());
149               TH1F *hQTC = (TH1F*) gFile->Get(qtc.Data()) ;
150               //              hCFD->SetDirectory(0);
151               //              hQTC->SetDirectory(0);
152               //              hLED->SetDirectory(0);
153               if(!hCFD )
154                 AliWarning(Form(" no CFD data in LASER DA for channel %i for amplitude %f MIPs",i,mips[im]));
155               if(!hQTC )
156                 AliWarning(Form(" no QTC correction data in LASER DA for channel %i for amplitude %f MIPs",i,mips[im]));
157               if(!hLED)       
158                 AliWarning(Form(" no LED correction data in LASER DA for channel %i for amplitude %f MIPs",i,mips[im]));
159               if( hCFD && hCFD->GetEntries()<500 ) {
160                 ok=false;
161                 printf("no peak in CFD spectrum for PMT %i amplitude %i\n",i,im);
162                 return ok;
163               }
164               if(hCFD && hCFD->GetEntries()>500 ) {
165                 if( hCFD->GetRMS() >= 1.5) 
166                   GetMeanAndSigma(hCFD, cfdmean, sigma);
167                 else
168                   cfdmean = hCFD->GetMean();
169                 
170                 Int_t   maxBin = hCFD->GetMaximumBin(); 
171                 Double_t  meanEstimate = hCFD->GetBinCenter( maxBin); 
172                 if(TMath::Abs(meanEstimate - cfdmean) > 20 ) cfdmean = meanEstimate; 
173                 if (im == 0) cfd0 = cfdmean;
174                 y1[im] =  cfdmean - cfd0;
175               } 
176               if(hQTC && hQTC->GetEntries()>500) {
177                 GetMeanAndSigma(hQTC, qtmean, sigma);
178                 
179                 x1[im] = qtmean;
180                 if( x1[im] == 0) {
181                   ok=false;
182                   printf("no peak in QTC signal for PMT %i amplitude %i\n",i,im);
183                   return ok;
184                 }
185               }
186                 
187               if( hLED && hLED->GetEntries()>500) {
188                 GetMeanAndSigma(hLED, ledmean, sigma);
189               }                            
190               else
191                 { 
192                   ok=false;
193                   printf("no peak in LED spectrum for PMT %i amplitude %i\n",i,im);
194                   return ok;
195                 }
196               x2[im] = ledmean;
197               xx2[im] = x2[nmips-im-1];
198                 
199                 xx[im]=mips[im];
200                 if (hQTC) delete  hQTC;
201                 if (hCFD) delete  hCFD;
202                 if (hLED) delete  hLED;
203                 
204             }
205           
206           for (Int_t imi=0; imi<nmips; imi++)
207             {
208               yy1[imi] = Float_t (mips[nmips-imi-1]);
209               xx1[imi] = x2[nmips-imi-1]; 
210               //              cout<<" LED rev "<<i<<" "<<imi<<" "<<xx1[imi]<<" "<< yy1[imi]<<"nmips-imi-1 = "<< nmips-imi-1<<endl;
211             }
212           
213           if(i==0) cout<<"Making graphs..."<<endl;
214           
215       TGraph *grwalkqtc = new TGraph (nmips,x1,y1);
216       grwalkqtc->SetTitle(Form("PMT%i",i));
217       TGraph *grwalkled = new TGraph (nmips,x2,y1);
218       grwalkled->SetTitle(Form("PMT%i",i));
219       fWalk.AddAtAndExpand(grwalkqtc,i);
220       fAmpLEDRec.AddAtAndExpand(grwalkled,i);
221       //          cout<<" add walk "<<i<<endl;
222       
223       //fit amplitude graphs to make comparison wth new one       
224       TGraph *grampled = new TGraph (nmips,xx1,yy1);
225       TGraph *grqtc = new TGraph (nmips,x1,xx);
226       fQTC.AddAtAndExpand(grqtc,i);      
227       fAmpLED.AddAtAndExpand(grampled,i);
228       //          cout<<" add amp "<<i<<endl;
229       
230       if(i==23)
231         cout<<"Graphs created..."<<endl;   
232         }
233     } //if gFile exits
234
235   return ok;
236 }
237
238 void AliT0CalibWalk::GetMeanAndSigma(TH1F* hist, Float_t &mean, Float_t &sigma) 
239 {
240
241   const double window = 2.;  //fit window 
242  
243   double meanEstimate, sigmaEstimate; 
244   int maxBin;
245   maxBin        =  hist->GetMaximumBin(); //position of maximum
246   meanEstimate  =  hist->GetBinCenter( maxBin); // mean of gaussian sitting in maximum
247   sigmaEstimate = hist->GetRMS();
248   TF1* fit= new TF1("fit","gaus", meanEstimate - window*sigmaEstimate, meanEstimate + window*sigmaEstimate);
249   fit->SetParameters(hist->GetBinContent(maxBin), meanEstimate, sigmaEstimate);
250   hist->Fit("fit","RQ","Q");
251
252   mean  = (Float_t) fit->GetParameter(1);
253   sigma = (Float_t) fit->GetParameter(2);
254   printf(" mean %f max %f sigma %f \n",mean, meanEstimate , sigma);  
255
256   delete fit;
257 }
258
259
260