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