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"
23 #include "AliMpConstants.h"
25 #include <TTimeStamp.h>
30 #include <THashList.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()
63 fErrorBuspatchTable(new AliMUON2DMap(kFALSE)),
64 fManuBuspatchTable(new AliMUON2DMap(kFALSE)),
65 fManuBPoutofconfigTable(new AliMUON2DMap(kFALSE)),
66 fDate(new TTimeStamp()),
69 fPedestalStore(new AliMUON2DMap(kTRUE)),
73 /// Default constructor
76 //______________________________________________________________________________
77 AliMUONPedestal::~AliMUONPedestal()
80 delete fErrorBuspatchTable;
81 delete fManuBuspatchTable;
82 delete fPedestalStore;
83 delete fManuBPoutofconfigTable;
86 //______________________________________________________________________________
88 AliMUONPedestal::GetHistoFileName() const
90 /// Return the name of file we use to store histograms
91 return fHistoFileName.Data();
94 //______________________________________________________________________________
95 void AliMUONPedestal::LoadConfig(const char* dbfile)
97 /// Load MUONTRK configuration from ascii file "dbfile" (in DetDB)
102 ifstream filein(dbfile,ios::in);
104 while (!filein.eof())
106 filein >> busPatchId >> manuId;
108 AliMUONVCalibParam* ped =
109 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
114 ped = new AliMUONCalibParamND(2, AliMpConstants::ManuNofChannels(),busPatchId, manuId, -1.); // put default wise -1, not connected channel
115 fPedestalStore ->Add(ped);
117 if ( ! fManuBuspatchTable->FindObject(busPatchId,manuId) )
119 // New (buspatch,manu)
120 AliMUONErrorCounter* manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
121 fManuBuspatchTable->Add(manuCounter);
126 //______________________________________________________________________________
127 void AliMUONPedestal::MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, Int_t charge)
130 /// Compute pedestals values
131 AliMUONVCalibParam* ped =
132 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
137 { // Fill out_of_config (buspatch,manu) table
138 if (!(static_cast<AliMUONErrorCounter*>(fManuBPoutofconfigTable->FindObject(busPatchId,manuId))))
139 fManuBPoutofconfigTable->Add(new AliMUONErrorCounter(busPatchId,manuId));
140 if(warn<10) cout << " !!! WARNING : busPatchId = " << busPatchId << " manuId = " << manuId << " not in the Detector configuration " << endl;
141 else if(warn==10) cout << " !!! see .log file for an exhaustive list of (busPatchId, manuId) out of Detector configuration \n" << endl;
143 (*fFilcout) << " !!! WARNING : busPatchId = " << busPatchId << " manuId = " << manuId << " not in the Detector configuration " << endl;
147 // put default wise -1, not connected channel
148 ped = new AliMUONCalibParamND(2, AliMpConstants::ManuNofChannels(),busPatchId, manuId, -1.);
149 fPedestalStore ->Add(ped);
152 // Initialization for the first value
153 if (ped->ValueAsDouble(channelId, 0) == -1)
155 if(fConfig && channelId == 0){fNManu++;}
156 ped->SetValueAsDouble(channelId, 0, 0.);
158 if (ped->ValueAsDouble(channelId, 1) == -1) ped->SetValueAsDouble(channelId, 1, 0.);
160 Double_t pedMean = ped->ValueAsDouble(channelId, 0) + (Double_t) charge;
161 Double_t pedSigma = ped->ValueAsDouble(channelId, 1) + (Double_t) charge*charge;
163 ped->SetValueAsDouble(channelId, 0, pedMean);
164 ped->SetValueAsDouble(channelId, 1, pedSigma);
166 AliMUONErrorCounter* manuCounter;
167 if (!(manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId))))
169 // New (buspatch,manu)
170 manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
171 fManuBuspatchTable->Add(manuCounter);
176 manuCounter->Increment();
179 //______________________________________________________________________________
180 void AliMUONPedestal::Finalize()
182 /// final polishing of the store
186 Double_t pedSigmalimit=0.5;
192 if (fErrorBuspatchTable->GetSize())
194 cout<<"\nWarning: Buspatches with less statistics (due to parity errors)"<<endl;
195 (*fFilcout)<<"\nWarning: Buspatches with less statistics (due to parity errors)"<<endl;
196 TIter nextParityError(fErrorBuspatchTable->CreateIterator());
197 AliMUONErrorCounter* parityerror;
198 while((parityerror = static_cast<AliMUONErrorCounter*>(nextParityError())))
200 cout<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
201 (*fFilcout)<<" bp "<<parityerror->BusPatch()<<": events used = "<<fNEvents-parityerror->Events()<<endl;
207 // iterator over pedestal
208 TIter next(fPedestalStore ->CreateIterator());
209 AliMUONVCalibParam* ped;
211 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
213 busPatchId = ped->ID0();
217 cout << "Warning: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
218 (*fFilcout) << "Warning: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
221 // Correct the number of events for buspatch with errors
222 AliMUONErrorCounter* errorCounter;
223 if ((errorCounter = (AliMUONErrorCounter*)fErrorBuspatchTable->FindObject(busPatchId)))
225 eventCounter = fNEvents - errorCounter->Events();
229 eventCounter = fNEvents;
231 Int_t occupancy=0; // channel missing in raw data or read but rejected (case of parity error)
232 // value of (buspatch, manu) occupancy
233 AliMUONErrorCounter* manuCounter;
234 manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId));
235 if(eventCounter>0)occupancy = manuCounter->Events()/64/eventCounter;
238 cout << "Warning: ManuId = " << manuId << " !!! in BP = " << busPatchId << " occupancy (>1) = " << occupancy << endl;
239 (*fFilcout) << "Warning: ManuId = " << manuId << " !!! in BP = " << busPatchId << " occupancy (>1) = " << occupancy <<endl;
242 for (channelId = 0; channelId < ped->Size() ; ++channelId)
244 pedMean = ped->ValueAsDouble(channelId, 0);
246 if (pedMean >= 0) // connected channels
248 ped->SetValueAsDouble(channelId, 0, pedMean/(Double_t)eventCounter);
249 pedMean = ped->ValueAsDouble(channelId, 0);
250 pedSigma = ped->ValueAsDouble(channelId, 1);
251 ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)eventCounter - pedMean*pedMean)));
253 if(eventCounter < fNEvthreshold )
254 { nADCmax++; ped->SetValueAsDouble(channelId, 0, ADCMax());
255 ped->SetValueAsDouble(channelId, 1, ADCMax());}
256 if( ped->ValueAsDouble(channelId, 1) < pedSigmalimit )
257 { nADC4090++; ped->SetValueAsDouble(channelId, 0, ADCMax()-5);
258 ped->SetValueAsDouble(channelId, 1, ADCMax()-5);}
259 if(manuId == 0 || occupancy>1)
260 { nADCmax++; ped->SetValueAsDouble(channelId, 0, ADCMax());
261 ped->SetValueAsDouble(channelId, 1, ADCMax());
262 if(occupancy>1 && channelId==0)ped->SetValueAsDouble(channelId, 0, ADCMax()+occupancy);}
265 { nADCmax++; ped->SetValueAsDouble(channelId, 0, ADCMax());
266 ped->SetValueAsDouble(channelId, 1, ADCMax());}
270 { char* detail=Form("Warning: Nb of Channels with bad Pedestal (Ped=4095) = %d over %d",nADCmax,fNChannel);
271 printf("%s\n",detail);
272 (*fFilcout) << detail << endl; }
274 { char* detail=Form("Warning: Nb of Channels with PedSigma<0.5 (Ped=4090) = %d over %d",nADC4090,fNChannel);
275 printf("%s\n",detail);
276 (*fFilcout) << detail << endl; }
278 //______________________________________________________________________________
279 void AliMUONPedestal::MakeASCIIoutput(ostream& out) const
281 /// put pedestal store in the output stream
283 out<<"//===========================================================================" << endl;
284 out<<"// Pedestal file calculated by "<< fPrefixDA.Data() << endl;
285 out<<"//===========================================================================" << endl;
286 out<<"// * Run : " << fRunNumber << endl;
287 out<<"// * Date : " << fDate->AsString("l") <<endl;
288 out<<"// * Statictics : " << fNEvents << endl;
290 out<<"// * Nb of MANUS : " << fNManuConfig << " read in the Det. config. " << endl;
291 out<<"// * Nb of MANUS : " << fNManu << " read in raw data " << endl;
292 out<<"// * Nb of MANUS : " << fNChannel/64 << " written in pedestal file " << endl;
293 out<<"// * Nb of channels: " << fNChannel << endl;
295 out<<"// * Below " << fNEvthreshold << " events=> Ped.&sig.=4095" << endl;
296 out<<"// * PedSigma < 0.5 => Ped.&sig.=4090" << endl;
298 if (fErrorBuspatchTable->GetSize())
301 out<<"// * Buspatches with less statistics (due to parity errors)"<<endl;
302 TIter next(fErrorBuspatchTable->CreateIterator());
303 AliMUONErrorCounter* parityerror;
304 while((parityerror = static_cast<AliMUONErrorCounter*>(next())))
306 if(fNEvents-parityerror->Events()>fNEvthreshold)
307 { out<<"// BusPatch = "<<parityerror->BusPatch()<<"\t Nevents used = "<<fNEvents-parityerror->Events()<<endl; }
309 { out<<"// BusPatch = "<<parityerror->BusPatch()<<"\t Nevents used = "<<fNEvents-parityerror->Events()<< " (Ped.&sig.=4095)" << endl; }
316 TIter next(fPedestalStore ->CreateIterator());
317 AliMUONVCalibParam* ped;
318 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
320 Int_t busPatchId = ped->ID0();
321 Int_t manuId = ped->ID1();
322 Double_t pedMean = ped->ValueAsDouble(0, 0); // check pedestal value for channelId=0
329 out<<"// * Puzzling (Buspatch,Manu) read in raw data ? (Ped.&sig.=4095)"<<endl;}
330 occupancy=TMath::Nint(pedMean-ADCMax());
331 ped->SetValueAsDouble(0, 0, ADCMax());
332 out<<"// BusPatch = "<< busPatchId <<"\t ManuId = "<< manuId << "\t occupancy = " << occupancy << endl;
335 if (manuId==0 || (fConfig && static_cast<AliMUONErrorCounter*>(fManuBPoutofconfigTable->FindObject(busPatchId,manuId))))
340 out<<"// * Puzzling (Buspatch,Manu) read in raw data ? (Ped.&sig.=4095)"<<endl;}
341 out<<"// BusPatch = "<< busPatchId <<"\t ManuId = "<< manuId << "\t missing in the mapping" << endl;
346 out<<"//---------------------------------------------------------------------------" << endl;
347 out<<"//---------------------------------------------------------------------------" << endl;
348 out<<"// BP MANU CH. MEAN SIGMA"<<endl;
349 out<<"//---------------------------------------------------------------------------" << endl;
351 TIter next(fPedestalStore->CreateIterator());
352 AliMUONVCalibParam* ped;
357 cout << " ..... sorting pedestal values ....." << endl;
358 THashList pedtable(100,2);
359 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
364 // iterator over sorted pedestal
365 TIter nextSorted(&pedtable);
366 while ( (ped = (AliMUONVCalibParam*)(nextSorted()) ) )
368 Int_t busPatchId = ped->ID0();
369 Int_t manuId = ped->ID1();
370 for ( Int_t channelId = 0; channelId < ped->Size(); ++channelId )
372 Double_t pedMean = ped->ValueAsDouble(channelId, 0);
373 Double_t pedSigma = ped->ValueAsDouble(channelId, 1);
374 out << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t" << pedMean <<"\t"<< pedSigma << endl;
380 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
382 Int_t busPatchId = ped->ID0();
383 Int_t manuId = ped->ID1();
384 for ( Int_t channelId = 0; channelId < ped->Size(); ++channelId )
386 Double_t pedMean = ped->ValueAsDouble(channelId, 0);
387 Double_t pedSigma = ped->ValueAsDouble(channelId, 1);
388 out << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t" << pedMean <<"\t"<< pedSigma << endl;
394 //______________________________________________________________________________
395 void AliMUONPedestal::MakeControlHistos()
397 /// Create control histograms
398 if (fIndex>=0) return; // Pedestal run (fIndex=-1)
408 TFile* histoFile = 0;
410 TH1F* pedMeanHisto = 0;
411 TH1F* pedSigmaHisto = 0;
413 fHistoFileName=Form("%s.root",fPrefixDA.Data());
414 histoFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking pedestals");
416 Int_t nx = ADCMax()+1;
418 Int_t xmax = ADCMax();
419 pedMeanHisto = new TH1F("pedmean_allch","Pedestal mean all channels",nx,xmin,xmax);
420 pedMeanHisto->SetDirectory(histoFile);
425 pedSigmaHisto = new TH1F("pedsigma_allch","Pedestal sigma all channels",nx,xmin,xmax);
426 pedSigmaHisto->SetDirectory(histoFile);
428 tree = new TTree("t","Pedestal tree");
429 tree->Branch("bp",&busPatchId,"bp/I");
430 tree->Branch("manu",&manuId,",manu/I");
431 tree->Branch("channel",&channelId,",channel/I");
432 tree->Branch("pedMean",&pedMean,",pedMean/D");
433 tree->Branch("pedSigma",&pedSigma,",pedSigma/D");
434 tree->Branch("nevt",&evt,",evt/D");
436 // iterator over pedestal
437 TIter next(fPedestalStore ->CreateIterator());
438 AliMUONVCalibParam* ped;
439 AliMUONErrorCounter* manuCounter;
441 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
443 busPatchId = ped->ID0();
446 for ( channelId = 0; channelId < ped->Size(); ++channelId )
448 pedMean = ped->ValueAsDouble(channelId, 0);
449 pedSigma = ped->ValueAsDouble(channelId, 1);
450 manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId));
451 evt = manuCounter->Events()/64;
453 pedMeanHisto->Fill(pedMean);
454 pedSigmaHisto->Fill(pedSigma);