1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
19 Responsible: Raphaelle Bailhache (rbailhache@ikf.uni-frankfurt.de)
20 Code to analyze the TRD calibration and to produce OCDB entries
24 gSystem->Load("libANALYSIS");
25 gSystem->Load("libTRDcalib");
27 AliTRDPreprocessorOffline proces;
28 TString ocdbPath="local:////"
29 ocdbPath+=gSystem->GetFromPipe("pwd");
31 proces.CalibTimeGain("CalibObjects.root",run0,run1,ocdbPath);
32 proces.CalibTimeVdrift("CalibObjects.root",run0,run1,ocdbPath);
33 // take the raw calibration data from the file CalibObjects.root
34 // and make a OCDB entry with run validity run0-run1
35 // results are stored at the ocdbPath - local or alien ...
36 // default storage ""- data stored at current working directory
40 #include "Riostream.h"
50 #include "THnSparse.h"
51 #include "TProfile2D.h"
52 #include "AliTRDCalDet.h"
53 #include "AliTRDCalPad.h"
54 #include "AliCDBMetaData.h"
56 #include "AliCDBManager.h"
57 #include "AliCDBStorage.h"
58 #include "AliTRDCalibraMode.h"
59 #include "AliTRDCalibraFit.h"
60 #include "AliTRDCalibraVdriftLinearFit.h"
61 #include "AliTRDCalibraExbAltFit.h"
62 #include "AliTRDPreprocessorOffline.h"
63 #include "AliTRDCalChamberStatus.h"
64 #include "AliTRDCalibChamberStatus.h"
65 #include "AliTRDCommonParam.h"
66 #include "AliCDBManager.h"
67 #include "AliCDBEntry.h"
68 #include "AliTRDdEdxBaseUtils.h"
69 #include "AliTRDdEdxCalibHistArray.h"
70 #include "AliTRDdEdxCalibUtils.h"
72 ClassImp(AliTRDPreprocessorOffline)
74 AliTRDPreprocessorOffline::AliTRDPreprocessorOffline():
75 TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
77 fNameList("TRDCalib"),
79 fCalDetVdriftUsed(0x0),
85 fAliTRDCalibraVdriftLinearFit(0x0),
86 fAliTRDCalibraExbAltFit(0x0),
89 fPlots(new TObjArray(kNumCalibObjs)),
90 fCalibObjects(new TObjArray(kNumCalibObjs)),
93 fSubVersionGainUsed(0),
94 fFirstRunVdriftUsed(0),
95 fVersionVdriftUsed(0),
96 fSubVersionVdriftUsed(0),
99 fSubVersionExBUsed(0),
100 fNoExBUsedInReco(kFALSE),
101 fSwitchOnValidation(kTRUE),
102 fVdriftValidated(kFALSE),
103 fExBValidated(kFALSE),
104 fT0Validated(kFALSE),
105 fMinStatsVdriftT0PH(800*20),
106 fMinStatsVdriftLinear(800),
109 fMinStatsChamberStatus(20),
110 fMinSingleStatsChamberStatus(0.05),
111 fBackCorrectGain(kFALSE),
112 fBackCorrectVdrift(kTRUE),
113 fNotEnoughStatisticsForTheGain(kFALSE),
114 fNotEnoughStatisticsForTheVdriftLinear(kFALSE),
117 fBadCalibValidate(40),
119 fRMSBadCalibratedGain(20.0),
120 fRMSBadCalibratedVdrift(20.0),
121 fRMSBadCalibratedExB(20.0),
122 fMinTimeOffsetValidate(-1.6),
123 fRobustFitDriftVelocity(kTRUE),
124 fRobustFitExbAlt(kFALSE),
125 fAlternativeVdrfitFit(kFALSE),
126 fAlternativeExbAltFit(kFALSE),
127 fMinNbOfPointVdriftFit(11),
129 fOutliersFitChargeLow(0.03),
130 fOutliersFitChargeHigh(0.7),
131 fBeginFitCharge(3.5),
138 // default constructor
141 memset(fBadCalib, 0, sizeof(Int_t) * 18);
142 memset(fNoData, 0, sizeof(Int_t) * 18);
144 //_________________________________________________________________________________________________________________
145 AliTRDPreprocessorOffline::~AliTRDPreprocessorOffline() {
150 if(fCalDetGainUsed) delete fCalDetGainUsed;
151 if(fCalDetVdriftUsed) delete fCalDetVdriftUsed;
152 if(fCalDetExBUsed) delete fCalDetExBUsed;
153 if(fCH2d) delete fCH2d;
154 if(fPH2d) delete fPH2d;
155 if(fPRF2d) delete fPRF2d;
156 if(fSparse) delete fSparse;
159 AliTRDdEdxCalibUtils::DeleteHistArray();
160 AliTRDdEdxCalibUtils::DeleteObjArray();
163 if(fAliTRDCalibraVdriftLinearFit) delete fAliTRDCalibraVdriftLinearFit;
164 if(fAliTRDCalibraExbAltFit) delete fAliTRDCalibraExbAltFit;
165 if(fNEvents) delete fNEvents;
166 if(fAbsoluteGain) delete fAbsoluteGain;
167 if(fPlots) delete fPlots;
168 if(fCalibObjects) delete fCalibObjects;
171 //___________________________________________________________________________________
172 void AliTRDPreprocessorOffline::Process(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage)
175 // Process to the gain, vdrift, timeoffset, exb and chamber status calibration
178 if(SetCalDetGain(startRunNumber,fVersionGainUsed,fSubVersionGainUsed) && SetCalDetVdriftExB(startRunNumber,fVersionVdriftUsed,fSubVersionVdriftUsed,fVersionExBUsed,fSubVersionExBUsed)) {
180 CalibVdriftT0(file,startRunNumber,endRunNumber,ocdbStorage);
181 CalibGain(file,startRunNumber,endRunNumber,ocdbStorage);
182 CalibChamberStatus(file,startRunNumber,endRunNumber,ocdbStorage);
183 CalibExbAlt(file,startRunNumber,endRunNumber,ocdbStorage);
188 printf("\n AliTRDPreprocessorOffline PHQ on!!\n\n");
189 AliTRDdEdxBaseUtils::PrintControl();
190 CalibPHQ(file, startRunNumber, endRunNumber, ocdbStorage);
193 printf("\n AliTRDPreprocessorOffline PHQ off!!\n\n");
199 //___________________________________________________________________________________________________________________
201 void AliTRDPreprocessorOffline::CalibVdriftT0(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
203 // make calibration of the drift velocity
205 // file - the location of input file
206 // startRunNumber, endRunNumber - run validity period
207 // ocdbStorage - OCDB storage
208 // - if empty - local storage 'pwd' uesed
209 if (ocdbStorage==0x0) {
210 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
211 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
216 fVdriftValidated = kTRUE;
217 fT0Validated = kTRUE;
218 fExBValidated = kTRUE;
219 fNotEnoughStatisticsForTheVdriftLinear = kFALSE;
221 // 2. extraction of the information
223 if(ReadVdriftLinearFitGlobal(file) && fCalDetVdriftUsed && fCalDetExBUsed) AnalyzeVdriftLinearFit();
224 if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
226 // 3. Append QA plots
228 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
231 // 4. validate OCDB entries
233 if(fSwitchOnValidation==kTRUE && ValidateVdrift()==kFALSE) {
234 //AliError("TRD vdrift OCDB parameters out of range!");
235 fVdriftValidated = kFALSE;
237 if(fSwitchOnValidation==kTRUE && ValidateT0()==kFALSE) {
238 //AliError("TRD t0 OCDB parameters out of range!");
239 fT0Validated = kFALSE;
241 if(fSwitchOnValidation==kTRUE && ValidateExB()==kFALSE) {
242 //AliError("TRD t0 OCDB parameters out of range!");
243 fExBValidated = kFALSE;
249 if(fVdriftValidated) UpdateOCDBVdrift(startRunNumber,endRunNumber,ocdbStorage);
250 if(fT0Validated) UpdateOCDBT0(startRunNumber,endRunNumber,ocdbStorage);
251 if(fExBValidated) UpdateOCDBExB(startRunNumber,endRunNumber,ocdbStorage);
254 //___________________________________________________________________________________________________________________
256 void AliTRDPreprocessorOffline::CalibExbAlt(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
258 // make calibration of the drift velocity
260 // file - the location of input file
261 // startRunNumber, endRunNumber - run validity period
262 // ocdbStorage - OCDB storage
263 // - if empty - local storage 'pwd' uesed
264 if (ocdbStorage==0x0) {
265 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
266 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
273 // 2. extraction of the information
275 if(ReadExbAltFitGlobal(file)) AnalyzeExbAltFit();
277 // 3. Append QA plots
279 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
282 // 4. validate OCDB entries
288 UpdateOCDBExBAlt(startRunNumber,endRunNumber,ocdbStorage);
292 //_________________________________________________________________________________________________________________
294 void AliTRDPreprocessorOffline::CalibGain(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
296 // make calibration of the drift velocity
298 // file - the location of input file
299 // startRunNumber, endRunNumber - run validity period
300 // ocdbStorage - OCDB storage
301 // - if empty - local storage 'pwd' uesed
302 if (ocdbStorage==0x0) {
303 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
304 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
307 fNotEnoughStatisticsForTheGain = kFALSE;
310 if(!ReadGainGlobal(file)) return;
313 // 2. extraction of the information
316 if(fBackCorrectGain) CorrectFromDetGainUsed();
317 //if(fBackCorrectVdrift) CorrectFromDetVdriftUsed();
319 // 3. Append QA plots
321 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
324 // 4. validate OCDB entries
326 if(fSwitchOnValidation==kTRUE && ValidateGain()==kFALSE) {
327 //AliError("TRD gain OCDB parameters out of range!");
334 if((!fCalDetVdriftUsed) || (fCalDetVdriftUsed && fVdriftValidated)) UpdateOCDBGain(startRunNumber,endRunNumber,ocdbStorage);
338 //________________________________________________________________________________________________________________
340 void AliTRDPreprocessorOffline::CalibPRF(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
342 // make calibration of the drift velocity
344 // file - the location of input file
345 // startRunNumber, endRunNumber - run validity period
346 // ocdbStorage - OCDB storage
347 // - if empty - local storage 'pwd' uesed
348 if (ocdbStorage==0x0) {
349 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
350 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
354 if(!ReadPRFGlobal(file)) return;
357 // 2. extraction of the information
361 // 3. Append QA plots
363 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
367 // 4. validate OCDB entries
369 if(fSwitchOnValidation==kTRUE && ValidatePRF()==kFALSE) {
370 //AliError("TRD prf OCDB parameters out of range!");
377 UpdateOCDBPRF(startRunNumber,endRunNumber,ocdbStorage);
380 //________________________________________________________________________________________________________________
381 void AliTRDPreprocessorOffline::CalibPHQ(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage)
384 // make calibration of puls height Q
386 // startRunNumber, endRunNumber - run validity period
387 // ocdbStorage - OCDB storage
388 // - if empty - local storage 'pwd' uesed
391 if (ocdbStorage==0x0) {
392 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
393 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
395 //printf("test %s\n", ocdbStorage.Data());
397 if(!ReadPHQGlobal(file)) return;
399 if(!AnalyzePHQ(startRunNumber)) return;
401 UpdateOCDBPHQ(startRunNumber,endRunNumber,ocdbStorage);
404 //________________________________________________________________________________________________________________
406 void AliTRDPreprocessorOffline::CalibChamberStatus(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
408 // make calibration of the chamber status
410 // startRunNumber, endRunNumber - run validity period
411 // ocdbStorage - OCDB storage
412 // - if empty - local storage 'pwd' uesed
413 if (ocdbStorage==0x0) {
414 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
415 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
420 if(!ReadStatusGlobal(file)) return;
424 // 2. extraction of the information
426 if(!AnalyzeChamberStatus()) return;
428 // 3. Append QA plots
430 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
434 // 4. validate OCDB entries
436 if(fSwitchOnValidation==kTRUE && ValidateChamberStatus()==kFALSE) {
437 //AliError("TRD Chamber status OCDB parameters not ok!");
444 if((!fNotEnoughStatisticsForTheVdriftLinear) && (!fNotEnoughStatisticsForTheGain)) UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
445 //UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
448 //______________________________________________________________________________________________________
449 Bool_t AliTRDPreprocessorOffline::Init(const Char_t* fileName){
451 // read the calibration used during the reconstruction
454 if(ReadVdriftT0Global(fileName)) {
456 TString nameph = fPH2d->GetTitle();
457 fFirstRunVdriftUsed = GetFirstRun(nameph);
458 fVersionVdriftUsed = GetVersion(nameph);
459 fSubVersionVdriftUsed = GetSubVersion(nameph);
461 //printf("Found Version %d, Subversion %d for vdrift\n",fVersionVdriftUsed,fSubVersionVdriftUsed);
465 if(ReadGainGlobal(fileName)) {
467 TString namech = fCH2d->GetTitle();
468 fFirstRunGainUsed = GetFirstRun(namech);
469 fVersionGainUsed = GetVersion(namech);
470 fSubVersionGainUsed = GetSubVersion(namech);
472 //printf("Found Version %d, Subversion %d for gain\n",fVersionGainUsed,fSubVersionGainUsed);
476 if(ReadVdriftLinearFitGlobal(fileName)) {
478 TString namelinear = fAliTRDCalibraVdriftLinearFit->GetNameCalibUsed();
479 fFirstRunExBUsed = GetFirstRun(namelinear);
480 fVersionExBUsed = GetVersion(namelinear);
481 fSubVersionExBUsed = GetSubVersion(namelinear);
483 //printf("Found Version %d, Subversion %d, run %d for ExB\n",fVersionExBUsed,fSubVersionExBUsed,fFirstRunExBUsed);
487 if(fVersionVdriftUsed == 0) fStatusPos = fStatusPos |kVdriftErrorOld;
488 if(fVersionGainUsed == 0) fStatusPos = fStatusPos | kGainErrorOld;
493 //___________________________________________________________________________________________________________________
495 Bool_t AliTRDPreprocessorOffline::ReadStatusGlobal(const Char_t* fileName){
497 // read calibration entries from file
499 if(fSparse) return kTRUE;
500 TFile fcalib(fileName);
501 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
503 fSparse = (THnSparseI *) array->FindObject("NumberOfEntries");
504 if(!fSparse) return kFALSE;
512 //___________________________________________________________________________________________________________________
514 Bool_t AliTRDPreprocessorOffline::ReadPHQGlobal(const Char_t* fileName)
517 // read calibration entries from file
520 return AliTRDdEdxCalibUtils::ReadHistArray(fileName, fNameList);
523 //___________________________________________________________________________________________________________________
525 Bool_t AliTRDPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
527 // read calibration entries from file
529 if(fCH2d) return kTRUE;
530 TFile fcalib(fileName);
531 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
533 TH2I *ch2d = (TH2I *) array->FindObject("CH2d");
534 if(!ch2d) return kFALSE;
535 fCH2d = (TH2I*)ch2d->Clone();
536 //fNEvents = (TH1I *) array->FindObject("NEvents");
537 //fAbsoluteGain = (TH2F *) array->FindObject("AbsoluteGain");
539 TH2I *ch2d = (TH2I *) fcalib.Get("CH2d");
540 if(!ch2d) return kFALSE;
541 fCH2d = (TH2I*)ch2d->Clone();
542 //fNEvents = (TH1I *) fcalib.Get("NEvents");
543 //fAbsoluteGain = (TH2F *) fcalib.Get("AbsoluteGain");
545 fCH2d->SetDirectory(0);
546 //printf("title of CH2d %s\n",fCH2d->GetTitle());
551 //_________________________________________________________________________________________________________________
553 Bool_t AliTRDPreprocessorOffline::ReadVdriftT0Global(const Char_t* fileName){
555 // read calibration entries from file
557 if(fPH2d) return kTRUE;
558 TFile fcalib(fileName);
559 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
561 TProfile2D *ph2d = (TProfile2D *) array->FindObject("PH2d");
562 if(!ph2d) return kFALSE;
563 fPH2d = (TProfile2D*)ph2d->Clone();
564 //fNEvents = (TH1I *) array->FindObject("NEvents");
566 TProfile2D *ph2d = (TProfile2D *) fcalib.Get("PH2d");
567 if(!ph2d) return kFALSE;
568 fPH2d = (TProfile2D*)ph2d->Clone();
569 //fNEvents = (TH1I *) fcalib.Get("NEvents");
571 fPH2d->SetDirectory(0);
572 //printf("title of PH2d %s\n",fPH2d->GetTitle());
577 //___________________________________________________________________________________________________________________
579 Bool_t AliTRDPreprocessorOffline::ReadVdriftLinearFitGlobal(const Char_t* fileName){
581 // read calibration entries from file
583 if(fAliTRDCalibraVdriftLinearFit) return kTRUE;
584 TFile fcalib(fileName);
585 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
587 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) array->FindObject("AliTRDCalibraVdriftLinearFit");
588 //fNEvents = (TH1I *) array->FindObject("NEvents");
590 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) fcalib.Get("AliTRDCalibraVdriftLinearFit");
591 //fNEvents = (TH1I *) fcalib.Get("NEvents");
593 if(!fAliTRDCalibraVdriftLinearFit) {
594 //printf("No AliTRDCalibraVdriftLinearFit\n");
600 //_____________________________________________________________________________________________________________
601 Bool_t AliTRDPreprocessorOffline::ReadExbAltFitGlobal(const Char_t* fileName){
603 // read calibration entries from file
605 if(fAliTRDCalibraExbAltFit) return kTRUE;
606 TFile fcalib(fileName);
607 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
609 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) array->FindObject("AliTRDCalibraExbAltFit");
610 //fNEvents = (TH1I *) array->FindObject("NEvents");
612 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) fcalib.Get("AliTRDCalibraExbAltFit");
613 //fNEvents = (TH1I *) fcalib.Get("NEvents");
615 if(!fAliTRDCalibraExbAltFit) {
616 //printf("No AliTRDCalibraExbAltFit\n");
622 //_____________________________________________________________________________________________________________
624 Bool_t AliTRDPreprocessorOffline::ReadPRFGlobal(const Char_t* fileName){
626 // read calibration entries from file
628 if(fPRF2d) return kTRUE;
629 TFile fcalib(fileName);
630 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
632 TProfile2D *prf2d = (TProfile2D *) array->FindObject("PRF2d");
633 if(!prf2d) return kFALSE;
634 fPRF2d = (TProfile2D*)prf2d->Clone();
635 //fNEvents = (TH1I *) array->FindObject("NEvents");
637 TProfile2D *prf2d = (TProfile2D *) fcalib.Get("PRF2d");
638 if(!prf2d) return kFALSE;
639 fPRF2d = (TProfile2D*)prf2d->Clone();
640 //fNEvents = (TH1I *) fcalib.Get("NEvents");
642 fPRF2d->SetDirectory(0);
643 //printf("title of PRF2d %s\n",fPRF2d->GetTitle());
648 //__________________________________________________________________________________________________________
650 Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
652 // Analyze gain - produce the calibration objects
655 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
656 calibra->ChooseMethod(fMethodeGain);
657 calibra->SetBeginFitCharge(fBeginFitCharge);
658 calibra->SetFitOutliersChargeLow(fOutliersFitChargeLow);
659 calibra->SetFitOutliersChargeHigh(fOutliersFitChargeHigh);
660 calibra->SetMinEntries(fMinStatsGain); // If there is less than 1000 entries in the histo: no fit
661 calibra->AnalyseCH(fCH2d);
663 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
664 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
665 Int_t nbfit = calibra->GetNumberFit();
666 Int_t nbE = calibra->GetNumberEnt();
670 Bool_t meanother = kFALSE;
673 (nbfit >= 0.5*nbE) && (nbE > 30)) {
674 // create the cal objects
675 if(!fBackCorrectGain) {
676 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
679 TObjArray object = calibra->GetVectorFit();
680 AliTRDCalDet *calDetGain = calibra->CreateDetObjectGain(&object,meanother);
681 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
682 // Put them in the array
683 fCalibObjects->AddAt(calDetGain,kGain);
684 fPlots->AddAt(coefGain,kGain);
689 fNotEnoughStatisticsForTheGain = kTRUE;
690 Int_t minStatsGain = fMinStatsGain*30;
691 calibra->SetMinEntries(minStatsGain); // Because we do it for all, we increase this
692 Double_t gainoverallnotnormalized = calibra->AnalyseCHAllTogether(fCH2d);
693 if(fCalDetGainUsed && (gainoverallnotnormalized > 0.0)) {
694 AliTRDCalDet *calDetGain = new AliTRDCalDet(*fCalDetGainUsed);
695 Double_t oldmean = fCalDetGainUsed->CalcMean(kFALSE);
696 //printf("oldmean %f\n",oldmean);
698 Double_t scalefactor = calibra->GetScaleFactorGain();
699 //printf("Correction factor %f\n",gainoverallnotnormalized*scalefactor);
700 calDetGain->Multiply(gainoverallnotnormalized*scalefactor/oldmean);
701 //printf("newmean %f\n",calDetGain->CalcMean(kFALSE));
702 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
703 fCalibObjects->AddAt(calDetGain,kGain);
704 fPlots->AddAt(coefGain,kGain);
707 fStatusNeg = fStatusNeg | kGainNotEnoughStatsButFill;
710 fStatusPos = fStatusPos | kGainErrorOld;
714 if(gainoverallnotnormalized <= 0.0) fStatusNeg = fStatusNeg | kGainNotEnoughStatsNotFill;
715 if(!fCalDetGainUsed) fStatusPos = fStatusPos | kGainErrorOld;
719 calibra->ResetVectorFit();
724 //_____________________________________________________________________________________________________
725 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftT0(){
727 // Analyze VdriftT0 - produce the calibration objects
730 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
731 calibra->SetT0Shift0(fT0Shift0);
732 calibra->SetT0Shift1(fT0Shift1);
733 calibra->SetMinEntries(fMinStatsVdriftT0PH); // If there is less than 1000 entries in the histo: no fit
734 calibra->AnalysePH(fPH2d);
735 //calibra->SetDebugLevel(2);
737 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
738 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
739 Int_t nbfit = calibra->GetNumberFit();
740 Int_t nbfitSuccess = calibra->GetNumberFitSuccess();
741 Int_t nbE = calibra->GetNumberEnt();
743 //printf("nbtg %d, nbfit %d, nbE %d, nbfitSuccess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
747 (nbfit >= 0.5*nbE) && (nbE > 30) && (nbfitSuccess > 30)) {
748 //printf("nbtg %d, nbfit %d, nbE %d, nbfitSucess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
749 //printf("Pass the cut for VdriftT0\n");
750 // create the cal objects
751 calibra->RemoveOutliers(1,kFALSE);
752 calibra->PutMeanValueOtherVectorFit(1,kFALSE);
753 calibra->RemoveOutliers2(kFALSE);
754 calibra->PutMeanValueOtherVectorFit2(1,kFALSE);
756 TObjArray object = calibra->GetVectorFit();
757 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object);
758 TH1F *coefVdriftPH = calDetVdrift->MakeHisto1DAsFunctionOfDet();
759 AliTRDCalPad *calPadVdrift = (AliTRDCalPad *)calibra->CreatePadObjectVdrift(&object,calDetVdrift);
760 TH1F *coefPadVdrift = calPadVdrift->MakeHisto1D();
761 object = calibra->GetVectorFit2();
762 AliTRDCalDet *calDetT0 = calibra->CreateDetObjectT0(&object);
763 TH1F *coefT0 = calDetT0->MakeHisto1DAsFunctionOfDet();
764 AliTRDCalPad *calPadT0 = (AliTRDCalPad *)calibra->CreatePadObjectT0(&object,calDetT0);
765 TH1F *coefPadT0 = calPadT0->MakeHisto1D();
766 // Put them in the array
767 fCalibObjects->AddAt(calDetT0,kT0PHDet);
768 fCalibObjects->AddAt(calDetVdrift,kVdriftPHDet);
769 fCalibObjects->AddAt(calPadT0,kT0PHPad);
770 fCalibObjects->AddAt(calPadVdrift,kVdriftPHPad);
771 fPlots->AddAt(coefVdriftPH,kVdriftPHDet);
772 fPlots->AddAt(coefT0,kT0PHDet);
773 fPlots->AddAt(coefPadVdrift,kVdriftPHPad);
774 fPlots->AddAt(coefPadT0,kT0PHPad);
779 //printf("Not enough stats timeoffset\n");
780 fStatusNeg = fStatusNeg | kTimeOffsetNotEnoughStatsNotFill;
782 calibra->ResetVectorFit();
787 //____________________________________________________________________________________________________________________
788 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftLinearFit(){
790 // Analyze vdrift linear fit - produce the calibration objects
793 //printf("Analyse linear fit\n");
796 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
797 calibra->SetCalDetVdriftExB(fCalDetVdriftUsed,fCalDetExBUsed);
798 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
799 //printf("The mean stat is by %d for VdriftLinear\n",fMinStatsVdriftLinear);
800 //fAliTRDCalibraVdriftLinearFit->SetSeeDetector(0);
801 //fAliTRDCalibraVdriftLinearFit->SetDebugLevel(1);
802 //printf("Fill PE Array\n");
803 fAliTRDCalibraVdriftLinearFit->SetRobustFit(fRobustFitDriftVelocity);
804 fAliTRDCalibraVdriftLinearFit->SetMinNumberOfPointsForFit(fMinNbOfPointVdriftFit);
805 if(!fAlternativeVdrfitFit)
806 fAliTRDCalibraVdriftLinearFit->FillPEArray();
808 fAliTRDCalibraVdriftLinearFit->FillPEArray2();
809 //printf("AliTRDCalibraFit\n");
810 calibra->AnalyseLinearFitters(fAliTRDCalibraVdriftLinearFit);
814 Int_t nbfit = calibra->GetNumberFit();
815 Int_t nbE = calibra->GetNumberEnt();
820 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
821 // create the cal objects
822 //calibra->RemoveOutliers(1,kTRUE);
823 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
824 //calibra->RemoveOutliers2(kTRUE);
825 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
827 TObjArray object = calibra->GetVectorFit();
828 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object,kTRUE);
829 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
830 object = calibra->GetVectorFit2();
831 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectLorentzAngle(&object);
832 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
833 //if(!calDetLorentz) printf("No lorentz created\n");
834 // Put them in the array
835 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
836 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
837 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
838 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
843 fNotEnoughStatisticsForTheVdriftLinear = kTRUE;
844 Int_t minNumberOfEntriesForAll = fMinStatsVdriftLinear*30;
845 calibra->SetMinEntries(minNumberOfEntriesForAll); // Because we do it for all, we increase this
846 Double_t vdriftoverall = -100.0;
847 Double_t exboverall = 100.0;
848 calibra->AnalyseLinearFittersAllTogether(fAliTRDCalibraVdriftLinearFit,vdriftoverall,exboverall);
849 //printf("Found mean vdrift %f and exb %f\n",vdriftoverall,exboverall);
850 if(fCalDetVdriftUsed && (vdriftoverall > 0.0) && (exboverall < 70.0)) {
851 AliTRDCalDet *calDetVdrift = new AliTRDCalDet(*fCalDetVdriftUsed);
852 AliTRDCalDet *calDetLorentz = new AliTRDCalDet(*fCalDetExBUsed);
853 Double_t oldmeanvdrift = fCalDetVdriftUsed->CalcMean(kFALSE);
854 Double_t oldmeanexb = fCalDetExBUsed->CalcMean(kFALSE);
855 //printf("oldmean %f\n",oldmean);
856 if((oldmeanvdrift > 0.0) && (oldmeanexb < 70.0)) {
857 //printf("Correction factor %f\n",vdriftoverall);
858 calDetVdrift->Multiply(vdriftoverall/oldmeanvdrift);
859 if(TMath::Abs(oldmeanexb) > 0.0001) calDetLorentz->Multiply(exboverall/oldmeanexb);
860 //printf("newmean %f\n",calDetVdrift->CalcMean(kFALSE));
861 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
862 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
863 // Put them in the array
864 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
865 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
866 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
867 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
870 fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsButFill;
873 if(oldmeanvdrift) fStatusPos = fStatusPos | kVdriftErrorOld;
874 if(oldmeanexb) fStatusPos = fStatusPos | kExBErrorOld;
878 if((vdriftoverall <= 0.0) && (exboverall > 70.0)) fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsNotFill;
879 if(!fCalDetVdriftUsed) fStatusPos = fStatusPos | kVdriftErrorOld;
880 if(!fCalDetExBUsed) fStatusPos = fStatusPos | kExBErrorOld;
884 calibra->ResetVectorFit();
889 //________________________________________________________________________________________________________________
891 Bool_t AliTRDPreprocessorOffline::AnalyzeExbAltFit(){
893 // Analyze vdrift linear fit - produce the calibration objects
896 //printf("Analyse linear fit\n");
899 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
900 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
901 //printf("Fill PE Array\n");
902 fAliTRDCalibraExbAltFit->SetRobustFit(fRobustFitExbAlt);
903 if(!fAlternativeExbAltFit)
904 fAliTRDCalibraExbAltFit->FillPEArray();
906 fAliTRDCalibraExbAltFit->FillPEArray2();
907 //printf("AliTRDCalibraFit\n");
908 calibra->AnalyseExbAltFit(fAliTRDCalibraExbAltFit);
912 Int_t nbfit = calibra->GetNumberFit();
913 Int_t nbE = calibra->GetNumberEnt();
918 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
919 // create the cal objects
920 //calibra->RemoveOutliers(1,kTRUE);
921 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
923 TObjArray object = calibra->GetVectorFit2();
924 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectExbAlt(&object);
925 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
926 //if(!calDetLorentz) printf("No lorentz created\n");
927 // Put them in the array
928 fCalibObjects->AddAt(calDetLorentz,kExbAlt);
929 fPlots->AddAt(coefLorentzAngle,kExbAlt);
934 calibra->ResetVectorFit();
939 //________________________________________________________________________________________________________________
941 Bool_t AliTRDPreprocessorOffline::AnalyzePRF(){
943 // Analyze PRF - produce the calibration objects
946 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
947 calibra->SetMinEntries(fMinStatsPRF); // If there is less than 1000 entries in the histo: no fit
948 calibra->AnalysePRFMarianFit(fPRF2d);
950 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
951 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
952 Int_t nbfit = calibra->GetNumberFit();
953 Int_t nbE = calibra->GetNumberEnt();
959 (nbfit >= 0.95*nbE) && (nbE > 30)) {
960 // create the cal objects
961 TObjArray object = calibra->GetVectorFit();
962 AliTRDCalPad *calPadPRF = (AliTRDCalPad*) calibra->CreatePadObjectPRF(&object);
963 TH1F *coefPRF = calPadPRF->MakeHisto1D();
964 // Put them in the array
965 fCalibObjects->AddAt(calPadPRF,kPRF);
966 fPlots->AddAt(coefPRF,kPRF);
971 calibra->ResetVectorFit();
977 //_____________________________________________________________________________
978 Bool_t AliTRDPreprocessorOffline::AnalyzePHQ(Int_t startRunNumber)
981 //Produce PHQ calibration results
984 TTreeSRedirector *calibStream = 0x0;
989 calibStream = new TTreeSRedirector(Form("TRDCalibStream_%010d.root", startRunNumber));
992 for(Int_t iter=0; iter<AliTRDdEdxCalibUtils::GetHistArray()->GetSize(); iter++){
993 THnBase *hi = (THnBase*) AliTRDdEdxCalibUtils::GetHistAt(iter);
994 TObjArray *obji = AliTRDdEdxCalibUtils::HistToObj(hi, startRunNumber, lout, calibStream);
995 //printf("test analyze %s\n", obji->GetName());
996 AliTRDdEdxCalibUtils::GetObjArray()->AddAt(obji, iter);
999 fCalibObjects->AddAt(AliTRDdEdxCalibUtils::GetObjArray(), kPHQ);
1002 TFile *fout=new TFile(Form("TRDCalibList_%010d.root", startRunNumber),"recreate");
1015 //_____________________________________________________________________________
1016 Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
1019 // Produce AliTRDCalChamberStatus out of calibration results
1022 // set up AliTRDCalibChamberStatus
1023 AliTRDCalibChamberStatus *chamberStatus = new AliTRDCalibChamberStatus();
1024 chamberStatus->SetSparseI(fSparse);
1025 chamberStatus->AnalyseHisto(fMinStatsChamberStatus, fMinSingleStatsChamberStatus);
1026 // get AliTRDCalChamberStatus
1027 AliTRDCalChamberStatus *calChamberStatus = chamberStatus->GetCalChamberStatus();
1029 // get calibration objects
1030 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1031 AliTRDCalDet *calDetVDrift = (AliTRDCalDet *) fCalibObjects->At(kVdriftLinear);
1032 AliTRDCalDet *calDetExB = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
1035 if((!calDetGain) || (!calDetVDrift) || (!fCH2d) || (!calDetExB) || (!calChamberStatus)) return kFALSE;
1038 Double_t gainmean = calDetGain->GetMean();
1039 Double_t vdriftmean = calDetVDrift->GetMean();
1040 Double_t exbmean = calDetExB->GetMean();
1042 Double_t gainrms = calDetGain->GetRMSRobust();
1043 Double_t vdriftrms = calDetVDrift->GetRMSRobust();
1044 Double_t exbrms = calDetExB->GetRMSRobust();
1046 //printf("Gain mean: %f, rms: %f\n",gainmean,gainrms);
1047 //printf("Vdrift mean: %f, rms: %f\n",vdriftmean,vdriftrms);
1048 //printf("ExB mean: %f, rms: %f\n",exbmean,exbrms);
1051 if((TMath::Abs(gainrms) < 0.001) || (TMath::Abs(vdriftrms) < 0.001) || (TMath::Abs(exbrms) < 0.0000001)) return kFALSE;
1053 // Take mean each SM
1054 Double_t *gainmeanSM = new Double_t[18];
1055 Double_t *vdriftmeanSM = new Double_t[18];
1056 Double_t *exbmeanSM = new Double_t[18];
1057 //Double_t *t0meanSM = new Double_t[18];
1058 for(Int_t sm=0; sm< 18; sm++) {
1059 gainmeanSM[sm] = calDetGain->GetMeanSM(kFALSE,sm);
1060 vdriftmeanSM[sm] = calDetVDrift->GetMeanSM(kFALSE,sm);
1061 exbmeanSM[sm] = calDetExB->GetMeanSM(kFALSE,sm);
1062 //t0meanSM[sm] = calDetGain->GetMeanSM(kFALSE);
1066 // mask chambers with empty gain entries
1067 //Int_t counter = 0;
1068 for (Int_t idet = 0; idet < 540; idet++) {
1071 TH1I *projch = (TH1I *) fCH2d->ProjectionX("projch",idet+1,idet+1,(Option_t *)"e");
1072 Double_t entries = projch->GetEntries();
1073 //printf("Number of entries %f for det %d\n",entries,idet);
1076 Int_t smnumber = (Int_t) idet/30;
1079 Double_t gain = calDetGain->GetValue(idet);
1082 Double_t vdrift = calDetVDrift->GetValue(idet);
1085 Double_t exb = calDetExB->GetValue(idet);
1088 if( (entries<50 && !calChamberStatus->IsNoData(idet)) ||
1089 TMath::Abs(gainmean-gain) > (fRMSBadCalibratedGain*gainrms) ||
1090 TMath::Abs(vdriftmean-vdrift) > (fRMSBadCalibratedVdrift*vdriftrms) ||
1091 TMath::Abs(exbmean-exb) > (fRMSBadCalibratedExB*exbrms) ) {
1093 //printf(" chamber det %03d masked \n",idet);
1094 //printf(" gainmean %f and gain %f, gainrms %f \n",gainmean,gain,gainrms);
1095 //printf(" vdriftmean %f and vdrift %f, vdriftrms %f \n",vdriftmean,vdrift,vdriftrms);
1096 //printf(" exbmean %f and exb %f, exbrms %f \n",exbmean,exb,exbrms);
1098 calChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kBadCalibrated);
1102 if(TMath::Abs(gainmeanSM[smnumber]-gain) < 0.000001 ||
1103 TMath::Abs(vdriftmeanSM[smnumber]-vdrift) < 0.000001 ||
1104 TMath::Abs(exbmeanSM[smnumber]-exb) < 0.000001) {
1106 //printf(" chamber det %03d notcalibrated sm %d \n",idet,smnumber);
1107 //printf(" gainmeanSM %f and gain %f\n",gainmeanSM[smnumber],gain);
1108 //printf(" vdriftmeanSM %f and vdrift %f \n",vdriftmeanSM[smnumber],vdrift);
1109 //printf(" exbmeanSM %f and exb %f \n",exbmeanSM[smnumber],exb);
1111 calChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kNotCalibrated);
1120 for(Int_t sm=0; sm < 18; sm++) {
1122 Int_t smbadcalib = 0;
1123 for(Int_t det = 0; det < 30; det++){
1124 Int_t detector = sm*30+det;
1125 if(calChamberStatus->IsNoData(detector)) smnodata++;
1127 if(calChamberStatus->IsBadCalibrated(detector)) smbadcalib++;
1130 fNoData[sm] = smnodata;
1131 fBadCalib[sm]= smbadcalib;
1132 //printf("No Data %d, bad calibrated %d for %d\n",fNoData[sm],fBadCalib[sm],sm);
1136 delete []gainmeanSM;
1137 delete []vdriftmeanSM;
1141 // for(Int_t sm=0; sm < 18; sm++) {
1142 // Int_t counter = 0;
1143 // for(Int_t det = 0; det < 30; det++){
1144 // Int_t detector = sm*30+det;
1145 // if(calChamberStatus->IsBadCalibrated(detector)) counter++;
1147 // if(counter >= 20) {
1148 // for(Int_t det = 0; det < 30; det++){
1149 // Int_t detector = sm*30+det;
1150 // calChamberStatus->SetStatus(detector,AliTRDCalChamberStatus::kGood);
1155 fCalibObjects->AddAt(calChamberStatus,kChamberStatus);
1161 //________________________________________________________________________________________________
1162 void AliTRDPreprocessorOffline::CorrectFromDetGainUsed() {
1164 // Correct from the gas gain used afterwards
1166 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1167 if(!calDetGain) return;
1170 Double_t mean = 0.0;
1173 for(Int_t det = 0; det < 540; det++) {
1175 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1176 Float_t gainout = calDetGain->GetValue(det);
1179 if(TMath::Abs(gainout-1.0) > 0.000001) {
1180 mean += (gaininit*gainout);
1184 if(nbdet > 0) mean = mean/nbdet;
1186 for(Int_t det = 0; det < 540; det++) {
1188 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1189 Float_t gainout = calDetGain->GetValue(det);
1191 if(TMath::Abs(gainout-1.0) > 0.000001) {
1192 Double_t newgain = gaininit*gainout;
1193 if(newgain < 0.1) newgain = 0.1;
1194 if(newgain > 1.9) newgain = 1.9;
1195 calDetGain->SetValue(det,newgain);
1198 Double_t newgain = mean;
1199 if(newgain < 0.1) newgain = 0.1;
1200 if(newgain > 1.9) newgain = 1.9;
1201 calDetGain->SetValue(det,newgain);
1207 //________________________________________________________________________________________________
1208 void AliTRDPreprocessorOffline::CorrectFromDetVdriftUsed() {
1210 // Correct from the drift velocity
1213 //printf("Correct for vdrift\n");
1215 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1216 if(!calDetGain) return;
1218 Int_t detVdrift = kVdriftPHDet;
1219 if(fMethodSecond) detVdrift = kVdriftLinear;
1220 AliTRDCalDet *calDetVdrift = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1221 if(!calDetVdrift) return;
1224 if(!fNotEnoughStatisticsForTheVdriftLinear) {
1225 for(Int_t det = 0; det < 540; det++) {
1227 Float_t vdriftinit = fCalDetVdriftUsed->GetValue(det);
1228 Float_t vdriftout = calDetVdrift->GetValue(det);
1230 Float_t gain = calDetGain->GetValue(det);
1231 if(vdriftout > 0.0) gain = gain*vdriftinit/vdriftout;
1232 if(gain < 0.1) gain = 0.1;
1233 if(gain > 1.9) gain = 1.9;
1234 calDetGain->SetValue(det,gain);
1239 Float_t vdriftinit = fCalDetVdriftUsed->CalcMean(kFALSE);
1240 Float_t vdriftout = calDetVdrift->CalcMean(kFALSE);
1241 Float_t factorcorrectif = 1.0;
1242 if(vdriftout > 0.0) factorcorrectif = vdriftinit/vdriftout;
1243 for(Int_t det = 0; det < 540; det++) {
1244 Float_t gain = calDetGain->GetValue(det);
1245 gain = gain*factorcorrectif;
1246 if(gain < 0.1) gain = 0.1;
1247 if(gain > 1.9) gain = 1.9;
1248 calDetGain->SetValue(det,gain);
1254 //_________________________________________________________________________________________________________________
1255 void AliTRDPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage *storage){
1257 // Update OCDB entry
1260 AliCDBMetaData *metaData= new AliCDBMetaData();
1261 metaData->SetObjectClassName("AliTRDCalDet");
1262 metaData->SetResponsible("Raphaelle Bailhache");
1263 metaData->AddDateToComment();
1264 metaData->SetBeamPeriod(1);
1266 AliCDBId id1("TRD/Calib/ChamberGainFactor", startRunNumber, endRunNumber);
1267 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1268 if(calDet) storage->Put(calDet, id1, metaData);
1272 //___________________________________________________________________________________________________________________
1273 void AliTRDPreprocessorOffline::UpdateOCDBExB(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage *storage){
1275 // Update OCDB entry
1278 Int_t detExB = kLorentzLinear;
1279 if(!fMethodSecond) return;
1283 AliCDBMetaData *metaData= new AliCDBMetaData();
1284 metaData->SetObjectClassName("AliTRDCalDet");
1285 metaData->SetResponsible("Raphaelle Bailhache");
1286 metaData->AddDateToComment();
1287 metaData->SetBeamPeriod(1);
1289 AliCDBId id1("TRD/Calib/ChamberExB", startRunNumber, endRunNumber);
1290 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1291 if(calDet) storage->Put(calDet, id1, metaData);
1292 //if(!calDet) printf("No caldet\n");
1295 //___________________________________________________________________________________________________________________
1296 void AliTRDPreprocessorOffline::UpdateOCDBExBAlt(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage *storage){
1298 // Update OCDB entry
1301 Int_t detExB = kExbAlt;
1302 if(!fMethodSecond) return;
1306 AliCDBMetaData *metaData= new AliCDBMetaData();
1307 metaData->SetObjectClassName("AliTRDCalDet");
1308 metaData->SetResponsible("Theo Rascanu");
1309 metaData->AddDateToComment();
1310 metaData->SetBeamPeriod(1);
1312 AliCDBId id1("TRD/Calib/ChamberExBAlt", startRunNumber, endRunNumber);
1313 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1314 if(calDet) storage->Put(calDet, id1, metaData);
1315 //if(!calDet) printf("No caldet\n");
1318 //___________________________________________________________________________________________________________________
1319 void AliTRDPreprocessorOffline::UpdateOCDBVdrift(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage){
1321 // Update OCDB entry
1324 Int_t detVdrift = kVdriftPHDet;
1326 if(fMethodSecond) detVdrift = kVdriftLinear;
1328 AliCDBMetaData *metaData= new AliCDBMetaData();
1329 metaData->SetObjectClassName("AliTRDCalDet");
1330 metaData->SetResponsible("Raphaelle Bailhache");
1331 metaData->AddDateToComment();
1332 metaData->SetBeamPeriod(1);
1334 AliCDBId id1("TRD/Calib/ChamberVdrift", startRunNumber, endRunNumber);
1335 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1336 if(calDet) storage->Put(calDet, id1, metaData);
1340 if(!fMethodSecond) {
1342 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1343 metaDataPad->SetObjectClassName("AliTRDCalPad");
1344 metaDataPad->SetResponsible("Raphaelle Bailhache");
1345 metaDataPad->AddDateToComment();
1346 metaDataPad->SetBeamPeriod(1);
1348 AliCDBId id1Pad("TRD/Calib/LocalVdrift", startRunNumber, endRunNumber);
1349 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1350 if(calPad) storage->Put(calPad, id1Pad, metaDataPad);
1355 //________________________________________________________________________________________________________________________
1356 void AliTRDPreprocessorOffline::UpdateOCDBT0(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage){
1358 // Update OCDB entry
1361 AliCDBMetaData *metaData= new AliCDBMetaData();
1362 metaData->SetObjectClassName("AliTRDCalDet");
1363 metaData->SetResponsible("Raphaelle Bailhache");
1364 metaData->AddDateToComment();
1365 metaData->SetBeamPeriod(1);
1367 AliCDBId id1("TRD/Calib/ChamberT0", startRunNumber, endRunNumber);
1368 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1369 if(calDet) storage->Put(calDet, id1, metaData);
1373 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1374 metaDataPad->SetObjectClassName("AliTRDCalPad");
1375 metaDataPad->SetResponsible("Raphaelle Bailhache");
1376 metaDataPad->AddDateToComment();
1377 metaDataPad->SetBeamPeriod(1);
1379 AliCDBId id1Pad("TRD/Calib/LocalT0", startRunNumber, endRunNumber);
1380 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1381 if(calPad) storage->Put(calPad, id1Pad, metaDataPad);
1386 //_________________________________________________________________________________________________________________
1387 void AliTRDPreprocessorOffline::UpdateOCDBPRF(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage){
1389 // Update OCDB entry
1392 AliCDBMetaData *metaData= new AliCDBMetaData();
1393 metaData->SetObjectClassName("AliTRDCalPad");
1394 metaData->SetResponsible("Raphaelle Bailhache");
1395 metaData->AddDateToComment();
1396 metaData->SetBeamPeriod(1);
1399 AliCDBId id1("TRD/Calib/PRFWidth", startRunNumber, endRunNumber);
1400 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1401 if(calPad) storage->Put(calPad, id1, metaData);
1405 //_________________________________________________________________________________________________________________
1406 void AliTRDPreprocessorOffline::UpdateOCDBPHQ(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage)
1409 // Update OCDB entry
1411 AliCDBMetaData *metaData= new AliCDBMetaData();
1412 metaData->SetObjectClassName("TObjArray");
1413 metaData->SetResponsible("Raphaelle Bailhache and Xianguo Lu");
1414 metaData->AddDateToComment();
1415 metaData->SetBeamPeriod(1);
1417 AliCDBId id1("TRD/Calib/PHQ", startRunNumber, endRunNumber);
1418 TObjArray *cobj = (TObjArray *) fCalibObjects->At(kPHQ);
1421 storage->Put(cobj, id1, metaData);
1425 //_________________________________________________________________________________________________________________
1426 void AliTRDPreprocessorOffline::UpdateOCDBChamberStatus(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage){
1428 // Update OCDB entry
1431 AliCDBMetaData *metaData= new AliCDBMetaData();
1432 metaData->SetObjectClassName("AliTRDCalChamberStatus");
1433 metaData->SetResponsible("Raphaelle Bailhache and Julian Book");
1434 metaData->AddDateToComment();
1435 metaData->SetBeamPeriod(1);
1437 AliCDBId id1("TRD/Calib/ChamberStatus", startRunNumber, endRunNumber);
1438 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1439 if(calChamberStatus) storage->Put(calChamberStatus, id1, metaData);
1443 //__________________________________________________________________________________________________________________________
1444 Bool_t AliTRDPreprocessorOffline::ValidateGain() {
1446 // Validate OCDB entry
1449 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1451 Double_t mean = calDet->GetMean();
1452 Double_t rms = calDet->GetRMSRobust();
1453 if((mean > 0.2) && (mean < 1.4) && (rms < 0.5)) return kTRUE;
1454 //if((mean > 0.2) && (mean < 1.4)) return kTRUE;
1456 fStatusPos = fStatusPos | kGainErrorRange;
1465 //__________________________________________________________________________________________________________________________
1466 Bool_t AliTRDPreprocessorOffline::ValidateVdrift(){
1468 // Update OCDB entry
1471 Int_t detVdrift = kVdriftPHDet;
1474 if(fMethodSecond) detVdrift = kVdriftLinear;
1476 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1478 Double_t mean = calDet->GetMean();
1479 Double_t rms = calDet->GetRMSRobust();
1480 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1481 if(!((mean > 1.0) && (mean < 2.0) && (rms < 0.5))) {
1482 fStatusPos = fStatusPos | kVdriftErrorRange;
1488 if(!fMethodSecond) {
1489 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1491 Double_t mean = calPad->GetMean();
1492 Double_t rms = calPad->GetRMS();
1493 //printf("Vdrift::meanpad %f, rmspad %f\n",mean,rms);
1494 if(!((mean > 0.9) && (mean < 1.1) && (rms < 0.6))) {
1495 fStatusPos = fStatusPos | kVdriftErrorRange;
1505 //__________________________________________________________________________________________________________________________
1506 Bool_t AliTRDPreprocessorOffline::ValidateExB(){
1508 // Update OCDB entry
1511 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
1513 Double_t mean = calDet->GetMean();
1514 Double_t rms = calDet->GetRMSRobust();
1515 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1516 if(!((mean > -1.0) && (mean < 1.0) && (rms < 0.5))) {
1517 fStatusNeg = fStatusNeg | kExBErrorRange;
1525 //__________________________________________________________________________________________________________________________
1526 Bool_t AliTRDPreprocessorOffline::ValidateT0(){
1528 // Update OCDB entry
1531 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1532 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1533 if(calDet && calPad) {
1534 Double_t meandet = calDet->GetMean();
1535 Double_t rmsdet = calDet->GetRMSRobust();
1536 Double_t meanpad = calPad->GetMean();
1537 //Double_t rmspad = calPad->GetRMS();
1538 printf("T0::meandet %f, rmsdet %f,meanpad %f\n",meandet,rmsdet,meanpad);
1539 if((meandet > fMinTimeOffsetValidate) && (meandet < 5.0) && (rmsdet < 4.0) && (meanpad < 5.0) && (meanpad > -0.5)) return kTRUE;
1541 fStatusPos = fStatusPos | kTimeOffsetErrorRange;
1548 //__________________________________________________________________________________________________________________________
1549 Bool_t AliTRDPreprocessorOffline::ValidatePRF() const{
1551 // Update OCDB entry
1554 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1556 Double_t meanpad = calPad->GetMean();
1557 Double_t rmspad = calPad->GetRMS();
1558 //printf("PRF::meanpad %f, rmspad %f\n",meanpad,rmspad);
1559 if((meanpad < 1.0) && (rmspad < 0.8)) return kTRUE;
1566 //__________________________________________________________________________________________________________________________
1567 Bool_t AliTRDPreprocessorOffline::ValidateChamberStatus(){
1569 // Update OCDB entry
1572 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1573 if(calChamberStatus) {
1575 Int_t detectornodata = 0;
1576 Int_t detectorbadcalib = 0;
1578 for(Int_t sm=0; sm < 18; sm++) {
1579 //printf("%d chambers w/o data in sm %d\n",fNoData[sm],sm);
1580 //printf("%d bad calibrated chambers in sm %d\n",fBadCalib[sm],sm);
1581 if(fNoData[sm] != 30) detectornodata += fNoData[sm];
1582 detectorbadcalib+=fBadCalib[sm];
1584 //printf("Number of chambers w/o data %d\n",detectornodata);
1585 //printf("Number of chambers bad calibrated %d\n",detectorbadcalib);
1587 if((detectornodata > fNoDataValidate) ||
1588 (detectorbadcalib > fBadCalibValidate)){
1589 fStatusPos = fStatusPos | kChamberStatusErrorRange;
1597 //_____________________________________________________________________________
1598 Int_t AliTRDPreprocessorOffline::GetVersion(TString name) const
1601 // Get version from the title
1605 const Char_t *version = "Ver";
1606 if(!strstr(name.Data(),version)) return -1;
1607 const Char_t *after = "Subver";
1608 if(!strstr(name.Data(),after)) return -1;
1610 for(Int_t ver = 0; ver < 999999999; ver++) {
1612 TString vertry(version);
1616 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1618 if(strstr(name.Data(),vertry.Data())) return ver;
1626 //_____________________________________________________________________________
1627 Int_t AliTRDPreprocessorOffline::GetSubVersion(TString name) const
1630 // Get subversion from the title
1634 const Char_t *subversion = "Subver";
1635 if(!strstr(name.Data(),subversion)) return -1;
1636 const Char_t *after = "FirstRun";
1637 if(!strstr(name.Data(),after)) {
1640 if(!strstr(name.Data(),after)) return -1;
1643 for(Int_t ver = 0; ver < 999999999; ver++) {
1645 TString vertry(subversion);
1649 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1651 if(strstr(name.Data(),vertry.Data())) return ver;
1659 //_____________________________________________________________________________
1660 Int_t AliTRDPreprocessorOffline::GetFirstRun(TString name) const
1663 // Get first run from the title
1667 const Char_t *firstrun = "FirstRun";
1668 if(!strstr(name.Data(),firstrun)) return -1;
1669 const Char_t *after = "Nz";
1670 if(!strstr(name.Data(),after)) return -1;
1673 for(Int_t ver = 0; ver < 999999999; ver++) {
1675 TString vertry(firstrun);
1679 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1681 if(strstr(name.Data(),vertry.Data())) return ver;
1688 //_____________________________________________________________________________
1689 Bool_t AliTRDPreprocessorOffline::CheckStatus(Int_t status, Int_t bitMask) const
1692 // Checks the status
1695 return (status & bitMask) ? kTRUE : kFALSE;
1698 //_____________________________________________________________________________
1699 Int_t AliTRDPreprocessorOffline::GetStatus() const
1702 // Checks the status
1703 // fStatusPos: errors
1704 // fStatusNeg: only info
1707 if(fStatusPos > 0) return fStatusPos;
1708 else return (-TMath::Abs(fStatusNeg));
1711 //_____________________________________________________________________________
1712 void AliTRDPreprocessorOffline::PrintStatus() const
1718 AliInfo(Form("The error status is %d",fStatusPos));
1719 AliInfo(Form("IsGainErrorOld? %d",(Int_t)IsGainErrorOld()));
1720 AliInfo(Form("IsVdriftErrorOld? %d",(Int_t)IsVdriftErrorOld()));
1721 AliInfo(Form("IsGainErrorRange? %d",(Int_t)IsGainErrorRange()));
1722 AliInfo(Form("IsVdriftErrorRange? %d",(Int_t)IsVdriftErrorRange()));
1723 AliInfo(Form("IsTimeOffsetErrorRange? %d",(Int_t)IsTimeOffsetErrorRange()));
1724 AliInfo(Form("IsChamberStatusErrorRange? %d",(Int_t)IsChamberStatusErrorRange()));
1727 AliInfo(Form("The info status is %d",fStatusNeg));
1728 AliInfo(Form("IsGainNotEnoughStatsButFill? %d",(Int_t)IsGainNotEnoughStatsButFill()));
1729 AliInfo(Form("IsVdriftNotEnoughStatsButFill? %d",(Int_t)IsVdriftNotEnoughStatsButFill()));
1730 AliInfo(Form("IsGainNotEnoughStatsNotFill? %d",(Int_t)IsGainNotEnoughStatsNotFill()));
1731 AliInfo(Form("IsVdriftNotEnoughStatsNotFill? %d",(Int_t)IsVdriftNotEnoughStatsNotFill()));
1732 AliInfo(Form("IsTimeOffsetNotEnoughStatsNotFill? %d",(Int_t)IsTimeOffsetNotEnoughStatsNotFill()));
1734 AliInfo(Form("IsExBErrorRange? %d",(Int_t)IsExBErrorRange()));
1735 AliInfo(Form("IsExBErrorOld? %d",(Int_t)IsExBErrorOld()));
1738 //___________________________________________________________________________________
1739 void AliTRDPreprocessorOffline::SetCalDetVdrift(AliTRDCalDet *calDetVdriftUsed)
1742 fCalDetVdriftUsed = calDetVdriftUsed;
1744 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1745 for(Int_t k = 0; k < 540; k++){
1746 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1747 //printf("Set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1751 //___________________________________________________________________________________
1752 Bool_t AliTRDPreprocessorOffline::SetCalDetGain(Int_t runNumber, Int_t version, Int_t subversion)
1755 // Set the fCalDetGainUsed
1758 if((version == 0) && (subversion == 0)) return kFALSE;
1760 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor",runNumber, version, subversion);
1762 AliError("Found no entry\n");
1763 fStatusPos = fStatusPos | kGainErrorOld;
1766 //const AliCDBId id = entry->GetId();
1767 //version = id.GetVersion();
1768 //subversion = id.GetSubVersion();
1769 //printf("Found version %d and subversion %d for vdrift\n",version,subversion);
1770 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1771 if(calDet) fCalDetGainUsed = calDet;
1773 fStatusPos = fStatusPos | kGainErrorOld;
1780 //___________________________________________________________________________________
1781 Bool_t AliTRDPreprocessorOffline::SetCalDetVdriftExB(Int_t runNumber, Int_t versionv, Int_t subversionv, Int_t versionexb, Int_t subversionexb)
1784 // Set the fCalDetVdriftUsed and fCalDetExBUsed
1787 if((versionv == 0) && (subversionv == 0)) return kFALSE;
1789 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberVdrift",runNumber, versionv, subversionv);
1791 AliError("Found no entry\n");
1792 fStatusPos = fStatusPos | kVdriftErrorOld;
1795 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1796 if(calDet) fCalDetVdriftUsed = calDet;
1798 fStatusPos = fStatusPos | kVdriftErrorOld;
1804 if((versionexb == 0) && (subversionexb == 0)) {
1806 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1807 for(Int_t k = 0; k < 540; k++){
1808 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1809 //printf("Nothing found: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1815 entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberExB",runNumber, versionexb, subversionexb);
1817 //printf("Found no entry\n");
1818 fStatusPos = fStatusPos | kExBErrorOld;
1821 AliTRDCalDet* calDetexb = (AliTRDCalDet *)entry->GetObject();
1823 fStatusPos = fStatusPos | kExBErrorOld;
1827 Double_t meanexb = calDetexb->GetMean();
1828 //printf("Mean value %f\n",meanexb);
1829 if((meanexb > 70) || (fNoExBUsedInReco)) {
1830 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1831 for(Int_t k = 0; k < 540; k++){
1832 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1833 //printf("Found but: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1837 fCalDetExBUsed = calDetexb;