]>
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), |
64 | fTOFGeometry(0) | |
65 | { | |
66 | // constructor | |
67 | } | |
68 | ||
69 | //_____________________________________________________________________________ | |
70 | ||
71 | AliTOFPreprocessor::~AliTOFPreprocessor() | |
72 | { | |
73 | // destructor | |
9d883ed9 | 74 | delete fData; |
75 | fData = 0; | |
76 | delete fh2; | |
77 | fh2 = 0; | |
78 | delete fCal; | |
79 | fCal = 0; | |
80 | delete fTOFGeometry; | |
81 | fTOFGeometry = 0; | |
c9fe8530 | 82 | } |
83 | ||
84 | //______________________________________________________________________________ | |
85 | void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime, | |
86 | UInt_t endTime) | |
87 | { | |
88 | // Creates AliTOFDataDCS object | |
89 | ||
90 | AliPreprocessor::Initialize(run, startTime, endTime); | |
91 | ||
92 | AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run, | |
93 | TTimeStamp(startTime).AsString(), | |
94 | TTimeStamp(endTime).AsString())); | |
95 | ||
96 | fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime); | |
708db10b | 97 | fh2 = 0x0; |
c9fe8530 | 98 | fTOFGeometry = new AliTOFGeometryV5(); |
99 | fCal = new AliTOFCalOnline(fTOFGeometry); | |
100 | fCal->CreateArray(); | |
101 | } | |
102 | ||
103 | //_____________________________________________________________________________ | |
104 | ||
105 | UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap) | |
106 | { | |
107 | // Fills data into a AliTOFDataDCS object | |
108 | ||
708db10b | 109 | TH1::AddDirectory(0); |
c9fe8530 | 110 | UInt_t resultDCS=0; |
111 | UInt_t resultDAQ=0; | |
112 | UInt_t resultDAQRef=0; | |
113 | UInt_t result=0; | |
114 | ||
115 | // processing DCS | |
116 | ||
117 | if (!dcsAliasMap){ | |
9d883ed9 | 118 | Log("No DCS map found"); |
c9fe8530 | 119 | } |
120 | else { | |
121 | // The processing of the DCS input data is forwarded to AliTOFDataDCS | |
122 | fData->ProcessData(*dcsAliasMap); | |
123 | AliCDBMetaData metaDataDCS; | |
124 | metaDataDCS.SetBeamPeriod(0); | |
125 | metaDataDCS.SetResponsible("Chiara Zampolli"); | |
126 | metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object."); resultDCS = Store("Calib","DCSData",fData, &metaDataDCS); | |
9d883ed9 | 127 | // result+=resultDCS; |
c9fe8530 | 128 | if (!resultDCS){ |
9d883ed9 | 129 | Log("Some problems occurred while storing DCS data processing results"); |
130 | return 0; | |
c9fe8530 | 131 | } |
132 | } | |
133 | ||
134 | // processing DAQ | |
135 | ||
136 | TFile * daqFile=0x0; | |
9bc469d1 | 137 | |
138 | //retrieving data at Run level | |
139 | TList* list = GetFileSources(kDAQ, "RUNLevel"); | |
c9fe8530 | 140 | if (list) |
141 | { | |
9bc469d1 | 142 | AliInfo("The following sources produced files with the id RUNLevel"); |
c9fe8530 | 143 | list->Print(); |
144 | for (Int_t jj=0;jj<list->GetEntries();jj++){ | |
145 | TObjString * str = dynamic_cast<TObjString*> (list->At(jj)); | |
146 | AliInfo(Form("found source %s", str->String().Data())); | |
147 | // file to be stored run per run | |
9bc469d1 | 148 | TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName()); |
149 | if (fileNameRun.Length()>0){ | |
150 | AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data())); | |
151 | daqFile = new TFile(fileNameRun.Data(),"READ"); | |
708db10b | 152 | fh2 = (TH2S*) daqFile->Get("htof"); |
c9fe8530 | 153 | AliCDBMetaData metaDataHisto; |
154 | metaDataHisto.SetBeamPeriod(0); | |
155 | metaDataHisto.SetResponsible("Chiara Zampolli"); | |
156 | metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data."); | |
708db10b | 157 | resultDAQRef = StoreReferenceData("Calib","DAQData",fh2, &metaDataHisto); |
9d883ed9 | 158 | // result+=resultDAQRef*2; |
c9fe8530 | 159 | if (!resultDAQRef){ |
9d883ed9 | 160 | Log("some problems occurred::No Reference Data stored, still going on (please check!)"); |
c9fe8530 | 161 | } |
162 | daqFile->Close(); | |
163 | delete daqFile; | |
164 | } | |
165 | ||
166 | else{ | |
9d883ed9 | 167 | Log("The input data file from DAQ (run-level) was not found, still going on with Cumulative data file (please check!) "); |
168 | } | |
9bc469d1 | 169 | } |
170 | } | |
171 | else{ | |
9d883ed9 | 172 | Log("The input data file list from DAQ (run-level) was not found, still going on with Cumulative data file (please check!) "); |
9bc469d1 | 173 | } |
174 | ||
175 | //Total files, with summed histos | |
176 | ||
177 | TList* listTot = GetFileSources(kDAQ, "DELAYS"); | |
178 | if (listTot) | |
179 | { | |
180 | AliInfo("The following sources produced files with the id DELAYS"); | |
181 | listTot->Print(); | |
182 | for (Int_t jj=0;jj<listTot->GetEntries();jj++){ | |
183 | TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj)); | |
184 | AliInfo(Form("found source %s", str->String().Data())); | |
185 | ||
c9fe8530 | 186 | // file with summed histos, to extract calib params |
9bc469d1 | 187 | TString fileName = GetFile(kDAQ, "DELAYS", str->GetName()); |
188 | if (fileName.Length()>0){ | |
189 | AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data())); | |
c9fe8530 | 190 | |
9bc469d1 | 191 | daqFile = new TFile(fileName.Data(),"READ"); |
708db10b | 192 | fh2 = (TH2S*) daqFile->Get("htoftot"); |
193 | if (!fh2){ | |
9d883ed9 | 194 | Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle"); |
195 | delete daqFile; | |
196 | return 0; | |
c9fe8530 | 197 | } |
c9fe8530 | 198 | else { |
708db10b | 199 | static const Int_t size=fh2->GetNbinsX(); |
200 | static const Int_t nbins=fh2->GetNbinsY(); | |
201 | static const Double_t xbinmin=fh2->GetYaxis()->GetBinLowEdge(1); | |
c9fe8530 | 202 | Int_t npads = fCal->NPads(); |
9bc469d1 | 203 | if (size != npads){ |
9d883ed9 | 204 | Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle"); |
205 | delete daqFile; | |
206 | return 0; | |
9bc469d1 | 207 | } |
708db10b | 208 | for (Int_t ich=0;ich<size;ich++){ |
209 | TH1S *h1 = new TH1S("h1","h1",nbins,xbinmin-0.5,nbins*1.+xbinmin-0.5); | |
210 | for (Int_t ibin=0;ibin<nbins;ibin++){ | |
211 | h1->SetBinContent(ibin+1,fh2->GetBinContent(ich+1,ibin+1)); | |
212 | } | |
c9fe8530 | 213 | Bool_t found=kFALSE; |
9bc469d1 | 214 | Float_t minContent=h1->Integral()*fgkThrPar; |
c9fe8530 | 215 | Int_t nbinsX = h1->GetNbinsX(); |
216 | Int_t startBin=1; | |
217 | for (Int_t j=1; j<=nbinsX; j++){ | |
218 | if (( | |
219 | h1->GetBinContent(j) + | |
220 | h1->GetBinContent(j+1)+ | |
221 | h1->GetBinContent(j+2)+ | |
222 | h1->GetBinContent(j+3))>minContent){ | |
223 | found=kTRUE; | |
224 | startBin=j; | |
225 | break; | |
226 | } | |
227 | } | |
708db10b | 228 | if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich)); |
c9fe8530 | 229 | // Now calculate the mean over the interval. |
230 | Double_t mean = 0; | |
231 | Double_t sumw2 = 0; | |
232 | Double_t nent = 0; | |
233 | for(Int_t k=0;k<fgkBinRangeAve;k++){ | |
234 | mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k); | |
235 | nent=nent+h1->GetBinContent(startBin+k); | |
236 | sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k)); | |
237 | } | |
c9fe8530 | 238 | mean= mean/nent; //<x> |
239 | sumw2=sumw2/nent; //<x^2> | |
240 | Double_t rmsmean= 0; | |
241 | rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent); | |
708db10b | 242 | if (ich<npads) { |
243 | AliTOFChannelOnline * ch = fCal->GetChannel(ich); | |
c9fe8530 | 244 | ch->SetDelay(mean); |
245 | } | |
708db10b | 246 | delete h1; |
247 | h1=0x0; | |
c9fe8530 | 248 | } |
c9fe8530 | 249 | } |
250 | daqFile->Close(); | |
251 | delete daqFile; | |
252 | AliCDBMetaData metaData; | |
253 | metaData.SetBeamPeriod(0); | |
254 | metaData.SetResponsible("Chiara Zampolli"); | |
255 | metaData.SetComment("This preprocessor fills an AliTOFCal object."); | |
256 | resultDAQ = Store("Calib","OnlineDelay",fCal, &metaData); | |
9d883ed9 | 257 | if(!resultDAQ){ |
258 | Log("Some problems occurred while storing DAQ data processing results"); | |
259 | return 0; | |
260 | } | |
c9fe8530 | 261 | } |
262 | else{ | |
9d883ed9 | 263 | Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle"); |
264 | return 0; | |
c9fe8530 | 265 | } |
266 | } | |
267 | } | |
268 | else{ | |
9d883ed9 | 269 | Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle"); |
708db10b | 270 | return 0; |
c9fe8530 | 271 | } |
272 | ||
9d883ed9 | 273 | // delete list; |
274 | // list = 0; | |
275 | // delete listTot; | |
276 | // listTot = 0; | |
c9fe8530 | 277 | daqFile=0; |
9d883ed9 | 278 | |
279 | if(resultDCS ==2|| resultDAQ ==2) { | |
280 | result=2; | |
281 | } | |
282 | else{ | |
283 | result=1; | |
284 | } | |
285 | ||
c9fe8530 | 286 | return result; |
287 | } | |
288 | ||
289 |