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>
43 //-----------------------------------------------------------------------------
44 /// \class AliMUONPedestal
46 /// Implementation of the pedestal computing
51 /// \author Alberto Baldisseri, JL Charvet (05/05/2009)
52 //-----------------------------------------------------------------------------
55 ClassImp(AliMUONPedestal)
58 //______________________________________________________________________________
59 AliMUONPedestal::AliMUONPedestal()
66 fErrorBuspatchTable(new THashTable(100,2)),
67 fManuBuspatchTable(new THashTable(100,2)),
68 fDate(new TTimeStamp()),
70 fPedestalStore(new AliMUON2DMap(kFALSE)),
73 /// Default constructor
74 sprintf(fHistoFileName," ");
75 sprintf(fprefixDA," ");
77 // AliMUONPedestal& operator=(const AliMUONPedestal& other); Copy ctor
79 //______________________________________________________________________________
80 AliMUONPedestal::~AliMUONPedestal()
85 //______________________________________________________________________________
86 void AliMUONPedestal::MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, Int_t charge)
88 /// Compute pedestals values
89 AliMUONVCalibParam* ped =
90 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
94 ped = new AliMUONCalibParamND(2, kNChannels,busPatchId, manuId, -1.); // put default wise -1, not connected channel
95 fPedestalStore ->Add(ped);
98 // Initialization for the first value
99 if (ped->ValueAsDouble(channelId, 0) == -1) ped->SetValueAsDouble(channelId, 0, 0.);
100 if (ped->ValueAsDouble(channelId, 1) == -1) ped->SetValueAsDouble(channelId, 1, 0.);
102 Double_t pedMean = ped->ValueAsDouble(channelId, 0) + (Double_t) charge;
103 Double_t pedSigma = ped->ValueAsDouble(channelId, 1) + (Double_t) charge*charge;
105 ped->SetValueAsDouble(channelId, 0, pedMean);
106 ped->SetValueAsDouble(channelId, 1, pedSigma);
108 char bpmanuname[256];
109 AliMUONErrorCounter* manuCounter;
110 sprintf(bpmanuname,"bp%dmanu%d",busPatchId,manuId);
111 if (!(manuCounter = (AliMUONErrorCounter*)GetManuBuspatchTable()->FindObject(bpmanuname)))
113 // New (buspatch,manu)
114 manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
115 manuCounter->SetName(bpmanuname);
116 GetManuBuspatchTable()->Add(manuCounter);
121 manuCounter->Increment();
125 //______________________________________________________________________________
126 TString AliMUONPedestal::WritePedHeader(void)
130 ostringstream stream;
131 stream<<"//===========================================================================" << endl;
132 stream<<"// Pedestal file calculated by MUONTRKda"<<endl;
133 stream<<"//===========================================================================" << endl;
134 stream<<"// * Run : " << fRunNumber << endl;
135 stream<<"// * Date : " << fDate->AsString("l") <<endl;
136 stream<<"// * Statictics : " << fNEvents << endl;
137 stream<<"// * # of MANUS : " << fNManu << endl;
138 stream<<"// * # of channels : " << fNChannel << endl;
139 if (fErrorBuspatchTable->GetSize())
142 stream<<"// * Buspatches with less statistics (due to parity errors)"<<endl;
143 TIterator* iter = fErrorBuspatchTable->MakeIterator();
144 AliMUONErrorCounter* parityerror;
145 while((parityerror = (AliMUONErrorCounter*) iter->Next()))
147 stream<<"// bp "<<parityerror->BusPatch()<<" events used "<<fNEvents-parityerror->Events()<<endl;
151 stream<<"//---------------------------------------------------------------------------" << endl;
152 stream<<"//---------------------------------------------------------------------------" << endl;
153 stream<<"// BP MANU CH. MEAN SIGMA"<<endl;
154 stream<<"//---------------------------------------------------------------------------" << endl;
156 return TString(stream.str().c_str());
159 //______________________________________________________________________________
160 TString AliMUONPedestal::WritePedData(Int_t BP, Int_t Manu, Int_t ch, Double_t pedMean, Double_t pedSigma)
164 ostringstream stream("");
165 stream << "\t" << BP << "\t" << Manu <<"\t"<< ch << "\t"
166 << pedMean <<"\t"<< pedSigma << endl;
167 return TString(stream.str().c_str());
171 //______________________________________________________________________________
172 void AliMUONPedestal::MakePedStore(TString shuttleFile_1 = "")
175 /// Store pedestals in ASCII files
180 ostringstream stringout; // String to be sent to AMORE_DB
188 TFile* histoFile = 0;
190 TH1F* pedMeanHisto = 0;
191 TH1F* pedSigmaHisto = 0;
193 if (fIndex<0) // Pedestal run (fIndex=-1)
195 sprintf(fHistoFileName,"%s.root",fprefixDA);
196 histoFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking pedestals");
200 sprintf(name,"pedmean_allch");
201 sprintf(title,"Pedestal mean all channels");
202 Int_t nx = kADCMax+1;
204 Int_t xmax = kADCMax;
205 pedMeanHisto = new TH1F(name,title,nx,xmin,xmax);
206 pedMeanHisto->SetDirectory(histoFile);
208 sprintf(name,"pedsigma_allch");
209 sprintf(title,"Pedestal sigma all channels");
213 pedSigmaHisto = new TH1F(name,title,nx,xmin,xmax);
214 pedSigmaHisto->SetDirectory(histoFile);
216 tree = new TTree("t","Pedestal tree");
217 tree->Branch("bp",&busPatchId,"bp/I");
218 tree->Branch("manu",&manuId,",manu/I");
219 tree->Branch("channel",&channelId,",channel/I");
220 tree->Branch("pedMean",&pedMean,",pedMean/D");
221 tree->Branch("pedSigma",&pedSigma,",pedSigma/D");
224 if (!shuttleFile_1.IsNull()) {
225 fileout.open(shuttleFile_1.Data());
226 tempstring = WritePedHeader();
227 fileout << tempstring;
229 stringout << tempstring;
233 if (fErrorBuspatchTable->GetSize())
235 cout<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
236 (*fFilcout)<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
237 TIterator* iter = fErrorBuspatchTable->MakeIterator();
238 AliMUONErrorCounter* parityerror;
239 while((parityerror = (AliMUONErrorCounter*) iter->Next()))
241 cout<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
242 (*fFilcout)<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
248 // iterator over pedestal
249 TIter next(fPedestalStore ->CreateIterator());
250 AliMUONVCalibParam* ped;
252 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
254 busPatchId = ped->ID0();
258 cout << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
259 (*fFilcout) << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
262 // Correct the number of events for buspatch with errors
264 AliMUONErrorCounter* errorCounter;
265 sprintf(bpname,"bp%d",busPatchId);
266 if ((errorCounter = (AliMUONErrorCounter*)fErrorBuspatchTable->FindObject(bpname)))
268 eventCounter = fNEvents - errorCounter->Events();
272 eventCounter = fNEvents;
276 // value of (buspatch, manu) occupancy
277 char bpmanuname[256];
278 AliMUONErrorCounter* manuCounter;
279 sprintf(bpmanuname,"bp%dmanu%d",busPatchId,manuId);
280 manuCounter = (AliMUONErrorCounter*)fManuBuspatchTable->FindObject(bpmanuname);
281 occupancy = manuCounter->Events()/64/eventCounter;
284 cout << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << " occupancy (>1) = " << occupancy << endl;
285 (*fFilcout) << " !!! BIG WARNING: ManuId = " << manuId << " !!! in BP = " << busPatchId << " occupancy (>1) = " << occupancy <<endl;
288 for (channelId = 0; channelId < ped->Size() ; ++channelId) {
289 pedMean = ped->ValueAsDouble(channelId, 0);
291 if (pedMean > 0) // connected channels
293 ped->SetValueAsDouble(channelId, 0, pedMean/(Double_t)eventCounter);
294 pedMean = ped->ValueAsDouble(channelId, 0);
295 pedSigma = ped->ValueAsDouble(channelId, 1);
296 ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)eventCounter - pedMean*pedMean)));
297 if(manuId == 0 || occupancy>1)
299 ped->SetValueAsDouble(channelId, 0, kADCMax);
300 ped->SetValueAsDouble(channelId, 1, kADCMax);
305 ped->SetValueAsDouble(channelId, 0, kADCMax);
306 ped->SetValueAsDouble(channelId, 1, kADCMax);
309 pedMean = ped->ValueAsDouble(channelId, 0);
310 pedSigma = ped->ValueAsDouble(channelId, 1);
312 if (!shuttleFile_1.IsNull()) {
313 tempstring = WritePedData(busPatchId,manuId,channelId,pedMean,pedSigma);
314 fileout << tempstring;
316 stringout << tempstring;
319 if(fIndex<0) // Pedestal Run
321 pedMeanHisto->Fill(pedMean);
322 pedSigmaHisto->Fill(pedSigma);
329 if (!shuttleFile_1.IsNull()) fileout.close();
331 // Outputs to root file and AMORE DB
334 //Send objects to the AMORE DB
336 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
337 TObjString peddata(stringout.str().c_str());
339 status = amoreDA.Send("Pedestals",&peddata);
341 cout << "Warning: Failed to write Pedestals in the AMORE database : " << status << endl;
343 cout << "amoreDA.Send(Pedestals) ok" << endl;
345 cout << "Warning: MCH DA not compiled with AMORE support" << endl;
347 if(fIndex<0) // Pedestal Run
351 delete fPedestalStore ;