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"
70 ClassImp(AliTRDPreprocessorOffline)
72 AliTRDPreprocessorOffline::AliTRDPreprocessorOffline():
73 TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
75 fNameList("TRDCalib"),
77 fCalDetVdriftUsed(0x0),
83 fAliTRDCalibraVdriftLinearFit(0x0),
84 fAliTRDCalibraExbAltFit(0x0),
87 fPlots(new TObjArray(kNumCalibObjs)),
88 fCalibObjects(new TObjArray(kNumCalibObjs)),
91 fSubVersionGainUsed(0),
92 fFirstRunVdriftUsed(0),
93 fVersionVdriftUsed(0),
94 fSubVersionVdriftUsed(0),
97 fSubVersionExBUsed(0),
98 fNoExBUsedInReco(kFALSE),
99 fSwitchOnValidation(kTRUE),
100 fVdriftValidated(kFALSE),
101 fExBValidated(kFALSE),
102 fT0Validated(kFALSE),
103 fMinStatsVdriftT0PH(800*20),
104 fMinStatsVdriftLinear(800),
107 fMinStatsChamberStatus(20),
108 fBackCorrectGain(kFALSE),
109 fBackCorrectVdrift(kTRUE),
110 fNotEnoughStatisticsForTheGain(kFALSE),
111 fNotEnoughStatisticsForTheVdriftLinear(kFALSE),
114 fBadCalibValidate(40),
116 fRMSBadCalibratedGain(20.0),
117 fRMSBadCalibratedVdrift(20.0),
118 fRMSBadCalibratedExB(20.0),
119 fRobustFitDriftVelocity(kTRUE),
120 fRobustFitExbAlt(kFALSE),
121 fAlternativeVdrfitFit(kFALSE),
122 fAlternativeExbAltFit(kFALSE)
125 // default constructor
128 memset(fBadCalib, 0, sizeof(Int_t) * 18);
129 memset(fNoData, 0, sizeof(Int_t) * 18);
131 //_________________________________________________________________________________________________________________
132 AliTRDPreprocessorOffline::~AliTRDPreprocessorOffline() {
137 if(fCalDetGainUsed) delete fCalDetGainUsed;
138 if(fCalDetVdriftUsed) delete fCalDetVdriftUsed;
139 if(fCalDetExBUsed) delete fCalDetExBUsed;
140 if(fCH2d) delete fCH2d;
141 if(fPH2d) delete fPH2d;
142 if(fPRF2d) delete fPRF2d;
143 if(fSparse) delete fSparse;
144 if(fAliTRDCalibraVdriftLinearFit) delete fAliTRDCalibraVdriftLinearFit;
145 if(fAliTRDCalibraExbAltFit) delete fAliTRDCalibraExbAltFit;
146 if(fNEvents) delete fNEvents;
147 if(fAbsoluteGain) delete fAbsoluteGain;
148 if(fPlots) delete fPlots;
149 if(fCalibObjects) delete fCalibObjects;
152 //___________________________________________________________________________________
153 void AliTRDPreprocessorOffline::Process(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage)
156 // Process to the gain, vdrift, timeoffset, exb and chamber status calibration
159 if(SetCalDetGain(startRunNumber,fVersionGainUsed,fSubVersionGainUsed) && SetCalDetVdriftExB(startRunNumber,fVersionVdriftUsed,fSubVersionVdriftUsed,fVersionExBUsed,fSubVersionExBUsed)) {
161 CalibVdriftT0(file,startRunNumber,endRunNumber,ocdbStorage);
162 CalibGain(file,startRunNumber,endRunNumber,ocdbStorage);
163 CalibChamberStatus(file,startRunNumber,endRunNumber,ocdbStorage);
164 CalibExbAlt(file,startRunNumber,endRunNumber,ocdbStorage);
171 //___________________________________________________________________________________________________________________
173 void AliTRDPreprocessorOffline::CalibVdriftT0(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
175 // make calibration of the drift velocity
177 // file - the location of input file
178 // startRunNumber, endRunNumber - run validity period
179 // ocdbStorage - path to the OCDB storage
180 // - if empty - local storage 'pwd' uesed
181 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
185 fVdriftValidated = kTRUE;
186 fT0Validated = kTRUE;
187 fExBValidated = kTRUE;
188 fNotEnoughStatisticsForTheVdriftLinear = kFALSE;
190 // 2. extraction of the information
192 if(ReadVdriftLinearFitGlobal(file) && fCalDetVdriftUsed && fCalDetExBUsed) AnalyzeVdriftLinearFit();
193 if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
195 // 3. Append QA plots
197 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
200 // 4. validate OCDB entries
202 if(fSwitchOnValidation==kTRUE && ValidateVdrift()==kFALSE) {
203 //AliError("TRD vdrift OCDB parameters out of range!");
204 fVdriftValidated = kFALSE;
206 if(fSwitchOnValidation==kTRUE && ValidateT0()==kFALSE) {
207 //AliError("TRD t0 OCDB parameters out of range!");
208 fT0Validated = kFALSE;
210 if(fSwitchOnValidation==kTRUE && ValidateExB()==kFALSE) {
211 //AliError("TRD t0 OCDB parameters out of range!");
212 fExBValidated = kFALSE;
218 if(fVdriftValidated) UpdateOCDBVdrift(startRunNumber,endRunNumber,ocdbStorage);
219 if(fT0Validated) UpdateOCDBT0(startRunNumber,endRunNumber,ocdbStorage);
220 if(fExBValidated) UpdateOCDBExB(startRunNumber,endRunNumber,ocdbStorage);
223 //___________________________________________________________________________________________________________________
225 void AliTRDPreprocessorOffline::CalibExbAlt(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
227 // make calibration of the drift velocity
229 // file - the location of input file
230 // startRunNumber, endRunNumber - run validity period
231 // ocdbStorage - path to the OCDB storage
232 // - if empty - local storage 'pwd' uesed
233 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
239 // 2. extraction of the information
241 if(ReadExbAltFitGlobal(file)) AnalyzeExbAltFit();
243 // 3. Append QA plots
245 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
248 // 4. validate OCDB entries
254 UpdateOCDBExBAlt(startRunNumber,endRunNumber,ocdbStorage);
258 //_________________________________________________________________________________________________________________
260 void AliTRDPreprocessorOffline::CalibGain(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
262 // make calibration of the drift velocity
264 // file - the location of input file
265 // startRunNumber, endRunNumber - run validity period
266 // ocdbStorage - path to the OCDB storage
267 // - if empty - local storage 'pwd' uesed
268 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
270 fNotEnoughStatisticsForTheGain = kFALSE;
273 if(!ReadGainGlobal(file)) return;
276 // 2. extraction of the information
279 if(fBackCorrectGain) CorrectFromDetGainUsed();
280 //if(fBackCorrectVdrift) CorrectFromDetVdriftUsed();
282 // 3. Append QA plots
284 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
287 // 4. validate OCDB entries
289 if(fSwitchOnValidation==kTRUE && ValidateGain()==kFALSE) {
290 //AliError("TRD gain OCDB parameters out of range!");
297 if((!fCalDetVdriftUsed) || (fCalDetVdriftUsed && fVdriftValidated)) UpdateOCDBGain(startRunNumber,endRunNumber,ocdbStorage);
301 //________________________________________________________________________________________________________________
303 void AliTRDPreprocessorOffline::CalibPRF(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
305 // make calibration of the drift velocity
307 // file - the location of input file
308 // startRunNumber, endRunNumber - run validity period
309 // ocdbStorage - path to the OCDB storage
310 // - if empty - local storage 'pwd' uesed
311 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
314 if(!ReadPRFGlobal(file)) return;
317 // 2. extraction of the information
321 // 3. Append QA plots
323 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
327 // 4. validate OCDB entries
329 if(fSwitchOnValidation==kTRUE && ValidatePRF()==kFALSE) {
330 //AliError("TRD prf OCDB parameters out of range!");
337 UpdateOCDBPRF(startRunNumber,endRunNumber,ocdbStorage);
340 //________________________________________________________________________________________________________________
342 void AliTRDPreprocessorOffline::CalibChamberStatus(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
344 // make calibration of the chamber status
346 // startRunNumber, endRunNumber - run validity period
347 // ocdbStorage - path to the OCDB storage
348 // - if empty - local storage 'pwd' uesed
349 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
353 if(!ReadStatusGlobal(file)) return;
357 // 2. extraction of the information
359 if(!AnalyzeChamberStatus()) return;
361 // 3. Append QA plots
363 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
367 // 4. validate OCDB entries
369 if(fSwitchOnValidation==kTRUE && ValidateChamberStatus()==kFALSE) {
370 //AliError("TRD Chamber status OCDB parameters not ok!");
377 if((!fNotEnoughStatisticsForTheVdriftLinear) && (!fNotEnoughStatisticsForTheGain)) UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
378 //UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
381 //______________________________________________________________________________________________________
382 Bool_t AliTRDPreprocessorOffline::Init(const Char_t* fileName){
384 // read the calibration used during the reconstruction
387 if(ReadVdriftT0Global(fileName)) {
389 TString nameph = fPH2d->GetTitle();
390 fFirstRunVdriftUsed = GetFirstRun(nameph);
391 fVersionVdriftUsed = GetVersion(nameph);
392 fSubVersionVdriftUsed = GetSubVersion(nameph);
394 //printf("Found Version %d, Subversion %d for vdrift\n",fVersionVdriftUsed,fSubVersionVdriftUsed);
398 if(ReadGainGlobal(fileName)) {
400 TString namech = fCH2d->GetTitle();
401 fFirstRunGainUsed = GetFirstRun(namech);
402 fVersionGainUsed = GetVersion(namech);
403 fSubVersionGainUsed = GetSubVersion(namech);
405 //printf("Found Version %d, Subversion %d for gain\n",fVersionGainUsed,fSubVersionGainUsed);
409 if(ReadVdriftLinearFitGlobal(fileName)) {
411 TString namelinear = fAliTRDCalibraVdriftLinearFit->GetNameCalibUsed();
412 fFirstRunExBUsed = GetFirstRun(namelinear);
413 fVersionExBUsed = GetVersion(namelinear);
414 fSubVersionExBUsed = GetSubVersion(namelinear);
416 //printf("Found Version %d, Subversion %d, run %d for ExB\n",fVersionExBUsed,fSubVersionExBUsed,fFirstRunExBUsed);
420 if(fVersionVdriftUsed == 0) fStatusPos = fStatusPos |kVdriftErrorOld;
421 if(fVersionGainUsed == 0) fStatusPos = fStatusPos | kGainErrorOld;
426 //___________________________________________________________________________________________________________________
428 Bool_t AliTRDPreprocessorOffline::ReadStatusGlobal(const Char_t* fileName){
430 // read calibration entries from file
432 if(fSparse) return kTRUE;
433 TFile fcalib(fileName);
434 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
436 fSparse = (THnSparseI *) array->FindObject("NumberOfEntries");
437 if(!fSparse) return kFALSE;
445 //___________________________________________________________________________________________________________________
447 Bool_t AliTRDPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
449 // read calibration entries from file
451 if(fCH2d) return kTRUE;
452 TFile fcalib(fileName);
453 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
455 TH2I *ch2d = (TH2I *) array->FindObject("CH2d");
456 if(!ch2d) return kFALSE;
457 fCH2d = (TH2I*)ch2d->Clone();
458 //fNEvents = (TH1I *) array->FindObject("NEvents");
459 //fAbsoluteGain = (TH2F *) array->FindObject("AbsoluteGain");
461 TH2I *ch2d = (TH2I *) fcalib.Get("CH2d");
462 if(!ch2d) return kFALSE;
463 fCH2d = (TH2I*)ch2d->Clone();
464 //fNEvents = (TH1I *) fcalib.Get("NEvents");
465 //fAbsoluteGain = (TH2F *) fcalib.Get("AbsoluteGain");
467 fCH2d->SetDirectory(0);
468 //printf("title of CH2d %s\n",fCH2d->GetTitle());
473 //_________________________________________________________________________________________________________________
475 Bool_t AliTRDPreprocessorOffline::ReadVdriftT0Global(const Char_t* fileName){
477 // read calibration entries from file
479 if(fPH2d) return kTRUE;
480 TFile fcalib(fileName);
481 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
483 TProfile2D *ph2d = (TProfile2D *) array->FindObject("PH2d");
484 if(!ph2d) return kFALSE;
485 fPH2d = (TProfile2D*)ph2d->Clone();
486 //fNEvents = (TH1I *) array->FindObject("NEvents");
488 TProfile2D *ph2d = (TProfile2D *) fcalib.Get("PH2d");
489 if(!ph2d) return kFALSE;
490 fPH2d = (TProfile2D*)ph2d->Clone();
491 //fNEvents = (TH1I *) fcalib.Get("NEvents");
493 fPH2d->SetDirectory(0);
494 //printf("title of PH2d %s\n",fPH2d->GetTitle());
499 //___________________________________________________________________________________________________________________
501 Bool_t AliTRDPreprocessorOffline::ReadVdriftLinearFitGlobal(const Char_t* fileName){
503 // read calibration entries from file
505 if(fAliTRDCalibraVdriftLinearFit) return kTRUE;
506 TFile fcalib(fileName);
507 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
509 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) array->FindObject("AliTRDCalibraVdriftLinearFit");
510 //fNEvents = (TH1I *) array->FindObject("NEvents");
512 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) fcalib.Get("AliTRDCalibraVdriftLinearFit");
513 //fNEvents = (TH1I *) fcalib.Get("NEvents");
515 if(!fAliTRDCalibraVdriftLinearFit) {
516 //printf("No AliTRDCalibraVdriftLinearFit\n");
522 //_____________________________________________________________________________________________________________
523 Bool_t AliTRDPreprocessorOffline::ReadExbAltFitGlobal(const Char_t* fileName){
525 // read calibration entries from file
527 if(fAliTRDCalibraExbAltFit) return kTRUE;
528 TFile fcalib(fileName);
529 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
531 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) array->FindObject("AliTRDCalibraExbAltFit");
532 //fNEvents = (TH1I *) array->FindObject("NEvents");
534 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) fcalib.Get("AliTRDCalibraExbAltFit");
535 //fNEvents = (TH1I *) fcalib.Get("NEvents");
537 if(!fAliTRDCalibraExbAltFit) {
538 //printf("No AliTRDCalibraExbAltFit\n");
544 //_____________________________________________________________________________________________________________
546 Bool_t AliTRDPreprocessorOffline::ReadPRFGlobal(const Char_t* fileName){
548 // read calibration entries from file
550 if(fPRF2d) return kTRUE;
551 TFile fcalib(fileName);
552 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
554 TProfile2D *prf2d = (TProfile2D *) array->FindObject("PRF2d");
555 if(!prf2d) return kFALSE;
556 fPRF2d = (TProfile2D*)prf2d->Clone();
557 //fNEvents = (TH1I *) array->FindObject("NEvents");
559 TProfile2D *prf2d = (TProfile2D *) fcalib.Get("PRF2d");
560 if(!prf2d) return kFALSE;
561 fPRF2d = (TProfile2D*)prf2d->Clone();
562 //fNEvents = (TH1I *) fcalib.Get("NEvents");
564 fPRF2d->SetDirectory(0);
565 //printf("title of PRF2d %s\n",fPRF2d->GetTitle());
570 //__________________________________________________________________________________________________________
572 Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
574 // Analyze gain - produce the calibration objects
577 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
578 calibra->SetMinEntries(fMinStatsGain); // If there is less than 1000 entries in the histo: no fit
579 calibra->AnalyseCH(fCH2d);
581 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
582 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
583 Int_t nbfit = calibra->GetNumberFit();
584 Int_t nbE = calibra->GetNumberEnt();
588 Bool_t meanother = kFALSE;
591 (nbfit >= 0.5*nbE) && (nbE > 30)) {
592 // create the cal objects
593 if(!fBackCorrectGain) {
594 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
597 TObjArray object = calibra->GetVectorFit();
598 AliTRDCalDet *calDetGain = calibra->CreateDetObjectGain(&object,meanother);
599 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
600 // Put them in the array
601 fCalibObjects->AddAt(calDetGain,kGain);
602 fPlots->AddAt(coefGain,kGain);
607 fNotEnoughStatisticsForTheGain = kTRUE;
608 Int_t minStatsGain = fMinStatsGain*30;
609 calibra->SetMinEntries(minStatsGain); // Because we do it for all, we increase this
610 Double_t gainoverallnotnormalized = calibra->AnalyseCHAllTogether(fCH2d);
611 if(fCalDetGainUsed && (gainoverallnotnormalized > 0.0)) {
612 AliTRDCalDet *calDetGain = new AliTRDCalDet(*fCalDetGainUsed);
613 Double_t oldmean = fCalDetGainUsed->CalcMean(kFALSE);
614 //printf("oldmean %f\n",oldmean);
616 Double_t scalefactor = calibra->GetScaleFactorGain();
617 //printf("Correction factor %f\n",gainoverallnotnormalized*scalefactor);
618 calDetGain->Multiply(gainoverallnotnormalized*scalefactor/oldmean);
619 //printf("newmean %f\n",calDetGain->CalcMean(kFALSE));
620 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
621 fCalibObjects->AddAt(calDetGain,kGain);
622 fPlots->AddAt(coefGain,kGain);
625 fStatusNeg = fStatusNeg | kGainNotEnoughStatsButFill;
628 fStatusPos = fStatusPos | kGainErrorOld;
632 if(gainoverallnotnormalized <= 0.0) fStatusNeg = fStatusNeg | kGainNotEnoughStatsNotFill;
633 if(!fCalDetGainUsed) fStatusPos = fStatusPos | kGainErrorOld;
637 calibra->ResetVectorFit();
642 //_____________________________________________________________________________________________________
643 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftT0(){
645 // Analyze VdriftT0 - produce the calibration objects
648 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
649 calibra->SetMinEntries(fMinStatsVdriftT0PH); // If there is less than 1000 entries in the histo: no fit
650 calibra->AnalysePH(fPH2d);
652 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
653 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
654 Int_t nbfit = calibra->GetNumberFit();
655 Int_t nbfitSuccess = calibra->GetNumberFitSuccess();
656 Int_t nbE = calibra->GetNumberEnt();
658 //printf("nbtg %d, nbfit %d, nbE %d, nbfitSuccess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
662 (nbfit >= 0.5*nbE) && (nbE > 30) && (nbfitSuccess > 30)) {
663 //printf("Pass the cut for VdriftT0\n");
664 // create the cal objects
665 calibra->RemoveOutliers(1,kFALSE);
666 calibra->PutMeanValueOtherVectorFit(1,kFALSE);
667 calibra->RemoveOutliers2(kFALSE);
668 calibra->PutMeanValueOtherVectorFit2(1,kFALSE);
670 TObjArray object = calibra->GetVectorFit();
671 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object);
672 TH1F *coefVdriftPH = calDetVdrift->MakeHisto1DAsFunctionOfDet();
673 AliTRDCalPad *calPadVdrift = (AliTRDCalPad *)calibra->CreatePadObjectVdrift(&object,calDetVdrift);
674 TH1F *coefPadVdrift = calPadVdrift->MakeHisto1D();
675 object = calibra->GetVectorFit2();
676 AliTRDCalDet *calDetT0 = calibra->CreateDetObjectT0(&object);
677 TH1F *coefT0 = calDetT0->MakeHisto1DAsFunctionOfDet();
678 AliTRDCalPad *calPadT0 = (AliTRDCalPad *)calibra->CreatePadObjectT0(&object,calDetT0);
679 TH1F *coefPadT0 = calPadT0->MakeHisto1D();
680 // Put them in the array
681 fCalibObjects->AddAt(calDetT0,kT0PHDet);
682 fCalibObjects->AddAt(calDetVdrift,kVdriftPHDet);
683 fCalibObjects->AddAt(calPadT0,kT0PHPad);
684 fCalibObjects->AddAt(calPadVdrift,kVdriftPHPad);
685 fPlots->AddAt(coefVdriftPH,kVdriftPHDet);
686 fPlots->AddAt(coefT0,kT0PHDet);
687 fPlots->AddAt(coefPadVdrift,kVdriftPHPad);
688 fPlots->AddAt(coefPadT0,kT0PHPad);
693 //printf("Not enough stats timeoffset\n");
694 fStatusNeg = fStatusNeg | kTimeOffsetNotEnoughStatsNotFill;
696 calibra->ResetVectorFit();
701 //____________________________________________________________________________________________________________________
702 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftLinearFit(){
704 // Analyze vdrift linear fit - produce the calibration objects
707 //printf("Analyse linear fit\n");
710 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
711 calibra->SetCalDetVdriftExB(fCalDetVdriftUsed,fCalDetExBUsed);
712 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
713 //printf("Fill PE Array\n");
714 fAliTRDCalibraVdriftLinearFit->SetRobustFit(fRobustFitDriftVelocity);
715 if(!fAlternativeVdrfitFit)
716 fAliTRDCalibraVdriftLinearFit->FillPEArray();
718 fAliTRDCalibraVdriftLinearFit->FillPEArray2();
719 //printf("AliTRDCalibraFit\n");
720 calibra->AnalyseLinearFitters(fAliTRDCalibraVdriftLinearFit);
724 Int_t nbfit = calibra->GetNumberFit();
725 Int_t nbE = calibra->GetNumberEnt();
730 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
731 // create the cal objects
732 //calibra->RemoveOutliers(1,kTRUE);
733 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
734 //calibra->RemoveOutliers2(kTRUE);
735 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
737 TObjArray object = calibra->GetVectorFit();
738 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object,kTRUE);
739 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
740 object = calibra->GetVectorFit2();
741 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectLorentzAngle(&object);
742 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
743 //if(!calDetLorentz) printf("No lorentz created\n");
744 // Put them in the array
745 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
746 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
747 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
748 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
753 fNotEnoughStatisticsForTheVdriftLinear = kTRUE;
754 Int_t minNumberOfEntriesForAll = fMinStatsVdriftLinear*30;
755 calibra->SetMinEntries(minNumberOfEntriesForAll); // Because we do it for all, we increase this
756 Double_t vdriftoverall = -100.0;
757 Double_t exboverall = 100.0;
758 calibra->AnalyseLinearFittersAllTogether(fAliTRDCalibraVdriftLinearFit,vdriftoverall,exboverall);
759 //printf("Found mean vdrift %f and exb %f\n",vdriftoverall,exboverall);
760 if(fCalDetVdriftUsed && (vdriftoverall > 0.0) && (exboverall < 70.0)) {
761 AliTRDCalDet *calDetVdrift = new AliTRDCalDet(*fCalDetVdriftUsed);
762 AliTRDCalDet *calDetLorentz = new AliTRDCalDet(*fCalDetExBUsed);
763 Double_t oldmeanvdrift = fCalDetVdriftUsed->CalcMean(kFALSE);
764 Double_t oldmeanexb = fCalDetExBUsed->CalcMean(kFALSE);
765 //printf("oldmean %f\n",oldmean);
766 if((oldmeanvdrift > 0.0) && (oldmeanexb < 70.0)) {
767 //printf("Correction factor %f\n",vdriftoverall);
768 calDetVdrift->Multiply(vdriftoverall/oldmeanvdrift);
769 calDetLorentz->Multiply(exboverall/oldmeanexb);
770 //printf("newmean %f\n",calDetVdrift->CalcMean(kFALSE));
771 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
772 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
773 // Put them in the array
774 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
775 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
776 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
777 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
780 fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsButFill;
783 if(oldmeanvdrift) fStatusPos = fStatusPos | kVdriftErrorOld;
784 if(oldmeanexb) fStatusPos = fStatusPos | kExBErrorOld;
788 if((vdriftoverall <= 0.0) && (exboverall > 70.0)) fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsNotFill;
789 if(!fCalDetVdriftUsed) fStatusPos = fStatusPos | kVdriftErrorOld;
790 if(!fCalDetExBUsed) fStatusPos = fStatusPos | kExBErrorOld;
794 calibra->ResetVectorFit();
799 //________________________________________________________________________________________________________________
801 Bool_t AliTRDPreprocessorOffline::AnalyzeExbAltFit(){
803 // Analyze vdrift linear fit - produce the calibration objects
806 //printf("Analyse linear fit\n");
809 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
810 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
811 //printf("Fill PE Array\n");
812 fAliTRDCalibraExbAltFit->SetRobustFit(fRobustFitExbAlt);
813 if(!fAlternativeExbAltFit)
814 fAliTRDCalibraExbAltFit->FillPEArray();
816 fAliTRDCalibraExbAltFit->FillPEArray2();
817 //printf("AliTRDCalibraFit\n");
818 calibra->AnalyseExbAltFit(fAliTRDCalibraExbAltFit);
822 Int_t nbfit = calibra->GetNumberFit();
823 Int_t nbE = calibra->GetNumberEnt();
828 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
829 // create the cal objects
830 //calibra->RemoveOutliers(1,kTRUE);
831 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
833 TObjArray object = calibra->GetVectorFit2();
834 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectExbAlt(&object);
835 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
836 //if(!calDetLorentz) printf("No lorentz created\n");
837 // Put them in the array
838 fCalibObjects->AddAt(calDetLorentz,kExbAlt);
839 fPlots->AddAt(coefLorentzAngle,kExbAlt);
844 calibra->ResetVectorFit();
849 //________________________________________________________________________________________________________________
851 Bool_t AliTRDPreprocessorOffline::AnalyzePRF(){
853 // Analyze PRF - produce the calibration objects
856 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
857 calibra->SetMinEntries(fMinStatsPRF); // If there is less than 1000 entries in the histo: no fit
858 calibra->AnalysePRFMarianFit(fPRF2d);
860 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
861 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
862 Int_t nbfit = calibra->GetNumberFit();
863 Int_t nbE = calibra->GetNumberEnt();
869 (nbfit >= 0.95*nbE) && (nbE > 30)) {
870 // create the cal objects
871 TObjArray object = calibra->GetVectorFit();
872 AliTRDCalPad *calPadPRF = (AliTRDCalPad*) calibra->CreatePadObjectPRF(&object);
873 TH1F *coefPRF = calPadPRF->MakeHisto1D();
874 // Put them in the array
875 fCalibObjects->AddAt(calPadPRF,kPRF);
876 fPlots->AddAt(coefPRF,kPRF);
881 calibra->ResetVectorFit();
887 //_____________________________________________________________________________
888 Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
891 // Produce AliTRDCalChamberStatus out of calibration results
894 // set up AliTRDCalibChamberStatus
895 AliTRDCalibChamberStatus *ChamberStatus = new AliTRDCalibChamberStatus();
896 ChamberStatus->SetSparseI(fSparse);
897 ChamberStatus->AnalyseHisto(fMinStatsChamberStatus);
898 // get AliTRDCalChamberStatus
899 AliTRDCalChamberStatus *CalChamberStatus = ChamberStatus->GetCalChamberStatus();
901 // get calibration objects
902 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
903 AliTRDCalDet *calDetVDrift = (AliTRDCalDet *) fCalibObjects->At(kVdriftLinear);
904 AliTRDCalDet *calDetExB = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
907 if((!calDetGain) || (!calDetVDrift) || (!fCH2d) || (!calDetExB) || (!CalChamberStatus)) return kFALSE;
910 Double_t gainmean = calDetGain->GetMean();
911 Double_t vdriftmean = calDetVDrift->GetMean();
912 Double_t exbmean = calDetExB->GetMean();
914 Double_t gainrms = calDetGain->GetRMSRobust();
915 Double_t vdriftrms = calDetVDrift->GetRMSRobust();
916 Double_t exbrms = calDetExB->GetRMSRobust();
918 //printf("Gain mean: %f, rms: %f\n",gainmean,gainrms);
919 //printf("Vdrift mean: %f, rms: %f\n",vdriftmean,vdriftrms);
920 //printf("ExB mean: %f, rms: %f\n",exbmean,exbrms);
923 if((TMath::Abs(gainrms) < 0.001) || (TMath::Abs(vdriftrms) < 0.001) || (TMath::Abs(exbrms) < 0.0000001)) return kFALSE;
925 // mask chambers with empty gain entries
927 for (Int_t idet = 0; idet < 540; idet++) {
930 TH1I *projch = (TH1I *) fCH2d->ProjectionX("projch",idet+1,idet+1,(Option_t *)"e");
931 Double_t entries = projch->GetEntries();
932 //printf("Number of entries %f for det %d\n",entries,idet);
935 Double_t gain = calDetGain->GetValue(idet);
938 Double_t vdrift = calDetVDrift->GetValue(idet);
941 Double_t exb = calDetExB->GetValue(idet);
944 if( (entries<50 && !CalChamberStatus->IsNoData(idet)) ||
945 TMath::Abs(gainmean-gain) > (fRMSBadCalibratedGain*gainrms) ||
946 TMath::Abs(vdriftmean-vdrift) > (fRMSBadCalibratedVdrift*vdriftrms) ||
947 TMath::Abs(exbmean-exb) > (fRMSBadCalibratedExB*exbrms) ) {
949 //printf(" chamber det %03d masked \n",idet);
950 //printf(" gainmean %f and gain %f, gainrms %f \n",gainmean,gain,gainrms);
951 //printf(" vdriftmean %f and vdrift %f, vdriftrms %f \n",vdriftmean,vdrift,vdriftrms);
952 //printf(" exbmean %f and exb %f, exbrms %f \n",exbmean,exb,exbrms);
954 CalChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kBadCalibrated);
963 for(Int_t sm=0; sm < 18; sm++) {
965 Int_t smbadcalib = 0;
966 for(Int_t det = 0; det < 30; det++){
967 Int_t detector = sm*30+det;
968 if(CalChamberStatus->IsNoData(detector)) smnodata++;
970 if(CalChamberStatus->IsBadCalibrated(detector)) smbadcalib++;
973 fNoData[sm] = smnodata;
974 fBadCalib[sm]= smbadcalib;
975 //printf("No Data %d, bad calibrated %d for %d\n",fNoData[sm],fBadCalib[sm],sm);
979 // for(Int_t sm=0; sm < 18; sm++) {
980 // Int_t counter = 0;
981 // for(Int_t det = 0; det < 30; det++){
982 // Int_t detector = sm*30+det;
983 // if(CalChamberStatus->IsBadCalibrated(detector)) counter++;
985 // if(counter >= 20) {
986 // for(Int_t det = 0; det < 30; det++){
987 // Int_t detector = sm*30+det;
988 // CalChamberStatus->SetStatus(detector,AliTRDCalChamberStatus::kGood);
993 fCalibObjects->AddAt(CalChamberStatus,kChamberStatus);
999 //________________________________________________________________________________________________
1000 void AliTRDPreprocessorOffline::CorrectFromDetGainUsed() {
1002 // Correct from the gas gain used afterwards
1004 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1005 if(!calDetGain) return;
1008 Double_t mean = 0.0;
1011 for(Int_t det = 0; det < 540; det++) {
1013 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1014 Float_t gainout = calDetGain->GetValue(det);
1017 if(TMath::Abs(gainout-1.0) > 0.000001) {
1018 mean += (gaininit*gainout);
1022 if(nbdet > 0) mean = mean/nbdet;
1024 for(Int_t det = 0; det < 540; det++) {
1026 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1027 Float_t gainout = calDetGain->GetValue(det);
1029 if(TMath::Abs(gainout-1.0) > 0.000001) {
1030 Double_t newgain = gaininit*gainout;
1031 if(newgain < 0.1) newgain = 0.1;
1032 if(newgain > 1.9) newgain = 1.9;
1033 calDetGain->SetValue(det,newgain);
1036 Double_t newgain = mean;
1037 if(newgain < 0.1) newgain = 0.1;
1038 if(newgain > 1.9) newgain = 1.9;
1039 calDetGain->SetValue(det,newgain);
1045 //________________________________________________________________________________________________
1046 void AliTRDPreprocessorOffline::CorrectFromDetVdriftUsed() {
1048 // Correct from the drift velocity
1051 //printf("Correct for vdrift\n");
1053 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1054 if(!calDetGain) return;
1056 Int_t detVdrift = kVdriftPHDet;
1057 if(fMethodSecond) detVdrift = kVdriftLinear;
1058 AliTRDCalDet *calDetVdrift = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1059 if(!calDetVdrift) return;
1062 if(!fNotEnoughStatisticsForTheVdriftLinear) {
1063 for(Int_t det = 0; det < 540; det++) {
1065 Float_t vdriftinit = fCalDetVdriftUsed->GetValue(det);
1066 Float_t vdriftout = calDetVdrift->GetValue(det);
1068 Float_t gain = calDetGain->GetValue(det);
1069 if(vdriftout > 0.0) gain = gain*vdriftinit/vdriftout;
1070 if(gain < 0.1) gain = 0.1;
1071 if(gain > 1.9) gain = 1.9;
1072 calDetGain->SetValue(det,gain);
1077 Float_t vdriftinit = fCalDetVdriftUsed->CalcMean(kFALSE);
1078 Float_t vdriftout = calDetVdrift->CalcMean(kFALSE);
1079 Float_t factorcorrectif = 1.0;
1080 if(vdriftout > 0.0) factorcorrectif = vdriftinit/vdriftout;
1081 for(Int_t det = 0; det < 540; det++) {
1082 Float_t gain = calDetGain->GetValue(det);
1083 gain = gain*factorcorrectif;
1084 if(gain < 0.1) gain = 0.1;
1085 if(gain > 1.9) gain = 1.9;
1086 calDetGain->SetValue(det,gain);
1092 //_________________________________________________________________________________________________________________
1093 void AliTRDPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1095 // Update OCDB entry
1098 AliCDBMetaData *metaData= new AliCDBMetaData();
1099 metaData->SetObjectClassName("AliTRDCalDet");
1100 metaData->SetResponsible("Raphaelle Bailhache");
1101 metaData->AddDateToComment();
1102 metaData->SetBeamPeriod(1);
1104 AliCDBId id1("TRD/Calib/ChamberGainFactor", startRunNumber, endRunNumber);
1105 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1106 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1107 if(calDet) gStorage->Put(calDet, id1, metaData);
1111 //___________________________________________________________________________________________________________________
1112 void AliTRDPreprocessorOffline::UpdateOCDBExB(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1114 // Update OCDB entry
1117 Int_t detExB = kLorentzLinear;
1118 if(!fMethodSecond) return;
1122 AliCDBMetaData *metaData= new AliCDBMetaData();
1123 metaData->SetObjectClassName("AliTRDCalDet");
1124 metaData->SetResponsible("Raphaelle Bailhache");
1125 metaData->AddDateToComment();
1126 metaData->SetBeamPeriod(1);
1128 AliCDBId id1("TRD/Calib/ChamberExB", startRunNumber, endRunNumber);
1129 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1130 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1131 if(calDet) gStorage->Put(calDet, id1, metaData);
1132 //if(!calDet) printf("No caldet\n");
1135 //___________________________________________________________________________________________________________________
1136 void AliTRDPreprocessorOffline::UpdateOCDBExBAlt(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1138 // Update OCDB entry
1141 Int_t detExB = kExbAlt;
1142 if(!fMethodSecond) return;
1146 AliCDBMetaData *metaData= new AliCDBMetaData();
1147 metaData->SetObjectClassName("AliTRDCalDet");
1148 metaData->SetResponsible("Theo Rascanu");
1149 metaData->AddDateToComment();
1150 metaData->SetBeamPeriod(1);
1152 AliCDBId id1("TRD/Calib/ChamberExBAlt", startRunNumber, endRunNumber);
1153 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1154 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1155 if(calDet) gStorage->Put(calDet, id1, metaData);
1156 //if(!calDet) printf("No caldet\n");
1159 //___________________________________________________________________________________________________________________
1160 void AliTRDPreprocessorOffline::UpdateOCDBVdrift(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1162 // Update OCDB entry
1165 Int_t detVdrift = kVdriftPHDet;
1167 if(fMethodSecond) detVdrift = kVdriftLinear;
1169 AliCDBMetaData *metaData= new AliCDBMetaData();
1170 metaData->SetObjectClassName("AliTRDCalDet");
1171 metaData->SetResponsible("Raphaelle Bailhache");
1172 metaData->AddDateToComment();
1173 metaData->SetBeamPeriod(1);
1175 AliCDBId id1("TRD/Calib/ChamberVdrift", startRunNumber, endRunNumber);
1176 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1177 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1178 if(calDet) gStorage->Put(calDet, id1, metaData);
1182 if(!fMethodSecond) {
1184 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1185 metaDataPad->SetObjectClassName("AliTRDCalPad");
1186 metaDataPad->SetResponsible("Raphaelle Bailhache");
1187 metaDataPad->AddDateToComment();
1188 metaDataPad->SetBeamPeriod(1);
1190 AliCDBId id1Pad("TRD/Calib/LocalVdrift", startRunNumber, endRunNumber);
1191 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1192 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
1197 //________________________________________________________________________________________________________________________
1198 void AliTRDPreprocessorOffline::UpdateOCDBT0(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1200 // Update OCDB entry
1203 AliCDBMetaData *metaData= new AliCDBMetaData();
1204 metaData->SetObjectClassName("AliTRDCalDet");
1205 metaData->SetResponsible("Raphaelle Bailhache");
1206 metaData->AddDateToComment();
1207 metaData->SetBeamPeriod(1);
1209 AliCDBId id1("TRD/Calib/ChamberT0", startRunNumber, endRunNumber);
1210 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1211 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1212 if(calDet) gStorage->Put(calDet, id1, metaData);
1216 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1217 metaDataPad->SetObjectClassName("AliTRDCalPad");
1218 metaDataPad->SetResponsible("Raphaelle Bailhache");
1219 metaDataPad->AddDateToComment();
1220 metaDataPad->SetBeamPeriod(1);
1222 AliCDBId id1Pad("TRD/Calib/LocalT0", startRunNumber, endRunNumber);
1223 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1224 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
1229 //_________________________________________________________________________________________________________________
1230 void AliTRDPreprocessorOffline::UpdateOCDBPRF(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1232 // Update OCDB entry
1235 AliCDBMetaData *metaData= new AliCDBMetaData();
1236 metaData->SetObjectClassName("AliTRDCalPad");
1237 metaData->SetResponsible("Raphaelle Bailhache");
1238 metaData->AddDateToComment();
1239 metaData->SetBeamPeriod(1);
1242 AliCDBId id1("TRD/Calib/PRFWidth", startRunNumber, endRunNumber);
1243 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1244 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1245 if(calPad) gStorage->Put(calPad, id1, metaData);
1249 //_________________________________________________________________________________________________________________
1250 void AliTRDPreprocessorOffline::UpdateOCDBChamberStatus(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1252 // Update OCDB entry
1255 AliCDBMetaData *metaData= new AliCDBMetaData();
1256 metaData->SetObjectClassName("AliTRDCalChamberStatus");
1257 metaData->SetResponsible("Raphaelle Bailhache and Julian Book");
1258 metaData->AddDateToComment();
1259 metaData->SetBeamPeriod(1);
1261 AliCDBId id1("TRD/Calib/ChamberStatus", startRunNumber, endRunNumber);
1262 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1263 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1264 if(calChamberStatus) gStorage->Put(calChamberStatus, id1, metaData);
1268 //__________________________________________________________________________________________________________________________
1269 Bool_t AliTRDPreprocessorOffline::ValidateGain() {
1271 // Validate OCDB entry
1274 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1276 Double_t mean = calDet->GetMean();
1277 Double_t rms = calDet->GetRMSRobust();
1278 if((mean > 0.2) && (mean < 1.4) && (rms < 0.5)) return kTRUE;
1279 //if((mean > 0.2) && (mean < 1.4)) return kTRUE;
1281 fStatusPos = fStatusPos | kGainErrorRange;
1290 //__________________________________________________________________________________________________________________________
1291 Bool_t AliTRDPreprocessorOffline::ValidateVdrift(){
1293 // Update OCDB entry
1296 Int_t detVdrift = kVdriftPHDet;
1299 if(fMethodSecond) detVdrift = kVdriftLinear;
1301 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1303 Double_t mean = calDet->GetMean();
1304 Double_t rms = calDet->GetRMSRobust();
1305 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1306 if(!((mean > 1.0) && (mean < 2.0) && (rms < 0.5))) {
1307 fStatusPos = fStatusPos | kVdriftErrorRange;
1313 if(!fMethodSecond) {
1314 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1316 Double_t mean = calPad->GetMean();
1317 Double_t rms = calPad->GetRMS();
1318 //printf("Vdrift::meanpad %f, rmspad %f\n",mean,rms);
1319 if(!((mean > 0.9) && (mean < 1.1) && (rms < 0.6))) {
1320 fStatusPos = fStatusPos | kVdriftErrorRange;
1330 //__________________________________________________________________________________________________________________________
1331 Bool_t AliTRDPreprocessorOffline::ValidateExB(){
1333 // Update OCDB entry
1336 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
1338 Double_t mean = calDet->GetMean();
1339 Double_t rms = calDet->GetRMSRobust();
1340 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1341 if(!((mean > -1.0) && (mean < 1.0) && (rms < 0.5))) {
1342 fStatusNeg = fStatusNeg | kExBErrorRange;
1350 //__________________________________________________________________________________________________________________________
1351 Bool_t AliTRDPreprocessorOffline::ValidateT0(){
1353 // Update OCDB entry
1356 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1357 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1358 if(calDet && calPad) {
1359 Double_t meandet = calDet->GetMean();
1360 Double_t rmsdet = calDet->GetRMSRobust();
1361 Double_t meanpad = calPad->GetMean();
1362 //Double_t rmspad = calPad->GetRMS();
1363 //printf("T0::minimum %f, rmsdet %f,meanpad %f, rmspad %f\n",meandet,rmsdet,meanpad,rmspad);
1364 if((meandet > -1.5) && (meandet < 5.0) && (rmsdet < 4.0) && (meanpad < 5.0) && (meanpad > -0.5)) return kTRUE;
1366 fStatusPos = fStatusPos | kTimeOffsetErrorRange;
1373 //__________________________________________________________________________________________________________________________
1374 Bool_t AliTRDPreprocessorOffline::ValidatePRF() const{
1376 // Update OCDB entry
1379 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1381 Double_t meanpad = calPad->GetMean();
1382 Double_t rmspad = calPad->GetRMS();
1383 //printf("PRF::meanpad %f, rmspad %f\n",meanpad,rmspad);
1384 if((meanpad < 1.0) && (rmspad < 0.8)) return kTRUE;
1391 //__________________________________________________________________________________________________________________________
1392 Bool_t AliTRDPreprocessorOffline::ValidateChamberStatus(){
1394 // Update OCDB entry
1397 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1398 if(calChamberStatus) {
1400 Int_t detectornodata = 0;
1401 Int_t detectorbadcalib = 0;
1403 for(Int_t sm=0; sm < 18; sm++) {
1404 //printf("%d chambers w/o data in sm %d\n",fNoData[sm],sm);
1405 //printf("%d bad calibrated chambers in sm %d\n",fBadCalib[sm],sm);
1406 if(fNoData[sm] != 30) detectornodata += fNoData[sm];
1407 detectorbadcalib+=fBadCalib[sm];
1409 //printf("Number of chambers w/o data %d\n",detectornodata);
1410 //printf("Number of chambers bad calibrated %d\n",detectorbadcalib);
1412 if((detectornodata > fNoDataValidate) ||
1413 (detectorbadcalib > fBadCalibValidate)){
1414 fStatusPos = fStatusPos | kChamberStatusErrorRange;
1422 //_____________________________________________________________________________
1423 Int_t AliTRDPreprocessorOffline::GetVersion(TString name) const
1426 // Get version from the title
1430 const Char_t *version = "Ver";
1431 if(!strstr(name.Data(),version)) return -1;
1432 const Char_t *after = "Subver";
1433 if(!strstr(name.Data(),after)) return -1;
1435 for(Int_t ver = 0; ver < 999999999; ver++) {
1437 TString vertry(version);
1441 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1443 if(strstr(name.Data(),vertry.Data())) return ver;
1451 //_____________________________________________________________________________
1452 Int_t AliTRDPreprocessorOffline::GetSubVersion(TString name) const
1455 // Get subversion from the title
1459 const Char_t *subversion = "Subver";
1460 if(!strstr(name.Data(),subversion)) return -1;
1461 const Char_t *after = "FirstRun";
1462 if(!strstr(name.Data(),after)) {
1465 if(!strstr(name.Data(),after)) return -1;
1468 for(Int_t ver = 0; ver < 999999999; ver++) {
1470 TString vertry(subversion);
1474 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1476 if(strstr(name.Data(),vertry.Data())) return ver;
1484 //_____________________________________________________________________________
1485 Int_t AliTRDPreprocessorOffline::GetFirstRun(TString name) const
1488 // Get first run from the title
1492 const Char_t *firstrun = "FirstRun";
1493 if(!strstr(name.Data(),firstrun)) return -1;
1494 const Char_t *after = "Nz";
1495 if(!strstr(name.Data(),after)) return -1;
1498 for(Int_t ver = 0; ver < 999999999; ver++) {
1500 TString vertry(firstrun);
1504 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1506 if(strstr(name.Data(),vertry.Data())) return ver;
1513 //_____________________________________________________________________________
1514 Bool_t AliTRDPreprocessorOffline::CheckStatus(Int_t status, Int_t bitMask) const
1517 // Checks the status
1520 return (status & bitMask) ? kTRUE : kFALSE;
1523 //_____________________________________________________________________________
1524 Int_t AliTRDPreprocessorOffline::GetStatus() const
1527 // Checks the status
1528 // fStatusPos: errors
1529 // fStatusNeg: only info
1532 if(fStatusPos > 0) return fStatusPos;
1533 else return (-TMath::Abs(fStatusNeg));
1536 //_____________________________________________________________________________
1537 void AliTRDPreprocessorOffline::PrintStatus() const
1543 AliInfo(Form("The error status is %d",fStatusPos));
1544 AliInfo(Form("IsGainErrorOld? %d",(Int_t)IsGainErrorOld()));
1545 AliInfo(Form("IsVdriftErrorOld? %d",(Int_t)IsVdriftErrorOld()));
1546 AliInfo(Form("IsGainErrorRange? %d",(Int_t)IsGainErrorRange()));
1547 AliInfo(Form("IsVdriftErrorRange? %d",(Int_t)IsVdriftErrorRange()));
1548 AliInfo(Form("IsTimeOffsetErrorRange? %d",(Int_t)IsTimeOffsetErrorRange()));
1549 AliInfo(Form("IsChamberStatusErrorRange? %d",(Int_t)IsChamberStatusErrorRange()));
1552 AliInfo(Form("The info status is %d",fStatusNeg));
1553 AliInfo(Form("IsGainNotEnoughStatsButFill? %d",(Int_t)IsGainNotEnoughStatsButFill()));
1554 AliInfo(Form("IsVdriftNotEnoughStatsButFill? %d",(Int_t)IsVdriftNotEnoughStatsButFill()));
1555 AliInfo(Form("IsGainNotEnoughStatsNotFill? %d",(Int_t)IsGainNotEnoughStatsNotFill()));
1556 AliInfo(Form("IsVdriftNotEnoughStatsNotFill? %d",(Int_t)IsVdriftNotEnoughStatsNotFill()));
1557 AliInfo(Form("IsTimeOffsetNotEnoughStatsNotFill? %d",(Int_t)IsTimeOffsetNotEnoughStatsNotFill()));
1559 AliInfo(Form("IsExBErrorRange? %d",(Int_t)IsExBErrorRange()));
1560 AliInfo(Form("IsExBErrorOld? %d",(Int_t)IsExBErrorOld()));
1563 //___________________________________________________________________________________
1564 void AliTRDPreprocessorOffline::SetCalDetVdrift(AliTRDCalDet *calDetVdriftUsed)
1567 fCalDetVdriftUsed = calDetVdriftUsed;
1569 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1570 for(Int_t k = 0; k < 540; k++){
1571 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1572 //printf("Set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1576 //___________________________________________________________________________________
1577 Bool_t AliTRDPreprocessorOffline::SetCalDetGain(Int_t runNumber, Int_t version, Int_t subversion)
1580 // Set the fCalDetGainUsed
1583 if((version == 0) && (subversion == 0)) return kFALSE;
1585 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor",runNumber, version, subversion);
1587 AliError("Found no entry\n");
1588 fStatusPos = fStatusPos | kGainErrorOld;
1591 //const AliCDBId id = entry->GetId();
1592 //version = id.GetVersion();
1593 //subversion = id.GetSubVersion();
1594 //printf("Found version %d and subversion %d for vdrift\n",version,subversion);
1595 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1596 if(calDet) fCalDetGainUsed = calDet;
1598 fStatusPos = fStatusPos | kGainErrorOld;
1605 //___________________________________________________________________________________
1606 Bool_t AliTRDPreprocessorOffline::SetCalDetVdriftExB(Int_t runNumber, Int_t versionv, Int_t subversionv, Int_t versionexb, Int_t subversionexb)
1609 // Set the fCalDetVdriftUsed and fCalDetExBUsed
1612 if((versionv == 0) && (subversionv == 0)) return kFALSE;
1614 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberVdrift",runNumber, versionv, subversionv);
1616 AliError("Found no entry\n");
1617 fStatusPos = fStatusPos | kVdriftErrorOld;
1620 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1621 if(calDet) fCalDetVdriftUsed = calDet;
1623 fStatusPos = fStatusPos | kVdriftErrorOld;
1629 if((versionexb == 0) && (subversionexb == 0)) {
1631 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1632 for(Int_t k = 0; k < 540; k++){
1633 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1634 //printf("Nothing found: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1640 entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberExB",runNumber, versionexb, subversionexb);
1642 //printf("Found no entry\n");
1643 fStatusPos = fStatusPos | kExBErrorOld;
1646 AliTRDCalDet* calDetexb = (AliTRDCalDet *)entry->GetObject();
1648 fStatusPos = fStatusPos | kExBErrorOld;
1652 Double_t meanexb = calDetexb->GetMean();
1653 //printf("Mean value %f\n",meanexb);
1654 if((meanexb > 70) || (fNoExBUsedInReco)) {
1655 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1656 for(Int_t k = 0; k < 540; k++){
1657 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1658 //printf("Found but: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1662 fCalDetExBUsed = calDetexb;