]>
Commit | Line | Data |
---|---|---|
c9fe8530 | 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 | ||
9edefa04 | 16 | /* $Id$ */ |
9d883ed9 | 17 | |
9edefa04 | 18 | #include <Riostream.h> |
19 | #include <stdio.h> | |
20 | #include <stdlib.h> | |
c9fe8530 | 21 | |
9edefa04 | 22 | #include <TFile.h> |
23 | #include <TH1.h> | |
24 | #include <TH1F.h> | |
25 | #include <TH1S.h> | |
26 | #include <TH2S.h> | |
27 | #include <TMath.h> | |
28 | #include <TObjArray.h> | |
29 | #include <TObjString.h> | |
30 | #include <TTimeStamp.h> | |
c9fe8530 | 31 | |
32 | #include "AliCDBMetaData.h" | |
33 | #include "AliLog.h" | |
c9fe8530 | 34 | #include "AliTOFCalOnline.h" |
35 | #include "AliTOFChannelOnline.h" | |
9edefa04 | 36 | #include "AliTOFDataDCS.h" |
c9fe8530 | 37 | #include "AliTOFGeometryV5.h" |
9edefa04 | 38 | #include "AliTOFPreprocessor.h" |
c9fe8530 | 39 | |
40 | class TF1; | |
41 | class AliDCSValue; | |
42 | class AliTOFGeometry; | |
43 | ||
44 | // TOF preprocessor class. | |
45 | // It takes data from DCS and passes them to the class AliTOFDataDCS, which | |
46 | // processes them. The result is then written to the CDB. | |
47 | // analogously, it takes data form DAQ (both at Run level and inclusive - | |
48 | // of all the runs - level, processes them, and stores both Reference Data | |
49 | // and Online Calibration files in the CDB. | |
50 | ||
51 | ||
52 | ClassImp(AliTOFPreprocessor) | |
53 | ||
54 | const Int_t AliTOFPreprocessor::fgkBinRangeAve = 13; // number of bins where to calculate the mean | |
9d883ed9 | 55 | const Double_t AliTOFPreprocessor::fgkThrPar = 0.013; // parameter used to trigger the calculation of the delay |
c9fe8530 | 56 | |
57 | //_____________________________________________________________________________ | |
58 | ||
708db10b | 59 | AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) : |
60 | AliPreprocessor("TOF", shuttle), | |
c9fe8530 | 61 | fData(0), |
708db10b | 62 | fh2(0), |
c9fe8530 | 63 | fCal(0), |
5936ab02 | 64 | fTOFGeometry(0), |
65 | fStoreRefData(kTRUE) | |
c9fe8530 | 66 | { |
67 | // constructor | |
68 | } | |
69 | ||
70 | //_____________________________________________________________________________ | |
71 | ||
72 | AliTOFPreprocessor::~AliTOFPreprocessor() | |
73 | { | |
74 | // destructor | |
9d883ed9 | 75 | delete fData; |
76 | fData = 0; | |
77 | delete fh2; | |
78 | fh2 = 0; | |
79 | delete fCal; | |
80 | fCal = 0; | |
81 | delete fTOFGeometry; | |
82 | fTOFGeometry = 0; | |
c9fe8530 | 83 | } |
84 | ||
85 | //______________________________________________________________________________ | |
86 | void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime, | |
87 | UInt_t endTime) | |
88 | { | |
89 | // Creates AliTOFDataDCS object | |
90 | ||
91 | AliPreprocessor::Initialize(run, startTime, endTime); | |
92 | ||
93 | AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run, | |
94 | TTimeStamp(startTime).AsString(), | |
95 | TTimeStamp(endTime).AsString())); | |
96 | ||
97 | fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime); | |
708db10b | 98 | fh2 = 0x0; |
c9fe8530 | 99 | fTOFGeometry = new AliTOFGeometryV5(); |
100 | fCal = new AliTOFCalOnline(fTOFGeometry); | |
101 | fCal->CreateArray(); | |
102 | } | |
103 | ||
104 | //_____________________________________________________________________________ | |
105 | ||
106 | UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap) | |
107 | { | |
108 | // Fills data into a AliTOFDataDCS object | |
5936ab02 | 109 | // return codes: |
110 | // return=0 : all ok | |
111 | // return=1 : no DCS input data | |
112 | // return=2 : no DCS processed data was stored | |
113 | // return=3 : no DAQ input for Ref Data | |
114 | // return=4 : failed to store Ref data | |
115 | // return=5 : failed to retrieve DAQ data for calibration | |
116 | // return=6 : problems in histos in the input DAQ file | |
117 | // return=7 : failed to store Online Delays | |
c9fe8530 | 118 | |
708db10b | 119 | TH1::AddDirectory(0); |
5936ab02 | 120 | |
121 | Bool_t resultDCS=kTRUE; | |
122 | Bool_t resultDAQ=kTRUE; | |
123 | Bool_t resultDAQRef=kTRUE; | |
c9fe8530 | 124 | |
125 | // processing DCS | |
126 | ||
127 | if (!dcsAliasMap){ | |
5936ab02 | 128 | Log("No DCS map found: TOF exiting from Shuttle"); |
129 | return 1;// return error Code for DCS input data not found | |
c9fe8530 | 130 | } |
131 | else { | |
132 | // The processing of the DCS input data is forwarded to AliTOFDataDCS | |
133 | fData->ProcessData(*dcsAliasMap); | |
134 | AliCDBMetaData metaDataDCS; | |
135 | metaDataDCS.SetBeamPeriod(0); | |
136 | metaDataDCS.SetResponsible("Chiara Zampolli"); | |
5936ab02 | 137 | metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object."); |
138 | AliInfo("Storing DCS Data"); | |
139 | resultDCS = Store("Calib","DCSData",fData, &metaDataDCS); | |
c9fe8530 | 140 | if (!resultDCS){ |
5936ab02 | 141 | Log("Some problems occurred while storing DCS data processing results, TOF exiting from Shuttle"); |
142 | return 2;// return error Code for processed DCS data not stored | |
c9fe8530 | 143 | } |
144 | } | |
145 | ||
5936ab02 | 146 | AliInfo("Surviving"); |
c9fe8530 | 147 | // processing DAQ |
148 | ||
149 | TFile * daqFile=0x0; | |
9bc469d1 | 150 | |
5936ab02 | 151 | if(fStoreRefData){ |
152 | //retrieving data at Run level | |
153 | TList* list = GetFileSources(kDAQ, "RUNLevel"); | |
154 | if (list) | |
155 | { | |
156 | AliInfo("The following sources produced files with the id RUNLevel"); | |
157 | list->Print(); | |
158 | for (Int_t jj=0;jj<list->GetEntries();jj++){ | |
159 | TObjString * str = dynamic_cast<TObjString*> (list->At(jj)); | |
160 | AliInfo(Form("found source %s", str->String().Data())); | |
161 | // file to be stored run per run | |
162 | TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName()); | |
163 | if (fileNameRun.Length()>0){ | |
164 | AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data())); | |
165 | daqFile = new TFile(fileNameRun.Data(),"READ"); | |
166 | fh2 = (TH2S*) daqFile->Get("htof"); | |
167 | AliCDBMetaData metaDataHisto; | |
168 | metaDataHisto.SetBeamPeriod(0); | |
169 | metaDataHisto.SetResponsible("Chiara Zampolli"); | |
170 | metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data."); | |
171 | AliInfo("Storing Reference Data"); | |
172 | resultDAQRef = StoreReferenceData("Calib","DAQData",fh2, &metaDataHisto); | |
173 | if (!resultDAQRef){ | |
174 | Log("some problems occurred::No Reference Data stored, TOF exiting from Shuttle"); | |
175 | return 4;//return error code for failure in storing Ref Data | |
176 | } | |
177 | daqFile->Close(); | |
178 | delete daqFile; | |
179 | } | |
180 | ||
181 | else{ | |
182 | Log("The input data file from DAQ (run-level) was not found, TOF exiting from Shuttle "); | |
183 | return 3;//return error code for failure in retrieving Ref Data | |
c9fe8530 | 184 | } |
c9fe8530 | 185 | } |
9bc469d1 | 186 | } |
5936ab02 | 187 | else{ |
188 | Log("The input data file list from DAQ (run-level) was not found, TOF exiting from Shuttle "); | |
189 | return 3;//return error code for failure in retrieving Ref Data | |
190 | } | |
9bc469d1 | 191 | } |
192 | ||
9bc469d1 | 193 | |
5936ab02 | 194 | //Total files, with cumulative histos |
195 | ||
9bc469d1 | 196 | TList* listTot = GetFileSources(kDAQ, "DELAYS"); |
197 | if (listTot) | |
198 | { | |
199 | AliInfo("The following sources produced files with the id DELAYS"); | |
200 | listTot->Print(); | |
201 | for (Int_t jj=0;jj<listTot->GetEntries();jj++){ | |
202 | TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj)); | |
203 | AliInfo(Form("found source %s", str->String().Data())); | |
204 | ||
c9fe8530 | 205 | // file with summed histos, to extract calib params |
9bc469d1 | 206 | TString fileName = GetFile(kDAQ, "DELAYS", str->GetName()); |
207 | if (fileName.Length()>0){ | |
208 | AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data())); | |
c9fe8530 | 209 | |
9bc469d1 | 210 | daqFile = new TFile(fileName.Data(),"READ"); |
708db10b | 211 | fh2 = (TH2S*) daqFile->Get("htoftot"); |
212 | if (!fh2){ | |
9d883ed9 | 213 | Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle"); |
214 | delete daqFile; | |
5936ab02 | 215 | return 6; //return error code for histograms not existing/junky |
c9fe8530 | 216 | } |
c9fe8530 | 217 | else { |
3a3ece53 | 218 | static const Int_t kSize=fh2->GetNbinsX(); |
219 | static const Int_t kNBins=fh2->GetNbinsY(); | |
220 | static const Double_t kXBinmin=fh2->GetYaxis()->GetBinLowEdge(1); | |
c9fe8530 | 221 | Int_t npads = fCal->NPads(); |
3a3ece53 | 222 | if (kSize != npads){ |
9d883ed9 | 223 | Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle"); |
224 | delete daqFile; | |
5936ab02 | 225 | return 6; //return error code for histograms not existing/junky |
9bc469d1 | 226 | } |
3a3ece53 | 227 | for (Int_t ich=0;ich<kSize;ich++){ |
228 | TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5); | |
229 | for (Int_t ibin=0;ibin<kNBins;ibin++){ | |
708db10b | 230 | h1->SetBinContent(ibin+1,fh2->GetBinContent(ich+1,ibin+1)); |
231 | } | |
c9fe8530 | 232 | Bool_t found=kFALSE; |
9bc469d1 | 233 | Float_t minContent=h1->Integral()*fgkThrPar; |
c9fe8530 | 234 | Int_t nbinsX = h1->GetNbinsX(); |
235 | Int_t startBin=1; | |
236 | for (Int_t j=1; j<=nbinsX; j++){ | |
237 | if (( | |
238 | h1->GetBinContent(j) + | |
239 | h1->GetBinContent(j+1)+ | |
240 | h1->GetBinContent(j+2)+ | |
241 | h1->GetBinContent(j+3))>minContent){ | |
242 | found=kTRUE; | |
243 | startBin=j; | |
244 | break; | |
245 | } | |
246 | } | |
708db10b | 247 | if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich)); |
c9fe8530 | 248 | // Now calculate the mean over the interval. |
249 | Double_t mean = 0; | |
250 | Double_t sumw2 = 0; | |
251 | Double_t nent = 0; | |
252 | for(Int_t k=0;k<fgkBinRangeAve;k++){ | |
253 | mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k); | |
254 | nent=nent+h1->GetBinContent(startBin+k); | |
255 | sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k)); | |
256 | } | |
c9fe8530 | 257 | mean= mean/nent; //<x> |
258 | sumw2=sumw2/nent; //<x^2> | |
259 | Double_t rmsmean= 0; | |
260 | rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent); | |
708db10b | 261 | if (ich<npads) { |
262 | AliTOFChannelOnline * ch = fCal->GetChannel(ich); | |
c9fe8530 | 263 | ch->SetDelay(mean); |
264 | } | |
708db10b | 265 | delete h1; |
266 | h1=0x0; | |
c9fe8530 | 267 | } |
c9fe8530 | 268 | } |
269 | daqFile->Close(); | |
270 | delete daqFile; | |
271 | AliCDBMetaData metaData; | |
272 | metaData.SetBeamPeriod(0); | |
273 | metaData.SetResponsible("Chiara Zampolli"); | |
274 | metaData.SetComment("This preprocessor fills an AliTOFCal object."); | |
5936ab02 | 275 | AliInfo("Storing Calibration Data"); |
c9fe8530 | 276 | resultDAQ = Store("Calib","OnlineDelay",fCal, &metaData); |
9d883ed9 | 277 | if(!resultDAQ){ |
278 | Log("Some problems occurred while storing DAQ data processing results"); | |
5936ab02 | 279 | return 7;//return error code for problems in storing DAQ data |
9d883ed9 | 280 | } |
c9fe8530 | 281 | } |
282 | else{ | |
9d883ed9 | 283 | Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle"); |
5936ab02 | 284 | return 5;//return error code for problems in retrieving DAQ data |
c9fe8530 | 285 | } |
286 | } | |
287 | } | |
288 | else{ | |
9d883ed9 | 289 | Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle"); |
5936ab02 | 290 | return 5; //return error code for problems in retrieving DAQ data |
c9fe8530 | 291 | } |
292 | ||
c9fe8530 | 293 | daqFile=0; |
9d883ed9 | 294 | |
5936ab02 | 295 | return 0; |
c9fe8530 | 296 | } |
297 | ||
298 |