]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDPreprocessorOffline.cxx
First fix for the exb calibration.
[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"
b3fcfd96 50#include "TProfile2D.h"
51#include "AliTRDCalDet.h"
52#include "AliTRDCalPad.h"
53#include "AliCDBMetaData.h"
54#include "AliCDBId.h"
55#include "AliCDBManager.h"
56#include "AliCDBStorage.h"
57#include "AliTRDCalibraMode.h"
58#include "AliTRDCalibraFit.h"
59#include "AliTRDCalibraVdriftLinearFit.h"
60#include "AliTRDPreprocessorOffline.h"
81a5aeca 61#include "AliTRDCalChamberStatus.h"
840ec79d 62#include "AliTRDCommonParam.h"
b3fcfd96 63
64
65ClassImp(AliTRDPreprocessorOffline)
66
54f2ff1c 67 AliTRDPreprocessorOffline::AliTRDPreprocessorOffline():
01239968 68 TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
b3fcfd96 69 fMethodSecond(kTRUE),
01239968 70 fNameList("TRDCalib"),
71 fCalDetGainUsed(0x0),
4c865c34 72 fCalDetVdriftUsed(0x0),
840ec79d 73 fCalDetExBUsed(0x0),
b3fcfd96 74 fCH2d(0x0),
75 fPH2d(0x0),
76 fPRF2d(0x0),
77 fAliTRDCalibraVdriftLinearFit(0x0),
78 fNEvents(0x0),
79 fAbsoluteGain(0x0),
adab6236 80 fPlots(new TObjArray(9)),
81 fCalibObjects(new TObjArray(9)),
4c865c34 82 fVersionGainUsed(0),
83 fSubVersionGainUsed(0),
ca7e6e64 84 fFirstRunVdriftUsed(0),
4c865c34 85 fVersionVdriftUsed(0),
00d203b6 86 fSubVersionVdriftUsed(0),
87 fSwitchOnValidation(kTRUE),
88 fVdriftValidated(kFALSE),
840ec79d 89 fExBValidated(kFALSE),
a2a4ec8e 90 fT0Validated(kFALSE),
91 fMinStatsVdriftT0PH(800*20),
92 fMinStatsVdriftLinear(800),
93 fMinStatsGain(800),
54f2ff1c 94 fMinStatsPRF(600),
95 fBackCorrectGain(kFALSE),
96 fBackCorrectVdrift(kTRUE),
97 fNotEnoughStatisticsForTheGain(kFALSE),
98 fNotEnoughStatisticsForTheVdriftLinear(kFALSE),
82b413fd 99 fStatusNeg(0),
100 fStatusPos(0)
b3fcfd96 101{
102 //
103 // default constructor
104 //
105}
00d203b6 106//_________________________________________________________________________________________________________________
b3fcfd96 107AliTRDPreprocessorOffline::~AliTRDPreprocessorOffline() {
108 //
109 // Destructor
110 //
111
01239968 112 if(fCalDetGainUsed) delete fCalDetGainUsed;
4c865c34 113 if(fCalDetVdriftUsed) delete fCalDetVdriftUsed;
840ec79d 114 if(fCalDetExBUsed) delete fCalDetExBUsed;
b3fcfd96 115 if(fCH2d) delete fCH2d;
116 if(fPH2d) delete fPH2d;
117 if(fPRF2d) delete fPRF2d;
118 if(fAliTRDCalibraVdriftLinearFit) delete fAliTRDCalibraVdriftLinearFit;
119 if(fNEvents) delete fNEvents;
120 if(fAbsoluteGain) delete fAbsoluteGain;
121 if(fPlots) delete fPlots;
122 if(fCalibObjects) delete fCalibObjects;
123
124}
00d203b6 125//___________________________________________________________________________________________________________________
b3fcfd96 126
127void AliTRDPreprocessorOffline::CalibVdriftT0(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
128 //
129 // make calibration of the drift velocity
130 // Input parameters:
131 // file - the location of input file
132 // startRunNumber, endRunNumber - run validity period
133 // ocdbStorage - path to the OCDB storage
134 // - if empty - local storage 'pwd' uesed
135 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
136 //
137 // 1. Initialization
138 //
008817a3 139 fVdriftValidated = kTRUE;
140 fT0Validated = kTRUE;
840ec79d 141 fExBValidated = kTRUE;
54f2ff1c 142 fNotEnoughStatisticsForTheVdriftLinear = kFALSE;
b3fcfd96 143 //
144 // 2. extraction of the information
145 //
840ec79d 146 if(ReadVdriftLinearFitGlobal(file) && fCalDetVdriftUsed && fCalDetExBUsed) AnalyzeVdriftLinearFit();
54f2ff1c 147 if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
b3fcfd96 148 //
149 // 3. Append QA plots
150 //
151 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
152 //
153 //
00d203b6 154 // 4. validate OCDB entries
b3fcfd96 155 //
00d203b6 156 if(fSwitchOnValidation==kTRUE && ValidateVdrift()==kFALSE) {
82b413fd 157 //AliError("TRD vdrift OCDB parameters out of range!");
00d203b6 158 fVdriftValidated = kFALSE;
159 }
160 if(fSwitchOnValidation==kTRUE && ValidateT0()==kFALSE) {
82b413fd 161 //AliError("TRD t0 OCDB parameters out of range!");
00d203b6 162 fT0Validated = kFALSE;
163 }
840ec79d 164 if(fSwitchOnValidation==kTRUE && ValidateExB()==kFALSE) {
165 //AliError("TRD t0 OCDB parameters out of range!");
166 fExBValidated = kFALSE;
167 }
b3fcfd96 168 //
00d203b6 169 // 5. update of OCDB
170 //
171 //
172 if(fVdriftValidated) UpdateOCDBVdrift(startRunNumber,endRunNumber,ocdbStorage);
173 if(fT0Validated) UpdateOCDBT0(startRunNumber,endRunNumber,ocdbStorage);
840ec79d 174 if(fExBValidated) UpdateOCDBExB(startRunNumber,endRunNumber,ocdbStorage);
00d203b6 175
b3fcfd96 176}
00d203b6 177//_________________________________________________________________________________________________________________
b3fcfd96 178
179void AliTRDPreprocessorOffline::CalibGain(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
180 //
181 // make calibration of the drift velocity
182 // Input parameters:
183 // file - the location of input file
184 // startRunNumber, endRunNumber - run validity period
185 // ocdbStorage - path to the OCDB storage
186 // - if empty - local storage 'pwd' uesed
187 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
188 //
54f2ff1c 189 fNotEnoughStatisticsForTheGain = kFALSE;
190 //
b3fcfd96 191 // 1. Initialization
192 if(!ReadGainGlobal(file)) return;
193 //
194 //
195 // 2. extraction of the information
196 //
197 AnalyzeGain();
54f2ff1c 198 if(fBackCorrectGain) CorrectFromDetGainUsed();
199 if(fBackCorrectVdrift) CorrectFromDetVdriftUsed();
b3fcfd96 200 //
201 // 3. Append QA plots
202 //
203 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
204 //
205 //
00d203b6 206 // 4. validate OCDB entries
207 //
208 if(fSwitchOnValidation==kTRUE && ValidateGain()==kFALSE) {
82b413fd 209 //AliError("TRD gain OCDB parameters out of range!");
00d203b6 210 return;
211 }
b3fcfd96 212 //
00d203b6 213 // 5. update of OCDB
b3fcfd96 214 //
00d203b6 215 //
216 if((!fCalDetVdriftUsed) || (fCalDetVdriftUsed && fVdriftValidated)) UpdateOCDBGain(startRunNumber,endRunNumber,ocdbStorage);
217
b3fcfd96 218
219}
00d203b6 220//________________________________________________________________________________________________________________
b3fcfd96 221
222void AliTRDPreprocessorOffline::CalibPRF(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
223 //
224 // make calibration of the drift velocity
225 // Input parameters:
226 // file - the location of input file
227 // startRunNumber, endRunNumber - run validity period
228 // ocdbStorage - path to the OCDB storage
229 // - if empty - local storage 'pwd' uesed
230 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
231 //
232 // 1. Initialization
233 if(!ReadPRFGlobal(file)) return;
234 //
235 //
236 // 2. extraction of the information
237 //
238 AnalyzePRF();
239 //
240 // 3. Append QA plots
241 //
242 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
243 //
244 //
00d203b6 245 //
246 // 4. validate OCDB entries
247 //
248 if(fSwitchOnValidation==kTRUE && ValidatePRF()==kFALSE) {
82b413fd 249 //AliError("TRD prf OCDB parameters out of range!");
00d203b6 250 return;
251 }
252 //
253 // 5. update of OCDB
b3fcfd96 254 //
255 //
256 UpdateOCDBPRF(startRunNumber,endRunNumber,ocdbStorage);
257
a5dcf618 258}
259//________________________________________________________________________________________________________________
260
261void AliTRDPreprocessorOffline::CalibChamberStatus(Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
262 //
263 // make calibration of the chamber status
264 // Input parameters:
265 // startRunNumber, endRunNumber - run validity period
266 // ocdbStorage - path to the OCDB storage
267 // - if empty - local storage 'pwd' uesed
268 if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
269 //
270 //
271 // 2. extraction of the information
272 //
273 if(!AnalyzeChamberStatus()) return;
274 //
275 // 3. Append QA plots
276 //
277 //MakeDefaultPlots(fVdriftArray,fVdriftArray);
278 //
279 //
280 //
281 // 4. validate OCDB entries
282 //
283 if(fSwitchOnValidation==kTRUE && ValidateChamberStatus()==kFALSE) {
82b413fd 284 //AliError("TRD Chamber status OCDB parameters not ok!");
a5dcf618 285 return;
286 }
287 //
288 // 5. update of OCDB
289 //
290 //
54f2ff1c 291 if((!fNotEnoughStatisticsForTheGain) && (!fNotEnoughStatisticsForTheGain)) UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
a5dcf618 292
b3fcfd96 293}
00d203b6 294//______________________________________________________________________________________________________
4c865c34 295Bool_t AliTRDPreprocessorOffline::Init(const Char_t* fileName){
296 //
297 // read the calibration used during the reconstruction
298 //
299
300 if(ReadVdriftT0Global(fileName)) {
301
302 TString nameph = fPH2d->GetTitle();
ca7e6e64 303 fFirstRunVdriftUsed = GetFirstRun(nameph);
4c865c34 304 fVersionVdriftUsed = GetVersion(nameph);
305 fSubVersionVdriftUsed = GetSubVersion(nameph);
306
307 //printf("Found Version %d, Subversion %d for vdrift\n",fVersionVdriftUsed,fSubVersionVdriftUsed);
308
309 }
310
311 if(ReadGainGlobal(fileName)) {
312
313 TString namech = fCH2d->GetTitle();
314 fVersionGainUsed = GetVersion(namech);
315 fSubVersionGainUsed = GetSubVersion(namech);
316
317 //printf("Found Version %d, Subversion %d for gain\n",fVersionGainUsed,fSubVersionGainUsed);
318
319 }
320
82b413fd 321 if(fVersionVdriftUsed == 0) fStatusPos = fStatusPos |kVdriftErrorOld;
322 if(fVersionGainUsed == 0) fStatusPos = fStatusPos | kGainErrorOld;
840ec79d 323
4c865c34 324 return kTRUE;
325
326}
00d203b6 327//___________________________________________________________________________________________________________________
b3fcfd96 328
329Bool_t AliTRDPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
330 //
331 // read calibration entries from file
332 //
4c865c34 333 if(fCH2d) return kTRUE;
b3fcfd96 334 TFile fcalib(fileName);
01239968 335 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
b3fcfd96 336 if (array){
337 TH2I *ch2d = (TH2I *) array->FindObject("CH2d");
338 if(!ch2d) return kFALSE;
339 fCH2d = (TH2I*)ch2d->Clone();
340 //fNEvents = (TH1I *) array->FindObject("NEvents");
341 //fAbsoluteGain = (TH2F *) array->FindObject("AbsoluteGain");
342 }else{
343 TH2I *ch2d = (TH2I *) fcalib.Get("CH2d");
344 if(!ch2d) return kFALSE;
345 fCH2d = (TH2I*)ch2d->Clone();
346 //fNEvents = (TH1I *) fcalib.Get("NEvents");
347 //fAbsoluteGain = (TH2F *) fcalib.Get("AbsoluteGain");
348 }
349 fCH2d->SetDirectory(0);
350 //printf("title of CH2d %s\n",fCH2d->GetTitle());
351
352 return kTRUE;
353
354}
00d203b6 355//_________________________________________________________________________________________________________________
b3fcfd96 356
357Bool_t AliTRDPreprocessorOffline::ReadVdriftT0Global(const Char_t* fileName){
358 //
359 // read calibration entries from file
360 //
4c865c34 361 if(fPH2d) return kTRUE;
b3fcfd96 362 TFile fcalib(fileName);
01239968 363 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
b3fcfd96 364 if (array){
365 TProfile2D *ph2d = (TProfile2D *) array->FindObject("PH2d");
366 if(!ph2d) return kFALSE;
367 fPH2d = (TProfile2D*)ph2d->Clone();
368 //fNEvents = (TH1I *) array->FindObject("NEvents");
369 }else{
370 TProfile2D *ph2d = (TProfile2D *) fcalib.Get("PH2d");
371 if(!ph2d) return kFALSE;
372 fPH2d = (TProfile2D*)ph2d->Clone();
373 //fNEvents = (TH1I *) fcalib.Get("NEvents");
374 }
375 fPH2d->SetDirectory(0);
376 //printf("title of PH2d %s\n",fPH2d->GetTitle());
377
378 return kTRUE;
379
380}
00d203b6 381//___________________________________________________________________________________________________________________
b3fcfd96 382
383Bool_t AliTRDPreprocessorOffline::ReadVdriftLinearFitGlobal(const Char_t* fileName){
384 //
385 // read calibration entries from file
386 //
4c865c34 387 if(fAliTRDCalibraVdriftLinearFit) return kTRUE;
b3fcfd96 388 TFile fcalib(fileName);
01239968 389 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
b3fcfd96 390 if (array){
391 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) array->FindObject("AliTRDCalibraVdriftLinearFit");
392 //fNEvents = (TH1I *) array->FindObject("NEvents");
393 }else{
394 fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) fcalib.Get("AliTRDCalibraVdriftLinearFit");
395 //fNEvents = (TH1I *) fcalib.Get("NEvents");
396 }
397 if(!fAliTRDCalibraVdriftLinearFit) {
398 //printf("No AliTRDCalibraVdriftLinearFit\n");
399 return kFALSE;
400 }
401 return kTRUE;
402
403}
00d203b6 404//_____________________________________________________________________________________________________________
b3fcfd96 405
406Bool_t AliTRDPreprocessorOffline::ReadPRFGlobal(const Char_t* fileName){
407 //
408 // read calibration entries from file
409 //
4c865c34 410 if(fPRF2d) return kTRUE;
b3fcfd96 411 TFile fcalib(fileName);
01239968 412 TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
b3fcfd96 413 if (array){
414 TProfile2D *prf2d = (TProfile2D *) array->FindObject("PRF2d");
415 if(!prf2d) return kFALSE;
416 fPRF2d = (TProfile2D*)prf2d->Clone();
417 //fNEvents = (TH1I *) array->FindObject("NEvents");
418 }else{
419 TProfile2D *prf2d = (TProfile2D *) fcalib.Get("PRF2d");
420 if(!prf2d) return kFALSE;
421 fPRF2d = (TProfile2D*)prf2d->Clone();
422 //fNEvents = (TH1I *) fcalib.Get("NEvents");
423 }
424 fPRF2d->SetDirectory(0);
425 //printf("title of PRF2d %s\n",fPRF2d->GetTitle());
426
427 return kTRUE;
428
429}
00d203b6 430//__________________________________________________________________________________________________________
b3fcfd96 431
432Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
433 //
434 // Analyze gain - produce the calibration objects
435 //
436
437 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
a2a4ec8e 438 calibra->SetMinEntries(fMinStatsGain); // If there is less than 1000 entries in the histo: no fit
b3fcfd96 439 calibra->AnalyseCH(fCH2d);
440
441 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
442 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
443 Int_t nbfit = calibra->GetNumberFit();
444 Int_t nbE = calibra->GetNumberEnt();
445
446
447 Bool_t ok = kFALSE;
4c865c34 448 Bool_t meanother = kFALSE;
b3fcfd96 449 // enough statistics
450 if ((nbtg > 0) &&
451 (nbfit >= 0.5*nbE) && (nbE > 30)) {
452 // create the cal objects
54f2ff1c 453 if(!fBackCorrectGain) {
4c865c34 454 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
455 meanother = kTRUE;
456 }
b3fcfd96 457 TObjArray object = calibra->GetVectorFit();
4c865c34 458 AliTRDCalDet *calDetGain = calibra->CreateDetObjectGain(&object,meanother);
b3fcfd96 459 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
460 // Put them in the array
461 fCalibObjects->AddAt(calDetGain,kGain);
462 fPlots->AddAt(coefGain,kGain);
463 //
464 ok = kTRUE;
465 }
54f2ff1c 466 else {
467 fNotEnoughStatisticsForTheGain = kTRUE;
dee5f636 468 Int_t minStatsGain = fMinStatsGain*30;
469 calibra->SetMinEntries(minStatsGain); // Because we do it for all, we increase this
54f2ff1c 470 Double_t gainoverallnotnormalized = calibra->AnalyseCHAllTogether(fCH2d);
471 if(fCalDetGainUsed && (gainoverallnotnormalized > 0.0)) {
472 AliTRDCalDet *calDetGain = new AliTRDCalDet(*fCalDetGainUsed);
473 Double_t oldmean = fCalDetGainUsed->CalcMean(kFALSE);
474 //printf("oldmean %f\n",oldmean);
475 if(oldmean > 0.0) {
476 Double_t scalefactor = calibra->GetScaleFactorGain();
477 //printf("Correction factor %f\n",gainoverallnotnormalized*scalefactor);
478 calDetGain->Multiply(gainoverallnotnormalized*scalefactor/oldmean);
479 //printf("newmean %f\n",calDetGain->CalcMean(kFALSE));
480 TH1F *coefGain = calDetGain->MakeHisto1DAsFunctionOfDet();
481 fCalibObjects->AddAt(calDetGain,kGain);
482 fPlots->AddAt(coefGain,kGain);
483 //
484 ok = kTRUE;
82b413fd 485 fStatusNeg = fStatusNeg | kGainNotEnoughStatsButFill;
54f2ff1c 486 }
487 else {
82b413fd 488 fStatusPos = fStatusPos | kGainErrorOld;
54f2ff1c 489 }
490 }
491 else {
82b413fd 492 if(gainoverallnotnormalized <= 0.0) fStatusNeg = fStatusNeg | kGainNotEnoughStatsNotFill;
493 if(!fCalDetGainUsed) fStatusPos = fStatusPos | kGainErrorOld;
54f2ff1c 494 }
495 }
b3fcfd96 496
497 calibra->ResetVectorFit();
498
499 return ok;
500
501}
00d203b6 502//_____________________________________________________________________________________________________
b3fcfd96 503Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftT0(){
504 //
505 // Analyze VdriftT0 - produce the calibration objects
506 //
507
508 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
a2a4ec8e 509 calibra->SetMinEntries(fMinStatsVdriftT0PH); // If there is less than 1000 entries in the histo: no fit
b3fcfd96 510 calibra->AnalysePH(fPH2d);
511
512 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
513 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
514 Int_t nbfit = calibra->GetNumberFit();
515 Int_t nbfitSuccess = calibra->GetNumberFitSuccess();
516 Int_t nbE = calibra->GetNumberEnt();
517
518 //printf("nbtg %d, nbfit %d, nbE %d, nbfitSuccess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
519
520 Bool_t ok = kFALSE;
521 if ((nbtg > 0) &&
522 (nbfit >= 0.5*nbE) && (nbE > 30) && (nbfitSuccess > 30)) {
523 //printf("Pass the cut for VdriftT0\n");
524 // create the cal objects
01239968 525 calibra->RemoveOutliers(1,kFALSE);
526 calibra->PutMeanValueOtherVectorFit(1,kFALSE);
527 calibra->RemoveOutliers2(kFALSE);
528 calibra->PutMeanValueOtherVectorFit2(1,kFALSE);
529 //
b3fcfd96 530 TObjArray object = calibra->GetVectorFit();
531 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object);
532 TH1F *coefVdriftPH = calDetVdrift->MakeHisto1DAsFunctionOfDet();
533 AliTRDCalPad *calPadVdrift = (AliTRDCalPad *)calibra->CreatePadObjectVdrift(&object,calDetVdrift);
534 TH1F *coefPadVdrift = calPadVdrift->MakeHisto1D();
535 object = calibra->GetVectorFit2();
536 AliTRDCalDet *calDetT0 = calibra->CreateDetObjectT0(&object);
537 TH1F *coefT0 = calDetT0->MakeHisto1DAsFunctionOfDet();
538 AliTRDCalPad *calPadT0 = (AliTRDCalPad *)calibra->CreatePadObjectT0(&object,calDetT0);
539 TH1F *coefPadT0 = calPadT0->MakeHisto1D();
540 // Put them in the array
541 fCalibObjects->AddAt(calDetT0,kT0PHDet);
542 fCalibObjects->AddAt(calDetVdrift,kVdriftPHDet);
543 fCalibObjects->AddAt(calPadT0,kT0PHPad);
544 fCalibObjects->AddAt(calPadVdrift,kVdriftPHPad);
545 fPlots->AddAt(coefVdriftPH,kVdriftPHDet);
546 fPlots->AddAt(coefT0,kT0PHDet);
547 fPlots->AddAt(coefPadVdrift,kVdriftPHPad);
548 fPlots->AddAt(coefPadT0,kT0PHPad);
549 //
550 ok = kTRUE;
551 }
54f2ff1c 552 else {
840ec79d 553 //printf("Not enough stats timeoffset\n");
82b413fd 554 fStatusNeg = fStatusNeg | kTimeOffsetNotEnoughStatsNotFill;
54f2ff1c 555 }
b3fcfd96 556 calibra->ResetVectorFit();
557
558 return ok;
559
560}
00d203b6 561//____________________________________________________________________________________________________________________
b3fcfd96 562Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftLinearFit(){
563 //
564 // Analyze vdrift linear fit - produce the calibration objects
565 //
566
a5dcf618 567 //printf("Analyse linear fit\n");
568
f558cb62 569
b3fcfd96 570 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
840ec79d 571 calibra->SetCalDetVdriftExB(fCalDetVdriftUsed,fCalDetExBUsed);
a2a4ec8e 572 calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
a5dcf618 573 //printf("Fill PE Array\n");
01239968 574 fAliTRDCalibraVdriftLinearFit->FillPEArray();
a5dcf618 575 //printf("AliTRDCalibraFit\n");
b3fcfd96 576 calibra->AnalyseLinearFitters(fAliTRDCalibraVdriftLinearFit);
a5dcf618 577 //printf("After\n");
b3fcfd96 578
579 //Int_t nbtg = 540;
580 Int_t nbfit = calibra->GetNumberFit();
581 Int_t nbE = calibra->GetNumberEnt();
582
583
584 Bool_t ok = kFALSE;
585 // enough statistics
586 if ((nbfit >= 0.5*nbE) && (nbE > 30)) {
587 // create the cal objects
01239968 588 //calibra->RemoveOutliers(1,kTRUE);
589 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
590 //calibra->RemoveOutliers2(kTRUE);
591 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
592 //
b3fcfd96 593 TObjArray object = calibra->GetVectorFit();
594 AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object,kTRUE);
595 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
596 object = calibra->GetVectorFit2();
597 AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectLorentzAngle(&object);
598 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
eec29d56 599 //if(!calDetLorentz) printf("No lorentz created\n");
b3fcfd96 600 // Put them in the array
601 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
602 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
603 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
604 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
605 //
606 ok = kTRUE;
607 }
54f2ff1c 608 else {
609 fNotEnoughStatisticsForTheVdriftLinear = kTRUE;
dee5f636 610 Int_t minNumberOfEntriesForAll = fMinStatsVdriftLinear*30;
611 calibra->SetMinEntries(minNumberOfEntriesForAll); // Because we do it for all, we increase this
840ec79d 612 Double_t vdriftoverall = -100.0;
613 Double_t exboverall = 100.0;
614 calibra->AnalyseLinearFittersAllTogether(fAliTRDCalibraVdriftLinearFit,vdriftoverall,exboverall);
615 //printf("Found mean vdrift %f and exb %f\n",vdriftoverall,exboverall);
616 if(fCalDetVdriftUsed && (vdriftoverall > 0.0) && (exboverall < 70.0)) {
54f2ff1c 617 AliTRDCalDet *calDetVdrift = new AliTRDCalDet(*fCalDetVdriftUsed);
840ec79d 618 AliTRDCalDet *calDetLorentz = new AliTRDCalDet(*fCalDetExBUsed);
619 Double_t oldmeanvdrift = fCalDetVdriftUsed->CalcMean(kFALSE);
620 Double_t oldmeanexb = fCalDetExBUsed->CalcMean(kFALSE);
54f2ff1c 621 //printf("oldmean %f\n",oldmean);
840ec79d 622 if((oldmeanvdrift > 0.0) && (oldmeanexb < 70.0)) {
54f2ff1c 623 //printf("Correction factor %f\n",vdriftoverall);
840ec79d 624 calDetVdrift->Multiply(vdriftoverall/oldmeanvdrift);
625 calDetLorentz->Multiply(exboverall/oldmeanexb);
54f2ff1c 626 //printf("newmean %f\n",calDetVdrift->CalcMean(kFALSE));
627 TH1F *coefDriftLinear = calDetVdrift->MakeHisto1DAsFunctionOfDet();
840ec79d 628 TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
54f2ff1c 629 // Put them in the array
630 fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
840ec79d 631 fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
54f2ff1c 632 fPlots->AddAt(coefDriftLinear,kVdriftLinear);
840ec79d 633 fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
54f2ff1c 634 //
635 ok = kTRUE;
82b413fd 636 fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsButFill;
54f2ff1c 637 }
82b413fd 638 else {
840ec79d 639 if(oldmeanvdrift) fStatusPos = fStatusPos | kVdriftErrorOld;
640 if(oldmeanexb) fStatusPos = fStatusPos | kExBErrorOld;
82b413fd 641 }
642 }
643 else {
840ec79d 644 if((vdriftoverall <= 0.0) && (exboverall > 70.0)) fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsNotFill;
82b413fd 645 if(!fCalDetVdriftUsed) fStatusPos = fStatusPos | kVdriftErrorOld;
840ec79d 646 if(!fCalDetExBUsed) fStatusPos = fStatusPos | kExBErrorOld;
54f2ff1c 647 }
54f2ff1c 648 }
b3fcfd96 649
650 calibra->ResetVectorFit();
651
652 return ok;
653
654}
00d203b6 655//________________________________________________________________________________________________________________
b3fcfd96 656
657Bool_t AliTRDPreprocessorOffline::AnalyzePRF(){
658 //
659 // Analyze PRF - produce the calibration objects
660 //
661
662 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
a2a4ec8e 663 calibra->SetMinEntries(fMinStatsPRF); // If there is less than 1000 entries in the histo: no fit
b3fcfd96 664 calibra->AnalysePRFMarianFit(fPRF2d);
665
666 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
667 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
668 Int_t nbfit = calibra->GetNumberFit();
669 Int_t nbE = calibra->GetNumberEnt();
670
671
672 Bool_t ok = kFALSE;
673 // enough statistics
674 if ((nbtg > 0) &&
675 (nbfit >= 0.95*nbE) && (nbE > 30)) {
676 // create the cal objects
677 TObjArray object = calibra->GetVectorFit();
678 AliTRDCalPad *calPadPRF = (AliTRDCalPad*) calibra->CreatePadObjectPRF(&object);
679 TH1F *coefPRF = calPadPRF->MakeHisto1D();
680 // Put them in the array
681 fCalibObjects->AddAt(calPadPRF,kPRF);
682 fPlots->AddAt(coefPRF,kPRF);
683 //
684 ok = kTRUE;
685 }
686
687 calibra->ResetVectorFit();
688
689 return ok;
690
691}
a5dcf618 692
693//_____________________________________________________________________________
694Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
695{
4c865c34 696 //
a5dcf618 697 // Produce AliTRDCalChamberStatus out of calibration results
4c865c34 698 //
b61b92a0 699
a5dcf618 700 // set up AliTRDCalChamberStatus
701 AliTRDCalChamberStatus *CalChamberStatus = new AliTRDCalChamberStatus();
702 for(Int_t det = 0; det < 540; det++) CalChamberStatus->SetStatus(det,1);
01239968 703
a5dcf618 704 // get calibration objects
705 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
706 AliTRDCalDet *calDetVDrift = (AliTRDCalDet *) fCalibObjects->At(kVdriftLinear);
840ec79d 707 AliTRDCalDet *calDetExB = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
a5dcf618 708
709 // Check
840ec79d 710 if((!calDetGain) || (!calDetVDrift) || (!fCH2d) || (!calDetExB)) return kFALSE;
a5dcf618 711
712 // Gain
713 Double_t gainmean = calDetGain->GetMean();
714 Double_t vdriftmean = calDetVDrift->GetMean();
840ec79d 715 Double_t exbmean = calDetExB->GetMean();
a5dcf618 716
717 Double_t gainrms = calDetGain->GetRMSRobust();
718 Double_t vdriftrms = calDetVDrift->GetRMSRobust();
840ec79d 719 Double_t exbrms = calDetExB->GetRMSRobust();
a5dcf618 720
721 //printf("Gain mean: %f, rms: %f\n",gainmean,gainrms);
722 //printf("Vdrift mean: %f, rms: %f\n",vdriftmean,vdriftrms);
840ec79d 723 //printf("ExB mean: %f, rms: %f\n",exbmean,exbrms);
724
a5dcf618 725 // Check
840ec79d 726 if((TMath::Abs(gainrms) < 0.001) || (TMath::Abs(vdriftrms) < 0.001) || (TMath::Abs(exbrms) < 0.0000001)) return kFALSE;
01239968 727
a5dcf618 728 // mask chambers with empty gain entries
729 //Int_t counter = 0;
730 for (Int_t idet = 0; idet < 540; idet++) {
01239968 731
a5dcf618 732 // ch2d
733 TH1I *projch = (TH1I *) fCH2d->ProjectionX("projch",idet+1,idet+1,(Option_t *)"e");
734 Double_t entries = projch->GetEntries();
4c865c34 735
a5dcf618 736 // gain
737 Double_t gain = calDetGain->GetValue(idet);
4c865c34 738
a5dcf618 739 // vdrift
740 Double_t vdrift = calDetVDrift->GetValue(idet);
4c865c34 741
840ec79d 742 // exb
743 Double_t exb = calDetExB->GetValue(idet);
744
4c865c34 745
a5dcf618 746 if(entries<=0.5 ||
747 TMath::Abs(gainmean-gain) > (15.0*gainrms) ||
840ec79d 748 TMath::Abs(vdriftmean-vdrift) > (15.0*vdriftrms) ||
749 TMath::Abs(exbmean-exb) > (50.0*exbrms)) {
a5dcf618 750
751 //printf(" chamber det %03d masked \n",idet);
752 //printf(" gainmean %f and gain %f, gainrms %f \n",gainmean,gain,gainrms);
753 //printf(" vdriftmean %f and vdrift %f, vdriftrms %f \n",vdriftmean,vdrift,vdriftrms);
840ec79d 754 //printf(" exbmean %f and exb %f, exbrms %f \n",exbmean,exb,exbrms);
755
a5dcf618 756 CalChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kMasked);
757 //counter++;
758 }
4c865c34 759
a5dcf618 760 /*
761 // installed supermodules+1 -> abort
762 if(counter > (7+1)*30) {
763 printf("ERROR: more than one SM to be masked!! \n Abort...\n");
764 if(projch) delete projch;
765 return 0x0;
766 }
767 */
4c865c34 768
b61b92a0 769 delete projch;
770
a5dcf618 771 }
b3fcfd96 772
a5dcf618 773 // Security
774 for(Int_t sm=0; sm < 18; sm++) {
775 Int_t counter = 0;
776 for(Int_t det = 0; det < 30; det++){
777 Int_t detector = sm*30+det;
778 if(CalChamberStatus->IsMasked(detector)) counter++;
779 }
780 if(counter >= 10) {
781 for(Int_t det = 0; det < 30; det++){
782 Int_t detector = sm*30+det;
783 CalChamberStatus->SetStatus(detector,AliTRDCalChamberStatus::kInstalled);
784 }
785 }
786 }
b3fcfd96 787
a5dcf618 788 fCalibObjects->AddAt(CalChamberStatus,kChamberStatus);
789 return kTRUE;
b3fcfd96 790
a5dcf618 791 }
b3fcfd96 792
b3fcfd96 793
a5dcf618 794 //________________________________________________________________________________________________
795 void AliTRDPreprocessorOffline::CorrectFromDetGainUsed() {
796 //
797 // Correct from the gas gain used afterwards
798 //
799 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
800 if(!calDetGain) return;
b3fcfd96 801
a5dcf618 802 // Calculate mean
803 Double_t mean = 0.0;
804 Int_t nbdet = 0;
b3fcfd96 805
a5dcf618 806 for(Int_t det = 0; det < 540; det++) {
00d203b6 807
a5dcf618 808 Float_t gaininit = fCalDetGainUsed->GetValue(det);
809 Float_t gainout = calDetGain->GetValue(det);
00d203b6 810
00d203b6 811
a5dcf618 812 if(TMath::Abs(gainout-1.0) > 0.000001) {
813 mean += (gaininit*gainout);
814 nbdet++;
815 }
816 }
817 if(nbdet > 0) mean = mean/nbdet;
00d203b6 818
a5dcf618 819 for(Int_t det = 0; det < 540; det++) {
00d203b6 820
a5dcf618 821 Float_t gaininit = fCalDetGainUsed->GetValue(det);
822 Float_t gainout = calDetGain->GetValue(det);
823
ba1aa7a7 824 if(TMath::Abs(gainout-1.0) > 0.000001) {
825 Double_t newgain = gaininit*gainout;
826 if(newgain < 0.1) newgain = 0.1;
58e2b572 827 if(newgain > 1.9) newgain = 1.9;
ba1aa7a7 828 calDetGain->SetValue(det,newgain);
829 }
830 else {
831 Double_t newgain = mean;
832 if(newgain < 0.1) newgain = 0.1;
58e2b572 833 if(newgain > 1.9) newgain = 1.9;
ba1aa7a7 834 calDetGain->SetValue(det,newgain);
835 }
a5dcf618 836 }
837
838
839 }
840 //________________________________________________________________________________________________
841 void AliTRDPreprocessorOffline::CorrectFromDetVdriftUsed() {
842 //
843 // Correct from the drift velocity
844 //
845
846 //printf("Correct for vdrift\n");
847
848 AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
849 if(!calDetGain) return;
850
851 Int_t detVdrift = kVdriftPHDet;
852 if(fMethodSecond) detVdrift = kVdriftLinear;
853 AliTRDCalDet *calDetVdrift = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
854 if(!calDetVdrift) return;
855
856 // Calculate mean
8dac2af1 857 if(!fNotEnoughStatisticsForTheVdriftLinear) {
54f2ff1c 858 for(Int_t det = 0; det < 540; det++) {
859
860 Float_t vdriftinit = fCalDetVdriftUsed->GetValue(det);
861 Float_t vdriftout = calDetVdrift->GetValue(det);
862
863 Float_t gain = calDetGain->GetValue(det);
864 if(vdriftout > 0.0) gain = gain*vdriftinit/vdriftout;
865 if(gain < 0.1) gain = 0.1;
866 if(gain > 1.9) gain = 1.9;
867 calDetGain->SetValue(det,gain);
868 }
a5dcf618 869 }
54f2ff1c 870 else {
871
872 Float_t vdriftinit = fCalDetVdriftUsed->CalcMean(kFALSE);
873 Float_t vdriftout = calDetVdrift->CalcMean(kFALSE);
874 Float_t factorcorrectif = 1.0;
875 if(vdriftout > 0.0) factorcorrectif = vdriftinit/vdriftout;
876 for(Int_t det = 0; det < 540; det++) {
877 Float_t gain = calDetGain->GetValue(det);
878 gain = gain*factorcorrectif;
879 if(gain < 0.1) gain = 0.1;
880 if(gain > 1.9) gain = 1.9;
881 calDetGain->SetValue(det,gain);
882 }
883
884 }
885
a5dcf618 886 }
54f2ff1c 887//_________________________________________________________________________________________________________________
a5dcf618 888 void AliTRDPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
889 //
890 // Update OCDB entry
891 //
892
893 AliCDBMetaData *metaData= new AliCDBMetaData();
894 metaData->SetObjectClassName("AliTRDCalDet");
895 metaData->SetResponsible("Raphaelle Bailhache");
896 metaData->SetBeamPeriod(1);
897
898 AliCDBId id1("TRD/Calib/ChamberGainFactor", startRunNumber, endRunNumber);
899 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
900 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
901 if(calDet) gStorage->Put(calDet, id1, metaData);
902
903
eec29d56 904 }
905 //___________________________________________________________________________________________________________________
906 void AliTRDPreprocessorOffline::UpdateOCDBExB(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
907 //
908 // Update OCDB entry
909 //
910
911 Int_t detExB = kLorentzLinear;
912 if(!fMethodSecond) return;
913
914 //printf("Pass\n");
915
916 AliCDBMetaData *metaData= new AliCDBMetaData();
917 metaData->SetObjectClassName("AliTRDCalDet");
918 metaData->SetResponsible("Raphaelle Bailhache");
919 metaData->SetBeamPeriod(1);
920
921 AliCDBId id1("TRD/Calib/ChamberExB", startRunNumber, endRunNumber);
922 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
923 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detExB);
924 if(calDet) gStorage->Put(calDet, id1, metaData);
925 //if(!calDet) printf("No caldet\n");
926
a5dcf618 927 }
928 //___________________________________________________________________________________________________________________
929 void AliTRDPreprocessorOffline::UpdateOCDBVdrift(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
930 //
931 // Update OCDB entry
932 //
933
934 Int_t detVdrift = kVdriftPHDet;
935
936 if(fMethodSecond) detVdrift = kVdriftLinear;
937
938 AliCDBMetaData *metaData= new AliCDBMetaData();
939 metaData->SetObjectClassName("AliTRDCalDet");
940 metaData->SetResponsible("Raphaelle Bailhache");
941 metaData->SetBeamPeriod(1);
942
943 AliCDBId id1("TRD/Calib/ChamberVdrift", startRunNumber, endRunNumber);
944 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
945 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
946 if(calDet) gStorage->Put(calDet, id1, metaData);
947
948 //
949
950 if(!fMethodSecond) {
951
952 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
953 metaDataPad->SetObjectClassName("AliTRDCalPad");
954 metaDataPad->SetResponsible("Raphaelle Bailhache");
955 metaDataPad->SetBeamPeriod(1);
956
957 AliCDBId id1Pad("TRD/Calib/LocalVdrift", startRunNumber, endRunNumber);
958 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
959 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
960
961 }
962
963 }
964 //________________________________________________________________________________________________________________________
965 void AliTRDPreprocessorOffline::UpdateOCDBT0(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
966 //
967 // Update OCDB entry
968 //
969
970 AliCDBMetaData *metaData= new AliCDBMetaData();
971 metaData->SetObjectClassName("AliTRDCalDet");
972 metaData->SetResponsible("Raphaelle Bailhache");
973 metaData->SetBeamPeriod(1);
974
975 AliCDBId id1("TRD/Calib/ChamberT0", startRunNumber, endRunNumber);
976 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
977 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
978 if(calDet) gStorage->Put(calDet, id1, metaData);
979
980 //
981
982 AliCDBMetaData *metaDataPad= new AliCDBMetaData();
983 metaDataPad->SetObjectClassName("AliTRDCalPad");
984 metaDataPad->SetResponsible("Raphaelle Bailhache");
985 metaDataPad->SetBeamPeriod(1);
986
987 AliCDBId id1Pad("TRD/Calib/LocalT0", startRunNumber, endRunNumber);
988 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
989 if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
990
991
992
993 }
994 //_________________________________________________________________________________________________________________
995 void AliTRDPreprocessorOffline::UpdateOCDBPRF(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
996 //
997 // Update OCDB entry
998 //
999
1000 AliCDBMetaData *metaData= new AliCDBMetaData();
1001 metaData->SetObjectClassName("AliTRDCalPad");
1002 metaData->SetResponsible("Raphaelle Bailhache");
1003 metaData->SetBeamPeriod(1);
1004
1005 AliCDBId id1("TRD/Calib/PRFWidth", startRunNumber, endRunNumber);
1006 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1007 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1008 if(calPad) gStorage->Put(calPad, id1, metaData);
1009
1010
1011 }
1012 //_________________________________________________________________________________________________________________
1013 void AliTRDPreprocessorOffline::UpdateOCDBChamberStatus(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1014 //
1015 // Update OCDB entry
1016 //
1017
1018 AliCDBMetaData *metaData= new AliCDBMetaData();
1019 metaData->SetObjectClassName("AliTRDCalChamberStatus");
1020 metaData->SetResponsible("Raphaelle Bailhache");
1021 metaData->SetBeamPeriod(1);
1022
1023 AliCDBId id1("TRD/Calib/ChamberStatus", startRunNumber, endRunNumber);
1024 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1025 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1026 if(calChamberStatus) gStorage->Put(calChamberStatus, id1, metaData);
1027
1028
1029 }
1030 //__________________________________________________________________________________________________________________________
54f2ff1c 1031 Bool_t AliTRDPreprocessorOffline::ValidateGain() {
a5dcf618 1032 //
1033 // Validate OCDB entry
1034 //
1035
1036 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
1037 if(calDet) {
1038 Double_t mean = calDet->GetMean();
1039 Double_t rms = calDet->GetRMSRobust();
1040 if((mean > 0.2) && (mean < 1.4) && (rms < 0.5)) return kTRUE;
1041 //if((mean > 0.2) && (mean < 1.4)) return kTRUE;
54f2ff1c 1042 else {
82b413fd 1043 fStatusPos = fStatusPos | kGainErrorRange;
54f2ff1c 1044 return kFALSE;
1045 }
a5dcf618 1046 }
1047 else return kFALSE;
54f2ff1c 1048
a5dcf618 1049
1050
1051 }
1052 //__________________________________________________________________________________________________________________________
1053 Bool_t AliTRDPreprocessorOffline::ValidateVdrift(){
1054 //
1055 // Update OCDB entry
1056 //
1057
1058 Int_t detVdrift = kVdriftPHDet;
1059 Bool_t ok = kTRUE;
1060
1061 if(fMethodSecond) detVdrift = kVdriftLinear;
1062
1063 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
1064 if(calDet) {
1065 Double_t mean = calDet->GetMean();
1066 Double_t rms = calDet->GetRMSRobust();
1067 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
54f2ff1c 1068 if(!((mean > 1.0) && (mean < 2.0) && (rms < 0.5))) {
82b413fd 1069 fStatusPos = fStatusPos | kVdriftErrorRange;
54f2ff1c 1070 ok = kFALSE;
1071 }
a5dcf618 1072 }
1073 else return kFALSE;
1074
1075 if(!fMethodSecond) {
1076 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
1077 if(calPad) {
1078 Double_t mean = calPad->GetMean();
1079 Double_t rms = calPad->GetRMS();
1080 //printf("Vdrift::meanpad %f, rmspad %f\n",mean,rms);
54f2ff1c 1081 if(!((mean > 0.9) && (mean < 1.1) && (rms < 0.6))) {
82b413fd 1082 fStatusPos = fStatusPos | kVdriftErrorRange;
54f2ff1c 1083 ok = kFALSE;
1084 }
a5dcf618 1085 }
1086 else return kFALSE;
1087 }
1088
1089 return ok;
1090
840ec79d 1091 }
1092 //__________________________________________________________________________________________________________________________
1093 Bool_t AliTRDPreprocessorOffline::ValidateExB(){
1094 //
1095 // Update OCDB entry
1096 //
1097
1098 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
1099 if(calDet) {
1100 Double_t mean = calDet->GetMean();
1101 Double_t rms = calDet->GetRMSRobust();
1102 //printf("Vdrift::mean %f, rms %f\n",mean,rms);
1103 if(!((mean > -1.0) && (mean < 1.0) && (rms < 0.5))) {
1104 fStatusNeg = fStatusNeg | kExBErrorRange;
1105 return kFALSE;
1106 }
1107 else return kTRUE;
1108 }
1109 else return kFALSE;
1110
a5dcf618 1111 }
1112 //__________________________________________________________________________________________________________________________
1113 Bool_t AliTRDPreprocessorOffline::ValidateT0(){
1114 //
1115 // Update OCDB entry
1116 //
1117
1118 AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
1119 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
1120 if(calDet && calPad) {
1121 Double_t meandet = calDet->GetMean();
1122 Double_t rmsdet = calDet->GetRMSRobust();
1123 Double_t meanpad = calPad->GetMean();
1124 //Double_t rmspad = calPad->GetRMS();
1125 //printf("T0::minimum %f, rmsdet %f,meanpad %f, rmspad %f\n",meandet,rmsdet,meanpad,rmspad);
1126 if((meandet > -1.5) && (meandet < 5.0) && (rmsdet < 4.0) && (meanpad < 5.0) && (meanpad > -0.5)) return kTRUE;
54f2ff1c 1127 else {
82b413fd 1128 fStatusPos = fStatusPos | kTimeOffsetErrorRange;
54f2ff1c 1129 return kFALSE;
1130 }
a5dcf618 1131 }
1132 else return kFALSE;
1133
1134 }
1135 //__________________________________________________________________________________________________________________________
1136 Bool_t AliTRDPreprocessorOffline::ValidatePRF() const{
1137 //
1138 // Update OCDB entry
1139 //
1140
1141 AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
1142 if(calPad) {
1143 Double_t meanpad = calPad->GetMean();
1144 Double_t rmspad = calPad->GetRMS();
1145 //printf("PRF::meanpad %f, rmspad %f\n",meanpad,rmspad);
1146 if((meanpad < 1.0) && (rmspad < 0.8)) return kTRUE;
1147 else return kFALSE;
1148 }
1149 else return kFALSE;
1150
1151
1152 }
1153 //__________________________________________________________________________________________________________________________
82b413fd 1154Bool_t AliTRDPreprocessorOffline::ValidateChamberStatus(){
00d203b6 1155 //
1156 // Update OCDB entry
1157 //
1158
a5dcf618 1159 AliTRDCalChamberStatus *calChamberStatus = (AliTRDCalChamberStatus *) fCalibObjects->At(kChamberStatus);
1160 if(calChamberStatus) {
1161 Int_t detectormasked = 0;
1162 for(Int_t det = 0; det < 540; det++) {
1163 if(calChamberStatus->IsMasked(det)) detectormasked++;
1164 }
1165 //printf("Number of chambers masked %d\n",detectormasked);
82b413fd 1166 if(detectormasked > 40) {
1167 fStatusPos = fStatusPos | kChamberStatusErrorRange;
1168 return kFALSE;
1169 }
a5dcf618 1170 else return kTRUE;
00d203b6 1171 }
1172 else return kFALSE;
1173
b3fcfd96 1174}
4c865c34 1175//_____________________________________________________________________________
1176Int_t AliTRDPreprocessorOffline::GetVersion(TString name) const
1177{
1178 //
1179 // Get version from the title
1180 //
1181
1182 // Some patterns
1183 const Char_t *version = "Ver";
1184 if(!strstr(name.Data(),version)) return -1;
f558cb62 1185 const Char_t *after = "Subver";
1186 if(!strstr(name.Data(),after)) return -1;
1187
4c865c34 1188 for(Int_t ver = 0; ver < 999999999; ver++) {
1189
1190 TString vertry(version);
1191 vertry += ver;
f558cb62 1192 vertry += after;
4c865c34 1193
1194 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1195
1196 if(strstr(name.Data(),vertry.Data())) return ver;
1197
1198 }
1199
1200 return -1;
1201
1202}
1203
1204//_____________________________________________________________________________
1205Int_t AliTRDPreprocessorOffline::GetSubVersion(TString name) const
1206{
1207 //
1208 // Get subversion from the title
1209 //
1210
1211 // Some patterns
1212 const Char_t *subversion = "Subver";
1213 if(!strstr(name.Data(),subversion)) return -1;
f558cb62 1214 const Char_t *after = "FirstRun";
1215 if(!strstr(name.Data(),after)) {
1216 after = "Nz";
1217 }
1218 if(!strstr(name.Data(),after)) return -1;
1219
4c865c34 1220
1221 for(Int_t ver = 0; ver < 999999999; ver++) {
1222
1223 TString vertry(subversion);
1224 vertry += ver;
f558cb62 1225 vertry += after;
ca7e6e64 1226
1227 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1228
1229 if(strstr(name.Data(),vertry.Data())) return ver;
1230
1231 }
1232
1233 return -1;
1234
1235}
1236
1237//_____________________________________________________________________________
1238Int_t AliTRDPreprocessorOffline::GetFirstRun(TString name) const
1239{
1240 //
1241 // Get first run from the title
1242 //
1243
1244 // Some patterns
1245 const Char_t *firstrun = "FirstRun";
1246 if(!strstr(name.Data(),firstrun)) return -1;
f558cb62 1247 const Char_t *after = "Nz";
1248 if(!strstr(name.Data(),after)) return -1;
1249
ca7e6e64 1250
1251 for(Int_t ver = 0; ver < 999999999; ver++) {
1252
1253 TString vertry(firstrun);
1254 vertry += ver;
f558cb62 1255 vertry += after;
4c865c34 1256
1257 //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
1258
1259 if(strstr(name.Data(),vertry.Data())) return ver;
1260
1261 }
1262
1263 return -1;
1264
1265}
82b413fd 1266//_____________________________________________________________________________
1267Bool_t AliTRDPreprocessorOffline::CheckStatus(Int_t status, Int_t bitMask) const
1268{
1269 //
1270 // Checks the status
1271 //
1272
1273 return (status & bitMask) ? kTRUE : kFALSE;
1274
1275}
1276//_____________________________________________________________________________
1277Int_t AliTRDPreprocessorOffline::GetStatus() const
1278{
1279 //
1280 // Checks the status
1281 // fStatusPos: errors
1282 // fStatusNeg: only info
1283 //
1284
1285 if(fStatusPos > 0) return fStatusPos;
1286 else return (-TMath::Abs(fStatusNeg));
1287
1288}
1289//_____________________________________________________________________________
1290void AliTRDPreprocessorOffline::PrintStatus() const
1291{
1292 //
1293 // Do Summary
1294 //
1295
1296 AliInfo(Form("The error status is %d",fStatusPos));
1297 AliInfo(Form("IsGainErrorOld? %d",(Int_t)IsGainErrorOld()));
1298 AliInfo(Form("IsVdriftErrorOld? %d",(Int_t)IsVdriftErrorOld()));
1299 AliInfo(Form("IsGainErrorRange? %d",(Int_t)IsGainErrorRange()));
1300 AliInfo(Form("IsVdriftErrorRange? %d",(Int_t)IsVdriftErrorRange()));
1301 AliInfo(Form("IsTimeOffsetErrorRange? %d",(Int_t)IsTimeOffsetErrorRange()));
1302 AliInfo(Form("IsChamberStatusErrorRange? %d",(Int_t)IsChamberStatusErrorRange()));
1303
1304
1305 AliInfo(Form("The info status is %d",fStatusNeg));
1306 AliInfo(Form("IsGainNotEnoughStatsButFill? %d",(Int_t)IsGainNotEnoughStatsButFill()));
1307 AliInfo(Form("IsVdriftNotEnoughStatsButFill? %d",(Int_t)IsVdriftNotEnoughStatsButFill()));
1308 AliInfo(Form("IsGainNotEnoughStatsNotFill? %d",(Int_t)IsGainNotEnoughStatsNotFill()));
1309 AliInfo(Form("IsVdriftNotEnoughStatsNotFill? %d",(Int_t)IsVdriftNotEnoughStatsNotFill()));
1310 AliInfo(Form("IsTimeOffsetNotEnoughStatsNotFill? %d",(Int_t)IsTimeOffsetNotEnoughStatsNotFill()));
840ec79d 1311
1312 AliInfo(Form("IsExBErrorRange? %d",(Int_t)IsExBErrorRange()));
1313 AliInfo(Form("IsExBErrorOld? %d",(Int_t)IsExBErrorOld()));
82b413fd 1314
1315}
840ec79d 1316//___________________________________________________________________________________
1317void AliTRDPreprocessorOffline::SetCalDetVdrift(AliTRDCalDet *calDetVdriftUsed)
1318{
1319
1320 fCalDetVdriftUsed = calDetVdriftUsed;
1321
1322 fCalDetExBUsed = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
1323 for(Int_t k = 0; k < 540; k++){
1324 fCalDetExBUsed->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDetVdriftUsed->GetValue(k)));
1325 //printf("Set the exb object for detector %d, vdrift %f and exb %f\n",k,fCalDetVdriftUsed->GetValue(k),fCalDetExBUsed->GetValue(k));
1326 }
1327
1328};
82b413fd 1329
01239968 1330