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 "AliTRDdEdxUtils.h"
71 ClassImp(AliTRDPreprocessorOffline)
73 AliTRDPreprocessorOffline::AliTRDPreprocessorOffline():
74 TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
76 fNameList("TRDCalib"),
78 fCalDetVdriftUsed(0x0),
84 fAliTRDCalibraVdriftLinearFit(0x0),
85 fAliTRDCalibraExbAltFit(0x0),
88 fPlots(new TObjArray(kNumCalibObjs)),
89 fCalibObjects(new TObjArray(kNumCalibObjs)),
92 fSubVersionGainUsed(0),
93 fFirstRunVdriftUsed(0),
94 fVersionVdriftUsed(0),
95 fSubVersionVdriftUsed(0),
98 fSubVersionExBUsed(0),
99 fNoExBUsedInReco(kFALSE),
100 fSwitchOnValidation(kTRUE),
101 fVdriftValidated(kFALSE),
102 fExBValidated(kFALSE),
103 fT0Validated(kFALSE),
104 fMinStatsVdriftT0PH(800*20),
105 fMinStatsVdriftLinear(800),
108 fMinStatsChamberStatus(20),
109 fMinSingleStatsChamberStatus(0.05),
110 fBackCorrectGain(kFALSE),
111 fBackCorrectVdrift(kTRUE),
112 fNotEnoughStatisticsForTheGain(kFALSE),
113 fNotEnoughStatisticsForTheVdriftLinear(kFALSE),
116 fBadCalibValidate(40),
118 fRMSBadCalibratedGain(20.0),
119 fRMSBadCalibratedVdrift(20.0),
120 fRMSBadCalibratedExB(20.0),
121 fRobustFitDriftVelocity(kTRUE),
122 fRobustFitExbAlt(kFALSE),
123 fAlternativeVdrfitFit(kFALSE),
124 fAlternativeExbAltFit(kFALSE),
126 fOutliersFitChargeLow(0.03),
127 fOutliersFitChargeHigh(0.7),
131 // default constructor
134 memset(fBadCalib, 0, sizeof(Int_t) * 18);
135 memset(fNoData, 0, sizeof(Int_t) * 18);
137 //_________________________________________________________________________________________________________________
138 AliTRDPreprocessorOffline::~AliTRDPreprocessorOffline() {
143 if(fCalDetGainUsed) delete fCalDetGainUsed;
144 if(fCalDetVdriftUsed) delete fCalDetVdriftUsed;
145 if(fCalDetExBUsed) delete fCalDetExBUsed;
146 if(fCH2d) delete fCH2d;
147 if(fPH2d) delete fPH2d;
148 if(fPRF2d) delete fPRF2d;
149 if(fSparse) delete fSparse;
150 AliTRDdEdxUtils::DeleteCalibHist();
151 AliTRDdEdxUtils::DeleteCalibObj();
152 if(fAliTRDCalibraVdriftLinearFit) delete fAliTRDCalibraVdriftLinearFit;
153 if(fAliTRDCalibraExbAltFit) delete fAliTRDCalibraExbAltFit;
154 if(fNEvents) delete fNEvents;
155 if(fAbsoluteGain) delete fAbsoluteGain;
156 if(fPlots) delete fPlots;
157 if(fCalibObjects) delete fCalibObjects;
160 //___________________________________________________________________________________
161 void AliTRDPreprocessorOffline::Process(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage)
164 // Process to the gain, vdrift, timeoffset, exb and chamber status calibration
167 if(SetCalDetGain(startRunNumber,fVersionGainUsed,fSubVersionGainUsed) && SetCalDetVdriftExB(startRunNumber,fVersionVdriftUsed,fSubVersionVdriftUsed,fVersionExBUsed,fSubVersionExBUsed)) {
169 CalibVdriftT0(file,startRunNumber,endRunNumber,ocdbStorage);
170 CalibGain(file,startRunNumber,endRunNumber,ocdbStorage);
171 CalibChamberStatus(file,startRunNumber,endRunNumber,ocdbStorage);
172 CalibExbAlt(file,startRunNumber,endRunNumber,ocdbStorage);
176 CalibPHQ(file, startRunNumber, endRunNumber, ocdbStorage);
181 //___________________________________________________________________________________________________________________
183 void AliTRDPreprocessorOffline::CalibVdriftT0(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
185 // make calibration of the drift velocity
187 // file - the location of input file
188 // startRunNumber, endRunNumber - run validity period
189 // ocdbStorage - path to the OCDB storage
190 // - if empty - local storage 'pwd' uesed
191 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
195 fVdriftValidated = kTRUE;
196 fT0Validated = kTRUE;
197 fExBValidated = kTRUE;
198 fNotEnoughStatisticsForTheVdriftLinear = kFALSE;
200 // 2. extraction of the information
202 if(ReadVdriftLinearFitGlobal(file) && fCalDetVdriftUsed && fCalDetExBUsed) AnalyzeVdriftLinearFit();
203 if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
205 // 3. Append QA plots
207 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
210 // 4. validate OCDB entries
212 if(fSwitchOnValidation==kTRUE && ValidateVdrift()==kFALSE) {
213 //AliError("TRD vdrift OCDB parameters out of range!");
214 fVdriftValidated = kFALSE;
216 if(fSwitchOnValidation==kTRUE && ValidateT0()==kFALSE) {
217 //AliError("TRD t0 OCDB parameters out of range!");
218 fT0Validated = kFALSE;
220 if(fSwitchOnValidation==kTRUE && ValidateExB()==kFALSE) {
221 //AliError("TRD t0 OCDB parameters out of range!");
222 fExBValidated = kFALSE;
228 if(fVdriftValidated) UpdateOCDBVdrift(startRunNumber,endRunNumber,ocdbStorage);
229 if(fT0Validated) UpdateOCDBT0(startRunNumber,endRunNumber,ocdbStorage);
230 if(fExBValidated) UpdateOCDBExB(startRunNumber,endRunNumber,ocdbStorage);
233 //___________________________________________________________________________________________________________________
235 void AliTRDPreprocessorOffline::CalibExbAlt(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
237 // make calibration of the drift velocity
239 // file - the location of input file
240 // startRunNumber, endRunNumber - run validity period
241 // ocdbStorage - path to the OCDB storage
242 // - if empty - local storage 'pwd' uesed
243 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
249 // 2. extraction of the information
251 if(ReadExbAltFitGlobal(file)) AnalyzeExbAltFit();
253 // 3. Append QA plots
255 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
258 // 4. validate OCDB entries
264 UpdateOCDBExBAlt(startRunNumber,endRunNumber,ocdbStorage);
268 //_________________________________________________________________________________________________________________
270 void AliTRDPreprocessorOffline::CalibGain(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
272 // make calibration of the drift velocity
274 // file - the location of input file
275 // startRunNumber, endRunNumber - run validity period
276 // ocdbStorage - path to the OCDB storage
277 // - if empty - local storage 'pwd' uesed
278 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
280 fNotEnoughStatisticsForTheGain = kFALSE;
283 if(!ReadGainGlobal(file)) return;
286 // 2. extraction of the information
289 if(fBackCorrectGain) CorrectFromDetGainUsed();
290 //if(fBackCorrectVdrift) CorrectFromDetVdriftUsed();
292 // 3. Append QA plots
294 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
297 // 4. validate OCDB entries
299 if(fSwitchOnValidation==kTRUE && ValidateGain()==kFALSE) {
300 //AliError("TRD gain OCDB parameters out of range!");
307 if((!fCalDetVdriftUsed) || (fCalDetVdriftUsed && fVdriftValidated)) UpdateOCDBGain(startRunNumber,endRunNumber,ocdbStorage);
311 //________________________________________________________________________________________________________________
313 void AliTRDPreprocessorOffline::CalibPRF(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
315 // make calibration of the drift velocity
317 // file - the location of input file
318 // startRunNumber, endRunNumber - run validity period
319 // ocdbStorage - path to the OCDB storage
320 // - if empty - local storage 'pwd' uesed
321 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
324 if(!ReadPRFGlobal(file)) return;
327 // 2. extraction of the information
331 // 3. Append QA plots
333 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
337 // 4. validate OCDB entries
339 if(fSwitchOnValidation==kTRUE && ValidatePRF()==kFALSE) {
340 //AliError("TRD prf OCDB parameters out of range!");
347 UpdateOCDBPRF(startRunNumber,endRunNumber,ocdbStorage);
350 //________________________________________________________________________________________________________________
351 void AliTRDPreprocessorOffline::CalibPHQ(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage)
354 // make calibration of puls height Q
356 // startRunNumber, endRunNumber - run validity period
357 // ocdbStorage - path to the OCDB storage
358 // - if empty - local storage 'pwd' uesed
361 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
362 //printf("test %s\n", ocdbStorage.Data());
364 if(!ReadPHQGlobal(file)) return;
366 if(!AnalyzePHQ(startRunNumber)) return;
368 UpdateOCDBPHQ(startRunNumber,endRunNumber,ocdbStorage);
371 //________________________________________________________________________________________________________________
373 void AliTRDPreprocessorOffline::CalibChamberStatus(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
375 // make calibration of the chamber status
377 // startRunNumber, endRunNumber - run validity period
378 // ocdbStorage - path to the OCDB storage
379 // - if empty - local storage 'pwd' uesed
380 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
384 if(!ReadStatusGlobal(file)) return;
388 // 2. extraction of the information
390 if(!AnalyzeChamberStatus()) return;
392 // 3. Append QA plots
394 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
398 // 4. validate OCDB entries
400 if(fSwitchOnValidation==kTRUE && ValidateChamberStatus()==kFALSE) {
401 //AliError("TRD Chamber status OCDB parameters not ok!");
408 if((!fNotEnoughStatisticsForTheVdriftLinear) && (!fNotEnoughStatisticsForTheGain)) UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
409 //UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
412 //______________________________________________________________________________________________________
413 Bool_t AliTRDPreprocessorOffline::Init(const Char_t* fileName){
415 // read the calibration used during the reconstruction
418 if(ReadVdriftT0Global(fileName)) {
420 TString nameph = fPH2d->GetTitle();
421 fFirstRunVdriftUsed = GetFirstRun(nameph);
422 fVersionVdriftUsed = GetVersion(nameph);
423 fSubVersionVdriftUsed = GetSubVersion(nameph);
425 //printf("Found Version %d, Subversion %d for vdrift\n",fVersionVdriftUsed,fSubVersionVdriftUsed);
429 if(ReadGainGlobal(fileName)) {
431 TString namech = fCH2d->GetTitle();
432 fFirstRunGainUsed = GetFirstRun(namech);
433 fVersionGainUsed = GetVersion(namech);
434 fSubVersionGainUsed = GetSubVersion(namech);
436 //printf("Found Version %d, Subversion %d for gain\n",fVersionGainUsed,fSubVersionGainUsed);
440 if(ReadVdriftLinearFitGlobal(fileName)) {
442 TString namelinear = fAliTRDCalibraVdriftLinearFit->GetNameCalibUsed();
443 fFirstRunExBUsed = GetFirstRun(namelinear);
444 fVersionExBUsed = GetVersion(namelinear);
445 fSubVersionExBUsed = GetSubVersion(namelinear);
447 //printf("Found Version %d, Subversion %d, run %d for ExB\n",fVersionExBUsed,fSubVersionExBUsed,fFirstRunExBUsed);
451 if(fVersionVdriftUsed == 0) fStatusPos = fStatusPos |kVdriftErrorOld;
452 if(fVersionGainUsed == 0) fStatusPos = fStatusPos | kGainErrorOld;
457 //___________________________________________________________________________________________________________________
459 Bool_t AliTRDPreprocessorOffline::ReadStatusGlobal(const Char_t* fileName){
461 // read calibration entries from file
463 if(fSparse) return kTRUE;
464 TFile fcalib(fileName);
465 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
467 fSparse = (THnSparseI *) array->FindObject("NumberOfEntries");
468 if(!fSparse) return kFALSE;
476 //___________________________________________________________________________________________________________________
478 Bool_t AliTRDPreprocessorOffline::ReadPHQGlobal(const Char_t* fileName)
481 // read calibration entries from file
484 return AliTRDdEdxUtils::ReadCalibHist(fileName, fNameList);
487 //___________________________________________________________________________________________________________________
489 Bool_t AliTRDPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
491 // read calibration entries from file
493 if(fCH2d) return kTRUE;
494 TFile fcalib(fileName);
495 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
497 TH2I *ch2d = (TH2I *) array->FindObject("CH2d");
498 if(!ch2d) return kFALSE;
499 fCH2d = (TH2I*)ch2d->Clone();
500 //fNEvents = (TH1I *) array->FindObject("NEvents");
501 //fAbsoluteGain = (TH2F *) array->FindObject("AbsoluteGain");
503 TH2I *ch2d = (TH2I *) fcalib.Get("CH2d");
504 if(!ch2d) return kFALSE;
505 fCH2d = (TH2I*)ch2d->Clone();
506 //fNEvents = (TH1I *) fcalib.Get("NEvents");
507 //fAbsoluteGain = (TH2F *) fcalib.Get("AbsoluteGain");
509 fCH2d->SetDirectory(0);
510 //printf("title of CH2d %s\n",fCH2d->GetTitle());
515 //_________________________________________________________________________________________________________________
517 Bool_t AliTRDPreprocessorOffline::ReadVdriftT0Global(const Char_t* fileName){
519 // read calibration entries from file
521 if(fPH2d) return kTRUE;
522 TFile fcalib(fileName);
523 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
525 TProfile2D *ph2d = (TProfile2D *) array->FindObject("PH2d");
526 if(!ph2d) return kFALSE;
527 fPH2d = (TProfile2D*)ph2d->Clone();
528 //fNEvents = (TH1I *) array->FindObject("NEvents");
530 TProfile2D *ph2d = (TProfile2D *) fcalib.Get("PH2d");
531 if(!ph2d) return kFALSE;
532 fPH2d = (TProfile2D*)ph2d->Clone();
533 //fNEvents = (TH1I *) fcalib.Get("NEvents");
535 fPH2d->SetDirectory(0);
536 //printf("title of PH2d %s\n",fPH2d->GetTitle());
541 //___________________________________________________________________________________________________________________
543 Bool_t AliTRDPreprocessorOffline::ReadVdriftLinearFitGlobal(const Char_t* fileName){
545 // read calibration entries from file
547 if(fAliTRDCalibraVdriftLinearFit) return kTRUE;
548 TFile fcalib(fileName);
549 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
551 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) array->FindObject("AliTRDCalibraVdriftLinearFit");
552 //fNEvents = (TH1I *) array->FindObject("NEvents");
554 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) fcalib.Get("AliTRDCalibraVdriftLinearFit");
555 //fNEvents = (TH1I *) fcalib.Get("NEvents");
557 if(!fAliTRDCalibraVdriftLinearFit) {
558 //printf("No AliTRDCalibraVdriftLinearFit\n");
564 //_____________________________________________________________________________________________________________
565 Bool_t AliTRDPreprocessorOffline::ReadExbAltFitGlobal(const Char_t* fileName){
567 // read calibration entries from file
569 if(fAliTRDCalibraExbAltFit) return kTRUE;
570 TFile fcalib(fileName);
571 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
573 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) array->FindObject("AliTRDCalibraExbAltFit");
574 //fNEvents = (TH1I *) array->FindObject("NEvents");
576 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) fcalib.Get("AliTRDCalibraExbAltFit");
577 //fNEvents = (TH1I *) fcalib.Get("NEvents");
579 if(!fAliTRDCalibraExbAltFit) {
580 //printf("No AliTRDCalibraExbAltFit\n");
586 //_____________________________________________________________________________________________________________
588 Bool_t AliTRDPreprocessorOffline::ReadPRFGlobal(const Char_t* fileName){
590 // read calibration entries from file
592 if(fPRF2d) return kTRUE;
593 TFile fcalib(fileName);
594 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
596 TProfile2D *prf2d = (TProfile2D *) array->FindObject("PRF2d");
597 if(!prf2d) return kFALSE;
598 fPRF2d = (TProfile2D*)prf2d->Clone();
599 //fNEvents = (TH1I *) array->FindObject("NEvents");
601 TProfile2D *prf2d = (TProfile2D *) fcalib.Get("PRF2d");
602 if(!prf2d) return kFALSE;
603 fPRF2d = (TProfile2D*)prf2d->Clone();
604 //fNEvents = (TH1I *) fcalib.Get("NEvents");
606 fPRF2d->SetDirectory(0);
607 //printf("title of PRF2d %s\n",fPRF2d->GetTitle());
612 //__________________________________________________________________________________________________________
614 Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
616 // Analyze gain - produce the calibration objects
619 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
620 calibra->ChooseMethod(fMethodeGain);
621 calibra->SetBeginFitCharge(fBeginFitCharge);
622 calibra->SetFitOutliersChargeLow(fOutliersFitChargeLow);
623 calibra->SetFitOutliersChargeHigh(fOutliersFitChargeHigh);
624 calibra->SetMinEntries(fMinStatsGain); // If there is less than 1000 entries in the histo: no fit
625 calibra->AnalyseCH(fCH2d);
627 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
628 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
629 Int_t nbfit = calibra->GetNumberFit();
630 Int_t nbE = calibra->GetNumberEnt();
634 Bool_t meanother = kFALSE;
637 (nbfit >= 0.5*nbE) && (nbE > 30)) {
638 // create the cal objects
639 if(!fBackCorrectGain) {
640 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
643 TObjArray object = calibra->GetVectorFit();
644 AliTRDCalDet *calDetGain = calibra->CreateDetObjectGain(&object,meanother);
645 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
646 // Put them in the array
647 fCalibObjects->AddAt(calDetGain,kGain);
648 fPlots->AddAt(coefGain,kGain);
653 fNotEnoughStatisticsForTheGain = kTRUE;
654 Int_t minStatsGain = fMinStatsGain*30;
655 calibra->SetMinEntries(minStatsGain); // Because we do it for all, we increase this
656 Double_t gainoverallnotnormalized = calibra->AnalyseCHAllTogether(fCH2d);
657 if(fCalDetGainUsed && (gainoverallnotnormalized > 0.0)) {
658 AliTRDCalDet *calDetGain = new AliTRDCalDet(*fCalDetGainUsed);
659 Double_t oldmean = fCalDetGainUsed->CalcMean(kFALSE);
660 //printf("oldmean %f\n",oldmean);
662 Double_t scalefactor = calibra->GetScaleFactorGain();
663 //printf("Correction factor %f\n",gainoverallnotnormalized*scalefactor);
664 calDetGain->Multiply(gainoverallnotnormalized*scalefactor/oldmean);
665 //printf("newmean %f\n",calDetGain->CalcMean(kFALSE));
666 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
667 fCalibObjects->AddAt(calDetGain,kGain);
668 fPlots->AddAt(coefGain,kGain);
671 fStatusNeg = fStatusNeg | kGainNotEnoughStatsButFill;
674 fStatusPos = fStatusPos | kGainErrorOld;
678 if(gainoverallnotnormalized <= 0.0) fStatusNeg = fStatusNeg | kGainNotEnoughStatsNotFill;
679 if(!fCalDetGainUsed) fStatusPos = fStatusPos | kGainErrorOld;
683 calibra->ResetVectorFit();
688 //_____________________________________________________________________________________________________
689 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftT0(){
691 // Analyze VdriftT0 - produce the calibration objects
694 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
695 calibra->SetMinEntries(fMinStatsVdriftT0PH); // If there is less than 1000 entries in the histo: no fit
696 calibra->AnalysePH(fPH2d);
698 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
699 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
700 Int_t nbfit = calibra->GetNumberFit();
701 Int_t nbfitSuccess = calibra->GetNumberFitSuccess();
702 Int_t nbE = calibra->GetNumberEnt();
704 //printf("nbtg %d, nbfit %d, nbE %d, nbfitSuccess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
708 (nbfit >= 0.5*nbE) && (nbE > 30) && (nbfitSuccess > 30)) {
709 //printf("Pass the cut for VdriftT0\n");
710 // create the cal objects
711 calibra->RemoveOutliers(1,kFALSE);
712 calibra->PutMeanValueOtherVectorFit(1,kFALSE);
713 calibra->RemoveOutliers2(kFALSE);
714 calibra->PutMeanValueOtherVectorFit2(1,kFALSE);
716 TObjArray object = calibra->GetVectorFit();
717 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object);
718 TH1F *coefVdriftPH = calDetVdrift->MakeHisto1DAsFunctionOfDet();
719 AliTRDCalPad *calPadVdrift = (AliTRDCalPad *)calibra->CreatePadObjectVdrift(&object,calDetVdrift);
720 TH1F *coefPadVdrift = calPadVdrift->MakeHisto1D();
721 object = calibra->GetVectorFit2();
722 AliTRDCalDet *calDetT0 = calibra->CreateDetObjectT0(&object);
723 TH1F *coefT0 = calDetT0->MakeHisto1DAsFunctionOfDet();
724 AliTRDCalPad *calPadT0 = (AliTRDCalPad *)calibra->CreatePadObjectT0(&object,calDetT0);
725 TH1F *coefPadT0 = calPadT0->MakeHisto1D();
726 // Put them in the array
727 fCalibObjects->AddAt(calDetT0,kT0PHDet);
728 fCalibObjects->AddAt(calDetVdrift,kVdriftPHDet);
729 fCalibObjects->AddAt(calPadT0,kT0PHPad);
730 fCalibObjects->AddAt(calPadVdrift,kVdriftPHPad);
731 fPlots->AddAt(coefVdriftPH,kVdriftPHDet);
732 fPlots->AddAt(coefT0,kT0PHDet);
733 fPlots->AddAt(coefPadVdrift,kVdriftPHPad);
734 fPlots->AddAt(coefPadT0,kT0PHPad);
739 //printf("Not enough stats timeoffset\n");
740 fStatusNeg = fStatusNeg | kTimeOffsetNotEnoughStatsNotFill;
742 calibra->ResetVectorFit();
747 //____________________________________________________________________________________________________________________
748 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftLinearFit(){
750 // Analyze vdrift linear fit - produce the calibration objects
753 //printf("Analyse linear fit\n");
756 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
757 calibra->SetCalDetVdriftExB(fCalDetVdriftUsed,fCalDetExBUsed);
758 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
759 //printf("Fill PE Array\n");
760 fAliTRDCalibraVdriftLinearFit->SetRobustFit(fRobustFitDriftVelocity);
761 if(!fAlternativeVdrfitFit)
762 fAliTRDCalibraVdriftLinearFit->FillPEArray();
764 fAliTRDCalibraVdriftLinearFit->FillPEArray2();
765 //printf("AliTRDCalibraFit\n");
766 calibra->AnalyseLinearFitters(fAliTRDCalibraVdriftLinearFit);
770 Int_t nbfit = calibra->GetNumberFit();
771 Int_t nbE = calibra->GetNumberEnt();
776 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
777 // create the cal objects
778 //calibra->RemoveOutliers(1,kTRUE);
779 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
780 //calibra->RemoveOutliers2(kTRUE);
781 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
783 TObjArray object = calibra->GetVectorFit();
784 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object,kTRUE);
785 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
786 object = calibra->GetVectorFit2();
787 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectLorentzAngle(&object);
788 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
789 //if(!calDetLorentz) printf("No lorentz created\n");
790 // Put them in the array
791 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
792 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
793 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
794 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
799 fNotEnoughStatisticsForTheVdriftLinear = kTRUE;
800 Int_t minNumberOfEntriesForAll = fMinStatsVdriftLinear*30;
801 calibra->SetMinEntries(minNumberOfEntriesForAll); // Because we do it for all, we increase this
802 Double_t vdriftoverall = -100.0;
803 Double_t exboverall = 100.0;
804 calibra->AnalyseLinearFittersAllTogether(fAliTRDCalibraVdriftLinearFit,vdriftoverall,exboverall);
805 //printf("Found mean vdrift %f and exb %f\n",vdriftoverall,exboverall);
806 if(fCalDetVdriftUsed && (vdriftoverall > 0.0) && (exboverall < 70.0)) {
807 AliTRDCalDet *calDetVdrift = new AliTRDCalDet(*fCalDetVdriftUsed);
808 AliTRDCalDet *calDetLorentz = new AliTRDCalDet(*fCalDetExBUsed);
809 Double_t oldmeanvdrift = fCalDetVdriftUsed->CalcMean(kFALSE);
810 Double_t oldmeanexb = fCalDetExBUsed->CalcMean(kFALSE);
811 //printf("oldmean %f\n",oldmean);
812 if((oldmeanvdrift > 0.0) && (oldmeanexb < 70.0)) {
813 //printf("Correction factor %f\n",vdriftoverall);
814 calDetVdrift->Multiply(vdriftoverall/oldmeanvdrift);
815 if(TMath::Abs(oldmeanexb) > 0.0001) calDetLorentz->Multiply(exboverall/oldmeanexb);
816 //printf("newmean %f\n",calDetVdrift->CalcMean(kFALSE));
817 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
818 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
819 // Put them in the array
820 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
821 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
822 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
823 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
826 fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsButFill;
829 if(oldmeanvdrift) fStatusPos = fStatusPos | kVdriftErrorOld;
830 if(oldmeanexb) fStatusPos = fStatusPos | kExBErrorOld;
834 if((vdriftoverall <= 0.0) && (exboverall > 70.0)) fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsNotFill;
835 if(!fCalDetVdriftUsed) fStatusPos = fStatusPos | kVdriftErrorOld;
836 if(!fCalDetExBUsed) fStatusPos = fStatusPos | kExBErrorOld;
840 calibra->ResetVectorFit();
845 //________________________________________________________________________________________________________________
847 Bool_t AliTRDPreprocessorOffline::AnalyzeExbAltFit(){
849 // Analyze vdrift linear fit - produce the calibration objects
852 //printf("Analyse linear fit\n");
855 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
856 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
857 //printf("Fill PE Array\n");
858 fAliTRDCalibraExbAltFit->SetRobustFit(fRobustFitExbAlt);
859 if(!fAlternativeExbAltFit)
860 fAliTRDCalibraExbAltFit->FillPEArray();
862 fAliTRDCalibraExbAltFit->FillPEArray2();
863 //printf("AliTRDCalibraFit\n");
864 calibra->AnalyseExbAltFit(fAliTRDCalibraExbAltFit);
868 Int_t nbfit = calibra->GetNumberFit();
869 Int_t nbE = calibra->GetNumberEnt();
874 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
875 // create the cal objects
876 //calibra->RemoveOutliers(1,kTRUE);
877 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
879 TObjArray object = calibra->GetVectorFit2();
880 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectExbAlt(&object);
881 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
882 //if(!calDetLorentz) printf("No lorentz created\n");
883 // Put them in the array
884 fCalibObjects->AddAt(calDetLorentz,kExbAlt);
885 fPlots->AddAt(coefLorentzAngle,kExbAlt);
890 calibra->ResetVectorFit();
895 //________________________________________________________________________________________________________________
897 Bool_t AliTRDPreprocessorOffline::AnalyzePRF(){
899 // Analyze PRF - produce the calibration objects
902 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
903 calibra->SetMinEntries(fMinStatsPRF); // If there is less than 1000 entries in the histo: no fit
904 calibra->AnalysePRFMarianFit(fPRF2d);
906 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
907 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
908 Int_t nbfit = calibra->GetNumberFit();
909 Int_t nbE = calibra->GetNumberEnt();
915 (nbfit >= 0.95*nbE) && (nbE > 30)) {
916 // create the cal objects
917 TObjArray object = calibra->GetVectorFit();
918 AliTRDCalPad *calPadPRF = (AliTRDCalPad*) calibra->CreatePadObjectPRF(&object);
919 TH1F *coefPRF = calPadPRF->MakeHisto1D();
920 // Put them in the array
921 fCalibObjects->AddAt(calPadPRF,kPRF);
922 fPlots->AddAt(coefPRF,kPRF);
927 calibra->ResetVectorFit();
933 //_____________________________________________________________________________
934 Bool_t AliTRDPreprocessorOffline::AnalyzePHQ(Int_t startRunNumber)
937 //Produce PHQ calibration results
939 AliTRDdEdxUtils::PrintControl();
941 for(Int_t iter=0; iter<8; iter++){
942 THnSparseD *hi = (THnSparseD*) AliTRDdEdxUtils::GetHistPHQ()->At(iter);
943 TObjArray *obji = AliTRDdEdxUtils::GetCalibObj(hi, startRunNumber);
944 //printf("test analyze %s\n", obji->GetName());
945 AliTRDdEdxUtils::GetObjPHQ()->AddAt(obji, iter);
948 fCalibObjects->AddAt(AliTRDdEdxUtils::GetObjPHQ(), kPHQ);
952 //_____________________________________________________________________________
953 Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
956 // Produce AliTRDCalChamberStatus out of calibration results
959 // set up AliTRDCalibChamberStatus
960 AliTRDCalibChamberStatus *chamberStatus = new AliTRDCalibChamberStatus();
961 chamberStatus->SetSparseI(fSparse);
962 chamberStatus->AnalyseHisto(fMinStatsChamberStatus, fMinSingleStatsChamberStatus);
963 // get AliTRDCalChamberStatus
964 AliTRDCalChamberStatus *calChamberStatus = chamberStatus->GetCalChamberStatus();
966 // get calibration objects
967 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
968 AliTRDCalDet *calDetVDrift = (AliTRDCalDet *) fCalibObjects->At(kVdriftLinear);
969 AliTRDCalDet *calDetExB = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
972 if((!calDetGain) || (!calDetVDrift) || (!fCH2d) || (!calDetExB) || (!calChamberStatus)) return kFALSE;
975 Double_t gainmean = calDetGain->GetMean();
976 Double_t vdriftmean = calDetVDrift->GetMean();
977 Double_t exbmean = calDetExB->GetMean();
979 Double_t gainrms = calDetGain->GetRMSRobust();
980 Double_t vdriftrms = calDetVDrift->GetRMSRobust();
981 Double_t exbrms = calDetExB->GetRMSRobust();
983 //printf("Gain mean: %f, rms: %f\n",gainmean,gainrms);
984 //printf("Vdrift mean: %f, rms: %f\n",vdriftmean,vdriftrms);
985 //printf("ExB mean: %f, rms: %f\n",exbmean,exbrms);
988 if((TMath::Abs(gainrms) < 0.001) || (TMath::Abs(vdriftrms) < 0.001) || (TMath::Abs(exbrms) < 0.0000001)) return kFALSE;
990 // mask chambers with empty gain entries
992 for (Int_t idet = 0; idet < 540; idet++) {
995 TH1I *projch = (TH1I *) fCH2d->ProjectionX("projch",idet+1,idet+1,(Option_t *)"e");
996 Double_t entries = projch->GetEntries();
997 //printf("Number of entries %f for det %d\n",entries,idet);
1000 Double_t gain = calDetGain->GetValue(idet);
1003 Double_t vdrift = calDetVDrift->GetValue(idet);
1006 Double_t exb = calDetExB->GetValue(idet);
1009 if( (entries<50 && !calChamberStatus->IsNoData(idet)) ||
1010 TMath::Abs(gainmean-gain) > (fRMSBadCalibratedGain*gainrms) ||
1011 TMath::Abs(vdriftmean-vdrift) > (fRMSBadCalibratedVdrift*vdriftrms) ||
1012 TMath::Abs(exbmean-exb) > (fRMSBadCalibratedExB*exbrms) ) {
1014 //printf(" chamber det %03d masked \n",idet);
1015 //printf(" gainmean %f and gain %f, gainrms %f \n",gainmean,gain,gainrms);
1016 //printf(" vdriftmean %f and vdrift %f, vdriftrms %f \n",vdriftmean,vdrift,vdriftrms);
1017 //printf(" exbmean %f and exb %f, exbrms %f \n",exbmean,exb,exbrms);
1019 calChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kBadCalibrated);
1028 for(Int_t sm=0; sm < 18; sm++) {
1030 Int_t smbadcalib = 0;
1031 for(Int_t det = 0; det < 30; det++){
1032 Int_t detector = sm*30+det;
1033 if(calChamberStatus->IsNoData(detector)) smnodata++;
1035 if(calChamberStatus->IsBadCalibrated(detector)) smbadcalib++;
1038 fNoData[sm] = smnodata;
1039 fBadCalib[sm]= smbadcalib;
1040 //printf("No Data %d, bad calibrated %d for %d\n",fNoData[sm],fBadCalib[sm],sm);
1044 // for(Int_t sm=0; sm < 18; sm++) {
1045 // Int_t counter = 0;
1046 // for(Int_t det = 0; det < 30; det++){
1047 // Int_t detector = sm*30+det;
1048 // if(calChamberStatus->IsBadCalibrated(detector)) counter++;
1050 // if(counter >= 20) {
1051 // for(Int_t det = 0; det < 30; det++){
1052 // Int_t detector = sm*30+det;
1053 // calChamberStatus->SetStatus(detector,AliTRDCalChamberStatus::kGood);
1058 fCalibObjects->AddAt(calChamberStatus,kChamberStatus);
1064 //________________________________________________________________________________________________
1065 void AliTRDPreprocessorOffline::CorrectFromDetGainUsed() {
1067 // Correct from the gas gain used afterwards
1069 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1070 if(!calDetGain) return;
1073 Double_t mean = 0.0;
1076 for(Int_t det = 0; det < 540; det++) {
1078 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1079 Float_t gainout = calDetGain->GetValue(det);
1082 if(TMath::Abs(gainout-1.0) > 0.000001) {
1083 mean += (gaininit*gainout);
1087 if(nbdet > 0) mean = mean/nbdet;
1089 for(Int_t det = 0; det < 540; det++) {
1091 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1092 Float_t gainout = calDetGain->GetValue(det);
1094 if(TMath::Abs(gainout-1.0) > 0.000001) {
1095 Double_t newgain = gaininit*gainout;
1096 if(newgain < 0.1) newgain = 0.1;
1097 if(newgain > 1.9) newgain = 1.9;
1098 calDetGain->SetValue(det,newgain);
1101 Double_t newgain = mean;
1102 if(newgain < 0.1) newgain = 0.1;
1103 if(newgain > 1.9) newgain = 1.9;
1104 calDetGain->SetValue(det,newgain);
1110 //________________________________________________________________________________________________
1111 void AliTRDPreprocessorOffline::CorrectFromDetVdriftUsed() {
1113 // Correct from the drift velocity
1116 //printf("Correct for vdrift\n");
1118 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1119 if(!calDetGain) return;
1121 Int_t detVdrift = kVdriftPHDet;
1122 if(fMethodSecond) detVdrift = kVdriftLinear;
1123 AliTRDCalDet *calDetVdrift = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1124 if(!calDetVdrift) return;
1127 if(!fNotEnoughStatisticsForTheVdriftLinear) {
1128 for(Int_t det = 0; det < 540; det++) {
1130 Float_t vdriftinit = fCalDetVdriftUsed->GetValue(det);
1131 Float_t vdriftout = calDetVdrift->GetValue(det);
1133 Float_t gain = calDetGain->GetValue(det);
1134 if(vdriftout > 0.0) gain = gain*vdriftinit/vdriftout;
1135 if(gain < 0.1) gain = 0.1;
1136 if(gain > 1.9) gain = 1.9;
1137 calDetGain->SetValue(det,gain);
1142 Float_t vdriftinit = fCalDetVdriftUsed->CalcMean(kFALSE);
1143 Float_t vdriftout = calDetVdrift->CalcMean(kFALSE);
1144 Float_t factorcorrectif = 1.0;
1145 if(vdriftout > 0.0) factorcorrectif = vdriftinit/vdriftout;
1146 for(Int_t det = 0; det < 540; det++) {
1147 Float_t gain = calDetGain->GetValue(det);
1148 gain = gain*factorcorrectif;
1149 if(gain < 0.1) gain = 0.1;
1150 if(gain > 1.9) gain = 1.9;
1151 calDetGain->SetValue(det,gain);
1157 //_________________________________________________________________________________________________________________
1158 void AliTRDPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1160 // Update OCDB entry
1163 AliCDBMetaData *metaData= new AliCDBMetaData();
1164 metaData->SetObjectClassName("AliTRDCalDet");
1165 metaData->SetResponsible("Raphaelle Bailhache");
1166 metaData->AddDateToComment();
1167 metaData->SetBeamPeriod(1);
1169 AliCDBId id1("TRD/Calib/ChamberGainFactor", startRunNumber, endRunNumber);
1170 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1171 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1172 if(calDet) gStorage->Put(calDet, id1, metaData);
1176 //___________________________________________________________________________________________________________________
1177 void AliTRDPreprocessorOffline::UpdateOCDBExB(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1179 // Update OCDB entry
1182 Int_t detExB = kLorentzLinear;
1183 if(!fMethodSecond) return;
1187 AliCDBMetaData *metaData= new AliCDBMetaData();
1188 metaData->SetObjectClassName("AliTRDCalDet");
1189 metaData->SetResponsible("Raphaelle Bailhache");
1190 metaData->AddDateToComment();
1191 metaData->SetBeamPeriod(1);
1193 AliCDBId id1("TRD/Calib/ChamberExB", startRunNumber, endRunNumber);
1194 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1195 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1196 if(calDet) gStorage->Put(calDet, id1, metaData);
1197 //if(!calDet) printf("No caldet\n");
1200 //___________________________________________________________________________________________________________________
1201 void AliTRDPreprocessorOffline::UpdateOCDBExBAlt(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1203 // Update OCDB entry
1206 Int_t detExB = kExbAlt;
1207 if(!fMethodSecond) return;
1211 AliCDBMetaData *metaData= new AliCDBMetaData();
1212 metaData->SetObjectClassName("AliTRDCalDet");
1213 metaData->SetResponsible("Theo Rascanu");
1214 metaData->AddDateToComment();
1215 metaData->SetBeamPeriod(1);
1217 AliCDBId id1("TRD/Calib/ChamberExBAlt", startRunNumber, endRunNumber);
1218 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1219 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1220 if(calDet) gStorage->Put(calDet, id1, metaData);
1221 //if(!calDet) printf("No caldet\n");
1224 //___________________________________________________________________________________________________________________
1225 void AliTRDPreprocessorOffline::UpdateOCDBVdrift(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1227 // Update OCDB entry
1230 Int_t detVdrift = kVdriftPHDet;
1232 if(fMethodSecond) detVdrift = kVdriftLinear;
1234 AliCDBMetaData *metaData= new AliCDBMetaData();
1235 metaData->SetObjectClassName("AliTRDCalDet");
1236 metaData->SetResponsible("Raphaelle Bailhache");
1237 metaData->AddDateToComment();
1238 metaData->SetBeamPeriod(1);
1240 AliCDBId id1("TRD/Calib/ChamberVdrift", startRunNumber, endRunNumber);
1241 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1242 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1243 if(calDet) gStorage->Put(calDet, id1, metaData);
1247 if(!fMethodSecond) {
1249 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1250 metaDataPad->SetObjectClassName("AliTRDCalPad");
1251 metaDataPad->SetResponsible("Raphaelle Bailhache");
1252 metaDataPad->AddDateToComment();
1253 metaDataPad->SetBeamPeriod(1);
1255 AliCDBId id1Pad("TRD/Calib/LocalVdrift", startRunNumber, endRunNumber);
1256 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1257 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
1262 //________________________________________________________________________________________________________________________
1263 void AliTRDPreprocessorOffline::UpdateOCDBT0(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1265 // Update OCDB entry
1268 AliCDBMetaData *metaData= new AliCDBMetaData();
1269 metaData->SetObjectClassName("AliTRDCalDet");
1270 metaData->SetResponsible("Raphaelle Bailhache");
1271 metaData->AddDateToComment();
1272 metaData->SetBeamPeriod(1);
1274 AliCDBId id1("TRD/Calib/ChamberT0", startRunNumber, endRunNumber);
1275 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1276 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1277 if(calDet) gStorage->Put(calDet, id1, metaData);
1281 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1282 metaDataPad->SetObjectClassName("AliTRDCalPad");
1283 metaDataPad->SetResponsible("Raphaelle Bailhache");
1284 metaDataPad->AddDateToComment();
1285 metaDataPad->SetBeamPeriod(1);
1287 AliCDBId id1Pad("TRD/Calib/LocalT0", startRunNumber, endRunNumber);
1288 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1289 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
1294 //_________________________________________________________________________________________________________________
1295 void AliTRDPreprocessorOffline::UpdateOCDBPRF(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1297 // Update OCDB entry
1300 AliCDBMetaData *metaData= new AliCDBMetaData();
1301 metaData->SetObjectClassName("AliTRDCalPad");
1302 metaData->SetResponsible("Raphaelle Bailhache");
1303 metaData->AddDateToComment();
1304 metaData->SetBeamPeriod(1);
1307 AliCDBId id1("TRD/Calib/PRFWidth", startRunNumber, endRunNumber);
1308 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1309 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1310 if(calPad) gStorage->Put(calPad, id1, metaData);
1314 //_________________________________________________________________________________________________________________
1315 void AliTRDPreprocessorOffline::UpdateOCDBPHQ(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath)
1318 // Update OCDB entry
1320 AliCDBMetaData *metaData= new AliCDBMetaData();
1321 metaData->SetObjectClassName("TObjArray");
1322 metaData->SetResponsible("Raphaelle Bailhache and Xianguo Lu");
1323 metaData->AddDateToComment();
1324 metaData->SetBeamPeriod(1);
1326 AliCDBId id1("TRD/Calib/PHQ", startRunNumber, endRunNumber);
1327 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1328 TObjArray *cobj = (TObjArray *) fCalibObjects->At(kPHQ);
1331 gStorage->Put(cobj, id1, metaData);
1335 //_________________________________________________________________________________________________________________
1336 void AliTRDPreprocessorOffline::UpdateOCDBChamberStatus(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1338 // Update OCDB entry
1341 AliCDBMetaData *metaData= new AliCDBMetaData();
1342 metaData->SetObjectClassName("AliTRDCalChamberStatus");
1343 metaData->SetResponsible("Raphaelle Bailhache and Julian Book");
1344 metaData->AddDateToComment();
1345 metaData->SetBeamPeriod(1);
1347 AliCDBId id1("TRD/Calib/ChamberStatus", startRunNumber, endRunNumber);
1348 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1349 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1350 if(calChamberStatus) gStorage->Put(calChamberStatus, id1, metaData);
1354 //__________________________________________________________________________________________________________________________
1355 Bool_t AliTRDPreprocessorOffline::ValidateGain() {
1357 // Validate OCDB entry
1360 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1362 Double_t mean = calDet->GetMean();
1363 Double_t rms = calDet->GetRMSRobust();
1364 if((mean > 0.2) && (mean < 1.4) && (rms < 0.5)) return kTRUE;
1365 //if((mean > 0.2) && (mean < 1.4)) return kTRUE;
1367 fStatusPos = fStatusPos | kGainErrorRange;
1376 //__________________________________________________________________________________________________________________________
1377 Bool_t AliTRDPreprocessorOffline::ValidateVdrift(){
1379 // Update OCDB entry
1382 Int_t detVdrift = kVdriftPHDet;
1385 if(fMethodSecond) detVdrift = kVdriftLinear;
1387 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1389 Double_t mean = calDet->GetMean();
1390 Double_t rms = calDet->GetRMSRobust();
1391 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1392 if(!((mean > 1.0) && (mean < 2.0) && (rms < 0.5))) {
1393 fStatusPos = fStatusPos | kVdriftErrorRange;
1399 if(!fMethodSecond) {
1400 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1402 Double_t mean = calPad->GetMean();
1403 Double_t rms = calPad->GetRMS();
1404 //printf("Vdrift::meanpad %f, rmspad %f\n",mean,rms);
1405 if(!((mean > 0.9) && (mean < 1.1) && (rms < 0.6))) {
1406 fStatusPos = fStatusPos | kVdriftErrorRange;
1416 //__________________________________________________________________________________________________________________________
1417 Bool_t AliTRDPreprocessorOffline::ValidateExB(){
1419 // Update OCDB entry
1422 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
1424 Double_t mean = calDet->GetMean();
1425 Double_t rms = calDet->GetRMSRobust();
1426 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1427 if(!((mean > -1.0) && (mean < 1.0) && (rms < 0.5))) {
1428 fStatusNeg = fStatusNeg | kExBErrorRange;
1436 //__________________________________________________________________________________________________________________________
1437 Bool_t AliTRDPreprocessorOffline::ValidateT0(){
1439 // Update OCDB entry
1442 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1443 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1444 if(calDet && calPad) {
1445 Double_t meandet = calDet->GetMean();
1446 Double_t rmsdet = calDet->GetRMSRobust();
1447 Double_t meanpad = calPad->GetMean();
1448 //Double_t rmspad = calPad->GetRMS();
1449 //printf("T0::minimum %f, rmsdet %f,meanpad %f, rmspad %f\n",meandet,rmsdet,meanpad,rmspad);
1450 if((meandet > -1.5) && (meandet < 5.0) && (rmsdet < 4.0) && (meanpad < 5.0) && (meanpad > -0.5)) return kTRUE;
1452 fStatusPos = fStatusPos | kTimeOffsetErrorRange;
1459 //__________________________________________________________________________________________________________________________
1460 Bool_t AliTRDPreprocessorOffline::ValidatePRF() const{
1462 // Update OCDB entry
1465 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1467 Double_t meanpad = calPad->GetMean();
1468 Double_t rmspad = calPad->GetRMS();
1469 //printf("PRF::meanpad %f, rmspad %f\n",meanpad,rmspad);
1470 if((meanpad < 1.0) && (rmspad < 0.8)) return kTRUE;
1477 //__________________________________________________________________________________________________________________________
1478 Bool_t AliTRDPreprocessorOffline::ValidateChamberStatus(){
1480 // Update OCDB entry
1483 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1484 if(calChamberStatus) {
1486 Int_t detectornodata = 0;
1487 Int_t detectorbadcalib = 0;
1489 for(Int_t sm=0; sm < 18; sm++) {
1490 //printf("%d chambers w/o data in sm %d\n",fNoData[sm],sm);
1491 //printf("%d bad calibrated chambers in sm %d\n",fBadCalib[sm],sm);
1492 if(fNoData[sm] != 30) detectornodata += fNoData[sm];
1493 detectorbadcalib+=fBadCalib[sm];
1495 //printf("Number of chambers w/o data %d\n",detectornodata);
1496 //printf("Number of chambers bad calibrated %d\n",detectorbadcalib);
1498 if((detectornodata > fNoDataValidate) ||
1499 (detectorbadcalib > fBadCalibValidate)){
1500 fStatusPos = fStatusPos | kChamberStatusErrorRange;
1508 //_____________________________________________________________________________
1509 Int_t AliTRDPreprocessorOffline::GetVersion(TString name) const
1512 // Get version from the title
1516 const Char_t *version = "Ver";
1517 if(!strstr(name.Data(),version)) return -1;
1518 const Char_t *after = "Subver";
1519 if(!strstr(name.Data(),after)) return -1;
1521 for(Int_t ver = 0; ver < 999999999; ver++) {
1523 TString vertry(version);
1527 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1529 if(strstr(name.Data(),vertry.Data())) return ver;
1537 //_____________________________________________________________________________
1538 Int_t AliTRDPreprocessorOffline::GetSubVersion(TString name) const
1541 // Get subversion from the title
1545 const Char_t *subversion = "Subver";
1546 if(!strstr(name.Data(),subversion)) return -1;
1547 const Char_t *after = "FirstRun";
1548 if(!strstr(name.Data(),after)) {
1551 if(!strstr(name.Data(),after)) return -1;
1554 for(Int_t ver = 0; ver < 999999999; ver++) {
1556 TString vertry(subversion);
1560 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1562 if(strstr(name.Data(),vertry.Data())) return ver;
1570 //_____________________________________________________________________________
1571 Int_t AliTRDPreprocessorOffline::GetFirstRun(TString name) const
1574 // Get first run from the title
1578 const Char_t *firstrun = "FirstRun";
1579 if(!strstr(name.Data(),firstrun)) return -1;
1580 const Char_t *after = "Nz";
1581 if(!strstr(name.Data(),after)) return -1;
1584 for(Int_t ver = 0; ver < 999999999; ver++) {
1586 TString vertry(firstrun);
1590 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1592 if(strstr(name.Data(),vertry.Data())) return ver;
1599 //_____________________________________________________________________________
1600 Bool_t AliTRDPreprocessorOffline::CheckStatus(Int_t status, Int_t bitMask) const
1603 // Checks the status
1606 return (status & bitMask) ? kTRUE : kFALSE;
1609 //_____________________________________________________________________________
1610 Int_t AliTRDPreprocessorOffline::GetStatus() const
1613 // Checks the status
1614 // fStatusPos: errors
1615 // fStatusNeg: only info
1618 if(fStatusPos > 0) return fStatusPos;
1619 else return (-TMath::Abs(fStatusNeg));
1622 //_____________________________________________________________________________
1623 void AliTRDPreprocessorOffline::PrintStatus() const
1629 AliInfo(Form("The error status is %d",fStatusPos));
1630 AliInfo(Form("IsGainErrorOld? %d",(Int_t)IsGainErrorOld()));
1631 AliInfo(Form("IsVdriftErrorOld? %d",(Int_t)IsVdriftErrorOld()));
1632 AliInfo(Form("IsGainErrorRange? %d",(Int_t)IsGainErrorRange()));
1633 AliInfo(Form("IsVdriftErrorRange? %d",(Int_t)IsVdriftErrorRange()));
1634 AliInfo(Form("IsTimeOffsetErrorRange? %d",(Int_t)IsTimeOffsetErrorRange()));
1635 AliInfo(Form("IsChamberStatusErrorRange? %d",(Int_t)IsChamberStatusErrorRange()));
1638 AliInfo(Form("The info status is %d",fStatusNeg));
1639 AliInfo(Form("IsGainNotEnoughStatsButFill? %d",(Int_t)IsGainNotEnoughStatsButFill()));
1640 AliInfo(Form("IsVdriftNotEnoughStatsButFill? %d",(Int_t)IsVdriftNotEnoughStatsButFill()));
1641 AliInfo(Form("IsGainNotEnoughStatsNotFill? %d",(Int_t)IsGainNotEnoughStatsNotFill()));
1642 AliInfo(Form("IsVdriftNotEnoughStatsNotFill? %d",(Int_t)IsVdriftNotEnoughStatsNotFill()));
1643 AliInfo(Form("IsTimeOffsetNotEnoughStatsNotFill? %d",(Int_t)IsTimeOffsetNotEnoughStatsNotFill()));
1645 AliInfo(Form("IsExBErrorRange? %d",(Int_t)IsExBErrorRange()));
1646 AliInfo(Form("IsExBErrorOld? %d",(Int_t)IsExBErrorOld()));
1649 //___________________________________________________________________________________
1650 void AliTRDPreprocessorOffline::SetCalDetVdrift(AliTRDCalDet *calDetVdriftUsed)
1653 fCalDetVdriftUsed = calDetVdriftUsed;
1655 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1656 for(Int_t k = 0; k < 540; k++){
1657 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1658 //printf("Set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1662 //___________________________________________________________________________________
1663 Bool_t AliTRDPreprocessorOffline::SetCalDetGain(Int_t runNumber, Int_t version, Int_t subversion)
1666 // Set the fCalDetGainUsed
1669 if((version == 0) && (subversion == 0)) return kFALSE;
1671 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor",runNumber, version, subversion);
1673 AliError("Found no entry\n");
1674 fStatusPos = fStatusPos | kGainErrorOld;
1677 //const AliCDBId id = entry->GetId();
1678 //version = id.GetVersion();
1679 //subversion = id.GetSubVersion();
1680 //printf("Found version %d and subversion %d for vdrift\n",version,subversion);
1681 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1682 if(calDet) fCalDetGainUsed = calDet;
1684 fStatusPos = fStatusPos | kGainErrorOld;
1691 //___________________________________________________________________________________
1692 Bool_t AliTRDPreprocessorOffline::SetCalDetVdriftExB(Int_t runNumber, Int_t versionv, Int_t subversionv, Int_t versionexb, Int_t subversionexb)
1695 // Set the fCalDetVdriftUsed and fCalDetExBUsed
1698 if((versionv == 0) && (subversionv == 0)) return kFALSE;
1700 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberVdrift",runNumber, versionv, subversionv);
1702 AliError("Found no entry\n");
1703 fStatusPos = fStatusPos | kVdriftErrorOld;
1706 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1707 if(calDet) fCalDetVdriftUsed = calDet;
1709 fStatusPos = fStatusPos | kVdriftErrorOld;
1715 if((versionexb == 0) && (subversionexb == 0)) {
1717 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1718 for(Int_t k = 0; k < 540; k++){
1719 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1720 //printf("Nothing found: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1726 entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberExB",runNumber, versionexb, subversionexb);
1728 //printf("Found no entry\n");
1729 fStatusPos = fStatusPos | kExBErrorOld;
1732 AliTRDCalDet* calDetexb = (AliTRDCalDet *)entry->GetObject();
1734 fStatusPos = fStatusPos | kExBErrorOld;
1738 Double_t meanexb = calDetexb->GetMean();
1739 //printf("Mean value %f\n",meanexb);
1740 if((meanexb > 70) || (fNoExBUsedInReco)) {
1741 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1742 for(Int_t k = 0; k < 540; k++){
1743 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1744 //printf("Found but: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1748 fCalDetExBUsed = calDetexb;