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