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