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