]>
Commit | Line | Data |
---|---|---|
5253c153 | 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 | #include "AliMUONPedestal.h" | |
19 | #include "AliMUONErrorCounter.h" | |
20 | #include "AliMUONVStore.h" | |
21 | #include "AliMUON2DMap.h" | |
22 | #include "AliMUONCalibParamND.h" | |
23 | ||
24 | #include <TString.h> | |
25 | #include <THashTable.h> | |
26 | #include <TTimeStamp.h> | |
27 | #include <TMath.h> | |
28 | #include <TTree.h> | |
29 | #include <TFile.h> | |
30 | #include <TH1F.h> | |
31 | #include <Riostream.h> | |
32 | ||
33 | #include <sstream> | |
34 | ||
35 | //----------------------------------------------------------------------------- | |
36 | /// \class AliMUONPedestal | |
37 | /// | |
38 | /// Implementation of the pedestal computing | |
39 | /// | |
40 | /// add | |
41 | /// | |
42 | /// | |
43 | /// \author Alberto Baldisseri, JL Charvet (05/05/2009) | |
44 | //----------------------------------------------------------------------------- | |
45 | ||
46 | /// \cond CLASSIMP | |
47 | ClassImp(AliMUONPedestal) | |
48 | /// \endcond | |
49 | ||
50 | //______________________________________________________________________________ | |
51 | AliMUONPedestal::AliMUONPedestal() | |
52 | : TObject(), | |
53 | fNEvents(0), | |
54 | fRunNumber(0), | |
55 | fNChannel(0), | |
56 | fNManu(0), | |
57 | fErrorBuspatchTable(new THashTable(100,2)), | |
58 | fDate(new TTimeStamp()), | |
59 | fFilcout(0), | |
60 | fPedestalStore(new AliMUON2DMap(kFALSE)), | |
61 | fIndex(-1) | |
62 | { | |
63 | /// Default constructor | |
521ca393 | 64 | sprintf(fHistoFileName," "); |
65 | sprintf(fprefixDA," "); | |
5253c153 | 66 | } |
67 | // AliMUONPedestal& operator=(const AliMUONPedestal& other); Copy ctor | |
68 | ||
69 | //______________________________________________________________________________ | |
70 | AliMUONPedestal::~AliMUONPedestal() | |
71 | { | |
72 | /// Destructor | |
73 | } | |
74 | ||
75 | //______________________________________________________________________________ | |
76 | void AliMUONPedestal::MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, Int_t charge) | |
77 | { | |
78 | /// Compute pedestals values | |
79 | AliMUONVCalibParam* ped = | |
80 | static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId)); | |
81 | ||
82 | if (!ped) { | |
83 | fNManu++; | |
84 | ped = new AliMUONCalibParamND(2, kNChannels,busPatchId, manuId, -1.); // put default wise -1, not connected channel | |
85 | fPedestalStore ->Add(ped); | |
86 | } | |
87 | ||
88 | // Initialization for the first value | |
89 | if (ped->ValueAsDouble(channelId, 0) == -1) ped->SetValueAsDouble(channelId, 0, 0.); | |
90 | if (ped->ValueAsDouble(channelId, 1) == -1) ped->SetValueAsDouble(channelId, 1, 0.); | |
91 | ||
92 | Double_t pedMean = ped->ValueAsDouble(channelId, 0) + (Double_t) charge; | |
93 | Double_t pedSigma = ped->ValueAsDouble(channelId, 1) + (Double_t) charge*charge; | |
94 | ||
95 | ped->SetValueAsDouble(channelId, 0, pedMean); | |
96 | ped->SetValueAsDouble(channelId, 1, pedSigma); | |
97 | } | |
98 | ||
99 | //______________________________________________________________________________ | |
100 | TString AliMUONPedestal::WritePedHeader(void) | |
101 | { | |
102 | /// | |
103 | ||
104 | ostringstream stream; | |
105 | stream<<"//===========================================================================" << endl; | |
106 | stream<<"// Pedestal file calculated by MUONTRKda"<<endl; | |
107 | stream<<"//===========================================================================" << endl; | |
108 | stream<<"// * Run : " << fRunNumber << endl; | |
109 | stream<<"// * Date : " << fDate->AsString("l") <<endl; | |
110 | stream<<"// * Statictics : " << fNEvents << endl; | |
111 | stream<<"// * # of MANUS : " << fNManu << endl; | |
112 | stream<<"// * # of channels : " << fNChannel << endl; | |
113 | if (fErrorBuspatchTable->GetSize()) | |
114 | { | |
115 | stream<<"//"<<endl; | |
116 | stream<<"// * Buspatches with less statistics (due to parity errors)"<<endl; | |
117 | TIterator* iter = fErrorBuspatchTable->MakeIterator(); | |
118 | AliMUONErrorCounter* parityerror; | |
119 | while((parityerror = (AliMUONErrorCounter*) iter->Next())) | |
120 | { | |
121 | stream<<"// bp "<<parityerror->BusPatch()<<" events used "<<fNEvents-parityerror->Events()<<endl; | |
122 | } | |
123 | } | |
124 | stream<<"//"<<endl; | |
125 | stream<<"//---------------------------------------------------------------------------" << endl; | |
126 | stream<<"//---------------------------------------------------------------------------" << endl; | |
127 | stream<<"// BP MANU CH. MEAN SIGMA"<<endl; | |
128 | stream<<"//---------------------------------------------------------------------------" << endl; | |
129 | ||
130 | return TString(stream.str().c_str()); | |
131 | } | |
132 | ||
133 | //______________________________________________________________________________ | |
134 | TString AliMUONPedestal::WritePedData(Int_t BP, Int_t Manu, Int_t ch, Double_t pedMean, Double_t pedSigma) | |
135 | { | |
136 | /// | |
137 | ||
138 | ostringstream stream(""); | |
139 | stream << "\t" << BP << "\t" << Manu <<"\t"<< ch << "\t" | |
140 | << pedMean <<"\t"<< pedSigma << endl; | |
141 | return TString(stream.str().c_str()); | |
142 | ||
143 | } | |
144 | ||
145 | //______________________________________________________________________________ | |
146 | void AliMUONPedestal::MakePedStore(TString shuttleFile_1 = "") | |
147 | { | |
148 | ||
149 | /// Store pedestals in ASCII files | |
150 | Double_t pedMean; | |
151 | Double_t pedSigma; | |
152 | ofstream fileout; | |
153 | #ifdef ALI_AMORE | |
154 | ostringstream stringout; // String to be sent to AMORE_DB | |
155 | #endif | |
156 | TString tempstring; | |
157 | Int_t busPatchId; | |
158 | Int_t manuId; | |
159 | Int_t channelId; | |
160 | ||
161 | // histo | |
162 | TFile* histoFile = 0; | |
163 | TTree* tree = 0; | |
164 | TH1F* pedMeanHisto = 0; | |
165 | TH1F* pedSigmaHisto = 0; | |
166 | ||
167 | if (fIndex<0) // Pedestal run (fIndex=-1) | |
168 | { | |
169 | sprintf(fHistoFileName,"%s_%d.root",fprefixDA,fRunNumber); | |
170 | histoFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking pedestals"); | |
171 | ||
172 | Char_t name[255]; | |
173 | Char_t title[255]; | |
174 | sprintf(name,"pedmean_allch"); | |
175 | sprintf(title,"Pedestal mean all channels"); | |
176 | Int_t nx = 4096; | |
177 | Int_t xmin = 0; | |
178 | Int_t xmax = 4095; | |
179 | pedMeanHisto = new TH1F(name,title,nx,xmin,xmax); | |
180 | pedMeanHisto->SetDirectory(histoFile); | |
181 | ||
182 | sprintf(name,"pedsigma_allch"); | |
183 | sprintf(title,"Pedestal sigma all channels"); | |
184 | nx = 201; | |
185 | xmin = 0; | |
186 | xmax = 200; | |
187 | pedSigmaHisto = new TH1F(name,title,nx,xmin,xmax); | |
188 | pedSigmaHisto->SetDirectory(histoFile); | |
189 | ||
190 | tree = new TTree("t","Pedestal tree"); | |
191 | tree->Branch("bp",&busPatchId,"bp/I"); | |
192 | tree->Branch("manu",&manuId,",manu/I"); | |
193 | tree->Branch("channel",&channelId,",channel/I"); | |
194 | tree->Branch("pedMean",&pedMean,",pedMean/D"); | |
195 | tree->Branch("pedSigma",&pedSigma,",pedSigma/D"); | |
196 | } | |
197 | ||
198 | if (!shuttleFile_1.IsNull()) { | |
199 | fileout.open(shuttleFile_1.Data()); | |
200 | tempstring = WritePedHeader(); | |
201 | fileout << tempstring; | |
202 | #ifdef ALI_AMORE | |
203 | stringout << tempstring; | |
204 | #endif | |
205 | } | |
206 | // print in logfile | |
207 | if (fErrorBuspatchTable->GetSize()) | |
208 | { | |
209 | cout<<"\n* Buspatches with less statistics (due to parity errors)"<<endl; | |
210 | (*fFilcout)<<"\n* Buspatches with less statistics (due to parity errors)"<<endl; | |
211 | TIterator* iter = fErrorBuspatchTable->MakeIterator(); | |
212 | AliMUONErrorCounter* parityerror; | |
213 | while((parityerror = (AliMUONErrorCounter*) iter->Next())) | |
214 | { | |
215 | cout<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl; | |
216 | (*fFilcout)<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl; | |
217 | } | |
218 | ||
219 | } | |
220 | ||
221 | ||
222 | // iterator over pedestal | |
223 | TIter next(fPedestalStore ->CreateIterator()); | |
224 | AliMUONVCalibParam* ped; | |
225 | ||
226 | while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) ) | |
227 | { | |
228 | busPatchId = ped->ID0(); | |
229 | manuId = ped->ID1(); | |
230 | Int_t eventCounter; | |
231 | ||
232 | // Correct the number of events for buspatch with errors | |
233 | char bpname[256]; | |
234 | AliMUONErrorCounter* errorCounter; | |
235 | sprintf(bpname,"bp%d",busPatchId); | |
236 | if ((errorCounter = (AliMUONErrorCounter*)fErrorBuspatchTable->FindObject(bpname))) | |
237 | { | |
238 | eventCounter = fNEvents - errorCounter->Events(); | |
239 | } | |
240 | else | |
241 | { | |
242 | eventCounter = fNEvents; | |
243 | } | |
244 | ||
245 | for (channelId = 0; channelId < ped->Size() ; ++channelId) { | |
246 | pedMean = ped->ValueAsDouble(channelId, 0); | |
247 | ||
248 | if (pedMean > 0) { // connected channels | |
249 | ||
250 | ped->SetValueAsDouble(channelId, 0, pedMean/(Double_t)eventCounter); | |
251 | ||
252 | pedMean = ped->ValueAsDouble(channelId, 0); | |
253 | pedSigma = ped->ValueAsDouble(channelId, 1); | |
254 | ||
255 | ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)eventCounter - pedMean*pedMean))); | |
256 | ||
257 | pedMean = ped->ValueAsDouble(channelId, 0); | |
258 | pedSigma = ped->ValueAsDouble(channelId, 1); | |
259 | ||
260 | ||
261 | if (!shuttleFile_1.IsNull()) { | |
262 | tempstring = WritePedData(busPatchId,manuId,channelId,pedMean,pedSigma); | |
263 | fileout << tempstring; | |
264 | #ifdef ALI_AMORE | |
265 | stringout << tempstring; | |
266 | #endif | |
267 | } | |
268 | if(fIndex<0) // Pedestal Run | |
269 | { | |
270 | pedMeanHisto->Fill(pedMean); | |
271 | pedSigmaHisto->Fill(pedSigma); | |
272 | tree->Fill(); | |
273 | } | |
274 | } | |
275 | } | |
276 | } | |
277 | ||
278 | // file outputs | |
279 | if (!shuttleFile_1.IsNull()) fileout.close(); | |
280 | ||
281 | // Outputs to root file and AMORE DB | |
282 | #ifdef ALI_AMORE | |
283 | // | |
284 | //Send objects to the AMORE DB | |
285 | // | |
286 | const char *role=gSystem->Getenv("AMORE_DA_NAME"); | |
287 | if ( role ){ | |
288 | amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender); | |
289 | // TObjString peddata(stringout.str().c_str()); | |
290 | TObjString peddata(stringout.str().c_str()); | |
291 | Int_t status =0; | |
292 | status = amoreDA.Send("Pedestals",&peddata); | |
293 | if ( status ) | |
294 | cout << "Warning: Failed to write Pedestals in the AMORE database : " << status << endl; | |
295 | } | |
296 | else { | |
297 | cout << "Warning: environment variable 'AMORE_DA_NAME' not set. Cannot write to the AMORE database" << endl; | |
298 | } | |
299 | #endif | |
300 | if(fIndex<0) // Pedestal Run | |
301 | { | |
302 | histoFile->Write(); | |
303 | histoFile->Close(); | |
304 | delete fPedestalStore ; | |
305 | } | |
4af2c34a | 306 | } |