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()
57 fErrorBuspatchTable(new AliMUON2DMap(kFALSE)),
58 fManuBuspatchTable(new AliMUON2DMap(kFALSE)),
59 fDate(new TTimeStamp()),
61 fPedestalStore(new AliMUON2DMap(kTRUE)),
64 /// Default constructor
65 sprintf(fHistoFileName," ");
66 sprintf(fprefixDA," ");
68 // AliMUONPedestal& operator=(const AliMUONPedestal& other); Copy ctor
70 //______________________________________________________________________________
71 AliMUONPedestal::~AliMUONPedestal()
74 delete fErrorBuspatchTable;
75 delete fManuBuspatchTable;
76 delete fPedestalStore;
79 //______________________________________________________________________________
80 void AliMUONPedestal::MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, Int_t charge)
82 /// Compute pedestals values
83 AliMUONVCalibParam* ped =
84 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
88 ped = new AliMUONCalibParamND(2, kNChannels,busPatchId, manuId, -1.); // put default wise -1, not connected channel
89 fPedestalStore ->Add(ped);
92 // Initialization for the first value
93 if (ped->ValueAsDouble(channelId, 0) == -1) ped->SetValueAsDouble(channelId, 0, 0.);
94 if (ped->ValueAsDouble(channelId, 1) == -1) ped->SetValueAsDouble(channelId, 1, 0.);
96 Double_t pedMean = ped->ValueAsDouble(channelId, 0) + (Double_t) charge;
97 Double_t pedSigma = ped->ValueAsDouble(channelId, 1) + (Double_t) charge*charge;
99 ped->SetValueAsDouble(channelId, 0, pedMean);
100 ped->SetValueAsDouble(channelId, 1, pedSigma);
102 AliMUONErrorCounter* manuCounter;
103 if (!(manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId))))
105 // New (buspatch,manu)
106 manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
107 fManuBuspatchTable->Add(manuCounter);
112 manuCounter->Increment();
116 //______________________________________________________________________________
117 void AliMUONPedestal::Finalize()
126 if (fErrorBuspatchTable->GetSize())
128 cout<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
129 (*fFilcout)<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
130 TIter nextParityError(fErrorBuspatchTable->CreateIterator());
131 AliMUONErrorCounter* parityerror;
132 while((parityerror = static_cast<AliMUONErrorCounter*>(nextParityError())))
134 cout<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
135 (*fFilcout)<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
139 // iterator over pedestal
140 TIter next(fPedestalStore ->CreateIterator());
141 AliMUONVCalibParam* ped;
143 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
145 busPatchId = ped->ID0();
149 cout << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
150 (*fFilcout) << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
153 // Correct the number of events for buspatch with errors
154 AliMUONErrorCounter* errorCounter;
155 if ((errorCounter = (AliMUONErrorCounter*)fErrorBuspatchTable->FindObject(busPatchId)))
157 eventCounter = fNEvents - errorCounter->Events();
161 eventCounter = fNEvents;
165 // value of (buspatch, manu) occupancy
166 AliMUONErrorCounter* manuCounter;
167 manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId));
168 occupancy = manuCounter->Events()/64/eventCounter;
171 cout << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << " occupancy (>1) = " << occupancy << endl;
172 (*fFilcout) << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << " occupancy (>1) = " << occupancy <<endl;
175 for (channelId = 0; channelId < ped->Size() ; ++channelId)
177 pedMean = ped->ValueAsDouble(channelId, 0);
179 if (pedMean > 0) // connected channels
181 ped->SetValueAsDouble(channelId, 0, pedMean/(Double_t)eventCounter);
182 pedMean = ped->ValueAsDouble(channelId, 0);
183 pedSigma = ped->ValueAsDouble(channelId, 1);
184 ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)eventCounter - pedMean*pedMean)));
185 if(manuId == 0 || occupancy>1)
187 ped->SetValueAsDouble(channelId, 0, kADCMax);
188 ped->SetValueAsDouble(channelId, 1, kADCMax);
193 ped->SetValueAsDouble(channelId, 0, kADCMax);
194 ped->SetValueAsDouble(channelId, 1, kADCMax);
200 //______________________________________________________________________________
201 void AliMUONPedestal::MakeASCIIoutput(ostream& out) const
203 /// put pedestal store in the output stream
205 out<<"//===========================================================================" << endl;
206 out<<"// Pedestal file calculated by MUONTRKda"<<endl;
207 out<<"//===========================================================================" << endl;
208 out<<"// * Run : " << fRunNumber << endl;
209 out<<"// * Date : " << fDate->AsString("l") <<endl;
210 out<<"// * Statictics : " << fNEvents << endl;
211 out<<"// * # of MANUS : " << fNManu << endl;
212 out<<"// * # of channels : " << fNChannel << endl;
213 if (fErrorBuspatchTable->GetSize())
216 out<<"// * Buspatches with less statistics (due to parity errors)"<<endl;
217 TIter next(fErrorBuspatchTable->CreateIterator());
218 AliMUONErrorCounter* parityerror;
219 while((parityerror = static_cast<AliMUONErrorCounter*>(next())))
221 out<<"// bp "<<parityerror->BusPatch()<<" events used "<<fNEvents-parityerror->Events()<<endl;
225 out<<"//---------------------------------------------------------------------------" << endl;
226 out<<"//---------------------------------------------------------------------------" << endl;
227 out<<"// BP MANU CH. MEAN SIGMA"<<endl;
228 out<<"//---------------------------------------------------------------------------" << endl;
230 // iterator over pedestal
231 TIter next(fPedestalStore ->CreateIterator());
232 AliMUONVCalibParam* ped;
234 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
236 Int_t busPatchId = ped->ID0();
237 Int_t manuId = ped->ID1();
239 for ( Int_t channelId = 0; channelId < ped->Size(); ++channelId )
241 Double_t pedMean = ped->ValueAsDouble(channelId, 0);
242 Double_t pedSigma = ped->ValueAsDouble(channelId, 1);
244 out << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t" << pedMean <<"\t"<< pedSigma << endl;
249 //______________________________________________________________________________
250 void AliMUONPedestal::MakeControlHistos()
253 if (fIndex>=0) return; // Pedestal run (fIndex=-1)
262 TFile* histoFile = 0;
264 TH1F* pedMeanHisto = 0;
265 TH1F* pedSigmaHisto = 0;
267 sprintf(fHistoFileName,"%s.root",fprefixDA);
268 histoFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking pedestals");
272 sprintf(name,"pedmean_allch");
273 sprintf(title,"Pedestal mean all channels");
274 Int_t nx = kADCMax+1;
276 Int_t xmax = kADCMax;
277 pedMeanHisto = new TH1F(name,title,nx,xmin,xmax);
278 pedMeanHisto->SetDirectory(histoFile);
280 sprintf(name,"pedsigma_allch");
281 sprintf(title,"Pedestal sigma all channels");
285 pedSigmaHisto = new TH1F(name,title,nx,xmin,xmax);
286 pedSigmaHisto->SetDirectory(histoFile);
288 tree = new TTree("t","Pedestal tree");
289 tree->Branch("bp",&busPatchId,"bp/I");
290 tree->Branch("manu",&manuId,",manu/I");
291 tree->Branch("channel",&channelId,",channel/I");
292 tree->Branch("pedMean",&pedMean,",pedMean/D");
293 tree->Branch("pedSigma",&pedSigma,",pedSigma/D");
295 // iterator over pedestal
296 TIter next(fPedestalStore ->CreateIterator());
297 AliMUONVCalibParam* ped;
299 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
301 busPatchId = ped->ID0();
304 for ( channelId = 0; channelId < ped->Size(); ++channelId )
306 pedMean = ped->ValueAsDouble(channelId, 0);
307 pedSigma = ped->ValueAsDouble(channelId, 1);
309 pedMeanHisto->Fill(pedMean);
310 pedSigmaHisto->Fill(pedSigma);