]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDPreprocessorOffline.cxx
Fix compiler warning (Julian)
[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 "TProfile2D.h"
50 #include "AliTRDCalDet.h"
51 #include "AliTRDCalPad.h"
52 #include "AliCDBMetaData.h"
53 #include "AliCDBId.h"
54 #include "AliCDBManager.h"
55 #include "AliCDBStorage.h"
56 #include "AliTRDCalibraMode.h"
57 #include "AliTRDCalibraFit.h"
58 #include "AliTRDCalibraVdriftLinearFit.h"
59 #include "AliTRDPreprocessorOffline.h"
60 #include "AliTRDCalChamberStatus.h"
61
62
63 ClassImp(AliTRDPreprocessorOffline)
64
65 AliTRDPreprocessorOffline::AliTRDPreprocessorOffline():
66   TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
67   fMethodSecond(kTRUE),
68   fNameList("TRDCalib"),
69   fCalDetGainUsed(0x0),
70   fCalDetVdriftUsed(0x0),
71   fCH2d(0x0),
72   fPH2d(0x0),
73   fPRF2d(0x0),
74   fAliTRDCalibraVdriftLinearFit(0x0),
75   fNEvents(0x0),
76   fAbsoluteGain(0x0),
77   fPlots(new TObjArray(8)),
78   fCalibObjects(new TObjArray(8)),
79   fVersionGainUsed(0),
80   fSubVersionGainUsed(0),
81   fVersionVdriftUsed(0), 
82   fSubVersionVdriftUsed(0),
83   fSwitchOnValidation(kTRUE),
84   fVdriftValidated(kFALSE),
85   fT0Validated(kFALSE),
86   fMinStatsVdriftT0PH(800*20),
87   fMinStatsVdriftLinear(800),
88   fMinStatsGain(800),
89   fMinStatsPRF(600)
90 {
91   //
92   // default constructor
93   //
94 }
95 //_________________________________________________________________________________________________________________
96 AliTRDPreprocessorOffline::~AliTRDPreprocessorOffline() {
97   //
98   // Destructor
99   //
100
101   if(fCalDetGainUsed) delete fCalDetGainUsed;
102   if(fCalDetVdriftUsed) delete fCalDetVdriftUsed;
103   if(fCH2d) delete fCH2d;
104   if(fPH2d) delete fPH2d;
105   if(fPRF2d) delete fPRF2d;
106   if(fAliTRDCalibraVdriftLinearFit) delete fAliTRDCalibraVdriftLinearFit;
107   if(fNEvents) delete fNEvents;
108   if(fAbsoluteGain) delete fAbsoluteGain;
109   if(fPlots) delete fPlots;
110   if(fCalibObjects) delete fCalibObjects;
111   
112 }
113 //___________________________________________________________________________________________________________________
114
115 void AliTRDPreprocessorOffline::CalibVdriftT0(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
116   //
117   // make calibration of the drift velocity
118   // Input parameters:
119   //      file                             - the location of input file
120   //      startRunNumber, endRunNumber     - run validity period 
121   //      ocdbStorage                      - path to the OCDB storage
122   //                                       - if empty - local storage 'pwd' uesed
123   if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
124   //
125   // 1. Initialization 
126   //
127   fVdriftValidated = kTRUE;
128   fT0Validated = kTRUE;
129   //
130   // 2. extraction of the information
131   //
132   if(ReadVdriftT0Global(file)) AnalyzeVdriftT0();
133   if(ReadVdriftLinearFitGlobal(file)) AnalyzeVdriftLinearFit();
134   //
135   // 3. Append QA plots
136   //
137   //MakeDefaultPlots(fVdriftArray,fVdriftArray);
138   //
139   //
140   // 4. validate OCDB entries
141   //
142   if(fSwitchOnValidation==kTRUE && ValidateVdrift()==kFALSE) { 
143     AliError("TRD vdrift OCDB parameters out of range!");
144     fVdriftValidated = kFALSE;
145   }
146   if(fSwitchOnValidation==kTRUE && ValidateT0()==kFALSE) { 
147     AliError("TRD t0 OCDB parameters out of range!");
148     fT0Validated = kFALSE;
149   }
150   //
151   // 5. update of OCDB
152   //
153   //
154   if(fVdriftValidated) UpdateOCDBVdrift(startRunNumber,endRunNumber,ocdbStorage);
155   if(fT0Validated) UpdateOCDBT0(startRunNumber,endRunNumber,ocdbStorage);
156   
157 }
158 //_________________________________________________________________________________________________________________
159
160 void AliTRDPreprocessorOffline::CalibGain(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
161   //
162   // make calibration of the drift velocity
163   // Input parameters:
164   //      file                             - the location of input file
165   //      startRunNumber, endRunNumber     - run validity period 
166   //      ocdbStorage                      - path to the OCDB storage
167   //                                       - if empty - local storage 'pwd' uesed
168   if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
169   //
170   // 1. Initialization 
171   if(!ReadGainGlobal(file)) return;
172   //
173   //
174   // 2. extraction of the information
175   //
176   AnalyzeGain();
177   if(fCalDetGainUsed) CorrectFromDetGainUsed();
178   if(fCalDetVdriftUsed) CorrectFromDetVdriftUsed();
179   //
180   // 3. Append QA plots
181   //
182   //MakeDefaultPlots(fVdriftArray,fVdriftArray);
183   //
184   //
185   // 4. validate OCDB entries
186   //
187   if(fSwitchOnValidation==kTRUE && ValidateGain()==kFALSE) { 
188     AliError("TRD gain OCDB parameters out of range!");
189     return;
190   }
191   //
192   // 5. update of OCDB
193   //
194   //
195   if((!fCalDetVdriftUsed) || (fCalDetVdriftUsed && fVdriftValidated)) UpdateOCDBGain(startRunNumber,endRunNumber,ocdbStorage);
196   
197   
198 }
199 //________________________________________________________________________________________________________________
200
201 void AliTRDPreprocessorOffline::CalibPRF(const Char_t* file, Int_t startRunNumber, Int_t endRunNumber, TString ocdbStorage){
202   //
203   // make calibration of the drift velocity
204   // Input parameters:
205   //      file                             - the location of input file
206   //      startRunNumber, endRunNumber     - run validity period 
207   //      ocdbStorage                      - path to the OCDB storage
208   //                                       - if empty - local storage 'pwd' uesed
209   if (ocdbStorage.Length()<=0) ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
210   //
211   // 1. Initialization 
212   if(!ReadPRFGlobal(file)) return;
213   //
214   //
215   // 2. extraction of the information
216   //
217   AnalyzePRF();
218   //
219   // 3. Append QA plots
220   //
221   //MakeDefaultPlots(fVdriftArray,fVdriftArray);
222   //
223   //
224   //
225   // 4. validate OCDB entries
226   //
227   if(fSwitchOnValidation==kTRUE && ValidatePRF()==kFALSE) { 
228     AliError("TRD prf OCDB parameters out of range!");
229     return;
230   }
231   //
232   // 5. update of OCDB
233   //
234   //
235   UpdateOCDBPRF(startRunNumber,endRunNumber,ocdbStorage);
236   
237 }
238 //______________________________________________________________________________________________________
239 Bool_t AliTRDPreprocessorOffline::Init(const Char_t* fileName){
240   //
241   // read the calibration used during the reconstruction
242   // 
243
244   if(ReadVdriftT0Global(fileName)) {
245     
246     TString nameph = fPH2d->GetTitle();
247     fVersionVdriftUsed = GetVersion(nameph);  
248     fSubVersionVdriftUsed = GetSubVersion(nameph);    
249
250     //printf("Found Version %d, Subversion %d for vdrift\n",fVersionVdriftUsed,fSubVersionVdriftUsed);
251   
252   }
253
254   if(ReadGainGlobal(fileName)) {
255
256     TString namech = fCH2d->GetTitle();
257     fVersionGainUsed = GetVersion(namech);  
258     fSubVersionGainUsed = GetSubVersion(namech);    
259
260     //printf("Found Version %d, Subversion %d for gain\n",fVersionGainUsed,fSubVersionGainUsed);
261
262   }
263    
264   return kTRUE;
265   
266 }
267 //___________________________________________________________________________________________________________________
268
269 Bool_t AliTRDPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
270   //
271   // read calibration entries from file
272   // 
273   if(fCH2d) return kTRUE;
274   TFile fcalib(fileName);
275   TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
276   if (array){
277     TH2I *ch2d = (TH2I *) array->FindObject("CH2d");
278     if(!ch2d) return kFALSE;
279     fCH2d = (TH2I*)ch2d->Clone();
280     //fNEvents = (TH1I *) array->FindObject("NEvents");
281     //fAbsoluteGain = (TH2F *) array->FindObject("AbsoluteGain");
282   }else{
283     TH2I *ch2d = (TH2I *) fcalib.Get("CH2d");
284     if(!ch2d) return kFALSE;
285     fCH2d = (TH2I*)ch2d->Clone();
286     //fNEvents = (TH1I *) fcalib.Get("NEvents");
287     //fAbsoluteGain = (TH2F *) fcalib.Get("AbsoluteGain");
288   }
289   fCH2d->SetDirectory(0);
290   //printf("title of CH2d %s\n",fCH2d->GetTitle());
291
292   return kTRUE;
293   
294 }
295 //_________________________________________________________________________________________________________________
296
297 Bool_t AliTRDPreprocessorOffline::ReadVdriftT0Global(const Char_t* fileName){
298   //
299   // read calibration entries from file
300   // 
301   if(fPH2d) return kTRUE;
302   TFile fcalib(fileName);
303   TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
304   if (array){
305     TProfile2D *ph2d = (TProfile2D *) array->FindObject("PH2d");
306     if(!ph2d) return kFALSE;
307     fPH2d = (TProfile2D*)ph2d->Clone();
308     //fNEvents = (TH1I *) array->FindObject("NEvents");
309   }else{
310     TProfile2D *ph2d = (TProfile2D *) fcalib.Get("PH2d");
311     if(!ph2d) return kFALSE;
312     fPH2d = (TProfile2D*)ph2d->Clone();
313     //fNEvents = (TH1I *) fcalib.Get("NEvents");
314   }
315   fPH2d->SetDirectory(0);
316   //printf("title of PH2d %s\n",fPH2d->GetTitle());
317   
318   return kTRUE;
319   
320 }
321 //___________________________________________________________________________________________________________________
322
323 Bool_t AliTRDPreprocessorOffline::ReadVdriftLinearFitGlobal(const Char_t* fileName){
324   //
325   // read calibration entries from file
326   // 
327   if(fAliTRDCalibraVdriftLinearFit) return kTRUE;
328   TFile fcalib(fileName);
329   TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
330   if (array){
331     fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) array->FindObject("AliTRDCalibraVdriftLinearFit");
332     //fNEvents = (TH1I *) array->FindObject("NEvents");
333   }else{
334     fAliTRDCalibraVdriftLinearFit = (AliTRDCalibraVdriftLinearFit *) fcalib.Get("AliTRDCalibraVdriftLinearFit");
335     //fNEvents = (TH1I *) fcalib.Get("NEvents");
336   }
337   if(!fAliTRDCalibraVdriftLinearFit) {
338     //printf("No AliTRDCalibraVdriftLinearFit\n");
339     return kFALSE;
340   }
341   return kTRUE;
342   
343 }
344 //_____________________________________________________________________________________________________________
345
346 Bool_t AliTRDPreprocessorOffline::ReadPRFGlobal(const Char_t* fileName){
347   //
348   // read calibration entries from file
349   // 
350   if(fPRF2d) return kTRUE;
351   TFile fcalib(fileName);
352   TObjArray * array = (TObjArray*)fcalib.Get(fNameList);
353   if (array){
354     TProfile2D *prf2d = (TProfile2D *) array->FindObject("PRF2d");
355     if(!prf2d) return kFALSE;
356     fPRF2d = (TProfile2D*)prf2d->Clone();
357     //fNEvents = (TH1I *) array->FindObject("NEvents");
358   }else{
359     TProfile2D *prf2d = (TProfile2D *) fcalib.Get("PRF2d");
360     if(!prf2d) return kFALSE;
361     fPRF2d = (TProfile2D*)prf2d->Clone();
362     //fNEvents = (TH1I *) fcalib.Get("NEvents");
363   }
364   fPRF2d->SetDirectory(0);
365   //printf("title of PRF2d %s\n",fPRF2d->GetTitle());
366   
367   return kTRUE;
368
369 }
370 //__________________________________________________________________________________________________________
371
372 Bool_t AliTRDPreprocessorOffline::AnalyzeGain(){
373   //
374   // Analyze gain - produce the calibration objects
375   //
376
377   AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
378   calibra->SetMinEntries(fMinStatsGain); // If there is less than 1000 entries in the histo: no fit
379   calibra->AnalyseCH(fCH2d);
380
381   Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
382     + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
383   Int_t nbfit       = calibra->GetNumberFit();
384   Int_t nbE         = calibra->GetNumberEnt();
385
386
387   Bool_t ok = kFALSE;
388   Bool_t meanother = kFALSE;
389   // enough statistics
390   if ((nbtg >                  0) && 
391       (nbfit        >= 0.5*nbE) && (nbE > 30)) {
392     // create the cal objects
393     if(!fCalDetGainUsed) {
394       calibra->PutMeanValueOtherVectorFit(1,kTRUE);
395       meanother = kTRUE;
396     }
397     TObjArray object           = calibra->GetVectorFit();
398     AliTRDCalDet *calDetGain   = calibra->CreateDetObjectGain(&object,meanother);
399     TH1F *coefGain  = calDetGain->MakeHisto1DAsFunctionOfDet();
400     // Put them in the array
401     fCalibObjects->AddAt(calDetGain,kGain);
402     fPlots->AddAt(coefGain,kGain);
403     //
404     ok = kTRUE;
405   }
406   
407   calibra->ResetVectorFit();
408   
409   return ok;
410   
411 }
412 //_____________________________________________________________________________________________________
413 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftT0(){
414   //
415   // Analyze VdriftT0 - produce the calibration objects
416   //
417
418   AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
419   calibra->SetMinEntries(fMinStatsVdriftT0PH); // If there is less than 1000 entries in the histo: no fit
420   calibra->AnalysePH(fPH2d);
421
422   Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
423     + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
424   Int_t nbfit       = calibra->GetNumberFit();
425   Int_t nbfitSuccess = calibra->GetNumberFitSuccess();
426   Int_t nbE         = calibra->GetNumberEnt();
427
428   //printf("nbtg %d, nbfit %d, nbE %d, nbfitSuccess %d\n",nbtg,nbfit,nbE,nbfitSuccess);
429
430   Bool_t ok = kFALSE;
431   if ((nbtg >                  0) && 
432       (nbfit        >= 0.5*nbE) && (nbE > 30) && (nbfitSuccess > 30)) {
433     //printf("Pass the cut for VdriftT0\n");
434     // create the cal objects
435     calibra->RemoveOutliers(1,kFALSE);
436     calibra->PutMeanValueOtherVectorFit(1,kFALSE);
437     calibra->RemoveOutliers2(kFALSE);
438     calibra->PutMeanValueOtherVectorFit2(1,kFALSE);
439     //
440     TObjArray object = calibra->GetVectorFit();
441     AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object);
442     TH1F *coefVdriftPH  = calDetVdrift->MakeHisto1DAsFunctionOfDet();
443     AliTRDCalPad *calPadVdrift = (AliTRDCalPad *)calibra->CreatePadObjectVdrift(&object,calDetVdrift);
444     TH1F *coefPadVdrift   = calPadVdrift->MakeHisto1D();
445     object       = calibra->GetVectorFit2();
446     AliTRDCalDet *calDetT0  = calibra->CreateDetObjectT0(&object);
447     TH1F *coefT0  = calDetT0->MakeHisto1DAsFunctionOfDet();
448     AliTRDCalPad *calPadT0 = (AliTRDCalPad *)calibra->CreatePadObjectT0(&object,calDetT0);
449     TH1F *coefPadT0  = calPadT0->MakeHisto1D();
450     // Put them in the array
451     fCalibObjects->AddAt(calDetT0,kT0PHDet);
452     fCalibObjects->AddAt(calDetVdrift,kVdriftPHDet);
453     fCalibObjects->AddAt(calPadT0,kT0PHPad);
454     fCalibObjects->AddAt(calPadVdrift,kVdriftPHPad);
455     fPlots->AddAt(coefVdriftPH,kVdriftPHDet);
456     fPlots->AddAt(coefT0,kT0PHDet);
457     fPlots->AddAt(coefPadVdrift,kVdriftPHPad);
458     fPlots->AddAt(coefPadT0,kT0PHPad);
459     //
460     ok = kTRUE;
461   }
462   calibra->ResetVectorFit();
463  
464   return ok;
465   
466 }
467 //____________________________________________________________________________________________________________________
468 Bool_t AliTRDPreprocessorOffline::AnalyzeVdriftLinearFit(){
469   //
470   // Analyze vdrift linear fit - produce the calibration objects
471   //
472
473   AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
474   calibra->SetMinEntries(fMinStatsVdriftLinear); // If there is less than 1000 entries in the histo: no fit
475   fAliTRDCalibraVdriftLinearFit->FillPEArray();
476   calibra->AnalyseLinearFitters(fAliTRDCalibraVdriftLinearFit);
477
478   //Int_t nbtg        = 540;
479   Int_t nbfit       = calibra->GetNumberFit();
480   Int_t nbE         = calibra->GetNumberEnt();
481
482   
483   Bool_t ok = kFALSE;
484   // enough statistics
485   if ((nbfit        >= 0.5*nbE) && (nbE > 30)) {
486     // create the cal objects
487     //calibra->RemoveOutliers(1,kTRUE);
488     calibra->PutMeanValueOtherVectorFit(1,kTRUE);
489     //calibra->RemoveOutliers2(kTRUE);
490     calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
491     //
492     TObjArray object  = calibra->GetVectorFit();
493     AliTRDCalDet *calDetVdrift = calibra->CreateDetObjectVdrift(&object,kTRUE);
494     TH1F *coefDriftLinear      = calDetVdrift->MakeHisto1DAsFunctionOfDet();
495     object                     = calibra->GetVectorFit2();
496     AliTRDCalDet *calDetLorentz = calibra->CreateDetObjectLorentzAngle(&object);
497     TH1F *coefLorentzAngle = calDetLorentz->MakeHisto1DAsFunctionOfDet();
498     // Put them in the array
499     fCalibObjects->AddAt(calDetVdrift,kVdriftLinear);
500     fCalibObjects->AddAt(calDetLorentz,kLorentzLinear);
501     fPlots->AddAt(coefDriftLinear,kVdriftLinear);
502     fPlots->AddAt(coefLorentzAngle,kLorentzLinear);
503     //
504     ok = kTRUE;
505   }
506   
507   calibra->ResetVectorFit();
508   
509   return ok;
510   
511 }
512 //________________________________________________________________________________________________________________
513
514 Bool_t AliTRDPreprocessorOffline::AnalyzePRF(){
515   //
516   // Analyze PRF - produce the calibration objects
517   //
518
519   AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
520   calibra->SetMinEntries(fMinStatsPRF); // If there is less than 1000 entries in the histo: no fit
521   calibra->AnalysePRFMarianFit(fPRF2d);
522
523   Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
524     + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
525   Int_t nbfit       = calibra->GetNumberFit();
526   Int_t nbE         = calibra->GetNumberEnt();
527
528   
529   Bool_t ok = kFALSE;
530   // enough statistics
531   if ((nbtg >                  0) && 
532       (nbfit        >= 0.95*nbE) && (nbE > 30)) {
533     // create the cal objects
534     TObjArray object  = calibra->GetVectorFit();
535     AliTRDCalPad *calPadPRF = (AliTRDCalPad*) calibra->CreatePadObjectPRF(&object);
536     TH1F *coefPRF           = calPadPRF->MakeHisto1D();
537     // Put them in the array
538     fCalibObjects->AddAt(calPadPRF,kPRF);
539     fPlots->AddAt(coefPRF,kPRF);
540     //
541     ok = kTRUE;
542   }
543   
544   calibra->ResetVectorFit();
545   
546   return ok;
547   
548 }
549 //________________________________________________________________________________________________
550 void AliTRDPreprocessorOffline::CorrectFromDetGainUsed() {
551   //
552   // Correct from the gas gain used afterwards
553   //
554   AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
555   if(!calDetGain) return;
556
557   // Calculate mean
558   Double_t mean = 0.0;
559   Int_t nbdet = 0;
560   
561   for(Int_t det = 0; det < 540; det++) {
562     
563     Float_t gaininit = fCalDetGainUsed->GetValue(det);
564     Float_t gainout = calDetGain->GetValue(det);
565
566    
567     if(TMath::Abs(gainout-1.0) > 0.000001) {
568       mean += (gaininit*gainout);
569       nbdet++;
570     }  
571   }
572   if(nbdet > 0) mean = mean/nbdet;
573    
574   for(Int_t det = 0; det < 540; det++) {
575     
576     Float_t gaininit = fCalDetGainUsed->GetValue(det);
577     Float_t gainout = calDetGain->GetValue(det);
578   
579     if(TMath::Abs(gainout-1.0) > 0.000001) calDetGain->SetValue(det,gaininit*gainout);
580     else calDetGain->SetValue(det,mean);
581   }
582
583
584 }
585 //________________________________________________________________________________________________
586 void AliTRDPreprocessorOffline::CorrectFromDetVdriftUsed() {
587   //
588   // Correct from the drift velocity
589   //
590
591   //printf("Correct for vdrift\n");
592
593   AliTRDCalDet *calDetGain = (AliTRDCalDet *) fCalibObjects->At(kGain);
594   if(!calDetGain) return;
595
596   Int_t detVdrift = kVdriftPHDet;
597   if(fMethodSecond) detVdrift = kVdriftLinear;
598   AliTRDCalDet *calDetVdrift = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
599   if(!calDetVdrift) return;
600
601   // Calculate mean
602   
603   for(Int_t det = 0; det < 540; det++) {
604     
605     Float_t vdriftinit = fCalDetVdriftUsed->GetValue(det);
606     Float_t vdriftout = calDetVdrift->GetValue(det);
607
608     Float_t gain = calDetGain->GetValue(det);
609     if(vdriftout > 0.0) gain = gain*vdriftinit/vdriftout;
610     calDetGain->SetValue(det,gain);
611
612     
613   }
614  
615 }
616 //_________________________________________________________________________________________________________________
617 void AliTRDPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
618   //
619   // Update OCDB entry
620   //
621   
622   AliCDBMetaData *metaData= new AliCDBMetaData();
623   metaData->SetObjectClassName("AliTRDCalDet");
624   metaData->SetResponsible("Raphaelle Bailhache");
625   metaData->SetBeamPeriod(1);
626   
627   AliCDBId id1("TRD/Calib/ChamberGainFactor", startRunNumber, endRunNumber);
628   AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
629   AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
630   if(calDet) gStorage->Put(calDet, id1, metaData);
631     
632
633 }
634 //___________________________________________________________________________________________________________________
635 void AliTRDPreprocessorOffline::UpdateOCDBVdrift(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
636   //
637   // Update OCDB entry
638   //
639
640   Int_t detVdrift = kVdriftPHDet;
641   
642   if(fMethodSecond) detVdrift = kVdriftLinear;
643   
644   AliCDBMetaData *metaData= new AliCDBMetaData();
645   metaData->SetObjectClassName("AliTRDCalDet");
646   metaData->SetResponsible("Raphaelle Bailhache");
647   metaData->SetBeamPeriod(1);
648   
649   AliCDBId id1("TRD/Calib/ChamberVdrift", startRunNumber, endRunNumber);
650   AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
651   AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
652   if(calDet) gStorage->Put(calDet, id1, metaData);
653   
654   //
655
656   if(!fMethodSecond) {
657     
658     AliCDBMetaData *metaDataPad= new AliCDBMetaData();
659     metaDataPad->SetObjectClassName("AliTRDCalPad");
660     metaDataPad->SetResponsible("Raphaelle Bailhache");
661     metaDataPad->SetBeamPeriod(1);
662     
663     AliCDBId id1Pad("TRD/Calib/LocalVdrift", startRunNumber, endRunNumber);
664     AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
665     if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
666      
667   }
668
669 }
670 //________________________________________________________________________________________________________________________
671 void AliTRDPreprocessorOffline::UpdateOCDBT0(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
672   //
673   // Update OCDB entry
674   //
675   
676   AliCDBMetaData *metaData= new AliCDBMetaData();
677   metaData->SetObjectClassName("AliTRDCalDet");
678   metaData->SetResponsible("Raphaelle Bailhache");
679   metaData->SetBeamPeriod(1);
680   
681   AliCDBId id1("TRD/Calib/ChamberT0", startRunNumber, endRunNumber);
682   AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
683   AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
684   if(calDet) gStorage->Put(calDet, id1, metaData);
685  
686   //
687
688   AliCDBMetaData *metaDataPad= new AliCDBMetaData();
689   metaDataPad->SetObjectClassName("AliTRDCalPad");
690   metaDataPad->SetResponsible("Raphaelle Bailhache");
691   metaDataPad->SetBeamPeriod(1);
692   
693   AliCDBId id1Pad("TRD/Calib/LocalT0", startRunNumber, endRunNumber);
694   AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
695   if(calPad) gStorage->Put(calPad, id1Pad, metaDataPad);
696  
697
698
699 }
700 //_________________________________________________________________________________________________________________
701 void AliTRDPreprocessorOffline::UpdateOCDBPRF(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
702   //
703   // Update OCDB entry
704   //
705   
706   AliCDBMetaData *metaData= new AliCDBMetaData();
707   metaData->SetObjectClassName("AliTRDCalPad");
708   metaData->SetResponsible("Raphaelle Bailhache");
709   metaData->SetBeamPeriod(1);
710   
711   AliCDBId id1("TRD/Calib/PRFWidth", startRunNumber, endRunNumber);
712   AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
713   AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
714   if(calPad) gStorage->Put(calPad, id1, metaData);
715  
716
717 }
718 //__________________________________________________________________________________________________________________________
719 Bool_t AliTRDPreprocessorOffline::ValidateGain() const {
720   //
721   // Validate OCDB entry
722   //
723
724   AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kGain);
725   if(calDet) {
726     Double_t mean = calDet->GetMean();
727     Double_t rms = calDet->GetRMS();
728     if((mean > 0.2) && (mean < 1.4) && (rms < 0.5)) return kTRUE;
729     else return kFALSE;
730   }
731   else return kFALSE;
732     
733
734 }
735 //__________________________________________________________________________________________________________________________
736 Bool_t AliTRDPreprocessorOffline::ValidateVdrift(){
737   //
738   // Update OCDB entry
739   //
740
741   Int_t detVdrift = kVdriftPHDet;
742   Bool_t ok = kTRUE;
743   
744   if(fMethodSecond) detVdrift = kVdriftLinear;
745   
746   AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(detVdrift);
747   if(calDet) {
748     Double_t mean = calDet->GetMean();
749     Double_t rms = calDet->GetRMS();
750     //printf("Vdrift::mean %f, rms %f\n",mean,rms);
751     if(!((mean > 1.0) && (mean < 2.0) && (rms < 0.5))) ok = kFALSE;
752   }
753   else return kFALSE; 
754
755   if(!fMethodSecond) {
756     AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kVdriftPHPad);
757     if(calPad) {
758       Double_t mean = calPad->GetMean();
759       Double_t rms = calPad->GetRMS();
760       //printf("Vdrift::meanpad %f, rmspad %f\n",mean,rms);
761       if(!((mean > 0.9) && (mean < 1.1) && (rms < 0.6))) ok = kFALSE;
762     }
763     else return kFALSE;
764   }
765
766   return ok;
767
768 }
769 //__________________________________________________________________________________________________________________________
770 Bool_t AliTRDPreprocessorOffline::ValidateT0(){
771   //
772   // Update OCDB entry
773   //
774   
775   AliTRDCalDet *calDet = (AliTRDCalDet *) fCalibObjects->At(kT0PHDet);
776   AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kT0PHPad);
777   if(calDet && calPad) {
778     Double_t meandet = calDet->GetMean();
779     Double_t rmsdet = calDet->GetRMS();
780     Double_t meanpad = calPad->GetMean();
781     //Double_t rmspad = calPad->GetRMS();
782     //printf("T0::minimum %f, rmsdet %f,meanpad %f, rmspad %f\n",meandet,rmsdet,meanpad,rmspad);
783     if((meandet > -1.5) && (meandet < 5.0) && (rmsdet < 4.0) && (meanpad < 5.0) && (meanpad > -0.5)) return kTRUE;
784     else return kFALSE;
785   }
786   else return kFALSE;
787  
788 }
789 //__________________________________________________________________________________________________________________________
790 Bool_t AliTRDPreprocessorOffline::ValidatePRF() const{
791   //
792   // Update OCDB entry
793   //
794   
795   AliTRDCalPad *calPad = (AliTRDCalPad *) fCalibObjects->At(kPRF);
796   if(calPad) {
797     Double_t meanpad = calPad->GetMean();
798     Double_t rmspad = calPad->GetRMS();
799     //printf("PRF::meanpad %f, rmspad %f\n",meanpad,rmspad);
800     if((meanpad < 1.0) && (rmspad < 0.8)) return kTRUE;
801     else return kFALSE;
802   }
803   else return kFALSE;
804  
805
806 }
807 //_____________________________________________________________________________
808 Int_t AliTRDPreprocessorOffline::GetVersion(TString name) const
809 {
810   //
811   // Get version from the title
812   //
813   
814   // Some patterns
815   const Char_t *version = "Ver";
816   if(!strstr(name.Data(),version)) return -1;
817   
818   for(Int_t ver = 0; ver < 999999999; ver++) {
819
820     TString vertry(version);
821     vertry += ver;
822     vertry += "Subver";
823
824     //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
825
826     if(strstr(name.Data(),vertry.Data())) return ver;
827     
828   }
829   
830   return -1;
831
832 }
833
834 //_____________________________________________________________________________
835 Int_t AliTRDPreprocessorOffline::GetSubVersion(TString name) const
836 {
837   //
838   // Get subversion from the title
839   //
840   
841   // Some patterns
842   const Char_t *subversion = "Subver";
843   if(!strstr(name.Data(),subversion)) return -1;
844   
845   for(Int_t ver = 0; ver < 999999999; ver++) {
846     
847     TString vertry(subversion);
848     vertry += ver;
849     vertry += "Nz";
850
851     //printf("vertry %s and name %s\n",vertry.Data(),name.Data());
852
853     if(strstr(name.Data(),vertry.Data())) return ver;
854     
855   }
856   
857   return -1;
858
859 }
860
861 //_____________________________________________________________________________
862 AliTRDCalChamberStatus *AliTRDPreprocessorOffline::ProduceChamberStatus()
863 {
864   //
865   // Produce AliTRDCalChamberStatus out of calibration results
866   //
867
868   // set up AliTRDCalChamberStatus
869   AliTRDCalChamberStatus *CalChamberStatus = new AliTRDCalChamberStatus();
870
871   // get calibration objects
872   AliTRDCalDet *calDetGain   = (AliTRDCalDet *) fCalibObjects->At(kGain);
873   AliTRDCalDet *calDetVDrift = (AliTRDCalDet *) fCalibObjects->At(kVdriftLinear);
874   
875   // mask chambers with empty gain entries
876   Int_t counter = 0;
877   for (Int_t idet = 0; idet < 540; idet++) {
878
879     // ch2d
880     TH1I *projch =  (TH1I *) fCH2d->ProjectionX("projch",idet+1,idet+1,(Option_t *)"e");
881     if (!projch) continue;
882
883     Int_t entries = static_cast<Int_t>(projch->GetEntries());
884
885     // gain
886     Double_t defaultgain = calDetGain->GetMean();
887     Double_t gain = calDetGain->GetValue(idet);
888
889     // vdrift
890     Double_t defaultvdrift = calDetVDrift->GetMean();
891     Double_t vdrift = calDetVDrift->GetValue(idet);
892
893     if(entries<=0 ||
894        TMath::Abs(defaultgain-gain) < 0.5 ||
895        TMath::Abs(defaultvdrift-vdrift) < 0.1) {
896      
897        printf(" chamber det %03d masked \n",idet);
898        CalChamberStatus->SetStatus(idet,2);
899        counter++;
900     }
901     
902     // installed supermodules+1 -> abort
903     if(counter > (7+1)*30) {
904       printf("ERROR: more than one SM to be masked!! \n Abort...\n");
905       delete projch;
906       return 0x0;
907     }
908
909     delete projch;
910
911   }
912   return CalChamberStatus;
913 }