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(20),
116 fRMSBadCalibratedGain(20.0),
117 fRMSBadCalibratedVdrift(20.0),
118 fRMSBadCalibratedExB(50.0),
119 fRobustFitDriftVelocity(kTRUE),
120 fRobustFitExbAlt(kFALSE)
123 // default constructor
126 memset(fBadCalib, 0, sizeof(Int_t) * 18);
127 memset(fNoData, 0, sizeof(Int_t) * 18);
129 //_________________________________________________________________________________________________________________
130 AliTRDPreprocessorOffline::~AliTRDPreprocessorOffline() {
135 if(fCalDetGainUsed) delete fCalDetGainUsed;
136 if(fCalDetVdriftUsed) delete fCalDetVdriftUsed;
137 if(fCalDetExBUsed) delete fCalDetExBUsed;
138 if(fCH2d) delete fCH2d;
139 if(fPH2d) delete fPH2d;
140 if(fPRF2d) delete fPRF2d;
141 if(fSparse) delete fSparse;
142 if(fAliTRDCalibraVdriftLinearFit) delete fAliTRDCalibraVdriftLinearFit;
143 if(fAliTRDCalibraExbAltFit) delete fAliTRDCalibraExbAltFit;
144 if(fNEvents) delete fNEvents;
145 if(fAbsoluteGain) delete fAbsoluteGain;
146 if(fPlots) delete fPlots;
147 if(fCalibObjects) delete fCalibObjects;
150 //___________________________________________________________________________________
151 void AliTRDPreprocessorOffline::Process(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage)
154 // Process to the gain, vdrift, timeoffset, exb and chamber status calibration
157 if(SetCalDetGain(startRunNumber,fVersionGainUsed,fSubVersionGainUsed) && SetCalDetVdriftExB(startRunNumber,fVersionVdriftUsed,fSubVersionVdriftUsed,fVersionExBUsed,fSubVersionExBUsed)) {
159 CalibVdriftT0(file,startRunNumber,endRunNumber,ocdbStorage);
160 CalibGain(file,startRunNumber,endRunNumber,ocdbStorage);
161 CalibChamberStatus(file,startRunNumber,endRunNumber,ocdbStorage);
162 CalibExbAlt(file,startRunNumber,endRunNumber,ocdbStorage);
169 //___________________________________________________________________________________________________________________
171 void AliTRDPreprocessorOffline::CalibVdriftT0(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
173 // make calibration of the drift velocity
175 // file - the location of input file
176 // startRunNumber, endRunNumber - run validity period
177 // ocdbStorage - path to the OCDB storage
178 // - if empty - local storage 'pwd' uesed
179 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
183 fVdriftValidated = kTRUE;
184 fT0Validated = kTRUE;
185 fExBValidated = kTRUE;
186 fNotEnoughStatisticsForTheVdriftLinear = kFALSE;
188 // 2. extraction of the information
190 if(ReadVdriftLinearFitGlobal(file) && fCalDetVdriftUsed && fCalDetExBUsed) AnalyzeVdriftLinearFit();
191 if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
193 // 3. Append QA plots
195 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
198 // 4. validate OCDB entries
200 if(fSwitchOnValidation==kTRUE && ValidateVdrift()==kFALSE) {
201 //AliError("TRD vdrift OCDB parameters out of range!");
202 fVdriftValidated = kFALSE;
204 if(fSwitchOnValidation==kTRUE && ValidateT0()==kFALSE) {
205 //AliError("TRD t0 OCDB parameters out of range!");
206 fT0Validated = kFALSE;
208 if(fSwitchOnValidation==kTRUE && ValidateExB()==kFALSE) {
209 //AliError("TRD t0 OCDB parameters out of range!");
210 fExBValidated = kFALSE;
216 if(fVdriftValidated) UpdateOCDBVdrift(startRunNumber,endRunNumber,ocdbStorage);
217 if(fT0Validated) UpdateOCDBT0(startRunNumber,endRunNumber,ocdbStorage);
218 if(fExBValidated) UpdateOCDBExB(startRunNumber,endRunNumber,ocdbStorage);
221 //___________________________________________________________________________________________________________________
223 void AliTRDPreprocessorOffline::CalibExbAlt(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
225 // make calibration of the drift velocity
227 // file - the location of input file
228 // startRunNumber, endRunNumber - run validity period
229 // ocdbStorage - path to the OCDB storage
230 // - if empty - local storage 'pwd' uesed
231 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
237 // 2. extraction of the information
239 if(ReadExbAltFitGlobal(file)) AnalyzeExbAltFit();
241 // 3. Append QA plots
243 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
246 // 4. validate OCDB entries
252 UpdateOCDBExBAlt(startRunNumber,endRunNumber,ocdbStorage);
256 //_________________________________________________________________________________________________________________
258 void AliTRDPreprocessorOffline::CalibGain(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
260 // make calibration of the drift velocity
262 // file - the location of input file
263 // startRunNumber, endRunNumber - run validity period
264 // ocdbStorage - path to the OCDB storage
265 // - if empty - local storage 'pwd' uesed
266 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
268 fNotEnoughStatisticsForTheGain = kFALSE;
271 if(!ReadGainGlobal(file)) return;
274 // 2. extraction of the information
277 if(fBackCorrectGain) CorrectFromDetGainUsed();
278 //if(fBackCorrectVdrift) CorrectFromDetVdriftUsed();
280 // 3. Append QA plots
282 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
285 // 4. validate OCDB entries
287 if(fSwitchOnValidation==kTRUE && ValidateGain()==kFALSE) {
288 //AliError("TRD gain OCDB parameters out of range!");
295 if((!fCalDetVdriftUsed) || (fCalDetVdriftUsed && fVdriftValidated)) UpdateOCDBGain(startRunNumber,endRunNumber,ocdbStorage);
299 //________________________________________________________________________________________________________________
301 void AliTRDPreprocessorOffline::CalibPRF(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
303 // make calibration of the drift velocity
305 // file - the location of input file
306 // startRunNumber, endRunNumber - run validity period
307 // ocdbStorage - path to the OCDB storage
308 // - if empty - local storage 'pwd' uesed
309 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
312 if(!ReadPRFGlobal(file)) return;
315 // 2. extraction of the information
319 // 3. Append QA plots
321 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
325 // 4. validate OCDB entries
327 if(fSwitchOnValidation==kTRUE && ValidatePRF()==kFALSE) {
328 //AliError("TRD prf OCDB parameters out of range!");
335 UpdateOCDBPRF(startRunNumber,endRunNumber,ocdbStorage);
338 //________________________________________________________________________________________________________________
340 void AliTRDPreprocessorOffline::CalibChamberStatus(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
342 // make calibration of the chamber status
344 // startRunNumber, endRunNumber - run validity period
345 // ocdbStorage - path to the OCDB storage
346 // - if empty - local storage 'pwd' uesed
347 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
351 if(!ReadStatusGlobal(file)) return;
355 // 2. extraction of the information
357 if(!AnalyzeChamberStatus()) return;
359 // 3. Append QA plots
361 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
365 // 4. validate OCDB entries
367 if(fSwitchOnValidation==kTRUE && ValidateChamberStatus()==kFALSE) {
368 //AliError("TRD Chamber status OCDB parameters not ok!");
375 if((!fNotEnoughStatisticsForTheVdriftLinear) && (!fNotEnoughStatisticsForTheGain)) UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
376 //UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
379 //______________________________________________________________________________________________________
380 Bool_t AliTRDPreprocessorOffline::Init(const Char_t* fileName){
382 // read the calibration used during the reconstruction
385 if(ReadVdriftT0Global(fileName)) {
387 TString nameph = fPH2d->GetTitle();
388 fFirstRunVdriftUsed = GetFirstRun(nameph);
389 fVersionVdriftUsed = GetVersion(nameph);
390 fSubVersionVdriftUsed = GetSubVersion(nameph);
392 //printf("Found Version %d, Subversion %d for vdrift\n",fVersionVdriftUsed,fSubVersionVdriftUsed);
396 if(ReadGainGlobal(fileName)) {
398 TString namech = fCH2d->GetTitle();
399 fFirstRunGainUsed = GetFirstRun(namech);
400 fVersionGainUsed = GetVersion(namech);
401 fSubVersionGainUsed = GetSubVersion(namech);
403 //printf("Found Version %d, Subversion %d for gain\n",fVersionGainUsed,fSubVersionGainUsed);
407 if(ReadVdriftLinearFitGlobal(fileName)) {
409 TString namelinear = fAliTRDCalibraVdriftLinearFit->GetNameCalibUsed();
410 fFirstRunExBUsed = GetFirstRun(namelinear);
411 fVersionExBUsed = GetVersion(namelinear);
412 fSubVersionExBUsed = GetSubVersion(namelinear);
414 //printf("Found Version %d, Subversion %d, run %d for ExB\n",fVersionExBUsed,fSubVersionExBUsed,fFirstRunExBUsed);
418 if(fVersionVdriftUsed == 0) fStatusPos = fStatusPos |kVdriftErrorOld;
419 if(fVersionGainUsed == 0) fStatusPos = fStatusPos | kGainErrorOld;
424 //___________________________________________________________________________________________________________________
426 Bool_t AliTRDPreprocessorOffline::ReadStatusGlobal(const Char_t* fileName){
428 // read calibration entries from file
430 if(fSparse) return kTRUE;
431 TFile fcalib(fileName);
432 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
434 fSparse = (THnSparseI *) array->FindObject("NumberOfEntries");
435 if(!fSparse) return kFALSE;
443 //___________________________________________________________________________________________________________________
445 Bool_t AliTRDPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
447 // read calibration entries from file
449 if(fCH2d) return kTRUE;
450 TFile fcalib(fileName);
451 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
453 TH2I *ch2d = (TH2I *) array->FindObject("CH2d");
454 if(!ch2d) return kFALSE;
455 fCH2d = (TH2I*)ch2d->Clone();
456 //fNEvents = (TH1I *) array->FindObject("NEvents");
457 //fAbsoluteGain = (TH2F *) array->FindObject("AbsoluteGain");
459 TH2I *ch2d = (TH2I *) fcalib.Get("CH2d");
460 if(!ch2d) return kFALSE;
461 fCH2d = (TH2I*)ch2d->Clone();
462 //fNEvents = (TH1I *) fcalib.Get("NEvents");
463 //fAbsoluteGain = (TH2F *) fcalib.Get("AbsoluteGain");
465 fCH2d->SetDirectory(0);
466 //printf("title of CH2d %s\n",fCH2d->GetTitle());
471 //_________________________________________________________________________________________________________________
473 Bool_t AliTRDPreprocessorOffline::ReadVdriftT0Global(const Char_t* fileName){
475 // read calibration entries from file
477 if(fPH2d) return kTRUE;
478 TFile fcalib(fileName);
479 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
481 TProfile2D *ph2d = (TProfile2D *) array->FindObject("PH2d");
482 if(!ph2d) return kFALSE;
483 fPH2d = (TProfile2D*)ph2d->Clone();
484 //fNEvents = (TH1I *) array->FindObject("NEvents");
486 TProfile2D *ph2d = (TProfile2D *) fcalib.Get("PH2d");
487 if(!ph2d) return kFALSE;
488 fPH2d = (TProfile2D*)ph2d->Clone();
489 //fNEvents = (TH1I *) fcalib.Get("NEvents");
491 fPH2d->SetDirectory(0);
492 //printf("title of PH2d %s\n",fPH2d->GetTitle());
497 //___________________________________________________________________________________________________________________
499 Bool_t AliTRDPreprocessorOffline::ReadVdriftLinearFitGlobal(const Char_t* fileName){
501 // read calibration entries from file
503 if(fAliTRDCalibraVdriftLinearFit) return kTRUE;
504 TFile fcalib(fileName);
505 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
507 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) array->FindObject("AliTRDCalibraVdriftLinearFit");
508 //fNEvents = (TH1I *) array->FindObject("NEvents");
510 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) fcalib.Get("AliTRDCalibraVdriftLinearFit");
511 //fNEvents = (TH1I *) fcalib.Get("NEvents");
513 if(!fAliTRDCalibraVdriftLinearFit) {
514 //printf("No AliTRDCalibraVdriftLinearFit\n");
520 //_____________________________________________________________________________________________________________
521 Bool_t AliTRDPreprocessorOffline::ReadExbAltFitGlobal(const Char_t* fileName){
523 // read calibration entries from file
525 if(fAliTRDCalibraExbAltFit) return kTRUE;
526 TFile fcalib(fileName);
527 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
529 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) array->FindObject("AliTRDCalibraExbAltFit");
530 //fNEvents = (TH1I *) array->FindObject("NEvents");
532 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) fcalib.Get("AliTRDCalibraExbAltFit");
533 //fNEvents = (TH1I *) fcalib.Get("NEvents");
535 if(!fAliTRDCalibraExbAltFit) {
536 //printf("No AliTRDCalibraExbAltFit\n");
542 //_____________________________________________________________________________________________________________
544 Bool_t AliTRDPreprocessorOffline::ReadPRFGlobal(const Char_t* fileName){
546 // read calibration entries from file
548 if(fPRF2d) return kTRUE;
549 TFile fcalib(fileName);
550 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
552 TProfile2D *prf2d = (TProfile2D *) array->FindObject("PRF2d");
553 if(!prf2d) return kFALSE;
554 fPRF2d = (TProfile2D*)prf2d->Clone();
555 //fNEvents = (TH1I *) array->FindObject("NEvents");
557 TProfile2D *prf2d = (TProfile2D *) fcalib.Get("PRF2d");
558 if(!prf2d) return kFALSE;
559 fPRF2d = (TProfile2D*)prf2d->Clone();
560 //fNEvents = (TH1I *) fcalib.Get("NEvents");
562 fPRF2d->SetDirectory(0);
563 //printf("title of PRF2d %s\n",fPRF2d->GetTitle());
568 //__________________________________________________________________________________________________________
570 Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
572 // Analyze gain - produce the calibration objects
575 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
576 calibra->SetMinEntries(fMinStatsGain); // If there is less than 1000 entries in the histo: no fit
577 calibra->AnalyseCH(fCH2d);
579 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
580 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
581 Int_t nbfit = calibra->GetNumberFit();
582 Int_t nbE = calibra->GetNumberEnt();
586 Bool_t meanother = kFALSE;
589 (nbfit >= 0.5*nbE) && (nbE > 30)) {
590 // create the cal objects
591 if(!fBackCorrectGain) {
592 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
595 TObjArray object = calibra->GetVectorFit();
596 AliTRDCalDet *calDetGain = calibra->CreateDetObjectGain(&object,meanother);
597 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
598 // Put them in the array
599 fCalibObjects->AddAt(calDetGain,kGain);
600 fPlots->AddAt(coefGain,kGain);
605 fNotEnoughStatisticsForTheGain = kTRUE;
606 Int_t minStatsGain = fMinStatsGain*30;
607 calibra->SetMinEntries(minStatsGain); // Because we do it for all, we increase this
608 Double_t gainoverallnotnormalized = calibra->AnalyseCHAllTogether(fCH2d);
609 if(fCalDetGainUsed && (gainoverallnotnormalized > 0.0)) {
610 AliTRDCalDet *calDetGain = new AliTRDCalDet(*fCalDetGainUsed);
611 Double_t oldmean = fCalDetGainUsed->CalcMean(kFALSE);
612 //printf("oldmean %f\n",oldmean);
614 Double_t scalefactor = calibra->GetScaleFactorGain();
615 //printf("Correction factor %f\n",gainoverallnotnormalized*scalefactor);
616 calDetGain->Multiply(gainoverallnotnormalized*scalefactor/oldmean);
617 //printf("newmean %f\n",calDetGain->CalcMean(kFALSE));
618 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
619 fCalibObjects->AddAt(calDetGain,kGain);
620 fPlots->AddAt(coefGain,kGain);
623 fStatusNeg = fStatusNeg | kGainNotEnoughStatsButFill;
626 fStatusPos = fStatusPos | kGainErrorOld;
630 if(gainoverallnotnormalized <= 0.0) fStatusNeg = fStatusNeg | kGainNotEnoughStatsNotFill;
631 if(!fCalDetGainUsed) fStatusPos = fStatusPos | kGainErrorOld;
635 calibra->ResetVectorFit();
640 //_____________________________________________________________________________________________________
641 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftT0(){
643 // Analyze VdriftT0 - produce the calibration objects
646 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
647 calibra->SetMinEntries(fMinStatsVdriftT0PH); // If there is less than 1000 entries in the histo: no fit
648 calibra->AnalysePH(fPH2d);
650 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
651 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
652 Int_t nbfit = calibra->GetNumberFit();
653 Int_t nbfitSuccess = calibra->GetNumberFitSuccess();
654 Int_t nbE = calibra->GetNumberEnt();
656 //printf("nbtg %d, nbfit %d, nbE %d, nbfitSuccess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
660 (nbfit >= 0.5*nbE) && (nbE > 30) && (nbfitSuccess > 30)) {
661 //printf("Pass the cut for VdriftT0\n");
662 // create the cal objects
663 calibra->RemoveOutliers(1,kFALSE);
664 calibra->PutMeanValueOtherVectorFit(1,kFALSE);
665 calibra->RemoveOutliers2(kFALSE);
666 calibra->PutMeanValueOtherVectorFit2(1,kFALSE);
668 TObjArray object = calibra->GetVectorFit();
669 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object);
670 TH1F *coefVdriftPH = calDetVdrift->MakeHisto1DAsFunctionOfDet();
671 AliTRDCalPad *calPadVdrift = (AliTRDCalPad *)calibra->CreatePadObjectVdrift(&object,calDetVdrift);
672 TH1F *coefPadVdrift = calPadVdrift->MakeHisto1D();
673 object = calibra->GetVectorFit2();
674 AliTRDCalDet *calDetT0 = calibra->CreateDetObjectT0(&object);
675 TH1F *coefT0 = calDetT0->MakeHisto1DAsFunctionOfDet();
676 AliTRDCalPad *calPadT0 = (AliTRDCalPad *)calibra->CreatePadObjectT0(&object,calDetT0);
677 TH1F *coefPadT0 = calPadT0->MakeHisto1D();
678 // Put them in the array
679 fCalibObjects->AddAt(calDetT0,kT0PHDet);
680 fCalibObjects->AddAt(calDetVdrift,kVdriftPHDet);
681 fCalibObjects->AddAt(calPadT0,kT0PHPad);
682 fCalibObjects->AddAt(calPadVdrift,kVdriftPHPad);
683 fPlots->AddAt(coefVdriftPH,kVdriftPHDet);
684 fPlots->AddAt(coefT0,kT0PHDet);
685 fPlots->AddAt(coefPadVdrift,kVdriftPHPad);
686 fPlots->AddAt(coefPadT0,kT0PHPad);
691 //printf("Not enough stats timeoffset\n");
692 fStatusNeg = fStatusNeg | kTimeOffsetNotEnoughStatsNotFill;
694 calibra->ResetVectorFit();
699 //____________________________________________________________________________________________________________________
700 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftLinearFit(){
702 // Analyze vdrift linear fit - produce the calibration objects
705 //printf("Analyse linear fit\n");
708 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
709 calibra->SetCalDetVdriftExB(fCalDetVdriftUsed,fCalDetExBUsed);
710 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
711 //printf("Fill PE Array\n");
712 fAliTRDCalibraVdriftLinearFit->SetRobustFit(fRobustFitDriftVelocity);
713 fAliTRDCalibraVdriftLinearFit->FillPEArray();
714 //printf("AliTRDCalibraFit\n");
715 calibra->AnalyseLinearFitters(fAliTRDCalibraVdriftLinearFit);
719 Int_t nbfit = calibra->GetNumberFit();
720 Int_t nbE = calibra->GetNumberEnt();
725 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
726 // create the cal objects
727 //calibra->RemoveOutliers(1,kTRUE);
728 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
729 //calibra->RemoveOutliers2(kTRUE);
730 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
732 TObjArray object = calibra->GetVectorFit();
733 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object,kTRUE);
734 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
735 object = calibra->GetVectorFit2();
736 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectLorentzAngle(&object);
737 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
738 //if(!calDetLorentz) printf("No lorentz created\n");
739 // Put them in the array
740 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
741 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
742 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
743 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
748 fNotEnoughStatisticsForTheVdriftLinear = kTRUE;
749 Int_t minNumberOfEntriesForAll = fMinStatsVdriftLinear*30;
750 calibra->SetMinEntries(minNumberOfEntriesForAll); // Because we do it for all, we increase this
751 Double_t vdriftoverall = -100.0;
752 Double_t exboverall = 100.0;
753 calibra->AnalyseLinearFittersAllTogether(fAliTRDCalibraVdriftLinearFit,vdriftoverall,exboverall);
754 //printf("Found mean vdrift %f and exb %f\n",vdriftoverall,exboverall);
755 if(fCalDetVdriftUsed && (vdriftoverall > 0.0) && (exboverall < 70.0)) {
756 AliTRDCalDet *calDetVdrift = new AliTRDCalDet(*fCalDetVdriftUsed);
757 AliTRDCalDet *calDetLorentz = new AliTRDCalDet(*fCalDetExBUsed);
758 Double_t oldmeanvdrift = fCalDetVdriftUsed->CalcMean(kFALSE);
759 Double_t oldmeanexb = fCalDetExBUsed->CalcMean(kFALSE);
760 //printf("oldmean %f\n",oldmean);
761 if((oldmeanvdrift > 0.0) && (oldmeanexb < 70.0)) {
762 //printf("Correction factor %f\n",vdriftoverall);
763 calDetVdrift->Multiply(vdriftoverall/oldmeanvdrift);
764 calDetLorentz->Multiply(exboverall/oldmeanexb);
765 //printf("newmean %f\n",calDetVdrift->CalcMean(kFALSE));
766 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
767 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
768 // Put them in the array
769 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
770 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
771 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
772 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
775 fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsButFill;
778 if(oldmeanvdrift) fStatusPos = fStatusPos | kVdriftErrorOld;
779 if(oldmeanexb) fStatusPos = fStatusPos | kExBErrorOld;
783 if((vdriftoverall <= 0.0) && (exboverall > 70.0)) fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsNotFill;
784 if(!fCalDetVdriftUsed) fStatusPos = fStatusPos | kVdriftErrorOld;
785 if(!fCalDetExBUsed) fStatusPos = fStatusPos | kExBErrorOld;
789 calibra->ResetVectorFit();
794 //________________________________________________________________________________________________________________
796 Bool_t AliTRDPreprocessorOffline::AnalyzeExbAltFit(){
798 // Analyze vdrift linear fit - produce the calibration objects
801 //printf("Analyse linear fit\n");
804 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
805 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
806 //printf("Fill PE Array\n");
807 fAliTRDCalibraExbAltFit->SetRobustFit(fRobustFitExbAlt);
808 fAliTRDCalibraExbAltFit->FillPEArray();
809 //printf("AliTRDCalibraFit\n");
810 calibra->AnalyseExbAltFit(fAliTRDCalibraExbAltFit);
814 Int_t nbfit = calibra->GetNumberFit();
815 Int_t nbE = calibra->GetNumberEnt();
820 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
821 // create the cal objects
822 //calibra->RemoveOutliers(1,kTRUE);
823 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
825 TObjArray object = calibra->GetVectorFit2();
826 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectExbAlt(&object);
827 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
828 //if(!calDetLorentz) printf("No lorentz created\n");
829 // Put them in the array
830 fCalibObjects->AddAt(calDetLorentz,kExbAlt);
831 fPlots->AddAt(coefLorentzAngle,kExbAlt);
836 calibra->ResetVectorFit();
841 //________________________________________________________________________________________________________________
843 Bool_t AliTRDPreprocessorOffline::AnalyzePRF(){
845 // Analyze PRF - produce the calibration objects
848 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
849 calibra->SetMinEntries(fMinStatsPRF); // If there is less than 1000 entries in the histo: no fit
850 calibra->AnalysePRFMarianFit(fPRF2d);
852 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
853 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
854 Int_t nbfit = calibra->GetNumberFit();
855 Int_t nbE = calibra->GetNumberEnt();
861 (nbfit >= 0.95*nbE) && (nbE > 30)) {
862 // create the cal objects
863 TObjArray object = calibra->GetVectorFit();
864 AliTRDCalPad *calPadPRF = (AliTRDCalPad*) calibra->CreatePadObjectPRF(&object);
865 TH1F *coefPRF = calPadPRF->MakeHisto1D();
866 // Put them in the array
867 fCalibObjects->AddAt(calPadPRF,kPRF);
868 fPlots->AddAt(coefPRF,kPRF);
873 calibra->ResetVectorFit();
879 //_____________________________________________________________________________
880 Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
883 // Produce AliTRDCalChamberStatus out of calibration results
886 // set up AliTRDCalibChamberStatus
887 AliTRDCalibChamberStatus *ChamberStatus = new AliTRDCalibChamberStatus();
888 ChamberStatus->SetSparseI(fSparse);
889 ChamberStatus->AnalyseHisto(fMinStatsChamberStatus);
890 // get AliTRDCalChamberStatus
891 AliTRDCalChamberStatus *CalChamberStatus = ChamberStatus->GetCalChamberStatus();
893 // get calibration objects
894 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
895 AliTRDCalDet *calDetVDrift = (AliTRDCalDet *) fCalibObjects->At(kVdriftLinear);
896 AliTRDCalDet *calDetExB = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
899 if((!calDetGain) || (!calDetVDrift) || (!fCH2d) || (!calDetExB) || (!CalChamberStatus)) return kFALSE;
902 Double_t gainmean = calDetGain->GetMean();
903 Double_t vdriftmean = calDetVDrift->GetMean();
904 Double_t exbmean = calDetExB->GetMean();
906 Double_t gainrms = calDetGain->GetRMSRobust();
907 Double_t vdriftrms = calDetVDrift->GetRMSRobust();
908 Double_t exbrms = calDetExB->GetRMSRobust();
910 //printf("Gain mean: %f, rms: %f\n",gainmean,gainrms);
911 //printf("Vdrift mean: %f, rms: %f\n",vdriftmean,vdriftrms);
912 //printf("ExB mean: %f, rms: %f\n",exbmean,exbrms);
915 if((TMath::Abs(gainrms) < 0.001) || (TMath::Abs(vdriftrms) < 0.001) || (TMath::Abs(exbrms) < 0.0000001)) return kFALSE;
917 // mask chambers with empty gain entries
919 for (Int_t idet = 0; idet < 540; idet++) {
922 TH1I *projch = (TH1I *) fCH2d->ProjectionX("projch",idet+1,idet+1,(Option_t *)"e");
923 Double_t entries = projch->GetEntries();
924 //printf("Number of entries %f for det %d\n",entries,idet);
927 Double_t gain = calDetGain->GetValue(idet);
930 Double_t vdrift = calDetVDrift->GetValue(idet);
933 Double_t exb = calDetExB->GetValue(idet);
936 if( (entries<50 && !CalChamberStatus->IsNoData(idet)) ||
937 TMath::Abs(gainmean-gain) > (fRMSBadCalibratedGain*gainrms) ||
938 TMath::Abs(vdriftmean-vdrift) > (fRMSBadCalibratedVdrift*vdriftrms) ||
939 TMath::Abs(exbmean-exb) > (fRMSBadCalibratedExB*exbrms) ) {
941 //printf(" chamber det %03d masked \n",idet);
942 //printf(" gainmean %f and gain %f, gainrms %f \n",gainmean,gain,gainrms);
943 //printf(" vdriftmean %f and vdrift %f, vdriftrms %f \n",vdriftmean,vdrift,vdriftrms);
944 //printf(" exbmean %f and exb %f, exbrms %f \n",exbmean,exb,exbrms);
946 CalChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kBadCalibrated);
955 for(Int_t sm=0; sm < 18; sm++) {
957 Int_t smbadcalib = 0;
958 for(Int_t det = 0; det < 30; det++){
959 Int_t detector = sm*30+det;
960 if(CalChamberStatus->IsNoData(detector)) smnodata++;
962 if(CalChamberStatus->IsBadCalibrated(detector)) smbadcalib++;
965 fNoData[sm] = smnodata;
966 fBadCalib[sm]= smbadcalib;
967 //printf("No Data %d, bad calibrated %d for %d\n",fNoData[sm],fBadCalib[sm],sm);
971 // for(Int_t sm=0; sm < 18; sm++) {
972 // Int_t counter = 0;
973 // for(Int_t det = 0; det < 30; det++){
974 // Int_t detector = sm*30+det;
975 // if(CalChamberStatus->IsBadCalibrated(detector)) counter++;
977 // if(counter >= 20) {
978 // for(Int_t det = 0; det < 30; det++){
979 // Int_t detector = sm*30+det;
980 // CalChamberStatus->SetStatus(detector,AliTRDCalChamberStatus::kGood);
985 fCalibObjects->AddAt(CalChamberStatus,kChamberStatus);
991 //________________________________________________________________________________________________
992 void AliTRDPreprocessorOffline::CorrectFromDetGainUsed() {
994 // Correct from the gas gain used afterwards
996 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
997 if(!calDetGain) return;
1000 Double_t mean = 0.0;
1003 for(Int_t det = 0; det < 540; det++) {
1005 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1006 Float_t gainout = calDetGain->GetValue(det);
1009 if(TMath::Abs(gainout-1.0) > 0.000001) {
1010 mean += (gaininit*gainout);
1014 if(nbdet > 0) mean = mean/nbdet;
1016 for(Int_t det = 0; det < 540; det++) {
1018 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1019 Float_t gainout = calDetGain->GetValue(det);
1021 if(TMath::Abs(gainout-1.0) > 0.000001) {
1022 Double_t newgain = gaininit*gainout;
1023 if(newgain < 0.1) newgain = 0.1;
1024 if(newgain > 1.9) newgain = 1.9;
1025 calDetGain->SetValue(det,newgain);
1028 Double_t newgain = mean;
1029 if(newgain < 0.1) newgain = 0.1;
1030 if(newgain > 1.9) newgain = 1.9;
1031 calDetGain->SetValue(det,newgain);
1037 //________________________________________________________________________________________________
1038 void AliTRDPreprocessorOffline::CorrectFromDetVdriftUsed() {
1040 // Correct from the drift velocity
1043 //printf("Correct for vdrift\n");
1045 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1046 if(!calDetGain) return;
1048 Int_t detVdrift = kVdriftPHDet;
1049 if(fMethodSecond) detVdrift = kVdriftLinear;
1050 AliTRDCalDet *calDetVdrift = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1051 if(!calDetVdrift) return;
1054 if(!fNotEnoughStatisticsForTheVdriftLinear) {
1055 for(Int_t det = 0; det < 540; det++) {
1057 Float_t vdriftinit = fCalDetVdriftUsed->GetValue(det);
1058 Float_t vdriftout = calDetVdrift->GetValue(det);
1060 Float_t gain = calDetGain->GetValue(det);
1061 if(vdriftout > 0.0) gain = gain*vdriftinit/vdriftout;
1062 if(gain < 0.1) gain = 0.1;
1063 if(gain > 1.9) gain = 1.9;
1064 calDetGain->SetValue(det,gain);
1069 Float_t vdriftinit = fCalDetVdriftUsed->CalcMean(kFALSE);
1070 Float_t vdriftout = calDetVdrift->CalcMean(kFALSE);
1071 Float_t factorcorrectif = 1.0;
1072 if(vdriftout > 0.0) factorcorrectif = vdriftinit/vdriftout;
1073 for(Int_t det = 0; det < 540; det++) {
1074 Float_t gain = calDetGain->GetValue(det);
1075 gain = gain*factorcorrectif;
1076 if(gain < 0.1) gain = 0.1;
1077 if(gain > 1.9) gain = 1.9;
1078 calDetGain->SetValue(det,gain);
1084 //_________________________________________________________________________________________________________________
1085 void AliTRDPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1087 // Update OCDB entry
1090 AliCDBMetaData *metaData= new AliCDBMetaData();
1091 metaData->SetObjectClassName("AliTRDCalDet");
1092 metaData->SetResponsible("Raphaelle Bailhache");
1093 metaData->AddDateToComment();
1094 metaData->SetBeamPeriod(1);
1096 AliCDBId id1("TRD/Calib/ChamberGainFactor", startRunNumber, endRunNumber);
1097 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1098 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1099 if(calDet) gStorage->Put(calDet, id1, metaData);
1103 //___________________________________________________________________________________________________________________
1104 void AliTRDPreprocessorOffline::UpdateOCDBExB(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1106 // Update OCDB entry
1109 Int_t detExB = kLorentzLinear;
1110 if(!fMethodSecond) return;
1114 AliCDBMetaData *metaData= new AliCDBMetaData();
1115 metaData->SetObjectClassName("AliTRDCalDet");
1116 metaData->SetResponsible("Raphaelle Bailhache");
1117 metaData->AddDateToComment();
1118 metaData->SetBeamPeriod(1);
1120 AliCDBId id1("TRD/Calib/ChamberExB", startRunNumber, endRunNumber);
1121 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1122 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1123 if(calDet) gStorage->Put(calDet, id1, metaData);
1124 //if(!calDet) printf("No caldet\n");
1127 //___________________________________________________________________________________________________________________
1128 void AliTRDPreprocessorOffline::UpdateOCDBExBAlt(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1130 // Update OCDB entry
1133 Int_t detExB = kExbAlt;
1134 if(!fMethodSecond) return;
1138 AliCDBMetaData *metaData= new AliCDBMetaData();
1139 metaData->SetObjectClassName("AliTRDCalDet");
1140 metaData->SetResponsible("Theo Rascanu");
1141 metaData->AddDateToComment();
1142 metaData->SetBeamPeriod(1);
1144 AliCDBId id1("TRD/Calib/ChamberExBAlt", startRunNumber, endRunNumber);
1145 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1146 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1147 if(calDet) gStorage->Put(calDet, id1, metaData);
1148 //if(!calDet) printf("No caldet\n");
1151 //___________________________________________________________________________________________________________________
1152 void AliTRDPreprocessorOffline::UpdateOCDBVdrift(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1154 // Update OCDB entry
1157 Int_t detVdrift = kVdriftPHDet;
1159 if(fMethodSecond) detVdrift = kVdriftLinear;
1161 AliCDBMetaData *metaData= new AliCDBMetaData();
1162 metaData->SetObjectClassName("AliTRDCalDet");
1163 metaData->SetResponsible("Raphaelle Bailhache");
1164 metaData->AddDateToComment();
1165 metaData->SetBeamPeriod(1);
1167 AliCDBId id1("TRD/Calib/ChamberVdrift", startRunNumber, endRunNumber);
1168 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1169 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1170 if(calDet) gStorage->Put(calDet, id1, metaData);
1174 if(!fMethodSecond) {
1176 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1177 metaDataPad->SetObjectClassName("AliTRDCalPad");
1178 metaDataPad->SetResponsible("Raphaelle Bailhache");
1179 metaDataPad->AddDateToComment();
1180 metaDataPad->SetBeamPeriod(1);
1182 AliCDBId id1Pad("TRD/Calib/LocalVdrift", startRunNumber, endRunNumber);
1183 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1184 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
1189 //________________________________________________________________________________________________________________________
1190 void AliTRDPreprocessorOffline::UpdateOCDBT0(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1192 // Update OCDB entry
1195 AliCDBMetaData *metaData= new AliCDBMetaData();
1196 metaData->SetObjectClassName("AliTRDCalDet");
1197 metaData->SetResponsible("Raphaelle Bailhache");
1198 metaData->AddDateToComment();
1199 metaData->SetBeamPeriod(1);
1201 AliCDBId id1("TRD/Calib/ChamberT0", startRunNumber, endRunNumber);
1202 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1203 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1204 if(calDet) gStorage->Put(calDet, id1, metaData);
1208 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1209 metaDataPad->SetObjectClassName("AliTRDCalPad");
1210 metaDataPad->SetResponsible("Raphaelle Bailhache");
1211 metaDataPad->AddDateToComment();
1212 metaDataPad->SetBeamPeriod(1);
1214 AliCDBId id1Pad("TRD/Calib/LocalT0", startRunNumber, endRunNumber);
1215 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1216 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
1221 //_________________________________________________________________________________________________________________
1222 void AliTRDPreprocessorOffline::UpdateOCDBPRF(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1224 // Update OCDB entry
1227 AliCDBMetaData *metaData= new AliCDBMetaData();
1228 metaData->SetObjectClassName("AliTRDCalPad");
1229 metaData->SetResponsible("Raphaelle Bailhache");
1230 metaData->AddDateToComment();
1231 metaData->SetBeamPeriod(1);
1234 AliCDBId id1("TRD/Calib/PRFWidth", startRunNumber, endRunNumber);
1235 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1236 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1237 if(calPad) gStorage->Put(calPad, id1, metaData);
1241 //_________________________________________________________________________________________________________________
1242 void AliTRDPreprocessorOffline::UpdateOCDBChamberStatus(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1244 // Update OCDB entry
1247 AliCDBMetaData *metaData= new AliCDBMetaData();
1248 metaData->SetObjectClassName("AliTRDCalChamberStatus");
1249 metaData->SetResponsible("Raphaelle Bailhache and Julian Book");
1250 metaData->AddDateToComment();
1251 metaData->SetBeamPeriod(1);
1253 AliCDBId id1("TRD/Calib/ChamberStatus", startRunNumber, endRunNumber);
1254 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1255 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1256 if(calChamberStatus) gStorage->Put(calChamberStatus, id1, metaData);
1260 //__________________________________________________________________________________________________________________________
1261 Bool_t AliTRDPreprocessorOffline::ValidateGain() {
1263 // Validate OCDB entry
1266 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1268 Double_t mean = calDet->GetMean();
1269 Double_t rms = calDet->GetRMSRobust();
1270 if((mean > 0.2) && (mean < 1.4) && (rms < 0.5)) return kTRUE;
1271 //if((mean > 0.2) && (mean < 1.4)) return kTRUE;
1273 fStatusPos = fStatusPos | kGainErrorRange;
1282 //__________________________________________________________________________________________________________________________
1283 Bool_t AliTRDPreprocessorOffline::ValidateVdrift(){
1285 // Update OCDB entry
1288 Int_t detVdrift = kVdriftPHDet;
1291 if(fMethodSecond) detVdrift = kVdriftLinear;
1293 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1295 Double_t mean = calDet->GetMean();
1296 Double_t rms = calDet->GetRMSRobust();
1297 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1298 if(!((mean > 1.0) && (mean < 2.0) && (rms < 0.5))) {
1299 fStatusPos = fStatusPos | kVdriftErrorRange;
1305 if(!fMethodSecond) {
1306 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1308 Double_t mean = calPad->GetMean();
1309 Double_t rms = calPad->GetRMS();
1310 //printf("Vdrift::meanpad %f, rmspad %f\n",mean,rms);
1311 if(!((mean > 0.9) && (mean < 1.1) && (rms < 0.6))) {
1312 fStatusPos = fStatusPos | kVdriftErrorRange;
1322 //__________________________________________________________________________________________________________________________
1323 Bool_t AliTRDPreprocessorOffline::ValidateExB(){
1325 // Update OCDB entry
1328 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
1330 Double_t mean = calDet->GetMean();
1331 Double_t rms = calDet->GetRMSRobust();
1332 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1333 if(!((mean > -1.0) && (mean < 1.0) && (rms < 0.5))) {
1334 fStatusNeg = fStatusNeg | kExBErrorRange;
1342 //__________________________________________________________________________________________________________________________
1343 Bool_t AliTRDPreprocessorOffline::ValidateT0(){
1345 // Update OCDB entry
1348 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1349 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1350 if(calDet && calPad) {
1351 Double_t meandet = calDet->GetMean();
1352 Double_t rmsdet = calDet->GetRMSRobust();
1353 Double_t meanpad = calPad->GetMean();
1354 //Double_t rmspad = calPad->GetRMS();
1355 //printf("T0::minimum %f, rmsdet %f,meanpad %f, rmspad %f\n",meandet,rmsdet,meanpad,rmspad);
1356 if((meandet > -1.5) && (meandet < 5.0) && (rmsdet < 4.0) && (meanpad < 5.0) && (meanpad > -0.5)) return kTRUE;
1358 fStatusPos = fStatusPos | kTimeOffsetErrorRange;
1365 //__________________________________________________________________________________________________________________________
1366 Bool_t AliTRDPreprocessorOffline::ValidatePRF() const{
1368 // Update OCDB entry
1371 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1373 Double_t meanpad = calPad->GetMean();
1374 Double_t rmspad = calPad->GetRMS();
1375 //printf("PRF::meanpad %f, rmspad %f\n",meanpad,rmspad);
1376 if((meanpad < 1.0) && (rmspad < 0.8)) return kTRUE;
1383 //__________________________________________________________________________________________________________________________
1384 Bool_t AliTRDPreprocessorOffline::ValidateChamberStatus(){
1386 // Update OCDB entry
1389 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1390 if(calChamberStatus) {
1392 Int_t detectornodata = 0;
1393 Int_t detectorbadcalib = 0;
1395 for(Int_t sm=0; sm < 18; sm++) {
1396 //printf("%d chambers w/o data in sm %d\n",fNoData[sm],sm);
1397 //printf("%d bad calibrated chambers in sm %d\n",fBadCalib[sm],sm);
1398 if(fNoData[sm] != 30) detectornodata += fNoData[sm];
1399 detectorbadcalib+=fBadCalib[sm];
1401 //printf("Number of chambers w/o data %d\n",detectornodata);
1402 //printf("Number of chambers bad calibrated %d\n",detectorbadcalib);
1404 if((detectornodata > fNoDataValidate) ||
1405 (detectorbadcalib > fBadCalibValidate)){
1406 fStatusPos = fStatusPos | kChamberStatusErrorRange;
1414 //_____________________________________________________________________________
1415 Int_t AliTRDPreprocessorOffline::GetVersion(TString name) const
1418 // Get version from the title
1422 const Char_t *version = "Ver";
1423 if(!strstr(name.Data(),version)) return -1;
1424 const Char_t *after = "Subver";
1425 if(!strstr(name.Data(),after)) return -1;
1427 for(Int_t ver = 0; ver < 999999999; ver++) {
1429 TString vertry(version);
1433 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1435 if(strstr(name.Data(),vertry.Data())) return ver;
1443 //_____________________________________________________________________________
1444 Int_t AliTRDPreprocessorOffline::GetSubVersion(TString name) const
1447 // Get subversion from the title
1451 const Char_t *subversion = "Subver";
1452 if(!strstr(name.Data(),subversion)) return -1;
1453 const Char_t *after = "FirstRun";
1454 if(!strstr(name.Data(),after)) {
1457 if(!strstr(name.Data(),after)) return -1;
1460 for(Int_t ver = 0; ver < 999999999; ver++) {
1462 TString vertry(subversion);
1466 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1468 if(strstr(name.Data(),vertry.Data())) return ver;
1476 //_____________________________________________________________________________
1477 Int_t AliTRDPreprocessorOffline::GetFirstRun(TString name) const
1480 // Get first run from the title
1484 const Char_t *firstrun = "FirstRun";
1485 if(!strstr(name.Data(),firstrun)) return -1;
1486 const Char_t *after = "Nz";
1487 if(!strstr(name.Data(),after)) return -1;
1490 for(Int_t ver = 0; ver < 999999999; ver++) {
1492 TString vertry(firstrun);
1496 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1498 if(strstr(name.Data(),vertry.Data())) return ver;
1505 //_____________________________________________________________________________
1506 Bool_t AliTRDPreprocessorOffline::CheckStatus(Int_t status, Int_t bitMask) const
1509 // Checks the status
1512 return (status & bitMask) ? kTRUE : kFALSE;
1515 //_____________________________________________________________________________
1516 Int_t AliTRDPreprocessorOffline::GetStatus() const
1519 // Checks the status
1520 // fStatusPos: errors
1521 // fStatusNeg: only info
1524 if(fStatusPos > 0) return fStatusPos;
1525 else return (-TMath::Abs(fStatusNeg));
1528 //_____________________________________________________________________________
1529 void AliTRDPreprocessorOffline::PrintStatus() const
1535 AliInfo(Form("The error status is %d",fStatusPos));
1536 AliInfo(Form("IsGainErrorOld? %d",(Int_t)IsGainErrorOld()));
1537 AliInfo(Form("IsVdriftErrorOld? %d",(Int_t)IsVdriftErrorOld()));
1538 AliInfo(Form("IsGainErrorRange? %d",(Int_t)IsGainErrorRange()));
1539 AliInfo(Form("IsVdriftErrorRange? %d",(Int_t)IsVdriftErrorRange()));
1540 AliInfo(Form("IsTimeOffsetErrorRange? %d",(Int_t)IsTimeOffsetErrorRange()));
1541 AliInfo(Form("IsChamberStatusErrorRange? %d",(Int_t)IsChamberStatusErrorRange()));
1544 AliInfo(Form("The info status is %d",fStatusNeg));
1545 AliInfo(Form("IsGainNotEnoughStatsButFill? %d",(Int_t)IsGainNotEnoughStatsButFill()));
1546 AliInfo(Form("IsVdriftNotEnoughStatsButFill? %d",(Int_t)IsVdriftNotEnoughStatsButFill()));
1547 AliInfo(Form("IsGainNotEnoughStatsNotFill? %d",(Int_t)IsGainNotEnoughStatsNotFill()));
1548 AliInfo(Form("IsVdriftNotEnoughStatsNotFill? %d",(Int_t)IsVdriftNotEnoughStatsNotFill()));
1549 AliInfo(Form("IsTimeOffsetNotEnoughStatsNotFill? %d",(Int_t)IsTimeOffsetNotEnoughStatsNotFill()));
1551 AliInfo(Form("IsExBErrorRange? %d",(Int_t)IsExBErrorRange()));
1552 AliInfo(Form("IsExBErrorOld? %d",(Int_t)IsExBErrorOld()));
1555 //___________________________________________________________________________________
1556 void AliTRDPreprocessorOffline::SetCalDetVdrift(AliTRDCalDet *calDetVdriftUsed)
1559 fCalDetVdriftUsed = calDetVdriftUsed;
1561 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1562 for(Int_t k = 0; k < 540; k++){
1563 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1564 //printf("Set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1568 //___________________________________________________________________________________
1569 Bool_t AliTRDPreprocessorOffline::SetCalDetGain(Int_t runNumber, Int_t version, Int_t subversion)
1572 // Set the fCalDetGainUsed
1575 if((version == 0) && (subversion == 0)) return kFALSE;
1577 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor",runNumber, version, subversion);
1579 AliError("Found no entry\n");
1580 fStatusPos = fStatusPos | kGainErrorOld;
1583 //const AliCDBId id = entry->GetId();
1584 //version = id.GetVersion();
1585 //subversion = id.GetSubVersion();
1586 //printf("Found version %d and subversion %d for vdrift\n",version,subversion);
1587 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1588 if(calDet) fCalDetGainUsed = calDet;
1590 fStatusPos = fStatusPos | kGainErrorOld;
1597 //___________________________________________________________________________________
1598 Bool_t AliTRDPreprocessorOffline::SetCalDetVdriftExB(Int_t runNumber, Int_t versionv, Int_t subversionv, Int_t versionexb, Int_t subversionexb)
1601 // Set the fCalDetVdriftUsed and fCalDetExBUsed
1604 if((versionv == 0) && (subversionv == 0)) return kFALSE;
1606 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberVdrift",runNumber, versionv, subversionv);
1608 AliError("Found no entry\n");
1609 fStatusPos = fStatusPos | kVdriftErrorOld;
1612 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1613 if(calDet) fCalDetVdriftUsed = calDet;
1615 fStatusPos = fStatusPos | kVdriftErrorOld;
1621 if((versionexb == 0) && (subversionexb == 0)) {
1623 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1624 for(Int_t k = 0; k < 540; k++){
1625 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1626 //printf("Nothing found: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1632 entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberExB",runNumber, versionexb, subversionexb);
1634 //printf("Found no entry\n");
1635 fStatusPos = fStatusPos | kExBErrorOld;
1638 AliTRDCalDet* calDetexb = (AliTRDCalDet *)entry->GetObject();
1640 fStatusPos = fStatusPos | kExBErrorOld;
1644 Double_t meanexb = calDetexb->GetMean();
1645 //printf("Mean value %f\n",meanexb);
1646 if((meanexb > 70) || (fNoExBUsedInReco)) {
1647 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1648 for(Int_t k = 0; k < 540; k++){
1649 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1650 //printf("Found but: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1654 fCalDetExBUsed = calDetexb;