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