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)
101 // NO NEED ANYMORE : change configuration tested by the Shuttle (from 16/02/10)
103 // getline(filein, line, '\n');
104 // cout << " line 1: " << line ;
105 // if ( int(line[0]) == 35 ) // ascii code of # character
107 // cout << " ==> 1st caracter = " << line[0] << " (ascii code =" << int(line[0]) << ")" << endl;
110 // { filein.clear(); filein.seekg(0); // rewind
111 // cout << " ==> rewind configuration file: "<< dbfile << endl;
114 while (!filein.eof())
116 filein >> busPatchId >> manuId;
118 AliMUONErrorCounter* manuCounter;
119 AliMUONVCalibParam* ped =
120 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
125 ped = new AliMUONCalibParamND(2, AliMpConstants::ManuNofChannels(),busPatchId, manuId, -1.); // put default wise -1, not connected channel
126 fPedestalStore ->Add(ped);
128 if (!(manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId))))
130 // New (buspatch,manu)
131 manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
132 fManuBuspatchTable->Add(manuCounter);
137 //______________________________________________________________________________
138 void AliMUONPedestal::MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, Int_t charge)
141 /// Compute pedestals values
142 AliMUONVCalibParam* ped =
143 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
148 { // Fill out_of_config (buspatch,manu) table
149 if (!(static_cast<AliMUONErrorCounter*>(fManuBPoutofconfigTable->FindObject(busPatchId,manuId))))
150 fManuBPoutofconfigTable->Add(new AliMUONErrorCounter(busPatchId,manuId));
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;
154 (*fFilcout) << " !!! WARNING : busPatchId = " << busPatchId << " manuId = " << manuId << " not in the Detector configuration " << endl;
158 // put default wise -1, not connected channel
159 ped = new AliMUONCalibParamND(2, AliMpConstants::ManuNofChannels(),busPatchId, manuId, -1.);
160 fPedestalStore ->Add(ped);
163 // Initialization for the first value
164 if (ped->ValueAsDouble(channelId, 0) == -1)
166 if(fConfig && channelId == 0){fNManu++;}
167 ped->SetValueAsDouble(channelId, 0, 0.);
169 if (ped->ValueAsDouble(channelId, 1) == -1) ped->SetValueAsDouble(channelId, 1, 0.);
171 Double_t pedMean = ped->ValueAsDouble(channelId, 0) + (Double_t) charge;
172 Double_t pedSigma = ped->ValueAsDouble(channelId, 1) + (Double_t) charge*charge;
174 ped->SetValueAsDouble(channelId, 0, pedMean);
175 ped->SetValueAsDouble(channelId, 1, pedSigma);
177 AliMUONErrorCounter* manuCounter;
178 if (!(manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId))))
180 // New (buspatch,manu)
181 manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
182 fManuBuspatchTable->Add(manuCounter);
187 manuCounter->Increment();
190 //______________________________________________________________________________
191 void AliMUONPedestal::Finalize()
193 /// final polishing of the store
202 if (fErrorBuspatchTable->GetSize())
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())))
210 cout<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
211 (*fFilcout)<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
215 // iterator over pedestal
216 TIter next(fPedestalStore ->CreateIterator());
217 AliMUONVCalibParam* ped;
219 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
221 busPatchId = ped->ID0();
225 cout << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
226 (*fFilcout) << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
229 // Correct the number of events for buspatch with errors
230 AliMUONErrorCounter* errorCounter;
231 if ((errorCounter = (AliMUONErrorCounter*)fErrorBuspatchTable->FindObject(busPatchId)))
233 eventCounter = fNEvents - errorCounter->Events();
237 eventCounter = fNEvents;
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;
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;
251 for (channelId = 0; channelId < ped->Size() ; ++channelId)
253 pedMean = ped->ValueAsDouble(channelId, 0);
255 if (pedMean > 0) // connected channels
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)));
263 ped->SetValueAsDouble(channelId, 0, ADCMax());
264 ped->SetValueAsDouble(channelId, 1, ADCMax());
268 ped->SetValueAsDouble(channelId, 0, ADCMax());
269 ped->SetValueAsDouble(channelId, 1, ADCMax());
270 if(channelId==0)ped->SetValueAsDouble(channelId, 0, ADCMax()+occupancy);
275 ped->SetValueAsDouble(channelId, 0, ADCMax());
276 ped->SetValueAsDouble(channelId, 1, ADCMax());
281 //______________________________________________________________________________
282 void AliMUONPedestal::MakeASCIIoutput(ostream& out) const
284 /// put pedestal store in the output stream
286 out<<"//===========================================================================" << endl;
287 out<<"// Pedestal file calculated by "<< fPrefixDA.Data() << endl;
288 out<<"//===========================================================================" << endl;
289 out<<"// * Run : " << fRunNumber << endl;
290 out<<"// * Date : " << fDate->AsString("l") <<endl;
291 out<<"// * Statictics : " << fNEvents << endl;
293 out<<"// * # of MANUS : " << fNManuConfig << " read in the Det. config. " << endl;
294 out<<"// * # of MANUS : " << fNManu << " read in raw data " << endl;
295 out<<"// * # of MANUS : " << fNChannel/64 << " written in pedestal file " << endl;
296 out<<"// * # of channels : " << fNChannel << endl;
297 if (fErrorBuspatchTable->GetSize())
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())))
305 out<<"// BusPatch = "<<parityerror->BusPatch()<<"\t Nevents used = "<<fNEvents-parityerror->Events()<<endl;
310 // out<<"// * Puzzling (Buspatch,Manu) read in raw data ?"<<endl;
315 TIter next(fPedestalStore ->CreateIterator());
316 AliMUONVCalibParam* ped;
317 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
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
328 out<<"// * Puzzling (Buspatch,Manu) read in raw data ?"<<endl;}
329 occupancy=TMath::Nint(pedMean-ADCMax());
330 ped->SetValueAsDouble(0, 0, ADCMax());
331 out<<"// BusPatch = "<< busPatchId <<"\t ManuId = "<< manuId << "\t occupancy = " << occupancy <<endl;
334 if (manuId==0 || (fConfig && static_cast<AliMUONErrorCounter*>(fManuBPoutofconfigTable->FindObject(busPatchId,manuId))))
339 out<<"// * Puzzling (Buspatch,Manu) read in raw data ?"<<endl;}
340 out<<"// BusPatch = "<< busPatchId <<"\t ManuId = "<< manuId << "\t missing in the mapping" << endl;
347 out<<"//---------------------------------------------------------------------------" << endl;
348 out<<"//---------------------------------------------------------------------------" << endl;
349 out<<"// BP MANU CH. MEAN SIGMA"<<endl;
350 out<<"//---------------------------------------------------------------------------" << endl;
352 // iterator over pedestal
353 TIter next(fPedestalStore ->CreateIterator());
354 AliMUONVCalibParam* ped;
356 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
358 Int_t busPatchId = ped->ID0();
359 Int_t manuId = ped->ID1();
361 for ( Int_t channelId = 0; channelId < ped->Size(); ++channelId )
363 Double_t pedMean = ped->ValueAsDouble(channelId, 0);
364 Double_t pedSigma = ped->ValueAsDouble(channelId, 1);
366 out << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t" << pedMean <<"\t"<< pedSigma << endl;
371 //______________________________________________________________________________
372 void AliMUONPedestal::MakeControlHistos()
374 /// Create control histograms
375 if (fIndex>=0) return; // Pedestal run (fIndex=-1)
384 TFile* histoFile = 0;
386 TH1F* pedMeanHisto = 0;
387 TH1F* pedSigmaHisto = 0;
389 fHistoFileName=Form("%s.root",fPrefixDA.Data());
390 histoFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking pedestals");
394 sprintf(name,"pedmean_allch");
395 sprintf(title,"Pedestal mean all channels");
396 Int_t nx = ADCMax()+1;
398 Int_t xmax = ADCMax();
399 pedMeanHisto = new TH1F(name,title,nx,xmin,xmax);
400 pedMeanHisto->SetDirectory(histoFile);
402 sprintf(name,"pedsigma_allch");
403 sprintf(title,"Pedestal sigma all channels");
407 pedSigmaHisto = new TH1F(name,title,nx,xmin,xmax);
408 pedSigmaHisto->SetDirectory(histoFile);
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");
417 // iterator over pedestal
418 TIter next(fPedestalStore ->CreateIterator());
419 AliMUONVCalibParam* ped;
421 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
423 busPatchId = ped->ID0();
426 for ( channelId = 0; channelId < ped->Size(); ++channelId )
428 pedMean = ped->ValueAsDouble(channelId, 0);
429 pedSigma = ped->ValueAsDouble(channelId, 1);
431 pedMeanHisto->Fill(pedMean);
432 pedSigmaHisto->Fill(pedSigma);