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)
121 // default constructor
124 memset(fBadCalib, 0, sizeof(Int_t) * 18);
125 memset(fNoData, 0, sizeof(Int_t) * 18);
127 //_________________________________________________________________________________________________________________
128 AliTRDPreprocessorOffline::~AliTRDPreprocessorOffline() {
133 if(fCalDetGainUsed) delete fCalDetGainUsed;
134 if(fCalDetVdriftUsed) delete fCalDetVdriftUsed;
135 if(fCalDetExBUsed) delete fCalDetExBUsed;
136 if(fCH2d) delete fCH2d;
137 if(fPH2d) delete fPH2d;
138 if(fPRF2d) delete fPRF2d;
139 if(fSparse) delete fSparse;
140 if(fAliTRDCalibraVdriftLinearFit) delete fAliTRDCalibraVdriftLinearFit;
141 if(fAliTRDCalibraExbAltFit) delete fAliTRDCalibraExbAltFit;
142 if(fNEvents) delete fNEvents;
143 if(fAbsoluteGain) delete fAbsoluteGain;
144 if(fPlots) delete fPlots;
145 if(fCalibObjects) delete fCalibObjects;
148 //___________________________________________________________________________________
149 void AliTRDPreprocessorOffline::Process(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage)
152 // Process to the gain, vdrift, timeoffset, exb and chamber status calibration
155 if(SetCalDetGain(startRunNumber,fVersionGainUsed,fSubVersionGainUsed) && SetCalDetVdriftExB(startRunNumber,fVersionVdriftUsed,fSubVersionVdriftUsed,fVersionExBUsed,fSubVersionExBUsed)) {
157 CalibVdriftT0(file,startRunNumber,endRunNumber,ocdbStorage);
158 CalibGain(file,startRunNumber,endRunNumber,ocdbStorage);
159 CalibChamberStatus(file,startRunNumber,endRunNumber,ocdbStorage);
160 CalibExbAlt(file,startRunNumber,endRunNumber,ocdbStorage);
167 //___________________________________________________________________________________________________________________
169 void AliTRDPreprocessorOffline::CalibVdriftT0(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
171 // make calibration of the drift velocity
173 // file - the location of input file
174 // startRunNumber, endRunNumber - run validity period
175 // ocdbStorage - path to the OCDB storage
176 // - if empty - local storage 'pwd' uesed
177 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
181 fVdriftValidated = kTRUE;
182 fT0Validated = kTRUE;
183 fExBValidated = kTRUE;
184 fNotEnoughStatisticsForTheVdriftLinear = kFALSE;
186 // 2. extraction of the information
188 if(ReadVdriftLinearFitGlobal(file) && fCalDetVdriftUsed && fCalDetExBUsed) AnalyzeVdriftLinearFit();
189 if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
191 // 3. Append QA plots
193 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
196 // 4. validate OCDB entries
198 if(fSwitchOnValidation==kTRUE && ValidateVdrift()==kFALSE) {
199 //AliError("TRD vdrift OCDB parameters out of range!");
200 fVdriftValidated = kFALSE;
202 if(fSwitchOnValidation==kTRUE && ValidateT0()==kFALSE) {
203 //AliError("TRD t0 OCDB parameters out of range!");
204 fT0Validated = kFALSE;
206 if(fSwitchOnValidation==kTRUE && ValidateExB()==kFALSE) {
207 //AliError("TRD t0 OCDB parameters out of range!");
208 fExBValidated = kFALSE;
214 if(fVdriftValidated) UpdateOCDBVdrift(startRunNumber,endRunNumber,ocdbStorage);
215 if(fT0Validated) UpdateOCDBT0(startRunNumber,endRunNumber,ocdbStorage);
216 if(fExBValidated) UpdateOCDBExB(startRunNumber,endRunNumber,ocdbStorage);
219 //___________________________________________________________________________________________________________________
221 void AliTRDPreprocessorOffline::CalibExbAlt(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
223 // make calibration of the drift velocity
225 // file - the location of input file
226 // startRunNumber, endRunNumber - run validity period
227 // ocdbStorage - path to the OCDB storage
228 // - if empty - local storage 'pwd' uesed
229 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
235 // 2. extraction of the information
237 if(ReadExbAltFitGlobal(file)) AnalyzeExbAltFit();
239 // 3. Append QA plots
241 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
244 // 4. validate OCDB entries
250 UpdateOCDBExBAlt(startRunNumber,endRunNumber,ocdbStorage);
254 //_________________________________________________________________________________________________________________
256 void AliTRDPreprocessorOffline::CalibGain(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
258 // make calibration of the drift velocity
260 // file - the location of input file
261 // startRunNumber, endRunNumber - run validity period
262 // ocdbStorage - path to the OCDB storage
263 // - if empty - local storage 'pwd' uesed
264 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
266 fNotEnoughStatisticsForTheGain = kFALSE;
269 if(!ReadGainGlobal(file)) return;
272 // 2. extraction of the information
275 if(fBackCorrectGain) CorrectFromDetGainUsed();
276 //if(fBackCorrectVdrift) CorrectFromDetVdriftUsed();
278 // 3. Append QA plots
280 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
283 // 4. validate OCDB entries
285 if(fSwitchOnValidation==kTRUE && ValidateGain()==kFALSE) {
286 //AliError("TRD gain OCDB parameters out of range!");
293 if((!fCalDetVdriftUsed) || (fCalDetVdriftUsed && fVdriftValidated)) UpdateOCDBGain(startRunNumber,endRunNumber,ocdbStorage);
297 //________________________________________________________________________________________________________________
299 void AliTRDPreprocessorOffline::CalibPRF(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
301 // make calibration of the drift velocity
303 // file - the location of input file
304 // startRunNumber, endRunNumber - run validity period
305 // ocdbStorage - path to the OCDB storage
306 // - if empty - local storage 'pwd' uesed
307 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
310 if(!ReadPRFGlobal(file)) return;
313 // 2. extraction of the information
317 // 3. Append QA plots
319 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
323 // 4. validate OCDB entries
325 if(fSwitchOnValidation==kTRUE && ValidatePRF()==kFALSE) {
326 //AliError("TRD prf OCDB parameters out of range!");
333 UpdateOCDBPRF(startRunNumber,endRunNumber,ocdbStorage);
336 //________________________________________________________________________________________________________________
338 void AliTRDPreprocessorOffline::CalibChamberStatus(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
340 // make calibration of the chamber status
342 // startRunNumber, endRunNumber - run validity period
343 // ocdbStorage - path to the OCDB storage
344 // - if empty - local storage 'pwd' uesed
345 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
349 if(!ReadStatusGlobal(file)) return;
353 // 2. extraction of the information
355 if(!AnalyzeChamberStatus()) return;
357 // 3. Append QA plots
359 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
363 // 4. validate OCDB entries
365 if(fSwitchOnValidation==kTRUE && ValidateChamberStatus()==kFALSE) {
366 //AliError("TRD Chamber status OCDB parameters not ok!");
373 if((!fNotEnoughStatisticsForTheVdriftLinear) && (!fNotEnoughStatisticsForTheGain)) UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
374 //UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
377 //______________________________________________________________________________________________________
378 Bool_t AliTRDPreprocessorOffline::Init(const Char_t* fileName){
380 // read the calibration used during the reconstruction
383 if(ReadVdriftT0Global(fileName)) {
385 TString nameph = fPH2d->GetTitle();
386 fFirstRunVdriftUsed = GetFirstRun(nameph);
387 fVersionVdriftUsed = GetVersion(nameph);
388 fSubVersionVdriftUsed = GetSubVersion(nameph);
390 //printf("Found Version %d, Subversion %d for vdrift\n",fVersionVdriftUsed,fSubVersionVdriftUsed);
394 if(ReadGainGlobal(fileName)) {
396 TString namech = fCH2d->GetTitle();
397 fFirstRunGainUsed = GetFirstRun(namech);
398 fVersionGainUsed = GetVersion(namech);
399 fSubVersionGainUsed = GetSubVersion(namech);
401 //printf("Found Version %d, Subversion %d for gain\n",fVersionGainUsed,fSubVersionGainUsed);
405 if(ReadVdriftLinearFitGlobal(fileName)) {
407 TString namelinear = fAliTRDCalibraVdriftLinearFit->GetNameCalibUsed();
408 fFirstRunExBUsed = GetFirstRun(namelinear);
409 fVersionExBUsed = GetVersion(namelinear);
410 fSubVersionExBUsed = GetSubVersion(namelinear);
412 //printf("Found Version %d, Subversion %d, run %d for ExB\n",fVersionExBUsed,fSubVersionExBUsed,fFirstRunExBUsed);
416 if(fVersionVdriftUsed == 0) fStatusPos = fStatusPos |kVdriftErrorOld;
417 if(fVersionGainUsed == 0) fStatusPos = fStatusPos | kGainErrorOld;
422 //___________________________________________________________________________________________________________________
424 Bool_t AliTRDPreprocessorOffline::ReadStatusGlobal(const Char_t* fileName){
426 // read calibration entries from file
428 if(fSparse) return kTRUE;
429 TFile fcalib(fileName);
430 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
432 fSparse = (THnSparseI *) array->FindObject("NumberOfEntries");
433 if(!fSparse) return kFALSE;
441 //___________________________________________________________________________________________________________________
443 Bool_t AliTRDPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
445 // read calibration entries from file
447 if(fCH2d) return kTRUE;
448 TFile fcalib(fileName);
449 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
451 TH2I *ch2d = (TH2I *) array->FindObject("CH2d");
452 if(!ch2d) return kFALSE;
453 fCH2d = (TH2I*)ch2d->Clone();
454 //fNEvents = (TH1I *) array->FindObject("NEvents");
455 //fAbsoluteGain = (TH2F *) array->FindObject("AbsoluteGain");
457 TH2I *ch2d = (TH2I *) fcalib.Get("CH2d");
458 if(!ch2d) return kFALSE;
459 fCH2d = (TH2I*)ch2d->Clone();
460 //fNEvents = (TH1I *) fcalib.Get("NEvents");
461 //fAbsoluteGain = (TH2F *) fcalib.Get("AbsoluteGain");
463 fCH2d->SetDirectory(0);
464 //printf("title of CH2d %s\n",fCH2d->GetTitle());
469 //_________________________________________________________________________________________________________________
471 Bool_t AliTRDPreprocessorOffline::ReadVdriftT0Global(const Char_t* fileName){
473 // read calibration entries from file
475 if(fPH2d) return kTRUE;
476 TFile fcalib(fileName);
477 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
479 TProfile2D *ph2d = (TProfile2D *) array->FindObject("PH2d");
480 if(!ph2d) return kFALSE;
481 fPH2d = (TProfile2D*)ph2d->Clone();
482 //fNEvents = (TH1I *) array->FindObject("NEvents");
484 TProfile2D *ph2d = (TProfile2D *) fcalib.Get("PH2d");
485 if(!ph2d) return kFALSE;
486 fPH2d = (TProfile2D*)ph2d->Clone();
487 //fNEvents = (TH1I *) fcalib.Get("NEvents");
489 fPH2d->SetDirectory(0);
490 //printf("title of PH2d %s\n",fPH2d->GetTitle());
495 //___________________________________________________________________________________________________________________
497 Bool_t AliTRDPreprocessorOffline::ReadVdriftLinearFitGlobal(const Char_t* fileName){
499 // read calibration entries from file
501 if(fAliTRDCalibraVdriftLinearFit) return kTRUE;
502 TFile fcalib(fileName);
503 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
505 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) array->FindObject("AliTRDCalibraVdriftLinearFit");
506 //fNEvents = (TH1I *) array->FindObject("NEvents");
508 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) fcalib.Get("AliTRDCalibraVdriftLinearFit");
509 //fNEvents = (TH1I *) fcalib.Get("NEvents");
511 if(!fAliTRDCalibraVdriftLinearFit) {
512 //printf("No AliTRDCalibraVdriftLinearFit\n");
518 //_____________________________________________________________________________________________________________
519 Bool_t AliTRDPreprocessorOffline::ReadExbAltFitGlobal(const Char_t* fileName){
521 // read calibration entries from file
523 if(fAliTRDCalibraExbAltFit) return kTRUE;
524 TFile fcalib(fileName);
525 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
527 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) array->FindObject("AliTRDCalibraExbAltFit");
528 //fNEvents = (TH1I *) array->FindObject("NEvents");
530 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) fcalib.Get("AliTRDCalibraExbAltFit");
531 //fNEvents = (TH1I *) fcalib.Get("NEvents");
533 if(!fAliTRDCalibraExbAltFit) {
534 //printf("No AliTRDCalibraExbAltFit\n");
540 //_____________________________________________________________________________________________________________
542 Bool_t AliTRDPreprocessorOffline::ReadPRFGlobal(const Char_t* fileName){
544 // read calibration entries from file
546 if(fPRF2d) return kTRUE;
547 TFile fcalib(fileName);
548 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
550 TProfile2D *prf2d = (TProfile2D *) array->FindObject("PRF2d");
551 if(!prf2d) return kFALSE;
552 fPRF2d = (TProfile2D*)prf2d->Clone();
553 //fNEvents = (TH1I *) array->FindObject("NEvents");
555 TProfile2D *prf2d = (TProfile2D *) fcalib.Get("PRF2d");
556 if(!prf2d) return kFALSE;
557 fPRF2d = (TProfile2D*)prf2d->Clone();
558 //fNEvents = (TH1I *) fcalib.Get("NEvents");
560 fPRF2d->SetDirectory(0);
561 //printf("title of PRF2d %s\n",fPRF2d->GetTitle());
566 //__________________________________________________________________________________________________________
568 Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
570 // Analyze gain - produce the calibration objects
573 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
574 calibra->SetMinEntries(fMinStatsGain); // If there is less than 1000 entries in the histo: no fit
575 calibra->AnalyseCH(fCH2d);
577 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
578 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
579 Int_t nbfit = calibra->GetNumberFit();
580 Int_t nbE = calibra->GetNumberEnt();
584 Bool_t meanother = kFALSE;
587 (nbfit >= 0.5*nbE) && (nbE > 30)) {
588 // create the cal objects
589 if(!fBackCorrectGain) {
590 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
593 TObjArray object = calibra->GetVectorFit();
594 AliTRDCalDet *calDetGain = calibra->CreateDetObjectGain(&object,meanother);
595 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
596 // Put them in the array
597 fCalibObjects->AddAt(calDetGain,kGain);
598 fPlots->AddAt(coefGain,kGain);
603 fNotEnoughStatisticsForTheGain = kTRUE;
604 Int_t minStatsGain = fMinStatsGain*30;
605 calibra->SetMinEntries(minStatsGain); // Because we do it for all, we increase this
606 Double_t gainoverallnotnormalized = calibra->AnalyseCHAllTogether(fCH2d);
607 if(fCalDetGainUsed && (gainoverallnotnormalized > 0.0)) {
608 AliTRDCalDet *calDetGain = new AliTRDCalDet(*fCalDetGainUsed);
609 Double_t oldmean = fCalDetGainUsed->CalcMean(kFALSE);
610 //printf("oldmean %f\n",oldmean);
612 Double_t scalefactor = calibra->GetScaleFactorGain();
613 //printf("Correction factor %f\n",gainoverallnotnormalized*scalefactor);
614 calDetGain->Multiply(gainoverallnotnormalized*scalefactor/oldmean);
615 //printf("newmean %f\n",calDetGain->CalcMean(kFALSE));
616 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
617 fCalibObjects->AddAt(calDetGain,kGain);
618 fPlots->AddAt(coefGain,kGain);
621 fStatusNeg = fStatusNeg | kGainNotEnoughStatsButFill;
624 fStatusPos = fStatusPos | kGainErrorOld;
628 if(gainoverallnotnormalized <= 0.0) fStatusNeg = fStatusNeg | kGainNotEnoughStatsNotFill;
629 if(!fCalDetGainUsed) fStatusPos = fStatusPos | kGainErrorOld;
633 calibra->ResetVectorFit();
638 //_____________________________________________________________________________________________________
639 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftT0(){
641 // Analyze VdriftT0 - produce the calibration objects
644 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
645 calibra->SetMinEntries(fMinStatsVdriftT0PH); // If there is less than 1000 entries in the histo: no fit
646 calibra->AnalysePH(fPH2d);
648 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
649 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
650 Int_t nbfit = calibra->GetNumberFit();
651 Int_t nbfitSuccess = calibra->GetNumberFitSuccess();
652 Int_t nbE = calibra->GetNumberEnt();
654 //printf("nbtg %d, nbfit %d, nbE %d, nbfitSuccess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
658 (nbfit >= 0.5*nbE) && (nbE > 30) && (nbfitSuccess > 30)) {
659 //printf("Pass the cut for VdriftT0\n");
660 // create the cal objects
661 calibra->RemoveOutliers(1,kFALSE);
662 calibra->PutMeanValueOtherVectorFit(1,kFALSE);
663 calibra->RemoveOutliers2(kFALSE);
664 calibra->PutMeanValueOtherVectorFit2(1,kFALSE);
666 TObjArray object = calibra->GetVectorFit();
667 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object);
668 TH1F *coefVdriftPH = calDetVdrift->MakeHisto1DAsFunctionOfDet();
669 AliTRDCalPad *calPadVdrift = (AliTRDCalPad *)calibra->CreatePadObjectVdrift(&object,calDetVdrift);
670 TH1F *coefPadVdrift = calPadVdrift->MakeHisto1D();
671 object = calibra->GetVectorFit2();
672 AliTRDCalDet *calDetT0 = calibra->CreateDetObjectT0(&object);
673 TH1F *coefT0 = calDetT0->MakeHisto1DAsFunctionOfDet();
674 AliTRDCalPad *calPadT0 = (AliTRDCalPad *)calibra->CreatePadObjectT0(&object,calDetT0);
675 TH1F *coefPadT0 = calPadT0->MakeHisto1D();
676 // Put them in the array
677 fCalibObjects->AddAt(calDetT0,kT0PHDet);
678 fCalibObjects->AddAt(calDetVdrift,kVdriftPHDet);
679 fCalibObjects->AddAt(calPadT0,kT0PHPad);
680 fCalibObjects->AddAt(calPadVdrift,kVdriftPHPad);
681 fPlots->AddAt(coefVdriftPH,kVdriftPHDet);
682 fPlots->AddAt(coefT0,kT0PHDet);
683 fPlots->AddAt(coefPadVdrift,kVdriftPHPad);
684 fPlots->AddAt(coefPadT0,kT0PHPad);
689 //printf("Not enough stats timeoffset\n");
690 fStatusNeg = fStatusNeg | kTimeOffsetNotEnoughStatsNotFill;
692 calibra->ResetVectorFit();
697 //____________________________________________________________________________________________________________________
698 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftLinearFit(){
700 // Analyze vdrift linear fit - produce the calibration objects
703 //printf("Analyse linear fit\n");
706 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
707 calibra->SetCalDetVdriftExB(fCalDetVdriftUsed,fCalDetExBUsed);
708 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
709 //printf("Fill PE Array\n");
710 fAliTRDCalibraVdriftLinearFit->FillPEArray();
711 //printf("AliTRDCalibraFit\n");
712 calibra->AnalyseLinearFitters(fAliTRDCalibraVdriftLinearFit);
716 Int_t nbfit = calibra->GetNumberFit();
717 Int_t nbE = calibra->GetNumberEnt();
722 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
723 // create the cal objects
724 //calibra->RemoveOutliers(1,kTRUE);
725 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
726 //calibra->RemoveOutliers2(kTRUE);
727 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
729 TObjArray object = calibra->GetVectorFit();
730 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object,kTRUE);
731 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
732 object = calibra->GetVectorFit2();
733 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectLorentzAngle(&object);
734 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
735 //if(!calDetLorentz) printf("No lorentz created\n");
736 // Put them in the array
737 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
738 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
739 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
740 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
745 fNotEnoughStatisticsForTheVdriftLinear = kTRUE;
746 Int_t minNumberOfEntriesForAll = fMinStatsVdriftLinear*30;
747 calibra->SetMinEntries(minNumberOfEntriesForAll); // Because we do it for all, we increase this
748 Double_t vdriftoverall = -100.0;
749 Double_t exboverall = 100.0;
750 calibra->AnalyseLinearFittersAllTogether(fAliTRDCalibraVdriftLinearFit,vdriftoverall,exboverall);
751 //printf("Found mean vdrift %f and exb %f\n",vdriftoverall,exboverall);
752 if(fCalDetVdriftUsed && (vdriftoverall > 0.0) && (exboverall < 70.0)) {
753 AliTRDCalDet *calDetVdrift = new AliTRDCalDet(*fCalDetVdriftUsed);
754 AliTRDCalDet *calDetLorentz = new AliTRDCalDet(*fCalDetExBUsed);
755 Double_t oldmeanvdrift = fCalDetVdriftUsed->CalcMean(kFALSE);
756 Double_t oldmeanexb = fCalDetExBUsed->CalcMean(kFALSE);
757 //printf("oldmean %f\n",oldmean);
758 if((oldmeanvdrift > 0.0) && (oldmeanexb < 70.0)) {
759 //printf("Correction factor %f\n",vdriftoverall);
760 calDetVdrift->Multiply(vdriftoverall/oldmeanvdrift);
761 calDetLorentz->Multiply(exboverall/oldmeanexb);
762 //printf("newmean %f\n",calDetVdrift->CalcMean(kFALSE));
763 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
764 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
765 // Put them in the array
766 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
767 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
768 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
769 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
772 fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsButFill;
775 if(oldmeanvdrift) fStatusPos = fStatusPos | kVdriftErrorOld;
776 if(oldmeanexb) fStatusPos = fStatusPos | kExBErrorOld;
780 if((vdriftoverall <= 0.0) && (exboverall > 70.0)) fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsNotFill;
781 if(!fCalDetVdriftUsed) fStatusPos = fStatusPos | kVdriftErrorOld;
782 if(!fCalDetExBUsed) fStatusPos = fStatusPos | kExBErrorOld;
786 calibra->ResetVectorFit();
791 //________________________________________________________________________________________________________________
793 Bool_t AliTRDPreprocessorOffline::AnalyzeExbAltFit(){
795 // Analyze vdrift linear fit - produce the calibration objects
798 //printf("Analyse linear fit\n");
801 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
802 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
803 //printf("Fill PE Array\n");
804 fAliTRDCalibraExbAltFit->FillPEArray();
805 //printf("AliTRDCalibraFit\n");
806 calibra->AnalyseExbAltFit(fAliTRDCalibraExbAltFit);
810 Int_t nbfit = calibra->GetNumberFit();
811 Int_t nbE = calibra->GetNumberEnt();
816 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
817 // create the cal objects
818 //calibra->RemoveOutliers(1,kTRUE);
819 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
821 TObjArray object = calibra->GetVectorFit2();
822 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectExbAlt(&object);
823 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
824 //if(!calDetLorentz) printf("No lorentz created\n");
825 // Put them in the array
826 fCalibObjects->AddAt(calDetLorentz,kExbAlt);
827 fPlots->AddAt(coefLorentzAngle,kExbAlt);
832 calibra->ResetVectorFit();
837 //________________________________________________________________________________________________________________
839 Bool_t AliTRDPreprocessorOffline::AnalyzePRF(){
841 // Analyze PRF - produce the calibration objects
844 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
845 calibra->SetMinEntries(fMinStatsPRF); // If there is less than 1000 entries in the histo: no fit
846 calibra->AnalysePRFMarianFit(fPRF2d);
848 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
849 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
850 Int_t nbfit = calibra->GetNumberFit();
851 Int_t nbE = calibra->GetNumberEnt();
857 (nbfit >= 0.95*nbE) && (nbE > 30)) {
858 // create the cal objects
859 TObjArray object = calibra->GetVectorFit();
860 AliTRDCalPad *calPadPRF = (AliTRDCalPad*) calibra->CreatePadObjectPRF(&object);
861 TH1F *coefPRF = calPadPRF->MakeHisto1D();
862 // Put them in the array
863 fCalibObjects->AddAt(calPadPRF,kPRF);
864 fPlots->AddAt(coefPRF,kPRF);
869 calibra->ResetVectorFit();
875 //_____________________________________________________________________________
876 Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
879 // Produce AliTRDCalChamberStatus out of calibration results
882 // set up AliTRDCalibChamberStatus
883 AliTRDCalibChamberStatus *ChamberStatus = new AliTRDCalibChamberStatus();
884 ChamberStatus->SetSparseI(fSparse);
885 ChamberStatus->AnalyseHisto(fMinStatsChamberStatus);
886 // get AliTRDCalChamberStatus
887 AliTRDCalChamberStatus *CalChamberStatus = ChamberStatus->GetCalChamberStatus();
889 // get calibration objects
890 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
891 AliTRDCalDet *calDetVDrift = (AliTRDCalDet *) fCalibObjects->At(kVdriftLinear);
892 AliTRDCalDet *calDetExB = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
895 if((!calDetGain) || (!calDetVDrift) || (!fCH2d) || (!calDetExB) || (!CalChamberStatus)) return kFALSE;
898 Double_t gainmean = calDetGain->GetMean();
899 Double_t vdriftmean = calDetVDrift->GetMean();
900 Double_t exbmean = calDetExB->GetMean();
902 Double_t gainrms = calDetGain->GetRMSRobust();
903 Double_t vdriftrms = calDetVDrift->GetRMSRobust();
904 Double_t exbrms = calDetExB->GetRMSRobust();
906 //printf("Gain mean: %f, rms: %f\n",gainmean,gainrms);
907 //printf("Vdrift mean: %f, rms: %f\n",vdriftmean,vdriftrms);
908 //printf("ExB mean: %f, rms: %f\n",exbmean,exbrms);
911 if((TMath::Abs(gainrms) < 0.001) || (TMath::Abs(vdriftrms) < 0.001) || (TMath::Abs(exbrms) < 0.0000001)) return kFALSE;
913 // mask chambers with empty gain entries
915 for (Int_t idet = 0; idet < 540; idet++) {
918 TH1I *projch = (TH1I *) fCH2d->ProjectionX("projch",idet+1,idet+1,(Option_t *)"e");
919 Double_t entries = projch->GetEntries();
920 //printf("Number of entries %f for det %d\n",entries,idet);
923 Double_t gain = calDetGain->GetValue(idet);
926 Double_t vdrift = calDetVDrift->GetValue(idet);
929 Double_t exb = calDetExB->GetValue(idet);
932 if( (entries<50 && !CalChamberStatus->IsNoData(idet)) ||
933 TMath::Abs(gainmean-gain) > (fRMSBadCalibratedGain*gainrms) ||
934 TMath::Abs(vdriftmean-vdrift) > (fRMSBadCalibratedVdrift*vdriftrms) ||
935 TMath::Abs(exbmean-exb) > (fRMSBadCalibratedExB*exbrms) ) {
937 //printf(" chamber det %03d masked \n",idet);
938 //printf(" gainmean %f and gain %f, gainrms %f \n",gainmean,gain,gainrms);
939 //printf(" vdriftmean %f and vdrift %f, vdriftrms %f \n",vdriftmean,vdrift,vdriftrms);
940 //printf(" exbmean %f and exb %f, exbrms %f \n",exbmean,exb,exbrms);
942 CalChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kBadCalibrated);
951 for(Int_t sm=0; sm < 18; sm++) {
953 Int_t smbadcalib = 0;
954 for(Int_t det = 0; det < 30; det++){
955 Int_t detector = sm*30+det;
956 if(CalChamberStatus->IsNoData(detector)) smnodata++;
958 if(CalChamberStatus->IsBadCalibrated(detector)) smbadcalib++;
961 fNoData[sm] = smnodata;
962 fBadCalib[sm]= smbadcalib;
963 //printf("No Data %d, bad calibrated %d for %d\n",fNoData[sm],fBadCalib[sm],sm);
967 // for(Int_t sm=0; sm < 18; sm++) {
968 // Int_t counter = 0;
969 // for(Int_t det = 0; det < 30; det++){
970 // Int_t detector = sm*30+det;
971 // if(CalChamberStatus->IsBadCalibrated(detector)) counter++;
973 // if(counter >= 20) {
974 // for(Int_t det = 0; det < 30; det++){
975 // Int_t detector = sm*30+det;
976 // CalChamberStatus->SetStatus(detector,AliTRDCalChamberStatus::kGood);
981 fCalibObjects->AddAt(CalChamberStatus,kChamberStatus);
987 //________________________________________________________________________________________________
988 void AliTRDPreprocessorOffline::CorrectFromDetGainUsed() {
990 // Correct from the gas gain used afterwards
992 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
993 if(!calDetGain) return;
999 for(Int_t det = 0; det < 540; det++) {
1001 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1002 Float_t gainout = calDetGain->GetValue(det);
1005 if(TMath::Abs(gainout-1.0) > 0.000001) {
1006 mean += (gaininit*gainout);
1010 if(nbdet > 0) mean = mean/nbdet;
1012 for(Int_t det = 0; det < 540; det++) {
1014 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1015 Float_t gainout = calDetGain->GetValue(det);
1017 if(TMath::Abs(gainout-1.0) > 0.000001) {
1018 Double_t newgain = gaininit*gainout;
1019 if(newgain < 0.1) newgain = 0.1;
1020 if(newgain > 1.9) newgain = 1.9;
1021 calDetGain->SetValue(det,newgain);
1024 Double_t newgain = mean;
1025 if(newgain < 0.1) newgain = 0.1;
1026 if(newgain > 1.9) newgain = 1.9;
1027 calDetGain->SetValue(det,newgain);
1033 //________________________________________________________________________________________________
1034 void AliTRDPreprocessorOffline::CorrectFromDetVdriftUsed() {
1036 // Correct from the drift velocity
1039 //printf("Correct for vdrift\n");
1041 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1042 if(!calDetGain) return;
1044 Int_t detVdrift = kVdriftPHDet;
1045 if(fMethodSecond) detVdrift = kVdriftLinear;
1046 AliTRDCalDet *calDetVdrift = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1047 if(!calDetVdrift) return;
1050 if(!fNotEnoughStatisticsForTheVdriftLinear) {
1051 for(Int_t det = 0; det < 540; det++) {
1053 Float_t vdriftinit = fCalDetVdriftUsed->GetValue(det);
1054 Float_t vdriftout = calDetVdrift->GetValue(det);
1056 Float_t gain = calDetGain->GetValue(det);
1057 if(vdriftout > 0.0) gain = gain*vdriftinit/vdriftout;
1058 if(gain < 0.1) gain = 0.1;
1059 if(gain > 1.9) gain = 1.9;
1060 calDetGain->SetValue(det,gain);
1065 Float_t vdriftinit = fCalDetVdriftUsed->CalcMean(kFALSE);
1066 Float_t vdriftout = calDetVdrift->CalcMean(kFALSE);
1067 Float_t factorcorrectif = 1.0;
1068 if(vdriftout > 0.0) factorcorrectif = vdriftinit/vdriftout;
1069 for(Int_t det = 0; det < 540; det++) {
1070 Float_t gain = calDetGain->GetValue(det);
1071 gain = gain*factorcorrectif;
1072 if(gain < 0.1) gain = 0.1;
1073 if(gain > 1.9) gain = 1.9;
1074 calDetGain->SetValue(det,gain);
1080 //_________________________________________________________________________________________________________________
1081 void AliTRDPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1083 // Update OCDB entry
1086 AliCDBMetaData *metaData= new AliCDBMetaData();
1087 metaData->SetObjectClassName("AliTRDCalDet");
1088 metaData->SetResponsible("Raphaelle Bailhache");
1089 metaData->SetBeamPeriod(1);
1091 AliCDBId id1("TRD/Calib/ChamberGainFactor", startRunNumber, endRunNumber);
1092 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1093 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1094 if(calDet) gStorage->Put(calDet, id1, metaData);
1098 //___________________________________________________________________________________________________________________
1099 void AliTRDPreprocessorOffline::UpdateOCDBExB(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1101 // Update OCDB entry
1104 Int_t detExB = kLorentzLinear;
1105 if(!fMethodSecond) return;
1109 AliCDBMetaData *metaData= new AliCDBMetaData();
1110 metaData->SetObjectClassName("AliTRDCalDet");
1111 metaData->SetResponsible("Raphaelle Bailhache");
1112 metaData->SetBeamPeriod(1);
1114 AliCDBId id1("TRD/Calib/ChamberExB", startRunNumber, endRunNumber);
1115 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1116 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1117 if(calDet) gStorage->Put(calDet, id1, metaData);
1118 //if(!calDet) printf("No caldet\n");
1121 //___________________________________________________________________________________________________________________
1122 void AliTRDPreprocessorOffline::UpdateOCDBExBAlt(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1124 // Update OCDB entry
1127 Int_t detExB = kExbAlt;
1128 if(!fMethodSecond) return;
1132 AliCDBMetaData *metaData= new AliCDBMetaData();
1133 metaData->SetObjectClassName("AliTRDCalDet");
1134 metaData->SetResponsible("Raphaelle Bailhache");
1135 metaData->SetBeamPeriod(1);
1137 AliCDBId id1("TRD/Calib/ChamberExBAlt", startRunNumber, endRunNumber);
1138 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1139 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1140 if(calDet) gStorage->Put(calDet, id1, metaData);
1141 //if(!calDet) printf("No caldet\n");
1144 //___________________________________________________________________________________________________________________
1145 void AliTRDPreprocessorOffline::UpdateOCDBVdrift(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1147 // Update OCDB entry
1150 Int_t detVdrift = kVdriftPHDet;
1152 if(fMethodSecond) detVdrift = kVdriftLinear;
1154 AliCDBMetaData *metaData= new AliCDBMetaData();
1155 metaData->SetObjectClassName("AliTRDCalDet");
1156 metaData->SetResponsible("Raphaelle Bailhache");
1157 metaData->SetBeamPeriod(1);
1159 AliCDBId id1("TRD/Calib/ChamberVdrift", startRunNumber, endRunNumber);
1160 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1161 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1162 if(calDet) gStorage->Put(calDet, id1, metaData);
1166 if(!fMethodSecond) {
1168 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1169 metaDataPad->SetObjectClassName("AliTRDCalPad");
1170 metaDataPad->SetResponsible("Raphaelle Bailhache");
1171 metaDataPad->SetBeamPeriod(1);
1173 AliCDBId id1Pad("TRD/Calib/LocalVdrift", startRunNumber, endRunNumber);
1174 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1175 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
1180 //________________________________________________________________________________________________________________________
1181 void AliTRDPreprocessorOffline::UpdateOCDBT0(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1183 // Update OCDB entry
1186 AliCDBMetaData *metaData= new AliCDBMetaData();
1187 metaData->SetObjectClassName("AliTRDCalDet");
1188 metaData->SetResponsible("Raphaelle Bailhache");
1189 metaData->SetBeamPeriod(1);
1191 AliCDBId id1("TRD/Calib/ChamberT0", startRunNumber, endRunNumber);
1192 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1193 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1194 if(calDet) gStorage->Put(calDet, id1, metaData);
1198 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1199 metaDataPad->SetObjectClassName("AliTRDCalPad");
1200 metaDataPad->SetResponsible("Raphaelle Bailhache");
1201 metaDataPad->SetBeamPeriod(1);
1203 AliCDBId id1Pad("TRD/Calib/LocalT0", startRunNumber, endRunNumber);
1204 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1205 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
1210 //_________________________________________________________________________________________________________________
1211 void AliTRDPreprocessorOffline::UpdateOCDBPRF(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1213 // Update OCDB entry
1216 AliCDBMetaData *metaData= new AliCDBMetaData();
1217 metaData->SetObjectClassName("AliTRDCalPad");
1218 metaData->SetResponsible("Raphaelle Bailhache");
1219 metaData->SetBeamPeriod(1);
1221 AliCDBId id1("TRD/Calib/PRFWidth", startRunNumber, endRunNumber);
1222 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1223 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1224 if(calPad) gStorage->Put(calPad, id1, metaData);
1228 //_________________________________________________________________________________________________________________
1229 void AliTRDPreprocessorOffline::UpdateOCDBChamberStatus(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1231 // Update OCDB entry
1234 AliCDBMetaData *metaData= new AliCDBMetaData();
1235 metaData->SetObjectClassName("AliTRDCalChamberStatus");
1236 metaData->SetResponsible("Raphaelle Bailhache");
1237 metaData->SetBeamPeriod(1);
1239 AliCDBId id1("TRD/Calib/ChamberStatus", startRunNumber, endRunNumber);
1240 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1241 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1242 if(calChamberStatus) gStorage->Put(calChamberStatus, id1, metaData);
1246 //__________________________________________________________________________________________________________________________
1247 Bool_t AliTRDPreprocessorOffline::ValidateGain() {
1249 // Validate OCDB entry
1252 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1254 Double_t mean = calDet->GetMean();
1255 Double_t rms = calDet->GetRMSRobust();
1256 if((mean > 0.2) && (mean < 1.4) && (rms < 0.5)) return kTRUE;
1257 //if((mean > 0.2) && (mean < 1.4)) return kTRUE;
1259 fStatusPos = fStatusPos | kGainErrorRange;
1268 //__________________________________________________________________________________________________________________________
1269 Bool_t AliTRDPreprocessorOffline::ValidateVdrift(){
1271 // Update OCDB entry
1274 Int_t detVdrift = kVdriftPHDet;
1277 if(fMethodSecond) detVdrift = kVdriftLinear;
1279 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1281 Double_t mean = calDet->GetMean();
1282 Double_t rms = calDet->GetRMSRobust();
1283 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1284 if(!((mean > 1.0) && (mean < 2.0) && (rms < 0.5))) {
1285 fStatusPos = fStatusPos | kVdriftErrorRange;
1291 if(!fMethodSecond) {
1292 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1294 Double_t mean = calPad->GetMean();
1295 Double_t rms = calPad->GetRMS();
1296 //printf("Vdrift::meanpad %f, rmspad %f\n",mean,rms);
1297 if(!((mean > 0.9) && (mean < 1.1) && (rms < 0.6))) {
1298 fStatusPos = fStatusPos | kVdriftErrorRange;
1308 //__________________________________________________________________________________________________________________________
1309 Bool_t AliTRDPreprocessorOffline::ValidateExB(){
1311 // Update OCDB entry
1314 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
1316 Double_t mean = calDet->GetMean();
1317 Double_t rms = calDet->GetRMSRobust();
1318 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1319 if(!((mean > -1.0) && (mean < 1.0) && (rms < 0.5))) {
1320 fStatusNeg = fStatusNeg | kExBErrorRange;
1328 //__________________________________________________________________________________________________________________________
1329 Bool_t AliTRDPreprocessorOffline::ValidateT0(){
1331 // Update OCDB entry
1334 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1335 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1336 if(calDet && calPad) {
1337 Double_t meandet = calDet->GetMean();
1338 Double_t rmsdet = calDet->GetRMSRobust();
1339 Double_t meanpad = calPad->GetMean();
1340 //Double_t rmspad = calPad->GetRMS();
1341 //printf("T0::minimum %f, rmsdet %f,meanpad %f, rmspad %f\n",meandet,rmsdet,meanpad,rmspad);
1342 if((meandet > -1.5) && (meandet < 5.0) && (rmsdet < 4.0) && (meanpad < 5.0) && (meanpad > -0.5)) return kTRUE;
1344 fStatusPos = fStatusPos | kTimeOffsetErrorRange;
1351 //__________________________________________________________________________________________________________________________
1352 Bool_t AliTRDPreprocessorOffline::ValidatePRF() const{
1354 // Update OCDB entry
1357 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1359 Double_t meanpad = calPad->GetMean();
1360 Double_t rmspad = calPad->GetRMS();
1361 //printf("PRF::meanpad %f, rmspad %f\n",meanpad,rmspad);
1362 if((meanpad < 1.0) && (rmspad < 0.8)) return kTRUE;
1369 //__________________________________________________________________________________________________________________________
1370 Bool_t AliTRDPreprocessorOffline::ValidateChamberStatus(){
1372 // Update OCDB entry
1375 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1376 if(calChamberStatus) {
1378 Int_t detectornodata = 0;
1379 Int_t detectorbadcalib = 0;
1381 for(Int_t sm=0; sm < 18; sm++) {
1382 //printf("%d chambers w/o data in sm %d\n",fNoData[sm],sm);
1383 //printf("%d bad calibrated chambers in sm %d\n",fBadCalib[sm],sm);
1384 if(fNoData[sm] != 30) detectornodata += fNoData[sm];
1385 detectorbadcalib+=fBadCalib[sm];
1387 //printf("Number of chambers w/o data %d\n",detectornodata);
1388 //printf("Number of chambers bad calibrated %d\n",detectorbadcalib);
1390 if((detectornodata > fNoDataValidate) ||
1391 (detectorbadcalib > fBadCalibValidate)){
1392 fStatusPos = fStatusPos | kChamberStatusErrorRange;
1400 //_____________________________________________________________________________
1401 Int_t AliTRDPreprocessorOffline::GetVersion(TString name) const
1404 // Get version from the title
1408 const Char_t *version = "Ver";
1409 if(!strstr(name.Data(),version)) return -1;
1410 const Char_t *after = "Subver";
1411 if(!strstr(name.Data(),after)) return -1;
1413 for(Int_t ver = 0; ver < 999999999; ver++) {
1415 TString vertry(version);
1419 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1421 if(strstr(name.Data(),vertry.Data())) return ver;
1429 //_____________________________________________________________________________
1430 Int_t AliTRDPreprocessorOffline::GetSubVersion(TString name) const
1433 // Get subversion from the title
1437 const Char_t *subversion = "Subver";
1438 if(!strstr(name.Data(),subversion)) return -1;
1439 const Char_t *after = "FirstRun";
1440 if(!strstr(name.Data(),after)) {
1443 if(!strstr(name.Data(),after)) return -1;
1446 for(Int_t ver = 0; ver < 999999999; ver++) {
1448 TString vertry(subversion);
1452 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1454 if(strstr(name.Data(),vertry.Data())) return ver;
1462 //_____________________________________________________________________________
1463 Int_t AliTRDPreprocessorOffline::GetFirstRun(TString name) const
1466 // Get first run from the title
1470 const Char_t *firstrun = "FirstRun";
1471 if(!strstr(name.Data(),firstrun)) return -1;
1472 const Char_t *after = "Nz";
1473 if(!strstr(name.Data(),after)) return -1;
1476 for(Int_t ver = 0; ver < 999999999; ver++) {
1478 TString vertry(firstrun);
1482 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1484 if(strstr(name.Data(),vertry.Data())) return ver;
1491 //_____________________________________________________________________________
1492 Bool_t AliTRDPreprocessorOffline::CheckStatus(Int_t status, Int_t bitMask) const
1495 // Checks the status
1498 return (status & bitMask) ? kTRUE : kFALSE;
1501 //_____________________________________________________________________________
1502 Int_t AliTRDPreprocessorOffline::GetStatus() const
1505 // Checks the status
1506 // fStatusPos: errors
1507 // fStatusNeg: only info
1510 if(fStatusPos > 0) return fStatusPos;
1511 else return (-TMath::Abs(fStatusNeg));
1514 //_____________________________________________________________________________
1515 void AliTRDPreprocessorOffline::PrintStatus() const
1521 AliInfo(Form("The error status is %d",fStatusPos));
1522 AliInfo(Form("IsGainErrorOld? %d",(Int_t)IsGainErrorOld()));
1523 AliInfo(Form("IsVdriftErrorOld? %d",(Int_t)IsVdriftErrorOld()));
1524 AliInfo(Form("IsGainErrorRange? %d",(Int_t)IsGainErrorRange()));
1525 AliInfo(Form("IsVdriftErrorRange? %d",(Int_t)IsVdriftErrorRange()));
1526 AliInfo(Form("IsTimeOffsetErrorRange? %d",(Int_t)IsTimeOffsetErrorRange()));
1527 AliInfo(Form("IsChamberStatusErrorRange? %d",(Int_t)IsChamberStatusErrorRange()));
1530 AliInfo(Form("The info status is %d",fStatusNeg));
1531 AliInfo(Form("IsGainNotEnoughStatsButFill? %d",(Int_t)IsGainNotEnoughStatsButFill()));
1532 AliInfo(Form("IsVdriftNotEnoughStatsButFill? %d",(Int_t)IsVdriftNotEnoughStatsButFill()));
1533 AliInfo(Form("IsGainNotEnoughStatsNotFill? %d",(Int_t)IsGainNotEnoughStatsNotFill()));
1534 AliInfo(Form("IsVdriftNotEnoughStatsNotFill? %d",(Int_t)IsVdriftNotEnoughStatsNotFill()));
1535 AliInfo(Form("IsTimeOffsetNotEnoughStatsNotFill? %d",(Int_t)IsTimeOffsetNotEnoughStatsNotFill()));
1537 AliInfo(Form("IsExBErrorRange? %d",(Int_t)IsExBErrorRange()));
1538 AliInfo(Form("IsExBErrorOld? %d",(Int_t)IsExBErrorOld()));
1541 //___________________________________________________________________________________
1542 void AliTRDPreprocessorOffline::SetCalDetVdrift(AliTRDCalDet *calDetVdriftUsed)
1545 fCalDetVdriftUsed = calDetVdriftUsed;
1547 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1548 for(Int_t k = 0; k < 540; k++){
1549 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1550 //printf("Set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1554 //___________________________________________________________________________________
1555 Bool_t AliTRDPreprocessorOffline::SetCalDetGain(Int_t runNumber, Int_t version, Int_t subversion)
1558 // Set the fCalDetGainUsed
1561 if((version == 0) && (subversion == 0)) return kFALSE;
1563 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor",runNumber, version, subversion);
1565 AliError("Found no entry\n");
1566 fStatusPos = fStatusPos | kGainErrorOld;
1569 //const AliCDBId id = entry->GetId();
1570 //version = id.GetVersion();
1571 //subversion = id.GetSubVersion();
1572 //printf("Found version %d and subversion %d for vdrift\n",version,subversion);
1573 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1574 if(calDet) fCalDetGainUsed = calDet;
1576 fStatusPos = fStatusPos | kGainErrorOld;
1583 //___________________________________________________________________________________
1584 Bool_t AliTRDPreprocessorOffline::SetCalDetVdriftExB(Int_t runNumber, Int_t versionv, Int_t subversionv, Int_t versionexb, Int_t subversionexb)
1587 // Set the fCalDetVdriftUsed and fCalDetExBUsed
1590 if((versionv == 0) && (subversionv == 0)) return kFALSE;
1592 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberVdrift",runNumber, versionv, subversionv);
1594 AliError("Found no entry\n");
1595 fStatusPos = fStatusPos | kVdriftErrorOld;
1598 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1599 if(calDet) fCalDetVdriftUsed = calDet;
1601 fStatusPos = fStatusPos | kVdriftErrorOld;
1607 if((versionexb == 0) && (subversionexb == 0)) {
1609 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1610 for(Int_t k = 0; k < 540; k++){
1611 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1612 //printf("Nothing found: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1618 entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberExB",runNumber, versionexb, subversionexb);
1620 //printf("Found no entry\n");
1621 fStatusPos = fStatusPos | kExBErrorOld;
1624 AliTRDCalDet* calDetexb = (AliTRDCalDet *)entry->GetObject();
1626 fStatusPos = fStatusPos | kExBErrorOld;
1630 Double_t meanexb = calDetexb->GetMean();
1631 //printf("Mean value %f\n",meanexb);
1632 if((meanexb > 70) || (fNoExBUsedInReco)) {
1633 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1634 for(Int_t k = 0; k < 540; k++){
1635 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1636 //printf("Found but: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1640 fCalDetExBUsed = calDetexb;