]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDPreprocessorOffline.cxx
b33b5ccfeca976ba2fbbee9bf678d854243398cf
[u/mrichter/AliRoot.git] / TRD / AliTRDPreprocessorOffline.cxx
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 /*
19   Responsible: Raphaelle Bailhache (rbailhache@ikf.uni-frankfurt.de) 
20   Code to analyze the TRD calibration and to produce OCDB entries  
21
22
23    .x ~/rootlogon.C
24    gSystem->Load("libANALYSIS");
25    gSystem->Load("libTRDcalib");
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 */
39 #include "AliLog.h"
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"
49 #include "TMath.h"
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"
61 #include "AliTRDCalChamberStatus.h"
62 #include "AliTRDCommonParam.h"
63
64
65 ClassImp(AliTRDPreprocessorOffline)
66
67   AliTRDPreprocessorOffline::AliTRDPreprocessorOffline():
68   TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
69   fMethodSecond(kTRUE),
70   fNameList("TRDCalib"),
71   fCalDetGainUsed(0x0),
72   fCalDetVdriftUsed(0x0),
73   fCalDetExBUsed(0x0),
74   fCH2d(0x0),
75   fPH2d(0x0),
76   fPRF2d(0x0),
77   fAliTRDCalibraVdriftLinearFit(0x0),
78   fNEvents(0x0),
79   fAbsoluteGain(0x0),
80   fPlots(new TObjArray(9)),
81   fCalibObjects(new TObjArray(9)),
82   fVersionGainUsed(0),
83   fSubVersionGainUsed(0),
84   fFirstRunVdriftUsed(0),
85   fVersionVdriftUsed(0), 
86   fSubVersionVdriftUsed(0),
87   fSwitchOnValidation(kTRUE),
88   fVdriftValidated(kFALSE),
89   fExBValidated(kFALSE),
90   fT0Validated(kFALSE),
91   fMinStatsVdriftT0PH(800*20),
92   fMinStatsVdriftLinear(800),
93   fMinStatsGain(800),
94   fMinStatsPRF(600),
95   fBackCorrectGain(kFALSE),  
96   fBackCorrectVdrift(kTRUE),
97   fNotEnoughStatisticsForTheGain(kFALSE),
98   fNotEnoughStatisticsForTheVdriftLinear(kFALSE),
99   fStatusNeg(0),
100   fStatusPos(0)
101 {
102   //
103   // default constructor
104   //
105 }
106 //_________________________________________________________________________________________________________________
107 AliTRDPreprocessorOffline::~AliTRDPreprocessorOffline() {
108   //
109   // Destructor
110   //
111
112   if(fCalDetGainUsed) delete fCalDetGainUsed;
113   if(fCalDetVdriftUsed) delete fCalDetVdriftUsed;
114   if(fCalDetExBUsed) delete fCalDetExBUsed;
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 }
125 //___________________________________________________________________________________________________________________
126
127 void 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   //
139   fVdriftValidated = kTRUE;
140   fT0Validated = kTRUE;
141   fExBValidated = kTRUE;
142   fNotEnoughStatisticsForTheVdriftLinear = kFALSE;
143   //
144   // 2. extraction of the information
145   //
146   if(ReadVdriftLinearFitGlobal(file) && fCalDetVdriftUsed && fCalDetExBUsed) AnalyzeVdriftLinearFit();
147   if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
148   //
149   // 3. Append QA plots
150   //
151   //MakeDefaultPlots(fVdriftArray,fVdriftArray);
152   //
153   //
154   // 4. validate OCDB entries
155   //
156   if(fSwitchOnValidation==kTRUE && ValidateVdrift()==kFALSE) { 
157     //AliError("TRD vdrift OCDB parameters out of range!");
158     fVdriftValidated = kFALSE;
159   }
160   if(fSwitchOnValidation==kTRUE && ValidateT0()==kFALSE) { 
161     //AliError("TRD t0 OCDB parameters out of range!");
162     fT0Validated = kFALSE;
163   }
164   if(fSwitchOnValidation==kTRUE && ValidateExB()==kFALSE) { 
165     //AliError("TRD t0 OCDB parameters out of range!");
166     fExBValidated = kFALSE;
167   }
168   //
169   // 5. update of OCDB
170   //
171   //
172   if(fVdriftValidated) UpdateOCDBVdrift(startRunNumber,endRunNumber,ocdbStorage);
173   if(fT0Validated) UpdateOCDBT0(startRunNumber,endRunNumber,ocdbStorage);
174   if(fExBValidated) UpdateOCDBExB(startRunNumber,endRunNumber,ocdbStorage);
175   
176 }
177 //_________________________________________________________________________________________________________________
178
179 void 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   //
189   fNotEnoughStatisticsForTheGain = kFALSE;
190   //
191   // 1. Initialization 
192   if(!ReadGainGlobal(file)) return;
193   //
194   //
195   // 2. extraction of the information
196   //
197   AnalyzeGain();
198   if(fBackCorrectGain) CorrectFromDetGainUsed();
199   if(fBackCorrectVdrift) CorrectFromDetVdriftUsed();
200   //
201   // 3. Append QA plots
202   //
203   //MakeDefaultPlots(fVdriftArray,fVdriftArray);
204   //
205   //
206   // 4. validate OCDB entries
207   //
208   if(fSwitchOnValidation==kTRUE && ValidateGain()==kFALSE) { 
209     //AliError("TRD gain OCDB parameters out of range!");
210     return;
211   }
212   //
213   // 5. update of OCDB
214   //
215   //
216   if((!fCalDetVdriftUsed) || (fCalDetVdriftUsed && fVdriftValidated)) UpdateOCDBGain(startRunNumber,endRunNumber,ocdbStorage);
217   
218   
219 }
220 //________________________________________________________________________________________________________________
221
222 void 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   //
245   //
246   // 4. validate OCDB entries
247   //
248   if(fSwitchOnValidation==kTRUE && ValidatePRF()==kFALSE) { 
249     //AliError("TRD prf OCDB parameters out of range!");
250     return;
251   }
252   //
253   // 5. update of OCDB
254   //
255   //
256   UpdateOCDBPRF(startRunNumber,endRunNumber,ocdbStorage);
257   
258 }
259 //________________________________________________________________________________________________________________
260
261 void 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) { 
284     //AliError("TRD Chamber status OCDB parameters not ok!");
285     return;
286   }
287   //
288   // 5. update of OCDB
289   //
290   //
291   if((!fNotEnoughStatisticsForTheGain) && (!fNotEnoughStatisticsForTheGain)) UpdateOCDBChamberStatus(startRunNumber,endRunNumber,ocdbStorage);
292   
293 }
294 //______________________________________________________________________________________________________
295 Bool_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();
303     fFirstRunVdriftUsed = GetFirstRun(nameph); 
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    
321   if(fVersionVdriftUsed == 0) fStatusPos = fStatusPos |kVdriftErrorOld;
322   if(fVersionGainUsed == 0) fStatusPos = fStatusPos | kGainErrorOld;
323  
324   return kTRUE;
325   
326 }
327 //___________________________________________________________________________________________________________________
328
329 Bool_t AliTRDPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
330   //
331   // read calibration entries from file
332   // 
333   if(fCH2d) return kTRUE;
334   TFile fcalib(fileName);
335   TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
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 }
355 //_________________________________________________________________________________________________________________
356
357 Bool_t AliTRDPreprocessorOffline::ReadVdriftT0Global(const Char_t* fileName){
358   //
359   // read calibration entries from file
360   // 
361   if(fPH2d) return kTRUE;
362   TFile fcalib(fileName);
363   TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
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 }
381 //___________________________________________________________________________________________________________________
382
383 Bool_t AliTRDPreprocessorOffline::ReadVdriftLinearFitGlobal(const Char_t* fileName){
384   //
385   // read calibration entries from file
386   // 
387   if(fAliTRDCalibraVdriftLinearFit) return kTRUE;
388   TFile fcalib(fileName);
389   TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
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 }
404 //_____________________________________________________________________________________________________________
405
406 Bool_t AliTRDPreprocessorOffline::ReadPRFGlobal(const Char_t* fileName){
407   //
408   // read calibration entries from file
409   // 
410   if(fPRF2d) return kTRUE;
411   TFile fcalib(fileName);
412   TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
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 }
430 //__________________________________________________________________________________________________________
431
432 Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
433   //
434   // Analyze gain - produce the calibration objects
435   //
436
437   AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
438   calibra->SetMinEntries(fMinStatsGain); // If there is less than 1000 entries in the histo: no fit
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;
448   Bool_t meanother = kFALSE;
449   // enough statistics
450   if ((nbtg >                  0) && 
451       (nbfit        >= 0.5*nbE) && (nbE > 30)) {
452     // create the cal objects
453     if(!fBackCorrectGain) {
454       calibra->PutMeanValueOtherVectorFit(1,kTRUE);
455       meanother = kTRUE;
456     }
457     TObjArray object           = calibra->GetVectorFit();
458     AliTRDCalDet *calDetGain   = calibra->CreateDetObjectGain(&object,meanother);
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   }
466   else {
467     fNotEnoughStatisticsForTheGain = kTRUE;
468     Int_t minStatsGain = fMinStatsGain*30;
469     calibra->SetMinEntries(minStatsGain); // Because we do it for all, we increase this
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;
485         fStatusNeg = fStatusNeg | kGainNotEnoughStatsButFill;
486       }
487       else {
488         fStatusPos = fStatusPos | kGainErrorOld;
489       }      
490     }
491     else {
492       if(gainoverallnotnormalized <= 0.0) fStatusNeg = fStatusNeg | kGainNotEnoughStatsNotFill;
493       if(!fCalDetGainUsed) fStatusPos = fStatusPos | kGainErrorOld;
494     }
495   }
496   
497   calibra->ResetVectorFit();
498   
499   return ok;
500   
501 }
502 //_____________________________________________________________________________________________________
503 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftT0(){
504   //
505   // Analyze VdriftT0 - produce the calibration objects
506   //
507
508   AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
509   calibra->SetMinEntries(fMinStatsVdriftT0PH); // If there is less than 1000 entries in the histo: no fit
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
525     calibra->RemoveOutliers(1,kFALSE);
526     calibra->PutMeanValueOtherVectorFit(1,kFALSE);
527     calibra->RemoveOutliers2(kFALSE);
528     calibra->PutMeanValueOtherVectorFit2(1,kFALSE);
529     //
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   }
552   else {
553     //printf("Not enough stats timeoffset\n");
554     fStatusNeg = fStatusNeg | kTimeOffsetNotEnoughStatsNotFill;
555   }
556   calibra->ResetVectorFit();
557  
558   return ok;
559   
560 }
561 //____________________________________________________________________________________________________________________
562 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftLinearFit(){
563   //
564   // Analyze vdrift linear fit - produce the calibration objects
565   //
566
567   //printf("Analyse linear fit\n");
568
569   
570   AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
571   calibra->SetCalDetVdriftExB(fCalDetVdriftUsed,fCalDetExBUsed);
572   calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
573   //printf("Fill PE Array\n");
574   fAliTRDCalibraVdriftLinearFit->FillPEArray();
575   //printf("AliTRDCalibraFit\n");
576   calibra->AnalyseLinearFitters(fAliTRDCalibraVdriftLinearFit);
577   //printf("After\n");
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
588     //calibra->RemoveOutliers(1,kTRUE);
589     calibra->PutMeanValueOtherVectorFit(1,kTRUE);
590     //calibra->RemoveOutliers2(kTRUE);
591     calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
592     //
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();
599     //if(!calDetLorentz) printf("No lorentz created\n");
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   }
608   else {
609     fNotEnoughStatisticsForTheVdriftLinear = kTRUE;
610     Int_t minNumberOfEntriesForAll = fMinStatsVdriftLinear*30;
611     calibra->SetMinEntries(minNumberOfEntriesForAll); // Because we do it for all, we increase this
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)) {
617       AliTRDCalDet *calDetVdrift = new AliTRDCalDet(*fCalDetVdriftUsed);
618       AliTRDCalDet *calDetLorentz = new AliTRDCalDet(*fCalDetExBUsed);
619       Double_t oldmeanvdrift = fCalDetVdriftUsed->CalcMean(kFALSE);
620       Double_t oldmeanexb = fCalDetExBUsed->CalcMean(kFALSE);
621       //printf("oldmean %f\n",oldmean);
622       if((oldmeanvdrift > 0.0) && (oldmeanexb < 70.0))  {
623         //printf("Correction factor %f\n",vdriftoverall);
624         calDetVdrift->Multiply(vdriftoverall/oldmeanvdrift);
625         calDetLorentz->Multiply(exboverall/oldmeanexb);
626         //printf("newmean %f\n",calDetVdrift->CalcMean(kFALSE));
627         TH1F *coefDriftLinear  = calDetVdrift->MakeHisto1DAsFunctionOfDet();
628         TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
629         // Put them in the array
630         fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
631         fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
632         fPlots->AddAt(coefDriftLinear,kVdriftLinear);
633         fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
634         // 
635         ok = kTRUE;
636         fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsButFill;
637       }
638       else {
639         if(oldmeanvdrift) fStatusPos = fStatusPos | kVdriftErrorOld;
640         if(oldmeanexb) fStatusPos = fStatusPos | kExBErrorOld;
641       }      
642     }
643     else {
644       if((vdriftoverall <= 0.0) && (exboverall > 70.0)) fStatusNeg = fStatusNeg | kVdriftNotEnoughStatsNotFill;
645       if(!fCalDetVdriftUsed) fStatusPos = fStatusPos | kVdriftErrorOld;
646       if(!fCalDetExBUsed) fStatusPos = fStatusPos | kExBErrorOld;
647     }
648   }
649   
650   calibra->ResetVectorFit();
651   
652   return ok;
653   
654 }
655 //________________________________________________________________________________________________________________
656
657 Bool_t AliTRDPreprocessorOffline::AnalyzePRF(){
658   //
659   // Analyze PRF - produce the calibration objects
660   //
661
662   AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
663   calibra->SetMinEntries(fMinStatsPRF); // If there is less than 1000 entries in the histo: no fit
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 }
692
693 //_____________________________________________________________________________
694 Bool_t AliTRDPreprocessorOffline::AnalyzeChamberStatus()
695 {
696   //
697   // Produce AliTRDCalChamberStatus out of calibration results
698   //
699   
700   // set up AliTRDCalChamberStatus
701   AliTRDCalChamberStatus *CalChamberStatus = new AliTRDCalChamberStatus();
702   for(Int_t det = 0; det < 540; det++) CalChamberStatus->SetStatus(det,1);
703
704   // get calibration objects
705   AliTRDCalDet *calDetGain   = (AliTRDCalDet *) fCalibObjects->At(kGain);
706   AliTRDCalDet *calDetVDrift = (AliTRDCalDet *) fCalibObjects->At(kVdriftLinear);
707   AliTRDCalDet *calDetExB    = (AliTRDCalDet *) fCalibObjects->At(kLorentzLinear);
708
709   // Check
710   if((!calDetGain) || (!calDetVDrift) || (!fCH2d) || (!calDetExB)) return kFALSE;
711
712   // Gain
713   Double_t gainmean = calDetGain->GetMean();
714   Double_t vdriftmean = calDetVDrift->GetMean();
715   Double_t exbmean = calDetExB->GetMean();
716
717   Double_t gainrms = calDetGain->GetRMSRobust();
718   Double_t vdriftrms = calDetVDrift->GetRMSRobust();
719   Double_t exbrms = calDetExB->GetRMSRobust();
720
721   //printf("Gain mean: %f, rms: %f\n",gainmean,gainrms);
722   //printf("Vdrift mean: %f, rms: %f\n",vdriftmean,vdriftrms);
723   //printf("ExB mean: %f, rms: %f\n",exbmean,exbrms);
724
725   // Check
726   if((TMath::Abs(gainrms) < 0.001) || (TMath::Abs(vdriftrms) < 0.001) || (TMath::Abs(exbrms) < 0.0000001)) return kFALSE;
727
728   // mask chambers with empty gain entries
729   //Int_t counter = 0;
730   for (Int_t idet = 0; idet < 540; idet++) {
731
732     // ch2d
733     TH1I *projch =  (TH1I *) fCH2d->ProjectionX("projch",idet+1,idet+1,(Option_t *)"e");
734     Double_t entries = projch->GetEntries();
735
736     // gain
737     Double_t gain = calDetGain->GetValue(idet);
738
739     // vdrift
740     Double_t vdrift = calDetVDrift->GetValue(idet);
741
742     // exb
743     Double_t exb = calDetExB->GetValue(idet);
744
745
746     if(entries<=0.5 ||
747        TMath::Abs(gainmean-gain) > (15.0*gainrms) ||
748        TMath::Abs(vdriftmean-vdrift) > (15.0*vdriftrms) ||
749        TMath::Abs(exbmean-exb) > (50.0*exbrms)) {
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);
754       //printf(" exbmean %f and exb %f, exbrms %f \n",exbmean,exb,exbrms);
755       
756       CalChamberStatus->SetStatus(idet,AliTRDCalChamberStatus::kMasked);
757       //counter++;
758     }
759
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      */
768
769     delete projch;
770     
771    }
772
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    }
787
788    fCalibObjects->AddAt(CalChamberStatus,kChamberStatus);
789    return kTRUE;
790
791  }
792
793
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;
801
802    // Calculate mean
803    Double_t mean = 0.0;
804    Int_t nbdet = 0;
805
806    for(Int_t det = 0; det < 540; det++) {
807
808      Float_t gaininit = fCalDetGainUsed->GetValue(det);
809      Float_t gainout = calDetGain->GetValue(det);
810
811
812      if(TMath::Abs(gainout-1.0) > 0.000001) {
813        mean += (gaininit*gainout);
814        nbdet++;
815      }  
816    }
817    if(nbdet > 0) mean = mean/nbdet;
818
819    for(Int_t det = 0; det < 540; det++) {
820
821      Float_t gaininit = fCalDetGainUsed->GetValue(det);
822      Float_t gainout = calDetGain->GetValue(det);
823
824      if(TMath::Abs(gainout-1.0) > 0.000001) {
825        Double_t newgain = gaininit*gainout;
826        if(newgain < 0.1) newgain = 0.1;
827        if(newgain > 1.9) newgain = 1.9;
828        calDetGain->SetValue(det,newgain);
829      }
830      else {
831        Double_t newgain = mean;
832        if(newgain < 0.1) newgain = 0.1;
833        if(newgain > 1.9) newgain = 1.9;
834        calDetGain->SetValue(det,newgain);
835      }
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
857    if(!fNotEnoughStatisticsForTheVdriftLinear) {
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      }
869    }
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    
886  }
887 //_________________________________________________________________________________________________________________
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
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
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  //__________________________________________________________________________________________________________________________
1031  Bool_t AliTRDPreprocessorOffline::ValidateGain() {
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;
1042      else {
1043        fStatusPos = fStatusPos | kGainErrorRange;
1044        return kFALSE;
1045      }
1046    }
1047    else return kFALSE;
1048    
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);
1068      if(!((mean > 1.0) && (mean < 2.0) && (rms < 0.5))) {
1069        fStatusPos = fStatusPos | kVdriftErrorRange;
1070        ok = kFALSE;
1071      }
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);
1081        if(!((mean > 0.9) && (mean < 1.1) && (rms < 0.6))) {
1082          fStatusPos = fStatusPos | kVdriftErrorRange;
1083          ok = kFALSE;
1084        }
1085      }
1086      else return kFALSE;
1087    }
1088
1089    return ok;
1090
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    
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;
1127      else {
1128        fStatusPos = fStatusPos | kTimeOffsetErrorRange;
1129        return kFALSE;
1130      }
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  //__________________________________________________________________________________________________________________________
1154 Bool_t AliTRDPreprocessorOffline::ValidateChamberStatus(){
1155   //
1156   // Update OCDB entry
1157   //
1158   
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);
1166     if(detectormasked > 40) {
1167       fStatusPos = fStatusPos | kChamberStatusErrorRange;
1168       return kFALSE;
1169     }
1170     else return kTRUE;
1171   }
1172   else return kFALSE;
1173  
1174 }
1175 //_____________________________________________________________________________
1176 Int_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;
1185   const Char_t *after = "Subver";  
1186   if(!strstr(name.Data(),after)) return -1;
1187
1188   for(Int_t ver = 0; ver < 999999999; ver++) {
1189
1190     TString vertry(version);
1191     vertry += ver;
1192     vertry += after;
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 //_____________________________________________________________________________
1205 Int_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;
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
1220   
1221   for(Int_t ver = 0; ver < 999999999; ver++) {
1222     
1223     TString vertry(subversion);
1224     vertry += ver;
1225     vertry += after;
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 //_____________________________________________________________________________
1238 Int_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;
1247   const Char_t *after = "Nz";  
1248   if(!strstr(name.Data(),after)) return -1;
1249   
1250   
1251   for(Int_t ver = 0; ver < 999999999; ver++) {
1252
1253     TString vertry(firstrun);
1254     vertry += ver;
1255     vertry += after;
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 }
1266 //_____________________________________________________________________________
1267 Bool_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 //_____________________________________________________________________________
1277 Int_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 //_____________________________________________________________________________
1290 void 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()));
1311
1312   AliInfo(Form("IsExBErrorRange? %d",(Int_t)IsExBErrorRange()));
1313   AliInfo(Form("IsExBErrorOld? %d",(Int_t)IsExBErrorOld()));
1314   
1315 }
1316 //___________________________________________________________________________________
1317 void 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 };
1329
1330