]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSCalibrator.cxx
Reconstruction of ESD data implemented
[u/mrichter/AliRoot.git] / PHOS / AliPHOSCalibrator.cxx
CommitLineData
a6edf90e 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
702ab87e 16/* $Id$ */
17
18/* History of cvs commits:
19 *
20 * $Log$
3f7dbdb7 21 * Revision 1.11 2006/01/13 16:59:39 kharlov
22 * Rename classes to read raw data 2004
23 *
45e334f8 24 * Revision 1.10 2005/05/28 14:19:04 schutz
25 * Compilation warnings fixed by T.P.
26 *
702ab87e 27 */
a6edf90e 28
29//_________________________________________________________________________
30// Class to calculate calibration parameters from beam tests etc.
31// First pass - one should calcuate pedestals, in the second pass - gains.
32//
33// To calculate pedestals we scan pedestals events and fill histos for each
34// channel. Then in each histo we find maximum and fit it with Gaussian in the
35// visinity of the maximum. Extracted mean and width of distribution are put into
36// resulting histogram which cheks results for 'reasonability'.
37//
38// To evaluate gains: scans beam events and calculate gain in the cristall with
39// maximal energy deposition, assuming, that 90% of energy deposited in it.
40// For each channel separate histogramm is filled. When scan is finished,
41// these histograms are fitted with Gaussian and finds mean and width, which
42// are put in final histogram. Finaly gains are checked for deviation from mean.
43
44// Finally fills database.
45//
46// Use Case:
47// AliPHOSCalibrator * c = new AliPHOSCalibrator("path/galice.root") ;
48// c->AddRun("path2/galice.root") ;
49// c->ScanPedestals();
50// c->CalculatePedestals();
51// c->WritePedestals();
52// c->ScanGains() ;
53// c->CalculateGains() ;
54// c->WriteGains() ;
55//
56//*-- Author : D.Peressounko (RRC KI)
57//////////////////////////////////////////////////////////////////////////////
58
59// --- ROOT system ---
a6edf90e 60#include "TF1.h"
024a7e64 61#include "TFile.h"
a6edf90e 62#include "TObjString.h"
024a7e64 63#include "TROOT.h"
9b471956 64#include "TClonesArray.h"
e957fea8 65
a6edf90e 66// --- Standard library ---
67
68// --- AliRoot header files ---
6f06e050 69#include "AliLog.h"
a6edf90e 70#include "AliPHOSCalibrManager.h"
71#include "AliPHOSCalibrationData.h"
024a7e64 72#include "AliPHOSCalibrator.h"
73#include "AliPHOSConTableDB.h"
3255d660 74#include "AliRawReaderDate.h"
45e334f8 75#include "AliPHOSRawStream2004.h"
9b471956 76#include "AliPHOSDigit.h"
a6edf90e 77
3255d660 78#ifdef ALI_DATE
79#include "event.h"
80#else
81#define PHYSICS_EVENT 7
82#endif
83
a6edf90e 84ClassImp(AliPHOSCalibrator)
85
86
87//____________________________________________________________________________
3f7dbdb7 88AliPHOSCalibrator::AliPHOSCalibrator() :
89 TTask("AliPHOSCalibrator","Default"),
90 fRunList(0),
91 fPedHistos(0),
92 fGainHistos(0),
93 fhPedestals(0),
94 fhPedestalsWid(0),
95 fhGains(0),
96 fhGainsWid(0),
97 fctdb(0),
98 fConTableDB("Beamtest2002"),
99 fConTableDBFile("ConTableDB.root"),
100 fBeamEnergy(0),
101 fGainAcceptCorr(0),
102 fAcceptCorr(0),
103 fGainMax(0),
104 fNGainBins(0),
105 fNch(0),
106 fNChan(0)
a6edf90e 107{
108 //Default constuctor for root. Normally should not be used
a6edf90e 109}
3f7dbdb7 110
a6edf90e 111//____________________________________________________________________________
88cb7938 112AliPHOSCalibrator::AliPHOSCalibrator(const char* file, const char* title):
3f7dbdb7 113 TTask("AliPHOSCalibrator",title),
114 fRunList(new TList),
115 fPedHistos(0),
116 fGainHistos(0),
117 fhPedestals(0),
118 fhPedestalsWid(0),
119 fhGains(0),
120 fhGainsWid(0),
121 fctdb(0),
122 fConTableDB("Beamtest2002"),
123 fConTableDBFile("ConTableDB.root"),
124 fBeamEnergy(10.),
125 fGainAcceptCorr(5),
126 fAcceptCorr(10),
127 fGainMax(0.1),
128 fNGainBins(100),
129 fNch(0),
130 fNChan(100)
131
00953b03 132{
133 //Constructor which should normally be used.
a6edf90e 134 //file: path/galice.root - header file
135 //title: branch name of PHOS reconstruction (e.g. "Default")
3f7dbdb7 136 fRunList->SetOwner();
137 fRunList->Add(new TObjString(file));
138}
a6edf90e 139
3f7dbdb7 140//____________________________________________________________________________
141AliPHOSCalibrator::AliPHOSCalibrator(const AliPHOSCalibrator & ctor) :
142 TTask(ctor),
143 fRunList(0),
144 fPedHistos(0),
145 fGainHistos(0),
146 fhPedestals(0),
147 fhPedestalsWid(0),
148 fhGains(0),
149 fhGainsWid(0),
150 fctdb(0),
151 fConTableDB("Beamtest2002"),
152 fConTableDBFile("ConTableDB.root"),
153 fBeamEnergy(0),
154 fGainAcceptCorr(0),
155 fAcceptCorr(0),
156 fGainMax(0),
157 fNGainBins(0),
158 fNch(0),
159 fNChan(0)
160{
161 // cpy ctor: no implementation yet
162 // requested by the Coding Convention
163 Fatal("cpy ctor", "not implemented") ;
a6edf90e 164}
165
166//____________________________________________________________________________
167 AliPHOSCalibrator::~AliPHOSCalibrator()
168{
00953b03 169 // dtor
a6edf90e 170 if(fPedHistos)
171 delete fPedHistos ;
172 if(fGainHistos)
173 delete fGainHistos ;
174 if(fhPedestals)
175 delete fhPedestals ;
176 if(fhPedestalsWid)
177 delete fhPedestalsWid ;
178 if(fctdb)
179 delete fctdb ;
180 if(fRunList)
181 delete fRunList ;
182}
183//____________________________________________________________________________
00953b03 184void AliPHOSCalibrator::AddRun(const char * filename)
185{
a6edf90e 186 //Adds one more run to list of runs, which will be scanned in ScanXXX methods
187
188 TObjString * fn = new TObjString(filename) ;
189 if(!fRunList){
190 fRunList=new TList() ;
191 fRunList->SetOwner() ;
192 fRunList->Add(fn) ;
193 return ;
194 }
195 else{
196 TIter next(fRunList) ;
197 TObjString * r ;
198 while((r=(TObjString *)(next()))){
199 if(fn->String().CompareTo(r->String())==0){
6f06e050 200 AliError(Form("Run already in list: %s",filename)) ;
a6edf90e 201 return ;
202 }
203 }
204 fRunList->Add(fn) ;
205 }
206
207}
208//____________________________________________________________________________
209void AliPHOSCalibrator::Exec(Option_t * option)
210{
00953b03 211 // reads parameters and does the calibration
a6edf90e 212 ScanPedestals(option);
213 CalculatePedestals();
214 WritePedestals();
215 ScanGains(option) ;
216 CalculateGains() ;
217 WriteGains() ;
218}
219//____________________________________________________________________________
00953b03 220void AliPHOSCalibrator::Init(void)
221{
222 // intializes everything
a6edf90e 223
224 //check if ConTableDB already read
225 if(!fctdb){
9b471956 226 SetConTableDB(fConTableDBFile) ;
a6edf90e 227 }
228
229 fNch = fctdb->GetNchanels() ;
230 fhPedestals = new TH1F("hPedestals","Pedestals mean",fNch,0.,fNch) ;
231 fhPedestalsWid= new TH1F("hPedestalsWid","Pedestals width",fNch,0.,fNch) ;
232 fhGains = new TH1F("hGains","Gains ",fNch,0.,fNch) ;
233 fhGainsWid = new TH1F("hGainsWid","Gains width",fNch,0.,fNch) ;
234}
235//____________________________________________________________________________
00953b03 236void AliPHOSCalibrator::SetConTableDB(const char * file,const char * name)
237{
a6edf90e 238 //Reads Connection Table database with name "name" from file "file"
239
240 if(file==0 || name == 0){
6f06e050 241 AliError(Form("Please, specify file with database and its title")) ;
a6edf90e 242 return ;
243 }
244 if(fctdb && strcmp(fctdb->GetTitle(),name)==0) //already read
245 return ;
246
247 //else read new one
248 if(fctdb){
249 delete fctdb ;
250 fctdb = 0;
251 }
252
253 TFile * v = gROOT->GetFile(fConTableDBFile) ;
254 if(!v)
255 v = TFile::Open(fConTableDBFile) ;
256 if(!v){
6f06e050 257 AliError(Form("Can not open file with Connection Table DB: %s",fConTableDBFile.Data())) ;
a6edf90e 258 return ;
259 }
9b471956 260 fctdb = new AliPHOSConTableDB(*(dynamic_cast<AliPHOSConTableDB *>(v->Get("AliPHOSConTableDB")))) ;
261 v->Close() ;
a6edf90e 262
263}
264//____________________________________________________________________________
00953b03 265void AliPHOSCalibrator::PlotPedestal(Int_t chanel)
266{
a6edf90e 267 //Plot histogram for a given channel, filled in Scan method
268 if(fPedHistos && fPedHistos->GetEntriesFast()){
269 static_cast<TH1F*>(fPedHistos->At(chanel))->Draw() ;
270 }
271 else{
6f06e050 272 AliInfo(Form("Histograms not created yet! \n")) ;
a6edf90e 273 }
274}
275//____________________________________________________________________________
00953b03 276void AliPHOSCalibrator::PlotPedestals(void)
277{
278 // draws pedestals distribution
a6edf90e 279 fhPedestals->Draw() ;
280}
281//____________________________________________________________________________
00953b03 282void AliPHOSCalibrator::PlotGain(Int_t chanel)
283{
a6edf90e 284 //Plot histogram for a given channel, filled in Scan method
285 if(fGainHistos && fGainHistos->GetEntriesFast()){
286 static_cast<TH1F*>(fGainHistos->At(chanel))->Draw() ;
287 }
288 else{
6f06e050 289 AliInfo(Form("Histograms not created yet! \n")) ;
a6edf90e 290 }
291}
292//____________________________________________________________________________
00953b03 293void AliPHOSCalibrator::PlotGains(void)
294{
295 // draws gains distribution
a6edf90e 296 fhGains->Draw() ;
297}
298//____________________________________________________________________________
00953b03 299void AliPHOSCalibrator::ScanPedestals(Option_t * option )
300{
a6edf90e 301 //scan all files in list fRunList and fill pedestal hisgrams
302 //option: "clear" - clear pedestal histograms filled up to now
303 // "deb" - plot file name currently processed
304
305 if(!fctdb)
306 Init() ;
307
308 if(fPedHistos && strstr(option,"clear"))
309 fPedHistos->Delete() ;
310 if(!fPedHistos)
311 fPedHistos = new TObjArray(fNch) ;
312
313 //Create histos for each channel, fills them and extracts mean values.
314 //First - prepare histos
315 Int_t ich ;
316 for(ich=0;ich<fNch ;ich++){
317 TH1F * h = static_cast<TH1F *>(fPedHistos->At(ich)) ;
318 if(!h ){
319 TString n("hPed");
320 n+=ich ;
321 TString name("Pedestal for channel ") ;
322 name += ich ;
323 fPedHistos->AddAt(new TH1F(n,name,fNChan,0,fNChan),ich) ;
324 }
325 }
326
327 TIter next(fRunList) ;
328 TObjString * file ;
329 while((file = static_cast<TObjString *>(next()))){
330 if(strstr(option,"deb"))
331 printf("Processing file %s \n ",file->String().Data()) ;
6f06e050 332
9b471956 333 //Now open data file
3255d660 334 AliRawReaderDate *rawReader = new AliRawReaderDate(file->String().Data()) ;
45e334f8 335 AliPHOSRawStream2004 *rawStream = new AliPHOSRawStream2004(rawReader) ;
9b471956 336 rawStream->SetConTableDB(fctdb) ;
337 TClonesArray * digits = new TClonesArray("AliPHOSDigit",300) ;
338 Int_t nevents=0 ;
339 //Scan all event in file
340 while(rawReader->NextEvent()){
341 //Is it PHYSICAL event
342 if(rawReader->GetType() == PHYSICS_EVENT){
343 nevents++ ;
344 if(rawStream->ReadDigits(digits)){
345 if(rawStream->IsPEDevent()){
346 for(Int_t idigit = 0; idigit<digits->GetEntriesFast() ; idigit++){
347 AliPHOSDigit * digit = static_cast<AliPHOSDigit *>(digits->At(idigit) ) ;
348 ich = fctdb->AbsId2Raw(digit->GetId());
349 if(ich>=0){
350 Float_t amp = digit->GetAmp() ;
351 TH1F * hh = dynamic_cast<TH1F*>(fPedHistos->At(ich)) ;
352 hh->Fill(amp) ;
353 }
354 }
a6edf90e 355 }
356 }
357 }
358 }
9b471956 359 if(strstr(option,"deb"))
6f06e050 360 AliInfo(Form(" found %d events \n ",nevents)) ;
9b471956 361 delete rawStream ;
362 delete rawReader ;
363 delete digits ;
364 }
a6edf90e 365}
366//____________________________________________________________________________
00953b03 367void AliPHOSCalibrator::CalculatePedestals()
368{
a6edf90e 369 //Fit histograms, filled in ScanPedestals method with Gaussian
370 //find mean and width, check deviation from mean for each channel.
371
372 if(!fPedHistos || !fPedHistos->At(0)){
6f06e050 373 AliError(Form("You should run ScanPedestals first!")) ;
a6edf90e 374 return ;
375 }
376
377 //Now fit results with Gauss
378 TF1 * gs = new TF1("gs","gaus",0.,10000.) ;
379 Int_t ich ;
380 for(ich=0;ich<fNch ;ich++){
381 TH1F * h = static_cast<TH1F *>(fPedHistos->At(ich)) ;
382 Int_t max = h->GetMaximumBin() ;
383 Axis_t xmin = max/2. ;
384 Axis_t xmax = max*3/2 ;
385 gs->SetRange(xmin,xmax) ;
386 Double_t par[3] ;
387 par[0] = h->GetBinContent(max) ;
388 par[1] = max ;
389 par[2] = max/3 ;
390 gs->SetParameters(par[0],par[1],par[2]) ;
391 h->Fit("gs","QR") ;
392 gs->GetParameters(par) ;
393 fhPedestals->SetBinContent(ich,par[1]) ;
394 fhPedestals->SetBinError(ich,par[2]) ;
395 fhPedestalsWid->Fill(ich,par[2]) ;
396 }
397 delete gs ;
398
399 //now check reasonability of results
400 TF1 * p0 = new TF1("p0","pol0",0.,fNch) ;
401 fhPedestals->Fit("p0","Q") ;
402 Double_t meanPed ;
403 p0->GetParameters(&meanPed);
404 for(ich=0;ich<fNch ;ich++){
405 Float_t ped = fhPedestals->GetBinContent(ich) ;
406 if(ped < 0 || ped > meanPed+fAcceptCorr){
407 TString out("Pedestal of channel ") ;
408 out+=ich ;
409 out+=" is ";
410 out+= ped ;
411 out+= "it is too far from mean " ;
412 out+= meanPed ;
6f06e050 413 AliError(Form("PHOSCalibrator %s",out.Data())) ;
a6edf90e 414 }
415 }
416 delete p0 ;
417
418}
419//____________________________________________________________________________
00953b03 420void AliPHOSCalibrator::ScanGains(Option_t * option)
421{
a6edf90e 422 //Scan all runs, listed in fRunList and fill histograms for all channels
423 //options: "clear" - clean histograms, filled up to now
424 // "deb" - print current file name
425 // "narrow" - scan only narrow beam events
426
427 if(!fctdb)
428 Init() ;
429 if(fGainHistos && strstr(option,"clear"))
430 fGainHistos->Delete() ;
431 if(!fGainHistos){
432 if(strstr(option,"deball"))
6f06e050 433 AliInfo(Form("creating array for %d channels \n",fNch)) ;
a6edf90e 434 fGainHistos = new TObjArray(fNch) ;
435 }
436
437 //Create histos for each channel, fills them and extracts mean values.
438 //First - prepare histos
439
440 if(!fGainHistos->GetEntriesFast()){
441 Int_t ich ;
442 for(ich=0;ich<fNch ;ich++){
443 TString n("hGain");
444 n+=ich ;
445 TString name("Gains for channel ") ;
446 name += ich ;
447 fGainHistos->AddAt(new TH1F(n,name,fNGainBins,0,fGainMax),ich) ;
448 // static_cast<TH1F*>(fGainHistos->At(ich))->Sumw2() ;
449 }
450 }
451
a6edf90e 452 TIter next(fRunList) ;
453 TObjString * file ;
454 while((file = static_cast<TObjString *>(next()))){
9b471956 455 //Now open data file
3255d660 456 AliRawReaderDate *rawReader = new AliRawReaderDate(file->String().Data()) ;
45e334f8 457 AliPHOSRawStream2004 *rawStream = new AliPHOSRawStream2004(rawReader) ;
9b471956 458 rawStream->SetConTableDB(fctdb) ;
459
460 TClonesArray * digits = new TClonesArray("AliPHOSDigit",300) ;
461 Int_t nevents=0 ;
462 //Scan all event in file
463 while(rawReader->NextEvent()){
464 //Is it PHYSICAL event
465 if(rawReader->GetType() == PHYSICS_EVENT){
466 if(rawStream->ReadDigits(digits)){
467 //Test trigger
468 if(rawStream->IsNELevent() || rawStream->IsWELevent()){
469 nevents ++ ;
470 AliPHOSDigit * digit ;
471 Int_t max = 0 ;
472 Int_t imax = 0;
473 for(Int_t idigit = 0; idigit<digits->GetEntriesFast() ; idigit++){
474 digit = static_cast<AliPHOSDigit *>(digits->At(idigit) ) ;
475 if(digit->GetAmp() > max){
476 imax = idigit ;
477 max = digit->GetAmp() ;
478 }
479 }
480 digit = static_cast<AliPHOSDigit *>(digits->At(imax) ) ;
481 Int_t ich = fctdb->AbsId2Raw(digit->GetId());
482 if(ich>=0){
483 Float_t pedestal = fhPedestals->GetBinContent(ich) ;
484 const Float_t kshowerInCrystall = 0.9 ;
485 Float_t gain = fBeamEnergy*kshowerInCrystall/
486 (digit->GetAmp() - pedestal) ;
487 static_cast<TH1F*>(fGainHistos->At(ich))->Fill(gain) ;
488 }
a6edf90e 489 }
490 }
a6edf90e 491 }
492 }
9b471956 493 delete rawReader ;
494 delete rawStream ;
495 delete digits ;
6f06e050 496 if(strstr(option,"deb"))
497 AliInfo(Form(" found %d events \n",nevents)) ;
a6edf90e 498 }
499}
500//____________________________________________________________________________
00953b03 501void AliPHOSCalibrator::CalculateGains(void)
502{
503 //calculates gain
a6edf90e 504
505 if(!fGainHistos || !fGainHistos->GetEntriesFast()){
6f06e050 506 AliError(Form("You should run ScanGains first!")) ;
a6edf90e 507 return ;
508 }
509
510 //Fit results with Landau
511 TF1 * gs = new TF1("gs","landau",0.,10000.) ;
512 Int_t ich ;
513 for(ich=0;ich<fNch ;ich++){
514 TH1F * h = static_cast<TH1F *>(fGainHistos->At(ich)) ;
515 Int_t bmax = h->GetMaximumBin() ;
516 Axis_t center = h->GetBinCenter(bmax) ;
517 Axis_t xmin = center - 0.01 ;
518 Axis_t xmax = center + 0.02 ;
519 gs->SetRange(xmin,xmax) ;
520 Double_t par[3] ;
521 par[0] = h->GetBinContent(bmax) ;
522 par[1] = center ;
523 par[2] = 0.001 ;
524 gs->SetParameters(par[0],par[1],par[2]) ;
525 h->Fit("gs","QR") ;
526 gs->GetParameters(par) ;
527 fhGains->SetBinContent(ich,par[1]) ;
528 fhGains->SetBinError(ich,par[2]) ;
529 fhGainsWid->Fill(ich,par[2]) ;
530 }
531 delete gs ;
532
533 //now check reasonability of results
534 TF1 * p0 = new TF1("p0","pol0",0.,fNch) ;
535 fhGains->Fit("p0","Q") ;
536 Double_t meanGain ;
537 p0->GetParameters(&meanGain);
538 for(ich=0;ich<fNch ;ich++){
539 Float_t gain = fhGains->GetBinContent(ich) ;
540 if(gain < meanGain/fGainAcceptCorr || gain > meanGain*fGainAcceptCorr){
541 TString out("Gain of channel ") ;
542 out+=ich ;
543 out+=" is ";
544 out+= gain ;
545 out+= "it is too far from mean " ;
546 out+= meanGain ;
6f06e050 547 AliError(Form("PHOSCalibrator %s",out.Data())) ;
a6edf90e 548 }
549 }
550 delete p0 ;
551
552}
9b471956 553//____________________________________________________________________________
554void AliPHOSCalibrator::ReadFromASCII(const char * filename){
555// We read pedestals and gains from *.dat file with following format:
556// 0 0 0 0 37.09 1972. // next nmodrows*nmodcols*ncryrows*ncrycols lines
557// 0 0 0 1 28.53 2072. // contains <RR CC r c ped peak>
558// 0 0 0 2 30.93 1938. //
559// where module is an array of 8*8 crystals and RR and CC are module raw and column position
560 FILE * file = fopen(filename, "r");
561 if (!file) {
562 Error("ReadFromASCII", "could not open file %s", filename);
563 return;
564 }
565 if(!fctdb || !fhPedestals || !fhGains){
566 Init() ;
567 }
568 else{
569 //Clean Hitograms
570 Reset() ;
571 }
a6edf90e 572
9b471956 573 Int_t modRaw,modCol,raw,col;
574 Float_t ped,pik;
575 Int_t nread = 0 ;
576 while(fscanf(file,"%d %d %d %d %f %f",&modRaw,&modCol,&raw,&col,&ped,&pik)==6){
577 //Calculate plain crystal position:
578 Int_t rawPosition = (modRaw*8+raw)*fctdb->GetNColumns()+modCol*8+col ;
579 fhPedestals->SetBinContent(rawPosition,ped) ;
580 if(pik!=0.)
581 fhGains->SetBinContent(rawPosition,1./pik);
582 else
583 fhGains->SetBinContent(rawPosition,0.);
584 nread++ ;
585 }
586 if(nread != fctdb->GetNColumns()*fctdb->GetNRaws()){
587 Error("ReadFromASCII","Read %d parameters instead of %d\n",nread,fctdb->GetNColumns()*fctdb->GetNRaws()) ;
588 }
589 fclose(file) ;
590}
a6edf90e 591//_____________________________________________________________________________
9b471956 592void AliPHOSCalibrator::WritePedestals(const char * version)
00953b03 593{
a6edf90e 594 //Write calculated data to file using AliPHOSCalibrManager
595 //version and validitirange (begin-end) will be used to identify data
596
597 if(!fctdb){
6f06e050 598 AliError(Form("\n Please, supply Connection Table DB (use SetConTableDB()) \n" )) ;
a6edf90e 599 return ;
600 }
601 //fill data
602 AliPHOSCalibrationData ped("Pedestals",version);
603 for(Int_t i=0; i<fNch;i++){
604 Int_t absid=fctdb->Raw2AbsId(i) ;
605 ped.SetData(absid,fhPedestals->GetBinContent(i)) ;
606 ped.SetDataCheck(absid,fhPedestalsWid->GetBinContent(i)) ;
607 }
608
9b471956 609// //evaluate validity range
610// if(begin==0){
611// TIter next(fRunList) ;
612// Int_t ibegin=99999;
613// Int_t iend=0 ;
614// TObjString * file ;
615// while((file=((TObjString*)next()))){
616// TString s = file->GetString() ;
617// TString ss = s(s.Last('_'),s.Last('.'));
618// Int_t tmp ;
619// if(sscanf(ss.Data(),"%d",&tmp)){
620// if(ibegin<tmp)
621// ibegin=tmp ;
622// if(iend>tmp)
623// iend=tmp ;
624// }
625// }
626// ped.SetValidityRange(ibegin,iend) ;
627// }
628// else
629// ped.SetValidityRange(begin,end) ;
a6edf90e 630
631 //check, may be Manager instance already configured?
632 AliPHOSCalibrManager * cmngr = AliPHOSCalibrManager::GetInstance() ;
633 if(!cmngr){
6f06e050 634 AliWarning(Form("Using database file 'PHOSBTCalibration.root'")) ;
a6edf90e 635 cmngr = AliPHOSCalibrManager::GetInstance("PHOSBTCalibration.root") ;
636 }
9b471956 637 cmngr->WriteData(ped) ;
a6edf90e 638}
639//_____________________________________________________________________________
9b471956 640void AliPHOSCalibrator::ReadPedestals(const char * version)
00953b03 641{
642 //Read data from file using AliPHOSCalibrManager
a6edf90e 643 //version and range will be used to choose proper data
644
645 AliPHOSCalibrationData ped("Pedestals",version);
646 AliPHOSCalibrManager * cmngr = AliPHOSCalibrManager::GetInstance() ;
647 if(!cmngr){
6f06e050 648 AliWarning(Form("Using database file 'PHOSBTCalibration.root'")) ;
a6edf90e 649 cmngr = AliPHOSCalibrManager::GetInstance("PHOSBTCalibration.root") ;
650 }
9b471956 651 cmngr->GetParameters(ped) ;
a6edf90e 652 Int_t npeds=ped.NChannels() ;
653 fNch = fctdb->GetNchanels() ;
654 if(fhPedestals)
655 delete fhPedestals ;
656 fhPedestals = new TH1F("hPedestals","Pedestals mean",fNch,0.,fNch) ;
657 for(Int_t i=0;i<npeds;i++){
658 Int_t raw =fctdb->AbsId2Raw(i) ;
659 if(raw){
660 fhPedestals->SetBinContent(raw-1,ped.Data(i)) ;
661 fhPedestals->SetBinError(raw-1,ped.DataCheck(i)) ;
662 }
663 }
664}
665//_____________________________________________________________________________
9b471956 666void AliPHOSCalibrator::ReadGains(const char * version)
00953b03 667{
668 //Read data from file using AliPHOSCalibrManager
a6edf90e 669 //version and range will be used to choose proper data
670
671 AliPHOSCalibrationData gains("Gains",version);
672 AliPHOSCalibrManager * cmngr = AliPHOSCalibrManager::GetInstance() ;
673 if(!cmngr){
6f06e050 674 AliWarning(Form("Using database file 'PHOSBTCalibration.root'")) ;
a6edf90e 675 cmngr = AliPHOSCalibrManager::GetInstance("PHOSBTCalibration.root") ;
676 }
9b471956 677 cmngr->GetParameters(gains) ;
a6edf90e 678 Int_t npeds=gains.NChannels() ;
679 fNch = fctdb->GetNchanels() ;
680 if(fhGains)
681 delete fhGains ;
682 fhGains = new TH1F("hGainss","Gains mean",fNch,0.,fNch) ;
683 for(Int_t i=0;i<npeds;i++){
684 Int_t raw =fctdb->AbsId2Raw(i) ;
685 if(raw){
686 fhGains->SetBinContent(raw-1,gains.Data(i)) ;
687 fhGains->SetBinError(raw-1,gains.DataCheck(i)) ;
688 }
689 }
690}
691//_____________________________________________________________________________
9b471956 692void AliPHOSCalibrator::WriteGains(const char * version)
00953b03 693{
694 //Write gains through AliPHOSCalibrManager
a6edf90e 695 //version and validity range(begin-end) are used to identify data
696
697 if(!fctdb){
6f06e050 698 AliError(Form("\n Please, supply Connection Table DB (use SetConTableDB()) \n" )) ;
a6edf90e 699 return ;
700 }
701
702 AliPHOSCalibrationData gains("Gains",version);
703 for(Int_t i=0; i<fNch;i++){
704 Int_t absid=fctdb->Raw2AbsId(i) ;
705 gains.SetData(absid,fhGains->GetBinContent(i)) ;
706 gains.SetDataCheck(absid,fhGainsWid->GetBinContent(i)) ;
707 }
9b471956 708// if(begin==0){
709// TIter next(fRunList) ;
710// Int_t ibegin=99999;
711// Int_t iend=0 ;
712// TObjString * file ;
713// while((file=((TObjString*)next()))){
714// TString s = file->GetString() ;
715// TSubString ss = s(s.Last('_'),s.Last('.'));
716// Int_t tmp ;
717// if(sscanf(ss.Data(),"%d",&tmp)){
718// if(ibegin<tmp)
719// ibegin=tmp ;
720// if(iend>tmp)
721// iend=tmp ;
722// }
723// }
724// gains.SetValidityRange(ibegin,iend) ;
725// }
726// else
727// gains.SetValidityRange(begin,end) ;
a6edf90e 728 AliPHOSCalibrManager * cmngr = AliPHOSCalibrManager::GetInstance() ;
729 if(!cmngr){
6f06e050 730 AliWarning(Form("Using database file 'PHOSBTCalibration.root'")) ;
a6edf90e 731 cmngr = AliPHOSCalibrManager::GetInstance("PHOSBTCalibration.root") ;
732 }
9b471956 733 cmngr->WriteData(gains) ;
a6edf90e 734}
735//_____________________________________________________________________________
702ab87e 736void AliPHOSCalibrator::Print(const Option_t *)const
00953b03 737{
738 // prints everything
6f06e050 739 AliInfo(Form("--------------PHOS Calibrator-----------------\n")) ;
a6edf90e 740 printf("Files to handle:\n") ;
741 TIter next(fRunList) ;
742 TObjString * r ;
743 while((r=(TObjString *)(next())))
744 printf(" %s\n",r->GetName()) ;
745
746 printf("Name of ConTableDB:.....................%s\n",fConTableDB.Data()) ;
747 printf("File of ConTableDB:.....................%s\n",fConTableDBFile.Data() ) ;
748 printf("Maximal deviation from mean Gain (factor):.%f\n",fGainAcceptCorr) ;
749 printf("Maximal deviation of Pedestal from mean:...%f\n",fAcceptCorr) ;
750 printf("Range used in Gain histos:..............%f\n",fGainMax) ;
751 printf("Number of bins in Gain histos:..........%d\n",fNGainBins) ;
752 printf("Number of channels to calibrate:........%d\n",fNch) ;
753 printf("Number of bins in pedestal histos:......%d\n",fNChan) ;
a6edf90e 754 printf("--------------------------------------------------\n") ;
755}