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