1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
19 Responsible: Raphaelle Bailhache (rbailhache@ikf.uni-frankfurt.de)
20 Code to analyze the TRD calibration and to produce OCDB entries
24 gSystem->Load("libANALYSIS");
25 gSystem->Load("libTRDcalib");
27 AliTRDPreprocessorOffline proces;
28 TString ocdbPath="local:////"
29 ocdbPath+=gSystem->GetFromPipe("pwd");
31 proces.CalibTimeGain("CalibObjects.root",run0,run1,ocdbPath);
32 proces.CalibTimeVdrift("CalibObjects.root",run0,run1,ocdbPath);
33 // take the raw calibration data from the file CalibObjects.root
34 // and make a OCDB entry with run validity run0-run1
35 // results are stored at the ocdbPath - local or alien ...
36 // default storage ""- data stored at current working directory
40 #include "Riostream.h"
50 #include "THnSparse.h"
51 #include "TProfile2D.h"
52 #include "AliTRDCalDet.h"
53 #include "AliTRDCalPad.h"
54 #include "AliCDBMetaData.h"
56 #include "AliCDBManager.h"
57 #include "AliCDBStorage.h"
58 #include "AliTRDCalibraMode.h"
59 #include "AliTRDCalibraFit.h"
60 #include "AliTRDCalibraVdriftLinearFit.h"
61 #include "AliTRDCalibraExbAltFit.h"
62 #include "AliTRDPreprocessorOffline.h"
63 #include "AliTRDCalChamberStatus.h"
64 #include "AliTRDCalibChamberStatus.h"
65 #include "AliTRDCommonParam.h"
66 #include "AliCDBManager.h"
67 #include "AliCDBEntry.h"
68 #include "AliTRDdEdxBaseUtils.h"
69 #include "AliTRDdEdxCalibHistArray.h"
70 #include "AliTRDdEdxCalibUtils.h"
72 ClassImp(AliTRDPreprocessorOffline)
74 AliTRDPreprocessorOffline::AliTRDPreprocessorOffline():
75 TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
77 fNameList("TRDCalib"),
79 fCalDetVdriftUsed(0x0),
85 fAliTRDCalibraVdriftLinearFit(0x0),
86 fAliTRDCalibraExbAltFit(0x0),
89 fPlots(new TObjArray(kNumCalibObjs)),
90 fCalibObjects(new TObjArray(kNumCalibObjs)),
93 fSubVersionGainUsed(0),
94 fFirstRunVdriftUsed(0),
95 fVersionVdriftUsed(0),
96 fSubVersionVdriftUsed(0),
99 fSubVersionExBUsed(0),
100 fNoExBUsedInReco(kFALSE),
101 fSwitchOnValidation(kTRUE),
102 fVdriftValidated(kFALSE),
103 fExBValidated(kFALSE),
104 fT0Validated(kFALSE),
105 fMinStatsVdriftT0PH(800*20),
106 fMinStatsVdriftLinear(800),
109 fMinStatsChamberStatus(20),
110 fMinSingleStatsChamberStatus(0.05),
111 fBackCorrectGain(kFALSE),
112 fBackCorrectVdrift(kTRUE),
113 fNotEnoughStatisticsForTheGain(kFALSE),
114 fNotEnoughStatisticsForTheVdriftLinear(kFALSE),
117 fBadCalibValidate(40),
119 fRMSBadCalibratedGain(20.0),
120 fRMSBadCalibratedVdrift(20.0),
121 fRMSBadCalibratedExB(20.0),
122 fRobustFitDriftVelocity(kTRUE),
123 fRobustFitExbAlt(kFALSE),
124 fAlternativeVdrfitFit(kFALSE),
125 fAlternativeExbAltFit(kFALSE),
126 fMinNbOfPointVdriftFit(11),
128 fOutliersFitChargeLow(0.03),
129 fOutliersFitChargeHigh(0.7),
130 fBeginFitCharge(3.5),
134 // default constructor
137 memset(fBadCalib, 0, sizeof(Int_t) * 18);
138 memset(fNoData, 0, sizeof(Int_t) * 18);
140 //_________________________________________________________________________________________________________________
141 AliTRDPreprocessorOffline::~AliTRDPreprocessorOffline() {
146 if(fCalDetGainUsed) delete fCalDetGainUsed;
147 if(fCalDetVdriftUsed) delete fCalDetVdriftUsed;
148 if(fCalDetExBUsed) delete fCalDetExBUsed;
149 if(fCH2d) delete fCH2d;
150 if(fPH2d) delete fPH2d;
151 if(fPRF2d) delete fPRF2d;
152 if(fSparse) delete fSparse;
155 AliTRDdEdxCalibUtils::DeleteHistArray();
156 AliTRDdEdxCalibUtils::DeleteObjArray();
159 if(fAliTRDCalibraVdriftLinearFit) delete fAliTRDCalibraVdriftLinearFit;
160 if(fAliTRDCalibraExbAltFit) delete fAliTRDCalibraExbAltFit;
161 if(fNEvents) delete fNEvents;
162 if(fAbsoluteGain) delete fAbsoluteGain;
163 if(fPlots) delete fPlots;
164 if(fCalibObjects) delete fCalibObjects;
167 //___________________________________________________________________________________
168 void AliTRDPreprocessorOffline::Process(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage)
171 // Process to the gain, vdrift, timeoffset, exb and chamber status calibration
174 if(SetCalDetGain(startRunNumber,fVersionGainUsed,fSubVersionGainUsed) && SetCalDetVdriftExB(startRunNumber,fVersionVdriftUsed,fSubVersionVdriftUsed,fVersionExBUsed,fSubVersionExBUsed)) {
176 CalibVdriftT0(file,startRunNumber,endRunNumber,ocdbStorage);
177 CalibGain(file,startRunNumber,endRunNumber,ocdbStorage);
178 CalibChamberStatus(file,startRunNumber,endRunNumber,ocdbStorage);
179 CalibExbAlt(file,startRunNumber,endRunNumber,ocdbStorage);
184 printf("\n AliTRDPreprocessorOffline PHQ on!!\n\n");
185 AliTRDdEdxBaseUtils::PrintControl();
186 CalibPHQ(file, startRunNumber, endRunNumber, ocdbStorage);
189 printf("\n AliTRDPreprocessorOffline PHQ off!!\n\n");
195 //___________________________________________________________________________________________________________________
197 void AliTRDPreprocessorOffline::CalibVdriftT0(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
199 // make calibration of the drift velocity
201 // file - the location of input file
202 // startRunNumber, endRunNumber - run validity period
203 // ocdbStorage - path to the OCDB storage
204 // - if empty - local storage 'pwd' uesed
205 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
209 fVdriftValidated = kTRUE;
210 fT0Validated = kTRUE;
211 fExBValidated = kTRUE;
212 fNotEnoughStatisticsForTheVdriftLinear = kFALSE;
214 // 2. extraction of the information
216 if(ReadVdriftLinearFitGlobal(file) && fCalDetVdriftUsed && fCalDetExBUsed) AnalyzeVdriftLinearFit();
217 if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
219 // 3. Append QA plots
221 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
224 // 4. validate OCDB entries
226 if(fSwitchOnValidation==kTRUE && ValidateVdrift()==kFALSE) {
227 //AliError("TRD vdrift OCDB parameters out of range!");
228 fVdriftValidated = kFALSE;
230 if(fSwitchOnValidation==kTRUE && ValidateT0()==kFALSE) {
231 //AliError("TRD t0 OCDB parameters out of range!");
232 fT0Validated = kFALSE;
234 if(fSwitchOnValidation==kTRUE && ValidateExB()==kFALSE) {
235 //AliError("TRD t0 OCDB parameters out of range!");
236 fExBValidated = kFALSE;
242 if(fVdriftValidated) UpdateOCDBVdrift(startRunNumber,endRunNumber,ocdbStorage);
243 if(fT0Validated) UpdateOCDBT0(startRunNumber,endRunNumber,ocdbStorage);
244 if(fExBValidated) UpdateOCDBExB(startRunNumber,endRunNumber,ocdbStorage);
247 //___________________________________________________________________________________________________________________
249 void AliTRDPreprocessorOffline::CalibExbAlt(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
251 // make calibration of the drift velocity
253 // file - the location of input file
254 // startRunNumber, endRunNumber - run validity period
255 // ocdbStorage - path to the OCDB storage
256 // - if empty - local storage 'pwd' uesed
257 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
263 // 2. extraction of the information
265 if(ReadExbAltFitGlobal(file)) AnalyzeExbAltFit();
267 // 3. Append QA plots
269 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
272 // 4. validate OCDB entries
278 UpdateOCDBExBAlt(startRunNumber,endRunNumber,ocdbStorage);
282 //_________________________________________________________________________________________________________________
284 void AliTRDPreprocessorOffline::CalibGain(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
286 // make calibration of the drift velocity
288 // file - the location of input file
289 // startRunNumber, endRunNumber - run validity period
290 // ocdbStorage - path to the OCDB storage
291 // - if empty - local storage 'pwd' uesed
292 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
294 fNotEnoughStatisticsForTheGain = kFALSE;
297 if(!ReadGainGlobal(file)) return;
300 // 2. extraction of the information
303 if(fBackCorrectGain) CorrectFromDetGainUsed();
304 //if(fBackCorrectVdrift) CorrectFromDetVdriftUsed();
306 // 3. Append QA plots
308 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
311 // 4. validate OCDB entries
313 if(fSwitchOnValidation==kTRUE && ValidateGain()==kFALSE) {
314 //AliError("TRD gain OCDB parameters out of range!");
321 if((!fCalDetVdriftUsed) || (fCalDetVdriftUsed && fVdriftValidated)) UpdateOCDBGain(startRunNumber,endRunNumber,ocdbStorage);
325 //________________________________________________________________________________________________________________
327 void AliTRDPreprocessorOffline::CalibPRF(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
329 // make calibration of the drift velocity
331 // file - the location of input file
332 // startRunNumber, endRunNumber - run validity period
333 // ocdbStorage - path to the OCDB storage
334 // - if empty - local storage 'pwd' uesed
335 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
338 if(!ReadPRFGlobal(file)) return;
341 // 2. extraction of the information
345 // 3. Append QA plots
347 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
351 // 4. validate OCDB entries
353 if(fSwitchOnValidation==kTRUE && ValidatePRF()==kFALSE) {
354 //AliError("TRD prf OCDB parameters out of range!");
361 UpdateOCDBPRF(startRunNumber,endRunNumber,ocdbStorage);
364 //________________________________________________________________________________________________________________
365 void AliTRDPreprocessorOffline::CalibPHQ(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage)
368 // make calibration of puls height Q
370 // startRunNumber, endRunNumber - run validity period
371 // ocdbStorage - path to the OCDB storage
372 // - if empty - local storage 'pwd' uesed
375 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
376 //printf("test %s\n", ocdbStorage.Data());
378 if(!ReadPHQGlobal(file)) return;
380 if(!AnalyzePHQ(startRunNumber)) return;
382 UpdateOCDBPHQ(startRunNumber,endRunNumber,ocdbStorage);
385 //________________________________________________________________________________________________________________
387 void AliTRDPreprocessorOffline::CalibChamberStatus(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
389 // make calibration of the chamber status
391 // startRunNumber, endRunNumber - run validity period
392 // ocdbStorage - path to the OCDB storage
393 // - if empty - local storage 'pwd' uesed
394 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
398 if(!ReadStatusGlobal(file)) return;
402 // 2. extraction of the information
404 if(!AnalyzeChamberStatus()) return;
406 // 3. Append QA plots
408 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
412 // 4. validate OCDB entries
414 if(fSwitchOnValidation==kTRUE && ValidateChamberStatus()==kFALSE) {
415 //AliError("TRD Chamber status OCDB parameters not ok!");
422 if((!fNotEnoughStatisticsForTheVdriftLinear) && (!fNotEnoughStatisticsForTheGain)) UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
423 //UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
426 //______________________________________________________________________________________________________
427 Bool_t AliTRDPreprocessorOffline::Init(const Char_t* fileName){
429 // read the calibration used during the reconstruction
432 if(ReadVdriftT0Global(fileName)) {
434 TString nameph = fPH2d->GetTitle();
435 fFirstRunVdriftUsed = GetFirstRun(nameph);
436 fVersionVdriftUsed = GetVersion(nameph);
437 fSubVersionVdriftUsed = GetSubVersion(nameph);
439 //printf("Found Version %d, Subversion %d for vdrift\n",fVersionVdriftUsed,fSubVersionVdriftUsed);
443 if(ReadGainGlobal(fileName)) {
445 TString namech = fCH2d->GetTitle();
446 fFirstRunGainUsed = GetFirstRun(namech);
447 fVersionGainUsed = GetVersion(namech);
448 fSubVersionGainUsed = GetSubVersion(namech);
450 //printf("Found Version %d, Subversion %d for gain\n",fVersionGainUsed,fSubVersionGainUsed);
454 if(ReadVdriftLinearFitGlobal(fileName)) {
456 TString namelinear = fAliTRDCalibraVdriftLinearFit->GetNameCalibUsed();
457 fFirstRunExBUsed = GetFirstRun(namelinear);
458 fVersionExBUsed = GetVersion(namelinear);
459 fSubVersionExBUsed = GetSubVersion(namelinear);
461 //printf("Found Version %d, Subversion %d, run %d for ExB\n",fVersionExBUsed,fSubVersionExBUsed,fFirstRunExBUsed);
465 if(fVersionVdriftUsed == 0) fStatusPos = fStatusPos |kVdriftErrorOld;
466 if(fVersionGainUsed == 0) fStatusPos = fStatusPos | kGainErrorOld;
471 //___________________________________________________________________________________________________________________
473 Bool_t AliTRDPreprocessorOffline::ReadStatusGlobal(const Char_t* fileName){
475 // read calibration entries from file
477 if(fSparse) return kTRUE;
478 TFile fcalib(fileName);
479 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
481 fSparse = (THnSparseI *) array->FindObject("NumberOfEntries");
482 if(!fSparse) return kFALSE;
490 //___________________________________________________________________________________________________________________
492 Bool_t AliTRDPreprocessorOffline::ReadPHQGlobal(const Char_t* fileName)
495 // read calibration entries from file
498 return AliTRDdEdxCalibUtils::ReadHistArray(fileName, fNameList);
501 //___________________________________________________________________________________________________________________
503 Bool_t AliTRDPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
505 // read calibration entries from file
507 if(fCH2d) return kTRUE;
508 TFile fcalib(fileName);
509 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
511 TH2I *ch2d = (TH2I *) array->FindObject("CH2d");
512 if(!ch2d) return kFALSE;
513 fCH2d = (TH2I*)ch2d->Clone();
514 //fNEvents = (TH1I *) array->FindObject("NEvents");
515 //fAbsoluteGain = (TH2F *) array->FindObject("AbsoluteGain");
517 TH2I *ch2d = (TH2I *) fcalib.Get("CH2d");
518 if(!ch2d) return kFALSE;
519 fCH2d = (TH2I*)ch2d->Clone();
520 //fNEvents = (TH1I *) fcalib.Get("NEvents");
521 //fAbsoluteGain = (TH2F *) fcalib.Get("AbsoluteGain");
523 fCH2d->SetDirectory(0);
524 //printf("title of CH2d %s\n",fCH2d->GetTitle());
529 //_________________________________________________________________________________________________________________
531 Bool_t AliTRDPreprocessorOffline::ReadVdriftT0Global(const Char_t* fileName){
533 // read calibration entries from file
535 if(fPH2d) return kTRUE;
536 TFile fcalib(fileName);
537 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
539 TProfile2D *ph2d = (TProfile2D *) array->FindObject("PH2d");
540 if(!ph2d) return kFALSE;
541 fPH2d = (TProfile2D*)ph2d->Clone();
542 //fNEvents = (TH1I *) array->FindObject("NEvents");
544 TProfile2D *ph2d = (TProfile2D *) fcalib.Get("PH2d");
545 if(!ph2d) return kFALSE;
546 fPH2d = (TProfile2D*)ph2d->Clone();
547 //fNEvents = (TH1I *) fcalib.Get("NEvents");
549 fPH2d->SetDirectory(0);
550 //printf("title of PH2d %s\n",fPH2d->GetTitle());
555 //___________________________________________________________________________________________________________________
557 Bool_t AliTRDPreprocessorOffline::ReadVdriftLinearFitGlobal(const Char_t* fileName){
559 // read calibration entries from file
561 if(fAliTRDCalibraVdriftLinearFit) return kTRUE;
562 TFile fcalib(fileName);
563 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
565 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) array->FindObject("AliTRDCalibraVdriftLinearFit");
566 //fNEvents = (TH1I *) array->FindObject("NEvents");
568 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) fcalib.Get("AliTRDCalibraVdriftLinearFit");
569 //fNEvents = (TH1I *) fcalib.Get("NEvents");
571 if(!fAliTRDCalibraVdriftLinearFit) {
572 //printf("No AliTRDCalibraVdriftLinearFit\n");
578 //_____________________________________________________________________________________________________________
579 Bool_t AliTRDPreprocessorOffline::ReadExbAltFitGlobal(const Char_t* fileName){
581 // read calibration entries from file
583 if(fAliTRDCalibraExbAltFit) return kTRUE;
584 TFile fcalib(fileName);
585 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
587 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) array->FindObject("AliTRDCalibraExbAltFit");
588 //fNEvents = (TH1I *) array->FindObject("NEvents");
590 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) fcalib.Get("AliTRDCalibraExbAltFit");
591 //fNEvents = (TH1I *) fcalib.Get("NEvents");
593 if(!fAliTRDCalibraExbAltFit) {
594 //printf("No AliTRDCalibraExbAltFit\n");
600 //_____________________________________________________________________________________________________________
602 Bool_t AliTRDPreprocessorOffline::ReadPRFGlobal(const Char_t* fileName){
604 // read calibration entries from file
606 if(fPRF2d) return kTRUE;
607 TFile fcalib(fileName);
608 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
610 TProfile2D *prf2d = (TProfile2D *) array->FindObject("PRF2d");
611 if(!prf2d) return kFALSE;
612 fPRF2d = (TProfile2D*)prf2d->Clone();
613 //fNEvents = (TH1I *) array->FindObject("NEvents");
615 TProfile2D *prf2d = (TProfile2D *) fcalib.Get("PRF2d");
616 if(!prf2d) return kFALSE;
617 fPRF2d = (TProfile2D*)prf2d->Clone();
618 //fNEvents = (TH1I *) fcalib.Get("NEvents");
620 fPRF2d->SetDirectory(0);
621 //printf("title of PRF2d %s\n",fPRF2d->GetTitle());
626 //__________________________________________________________________________________________________________
628 Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
630 // Analyze gain - produce the calibration objects
633 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
634 calibra->ChooseMethod(fMethodeGain);
635 calibra->SetBeginFitCharge(fBeginFitCharge);
636 calibra->SetFitOutliersChargeLow(fOutliersFitChargeLow);
637 calibra->SetFitOutliersChargeHigh(fOutliersFitChargeHigh);
638 calibra->SetMinEntries(fMinStatsGain); // If there is less than 1000 entries in the histo: no fit
639 calibra->AnalyseCH(fCH2d);
641 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
642 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
643 Int_t nbfit = calibra->GetNumberFit();
644 Int_t nbE = calibra->GetNumberEnt();
648 Bool_t meanother = kFALSE;
651 (nbfit >= 0.5*nbE) && (nbE > 30)) {
652 // create the cal objects
653 if(!fBackCorrectGain) {
654 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
657 TObjArray object = calibra->GetVectorFit();
658 AliTRDCalDet *calDetGain = calibra->CreateDetObjectGain(&object,meanother);
659 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
660 // Put them in the array
661 fCalibObjects->AddAt(calDetGain,kGain);
662 fPlots->AddAt(coefGain,kGain);
667 fNotEnoughStatisticsForTheGain = kTRUE;
668 Int_t minStatsGain = fMinStatsGain*30;
669 calibra->SetMinEntries(minStatsGain); // Because we do it for all, we increase this
670 Double_t gainoverallnotnormalized = calibra->AnalyseCHAllTogether(fCH2d);
671 if(fCalDetGainUsed && (gainoverallnotnormalized > 0.0)) {
672 AliTRDCalDet *calDetGain = new AliTRDCalDet(*fCalDetGainUsed);
673 Double_t oldmean = fCalDetGainUsed->CalcMean(kFALSE);
674 //printf("oldmean %f\n",oldmean);
676 Double_t scalefactor = calibra->GetScaleFactorGain();
677 //printf("Correction factor %f\n",gainoverallnotnormalized*scalefactor);
678 calDetGain->Multiply(gainoverallnotnormalized*scalefactor/oldmean);
679 //printf("newmean %f\n",calDetGain->CalcMean(kFALSE));
680 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
681 fCalibObjects->AddAt(calDetGain,kGain);
682 fPlots->AddAt(coefGain,kGain);
685 fStatusNeg = fStatusNeg | kGainNotEnoughStatsButFill;
688 fStatusPos = fStatusPos | kGainErrorOld;
692 if(gainoverallnotnormalized <= 0.0) fStatusNeg = fStatusNeg | kGainNotEnoughStatsNotFill;
693 if(!fCalDetGainUsed) fStatusPos = fStatusPos | kGainErrorOld;
697 calibra->ResetVectorFit();
702 //_____________________________________________________________________________________________________
703 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftT0(){
705 // Analyze VdriftT0 - produce the calibration objects
708 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
709 calibra->SetMinEntries(fMinStatsVdriftT0PH); // If there is less than 1000 entries in the histo: no fit
710 calibra->AnalysePH(fPH2d);
712 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
713 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
714 Int_t nbfit = calibra->GetNumberFit();
715 Int_t nbfitSuccess = calibra->GetNumberFitSuccess();
716 Int_t nbE = calibra->GetNumberEnt();
718 //printf("nbtg %d, nbfit %d, nbE %d, nbfitSuccess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
722 (nbfit >= 0.5*nbE) && (nbE > 30) && (nbfitSuccess > 30)) {
723 //printf("Pass the cut for VdriftT0\n");
724 // create the cal objects
725 calibra->RemoveOutliers(1,kFALSE);
726 calibra->PutMeanValueOtherVectorFit(1,kFALSE);
727 calibra->RemoveOutliers2(kFALSE);
728 calibra->PutMeanValueOtherVectorFit2(1,kFALSE);
730 TObjArray object = calibra->GetVectorFit();
731 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object);
732 TH1F *coefVdriftPH = calDetVdrift->MakeHisto1DAsFunctionOfDet();
733 AliTRDCalPad *calPadVdrift = (AliTRDCalPad *)calibra->CreatePadObjectVdrift(&object,calDetVdrift);
734 TH1F *coefPadVdrift = calPadVdrift->MakeHisto1D();
735 object = calibra->GetVectorFit2();
736 AliTRDCalDet *calDetT0 = calibra->CreateDetObjectT0(&object);
737 TH1F *coefT0 = calDetT0->MakeHisto1DAsFunctionOfDet();
738 AliTRDCalPad *calPadT0 = (AliTRDCalPad *)calibra->CreatePadObjectT0(&object,calDetT0);
739 TH1F *coefPadT0 = calPadT0->MakeHisto1D();
740 // Put them in the array
741 fCalibObjects->AddAt(calDetT0,kT0PHDet);
742 fCalibObjects->AddAt(calDetVdrift,kVdriftPHDet);
743 fCalibObjects->AddAt(calPadT0,kT0PHPad);
744 fCalibObjects->AddAt(calPadVdrift,kVdriftPHPad);
745 fPlots->AddAt(coefVdriftPH,kVdriftPHDet);
746 fPlots->AddAt(coefT0,kT0PHDet);
747 fPlots->AddAt(coefPadVdrift,kVdriftPHPad);
748 fPlots->AddAt(coefPadT0,kT0PHPad);
753 //printf("Not enough stats timeoffset\n");
754 fStatusNeg = fStatusNeg | kTimeOffsetNotEnoughStatsNotFill;
756 calibra->ResetVectorFit();
761 //____________________________________________________________________________________________________________________
762 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftLinearFit(){
764 // Analyze vdrift linear fit - produce the calibration objects
767 //printf("Analyse linear fit\n");
770 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
771 calibra->SetCalDetVdriftExB(fCalDetVdriftUsed,fCalDetExBUsed);
772 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
773 printf("The mean stat is by %d for VdriftLinear\n",fMinStatsVdriftLinear);
774 //printf("Fill PE Array\n");
775 fAliTRDCalibraVdriftLinearFit->SetRobustFit(fRobustFitDriftVelocity);
776 fAliTRDCalibraVdriftLinearFit->SetMinNumberOfPointsForFit(fMinNbOfPointVdriftFit);
777 if(!fAlternativeVdrfitFit)
778 fAliTRDCalibraVdriftLinearFit->FillPEArray();
780 fAliTRDCalibraVdriftLinearFit->FillPEArray2();
781 //printf("AliTRDCalibraFit\n");
782 calibra->AnalyseLinearFitters(fAliTRDCalibraVdriftLinearFit);
786 Int_t nbfit = calibra->GetNumberFit();
787 Int_t nbE = calibra->GetNumberEnt();
792 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
793 // create the cal objects
794 //calibra->RemoveOutliers(1,kTRUE);
795 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
796 //calibra->RemoveOutliers2(kTRUE);
797 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
799 TObjArray object = calibra->GetVectorFit();
800 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object,kTRUE);
801 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
802 object = calibra->GetVectorFit2();
803 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectLorentzAngle(&object);
804 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
805 //if(!calDetLorentz) printf("No lorentz created\n");
806 // Put them in the array
807 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
808 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
809 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
810 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
815 fNotEnoughStatisticsForTheVdriftLinear = kTRUE;
816 Int_t minNumberOfEntriesForAll = fMinStatsVdriftLinear*30;
817 calibra->SetMinEntries(minNumberOfEntriesForAll); // Because we do it for all, we increase this
818 Double_t vdriftoverall = -100.0;
819 Double_t exboverall = 100.0;
820 calibra->AnalyseLinearFittersAllTogether(fAliTRDCalibraVdriftLinearFit,vdriftoverall,exboverall);
821 //printf("Found mean vdrift %f and exb %f\n",vdriftoverall,exboverall);
822 if(fCalDetVdriftUsed && (vdriftoverall > 0.0) && (exboverall < 70.0)) {
823 AliTRDCalDet *calDetVdrift = new AliTRDCalDet(*fCalDetVdriftUsed);
824 AliTRDCalDet *calDetLorentz = new AliTRDCalDet(*fCalDetExBUsed);
825 Double_t oldmeanvdrift = fCalDetVdriftUsed->CalcMean(kFALSE);
826 Double_t oldmeanexb = fCalDetExBUsed->CalcMean(kFALSE);
827 //printf("oldmean %f\n",oldmean);
828 if((oldmeanvdrift > 0.0) && (oldmeanexb < 70.0)) {
829 //printf("Correction factor %f\n",vdriftoverall);
830 calDetVdrift->Multiply(vdriftoverall/oldmeanvdrift);
831 if(TMath::Abs(oldmeanexb) > 0.0001) calDetLorentz->Multiply(exboverall/oldmeanexb);
832 //printf("newmean %f\n",calDetVdrift->CalcMean(kFALSE));
833 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
834 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
835 // Put them in the array
836 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
837 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
838 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
839 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
842 fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsButFill;
845 if(oldmeanvdrift) fStatusPos = fStatusPos | kVdriftErrorOld;
846 if(oldmeanexb) fStatusPos = fStatusPos | kExBErrorOld;
850 if((vdriftoverall <= 0.0) && (exboverall > 70.0)) fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsNotFill;
851 if(!fCalDetVdriftUsed) fStatusPos = fStatusPos | kVdriftErrorOld;
852 if(!fCalDetExBUsed) fStatusPos = fStatusPos | kExBErrorOld;
856 calibra->ResetVectorFit();
861 //________________________________________________________________________________________________________________
863 Bool_t AliTRDPreprocessorOffline::AnalyzeExbAltFit(){
865 // Analyze vdrift linear fit - produce the calibration objects
868 //printf("Analyse linear fit\n");
871 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
872 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
873 //printf("Fill PE Array\n");
874 fAliTRDCalibraExbAltFit->SetRobustFit(fRobustFitExbAlt);
875 if(!fAlternativeExbAltFit)
876 fAliTRDCalibraExbAltFit->FillPEArray();
878 fAliTRDCalibraExbAltFit->FillPEArray2();
879 //printf("AliTRDCalibraFit\n");
880 calibra->AnalyseExbAltFit(fAliTRDCalibraExbAltFit);
884 Int_t nbfit = calibra->GetNumberFit();
885 Int_t nbE = calibra->GetNumberEnt();
890 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
891 // create the cal objects
892 //calibra->RemoveOutliers(1,kTRUE);
893 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
895 TObjArray object = calibra->GetVectorFit2();
896 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectExbAlt(&object);
897 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
898 //if(!calDetLorentz) printf("No lorentz created\n");
899 // Put them in the array
900 fCalibObjects->AddAt(calDetLorentz,kExbAlt);
901 fPlots->AddAt(coefLorentzAngle,kExbAlt);
906 calibra->ResetVectorFit();
911 //________________________________________________________________________________________________________________
913 Bool_t AliTRDPreprocessorOffline::AnalyzePRF(){
915 // Analyze PRF - produce the calibration objects
918 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
919 calibra->SetMinEntries(fMinStatsPRF); // If there is less than 1000 entries in the histo: no fit
920 calibra->AnalysePRFMarianFit(fPRF2d);
922 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
923 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
924 Int_t nbfit = calibra->GetNumberFit();
925 Int_t nbE = calibra->GetNumberEnt();
931 (nbfit >= 0.95*nbE) && (nbE > 30)) {
932 // create the cal objects
933 TObjArray object = calibra->GetVectorFit();
934 AliTRDCalPad *calPadPRF = (AliTRDCalPad*) calibra->CreatePadObjectPRF(&object);
935 TH1F *coefPRF = calPadPRF->MakeHisto1D();
936 // Put them in the array
937 fCalibObjects->AddAt(calPadPRF,kPRF);
938 fPlots->AddAt(coefPRF,kPRF);
943 calibra->ResetVectorFit();
949 //_____________________________________________________________________________
950 Bool_t AliTRDPreprocessorOffline::AnalyzePHQ(Int_t startRunNumber)
953 //Produce PHQ calibration results
955 for(Int_t iter=0; iter<AliTRDdEdxCalibUtils::GetHistArray()->GetSize(); iter++){
956 THnBase *hi = (THnBase*) AliTRDdEdxCalibUtils::GetHistAt(iter);
957 TObjArray *obji = AliTRDdEdxCalibUtils::HistToObj(hi, startRunNumber);
958 //printf("test analyze %s\n", obji->GetName());
959 AliTRDdEdxCalibUtils::GetObjArray()->AddAt(obji, iter);
962 fCalibObjects->AddAt(AliTRDdEdxCalibUtils::GetObjArray(), kPHQ);
966 //_____________________________________________________________________________
967 Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
970 // Produce AliTRDCalChamberStatus out of calibration results
973 // set up AliTRDCalibChamberStatus
974 AliTRDCalibChamberStatus *chamberStatus = new AliTRDCalibChamberStatus();
975 chamberStatus->SetSparseI(fSparse);
976 chamberStatus->AnalyseHisto(fMinStatsChamberStatus, fMinSingleStatsChamberStatus);
977 // get AliTRDCalChamberStatus
978 AliTRDCalChamberStatus *calChamberStatus = chamberStatus->GetCalChamberStatus();
980 // get calibration objects
981 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
982 AliTRDCalDet *calDetVDrift = (AliTRDCalDet *) fCalibObjects->At(kVdriftLinear);
983 AliTRDCalDet *calDetExB = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
986 if((!calDetGain) || (!calDetVDrift) || (!fCH2d) || (!calDetExB) || (!calChamberStatus)) return kFALSE;
989 Double_t gainmean = calDetGain->GetMean();
990 Double_t vdriftmean = calDetVDrift->GetMean();
991 Double_t exbmean = calDetExB->GetMean();
993 Double_t gainrms = calDetGain->GetRMSRobust();
994 Double_t vdriftrms = calDetVDrift->GetRMSRobust();
995 Double_t exbrms = calDetExB->GetRMSRobust();
997 //printf("Gain mean: %f, rms: %f\n",gainmean,gainrms);
998 //printf("Vdrift mean: %f, rms: %f\n",vdriftmean,vdriftrms);
999 //printf("ExB mean: %f, rms: %f\n",exbmean,exbrms);
1002 if((TMath::Abs(gainrms) < 0.001) || (TMath::Abs(vdriftrms) < 0.001) || (TMath::Abs(exbrms) < 0.0000001)) return kFALSE;
1004 // mask chambers with empty gain entries
1005 //Int_t counter = 0;
1006 for (Int_t idet = 0; idet < 540; idet++) {
1009 TH1I *projch = (TH1I *) fCH2d->ProjectionX("projch",idet+1,idet+1,(Option_t *)"e");
1010 Double_t entries = projch->GetEntries();
1011 //printf("Number of entries %f for det %d\n",entries,idet);
1014 Double_t gain = calDetGain->GetValue(idet);
1017 Double_t vdrift = calDetVDrift->GetValue(idet);
1020 Double_t exb = calDetExB->GetValue(idet);
1023 if( (entries<50 && !calChamberStatus->IsNoData(idet)) ||
1024 TMath::Abs(gainmean-gain) > (fRMSBadCalibratedGain*gainrms) ||
1025 TMath::Abs(vdriftmean-vdrift) > (fRMSBadCalibratedVdrift*vdriftrms) ||
1026 TMath::Abs(exbmean-exb) > (fRMSBadCalibratedExB*exbrms) ) {
1028 //printf(" chamber det %03d masked \n",idet);
1029 //printf(" gainmean %f and gain %f, gainrms %f \n",gainmean,gain,gainrms);
1030 //printf(" vdriftmean %f and vdrift %f, vdriftrms %f \n",vdriftmean,vdrift,vdriftrms);
1031 //printf(" exbmean %f and exb %f, exbrms %f \n",exbmean,exb,exbrms);
1033 calChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kBadCalibrated);
1042 for(Int_t sm=0; sm < 18; sm++) {
1044 Int_t smbadcalib = 0;
1045 for(Int_t det = 0; det < 30; det++){
1046 Int_t detector = sm*30+det;
1047 if(calChamberStatus->IsNoData(detector)) smnodata++;
1049 if(calChamberStatus->IsBadCalibrated(detector)) smbadcalib++;
1052 fNoData[sm] = smnodata;
1053 fBadCalib[sm]= smbadcalib;
1054 //printf("No Data %d, bad calibrated %d for %d\n",fNoData[sm],fBadCalib[sm],sm);
1058 // for(Int_t sm=0; sm < 18; sm++) {
1059 // Int_t counter = 0;
1060 // for(Int_t det = 0; det < 30; det++){
1061 // Int_t detector = sm*30+det;
1062 // if(calChamberStatus->IsBadCalibrated(detector)) counter++;
1064 // if(counter >= 20) {
1065 // for(Int_t det = 0; det < 30; det++){
1066 // Int_t detector = sm*30+det;
1067 // calChamberStatus->SetStatus(detector,AliTRDCalChamberStatus::kGood);
1072 fCalibObjects->AddAt(calChamberStatus,kChamberStatus);
1078 //________________________________________________________________________________________________
1079 void AliTRDPreprocessorOffline::CorrectFromDetGainUsed() {
1081 // Correct from the gas gain used afterwards
1083 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1084 if(!calDetGain) return;
1087 Double_t mean = 0.0;
1090 for(Int_t det = 0; det < 540; det++) {
1092 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1093 Float_t gainout = calDetGain->GetValue(det);
1096 if(TMath::Abs(gainout-1.0) > 0.000001) {
1097 mean += (gaininit*gainout);
1101 if(nbdet > 0) mean = mean/nbdet;
1103 for(Int_t det = 0; det < 540; det++) {
1105 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1106 Float_t gainout = calDetGain->GetValue(det);
1108 if(TMath::Abs(gainout-1.0) > 0.000001) {
1109 Double_t newgain = gaininit*gainout;
1110 if(newgain < 0.1) newgain = 0.1;
1111 if(newgain > 1.9) newgain = 1.9;
1112 calDetGain->SetValue(det,newgain);
1115 Double_t newgain = mean;
1116 if(newgain < 0.1) newgain = 0.1;
1117 if(newgain > 1.9) newgain = 1.9;
1118 calDetGain->SetValue(det,newgain);
1124 //________________________________________________________________________________________________
1125 void AliTRDPreprocessorOffline::CorrectFromDetVdriftUsed() {
1127 // Correct from the drift velocity
1130 //printf("Correct for vdrift\n");
1132 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1133 if(!calDetGain) return;
1135 Int_t detVdrift = kVdriftPHDet;
1136 if(fMethodSecond) detVdrift = kVdriftLinear;
1137 AliTRDCalDet *calDetVdrift = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1138 if(!calDetVdrift) return;
1141 if(!fNotEnoughStatisticsForTheVdriftLinear) {
1142 for(Int_t det = 0; det < 540; det++) {
1144 Float_t vdriftinit = fCalDetVdriftUsed->GetValue(det);
1145 Float_t vdriftout = calDetVdrift->GetValue(det);
1147 Float_t gain = calDetGain->GetValue(det);
1148 if(vdriftout > 0.0) gain = gain*vdriftinit/vdriftout;
1149 if(gain < 0.1) gain = 0.1;
1150 if(gain > 1.9) gain = 1.9;
1151 calDetGain->SetValue(det,gain);
1156 Float_t vdriftinit = fCalDetVdriftUsed->CalcMean(kFALSE);
1157 Float_t vdriftout = calDetVdrift->CalcMean(kFALSE);
1158 Float_t factorcorrectif = 1.0;
1159 if(vdriftout > 0.0) factorcorrectif = vdriftinit/vdriftout;
1160 for(Int_t det = 0; det < 540; det++) {
1161 Float_t gain = calDetGain->GetValue(det);
1162 gain = gain*factorcorrectif;
1163 if(gain < 0.1) gain = 0.1;
1164 if(gain > 1.9) gain = 1.9;
1165 calDetGain->SetValue(det,gain);
1171 //_________________________________________________________________________________________________________________
1172 void AliTRDPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1174 // Update OCDB entry
1177 AliCDBMetaData *metaData= new AliCDBMetaData();
1178 metaData->SetObjectClassName("AliTRDCalDet");
1179 metaData->SetResponsible("Raphaelle Bailhache");
1180 metaData->AddDateToComment();
1181 metaData->SetBeamPeriod(1);
1183 AliCDBId id1("TRD/Calib/ChamberGainFactor", startRunNumber, endRunNumber);
1184 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1185 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1186 if(calDet) gStorage->Put(calDet, id1, metaData);
1190 //___________________________________________________________________________________________________________________
1191 void AliTRDPreprocessorOffline::UpdateOCDBExB(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1193 // Update OCDB entry
1196 Int_t detExB = kLorentzLinear;
1197 if(!fMethodSecond) return;
1201 AliCDBMetaData *metaData= new AliCDBMetaData();
1202 metaData->SetObjectClassName("AliTRDCalDet");
1203 metaData->SetResponsible("Raphaelle Bailhache");
1204 metaData->AddDateToComment();
1205 metaData->SetBeamPeriod(1);
1207 AliCDBId id1("TRD/Calib/ChamberExB", startRunNumber, endRunNumber);
1208 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1209 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1210 if(calDet) gStorage->Put(calDet, id1, metaData);
1211 //if(!calDet) printf("No caldet\n");
1214 //___________________________________________________________________________________________________________________
1215 void AliTRDPreprocessorOffline::UpdateOCDBExBAlt(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1217 // Update OCDB entry
1220 Int_t detExB = kExbAlt;
1221 if(!fMethodSecond) return;
1225 AliCDBMetaData *metaData= new AliCDBMetaData();
1226 metaData->SetObjectClassName("AliTRDCalDet");
1227 metaData->SetResponsible("Theo Rascanu");
1228 metaData->AddDateToComment();
1229 metaData->SetBeamPeriod(1);
1231 AliCDBId id1("TRD/Calib/ChamberExBAlt", startRunNumber, endRunNumber);
1232 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1233 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1234 if(calDet) gStorage->Put(calDet, id1, metaData);
1235 //if(!calDet) printf("No caldet\n");
1238 //___________________________________________________________________________________________________________________
1239 void AliTRDPreprocessorOffline::UpdateOCDBVdrift(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1241 // Update OCDB entry
1244 Int_t detVdrift = kVdriftPHDet;
1246 if(fMethodSecond) detVdrift = kVdriftLinear;
1248 AliCDBMetaData *metaData= new AliCDBMetaData();
1249 metaData->SetObjectClassName("AliTRDCalDet");
1250 metaData->SetResponsible("Raphaelle Bailhache");
1251 metaData->AddDateToComment();
1252 metaData->SetBeamPeriod(1);
1254 AliCDBId id1("TRD/Calib/ChamberVdrift", startRunNumber, endRunNumber);
1255 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1256 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1257 if(calDet) gStorage->Put(calDet, id1, metaData);
1261 if(!fMethodSecond) {
1263 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1264 metaDataPad->SetObjectClassName("AliTRDCalPad");
1265 metaDataPad->SetResponsible("Raphaelle Bailhache");
1266 metaDataPad->AddDateToComment();
1267 metaDataPad->SetBeamPeriod(1);
1269 AliCDBId id1Pad("TRD/Calib/LocalVdrift", startRunNumber, endRunNumber);
1270 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1271 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
1276 //________________________________________________________________________________________________________________________
1277 void AliTRDPreprocessorOffline::UpdateOCDBT0(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1279 // Update OCDB entry
1282 AliCDBMetaData *metaData= new AliCDBMetaData();
1283 metaData->SetObjectClassName("AliTRDCalDet");
1284 metaData->SetResponsible("Raphaelle Bailhache");
1285 metaData->AddDateToComment();
1286 metaData->SetBeamPeriod(1);
1288 AliCDBId id1("TRD/Calib/ChamberT0", startRunNumber, endRunNumber);
1289 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1290 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1291 if(calDet) gStorage->Put(calDet, id1, metaData);
1295 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1296 metaDataPad->SetObjectClassName("AliTRDCalPad");
1297 metaDataPad->SetResponsible("Raphaelle Bailhache");
1298 metaDataPad->AddDateToComment();
1299 metaDataPad->SetBeamPeriod(1);
1301 AliCDBId id1Pad("TRD/Calib/LocalT0", startRunNumber, endRunNumber);
1302 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1303 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
1308 //_________________________________________________________________________________________________________________
1309 void AliTRDPreprocessorOffline::UpdateOCDBPRF(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1311 // Update OCDB entry
1314 AliCDBMetaData *metaData= new AliCDBMetaData();
1315 metaData->SetObjectClassName("AliTRDCalPad");
1316 metaData->SetResponsible("Raphaelle Bailhache");
1317 metaData->AddDateToComment();
1318 metaData->SetBeamPeriod(1);
1321 AliCDBId id1("TRD/Calib/PRFWidth", startRunNumber, endRunNumber);
1322 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1323 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1324 if(calPad) gStorage->Put(calPad, id1, metaData);
1328 //_________________________________________________________________________________________________________________
1329 void AliTRDPreprocessorOffline::UpdateOCDBPHQ(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath)
1332 // Update OCDB entry
1334 AliCDBMetaData *metaData= new AliCDBMetaData();
1335 metaData->SetObjectClassName("TObjArray");
1336 metaData->SetResponsible("Raphaelle Bailhache and Xianguo Lu");
1337 metaData->AddDateToComment();
1338 metaData->SetBeamPeriod(1);
1340 AliCDBId id1("TRD/Calib/PHQ", startRunNumber, endRunNumber);
1341 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1342 TObjArray *cobj = (TObjArray *) fCalibObjects->At(kPHQ);
1345 gStorage->Put(cobj, id1, metaData);
1349 //_________________________________________________________________________________________________________________
1350 void AliTRDPreprocessorOffline::UpdateOCDBChamberStatus(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1352 // Update OCDB entry
1355 AliCDBMetaData *metaData= new AliCDBMetaData();
1356 metaData->SetObjectClassName("AliTRDCalChamberStatus");
1357 metaData->SetResponsible("Raphaelle Bailhache and Julian Book");
1358 metaData->AddDateToComment();
1359 metaData->SetBeamPeriod(1);
1361 AliCDBId id1("TRD/Calib/ChamberStatus", startRunNumber, endRunNumber);
1362 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1363 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1364 if(calChamberStatus) gStorage->Put(calChamberStatus, id1, metaData);
1368 //__________________________________________________________________________________________________________________________
1369 Bool_t AliTRDPreprocessorOffline::ValidateGain() {
1371 // Validate OCDB entry
1374 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1376 Double_t mean = calDet->GetMean();
1377 Double_t rms = calDet->GetRMSRobust();
1378 if((mean > 0.2) && (mean < 1.4) && (rms < 0.5)) return kTRUE;
1379 //if((mean > 0.2) && (mean < 1.4)) return kTRUE;
1381 fStatusPos = fStatusPos | kGainErrorRange;
1390 //__________________________________________________________________________________________________________________________
1391 Bool_t AliTRDPreprocessorOffline::ValidateVdrift(){
1393 // Update OCDB entry
1396 Int_t detVdrift = kVdriftPHDet;
1399 if(fMethodSecond) detVdrift = kVdriftLinear;
1401 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1403 Double_t mean = calDet->GetMean();
1404 Double_t rms = calDet->GetRMSRobust();
1405 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1406 if(!((mean > 1.0) && (mean < 2.0) && (rms < 0.5))) {
1407 fStatusPos = fStatusPos | kVdriftErrorRange;
1413 if(!fMethodSecond) {
1414 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1416 Double_t mean = calPad->GetMean();
1417 Double_t rms = calPad->GetRMS();
1418 //printf("Vdrift::meanpad %f, rmspad %f\n",mean,rms);
1419 if(!((mean > 0.9) && (mean < 1.1) && (rms < 0.6))) {
1420 fStatusPos = fStatusPos | kVdriftErrorRange;
1430 //__________________________________________________________________________________________________________________________
1431 Bool_t AliTRDPreprocessorOffline::ValidateExB(){
1433 // Update OCDB entry
1436 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
1438 Double_t mean = calDet->GetMean();
1439 Double_t rms = calDet->GetRMSRobust();
1440 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1441 if(!((mean > -1.0) && (mean < 1.0) && (rms < 0.5))) {
1442 fStatusNeg = fStatusNeg | kExBErrorRange;
1450 //__________________________________________________________________________________________________________________________
1451 Bool_t AliTRDPreprocessorOffline::ValidateT0(){
1453 // Update OCDB entry
1456 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1457 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1458 if(calDet && calPad) {
1459 Double_t meandet = calDet->GetMean();
1460 Double_t rmsdet = calDet->GetRMSRobust();
1461 Double_t meanpad = calPad->GetMean();
1462 //Double_t rmspad = calPad->GetRMS();
1463 //printf("T0::minimum %f, rmsdet %f,meanpad %f, rmspad %f\n",meandet,rmsdet,meanpad,rmspad);
1464 if((meandet > -1.5) && (meandet < 5.0) && (rmsdet < 4.0) && (meanpad < 5.0) && (meanpad > -0.5)) return kTRUE;
1466 fStatusPos = fStatusPos | kTimeOffsetErrorRange;
1473 //__________________________________________________________________________________________________________________________
1474 Bool_t AliTRDPreprocessorOffline::ValidatePRF() const{
1476 // Update OCDB entry
1479 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1481 Double_t meanpad = calPad->GetMean();
1482 Double_t rmspad = calPad->GetRMS();
1483 //printf("PRF::meanpad %f, rmspad %f\n",meanpad,rmspad);
1484 if((meanpad < 1.0) && (rmspad < 0.8)) return kTRUE;
1491 //__________________________________________________________________________________________________________________________
1492 Bool_t AliTRDPreprocessorOffline::ValidateChamberStatus(){
1494 // Update OCDB entry
1497 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1498 if(calChamberStatus) {
1500 Int_t detectornodata = 0;
1501 Int_t detectorbadcalib = 0;
1503 for(Int_t sm=0; sm < 18; sm++) {
1504 //printf("%d chambers w/o data in sm %d\n",fNoData[sm],sm);
1505 //printf("%d bad calibrated chambers in sm %d\n",fBadCalib[sm],sm);
1506 if(fNoData[sm] != 30) detectornodata += fNoData[sm];
1507 detectorbadcalib+=fBadCalib[sm];
1509 //printf("Number of chambers w/o data %d\n",detectornodata);
1510 //printf("Number of chambers bad calibrated %d\n",detectorbadcalib);
1512 if((detectornodata > fNoDataValidate) ||
1513 (detectorbadcalib > fBadCalibValidate)){
1514 fStatusPos = fStatusPos | kChamberStatusErrorRange;
1522 //_____________________________________________________________________________
1523 Int_t AliTRDPreprocessorOffline::GetVersion(TString name) const
1526 // Get version from the title
1530 const Char_t *version = "Ver";
1531 if(!strstr(name.Data(),version)) return -1;
1532 const Char_t *after = "Subver";
1533 if(!strstr(name.Data(),after)) return -1;
1535 for(Int_t ver = 0; ver < 999999999; ver++) {
1537 TString vertry(version);
1541 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1543 if(strstr(name.Data(),vertry.Data())) return ver;
1551 //_____________________________________________________________________________
1552 Int_t AliTRDPreprocessorOffline::GetSubVersion(TString name) const
1555 // Get subversion from the title
1559 const Char_t *subversion = "Subver";
1560 if(!strstr(name.Data(),subversion)) return -1;
1561 const Char_t *after = "FirstRun";
1562 if(!strstr(name.Data(),after)) {
1565 if(!strstr(name.Data(),after)) return -1;
1568 for(Int_t ver = 0; ver < 999999999; ver++) {
1570 TString vertry(subversion);
1574 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1576 if(strstr(name.Data(),vertry.Data())) return ver;
1584 //_____________________________________________________________________________
1585 Int_t AliTRDPreprocessorOffline::GetFirstRun(TString name) const
1588 // Get first run from the title
1592 const Char_t *firstrun = "FirstRun";
1593 if(!strstr(name.Data(),firstrun)) return -1;
1594 const Char_t *after = "Nz";
1595 if(!strstr(name.Data(),after)) return -1;
1598 for(Int_t ver = 0; ver < 999999999; ver++) {
1600 TString vertry(firstrun);
1604 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1606 if(strstr(name.Data(),vertry.Data())) return ver;
1613 //_____________________________________________________________________________
1614 Bool_t AliTRDPreprocessorOffline::CheckStatus(Int_t status, Int_t bitMask) const
1617 // Checks the status
1620 return (status & bitMask) ? kTRUE : kFALSE;
1623 //_____________________________________________________________________________
1624 Int_t AliTRDPreprocessorOffline::GetStatus() const
1627 // Checks the status
1628 // fStatusPos: errors
1629 // fStatusNeg: only info
1632 if(fStatusPos > 0) return fStatusPos;
1633 else return (-TMath::Abs(fStatusNeg));
1636 //_____________________________________________________________________________
1637 void AliTRDPreprocessorOffline::PrintStatus() const
1643 AliInfo(Form("The error status is %d",fStatusPos));
1644 AliInfo(Form("IsGainErrorOld? %d",(Int_t)IsGainErrorOld()));
1645 AliInfo(Form("IsVdriftErrorOld? %d",(Int_t)IsVdriftErrorOld()));
1646 AliInfo(Form("IsGainErrorRange? %d",(Int_t)IsGainErrorRange()));
1647 AliInfo(Form("IsVdriftErrorRange? %d",(Int_t)IsVdriftErrorRange()));
1648 AliInfo(Form("IsTimeOffsetErrorRange? %d",(Int_t)IsTimeOffsetErrorRange()));
1649 AliInfo(Form("IsChamberStatusErrorRange? %d",(Int_t)IsChamberStatusErrorRange()));
1652 AliInfo(Form("The info status is %d",fStatusNeg));
1653 AliInfo(Form("IsGainNotEnoughStatsButFill? %d",(Int_t)IsGainNotEnoughStatsButFill()));
1654 AliInfo(Form("IsVdriftNotEnoughStatsButFill? %d",(Int_t)IsVdriftNotEnoughStatsButFill()));
1655 AliInfo(Form("IsGainNotEnoughStatsNotFill? %d",(Int_t)IsGainNotEnoughStatsNotFill()));
1656 AliInfo(Form("IsVdriftNotEnoughStatsNotFill? %d",(Int_t)IsVdriftNotEnoughStatsNotFill()));
1657 AliInfo(Form("IsTimeOffsetNotEnoughStatsNotFill? %d",(Int_t)IsTimeOffsetNotEnoughStatsNotFill()));
1659 AliInfo(Form("IsExBErrorRange? %d",(Int_t)IsExBErrorRange()));
1660 AliInfo(Form("IsExBErrorOld? %d",(Int_t)IsExBErrorOld()));
1663 //___________________________________________________________________________________
1664 void AliTRDPreprocessorOffline::SetCalDetVdrift(AliTRDCalDet *calDetVdriftUsed)
1667 fCalDetVdriftUsed = calDetVdriftUsed;
1669 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1670 for(Int_t k = 0; k < 540; k++){
1671 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1672 //printf("Set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1676 //___________________________________________________________________________________
1677 Bool_t AliTRDPreprocessorOffline::SetCalDetGain(Int_t runNumber, Int_t version, Int_t subversion)
1680 // Set the fCalDetGainUsed
1683 if((version == 0) && (subversion == 0)) return kFALSE;
1685 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor",runNumber, version, subversion);
1687 AliError("Found no entry\n");
1688 fStatusPos = fStatusPos | kGainErrorOld;
1691 //const AliCDBId id = entry->GetId();
1692 //version = id.GetVersion();
1693 //subversion = id.GetSubVersion();
1694 //printf("Found version %d and subversion %d for vdrift\n",version,subversion);
1695 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1696 if(calDet) fCalDetGainUsed = calDet;
1698 fStatusPos = fStatusPos | kGainErrorOld;
1705 //___________________________________________________________________________________
1706 Bool_t AliTRDPreprocessorOffline::SetCalDetVdriftExB(Int_t runNumber, Int_t versionv, Int_t subversionv, Int_t versionexb, Int_t subversionexb)
1709 // Set the fCalDetVdriftUsed and fCalDetExBUsed
1712 if((versionv == 0) && (subversionv == 0)) return kFALSE;
1714 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberVdrift",runNumber, versionv, subversionv);
1716 AliError("Found no entry\n");
1717 fStatusPos = fStatusPos | kVdriftErrorOld;
1720 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1721 if(calDet) fCalDetVdriftUsed = calDet;
1723 fStatusPos = fStatusPos | kVdriftErrorOld;
1729 if((versionexb == 0) && (subversionexb == 0)) {
1731 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1732 for(Int_t k = 0; k < 540; k++){
1733 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1734 //printf("Nothing found: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1740 entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberExB",runNumber, versionexb, subversionexb);
1742 //printf("Found no entry\n");
1743 fStatusPos = fStatusPos | kExBErrorOld;
1746 AliTRDCalDet* calDetexb = (AliTRDCalDet *)entry->GetObject();
1748 fStatusPos = fStatusPos | kExBErrorOld;
1752 Double_t meanexb = calDetexb->GetMean();
1753 //printf("Mean value %f\n",meanexb);
1754 if((meanexb > 70) || (fNoExBUsedInReco)) {
1755 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1756 for(Int_t k = 0; k < 540; k++){
1757 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1758 //printf("Found but: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1762 fCalDetExBUsed = calDetexb;