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
65 // sprintf(fOutFolder,".");
66 sprintf(fHistoFileName,"");
67 sprintf(fprefixDA,"");
69 // AliMUONPedestal& operator=(const AliMUONPedestal& other); Copy ctor
71 //______________________________________________________________________________
72 AliMUONPedestal::~AliMUONPedestal()
77 //______________________________________________________________________________
78 void AliMUONPedestal::MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, Int_t charge)
80 /// Compute pedestals values
81 AliMUONVCalibParam* ped =
82 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
86 ped = new AliMUONCalibParamND(2, kNChannels,busPatchId, manuId, -1.); // put default wise -1, not connected channel
87 fPedestalStore ->Add(ped);
90 // Initialization for the first value
91 if (ped->ValueAsDouble(channelId, 0) == -1) ped->SetValueAsDouble(channelId, 0, 0.);
92 if (ped->ValueAsDouble(channelId, 1) == -1) ped->SetValueAsDouble(channelId, 1, 0.);
94 Double_t pedMean = ped->ValueAsDouble(channelId, 0) + (Double_t) charge;
95 Double_t pedSigma = ped->ValueAsDouble(channelId, 1) + (Double_t) charge*charge;
97 ped->SetValueAsDouble(channelId, 0, pedMean);
98 ped->SetValueAsDouble(channelId, 1, pedSigma);
101 //______________________________________________________________________________
102 TString AliMUONPedestal::WritePedHeader(void)
106 ostringstream stream;
107 stream<<"//===========================================================================" << endl;
108 stream<<"// Pedestal file calculated by MUONTRKda"<<endl;
109 stream<<"//===========================================================================" << endl;
110 stream<<"// * Run : " << fRunNumber << endl;
111 stream<<"// * Date : " << fDate->AsString("l") <<endl;
112 stream<<"// * Statictics : " << fNEvents << endl;
113 stream<<"// * # of MANUS : " << fNManu << endl;
114 stream<<"// * # of channels : " << fNChannel << endl;
115 if (fErrorBuspatchTable->GetSize())
118 stream<<"// * Buspatches with less statistics (due to parity errors)"<<endl;
119 TIterator* iter = fErrorBuspatchTable->MakeIterator();
120 AliMUONErrorCounter* parityerror;
121 while((parityerror = (AliMUONErrorCounter*) iter->Next()))
123 stream<<"// bp "<<parityerror->BusPatch()<<" events used "<<fNEvents-parityerror->Events()<<endl;
127 stream<<"//---------------------------------------------------------------------------" << endl;
128 stream<<"//---------------------------------------------------------------------------" << endl;
129 stream<<"// BP MANU CH. MEAN SIGMA"<<endl;
130 stream<<"//---------------------------------------------------------------------------" << endl;
132 return TString(stream.str().c_str());
135 //______________________________________________________________________________
136 TString AliMUONPedestal::WritePedData(Int_t BP, Int_t Manu, Int_t ch, Double_t pedMean, Double_t pedSigma)
140 ostringstream stream("");
141 stream << "\t" << BP << "\t" << Manu <<"\t"<< ch << "\t"
142 << pedMean <<"\t"<< pedSigma << endl;
143 return TString(stream.str().c_str());
147 //______________________________________________________________________________
148 void AliMUONPedestal::MakePedStore(TString shuttleFile_1 = "")
151 /// Store pedestals in ASCII files
156 ostringstream stringout; // String to be sent to AMORE_DB
164 TFile* histoFile = 0;
166 TH1F* pedMeanHisto = 0;
167 TH1F* pedSigmaHisto = 0;
169 if (fIndex<0) // Pedestal run (fIndex=-1)
171 sprintf(fHistoFileName,"%s_%d.root",fprefixDA,fRunNumber);
172 histoFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking pedestals");
176 sprintf(name,"pedmean_allch");
177 sprintf(title,"Pedestal mean all channels");
181 pedMeanHisto = new TH1F(name,title,nx,xmin,xmax);
182 pedMeanHisto->SetDirectory(histoFile);
184 sprintf(name,"pedsigma_allch");
185 sprintf(title,"Pedestal sigma all channels");
189 pedSigmaHisto = new TH1F(name,title,nx,xmin,xmax);
190 pedSigmaHisto->SetDirectory(histoFile);
192 tree = new TTree("t","Pedestal tree");
193 tree->Branch("bp",&busPatchId,"bp/I");
194 tree->Branch("manu",&manuId,",manu/I");
195 tree->Branch("channel",&channelId,",channel/I");
196 tree->Branch("pedMean",&pedMean,",pedMean/D");
197 tree->Branch("pedSigma",&pedSigma,",pedSigma/D");
200 if (!shuttleFile_1.IsNull()) {
201 fileout.open(shuttleFile_1.Data());
202 tempstring = WritePedHeader();
203 fileout << tempstring;
205 stringout << tempstring;
209 if (fErrorBuspatchTable->GetSize())
211 cout<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
212 (*fFilcout)<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
213 TIterator* iter = fErrorBuspatchTable->MakeIterator();
214 AliMUONErrorCounter* parityerror;
215 while((parityerror = (AliMUONErrorCounter*) iter->Next()))
217 cout<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
218 (*fFilcout)<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
224 // iterator over pedestal
225 TIter next(fPedestalStore ->CreateIterator());
226 AliMUONVCalibParam* ped;
228 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
230 busPatchId = ped->ID0();
234 // Correct the number of events for buspatch with errors
236 AliMUONErrorCounter* errorCounter;
237 sprintf(bpname,"bp%d",busPatchId);
238 if ((errorCounter = (AliMUONErrorCounter*)fErrorBuspatchTable->FindObject(bpname)))
240 eventCounter = fNEvents - errorCounter->Events();
244 eventCounter = fNEvents;
247 for (channelId = 0; channelId < ped->Size() ; ++channelId) {
248 pedMean = ped->ValueAsDouble(channelId, 0);
250 if (pedMean > 0) { // connected channels
252 ped->SetValueAsDouble(channelId, 0, pedMean/(Double_t)eventCounter);
254 pedMean = ped->ValueAsDouble(channelId, 0);
255 pedSigma = ped->ValueAsDouble(channelId, 1);
257 ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)eventCounter - pedMean*pedMean)));
259 pedMean = ped->ValueAsDouble(channelId, 0);
260 pedSigma = ped->ValueAsDouble(channelId, 1);
263 if (!shuttleFile_1.IsNull()) {
264 tempstring = WritePedData(busPatchId,manuId,channelId,pedMean,pedSigma);
265 fileout << tempstring;
267 stringout << tempstring;
270 if(fIndex<0) // Pedestal Run
272 pedMeanHisto->Fill(pedMean);
273 pedSigmaHisto->Fill(pedSigma);
281 if (!shuttleFile_1.IsNull()) fileout.close();
283 // Outputs to root file and AMORE DB
286 //Send objects to the AMORE DB
288 const char *role=gSystem->Getenv("AMORE_DA_NAME");
290 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
291 // TObjString peddata(stringout.str().c_str());
292 TObjString peddata(stringout.str().c_str());
294 status = amoreDA.Send("Pedestals",&peddata);
296 cout << "Warning: Failed to write Pedestals in the AMORE database : " << status << endl;
299 cout << "Warning: environment variable 'AMORE_DA_NAME' not set. Cannot write to the AMORE database" << endl;
302 if(fIndex<0) // Pedestal Run
306 delete fPedestalStore ;