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 "TProfile2D.h"
51 #include "AliTRDCalDet.h"
52 #include "AliTRDCalPad.h"
53 #include "AliCDBMetaData.h"
55 #include "AliCDBManager.h"
56 #include "AliCDBStorage.h"
57 #include "AliTRDCalibraMode.h"
58 #include "AliTRDCalibraFit.h"
59 #include "AliTRDCalibraVdriftLinearFit.h"
60 #include "AliTRDPreprocessorOffline.h"
61 #include "AliTRDCalChamberStatus.h"
64 ClassImp(AliTRDPreprocessorOffline)
66 AliTRDPreprocessorOffline::AliTRDPreprocessorOffline():
67 TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
69 fNameList("TRDCalib"),
71 fCalDetVdriftUsed(0x0),
75 fAliTRDCalibraVdriftLinearFit(0x0),
78 fPlots(new TObjArray(9)),
79 fCalibObjects(new TObjArray(9)),
81 fSubVersionGainUsed(0),
82 fFirstRunVdriftUsed(0),
83 fVersionVdriftUsed(0),
84 fSubVersionVdriftUsed(0),
85 fSwitchOnValidation(kTRUE),
86 fVdriftValidated(kFALSE),
88 fMinStatsVdriftT0PH(800*20),
89 fMinStatsVdriftLinear(800),
92 fBackCorrectGain(kFALSE),
93 fBackCorrectVdrift(kTRUE),
94 fNotEnoughStatisticsForTheGain(kFALSE),
95 fNotEnoughStatisticsForTheVdriftLinear(kFALSE),
100 // default constructor
103 //_________________________________________________________________________________________________________________
104 AliTRDPreprocessorOffline::~AliTRDPreprocessorOffline() {
109 if(fCalDetGainUsed) delete fCalDetGainUsed;
110 if(fCalDetVdriftUsed) delete fCalDetVdriftUsed;
111 if(fCH2d) delete fCH2d;
112 if(fPH2d) delete fPH2d;
113 if(fPRF2d) delete fPRF2d;
114 if(fAliTRDCalibraVdriftLinearFit) delete fAliTRDCalibraVdriftLinearFit;
115 if(fNEvents) delete fNEvents;
116 if(fAbsoluteGain) delete fAbsoluteGain;
117 if(fPlots) delete fPlots;
118 if(fCalibObjects) delete fCalibObjects;
121 //___________________________________________________________________________________________________________________
123 void AliTRDPreprocessorOffline::CalibVdriftT0(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
125 // make calibration of the drift velocity
127 // file - the location of input file
128 // startRunNumber, endRunNumber - run validity period
129 // ocdbStorage - path to the OCDB storage
130 // - if empty - local storage 'pwd' uesed
131 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
135 fVdriftValidated = kTRUE;
136 fT0Validated = kTRUE;
137 fNotEnoughStatisticsForTheVdriftLinear = kFALSE;
139 // 2. extraction of the information
141 if(ReadVdriftLinearFitGlobal(file)) AnalyzeVdriftLinearFit();
142 if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
144 // 3. Append QA plots
146 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
149 // 4. validate OCDB entries
151 if(fSwitchOnValidation==kTRUE && ValidateVdrift()==kFALSE) {
152 //AliError("TRD vdrift OCDB parameters out of range!");
153 fVdriftValidated = kFALSE;
155 if(fSwitchOnValidation==kTRUE && ValidateT0()==kFALSE) {
156 //AliError("TRD t0 OCDB parameters out of range!");
157 fT0Validated = kFALSE;
163 if(fVdriftValidated) UpdateOCDBVdrift(startRunNumber,endRunNumber,ocdbStorage);
164 if(fT0Validated) UpdateOCDBT0(startRunNumber,endRunNumber,ocdbStorage);
165 UpdateOCDBExB(startRunNumber,endRunNumber,ocdbStorage);
168 //_________________________________________________________________________________________________________________
170 void AliTRDPreprocessorOffline::CalibGain(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
172 // make calibration of the drift velocity
174 // file - the location of input file
175 // startRunNumber, endRunNumber - run validity period
176 // ocdbStorage - path to the OCDB storage
177 // - if empty - local storage 'pwd' uesed
178 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
180 fNotEnoughStatisticsForTheGain = kFALSE;
183 if(!ReadGainGlobal(file)) return;
186 // 2. extraction of the information
189 if(fBackCorrectGain) CorrectFromDetGainUsed();
190 if(fBackCorrectVdrift) CorrectFromDetVdriftUsed();
192 // 3. Append QA plots
194 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
197 // 4. validate OCDB entries
199 if(fSwitchOnValidation==kTRUE && ValidateGain()==kFALSE) {
200 //AliError("TRD gain OCDB parameters out of range!");
207 if((!fCalDetVdriftUsed) || (fCalDetVdriftUsed && fVdriftValidated)) UpdateOCDBGain(startRunNumber,endRunNumber,ocdbStorage);
211 //________________________________________________________________________________________________________________
213 void AliTRDPreprocessorOffline::CalibPRF(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
215 // make calibration of the drift velocity
217 // file - the location of input file
218 // startRunNumber, endRunNumber - run validity period
219 // ocdbStorage - path to the OCDB storage
220 // - if empty - local storage 'pwd' uesed
221 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
224 if(!ReadPRFGlobal(file)) return;
227 // 2. extraction of the information
231 // 3. Append QA plots
233 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
237 // 4. validate OCDB entries
239 if(fSwitchOnValidation==kTRUE && ValidatePRF()==kFALSE) {
240 //AliError("TRD prf OCDB parameters out of range!");
247 UpdateOCDBPRF(startRunNumber,endRunNumber,ocdbStorage);
250 //________________________________________________________________________________________________________________
252 void AliTRDPreprocessorOffline::CalibChamberStatus(Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
254 // make calibration of the chamber status
256 // startRunNumber, endRunNumber - run validity period
257 // ocdbStorage - path to the OCDB storage
258 // - if empty - local storage 'pwd' uesed
259 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
262 // 2. extraction of the information
264 if(!AnalyzeChamberStatus()) return;
266 // 3. Append QA plots
268 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
272 // 4. validate OCDB entries
274 if(fSwitchOnValidation==kTRUE && ValidateChamberStatus()==kFALSE) {
275 //AliError("TRD Chamber status OCDB parameters not ok!");
282 if((!fNotEnoughStatisticsForTheGain) && (!fNotEnoughStatisticsForTheGain)) UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
285 //______________________________________________________________________________________________________
286 Bool_t AliTRDPreprocessorOffline::Init(const Char_t* fileName){
288 // read the calibration used during the reconstruction
291 if(ReadVdriftT0Global(fileName)) {
293 TString nameph = fPH2d->GetTitle();
294 fFirstRunVdriftUsed = GetFirstRun(nameph);
295 fVersionVdriftUsed = GetVersion(nameph);
296 fSubVersionVdriftUsed = GetSubVersion(nameph);
298 //printf("Found Version %d, Subversion %d for vdrift\n",fVersionVdriftUsed,fSubVersionVdriftUsed);
302 if(ReadGainGlobal(fileName)) {
304 TString namech = fCH2d->GetTitle();
305 fVersionGainUsed = GetVersion(namech);
306 fSubVersionGainUsed = GetSubVersion(namech);
308 //printf("Found Version %d, Subversion %d for gain\n",fVersionGainUsed,fSubVersionGainUsed);
312 if(fVersionVdriftUsed == 0) fStatusPos = fStatusPos |kVdriftErrorOld;
313 if(fVersionGainUsed == 0) fStatusPos = fStatusPos | kGainErrorOld;
318 //___________________________________________________________________________________________________________________
320 Bool_t AliTRDPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
322 // read calibration entries from file
324 if(fCH2d) return kTRUE;
325 TFile fcalib(fileName);
326 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
328 TH2I *ch2d = (TH2I *) array->FindObject("CH2d");
329 if(!ch2d) return kFALSE;
330 fCH2d = (TH2I*)ch2d->Clone();
331 //fNEvents = (TH1I *) array->FindObject("NEvents");
332 //fAbsoluteGain = (TH2F *) array->FindObject("AbsoluteGain");
334 TH2I *ch2d = (TH2I *) fcalib.Get("CH2d");
335 if(!ch2d) return kFALSE;
336 fCH2d = (TH2I*)ch2d->Clone();
337 //fNEvents = (TH1I *) fcalib.Get("NEvents");
338 //fAbsoluteGain = (TH2F *) fcalib.Get("AbsoluteGain");
340 fCH2d->SetDirectory(0);
341 //printf("title of CH2d %s\n",fCH2d->GetTitle());
346 //_________________________________________________________________________________________________________________
348 Bool_t AliTRDPreprocessorOffline::ReadVdriftT0Global(const Char_t* fileName){
350 // read calibration entries from file
352 if(fPH2d) return kTRUE;
353 TFile fcalib(fileName);
354 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
356 TProfile2D *ph2d = (TProfile2D *) array->FindObject("PH2d");
357 if(!ph2d) return kFALSE;
358 fPH2d = (TProfile2D*)ph2d->Clone();
359 //fNEvents = (TH1I *) array->FindObject("NEvents");
361 TProfile2D *ph2d = (TProfile2D *) fcalib.Get("PH2d");
362 if(!ph2d) return kFALSE;
363 fPH2d = (TProfile2D*)ph2d->Clone();
364 //fNEvents = (TH1I *) fcalib.Get("NEvents");
366 fPH2d->SetDirectory(0);
367 //printf("title of PH2d %s\n",fPH2d->GetTitle());
372 //___________________________________________________________________________________________________________________
374 Bool_t AliTRDPreprocessorOffline::ReadVdriftLinearFitGlobal(const Char_t* fileName){
376 // read calibration entries from file
378 if(fAliTRDCalibraVdriftLinearFit) return kTRUE;
379 TFile fcalib(fileName);
380 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
382 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) array->FindObject("AliTRDCalibraVdriftLinearFit");
383 //fNEvents = (TH1I *) array->FindObject("NEvents");
385 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) fcalib.Get("AliTRDCalibraVdriftLinearFit");
386 //fNEvents = (TH1I *) fcalib.Get("NEvents");
388 if(!fAliTRDCalibraVdriftLinearFit) {
389 //printf("No AliTRDCalibraVdriftLinearFit\n");
395 //_____________________________________________________________________________________________________________
397 Bool_t AliTRDPreprocessorOffline::ReadPRFGlobal(const Char_t* fileName){
399 // read calibration entries from file
401 if(fPRF2d) return kTRUE;
402 TFile fcalib(fileName);
403 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
405 TProfile2D *prf2d = (TProfile2D *) array->FindObject("PRF2d");
406 if(!prf2d) return kFALSE;
407 fPRF2d = (TProfile2D*)prf2d->Clone();
408 //fNEvents = (TH1I *) array->FindObject("NEvents");
410 TProfile2D *prf2d = (TProfile2D *) fcalib.Get("PRF2d");
411 if(!prf2d) return kFALSE;
412 fPRF2d = (TProfile2D*)prf2d->Clone();
413 //fNEvents = (TH1I *) fcalib.Get("NEvents");
415 fPRF2d->SetDirectory(0);
416 //printf("title of PRF2d %s\n",fPRF2d->GetTitle());
421 //__________________________________________________________________________________________________________
423 Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
425 // Analyze gain - produce the calibration objects
428 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
429 calibra->SetMinEntries(fMinStatsGain); // If there is less than 1000 entries in the histo: no fit
430 calibra->AnalyseCH(fCH2d);
432 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
433 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
434 Int_t nbfit = calibra->GetNumberFit();
435 Int_t nbE = calibra->GetNumberEnt();
439 Bool_t meanother = kFALSE;
442 (nbfit >= 0.5*nbE) && (nbE > 30)) {
443 // create the cal objects
444 if(!fBackCorrectGain) {
445 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
448 TObjArray object = calibra->GetVectorFit();
449 AliTRDCalDet *calDetGain = calibra->CreateDetObjectGain(&object,meanother);
450 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
451 // Put them in the array
452 fCalibObjects->AddAt(calDetGain,kGain);
453 fPlots->AddAt(coefGain,kGain);
458 fNotEnoughStatisticsForTheGain = kTRUE;
459 Int_t minStatsGain = fMinStatsGain*30;
460 calibra->SetMinEntries(minStatsGain); // Because we do it for all, we increase this
461 Double_t gainoverallnotnormalized = calibra->AnalyseCHAllTogether(fCH2d);
462 if(fCalDetGainUsed && (gainoverallnotnormalized > 0.0)) {
463 AliTRDCalDet *calDetGain = new AliTRDCalDet(*fCalDetGainUsed);
464 Double_t oldmean = fCalDetGainUsed->CalcMean(kFALSE);
465 //printf("oldmean %f\n",oldmean);
467 Double_t scalefactor = calibra->GetScaleFactorGain();
468 //printf("Correction factor %f\n",gainoverallnotnormalized*scalefactor);
469 calDetGain->Multiply(gainoverallnotnormalized*scalefactor/oldmean);
470 //printf("newmean %f\n",calDetGain->CalcMean(kFALSE));
471 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
472 fCalibObjects->AddAt(calDetGain,kGain);
473 fPlots->AddAt(coefGain,kGain);
476 fStatusNeg = fStatusNeg | kGainNotEnoughStatsButFill;
479 fStatusPos = fStatusPos | kGainErrorOld;
483 if(gainoverallnotnormalized <= 0.0) fStatusNeg = fStatusNeg | kGainNotEnoughStatsNotFill;
484 if(!fCalDetGainUsed) fStatusPos = fStatusPos | kGainErrorOld;
488 calibra->ResetVectorFit();
493 //_____________________________________________________________________________________________________
494 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftT0(){
496 // Analyze VdriftT0 - produce the calibration objects
499 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
500 calibra->SetMinEntries(fMinStatsVdriftT0PH); // If there is less than 1000 entries in the histo: no fit
501 calibra->AnalysePH(fPH2d);
503 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
504 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
505 Int_t nbfit = calibra->GetNumberFit();
506 Int_t nbfitSuccess = calibra->GetNumberFitSuccess();
507 Int_t nbE = calibra->GetNumberEnt();
509 //printf("nbtg %d, nbfit %d, nbE %d, nbfitSuccess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
513 (nbfit >= 0.5*nbE) && (nbE > 30) && (nbfitSuccess > 30)) {
514 //printf("Pass the cut for VdriftT0\n");
515 // create the cal objects
516 calibra->RemoveOutliers(1,kFALSE);
517 calibra->PutMeanValueOtherVectorFit(1,kFALSE);
518 calibra->RemoveOutliers2(kFALSE);
519 calibra->PutMeanValueOtherVectorFit2(1,kFALSE);
521 TObjArray object = calibra->GetVectorFit();
522 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object);
523 TH1F *coefVdriftPH = calDetVdrift->MakeHisto1DAsFunctionOfDet();
524 AliTRDCalPad *calPadVdrift = (AliTRDCalPad *)calibra->CreatePadObjectVdrift(&object,calDetVdrift);
525 TH1F *coefPadVdrift = calPadVdrift->MakeHisto1D();
526 object = calibra->GetVectorFit2();
527 AliTRDCalDet *calDetT0 = calibra->CreateDetObjectT0(&object);
528 TH1F *coefT0 = calDetT0->MakeHisto1DAsFunctionOfDet();
529 AliTRDCalPad *calPadT0 = (AliTRDCalPad *)calibra->CreatePadObjectT0(&object,calDetT0);
530 TH1F *coefPadT0 = calPadT0->MakeHisto1D();
531 // Put them in the array
532 fCalibObjects->AddAt(calDetT0,kT0PHDet);
533 fCalibObjects->AddAt(calDetVdrift,kVdriftPHDet);
534 fCalibObjects->AddAt(calPadT0,kT0PHPad);
535 fCalibObjects->AddAt(calPadVdrift,kVdriftPHPad);
536 fPlots->AddAt(coefVdriftPH,kVdriftPHDet);
537 fPlots->AddAt(coefT0,kT0PHDet);
538 fPlots->AddAt(coefPadVdrift,kVdriftPHPad);
539 fPlots->AddAt(coefPadT0,kT0PHPad);
544 fStatusNeg = fStatusNeg | kTimeOffsetNotEnoughStatsNotFill;
546 calibra->ResetVectorFit();
551 //____________________________________________________________________________________________________________________
552 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftLinearFit(){
554 // Analyze vdrift linear fit - produce the calibration objects
557 //printf("Analyse linear fit\n");
560 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
561 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
562 //printf("Fill PE Array\n");
563 fAliTRDCalibraVdriftLinearFit->FillPEArray();
564 //printf("AliTRDCalibraFit\n");
565 calibra->AnalyseLinearFitters(fAliTRDCalibraVdriftLinearFit);
569 Int_t nbfit = calibra->GetNumberFit();
570 Int_t nbE = calibra->GetNumberEnt();
575 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
576 // create the cal objects
577 //calibra->RemoveOutliers(1,kTRUE);
578 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
579 //calibra->RemoveOutliers2(kTRUE);
580 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
582 TObjArray object = calibra->GetVectorFit();
583 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object,kTRUE);
584 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
585 object = calibra->GetVectorFit2();
586 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectLorentzAngle(&object);
587 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
588 //if(!calDetLorentz) printf("No lorentz created\n");
589 // Put them in the array
590 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
591 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
592 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
593 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
598 fNotEnoughStatisticsForTheVdriftLinear = kTRUE;
599 Int_t minNumberOfEntriesForAll = fMinStatsVdriftLinear*30;
600 calibra->SetMinEntries(minNumberOfEntriesForAll); // Because we do it for all, we increase this
601 Double_t vdriftoverall = calibra->AnalyseLinearFittersAllTogether(fAliTRDCalibraVdriftLinearFit);
602 if(fCalDetVdriftUsed && (vdriftoverall > 0.0)) {
603 AliTRDCalDet *calDetVdrift = new AliTRDCalDet(*fCalDetVdriftUsed);
604 Double_t oldmean = fCalDetVdriftUsed->CalcMean(kFALSE);
605 //printf("oldmean %f\n",oldmean);
607 //printf("Correction factor %f\n",vdriftoverall);
608 calDetVdrift->Multiply(vdriftoverall/oldmean);
609 //printf("newmean %f\n",calDetVdrift->CalcMean(kFALSE));
610 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
611 // Put them in the array
612 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
613 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
616 fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsButFill;
619 fStatusPos = fStatusPos | kVdriftErrorOld;
623 if(vdriftoverall <= 0.0) fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsNotFill;
624 if(!fCalDetVdriftUsed) fStatusPos = fStatusPos | kVdriftErrorOld;
628 calibra->ResetVectorFit();
633 //________________________________________________________________________________________________________________
635 Bool_t AliTRDPreprocessorOffline::AnalyzePRF(){
637 // Analyze PRF - produce the calibration objects
640 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
641 calibra->SetMinEntries(fMinStatsPRF); // If there is less than 1000 entries in the histo: no fit
642 calibra->AnalysePRFMarianFit(fPRF2d);
644 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
645 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
646 Int_t nbfit = calibra->GetNumberFit();
647 Int_t nbE = calibra->GetNumberEnt();
653 (nbfit >= 0.95*nbE) && (nbE > 30)) {
654 // create the cal objects
655 TObjArray object = calibra->GetVectorFit();
656 AliTRDCalPad *calPadPRF = (AliTRDCalPad*) calibra->CreatePadObjectPRF(&object);
657 TH1F *coefPRF = calPadPRF->MakeHisto1D();
658 // Put them in the array
659 fCalibObjects->AddAt(calPadPRF,kPRF);
660 fPlots->AddAt(coefPRF,kPRF);
665 calibra->ResetVectorFit();
671 //_____________________________________________________________________________
672 Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
675 // Produce AliTRDCalChamberStatus out of calibration results
678 // set up AliTRDCalChamberStatus
679 AliTRDCalChamberStatus *CalChamberStatus = new AliTRDCalChamberStatus();
680 for(Int_t det = 0; det < 540; det++) CalChamberStatus->SetStatus(det,1);
682 // get calibration objects
683 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
684 AliTRDCalDet *calDetVDrift = (AliTRDCalDet *) fCalibObjects->At(kVdriftLinear);
687 if((!calDetGain) || (!calDetVDrift) || (!fCH2d)) return kFALSE;
690 Double_t gainmean = calDetGain->GetMean();
691 Double_t vdriftmean = calDetVDrift->GetMean();
693 Double_t gainrms = calDetGain->GetRMSRobust();
694 Double_t vdriftrms = calDetVDrift->GetRMSRobust();
696 //printf("Gain mean: %f, rms: %f\n",gainmean,gainrms);
697 //printf("Vdrift mean: %f, rms: %f\n",vdriftmean,vdriftrms);
700 if((TMath::Abs(gainrms) < 0.001) || (TMath::Abs(vdriftrms) < 0.001)) return kFALSE;
702 // mask chambers with empty gain entries
704 for (Int_t idet = 0; idet < 540; idet++) {
707 TH1I *projch = (TH1I *) fCH2d->ProjectionX("projch",idet+1,idet+1,(Option_t *)"e");
708 Double_t entries = projch->GetEntries();
711 Double_t gain = calDetGain->GetValue(idet);
714 Double_t vdrift = calDetVDrift->GetValue(idet);
718 TMath::Abs(gainmean-gain) > (15.0*gainrms) ||
719 TMath::Abs(vdriftmean-vdrift) > (15.0*vdriftrms)) {
721 //printf(" chamber det %03d masked \n",idet);
722 //printf(" gainmean %f and gain %f, gainrms %f \n",gainmean,gain,gainrms);
723 //printf(" vdriftmean %f and vdrift %f, vdriftrms %f \n",vdriftmean,vdrift,vdriftrms);
724 CalChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kMasked);
729 // installed supermodules+1 -> abort
730 if(counter > (7+1)*30) {
731 printf("ERROR: more than one SM to be masked!! \n Abort...\n");
732 if(projch) delete projch;
742 for(Int_t sm=0; sm < 18; sm++) {
744 for(Int_t det = 0; det < 30; det++){
745 Int_t detector = sm*30+det;
746 if(CalChamberStatus->IsMasked(detector)) counter++;
749 for(Int_t det = 0; det < 30; det++){
750 Int_t detector = sm*30+det;
751 CalChamberStatus->SetStatus(detector,AliTRDCalChamberStatus::kInstalled);
756 fCalibObjects->AddAt(CalChamberStatus,kChamberStatus);
762 //________________________________________________________________________________________________
763 void AliTRDPreprocessorOffline::CorrectFromDetGainUsed() {
765 // Correct from the gas gain used afterwards
767 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
768 if(!calDetGain) return;
774 for(Int_t det = 0; det < 540; det++) {
776 Float_t gaininit = fCalDetGainUsed->GetValue(det);
777 Float_t gainout = calDetGain->GetValue(det);
780 if(TMath::Abs(gainout-1.0) > 0.000001) {
781 mean += (gaininit*gainout);
785 if(nbdet > 0) mean = mean/nbdet;
787 for(Int_t det = 0; det < 540; det++) {
789 Float_t gaininit = fCalDetGainUsed->GetValue(det);
790 Float_t gainout = calDetGain->GetValue(det);
792 if(TMath::Abs(gainout-1.0) > 0.000001) {
793 Double_t newgain = gaininit*gainout;
794 if(newgain < 0.1) newgain = 0.1;
795 if(newgain > 1.9) newgain = 1.9;
796 calDetGain->SetValue(det,newgain);
799 Double_t newgain = mean;
800 if(newgain < 0.1) newgain = 0.1;
801 if(newgain > 1.9) newgain = 1.9;
802 calDetGain->SetValue(det,newgain);
808 //________________________________________________________________________________________________
809 void AliTRDPreprocessorOffline::CorrectFromDetVdriftUsed() {
811 // Correct from the drift velocity
814 //printf("Correct for vdrift\n");
816 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
817 if(!calDetGain) return;
819 Int_t detVdrift = kVdriftPHDet;
820 if(fMethodSecond) detVdrift = kVdriftLinear;
821 AliTRDCalDet *calDetVdrift = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
822 if(!calDetVdrift) return;
825 if(!fNotEnoughStatisticsForTheVdriftLinear) {
826 for(Int_t det = 0; det < 540; det++) {
828 Float_t vdriftinit = fCalDetVdriftUsed->GetValue(det);
829 Float_t vdriftout = calDetVdrift->GetValue(det);
831 Float_t gain = calDetGain->GetValue(det);
832 if(vdriftout > 0.0) gain = gain*vdriftinit/vdriftout;
833 if(gain < 0.1) gain = 0.1;
834 if(gain > 1.9) gain = 1.9;
835 calDetGain->SetValue(det,gain);
840 Float_t vdriftinit = fCalDetVdriftUsed->CalcMean(kFALSE);
841 Float_t vdriftout = calDetVdrift->CalcMean(kFALSE);
842 Float_t factorcorrectif = 1.0;
843 if(vdriftout > 0.0) factorcorrectif = vdriftinit/vdriftout;
844 for(Int_t det = 0; det < 540; det++) {
845 Float_t gain = calDetGain->GetValue(det);
846 gain = gain*factorcorrectif;
847 if(gain < 0.1) gain = 0.1;
848 if(gain > 1.9) gain = 1.9;
849 calDetGain->SetValue(det,gain);
855 //_________________________________________________________________________________________________________________
856 void AliTRDPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
861 AliCDBMetaData *metaData= new AliCDBMetaData();
862 metaData->SetObjectClassName("AliTRDCalDet");
863 metaData->SetResponsible("Raphaelle Bailhache");
864 metaData->SetBeamPeriod(1);
866 AliCDBId id1("TRD/Calib/ChamberGainFactor", startRunNumber, endRunNumber);
867 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
868 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
869 if(calDet) gStorage->Put(calDet, id1, metaData);
873 //___________________________________________________________________________________________________________________
874 void AliTRDPreprocessorOffline::UpdateOCDBExB(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
879 Int_t detExB = kLorentzLinear;
880 if(!fMethodSecond) return;
884 AliCDBMetaData *metaData= new AliCDBMetaData();
885 metaData->SetObjectClassName("AliTRDCalDet");
886 metaData->SetResponsible("Raphaelle Bailhache");
887 metaData->SetBeamPeriod(1);
889 AliCDBId id1("TRD/Calib/ChamberExB", startRunNumber, endRunNumber);
890 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
891 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
892 if(calDet) gStorage->Put(calDet, id1, metaData);
893 //if(!calDet) printf("No caldet\n");
896 //___________________________________________________________________________________________________________________
897 void AliTRDPreprocessorOffline::UpdateOCDBVdrift(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
902 Int_t detVdrift = kVdriftPHDet;
904 if(fMethodSecond) detVdrift = kVdriftLinear;
906 AliCDBMetaData *metaData= new AliCDBMetaData();
907 metaData->SetObjectClassName("AliTRDCalDet");
908 metaData->SetResponsible("Raphaelle Bailhache");
909 metaData->SetBeamPeriod(1);
911 AliCDBId id1("TRD/Calib/ChamberVdrift", startRunNumber, endRunNumber);
912 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
913 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
914 if(calDet) gStorage->Put(calDet, id1, metaData);
920 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
921 metaDataPad->SetObjectClassName("AliTRDCalPad");
922 metaDataPad->SetResponsible("Raphaelle Bailhache");
923 metaDataPad->SetBeamPeriod(1);
925 AliCDBId id1Pad("TRD/Calib/LocalVdrift", startRunNumber, endRunNumber);
926 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
927 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
932 //________________________________________________________________________________________________________________________
933 void AliTRDPreprocessorOffline::UpdateOCDBT0(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
938 AliCDBMetaData *metaData= new AliCDBMetaData();
939 metaData->SetObjectClassName("AliTRDCalDet");
940 metaData->SetResponsible("Raphaelle Bailhache");
941 metaData->SetBeamPeriod(1);
943 AliCDBId id1("TRD/Calib/ChamberT0", startRunNumber, endRunNumber);
944 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
945 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
946 if(calDet) gStorage->Put(calDet, id1, metaData);
950 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
951 metaDataPad->SetObjectClassName("AliTRDCalPad");
952 metaDataPad->SetResponsible("Raphaelle Bailhache");
953 metaDataPad->SetBeamPeriod(1);
955 AliCDBId id1Pad("TRD/Calib/LocalT0", startRunNumber, endRunNumber);
956 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
957 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
962 //_________________________________________________________________________________________________________________
963 void AliTRDPreprocessorOffline::UpdateOCDBPRF(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
968 AliCDBMetaData *metaData= new AliCDBMetaData();
969 metaData->SetObjectClassName("AliTRDCalPad");
970 metaData->SetResponsible("Raphaelle Bailhache");
971 metaData->SetBeamPeriod(1);
973 AliCDBId id1("TRD/Calib/PRFWidth", startRunNumber, endRunNumber);
974 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
975 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
976 if(calPad) gStorage->Put(calPad, id1, metaData);
980 //_________________________________________________________________________________________________________________
981 void AliTRDPreprocessorOffline::UpdateOCDBChamberStatus(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
986 AliCDBMetaData *metaData= new AliCDBMetaData();
987 metaData->SetObjectClassName("AliTRDCalChamberStatus");
988 metaData->SetResponsible("Raphaelle Bailhache");
989 metaData->SetBeamPeriod(1);
991 AliCDBId id1("TRD/Calib/ChamberStatus", startRunNumber, endRunNumber);
992 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
993 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
994 if(calChamberStatus) gStorage->Put(calChamberStatus, id1, metaData);
998 //__________________________________________________________________________________________________________________________
999 Bool_t AliTRDPreprocessorOffline::ValidateGain() {
1001 // Validate OCDB entry
1004 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1006 Double_t mean = calDet->GetMean();
1007 Double_t rms = calDet->GetRMSRobust();
1008 if((mean > 0.2) && (mean < 1.4) && (rms < 0.5)) return kTRUE;
1009 //if((mean > 0.2) && (mean < 1.4)) return kTRUE;
1011 fStatusPos = fStatusPos | kGainErrorRange;
1020 //__________________________________________________________________________________________________________________________
1021 Bool_t AliTRDPreprocessorOffline::ValidateVdrift(){
1023 // Update OCDB entry
1026 Int_t detVdrift = kVdriftPHDet;
1029 if(fMethodSecond) detVdrift = kVdriftLinear;
1031 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1033 Double_t mean = calDet->GetMean();
1034 Double_t rms = calDet->GetRMSRobust();
1035 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1036 if(!((mean > 1.0) && (mean < 2.0) && (rms < 0.5))) {
1037 fStatusPos = fStatusPos | kVdriftErrorRange;
1043 if(!fMethodSecond) {
1044 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1046 Double_t mean = calPad->GetMean();
1047 Double_t rms = calPad->GetRMS();
1048 //printf("Vdrift::meanpad %f, rmspad %f\n",mean,rms);
1049 if(!((mean > 0.9) && (mean < 1.1) && (rms < 0.6))) {
1050 fStatusPos = fStatusPos | kVdriftErrorRange;
1060 //__________________________________________________________________________________________________________________________
1061 Bool_t AliTRDPreprocessorOffline::ValidateT0(){
1063 // Update OCDB entry
1066 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1067 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1068 if(calDet && calPad) {
1069 Double_t meandet = calDet->GetMean();
1070 Double_t rmsdet = calDet->GetRMSRobust();
1071 Double_t meanpad = calPad->GetMean();
1072 //Double_t rmspad = calPad->GetRMS();
1073 //printf("T0::minimum %f, rmsdet %f,meanpad %f, rmspad %f\n",meandet,rmsdet,meanpad,rmspad);
1074 if((meandet > -1.5) && (meandet < 5.0) && (rmsdet < 4.0) && (meanpad < 5.0) && (meanpad > -0.5)) return kTRUE;
1076 fStatusPos = fStatusPos | kTimeOffsetErrorRange;
1083 //__________________________________________________________________________________________________________________________
1084 Bool_t AliTRDPreprocessorOffline::ValidatePRF() const{
1086 // Update OCDB entry
1089 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1091 Double_t meanpad = calPad->GetMean();
1092 Double_t rmspad = calPad->GetRMS();
1093 //printf("PRF::meanpad %f, rmspad %f\n",meanpad,rmspad);
1094 if((meanpad < 1.0) && (rmspad < 0.8)) return kTRUE;
1101 //__________________________________________________________________________________________________________________________
1102 Bool_t AliTRDPreprocessorOffline::ValidateChamberStatus(){
1104 // Update OCDB entry
1107 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1108 if(calChamberStatus) {
1109 Int_t detectormasked = 0;
1110 for(Int_t det = 0; det < 540; det++) {
1111 if(calChamberStatus->IsMasked(det)) detectormasked++;
1113 //printf("Number of chambers masked %d\n",detectormasked);
1114 if(detectormasked > 40) {
1115 fStatusPos = fStatusPos | kChamberStatusErrorRange;
1123 //_____________________________________________________________________________
1124 Int_t AliTRDPreprocessorOffline::GetVersion(TString name) const
1127 // Get version from the title
1131 const Char_t *version = "Ver";
1132 if(!strstr(name.Data(),version)) return -1;
1133 const Char_t *after = "Subver";
1134 if(!strstr(name.Data(),after)) return -1;
1136 for(Int_t ver = 0; ver < 999999999; ver++) {
1138 TString vertry(version);
1142 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1144 if(strstr(name.Data(),vertry.Data())) return ver;
1152 //_____________________________________________________________________________
1153 Int_t AliTRDPreprocessorOffline::GetSubVersion(TString name) const
1156 // Get subversion from the title
1160 const Char_t *subversion = "Subver";
1161 if(!strstr(name.Data(),subversion)) return -1;
1162 const Char_t *after = "FirstRun";
1163 if(!strstr(name.Data(),after)) {
1166 if(!strstr(name.Data(),after)) return -1;
1169 for(Int_t ver = 0; ver < 999999999; ver++) {
1171 TString vertry(subversion);
1175 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1177 if(strstr(name.Data(),vertry.Data())) return ver;
1185 //_____________________________________________________________________________
1186 Int_t AliTRDPreprocessorOffline::GetFirstRun(TString name) const
1189 // Get first run from the title
1193 const Char_t *firstrun = "FirstRun";
1194 if(!strstr(name.Data(),firstrun)) return -1;
1195 const Char_t *after = "Nz";
1196 if(!strstr(name.Data(),after)) return -1;
1199 for(Int_t ver = 0; ver < 999999999; ver++) {
1201 TString vertry(firstrun);
1205 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1207 if(strstr(name.Data(),vertry.Data())) return ver;
1214 //_____________________________________________________________________________
1215 Bool_t AliTRDPreprocessorOffline::CheckStatus(Int_t status, Int_t bitMask) const
1218 // Checks the status
1221 return (status & bitMask) ? kTRUE : kFALSE;
1224 //_____________________________________________________________________________
1225 Int_t AliTRDPreprocessorOffline::GetStatus() const
1228 // Checks the status
1229 // fStatusPos: errors
1230 // fStatusNeg: only info
1233 if(fStatusPos > 0) return fStatusPos;
1234 else return (-TMath::Abs(fStatusNeg));
1237 //_____________________________________________________________________________
1238 void AliTRDPreprocessorOffline::PrintStatus() const
1244 AliInfo(Form("The error status is %d",fStatusPos));
1245 AliInfo(Form("IsGainErrorOld? %d",(Int_t)IsGainErrorOld()));
1246 AliInfo(Form("IsVdriftErrorOld? %d",(Int_t)IsVdriftErrorOld()));
1247 AliInfo(Form("IsGainErrorRange? %d",(Int_t)IsGainErrorRange()));
1248 AliInfo(Form("IsVdriftErrorRange? %d",(Int_t)IsVdriftErrorRange()));
1249 AliInfo(Form("IsTimeOffsetErrorRange? %d",(Int_t)IsTimeOffsetErrorRange()));
1250 AliInfo(Form("IsChamberStatusErrorRange? %d",(Int_t)IsChamberStatusErrorRange()));
1253 AliInfo(Form("The info status is %d",fStatusNeg));
1254 AliInfo(Form("IsGainNotEnoughStatsButFill? %d",(Int_t)IsGainNotEnoughStatsButFill()));
1255 AliInfo(Form("IsVdriftNotEnoughStatsButFill? %d",(Int_t)IsVdriftNotEnoughStatsButFill()));
1256 AliInfo(Form("IsGainNotEnoughStatsNotFill? %d",(Int_t)IsGainNotEnoughStatsNotFill()));
1257 AliInfo(Form("IsVdriftNotEnoughStatsNotFill? %d",(Int_t)IsVdriftNotEnoughStatsNotFill()));
1258 AliInfo(Form("IsTimeOffsetNotEnoughStatsNotFill? %d",(Int_t)IsTimeOffsetNotEnoughStatsNotFill()));