1 ////////////////////////////////////////////////////////
3 // This class is a first implementation for the TRD.
4 // It takes data from HLT and computes the parameters
5 // and stores both reference data and online calibration parameters in the CDB
7 /////////////////////////////////////////////////////////
9 #include "AliTRDPreprocessor.h"
11 #include <TTimeStamp.h>
13 #include <TProfile2D.h>
15 #include <TStopwatch.h>
16 #include <TObjString.h>
19 #include <TCollection.h>
21 #include "AliCDBMetaData.h"
22 #include "AliDCSValue.h"
25 #include "AliTRDCalibra.h"
26 #include "Cal/AliTRDCalDet.h"
29 ClassImp(AliTRDPreprocessor)
31 //______________________________________________________________________________________________
32 AliTRDPreprocessor::AliTRDPreprocessor(const Char_t *detector, AliShuttleInterface *shuttle)
33 :AliPreprocessor(detector, shuttle)
41 //______________________________________________________________________________________________
42 AliTRDPreprocessor::~AliTRDPreprocessor()
50 //______________________________________________________________________________________________
51 void AliTRDPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
54 // Initialization routine for the TRD preprocessor
57 AliPreprocessor::Initialize(run,startTime,endTime);
61 //______________________________________________________________________________________________
62 UInt_t AliTRDPreprocessor::Process(TMap* /*dcsAliasMap*/)
65 // Process the calibraion data for the HLT part
68 // How long does it take for the HLT part?
72 // Metadata for the reference data
73 AliCDBMetaData metaData;
74 metaData.SetBeamPeriod(1);
75 metaData.SetResponsible("Raphaelle Bailhache");
76 metaData.SetComment("This preprocessor fills reference data.");
79 // Take the file from the HLT file exchange server
80 TList *filesources = GetFileSources(kHLT,"GAINDRIFTPRF");
82 AliError(Form("No sources found for GAINDRIFTPRF for run %d !",fRun));
85 if (filesources->GetSize() != 1) {
86 AliError(Form("More than one source found for GAINDRIFTPRF for run %d!",fRun));
90 // Call a AliTRDCalibra instance for fit
91 AliTRDCalibra *calibra = AliTRDCalibra::Instance();
94 AliTRDCalDet *objgaindet = 0x0; // Object for det average gain factor
95 AliTRDCalDet *objdriftvelocitydet = 0x0; // Object for det average drift velocity
96 AliTRDCalDet *objtime0det = 0x0; // Object for det average time0
97 TObject *objgainpad = 0x0; // Object for pad (relative to the det) gain factor
98 TObject *objdriftvelocitypad = 0x0; // Object for pad (relative to the det) drift velocity
99 TObject *objtime0pad = 0x0; // Object for pad (relative to the det) time0
100 TObject *objPRFpad = 0x0; // Object for pad prf width
101 TH2I *histogain = 0x0; // Histogram taken from HLT for gain factor
102 TProfile2D *histodriftvelocity = 0x0; // Profile taken from HLT for drift velocity and time0
103 TProfile2D *histoprf = 0x0; // Profile taken from HLT for prf
105 Int_t numberfit[3] = { 0, 0, 0 }; // Number of histos fitted for gain, drift velocity and prf
106 Int_t numberEnt[3] = { 0, 0, 0 }; // Number of histos with entries
107 Double_t statisticmean[3] = { 0.0, 0.0, 0.0 }; // Mean values of the number of entries in these histos
108 Int_t numbertotalgroup[3] = { 0, 0, 0 }; // Total number of groups
111 // Loop over the files taken from the HLT/
112 TIter iter(filesources);
114 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
116 TString filename = GetFile(kHLT,"GAINDRIFTPRF",source->GetName());
117 if (!filename.Data()) {
118 AliError(Form("Error retrieving file from source %d failed!", source->GetName()));
124 TFile *file = TFile::Open(filename);
125 histogain = (TH2I *) file->Get("CH2d");
126 histogain->SetDirectory(0);
128 AliError("Error retrieving 2D histos for gain failed!");
130 histodriftvelocity = (TProfile2D *) file->Get("PH2d");
131 histodriftvelocity->SetDirectory(0);
132 if (!histodriftvelocity) {
133 AliError("Error retrieving 2D Profile for average pulse height failed!");
135 histoprf = (TProfile2D *) file->Get("PRF2d");
136 histoprf->SetDirectory(0);
138 AliError("Error retrieving 2D Profile for Pad Response Function failed!");
142 // Set the mode of calibration from the TObject, store the reference data and try to fit them
144 calibra->SetModeCalibrationFromTObject((TObject *) histogain,0);
145 Store("Data","Gain",(TObject *) histogain,&metaData,0,0);
146 AliInfo("Take the CH reference data. Now we will try to fit\n");
147 calibra->SetMinEntries(100); // If there is less than 100 entries in the histo: no fit
148 calibra->FitCHOnline(histogain);
149 numbertotalgroup[0] = 6*4*18*((Int_t) calibra->GetDetChamb0(0))
150 + 6* 18*((Int_t) calibra->GetDetChamb2(0));
151 numberfit[0] = calibra->GetNumberFit();
152 statisticmean[0] = calibra->GetStatisticMean();
153 numberEnt[0] = calibra->GetNumberEnt();
154 objgaindet = calibra->CreateDetObjectTree(calibra->GetGain(),0);
155 objgainpad = calibra->CreatePadObjectTree(calibra->GetGain(),0,objgaindet);
158 if (histodriftvelocity) {
159 calibra->SetModeCalibrationFromTObject((TObject *) histodriftvelocity,1);
160 Store("Data","VdriftT0",(TObject *) histodriftvelocity,&metaData,0,0);
161 AliInfo("Take the PH reference data. Now we will try to fit\n");
162 calibra->SetMinEntries(100*20); // If there is less than 2000
163 calibra->FitPHOnline(histodriftvelocity);
164 numbertotalgroup[1] = 6*4*18*((Int_t) calibra->GetDetChamb0(1))
165 + 6* 18*((Int_t) calibra->GetDetChamb2(1));
166 numberfit[1] = calibra->GetNumberFit();
167 statisticmean[1] = calibra->GetStatisticMean();
168 numberEnt[1] = calibra->GetNumberEnt();
169 objdriftvelocitydet = calibra->CreateDetObjectTree(calibra->GetVdrift(),1);
170 objdriftvelocitypad = calibra->CreatePadObjectTree(calibra->GetVdrift(),1,objdriftvelocitydet);
171 objtime0det = calibra->CreateDetObjectTree(calibra->GetT0(),3);
172 objtime0pad = calibra->CreatePadObjectTree(calibra->GetT0(),3,objtime0det);
176 calibra->SetModeCalibrationFromTObject((TObject *) histoprf,2);
177 Store("Data","PRF",(TObject *) histoprf,&metaData,0,0);
178 AliInfo("Take the PRF reference data. Now we will try to fit\n");
179 calibra->SetMinEntries(100*20); // If there is less than 2000
180 calibra->SetRangeFitPRF(0.5);
181 calibra->FitPRFOnline(histoprf);
182 numbertotalgroup[2] = 6*4*18*((Int_t) calibra->GetDetChamb0(2))
183 + 6* 18*((Int_t) calibra->GetDetChamb2(2));
184 numberfit[2] = calibra->GetNumberFit();
185 statisticmean[2] = calibra->GetStatisticMean();
186 numberEnt[2] = calibra->GetNumberEnt();
187 objPRFpad = calibra->CreatePadObjectTree(calibra->GetPRF());
192 // Bilan of the fit statistic
193 AliInfo(Form("The mean number of entries required for a fit is: %d"
194 ,(Int_t) calibra->GetMinEntries()));
195 AliInfo(Form("FOR THE CH: There is a mean statistic of: %f, with %d fits for %d groups and %d histos with entries"
196 ,statisticmean[0],numberfit[0],numbertotalgroup[0],numberEnt[0]));
197 AliInfo(Form("FOR THE PH: There is a mean statistic of: %f, with %d fits for %d groups and %d histos with entries"
198 ,statisticmean[1],numberfit[1],numbertotalgroup[1],numberEnt[1]));
199 AliInfo(Form("FOR THE PRF: There is a mean statistic of: %f, with %d fits for %d groups and %d histos with entries"
200 ,statisticmean[2],numberfit[2],numbertotalgroup[2],numberEnt[2]));
204 // Store the coefficients in the grid OCDB if enough statistics
207 // Store the infos for the detector
208 AliCDBMetaData *md1= new AliCDBMetaData();
209 md1->SetObjectClassName("AliTRDCalDet");
210 md1->SetResponsible("Raphaelle Bailhache");
211 md1->SetBeamPeriod(1);
212 md1->SetAliRootVersion("01-10-06"); // root version
213 md1->SetComment("The dummy values in this calibration file are for testing only");
214 if ((numbertotalgroup[0] > 0) &&
215 (numberfit[0] >= 0.95*numberEnt[0])) {
216 Store("Calib","ChamberGainFactor",(TObject *) objgaindet ,md1,0,kTRUE);
218 if ((numbertotalgroup[1] > 0) &&
219 (numberfit[1] >= 0.95*numberEnt[1])) {
220 Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,md1,0,kTRUE);
221 Store("Calib","ChamberT0" ,(TObject *) objtime0det ,md1,0,kTRUE);
224 // Store the infos for the pads
225 AliCDBMetaData *md2= new AliCDBMetaData();
226 md2->SetObjectClassName("AliTRDCalPad");
227 md2->SetResponsible("Raphaelle Bailhache");
228 md2->SetBeamPeriod(1);
229 md2->SetAliRootVersion("01-10-06"); //root version
230 md2->SetComment("The dummy values in this calibration file are for testing only");
231 if ((numbertotalgroup[0] > 0) &&
232 (numberfit[0] >= 0.95*numberEnt[0])) {
233 Store("Calib","LocalGainFactor" ,(TObject *) objgainpad ,md2,0,kTRUE);
235 if ((numbertotalgroup[1] > 0) &&
236 (numberfit[1] >= 0.95*numberEnt[1])) {
237 Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,md2,0,kTRUE);
238 Store("Calib","LocalT0" ,(TObject *) objtime0pad ,md2,0,kTRUE);
240 if ((numbertotalgroup[2] > 0) &&
241 (numberfit[2] >= 0.95*numberEnt[2])) {
242 Store("Calib","PRFWidth" ,(TObject *) objPRFpad ,md2,0,kTRUE);