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, TString 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, TString ocdbStorage){
200 // make calibration of the drift velocity
202 // file - the location of input file
203 // startRunNumber, endRunNumber - run validity period
204 // ocdbStorage - path to the OCDB storage
205 // - if empty - local storage 'pwd' uesed
206 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
210 fVdriftValidated = kTRUE;
211 fT0Validated = kTRUE;
212 fExBValidated = kTRUE;
213 fNotEnoughStatisticsForTheVdriftLinear = kFALSE;
215 // 2. extraction of the information
217 if(ReadVdriftLinearFitGlobal(file) && fCalDetVdriftUsed && fCalDetExBUsed) AnalyzeVdriftLinearFit();
218 if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
220 // 3. Append QA plots
222 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
225 // 4. validate OCDB entries
227 if(fSwitchOnValidation==kTRUE && ValidateVdrift()==kFALSE) {
228 //AliError("TRD vdrift OCDB parameters out of range!");
229 fVdriftValidated = kFALSE;
231 if(fSwitchOnValidation==kTRUE && ValidateT0()==kFALSE) {
232 //AliError("TRD t0 OCDB parameters out of range!");
233 fT0Validated = kFALSE;
235 if(fSwitchOnValidation==kTRUE && ValidateExB()==kFALSE) {
236 //AliError("TRD t0 OCDB parameters out of range!");
237 fExBValidated = kFALSE;
243 if(fVdriftValidated) UpdateOCDBVdrift(startRunNumber,endRunNumber,ocdbStorage);
244 if(fT0Validated) UpdateOCDBT0(startRunNumber,endRunNumber,ocdbStorage);
245 if(fExBValidated) UpdateOCDBExB(startRunNumber,endRunNumber,ocdbStorage);
248 //___________________________________________________________________________________________________________________
250 void AliTRDPreprocessorOffline::CalibExbAlt(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
252 // make calibration of the drift velocity
254 // file - the location of input file
255 // startRunNumber, endRunNumber - run validity period
256 // ocdbStorage - path to the OCDB storage
257 // - if empty - local storage 'pwd' uesed
258 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
264 // 2. extraction of the information
266 if(ReadExbAltFitGlobal(file)) AnalyzeExbAltFit();
268 // 3. Append QA plots
270 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
273 // 4. validate OCDB entries
279 UpdateOCDBExBAlt(startRunNumber,endRunNumber,ocdbStorage);
283 //_________________________________________________________________________________________________________________
285 void AliTRDPreprocessorOffline::CalibGain(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
287 // make calibration of the drift velocity
289 // file - the location of input file
290 // startRunNumber, endRunNumber - run validity period
291 // ocdbStorage - path to the OCDB storage
292 // - if empty - local storage 'pwd' uesed
293 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
295 fNotEnoughStatisticsForTheGain = kFALSE;
298 if(!ReadGainGlobal(file)) return;
301 // 2. extraction of the information
304 if(fBackCorrectGain) CorrectFromDetGainUsed();
305 //if(fBackCorrectVdrift) CorrectFromDetVdriftUsed();
307 // 3. Append QA plots
309 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
312 // 4. validate OCDB entries
314 if(fSwitchOnValidation==kTRUE && ValidateGain()==kFALSE) {
315 //AliError("TRD gain OCDB parameters out of range!");
322 if((!fCalDetVdriftUsed) || (fCalDetVdriftUsed && fVdriftValidated)) UpdateOCDBGain(startRunNumber,endRunNumber,ocdbStorage);
326 //________________________________________________________________________________________________________________
328 void AliTRDPreprocessorOffline::CalibPRF(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
330 // make calibration of the drift velocity
332 // file - the location of input file
333 // startRunNumber, endRunNumber - run validity period
334 // ocdbStorage - path to the OCDB storage
335 // - if empty - local storage 'pwd' uesed
336 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
339 if(!ReadPRFGlobal(file)) return;
342 // 2. extraction of the information
346 // 3. Append QA plots
348 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
352 // 4. validate OCDB entries
354 if(fSwitchOnValidation==kTRUE && ValidatePRF()==kFALSE) {
355 //AliError("TRD prf OCDB parameters out of range!");
362 UpdateOCDBPRF(startRunNumber,endRunNumber,ocdbStorage);
365 //________________________________________________________________________________________________________________
366 void AliTRDPreprocessorOffline::CalibPHQ(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage)
369 // make calibration of puls height Q
371 // startRunNumber, endRunNumber - run validity period
372 // ocdbStorage - path to the OCDB storage
373 // - if empty - local storage 'pwd' uesed
376 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
377 //printf("test %s\n", ocdbStorage.Data());
379 if(!ReadPHQGlobal(file)) return;
381 if(!AnalyzePHQ(startRunNumber)) return;
383 UpdateOCDBPHQ(startRunNumber,endRunNumber,ocdbStorage);
386 //________________________________________________________________________________________________________________
388 void AliTRDPreprocessorOffline::CalibChamberStatus(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
390 // make calibration of the chamber status
392 // startRunNumber, endRunNumber - run validity period
393 // ocdbStorage - path to the OCDB storage
394 // - if empty - local storage 'pwd' uesed
395 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
399 if(!ReadStatusGlobal(file)) return;
403 // 2. extraction of the information
405 if(!AnalyzeChamberStatus()) return;
407 // 3. Append QA plots
409 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
413 // 4. validate OCDB entries
415 if(fSwitchOnValidation==kTRUE && ValidateChamberStatus()==kFALSE) {
416 //AliError("TRD Chamber status OCDB parameters not ok!");
423 if((!fNotEnoughStatisticsForTheVdriftLinear) && (!fNotEnoughStatisticsForTheGain)) UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
424 //UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
427 //______________________________________________________________________________________________________
428 Bool_t AliTRDPreprocessorOffline::Init(const Char_t* fileName){
430 // read the calibration used during the reconstruction
433 if(ReadVdriftT0Global(fileName)) {
435 TString nameph = fPH2d->GetTitle();
436 fFirstRunVdriftUsed = GetFirstRun(nameph);
437 fVersionVdriftUsed = GetVersion(nameph);
438 fSubVersionVdriftUsed = GetSubVersion(nameph);
440 //printf("Found Version %d, Subversion %d for vdrift\n",fVersionVdriftUsed,fSubVersionVdriftUsed);
444 if(ReadGainGlobal(fileName)) {
446 TString namech = fCH2d->GetTitle();
447 fFirstRunGainUsed = GetFirstRun(namech);
448 fVersionGainUsed = GetVersion(namech);
449 fSubVersionGainUsed = GetSubVersion(namech);
451 //printf("Found Version %d, Subversion %d for gain\n",fVersionGainUsed,fSubVersionGainUsed);
455 if(ReadVdriftLinearFitGlobal(fileName)) {
457 TString namelinear = fAliTRDCalibraVdriftLinearFit->GetNameCalibUsed();
458 fFirstRunExBUsed = GetFirstRun(namelinear);
459 fVersionExBUsed = GetVersion(namelinear);
460 fSubVersionExBUsed = GetSubVersion(namelinear);
462 //printf("Found Version %d, Subversion %d, run %d for ExB\n",fVersionExBUsed,fSubVersionExBUsed,fFirstRunExBUsed);
466 if(fVersionVdriftUsed == 0) fStatusPos = fStatusPos |kVdriftErrorOld;
467 if(fVersionGainUsed == 0) fStatusPos = fStatusPos | kGainErrorOld;
472 //___________________________________________________________________________________________________________________
474 Bool_t AliTRDPreprocessorOffline::ReadStatusGlobal(const Char_t* fileName){
476 // read calibration entries from file
478 if(fSparse) return kTRUE;
479 TFile fcalib(fileName);
480 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
482 fSparse = (THnSparseI *) array->FindObject("NumberOfEntries");
483 if(!fSparse) return kFALSE;
491 //___________________________________________________________________________________________________________________
493 Bool_t AliTRDPreprocessorOffline::ReadPHQGlobal(const Char_t* fileName)
496 // read calibration entries from file
499 return AliTRDdEdxCalibUtils::ReadHistArray(fileName, fNameList);
502 //___________________________________________________________________________________________________________________
504 Bool_t AliTRDPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
506 // read calibration entries from file
508 if(fCH2d) return kTRUE;
509 TFile fcalib(fileName);
510 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
512 TH2I *ch2d = (TH2I *) array->FindObject("CH2d");
513 if(!ch2d) return kFALSE;
514 fCH2d = (TH2I*)ch2d->Clone();
515 //fNEvents = (TH1I *) array->FindObject("NEvents");
516 //fAbsoluteGain = (TH2F *) array->FindObject("AbsoluteGain");
518 TH2I *ch2d = (TH2I *) fcalib.Get("CH2d");
519 if(!ch2d) return kFALSE;
520 fCH2d = (TH2I*)ch2d->Clone();
521 //fNEvents = (TH1I *) fcalib.Get("NEvents");
522 //fAbsoluteGain = (TH2F *) fcalib.Get("AbsoluteGain");
524 fCH2d->SetDirectory(0);
525 //printf("title of CH2d %s\n",fCH2d->GetTitle());
530 //_________________________________________________________________________________________________________________
532 Bool_t AliTRDPreprocessorOffline::ReadVdriftT0Global(const Char_t* fileName){
534 // read calibration entries from file
536 if(fPH2d) return kTRUE;
537 TFile fcalib(fileName);
538 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
540 TProfile2D *ph2d = (TProfile2D *) array->FindObject("PH2d");
541 if(!ph2d) return kFALSE;
542 fPH2d = (TProfile2D*)ph2d->Clone();
543 //fNEvents = (TH1I *) array->FindObject("NEvents");
545 TProfile2D *ph2d = (TProfile2D *) fcalib.Get("PH2d");
546 if(!ph2d) return kFALSE;
547 fPH2d = (TProfile2D*)ph2d->Clone();
548 //fNEvents = (TH1I *) fcalib.Get("NEvents");
550 fPH2d->SetDirectory(0);
551 //printf("title of PH2d %s\n",fPH2d->GetTitle());
556 //___________________________________________________________________________________________________________________
558 Bool_t AliTRDPreprocessorOffline::ReadVdriftLinearFitGlobal(const Char_t* fileName){
560 // read calibration entries from file
562 if(fAliTRDCalibraVdriftLinearFit) return kTRUE;
563 TFile fcalib(fileName);
564 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
566 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) array->FindObject("AliTRDCalibraVdriftLinearFit");
567 //fNEvents = (TH1I *) array->FindObject("NEvents");
569 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) fcalib.Get("AliTRDCalibraVdriftLinearFit");
570 //fNEvents = (TH1I *) fcalib.Get("NEvents");
572 if(!fAliTRDCalibraVdriftLinearFit) {
573 //printf("No AliTRDCalibraVdriftLinearFit\n");
579 //_____________________________________________________________________________________________________________
580 Bool_t AliTRDPreprocessorOffline::ReadExbAltFitGlobal(const Char_t* fileName){
582 // read calibration entries from file
584 if(fAliTRDCalibraExbAltFit) return kTRUE;
585 TFile fcalib(fileName);
586 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
588 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) array->FindObject("AliTRDCalibraExbAltFit");
589 //fNEvents = (TH1I *) array->FindObject("NEvents");
591 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) fcalib.Get("AliTRDCalibraExbAltFit");
592 //fNEvents = (TH1I *) fcalib.Get("NEvents");
594 if(!fAliTRDCalibraExbAltFit) {
595 //printf("No AliTRDCalibraExbAltFit\n");
601 //_____________________________________________________________________________________________________________
603 Bool_t AliTRDPreprocessorOffline::ReadPRFGlobal(const Char_t* fileName){
605 // read calibration entries from file
607 if(fPRF2d) return kTRUE;
608 TFile fcalib(fileName);
609 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
611 TProfile2D *prf2d = (TProfile2D *) array->FindObject("PRF2d");
612 if(!prf2d) return kFALSE;
613 fPRF2d = (TProfile2D*)prf2d->Clone();
614 //fNEvents = (TH1I *) array->FindObject("NEvents");
616 TProfile2D *prf2d = (TProfile2D *) fcalib.Get("PRF2d");
617 if(!prf2d) return kFALSE;
618 fPRF2d = (TProfile2D*)prf2d->Clone();
619 //fNEvents = (TH1I *) fcalib.Get("NEvents");
621 fPRF2d->SetDirectory(0);
622 //printf("title of PRF2d %s\n",fPRF2d->GetTitle());
627 //__________________________________________________________________________________________________________
629 Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
631 // Analyze gain - produce the calibration objects
634 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
635 calibra->ChooseMethod(fMethodeGain);
636 calibra->SetBeginFitCharge(fBeginFitCharge);
637 calibra->SetFitOutliersChargeLow(fOutliersFitChargeLow);
638 calibra->SetFitOutliersChargeHigh(fOutliersFitChargeHigh);
639 calibra->SetMinEntries(fMinStatsGain); // If there is less than 1000 entries in the histo: no fit
640 calibra->AnalyseCH(fCH2d);
642 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
643 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
644 Int_t nbfit = calibra->GetNumberFit();
645 Int_t nbE = calibra->GetNumberEnt();
649 Bool_t meanother = kFALSE;
652 (nbfit >= 0.5*nbE) && (nbE > 30)) {
653 // create the cal objects
654 if(!fBackCorrectGain) {
655 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
658 TObjArray object = calibra->GetVectorFit();
659 AliTRDCalDet *calDetGain = calibra->CreateDetObjectGain(&object,meanother);
660 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
661 // Put them in the array
662 fCalibObjects->AddAt(calDetGain,kGain);
663 fPlots->AddAt(coefGain,kGain);
668 fNotEnoughStatisticsForTheGain = kTRUE;
669 Int_t minStatsGain = fMinStatsGain*30;
670 calibra->SetMinEntries(minStatsGain); // Because we do it for all, we increase this
671 Double_t gainoverallnotnormalized = calibra->AnalyseCHAllTogether(fCH2d);
672 if(fCalDetGainUsed && (gainoverallnotnormalized > 0.0)) {
673 AliTRDCalDet *calDetGain = new AliTRDCalDet(*fCalDetGainUsed);
674 Double_t oldmean = fCalDetGainUsed->CalcMean(kFALSE);
675 //printf("oldmean %f\n",oldmean);
677 Double_t scalefactor = calibra->GetScaleFactorGain();
678 //printf("Correction factor %f\n",gainoverallnotnormalized*scalefactor);
679 calDetGain->Multiply(gainoverallnotnormalized*scalefactor/oldmean);
680 //printf("newmean %f\n",calDetGain->CalcMean(kFALSE));
681 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
682 fCalibObjects->AddAt(calDetGain,kGain);
683 fPlots->AddAt(coefGain,kGain);
686 fStatusNeg = fStatusNeg | kGainNotEnoughStatsButFill;
689 fStatusPos = fStatusPos | kGainErrorOld;
693 if(gainoverallnotnormalized <= 0.0) fStatusNeg = fStatusNeg | kGainNotEnoughStatsNotFill;
694 if(!fCalDetGainUsed) fStatusPos = fStatusPos | kGainErrorOld;
698 calibra->ResetVectorFit();
703 //_____________________________________________________________________________________________________
704 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftT0(){
706 // Analyze VdriftT0 - produce the calibration objects
709 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
710 calibra->SetMinEntries(fMinStatsVdriftT0PH); // If there is less than 1000 entries in the histo: no fit
711 calibra->AnalysePH(fPH2d);
713 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
714 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
715 Int_t nbfit = calibra->GetNumberFit();
716 Int_t nbfitSuccess = calibra->GetNumberFitSuccess();
717 Int_t nbE = calibra->GetNumberEnt();
719 //printf("nbtg %d, nbfit %d, nbE %d, nbfitSuccess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
723 (nbfit >= 0.5*nbE) && (nbE > 30) && (nbfitSuccess > 30)) {
724 //printf("Pass the cut for VdriftT0\n");
725 // create the cal objects
726 calibra->RemoveOutliers(1,kFALSE);
727 calibra->PutMeanValueOtherVectorFit(1,kFALSE);
728 calibra->RemoveOutliers2(kFALSE);
729 calibra->PutMeanValueOtherVectorFit2(1,kFALSE);
731 TObjArray object = calibra->GetVectorFit();
732 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object);
733 TH1F *coefVdriftPH = calDetVdrift->MakeHisto1DAsFunctionOfDet();
734 AliTRDCalPad *calPadVdrift = (AliTRDCalPad *)calibra->CreatePadObjectVdrift(&object,calDetVdrift);
735 TH1F *coefPadVdrift = calPadVdrift->MakeHisto1D();
736 object = calibra->GetVectorFit2();
737 AliTRDCalDet *calDetT0 = calibra->CreateDetObjectT0(&object);
738 TH1F *coefT0 = calDetT0->MakeHisto1DAsFunctionOfDet();
739 AliTRDCalPad *calPadT0 = (AliTRDCalPad *)calibra->CreatePadObjectT0(&object,calDetT0);
740 TH1F *coefPadT0 = calPadT0->MakeHisto1D();
741 // Put them in the array
742 fCalibObjects->AddAt(calDetT0,kT0PHDet);
743 fCalibObjects->AddAt(calDetVdrift,kVdriftPHDet);
744 fCalibObjects->AddAt(calPadT0,kT0PHPad);
745 fCalibObjects->AddAt(calPadVdrift,kVdriftPHPad);
746 fPlots->AddAt(coefVdriftPH,kVdriftPHDet);
747 fPlots->AddAt(coefT0,kT0PHDet);
748 fPlots->AddAt(coefPadVdrift,kVdriftPHPad);
749 fPlots->AddAt(coefPadT0,kT0PHPad);
754 //printf("Not enough stats timeoffset\n");
755 fStatusNeg = fStatusNeg | kTimeOffsetNotEnoughStatsNotFill;
757 calibra->ResetVectorFit();
762 //____________________________________________________________________________________________________________________
763 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftLinearFit(){
765 // Analyze vdrift linear fit - produce the calibration objects
768 //printf("Analyse linear fit\n");
771 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
772 calibra->SetCalDetVdriftExB(fCalDetVdriftUsed,fCalDetExBUsed);
773 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
774 printf("The mean stat is by %d for VdriftLinear\n",fMinStatsVdriftLinear);
775 //printf("Fill PE Array\n");
776 fAliTRDCalibraVdriftLinearFit->SetRobustFit(fRobustFitDriftVelocity);
777 fAliTRDCalibraVdriftLinearFit->SetMinNumberOfPointsForFit(fMinNbOfPointVdriftFit);
778 if(!fAlternativeVdrfitFit)
779 fAliTRDCalibraVdriftLinearFit->FillPEArray();
781 fAliTRDCalibraVdriftLinearFit->FillPEArray2();
782 //printf("AliTRDCalibraFit\n");
783 calibra->AnalyseLinearFitters(fAliTRDCalibraVdriftLinearFit);
787 Int_t nbfit = calibra->GetNumberFit();
788 Int_t nbE = calibra->GetNumberEnt();
793 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
794 // create the cal objects
795 //calibra->RemoveOutliers(1,kTRUE);
796 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
797 //calibra->RemoveOutliers2(kTRUE);
798 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
800 TObjArray object = calibra->GetVectorFit();
801 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object,kTRUE);
802 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
803 object = calibra->GetVectorFit2();
804 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectLorentzAngle(&object);
805 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
806 //if(!calDetLorentz) printf("No lorentz created\n");
807 // Put them in the array
808 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
809 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
810 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
811 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
816 fNotEnoughStatisticsForTheVdriftLinear = kTRUE;
817 Int_t minNumberOfEntriesForAll = fMinStatsVdriftLinear*30;
818 calibra->SetMinEntries(minNumberOfEntriesForAll); // Because we do it for all, we increase this
819 Double_t vdriftoverall = -100.0;
820 Double_t exboverall = 100.0;
821 calibra->AnalyseLinearFittersAllTogether(fAliTRDCalibraVdriftLinearFit,vdriftoverall,exboverall);
822 //printf("Found mean vdrift %f and exb %f\n",vdriftoverall,exboverall);
823 if(fCalDetVdriftUsed && (vdriftoverall > 0.0) && (exboverall < 70.0)) {
824 AliTRDCalDet *calDetVdrift = new AliTRDCalDet(*fCalDetVdriftUsed);
825 AliTRDCalDet *calDetLorentz = new AliTRDCalDet(*fCalDetExBUsed);
826 Double_t oldmeanvdrift = fCalDetVdriftUsed->CalcMean(kFALSE);
827 Double_t oldmeanexb = fCalDetExBUsed->CalcMean(kFALSE);
828 //printf("oldmean %f\n",oldmean);
829 if((oldmeanvdrift > 0.0) && (oldmeanexb < 70.0)) {
830 //printf("Correction factor %f\n",vdriftoverall);
831 calDetVdrift->Multiply(vdriftoverall/oldmeanvdrift);
832 if(TMath::Abs(oldmeanexb) > 0.0001) calDetLorentz->Multiply(exboverall/oldmeanexb);
833 //printf("newmean %f\n",calDetVdrift->CalcMean(kFALSE));
834 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
835 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
836 // Put them in the array
837 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
838 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
839 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
840 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
843 fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsButFill;
846 if(oldmeanvdrift) fStatusPos = fStatusPos | kVdriftErrorOld;
847 if(oldmeanexb) fStatusPos = fStatusPos | kExBErrorOld;
851 if((vdriftoverall <= 0.0) && (exboverall > 70.0)) fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsNotFill;
852 if(!fCalDetVdriftUsed) fStatusPos = fStatusPos | kVdriftErrorOld;
853 if(!fCalDetExBUsed) fStatusPos = fStatusPos | kExBErrorOld;
857 calibra->ResetVectorFit();
862 //________________________________________________________________________________________________________________
864 Bool_t AliTRDPreprocessorOffline::AnalyzeExbAltFit(){
866 // Analyze vdrift linear fit - produce the calibration objects
869 //printf("Analyse linear fit\n");
872 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
873 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
874 //printf("Fill PE Array\n");
875 fAliTRDCalibraExbAltFit->SetRobustFit(fRobustFitExbAlt);
876 if(!fAlternativeExbAltFit)
877 fAliTRDCalibraExbAltFit->FillPEArray();
879 fAliTRDCalibraExbAltFit->FillPEArray2();
880 //printf("AliTRDCalibraFit\n");
881 calibra->AnalyseExbAltFit(fAliTRDCalibraExbAltFit);
885 Int_t nbfit = calibra->GetNumberFit();
886 Int_t nbE = calibra->GetNumberEnt();
891 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
892 // create the cal objects
893 //calibra->RemoveOutliers(1,kTRUE);
894 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
896 TObjArray object = calibra->GetVectorFit2();
897 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectExbAlt(&object);
898 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
899 //if(!calDetLorentz) printf("No lorentz created\n");
900 // Put them in the array
901 fCalibObjects->AddAt(calDetLorentz,kExbAlt);
902 fPlots->AddAt(coefLorentzAngle,kExbAlt);
907 calibra->ResetVectorFit();
912 //________________________________________________________________________________________________________________
914 Bool_t AliTRDPreprocessorOffline::AnalyzePRF(){
916 // Analyze PRF - produce the calibration objects
919 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
920 calibra->SetMinEntries(fMinStatsPRF); // If there is less than 1000 entries in the histo: no fit
921 calibra->AnalysePRFMarianFit(fPRF2d);
923 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
924 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
925 Int_t nbfit = calibra->GetNumberFit();
926 Int_t nbE = calibra->GetNumberEnt();
932 (nbfit >= 0.95*nbE) && (nbE > 30)) {
933 // create the cal objects
934 TObjArray object = calibra->GetVectorFit();
935 AliTRDCalPad *calPadPRF = (AliTRDCalPad*) calibra->CreatePadObjectPRF(&object);
936 TH1F *coefPRF = calPadPRF->MakeHisto1D();
937 // Put them in the array
938 fCalibObjects->AddAt(calPadPRF,kPRF);
939 fPlots->AddAt(coefPRF,kPRF);
944 calibra->ResetVectorFit();
950 //_____________________________________________________________________________
951 Bool_t AliTRDPreprocessorOffline::AnalyzePHQ(Int_t startRunNumber)
954 //Produce PHQ calibration results
957 TTreeSRedirector *calibStream = 0x0;
962 calibStream = new TTreeSRedirector(Form("TRDCalibStream_%010d.root", startRunNumber));
965 for(Int_t iter=0; iter<AliTRDdEdxCalibUtils::GetHistArray()->GetSize(); iter++){
966 THnBase *hi = (THnBase*) AliTRDdEdxCalibUtils::GetHistAt(iter);
967 TObjArray *obji = AliTRDdEdxCalibUtils::HistToObj(hi, startRunNumber, lout, calibStream);
968 //printf("test analyze %s\n", obji->GetName());
969 AliTRDdEdxCalibUtils::GetObjArray()->AddAt(obji, iter);
972 fCalibObjects->AddAt(AliTRDdEdxCalibUtils::GetObjArray(), kPHQ);
975 TFile *fout=new TFile(Form("TRDCalibList_%010d.root", startRunNumber),"recreate");
988 //_____________________________________________________________________________
989 Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
992 // Produce AliTRDCalChamberStatus out of calibration results
995 // set up AliTRDCalibChamberStatus
996 AliTRDCalibChamberStatus *chamberStatus = new AliTRDCalibChamberStatus();
997 chamberStatus->SetSparseI(fSparse);
998 chamberStatus->AnalyseHisto(fMinStatsChamberStatus, fMinSingleStatsChamberStatus);
999 // get AliTRDCalChamberStatus
1000 AliTRDCalChamberStatus *calChamberStatus = chamberStatus->GetCalChamberStatus();
1002 // get calibration objects
1003 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1004 AliTRDCalDet *calDetVDrift = (AliTRDCalDet *) fCalibObjects->At(kVdriftLinear);
1005 AliTRDCalDet *calDetExB = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
1008 if((!calDetGain) || (!calDetVDrift) || (!fCH2d) || (!calDetExB) || (!calChamberStatus)) return kFALSE;
1011 Double_t gainmean = calDetGain->GetMean();
1012 Double_t vdriftmean = calDetVDrift->GetMean();
1013 Double_t exbmean = calDetExB->GetMean();
1015 Double_t gainrms = calDetGain->GetRMSRobust();
1016 Double_t vdriftrms = calDetVDrift->GetRMSRobust();
1017 Double_t exbrms = calDetExB->GetRMSRobust();
1019 //printf("Gain mean: %f, rms: %f\n",gainmean,gainrms);
1020 //printf("Vdrift mean: %f, rms: %f\n",vdriftmean,vdriftrms);
1021 //printf("ExB mean: %f, rms: %f\n",exbmean,exbrms);
1024 if((TMath::Abs(gainrms) < 0.001) || (TMath::Abs(vdriftrms) < 0.001) || (TMath::Abs(exbrms) < 0.0000001)) return kFALSE;
1026 // mask chambers with empty gain entries
1027 //Int_t counter = 0;
1028 for (Int_t idet = 0; idet < 540; idet++) {
1031 TH1I *projch = (TH1I *) fCH2d->ProjectionX("projch",idet+1,idet+1,(Option_t *)"e");
1032 Double_t entries = projch->GetEntries();
1033 //printf("Number of entries %f for det %d\n",entries,idet);
1036 Double_t gain = calDetGain->GetValue(idet);
1039 Double_t vdrift = calDetVDrift->GetValue(idet);
1042 Double_t exb = calDetExB->GetValue(idet);
1045 if( (entries<50 && !calChamberStatus->IsNoData(idet)) ||
1046 TMath::Abs(gainmean-gain) > (fRMSBadCalibratedGain*gainrms) ||
1047 TMath::Abs(vdriftmean-vdrift) > (fRMSBadCalibratedVdrift*vdriftrms) ||
1048 TMath::Abs(exbmean-exb) > (fRMSBadCalibratedExB*exbrms) ) {
1050 //printf(" chamber det %03d masked \n",idet);
1051 //printf(" gainmean %f and gain %f, gainrms %f \n",gainmean,gain,gainrms);
1052 //printf(" vdriftmean %f and vdrift %f, vdriftrms %f \n",vdriftmean,vdrift,vdriftrms);
1053 //printf(" exbmean %f and exb %f, exbrms %f \n",exbmean,exb,exbrms);
1055 calChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kBadCalibrated);
1064 for(Int_t sm=0; sm < 18; sm++) {
1066 Int_t smbadcalib = 0;
1067 for(Int_t det = 0; det < 30; det++){
1068 Int_t detector = sm*30+det;
1069 if(calChamberStatus->IsNoData(detector)) smnodata++;
1071 if(calChamberStatus->IsBadCalibrated(detector)) smbadcalib++;
1074 fNoData[sm] = smnodata;
1075 fBadCalib[sm]= smbadcalib;
1076 //printf("No Data %d, bad calibrated %d for %d\n",fNoData[sm],fBadCalib[sm],sm);
1080 // for(Int_t sm=0; sm < 18; sm++) {
1081 // Int_t counter = 0;
1082 // for(Int_t det = 0; det < 30; det++){
1083 // Int_t detector = sm*30+det;
1084 // if(calChamberStatus->IsBadCalibrated(detector)) counter++;
1086 // if(counter >= 20) {
1087 // for(Int_t det = 0; det < 30; det++){
1088 // Int_t detector = sm*30+det;
1089 // calChamberStatus->SetStatus(detector,AliTRDCalChamberStatus::kGood);
1094 fCalibObjects->AddAt(calChamberStatus,kChamberStatus);
1100 //________________________________________________________________________________________________
1101 void AliTRDPreprocessorOffline::CorrectFromDetGainUsed() {
1103 // Correct from the gas gain used afterwards
1105 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1106 if(!calDetGain) return;
1109 Double_t mean = 0.0;
1112 for(Int_t det = 0; det < 540; det++) {
1114 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1115 Float_t gainout = calDetGain->GetValue(det);
1118 if(TMath::Abs(gainout-1.0) > 0.000001) {
1119 mean += (gaininit*gainout);
1123 if(nbdet > 0) mean = mean/nbdet;
1125 for(Int_t det = 0; det < 540; det++) {
1127 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1128 Float_t gainout = calDetGain->GetValue(det);
1130 if(TMath::Abs(gainout-1.0) > 0.000001) {
1131 Double_t newgain = gaininit*gainout;
1132 if(newgain < 0.1) newgain = 0.1;
1133 if(newgain > 1.9) newgain = 1.9;
1134 calDetGain->SetValue(det,newgain);
1137 Double_t newgain = mean;
1138 if(newgain < 0.1) newgain = 0.1;
1139 if(newgain > 1.9) newgain = 1.9;
1140 calDetGain->SetValue(det,newgain);
1146 //________________________________________________________________________________________________
1147 void AliTRDPreprocessorOffline::CorrectFromDetVdriftUsed() {
1149 // Correct from the drift velocity
1152 //printf("Correct for vdrift\n");
1154 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1155 if(!calDetGain) return;
1157 Int_t detVdrift = kVdriftPHDet;
1158 if(fMethodSecond) detVdrift = kVdriftLinear;
1159 AliTRDCalDet *calDetVdrift = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1160 if(!calDetVdrift) return;
1163 if(!fNotEnoughStatisticsForTheVdriftLinear) {
1164 for(Int_t det = 0; det < 540; det++) {
1166 Float_t vdriftinit = fCalDetVdriftUsed->GetValue(det);
1167 Float_t vdriftout = calDetVdrift->GetValue(det);
1169 Float_t gain = calDetGain->GetValue(det);
1170 if(vdriftout > 0.0) gain = gain*vdriftinit/vdriftout;
1171 if(gain < 0.1) gain = 0.1;
1172 if(gain > 1.9) gain = 1.9;
1173 calDetGain->SetValue(det,gain);
1178 Float_t vdriftinit = fCalDetVdriftUsed->CalcMean(kFALSE);
1179 Float_t vdriftout = calDetVdrift->CalcMean(kFALSE);
1180 Float_t factorcorrectif = 1.0;
1181 if(vdriftout > 0.0) factorcorrectif = vdriftinit/vdriftout;
1182 for(Int_t det = 0; det < 540; det++) {
1183 Float_t gain = calDetGain->GetValue(det);
1184 gain = gain*factorcorrectif;
1185 if(gain < 0.1) gain = 0.1;
1186 if(gain > 1.9) gain = 1.9;
1187 calDetGain->SetValue(det,gain);
1193 //_________________________________________________________________________________________________________________
1194 void AliTRDPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1196 // Update OCDB entry
1199 AliCDBMetaData *metaData= new AliCDBMetaData();
1200 metaData->SetObjectClassName("AliTRDCalDet");
1201 metaData->SetResponsible("Raphaelle Bailhache");
1202 metaData->AddDateToComment();
1203 metaData->SetBeamPeriod(1);
1205 AliCDBId id1("TRD/Calib/ChamberGainFactor", startRunNumber, endRunNumber);
1206 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1207 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1208 if(calDet) gStorage->Put(calDet, id1, metaData);
1212 //___________________________________________________________________________________________________________________
1213 void AliTRDPreprocessorOffline::UpdateOCDBExB(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1215 // Update OCDB entry
1218 Int_t detExB = kLorentzLinear;
1219 if(!fMethodSecond) return;
1223 AliCDBMetaData *metaData= new AliCDBMetaData();
1224 metaData->SetObjectClassName("AliTRDCalDet");
1225 metaData->SetResponsible("Raphaelle Bailhache");
1226 metaData->AddDateToComment();
1227 metaData->SetBeamPeriod(1);
1229 AliCDBId id1("TRD/Calib/ChamberExB", startRunNumber, endRunNumber);
1230 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1231 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1232 if(calDet) gStorage->Put(calDet, id1, metaData);
1233 //if(!calDet) printf("No caldet\n");
1236 //___________________________________________________________________________________________________________________
1237 void AliTRDPreprocessorOffline::UpdateOCDBExBAlt(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1239 // Update OCDB entry
1242 Int_t detExB = kExbAlt;
1243 if(!fMethodSecond) return;
1247 AliCDBMetaData *metaData= new AliCDBMetaData();
1248 metaData->SetObjectClassName("AliTRDCalDet");
1249 metaData->SetResponsible("Theo Rascanu");
1250 metaData->AddDateToComment();
1251 metaData->SetBeamPeriod(1);
1253 AliCDBId id1("TRD/Calib/ChamberExBAlt", startRunNumber, endRunNumber);
1254 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1255 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1256 if(calDet) gStorage->Put(calDet, id1, metaData);
1257 //if(!calDet) printf("No caldet\n");
1260 //___________________________________________________________________________________________________________________
1261 void AliTRDPreprocessorOffline::UpdateOCDBVdrift(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1263 // Update OCDB entry
1266 Int_t detVdrift = kVdriftPHDet;
1268 if(fMethodSecond) detVdrift = kVdriftLinear;
1270 AliCDBMetaData *metaData= new AliCDBMetaData();
1271 metaData->SetObjectClassName("AliTRDCalDet");
1272 metaData->SetResponsible("Raphaelle Bailhache");
1273 metaData->AddDateToComment();
1274 metaData->SetBeamPeriod(1);
1276 AliCDBId id1("TRD/Calib/ChamberVdrift", startRunNumber, endRunNumber);
1277 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1278 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1279 if(calDet) gStorage->Put(calDet, id1, metaData);
1283 if(!fMethodSecond) {
1285 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1286 metaDataPad->SetObjectClassName("AliTRDCalPad");
1287 metaDataPad->SetResponsible("Raphaelle Bailhache");
1288 metaDataPad->AddDateToComment();
1289 metaDataPad->SetBeamPeriod(1);
1291 AliCDBId id1Pad("TRD/Calib/LocalVdrift", startRunNumber, endRunNumber);
1292 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1293 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
1298 //________________________________________________________________________________________________________________________
1299 void AliTRDPreprocessorOffline::UpdateOCDBT0(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1301 // Update OCDB entry
1304 AliCDBMetaData *metaData= new AliCDBMetaData();
1305 metaData->SetObjectClassName("AliTRDCalDet");
1306 metaData->SetResponsible("Raphaelle Bailhache");
1307 metaData->AddDateToComment();
1308 metaData->SetBeamPeriod(1);
1310 AliCDBId id1("TRD/Calib/ChamberT0", startRunNumber, endRunNumber);
1311 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1312 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1313 if(calDet) gStorage->Put(calDet, id1, metaData);
1317 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1318 metaDataPad->SetObjectClassName("AliTRDCalPad");
1319 metaDataPad->SetResponsible("Raphaelle Bailhache");
1320 metaDataPad->AddDateToComment();
1321 metaDataPad->SetBeamPeriod(1);
1323 AliCDBId id1Pad("TRD/Calib/LocalT0", startRunNumber, endRunNumber);
1324 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1325 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
1330 //_________________________________________________________________________________________________________________
1331 void AliTRDPreprocessorOffline::UpdateOCDBPRF(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1333 // Update OCDB entry
1336 AliCDBMetaData *metaData= new AliCDBMetaData();
1337 metaData->SetObjectClassName("AliTRDCalPad");
1338 metaData->SetResponsible("Raphaelle Bailhache");
1339 metaData->AddDateToComment();
1340 metaData->SetBeamPeriod(1);
1343 AliCDBId id1("TRD/Calib/PRFWidth", startRunNumber, endRunNumber);
1344 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1345 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1346 if(calPad) gStorage->Put(calPad, id1, metaData);
1350 //_________________________________________________________________________________________________________________
1351 void AliTRDPreprocessorOffline::UpdateOCDBPHQ(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath)
1354 // Update OCDB entry
1356 AliCDBMetaData *metaData= new AliCDBMetaData();
1357 metaData->SetObjectClassName("TObjArray");
1358 metaData->SetResponsible("Raphaelle Bailhache and Xianguo Lu");
1359 metaData->AddDateToComment();
1360 metaData->SetBeamPeriod(1);
1362 AliCDBId id1("TRD/Calib/PHQ", startRunNumber, endRunNumber);
1363 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1364 TObjArray *cobj = (TObjArray *) fCalibObjects->At(kPHQ);
1367 gStorage->Put(cobj, id1, metaData);
1371 //_________________________________________________________________________________________________________________
1372 void AliTRDPreprocessorOffline::UpdateOCDBChamberStatus(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1374 // Update OCDB entry
1377 AliCDBMetaData *metaData= new AliCDBMetaData();
1378 metaData->SetObjectClassName("AliTRDCalChamberStatus");
1379 metaData->SetResponsible("Raphaelle Bailhache and Julian Book");
1380 metaData->AddDateToComment();
1381 metaData->SetBeamPeriod(1);
1383 AliCDBId id1("TRD/Calib/ChamberStatus", startRunNumber, endRunNumber);
1384 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1385 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1386 if(calChamberStatus) gStorage->Put(calChamberStatus, id1, metaData);
1390 //__________________________________________________________________________________________________________________________
1391 Bool_t AliTRDPreprocessorOffline::ValidateGain() {
1393 // Validate OCDB entry
1396 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1398 Double_t mean = calDet->GetMean();
1399 Double_t rms = calDet->GetRMSRobust();
1400 if((mean > 0.2) && (mean < 1.4) && (rms < 0.5)) return kTRUE;
1401 //if((mean > 0.2) && (mean < 1.4)) return kTRUE;
1403 fStatusPos = fStatusPos | kGainErrorRange;
1412 //__________________________________________________________________________________________________________________________
1413 Bool_t AliTRDPreprocessorOffline::ValidateVdrift(){
1415 // Update OCDB entry
1418 Int_t detVdrift = kVdriftPHDet;
1421 if(fMethodSecond) detVdrift = kVdriftLinear;
1423 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1425 Double_t mean = calDet->GetMean();
1426 Double_t rms = calDet->GetRMSRobust();
1427 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1428 if(!((mean > 1.0) && (mean < 2.0) && (rms < 0.5))) {
1429 fStatusPos = fStatusPos | kVdriftErrorRange;
1435 if(!fMethodSecond) {
1436 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1438 Double_t mean = calPad->GetMean();
1439 Double_t rms = calPad->GetRMS();
1440 //printf("Vdrift::meanpad %f, rmspad %f\n",mean,rms);
1441 if(!((mean > 0.9) && (mean < 1.1) && (rms < 0.6))) {
1442 fStatusPos = fStatusPos | kVdriftErrorRange;
1452 //__________________________________________________________________________________________________________________________
1453 Bool_t AliTRDPreprocessorOffline::ValidateExB(){
1455 // Update OCDB entry
1458 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
1460 Double_t mean = calDet->GetMean();
1461 Double_t rms = calDet->GetRMSRobust();
1462 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1463 if(!((mean > -1.0) && (mean < 1.0) && (rms < 0.5))) {
1464 fStatusNeg = fStatusNeg | kExBErrorRange;
1472 //__________________________________________________________________________________________________________________________
1473 Bool_t AliTRDPreprocessorOffline::ValidateT0(){
1475 // Update OCDB entry
1478 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1479 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1480 if(calDet && calPad) {
1481 Double_t meandet = calDet->GetMean();
1482 Double_t rmsdet = calDet->GetRMSRobust();
1483 Double_t meanpad = calPad->GetMean();
1484 //Double_t rmspad = calPad->GetRMS();
1485 //printf("T0::minimum %f, rmsdet %f,meanpad %f, rmspad %f\n",meandet,rmsdet,meanpad,rmspad);
1486 if((meandet > -1.5) && (meandet < 5.0) && (rmsdet < 4.0) && (meanpad < 5.0) && (meanpad > -0.5)) return kTRUE;
1488 fStatusPos = fStatusPos | kTimeOffsetErrorRange;
1495 //__________________________________________________________________________________________________________________________
1496 Bool_t AliTRDPreprocessorOffline::ValidatePRF() const{
1498 // Update OCDB entry
1501 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1503 Double_t meanpad = calPad->GetMean();
1504 Double_t rmspad = calPad->GetRMS();
1505 //printf("PRF::meanpad %f, rmspad %f\n",meanpad,rmspad);
1506 if((meanpad < 1.0) && (rmspad < 0.8)) return kTRUE;
1513 //__________________________________________________________________________________________________________________________
1514 Bool_t AliTRDPreprocessorOffline::ValidateChamberStatus(){
1516 // Update OCDB entry
1519 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1520 if(calChamberStatus) {
1522 Int_t detectornodata = 0;
1523 Int_t detectorbadcalib = 0;
1525 for(Int_t sm=0; sm < 18; sm++) {
1526 //printf("%d chambers w/o data in sm %d\n",fNoData[sm],sm);
1527 //printf("%d bad calibrated chambers in sm %d\n",fBadCalib[sm],sm);
1528 if(fNoData[sm] != 30) detectornodata += fNoData[sm];
1529 detectorbadcalib+=fBadCalib[sm];
1531 //printf("Number of chambers w/o data %d\n",detectornodata);
1532 //printf("Number of chambers bad calibrated %d\n",detectorbadcalib);
1534 if((detectornodata > fNoDataValidate) ||
1535 (detectorbadcalib > fBadCalibValidate)){
1536 fStatusPos = fStatusPos | kChamberStatusErrorRange;
1544 //_____________________________________________________________________________
1545 Int_t AliTRDPreprocessorOffline::GetVersion(TString name) const
1548 // Get version from the title
1552 const Char_t *version = "Ver";
1553 if(!strstr(name.Data(),version)) return -1;
1554 const Char_t *after = "Subver";
1555 if(!strstr(name.Data(),after)) return -1;
1557 for(Int_t ver = 0; ver < 999999999; ver++) {
1559 TString vertry(version);
1563 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1565 if(strstr(name.Data(),vertry.Data())) return ver;
1573 //_____________________________________________________________________________
1574 Int_t AliTRDPreprocessorOffline::GetSubVersion(TString name) const
1577 // Get subversion from the title
1581 const Char_t *subversion = "Subver";
1582 if(!strstr(name.Data(),subversion)) return -1;
1583 const Char_t *after = "FirstRun";
1584 if(!strstr(name.Data(),after)) {
1587 if(!strstr(name.Data(),after)) return -1;
1590 for(Int_t ver = 0; ver < 999999999; ver++) {
1592 TString vertry(subversion);
1596 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1598 if(strstr(name.Data(),vertry.Data())) return ver;
1606 //_____________________________________________________________________________
1607 Int_t AliTRDPreprocessorOffline::GetFirstRun(TString name) const
1610 // Get first run from the title
1614 const Char_t *firstrun = "FirstRun";
1615 if(!strstr(name.Data(),firstrun)) return -1;
1616 const Char_t *after = "Nz";
1617 if(!strstr(name.Data(),after)) return -1;
1620 for(Int_t ver = 0; ver < 999999999; ver++) {
1622 TString vertry(firstrun);
1626 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1628 if(strstr(name.Data(),vertry.Data())) return ver;
1635 //_____________________________________________________________________________
1636 Bool_t AliTRDPreprocessorOffline::CheckStatus(Int_t status, Int_t bitMask) const
1639 // Checks the status
1642 return (status & bitMask) ? kTRUE : kFALSE;
1645 //_____________________________________________________________________________
1646 Int_t AliTRDPreprocessorOffline::GetStatus() const
1649 // Checks the status
1650 // fStatusPos: errors
1651 // fStatusNeg: only info
1654 if(fStatusPos > 0) return fStatusPos;
1655 else return (-TMath::Abs(fStatusNeg));
1658 //_____________________________________________________________________________
1659 void AliTRDPreprocessorOffline::PrintStatus() const
1665 AliInfo(Form("The error status is %d",fStatusPos));
1666 AliInfo(Form("IsGainErrorOld? %d",(Int_t)IsGainErrorOld()));
1667 AliInfo(Form("IsVdriftErrorOld? %d",(Int_t)IsVdriftErrorOld()));
1668 AliInfo(Form("IsGainErrorRange? %d",(Int_t)IsGainErrorRange()));
1669 AliInfo(Form("IsVdriftErrorRange? %d",(Int_t)IsVdriftErrorRange()));
1670 AliInfo(Form("IsTimeOffsetErrorRange? %d",(Int_t)IsTimeOffsetErrorRange()));
1671 AliInfo(Form("IsChamberStatusErrorRange? %d",(Int_t)IsChamberStatusErrorRange()));
1674 AliInfo(Form("The info status is %d",fStatusNeg));
1675 AliInfo(Form("IsGainNotEnoughStatsButFill? %d",(Int_t)IsGainNotEnoughStatsButFill()));
1676 AliInfo(Form("IsVdriftNotEnoughStatsButFill? %d",(Int_t)IsVdriftNotEnoughStatsButFill()));
1677 AliInfo(Form("IsGainNotEnoughStatsNotFill? %d",(Int_t)IsGainNotEnoughStatsNotFill()));
1678 AliInfo(Form("IsVdriftNotEnoughStatsNotFill? %d",(Int_t)IsVdriftNotEnoughStatsNotFill()));
1679 AliInfo(Form("IsTimeOffsetNotEnoughStatsNotFill? %d",(Int_t)IsTimeOffsetNotEnoughStatsNotFill()));
1681 AliInfo(Form("IsExBErrorRange? %d",(Int_t)IsExBErrorRange()));
1682 AliInfo(Form("IsExBErrorOld? %d",(Int_t)IsExBErrorOld()));
1685 //___________________________________________________________________________________
1686 void AliTRDPreprocessorOffline::SetCalDetVdrift(AliTRDCalDet *calDetVdriftUsed)
1689 fCalDetVdriftUsed = calDetVdriftUsed;
1691 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1692 for(Int_t k = 0; k < 540; k++){
1693 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1694 //printf("Set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1698 //___________________________________________________________________________________
1699 Bool_t AliTRDPreprocessorOffline::SetCalDetGain(Int_t runNumber, Int_t version, Int_t subversion)
1702 // Set the fCalDetGainUsed
1705 if((version == 0) && (subversion == 0)) return kFALSE;
1707 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor",runNumber, version, subversion);
1709 AliError("Found no entry\n");
1710 fStatusPos = fStatusPos | kGainErrorOld;
1713 //const AliCDBId id = entry->GetId();
1714 //version = id.GetVersion();
1715 //subversion = id.GetSubVersion();
1716 //printf("Found version %d and subversion %d for vdrift\n",version,subversion);
1717 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1718 if(calDet) fCalDetGainUsed = calDet;
1720 fStatusPos = fStatusPos | kGainErrorOld;
1727 //___________________________________________________________________________________
1728 Bool_t AliTRDPreprocessorOffline::SetCalDetVdriftExB(Int_t runNumber, Int_t versionv, Int_t subversionv, Int_t versionexb, Int_t subversionexb)
1731 // Set the fCalDetVdriftUsed and fCalDetExBUsed
1734 if((versionv == 0) && (subversionv == 0)) return kFALSE;
1736 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberVdrift",runNumber, versionv, subversionv);
1738 AliError("Found no entry\n");
1739 fStatusPos = fStatusPos | kVdriftErrorOld;
1742 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1743 if(calDet) fCalDetVdriftUsed = calDet;
1745 fStatusPos = fStatusPos | kVdriftErrorOld;
1751 if((versionexb == 0) && (subversionexb == 0)) {
1753 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1754 for(Int_t k = 0; k < 540; k++){
1755 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1756 //printf("Nothing found: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1762 entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberExB",runNumber, versionexb, subversionexb);
1764 //printf("Found no entry\n");
1765 fStatusPos = fStatusPos | kExBErrorOld;
1768 AliTRDCalDet* calDetexb = (AliTRDCalDet *)entry->GetObject();
1770 fStatusPos = fStatusPos | kExBErrorOld;
1774 Double_t meanexb = calDetexb->GetMean();
1775 //printf("Mean value %f\n",meanexb);
1776 if((meanexb > 70) || (fNoExBUsedInReco)) {
1777 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1778 for(Int_t k = 0; k < 540; k++){
1779 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1780 //printf("Found but: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1784 fCalDetExBUsed = calDetexb;