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: Raphaelle Bailhache (rbailhache@ikf.uni-frankfurt.de)
20 Code to analyze the TRD calibration and to produce OCDB entries
24 gSystem->Load("libANALYSIS");
25 gSystem->Load("libTRDcalib");
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
40 #include "Riostream.h"
50 #include "THnSparse.h"
51 #include "TProfile2D.h"
52 #include "AliTRDCalDet.h"
53 #include "AliTRDCalPad.h"
54 #include "AliCDBMetaData.h"
56 #include "AliCDBManager.h"
57 #include "AliCDBStorage.h"
58 #include "AliTRDCalibraMode.h"
59 #include "AliTRDCalibraFit.h"
60 #include "AliTRDCalibraVdriftLinearFit.h"
61 #include "AliTRDCalibraExbAltFit.h"
62 #include "AliTRDPreprocessorOffline.h"
63 #include "AliTRDCalChamberStatus.h"
64 #include "AliTRDCalibChamberStatus.h"
65 #include "AliTRDCommonParam.h"
66 #include "AliCDBManager.h"
67 #include "AliCDBEntry.h"
68 #include "AliTRDdEdxBaseUtils.h"
69 #include "AliTRDdEdxCalibHistArray.h"
70 #include "AliTRDdEdxCalibUtils.h"
72 ClassImp(AliTRDPreprocessorOffline)
74 AliTRDPreprocessorOffline::AliTRDPreprocessorOffline():
75 TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
77 fNameList("TRDCalib"),
79 fCalDetVdriftUsed(0x0),
85 fAliTRDCalibraVdriftLinearFit(0x0),
86 fAliTRDCalibraExbAltFit(0x0),
89 fPlots(new TObjArray(kNumCalibObjs)),
90 fCalibObjects(new TObjArray(kNumCalibObjs)),
93 fSubVersionGainUsed(0),
94 fFirstRunVdriftUsed(0),
95 fVersionVdriftUsed(0),
96 fSubVersionVdriftUsed(0),
99 fSubVersionExBUsed(0),
100 fNoExBUsedInReco(kFALSE),
101 fSwitchOnValidation(kTRUE),
102 fVdriftValidated(kFALSE),
103 fExBValidated(kFALSE),
104 fT0Validated(kFALSE),
105 fMinStatsVdriftT0PH(800*20),
106 fMinStatsVdriftLinear(800),
109 fMinStatsChamberStatus(20),
110 fMinSingleStatsChamberStatus(0.05),
111 fBackCorrectGain(kFALSE),
112 fBackCorrectVdrift(kTRUE),
113 fNotEnoughStatisticsForTheGain(kFALSE),
114 fNotEnoughStatisticsForTheVdriftLinear(kFALSE),
117 fBadCalibValidate(40),
119 fRMSBadCalibratedGain(20.0),
120 fRMSBadCalibratedVdrift(20.0),
121 fRMSBadCalibratedExB(20.0),
122 fRobustFitDriftVelocity(kTRUE),
123 fRobustFitExbAlt(kFALSE),
124 fAlternativeVdrfitFit(kFALSE),
125 fAlternativeExbAltFit(kFALSE),
126 fMinNbOfPointVdriftFit(11),
128 fOutliersFitChargeLow(0.03),
129 fOutliersFitChargeHigh(0.7),
130 fBeginFitCharge(3.5),
135 // default constructor
138 memset(fBadCalib, 0, sizeof(Int_t) * 18);
139 memset(fNoData, 0, sizeof(Int_t) * 18);
141 //_________________________________________________________________________________________________________________
142 AliTRDPreprocessorOffline::~AliTRDPreprocessorOffline() {
147 if(fCalDetGainUsed) delete fCalDetGainUsed;
148 if(fCalDetVdriftUsed) delete fCalDetVdriftUsed;
149 if(fCalDetExBUsed) delete fCalDetExBUsed;
150 if(fCH2d) delete fCH2d;
151 if(fPH2d) delete fPH2d;
152 if(fPRF2d) delete fPRF2d;
153 if(fSparse) delete fSparse;
156 AliTRDdEdxCalibUtils::DeleteHistArray();
157 AliTRDdEdxCalibUtils::DeleteObjArray();
160 if(fAliTRDCalibraVdriftLinearFit) delete fAliTRDCalibraVdriftLinearFit;
161 if(fAliTRDCalibraExbAltFit) delete fAliTRDCalibraExbAltFit;
162 if(fNEvents) delete fNEvents;
163 if(fAbsoluteGain) delete fAbsoluteGain;
164 if(fPlots) delete fPlots;
165 if(fCalibObjects) delete fCalibObjects;
168 //___________________________________________________________________________________
169 void AliTRDPreprocessorOffline::Process(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage)
172 // Process to the gain, vdrift, timeoffset, exb and chamber status calibration
175 if(SetCalDetGain(startRunNumber,fVersionGainUsed,fSubVersionGainUsed) && SetCalDetVdriftExB(startRunNumber,fVersionVdriftUsed,fSubVersionVdriftUsed,fVersionExBUsed,fSubVersionExBUsed)) {
177 CalibVdriftT0(file,startRunNumber,endRunNumber,ocdbStorage);
178 CalibGain(file,startRunNumber,endRunNumber,ocdbStorage);
179 CalibChamberStatus(file,startRunNumber,endRunNumber,ocdbStorage);
180 CalibExbAlt(file,startRunNumber,endRunNumber,ocdbStorage);
185 printf("\n AliTRDPreprocessorOffline PHQ on!!\n\n");
186 AliTRDdEdxBaseUtils::PrintControl();
187 CalibPHQ(file, startRunNumber, endRunNumber, ocdbStorage);
190 printf("\n AliTRDPreprocessorOffline PHQ off!!\n\n");
196 //___________________________________________________________________________________________________________________
198 void AliTRDPreprocessorOffline::CalibVdriftT0(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
200 // make calibration of the drift velocity
202 // file - the location of input file
203 // startRunNumber, endRunNumber - run validity period
204 // ocdbStorage - OCDB storage
205 // - if empty - local storage 'pwd' uesed
206 if (ocdbStorage==0x0) {
207 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
208 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
213 fVdriftValidated = kTRUE;
214 fT0Validated = kTRUE;
215 fExBValidated = kTRUE;
216 fNotEnoughStatisticsForTheVdriftLinear = kFALSE;
218 // 2. extraction of the information
220 if(ReadVdriftLinearFitGlobal(file) && fCalDetVdriftUsed && fCalDetExBUsed) AnalyzeVdriftLinearFit();
221 if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
223 // 3. Append QA plots
225 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
228 // 4. validate OCDB entries
230 if(fSwitchOnValidation==kTRUE && ValidateVdrift()==kFALSE) {
231 //AliError("TRD vdrift OCDB parameters out of range!");
232 fVdriftValidated = kFALSE;
234 if(fSwitchOnValidation==kTRUE && ValidateT0()==kFALSE) {
235 //AliError("TRD t0 OCDB parameters out of range!");
236 fT0Validated = kFALSE;
238 if(fSwitchOnValidation==kTRUE && ValidateExB()==kFALSE) {
239 //AliError("TRD t0 OCDB parameters out of range!");
240 fExBValidated = kFALSE;
246 if(fVdriftValidated) UpdateOCDBVdrift(startRunNumber,endRunNumber,ocdbStorage);
247 if(fT0Validated) UpdateOCDBT0(startRunNumber,endRunNumber,ocdbStorage);
248 if(fExBValidated) UpdateOCDBExB(startRunNumber,endRunNumber,ocdbStorage);
251 //___________________________________________________________________________________________________________________
253 void AliTRDPreprocessorOffline::CalibExbAlt(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
255 // make calibration of the drift velocity
257 // file - the location of input file
258 // startRunNumber, endRunNumber - run validity period
259 // ocdbStorage - OCDB storage
260 // - if empty - local storage 'pwd' uesed
261 if (ocdbStorage==0x0) {
262 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
263 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
270 // 2. extraction of the information
272 if(ReadExbAltFitGlobal(file)) AnalyzeExbAltFit();
274 // 3. Append QA plots
276 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
279 // 4. validate OCDB entries
285 UpdateOCDBExBAlt(startRunNumber,endRunNumber,ocdbStorage);
289 //_________________________________________________________________________________________________________________
291 void AliTRDPreprocessorOffline::CalibGain(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
293 // make calibration of the drift velocity
295 // file - the location of input file
296 // startRunNumber, endRunNumber - run validity period
297 // ocdbStorage - OCDB storage
298 // - if empty - local storage 'pwd' uesed
299 if (ocdbStorage==0x0) {
300 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
301 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
304 fNotEnoughStatisticsForTheGain = kFALSE;
307 if(!ReadGainGlobal(file)) return;
310 // 2. extraction of the information
313 if(fBackCorrectGain) CorrectFromDetGainUsed();
314 //if(fBackCorrectVdrift) CorrectFromDetVdriftUsed();
316 // 3. Append QA plots
318 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
321 // 4. validate OCDB entries
323 if(fSwitchOnValidation==kTRUE && ValidateGain()==kFALSE) {
324 //AliError("TRD gain OCDB parameters out of range!");
331 if((!fCalDetVdriftUsed) || (fCalDetVdriftUsed && fVdriftValidated)) UpdateOCDBGain(startRunNumber,endRunNumber,ocdbStorage);
335 //________________________________________________________________________________________________________________
337 void AliTRDPreprocessorOffline::CalibPRF(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
339 // make calibration of the drift velocity
341 // file - the location of input file
342 // startRunNumber, endRunNumber - run validity period
343 // ocdbStorage - OCDB storage
344 // - if empty - local storage 'pwd' uesed
345 if (ocdbStorage==0x0) {
346 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
347 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
351 if(!ReadPRFGlobal(file)) return;
354 // 2. extraction of the information
358 // 3. Append QA plots
360 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
364 // 4. validate OCDB entries
366 if(fSwitchOnValidation==kTRUE && ValidatePRF()==kFALSE) {
367 //AliError("TRD prf OCDB parameters out of range!");
374 UpdateOCDBPRF(startRunNumber,endRunNumber,ocdbStorage);
377 //________________________________________________________________________________________________________________
378 void AliTRDPreprocessorOffline::CalibPHQ(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage)
381 // make calibration of puls height Q
383 // startRunNumber, endRunNumber - run validity period
384 // ocdbStorage - OCDB storage
385 // - if empty - local storage 'pwd' uesed
388 if (ocdbStorage==0x0) {
389 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
390 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
392 //printf("test %s\n", ocdbStorage.Data());
394 if(!ReadPHQGlobal(file)) return;
396 if(!AnalyzePHQ(startRunNumber)) return;
398 UpdateOCDBPHQ(startRunNumber,endRunNumber,ocdbStorage);
401 //________________________________________________________________________________________________________________
403 void AliTRDPreprocessorOffline::CalibChamberStatus(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
405 // make calibration of the chamber status
407 // startRunNumber, endRunNumber - run validity period
408 // ocdbStorage - OCDB storage
409 // - if empty - local storage 'pwd' uesed
410 if (ocdbStorage==0x0) {
411 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
412 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
417 if(!ReadStatusGlobal(file)) return;
421 // 2. extraction of the information
423 if(!AnalyzeChamberStatus()) return;
425 // 3. Append QA plots
427 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
431 // 4. validate OCDB entries
433 if(fSwitchOnValidation==kTRUE && ValidateChamberStatus()==kFALSE) {
434 //AliError("TRD Chamber status OCDB parameters not ok!");
441 if((!fNotEnoughStatisticsForTheVdriftLinear) && (!fNotEnoughStatisticsForTheGain)) UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
442 //UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
445 //______________________________________________________________________________________________________
446 Bool_t AliTRDPreprocessorOffline::Init(const Char_t* fileName){
448 // read the calibration used during the reconstruction
451 if(ReadVdriftT0Global(fileName)) {
453 TString nameph = fPH2d->GetTitle();
454 fFirstRunVdriftUsed = GetFirstRun(nameph);
455 fVersionVdriftUsed = GetVersion(nameph);
456 fSubVersionVdriftUsed = GetSubVersion(nameph);
458 //printf("Found Version %d, Subversion %d for vdrift\n",fVersionVdriftUsed,fSubVersionVdriftUsed);
462 if(ReadGainGlobal(fileName)) {
464 TString namech = fCH2d->GetTitle();
465 fFirstRunGainUsed = GetFirstRun(namech);
466 fVersionGainUsed = GetVersion(namech);
467 fSubVersionGainUsed = GetSubVersion(namech);
469 //printf("Found Version %d, Subversion %d for gain\n",fVersionGainUsed,fSubVersionGainUsed);
473 if(ReadVdriftLinearFitGlobal(fileName)) {
475 TString namelinear = fAliTRDCalibraVdriftLinearFit->GetNameCalibUsed();
476 fFirstRunExBUsed = GetFirstRun(namelinear);
477 fVersionExBUsed = GetVersion(namelinear);
478 fSubVersionExBUsed = GetSubVersion(namelinear);
480 //printf("Found Version %d, Subversion %d, run %d for ExB\n",fVersionExBUsed,fSubVersionExBUsed,fFirstRunExBUsed);
484 if(fVersionVdriftUsed == 0) fStatusPos = fStatusPos |kVdriftErrorOld;
485 if(fVersionGainUsed == 0) fStatusPos = fStatusPos | kGainErrorOld;
490 //___________________________________________________________________________________________________________________
492 Bool_t AliTRDPreprocessorOffline::ReadStatusGlobal(const Char_t* fileName){
494 // read calibration entries from file
496 if(fSparse) return kTRUE;
497 TFile fcalib(fileName);
498 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
500 fSparse = (THnSparseI *) array->FindObject("NumberOfEntries");
501 if(!fSparse) return kFALSE;
509 //___________________________________________________________________________________________________________________
511 Bool_t AliTRDPreprocessorOffline::ReadPHQGlobal(const Char_t* fileName)
514 // read calibration entries from file
517 return AliTRDdEdxCalibUtils::ReadHistArray(fileName, fNameList);
520 //___________________________________________________________________________________________________________________
522 Bool_t AliTRDPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
524 // read calibration entries from file
526 if(fCH2d) return kTRUE;
527 TFile fcalib(fileName);
528 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
530 TH2I *ch2d = (TH2I *) array->FindObject("CH2d");
531 if(!ch2d) return kFALSE;
532 fCH2d = (TH2I*)ch2d->Clone();
533 //fNEvents = (TH1I *) array->FindObject("NEvents");
534 //fAbsoluteGain = (TH2F *) array->FindObject("AbsoluteGain");
536 TH2I *ch2d = (TH2I *) fcalib.Get("CH2d");
537 if(!ch2d) return kFALSE;
538 fCH2d = (TH2I*)ch2d->Clone();
539 //fNEvents = (TH1I *) fcalib.Get("NEvents");
540 //fAbsoluteGain = (TH2F *) fcalib.Get("AbsoluteGain");
542 fCH2d->SetDirectory(0);
543 //printf("title of CH2d %s\n",fCH2d->GetTitle());
548 //_________________________________________________________________________________________________________________
550 Bool_t AliTRDPreprocessorOffline::ReadVdriftT0Global(const Char_t* fileName){
552 // read calibration entries from file
554 if(fPH2d) return kTRUE;
555 TFile fcalib(fileName);
556 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
558 TProfile2D *ph2d = (TProfile2D *) array->FindObject("PH2d");
559 if(!ph2d) return kFALSE;
560 fPH2d = (TProfile2D*)ph2d->Clone();
561 //fNEvents = (TH1I *) array->FindObject("NEvents");
563 TProfile2D *ph2d = (TProfile2D *) fcalib.Get("PH2d");
564 if(!ph2d) return kFALSE;
565 fPH2d = (TProfile2D*)ph2d->Clone();
566 //fNEvents = (TH1I *) fcalib.Get("NEvents");
568 fPH2d->SetDirectory(0);
569 //printf("title of PH2d %s\n",fPH2d->GetTitle());
574 //___________________________________________________________________________________________________________________
576 Bool_t AliTRDPreprocessorOffline::ReadVdriftLinearFitGlobal(const Char_t* fileName){
578 // read calibration entries from file
580 if(fAliTRDCalibraVdriftLinearFit) return kTRUE;
581 TFile fcalib(fileName);
582 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
584 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) array->FindObject("AliTRDCalibraVdriftLinearFit");
585 //fNEvents = (TH1I *) array->FindObject("NEvents");
587 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) fcalib.Get("AliTRDCalibraVdriftLinearFit");
588 //fNEvents = (TH1I *) fcalib.Get("NEvents");
590 if(!fAliTRDCalibraVdriftLinearFit) {
591 //printf("No AliTRDCalibraVdriftLinearFit\n");
597 //_____________________________________________________________________________________________________________
598 Bool_t AliTRDPreprocessorOffline::ReadExbAltFitGlobal(const Char_t* fileName){
600 // read calibration entries from file
602 if(fAliTRDCalibraExbAltFit) return kTRUE;
603 TFile fcalib(fileName);
604 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
606 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) array->FindObject("AliTRDCalibraExbAltFit");
607 //fNEvents = (TH1I *) array->FindObject("NEvents");
609 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) fcalib.Get("AliTRDCalibraExbAltFit");
610 //fNEvents = (TH1I *) fcalib.Get("NEvents");
612 if(!fAliTRDCalibraExbAltFit) {
613 //printf("No AliTRDCalibraExbAltFit\n");
619 //_____________________________________________________________________________________________________________
621 Bool_t AliTRDPreprocessorOffline::ReadPRFGlobal(const Char_t* fileName){
623 // read calibration entries from file
625 if(fPRF2d) return kTRUE;
626 TFile fcalib(fileName);
627 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
629 TProfile2D *prf2d = (TProfile2D *) array->FindObject("PRF2d");
630 if(!prf2d) return kFALSE;
631 fPRF2d = (TProfile2D*)prf2d->Clone();
632 //fNEvents = (TH1I *) array->FindObject("NEvents");
634 TProfile2D *prf2d = (TProfile2D *) fcalib.Get("PRF2d");
635 if(!prf2d) return kFALSE;
636 fPRF2d = (TProfile2D*)prf2d->Clone();
637 //fNEvents = (TH1I *) fcalib.Get("NEvents");
639 fPRF2d->SetDirectory(0);
640 //printf("title of PRF2d %s\n",fPRF2d->GetTitle());
645 //__________________________________________________________________________________________________________
647 Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
649 // Analyze gain - produce the calibration objects
652 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
653 calibra->ChooseMethod(fMethodeGain);
654 calibra->SetBeginFitCharge(fBeginFitCharge);
655 calibra->SetFitOutliersChargeLow(fOutliersFitChargeLow);
656 calibra->SetFitOutliersChargeHigh(fOutliersFitChargeHigh);
657 calibra->SetMinEntries(fMinStatsGain); // If there is less than 1000 entries in the histo: no fit
658 calibra->AnalyseCH(fCH2d);
660 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
661 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
662 Int_t nbfit = calibra->GetNumberFit();
663 Int_t nbE = calibra->GetNumberEnt();
667 Bool_t meanother = kFALSE;
670 (nbfit >= 0.5*nbE) && (nbE > 30)) {
671 // create the cal objects
672 if(!fBackCorrectGain) {
673 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
676 TObjArray object = calibra->GetVectorFit();
677 AliTRDCalDet *calDetGain = calibra->CreateDetObjectGain(&object,meanother);
678 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
679 // Put them in the array
680 fCalibObjects->AddAt(calDetGain,kGain);
681 fPlots->AddAt(coefGain,kGain);
686 fNotEnoughStatisticsForTheGain = kTRUE;
687 Int_t minStatsGain = fMinStatsGain*30;
688 calibra->SetMinEntries(minStatsGain); // Because we do it for all, we increase this
689 Double_t gainoverallnotnormalized = calibra->AnalyseCHAllTogether(fCH2d);
690 if(fCalDetGainUsed && (gainoverallnotnormalized > 0.0)) {
691 AliTRDCalDet *calDetGain = new AliTRDCalDet(*fCalDetGainUsed);
692 Double_t oldmean = fCalDetGainUsed->CalcMean(kFALSE);
693 //printf("oldmean %f\n",oldmean);
695 Double_t scalefactor = calibra->GetScaleFactorGain();
696 //printf("Correction factor %f\n",gainoverallnotnormalized*scalefactor);
697 calDetGain->Multiply(gainoverallnotnormalized*scalefactor/oldmean);
698 //printf("newmean %f\n",calDetGain->CalcMean(kFALSE));
699 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
700 fCalibObjects->AddAt(calDetGain,kGain);
701 fPlots->AddAt(coefGain,kGain);
704 fStatusNeg = fStatusNeg | kGainNotEnoughStatsButFill;
707 fStatusPos = fStatusPos | kGainErrorOld;
711 if(gainoverallnotnormalized <= 0.0) fStatusNeg = fStatusNeg | kGainNotEnoughStatsNotFill;
712 if(!fCalDetGainUsed) fStatusPos = fStatusPos | kGainErrorOld;
716 calibra->ResetVectorFit();
721 //_____________________________________________________________________________________________________
722 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftT0(){
724 // Analyze VdriftT0 - produce the calibration objects
727 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
728 calibra->SetMinEntries(fMinStatsVdriftT0PH); // If there is less than 1000 entries in the histo: no fit
729 calibra->AnalysePH(fPH2d);
731 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
732 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
733 Int_t nbfit = calibra->GetNumberFit();
734 Int_t nbfitSuccess = calibra->GetNumberFitSuccess();
735 Int_t nbE = calibra->GetNumberEnt();
737 //printf("nbtg %d, nbfit %d, nbE %d, nbfitSuccess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
741 (nbfit >= 0.5*nbE) && (nbE > 30) && (nbfitSuccess > 30)) {
742 //printf("Pass the cut for VdriftT0\n");
743 // create the cal objects
744 calibra->RemoveOutliers(1,kFALSE);
745 calibra->PutMeanValueOtherVectorFit(1,kFALSE);
746 calibra->RemoveOutliers2(kFALSE);
747 calibra->PutMeanValueOtherVectorFit2(1,kFALSE);
749 TObjArray object = calibra->GetVectorFit();
750 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object);
751 TH1F *coefVdriftPH = calDetVdrift->MakeHisto1DAsFunctionOfDet();
752 AliTRDCalPad *calPadVdrift = (AliTRDCalPad *)calibra->CreatePadObjectVdrift(&object,calDetVdrift);
753 TH1F *coefPadVdrift = calPadVdrift->MakeHisto1D();
754 object = calibra->GetVectorFit2();
755 AliTRDCalDet *calDetT0 = calibra->CreateDetObjectT0(&object);
756 TH1F *coefT0 = calDetT0->MakeHisto1DAsFunctionOfDet();
757 AliTRDCalPad *calPadT0 = (AliTRDCalPad *)calibra->CreatePadObjectT0(&object,calDetT0);
758 TH1F *coefPadT0 = calPadT0->MakeHisto1D();
759 // Put them in the array
760 fCalibObjects->AddAt(calDetT0,kT0PHDet);
761 fCalibObjects->AddAt(calDetVdrift,kVdriftPHDet);
762 fCalibObjects->AddAt(calPadT0,kT0PHPad);
763 fCalibObjects->AddAt(calPadVdrift,kVdriftPHPad);
764 fPlots->AddAt(coefVdriftPH,kVdriftPHDet);
765 fPlots->AddAt(coefT0,kT0PHDet);
766 fPlots->AddAt(coefPadVdrift,kVdriftPHPad);
767 fPlots->AddAt(coefPadT0,kT0PHPad);
772 //printf("Not enough stats timeoffset\n");
773 fStatusNeg = fStatusNeg | kTimeOffsetNotEnoughStatsNotFill;
775 calibra->ResetVectorFit();
780 //____________________________________________________________________________________________________________________
781 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftLinearFit(){
783 // Analyze vdrift linear fit - produce the calibration objects
786 //printf("Analyse linear fit\n");
789 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
790 calibra->SetCalDetVdriftExB(fCalDetVdriftUsed,fCalDetExBUsed);
791 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
792 printf("The mean stat is by %d for VdriftLinear\n",fMinStatsVdriftLinear);
793 //fAliTRDCalibraVdriftLinearFit->SetSeeDetector(0);
794 //fAliTRDCalibraVdriftLinearFit->SetDebugLevel(1);
795 //printf("Fill PE Array\n");
796 fAliTRDCalibraVdriftLinearFit->SetRobustFit(fRobustFitDriftVelocity);
797 fAliTRDCalibraVdriftLinearFit->SetMinNumberOfPointsForFit(fMinNbOfPointVdriftFit);
798 if(!fAlternativeVdrfitFit)
799 fAliTRDCalibraVdriftLinearFit->FillPEArray();
801 fAliTRDCalibraVdriftLinearFit->FillPEArray2();
802 //printf("AliTRDCalibraFit\n");
803 calibra->AnalyseLinearFitters(fAliTRDCalibraVdriftLinearFit);
807 Int_t nbfit = calibra->GetNumberFit();
808 Int_t nbE = calibra->GetNumberEnt();
813 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
814 // create the cal objects
815 //calibra->RemoveOutliers(1,kTRUE);
816 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
817 //calibra->RemoveOutliers2(kTRUE);
818 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
820 TObjArray object = calibra->GetVectorFit();
821 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object,kTRUE);
822 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
823 object = calibra->GetVectorFit2();
824 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectLorentzAngle(&object);
825 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
826 //if(!calDetLorentz) printf("No lorentz created\n");
827 // Put them in the array
828 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
829 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
830 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
831 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
836 fNotEnoughStatisticsForTheVdriftLinear = kTRUE;
837 Int_t minNumberOfEntriesForAll = fMinStatsVdriftLinear*30;
838 calibra->SetMinEntries(minNumberOfEntriesForAll); // Because we do it for all, we increase this
839 Double_t vdriftoverall = -100.0;
840 Double_t exboverall = 100.0;
841 calibra->AnalyseLinearFittersAllTogether(fAliTRDCalibraVdriftLinearFit,vdriftoverall,exboverall);
842 //printf("Found mean vdrift %f and exb %f\n",vdriftoverall,exboverall);
843 if(fCalDetVdriftUsed && (vdriftoverall > 0.0) && (exboverall < 70.0)) {
844 AliTRDCalDet *calDetVdrift = new AliTRDCalDet(*fCalDetVdriftUsed);
845 AliTRDCalDet *calDetLorentz = new AliTRDCalDet(*fCalDetExBUsed);
846 Double_t oldmeanvdrift = fCalDetVdriftUsed->CalcMean(kFALSE);
847 Double_t oldmeanexb = fCalDetExBUsed->CalcMean(kFALSE);
848 //printf("oldmean %f\n",oldmean);
849 if((oldmeanvdrift > 0.0) && (oldmeanexb < 70.0)) {
850 //printf("Correction factor %f\n",vdriftoverall);
851 calDetVdrift->Multiply(vdriftoverall/oldmeanvdrift);
852 if(TMath::Abs(oldmeanexb) > 0.0001) calDetLorentz->Multiply(exboverall/oldmeanexb);
853 //printf("newmean %f\n",calDetVdrift->CalcMean(kFALSE));
854 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
855 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
856 // Put them in the array
857 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
858 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
859 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
860 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
863 fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsButFill;
866 if(oldmeanvdrift) fStatusPos = fStatusPos | kVdriftErrorOld;
867 if(oldmeanexb) fStatusPos = fStatusPos | kExBErrorOld;
871 if((vdriftoverall <= 0.0) && (exboverall > 70.0)) fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsNotFill;
872 if(!fCalDetVdriftUsed) fStatusPos = fStatusPos | kVdriftErrorOld;
873 if(!fCalDetExBUsed) fStatusPos = fStatusPos | kExBErrorOld;
877 calibra->ResetVectorFit();
882 //________________________________________________________________________________________________________________
884 Bool_t AliTRDPreprocessorOffline::AnalyzeExbAltFit(){
886 // Analyze vdrift linear fit - produce the calibration objects
889 //printf("Analyse linear fit\n");
892 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
893 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
894 //printf("Fill PE Array\n");
895 fAliTRDCalibraExbAltFit->SetRobustFit(fRobustFitExbAlt);
896 if(!fAlternativeExbAltFit)
897 fAliTRDCalibraExbAltFit->FillPEArray();
899 fAliTRDCalibraExbAltFit->FillPEArray2();
900 //printf("AliTRDCalibraFit\n");
901 calibra->AnalyseExbAltFit(fAliTRDCalibraExbAltFit);
905 Int_t nbfit = calibra->GetNumberFit();
906 Int_t nbE = calibra->GetNumberEnt();
911 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
912 // create the cal objects
913 //calibra->RemoveOutliers(1,kTRUE);
914 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
916 TObjArray object = calibra->GetVectorFit2();
917 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectExbAlt(&object);
918 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
919 //if(!calDetLorentz) printf("No lorentz created\n");
920 // Put them in the array
921 fCalibObjects->AddAt(calDetLorentz,kExbAlt);
922 fPlots->AddAt(coefLorentzAngle,kExbAlt);
927 calibra->ResetVectorFit();
932 //________________________________________________________________________________________________________________
934 Bool_t AliTRDPreprocessorOffline::AnalyzePRF(){
936 // Analyze PRF - produce the calibration objects
939 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
940 calibra->SetMinEntries(fMinStatsPRF); // If there is less than 1000 entries in the histo: no fit
941 calibra->AnalysePRFMarianFit(fPRF2d);
943 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
944 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
945 Int_t nbfit = calibra->GetNumberFit();
946 Int_t nbE = calibra->GetNumberEnt();
952 (nbfit >= 0.95*nbE) && (nbE > 30)) {
953 // create the cal objects
954 TObjArray object = calibra->GetVectorFit();
955 AliTRDCalPad *calPadPRF = (AliTRDCalPad*) calibra->CreatePadObjectPRF(&object);
956 TH1F *coefPRF = calPadPRF->MakeHisto1D();
957 // Put them in the array
958 fCalibObjects->AddAt(calPadPRF,kPRF);
959 fPlots->AddAt(coefPRF,kPRF);
964 calibra->ResetVectorFit();
970 //_____________________________________________________________________________
971 Bool_t AliTRDPreprocessorOffline::AnalyzePHQ(Int_t startRunNumber)
974 //Produce PHQ calibration results
977 TTreeSRedirector *calibStream = 0x0;
982 calibStream = new TTreeSRedirector(Form("TRDCalibStream_%010d.root", startRunNumber));
985 for(Int_t iter=0; iter<AliTRDdEdxCalibUtils::GetHistArray()->GetSize(); iter++){
986 THnBase *hi = (THnBase*) AliTRDdEdxCalibUtils::GetHistAt(iter);
987 TObjArray *obji = AliTRDdEdxCalibUtils::HistToObj(hi, startRunNumber, lout, calibStream);
988 //printf("test analyze %s\n", obji->GetName());
989 AliTRDdEdxCalibUtils::GetObjArray()->AddAt(obji, iter);
992 fCalibObjects->AddAt(AliTRDdEdxCalibUtils::GetObjArray(), kPHQ);
995 TFile *fout=new TFile(Form("TRDCalibList_%010d.root", startRunNumber),"recreate");
1008 //_____________________________________________________________________________
1009 Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
1012 // Produce AliTRDCalChamberStatus out of calibration results
1015 // set up AliTRDCalibChamberStatus
1016 AliTRDCalibChamberStatus *chamberStatus = new AliTRDCalibChamberStatus();
1017 chamberStatus->SetSparseI(fSparse);
1018 chamberStatus->AnalyseHisto(fMinStatsChamberStatus, fMinSingleStatsChamberStatus);
1019 // get AliTRDCalChamberStatus
1020 AliTRDCalChamberStatus *calChamberStatus = chamberStatus->GetCalChamberStatus();
1022 // get calibration objects
1023 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1024 AliTRDCalDet *calDetVDrift = (AliTRDCalDet *) fCalibObjects->At(kVdriftLinear);
1025 AliTRDCalDet *calDetExB = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
1028 if((!calDetGain) || (!calDetVDrift) || (!fCH2d) || (!calDetExB) || (!calChamberStatus)) return kFALSE;
1031 Double_t gainmean = calDetGain->GetMean();
1032 Double_t vdriftmean = calDetVDrift->GetMean();
1033 Double_t exbmean = calDetExB->GetMean();
1035 Double_t gainrms = calDetGain->GetRMSRobust();
1036 Double_t vdriftrms = calDetVDrift->GetRMSRobust();
1037 Double_t exbrms = calDetExB->GetRMSRobust();
1039 //printf("Gain mean: %f, rms: %f\n",gainmean,gainrms);
1040 //printf("Vdrift mean: %f, rms: %f\n",vdriftmean,vdriftrms);
1041 //printf("ExB mean: %f, rms: %f\n",exbmean,exbrms);
1044 if((TMath::Abs(gainrms) < 0.001) || (TMath::Abs(vdriftrms) < 0.001) || (TMath::Abs(exbrms) < 0.0000001)) return kFALSE;
1046 // Take mean each SM
1047 Double_t *gainmeanSM = new Double_t[18];
1048 Double_t *vdriftmeanSM = new Double_t[18];
1049 Double_t *exbmeanSM = new Double_t[18];
1050 //Double_t *t0meanSM = new Double_t[18];
1051 for(Int_t sm=0; sm< 18; sm++) {
1052 gainmeanSM[sm] = calDetGain->GetMeanSM(kFALSE,sm);
1053 vdriftmeanSM[sm] = calDetVDrift->GetMeanSM(kFALSE,sm);
1054 exbmeanSM[sm] = calDetExB->GetMeanSM(kFALSE,sm);
1055 //t0meanSM[sm] = calDetGain->GetMeanSM(kFALSE);
1059 // mask chambers with empty gain entries
1060 //Int_t counter = 0;
1061 for (Int_t idet = 0; idet < 540; idet++) {
1064 TH1I *projch = (TH1I *) fCH2d->ProjectionX("projch",idet+1,idet+1,(Option_t *)"e");
1065 Double_t entries = projch->GetEntries();
1066 //printf("Number of entries %f for det %d\n",entries,idet);
1069 Int_t smnumber = (Int_t) idet/30;
1072 Double_t gain = calDetGain->GetValue(idet);
1075 Double_t vdrift = calDetVDrift->GetValue(idet);
1078 Double_t exb = calDetExB->GetValue(idet);
1081 if( (entries<50 && !calChamberStatus->IsNoData(idet)) ||
1082 TMath::Abs(gainmean-gain) > (fRMSBadCalibratedGain*gainrms) ||
1083 TMath::Abs(vdriftmean-vdrift) > (fRMSBadCalibratedVdrift*vdriftrms) ||
1084 TMath::Abs(exbmean-exb) > (fRMSBadCalibratedExB*exbrms) ) {
1086 //printf(" chamber det %03d masked \n",idet);
1087 //printf(" gainmean %f and gain %f, gainrms %f \n",gainmean,gain,gainrms);
1088 //printf(" vdriftmean %f and vdrift %f, vdriftrms %f \n",vdriftmean,vdrift,vdriftrms);
1089 //printf(" exbmean %f and exb %f, exbrms %f \n",exbmean,exb,exbrms);
1091 calChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kBadCalibrated);
1095 if(TMath::Abs(gainmeanSM[smnumber]-gain) < 0.000001 ||
1096 TMath::Abs(vdriftmeanSM[smnumber]-vdrift) < 0.000001 ||
1097 TMath::Abs(exbmeanSM[smnumber]-exb) < 0.000001) {
1099 //printf(" chamber det %03d notcalibrated sm %d \n",idet,smnumber);
1100 //printf(" gainmeanSM %f and gain %f\n",gainmeanSM[smnumber],gain);
1101 //printf(" vdriftmeanSM %f and vdrift %f \n",vdriftmeanSM[smnumber],vdrift);
1102 //printf(" exbmeanSM %f and exb %f \n",exbmeanSM[smnumber],exb);
1104 calChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kNotCalibrated);
1113 for(Int_t sm=0; sm < 18; sm++) {
1115 Int_t smbadcalib = 0;
1116 for(Int_t det = 0; det < 30; det++){
1117 Int_t detector = sm*30+det;
1118 if(calChamberStatus->IsNoData(detector)) smnodata++;
1120 if(calChamberStatus->IsBadCalibrated(detector)) smbadcalib++;
1123 fNoData[sm] = smnodata;
1124 fBadCalib[sm]= smbadcalib;
1125 //printf("No Data %d, bad calibrated %d for %d\n",fNoData[sm],fBadCalib[sm],sm);
1129 delete []gainmeanSM;
1130 delete []vdriftmeanSM;
1134 // for(Int_t sm=0; sm < 18; sm++) {
1135 // Int_t counter = 0;
1136 // for(Int_t det = 0; det < 30; det++){
1137 // Int_t detector = sm*30+det;
1138 // if(calChamberStatus->IsBadCalibrated(detector)) counter++;
1140 // if(counter >= 20) {
1141 // for(Int_t det = 0; det < 30; det++){
1142 // Int_t detector = sm*30+det;
1143 // calChamberStatus->SetStatus(detector,AliTRDCalChamberStatus::kGood);
1148 fCalibObjects->AddAt(calChamberStatus,kChamberStatus);
1154 //________________________________________________________________________________________________
1155 void AliTRDPreprocessorOffline::CorrectFromDetGainUsed() {
1157 // Correct from the gas gain used afterwards
1159 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1160 if(!calDetGain) return;
1163 Double_t mean = 0.0;
1166 for(Int_t det = 0; det < 540; det++) {
1168 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1169 Float_t gainout = calDetGain->GetValue(det);
1172 if(TMath::Abs(gainout-1.0) > 0.000001) {
1173 mean += (gaininit*gainout);
1177 if(nbdet > 0) mean = mean/nbdet;
1179 for(Int_t det = 0; det < 540; det++) {
1181 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1182 Float_t gainout = calDetGain->GetValue(det);
1184 if(TMath::Abs(gainout-1.0) > 0.000001) {
1185 Double_t newgain = gaininit*gainout;
1186 if(newgain < 0.1) newgain = 0.1;
1187 if(newgain > 1.9) newgain = 1.9;
1188 calDetGain->SetValue(det,newgain);
1191 Double_t newgain = mean;
1192 if(newgain < 0.1) newgain = 0.1;
1193 if(newgain > 1.9) newgain = 1.9;
1194 calDetGain->SetValue(det,newgain);
1200 //________________________________________________________________________________________________
1201 void AliTRDPreprocessorOffline::CorrectFromDetVdriftUsed() {
1203 // Correct from the drift velocity
1206 //printf("Correct for vdrift\n");
1208 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1209 if(!calDetGain) return;
1211 Int_t detVdrift = kVdriftPHDet;
1212 if(fMethodSecond) detVdrift = kVdriftLinear;
1213 AliTRDCalDet *calDetVdrift = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1214 if(!calDetVdrift) return;
1217 if(!fNotEnoughStatisticsForTheVdriftLinear) {
1218 for(Int_t det = 0; det < 540; det++) {
1220 Float_t vdriftinit = fCalDetVdriftUsed->GetValue(det);
1221 Float_t vdriftout = calDetVdrift->GetValue(det);
1223 Float_t gain = calDetGain->GetValue(det);
1224 if(vdriftout > 0.0) gain = gain*vdriftinit/vdriftout;
1225 if(gain < 0.1) gain = 0.1;
1226 if(gain > 1.9) gain = 1.9;
1227 calDetGain->SetValue(det,gain);
1232 Float_t vdriftinit = fCalDetVdriftUsed->CalcMean(kFALSE);
1233 Float_t vdriftout = calDetVdrift->CalcMean(kFALSE);
1234 Float_t factorcorrectif = 1.0;
1235 if(vdriftout > 0.0) factorcorrectif = vdriftinit/vdriftout;
1236 for(Int_t det = 0; det < 540; det++) {
1237 Float_t gain = calDetGain->GetValue(det);
1238 gain = gain*factorcorrectif;
1239 if(gain < 0.1) gain = 0.1;
1240 if(gain > 1.9) gain = 1.9;
1241 calDetGain->SetValue(det,gain);
1247 //_________________________________________________________________________________________________________________
1248 void AliTRDPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage *storage){
1250 // Update OCDB entry
1253 AliCDBMetaData *metaData= new AliCDBMetaData();
1254 metaData->SetObjectClassName("AliTRDCalDet");
1255 metaData->SetResponsible("Raphaelle Bailhache");
1256 metaData->AddDateToComment();
1257 metaData->SetBeamPeriod(1);
1259 AliCDBId id1("TRD/Calib/ChamberGainFactor", startRunNumber, endRunNumber);
1260 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1261 if(calDet) storage->Put(calDet, id1, metaData);
1265 //___________________________________________________________________________________________________________________
1266 void AliTRDPreprocessorOffline::UpdateOCDBExB(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage *storage){
1268 // Update OCDB entry
1271 Int_t detExB = kLorentzLinear;
1272 if(!fMethodSecond) return;
1276 AliCDBMetaData *metaData= new AliCDBMetaData();
1277 metaData->SetObjectClassName("AliTRDCalDet");
1278 metaData->SetResponsible("Raphaelle Bailhache");
1279 metaData->AddDateToComment();
1280 metaData->SetBeamPeriod(1);
1282 AliCDBId id1("TRD/Calib/ChamberExB", startRunNumber, endRunNumber);
1283 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1284 if(calDet) storage->Put(calDet, id1, metaData);
1285 //if(!calDet) printf("No caldet\n");
1288 //___________________________________________________________________________________________________________________
1289 void AliTRDPreprocessorOffline::UpdateOCDBExBAlt(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage *storage){
1291 // Update OCDB entry
1294 Int_t detExB = kExbAlt;
1295 if(!fMethodSecond) return;
1299 AliCDBMetaData *metaData= new AliCDBMetaData();
1300 metaData->SetObjectClassName("AliTRDCalDet");
1301 metaData->SetResponsible("Theo Rascanu");
1302 metaData->AddDateToComment();
1303 metaData->SetBeamPeriod(1);
1305 AliCDBId id1("TRD/Calib/ChamberExBAlt", startRunNumber, endRunNumber);
1306 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1307 if(calDet) storage->Put(calDet, id1, metaData);
1308 //if(!calDet) printf("No caldet\n");
1311 //___________________________________________________________________________________________________________________
1312 void AliTRDPreprocessorOffline::UpdateOCDBVdrift(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage){
1314 // Update OCDB entry
1317 Int_t detVdrift = kVdriftPHDet;
1319 if(fMethodSecond) detVdrift = kVdriftLinear;
1321 AliCDBMetaData *metaData= new AliCDBMetaData();
1322 metaData->SetObjectClassName("AliTRDCalDet");
1323 metaData->SetResponsible("Raphaelle Bailhache");
1324 metaData->AddDateToComment();
1325 metaData->SetBeamPeriod(1);
1327 AliCDBId id1("TRD/Calib/ChamberVdrift", startRunNumber, endRunNumber);
1328 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1329 if(calDet) storage->Put(calDet, id1, metaData);
1333 if(!fMethodSecond) {
1335 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1336 metaDataPad->SetObjectClassName("AliTRDCalPad");
1337 metaDataPad->SetResponsible("Raphaelle Bailhache");
1338 metaDataPad->AddDateToComment();
1339 metaDataPad->SetBeamPeriod(1);
1341 AliCDBId id1Pad("TRD/Calib/LocalVdrift", startRunNumber, endRunNumber);
1342 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1343 if(calPad) storage->Put(calPad, id1Pad, metaDataPad);
1348 //________________________________________________________________________________________________________________________
1349 void AliTRDPreprocessorOffline::UpdateOCDBT0(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage){
1351 // Update OCDB entry
1354 AliCDBMetaData *metaData= new AliCDBMetaData();
1355 metaData->SetObjectClassName("AliTRDCalDet");
1356 metaData->SetResponsible("Raphaelle Bailhache");
1357 metaData->AddDateToComment();
1358 metaData->SetBeamPeriod(1);
1360 AliCDBId id1("TRD/Calib/ChamberT0", startRunNumber, endRunNumber);
1361 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1362 if(calDet) storage->Put(calDet, id1, metaData);
1366 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1367 metaDataPad->SetObjectClassName("AliTRDCalPad");
1368 metaDataPad->SetResponsible("Raphaelle Bailhache");
1369 metaDataPad->AddDateToComment();
1370 metaDataPad->SetBeamPeriod(1);
1372 AliCDBId id1Pad("TRD/Calib/LocalT0", startRunNumber, endRunNumber);
1373 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1374 if(calPad) storage->Put(calPad, id1Pad, metaDataPad);
1379 //_________________________________________________________________________________________________________________
1380 void AliTRDPreprocessorOffline::UpdateOCDBPRF(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage){
1382 // Update OCDB entry
1385 AliCDBMetaData *metaData= new AliCDBMetaData();
1386 metaData->SetObjectClassName("AliTRDCalPad");
1387 metaData->SetResponsible("Raphaelle Bailhache");
1388 metaData->AddDateToComment();
1389 metaData->SetBeamPeriod(1);
1392 AliCDBId id1("TRD/Calib/PRFWidth", startRunNumber, endRunNumber);
1393 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1394 if(calPad) storage->Put(calPad, id1, metaData);
1398 //_________________________________________________________________________________________________________________
1399 void AliTRDPreprocessorOffline::UpdateOCDBPHQ(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage)
1402 // Update OCDB entry
1404 AliCDBMetaData *metaData= new AliCDBMetaData();
1405 metaData->SetObjectClassName("TObjArray");
1406 metaData->SetResponsible("Raphaelle Bailhache and Xianguo Lu");
1407 metaData->AddDateToComment();
1408 metaData->SetBeamPeriod(1);
1410 AliCDBId id1("TRD/Calib/PHQ", startRunNumber, endRunNumber);
1411 TObjArray *cobj = (TObjArray *) fCalibObjects->At(kPHQ);
1414 storage->Put(cobj, id1, metaData);
1418 //_________________________________________________________________________________________________________________
1419 void AliTRDPreprocessorOffline::UpdateOCDBChamberStatus(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage){
1421 // Update OCDB entry
1424 AliCDBMetaData *metaData= new AliCDBMetaData();
1425 metaData->SetObjectClassName("AliTRDCalChamberStatus");
1426 metaData->SetResponsible("Raphaelle Bailhache and Julian Book");
1427 metaData->AddDateToComment();
1428 metaData->SetBeamPeriod(1);
1430 AliCDBId id1("TRD/Calib/ChamberStatus", startRunNumber, endRunNumber);
1431 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1432 if(calChamberStatus) storage->Put(calChamberStatus, id1, metaData);
1436 //__________________________________________________________________________________________________________________________
1437 Bool_t AliTRDPreprocessorOffline::ValidateGain() {
1439 // Validate OCDB entry
1442 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1444 Double_t mean = calDet->GetMean();
1445 Double_t rms = calDet->GetRMSRobust();
1446 if((mean > 0.2) && (mean < 1.4) && (rms < 0.5)) return kTRUE;
1447 //if((mean > 0.2) && (mean < 1.4)) return kTRUE;
1449 fStatusPos = fStatusPos | kGainErrorRange;
1458 //__________________________________________________________________________________________________________________________
1459 Bool_t AliTRDPreprocessorOffline::ValidateVdrift(){
1461 // Update OCDB entry
1464 Int_t detVdrift = kVdriftPHDet;
1467 if(fMethodSecond) detVdrift = kVdriftLinear;
1469 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1471 Double_t mean = calDet->GetMean();
1472 Double_t rms = calDet->GetRMSRobust();
1473 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1474 if(!((mean > 1.0) && (mean < 2.0) && (rms < 0.5))) {
1475 fStatusPos = fStatusPos | kVdriftErrorRange;
1481 if(!fMethodSecond) {
1482 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1484 Double_t mean = calPad->GetMean();
1485 Double_t rms = calPad->GetRMS();
1486 //printf("Vdrift::meanpad %f, rmspad %f\n",mean,rms);
1487 if(!((mean > 0.9) && (mean < 1.1) && (rms < 0.6))) {
1488 fStatusPos = fStatusPos | kVdriftErrorRange;
1498 //__________________________________________________________________________________________________________________________
1499 Bool_t AliTRDPreprocessorOffline::ValidateExB(){
1501 // Update OCDB entry
1504 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
1506 Double_t mean = calDet->GetMean();
1507 Double_t rms = calDet->GetRMSRobust();
1508 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1509 if(!((mean > -1.0) && (mean < 1.0) && (rms < 0.5))) {
1510 fStatusNeg = fStatusNeg | kExBErrorRange;
1518 //__________________________________________________________________________________________________________________________
1519 Bool_t AliTRDPreprocessorOffline::ValidateT0(){
1521 // Update OCDB entry
1524 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1525 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1526 if(calDet && calPad) {
1527 Double_t meandet = calDet->GetMean();
1528 Double_t rmsdet = calDet->GetRMSRobust();
1529 Double_t meanpad = calPad->GetMean();
1530 //Double_t rmspad = calPad->GetRMS();
1531 //printf("T0::minimum %f, rmsdet %f,meanpad %f, rmspad %f\n",meandet,rmsdet,meanpad,rmspad);
1532 if((meandet > -1.5) && (meandet < 5.0) && (rmsdet < 4.0) && (meanpad < 5.0) && (meanpad > -0.5)) return kTRUE;
1534 fStatusPos = fStatusPos | kTimeOffsetErrorRange;
1541 //__________________________________________________________________________________________________________________________
1542 Bool_t AliTRDPreprocessorOffline::ValidatePRF() const{
1544 // Update OCDB entry
1547 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1549 Double_t meanpad = calPad->GetMean();
1550 Double_t rmspad = calPad->GetRMS();
1551 //printf("PRF::meanpad %f, rmspad %f\n",meanpad,rmspad);
1552 if((meanpad < 1.0) && (rmspad < 0.8)) return kTRUE;
1559 //__________________________________________________________________________________________________________________________
1560 Bool_t AliTRDPreprocessorOffline::ValidateChamberStatus(){
1562 // Update OCDB entry
1565 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1566 if(calChamberStatus) {
1568 Int_t detectornodata = 0;
1569 Int_t detectorbadcalib = 0;
1571 for(Int_t sm=0; sm < 18; sm++) {
1572 //printf("%d chambers w/o data in sm %d\n",fNoData[sm],sm);
1573 //printf("%d bad calibrated chambers in sm %d\n",fBadCalib[sm],sm);
1574 if(fNoData[sm] != 30) detectornodata += fNoData[sm];
1575 detectorbadcalib+=fBadCalib[sm];
1577 //printf("Number of chambers w/o data %d\n",detectornodata);
1578 //printf("Number of chambers bad calibrated %d\n",detectorbadcalib);
1580 if((detectornodata > fNoDataValidate) ||
1581 (detectorbadcalib > fBadCalibValidate)){
1582 fStatusPos = fStatusPos | kChamberStatusErrorRange;
1590 //_____________________________________________________________________________
1591 Int_t AliTRDPreprocessorOffline::GetVersion(TString name) const
1594 // Get version from the title
1598 const Char_t *version = "Ver";
1599 if(!strstr(name.Data(),version)) return -1;
1600 const Char_t *after = "Subver";
1601 if(!strstr(name.Data(),after)) return -1;
1603 for(Int_t ver = 0; ver < 999999999; ver++) {
1605 TString vertry(version);
1609 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1611 if(strstr(name.Data(),vertry.Data())) return ver;
1619 //_____________________________________________________________________________
1620 Int_t AliTRDPreprocessorOffline::GetSubVersion(TString name) const
1623 // Get subversion from the title
1627 const Char_t *subversion = "Subver";
1628 if(!strstr(name.Data(),subversion)) return -1;
1629 const Char_t *after = "FirstRun";
1630 if(!strstr(name.Data(),after)) {
1633 if(!strstr(name.Data(),after)) return -1;
1636 for(Int_t ver = 0; ver < 999999999; ver++) {
1638 TString vertry(subversion);
1642 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1644 if(strstr(name.Data(),vertry.Data())) return ver;
1652 //_____________________________________________________________________________
1653 Int_t AliTRDPreprocessorOffline::GetFirstRun(TString name) const
1656 // Get first run from the title
1660 const Char_t *firstrun = "FirstRun";
1661 if(!strstr(name.Data(),firstrun)) return -1;
1662 const Char_t *after = "Nz";
1663 if(!strstr(name.Data(),after)) return -1;
1666 for(Int_t ver = 0; ver < 999999999; ver++) {
1668 TString vertry(firstrun);
1672 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1674 if(strstr(name.Data(),vertry.Data())) return ver;
1681 //_____________________________________________________________________________
1682 Bool_t AliTRDPreprocessorOffline::CheckStatus(Int_t status, Int_t bitMask) const
1685 // Checks the status
1688 return (status & bitMask) ? kTRUE : kFALSE;
1691 //_____________________________________________________________________________
1692 Int_t AliTRDPreprocessorOffline::GetStatus() const
1695 // Checks the status
1696 // fStatusPos: errors
1697 // fStatusNeg: only info
1700 if(fStatusPos > 0) return fStatusPos;
1701 else return (-TMath::Abs(fStatusNeg));
1704 //_____________________________________________________________________________
1705 void AliTRDPreprocessorOffline::PrintStatus() const
1711 AliInfo(Form("The error status is %d",fStatusPos));
1712 AliInfo(Form("IsGainErrorOld? %d",(Int_t)IsGainErrorOld()));
1713 AliInfo(Form("IsVdriftErrorOld? %d",(Int_t)IsVdriftErrorOld()));
1714 AliInfo(Form("IsGainErrorRange? %d",(Int_t)IsGainErrorRange()));
1715 AliInfo(Form("IsVdriftErrorRange? %d",(Int_t)IsVdriftErrorRange()));
1716 AliInfo(Form("IsTimeOffsetErrorRange? %d",(Int_t)IsTimeOffsetErrorRange()));
1717 AliInfo(Form("IsChamberStatusErrorRange? %d",(Int_t)IsChamberStatusErrorRange()));
1720 AliInfo(Form("The info status is %d",fStatusNeg));
1721 AliInfo(Form("IsGainNotEnoughStatsButFill? %d",(Int_t)IsGainNotEnoughStatsButFill()));
1722 AliInfo(Form("IsVdriftNotEnoughStatsButFill? %d",(Int_t)IsVdriftNotEnoughStatsButFill()));
1723 AliInfo(Form("IsGainNotEnoughStatsNotFill? %d",(Int_t)IsGainNotEnoughStatsNotFill()));
1724 AliInfo(Form("IsVdriftNotEnoughStatsNotFill? %d",(Int_t)IsVdriftNotEnoughStatsNotFill()));
1725 AliInfo(Form("IsTimeOffsetNotEnoughStatsNotFill? %d",(Int_t)IsTimeOffsetNotEnoughStatsNotFill()));
1727 AliInfo(Form("IsExBErrorRange? %d",(Int_t)IsExBErrorRange()));
1728 AliInfo(Form("IsExBErrorOld? %d",(Int_t)IsExBErrorOld()));
1731 //___________________________________________________________________________________
1732 void AliTRDPreprocessorOffline::SetCalDetVdrift(AliTRDCalDet *calDetVdriftUsed)
1735 fCalDetVdriftUsed = calDetVdriftUsed;
1737 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1738 for(Int_t k = 0; k < 540; k++){
1739 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1740 //printf("Set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1744 //___________________________________________________________________________________
1745 Bool_t AliTRDPreprocessorOffline::SetCalDetGain(Int_t runNumber, Int_t version, Int_t subversion)
1748 // Set the fCalDetGainUsed
1751 if((version == 0) && (subversion == 0)) return kFALSE;
1753 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor",runNumber, version, subversion);
1755 AliError("Found no entry\n");
1756 fStatusPos = fStatusPos | kGainErrorOld;
1759 //const AliCDBId id = entry->GetId();
1760 //version = id.GetVersion();
1761 //subversion = id.GetSubVersion();
1762 //printf("Found version %d and subversion %d for vdrift\n",version,subversion);
1763 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1764 if(calDet) fCalDetGainUsed = calDet;
1766 fStatusPos = fStatusPos | kGainErrorOld;
1773 //___________________________________________________________________________________
1774 Bool_t AliTRDPreprocessorOffline::SetCalDetVdriftExB(Int_t runNumber, Int_t versionv, Int_t subversionv, Int_t versionexb, Int_t subversionexb)
1777 // Set the fCalDetVdriftUsed and fCalDetExBUsed
1780 if((versionv == 0) && (subversionv == 0)) return kFALSE;
1782 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberVdrift",runNumber, versionv, subversionv);
1784 AliError("Found no entry\n");
1785 fStatusPos = fStatusPos | kVdriftErrorOld;
1788 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1789 if(calDet) fCalDetVdriftUsed = calDet;
1791 fStatusPos = fStatusPos | kVdriftErrorOld;
1797 if((versionexb == 0) && (subversionexb == 0)) {
1799 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1800 for(Int_t k = 0; k < 540; k++){
1801 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1802 //printf("Nothing found: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1808 entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberExB",runNumber, versionexb, subversionexb);
1810 //printf("Found no entry\n");
1811 fStatusPos = fStatusPos | kExBErrorOld;
1814 AliTRDCalDet* calDetexb = (AliTRDCalDet *)entry->GetObject();
1816 fStatusPos = fStatusPos | kExBErrorOld;
1820 Double_t meanexb = calDetexb->GetMean();
1821 //printf("Mean value %f\n",meanexb);
1822 if((meanexb > 70) || (fNoExBUsedInReco)) {
1823 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1824 for(Int_t k = 0; k < 540; k++){
1825 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1826 //printf("Found but: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1830 fCalDetExBUsed = calDetexb;