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 <THashTable.h>
26 #include <THashList.h>
27 #include <TTimeStamp.h>
32 #include <Riostream.h>
36 //-----------------------------------------------------------------------------
37 /// \class AliMUONPedestal
39 /// Implementation of the pedestal computing
44 /// \author Alberto Baldisseri, JL Charvet (05/05/2009)
45 //-----------------------------------------------------------------------------
48 ClassImp(AliMUONPedestal)
51 //______________________________________________________________________________
52 AliMUONPedestal::AliMUONPedestal()
59 fErrorBuspatchTable(new THashTable(100,2)),
60 fManuBuspatchTable(new THashTable(100,2)),
61 fDate(new TTimeStamp()),
63 fPedestalStore(new AliMUON2DMap(kFALSE)),
66 /// Default constructor
67 sprintf(fHistoFileName," ");
68 sprintf(fprefixDA," ");
70 // AliMUONPedestal& operator=(const AliMUONPedestal& other); Copy ctor
72 //______________________________________________________________________________
73 AliMUONPedestal::~AliMUONPedestal()
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 char bpmanuname[256];
103 AliMUONErrorCounter* manuCounter;
104 sprintf(bpmanuname,"bp%dmanu%d",busPatchId,manuId);
105 if (!(manuCounter = (AliMUONErrorCounter*)GetManuBuspatchTable()->FindObject(bpmanuname)))
107 // New (buspatch,manu)
108 manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
109 manuCounter->SetName(bpmanuname);
110 GetManuBuspatchTable()->Add(manuCounter);
115 manuCounter->Increment();
119 //______________________________________________________________________________
120 void AliMUONPedestal::Finalize()
129 if (fErrorBuspatchTable->GetSize())
131 cout<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
132 (*fFilcout)<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
133 TIterator* iter = fErrorBuspatchTable->MakeIterator();
134 AliMUONErrorCounter* parityerror;
135 while((parityerror = (AliMUONErrorCounter*) iter->Next()))
137 cout<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
138 (*fFilcout)<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
143 // iterator over pedestal
144 TIter next(fPedestalStore ->CreateIterator());
145 AliMUONVCalibParam* ped;
147 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
149 busPatchId = ped->ID0();
153 cout << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
154 (*fFilcout) << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
157 // Correct the number of events for buspatch with errors
159 AliMUONErrorCounter* errorCounter;
160 sprintf(bpname,"bp%d",busPatchId);
161 if ((errorCounter = (AliMUONErrorCounter*)fErrorBuspatchTable->FindObject(bpname)))
163 eventCounter = fNEvents - errorCounter->Events();
167 eventCounter = fNEvents;
171 // value of (buspatch, manu) occupancy
172 char bpmanuname[256];
173 AliMUONErrorCounter* manuCounter;
174 sprintf(bpmanuname,"bp%dmanu%d",busPatchId,manuId);
175 manuCounter = (AliMUONErrorCounter*)fManuBuspatchTable->FindObject(bpmanuname);
176 occupancy = manuCounter->Events()/64/eventCounter;
179 cout << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << " occupancy (>1) = " << occupancy << endl;
180 (*fFilcout) << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << " occupancy (>1) = " << occupancy <<endl;
183 for (channelId = 0; channelId < ped->Size() ; ++channelId)
185 pedMean = ped->ValueAsDouble(channelId, 0);
187 if (pedMean > 0) // connected channels
189 ped->SetValueAsDouble(channelId, 0, pedMean/(Double_t)eventCounter);
190 pedMean = ped->ValueAsDouble(channelId, 0);
191 pedSigma = ped->ValueAsDouble(channelId, 1);
192 ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)eventCounter - pedMean*pedMean)));
193 if(manuId == 0 || occupancy>1)
195 ped->SetValueAsDouble(channelId, 0, kADCMax);
196 ped->SetValueAsDouble(channelId, 1, kADCMax);
201 ped->SetValueAsDouble(channelId, 0, kADCMax);
202 ped->SetValueAsDouble(channelId, 1, kADCMax);
208 //______________________________________________________________________________
209 void AliMUONPedestal::MakeASCIIoutput(ostream& out) const
211 /// put pedestal store in the output stream
213 out<<"//===========================================================================" << endl;
214 out<<"// Pedestal file calculated by MUONTRKda"<<endl;
215 out<<"//===========================================================================" << endl;
216 out<<"// * Run : " << fRunNumber << endl;
217 out<<"// * Date : " << fDate->AsString("l") <<endl;
218 out<<"// * Statictics : " << fNEvents << endl;
219 out<<"// * # of MANUS : " << fNManu << endl;
220 out<<"// * # of channels : " << fNChannel << endl;
221 if (fErrorBuspatchTable->GetSize())
224 out<<"// * Buspatches with less statistics (due to parity errors)"<<endl;
225 TIterator* iter = fErrorBuspatchTable->MakeIterator();
226 AliMUONErrorCounter* parityerror;
227 while((parityerror = (AliMUONErrorCounter*) iter->Next()))
229 out<<"// bp "<<parityerror->BusPatch()<<" events used "<<fNEvents-parityerror->Events()<<endl;
233 out<<"//---------------------------------------------------------------------------" << endl;
234 out<<"//---------------------------------------------------------------------------" << endl;
235 out<<"// BP MANU CH. MEAN SIGMA"<<endl;
236 out<<"//---------------------------------------------------------------------------" << endl;
238 // iterator over pedestal
239 TIter next(fPedestalStore ->CreateIterator());
240 AliMUONVCalibParam* ped;
242 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
244 Int_t busPatchId = ped->ID0();
245 Int_t manuId = ped->ID1();
247 for ( Int_t channelId = 0; channelId < ped->Size(); ++channelId )
249 Double_t pedMean = ped->ValueAsDouble(channelId, 0);
250 Double_t pedSigma = ped->ValueAsDouble(channelId, 1);
252 out << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t" << pedMean <<"\t"<< pedSigma << endl;
257 //______________________________________________________________________________
258 void AliMUONPedestal::MakeControlHistos()
261 if (fIndex>=0) return; // Pedestal run (fIndex=-1)
270 TFile* histoFile = 0;
272 TH1F* pedMeanHisto = 0;
273 TH1F* pedSigmaHisto = 0;
275 sprintf(fHistoFileName,"%s.root",fprefixDA);
276 histoFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking pedestals");
280 sprintf(name,"pedmean_allch");
281 sprintf(title,"Pedestal mean all channels");
282 Int_t nx = kADCMax+1;
284 Int_t xmax = kADCMax;
285 pedMeanHisto = new TH1F(name,title,nx,xmin,xmax);
286 pedMeanHisto->SetDirectory(histoFile);
288 sprintf(name,"pedsigma_allch");
289 sprintf(title,"Pedestal sigma all channels");
293 pedSigmaHisto = new TH1F(name,title,nx,xmin,xmax);
294 pedSigmaHisto->SetDirectory(histoFile);
296 tree = new TTree("t","Pedestal tree");
297 tree->Branch("bp",&busPatchId,"bp/I");
298 tree->Branch("manu",&manuId,",manu/I");
299 tree->Branch("channel",&channelId,",channel/I");
300 tree->Branch("pedMean",&pedMean,",pedMean/D");
301 tree->Branch("pedSigma",&pedSigma,",pedSigma/D");
303 // iterator over pedestal
304 TIter next(fPedestalStore ->CreateIterator());
305 AliMUONVCalibParam* ped;
307 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
309 busPatchId = ped->ID0();
312 for ( channelId = 0; channelId < ped->Size(); ++channelId )
314 pedMean = ped->ValueAsDouble(channelId, 0);
315 pedSigma = ped->ValueAsDouble(channelId, 1);
317 pedMeanHisto->Fill(pedMean);
318 pedSigmaHisto->Fill(pedSigma);