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 **************************************************************************/
19 Responsible: marian.ivanov@cern.ch
20 Code to analyze the TPC calibration and to produce OCDB entries
24 gSystem->Load("libANALYSIS");
25 gSystem->Load("libTPCcalib");
27 AliTRDPreprocessorOffline proces;
28 TString ocdbPath="local:////"
29 ocdbPath+=gSystem->GetFromPipe("pwd");
31 proces.CalibTimeGain("CalibObjects.root",run0,run1,ocdbPath);
32 proces.CalibTimeVdrift("CalibObjects.root",run0,run1,ocdbPath);
33 // take the raw calibration data from the file CalibObjects.root
34 // and make a OCDB entry with run validity run0-run1
35 // results are stored at the ocdbPath - local or alien ...
36 // default storage ""- data stored at current working directory
39 #include "Riostream.h"
48 #include "TProfile2D.h"
49 #include "AliTRDCalDet.h"
50 #include "AliTRDCalPad.h"
51 #include "AliCDBMetaData.h"
53 #include "AliCDBManager.h"
54 #include "AliCDBStorage.h"
55 #include "AliTRDCalibraMode.h"
56 #include "AliTRDCalibraFit.h"
57 #include "AliTRDCalibraVdriftLinearFit.h"
58 #include "AliTRDPreprocessorOffline.h"
61 ClassImp(AliTRDPreprocessorOffline)
63 AliTRDPreprocessorOffline::AliTRDPreprocessorOffline():
64 TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
66 fNameList("TRDCalib"),
71 fAliTRDCalibraVdriftLinearFit(0x0),
74 fPlots(new TObjArray(8)),
75 fCalibObjects(new TObjArray(8))
78 // default constructor
82 AliTRDPreprocessorOffline::~AliTRDPreprocessorOffline() {
87 if(fCalDetGainUsed) delete fCalDetGainUsed;
88 if(fCH2d) delete fCH2d;
89 if(fPH2d) delete fPH2d;
90 if(fPRF2d) delete fPRF2d;
91 if(fAliTRDCalibraVdriftLinearFit) delete fAliTRDCalibraVdriftLinearFit;
92 if(fNEvents) delete fNEvents;
93 if(fAbsoluteGain) delete fAbsoluteGain;
94 if(fPlots) delete fPlots;
95 if(fCalibObjects) delete fCalibObjects;
99 void AliTRDPreprocessorOffline::CalibVdriftT0(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
101 // make calibration of the drift velocity
103 // file - the location of input file
104 // startRunNumber, endRunNumber - run validity period
105 // ocdbStorage - path to the OCDB storage
106 // - if empty - local storage 'pwd' uesed
107 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
112 // 2. extraction of the information
114 if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
115 if(ReadVdriftLinearFitGlobal(file)) AnalyzeVdriftLinearFit();
117 // 3. Append QA plots
119 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
125 UpdateOCDBVdrift(startRunNumber,endRunNumber,ocdbStorage);
126 UpdateOCDBT0(startRunNumber,endRunNumber,ocdbStorage);
131 void AliTRDPreprocessorOffline::CalibGain(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
133 // make calibration of the drift velocity
135 // file - the location of input file
136 // startRunNumber, endRunNumber - run validity period
137 // ocdbStorage - path to the OCDB storage
138 // - if empty - local storage 'pwd' uesed
139 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
142 if(!ReadGainGlobal(file)) return;
145 // 2. extraction of the information
148 if(fCalDetGainUsed) CorrectFromDetGainUsed();
150 // 3. Append QA plots
152 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
158 UpdateOCDBGain(startRunNumber,endRunNumber,ocdbStorage);
163 void AliTRDPreprocessorOffline::CalibPRF(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
165 // make calibration of the drift velocity
167 // file - the location of input file
168 // startRunNumber, endRunNumber - run validity period
169 // ocdbStorage - path to the OCDB storage
170 // - if empty - local storage 'pwd' uesed
171 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
174 if(!ReadPRFGlobal(file)) return;
177 // 2. extraction of the information
181 // 3. Append QA plots
183 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
189 UpdateOCDBPRF(startRunNumber,endRunNumber,ocdbStorage);
194 Bool_t AliTRDPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
196 // read calibration entries from file
198 TFile fcalib(fileName);
199 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
201 TH2I *ch2d = (TH2I *) array->FindObject("CH2d");
202 if(!ch2d) return kFALSE;
203 fCH2d = (TH2I*)ch2d->Clone();
204 //fNEvents = (TH1I *) array->FindObject("NEvents");
205 //fAbsoluteGain = (TH2F *) array->FindObject("AbsoluteGain");
207 TH2I *ch2d = (TH2I *) fcalib.Get("CH2d");
208 if(!ch2d) return kFALSE;
209 fCH2d = (TH2I*)ch2d->Clone();
210 //fNEvents = (TH1I *) fcalib.Get("NEvents");
211 //fAbsoluteGain = (TH2F *) fcalib.Get("AbsoluteGain");
213 fCH2d->SetDirectory(0);
214 //printf("title of CH2d %s\n",fCH2d->GetTitle());
220 Bool_t AliTRDPreprocessorOffline::ReadVdriftT0Global(const Char_t* fileName){
222 // read calibration entries from file
224 TFile fcalib(fileName);
225 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
227 TProfile2D *ph2d = (TProfile2D *) array->FindObject("PH2d");
228 if(!ph2d) return kFALSE;
229 fPH2d = (TProfile2D*)ph2d->Clone();
230 //fNEvents = (TH1I *) array->FindObject("NEvents");
232 TProfile2D *ph2d = (TProfile2D *) fcalib.Get("PH2d");
233 if(!ph2d) return kFALSE;
234 fPH2d = (TProfile2D*)ph2d->Clone();
235 //fNEvents = (TH1I *) fcalib.Get("NEvents");
237 fPH2d->SetDirectory(0);
238 //printf("title of PH2d %s\n",fPH2d->GetTitle());
244 Bool_t AliTRDPreprocessorOffline::ReadVdriftLinearFitGlobal(const Char_t* fileName){
246 // read calibration entries from file
248 TFile fcalib(fileName);
249 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
251 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) array->FindObject("AliTRDCalibraVdriftLinearFit");
252 //fNEvents = (TH1I *) array->FindObject("NEvents");
254 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) fcalib.Get("AliTRDCalibraVdriftLinearFit");
255 //fNEvents = (TH1I *) fcalib.Get("NEvents");
257 if(!fAliTRDCalibraVdriftLinearFit) {
258 //printf("No AliTRDCalibraVdriftLinearFit\n");
265 Bool_t AliTRDPreprocessorOffline::ReadPRFGlobal(const Char_t* fileName){
267 // read calibration entries from file
269 TFile fcalib(fileName);
270 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
272 TProfile2D *prf2d = (TProfile2D *) array->FindObject("PRF2d");
273 if(!prf2d) return kFALSE;
274 fPRF2d = (TProfile2D*)prf2d->Clone();
275 //fNEvents = (TH1I *) array->FindObject("NEvents");
277 TProfile2D *prf2d = (TProfile2D *) fcalib.Get("PRF2d");
278 if(!prf2d) return kFALSE;
279 fPRF2d = (TProfile2D*)prf2d->Clone();
280 //fNEvents = (TH1I *) fcalib.Get("NEvents");
282 fPRF2d->SetDirectory(0);
283 //printf("title of PRF2d %s\n",fPRF2d->GetTitle());
291 Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
293 // Analyze gain - produce the calibration objects
296 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
297 calibra->SetMinEntries(800); // If there is less than 1000 entries in the histo: no fit
298 calibra->AnalyseCH(fCH2d);
300 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
301 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
302 Int_t nbfit = calibra->GetNumberFit();
303 Int_t nbE = calibra->GetNumberEnt();
309 (nbfit >= 0.5*nbE) && (nbE > 30)) {
310 // create the cal objects
311 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
312 TObjArray object = calibra->GetVectorFit();
313 AliTRDCalDet *calDetGain = calibra->CreateDetObjectGain(&object);
314 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
315 // Put them in the array
316 fCalibObjects->AddAt(calDetGain,kGain);
317 fPlots->AddAt(coefGain,kGain);
322 calibra->ResetVectorFit();
328 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftT0(){
330 // Analyze VdriftT0 - produce the calibration objects
333 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
334 calibra->SetMinEntries(800*20); // If there is less than 1000 entries in the histo: no fit
335 calibra->AnalysePH(fPH2d);
337 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
338 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
339 Int_t nbfit = calibra->GetNumberFit();
340 Int_t nbfitSuccess = calibra->GetNumberFitSuccess();
341 Int_t nbE = calibra->GetNumberEnt();
343 //printf("nbtg %d, nbfit %d, nbE %d, nbfitSuccess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
347 (nbfit >= 0.5*nbE) && (nbE > 30) && (nbfitSuccess > 30)) {
348 //printf("Pass the cut for VdriftT0\n");
349 // create the cal objects
350 calibra->RemoveOutliers(1,kFALSE);
351 calibra->PutMeanValueOtherVectorFit(1,kFALSE);
352 calibra->RemoveOutliers2(kFALSE);
353 calibra->PutMeanValueOtherVectorFit2(1,kFALSE);
355 TObjArray object = calibra->GetVectorFit();
356 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object);
357 TH1F *coefVdriftPH = calDetVdrift->MakeHisto1DAsFunctionOfDet();
358 AliTRDCalPad *calPadVdrift = (AliTRDCalPad *)calibra->CreatePadObjectVdrift(&object,calDetVdrift);
359 TH1F *coefPadVdrift = calPadVdrift->MakeHisto1D();
360 object = calibra->GetVectorFit2();
361 AliTRDCalDet *calDetT0 = calibra->CreateDetObjectT0(&object);
362 TH1F *coefT0 = calDetT0->MakeHisto1DAsFunctionOfDet();
363 AliTRDCalPad *calPadT0 = (AliTRDCalPad *)calibra->CreatePadObjectT0(&object,calDetT0);
364 TH1F *coefPadT0 = calPadT0->MakeHisto1D();
365 // Put them in the array
366 fCalibObjects->AddAt(calDetT0,kT0PHDet);
367 fCalibObjects->AddAt(calDetVdrift,kVdriftPHDet);
368 fCalibObjects->AddAt(calPadT0,kT0PHPad);
369 fCalibObjects->AddAt(calPadVdrift,kVdriftPHPad);
370 fPlots->AddAt(coefVdriftPH,kVdriftPHDet);
371 fPlots->AddAt(coefT0,kT0PHDet);
372 fPlots->AddAt(coefPadVdrift,kVdriftPHPad);
373 fPlots->AddAt(coefPadT0,kT0PHPad);
377 calibra->ResetVectorFit();
383 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftLinearFit(){
385 // Analyze vdrift linear fit - produce the calibration objects
388 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
389 calibra->SetMinEntries(800); // If there is less than 1000 entries in the histo: no fit
390 fAliTRDCalibraVdriftLinearFit->FillPEArray();
391 calibra->AnalyseLinearFitters(fAliTRDCalibraVdriftLinearFit);
394 Int_t nbfit = calibra->GetNumberFit();
395 Int_t nbE = calibra->GetNumberEnt();
400 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
401 // create the cal objects
402 //calibra->RemoveOutliers(1,kTRUE);
403 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
404 //calibra->RemoveOutliers2(kTRUE);
405 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
407 TObjArray object = calibra->GetVectorFit();
408 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object,kTRUE);
409 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
410 object = calibra->GetVectorFit2();
411 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectLorentzAngle(&object);
412 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
413 // Put them in the array
414 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
415 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
416 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
417 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
422 calibra->ResetVectorFit();
429 Bool_t AliTRDPreprocessorOffline::AnalyzePRF(){
431 // Analyze PRF - produce the calibration objects
434 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
435 calibra->SetMinEntries(600); // If there is less than 1000 entries in the histo: no fit
436 calibra->AnalysePRFMarianFit(fPRF2d);
438 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
439 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
440 Int_t nbfit = calibra->GetNumberFit();
441 Int_t nbE = calibra->GetNumberEnt();
447 (nbfit >= 0.95*nbE) && (nbE > 30)) {
448 // create the cal objects
449 TObjArray object = calibra->GetVectorFit();
450 AliTRDCalPad *calPadPRF = (AliTRDCalPad*) calibra->CreatePadObjectPRF(&object);
451 TH1F *coefPRF = calPadPRF->MakeHisto1D();
452 // Put them in the array
453 fCalibObjects->AddAt(calPadPRF,kPRF);
454 fPlots->AddAt(coefPRF,kPRF);
459 calibra->ResetVectorFit();
465 void AliTRDPreprocessorOffline::CorrectFromDetGainUsed() {
467 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
468 if(!calDetGain) return;
470 for(Int_t det = 0; det < 540; det++) {
472 Float_t gaininit = fCalDetGainUsed->GetValue(det);
473 Float_t gainout = calDetGain->GetValue(det);
475 calDetGain->SetValue(det,gaininit*gainout);
482 void AliTRDPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
487 AliCDBMetaData *metaData= new AliCDBMetaData();
488 metaData->SetObjectClassName("AliTRDCalDet");
489 metaData->SetResponsible("Raphaelle Bailhache");
490 metaData->SetBeamPeriod(1);
492 AliCDBId id1("TRD/Calib/ChamberGainFactor", startRunNumber, endRunNumber);
493 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
494 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
495 if(calDet) gStorage->Put(calDet, id1, metaData);
497 // printf("No calDet object for Gain\n");
504 void AliTRDPreprocessorOffline::UpdateOCDBVdrift(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
509 Int_t detVdrift = kVdriftPHDet;
511 if(fMethodSecond) detVdrift = kVdriftLinear;
513 AliCDBMetaData *metaData= new AliCDBMetaData();
514 metaData->SetObjectClassName("AliTRDCalDet");
515 metaData->SetResponsible("Raphaelle Bailhache");
516 metaData->SetBeamPeriod(1);
518 AliCDBId id1("TRD/Calib/ChamberVdrift", startRunNumber, endRunNumber);
519 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
520 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
521 if(calDet) gStorage->Put(calDet, id1, metaData);
523 // printf("No calDet object for Vdrift\n");
530 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
531 metaDataPad->SetObjectClassName("AliTRDCalPad");
532 metaDataPad->SetResponsible("Raphaelle Bailhache");
533 metaDataPad->SetBeamPeriod(1);
535 AliCDBId id1Pad("TRD/Calib/LocalVdrift", startRunNumber, endRunNumber);
536 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
537 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
539 // printf("No calPad object for Vdrift\n");
547 void AliTRDPreprocessorOffline::UpdateOCDBT0(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
552 AliCDBMetaData *metaData= new AliCDBMetaData();
553 metaData->SetObjectClassName("AliTRDCalDet");
554 metaData->SetResponsible("Raphaelle Bailhache");
555 metaData->SetBeamPeriod(1);
557 AliCDBId id1("TRD/Calib/ChamberT0", startRunNumber, endRunNumber);
558 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
559 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
560 if(calDet) gStorage->Put(calDet, id1, metaData);
562 // printf("No calDet object for T0\n");
568 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
569 metaDataPad->SetObjectClassName("AliTRDCalPad");
570 metaDataPad->SetResponsible("Raphaelle Bailhache");
571 metaDataPad->SetBeamPeriod(1);
573 AliCDBId id1Pad("TRD/Calib/LocalT0", startRunNumber, endRunNumber);
574 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
575 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
577 // printf("No calPad object for T0\n");
583 void AliTRDPreprocessorOffline::UpdateOCDBPRF(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
588 AliCDBMetaData *metaData= new AliCDBMetaData();
589 metaData->SetObjectClassName("AliTRDCalPad");
590 metaData->SetResponsible("Raphaelle Bailhache");
591 metaData->SetBeamPeriod(1);
593 AliCDBId id1("TRD/Calib/PRFWidth", startRunNumber, endRunNumber);
594 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
595 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
596 if(calPad) gStorage->Put(calPad, id1, metaData);
598 // printf("No calPad object for PRF\n");