]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPedestal.cxx
Added two missing includes to allow macro compilation (thanks to Laurent for remarkin...
[u/mrichter/AliRoot.git] / MUON / AliMUONPedestal.cxx
CommitLineData
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>
5253c153 25#include <TTimeStamp.h>
26#include <TMath.h>
27#include <TTree.h>
28#include <TFile.h>
29#include <TH1F.h>
30#include <Riostream.h>
31
32#include <sstream>
33
34//-----------------------------------------------------------------------------
35/// \class AliMUONPedestal
36///
37/// Implementation of the pedestal computing
38///
39/// add
40///
41///
42/// \author Alberto Baldisseri, JL Charvet (05/05/2009)
43//-----------------------------------------------------------------------------
44
45/// \cond CLASSIMP
46ClassImp(AliMUONPedestal)
47/// \endcond
48
49//______________________________________________________________________________
50AliMUONPedestal::AliMUONPedestal()
51: TObject(),
5431405e 52fN(0),
5253c153 53fNEvents(0),
54fRunNumber(0),
55fNChannel(0),
56fNManu(0),
1b15b395 57fNManu_config(0),
d9e6dc5e 58fConfig(1),
a54854fc 59fErrorBuspatchTable(new AliMUON2DMap(kFALSE)),
60fManuBuspatchTable(new AliMUON2DMap(kFALSE)),
1b15b395 61fManuBPoutofconfigTable(new AliMUON2DMap(kFALSE)),
5253c153 62fDate(new TTimeStamp()),
63fFilcout(0),
a54854fc 64fPedestalStore(new AliMUON2DMap(kTRUE)),
d9e6dc5e 65fIndex(-1)
5253c153 66{
67/// Default constructor
521ca393 68 sprintf(fHistoFileName," ");
69 sprintf(fprefixDA," ");
5253c153 70}
71// AliMUONPedestal& operator=(const AliMUONPedestal& other); Copy ctor
72
73//______________________________________________________________________________
74AliMUONPedestal::~AliMUONPedestal()
75{
76/// Destructor
a54854fc 77 delete fErrorBuspatchTable;
78 delete fManuBuspatchTable;
dbbb2c64 79 delete fPedestalStore;
1b15b395 80 delete fManuBPoutofconfigTable;
5253c153 81}
82
1b15b395 83//______________________________________________________________________________
84void AliMUONPedestal::Load_config(char* dbfile)
85{
86 /// Load MUONTRK configuration from ascii file "dbfile" (in DetDB)
87
88 Int_t manuId;
89 Int_t busPatchId;
90
91 ifstream fileinit(dbfile,ios::in);
92 while (!fileinit.eof())
93 {
94 fileinit >> busPatchId >> manuId;
95
96 AliMUONErrorCounter* manuCounter;
97 AliMUONVCalibParam* ped =
98 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
99
100 if (!ped) {
101 fNManu_config++;
102 fNChannel+=64;
103 ped = new AliMUONCalibParamND(2, kNChannels,busPatchId, manuId, -1.); // put default wise -1, not connected channel
104 fPedestalStore ->Add(ped);
105
106 if (!(manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId))))
107 {
108 // New (buspatch,manu)
109 manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
110 fManuBuspatchTable->Add(manuCounter);
111 }
112 }
113 }
114}
5253c153 115//______________________________________________________________________________
116void AliMUONPedestal::MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, Int_t charge)
117{
118 /// Compute pedestals values
119 AliMUONVCalibParam* ped =
120 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
121
1b15b395 122 if (!ped)
123 {
124 if(fConfig)
125 { // Fill out_of_config (buspatch,manu) table
126 if (!(static_cast<AliMUONErrorCounter*>(fManuBPoutofconfigTable->FindObject(busPatchId,manuId))))
127 fManuBPoutofconfigTable->Add(new AliMUONErrorCounter(busPatchId,manuId));
128 cout << " !!! WARNING : busPatchId = " << busPatchId << " manuId = " << manuId << " not in the Detector configuration " << endl;
129 }
130 else {fNManu++;}
131 fNChannel+=64;
132 // put default wise -1, not connected channel
133 ped = new AliMUONCalibParamND(2, kNChannels,busPatchId, manuId, -1.);
134 fPedestalStore ->Add(ped);
135 }
5253c153 136
137 // Initialization for the first value
1b15b395 138 if (ped->ValueAsDouble(channelId, 0) == -1)
139 {
140 if(fConfig && channelId == 0){fNManu++;}
141 ped->SetValueAsDouble(channelId, 0, 0.);
142 }
5253c153 143 if (ped->ValueAsDouble(channelId, 1) == -1) ped->SetValueAsDouble(channelId, 1, 0.);
144
145 Double_t pedMean = ped->ValueAsDouble(channelId, 0) + (Double_t) charge;
146 Double_t pedSigma = ped->ValueAsDouble(channelId, 1) + (Double_t) charge*charge;
147
148 ped->SetValueAsDouble(channelId, 0, pedMean);
149 ped->SetValueAsDouble(channelId, 1, pedSigma);
5431405e 150
5431405e 151 AliMUONErrorCounter* manuCounter;
a54854fc 152 if (!(manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId))))
5431405e 153 {
154 // New (buspatch,manu)
155 manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
a54854fc 156 fManuBuspatchTable->Add(manuCounter);
5431405e 157 }
158 else
159 {
160 // Existing buspatch
161 manuCounter->Increment();
162 }
5253c153 163}
5253c153 164//______________________________________________________________________________
dbbb2c64 165void AliMUONPedestal::Finalize()
5253c153 166{
5253c153 167 Double_t pedMean;
168 Double_t pedSigma;
5253c153 169 Int_t busPatchId;
170 Int_t manuId;
171 Int_t channelId;
172
5253c153 173 // print in logfile
174 if (fErrorBuspatchTable->GetSize())
5253c153 175 {
1b15b395 176 cout<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
177 (*fFilcout)<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
178 TIter nextParityError(fErrorBuspatchTable->CreateIterator());
179 AliMUONErrorCounter* parityerror;
180 while((parityerror = static_cast<AliMUONErrorCounter*>(nextParityError())))
181 {
182 cout<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
183 (*fFilcout)<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
184 }
5253c153 185 }
5253c153 186
1b15b395 187 // iterator over pedestal
5253c153 188 TIter next(fPedestalStore ->CreateIterator());
189 AliMUONVCalibParam* ped;
190
191 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
dbbb2c64 192 {
1b15b395 193 busPatchId = ped->ID0();
194 manuId = ped->ID1();
195 if(manuId==0)
196 {
197 cout << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
198 (*fFilcout) << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
199 }
200 Int_t eventCounter;
201 // Correct the number of events for buspatch with errors
202 AliMUONErrorCounter* errorCounter;
203 if ((errorCounter = (AliMUONErrorCounter*)fErrorBuspatchTable->FindObject(busPatchId)))
204 {
205 eventCounter = fNEvents - errorCounter->Events();
206 }
207 else
208 {
209 eventCounter = fNEvents;
210 }
5431405e 211
1b15b395 212 Int_t occupancy=0; // channel missing in raw data or read but rejected (case of parity error)
213 // value of (buspatch, manu) occupancy
214 AliMUONErrorCounter* manuCounter;
215 manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId));
216 if(eventCounter>0)occupancy = manuCounter->Events()/64/eventCounter;
217 if(occupancy>1)
218 {
219 cout << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << " occupancy (>1) = " << occupancy << endl;
220 (*fFilcout) << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << " occupancy (>1) = " << occupancy <<endl;
221 }
5253c153 222
1b15b395 223 for (channelId = 0; channelId < ped->Size() ; ++channelId)
224 {
5431405e 225 pedMean = ped->ValueAsDouble(channelId, 0);
1b15b395 226
227 if (pedMean > 0) // connected channels
228 {
229 ped->SetValueAsDouble(channelId, 0, pedMean/(Double_t)eventCounter);
230 pedMean = ped->ValueAsDouble(channelId, 0);
231 pedSigma = ped->ValueAsDouble(channelId, 1);
232 ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)eventCounter - pedMean*pedMean)));
233 if(manuId == 0)
234 {
235 ped->SetValueAsDouble(channelId, 0, kADCMax);
236 ped->SetValueAsDouble(channelId, 1, kADCMax);
237 }
238 if(occupancy>1)
239 {
240 ped->SetValueAsDouble(channelId, 0, kADCMax);
241 ped->SetValueAsDouble(channelId, 1, kADCMax);
242 if(channelId==0)ped->SetValueAsDouble(channelId, 0, kADCMax+occupancy);
243 }
244 }
245 else
246 {
5431405e 247 ped->SetValueAsDouble(channelId, 0, kADCMax);
248 ped->SetValueAsDouble(channelId, 1, kADCMax);
1b15b395 249 }
250 }
dbbb2c64 251 }
dbbb2c64 252}
dbbb2c64 253//______________________________________________________________________________
254void AliMUONPedestal::MakeASCIIoutput(ostream& out) const
255{
1b15b395 256 /// put pedestal store in the output stream
dbbb2c64 257
258 out<<"//===========================================================================" << endl;
1b15b395 259 out<<"// Pedestal file calculated by "<< fprefixDA << endl;
dbbb2c64 260 out<<"//===========================================================================" << endl;
261 out<<"// * Run : " << fRunNumber << endl;
262 out<<"// * Date : " << fDate->AsString("l") <<endl;
263 out<<"// * Statictics : " << fNEvents << endl;
1b15b395 264 if(fConfig)
265 out<<"// * # of MANUS : " << fNManu_config << " read in the Det. config. " << endl;
266 out<<"// * # of MANUS : " << fNManu << " read in raw data " << endl;
267 out<<"// * # of MANUS : " << fNChannel/64 << " written in pedestal file " << endl;
dbbb2c64 268 out<<"// * # of channels : " << fNChannel << endl;
269 if (fErrorBuspatchTable->GetSize())
dbbb2c64 270 {
1b15b395 271 out<<"//"<<endl;
272 out<<"// * Buspatches with less statistics (due to parity errors)"<<endl;
273 TIter next(fErrorBuspatchTable->CreateIterator());
274 AliMUONErrorCounter* parityerror;
275 while((parityerror = static_cast<AliMUONErrorCounter*>(next())))
276 {
277 out<<"// BusPatch = "<<parityerror->BusPatch()<<"\t Nevents used = "<<fNEvents-parityerror->Events()<<endl;
278 }
279 }
280
281 out<<"//"<<endl;
282 out<<"// * Puzzling (Buspatch,Manu) read in raw data ?"<<endl;
283 Int_t occupancy=1;
284 if(occupancy){
285 TIter next(fPedestalStore ->CreateIterator());
286 AliMUONVCalibParam* ped;
287 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
288 {
289 Int_t busPatchId = ped->ID0();
290 Int_t manuId = ped->ID1();
291 Double_t pedMean = ped->ValueAsDouble(0, 0); // check pedestal value for channelId=0
292
293 if(pedMean>kADCMax)
294 {
295 occupancy=pedMean-kADCMax;
296 ped->SetValueAsDouble(0, 0, kADCMax);
297 out<<"// BusPatch = "<< busPatchId <<"\t ManuId = "<< manuId << "\t occupancy = " << occupancy <<endl;
298 }
299
300 if (manuId==0 || (fConfig && static_cast<AliMUONErrorCounter*>(fManuBPoutofconfigTable->FindObject(busPatchId,manuId))))
301 {
302 out<<"// BusPatch = "<< busPatchId <<"\t ManuId = "<< manuId << "\t missing in the mapping" << endl;
303 }
dbbb2c64 304 }
1b15b395 305}
306
307
dbbb2c64 308 out<<"//"<<endl;
309 out<<"//---------------------------------------------------------------------------" << endl;
310 out<<"//---------------------------------------------------------------------------" << endl;
311 out<<"// BP MANU CH. MEAN SIGMA"<<endl;
312 out<<"//---------------------------------------------------------------------------" << endl;
5253c153 313
dbbb2c64 314 // iterator over pedestal
315 TIter next(fPedestalStore ->CreateIterator());
316 AliMUONVCalibParam* ped;
317
318 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
dbbb2c64 319 {
1b15b395 320 Int_t busPatchId = ped->ID0();
321 Int_t manuId = ped->ID1();
322
323 for ( Int_t channelId = 0; channelId < ped->Size(); ++channelId )
324 {
325 Double_t pedMean = ped->ValueAsDouble(channelId, 0);
326 Double_t pedSigma = ped->ValueAsDouble(channelId, 1);
327
328 out << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t" << pedMean <<"\t"<< pedSigma << endl;
329 }
5253c153 330 }
dbbb2c64 331}
332
333//______________________________________________________________________________
334void AliMUONPedestal::MakeControlHistos()
335{
5253c153 336
dbbb2c64 337 if (fIndex>=0) return; // Pedestal run (fIndex=-1)
338
339 Double_t pedMean;
340 Double_t pedSigma;
341 Int_t busPatchId;
342 Int_t manuId;
343 Int_t channelId;
344
345// histo
346 TFile* histoFile = 0;
347 TTree* tree = 0;
348 TH1F* pedMeanHisto = 0;
349 TH1F* pedSigmaHisto = 0;
350
351 sprintf(fHistoFileName,"%s.root",fprefixDA);
352 histoFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking pedestals");
353
354 Char_t name[255];
355 Char_t title[255];
356 sprintf(name,"pedmean_allch");
357 sprintf(title,"Pedestal mean all channels");
358 Int_t nx = kADCMax+1;
359 Int_t xmin = 0;
360 Int_t xmax = kADCMax;
361 pedMeanHisto = new TH1F(name,title,nx,xmin,xmax);
362 pedMeanHisto->SetDirectory(histoFile);
363
364 sprintf(name,"pedsigma_allch");
365 sprintf(title,"Pedestal sigma all channels");
366 nx = 201;
367 xmin = 0;
368 xmax = 200;
369 pedSigmaHisto = new TH1F(name,title,nx,xmin,xmax);
370 pedSigmaHisto->SetDirectory(histoFile);
371
372 tree = new TTree("t","Pedestal tree");
373 tree->Branch("bp",&busPatchId,"bp/I");
374 tree->Branch("manu",&manuId,",manu/I");
375 tree->Branch("channel",&channelId,",channel/I");
376 tree->Branch("pedMean",&pedMean,",pedMean/D");
377 tree->Branch("pedSigma",&pedSigma,",pedSigma/D");
378
379 // iterator over pedestal
380 TIter next(fPedestalStore ->CreateIterator());
381 AliMUONVCalibParam* ped;
382
383 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
384 {
385 busPatchId = ped->ID0();
386 manuId = ped->ID1();
387
388 for ( channelId = 0; channelId < ped->Size(); ++channelId )
389 {
390 pedMean = ped->ValueAsDouble(channelId, 0);
391 pedSigma = ped->ValueAsDouble(channelId, 1);
392
393 pedMeanHisto->Fill(pedMean);
394 pedSigmaHisto->Fill(pedSigma);
395 tree->Fill();
396 }
5253c153 397 }
dbbb2c64 398
399 histoFile->Write();
400 histoFile->Close();
401
4af2c34a 402}