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 <TTimeStamp.h>
31 #include <Riostream.h>
35 //-----------------------------------------------------------------------------
36 /// \class AliMUONPedestal
38 /// Implementation of the pedestal computing
43 /// \author Alberto Baldisseri, JL Charvet (05/05/2009)
44 //-----------------------------------------------------------------------------
47 ClassImp(AliMUONPedestal)
50 //______________________________________________________________________________
51 AliMUONPedestal::AliMUONPedestal()
57 fErrorBuspatchTable(new THashTable(100,2)),
58 fDate(new TTimeStamp()),
60 fPedestalStore(new AliMUON2DMap(kFALSE)),
63 /// Default constructor
64 sprintf(fHistoFileName," ");
65 sprintf(fprefixDA," ");
67 // AliMUONPedestal& operator=(const AliMUONPedestal& other); Copy ctor
69 //______________________________________________________________________________
70 AliMUONPedestal::~AliMUONPedestal()
75 //______________________________________________________________________________
76 void AliMUONPedestal::MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, Int_t charge)
78 /// Compute pedestals values
79 AliMUONVCalibParam* ped =
80 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
84 ped = new AliMUONCalibParamND(2, kNChannels,busPatchId, manuId, -1.); // put default wise -1, not connected channel
85 fPedestalStore ->Add(ped);
88 // Initialization for the first value
89 if (ped->ValueAsDouble(channelId, 0) == -1) ped->SetValueAsDouble(channelId, 0, 0.);
90 if (ped->ValueAsDouble(channelId, 1) == -1) ped->SetValueAsDouble(channelId, 1, 0.);
92 Double_t pedMean = ped->ValueAsDouble(channelId, 0) + (Double_t) charge;
93 Double_t pedSigma = ped->ValueAsDouble(channelId, 1) + (Double_t) charge*charge;
95 ped->SetValueAsDouble(channelId, 0, pedMean);
96 ped->SetValueAsDouble(channelId, 1, pedSigma);
99 //______________________________________________________________________________
100 TString AliMUONPedestal::WritePedHeader(void)
104 ostringstream stream;
105 stream<<"//===========================================================================" << endl;
106 stream<<"// Pedestal file calculated by MUONTRKda"<<endl;
107 stream<<"//===========================================================================" << endl;
108 stream<<"// * Run : " << fRunNumber << endl;
109 stream<<"// * Date : " << fDate->AsString("l") <<endl;
110 stream<<"// * Statictics : " << fNEvents << endl;
111 stream<<"// * # of MANUS : " << fNManu << endl;
112 stream<<"// * # of channels : " << fNChannel << endl;
113 if (fErrorBuspatchTable->GetSize())
116 stream<<"// * Buspatches with less statistics (due to parity errors)"<<endl;
117 TIterator* iter = fErrorBuspatchTable->MakeIterator();
118 AliMUONErrorCounter* parityerror;
119 while((parityerror = (AliMUONErrorCounter*) iter->Next()))
121 stream<<"// bp "<<parityerror->BusPatch()<<" events used "<<fNEvents-parityerror->Events()<<endl;
125 stream<<"//---------------------------------------------------------------------------" << endl;
126 stream<<"//---------------------------------------------------------------------------" << endl;
127 stream<<"// BP MANU CH. MEAN SIGMA"<<endl;
128 stream<<"//---------------------------------------------------------------------------" << endl;
130 return TString(stream.str().c_str());
133 //______________________________________________________________________________
134 TString AliMUONPedestal::WritePedData(Int_t BP, Int_t Manu, Int_t ch, Double_t pedMean, Double_t pedSigma)
138 ostringstream stream("");
139 stream << "\t" << BP << "\t" << Manu <<"\t"<< ch << "\t"
140 << pedMean <<"\t"<< pedSigma << endl;
141 return TString(stream.str().c_str());
145 //______________________________________________________________________________
146 void AliMUONPedestal::MakePedStore(TString shuttleFile_1 = "")
149 /// Store pedestals in ASCII files
154 ostringstream stringout; // String to be sent to AMORE_DB
162 TFile* histoFile = 0;
164 TH1F* pedMeanHisto = 0;
165 TH1F* pedSigmaHisto = 0;
167 if (fIndex<0) // Pedestal run (fIndex=-1)
169 sprintf(fHistoFileName,"%s_%d.root",fprefixDA,fRunNumber);
170 histoFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking pedestals");
174 sprintf(name,"pedmean_allch");
175 sprintf(title,"Pedestal mean all channels");
179 pedMeanHisto = new TH1F(name,title,nx,xmin,xmax);
180 pedMeanHisto->SetDirectory(histoFile);
182 sprintf(name,"pedsigma_allch");
183 sprintf(title,"Pedestal sigma all channels");
187 pedSigmaHisto = new TH1F(name,title,nx,xmin,xmax);
188 pedSigmaHisto->SetDirectory(histoFile);
190 tree = new TTree("t","Pedestal tree");
191 tree->Branch("bp",&busPatchId,"bp/I");
192 tree->Branch("manu",&manuId,",manu/I");
193 tree->Branch("channel",&channelId,",channel/I");
194 tree->Branch("pedMean",&pedMean,",pedMean/D");
195 tree->Branch("pedSigma",&pedSigma,",pedSigma/D");
198 if (!shuttleFile_1.IsNull()) {
199 fileout.open(shuttleFile_1.Data());
200 tempstring = WritePedHeader();
201 fileout << tempstring;
203 stringout << tempstring;
207 if (fErrorBuspatchTable->GetSize())
209 cout<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
210 (*fFilcout)<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
211 TIterator* iter = fErrorBuspatchTable->MakeIterator();
212 AliMUONErrorCounter* parityerror;
213 while((parityerror = (AliMUONErrorCounter*) iter->Next()))
215 cout<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
216 (*fFilcout)<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
222 // iterator over pedestal
223 TIter next(fPedestalStore ->CreateIterator());
224 AliMUONVCalibParam* ped;
226 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
228 busPatchId = ped->ID0();
232 // Correct the number of events for buspatch with errors
234 AliMUONErrorCounter* errorCounter;
235 sprintf(bpname,"bp%d",busPatchId);
236 if ((errorCounter = (AliMUONErrorCounter*)fErrorBuspatchTable->FindObject(bpname)))
238 eventCounter = fNEvents - errorCounter->Events();
242 eventCounter = fNEvents;
245 for (channelId = 0; channelId < ped->Size() ; ++channelId) {
246 pedMean = ped->ValueAsDouble(channelId, 0);
248 if (pedMean > 0) { // connected channels
250 ped->SetValueAsDouble(channelId, 0, pedMean/(Double_t)eventCounter);
252 pedMean = ped->ValueAsDouble(channelId, 0);
253 pedSigma = ped->ValueAsDouble(channelId, 1);
255 ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)eventCounter - pedMean*pedMean)));
257 pedMean = ped->ValueAsDouble(channelId, 0);
258 pedSigma = ped->ValueAsDouble(channelId, 1);
261 if (!shuttleFile_1.IsNull()) {
262 tempstring = WritePedData(busPatchId,manuId,channelId,pedMean,pedSigma);
263 fileout << tempstring;
265 stringout << tempstring;
268 if(fIndex<0) // Pedestal Run
270 pedMeanHisto->Fill(pedMean);
271 pedSigmaHisto->Fill(pedSigma);
279 if (!shuttleFile_1.IsNull()) fileout.close();
281 // Outputs to root file and AMORE DB
284 //Send objects to the AMORE DB
286 const char *role=gSystem->Getenv("AMORE_DA_NAME");
288 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
289 // TObjString peddata(stringout.str().c_str());
290 TObjString peddata(stringout.str().c_str());
292 status = amoreDA.Send("Pedestals",&peddata);
294 cout << "Warning: Failed to write Pedestals in the AMORE database : " << status << endl;
297 cout << "Warning: environment variable 'AMORE_DA_NAME' not set. Cannot write to the AMORE database" << endl;
300 if(fIndex<0) // Pedestal Run
304 delete fPedestalStore ;