1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
19 Responsible: Raphaelle Bailhache (rbailhache@ikf.uni-frankfurt.de)
20 Code to analyze the TRD calibration and to produce OCDB entries
24 gSystem->Load("libANALYSIS");
25 gSystem->Load("libTRDcalib");
27 AliTRDPreprocessorOffline proces;
28 TString ocdbPath="local:////"
29 ocdbPath+=gSystem->GetFromPipe("pwd");
31 proces.CalibTimeGain("CalibObjects.root",run0,run1,ocdbPath);
32 proces.CalibTimeVdrift("CalibObjects.root",run0,run1,ocdbPath);
33 // take the raw calibration data from the file CalibObjects.root
34 // and make a OCDB entry with run validity run0-run1
35 // results are stored at the ocdbPath - local or alien ...
36 // default storage ""- data stored at current working directory
40 #include "Riostream.h"
50 #include "THnSparse.h"
51 #include "TProfile2D.h"
52 #include "AliTRDCalDet.h"
53 #include "AliTRDCalPad.h"
54 #include "AliCDBMetaData.h"
56 #include "AliCDBManager.h"
57 #include "AliCDBStorage.h"
58 #include "AliTRDCalibraMode.h"
59 #include "AliTRDCalibraFit.h"
60 #include "AliTRDCalibraVdriftLinearFit.h"
61 #include "AliTRDCalibraExbAltFit.h"
62 #include "AliTRDPreprocessorOffline.h"
63 #include "AliTRDCalChamberStatus.h"
64 #include "AliTRDCalibChamberStatus.h"
65 #include "AliTRDCommonParam.h"
66 #include "AliCDBManager.h"
67 #include "AliCDBEntry.h"
68 #include "AliTRDdEdxBaseUtils.h"
69 #include "AliTRDdEdxCalibHistArray.h"
70 #include "AliTRDdEdxCalibUtils.h"
72 ClassImp(AliTRDPreprocessorOffline)
74 AliTRDPreprocessorOffline::AliTRDPreprocessorOffline():
75 TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
77 fNameList("TRDCalib"),
79 fCalDetVdriftUsed(0x0),
85 fAliTRDCalibraVdriftLinearFit(0x0),
86 fAliTRDCalibraExbAltFit(0x0),
89 fPlots(new TObjArray(kNumCalibObjs)),
90 fCalibObjects(new TObjArray(kNumCalibObjs)),
93 fSubVersionGainUsed(0),
94 fFirstRunVdriftUsed(0),
95 fVersionVdriftUsed(0),
96 fSubVersionVdriftUsed(0),
99 fSubVersionExBUsed(0),
100 fNoExBUsedInReco(kFALSE),
101 fSwitchOnValidation(kTRUE),
102 fVdriftValidated(kFALSE),
103 fExBValidated(kFALSE),
104 fT0Validated(kFALSE),
105 fMinStatsVdriftT0PH(800*20),
106 fMinStatsVdriftLinear(800),
109 fMinStatsChamberStatus(20),
110 fMinSingleStatsChamberStatus(0.05),
111 fBackCorrectGain(kFALSE),
112 fBackCorrectVdrift(kTRUE),
113 fNotEnoughStatisticsForTheGain(kFALSE),
114 fNotEnoughStatisticsForTheVdriftLinear(kFALSE),
117 fBadCalibValidate(40),
119 fRMSBadCalibratedGain(20.0),
120 fRMSBadCalibratedVdrift(20.0),
121 fRMSBadCalibratedExB(20.0),
122 fMinTimeOffsetValidate(-1.6),
123 fRobustFitDriftVelocity(kTRUE),
124 fRobustFitExbAlt(kFALSE),
125 fAlternativeVdrfitFit(kFALSE),
126 fAlternativeExbAltFit(kFALSE),
127 fMinNbOfPointVdriftFit(11),
129 fOutliersFitChargeLow(0.03),
130 fOutliersFitChargeHigh(0.7),
131 fBeginFitCharge(3.5),
138 // default constructor
141 memset(fBadCalib, 0, sizeof(Int_t) * 18);
142 memset(fNoData, 0, sizeof(Int_t) * 18);
144 //_________________________________________________________________________________________________________________
145 AliTRDPreprocessorOffline::~AliTRDPreprocessorOffline() {
150 if(fCalDetGainUsed) delete fCalDetGainUsed;
151 if(fCalDetVdriftUsed) delete fCalDetVdriftUsed;
152 if(fCalDetExBUsed) delete fCalDetExBUsed;
153 if(fCH2d) delete fCH2d;
154 if(fPH2d) delete fPH2d;
155 if(fPRF2d) delete fPRF2d;
156 if(fSparse) delete fSparse;
159 AliTRDdEdxCalibUtils::DeleteHistArray();
160 AliTRDdEdxCalibUtils::DeleteObjArray();
163 if(fAliTRDCalibraVdriftLinearFit) delete fAliTRDCalibraVdriftLinearFit;
164 if(fAliTRDCalibraExbAltFit) delete fAliTRDCalibraExbAltFit;
165 if(fNEvents) delete fNEvents;
166 if(fAbsoluteGain) delete fAbsoluteGain;
167 if(fPlots) delete fPlots;
168 if(fCalibObjects) delete fCalibObjects;
171 //___________________________________________________________________________________
172 void AliTRDPreprocessorOffline::Process(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage)
175 // Process to the gain, vdrift, timeoffset, exb and chamber status calibration
178 if(SetCalDetGain(startRunNumber,fVersionGainUsed,fSubVersionGainUsed) && SetCalDetVdriftExB(startRunNumber,fVersionVdriftUsed,fSubVersionVdriftUsed,fVersionExBUsed,fSubVersionExBUsed)) {
180 CalibVdriftT0(file,startRunNumber,endRunNumber,ocdbStorage);
181 CalibGain(file,startRunNumber,endRunNumber,ocdbStorage);
182 CalibChamberStatus(file,startRunNumber,endRunNumber,ocdbStorage);
183 CalibExbAlt(file,startRunNumber,endRunNumber,ocdbStorage);
188 printf("\n AliTRDPreprocessorOffline PHQ on!!\n\n");
189 AliTRDdEdxBaseUtils::PrintControl();
190 CalibPHQ(file, startRunNumber, endRunNumber, ocdbStorage);
193 printf("\n AliTRDPreprocessorOffline PHQ off!!\n\n");
199 //___________________________________________________________________________________________________________________
201 void AliTRDPreprocessorOffline::CalibVdriftT0(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
203 // make calibration of the drift velocity
205 // file - the location of input file
206 // startRunNumber, endRunNumber - run validity period
207 // ocdbStorage - OCDB storage
208 // - if empty - local storage 'pwd' uesed
209 if (ocdbStorage==0x0) {
210 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
211 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
216 fVdriftValidated = kTRUE;
217 fT0Validated = kTRUE;
218 fExBValidated = kTRUE;
219 fNotEnoughStatisticsForTheVdriftLinear = kFALSE;
221 // 2. extraction of the information
223 if(ReadVdriftLinearFitGlobal(file) && fCalDetVdriftUsed && fCalDetExBUsed) AnalyzeVdriftLinearFit();
224 if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
226 // 3. Append QA plots
228 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
231 // 4. validate OCDB entries
233 if(fSwitchOnValidation==kTRUE && ValidateVdrift()==kFALSE) {
234 //AliError("TRD vdrift OCDB parameters out of range!");
235 fVdriftValidated = kFALSE;
237 if(fSwitchOnValidation==kTRUE && ValidateT0()==kFALSE) {
238 //AliError("TRD t0 OCDB parameters out of range!");
239 fT0Validated = kFALSE;
241 if(fSwitchOnValidation==kTRUE && ValidateExB()==kFALSE) {
242 //AliError("TRD t0 OCDB parameters out of range!");
243 fExBValidated = kFALSE;
249 if(fVdriftValidated) UpdateOCDBVdrift(startRunNumber,endRunNumber,ocdbStorage);
250 if(fT0Validated) UpdateOCDBT0(startRunNumber,endRunNumber,ocdbStorage);
251 if(fExBValidated) UpdateOCDBExB(startRunNumber,endRunNumber,ocdbStorage);
254 //___________________________________________________________________________________________________________________
256 void AliTRDPreprocessorOffline::CalibExbAlt(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
258 // make calibration of the drift velocity
260 // file - the location of input file
261 // startRunNumber, endRunNumber - run validity period
262 // ocdbStorage - OCDB storage
263 // - if empty - local storage 'pwd' uesed
264 if (ocdbStorage==0x0) {
265 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
266 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
273 // 2. extraction of the information
275 if(ReadExbAltFitGlobal(file)) AnalyzeExbAltFit();
277 // 3. Append QA plots
279 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
282 // 4. validate OCDB entries
288 UpdateOCDBExBAlt(startRunNumber,endRunNumber,ocdbStorage);
292 //_________________________________________________________________________________________________________________
294 void AliTRDPreprocessorOffline::CalibGain(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
296 // make calibration of the drift velocity
298 // file - the location of input file
299 // startRunNumber, endRunNumber - run validity period
300 // ocdbStorage - OCDB storage
301 // - if empty - local storage 'pwd' uesed
302 if (ocdbStorage==0x0) {
303 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
304 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
307 fNotEnoughStatisticsForTheGain = kFALSE;
310 if(!ReadGainGlobal(file)) return;
313 // 2. extraction of the information
316 if(fBackCorrectGain) CorrectFromDetGainUsed();
317 //if(fBackCorrectVdrift) CorrectFromDetVdriftUsed();
319 // 3. Append QA plots
321 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
324 // 4. validate OCDB entries
326 if(fSwitchOnValidation==kTRUE && ValidateGain()==kFALSE) {
327 //AliError("TRD gain OCDB parameters out of range!");
334 if((!fCalDetVdriftUsed) || (fCalDetVdriftUsed && fVdriftValidated)) UpdateOCDBGain(startRunNumber,endRunNumber,ocdbStorage);
338 //________________________________________________________________________________________________________________
340 void AliTRDPreprocessorOffline::CalibPRF(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
342 // make calibration of the drift velocity
344 // file - the location of input file
345 // startRunNumber, endRunNumber - run validity period
346 // ocdbStorage - OCDB storage
347 // - if empty - local storage 'pwd' uesed
348 if (ocdbStorage==0x0) {
349 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
350 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
354 if(!ReadPRFGlobal(file)) return;
357 // 2. extraction of the information
361 // 3. Append QA plots
363 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
367 // 4. validate OCDB entries
369 if(fSwitchOnValidation==kTRUE && ValidatePRF()==kFALSE) {
370 //AliError("TRD prf OCDB parameters out of range!");
377 UpdateOCDBPRF(startRunNumber,endRunNumber,ocdbStorage);
380 //________________________________________________________________________________________________________________
381 void AliTRDPreprocessorOffline::CalibPHQ(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage)
384 // make calibration of puls height Q
386 // startRunNumber, endRunNumber - run validity period
387 // ocdbStorage - OCDB storage
388 // - if empty - local storage 'pwd' uesed
391 if (ocdbStorage==0x0) {
392 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
393 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
395 //printf("test %s\n", ocdbStorage.Data());
397 if(!ReadPHQGlobal(file)) return;
399 if(!AnalyzePHQ(startRunNumber)) return;
401 UpdateOCDBPHQ(startRunNumber,endRunNumber,ocdbStorage);
404 //________________________________________________________________________________________________________________
406 void AliTRDPreprocessorOffline::CalibChamberStatus(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
408 // make calibration of the chamber status
410 // startRunNumber, endRunNumber - run validity period
411 // ocdbStorage - OCDB storage
412 // - if empty - local storage 'pwd' uesed
413 if (ocdbStorage==0x0) {
414 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
415 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
420 if(!ReadStatusGlobal(file)) return;
424 // 2. extraction of the information
426 if(!AnalyzeChamberStatus()) return;
428 // 3. Append QA plots
430 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
434 // 4. validate OCDB entries
436 //printf("Enough stats for vdrift? %d\n",(Int_t)fNotEnoughStatisticsForTheVdriftLinear);
437 //printf("Enough stats for gain? %d\n",(Int_t)fNotEnoughStatisticsForTheGain);
438 if((!fNotEnoughStatisticsForTheVdriftLinear) && (!fNotEnoughStatisticsForTheGain)) {
439 if(fSwitchOnValidation==kTRUE && ValidateChamberStatus()==kFALSE) {
440 //AliError("TRD Chamber status OCDB parameters not ok!");
447 UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
451 //______________________________________________________________________________________________________
452 Bool_t AliTRDPreprocessorOffline::Init(const Char_t* fileName){
454 // read the calibration used during the reconstruction
457 if(ReadVdriftT0Global(fileName)) {
459 TString nameph = fPH2d->GetTitle();
460 fFirstRunVdriftUsed = GetFirstRun(nameph);
461 fVersionVdriftUsed = GetVersion(nameph);
462 fSubVersionVdriftUsed = GetSubVersion(nameph);
464 //printf("Found Version %d, Subversion %d for vdrift\n",fVersionVdriftUsed,fSubVersionVdriftUsed);
468 if(ReadGainGlobal(fileName)) {
470 TString namech = fCH2d->GetTitle();
471 fFirstRunGainUsed = GetFirstRun(namech);
472 fVersionGainUsed = GetVersion(namech);
473 fSubVersionGainUsed = GetSubVersion(namech);
475 //printf("Found Version %d, Subversion %d for gain\n",fVersionGainUsed,fSubVersionGainUsed);
479 if(ReadVdriftLinearFitGlobal(fileName)) {
481 TString namelinear = fAliTRDCalibraVdriftLinearFit->GetNameCalibUsed();
482 fFirstRunExBUsed = GetFirstRun(namelinear);
483 fVersionExBUsed = GetVersion(namelinear);
484 fSubVersionExBUsed = GetSubVersion(namelinear);
486 //printf("Found Version %d, Subversion %d, run %d for ExB\n",fVersionExBUsed,fSubVersionExBUsed,fFirstRunExBUsed);
490 if(fVersionVdriftUsed == 0) fStatusPos = fStatusPos |kVdriftErrorOld;
491 if(fVersionGainUsed == 0) fStatusPos = fStatusPos | kGainErrorOld;
496 //___________________________________________________________________________________________________________________
498 Bool_t AliTRDPreprocessorOffline::ReadStatusGlobal(const Char_t* fileName){
500 // read calibration entries from file
502 if(fSparse) return kTRUE;
503 TFile fcalib(fileName);
504 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
506 fSparse = (THnSparseI *) array->FindObject("NumberOfEntries");
507 if(!fSparse) return kFALSE;
515 //___________________________________________________________________________________________________________________
517 Bool_t AliTRDPreprocessorOffline::ReadPHQGlobal(const Char_t* fileName)
520 // read calibration entries from file
523 return AliTRDdEdxCalibUtils::ReadHistArray(fileName, fNameList);
526 //___________________________________________________________________________________________________________________
528 Bool_t AliTRDPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
530 // read calibration entries from file
532 if(fCH2d) return kTRUE;
533 TFile fcalib(fileName);
534 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
536 TH2I *ch2d = (TH2I *) array->FindObject("CH2d");
537 if(!ch2d) return kFALSE;
538 fCH2d = (TH2I*)ch2d->Clone();
539 //fNEvents = (TH1I *) array->FindObject("NEvents");
540 //fAbsoluteGain = (TH2F *) array->FindObject("AbsoluteGain");
542 TH2I *ch2d = (TH2I *) fcalib.Get("CH2d");
543 if(!ch2d) return kFALSE;
544 fCH2d = (TH2I*)ch2d->Clone();
545 //fNEvents = (TH1I *) fcalib.Get("NEvents");
546 //fAbsoluteGain = (TH2F *) fcalib.Get("AbsoluteGain");
548 fCH2d->SetDirectory(0);
549 //printf("title of CH2d %s\n",fCH2d->GetTitle());
554 //_________________________________________________________________________________________________________________
556 Bool_t AliTRDPreprocessorOffline::ReadVdriftT0Global(const Char_t* fileName){
558 // read calibration entries from file
560 if(fPH2d) return kTRUE;
561 TFile fcalib(fileName);
562 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
564 TProfile2D *ph2d = (TProfile2D *) array->FindObject("PH2d");
565 if(!ph2d) return kFALSE;
566 fPH2d = (TProfile2D*)ph2d->Clone();
567 //fNEvents = (TH1I *) array->FindObject("NEvents");
569 TProfile2D *ph2d = (TProfile2D *) fcalib.Get("PH2d");
570 if(!ph2d) return kFALSE;
571 fPH2d = (TProfile2D*)ph2d->Clone();
572 //fNEvents = (TH1I *) fcalib.Get("NEvents");
574 fPH2d->SetDirectory(0);
575 //printf("title of PH2d %s\n",fPH2d->GetTitle());
580 //___________________________________________________________________________________________________________________
582 Bool_t AliTRDPreprocessorOffline::ReadVdriftLinearFitGlobal(const Char_t* fileName){
584 // read calibration entries from file
586 if(fAliTRDCalibraVdriftLinearFit) return kTRUE;
587 TFile fcalib(fileName);
588 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
590 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) array->FindObject("AliTRDCalibraVdriftLinearFit");
591 //fNEvents = (TH1I *) array->FindObject("NEvents");
593 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) fcalib.Get("AliTRDCalibraVdriftLinearFit");
594 //fNEvents = (TH1I *) fcalib.Get("NEvents");
596 if(!fAliTRDCalibraVdriftLinearFit) {
597 //printf("No AliTRDCalibraVdriftLinearFit\n");
603 //_____________________________________________________________________________________________________________
604 Bool_t AliTRDPreprocessorOffline::ReadExbAltFitGlobal(const Char_t* fileName){
606 // read calibration entries from file
608 if(fAliTRDCalibraExbAltFit) return kTRUE;
609 TFile fcalib(fileName);
610 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
612 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) array->FindObject("AliTRDCalibraExbAltFit");
613 //fNEvents = (TH1I *) array->FindObject("NEvents");
615 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) fcalib.Get("AliTRDCalibraExbAltFit");
616 //fNEvents = (TH1I *) fcalib.Get("NEvents");
618 if(!fAliTRDCalibraExbAltFit) {
619 //printf("No AliTRDCalibraExbAltFit\n");
625 //_____________________________________________________________________________________________________________
627 Bool_t AliTRDPreprocessorOffline::ReadPRFGlobal(const Char_t* fileName){
629 // read calibration entries from file
631 if(fPRF2d) return kTRUE;
632 TFile fcalib(fileName);
633 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
635 TProfile2D *prf2d = (TProfile2D *) array->FindObject("PRF2d");
636 if(!prf2d) return kFALSE;
637 fPRF2d = (TProfile2D*)prf2d->Clone();
638 //fNEvents = (TH1I *) array->FindObject("NEvents");
640 TProfile2D *prf2d = (TProfile2D *) fcalib.Get("PRF2d");
641 if(!prf2d) return kFALSE;
642 fPRF2d = (TProfile2D*)prf2d->Clone();
643 //fNEvents = (TH1I *) fcalib.Get("NEvents");
645 fPRF2d->SetDirectory(0);
646 //printf("title of PRF2d %s\n",fPRF2d->GetTitle());
651 //__________________________________________________________________________________________________________
653 Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
655 // Analyze gain - produce the calibration objects
658 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
659 calibra->ChooseMethod(fMethodeGain);
660 calibra->SetBeginFitCharge(fBeginFitCharge);
661 calibra->SetFitOutliersChargeLow(fOutliersFitChargeLow);
662 calibra->SetFitOutliersChargeHigh(fOutliersFitChargeHigh);
663 calibra->SetMinEntries(fMinStatsGain); // If there is less than 1000 entries in the histo: no fit
664 calibra->AnalyseCH(fCH2d);
666 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
667 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
668 Int_t nbfit = calibra->GetNumberFit();
669 Int_t nbE = calibra->GetNumberEnt();
673 Bool_t meanother = kFALSE;
676 (nbfit >= 0.5*nbE) && (nbE > 30)) {
677 // create the cal objects
678 if(!fBackCorrectGain) {
679 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
682 TObjArray object = calibra->GetVectorFit();
683 AliTRDCalDet *calDetGain = calibra->CreateDetObjectGain(&object,meanother);
684 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
685 // Put them in the array
686 fCalibObjects->AddAt(calDetGain,kGain);
687 fPlots->AddAt(coefGain,kGain);
692 fNotEnoughStatisticsForTheGain = kTRUE;
693 Int_t minStatsGain = fMinStatsGain*30;
694 calibra->SetMinEntries(minStatsGain); // Because we do it for all, we increase this
695 Double_t gainoverallnotnormalized = calibra->AnalyseCHAllTogether(fCH2d);
696 if(fCalDetGainUsed && (gainoverallnotnormalized > 0.0)) {
697 AliTRDCalDet *calDetGain = new AliTRDCalDet(*fCalDetGainUsed);
698 Double_t oldmean = fCalDetGainUsed->CalcMean(kFALSE);
699 //printf("oldmean %f\n",oldmean);
701 Double_t scalefactor = calibra->GetScaleFactorGain();
702 //printf("Correction factor %f\n",gainoverallnotnormalized*scalefactor);
703 calDetGain->Multiply(gainoverallnotnormalized*scalefactor/oldmean);
704 //printf("newmean %f\n",calDetGain->CalcMean(kFALSE));
705 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
706 fCalibObjects->AddAt(calDetGain,kGain);
707 fPlots->AddAt(coefGain,kGain);
710 fStatusNeg = fStatusNeg | kGainNotEnoughStatsButFill;
713 fStatusPos = fStatusPos | kGainErrorOld;
717 if(gainoverallnotnormalized <= 0.0) fStatusNeg = fStatusNeg | kGainNotEnoughStatsNotFill;
718 if(!fCalDetGainUsed) fStatusPos = fStatusPos | kGainErrorOld;
722 calibra->ResetVectorFit();
727 //_____________________________________________________________________________________________________
728 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftT0(){
730 // Analyze VdriftT0 - produce the calibration objects
733 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
734 calibra->SetT0Shift0(fT0Shift0);
735 calibra->SetT0Shift1(fT0Shift1);
736 calibra->SetMinEntries(fMinStatsVdriftT0PH); // If there is less than 1000 entries in the histo: no fit
737 calibra->AnalysePH(fPH2d);
738 //calibra->SetDebugLevel(2);
740 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
741 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
742 Int_t nbfit = calibra->GetNumberFit();
743 Int_t nbfitSuccess = calibra->GetNumberFitSuccess();
744 Int_t nbE = calibra->GetNumberEnt();
746 //printf("nbtg %d, nbfit %d, nbE %d, nbfitSuccess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
750 (nbfit >= 0.5*nbE) && (nbE > 30) && (nbfitSuccess > 30)) {
751 //printf("nbtg %d, nbfit %d, nbE %d, nbfitSucess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
752 //printf("Pass the cut for VdriftT0\n");
753 // create the cal objects
754 calibra->RemoveOutliers(1,kFALSE);
755 calibra->PutMeanValueOtherVectorFit(1,kFALSE);
756 calibra->RemoveOutliers2(kFALSE);
757 calibra->PutMeanValueOtherVectorFit2(1,kFALSE);
759 TObjArray object = calibra->GetVectorFit();
760 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object);
761 TH1F *coefVdriftPH = calDetVdrift->MakeHisto1DAsFunctionOfDet();
762 AliTRDCalPad *calPadVdrift = (AliTRDCalPad *)calibra->CreatePadObjectVdrift(&object,calDetVdrift);
763 TH1F *coefPadVdrift = calPadVdrift->MakeHisto1D();
764 object = calibra->GetVectorFit2();
765 AliTRDCalDet *calDetT0 = calibra->CreateDetObjectT0(&object);
766 TH1F *coefT0 = calDetT0->MakeHisto1DAsFunctionOfDet();
767 AliTRDCalPad *calPadT0 = (AliTRDCalPad *)calibra->CreatePadObjectT0(&object,calDetT0);
768 TH1F *coefPadT0 = calPadT0->MakeHisto1D();
769 // Put them in the array
770 fCalibObjects->AddAt(calDetT0,kT0PHDet);
771 fCalibObjects->AddAt(calDetVdrift,kVdriftPHDet);
772 fCalibObjects->AddAt(calPadT0,kT0PHPad);
773 fCalibObjects->AddAt(calPadVdrift,kVdriftPHPad);
774 fPlots->AddAt(coefVdriftPH,kVdriftPHDet);
775 fPlots->AddAt(coefT0,kT0PHDet);
776 fPlots->AddAt(coefPadVdrift,kVdriftPHPad);
777 fPlots->AddAt(coefPadT0,kT0PHPad);
782 //printf("Not enough stats timeoffset\n");
783 fStatusNeg = fStatusNeg | kTimeOffsetNotEnoughStatsNotFill;
785 calibra->ResetVectorFit();
790 //____________________________________________________________________________________________________________________
791 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftLinearFit(){
793 // Analyze vdrift linear fit - produce the calibration objects
796 //printf("Analyse linear fit\n");
799 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
800 calibra->SetCalDetVdriftExB(fCalDetVdriftUsed,fCalDetExBUsed);
801 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
802 //printf("The mean stat is by %d for VdriftLinear\n",fMinStatsVdriftLinear);
803 //fAliTRDCalibraVdriftLinearFit->SetSeeDetector(0);
804 //fAliTRDCalibraVdriftLinearFit->SetDebugLevel(1);
805 //printf("Fill PE Array\n");
806 fAliTRDCalibraVdriftLinearFit->SetRobustFit(fRobustFitDriftVelocity);
807 fAliTRDCalibraVdriftLinearFit->SetMinNumberOfPointsForFit(fMinNbOfPointVdriftFit);
808 if(!fAlternativeVdrfitFit)
809 fAliTRDCalibraVdriftLinearFit->FillPEArray();
811 fAliTRDCalibraVdriftLinearFit->FillPEArray2();
812 //printf("AliTRDCalibraFit\n");
813 calibra->AnalyseLinearFitters(fAliTRDCalibraVdriftLinearFit);
817 Int_t nbfit = calibra->GetNumberFit();
818 Int_t nbE = calibra->GetNumberEnt();
823 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
824 // create the cal objects
825 //calibra->RemoveOutliers(1,kTRUE);
826 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
827 //calibra->RemoveOutliers2(kTRUE);
828 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
830 TObjArray object = calibra->GetVectorFit();
831 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object,kTRUE);
832 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
833 object = calibra->GetVectorFit2();
834 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectLorentzAngle(&object);
835 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
836 //if(!calDetLorentz) printf("No lorentz created\n");
837 // Put them in the array
838 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
839 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
840 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
841 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
846 fNotEnoughStatisticsForTheVdriftLinear = kTRUE;
847 Int_t minNumberOfEntriesForAll = fMinStatsVdriftLinear*30;
848 calibra->SetMinEntries(minNumberOfEntriesForAll); // Because we do it for all, we increase this
849 Double_t vdriftoverall = -100.0;
850 Double_t exboverall = 100.0;
851 calibra->AnalyseLinearFittersAllTogether(fAliTRDCalibraVdriftLinearFit,vdriftoverall,exboverall);
852 //printf("Found mean vdrift %f and exb %f\n",vdriftoverall,exboverall);
853 if(fCalDetVdriftUsed && (vdriftoverall > 0.0) && (exboverall < 70.0)) {
854 AliTRDCalDet *calDetVdrift = new AliTRDCalDet(*fCalDetVdriftUsed);
855 AliTRDCalDet *calDetLorentz = new AliTRDCalDet(*fCalDetExBUsed);
856 Double_t oldmeanvdrift = fCalDetVdriftUsed->CalcMean(kFALSE);
857 Double_t oldmeanexb = fCalDetExBUsed->CalcMean(kFALSE);
858 //printf("oldmean %f\n",oldmean);
859 if((oldmeanvdrift > 0.0) && (oldmeanexb < 70.0)) {
860 //printf("Correction factor %f\n",vdriftoverall);
861 calDetVdrift->Multiply(vdriftoverall/oldmeanvdrift);
862 if(TMath::Abs(oldmeanexb) > 0.0001) calDetLorentz->Multiply(exboverall/oldmeanexb);
863 //printf("newmean %f\n",calDetVdrift->CalcMean(kFALSE));
864 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
865 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
866 // Put them in the array
867 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
868 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
869 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
870 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
873 fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsButFill;
876 if(oldmeanvdrift) fStatusPos = fStatusPos | kVdriftErrorOld;
877 if(oldmeanexb) fStatusPos = fStatusPos | kExBErrorOld;
881 if((vdriftoverall <= 0.0) && (exboverall > 70.0)) fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsNotFill;
882 if(!fCalDetVdriftUsed) fStatusPos = fStatusPos | kVdriftErrorOld;
883 if(!fCalDetExBUsed) fStatusPos = fStatusPos | kExBErrorOld;
887 calibra->ResetVectorFit();
892 //________________________________________________________________________________________________________________
894 Bool_t AliTRDPreprocessorOffline::AnalyzeExbAltFit(){
896 // Analyze vdrift linear fit - produce the calibration objects
899 //printf("Analyse linear fit\n");
902 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
903 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
904 //printf("Fill PE Array\n");
905 fAliTRDCalibraExbAltFit->SetRobustFit(fRobustFitExbAlt);
906 if(!fAlternativeExbAltFit)
907 fAliTRDCalibraExbAltFit->FillPEArray();
909 fAliTRDCalibraExbAltFit->FillPEArray2();
910 //printf("AliTRDCalibraFit\n");
911 calibra->AnalyseExbAltFit(fAliTRDCalibraExbAltFit);
915 Int_t nbfit = calibra->GetNumberFit();
916 Int_t nbE = calibra->GetNumberEnt();
921 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
922 // create the cal objects
923 //calibra->RemoveOutliers(1,kTRUE);
924 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
926 TObjArray object = calibra->GetVectorFit2();
927 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectExbAlt(&object);
928 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
929 //if(!calDetLorentz) printf("No lorentz created\n");
930 // Put them in the array
931 fCalibObjects->AddAt(calDetLorentz,kExbAlt);
932 fPlots->AddAt(coefLorentzAngle,kExbAlt);
937 calibra->ResetVectorFit();
942 //________________________________________________________________________________________________________________
944 Bool_t AliTRDPreprocessorOffline::AnalyzePRF(){
946 // Analyze PRF - produce the calibration objects
949 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
950 calibra->SetMinEntries(fMinStatsPRF); // If there is less than 1000 entries in the histo: no fit
951 calibra->AnalysePRFMarianFit(fPRF2d);
953 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
954 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
955 Int_t nbfit = calibra->GetNumberFit();
956 Int_t nbE = calibra->GetNumberEnt();
962 (nbfit >= 0.95*nbE) && (nbE > 30)) {
963 // create the cal objects
964 TObjArray object = calibra->GetVectorFit();
965 AliTRDCalPad *calPadPRF = (AliTRDCalPad*) calibra->CreatePadObjectPRF(&object);
966 TH1F *coefPRF = calPadPRF->MakeHisto1D();
967 // Put them in the array
968 fCalibObjects->AddAt(calPadPRF,kPRF);
969 fPlots->AddAt(coefPRF,kPRF);
974 calibra->ResetVectorFit();
980 //_____________________________________________________________________________
981 Bool_t AliTRDPreprocessorOffline::AnalyzePHQ(Int_t startRunNumber)
984 //Produce PHQ calibration results
987 TTreeSRedirector *calibStream = 0x0;
992 calibStream = new TTreeSRedirector(Form("TRDCalibStream_%010d.root", startRunNumber));
995 for(Int_t iter=0; iter<AliTRDdEdxCalibUtils::GetHistArray()->GetSize(); iter++){
996 THnBase *hi = (THnBase*) AliTRDdEdxCalibUtils::GetHistAt(iter);
997 TObjArray *obji = AliTRDdEdxCalibUtils::HistToObj(hi, startRunNumber, lout, calibStream);
998 //printf("test analyze %s\n", obji->GetName());
999 AliTRDdEdxCalibUtils::GetObjArray()->AddAt(obji, iter);
1002 fCalibObjects->AddAt(AliTRDdEdxCalibUtils::GetObjArray(), kPHQ);
1005 TFile *fout=new TFile(Form("TRDCalibList_%010d.root", startRunNumber),"recreate");
1018 //_____________________________________________________________________________
1019 Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
1022 // Produce AliTRDCalChamberStatus out of calibration results
1025 // set up AliTRDCalibChamberStatus
1026 AliTRDCalibChamberStatus *chamberStatus = new AliTRDCalibChamberStatus();
1027 chamberStatus->SetSparseI(fSparse);
1028 chamberStatus->AnalyseHisto(fMinStatsChamberStatus, fMinSingleStatsChamberStatus);
1029 // get AliTRDCalChamberStatus
1030 AliTRDCalChamberStatus *calChamberStatus = chamberStatus->GetCalChamberStatus();
1032 // get calibration objects
1033 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1034 AliTRDCalDet *calDetVDrift = (AliTRDCalDet *) fCalibObjects->At(kVdriftLinear);
1035 AliTRDCalDet *calDetExB = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
1038 if((!calDetGain) || (!calDetVDrift) || (!fCH2d) || (!calDetExB) || (!calChamberStatus)) return kFALSE;
1041 Double_t gainmean = calDetGain->GetMean();
1042 Double_t vdriftmean = calDetVDrift->GetMean();
1043 Double_t exbmean = calDetExB->GetMean();
1045 Double_t gainrms = calDetGain->GetRMSRobust();
1046 Double_t vdriftrms = calDetVDrift->GetRMSRobust();
1047 Double_t exbrms = calDetExB->GetRMSRobust();
1049 //printf("Gain mean: %f, rms: %f\n",gainmean,gainrms);
1050 //printf("Vdrift mean: %f, rms: %f\n",vdriftmean,vdriftrms);
1051 //printf("ExB mean: %f, rms: %f\n",exbmean,exbrms);
1054 if((TMath::Abs(gainrms) < 0.001) || (TMath::Abs(vdriftrms) < 0.001) || (TMath::Abs(exbrms) < 0.0000001)) return kFALSE;
1056 // Take mean each SM
1057 Double_t *gainmeanSM = new Double_t[18];
1058 Double_t *vdriftmeanSM = new Double_t[18];
1059 Double_t *exbmeanSM = new Double_t[18];
1060 //Double_t *t0meanSM = new Double_t[18];
1061 for(Int_t sm=0; sm< 18; sm++) {
1062 gainmeanSM[sm] = calDetGain->GetMeanSM(kFALSE,sm);
1063 vdriftmeanSM[sm] = calDetVDrift->GetMeanSM(kFALSE,sm);
1064 exbmeanSM[sm] = calDetExB->GetMeanSM(kFALSE,sm);
1065 //t0meanSM[sm] = calDetGain->GetMeanSM(kFALSE);
1069 // mask chambers with empty gain entries
1070 //Int_t counter = 0;
1071 for (Int_t idet = 0; idet < 540; idet++) {
1074 TH1I *projch = (TH1I *) fCH2d->ProjectionX("projch",idet+1,idet+1,(Option_t *)"e");
1075 Double_t entries = projch->GetEntries();
1076 //printf("Number of entries %f for det %d\n",entries,idet);
1079 Int_t smnumber = (Int_t) idet/30;
1082 Double_t gain = calDetGain->GetValue(idet);
1085 Double_t vdrift = calDetVDrift->GetValue(idet);
1088 Double_t exb = calDetExB->GetValue(idet);
1091 if( (entries<50 && !calChamberStatus->IsNoData(idet)) ||
1092 TMath::Abs(gainmean-gain) > (fRMSBadCalibratedGain*gainrms) ||
1093 TMath::Abs(vdriftmean-vdrift) > (fRMSBadCalibratedVdrift*vdriftrms) ||
1094 TMath::Abs(exbmean-exb) > (fRMSBadCalibratedExB*exbrms) ) {
1096 //printf(" chamber det %03d masked \n",idet);
1097 //printf(" gainmean %f and gain %f, gainrms %f \n",gainmean,gain,gainrms);
1098 //printf(" vdriftmean %f and vdrift %f, vdriftrms %f \n",vdriftmean,vdrift,vdriftrms);
1099 //printf(" exbmean %f and exb %f, exbrms %f \n",exbmean,exb,exbrms);
1101 calChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kBadCalibrated);
1105 if(TMath::Abs(gainmeanSM[smnumber]-gain) < 0.000001 ||
1106 TMath::Abs(vdriftmeanSM[smnumber]-vdrift) < 0.000001 ||
1107 TMath::Abs(exbmeanSM[smnumber]-exb) < 0.000001) {
1109 //printf(" chamber det %03d notcalibrated sm %d \n",idet,smnumber);
1110 //printf(" gainmeanSM %f and gain %f\n",gainmeanSM[smnumber],gain);
1111 //printf(" vdriftmeanSM %f and vdrift %f \n",vdriftmeanSM[smnumber],vdrift);
1112 //printf(" exbmeanSM %f and exb %f \n",exbmeanSM[smnumber],exb);
1114 calChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kNotCalibrated);
1123 for(Int_t sm=0; sm < 18; sm++) {
1125 Int_t smbadcalib = 0;
1126 for(Int_t det = 0; det < 30; det++){
1127 Int_t detector = sm*30+det;
1128 if(calChamberStatus->IsNoData(detector)) smnodata++;
1130 if(calChamberStatus->IsBadCalibrated(detector)) smbadcalib++;
1133 fNoData[sm] = smnodata;
1134 fBadCalib[sm]= smbadcalib;
1135 //printf("No Data %d, bad calibrated %d for %d\n",fNoData[sm],fBadCalib[sm],sm);
1139 delete []gainmeanSM;
1140 delete []vdriftmeanSM;
1144 // for(Int_t sm=0; sm < 18; sm++) {
1145 // Int_t counter = 0;
1146 // for(Int_t det = 0; det < 30; det++){
1147 // Int_t detector = sm*30+det;
1148 // if(calChamberStatus->IsBadCalibrated(detector)) counter++;
1150 // if(counter >= 20) {
1151 // for(Int_t det = 0; det < 30; det++){
1152 // Int_t detector = sm*30+det;
1153 // calChamberStatus->SetStatus(detector,AliTRDCalChamberStatus::kGood);
1158 fCalibObjects->AddAt(calChamberStatus,kChamberStatus);
1164 //________________________________________________________________________________________________
1165 void AliTRDPreprocessorOffline::CorrectFromDetGainUsed() {
1167 // Correct from the gas gain used afterwards
1169 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1170 if(!calDetGain) return;
1173 Double_t mean = 0.0;
1176 for(Int_t det = 0; det < 540; det++) {
1178 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1179 Float_t gainout = calDetGain->GetValue(det);
1182 if(TMath::Abs(gainout-1.0) > 0.000001) {
1183 mean += (gaininit*gainout);
1187 if(nbdet > 0) mean = mean/nbdet;
1189 for(Int_t det = 0; det < 540; det++) {
1191 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1192 Float_t gainout = calDetGain->GetValue(det);
1194 if(TMath::Abs(gainout-1.0) > 0.000001) {
1195 Double_t newgain = gaininit*gainout;
1196 if(newgain < 0.1) newgain = 0.1;
1197 if(newgain > 1.9) newgain = 1.9;
1198 calDetGain->SetValue(det,newgain);
1201 Double_t newgain = mean;
1202 if(newgain < 0.1) newgain = 0.1;
1203 if(newgain > 1.9) newgain = 1.9;
1204 calDetGain->SetValue(det,newgain);
1210 //________________________________________________________________________________________________
1211 void AliTRDPreprocessorOffline::CorrectFromDetVdriftUsed() {
1213 // Correct from the drift velocity
1216 //printf("Correct for vdrift\n");
1218 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1219 if(!calDetGain) return;
1221 Int_t detVdrift = kVdriftPHDet;
1222 if(fMethodSecond) detVdrift = kVdriftLinear;
1223 AliTRDCalDet *calDetVdrift = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1224 if(!calDetVdrift) return;
1227 if(!fNotEnoughStatisticsForTheVdriftLinear) {
1228 for(Int_t det = 0; det < 540; det++) {
1230 Float_t vdriftinit = fCalDetVdriftUsed->GetValue(det);
1231 Float_t vdriftout = calDetVdrift->GetValue(det);
1233 Float_t gain = calDetGain->GetValue(det);
1234 if(vdriftout > 0.0) gain = gain*vdriftinit/vdriftout;
1235 if(gain < 0.1) gain = 0.1;
1236 if(gain > 1.9) gain = 1.9;
1237 calDetGain->SetValue(det,gain);
1242 Float_t vdriftinit = fCalDetVdriftUsed->CalcMean(kFALSE);
1243 Float_t vdriftout = calDetVdrift->CalcMean(kFALSE);
1244 Float_t factorcorrectif = 1.0;
1245 if(vdriftout > 0.0) factorcorrectif = vdriftinit/vdriftout;
1246 for(Int_t det = 0; det < 540; det++) {
1247 Float_t gain = calDetGain->GetValue(det);
1248 gain = gain*factorcorrectif;
1249 if(gain < 0.1) gain = 0.1;
1250 if(gain > 1.9) gain = 1.9;
1251 calDetGain->SetValue(det,gain);
1257 //_________________________________________________________________________________________________________________
1258 void AliTRDPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage *storage){
1260 // Update OCDB entry
1263 AliCDBMetaData *metaData= new AliCDBMetaData();
1264 metaData->SetObjectClassName("AliTRDCalDet");
1265 metaData->SetResponsible("Raphaelle Bailhache");
1266 metaData->AddDateToComment();
1267 metaData->SetBeamPeriod(1);
1269 AliCDBId id1("TRD/Calib/ChamberGainFactor", startRunNumber, endRunNumber);
1270 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1271 if(calDet) storage->Put(calDet, id1, metaData);
1275 //___________________________________________________________________________________________________________________
1276 void AliTRDPreprocessorOffline::UpdateOCDBExB(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage *storage){
1278 // Update OCDB entry
1281 Int_t detExB = kLorentzLinear;
1282 if(!fMethodSecond) return;
1286 AliCDBMetaData *metaData= new AliCDBMetaData();
1287 metaData->SetObjectClassName("AliTRDCalDet");
1288 metaData->SetResponsible("Raphaelle Bailhache");
1289 metaData->AddDateToComment();
1290 metaData->SetBeamPeriod(1);
1292 AliCDBId id1("TRD/Calib/ChamberExB", startRunNumber, endRunNumber);
1293 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1294 if(calDet) storage->Put(calDet, id1, metaData);
1295 //if(!calDet) printf("No caldet\n");
1298 //___________________________________________________________________________________________________________________
1299 void AliTRDPreprocessorOffline::UpdateOCDBExBAlt(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage *storage){
1301 // Update OCDB entry
1304 Int_t detExB = kExbAlt;
1305 if(!fMethodSecond) return;
1309 AliCDBMetaData *metaData= new AliCDBMetaData();
1310 metaData->SetObjectClassName("AliTRDCalDet");
1311 metaData->SetResponsible("Theo Rascanu");
1312 metaData->AddDateToComment();
1313 metaData->SetBeamPeriod(1);
1315 AliCDBId id1("TRD/Calib/ChamberExBAlt", startRunNumber, endRunNumber);
1316 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1317 if(calDet) storage->Put(calDet, id1, metaData);
1318 //if(!calDet) printf("No caldet\n");
1321 //___________________________________________________________________________________________________________________
1322 void AliTRDPreprocessorOffline::UpdateOCDBVdrift(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage){
1324 // Update OCDB entry
1327 Int_t detVdrift = kVdriftPHDet;
1329 if(fMethodSecond) detVdrift = kVdriftLinear;
1331 AliCDBMetaData *metaData= new AliCDBMetaData();
1332 metaData->SetObjectClassName("AliTRDCalDet");
1333 metaData->SetResponsible("Raphaelle Bailhache");
1334 metaData->AddDateToComment();
1335 metaData->SetBeamPeriod(1);
1337 AliCDBId id1("TRD/Calib/ChamberVdrift", startRunNumber, endRunNumber);
1338 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1339 if(calDet) storage->Put(calDet, id1, metaData);
1343 if(!fMethodSecond) {
1345 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1346 metaDataPad->SetObjectClassName("AliTRDCalPad");
1347 metaDataPad->SetResponsible("Raphaelle Bailhache");
1348 metaDataPad->AddDateToComment();
1349 metaDataPad->SetBeamPeriod(1);
1351 AliCDBId id1Pad("TRD/Calib/LocalVdrift", startRunNumber, endRunNumber);
1352 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1353 if(calPad) storage->Put(calPad, id1Pad, metaDataPad);
1358 //________________________________________________________________________________________________________________________
1359 void AliTRDPreprocessorOffline::UpdateOCDBT0(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage){
1361 // Update OCDB entry
1364 AliCDBMetaData *metaData= new AliCDBMetaData();
1365 metaData->SetObjectClassName("AliTRDCalDet");
1366 metaData->SetResponsible("Raphaelle Bailhache");
1367 metaData->AddDateToComment();
1368 metaData->SetBeamPeriod(1);
1370 AliCDBId id1("TRD/Calib/ChamberT0", startRunNumber, endRunNumber);
1371 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1372 if(calDet) storage->Put(calDet, id1, metaData);
1376 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1377 metaDataPad->SetObjectClassName("AliTRDCalPad");
1378 metaDataPad->SetResponsible("Raphaelle Bailhache");
1379 metaDataPad->AddDateToComment();
1380 metaDataPad->SetBeamPeriod(1);
1382 AliCDBId id1Pad("TRD/Calib/LocalT0", startRunNumber, endRunNumber);
1383 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1384 if(calPad) storage->Put(calPad, id1Pad, metaDataPad);
1389 //_________________________________________________________________________________________________________________
1390 void AliTRDPreprocessorOffline::UpdateOCDBPRF(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage){
1392 // Update OCDB entry
1395 AliCDBMetaData *metaData= new AliCDBMetaData();
1396 metaData->SetObjectClassName("AliTRDCalPad");
1397 metaData->SetResponsible("Raphaelle Bailhache");
1398 metaData->AddDateToComment();
1399 metaData->SetBeamPeriod(1);
1402 AliCDBId id1("TRD/Calib/PRFWidth", startRunNumber, endRunNumber);
1403 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1404 if(calPad) storage->Put(calPad, id1, metaData);
1408 //_________________________________________________________________________________________________________________
1409 void AliTRDPreprocessorOffline::UpdateOCDBPHQ(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage)
1412 // Update OCDB entry
1414 AliCDBMetaData *metaData= new AliCDBMetaData();
1415 metaData->SetObjectClassName("TObjArray");
1416 metaData->SetResponsible("Raphaelle Bailhache and Xianguo Lu");
1417 metaData->AddDateToComment();
1418 metaData->SetBeamPeriod(1);
1420 AliCDBId id1("TRD/Calib/PHQ", startRunNumber, endRunNumber);
1421 TObjArray *cobj = (TObjArray *) fCalibObjects->At(kPHQ);
1424 storage->Put(cobj, id1, metaData);
1428 //_________________________________________________________________________________________________________________
1429 void AliTRDPreprocessorOffline::UpdateOCDBChamberStatus(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage){
1431 // Update OCDB entry
1434 AliCDBMetaData *metaData= new AliCDBMetaData();
1435 metaData->SetObjectClassName("AliTRDCalChamberStatus");
1436 metaData->SetResponsible("Raphaelle Bailhache and Julian Book");
1437 metaData->AddDateToComment();
1438 metaData->SetBeamPeriod(1);
1440 AliCDBId id1("TRD/Calib/ChamberStatus", startRunNumber, endRunNumber);
1441 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1442 if(calChamberStatus) storage->Put(calChamberStatus, id1, metaData);
1446 //__________________________________________________________________________________________________________________________
1447 Bool_t AliTRDPreprocessorOffline::ValidateGain() {
1449 // Validate OCDB entry
1452 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1454 Double_t mean = calDet->GetMean();
1455 Double_t rms = calDet->GetRMSRobust();
1456 if((mean > 0.2) && (mean < 1.4) && (rms < 0.5)) return kTRUE;
1457 //if((mean > 0.2) && (mean < 1.4)) return kTRUE;
1459 fStatusPos = fStatusPos | kGainErrorRange;
1468 //__________________________________________________________________________________________________________________________
1469 Bool_t AliTRDPreprocessorOffline::ValidateVdrift(){
1471 // Update OCDB entry
1474 Int_t detVdrift = kVdriftPHDet;
1477 if(fMethodSecond) detVdrift = kVdriftLinear;
1479 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1481 Double_t mean = calDet->GetMean();
1482 Double_t rms = calDet->GetRMSRobust();
1483 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1484 if(!((mean > 1.0) && (mean < 2.0) && (rms < 0.5))) {
1485 fStatusPos = fStatusPos | kVdriftErrorRange;
1491 if(!fMethodSecond) {
1492 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1494 Double_t mean = calPad->GetMean();
1495 Double_t rms = calPad->GetRMS();
1496 //printf("Vdrift::meanpad %f, rmspad %f\n",mean,rms);
1497 if(!((mean > 0.9) && (mean < 1.1) && (rms < 0.6))) {
1498 fStatusPos = fStatusPos | kVdriftErrorRange;
1508 //__________________________________________________________________________________________________________________________
1509 Bool_t AliTRDPreprocessorOffline::ValidateExB(){
1511 // Update OCDB entry
1514 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
1516 Double_t mean = calDet->GetMean();
1517 Double_t rms = calDet->GetRMSRobust();
1518 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1519 if(!((mean > -1.0) && (mean < 1.0) && (rms < 0.5))) {
1520 fStatusNeg = fStatusNeg | kExBErrorRange;
1528 //__________________________________________________________________________________________________________________________
1529 Bool_t AliTRDPreprocessorOffline::ValidateT0(){
1531 // Update OCDB entry
1534 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1535 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1536 if(calDet && calPad) {
1537 Double_t meandet = calDet->GetMean();
1538 Double_t rmsdet = calDet->GetRMSRobust();
1539 Double_t meanpad = calPad->GetMean();
1540 //Double_t rmspad = calPad->GetRMS();
1541 printf("T0::meandet %f, rmsdet %f,meanpad %f\n",meandet,rmsdet,meanpad);
1542 if((meandet > fMinTimeOffsetValidate) && (meandet < 5.0) && (rmsdet < 4.0) && (meanpad < 5.0) && (meanpad > -0.5)) return kTRUE;
1544 fStatusPos = fStatusPos | kTimeOffsetErrorRange;
1551 //__________________________________________________________________________________________________________________________
1552 Bool_t AliTRDPreprocessorOffline::ValidatePRF() const{
1554 // Update OCDB entry
1557 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1559 Double_t meanpad = calPad->GetMean();
1560 Double_t rmspad = calPad->GetRMS();
1561 //printf("PRF::meanpad %f, rmspad %f\n",meanpad,rmspad);
1562 if((meanpad < 1.0) && (rmspad < 0.8)) return kTRUE;
1569 //__________________________________________________________________________________________________________________________
1570 Bool_t AliTRDPreprocessorOffline::ValidateChamberStatus(){
1572 // Update OCDB entry
1575 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1576 if(calChamberStatus) {
1578 Int_t detectornodata = 0;
1579 Int_t detectorbadcalib = 0;
1581 for(Int_t sm=0; sm < 18; sm++) {
1582 //printf("%d chambers w/o data in sm %d\n",fNoData[sm],sm);
1583 //printf("%d bad calibrated chambers in sm %d\n",fBadCalib[sm],sm);
1584 if(fNoData[sm] != 30) detectornodata += fNoData[sm];
1585 detectorbadcalib+=fBadCalib[sm];
1587 //printf("Number of chambers w/o data %d\n",detectornodata);
1588 //printf("Number of chambers bad calibrated %d\n",detectorbadcalib);
1590 if((detectornodata > fNoDataValidate) ||
1591 (detectorbadcalib > fBadCalibValidate)){
1592 fStatusPos = fStatusPos | kChamberStatusErrorRange;
1600 //_____________________________________________________________________________
1601 Int_t AliTRDPreprocessorOffline::GetVersion(TString name) const
1604 // Get version from the title
1608 const Char_t *version = "Ver";
1609 if(!strstr(name.Data(),version)) return -1;
1610 const Char_t *after = "Subver";
1611 if(!strstr(name.Data(),after)) return -1;
1613 for(Int_t ver = 0; ver < 999999999; ver++) {
1615 TString vertry(version);
1619 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1621 if(strstr(name.Data(),vertry.Data())) return ver;
1629 //_____________________________________________________________________________
1630 Int_t AliTRDPreprocessorOffline::GetSubVersion(TString name) const
1633 // Get subversion from the title
1637 const Char_t *subversion = "Subver";
1638 if(!strstr(name.Data(),subversion)) return -1;
1639 const Char_t *after = "FirstRun";
1640 if(!strstr(name.Data(),after)) {
1643 if(!strstr(name.Data(),after)) return -1;
1646 for(Int_t ver = 0; ver < 999999999; ver++) {
1648 TString vertry(subversion);
1652 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1654 if(strstr(name.Data(),vertry.Data())) return ver;
1662 //_____________________________________________________________________________
1663 Int_t AliTRDPreprocessorOffline::GetFirstRun(TString name) const
1666 // Get first run from the title
1670 const Char_t *firstrun = "FirstRun";
1671 if(!strstr(name.Data(),firstrun)) return -1;
1672 const Char_t *after = "Nz";
1673 if(!strstr(name.Data(),after)) return -1;
1676 for(Int_t ver = 0; ver < 999999999; ver++) {
1678 TString vertry(firstrun);
1682 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1684 if(strstr(name.Data(),vertry.Data())) return ver;
1691 //_____________________________________________________________________________
1692 Bool_t AliTRDPreprocessorOffline::CheckStatus(Int_t status, Int_t bitMask) const
1695 // Checks the status
1698 return (status & bitMask) ? kTRUE : kFALSE;
1701 //_____________________________________________________________________________
1702 Int_t AliTRDPreprocessorOffline::GetStatus() const
1705 // Checks the status
1706 // fStatusPos: errors
1707 // fStatusNeg: only info
1710 if(fStatusPos > 0) return fStatusPos;
1711 else return (-TMath::Abs(fStatusNeg));
1714 //_____________________________________________________________________________
1715 void AliTRDPreprocessorOffline::PrintStatus() const
1721 AliInfo(Form("The error status is %d",fStatusPos));
1722 AliInfo(Form("IsGainErrorOld? %d",(Int_t)IsGainErrorOld()));
1723 AliInfo(Form("IsVdriftErrorOld? %d",(Int_t)IsVdriftErrorOld()));
1724 AliInfo(Form("IsGainErrorRange? %d",(Int_t)IsGainErrorRange()));
1725 AliInfo(Form("IsVdriftErrorRange? %d",(Int_t)IsVdriftErrorRange()));
1726 AliInfo(Form("IsTimeOffsetErrorRange? %d",(Int_t)IsTimeOffsetErrorRange()));
1727 AliInfo(Form("IsChamberStatusErrorRange? %d",(Int_t)IsChamberStatusErrorRange()));
1730 AliInfo(Form("The info status is %d",fStatusNeg));
1731 AliInfo(Form("IsGainNotEnoughStatsButFill? %d",(Int_t)IsGainNotEnoughStatsButFill()));
1732 AliInfo(Form("IsVdriftNotEnoughStatsButFill? %d",(Int_t)IsVdriftNotEnoughStatsButFill()));
1733 AliInfo(Form("IsGainNotEnoughStatsNotFill? %d",(Int_t)IsGainNotEnoughStatsNotFill()));
1734 AliInfo(Form("IsVdriftNotEnoughStatsNotFill? %d",(Int_t)IsVdriftNotEnoughStatsNotFill()));
1735 AliInfo(Form("IsTimeOffsetNotEnoughStatsNotFill? %d",(Int_t)IsTimeOffsetNotEnoughStatsNotFill()));
1737 AliInfo(Form("IsExBErrorRange? %d",(Int_t)IsExBErrorRange()));
1738 AliInfo(Form("IsExBErrorOld? %d",(Int_t)IsExBErrorOld()));
1741 //___________________________________________________________________________________
1742 void AliTRDPreprocessorOffline::SetCalDetVdrift(AliTRDCalDet *calDetVdriftUsed)
1745 fCalDetVdriftUsed = calDetVdriftUsed;
1747 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1748 for(Int_t k = 0; k < 540; k++){
1749 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1750 //printf("Set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1754 //___________________________________________________________________________________
1755 Bool_t AliTRDPreprocessorOffline::SetCalDetGain(Int_t runNumber, Int_t version, Int_t subversion)
1758 // Set the fCalDetGainUsed
1761 if((version == 0) && (subversion == 0)) return kFALSE;
1763 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor",runNumber, version, subversion);
1765 AliError("Found no entry\n");
1766 fStatusPos = fStatusPos | kGainErrorOld;
1769 //const AliCDBId id = entry->GetId();
1770 //version = id.GetVersion();
1771 //subversion = id.GetSubVersion();
1772 //printf("Found version %d and subversion %d for vdrift\n",version,subversion);
1773 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1774 if(calDet) fCalDetGainUsed = calDet;
1776 fStatusPos = fStatusPos | kGainErrorOld;
1783 //___________________________________________________________________________________
1784 Bool_t AliTRDPreprocessorOffline::SetCalDetVdriftExB(Int_t runNumber, Int_t versionv, Int_t subversionv, Int_t versionexb, Int_t subversionexb)
1787 // Set the fCalDetVdriftUsed and fCalDetExBUsed
1790 if((versionv == 0) && (subversionv == 0)) return kFALSE;
1792 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberVdrift",runNumber, versionv, subversionv);
1794 AliError("Found no entry\n");
1795 fStatusPos = fStatusPos | kVdriftErrorOld;
1798 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1799 if(calDet) fCalDetVdriftUsed = calDet;
1801 fStatusPos = fStatusPos | kVdriftErrorOld;
1807 if((versionexb == 0) && (subversionexb == 0)) {
1809 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1810 for(Int_t k = 0; k < 540; k++){
1811 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1812 //printf("Nothing found: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1818 entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberExB",runNumber, versionexb, subversionexb);
1820 //printf("Found no entry\n");
1821 fStatusPos = fStatusPos | kExBErrorOld;
1824 AliTRDCalDet* calDetexb = (AliTRDCalDet *)entry->GetObject();
1826 fStatusPos = fStatusPos | kExBErrorOld;
1830 Double_t meanexb = calDetexb->GetMean();
1831 //printf("Mean value %f\n",meanexb);
1832 if((meanexb > 70) || (fNoExBUsedInReco)) {
1833 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1834 for(Int_t k = 0; k < 540; k++){
1835 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1836 //printf("Found but: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1840 fCalDetExBUsed = calDetexb;