]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDPreprocessor.cxx
Remove event number reading due to interface changes
[u/mrichter/AliRoot.git] / TRD / AliTRDPreprocessor.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 /* $Id$ */
17
18 ////////////////////////////////////////////////////////////////////////////
19 //                                                                        //
20 // This class is a first implementation for the TRD.                      //
21 // It takes data from HLT and computes the parameters                     //
22 // and stores both reference data and online calibration                  //
23 // parameters in the CDB                                                  //
24 //                                                                        //
25 // Author:                                                                //
26 //   R. Bailhache (R.Bailhache@gsi.de)                                    //
27 //                                                                        //
28 ////////////////////////////////////////////////////////////////////////////
29
30 #include "AliTRDPreprocessor.h"
31
32 #include <TTimeStamp.h>
33 #include <TFile.h>
34 #include <TProfile2D.h>
35 #include <TH2I.h>
36 #include <TStopwatch.h>
37 #include <TObjString.h>
38 #include <TString.h>
39 #include <TList.h>
40 #include <TCollection.h>
41
42 #include "AliCDBMetaData.h"
43 #include "AliDCSValue.h"
44 #include "AliLog.h"
45
46 #include "AliTRDCalibraFit.h"
47 #include "AliTRDCalibraMode.h"
48 #include "Cal/AliTRDCalDet.h"
49
50 ClassImp(AliTRDPreprocessor)
51
52 //______________________________________________________________________________________________
53 AliTRDPreprocessor::AliTRDPreprocessor(AliShuttleInterface *shuttle)
54                    :AliPreprocessor("TRD", shuttle)
55 {
56   //
57   // Constructor
58   //
59
60 }
61
62 //______________________________________________________________________________________________
63 AliTRDPreprocessor::~AliTRDPreprocessor()
64 {
65   //
66   // Destructor
67   //
68
69 }
70
71 //______________________________________________________________________________________________
72 void AliTRDPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
73 {
74   //
75   // Initialization routine for the TRD preprocessor
76   //
77
78   AliPreprocessor::Initialize(run,startTime,endTime);
79
80 }
81
82 //______________________________________________________________________________________________
83 UInt_t AliTRDPreprocessor::Process(TMap* /*dcsAliasMap*/)
84 {
85   //
86   // Process the calibration data for the HLT part
87   //
88
89   // How long does it take for the HLT part?
90   TStopwatch timer;
91   timer.Start();
92
93   //Run type
94   TString runType = GetRunType();
95   Log(Form("Run type for run %d: %s", fRun, runType.Data()));
96   if (strcmp(runType, "PHYSICS") != 0){
97     Log("Nothing to do!");
98     return 0;
99   }
100
101
102   // note that the parameters are returned as character strings!
103   const char* nEvents = GetRunParameter("totalEvents");
104   if (nEvents) {
105     Log(Form("Number of events for run %d: %s",fRun, nEvents));
106   } else {
107     Log(Form("Number of events not put in logbook!"));
108   }
109
110
111   // Metadata for the reference data
112   AliCDBMetaData metaData;
113   metaData.SetBeamPeriod(1);
114   metaData.SetResponsible("Raphaelle Bailhache");
115   metaData.SetComment("This preprocessor fills reference data.");
116
117   // Take the file from the HLT file exchange server
118   TList *filesources = GetFileSources(kHLT,"GAINDRIFTPRF");
119   if (!filesources) {
120     Log(Form("No sources found for GAINDRIFTPRF for run %d !",fRun));
121     return 1;
122   }
123   if (filesources->GetSize() != 1) {
124     Log(Form("More than one source found for GAINDRIFTPRF for run %d!",fRun));
125     filesources->Print();
126     delete filesources;
127     return 1;
128   }
129
130   // Call a AliTRDCalibra instance for fit
131   AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
132
133   //Choose the fit methods
134   calibra->SetFitChargeNDB(4); //for the relative gain
135   calibra->SetFitMeanWOn();   //weighted mean
136   calibra->SetFitPHNDB(3);    //for the average pulse height
137   calibra->SetFitLagrPolOn(); //LagrPol
138   calibra->SetFitPRFNDB(0);   //for the PRF
139   calibra->SetFitPRFOn();     //gaussian fit
140
141   //Debug mode
142   //calibra->SetDebug(1);       //Debug
143
144   // Init some things
145   AliTRDCalDet *objgaindet          = 0x0; // Object for det average gain factor
146   AliTRDCalDet *objdriftvelocitydet = 0x0; // Object for det average drift velocity
147   AliTRDCalDet *objtime0det         = 0x0; // Object for det average time0 
148   TObject      *objgainpad          = 0x0; // Object for pad (relative to the det) gain factor
149   TObject      *objdriftvelocitypad = 0x0; // Object for pad (relative to the det) drift velocity
150   TObject      *objtime0pad         = 0x0; // Object for pad (relative to the det) time0
151   TObject      *objPRFpad           = 0x0; // Object for pad prf width
152   TH2I         *histogain           = 0x0; // Histogram taken from HLT for gain factor
153   TProfile2D   *histodriftvelocity  = 0x0; // Profile taken from HLT for drift velocity and time0
154   TProfile2D   *histoprf            = 0x0; // Profile taken from HLT for prf
155
156   Int_t    numberfit[3]        = { 0,   0,   0   }; // Number of histos fitted for gain, drift velocity and prf
157   Int_t    numberEnt[3]        = { 0,   0,   0   }; // Number of histos with entries
158   Double_t statisticmean[3]    = { 0.0, 0.0, 0.0 }; // Mean values of the number of entries in these histos
159   Int_t    numbertotalgroup[3] = { 0,   0,   0   }; // Total number of groups
160
161   // Loop over the files taken from the HLT
162   TIter iter(filesources);
163   TObjString *source;
164   while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
165     
166     TString filename = GetFile(kHLT,"GAINDRIFTPRF",source->GetName());
167     if (filename.Length() == 0) {
168       Log(Form("Error retrieving file from source %d failed!", source->GetName()));
169       delete filesources;
170       return 2;
171     }
172
173     // Take the histos
174     TFile *file = TFile::Open(filename);
175     histogain = (TH2I *) file->Get("CH2d");
176     histogain->SetDirectory(0);
177     if (!histogain) {
178       Log("Error retrieving 2D histos for gain failed!");
179       delete filesources;
180       return 2;
181     }
182     histodriftvelocity = (TProfile2D *) file->Get("PH2d");
183     histodriftvelocity->SetDirectory(0);
184     if (!histodriftvelocity) {
185       Log("Error retrieving 2D Profile for average pulse height failed!");
186       delete filesources;
187       return 2;
188     }
189     histoprf = (TProfile2D *) file->Get("PRF2d");
190     histoprf->SetDirectory(0);
191     if (!histoprf) {
192       Log("Error retrieving 2D Profile for Pad Response Function failed!");
193       delete filesources;
194       return 2;
195     }
196     file->Close();
197
198     // Set the mode of calibration from the TObject, store the reference data and try to fit them
199     if (histogain) {
200       calibra->SetModeCalibrationFromTObject((TObject *) histogain,0);
201       if(!StoreReferenceData("HLTData","Gain",(TObject *) histogain,&metaData)){
202         Log("Error storing 2D histos for gain as reference data");
203         delete filesources;
204         return 3;
205       }
206       Log("Take the CH reference data. Now we will try to fit\n");
207       calibra->SetMinEntries(100); // If there is less than 100 entries in the histo: no fit
208       calibra->FitCHOnline(histogain);
209       numbertotalgroup[0] = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
210                           + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
211       numberfit[0]        = calibra->GetNumberFit();
212       statisticmean[0]    = calibra->GetStatisticMean(); 
213       numberEnt[0]        = calibra->GetNumberEnt();
214       objgaindet          = calibra->CreateDetObjectTree(calibra->GetGain(),0);
215       objgainpad          = calibra->CreatePadObjectTree(calibra->GetGain(),0,objgaindet);
216     }
217     
218     if (histodriftvelocity) {
219       calibra->SetModeCalibrationFromTObject((TObject *) histodriftvelocity,1);
220       if(!StoreReferenceData("HLTData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
221         Log("Error storing 2D Profile for average pulse height as reference data");
222         delete filesources;
223         return 3;
224       }
225       Log("Take the PH reference data. Now we will try to fit\n");
226       calibra->SetMinEntries(100*20); // If there is less than 2000
227       calibra->FitPHOnline(histodriftvelocity);
228       numbertotalgroup[1] = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
229                           + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
230       numberfit[1]        = calibra->GetNumberFit();
231       statisticmean[1]    = calibra->GetStatisticMean(); 
232       numberEnt[1]        = calibra->GetNumberEnt();
233       objdriftvelocitydet = calibra->CreateDetObjectTree(calibra->GetVdrift(),1);
234       objdriftvelocitypad = calibra->CreatePadObjectTree(calibra->GetVdrift(),1,objdriftvelocitydet);
235       objtime0det         = calibra->CreateDetObjectTree(calibra->GetT0(),3);
236       objtime0pad         = calibra->CreatePadObjectTree(calibra->GetT0(),3,objtime0det);
237     }
238     
239     if (histoprf) {
240       calibra->SetModeCalibrationFromTObject((TObject *) histoprf,2);
241       if(!StoreReferenceData("HLTData","PRF",(TObject *) histoprf,&metaData)){
242         Log("Error storing the 2D Profile for Pad Response Function as reference data");
243         delete filesources;
244         return 3;
245       }
246       Log("Take the PRF reference data. Now we will try to fit\n");
247       calibra->SetMinEntries(100*20); // If there is less than 2000
248       calibra->SetRangeFitPRF(0.5);
249       calibra->FitPRFOnline(histoprf);
250       numbertotalgroup[2] = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
251                            + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
252       numberfit[2]        = calibra->GetNumberFit();
253       statisticmean[2]    = calibra->GetStatisticMean(); 
254       numberEnt[2]        = calibra->GetNumberEnt();
255       objPRFpad           = calibra->CreatePadObjectTree(calibra->GetPRF());
256     }
257
258   }
259   
260   // Bilan of the fit statistic
261   Log(Form("The mean number of entries required for a fit is: %d"
262               ,(Int_t) calibra->GetMinEntries()));
263   Log(Form("FOR THE CH: There is a mean statistic of: %f, with %d fits for %d groups and %d histos with entries"
264               ,statisticmean[0],numberfit[0],numbertotalgroup[0],numberEnt[0]));
265   Log(Form("FOR THE PH: There is a mean statistic of: %f, with %d fits for %d groups and %d histos with entries"
266               ,statisticmean[1],numberfit[1],numbertotalgroup[1],numberEnt[1]));
267   Log(Form("FOR THE PRF: There is a mean statistic of: %f, with %d fits for %d groups and %d histos with entries"
268               ,statisticmean[2],numberfit[2],numbertotalgroup[2],numberEnt[2]));
269   
270   
271   //
272   // Store the coefficients in the grid OCDB if enough statistics
273   //
274   
275   // Store the infos for the detector
276   AliCDBMetaData *md1= new AliCDBMetaData(); 
277   md1->SetObjectClassName("AliTRDCalDet");
278   md1->SetResponsible("Raphaelle Bailhache");
279   md1->SetBeamPeriod(1);
280   md1->SetAliRootVersion("01-10-06"); // root version
281   md1->SetComment("The dummy values in this calibration file are for testing only");
282   // Gain
283   if ((numbertotalgroup[0] >                  0) && 
284       (numberfit[0]        >= 0.95*numberEnt[0])) {
285     if(!Store("Calib","ChamberGainFactor",(TObject *) objgaindet         ,md1,0,kTRUE)){
286       Log("Error storing the calibration object for the chamber gain");
287       delete filesources;
288       return 4;
289     }
290   }
291   else{
292     Log("Not enough statistics for the gain");
293   }
294   // Vdrift and time0
295   if ((numbertotalgroup[1] >                  0) && 
296       (numberfit[1]        >= 0.95*numberEnt[1])) {
297     if(!Store("Calib","ChamberVdrift"    ,(TObject *) objdriftvelocitydet,md1,0,kTRUE)){
298       Log("Error storing the calibration object for the chamber vdrift");
299       delete filesources;
300       return 4;
301     }
302     if(!Store("Calib","ChamberT0"        ,(TObject *) objtime0det        ,md1,0,kTRUE)){
303       Log("Error storing the calibration object for the chamber t0");
304       delete filesources;
305       return 4;
306     }
307   }
308   else{
309     Log("Not enough statistics for the average pulse height");
310   }
311   
312   // Store the infos for the pads
313   AliCDBMetaData *md2= new AliCDBMetaData(); 
314   md2->SetObjectClassName("AliTRDCalPad");
315   md2->SetResponsible("Raphaelle Bailhache");
316   md2->SetBeamPeriod(1);
317   md2->SetAliRootVersion("01-10-06"); //root version
318   md2->SetComment("The dummy values in this calibration file are for testing only");
319   // Gain
320   if ((numbertotalgroup[0] >                  0) && 
321       (numberfit[0]        >= 0.95*numberEnt[0])) {
322     if(!Store("Calib","LocalGainFactor"  ,(TObject *) objgainpad         ,md2,0,kTRUE)){
323       Log("Error storing the calibration object for the local gain factor");
324       delete filesources;
325       return 4;
326     }
327   }
328   // Vdrift and time0
329   if ((numbertotalgroup[1] >                  0) && 
330       (numberfit[1]        >= 0.95*numberEnt[1])) {
331     if(!Store("Calib","LocalVdrift"      ,(TObject *) objdriftvelocitypad,md2,0,kTRUE)){
332       Log("Error storing the calibration object for the local drift velocity");
333       delete filesources;
334       return 4;
335     }
336     if(!Store("Calib","LocalT0"          ,(TObject *) objtime0pad        ,md2,0,kTRUE)){
337       Log("Error storing the calibration object for the local time0");
338       delete filesources;
339       return 4;
340     }
341   }
342   // Pad Response Width
343   if ((numbertotalgroup[2] >                  0) && 
344       (numberfit[2]        >= 0.95*numberEnt[2])) {
345     if(!Store("Calib","PRFWidth"         ,(TObject *) objPRFpad          ,md2,0,kTRUE)){
346       Log("Error storing the calibration object for the Pad Response Function");
347       delete filesources;
348       return 4;
349     }
350   }
351   else{
352     Log("Not enough statistics for the Pad Response Function");
353   }
354   
355   // End
356   delete filesources;
357   timer.Stop();
358   timer.Print();
359   return 0;  
360
361 }