]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPedestal.cxx
Updated test script and added macros for running with Geant4.
[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"
f3cfa63e 23#include "AliMpConstants.h"
5253c153 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(),
f3cfa63e 52//fN(0),
5253c153 53fNEvents(0),
54fRunNumber(0),
55fNChannel(0),
56fNManu(0),
f3cfa63e 57fNManuConfig(0),
d9e6dc5e 58fConfig(1),
a54854fc 59fErrorBuspatchTable(new AliMUON2DMap(kFALSE)),
60fManuBuspatchTable(new AliMUON2DMap(kFALSE)),
1b15b395 61fManuBPoutofconfigTable(new AliMUON2DMap(kFALSE)),
5253c153 62fDate(new TTimeStamp()),
63fFilcout(0),
f3cfa63e 64fHistoFileName(),
a54854fc 65fPedestalStore(new AliMUON2DMap(kTRUE)),
f3cfa63e 66fIndex(-1),
67fPrefixDA()
5253c153 68{
69/// Default constructor
5253c153 70}
5253c153 71
72//______________________________________________________________________________
73AliMUONPedestal::~AliMUONPedestal()
74{
75/// Destructor
a54854fc 76 delete fErrorBuspatchTable;
77 delete fManuBuspatchTable;
dbbb2c64 78 delete fPedestalStore;
1b15b395 79 delete fManuBPoutofconfigTable;
5253c153 80}
81
1b15b395 82//______________________________________________________________________________
f3cfa63e 83const char*
84AliMUONPedestal::GetHistoFileName() const
85{
86 /// Return the name of file we use to store histograms
87 return fHistoFileName.Data();
88}
89
90//______________________________________________________________________________
91void AliMUONPedestal::LoadConfig(const char* dbfile)
1b15b395 92{
93 /// Load MUONTRK configuration from ascii file "dbfile" (in DetDB)
94
95 Int_t manuId;
96 Int_t busPatchId;
97
f3cfa63e 98 ifstream filein(dbfile,ios::in);
99
100 // check if the 1st caracter of the 1st line is # (Config read from the OCDB => OffLine)
b9c33bca 101 // NO NEED ANYMORE : change configuration tested by the Shuttle (from 16/02/10)
102// string line;
103// getline(filein, line, '\n');
104// cout << " line 1: " << line ;
105// if ( int(line[0]) == 35 ) // ascii code of # character
106// {
107// cout << " ==> 1st caracter = " << line[0] << " (ascii code =" << int(line[0]) << ")" << endl;
108// }
109// else
110// { filein.clear(); filein.seekg(0); // rewind
111// cout << " ==> rewind configuration file: "<< dbfile << endl;
112// }
f3cfa63e 113
114 while (!filein.eof())
1b15b395 115 {
f3cfa63e 116 filein >> busPatchId >> manuId;
1b15b395 117
118 AliMUONErrorCounter* manuCounter;
119 AliMUONVCalibParam* ped =
120 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
121
122 if (!ped) {
f3cfa63e 123 fNManuConfig++;
1b15b395 124 fNChannel+=64;
f3cfa63e 125 ped = new AliMUONCalibParamND(2, AliMpConstants::ManuNofChannels(),busPatchId, manuId, -1.); // put default wise -1, not connected channel
1b15b395 126 fPedestalStore ->Add(ped);
127
128 if (!(manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId))))
129 {
130 // New (buspatch,manu)
131 manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
132 fManuBuspatchTable->Add(manuCounter);
133 }
134 }
135 }
136}
5253c153 137//______________________________________________________________________________
138void AliMUONPedestal::MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, Int_t charge)
139{
b9c33bca 140 static Int_t warn=0;
5253c153 141 /// Compute pedestals values
142 AliMUONVCalibParam* ped =
143 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
144
1b15b395 145 if (!ped)
146 {
147 if(fConfig)
148 { // Fill out_of_config (buspatch,manu) table
149 if (!(static_cast<AliMUONErrorCounter*>(fManuBPoutofconfigTable->FindObject(busPatchId,manuId))))
150 fManuBPoutofconfigTable->Add(new AliMUONErrorCounter(busPatchId,manuId));
b9c33bca 151 if(warn<10) cout << " !!! WARNING : busPatchId = " << busPatchId << " manuId = " << manuId << " not in the Detector configuration " << endl;
152 else if(warn==10) cout << " !!! see .log file for an exhaustive list of (busPatchId, manuId) out of Detector configuration \n" << endl;
153 warn++;
154 (*fFilcout) << " !!! WARNING : busPatchId = " << busPatchId << " manuId = " << manuId << " not in the Detector configuration " << endl;
1b15b395 155 }
156 else {fNManu++;}
157 fNChannel+=64;
158 // put default wise -1, not connected channel
f3cfa63e 159 ped = new AliMUONCalibParamND(2, AliMpConstants::ManuNofChannels(),busPatchId, manuId, -1.);
1b15b395 160 fPedestalStore ->Add(ped);
161 }
5253c153 162
163 // Initialization for the first value
1b15b395 164 if (ped->ValueAsDouble(channelId, 0) == -1)
165 {
166 if(fConfig && channelId == 0){fNManu++;}
167 ped->SetValueAsDouble(channelId, 0, 0.);
168 }
5253c153 169 if (ped->ValueAsDouble(channelId, 1) == -1) ped->SetValueAsDouble(channelId, 1, 0.);
170
171 Double_t pedMean = ped->ValueAsDouble(channelId, 0) + (Double_t) charge;
172 Double_t pedSigma = ped->ValueAsDouble(channelId, 1) + (Double_t) charge*charge;
173
174 ped->SetValueAsDouble(channelId, 0, pedMean);
175 ped->SetValueAsDouble(channelId, 1, pedSigma);
5431405e 176
5431405e 177 AliMUONErrorCounter* manuCounter;
a54854fc 178 if (!(manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId))))
5431405e 179 {
180 // New (buspatch,manu)
181 manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
a54854fc 182 fManuBuspatchTable->Add(manuCounter);
5431405e 183 }
184 else
185 {
186 // Existing buspatch
187 manuCounter->Increment();
188 }
5253c153 189}
5253c153 190//______________________________________________________________________________
dbbb2c64 191void AliMUONPedestal::Finalize()
5253c153 192{
f3cfa63e 193 /// final polishing of the store
194
5253c153 195 Double_t pedMean;
196 Double_t pedSigma;
5253c153 197 Int_t busPatchId;
198 Int_t manuId;
199 Int_t channelId;
200
5253c153 201 // print in logfile
202 if (fErrorBuspatchTable->GetSize())
5253c153 203 {
1b15b395 204 cout<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
205 (*fFilcout)<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
206 TIter nextParityError(fErrorBuspatchTable->CreateIterator());
207 AliMUONErrorCounter* parityerror;
208 while((parityerror = static_cast<AliMUONErrorCounter*>(nextParityError())))
209 {
210 cout<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
211 (*fFilcout)<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
212 }
5253c153 213 }
5253c153 214
1b15b395 215 // iterator over pedestal
5253c153 216 TIter next(fPedestalStore ->CreateIterator());
217 AliMUONVCalibParam* ped;
218
219 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
dbbb2c64 220 {
1b15b395 221 busPatchId = ped->ID0();
222 manuId = ped->ID1();
223 if(manuId==0)
224 {
225 cout << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
226 (*fFilcout) << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
227 }
228 Int_t eventCounter;
229 // Correct the number of events for buspatch with errors
230 AliMUONErrorCounter* errorCounter;
231 if ((errorCounter = (AliMUONErrorCounter*)fErrorBuspatchTable->FindObject(busPatchId)))
232 {
233 eventCounter = fNEvents - errorCounter->Events();
234 }
235 else
236 {
237 eventCounter = fNEvents;
238 }
5431405e 239
1b15b395 240 Int_t occupancy=0; // channel missing in raw data or read but rejected (case of parity error)
241 // value of (buspatch, manu) occupancy
242 AliMUONErrorCounter* manuCounter;
243 manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId));
244 if(eventCounter>0)occupancy = manuCounter->Events()/64/eventCounter;
245 if(occupancy>1)
246 {
247 cout << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << " occupancy (>1) = " << occupancy << endl;
248 (*fFilcout) << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << " occupancy (>1) = " << occupancy <<endl;
249 }
5253c153 250
1b15b395 251 for (channelId = 0; channelId < ped->Size() ; ++channelId)
252 {
5431405e 253 pedMean = ped->ValueAsDouble(channelId, 0);
1b15b395 254
255 if (pedMean > 0) // connected channels
256 {
257 ped->SetValueAsDouble(channelId, 0, pedMean/(Double_t)eventCounter);
258 pedMean = ped->ValueAsDouble(channelId, 0);
259 pedSigma = ped->ValueAsDouble(channelId, 1);
260 ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)eventCounter - pedMean*pedMean)));
261 if(manuId == 0)
262 {
f3cfa63e 263 ped->SetValueAsDouble(channelId, 0, ADCMax());
264 ped->SetValueAsDouble(channelId, 1, ADCMax());
1b15b395 265 }
266 if(occupancy>1)
267 {
f3cfa63e 268 ped->SetValueAsDouble(channelId, 0, ADCMax());
269 ped->SetValueAsDouble(channelId, 1, ADCMax());
270 if(channelId==0)ped->SetValueAsDouble(channelId, 0, ADCMax()+occupancy);
1b15b395 271 }
272 }
273 else
274 {
f3cfa63e 275 ped->SetValueAsDouble(channelId, 0, ADCMax());
276 ped->SetValueAsDouble(channelId, 1, ADCMax());
1b15b395 277 }
278 }
dbbb2c64 279 }
dbbb2c64 280}
dbbb2c64 281//______________________________________________________________________________
282void AliMUONPedestal::MakeASCIIoutput(ostream& out) const
283{
1b15b395 284 /// put pedestal store in the output stream
dbbb2c64 285
286 out<<"//===========================================================================" << endl;
f3cfa63e 287 out<<"// Pedestal file calculated by "<< fPrefixDA.Data() << endl;
dbbb2c64 288 out<<"//===========================================================================" << endl;
289 out<<"// * Run : " << fRunNumber << endl;
290 out<<"// * Date : " << fDate->AsString("l") <<endl;
291 out<<"// * Statictics : " << fNEvents << endl;
1b15b395 292 if(fConfig)
f3cfa63e 293 out<<"// * # of MANUS : " << fNManuConfig << " read in the Det. config. " << endl;
1b15b395 294 out<<"// * # of MANUS : " << fNManu << " read in raw data " << endl;
295 out<<"// * # of MANUS : " << fNChannel/64 << " written in pedestal file " << endl;
dbbb2c64 296 out<<"// * # of channels : " << fNChannel << endl;
297 if (fErrorBuspatchTable->GetSize())
dbbb2c64 298 {
1b15b395 299 out<<"//"<<endl;
300 out<<"// * Buspatches with less statistics (due to parity errors)"<<endl;
301 TIter next(fErrorBuspatchTable->CreateIterator());
302 AliMUONErrorCounter* parityerror;
303 while((parityerror = static_cast<AliMUONErrorCounter*>(next())))
304 {
305 out<<"// BusPatch = "<<parityerror->BusPatch()<<"\t Nevents used = "<<fNEvents-parityerror->Events()<<endl;
306 }
307 }
308
f3cfa63e 309// out<<"//"<<endl;
310// out<<"// * Puzzling (Buspatch,Manu) read in raw data ?"<<endl;
311 Int_t writitle=0;
312 Int_t occupancy=1;
313 if(occupancy)
1b15b395 314 {
f3cfa63e 315 TIter next(fPedestalStore ->CreateIterator());
316 AliMUONVCalibParam* ped;
317 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
1b15b395 318 {
f3cfa63e 319 Int_t busPatchId = ped->ID0();
320 Int_t manuId = ped->ID1();
321 Double_t pedMean = ped->ValueAsDouble(0, 0); // check pedestal value for channelId=0
1b15b395 322
f3cfa63e 323 if(pedMean>ADCMax())
324 {
325 writitle++;
326 if(writitle==1){
327 out<<"//"<<endl;
328 out<<"// * Puzzling (Buspatch,Manu) read in raw data ?"<<endl;}
1ccd531d 329 occupancy=TMath::Nint(pedMean-ADCMax());
f3cfa63e 330 ped->SetValueAsDouble(0, 0, ADCMax());
331 out<<"// BusPatch = "<< busPatchId <<"\t ManuId = "<< manuId << "\t occupancy = " << occupancy <<endl;
332 }
333
334 if (manuId==0 || (fConfig && static_cast<AliMUONErrorCounter*>(fManuBPoutofconfigTable->FindObject(busPatchId,manuId))))
335 {
336 writitle++;
337 if(writitle==1){
338 out<<"//"<<endl;
339 out<<"// * Puzzling (Buspatch,Manu) read in raw data ?"<<endl;}
340 out<<"// BusPatch = "<< busPatchId <<"\t ManuId = "<< manuId << "\t missing in the mapping" << endl;
341 }
1b15b395 342 }
dbbb2c64 343 }
1b15b395 344
345
dbbb2c64 346 out<<"//"<<endl;
347 out<<"//---------------------------------------------------------------------------" << endl;
348 out<<"//---------------------------------------------------------------------------" << endl;
349 out<<"// BP MANU CH. MEAN SIGMA"<<endl;
350 out<<"//---------------------------------------------------------------------------" << endl;
5253c153 351
dbbb2c64 352 // iterator over pedestal
353 TIter next(fPedestalStore ->CreateIterator());
354 AliMUONVCalibParam* ped;
355
356 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
dbbb2c64 357 {
1b15b395 358 Int_t busPatchId = ped->ID0();
359 Int_t manuId = ped->ID1();
360
361 for ( Int_t channelId = 0; channelId < ped->Size(); ++channelId )
362 {
363 Double_t pedMean = ped->ValueAsDouble(channelId, 0);
364 Double_t pedSigma = ped->ValueAsDouble(channelId, 1);
365
366 out << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t" << pedMean <<"\t"<< pedSigma << endl;
367 }
5253c153 368 }
dbbb2c64 369}
370
371//______________________________________________________________________________
372void AliMUONPedestal::MakeControlHistos()
373{
f3cfa63e 374 /// Create control histograms
dbbb2c64 375 if (fIndex>=0) return; // Pedestal run (fIndex=-1)
376
377 Double_t pedMean;
378 Double_t pedSigma;
379 Int_t busPatchId;
380 Int_t manuId;
381 Int_t channelId;
382
383// histo
384 TFile* histoFile = 0;
385 TTree* tree = 0;
386 TH1F* pedMeanHisto = 0;
387 TH1F* pedSigmaHisto = 0;
388
f3cfa63e 389 fHistoFileName=Form("%s.root",fPrefixDA.Data());
dbbb2c64 390 histoFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking pedestals");
391
392 Char_t name[255];
393 Char_t title[255];
394 sprintf(name,"pedmean_allch");
395 sprintf(title,"Pedestal mean all channels");
f3cfa63e 396 Int_t nx = ADCMax()+1;
dbbb2c64 397 Int_t xmin = 0;
f3cfa63e 398 Int_t xmax = ADCMax();
dbbb2c64 399 pedMeanHisto = new TH1F(name,title,nx,xmin,xmax);
400 pedMeanHisto->SetDirectory(histoFile);
401
402 sprintf(name,"pedsigma_allch");
403 sprintf(title,"Pedestal sigma all channels");
404 nx = 201;
405 xmin = 0;
406 xmax = 200;
407 pedSigmaHisto = new TH1F(name,title,nx,xmin,xmax);
408 pedSigmaHisto->SetDirectory(histoFile);
409
410 tree = new TTree("t","Pedestal tree");
411 tree->Branch("bp",&busPatchId,"bp/I");
412 tree->Branch("manu",&manuId,",manu/I");
413 tree->Branch("channel",&channelId,",channel/I");
414 tree->Branch("pedMean",&pedMean,",pedMean/D");
415 tree->Branch("pedSigma",&pedSigma,",pedSigma/D");
416
417 // iterator over pedestal
418 TIter next(fPedestalStore ->CreateIterator());
419 AliMUONVCalibParam* ped;
420
421 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
422 {
423 busPatchId = ped->ID0();
424 manuId = ped->ID1();
425
426 for ( channelId = 0; channelId < ped->Size(); ++channelId )
427 {
428 pedMean = ped->ValueAsDouble(channelId, 0);
429 pedSigma = ped->ValueAsDouble(channelId, 1);
430
431 pedMeanHisto->Fill(pedMean);
432 pedSigmaHisto->Fill(pedSigma);
433 tree->Fill();
434 }
5253c153 435 }
dbbb2c64 436
437 histoFile->Write();
438 histoFile->Close();
439
4af2c34a 440}