1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
19 Responsible: Raphaelle Bailhache (rbailhache@ikf.uni-frankfurt.de)
20 Code to analyze the TRD calibration and to produce OCDB entries
24 gSystem->Load("libANALYSIS");
25 gSystem->Load("libTRDcalib");
27 AliTRDPreprocessorOffline proces;
28 TString ocdbPath="local:////"
29 ocdbPath+=gSystem->GetFromPipe("pwd");
31 proces.CalibTimeGain("CalibObjects.root",run0,run1,ocdbPath);
32 proces.CalibTimeVdrift("CalibObjects.root",run0,run1,ocdbPath);
33 // take the raw calibration data from the file CalibObjects.root
34 // and make a OCDB entry with run validity run0-run1
35 // results are stored at the ocdbPath - local or alien ...
36 // default storage ""- data stored at current working directory
40 #include "Riostream.h"
50 #include "THnSparse.h"
51 #include "TProfile2D.h"
52 #include "AliTRDCalDet.h"
53 #include "AliTRDCalPad.h"
54 #include "AliCDBMetaData.h"
56 #include "AliCDBManager.h"
57 #include "AliCDBStorage.h"
58 #include "AliTRDCalibraMode.h"
59 #include "AliTRDCalibraFit.h"
60 #include "AliTRDCalibraVdriftLinearFit.h"
61 #include "AliTRDCalibraExbAltFit.h"
62 #include "AliTRDPreprocessorOffline.h"
63 #include "AliTRDCalChamberStatus.h"
64 #include "AliTRDCalibChamberStatus.h"
65 #include "AliTRDCommonParam.h"
66 #include "AliCDBManager.h"
67 #include "AliCDBEntry.h"
70 ClassImp(AliTRDPreprocessorOffline)
72 AliTRDPreprocessorOffline::AliTRDPreprocessorOffline():
73 TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
75 fNameList("TRDCalib"),
77 fCalDetVdriftUsed(0x0),
83 fAliTRDCalibraVdriftLinearFit(0x0),
84 fAliTRDCalibraExbAltFit(0x0),
87 fPlots(new TObjArray(kNumCalibObjs)),
88 fCalibObjects(new TObjArray(kNumCalibObjs)),
91 fSubVersionGainUsed(0),
92 fFirstRunVdriftUsed(0),
93 fVersionVdriftUsed(0),
94 fSubVersionVdriftUsed(0),
97 fSubVersionExBUsed(0),
98 fNoExBUsedInReco(kFALSE),
99 fSwitchOnValidation(kTRUE),
100 fVdriftValidated(kFALSE),
101 fExBValidated(kFALSE),
102 fT0Validated(kFALSE),
103 fMinStatsVdriftT0PH(800*20),
104 fMinStatsVdriftLinear(800),
107 fMinStatsChamberStatus(20),
108 fMinSingleStatsChamberStatus(0.05),
109 fBackCorrectGain(kFALSE),
110 fBackCorrectVdrift(kTRUE),
111 fNotEnoughStatisticsForTheGain(kFALSE),
112 fNotEnoughStatisticsForTheVdriftLinear(kFALSE),
115 fBadCalibValidate(40),
117 fRMSBadCalibratedGain(20.0),
118 fRMSBadCalibratedVdrift(20.0),
119 fRMSBadCalibratedExB(20.0),
120 fRobustFitDriftVelocity(kTRUE),
121 fRobustFitExbAlt(kFALSE),
122 fAlternativeVdrfitFit(kFALSE),
123 fAlternativeExbAltFit(kFALSE),
125 fOutliersFitChargeLow(0.03),
126 fOutliersFitChargeHigh(0.7),
130 // default constructor
133 memset(fBadCalib, 0, sizeof(Int_t) * 18);
134 memset(fNoData, 0, sizeof(Int_t) * 18);
136 //_________________________________________________________________________________________________________________
137 AliTRDPreprocessorOffline::~AliTRDPreprocessorOffline() {
142 if(fCalDetGainUsed) delete fCalDetGainUsed;
143 if(fCalDetVdriftUsed) delete fCalDetVdriftUsed;
144 if(fCalDetExBUsed) delete fCalDetExBUsed;
145 if(fCH2d) delete fCH2d;
146 if(fPH2d) delete fPH2d;
147 if(fPRF2d) delete fPRF2d;
148 if(fSparse) delete fSparse;
149 if(fAliTRDCalibraVdriftLinearFit) delete fAliTRDCalibraVdriftLinearFit;
150 if(fAliTRDCalibraExbAltFit) delete fAliTRDCalibraExbAltFit;
151 if(fNEvents) delete fNEvents;
152 if(fAbsoluteGain) delete fAbsoluteGain;
153 if(fPlots) delete fPlots;
154 if(fCalibObjects) delete fCalibObjects;
157 //___________________________________________________________________________________
158 void AliTRDPreprocessorOffline::Process(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage)
161 // Process to the gain, vdrift, timeoffset, exb and chamber status calibration
164 if(SetCalDetGain(startRunNumber,fVersionGainUsed,fSubVersionGainUsed) && SetCalDetVdriftExB(startRunNumber,fVersionVdriftUsed,fSubVersionVdriftUsed,fVersionExBUsed,fSubVersionExBUsed)) {
166 CalibVdriftT0(file,startRunNumber,endRunNumber,ocdbStorage);
167 CalibGain(file,startRunNumber,endRunNumber,ocdbStorage);
168 CalibChamberStatus(file,startRunNumber,endRunNumber,ocdbStorage);
169 CalibExbAlt(file,startRunNumber,endRunNumber,ocdbStorage);
176 //___________________________________________________________________________________________________________________
178 void AliTRDPreprocessorOffline::CalibVdriftT0(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
180 // make calibration of the drift velocity
182 // file - the location of input file
183 // startRunNumber, endRunNumber - run validity period
184 // ocdbStorage - path to the OCDB storage
185 // - if empty - local storage 'pwd' uesed
186 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
190 fVdriftValidated = kTRUE;
191 fT0Validated = kTRUE;
192 fExBValidated = kTRUE;
193 fNotEnoughStatisticsForTheVdriftLinear = kFALSE;
195 // 2. extraction of the information
197 if(ReadVdriftLinearFitGlobal(file) && fCalDetVdriftUsed && fCalDetExBUsed) AnalyzeVdriftLinearFit();
198 if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
200 // 3. Append QA plots
202 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
205 // 4. validate OCDB entries
207 if(fSwitchOnValidation==kTRUE && ValidateVdrift()==kFALSE) {
208 //AliError("TRD vdrift OCDB parameters out of range!");
209 fVdriftValidated = kFALSE;
211 if(fSwitchOnValidation==kTRUE && ValidateT0()==kFALSE) {
212 //AliError("TRD t0 OCDB parameters out of range!");
213 fT0Validated = kFALSE;
215 if(fSwitchOnValidation==kTRUE && ValidateExB()==kFALSE) {
216 //AliError("TRD t0 OCDB parameters out of range!");
217 fExBValidated = kFALSE;
223 if(fVdriftValidated) UpdateOCDBVdrift(startRunNumber,endRunNumber,ocdbStorage);
224 if(fT0Validated) UpdateOCDBT0(startRunNumber,endRunNumber,ocdbStorage);
225 if(fExBValidated) UpdateOCDBExB(startRunNumber,endRunNumber,ocdbStorage);
228 //___________________________________________________________________________________________________________________
230 void AliTRDPreprocessorOffline::CalibExbAlt(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
232 // make calibration of the drift velocity
234 // file - the location of input file
235 // startRunNumber, endRunNumber - run validity period
236 // ocdbStorage - path to the OCDB storage
237 // - if empty - local storage 'pwd' uesed
238 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
244 // 2. extraction of the information
246 if(ReadExbAltFitGlobal(file)) AnalyzeExbAltFit();
248 // 3. Append QA plots
250 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
253 // 4. validate OCDB entries
259 UpdateOCDBExBAlt(startRunNumber,endRunNumber,ocdbStorage);
263 //_________________________________________________________________________________________________________________
265 void AliTRDPreprocessorOffline::CalibGain(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
267 // make calibration of the drift velocity
269 // file - the location of input file
270 // startRunNumber, endRunNumber - run validity period
271 // ocdbStorage - path to the OCDB storage
272 // - if empty - local storage 'pwd' uesed
273 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
275 fNotEnoughStatisticsForTheGain = kFALSE;
278 if(!ReadGainGlobal(file)) return;
281 // 2. extraction of the information
284 if(fBackCorrectGain) CorrectFromDetGainUsed();
285 //if(fBackCorrectVdrift) CorrectFromDetVdriftUsed();
287 // 3. Append QA plots
289 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
292 // 4. validate OCDB entries
294 if(fSwitchOnValidation==kTRUE && ValidateGain()==kFALSE) {
295 //AliError("TRD gain OCDB parameters out of range!");
302 if((!fCalDetVdriftUsed) || (fCalDetVdriftUsed && fVdriftValidated)) UpdateOCDBGain(startRunNumber,endRunNumber,ocdbStorage);
306 //________________________________________________________________________________________________________________
308 void AliTRDPreprocessorOffline::CalibPRF(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
310 // make calibration of the drift velocity
312 // file - the location of input file
313 // startRunNumber, endRunNumber - run validity period
314 // ocdbStorage - path to the OCDB storage
315 // - if empty - local storage 'pwd' uesed
316 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
319 if(!ReadPRFGlobal(file)) return;
322 // 2. extraction of the information
326 // 3. Append QA plots
328 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
332 // 4. validate OCDB entries
334 if(fSwitchOnValidation==kTRUE && ValidatePRF()==kFALSE) {
335 //AliError("TRD prf OCDB parameters out of range!");
342 UpdateOCDBPRF(startRunNumber,endRunNumber,ocdbStorage);
345 //________________________________________________________________________________________________________________
347 void AliTRDPreprocessorOffline::CalibChamberStatus(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
349 // make calibration of the chamber status
351 // startRunNumber, endRunNumber - run validity period
352 // ocdbStorage - path to the OCDB storage
353 // - if empty - local storage 'pwd' uesed
354 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
358 if(!ReadStatusGlobal(file)) return;
362 // 2. extraction of the information
364 if(!AnalyzeChamberStatus()) return;
366 // 3. Append QA plots
368 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
372 // 4. validate OCDB entries
374 if(fSwitchOnValidation==kTRUE && ValidateChamberStatus()==kFALSE) {
375 //AliError("TRD Chamber status OCDB parameters not ok!");
382 if((!fNotEnoughStatisticsForTheVdriftLinear) && (!fNotEnoughStatisticsForTheGain)) UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
383 //UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
386 //______________________________________________________________________________________________________
387 Bool_t AliTRDPreprocessorOffline::Init(const Char_t* fileName){
389 // read the calibration used during the reconstruction
392 if(ReadVdriftT0Global(fileName)) {
394 TString nameph = fPH2d->GetTitle();
395 fFirstRunVdriftUsed = GetFirstRun(nameph);
396 fVersionVdriftUsed = GetVersion(nameph);
397 fSubVersionVdriftUsed = GetSubVersion(nameph);
399 //printf("Found Version %d, Subversion %d for vdrift\n",fVersionVdriftUsed,fSubVersionVdriftUsed);
403 if(ReadGainGlobal(fileName)) {
405 TString namech = fCH2d->GetTitle();
406 fFirstRunGainUsed = GetFirstRun(namech);
407 fVersionGainUsed = GetVersion(namech);
408 fSubVersionGainUsed = GetSubVersion(namech);
410 //printf("Found Version %d, Subversion %d for gain\n",fVersionGainUsed,fSubVersionGainUsed);
414 if(ReadVdriftLinearFitGlobal(fileName)) {
416 TString namelinear = fAliTRDCalibraVdriftLinearFit->GetNameCalibUsed();
417 fFirstRunExBUsed = GetFirstRun(namelinear);
418 fVersionExBUsed = GetVersion(namelinear);
419 fSubVersionExBUsed = GetSubVersion(namelinear);
421 //printf("Found Version %d, Subversion %d, run %d for ExB\n",fVersionExBUsed,fSubVersionExBUsed,fFirstRunExBUsed);
425 if(fVersionVdriftUsed == 0) fStatusPos = fStatusPos |kVdriftErrorOld;
426 if(fVersionGainUsed == 0) fStatusPos = fStatusPos | kGainErrorOld;
431 //___________________________________________________________________________________________________________________
433 Bool_t AliTRDPreprocessorOffline::ReadStatusGlobal(const Char_t* fileName){
435 // read calibration entries from file
437 if(fSparse) return kTRUE;
438 TFile fcalib(fileName);
439 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
441 fSparse = (THnSparseI *) array->FindObject("NumberOfEntries");
442 if(!fSparse) return kFALSE;
450 //___________________________________________________________________________________________________________________
452 Bool_t AliTRDPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
454 // read calibration entries from file
456 if(fCH2d) return kTRUE;
457 TFile fcalib(fileName);
458 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
460 TH2I *ch2d = (TH2I *) array->FindObject("CH2d");
461 if(!ch2d) return kFALSE;
462 fCH2d = (TH2I*)ch2d->Clone();
463 //fNEvents = (TH1I *) array->FindObject("NEvents");
464 //fAbsoluteGain = (TH2F *) array->FindObject("AbsoluteGain");
466 TH2I *ch2d = (TH2I *) fcalib.Get("CH2d");
467 if(!ch2d) return kFALSE;
468 fCH2d = (TH2I*)ch2d->Clone();
469 //fNEvents = (TH1I *) fcalib.Get("NEvents");
470 //fAbsoluteGain = (TH2F *) fcalib.Get("AbsoluteGain");
472 fCH2d->SetDirectory(0);
473 //printf("title of CH2d %s\n",fCH2d->GetTitle());
478 //_________________________________________________________________________________________________________________
480 Bool_t AliTRDPreprocessorOffline::ReadVdriftT0Global(const Char_t* fileName){
482 // read calibration entries from file
484 if(fPH2d) return kTRUE;
485 TFile fcalib(fileName);
486 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
488 TProfile2D *ph2d = (TProfile2D *) array->FindObject("PH2d");
489 if(!ph2d) return kFALSE;
490 fPH2d = (TProfile2D*)ph2d->Clone();
491 //fNEvents = (TH1I *) array->FindObject("NEvents");
493 TProfile2D *ph2d = (TProfile2D *) fcalib.Get("PH2d");
494 if(!ph2d) return kFALSE;
495 fPH2d = (TProfile2D*)ph2d->Clone();
496 //fNEvents = (TH1I *) fcalib.Get("NEvents");
498 fPH2d->SetDirectory(0);
499 //printf("title of PH2d %s\n",fPH2d->GetTitle());
504 //___________________________________________________________________________________________________________________
506 Bool_t AliTRDPreprocessorOffline::ReadVdriftLinearFitGlobal(const Char_t* fileName){
508 // read calibration entries from file
510 if(fAliTRDCalibraVdriftLinearFit) return kTRUE;
511 TFile fcalib(fileName);
512 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
514 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) array->FindObject("AliTRDCalibraVdriftLinearFit");
515 //fNEvents = (TH1I *) array->FindObject("NEvents");
517 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) fcalib.Get("AliTRDCalibraVdriftLinearFit");
518 //fNEvents = (TH1I *) fcalib.Get("NEvents");
520 if(!fAliTRDCalibraVdriftLinearFit) {
521 //printf("No AliTRDCalibraVdriftLinearFit\n");
527 //_____________________________________________________________________________________________________________
528 Bool_t AliTRDPreprocessorOffline::ReadExbAltFitGlobal(const Char_t* fileName){
530 // read calibration entries from file
532 if(fAliTRDCalibraExbAltFit) return kTRUE;
533 TFile fcalib(fileName);
534 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
536 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) array->FindObject("AliTRDCalibraExbAltFit");
537 //fNEvents = (TH1I *) array->FindObject("NEvents");
539 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) fcalib.Get("AliTRDCalibraExbAltFit");
540 //fNEvents = (TH1I *) fcalib.Get("NEvents");
542 if(!fAliTRDCalibraExbAltFit) {
543 //printf("No AliTRDCalibraExbAltFit\n");
549 //_____________________________________________________________________________________________________________
551 Bool_t AliTRDPreprocessorOffline::ReadPRFGlobal(const Char_t* fileName){
553 // read calibration entries from file
555 if(fPRF2d) return kTRUE;
556 TFile fcalib(fileName);
557 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
559 TProfile2D *prf2d = (TProfile2D *) array->FindObject("PRF2d");
560 if(!prf2d) return kFALSE;
561 fPRF2d = (TProfile2D*)prf2d->Clone();
562 //fNEvents = (TH1I *) array->FindObject("NEvents");
564 TProfile2D *prf2d = (TProfile2D *) fcalib.Get("PRF2d");
565 if(!prf2d) return kFALSE;
566 fPRF2d = (TProfile2D*)prf2d->Clone();
567 //fNEvents = (TH1I *) fcalib.Get("NEvents");
569 fPRF2d->SetDirectory(0);
570 //printf("title of PRF2d %s\n",fPRF2d->GetTitle());
575 //__________________________________________________________________________________________________________
577 Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
579 // Analyze gain - produce the calibration objects
582 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
583 calibra->ChooseMethod(fMethodeGain);
584 calibra->SetBeginFitCharge(fBeginFitCharge);
585 calibra->SetFitOutliersChargeLow(fOutliersFitChargeLow);
586 calibra->SetFitOutliersChargeHigh(fOutliersFitChargeHigh);
587 calibra->SetMinEntries(fMinStatsGain); // If there is less than 1000 entries in the histo: no fit
588 calibra->AnalyseCH(fCH2d);
590 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
591 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
592 Int_t nbfit = calibra->GetNumberFit();
593 Int_t nbE = calibra->GetNumberEnt();
597 Bool_t meanother = kFALSE;
600 (nbfit >= 0.5*nbE) && (nbE > 30)) {
601 // create the cal objects
602 if(!fBackCorrectGain) {
603 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
606 TObjArray object = calibra->GetVectorFit();
607 AliTRDCalDet *calDetGain = calibra->CreateDetObjectGain(&object,meanother);
608 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
609 // Put them in the array
610 fCalibObjects->AddAt(calDetGain,kGain);
611 fPlots->AddAt(coefGain,kGain);
616 fNotEnoughStatisticsForTheGain = kTRUE;
617 Int_t minStatsGain = fMinStatsGain*30;
618 calibra->SetMinEntries(minStatsGain); // Because we do it for all, we increase this
619 Double_t gainoverallnotnormalized = calibra->AnalyseCHAllTogether(fCH2d);
620 if(fCalDetGainUsed && (gainoverallnotnormalized > 0.0)) {
621 AliTRDCalDet *calDetGain = new AliTRDCalDet(*fCalDetGainUsed);
622 Double_t oldmean = fCalDetGainUsed->CalcMean(kFALSE);
623 //printf("oldmean %f\n",oldmean);
625 Double_t scalefactor = calibra->GetScaleFactorGain();
626 //printf("Correction factor %f\n",gainoverallnotnormalized*scalefactor);
627 calDetGain->Multiply(gainoverallnotnormalized*scalefactor/oldmean);
628 //printf("newmean %f\n",calDetGain->CalcMean(kFALSE));
629 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
630 fCalibObjects->AddAt(calDetGain,kGain);
631 fPlots->AddAt(coefGain,kGain);
634 fStatusNeg = fStatusNeg | kGainNotEnoughStatsButFill;
637 fStatusPos = fStatusPos | kGainErrorOld;
641 if(gainoverallnotnormalized <= 0.0) fStatusNeg = fStatusNeg | kGainNotEnoughStatsNotFill;
642 if(!fCalDetGainUsed) fStatusPos = fStatusPos | kGainErrorOld;
646 calibra->ResetVectorFit();
651 //_____________________________________________________________________________________________________
652 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftT0(){
654 // Analyze VdriftT0 - produce the calibration objects
657 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
658 calibra->SetMinEntries(fMinStatsVdriftT0PH); // If there is less than 1000 entries in the histo: no fit
659 calibra->AnalysePH(fPH2d);
661 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
662 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
663 Int_t nbfit = calibra->GetNumberFit();
664 Int_t nbfitSuccess = calibra->GetNumberFitSuccess();
665 Int_t nbE = calibra->GetNumberEnt();
667 //printf("nbtg %d, nbfit %d, nbE %d, nbfitSuccess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
671 (nbfit >= 0.5*nbE) && (nbE > 30) && (nbfitSuccess > 30)) {
672 //printf("Pass the cut for VdriftT0\n");
673 // create the cal objects
674 calibra->RemoveOutliers(1,kFALSE);
675 calibra->PutMeanValueOtherVectorFit(1,kFALSE);
676 calibra->RemoveOutliers2(kFALSE);
677 calibra->PutMeanValueOtherVectorFit2(1,kFALSE);
679 TObjArray object = calibra->GetVectorFit();
680 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object);
681 TH1F *coefVdriftPH = calDetVdrift->MakeHisto1DAsFunctionOfDet();
682 AliTRDCalPad *calPadVdrift = (AliTRDCalPad *)calibra->CreatePadObjectVdrift(&object,calDetVdrift);
683 TH1F *coefPadVdrift = calPadVdrift->MakeHisto1D();
684 object = calibra->GetVectorFit2();
685 AliTRDCalDet *calDetT0 = calibra->CreateDetObjectT0(&object);
686 TH1F *coefT0 = calDetT0->MakeHisto1DAsFunctionOfDet();
687 AliTRDCalPad *calPadT0 = (AliTRDCalPad *)calibra->CreatePadObjectT0(&object,calDetT0);
688 TH1F *coefPadT0 = calPadT0->MakeHisto1D();
689 // Put them in the array
690 fCalibObjects->AddAt(calDetT0,kT0PHDet);
691 fCalibObjects->AddAt(calDetVdrift,kVdriftPHDet);
692 fCalibObjects->AddAt(calPadT0,kT0PHPad);
693 fCalibObjects->AddAt(calPadVdrift,kVdriftPHPad);
694 fPlots->AddAt(coefVdriftPH,kVdriftPHDet);
695 fPlots->AddAt(coefT0,kT0PHDet);
696 fPlots->AddAt(coefPadVdrift,kVdriftPHPad);
697 fPlots->AddAt(coefPadT0,kT0PHPad);
702 //printf("Not enough stats timeoffset\n");
703 fStatusNeg = fStatusNeg | kTimeOffsetNotEnoughStatsNotFill;
705 calibra->ResetVectorFit();
710 //____________________________________________________________________________________________________________________
711 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftLinearFit(){
713 // Analyze vdrift linear fit - produce the calibration objects
716 //printf("Analyse linear fit\n");
719 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
720 calibra->SetCalDetVdriftExB(fCalDetVdriftUsed,fCalDetExBUsed);
721 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
722 //printf("Fill PE Array\n");
723 fAliTRDCalibraVdriftLinearFit->SetRobustFit(fRobustFitDriftVelocity);
724 if(!fAlternativeVdrfitFit)
725 fAliTRDCalibraVdriftLinearFit->FillPEArray();
727 fAliTRDCalibraVdriftLinearFit->FillPEArray2();
728 //printf("AliTRDCalibraFit\n");
729 calibra->AnalyseLinearFitters(fAliTRDCalibraVdriftLinearFit);
733 Int_t nbfit = calibra->GetNumberFit();
734 Int_t nbE = calibra->GetNumberEnt();
739 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
740 // create the cal objects
741 //calibra->RemoveOutliers(1,kTRUE);
742 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
743 //calibra->RemoveOutliers2(kTRUE);
744 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
746 TObjArray object = calibra->GetVectorFit();
747 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object,kTRUE);
748 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
749 object = calibra->GetVectorFit2();
750 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectLorentzAngle(&object);
751 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
752 //if(!calDetLorentz) printf("No lorentz created\n");
753 // Put them in the array
754 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
755 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
756 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
757 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
762 fNotEnoughStatisticsForTheVdriftLinear = kTRUE;
763 Int_t minNumberOfEntriesForAll = fMinStatsVdriftLinear*30;
764 calibra->SetMinEntries(minNumberOfEntriesForAll); // Because we do it for all, we increase this
765 Double_t vdriftoverall = -100.0;
766 Double_t exboverall = 100.0;
767 calibra->AnalyseLinearFittersAllTogether(fAliTRDCalibraVdriftLinearFit,vdriftoverall,exboverall);
768 //printf("Found mean vdrift %f and exb %f\n",vdriftoverall,exboverall);
769 if(fCalDetVdriftUsed && (vdriftoverall > 0.0) && (exboverall < 70.0)) {
770 AliTRDCalDet *calDetVdrift = new AliTRDCalDet(*fCalDetVdriftUsed);
771 AliTRDCalDet *calDetLorentz = new AliTRDCalDet(*fCalDetExBUsed);
772 Double_t oldmeanvdrift = fCalDetVdriftUsed->CalcMean(kFALSE);
773 Double_t oldmeanexb = fCalDetExBUsed->CalcMean(kFALSE);
774 //printf("oldmean %f\n",oldmean);
775 if((oldmeanvdrift > 0.0) && (oldmeanexb < 70.0)) {
776 //printf("Correction factor %f\n",vdriftoverall);
777 calDetVdrift->Multiply(vdriftoverall/oldmeanvdrift);
778 if(TMath::Abs(oldmeanexb) > 0.0001) calDetLorentz->Multiply(exboverall/oldmeanexb);
779 //printf("newmean %f\n",calDetVdrift->CalcMean(kFALSE));
780 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
781 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
782 // Put them in the array
783 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
784 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
785 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
786 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
789 fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsButFill;
792 if(oldmeanvdrift) fStatusPos = fStatusPos | kVdriftErrorOld;
793 if(oldmeanexb) fStatusPos = fStatusPos | kExBErrorOld;
797 if((vdriftoverall <= 0.0) && (exboverall > 70.0)) fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsNotFill;
798 if(!fCalDetVdriftUsed) fStatusPos = fStatusPos | kVdriftErrorOld;
799 if(!fCalDetExBUsed) fStatusPos = fStatusPos | kExBErrorOld;
803 calibra->ResetVectorFit();
808 //________________________________________________________________________________________________________________
810 Bool_t AliTRDPreprocessorOffline::AnalyzeExbAltFit(){
812 // Analyze vdrift linear fit - produce the calibration objects
815 //printf("Analyse linear fit\n");
818 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
819 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
820 //printf("Fill PE Array\n");
821 fAliTRDCalibraExbAltFit->SetRobustFit(fRobustFitExbAlt);
822 if(!fAlternativeExbAltFit)
823 fAliTRDCalibraExbAltFit->FillPEArray();
825 fAliTRDCalibraExbAltFit->FillPEArray2();
826 //printf("AliTRDCalibraFit\n");
827 calibra->AnalyseExbAltFit(fAliTRDCalibraExbAltFit);
831 Int_t nbfit = calibra->GetNumberFit();
832 Int_t nbE = calibra->GetNumberEnt();
837 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
838 // create the cal objects
839 //calibra->RemoveOutliers(1,kTRUE);
840 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
842 TObjArray object = calibra->GetVectorFit2();
843 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectExbAlt(&object);
844 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
845 //if(!calDetLorentz) printf("No lorentz created\n");
846 // Put them in the array
847 fCalibObjects->AddAt(calDetLorentz,kExbAlt);
848 fPlots->AddAt(coefLorentzAngle,kExbAlt);
853 calibra->ResetVectorFit();
858 //________________________________________________________________________________________________________________
860 Bool_t AliTRDPreprocessorOffline::AnalyzePRF(){
862 // Analyze PRF - produce the calibration objects
865 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
866 calibra->SetMinEntries(fMinStatsPRF); // If there is less than 1000 entries in the histo: no fit
867 calibra->AnalysePRFMarianFit(fPRF2d);
869 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
870 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
871 Int_t nbfit = calibra->GetNumberFit();
872 Int_t nbE = calibra->GetNumberEnt();
878 (nbfit >= 0.95*nbE) && (nbE > 30)) {
879 // create the cal objects
880 TObjArray object = calibra->GetVectorFit();
881 AliTRDCalPad *calPadPRF = (AliTRDCalPad*) calibra->CreatePadObjectPRF(&object);
882 TH1F *coefPRF = calPadPRF->MakeHisto1D();
883 // Put them in the array
884 fCalibObjects->AddAt(calPadPRF,kPRF);
885 fPlots->AddAt(coefPRF,kPRF);
890 calibra->ResetVectorFit();
896 //_____________________________________________________________________________
897 Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
900 // Produce AliTRDCalChamberStatus out of calibration results
903 // set up AliTRDCalibChamberStatus
904 AliTRDCalibChamberStatus *chamberStatus = new AliTRDCalibChamberStatus();
905 chamberStatus->SetSparseI(fSparse);
906 chamberStatus->AnalyseHisto(fMinStatsChamberStatus, fMinSingleStatsChamberStatus);
907 // get AliTRDCalChamberStatus
908 AliTRDCalChamberStatus *calChamberStatus = chamberStatus->GetCalChamberStatus();
910 // get calibration objects
911 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
912 AliTRDCalDet *calDetVDrift = (AliTRDCalDet *) fCalibObjects->At(kVdriftLinear);
913 AliTRDCalDet *calDetExB = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
916 if((!calDetGain) || (!calDetVDrift) || (!fCH2d) || (!calDetExB) || (!calChamberStatus)) return kFALSE;
919 Double_t gainmean = calDetGain->GetMean();
920 Double_t vdriftmean = calDetVDrift->GetMean();
921 Double_t exbmean = calDetExB->GetMean();
923 Double_t gainrms = calDetGain->GetRMSRobust();
924 Double_t vdriftrms = calDetVDrift->GetRMSRobust();
925 Double_t exbrms = calDetExB->GetRMSRobust();
927 //printf("Gain mean: %f, rms: %f\n",gainmean,gainrms);
928 //printf("Vdrift mean: %f, rms: %f\n",vdriftmean,vdriftrms);
929 //printf("ExB mean: %f, rms: %f\n",exbmean,exbrms);
932 if((TMath::Abs(gainrms) < 0.001) || (TMath::Abs(vdriftrms) < 0.001) || (TMath::Abs(exbrms) < 0.0000001)) return kFALSE;
934 // mask chambers with empty gain entries
936 for (Int_t idet = 0; idet < 540; idet++) {
939 TH1I *projch = (TH1I *) fCH2d->ProjectionX("projch",idet+1,idet+1,(Option_t *)"e");
940 Double_t entries = projch->GetEntries();
941 //printf("Number of entries %f for det %d\n",entries,idet);
944 Double_t gain = calDetGain->GetValue(idet);
947 Double_t vdrift = calDetVDrift->GetValue(idet);
950 Double_t exb = calDetExB->GetValue(idet);
953 if( (entries<50 && !calChamberStatus->IsNoData(idet)) ||
954 TMath::Abs(gainmean-gain) > (fRMSBadCalibratedGain*gainrms) ||
955 TMath::Abs(vdriftmean-vdrift) > (fRMSBadCalibratedVdrift*vdriftrms) ||
956 TMath::Abs(exbmean-exb) > (fRMSBadCalibratedExB*exbrms) ) {
958 //printf(" chamber det %03d masked \n",idet);
959 //printf(" gainmean %f and gain %f, gainrms %f \n",gainmean,gain,gainrms);
960 //printf(" vdriftmean %f and vdrift %f, vdriftrms %f \n",vdriftmean,vdrift,vdriftrms);
961 //printf(" exbmean %f and exb %f, exbrms %f \n",exbmean,exb,exbrms);
963 calChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kBadCalibrated);
972 for(Int_t sm=0; sm < 18; sm++) {
974 Int_t smbadcalib = 0;
975 for(Int_t det = 0; det < 30; det++){
976 Int_t detector = sm*30+det;
977 if(calChamberStatus->IsNoData(detector)) smnodata++;
979 if(calChamberStatus->IsBadCalibrated(detector)) smbadcalib++;
982 fNoData[sm] = smnodata;
983 fBadCalib[sm]= smbadcalib;
984 //printf("No Data %d, bad calibrated %d for %d\n",fNoData[sm],fBadCalib[sm],sm);
988 // for(Int_t sm=0; sm < 18; sm++) {
989 // Int_t counter = 0;
990 // for(Int_t det = 0; det < 30; det++){
991 // Int_t detector = sm*30+det;
992 // if(calChamberStatus->IsBadCalibrated(detector)) counter++;
994 // if(counter >= 20) {
995 // for(Int_t det = 0; det < 30; det++){
996 // Int_t detector = sm*30+det;
997 // calChamberStatus->SetStatus(detector,AliTRDCalChamberStatus::kGood);
1002 fCalibObjects->AddAt(calChamberStatus,kChamberStatus);
1008 //________________________________________________________________________________________________
1009 void AliTRDPreprocessorOffline::CorrectFromDetGainUsed() {
1011 // Correct from the gas gain used afterwards
1013 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1014 if(!calDetGain) return;
1017 Double_t mean = 0.0;
1020 for(Int_t det = 0; det < 540; det++) {
1022 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1023 Float_t gainout = calDetGain->GetValue(det);
1026 if(TMath::Abs(gainout-1.0) > 0.000001) {
1027 mean += (gaininit*gainout);
1031 if(nbdet > 0) mean = mean/nbdet;
1033 for(Int_t det = 0; det < 540; det++) {
1035 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1036 Float_t gainout = calDetGain->GetValue(det);
1038 if(TMath::Abs(gainout-1.0) > 0.000001) {
1039 Double_t newgain = gaininit*gainout;
1040 if(newgain < 0.1) newgain = 0.1;
1041 if(newgain > 1.9) newgain = 1.9;
1042 calDetGain->SetValue(det,newgain);
1045 Double_t newgain = mean;
1046 if(newgain < 0.1) newgain = 0.1;
1047 if(newgain > 1.9) newgain = 1.9;
1048 calDetGain->SetValue(det,newgain);
1054 //________________________________________________________________________________________________
1055 void AliTRDPreprocessorOffline::CorrectFromDetVdriftUsed() {
1057 // Correct from the drift velocity
1060 //printf("Correct for vdrift\n");
1062 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1063 if(!calDetGain) return;
1065 Int_t detVdrift = kVdriftPHDet;
1066 if(fMethodSecond) detVdrift = kVdriftLinear;
1067 AliTRDCalDet *calDetVdrift = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1068 if(!calDetVdrift) return;
1071 if(!fNotEnoughStatisticsForTheVdriftLinear) {
1072 for(Int_t det = 0; det < 540; det++) {
1074 Float_t vdriftinit = fCalDetVdriftUsed->GetValue(det);
1075 Float_t vdriftout = calDetVdrift->GetValue(det);
1077 Float_t gain = calDetGain->GetValue(det);
1078 if(vdriftout > 0.0) gain = gain*vdriftinit/vdriftout;
1079 if(gain < 0.1) gain = 0.1;
1080 if(gain > 1.9) gain = 1.9;
1081 calDetGain->SetValue(det,gain);
1086 Float_t vdriftinit = fCalDetVdriftUsed->CalcMean(kFALSE);
1087 Float_t vdriftout = calDetVdrift->CalcMean(kFALSE);
1088 Float_t factorcorrectif = 1.0;
1089 if(vdriftout > 0.0) factorcorrectif = vdriftinit/vdriftout;
1090 for(Int_t det = 0; det < 540; det++) {
1091 Float_t gain = calDetGain->GetValue(det);
1092 gain = gain*factorcorrectif;
1093 if(gain < 0.1) gain = 0.1;
1094 if(gain > 1.9) gain = 1.9;
1095 calDetGain->SetValue(det,gain);
1101 //_________________________________________________________________________________________________________________
1102 void AliTRDPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1104 // Update OCDB entry
1107 AliCDBMetaData *metaData= new AliCDBMetaData();
1108 metaData->SetObjectClassName("AliTRDCalDet");
1109 metaData->SetResponsible("Raphaelle Bailhache");
1110 metaData->AddDateToComment();
1111 metaData->SetBeamPeriod(1);
1113 AliCDBId id1("TRD/Calib/ChamberGainFactor", startRunNumber, endRunNumber);
1114 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1115 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1116 if(calDet) gStorage->Put(calDet, id1, metaData);
1120 //___________________________________________________________________________________________________________________
1121 void AliTRDPreprocessorOffline::UpdateOCDBExB(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1123 // Update OCDB entry
1126 Int_t detExB = kLorentzLinear;
1127 if(!fMethodSecond) return;
1131 AliCDBMetaData *metaData= new AliCDBMetaData();
1132 metaData->SetObjectClassName("AliTRDCalDet");
1133 metaData->SetResponsible("Raphaelle Bailhache");
1134 metaData->AddDateToComment();
1135 metaData->SetBeamPeriod(1);
1137 AliCDBId id1("TRD/Calib/ChamberExB", startRunNumber, endRunNumber);
1138 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1139 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1140 if(calDet) gStorage->Put(calDet, id1, metaData);
1141 //if(!calDet) printf("No caldet\n");
1144 //___________________________________________________________________________________________________________________
1145 void AliTRDPreprocessorOffline::UpdateOCDBExBAlt(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1147 // Update OCDB entry
1150 Int_t detExB = kExbAlt;
1151 if(!fMethodSecond) return;
1155 AliCDBMetaData *metaData= new AliCDBMetaData();
1156 metaData->SetObjectClassName("AliTRDCalDet");
1157 metaData->SetResponsible("Theo Rascanu");
1158 metaData->AddDateToComment();
1159 metaData->SetBeamPeriod(1);
1161 AliCDBId id1("TRD/Calib/ChamberExBAlt", startRunNumber, endRunNumber);
1162 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1163 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
1164 if(calDet) gStorage->Put(calDet, id1, metaData);
1165 //if(!calDet) printf("No caldet\n");
1168 //___________________________________________________________________________________________________________________
1169 void AliTRDPreprocessorOffline::UpdateOCDBVdrift(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1171 // Update OCDB entry
1174 Int_t detVdrift = kVdriftPHDet;
1176 if(fMethodSecond) detVdrift = kVdriftLinear;
1178 AliCDBMetaData *metaData= new AliCDBMetaData();
1179 metaData->SetObjectClassName("AliTRDCalDet");
1180 metaData->SetResponsible("Raphaelle Bailhache");
1181 metaData->AddDateToComment();
1182 metaData->SetBeamPeriod(1);
1184 AliCDBId id1("TRD/Calib/ChamberVdrift", startRunNumber, endRunNumber);
1185 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1186 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1187 if(calDet) gStorage->Put(calDet, id1, metaData);
1191 if(!fMethodSecond) {
1193 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1194 metaDataPad->SetObjectClassName("AliTRDCalPad");
1195 metaDataPad->SetResponsible("Raphaelle Bailhache");
1196 metaDataPad->AddDateToComment();
1197 metaDataPad->SetBeamPeriod(1);
1199 AliCDBId id1Pad("TRD/Calib/LocalVdrift", startRunNumber, endRunNumber);
1200 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1201 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
1206 //________________________________________________________________________________________________________________________
1207 void AliTRDPreprocessorOffline::UpdateOCDBT0(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1209 // Update OCDB entry
1212 AliCDBMetaData *metaData= new AliCDBMetaData();
1213 metaData->SetObjectClassName("AliTRDCalDet");
1214 metaData->SetResponsible("Raphaelle Bailhache");
1215 metaData->AddDateToComment();
1216 metaData->SetBeamPeriod(1);
1218 AliCDBId id1("TRD/Calib/ChamberT0", startRunNumber, endRunNumber);
1219 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1220 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1221 if(calDet) gStorage->Put(calDet, id1, metaData);
1225 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1226 metaDataPad->SetObjectClassName("AliTRDCalPad");
1227 metaDataPad->SetResponsible("Raphaelle Bailhache");
1228 metaDataPad->AddDateToComment();
1229 metaDataPad->SetBeamPeriod(1);
1231 AliCDBId id1Pad("TRD/Calib/LocalT0", startRunNumber, endRunNumber);
1232 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1233 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
1238 //_________________________________________________________________________________________________________________
1239 void AliTRDPreprocessorOffline::UpdateOCDBPRF(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1241 // Update OCDB entry
1244 AliCDBMetaData *metaData= new AliCDBMetaData();
1245 metaData->SetObjectClassName("AliTRDCalPad");
1246 metaData->SetResponsible("Raphaelle Bailhache");
1247 metaData->AddDateToComment();
1248 metaData->SetBeamPeriod(1);
1251 AliCDBId id1("TRD/Calib/PRFWidth", startRunNumber, endRunNumber);
1252 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1253 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1254 if(calPad) gStorage->Put(calPad, id1, metaData);
1258 //_________________________________________________________________________________________________________________
1259 void AliTRDPreprocessorOffline::UpdateOCDBChamberStatus(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1261 // Update OCDB entry
1264 AliCDBMetaData *metaData= new AliCDBMetaData();
1265 metaData->SetObjectClassName("AliTRDCalChamberStatus");
1266 metaData->SetResponsible("Raphaelle Bailhache and Julian Book");
1267 metaData->AddDateToComment();
1268 metaData->SetBeamPeriod(1);
1270 AliCDBId id1("TRD/Calib/ChamberStatus", startRunNumber, endRunNumber);
1271 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1272 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1273 if(calChamberStatus) gStorage->Put(calChamberStatus, id1, metaData);
1277 //__________________________________________________________________________________________________________________________
1278 Bool_t AliTRDPreprocessorOffline::ValidateGain() {
1280 // Validate OCDB entry
1283 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1285 Double_t mean = calDet->GetMean();
1286 Double_t rms = calDet->GetRMSRobust();
1287 if((mean > 0.2) && (mean < 1.4) && (rms < 0.5)) return kTRUE;
1288 //if((mean > 0.2) && (mean < 1.4)) return kTRUE;
1290 fStatusPos = fStatusPos | kGainErrorRange;
1299 //__________________________________________________________________________________________________________________________
1300 Bool_t AliTRDPreprocessorOffline::ValidateVdrift(){
1302 // Update OCDB entry
1305 Int_t detVdrift = kVdriftPHDet;
1308 if(fMethodSecond) detVdrift = kVdriftLinear;
1310 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1312 Double_t mean = calDet->GetMean();
1313 Double_t rms = calDet->GetRMSRobust();
1314 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1315 if(!((mean > 1.0) && (mean < 2.0) && (rms < 0.5))) {
1316 fStatusPos = fStatusPos | kVdriftErrorRange;
1322 if(!fMethodSecond) {
1323 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1325 Double_t mean = calPad->GetMean();
1326 Double_t rms = calPad->GetRMS();
1327 //printf("Vdrift::meanpad %f, rmspad %f\n",mean,rms);
1328 if(!((mean > 0.9) && (mean < 1.1) && (rms < 0.6))) {
1329 fStatusPos = fStatusPos | kVdriftErrorRange;
1339 //__________________________________________________________________________________________________________________________
1340 Bool_t AliTRDPreprocessorOffline::ValidateExB(){
1342 // Update OCDB entry
1345 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
1347 Double_t mean = calDet->GetMean();
1348 Double_t rms = calDet->GetRMSRobust();
1349 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1350 if(!((mean > -1.0) && (mean < 1.0) && (rms < 0.5))) {
1351 fStatusNeg = fStatusNeg | kExBErrorRange;
1359 //__________________________________________________________________________________________________________________________
1360 Bool_t AliTRDPreprocessorOffline::ValidateT0(){
1362 // Update OCDB entry
1365 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1366 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1367 if(calDet && calPad) {
1368 Double_t meandet = calDet->GetMean();
1369 Double_t rmsdet = calDet->GetRMSRobust();
1370 Double_t meanpad = calPad->GetMean();
1371 //Double_t rmspad = calPad->GetRMS();
1372 //printf("T0::minimum %f, rmsdet %f,meanpad %f, rmspad %f\n",meandet,rmsdet,meanpad,rmspad);
1373 if((meandet > -1.5) && (meandet < 5.0) && (rmsdet < 4.0) && (meanpad < 5.0) && (meanpad > -0.5)) return kTRUE;
1375 fStatusPos = fStatusPos | kTimeOffsetErrorRange;
1382 //__________________________________________________________________________________________________________________________
1383 Bool_t AliTRDPreprocessorOffline::ValidatePRF() const{
1385 // Update OCDB entry
1388 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1390 Double_t meanpad = calPad->GetMean();
1391 Double_t rmspad = calPad->GetRMS();
1392 //printf("PRF::meanpad %f, rmspad %f\n",meanpad,rmspad);
1393 if((meanpad < 1.0) && (rmspad < 0.8)) return kTRUE;
1400 //__________________________________________________________________________________________________________________________
1401 Bool_t AliTRDPreprocessorOffline::ValidateChamberStatus(){
1403 // Update OCDB entry
1406 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1407 if(calChamberStatus) {
1409 Int_t detectornodata = 0;
1410 Int_t detectorbadcalib = 0;
1412 for(Int_t sm=0; sm < 18; sm++) {
1413 //printf("%d chambers w/o data in sm %d\n",fNoData[sm],sm);
1414 //printf("%d bad calibrated chambers in sm %d\n",fBadCalib[sm],sm);
1415 if(fNoData[sm] != 30) detectornodata += fNoData[sm];
1416 detectorbadcalib+=fBadCalib[sm];
1418 //printf("Number of chambers w/o data %d\n",detectornodata);
1419 //printf("Number of chambers bad calibrated %d\n",detectorbadcalib);
1421 if((detectornodata > fNoDataValidate) ||
1422 (detectorbadcalib > fBadCalibValidate)){
1423 fStatusPos = fStatusPos | kChamberStatusErrorRange;
1431 //_____________________________________________________________________________
1432 Int_t AliTRDPreprocessorOffline::GetVersion(TString name) const
1435 // Get version from the title
1439 const Char_t *version = "Ver";
1440 if(!strstr(name.Data(),version)) return -1;
1441 const Char_t *after = "Subver";
1442 if(!strstr(name.Data(),after)) return -1;
1444 for(Int_t ver = 0; ver < 999999999; ver++) {
1446 TString vertry(version);
1450 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1452 if(strstr(name.Data(),vertry.Data())) return ver;
1460 //_____________________________________________________________________________
1461 Int_t AliTRDPreprocessorOffline::GetSubVersion(TString name) const
1464 // Get subversion from the title
1468 const Char_t *subversion = "Subver";
1469 if(!strstr(name.Data(),subversion)) return -1;
1470 const Char_t *after = "FirstRun";
1471 if(!strstr(name.Data(),after)) {
1474 if(!strstr(name.Data(),after)) return -1;
1477 for(Int_t ver = 0; ver < 999999999; ver++) {
1479 TString vertry(subversion);
1483 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1485 if(strstr(name.Data(),vertry.Data())) return ver;
1493 //_____________________________________________________________________________
1494 Int_t AliTRDPreprocessorOffline::GetFirstRun(TString name) const
1497 // Get first run from the title
1501 const Char_t *firstrun = "FirstRun";
1502 if(!strstr(name.Data(),firstrun)) return -1;
1503 const Char_t *after = "Nz";
1504 if(!strstr(name.Data(),after)) return -1;
1507 for(Int_t ver = 0; ver < 999999999; ver++) {
1509 TString vertry(firstrun);
1513 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1515 if(strstr(name.Data(),vertry.Data())) return ver;
1522 //_____________________________________________________________________________
1523 Bool_t AliTRDPreprocessorOffline::CheckStatus(Int_t status, Int_t bitMask) const
1526 // Checks the status
1529 return (status & bitMask) ? kTRUE : kFALSE;
1532 //_____________________________________________________________________________
1533 Int_t AliTRDPreprocessorOffline::GetStatus() const
1536 // Checks the status
1537 // fStatusPos: errors
1538 // fStatusNeg: only info
1541 if(fStatusPos > 0) return fStatusPos;
1542 else return (-TMath::Abs(fStatusNeg));
1545 //_____________________________________________________________________________
1546 void AliTRDPreprocessorOffline::PrintStatus() const
1552 AliInfo(Form("The error status is %d",fStatusPos));
1553 AliInfo(Form("IsGainErrorOld? %d",(Int_t)IsGainErrorOld()));
1554 AliInfo(Form("IsVdriftErrorOld? %d",(Int_t)IsVdriftErrorOld()));
1555 AliInfo(Form("IsGainErrorRange? %d",(Int_t)IsGainErrorRange()));
1556 AliInfo(Form("IsVdriftErrorRange? %d",(Int_t)IsVdriftErrorRange()));
1557 AliInfo(Form("IsTimeOffsetErrorRange? %d",(Int_t)IsTimeOffsetErrorRange()));
1558 AliInfo(Form("IsChamberStatusErrorRange? %d",(Int_t)IsChamberStatusErrorRange()));
1561 AliInfo(Form("The info status is %d",fStatusNeg));
1562 AliInfo(Form("IsGainNotEnoughStatsButFill? %d",(Int_t)IsGainNotEnoughStatsButFill()));
1563 AliInfo(Form("IsVdriftNotEnoughStatsButFill? %d",(Int_t)IsVdriftNotEnoughStatsButFill()));
1564 AliInfo(Form("IsGainNotEnoughStatsNotFill? %d",(Int_t)IsGainNotEnoughStatsNotFill()));
1565 AliInfo(Form("IsVdriftNotEnoughStatsNotFill? %d",(Int_t)IsVdriftNotEnoughStatsNotFill()));
1566 AliInfo(Form("IsTimeOffsetNotEnoughStatsNotFill? %d",(Int_t)IsTimeOffsetNotEnoughStatsNotFill()));
1568 AliInfo(Form("IsExBErrorRange? %d",(Int_t)IsExBErrorRange()));
1569 AliInfo(Form("IsExBErrorOld? %d",(Int_t)IsExBErrorOld()));
1572 //___________________________________________________________________________________
1573 void AliTRDPreprocessorOffline::SetCalDetVdrift(AliTRDCalDet *calDetVdriftUsed)
1576 fCalDetVdriftUsed = calDetVdriftUsed;
1578 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1579 for(Int_t k = 0; k < 540; k++){
1580 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1581 //printf("Set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1585 //___________________________________________________________________________________
1586 Bool_t AliTRDPreprocessorOffline::SetCalDetGain(Int_t runNumber, Int_t version, Int_t subversion)
1589 // Set the fCalDetGainUsed
1592 if((version == 0) && (subversion == 0)) return kFALSE;
1594 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor",runNumber, version, subversion);
1596 AliError("Found no entry\n");
1597 fStatusPos = fStatusPos | kGainErrorOld;
1600 //const AliCDBId id = entry->GetId();
1601 //version = id.GetVersion();
1602 //subversion = id.GetSubVersion();
1603 //printf("Found version %d and subversion %d for vdrift\n",version,subversion);
1604 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1605 if(calDet) fCalDetGainUsed = calDet;
1607 fStatusPos = fStatusPos | kGainErrorOld;
1614 //___________________________________________________________________________________
1615 Bool_t AliTRDPreprocessorOffline::SetCalDetVdriftExB(Int_t runNumber, Int_t versionv, Int_t subversionv, Int_t versionexb, Int_t subversionexb)
1618 // Set the fCalDetVdriftUsed and fCalDetExBUsed
1621 if((versionv == 0) && (subversionv == 0)) return kFALSE;
1623 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberVdrift",runNumber, versionv, subversionv);
1625 AliError("Found no entry\n");
1626 fStatusPos = fStatusPos | kVdriftErrorOld;
1629 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1630 if(calDet) fCalDetVdriftUsed = calDet;
1632 fStatusPos = fStatusPos | kVdriftErrorOld;
1638 if((versionexb == 0) && (subversionexb == 0)) {
1640 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1641 for(Int_t k = 0; k < 540; k++){
1642 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1643 //printf("Nothing found: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1649 entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberExB",runNumber, versionexb, subversionexb);
1651 //printf("Found no entry\n");
1652 fStatusPos = fStatusPos | kExBErrorOld;
1655 AliTRDCalDet* calDetexb = (AliTRDCalDet *)entry->GetObject();
1657 fStatusPos = fStatusPos | kExBErrorOld;
1661 Double_t meanexb = calDetexb->GetMean();
1662 //printf("Mean value %f\n",meanexb);
1663 if((meanexb > 70) || (fNoExBUsedInReco)) {
1664 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1665 for(Int_t k = 0; k < 540; k++){
1666 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1667 //printf("Found but: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1671 fCalDetExBUsed = calDetexb;