]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0CalibWalk.cxx
Fix for compilation problem with icc.
[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 ClassImp(AliT0CalibWalk)
39
40 //________________________________________________________________
41   AliT0CalibWalk::AliT0CalibWalk():   TNamed(),
42                                       fWalk(0),
43                                       fAmpLEDRec(0),
44                                       fQTC(0),
45                                       fAmpLED(0)
46 {
47   //
48 }
49
50 //________________________________________________________________
51 AliT0CalibWalk::AliT0CalibWalk(const char* name):TNamed(),
52                                       fWalk(0),
53                                       fAmpLEDRec(0),                                                                  fQTC(0),
54                                       fAmpLED(0)
55     
56 {
57   TString namst = "Calib_";
58   namst += name;
59   SetName(namst.Data());
60   SetTitle(namst.Data());
61
62 }
63
64 //________________________________________________________________
65 AliT0CalibWalk::AliT0CalibWalk(const AliT0CalibWalk& calibda) :
66   TNamed(calibda),              
67   fWalk(0),
68   fAmpLEDRec(0),
69   fQTC(0),
70   fAmpLED(0)
71  
72 {
73 // copy constructor
74   SetName(calibda.GetName());
75   SetTitle(calibda.GetName());
76
77
78 }
79
80 //________________________________________________________________
81 AliT0CalibWalk &AliT0CalibWalk::operator =(const AliT0CalibWalk& calibda)
82 {
83 // assignment operator
84   SetName(calibda.GetName());
85   SetTitle(calibda.GetName());
86  
87   return *this;
88 }
89
90 //________________________________________________________________
91 AliT0CalibWalk::~AliT0CalibWalk()
92 {
93   //
94 }
95 //________________________________________________________________  
96
97 Bool_t AliT0CalibWalk::MakeWalkCorrGraph(const char *laserFile)
98 {
99   //make walk corerction for preprocessor
100   Int_t npeaks = 20;
101   Int_t sigma=3;
102   Bool_t down=false;
103   Int_t index[20];
104   Bool_t ok=true;
105   Float_t   mips[20];
106   Int_t nfound=0;
107   
108   gFile = TFile::Open(laserFile);
109   if(!gFile) {
110     AliError("No input laser data found ");
111   }
112   else
113     {
114       //      gFile->ls();
115       TH1F* hAmp = (TH1F*) gFile->Get("hAmpLaser");
116       Int_t nmips=0;
117       for (Int_t ibin=0; ibin<2000; ibin++) {
118         Float_t bincont = hAmp->GetBinContent(ibin);
119         if(bincont>0){ 
120           mips[nmips] = hAmp->GetXaxis()->GetBinCenter(ibin);
121           cout<<ibin<<" bincont "<<bincont<<" amp "<< mips[nmips]<<endl;
122           nmips++;
123         }       
124       }    
125       
126       if (nmips<17) {
127         ok=false;
128         return ok;
129       } 
130        
131       Float_t x1[50], y1[50]; 
132       Float_t x2[50], xx2[50],y2[50];
133       Float_t xx1[50],yy1[50], xx[50];
134       
135       Float_t cfd0[24];
136       Int_t startim = 0;
137       
138       for (Int_t ii=0; ii<nmips; ii++)
139         x1[ii] = y1[ii] = x2[ii] = y2[ii] = 0; 
140       
141       for (Int_t i=0; i<24; i++)
142         {
143           for (Int_t im=startim; im<nmips; im++)
144             {         
145               TString cfd = Form("hCFD%i_%i",i+1,im+1);
146               TString qtc = Form("hQTC%i_%i",i+1,im+1);
147               TString led = Form("hLED%i_%i",i+1,im+1);
148               
149               TH1F *hCFD = (TH1F*) gFile->Get(cfd.Data()) ;
150               TH1F *hLED = (TH1F*) gFile->Get(led.Data());
151               TH1F *hQTC = (TH1F*) gFile->Get(qtc.Data()) ;
152               hCFD->SetDirectory(0);
153               hQTC->SetDirectory(0);
154               hLED->SetDirectory(0);
155               if(!hCFD )
156                 AliWarning(Form(" no CFD data in LASER DA for channel %i for amplitude %f MIPs",i,mips[im]));
157               if(!hQTC )
158                 AliWarning(Form(" no QTC correction data in LASER DA for channel %i for amplitude %f MIPs",i,mips[im]));
159               if(!hLED)       
160                 AliWarning(Form(" no LED correction data in LASER DA for channel %i for amplitude %f MIPs",i,mips[im]));
161               
162               if(hCFD ) {
163                 TSpectrum *s = new TSpectrum(2*npeaks,1);
164                 nfound = s->Search(hCFD,sigma," ",0.1);
165                 if(nfound!=0){
166                   Float_t *xpeak = s->GetPositionX();
167                   TMath::Sort(nfound, xpeak, index,down);
168                   Float_t xp = xpeak[index[0]];
169                   Double_t hmax = xp+3*sigma;
170                   Double_t hmin = xp-3*sigma;
171                   hCFD->GetXaxis()->SetRangeUser(hmin-10,hmax+10);
172                 }
173                 else
174                   {
175                     hCFD->Rebin(2);
176                     TSpectrum *s1 = new TSpectrum(2*npeaks,1);
177                     nfound = s1->Search(hCFD,sigma," ",0.1);
178                     if(nfound!=0){
179                       Float_t *xpeak = s1->GetPositionX();
180                       TMath::Sort(nfound, xpeak, index,down);
181                       Float_t xp = xpeak[index[0]];
182                       Double_t hmax = xp+3*sigma;
183                       Double_t hmin = xp-3*sigma;
184                       hCFD->GetXaxis()->SetRangeUser(hmin-10,hmax+10);
185                     }
186                     else 
187                       {
188                         ok=false;
189                         printf("no peak in CFD spectrum for PMT %i amplitude %i\n",i,im);
190                         return ok;
191                       }
192
193                   }
194
195                 if (im == 0) cfd0[i] = hCFD->GetMean();
196                 y1[im] =  hCFD->GetMean() - cfd0[i];
197               }
198               if( hQTC) {
199                 x1[im] = hQTC->GetMean();
200                 if( x1[im] == 0) {
201                   ok=false;
202                   printf("no peak in QTC signal for PMT %i amplitude %i\n",i,im);
203                   return ok;
204                   }
205               }
206               
207               if( hLED){
208                 TSpectrum *s = new TSpectrum(2*npeaks,1);
209                 nfound = s->Search(hLED,sigma," ",0.1);
210                 if(nfound!=0){
211                   Float_t *xpeak = s->GetPositionX();
212                   TMath::Sort(nfound, xpeak, index,down);
213                   Float_t xp = xpeak[index[0]];
214                   Double_t hmax = xp+10*sigma;
215                   Double_t hmin = xp-10*sigma;
216                   hLED->GetXaxis()->SetRangeUser(hmin-10,hmax+10);
217                 }
218                 else
219                   { 
220                     ok=false;
221                     printf("no peak in LED spectrum for PMT %i amplitude %i\n",i,im);
222                     return ok;
223                   }
224                 x2[im] = hLED->GetMean();
225                 xx2[im] = x2[nmips-im-1];
226               }
227               xx[im]=mips[im];
228               
229               if (hQTC) delete  hQTC;
230               if (hCFD) delete  hCFD;
231               if (hLED) delete  hLED;
232             }
233           
234           for (Int_t imi=0; imi<nmips; imi++)
235             {
236               yy1[imi] = Float_t (mips[nmips-imi-1]);
237               xx1[imi] = x2[nmips-imi-1]; 
238               //              cout<<" LED rev "<<i<<" "<<imi<<" "<<xx1[imi]<<" "<< yy1[imi]<<"nmips-imi-1 = "<< nmips-imi-1<<endl;
239             }
240           
241           if(i==0) cout<<"Making graphs..."<<endl;
242           
243           
244           /*
245           
246           
247           Float_t x1[50], y1[50]; 
248           Float_t x2[50], xx2[50],y2[50];
249           Float_t xx1[50],yy1[50], xx[50];
250           
251           Int_t nmips=20;
252           for (Int_t i=0; i<24; i++)
253           {
254  
255           for (Int_t im=0; im<nmips; im++)
256           {
257           x1[im]=xx[im]=500+im*200;
258           y1[im]=0;
259           x2[im]=xx1[im]=yy1[im]=260+20*im;
260           } 
261           */      
262        TGraph *grwalkqtc = new TGraph (nmips,x1,y1);
263       grwalkqtc->SetTitle(Form("PMT%i",i));
264       TGraph *grwalkled = new TGraph (nmips,x2,y1);
265       grwalkled->SetTitle(Form("PMT%i",i));
266       fWalk.AddAtAndExpand(grwalkqtc,i);
267       fAmpLEDRec.AddAtAndExpand(grwalkled,i);
268       //          cout<<" add walk "<<i<<endl;
269       
270       //fit amplitude graphs to make comparison wth new one       
271       TGraph *grampled = new TGraph (nmips,xx1,yy1);
272       TGraph *grqtc = new TGraph (nmips,x1,xx);
273       fQTC.AddAtAndExpand(grqtc,i);      
274       fAmpLED.AddAtAndExpand(grampled,i);
275       //          cout<<" add amp "<<i<<endl;
276       
277       if(i==23)
278         cout<<"Graphs created..."<<endl;
279         }
280     } //if gFile exits
281
282   return ok;
283 }
284
285
286
287