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"
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()),
64 fPedestalStore(new AliMUON2DMap(kTRUE)),
67 /// Default constructor
68 sprintf(fHistoFileName," ");
69 sprintf(fprefixDA," ");
71 // AliMUONPedestal& operator=(const AliMUONPedestal& other); Copy ctor
73 //______________________________________________________________________________
74 AliMUONPedestal::~AliMUONPedestal()
77 delete fErrorBuspatchTable;
78 delete fManuBuspatchTable;
79 delete fPedestalStore;
80 delete fManuBPoutofconfigTable;
83 //______________________________________________________________________________
84 void AliMUONPedestal::Load_config(char* dbfile)
86 /// Load MUONTRK configuration from ascii file "dbfile" (in DetDB)
91 ifstream fileinit(dbfile,ios::in);
92 while (!fileinit.eof())
94 fileinit >> busPatchId >> manuId;
96 AliMUONErrorCounter* manuCounter;
97 AliMUONVCalibParam* ped =
98 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
103 ped = new AliMUONCalibParamND(2, kNChannels,busPatchId, manuId, -1.); // put default wise -1, not connected channel
104 fPedestalStore ->Add(ped);
106 if (!(manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId))))
108 // New (buspatch,manu)
109 manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
110 fManuBuspatchTable->Add(manuCounter);
115 //______________________________________________________________________________
116 void AliMUONPedestal::MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, Int_t charge)
118 /// Compute pedestals values
119 AliMUONVCalibParam* ped =
120 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
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;
132 // put default wise -1, not connected channel
133 ped = new AliMUONCalibParamND(2, kNChannels,busPatchId, manuId, -1.);
134 fPedestalStore ->Add(ped);
137 // Initialization for the first value
138 if (ped->ValueAsDouble(channelId, 0) == -1)
140 if(fConfig && channelId == 0){fNManu++;}
141 ped->SetValueAsDouble(channelId, 0, 0.);
143 if (ped->ValueAsDouble(channelId, 1) == -1) ped->SetValueAsDouble(channelId, 1, 0.);
145 Double_t pedMean = ped->ValueAsDouble(channelId, 0) + (Double_t) charge;
146 Double_t pedSigma = ped->ValueAsDouble(channelId, 1) + (Double_t) charge*charge;
148 ped->SetValueAsDouble(channelId, 0, pedMean);
149 ped->SetValueAsDouble(channelId, 1, pedSigma);
151 AliMUONErrorCounter* manuCounter;
152 if (!(manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId))))
154 // New (buspatch,manu)
155 manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
156 fManuBuspatchTable->Add(manuCounter);
161 manuCounter->Increment();
164 //______________________________________________________________________________
165 void AliMUONPedestal::Finalize()
174 if (fErrorBuspatchTable->GetSize())
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())))
182 cout<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
183 (*fFilcout)<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
187 // iterator over pedestal
188 TIter next(fPedestalStore ->CreateIterator());
189 AliMUONVCalibParam* ped;
191 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
193 busPatchId = ped->ID0();
197 cout << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
198 (*fFilcout) << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
201 // Correct the number of events for buspatch with errors
202 AliMUONErrorCounter* errorCounter;
203 if ((errorCounter = (AliMUONErrorCounter*)fErrorBuspatchTable->FindObject(busPatchId)))
205 eventCounter = fNEvents - errorCounter->Events();
209 eventCounter = fNEvents;
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;
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;
223 for (channelId = 0; channelId < ped->Size() ; ++channelId)
225 pedMean = ped->ValueAsDouble(channelId, 0);
227 if (pedMean > 0) // connected channels
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)));
235 ped->SetValueAsDouble(channelId, 0, kADCMax);
236 ped->SetValueAsDouble(channelId, 1, kADCMax);
240 ped->SetValueAsDouble(channelId, 0, kADCMax);
241 ped->SetValueAsDouble(channelId, 1, kADCMax);
242 if(channelId==0)ped->SetValueAsDouble(channelId, 0, kADCMax+occupancy);
247 ped->SetValueAsDouble(channelId, 0, kADCMax);
248 ped->SetValueAsDouble(channelId, 1, kADCMax);
253 //______________________________________________________________________________
254 void AliMUONPedestal::MakeASCIIoutput(ostream& out) const
256 /// put pedestal store in the output stream
258 out<<"//===========================================================================" << endl;
259 out<<"// Pedestal file calculated by "<< fprefixDA << endl;
260 out<<"//===========================================================================" << endl;
261 out<<"// * Run : " << fRunNumber << endl;
262 out<<"// * Date : " << fDate->AsString("l") <<endl;
263 out<<"// * Statictics : " << fNEvents << endl;
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;
268 out<<"// * # of channels : " << fNChannel << endl;
269 if (fErrorBuspatchTable->GetSize())
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())))
277 out<<"// BusPatch = "<<parityerror->BusPatch()<<"\t Nevents used = "<<fNEvents-parityerror->Events()<<endl;
282 out<<"// * Puzzling (Buspatch,Manu) read in raw data ?"<<endl;
285 TIter next(fPedestalStore ->CreateIterator());
286 AliMUONVCalibParam* ped;
287 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
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
295 occupancy=pedMean-kADCMax;
296 ped->SetValueAsDouble(0, 0, kADCMax);
297 out<<"// BusPatch = "<< busPatchId <<"\t ManuId = "<< manuId << "\t occupancy = " << occupancy <<endl;
300 if (manuId==0 || (fConfig && static_cast<AliMUONErrorCounter*>(fManuBPoutofconfigTable->FindObject(busPatchId,manuId))))
302 out<<"// BusPatch = "<< busPatchId <<"\t ManuId = "<< manuId << "\t missing in the mapping" << endl;
309 out<<"//---------------------------------------------------------------------------" << endl;
310 out<<"//---------------------------------------------------------------------------" << endl;
311 out<<"// BP MANU CH. MEAN SIGMA"<<endl;
312 out<<"//---------------------------------------------------------------------------" << endl;
314 // iterator over pedestal
315 TIter next(fPedestalStore ->CreateIterator());
316 AliMUONVCalibParam* ped;
318 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
320 Int_t busPatchId = ped->ID0();
321 Int_t manuId = ped->ID1();
323 for ( Int_t channelId = 0; channelId < ped->Size(); ++channelId )
325 Double_t pedMean = ped->ValueAsDouble(channelId, 0);
326 Double_t pedSigma = ped->ValueAsDouble(channelId, 1);
328 out << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t" << pedMean <<"\t"<< pedSigma << endl;
333 //______________________________________________________________________________
334 void AliMUONPedestal::MakeControlHistos()
337 if (fIndex>=0) return; // Pedestal run (fIndex=-1)
346 TFile* histoFile = 0;
348 TH1F* pedMeanHisto = 0;
349 TH1F* pedSigmaHisto = 0;
351 sprintf(fHistoFileName,"%s.root",fprefixDA);
352 histoFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking pedestals");
356 sprintf(name,"pedmean_allch");
357 sprintf(title,"Pedestal mean all channels");
358 Int_t nx = kADCMax+1;
360 Int_t xmax = kADCMax;
361 pedMeanHisto = new TH1F(name,title,nx,xmin,xmax);
362 pedMeanHisto->SetDirectory(histoFile);
364 sprintf(name,"pedsigma_allch");
365 sprintf(title,"Pedestal sigma all channels");
369 pedSigmaHisto = new TH1F(name,title,nx,xmin,xmax);
370 pedSigmaHisto->SetDirectory(histoFile);
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");
379 // iterator over pedestal
380 TIter next(fPedestalStore ->CreateIterator());
381 AliMUONVCalibParam* ped;
383 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
385 busPatchId = ped->ID0();
388 for ( channelId = 0; channelId < ped->Size(); ++channelId )
390 pedMean = ped->ValueAsDouble(channelId, 0);
391 pedSigma = ped->ValueAsDouble(channelId, 1);
393 pedMeanHisto->Fill(pedMean);
394 pedSigmaHisto->Fill(pedSigma);