1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONPedestal.h"
19 #include "AliMUONErrorCounter.h"
20 #include "AliMUONVStore.h"
21 #include "AliMUON2DMap.h"
22 #include "AliMUONCalibParamND.h"
23 #include "AliMpConstants.h"
25 #include <TTimeStamp.h>
30 #include <Riostream.h>
34 //-----------------------------------------------------------------------------
35 /// \class AliMUONPedestal
37 /// Implementation of the pedestal computing
42 /// \author Alberto Baldisseri, JL Charvet (05/05/2009)
43 //-----------------------------------------------------------------------------
46 ClassImp(AliMUONPedestal)
49 //______________________________________________________________________________
50 AliMUONPedestal::AliMUONPedestal()
59 fErrorBuspatchTable(new AliMUON2DMap(kFALSE)),
60 fManuBuspatchTable(new AliMUON2DMap(kFALSE)),
61 fManuBPoutofconfigTable(new AliMUON2DMap(kFALSE)),
62 fDate(new TTimeStamp()),
65 fPedestalStore(new AliMUON2DMap(kTRUE)),
69 /// Default constructor
72 //______________________________________________________________________________
73 AliMUONPedestal::~AliMUONPedestal()
76 delete fErrorBuspatchTable;
77 delete fManuBuspatchTable;
78 delete fPedestalStore;
79 delete fManuBPoutofconfigTable;
82 //______________________________________________________________________________
84 AliMUONPedestal::GetHistoFileName() const
86 /// Return the name of file we use to store histograms
87 return fHistoFileName.Data();
90 //______________________________________________________________________________
91 void AliMUONPedestal::LoadConfig(const char* dbfile)
93 /// Load MUONTRK configuration from ascii file "dbfile" (in DetDB)
98 ifstream filein(dbfile,ios::in);
100 // check if the 1st caracter of the 1st line is # (Config read from the OCDB => OffLine)
102 getline(filein, line, '\n');
103 cout << " line 1: " << line ;
104 if ( int(line[0]) == 35 ) // ascii code of # character
106 cout << " ==> 1st caracter = " << line[0] << " (ascii code =" << int(line[0]) << ")" << endl;
109 { filein.clear(); filein.seekg(0); // rewind
110 cout << " ==> rewind configuration file: "<< dbfile << endl;
113 while (!filein.eof())
115 filein >> busPatchId >> manuId;
117 AliMUONErrorCounter* manuCounter;
118 AliMUONVCalibParam* ped =
119 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
124 ped = new AliMUONCalibParamND(2, AliMpConstants::ManuNofChannels(),busPatchId, manuId, -1.); // put default wise -1, not connected channel
125 fPedestalStore ->Add(ped);
127 if (!(manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId))))
129 // New (buspatch,manu)
130 manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
131 fManuBuspatchTable->Add(manuCounter);
136 //______________________________________________________________________________
137 void AliMUONPedestal::MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, Int_t charge)
139 /// Compute pedestals values
140 AliMUONVCalibParam* ped =
141 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
146 { // Fill out_of_config (buspatch,manu) table
147 if (!(static_cast<AliMUONErrorCounter*>(fManuBPoutofconfigTable->FindObject(busPatchId,manuId))))
148 fManuBPoutofconfigTable->Add(new AliMUONErrorCounter(busPatchId,manuId));
149 cout << " !!! WARNING : busPatchId = " << busPatchId << " manuId = " << manuId << " not in the Detector configuration " << endl;
153 // put default wise -1, not connected channel
154 ped = new AliMUONCalibParamND(2, AliMpConstants::ManuNofChannels(),busPatchId, manuId, -1.);
155 fPedestalStore ->Add(ped);
158 // Initialization for the first value
159 if (ped->ValueAsDouble(channelId, 0) == -1)
161 if(fConfig && channelId == 0){fNManu++;}
162 ped->SetValueAsDouble(channelId, 0, 0.);
164 if (ped->ValueAsDouble(channelId, 1) == -1) ped->SetValueAsDouble(channelId, 1, 0.);
166 Double_t pedMean = ped->ValueAsDouble(channelId, 0) + (Double_t) charge;
167 Double_t pedSigma = ped->ValueAsDouble(channelId, 1) + (Double_t) charge*charge;
169 ped->SetValueAsDouble(channelId, 0, pedMean);
170 ped->SetValueAsDouble(channelId, 1, pedSigma);
172 AliMUONErrorCounter* manuCounter;
173 if (!(manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId))))
175 // New (buspatch,manu)
176 manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
177 fManuBuspatchTable->Add(manuCounter);
182 manuCounter->Increment();
185 //______________________________________________________________________________
186 void AliMUONPedestal::Finalize()
188 /// final polishing of the store
197 if (fErrorBuspatchTable->GetSize())
199 cout<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
200 (*fFilcout)<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
201 TIter nextParityError(fErrorBuspatchTable->CreateIterator());
202 AliMUONErrorCounter* parityerror;
203 while((parityerror = static_cast<AliMUONErrorCounter*>(nextParityError())))
205 cout<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
206 (*fFilcout)<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
210 // iterator over pedestal
211 TIter next(fPedestalStore ->CreateIterator());
212 AliMUONVCalibParam* ped;
214 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
216 busPatchId = ped->ID0();
220 cout << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
221 (*fFilcout) << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
224 // Correct the number of events for buspatch with errors
225 AliMUONErrorCounter* errorCounter;
226 if ((errorCounter = (AliMUONErrorCounter*)fErrorBuspatchTable->FindObject(busPatchId)))
228 eventCounter = fNEvents - errorCounter->Events();
232 eventCounter = fNEvents;
235 Int_t occupancy=0; // channel missing in raw data or read but rejected (case of parity error)
236 // value of (buspatch, manu) occupancy
237 AliMUONErrorCounter* manuCounter;
238 manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId));
239 if(eventCounter>0)occupancy = manuCounter->Events()/64/eventCounter;
242 cout << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << " occupancy (>1) = " << occupancy << endl;
243 (*fFilcout) << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << " occupancy (>1) = " << occupancy <<endl;
246 for (channelId = 0; channelId < ped->Size() ; ++channelId)
248 pedMean = ped->ValueAsDouble(channelId, 0);
250 if (pedMean > 0) // connected channels
252 ped->SetValueAsDouble(channelId, 0, pedMean/(Double_t)eventCounter);
253 pedMean = ped->ValueAsDouble(channelId, 0);
254 pedSigma = ped->ValueAsDouble(channelId, 1);
255 ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)eventCounter - pedMean*pedMean)));
258 ped->SetValueAsDouble(channelId, 0, ADCMax());
259 ped->SetValueAsDouble(channelId, 1, ADCMax());
263 ped->SetValueAsDouble(channelId, 0, ADCMax());
264 ped->SetValueAsDouble(channelId, 1, ADCMax());
265 if(channelId==0)ped->SetValueAsDouble(channelId, 0, ADCMax()+occupancy);
270 ped->SetValueAsDouble(channelId, 0, ADCMax());
271 ped->SetValueAsDouble(channelId, 1, ADCMax());
276 //______________________________________________________________________________
277 void AliMUONPedestal::MakeASCIIoutput(ostream& out) const
279 /// put pedestal store in the output stream
281 out<<"//===========================================================================" << endl;
282 out<<"// Pedestal file calculated by "<< fPrefixDA.Data() << endl;
283 out<<"//===========================================================================" << endl;
284 out<<"// * Run : " << fRunNumber << endl;
285 out<<"// * Date : " << fDate->AsString("l") <<endl;
286 out<<"// * Statictics : " << fNEvents << endl;
288 out<<"// * # of MANUS : " << fNManuConfig << " read in the Det. config. " << endl;
289 out<<"// * # of MANUS : " << fNManu << " read in raw data " << endl;
290 out<<"// * # of MANUS : " << fNChannel/64 << " written in pedestal file " << endl;
291 out<<"// * # of channels : " << fNChannel << endl;
292 if (fErrorBuspatchTable->GetSize())
295 out<<"// * Buspatches with less statistics (due to parity errors)"<<endl;
296 TIter next(fErrorBuspatchTable->CreateIterator());
297 AliMUONErrorCounter* parityerror;
298 while((parityerror = static_cast<AliMUONErrorCounter*>(next())))
300 out<<"// BusPatch = "<<parityerror->BusPatch()<<"\t Nevents used = "<<fNEvents-parityerror->Events()<<endl;
305 // out<<"// * Puzzling (Buspatch,Manu) read in raw data ?"<<endl;
310 TIter next(fPedestalStore ->CreateIterator());
311 AliMUONVCalibParam* ped;
312 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
314 Int_t busPatchId = ped->ID0();
315 Int_t manuId = ped->ID1();
316 Double_t pedMean = ped->ValueAsDouble(0, 0); // check pedestal value for channelId=0
323 out<<"// * Puzzling (Buspatch,Manu) read in raw data ?"<<endl;}
324 occupancy=pedMean-ADCMax();
325 ped->SetValueAsDouble(0, 0, ADCMax());
326 out<<"// BusPatch = "<< busPatchId <<"\t ManuId = "<< manuId << "\t occupancy = " << occupancy <<endl;
329 if (manuId==0 || (fConfig && static_cast<AliMUONErrorCounter*>(fManuBPoutofconfigTable->FindObject(busPatchId,manuId))))
334 out<<"// * Puzzling (Buspatch,Manu) read in raw data ?"<<endl;}
335 out<<"// BusPatch = "<< busPatchId <<"\t ManuId = "<< manuId << "\t missing in the mapping" << endl;
342 out<<"//---------------------------------------------------------------------------" << endl;
343 out<<"//---------------------------------------------------------------------------" << endl;
344 out<<"// BP MANU CH. MEAN SIGMA"<<endl;
345 out<<"//---------------------------------------------------------------------------" << endl;
347 // iterator over pedestal
348 TIter next(fPedestalStore ->CreateIterator());
349 AliMUONVCalibParam* ped;
351 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
353 Int_t busPatchId = ped->ID0();
354 Int_t manuId = ped->ID1();
356 for ( Int_t channelId = 0; channelId < ped->Size(); ++channelId )
358 Double_t pedMean = ped->ValueAsDouble(channelId, 0);
359 Double_t pedSigma = ped->ValueAsDouble(channelId, 1);
361 out << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t" << pedMean <<"\t"<< pedSigma << endl;
366 //______________________________________________________________________________
367 void AliMUONPedestal::MakeControlHistos()
369 /// Create control histograms
370 if (fIndex>=0) return; // Pedestal run (fIndex=-1)
379 TFile* histoFile = 0;
381 TH1F* pedMeanHisto = 0;
382 TH1F* pedSigmaHisto = 0;
384 fHistoFileName=Form("%s.root",fPrefixDA.Data());
385 histoFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking pedestals");
389 sprintf(name,"pedmean_allch");
390 sprintf(title,"Pedestal mean all channels");
391 Int_t nx = ADCMax()+1;
393 Int_t xmax = ADCMax();
394 pedMeanHisto = new TH1F(name,title,nx,xmin,xmax);
395 pedMeanHisto->SetDirectory(histoFile);
397 sprintf(name,"pedsigma_allch");
398 sprintf(title,"Pedestal sigma all channels");
402 pedSigmaHisto = new TH1F(name,title,nx,xmin,xmax);
403 pedSigmaHisto->SetDirectory(histoFile);
405 tree = new TTree("t","Pedestal tree");
406 tree->Branch("bp",&busPatchId,"bp/I");
407 tree->Branch("manu",&manuId,",manu/I");
408 tree->Branch("channel",&channelId,",channel/I");
409 tree->Branch("pedMean",&pedMean,",pedMean/D");
410 tree->Branch("pedSigma",&pedSigma,",pedSigma/D");
412 // iterator over pedestal
413 TIter next(fPedestalStore ->CreateIterator());
414 AliMUONVCalibParam* ped;
416 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
418 busPatchId = ped->ID0();
421 for ( channelId = 0; channelId < ped->Size(); ++channelId )
423 pedMean = ped->ValueAsDouble(channelId, 0);
424 pedSigma = ped->ValueAsDouble(channelId, 1);
426 pedMeanHisto->Fill(pedMean);
427 pedSigmaHisto->Fill(pedSigma);