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