]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDPreprocessorOffline.cxx
adapted to new version of FitRobust
[u/mrichter/AliRoot.git] / TRD / AliTRDPreprocessorOffline.cxx
CommitLineData
b3fcfd96 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16
17
18/*
4c865c34 19 Responsible: Raphaelle Bailhache (rbailhache@ikf.uni-frankfurt.de)
20 Code to analyze the TRD calibration and to produce OCDB entries
b3fcfd96 21
22
23 .x ~/rootlogon.C
24 gSystem->Load("libANALYSIS");
4c865c34 25 gSystem->Load("libTRDcalib");
b3fcfd96 26
27 AliTRDPreprocessorOffline proces;
28 TString ocdbPath="local:////"
29 ocdbPath+=gSystem->GetFromPipe("pwd");
30
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
37
38*/
00d203b6 39#include "AliLog.h"
b3fcfd96 40#include "Riostream.h"
41#include <fstream>
42#include "TFile.h"
43#include "TCanvas.h"
44#include "TLegend.h"
45#include "TH2I.h"
46#include "TH1I.h"
47#include "TH2F.h"
48#include "TH1F.h"
82b413fd 49#include "TMath.h"
83d0cc79 50#include "THnSparse.h"
b3fcfd96 51#include "TProfile2D.h"
52#include "AliTRDCalDet.h"
53#include "AliTRDCalPad.h"
54#include "AliCDBMetaData.h"
55#include "AliCDBId.h"
56#include "AliCDBManager.h"
57#include "AliCDBStorage.h"
58#include "AliTRDCalibraMode.h"
59#include "AliTRDCalibraFit.h"
60#include "AliTRDCalibraVdriftLinearFit.h"
a0bb5615 61#include "AliTRDCalibraExbAltFit.h"
b3fcfd96 62#include "AliTRDPreprocessorOffline.h"
81a5aeca 63#include "AliTRDCalChamberStatus.h"
83d0cc79 64#include "AliTRDCalibChamberStatus.h"
840ec79d 65#include "AliTRDCommonParam.h"
83d0cc79 66#include "AliCDBManager.h"
67#include "AliCDBEntry.h"
6951a056 68#include "AliTRDdEdxBaseUtils.h"
69#include "AliTRDdEdxCalibHistArray.h"
70#include "AliTRDdEdxCalibUtils.h"
b3fcfd96 71
b3fcfd96 72ClassImp(AliTRDPreprocessorOffline)
73
54f2ff1c 74 AliTRDPreprocessorOffline::AliTRDPreprocessorOffline():
01239968 75 TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
b3fcfd96 76 fMethodSecond(kTRUE),
01239968 77 fNameList("TRDCalib"),
78 fCalDetGainUsed(0x0),
4c865c34 79 fCalDetVdriftUsed(0x0),
840ec79d 80 fCalDetExBUsed(0x0),
b3fcfd96 81 fCH2d(0x0),
82 fPH2d(0x0),
83 fPRF2d(0x0),
83d0cc79 84 fSparse(0x0),
b3fcfd96 85 fAliTRDCalibraVdriftLinearFit(0x0),
a0bb5615 86 fAliTRDCalibraExbAltFit(0x0),
b3fcfd96 87 fNEvents(0x0),
88 fAbsoluteGain(0x0),
a0bb5615 89 fPlots(new TObjArray(kNumCalibObjs)),
90 fCalibObjects(new TObjArray(kNumCalibObjs)),
83d0cc79 91 fFirstRunGainUsed(0),
4c865c34 92 fVersionGainUsed(0),
93 fSubVersionGainUsed(0),
ca7e6e64 94 fFirstRunVdriftUsed(0),
4c865c34 95 fVersionVdriftUsed(0),
00d203b6 96 fSubVersionVdriftUsed(0),
83d0cc79 97 fFirstRunExBUsed(0),
98 fVersionExBUsed(0),
99 fSubVersionExBUsed(0),
100 fNoExBUsedInReco(kFALSE),
00d203b6 101 fSwitchOnValidation(kTRUE),
102 fVdriftValidated(kFALSE),
840ec79d 103 fExBValidated(kFALSE),
a2a4ec8e 104 fT0Validated(kFALSE),
105 fMinStatsVdriftT0PH(800*20),
106 fMinStatsVdriftLinear(800),
107 fMinStatsGain(800),
54f2ff1c 108 fMinStatsPRF(600),
83d0cc79 109 fMinStatsChamberStatus(20),
17aa2935 110 fMinSingleStatsChamberStatus(0.05),
54f2ff1c 111 fBackCorrectGain(kFALSE),
112 fBackCorrectVdrift(kTRUE),
113 fNotEnoughStatisticsForTheGain(kFALSE),
114 fNotEnoughStatisticsForTheVdriftLinear(kFALSE),
82b413fd 115 fStatusNeg(0),
83d0cc79 116 fStatusPos(0),
661c7be6 117 fBadCalibValidate(40),
118 fNoDataValidate(40),
83d0cc79 119 fRMSBadCalibratedGain(20.0),
120 fRMSBadCalibratedVdrift(20.0),
661c7be6 121 fRMSBadCalibratedExB(20.0),
d82bad1e 122 fMinTimeOffsetValidate(-1.6),
2a1a7b36 123 fRobustFitDriftVelocity(kTRUE),
661c7be6 124 fRobustFitExbAlt(kFALSE),
125 fAlternativeVdrfitFit(kFALSE),
595cfc12 126 fAlternativeExbAltFit(kFALSE),
532be2d4 127 fMinNbOfPointVdriftFit(11),
595cfc12 128 fMethodeGain(0),
129 fOutliersFitChargeLow(0.03),
130 fOutliersFitChargeHigh(0.7),
9a8b0e85 131 fBeginFitCharge(3.5),
4f3bd513 132 fT0Shift0(0.124797),
133 fT0Shift1(0.267451),
687aa844 134 fPHQon(kTRUE),
135 fDebugPHQon(kFALSE)
b3fcfd96 136{
137 //
138 // default constructor
139 //
83d0cc79 140
141 memset(fBadCalib, 0, sizeof(Int_t) * 18);
142 memset(fNoData, 0, sizeof(Int_t) * 18);
b3fcfd96 143}
00d203b6 144//_________________________________________________________________________________________________________________
b3fcfd96 145AliTRDPreprocessorOffline::~AliTRDPreprocessorOffline() {
146 //
147 // Destructor
148 //
149
01239968 150 if(fCalDetGainUsed) delete fCalDetGainUsed;
4c865c34 151 if(fCalDetVdriftUsed) delete fCalDetVdriftUsed;
840ec79d 152 if(fCalDetExBUsed) delete fCalDetExBUsed;
b3fcfd96 153 if(fCH2d) delete fCH2d;
154 if(fPH2d) delete fPH2d;
155 if(fPRF2d) delete fPRF2d;
83d0cc79 156 if(fSparse) delete fSparse;
9a8b0e85 157
158 if(IsPHQon()){
6951a056 159 AliTRDdEdxCalibUtils::DeleteHistArray();
160 AliTRDdEdxCalibUtils::DeleteObjArray();
9a8b0e85 161 }
162
b3fcfd96 163 if(fAliTRDCalibraVdriftLinearFit) delete fAliTRDCalibraVdriftLinearFit;
a0bb5615 164 if(fAliTRDCalibraExbAltFit) delete fAliTRDCalibraExbAltFit;
b3fcfd96 165 if(fNEvents) delete fNEvents;
166 if(fAbsoluteGain) delete fAbsoluteGain;
167 if(fPlots) delete fPlots;
168 if(fCalibObjects) delete fCalibObjects;
169
83d0cc79 170}
171//___________________________________________________________________________________
a9f9c69b 172void AliTRDPreprocessorOffline::Process(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage)
83d0cc79 173{
174 //
175 // Process to the gain, vdrift, timeoffset, exb and chamber status calibration
176 //
177
178 if(SetCalDetGain(startRunNumber,fVersionGainUsed,fSubVersionGainUsed) && SetCalDetVdriftExB(startRunNumber,fVersionVdriftUsed,fSubVersionVdriftUsed,fVersionExBUsed,fSubVersionExBUsed)) {
179
180 CalibVdriftT0(file,startRunNumber,endRunNumber,ocdbStorage);
181 CalibGain(file,startRunNumber,endRunNumber,ocdbStorage);
182 CalibChamberStatus(file,startRunNumber,endRunNumber,ocdbStorage);
f29cf84c 183 CalibExbAlt(file,startRunNumber,endRunNumber,ocdbStorage);
e2a1c98b 184
83d0cc79 185 }
e2a1c98b 186
9a8b0e85 187 if(IsPHQon()){
188 printf("\n AliTRDPreprocessorOffline PHQ on!!\n\n");
6951a056 189 AliTRDdEdxBaseUtils::PrintControl();
9a8b0e85 190 CalibPHQ(file, startRunNumber, endRunNumber, ocdbStorage);
191 }
192 else{
193 printf("\n AliTRDPreprocessorOffline PHQ off!!\n\n");
194 }
195
83d0cc79 196 PrintStatus();
197
b3fcfd96 198}
00d203b6 199//___________________________________________________________________________________________________________________
b3fcfd96 200
a9f9c69b 201void AliTRDPreprocessorOffline::CalibVdriftT0(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
b3fcfd96 202 //
203 // make calibration of the drift velocity
204 // Input parameters:
205 // file - the location of input file
206 // startRunNumber, endRunNumber - run validity period
a9f9c69b 207 // ocdbStorage - OCDB storage
b3fcfd96 208 // - if empty - local storage 'pwd' uesed
a9f9c69b 209 if (ocdbStorage==0x0) {
210 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
211 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
212 }
b3fcfd96 213 //
214 // 1. Initialization
215 //
008817a3 216 fVdriftValidated = kTRUE;
217 fT0Validated = kTRUE;
840ec79d 218 fExBValidated = kTRUE;
54f2ff1c 219 fNotEnoughStatisticsForTheVdriftLinear = kFALSE;
b3fcfd96 220 //
221 // 2. extraction of the information
222 //
840ec79d 223 if(ReadVdriftLinearFitGlobal(file) && fCalDetVdriftUsed && fCalDetExBUsed) AnalyzeVdriftLinearFit();
54f2ff1c 224 if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
b3fcfd96 225 //
226 // 3. Append QA plots
227 //
228 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
229 //
230 //
00d203b6 231 // 4. validate OCDB entries
b3fcfd96 232 //
00d203b6 233 if(fSwitchOnValidation==kTRUE && ValidateVdrift()==kFALSE) {
82b413fd 234 //AliError("TRD vdrift OCDB parameters out of range!");
00d203b6 235 fVdriftValidated = kFALSE;
236 }
237 if(fSwitchOnValidation==kTRUE && ValidateT0()==kFALSE) {
82b413fd 238 //AliError("TRD t0 OCDB parameters out of range!");
00d203b6 239 fT0Validated = kFALSE;
240 }
840ec79d 241 if(fSwitchOnValidation==kTRUE && ValidateExB()==kFALSE) {
242 //AliError("TRD t0 OCDB parameters out of range!");
243 fExBValidated = kFALSE;
244 }
b3fcfd96 245 //
00d203b6 246 // 5. update of OCDB
247 //
248 //
249 if(fVdriftValidated) UpdateOCDBVdrift(startRunNumber,endRunNumber,ocdbStorage);
250 if(fT0Validated) UpdateOCDBT0(startRunNumber,endRunNumber,ocdbStorage);
840ec79d 251 if(fExBValidated) UpdateOCDBExB(startRunNumber,endRunNumber,ocdbStorage);
00d203b6 252
b3fcfd96 253}
a0bb5615 254//___________________________________________________________________________________________________________________
255
a9f9c69b 256void AliTRDPreprocessorOffline::CalibExbAlt(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
a0bb5615 257 //
258 // make calibration of the drift velocity
259 // Input parameters:
260 // file - the location of input file
261 // startRunNumber, endRunNumber - run validity period
a9f9c69b 262 // ocdbStorage - OCDB storage
a0bb5615 263 // - if empty - local storage 'pwd' uesed
a9f9c69b 264 if (ocdbStorage==0x0) {
265 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
266 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
267 }
a0bb5615 268 //
269 // 1. Initialization
270 //
271
272 //
273 // 2. extraction of the information
274 //
275 if(ReadExbAltFitGlobal(file)) AnalyzeExbAltFit();
276 //
277 // 3. Append QA plots
278 //
279 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
280 //
281 //
282 // 4. validate OCDB entries
283 //
284 //
285 // 5. update of OCDB
286 //
287 //
288 UpdateOCDBExBAlt(startRunNumber,endRunNumber,ocdbStorage);
289
290}
291
00d203b6 292//_________________________________________________________________________________________________________________
b3fcfd96 293
a9f9c69b 294void AliTRDPreprocessorOffline::CalibGain(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
b3fcfd96 295 //
296 // make calibration of the drift velocity
297 // Input parameters:
298 // file - the location of input file
299 // startRunNumber, endRunNumber - run validity period
a9f9c69b 300 // ocdbStorage - OCDB storage
b3fcfd96 301 // - if empty - local storage 'pwd' uesed
a9f9c69b 302 if (ocdbStorage==0x0) {
303 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
304 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
305 }
b3fcfd96 306 //
54f2ff1c 307 fNotEnoughStatisticsForTheGain = kFALSE;
308 //
b3fcfd96 309 // 1. Initialization
310 if(!ReadGainGlobal(file)) return;
311 //
312 //
313 // 2. extraction of the information
314 //
315 AnalyzeGain();
54f2ff1c 316 if(fBackCorrectGain) CorrectFromDetGainUsed();
a0bb5615 317 //if(fBackCorrectVdrift) CorrectFromDetVdriftUsed();
b3fcfd96 318 //
319 // 3. Append QA plots
320 //
321 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
322 //
323 //
00d203b6 324 // 4. validate OCDB entries
325 //
326 if(fSwitchOnValidation==kTRUE && ValidateGain()==kFALSE) {
82b413fd 327 //AliError("TRD gain OCDB parameters out of range!");
00d203b6 328 return;
329 }
b3fcfd96 330 //
00d203b6 331 // 5. update of OCDB
b3fcfd96 332 //
00d203b6 333 //
334 if((!fCalDetVdriftUsed) || (fCalDetVdriftUsed && fVdriftValidated)) UpdateOCDBGain(startRunNumber,endRunNumber,ocdbStorage);
335
b3fcfd96 336
337}
00d203b6 338//________________________________________________________________________________________________________________
b3fcfd96 339
a9f9c69b 340void AliTRDPreprocessorOffline::CalibPRF(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
b3fcfd96 341 //
342 // make calibration of the drift velocity
343 // Input parameters:
344 // file - the location of input file
345 // startRunNumber, endRunNumber - run validity period
a9f9c69b 346 // ocdbStorage - OCDB storage
b3fcfd96 347 // - if empty - local storage 'pwd' uesed
a9f9c69b 348 if (ocdbStorage==0x0) {
349 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
350 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
351 }
b3fcfd96 352 //
353 // 1. Initialization
354 if(!ReadPRFGlobal(file)) return;
355 //
356 //
357 // 2. extraction of the information
358 //
359 AnalyzePRF();
360 //
361 // 3. Append QA plots
362 //
363 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
364 //
365 //
00d203b6 366 //
367 // 4. validate OCDB entries
368 //
369 if(fSwitchOnValidation==kTRUE && ValidatePRF()==kFALSE) {
82b413fd 370 //AliError("TRD prf OCDB parameters out of range!");
00d203b6 371 return;
372 }
373 //
374 // 5. update of OCDB
b3fcfd96 375 //
376 //
377 UpdateOCDBPRF(startRunNumber,endRunNumber,ocdbStorage);
378
a5dcf618 379}
e2a1c98b 380//________________________________________________________________________________________________________________
a9f9c69b 381void AliTRDPreprocessorOffline::CalibPHQ(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage)
e2a1c98b 382{
383 //
384 // make calibration of puls height Q
385 // Input parameters:
386 // startRunNumber, endRunNumber - run validity period
a9f9c69b 387 // ocdbStorage - OCDB storage
e2a1c98b 388 // - if empty - local storage 'pwd' uesed
389 //
390
a9f9c69b 391 if (ocdbStorage==0x0) {
392 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
393 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
394 }
e2a1c98b 395 //printf("test %s\n", ocdbStorage.Data());
396
397 if(!ReadPHQGlobal(file)) return;
398
399 if(!AnalyzePHQ(startRunNumber)) return;
400
401 UpdateOCDBPHQ(startRunNumber,endRunNumber,ocdbStorage);
402}
403
a5dcf618 404//________________________________________________________________________________________________________________
405
a9f9c69b 406void AliTRDPreprocessorOffline::CalibChamberStatus(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* ocdbStorage){
a5dcf618 407 //
408 // make calibration of the chamber status
409 // Input parameters:
410 // startRunNumber, endRunNumber - run validity period
a9f9c69b 411 // ocdbStorage - OCDB storage
a5dcf618 412 // - if empty - local storage 'pwd' uesed
a9f9c69b 413 if (ocdbStorage==0x0) {
414 TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
415 ocdbStorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
416 }
a5dcf618 417 //
418 //
83d0cc79 419 // 1. Initialization
420 if(!ReadStatusGlobal(file)) return;
421 //
422 //
423 //
a5dcf618 424 // 2. extraction of the information
425 //
426 if(!AnalyzeChamberStatus()) return;
427 //
428 // 3. Append QA plots
429 //
430 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
431 //
432 //
433 //
434 // 4. validate OCDB entries
435 //
7954133b 436 //printf("Enough stats for vdrift? %d\n",(Int_t)fNotEnoughStatisticsForTheVdriftLinear);
437 //printf("Enough stats for gain? %d\n",(Int_t)fNotEnoughStatisticsForTheGain);
438 if((!fNotEnoughStatisticsForTheVdriftLinear) && (!fNotEnoughStatisticsForTheGain)) {
439 if(fSwitchOnValidation==kTRUE && ValidateChamberStatus()==kFALSE) {
440 //AliError("TRD Chamber status OCDB parameters not ok!");
441 return;
442 }
443 //
444 // 5. update of OCDB
445 //
446 //
447 UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
a5dcf618 448 }
a5dcf618 449
b3fcfd96 450}
00d203b6 451//______________________________________________________________________________________________________
4c865c34 452Bool_t AliTRDPreprocessorOffline::Init(const Char_t* fileName){
453 //
454 // read the calibration used during the reconstruction
455 //
456
457 if(ReadVdriftT0Global(fileName)) {
458
459 TString nameph = fPH2d->GetTitle();
ca7e6e64 460 fFirstRunVdriftUsed = GetFirstRun(nameph);
4c865c34 461 fVersionVdriftUsed = GetVersion(nameph);
462 fSubVersionVdriftUsed = GetSubVersion(nameph);
463
464 //printf("Found Version %d, Subversion %d for vdrift\n",fVersionVdriftUsed,fSubVersionVdriftUsed);
465
466 }
467
468 if(ReadGainGlobal(fileName)) {
469
470 TString namech = fCH2d->GetTitle();
83d0cc79 471 fFirstRunGainUsed = GetFirstRun(namech);
4c865c34 472 fVersionGainUsed = GetVersion(namech);
473 fSubVersionGainUsed = GetSubVersion(namech);
474
475 //printf("Found Version %d, Subversion %d for gain\n",fVersionGainUsed,fSubVersionGainUsed);
476
477 }
83d0cc79 478
479 if(ReadVdriftLinearFitGlobal(fileName)) {
480
481 TString namelinear = fAliTRDCalibraVdriftLinearFit->GetNameCalibUsed();
482 fFirstRunExBUsed = GetFirstRun(namelinear);
483 fVersionExBUsed = GetVersion(namelinear);
484 fSubVersionExBUsed = GetSubVersion(namelinear);
485
486 //printf("Found Version %d, Subversion %d, run %d for ExB\n",fVersionExBUsed,fSubVersionExBUsed,fFirstRunExBUsed);
487
488 }
4c865c34 489
82b413fd 490 if(fVersionVdriftUsed == 0) fStatusPos = fStatusPos |kVdriftErrorOld;
491 if(fVersionGainUsed == 0) fStatusPos = fStatusPos | kGainErrorOld;
e2a1c98b 492
4c865c34 493 return kTRUE;
494
495}
00d203b6 496//___________________________________________________________________________________________________________________
b3fcfd96 497
83d0cc79 498Bool_t AliTRDPreprocessorOffline::ReadStatusGlobal(const Char_t* fileName){
499 //
500 // read calibration entries from file
501 //
502 if(fSparse) return kTRUE;
503 TFile fcalib(fileName);
504 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
505 if (array){
506 fSparse = (THnSparseI *) array->FindObject("NumberOfEntries");
507 if(!fSparse) return kFALSE;
508 }
509 else
510 return kFALSE;
511
512 return kTRUE;
513
514}
515//___________________________________________________________________________________________________________________
516
e2a1c98b 517Bool_t AliTRDPreprocessorOffline::ReadPHQGlobal(const Char_t* fileName)
518{
519 //
520 // read calibration entries from file
521 //
522
6951a056 523 return AliTRDdEdxCalibUtils::ReadHistArray(fileName, fNameList);
e2a1c98b 524}
525
526//___________________________________________________________________________________________________________________
527
b3fcfd96 528Bool_t AliTRDPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
529 //
530 // read calibration entries from file
531 //
4c865c34 532 if(fCH2d) return kTRUE;
b3fcfd96 533 TFile fcalib(fileName);
01239968 534 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
b3fcfd96 535 if (array){
536 TH2I *ch2d = (TH2I *) array->FindObject("CH2d");
537 if(!ch2d) return kFALSE;
538 fCH2d = (TH2I*)ch2d->Clone();
539 //fNEvents = (TH1I *) array->FindObject("NEvents");
540 //fAbsoluteGain = (TH2F *) array->FindObject("AbsoluteGain");
541 }else{
542 TH2I *ch2d = (TH2I *) fcalib.Get("CH2d");
543 if(!ch2d) return kFALSE;
544 fCH2d = (TH2I*)ch2d->Clone();
545 //fNEvents = (TH1I *) fcalib.Get("NEvents");
546 //fAbsoluteGain = (TH2F *) fcalib.Get("AbsoluteGain");
547 }
548 fCH2d->SetDirectory(0);
549 //printf("title of CH2d %s\n",fCH2d->GetTitle());
550
551 return kTRUE;
552
553}
00d203b6 554//_________________________________________________________________________________________________________________
b3fcfd96 555
556Bool_t AliTRDPreprocessorOffline::ReadVdriftT0Global(const Char_t* fileName){
557 //
558 // read calibration entries from file
559 //
4c865c34 560 if(fPH2d) return kTRUE;
b3fcfd96 561 TFile fcalib(fileName);
01239968 562 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
b3fcfd96 563 if (array){
564 TProfile2D *ph2d = (TProfile2D *) array->FindObject("PH2d");
565 if(!ph2d) return kFALSE;
566 fPH2d = (TProfile2D*)ph2d->Clone();
567 //fNEvents = (TH1I *) array->FindObject("NEvents");
568 }else{
569 TProfile2D *ph2d = (TProfile2D *) fcalib.Get("PH2d");
570 if(!ph2d) return kFALSE;
571 fPH2d = (TProfile2D*)ph2d->Clone();
572 //fNEvents = (TH1I *) fcalib.Get("NEvents");
573 }
574 fPH2d->SetDirectory(0);
575 //printf("title of PH2d %s\n",fPH2d->GetTitle());
576
577 return kTRUE;
578
579}
00d203b6 580//___________________________________________________________________________________________________________________
b3fcfd96 581
582Bool_t AliTRDPreprocessorOffline::ReadVdriftLinearFitGlobal(const Char_t* fileName){
583 //
584 // read calibration entries from file
585 //
4c865c34 586 if(fAliTRDCalibraVdriftLinearFit) return kTRUE;
b3fcfd96 587 TFile fcalib(fileName);
01239968 588 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
b3fcfd96 589 if (array){
590 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) array->FindObject("AliTRDCalibraVdriftLinearFit");
591 //fNEvents = (TH1I *) array->FindObject("NEvents");
592 }else{
593 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) fcalib.Get("AliTRDCalibraVdriftLinearFit");
594 //fNEvents = (TH1I *) fcalib.Get("NEvents");
595 }
596 if(!fAliTRDCalibraVdriftLinearFit) {
597 //printf("No AliTRDCalibraVdriftLinearFit\n");
598 return kFALSE;
599 }
600 return kTRUE;
601
a0bb5615 602}
603//_____________________________________________________________________________________________________________
604Bool_t AliTRDPreprocessorOffline::ReadExbAltFitGlobal(const Char_t* fileName){
605 //
606 // read calibration entries from file
607 //
608 if(fAliTRDCalibraExbAltFit) return kTRUE;
609 TFile fcalib(fileName);
610 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
611 if (array){
612 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) array->FindObject("AliTRDCalibraExbAltFit");
613 //fNEvents = (TH1I *) array->FindObject("NEvents");
614 }else{
615 fAliTRDCalibraExbAltFit = (AliTRDCalibraExbAltFit *) fcalib.Get("AliTRDCalibraExbAltFit");
616 //fNEvents = (TH1I *) fcalib.Get("NEvents");
617 }
618 if(!fAliTRDCalibraExbAltFit) {
619 //printf("No AliTRDCalibraExbAltFit\n");
620 return kFALSE;
621 }
622 return kTRUE;
623
b3fcfd96 624}
00d203b6 625//_____________________________________________________________________________________________________________
b3fcfd96 626
627Bool_t AliTRDPreprocessorOffline::ReadPRFGlobal(const Char_t* fileName){
628 //
629 // read calibration entries from file
630 //
4c865c34 631 if(fPRF2d) return kTRUE;
b3fcfd96 632 TFile fcalib(fileName);
01239968 633 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
b3fcfd96 634 if (array){
635 TProfile2D *prf2d = (TProfile2D *) array->FindObject("PRF2d");
636 if(!prf2d) return kFALSE;
637 fPRF2d = (TProfile2D*)prf2d->Clone();
638 //fNEvents = (TH1I *) array->FindObject("NEvents");
639 }else{
640 TProfile2D *prf2d = (TProfile2D *) fcalib.Get("PRF2d");
641 if(!prf2d) return kFALSE;
642 fPRF2d = (TProfile2D*)prf2d->Clone();
643 //fNEvents = (TH1I *) fcalib.Get("NEvents");
644 }
645 fPRF2d->SetDirectory(0);
646 //printf("title of PRF2d %s\n",fPRF2d->GetTitle());
647
648 return kTRUE;
649
650}
00d203b6 651//__________________________________________________________________________________________________________
b3fcfd96 652
653Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
654 //
655 // Analyze gain - produce the calibration objects
656 //
657
658 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
595cfc12 659 calibra->ChooseMethod(fMethodeGain);
660 calibra->SetBeginFitCharge(fBeginFitCharge);
661 calibra->SetFitOutliersChargeLow(fOutliersFitChargeLow);
662 calibra->SetFitOutliersChargeHigh(fOutliersFitChargeHigh);
a2a4ec8e 663 calibra->SetMinEntries(fMinStatsGain); // If there is less than 1000 entries in the histo: no fit
b3fcfd96 664 calibra->AnalyseCH(fCH2d);
665
666 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
667 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
668 Int_t nbfit = calibra->GetNumberFit();
669 Int_t nbE = calibra->GetNumberEnt();
670
671
672 Bool_t ok = kFALSE;
4c865c34 673 Bool_t meanother = kFALSE;
b3fcfd96 674 // enough statistics
675 if ((nbtg > 0) &&
676 (nbfit >= 0.5*nbE) && (nbE > 30)) {
677 // create the cal objects
54f2ff1c 678 if(!fBackCorrectGain) {
4c865c34 679 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
680 meanother = kTRUE;
681 }
b3fcfd96 682 TObjArray object = calibra->GetVectorFit();
4c865c34 683 AliTRDCalDet *calDetGain = calibra->CreateDetObjectGain(&object,meanother);
b3fcfd96 684 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
685 // Put them in the array
686 fCalibObjects->AddAt(calDetGain,kGain);
687 fPlots->AddAt(coefGain,kGain);
688 //
689 ok = kTRUE;
690 }
54f2ff1c 691 else {
692 fNotEnoughStatisticsForTheGain = kTRUE;
dee5f636 693 Int_t minStatsGain = fMinStatsGain*30;
694 calibra->SetMinEntries(minStatsGain); // Because we do it for all, we increase this
54f2ff1c 695 Double_t gainoverallnotnormalized = calibra->AnalyseCHAllTogether(fCH2d);
696 if(fCalDetGainUsed && (gainoverallnotnormalized > 0.0)) {
697 AliTRDCalDet *calDetGain = new AliTRDCalDet(*fCalDetGainUsed);
698 Double_t oldmean = fCalDetGainUsed->CalcMean(kFALSE);
699 //printf("oldmean %f\n",oldmean);
700 if(oldmean > 0.0) {
701 Double_t scalefactor = calibra->GetScaleFactorGain();
702 //printf("Correction factor %f\n",gainoverallnotnormalized*scalefactor);
703 calDetGain->Multiply(gainoverallnotnormalized*scalefactor/oldmean);
704 //printf("newmean %f\n",calDetGain->CalcMean(kFALSE));
705 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
706 fCalibObjects->AddAt(calDetGain,kGain);
707 fPlots->AddAt(coefGain,kGain);
708 //
709 ok = kTRUE;
82b413fd 710 fStatusNeg = fStatusNeg | kGainNotEnoughStatsButFill;
54f2ff1c 711 }
712 else {
82b413fd 713 fStatusPos = fStatusPos | kGainErrorOld;
54f2ff1c 714 }
715 }
716 else {
82b413fd 717 if(gainoverallnotnormalized <= 0.0) fStatusNeg = fStatusNeg | kGainNotEnoughStatsNotFill;
718 if(!fCalDetGainUsed) fStatusPos = fStatusPos | kGainErrorOld;
54f2ff1c 719 }
720 }
b3fcfd96 721
722 calibra->ResetVectorFit();
723
724 return ok;
725
726}
00d203b6 727//_____________________________________________________________________________________________________
b3fcfd96 728Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftT0(){
729 //
730 // Analyze VdriftT0 - produce the calibration objects
731 //
732
733 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
4f3bd513 734 calibra->SetT0Shift0(fT0Shift0);
735 calibra->SetT0Shift1(fT0Shift1);
a2a4ec8e 736 calibra->SetMinEntries(fMinStatsVdriftT0PH); // If there is less than 1000 entries in the histo: no fit
4f3bd513 737 calibra->AnalysePH(fPH2d);
738 //calibra->SetDebugLevel(2);
b3fcfd96 739
740 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
741 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
742 Int_t nbfit = calibra->GetNumberFit();
743 Int_t nbfitSuccess = calibra->GetNumberFitSuccess();
744 Int_t nbE = calibra->GetNumberEnt();
745
746 //printf("nbtg %d, nbfit %d, nbE %d, nbfitSuccess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
747
748 Bool_t ok = kFALSE;
749 if ((nbtg > 0) &&
750 (nbfit >= 0.5*nbE) && (nbE > 30) && (nbfitSuccess > 30)) {
4f3bd513 751 //printf("nbtg %d, nbfit %d, nbE %d, nbfitSucess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
b3fcfd96 752 //printf("Pass the cut for VdriftT0\n");
753 // create the cal objects
01239968 754 calibra->RemoveOutliers(1,kFALSE);
755 calibra->PutMeanValueOtherVectorFit(1,kFALSE);
756 calibra->RemoveOutliers2(kFALSE);
757 calibra->PutMeanValueOtherVectorFit2(1,kFALSE);
758 //
b3fcfd96 759 TObjArray object = calibra->GetVectorFit();
760 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object);
761 TH1F *coefVdriftPH = calDetVdrift->MakeHisto1DAsFunctionOfDet();
762 AliTRDCalPad *calPadVdrift = (AliTRDCalPad *)calibra->CreatePadObjectVdrift(&object,calDetVdrift);
763 TH1F *coefPadVdrift = calPadVdrift->MakeHisto1D();
764 object = calibra->GetVectorFit2();
765 AliTRDCalDet *calDetT0 = calibra->CreateDetObjectT0(&object);
766 TH1F *coefT0 = calDetT0->MakeHisto1DAsFunctionOfDet();
767 AliTRDCalPad *calPadT0 = (AliTRDCalPad *)calibra->CreatePadObjectT0(&object,calDetT0);
768 TH1F *coefPadT0 = calPadT0->MakeHisto1D();
769 // Put them in the array
770 fCalibObjects->AddAt(calDetT0,kT0PHDet);
771 fCalibObjects->AddAt(calDetVdrift,kVdriftPHDet);
772 fCalibObjects->AddAt(calPadT0,kT0PHPad);
773 fCalibObjects->AddAt(calPadVdrift,kVdriftPHPad);
774 fPlots->AddAt(coefVdriftPH,kVdriftPHDet);
775 fPlots->AddAt(coefT0,kT0PHDet);
776 fPlots->AddAt(coefPadVdrift,kVdriftPHPad);
777 fPlots->AddAt(coefPadT0,kT0PHPad);
778 //
779 ok = kTRUE;
780 }
54f2ff1c 781 else {
840ec79d 782 //printf("Not enough stats timeoffset\n");
82b413fd 783 fStatusNeg = fStatusNeg | kTimeOffsetNotEnoughStatsNotFill;
54f2ff1c 784 }
b3fcfd96 785 calibra->ResetVectorFit();
786
787 return ok;
788
789}
00d203b6 790//____________________________________________________________________________________________________________________
b3fcfd96 791Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftLinearFit(){
792 //
793 // Analyze vdrift linear fit - produce the calibration objects
794 //
795
a5dcf618 796 //printf("Analyse linear fit\n");
797
f558cb62 798
b3fcfd96 799 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
840ec79d 800 calibra->SetCalDetVdriftExB(fCalDetVdriftUsed,fCalDetExBUsed);
a2a4ec8e 801 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
4f3bd513 802 //printf("The mean stat is by %d for VdriftLinear\n",fMinStatsVdriftLinear);
67abca5c 803 //fAliTRDCalibraVdriftLinearFit->SetSeeDetector(0);
804 //fAliTRDCalibraVdriftLinearFit->SetDebugLevel(1);
a5dcf618 805 //printf("Fill PE Array\n");
2a1a7b36 806 fAliTRDCalibraVdriftLinearFit->SetRobustFit(fRobustFitDriftVelocity);
532be2d4 807 fAliTRDCalibraVdriftLinearFit->SetMinNumberOfPointsForFit(fMinNbOfPointVdriftFit);
661c7be6 808 if(!fAlternativeVdrfitFit)
809 fAliTRDCalibraVdriftLinearFit->FillPEArray();
810 else
811 fAliTRDCalibraVdriftLinearFit->FillPEArray2();
a5dcf618 812 //printf("AliTRDCalibraFit\n");
b3fcfd96 813 calibra->AnalyseLinearFitters(fAliTRDCalibraVdriftLinearFit);
a5dcf618 814 //printf("After\n");
b3fcfd96 815
816 //Int_t nbtg = 540;
817 Int_t nbfit = calibra->GetNumberFit();
818 Int_t nbE = calibra->GetNumberEnt();
819
820
821 Bool_t ok = kFALSE;
822 // enough statistics
823 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
824 // create the cal objects
01239968 825 //calibra->RemoveOutliers(1,kTRUE);
826 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
827 //calibra->RemoveOutliers2(kTRUE);
828 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
829 //
b3fcfd96 830 TObjArray object = calibra->GetVectorFit();
831 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object,kTRUE);
832 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
833 object = calibra->GetVectorFit2();
834 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectLorentzAngle(&object);
835 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
eec29d56 836 //if(!calDetLorentz) printf("No lorentz created\n");
b3fcfd96 837 // Put them in the array
838 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
839 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
840 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
841 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
842 //
843 ok = kTRUE;
844 }
54f2ff1c 845 else {
846 fNotEnoughStatisticsForTheVdriftLinear = kTRUE;
dee5f636 847 Int_t minNumberOfEntriesForAll = fMinStatsVdriftLinear*30;
848 calibra->SetMinEntries(minNumberOfEntriesForAll); // Because we do it for all, we increase this
840ec79d 849 Double_t vdriftoverall = -100.0;
850 Double_t exboverall = 100.0;
851 calibra->AnalyseLinearFittersAllTogether(fAliTRDCalibraVdriftLinearFit,vdriftoverall,exboverall);
852 //printf("Found mean vdrift %f and exb %f\n",vdriftoverall,exboverall);
853 if(fCalDetVdriftUsed && (vdriftoverall > 0.0) && (exboverall < 70.0)) {
54f2ff1c 854 AliTRDCalDet *calDetVdrift = new AliTRDCalDet(*fCalDetVdriftUsed);
840ec79d 855 AliTRDCalDet *calDetLorentz = new AliTRDCalDet(*fCalDetExBUsed);
856 Double_t oldmeanvdrift = fCalDetVdriftUsed->CalcMean(kFALSE);
857 Double_t oldmeanexb = fCalDetExBUsed->CalcMean(kFALSE);
54f2ff1c 858 //printf("oldmean %f\n",oldmean);
840ec79d 859 if((oldmeanvdrift > 0.0) && (oldmeanexb < 70.0)) {
54f2ff1c 860 //printf("Correction factor %f\n",vdriftoverall);
840ec79d 861 calDetVdrift->Multiply(vdriftoverall/oldmeanvdrift);
a50946d4 862 if(TMath::Abs(oldmeanexb) > 0.0001) calDetLorentz->Multiply(exboverall/oldmeanexb);
54f2ff1c 863 //printf("newmean %f\n",calDetVdrift->CalcMean(kFALSE));
864 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
840ec79d 865 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
54f2ff1c 866 // Put them in the array
867 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
840ec79d 868 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
54f2ff1c 869 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
840ec79d 870 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
54f2ff1c 871 //
872 ok = kTRUE;
82b413fd 873 fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsButFill;
54f2ff1c 874 }
82b413fd 875 else {
840ec79d 876 if(oldmeanvdrift) fStatusPos = fStatusPos | kVdriftErrorOld;
877 if(oldmeanexb) fStatusPos = fStatusPos | kExBErrorOld;
82b413fd 878 }
879 }
880 else {
840ec79d 881 if((vdriftoverall <= 0.0) && (exboverall > 70.0)) fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsNotFill;
82b413fd 882 if(!fCalDetVdriftUsed) fStatusPos = fStatusPos | kVdriftErrorOld;
840ec79d 883 if(!fCalDetExBUsed) fStatusPos = fStatusPos | kExBErrorOld;
54f2ff1c 884 }
54f2ff1c 885 }
b3fcfd96 886
887 calibra->ResetVectorFit();
888
889 return ok;
890
891}
00d203b6 892//________________________________________________________________________________________________________________
b3fcfd96 893
a0bb5615 894Bool_t AliTRDPreprocessorOffline::AnalyzeExbAltFit(){
895 //
896 // Analyze vdrift linear fit - produce the calibration objects
897 //
898
899 //printf("Analyse linear fit\n");
900
901
902 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
903 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
904 //printf("Fill PE Array\n");
2a1a7b36 905 fAliTRDCalibraExbAltFit->SetRobustFit(fRobustFitExbAlt);
661c7be6 906 if(!fAlternativeExbAltFit)
907 fAliTRDCalibraExbAltFit->FillPEArray();
908 else
909 fAliTRDCalibraExbAltFit->FillPEArray2();
a0bb5615 910 //printf("AliTRDCalibraFit\n");
911 calibra->AnalyseExbAltFit(fAliTRDCalibraExbAltFit);
912 //printf("After\n");
913
914 //Int_t nbtg = 540;
915 Int_t nbfit = calibra->GetNumberFit();
916 Int_t nbE = calibra->GetNumberEnt();
917
918
919 Bool_t ok = kFALSE;
920 // enough statistics
921 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
922 // create the cal objects
923 //calibra->RemoveOutliers(1,kTRUE);
924 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
925 //
926 TObjArray object = calibra->GetVectorFit2();
927 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectExbAlt(&object);
928 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
929 //if(!calDetLorentz) printf("No lorentz created\n");
930 // Put them in the array
931 fCalibObjects->AddAt(calDetLorentz,kExbAlt);
932 fPlots->AddAt(coefLorentzAngle,kExbAlt);
933 //
934 ok = kTRUE;
935 }
936
937 calibra->ResetVectorFit();
938
939 return ok;
940
941}
942//________________________________________________________________________________________________________________
943
b3fcfd96 944Bool_t AliTRDPreprocessorOffline::AnalyzePRF(){
945 //
946 // Analyze PRF - produce the calibration objects
947 //
948
949 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
a2a4ec8e 950 calibra->SetMinEntries(fMinStatsPRF); // If there is less than 1000 entries in the histo: no fit
b3fcfd96 951 calibra->AnalysePRFMarianFit(fPRF2d);
952
953 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
954 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
955 Int_t nbfit = calibra->GetNumberFit();
956 Int_t nbE = calibra->GetNumberEnt();
957
958
959 Bool_t ok = kFALSE;
960 // enough statistics
961 if ((nbtg > 0) &&
962 (nbfit >= 0.95*nbE) && (nbE > 30)) {
963 // create the cal objects
964 TObjArray object = calibra->GetVectorFit();
965 AliTRDCalPad *calPadPRF = (AliTRDCalPad*) calibra->CreatePadObjectPRF(&object);
966 TH1F *coefPRF = calPadPRF->MakeHisto1D();
967 // Put them in the array
968 fCalibObjects->AddAt(calPadPRF,kPRF);
969 fPlots->AddAt(coefPRF,kPRF);
970 //
971 ok = kTRUE;
972 }
973
974 calibra->ResetVectorFit();
975
976 return ok;
977
978}
a5dcf618 979
e2a1c98b 980//_____________________________________________________________________________
981Bool_t AliTRDPreprocessorOffline::AnalyzePHQ(Int_t startRunNumber)
982{
983 //
984 //Produce PHQ calibration results
985 //
687aa844 986 TList *lout = 0x0;
987 TTreeSRedirector *calibStream = 0x0;
988 if(IsDebugPHQon()){
989 lout = new TList;
990 lout->SetOwner();
991
992 calibStream = new TTreeSRedirector(Form("TRDCalibStream_%010d.root", startRunNumber));
993 }
994
6951a056 995 for(Int_t iter=0; iter<AliTRDdEdxCalibUtils::GetHistArray()->GetSize(); iter++){
996 THnBase *hi = (THnBase*) AliTRDdEdxCalibUtils::GetHistAt(iter);
687aa844 997 TObjArray *obji = AliTRDdEdxCalibUtils::HistToObj(hi, startRunNumber, lout, calibStream);
e2a1c98b 998 //printf("test analyze %s\n", obji->GetName());
6951a056 999 AliTRDdEdxCalibUtils::GetObjArray()->AddAt(obji, iter);
e2a1c98b 1000 }
1001
6951a056 1002 fCalibObjects->AddAt(AliTRDdEdxCalibUtils::GetObjArray(), kPHQ);
687aa844 1003
1004 if(lout){
1005 TFile *fout=new TFile(Form("TRDCalibList_%010d.root", startRunNumber),"recreate");
1006 fout->cd();
1007 lout->Write();
1008 fout->Save();
1009 fout->Close();
1010 delete fout;
1011 }
1012 delete calibStream;
1013 delete lout;
1014
e2a1c98b 1015 return kTRUE;
1016}
1017
a5dcf618 1018//_____________________________________________________________________________
1019Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
1020{
4c865c34 1021 //
a5dcf618 1022 // Produce AliTRDCalChamberStatus out of calibration results
4c865c34 1023 //
b61b92a0 1024
83d0cc79 1025 // set up AliTRDCalibChamberStatus
92df0132 1026 AliTRDCalibChamberStatus *chamberStatus = new AliTRDCalibChamberStatus();
1027 chamberStatus->SetSparseI(fSparse);
1028 chamberStatus->AnalyseHisto(fMinStatsChamberStatus, fMinSingleStatsChamberStatus);
83d0cc79 1029 // get AliTRDCalChamberStatus
92df0132 1030 AliTRDCalChamberStatus *calChamberStatus = chamberStatus->GetCalChamberStatus();
01239968 1031
a5dcf618 1032 // get calibration objects
1033 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1034 AliTRDCalDet *calDetVDrift = (AliTRDCalDet *) fCalibObjects->At(kVdriftLinear);
840ec79d 1035 AliTRDCalDet *calDetExB = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
a5dcf618 1036
1037 // Check
92df0132 1038 if((!calDetGain) || (!calDetVDrift) || (!fCH2d) || (!calDetExB) || (!calChamberStatus)) return kFALSE;
a5dcf618 1039
1040 // Gain
83d0cc79 1041 Double_t gainmean = calDetGain->GetMean();
a5dcf618 1042 Double_t vdriftmean = calDetVDrift->GetMean();
83d0cc79 1043 Double_t exbmean = calDetExB->GetMean();
a5dcf618 1044
83d0cc79 1045 Double_t gainrms = calDetGain->GetRMSRobust();
1046 Double_t vdriftrms = calDetVDrift->GetRMSRobust();
1047 Double_t exbrms = calDetExB->GetRMSRobust();
a5dcf618 1048
1049 //printf("Gain mean: %f, rms: %f\n",gainmean,gainrms);
1050 //printf("Vdrift mean: %f, rms: %f\n",vdriftmean,vdriftrms);
840ec79d 1051 //printf("ExB mean: %f, rms: %f\n",exbmean,exbrms);
1052
a5dcf618 1053 // Check
840ec79d 1054 if((TMath::Abs(gainrms) < 0.001) || (TMath::Abs(vdriftrms) < 0.001) || (TMath::Abs(exbrms) < 0.0000001)) return kFALSE;
01239968 1055
67abca5c 1056 // Take mean each SM
1057 Double_t *gainmeanSM = new Double_t[18];
1058 Double_t *vdriftmeanSM = new Double_t[18];
1059 Double_t *exbmeanSM = new Double_t[18];
1060 //Double_t *t0meanSM = new Double_t[18];
1061 for(Int_t sm=0; sm< 18; sm++) {
1062 gainmeanSM[sm] = calDetGain->GetMeanSM(kFALSE,sm);
1063 vdriftmeanSM[sm] = calDetVDrift->GetMeanSM(kFALSE,sm);
1064 exbmeanSM[sm] = calDetExB->GetMeanSM(kFALSE,sm);
1065 //t0meanSM[sm] = calDetGain->GetMeanSM(kFALSE);
1066 }
1067
1068
a5dcf618 1069 // mask chambers with empty gain entries
1070 //Int_t counter = 0;
1071 for (Int_t idet = 0; idet < 540; idet++) {
01239968 1072
a5dcf618 1073 // ch2d
1074 TH1I *projch = (TH1I *) fCH2d->ProjectionX("projch",idet+1,idet+1,(Option_t *)"e");
1075 Double_t entries = projch->GetEntries();
83d0cc79 1076 //printf("Number of entries %f for det %d\n",entries,idet);
4c865c34 1077
67abca5c 1078 // sm number
1079 Int_t smnumber = (Int_t) idet/30;
1080
a5dcf618 1081 // gain
1082 Double_t gain = calDetGain->GetValue(idet);
4c865c34 1083
a5dcf618 1084 // vdrift
1085 Double_t vdrift = calDetVDrift->GetValue(idet);
4c865c34 1086
840ec79d 1087 // exb
1088 Double_t exb = calDetExB->GetValue(idet);
1089
4c865c34 1090
92df0132 1091 if( (entries<50 && !calChamberStatus->IsNoData(idet)) ||
83d0cc79 1092 TMath::Abs(gainmean-gain) > (fRMSBadCalibratedGain*gainrms) ||
1093 TMath::Abs(vdriftmean-vdrift) > (fRMSBadCalibratedVdrift*vdriftrms) ||
1094 TMath::Abs(exbmean-exb) > (fRMSBadCalibratedExB*exbrms) ) {
a5dcf618 1095
1096 //printf(" chamber det %03d masked \n",idet);
1097 //printf(" gainmean %f and gain %f, gainrms %f \n",gainmean,gain,gainrms);
1098 //printf(" vdriftmean %f and vdrift %f, vdriftrms %f \n",vdriftmean,vdrift,vdriftrms);
840ec79d 1099 //printf(" exbmean %f and exb %f, exbrms %f \n",exbmean,exb,exbrms);
1100
92df0132 1101 calChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kBadCalibrated);
a5dcf618 1102 //counter++;
1103 }
4c865c34 1104
67abca5c 1105 if(TMath::Abs(gainmeanSM[smnumber]-gain) < 0.000001 ||
1106 TMath::Abs(vdriftmeanSM[smnumber]-vdrift) < 0.000001 ||
1107 TMath::Abs(exbmeanSM[smnumber]-exb) < 0.000001) {
1108
1109 //printf(" chamber det %03d notcalibrated sm %d \n",idet,smnumber);
1110 //printf(" gainmeanSM %f and gain %f\n",gainmeanSM[smnumber],gain);
1111 //printf(" vdriftmeanSM %f and vdrift %f \n",vdriftmeanSM[smnumber],vdrift);
1112 //printf(" exbmeanSM %f and exb %f \n",exbmeanSM[smnumber],exb);
1113
1114 calChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kNotCalibrated);
1115 }
1116
1117
b61b92a0 1118 delete projch;
1119
a5dcf618 1120 }
b3fcfd96 1121
83d0cc79 1122 // Security
1123 for(Int_t sm=0; sm < 18; sm++) {
1124 Int_t smnodata = 0;
1125 Int_t smbadcalib = 0;
1126 for(Int_t det = 0; det < 30; det++){
1127 Int_t detector = sm*30+det;
92df0132 1128 if(calChamberStatus->IsNoData(detector)) smnodata++;
83d0cc79 1129 else {
92df0132 1130 if(calChamberStatus->IsBadCalibrated(detector)) smbadcalib++;
83d0cc79 1131 }
1132 }
1133 fNoData[sm] = smnodata;
1134 fBadCalib[sm]= smbadcalib;
1135 //printf("No Data %d, bad calibrated %d for %d\n",fNoData[sm],fBadCalib[sm],sm);
1136 }
67abca5c 1137
1138 // delete
1139 delete []gainmeanSM;
1140 delete []vdriftmeanSM;
1141 delete []exbmeanSM;
83d0cc79 1142
1143 // Security
1144 // for(Int_t sm=0; sm < 18; sm++) {
1145 // Int_t counter = 0;
1146 // for(Int_t det = 0; det < 30; det++){
1147 // Int_t detector = sm*30+det;
92df0132 1148 // if(calChamberStatus->IsBadCalibrated(detector)) counter++;
83d0cc79 1149 // }
1150 // if(counter >= 20) {
1151 // for(Int_t det = 0; det < 30; det++){
1152 // Int_t detector = sm*30+det;
92df0132 1153 // calChamberStatus->SetStatus(detector,AliTRDCalChamberStatus::kGood);
83d0cc79 1154 // }
1155 // }
1156 // }
b3fcfd96 1157
92df0132 1158 fCalibObjects->AddAt(calChamberStatus,kChamberStatus);
a5dcf618 1159 return kTRUE;
b3fcfd96 1160
a5dcf618 1161 }
b3fcfd96 1162
b3fcfd96 1163
a5dcf618 1164 //________________________________________________________________________________________________
1165 void AliTRDPreprocessorOffline::CorrectFromDetGainUsed() {
1166 //
1167 // Correct from the gas gain used afterwards
1168 //
1169 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1170 if(!calDetGain) return;
b3fcfd96 1171
a5dcf618 1172 // Calculate mean
1173 Double_t mean = 0.0;
1174 Int_t nbdet = 0;
b3fcfd96 1175
a5dcf618 1176 for(Int_t det = 0; det < 540; det++) {
00d203b6 1177
a5dcf618 1178 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1179 Float_t gainout = calDetGain->GetValue(det);
00d203b6 1180
00d203b6 1181
a5dcf618 1182 if(TMath::Abs(gainout-1.0) > 0.000001) {
1183 mean += (gaininit*gainout);
1184 nbdet++;
1185 }
1186 }
1187 if(nbdet > 0) mean = mean/nbdet;
00d203b6 1188
a5dcf618 1189 for(Int_t det = 0; det < 540; det++) {
00d203b6 1190
a5dcf618 1191 Float_t gaininit = fCalDetGainUsed->GetValue(det);
1192 Float_t gainout = calDetGain->GetValue(det);
1193
ba1aa7a7 1194 if(TMath::Abs(gainout-1.0) > 0.000001) {
1195 Double_t newgain = gaininit*gainout;
1196 if(newgain < 0.1) newgain = 0.1;
58e2b572 1197 if(newgain > 1.9) newgain = 1.9;
ba1aa7a7 1198 calDetGain->SetValue(det,newgain);
1199 }
1200 else {
1201 Double_t newgain = mean;
1202 if(newgain < 0.1) newgain = 0.1;
58e2b572 1203 if(newgain > 1.9) newgain = 1.9;
ba1aa7a7 1204 calDetGain->SetValue(det,newgain);
1205 }
a5dcf618 1206 }
1207
1208
1209 }
1210 //________________________________________________________________________________________________
1211 void AliTRDPreprocessorOffline::CorrectFromDetVdriftUsed() {
1212 //
1213 // Correct from the drift velocity
1214 //
1215
1216 //printf("Correct for vdrift\n");
1217
1218 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
1219 if(!calDetGain) return;
1220
1221 Int_t detVdrift = kVdriftPHDet;
1222 if(fMethodSecond) detVdrift = kVdriftLinear;
1223 AliTRDCalDet *calDetVdrift = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1224 if(!calDetVdrift) return;
1225
1226 // Calculate mean
8dac2af1 1227 if(!fNotEnoughStatisticsForTheVdriftLinear) {
54f2ff1c 1228 for(Int_t det = 0; det < 540; det++) {
1229
1230 Float_t vdriftinit = fCalDetVdriftUsed->GetValue(det);
1231 Float_t vdriftout = calDetVdrift->GetValue(det);
1232
1233 Float_t gain = calDetGain->GetValue(det);
1234 if(vdriftout > 0.0) gain = gain*vdriftinit/vdriftout;
1235 if(gain < 0.1) gain = 0.1;
1236 if(gain > 1.9) gain = 1.9;
1237 calDetGain->SetValue(det,gain);
1238 }
a5dcf618 1239 }
54f2ff1c 1240 else {
1241
1242 Float_t vdriftinit = fCalDetVdriftUsed->CalcMean(kFALSE);
1243 Float_t vdriftout = calDetVdrift->CalcMean(kFALSE);
1244 Float_t factorcorrectif = 1.0;
1245 if(vdriftout > 0.0) factorcorrectif = vdriftinit/vdriftout;
1246 for(Int_t det = 0; det < 540; det++) {
1247 Float_t gain = calDetGain->GetValue(det);
1248 gain = gain*factorcorrectif;
1249 if(gain < 0.1) gain = 0.1;
1250 if(gain > 1.9) gain = 1.9;
1251 calDetGain->SetValue(det,gain);
1252 }
1253
1254 }
1255
a5dcf618 1256 }
54f2ff1c 1257//_________________________________________________________________________________________________________________
a9f9c69b 1258 void AliTRDPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage *storage){
a5dcf618 1259 //
1260 // Update OCDB entry
1261 //
1262
1263 AliCDBMetaData *metaData= new AliCDBMetaData();
1264 metaData->SetObjectClassName("AliTRDCalDet");
1265 metaData->SetResponsible("Raphaelle Bailhache");
58006729 1266 metaData->AddDateToComment();
a5dcf618 1267 metaData->SetBeamPeriod(1);
1268
1269 AliCDBId id1("TRD/Calib/ChamberGainFactor", startRunNumber, endRunNumber);
a5dcf618 1270 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
a9f9c69b 1271 if(calDet) storage->Put(calDet, id1, metaData);
a5dcf618 1272
1273
eec29d56 1274 }
1275 //___________________________________________________________________________________________________________________
a9f9c69b 1276 void AliTRDPreprocessorOffline::UpdateOCDBExB(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage *storage){
eec29d56 1277 //
1278 // Update OCDB entry
1279 //
1280
1281 Int_t detExB = kLorentzLinear;
1282 if(!fMethodSecond) return;
1283
1284 //printf("Pass\n");
1285
1286 AliCDBMetaData *metaData= new AliCDBMetaData();
1287 metaData->SetObjectClassName("AliTRDCalDet");
1288 metaData->SetResponsible("Raphaelle Bailhache");
58006729 1289 metaData->AddDateToComment();
eec29d56 1290 metaData->SetBeamPeriod(1);
1291
1292 AliCDBId id1("TRD/Calib/ChamberExB", startRunNumber, endRunNumber);
eec29d56 1293 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
a9f9c69b 1294 if(calDet) storage->Put(calDet, id1, metaData);
eec29d56 1295 //if(!calDet) printf("No caldet\n");
1296
a5dcf618 1297 }
a0bb5615 1298//___________________________________________________________________________________________________________________
a9f9c69b 1299void AliTRDPreprocessorOffline::UpdateOCDBExBAlt(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage *storage){
a0bb5615 1300 //
1301 // Update OCDB entry
1302 //
1303
1304 Int_t detExB = kExbAlt;
1305 if(!fMethodSecond) return;
1306
1307 //printf("Pass\n");
1308
1309 AliCDBMetaData *metaData= new AliCDBMetaData();
1310 metaData->SetObjectClassName("AliTRDCalDet");
58006729 1311 metaData->SetResponsible("Theo Rascanu");
1312 metaData->AddDateToComment();
a0bb5615 1313 metaData->SetBeamPeriod(1);
1314
1315 AliCDBId id1("TRD/Calib/ChamberExBAlt", startRunNumber, endRunNumber);
a0bb5615 1316 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
a9f9c69b 1317 if(calDet) storage->Put(calDet, id1, metaData);
a0bb5615 1318 //if(!calDet) printf("No caldet\n");
1319
1320}
a5dcf618 1321 //___________________________________________________________________________________________________________________
a9f9c69b 1322 void AliTRDPreprocessorOffline::UpdateOCDBVdrift(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage){
a5dcf618 1323 //
1324 // Update OCDB entry
1325 //
1326
1327 Int_t detVdrift = kVdriftPHDet;
1328
1329 if(fMethodSecond) detVdrift = kVdriftLinear;
1330
1331 AliCDBMetaData *metaData= new AliCDBMetaData();
1332 metaData->SetObjectClassName("AliTRDCalDet");
1333 metaData->SetResponsible("Raphaelle Bailhache");
58006729 1334 metaData->AddDateToComment();
a5dcf618 1335 metaData->SetBeamPeriod(1);
1336
1337 AliCDBId id1("TRD/Calib/ChamberVdrift", startRunNumber, endRunNumber);
a5dcf618 1338 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
a9f9c69b 1339 if(calDet) storage->Put(calDet, id1, metaData);
a5dcf618 1340
1341 //
1342
1343 if(!fMethodSecond) {
1344
1345 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1346 metaDataPad->SetObjectClassName("AliTRDCalPad");
1347 metaDataPad->SetResponsible("Raphaelle Bailhache");
58006729 1348 metaDataPad->AddDateToComment();
a5dcf618 1349 metaDataPad->SetBeamPeriod(1);
1350
1351 AliCDBId id1Pad("TRD/Calib/LocalVdrift", startRunNumber, endRunNumber);
1352 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
a9f9c69b 1353 if(calPad) storage->Put(calPad, id1Pad, metaDataPad);
a5dcf618 1354
1355 }
1356
1357 }
1358 //________________________________________________________________________________________________________________________
a9f9c69b 1359 void AliTRDPreprocessorOffline::UpdateOCDBT0(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage){
a5dcf618 1360 //
1361 // Update OCDB entry
1362 //
1363
1364 AliCDBMetaData *metaData= new AliCDBMetaData();
1365 metaData->SetObjectClassName("AliTRDCalDet");
1366 metaData->SetResponsible("Raphaelle Bailhache");
58006729 1367 metaData->AddDateToComment();
a5dcf618 1368 metaData->SetBeamPeriod(1);
1369
1370 AliCDBId id1("TRD/Calib/ChamberT0", startRunNumber, endRunNumber);
a5dcf618 1371 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
a9f9c69b 1372 if(calDet) storage->Put(calDet, id1, metaData);
a5dcf618 1373
1374 //
1375
1376 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
1377 metaDataPad->SetObjectClassName("AliTRDCalPad");
1378 metaDataPad->SetResponsible("Raphaelle Bailhache");
58006729 1379 metaDataPad->AddDateToComment();
a5dcf618 1380 metaDataPad->SetBeamPeriod(1);
1381
1382 AliCDBId id1Pad("TRD/Calib/LocalT0", startRunNumber, endRunNumber);
1383 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
a9f9c69b 1384 if(calPad) storage->Put(calPad, id1Pad, metaDataPad);
a5dcf618 1385
1386
1387
1388 }
1389 //_________________________________________________________________________________________________________________
a9f9c69b 1390 void AliTRDPreprocessorOffline::UpdateOCDBPRF(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage){
a5dcf618 1391 //
1392 // Update OCDB entry
1393 //
1394
1395 AliCDBMetaData *metaData= new AliCDBMetaData();
1396 metaData->SetObjectClassName("AliTRDCalPad");
1397 metaData->SetResponsible("Raphaelle Bailhache");
58006729 1398 metaData->AddDateToComment();
a5dcf618 1399 metaData->SetBeamPeriod(1);
1400
58006729 1401
a5dcf618 1402 AliCDBId id1("TRD/Calib/PRFWidth", startRunNumber, endRunNumber);
a5dcf618 1403 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
a9f9c69b 1404 if(calPad) storage->Put(calPad, id1, metaData);
a5dcf618 1405
1406
1407 }
e2a1c98b 1408//_________________________________________________________________________________________________________________
a9f9c69b 1409void AliTRDPreprocessorOffline::UpdateOCDBPHQ(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage)
e2a1c98b 1410{
1411 //
1412 // Update OCDB entry
1413 //
1414 AliCDBMetaData *metaData= new AliCDBMetaData();
1415 metaData->SetObjectClassName("TObjArray");
1416 metaData->SetResponsible("Raphaelle Bailhache and Xianguo Lu");
1417 metaData->AddDateToComment();
1418 metaData->SetBeamPeriod(1);
1419
1420 AliCDBId id1("TRD/Calib/PHQ", startRunNumber, endRunNumber);
e2a1c98b 1421 TObjArray *cobj = (TObjArray *) fCalibObjects->At(kPHQ);
1422 if(cobj){
1423 //cobj->Print();
a9f9c69b 1424 storage->Put(cobj, id1, metaData);
e2a1c98b 1425 }
1426}
1427
a5dcf618 1428 //_________________________________________________________________________________________________________________
a9f9c69b 1429 void AliTRDPreprocessorOffline::UpdateOCDBChamberStatus(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage* storage){
a5dcf618 1430 //
1431 // Update OCDB entry
1432 //
1433
1434 AliCDBMetaData *metaData= new AliCDBMetaData();
1435 metaData->SetObjectClassName("AliTRDCalChamberStatus");
58006729 1436 metaData->SetResponsible("Raphaelle Bailhache and Julian Book");
1437 metaData->AddDateToComment();
a5dcf618 1438 metaData->SetBeamPeriod(1);
1439
1440 AliCDBId id1("TRD/Calib/ChamberStatus", startRunNumber, endRunNumber);
a5dcf618 1441 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
a9f9c69b 1442 if(calChamberStatus) storage->Put(calChamberStatus, id1, metaData);
a5dcf618 1443
1444
1445 }
1446 //__________________________________________________________________________________________________________________________
54f2ff1c 1447 Bool_t AliTRDPreprocessorOffline::ValidateGain() {
a5dcf618 1448 //
1449 // Validate OCDB entry
1450 //
1451
1452 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1453 if(calDet) {
1454 Double_t mean = calDet->GetMean();
1455 Double_t rms = calDet->GetRMSRobust();
1456 if((mean > 0.2) && (mean < 1.4) && (rms < 0.5)) return kTRUE;
1457 //if((mean > 0.2) && (mean < 1.4)) return kTRUE;
54f2ff1c 1458 else {
82b413fd 1459 fStatusPos = fStatusPos | kGainErrorRange;
54f2ff1c 1460 return kFALSE;
1461 }
a5dcf618 1462 }
1463 else return kFALSE;
54f2ff1c 1464
a5dcf618 1465
1466
1467 }
1468 //__________________________________________________________________________________________________________________________
1469 Bool_t AliTRDPreprocessorOffline::ValidateVdrift(){
1470 //
1471 // Update OCDB entry
1472 //
1473
1474 Int_t detVdrift = kVdriftPHDet;
1475 Bool_t ok = kTRUE;
1476
1477 if(fMethodSecond) detVdrift = kVdriftLinear;
1478
1479 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1480 if(calDet) {
1481 Double_t mean = calDet->GetMean();
1482 Double_t rms = calDet->GetRMSRobust();
1483 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
54f2ff1c 1484 if(!((mean > 1.0) && (mean < 2.0) && (rms < 0.5))) {
82b413fd 1485 fStatusPos = fStatusPos | kVdriftErrorRange;
54f2ff1c 1486 ok = kFALSE;
1487 }
a5dcf618 1488 }
1489 else return kFALSE;
1490
1491 if(!fMethodSecond) {
1492 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1493 if(calPad) {
1494 Double_t mean = calPad->GetMean();
1495 Double_t rms = calPad->GetRMS();
1496 //printf("Vdrift::meanpad %f, rmspad %f\n",mean,rms);
54f2ff1c 1497 if(!((mean > 0.9) && (mean < 1.1) && (rms < 0.6))) {
82b413fd 1498 fStatusPos = fStatusPos | kVdriftErrorRange;
54f2ff1c 1499 ok = kFALSE;
1500 }
a5dcf618 1501 }
1502 else return kFALSE;
1503 }
1504
1505 return ok;
1506
840ec79d 1507 }
1508 //__________________________________________________________________________________________________________________________
1509 Bool_t AliTRDPreprocessorOffline::ValidateExB(){
1510 //
1511 // Update OCDB entry
1512 //
1513
1514 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
1515 if(calDet) {
1516 Double_t mean = calDet->GetMean();
1517 Double_t rms = calDet->GetRMSRobust();
1518 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1519 if(!((mean > -1.0) && (mean < 1.0) && (rms < 0.5))) {
1520 fStatusNeg = fStatusNeg | kExBErrorRange;
1521 return kFALSE;
1522 }
1523 else return kTRUE;
1524 }
1525 else return kFALSE;
1526
a5dcf618 1527 }
1528 //__________________________________________________________________________________________________________________________
1529 Bool_t AliTRDPreprocessorOffline::ValidateT0(){
1530 //
1531 // Update OCDB entry
1532 //
1533
1534 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1535 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1536 if(calDet && calPad) {
1537 Double_t meandet = calDet->GetMean();
1538 Double_t rmsdet = calDet->GetRMSRobust();
1539 Double_t meanpad = calPad->GetMean();
1540 //Double_t rmspad = calPad->GetRMS();
4f3bd513 1541 printf("T0::meandet %f, rmsdet %f,meanpad %f\n",meandet,rmsdet,meanpad);
d82bad1e 1542 if((meandet > fMinTimeOffsetValidate) && (meandet < 5.0) && (rmsdet < 4.0) && (meanpad < 5.0) && (meanpad > -0.5)) return kTRUE;
54f2ff1c 1543 else {
82b413fd 1544 fStatusPos = fStatusPos | kTimeOffsetErrorRange;
54f2ff1c 1545 return kFALSE;
1546 }
a5dcf618 1547 }
1548 else return kFALSE;
1549
1550 }
1551 //__________________________________________________________________________________________________________________________
1552 Bool_t AliTRDPreprocessorOffline::ValidatePRF() const{
1553 //
1554 // Update OCDB entry
1555 //
1556
1557 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1558 if(calPad) {
1559 Double_t meanpad = calPad->GetMean();
1560 Double_t rmspad = calPad->GetRMS();
1561 //printf("PRF::meanpad %f, rmspad %f\n",meanpad,rmspad);
1562 if((meanpad < 1.0) && (rmspad < 0.8)) return kTRUE;
1563 else return kFALSE;
1564 }
1565 else return kFALSE;
1566
1567
1568 }
1569 //__________________________________________________________________________________________________________________________
82b413fd 1570Bool_t AliTRDPreprocessorOffline::ValidateChamberStatus(){
00d203b6 1571 //
1572 // Update OCDB entry
1573 //
1574
a5dcf618 1575 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1576 if(calChamberStatus) {
83d0cc79 1577
1578 Int_t detectornodata = 0;
1579 Int_t detectorbadcalib = 0;
1580
1581 for(Int_t sm=0; sm < 18; sm++) {
1582 //printf("%d chambers w/o data in sm %d\n",fNoData[sm],sm);
1583 //printf("%d bad calibrated chambers in sm %d\n",fBadCalib[sm],sm);
1584 if(fNoData[sm] != 30) detectornodata += fNoData[sm];
1585 detectorbadcalib+=fBadCalib[sm];
a5dcf618 1586 }
83d0cc79 1587 //printf("Number of chambers w/o data %d\n",detectornodata);
1588 //printf("Number of chambers bad calibrated %d\n",detectorbadcalib);
1589
1590 if((detectornodata > fNoDataValidate) ||
1591 (detectorbadcalib > fBadCalibValidate)){
82b413fd 1592 fStatusPos = fStatusPos | kChamberStatusErrorRange;
1593 return kFALSE;
1594 }
83d0cc79 1595 return kTRUE;
00d203b6 1596 }
1597 else return kFALSE;
83d0cc79 1598
b3fcfd96 1599}
4c865c34 1600//_____________________________________________________________________________
1601Int_t AliTRDPreprocessorOffline::GetVersion(TString name) const
1602{
1603 //
1604 // Get version from the title
1605 //
1606
1607 // Some patterns
1608 const Char_t *version = "Ver";
1609 if(!strstr(name.Data(),version)) return -1;
f558cb62 1610 const Char_t *after = "Subver";
1611 if(!strstr(name.Data(),after)) return -1;
1612
4c865c34 1613 for(Int_t ver = 0; ver < 999999999; ver++) {
1614
1615 TString vertry(version);
1616 vertry += ver;
f558cb62 1617 vertry += after;
4c865c34 1618
1619 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1620
1621 if(strstr(name.Data(),vertry.Data())) return ver;
1622
1623 }
1624
1625 return -1;
1626
1627}
1628
1629//_____________________________________________________________________________
1630Int_t AliTRDPreprocessorOffline::GetSubVersion(TString name) const
1631{
1632 //
1633 // Get subversion from the title
1634 //
1635
1636 // Some patterns
1637 const Char_t *subversion = "Subver";
1638 if(!strstr(name.Data(),subversion)) return -1;
f558cb62 1639 const Char_t *after = "FirstRun";
1640 if(!strstr(name.Data(),after)) {
1641 after = "Nz";
1642 }
1643 if(!strstr(name.Data(),after)) return -1;
1644
4c865c34 1645
1646 for(Int_t ver = 0; ver < 999999999; ver++) {
1647
1648 TString vertry(subversion);
1649 vertry += ver;
f558cb62 1650 vertry += after;
ca7e6e64 1651
1652 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1653
1654 if(strstr(name.Data(),vertry.Data())) return ver;
1655
1656 }
1657
1658 return -1;
1659
1660}
1661
1662//_____________________________________________________________________________
1663Int_t AliTRDPreprocessorOffline::GetFirstRun(TString name) const
1664{
1665 //
1666 // Get first run from the title
1667 //
1668
1669 // Some patterns
1670 const Char_t *firstrun = "FirstRun";
1671 if(!strstr(name.Data(),firstrun)) return -1;
f558cb62 1672 const Char_t *after = "Nz";
1673 if(!strstr(name.Data(),after)) return -1;
1674
ca7e6e64 1675
1676 for(Int_t ver = 0; ver < 999999999; ver++) {
1677
1678 TString vertry(firstrun);
1679 vertry += ver;
f558cb62 1680 vertry += after;
4c865c34 1681
1682 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1683
1684 if(strstr(name.Data(),vertry.Data())) return ver;
1685
1686 }
1687
1688 return -1;
1689
1690}
82b413fd 1691//_____________________________________________________________________________
1692Bool_t AliTRDPreprocessorOffline::CheckStatus(Int_t status, Int_t bitMask) const
1693{
1694 //
1695 // Checks the status
1696 //
1697
1698 return (status & bitMask) ? kTRUE : kFALSE;
1699
1700}
1701//_____________________________________________________________________________
1702Int_t AliTRDPreprocessorOffline::GetStatus() const
1703{
1704 //
1705 // Checks the status
1706 // fStatusPos: errors
1707 // fStatusNeg: only info
1708 //
1709
1710 if(fStatusPos > 0) return fStatusPos;
1711 else return (-TMath::Abs(fStatusNeg));
1712
1713}
1714//_____________________________________________________________________________
1715void AliTRDPreprocessorOffline::PrintStatus() const
1716{
1717 //
1718 // Do Summary
1719 //
1720
1721 AliInfo(Form("The error status is %d",fStatusPos));
1722 AliInfo(Form("IsGainErrorOld? %d",(Int_t)IsGainErrorOld()));
1723 AliInfo(Form("IsVdriftErrorOld? %d",(Int_t)IsVdriftErrorOld()));
1724 AliInfo(Form("IsGainErrorRange? %d",(Int_t)IsGainErrorRange()));
1725 AliInfo(Form("IsVdriftErrorRange? %d",(Int_t)IsVdriftErrorRange()));
1726 AliInfo(Form("IsTimeOffsetErrorRange? %d",(Int_t)IsTimeOffsetErrorRange()));
1727 AliInfo(Form("IsChamberStatusErrorRange? %d",(Int_t)IsChamberStatusErrorRange()));
1728
1729
1730 AliInfo(Form("The info status is %d",fStatusNeg));
1731 AliInfo(Form("IsGainNotEnoughStatsButFill? %d",(Int_t)IsGainNotEnoughStatsButFill()));
1732 AliInfo(Form("IsVdriftNotEnoughStatsButFill? %d",(Int_t)IsVdriftNotEnoughStatsButFill()));
1733 AliInfo(Form("IsGainNotEnoughStatsNotFill? %d",(Int_t)IsGainNotEnoughStatsNotFill()));
1734 AliInfo(Form("IsVdriftNotEnoughStatsNotFill? %d",(Int_t)IsVdriftNotEnoughStatsNotFill()));
1735 AliInfo(Form("IsTimeOffsetNotEnoughStatsNotFill? %d",(Int_t)IsTimeOffsetNotEnoughStatsNotFill()));
840ec79d 1736
1737 AliInfo(Form("IsExBErrorRange? %d",(Int_t)IsExBErrorRange()));
1738 AliInfo(Form("IsExBErrorOld? %d",(Int_t)IsExBErrorOld()));
82b413fd 1739
1740}
840ec79d 1741//___________________________________________________________________________________
1742void AliTRDPreprocessorOffline::SetCalDetVdrift(AliTRDCalDet *calDetVdriftUsed)
1743{
1744
1745 fCalDetVdriftUsed = calDetVdriftUsed;
1746
1747 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1748 for(Int_t k = 0; k < 540; k++){
1749 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1750 //printf("Set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1751 }
1752
1753};
83d0cc79 1754//___________________________________________________________________________________
1755Bool_t AliTRDPreprocessorOffline::SetCalDetGain(Int_t runNumber, Int_t version, Int_t subversion)
1756{
1757 //
1758 // Set the fCalDetGainUsed
1759 //
1760
1761 if((version == 0) && (subversion == 0)) return kFALSE;
82b413fd 1762
83d0cc79 1763 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor",runNumber, version, subversion);
1764 if(!entry) {
1765 AliError("Found no entry\n");
1766 fStatusPos = fStatusPos | kGainErrorOld;
1767 return kFALSE;
1768 }
1769 //const AliCDBId id = entry->GetId();
1770 //version = id.GetVersion();
1771 //subversion = id.GetSubVersion();
1772 //printf("Found version %d and subversion %d for vdrift\n",version,subversion);
1773 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1774 if(calDet) fCalDetGainUsed = calDet;
1775 else {
1776 fStatusPos = fStatusPos | kGainErrorOld;
1777 return kFALSE;
1778 }
1779
1780 return kTRUE;
1781
1782}
1783//___________________________________________________________________________________
1784Bool_t AliTRDPreprocessorOffline::SetCalDetVdriftExB(Int_t runNumber, Int_t versionv, Int_t subversionv, Int_t versionexb, Int_t subversionexb)
1785{
1786 //
1787 // Set the fCalDetVdriftUsed and fCalDetExBUsed
1788 //
1789
1790 if((versionv == 0) && (subversionv == 0)) return kFALSE;
1791
1792 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberVdrift",runNumber, versionv, subversionv);
1793 if(!entry) {
1794 AliError("Found no entry\n");
1795 fStatusPos = fStatusPos | kVdriftErrorOld;
1796 return kFALSE;
1797 }
1798 AliTRDCalDet* calDet = (AliTRDCalDet *)entry->GetObject();
1799 if(calDet) fCalDetVdriftUsed = calDet;
1800 else {
1801 fStatusPos = fStatusPos | kVdriftErrorOld;
1802 return kFALSE;
1803 }
1804
1805 // ExB object
1806
1807 if((versionexb == 0) && (subversionexb == 0)) {
1808
1809 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1810 for(Int_t k = 0; k < 540; k++){
1811 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1812 //printf("Nothing found: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1813 }
1814 }
1815 else {
1816
1817 entry = 0x0;
1818 entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberExB",runNumber, versionexb, subversionexb);
1819 if(!entry) {
1820 //printf("Found no entry\n");
1821 fStatusPos = fStatusPos | kExBErrorOld;
1822 return kFALSE;
1823 }
1824 AliTRDCalDet* calDetexb = (AliTRDCalDet *)entry->GetObject();
1825 if(!calDetexb) {
1826 fStatusPos = fStatusPos | kExBErrorOld;
1827 return kFALSE;
1828 }
1829
1830 Double_t meanexb = calDetexb->GetMean();
1831 //printf("Mean value %f\n",meanexb);
1832 if((meanexb > 70) || (fNoExBUsedInReco)) {
1833 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1834 for(Int_t k = 0; k < 540; k++){
1835 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1836 //printf("Found but: set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1837 }
1838 }
1839 else {
1840 fCalDetExBUsed = calDetexb;
1841 }
1842
1843 }
1844
1845
1846 return kTRUE;
1847
1848}
01239968 1849