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 //-----------------------------------------------------------------------------
52 ClassImp(AliMUONPedestal)
55 //______________________________________________________________________________
56 AliMUONPedestal::AliMUONPedestal()
69 fErrorBuspatchTable(new AliMUON2DMap(kFALSE)),
70 fManuBuspatchTable(new AliMUON2DMap(kFALSE)),
71 fManuBPoutofconfigTable(new AliMUON2DMap(kFALSE)),
72 fDate(new TTimeStamp()),
75 fPedestalStore(new AliMUON2DMap(kTRUE)),
80 /// Default constructor
82 //______________________________________________________________________________
83 AliMUONPedestal::AliMUONPedestal(TRootIOCtor* /*dummy*/)
96 fErrorBuspatchTable(0),
97 fManuBuspatchTable(0),
98 fManuBPoutofconfigTable(0),
107 /// Root IO constructor
110 //______________________________________________________________________________
111 AliMUONPedestal::~AliMUONPedestal()
114 delete fErrorBuspatchTable;
115 delete fManuBuspatchTable;
116 delete fPedestalStore;
117 delete fManuBPoutofconfigTable;
120 //______________________________________________________________________________
122 AliMUONPedestal::GetHistoFileName() const
124 /// Return the name of file we use to store histograms
125 return fHistoFileName.Data();
128 //______________________________________________________________________________
129 void AliMUONPedestal::LoadConfig(const char* dbfile)
131 /// Load MUONTRK configuration from ascii file "dbfile" (in DetDB)
136 ifstream filein(dbfile,ios::in);
138 while (!filein.eof())
140 filein >> busPatchId >> manuId;
142 AliMUONVCalibParam* ped =
143 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
148 ped = new AliMUONCalibParamND(2, AliMpConstants::ManuNofChannels(),busPatchId, manuId, -1.); // put default wise -1, not connected channel
149 fPedestalStore ->Add(ped);
151 if ( ! fManuBuspatchTable->FindObject(busPatchId,manuId) )
153 // New (buspatch,manu)
154 AliMUONErrorCounter* manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
155 fManuBuspatchTable->Add(manuCounter);
160 //______________________________________________________________________________
161 void AliMUONPedestal::MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, Int_t charge)
164 /// Compute pedestals values
165 AliMUONVCalibParam* ped =
166 static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
171 { // Fill out_of_config (buspatch,manu) table
172 if (!(static_cast<AliMUONErrorCounter*>(fManuBPoutofconfigTable->FindObject(busPatchId,manuId))))
173 fManuBPoutofconfigTable->Add(new AliMUONErrorCounter(busPatchId,manuId));
174 if(warn<10) cout << fPrefixLDC.Data() << " : !!! WARNING : busPatchId = " << busPatchId << " manuId = " << manuId << " not in the Detector configuration " << endl;
175 else if(warn==10) cout << fPrefixLDC.Data() << " : !!! see .log file for an exhaustive list of (busPatchId, manuId) out of Detector configuration \n" << endl;
177 (*fFilcout) <<" !!! WARNING : busPatchId = " << busPatchId << " manuId = " << manuId << " not in the Detector configuration " << endl;
181 // put default wise -1, not connected channel
182 ped = new AliMUONCalibParamND(2, AliMpConstants::ManuNofChannels(),busPatchId, manuId, -1.);
183 fPedestalStore ->Add(ped);
186 // Initialization for the first value
187 if (ped->ValueAsDouble(channelId, 0) == -1)
189 if(fConfig && channelId == 0){fNManu++;}
190 ped->SetValueAsDouble(channelId, 0, 0.);
192 if (ped->ValueAsDouble(channelId, 1) == -1) ped->SetValueAsDouble(channelId, 1, 0.);
194 Double_t pedMean = ped->ValueAsDouble(channelId, 0) + (Double_t) charge;
195 Double_t pedSigma = ped->ValueAsDouble(channelId, 1) + (Double_t) charge*charge;
197 ped->SetValueAsDouble(channelId, 0, pedMean);
198 ped->SetValueAsDouble(channelId, 1, pedSigma);
200 AliMUONErrorCounter* manuCounter;
201 if (!(manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId))))
203 // New (buspatch,manu)
204 manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
205 fManuBuspatchTable->Add(manuCounter);
210 manuCounter->Increment();
213 //______________________________________________________________________________
214 void AliMUONPedestal::Finalize()
216 /// final polishing of the store
220 Double_t pedSigmalimit=0.5;
227 if (fErrorBuspatchTable->GetSize())
229 cout<< "\n" << fPrefixLDC.Data() << " : See list of Buspatches with lower statistics (due to parity errors) in .log or .ped file "<<endl;
230 (*fFilcout)<<"\nWarning: Buspatches with less statistics (due to parity errors)"<<endl;
231 TIter nextParityError(fErrorBuspatchTable->CreateIterator());
232 AliMUONErrorCounter* parityerror;
233 while((parityerror = static_cast<AliMUONErrorCounter*>(nextParityError())))
235 // cout<<" bp "<<parityerror->BusPatch()<<": used events = "<<fNEvents-parityerror->Events()<<endl;
236 (*fFilcout)<<" bp "<<parityerror->BusPatch()<<": used events = "<<fNEvents-parityerror->Events()<<endl;
242 // iterator over pedestal
243 TIter next(fPedestalStore ->CreateIterator());
244 AliMUONVCalibParam* ped;
246 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
248 busPatchId = ped->ID0();
252 cout << fPrefixLDC.Data() << " : Warning: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
253 (*fFilcout) << "Warning: ManuId = " << manuId << " !!! in BP = " << busPatchId << endl;
256 // Correct the number of events for buspatch with errors
257 AliMUONErrorCounter* errorCounter;
258 if ((errorCounter = (AliMUONErrorCounter*)fErrorBuspatchTable->FindObject(busPatchId)))
260 eventCounter = fNEvents - errorCounter->Events();
264 eventCounter = fNEvents;
266 Int_t occupancy=0; // channel missing in raw data or read but rejected (case of parity error)
267 // value of (buspatch, manu) occupancy
268 AliMUONErrorCounter* manuCounter;
269 manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId));
270 if(eventCounter>0)occupancy = manuCounter->Events()/64/eventCounter;
273 cout << fPrefixLDC.Data() << " : Warning: ManuId = " << manuId << " !!! in BP = " << busPatchId << " occupancy (>1) = " << occupancy << endl;
274 (*fFilcout) << "Warning: ManuId = " << manuId << " !!! in BP = " << busPatchId << " occupancy (>1) = " << occupancy <<endl;
277 for (channelId = 0; channelId < ped->Size() ; ++channelId)
279 pedMean = ped->ValueAsDouble(channelId, 0);
281 if (pedMean >= 0) // connected channels
283 ped->SetValueAsDouble(channelId, 0, pedMean/(Double_t)eventCounter);
284 pedMean = ped->ValueAsDouble(channelId, 0);
285 pedSigma = ped->ValueAsDouble(channelId, 1);
286 ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)eventCounter - pedMean*pedMean)));
288 if(eventCounter < fNEvthreshold )
289 { nADCmax++; ped->SetValueAsDouble(channelId, 0, ADCMax());
290 ped->SetValueAsDouble(channelId, 1, ADCMax());}
291 if( ped->ValueAsDouble(channelId, 1) < pedSigmalimit )
292 { nADC4090++; ped->SetValueAsDouble(channelId, 0, ADCMax()-5);
293 ped->SetValueAsDouble(channelId, 1, ADCMax()-5);}
294 if(manuId == 0 || occupancy>1)
295 { nADCmax++; ped->SetValueAsDouble(channelId, 0, ADCMax());
296 ped->SetValueAsDouble(channelId, 1, ADCMax());
297 if(occupancy>1 && channelId==0)ped->SetValueAsDouble(channelId, 0, ADCMax()+occupancy);}
300 { nADCmax++; ped->SetValueAsDouble(channelId, 0, ADCMax());
301 ped->SetValueAsDouble(channelId, 1, ADCMax());}
305 float frac1=0. , frac2=0. ;
306 float frac_badped = 0.25 ; // maximal acceptable ratio of bad pedestals
312 { frac1 = float(nADCmax)/float(fNChannel);
313 detail=Form("%s : Warning: Nb of Channels with bad Pedestal (Ped=4095) = %d over %d (%6.4f)",fPrefixLDC.Data(),nADCmax,fNChannel,frac1);
314 printf("%s\n",detail);
315 (*fFilcout) << detail << endl;}
318 { frac2 = 1.*nADC4090/fNChannel;
319 detail=Form("%s : Warning: Nb of Channels with PedSigma<0.5 (Ped=4090) = %d over %d (%6.4f)",fPrefixLDC.Data(),nADC4090,fNChannel,frac2);
320 printf("%s\n",detail);
321 (*fFilcout) << detail << endl; }
323 if (frac1+frac2 > frac_badped) { status=-1 ;
324 detail=Form("\n%s !!! ERROR : fraction of Channels with Pedestal>=4090 = %6.4f (> %5.3f) (status= %d) \n",fPrefixLDC.Data(),frac1+frac2,frac_badped,status);
325 (*fFilcout) << detail << endl; printf("%s",detail) ;}
328 detail=Form("\n%s !!! ERROR : Nb good channel = 0 (all pedestals are forced to 4095) !!! (status= %d)\n",fPrefixLDC.Data(),status);
329 cout << detail; (*fFilcout) << detail ;}
333 //______________________________________________________________________________
334 void AliMUONPedestal::MakeASCIIoutput(ostream& out) const
336 /// put pedestal store in the output stream
338 out<<"//===========================================================================" << endl;
339 out<<"// Pedestal file calculated by "<< fPrefixDA.Data() << endl;
340 out<<"//===========================================================================" << endl;
341 out<<"// * Run : " << fRunNumber << endl;
342 out<<"// * Date : " << fDate->AsString("l") <<endl;
343 out<<"// * Statictics : " << fNEvents << endl;
345 out<<"// * Nb of MANUS : " << fNManuConfig << " read in the Det. config. " << endl;
346 out<<"// * Nb of MANUS : " << fNManu << " read in raw data " << endl;
347 out<<"// * Nb of MANUS : " << fNChannel/64 << " written in pedestal file " << endl;
348 out<<"// * Nb of channels: " << fNChannel << endl;
350 out<<"// * Below " << fNEvthreshold << " events=> Ped.&sig.=4095" << endl;
351 out<<"// * PedSigma < 0.5 => Ped.&sig.=4090" << endl;
353 if (fErrorBuspatchTable->GetSize())
356 out<<"// * Buspatches with less statistics (due to parity errors)"<<endl;
357 TIter next(fErrorBuspatchTable->CreateIterator());
358 AliMUONErrorCounter* parityerror;
359 while((parityerror = static_cast<AliMUONErrorCounter*>(next())))
361 if(fNEvents-parityerror->Events()>fNEvthreshold)
362 { out<<"// BusPatch = "<<parityerror->BusPatch()<<"\t Nevents used = "<<fNEvents-parityerror->Events()<<endl; }
364 { out<<"// BusPatch = "<<parityerror->BusPatch()<<"\t Nevents used = "<<fNEvents-parityerror->Events()<< " (Ped.&sig.=4095)" << endl; }
371 TIter next(fPedestalStore ->CreateIterator());
372 AliMUONVCalibParam* ped;
373 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
375 Int_t busPatchId = ped->ID0();
376 Int_t manuId = ped->ID1();
377 Double_t pedMean = ped->ValueAsDouble(0, 0); // check pedestal value for channelId=0
384 out<<"// * Puzzling (Buspatch,Manu) read in raw data ? (Ped.&sig.=4095)"<<endl;}
385 occupancy=TMath::Nint(pedMean-ADCMax());
386 ped->SetValueAsDouble(0, 0, ADCMax());
387 out<<"// BusPatch = "<< busPatchId <<"\t ManuId = "<< manuId << "\t occupancy = " << occupancy << endl;
390 if (manuId==0 || (fConfig && static_cast<AliMUONErrorCounter*>(fManuBPoutofconfigTable->FindObject(busPatchId,manuId))))
395 out<<"// * Puzzling (Buspatch,Manu) read in raw data ? (Ped.&sig.=4095)"<<endl;}
396 out<<"// BusPatch = "<< busPatchId <<"\t ManuId = "<< manuId << "\t missing in the mapping" << endl;
401 out<<"//---------------------------------------------------------------------------" << endl;
402 out<<"//---------------------------------------------------------------------------" << endl;
403 out<<"// BP MANU CH. MEAN SIGMA"<<endl;
404 out<<"//---------------------------------------------------------------------------" << endl;
406 TIter next(fPedestalStore->CreateIterator());
407 AliMUONVCalibParam* ped;
412 printf("%s : ..... sorting pedestal values .....\n",fPrefixLDC.Data());
413 THashList pedtable(100,2);
414 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
419 // iterator over sorted pedestal
420 TIter nextSorted(&pedtable);
421 while ( (ped = (AliMUONVCalibParam*)(nextSorted()) ) )
423 Int_t busPatchId = ped->ID0();
424 Int_t manuId = ped->ID1();
425 for ( Int_t channelId = 0; channelId < ped->Size(); ++channelId )
427 Double_t pedMean = ped->ValueAsDouble(channelId, 0);
428 Double_t pedSigma = ped->ValueAsDouble(channelId, 1);
429 out << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t" << pedMean <<"\t"<< pedSigma << endl;
435 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
437 Int_t busPatchId = ped->ID0();
438 Int_t manuId = ped->ID1();
439 for ( Int_t channelId = 0; channelId < ped->Size(); ++channelId )
441 Double_t pedMean = ped->ValueAsDouble(channelId, 0);
442 Double_t pedSigma = ped->ValueAsDouble(channelId, 1);
443 out << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t" << pedMean <<"\t"<< pedSigma << endl;
449 //______________________________________________________________________________
450 void AliMUONPedestal::MakeControlHistos()
452 /// Create control histograms
453 if (fIndex>=0) return; // Pedestal run (fIndex=-1)
463 TFile* histoFile = 0;
465 TH1F* pedMeanHisto = 0;
466 TH1F* pedSigmaHisto = 0;
468 fHistoFileName=Form("%s.root",fPrefixDA.Data());
469 histoFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking pedestals");
471 Int_t nx = ADCMax()+1;
473 Int_t xmax = ADCMax();
474 pedMeanHisto = new TH1F("pedmean_allch","Pedestal mean all channels",nx,xmin,xmax);
475 pedMeanHisto->SetDirectory(histoFile);
480 pedSigmaHisto = new TH1F("pedsigma_allch","Pedestal sigma all channels",nx,xmin,xmax);
481 pedSigmaHisto->SetDirectory(histoFile);
483 tree = new TTree("t","Pedestal tree");
484 tree->Branch("bp",&busPatchId,"bp/I");
485 tree->Branch("manu",&manuId,",manu/I");
486 tree->Branch("channel",&channelId,",channel/I");
487 tree->Branch("pedMean",&pedMean,",pedMean/D");
488 tree->Branch("pedSigma",&pedSigma,",pedSigma/D");
489 tree->Branch("nevt",&evt,",evt/D");
491 // iterator over pedestal
492 TIter next(fPedestalStore ->CreateIterator());
493 AliMUONVCalibParam* ped;
494 AliMUONErrorCounter* manuCounter;
496 while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
498 busPatchId = ped->ID0();
501 for ( channelId = 0; channelId < ped->Size(); ++channelId )
503 pedMean = ped->ValueAsDouble(channelId, 0);
504 pedSigma = ped->ValueAsDouble(channelId, 1);
505 manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId));
506 evt = manuCounter->Events()/64;
508 pedMeanHisto->Fill(pedMean);
509 pedSigmaHisto->Fill(pedSigma);