From: laphecet Date: Fri, 13 Nov 2009 12:47:02 +0000 (+0000) Subject: DA_PED: clean up of the code X-Git-Url: http://git.uio.no/git/?a=commitdiff_plain;h=f3cfa63e583da8a7ac532cee41ce8c11b5b5d062;p=u%2Fmrichter%2FAliRoot.git DA_PED: clean up of the code DA_GAIN: modification of the conditions (second order parameter) to validate gain values And relevant documentation update. (Jean-Luc Charvet) --- diff --git a/MUON/AliMUONErrorCounter.cxx b/MUON/AliMUONErrorCounter.cxx index ca27b242f65..f1312be0b24 100644 --- a/MUON/AliMUONErrorCounter.cxx +++ b/MUON/AliMUONErrorCounter.cxx @@ -73,7 +73,7 @@ void AliMUONErrorCounter::Print(const Option_t* option) const } //______________________________________________________________________________ -void AliMUONErrorCounter::Print_uncal(const Option_t* option) const +void AliMUONErrorCounter::PrintUncal(const Option_t* option) const { TNamed::Print(option); cout<<"bp = "<AsString("l") < Shuttle if(fIndexAsString("l")); @@ -165,9 +163,9 @@ void AliMUONGain::MakePedStoreForGain(TString shuttleFile) if(fPrintLevel>0) { // compute and store mean DAC values (like pedestals) - sprintf(flatFile,"%s.ped",fprefixDA); + flatFile = Form("%s.ped",fPrefixDA.Data()); outputFile=flatFile; - cout << "\n" << fprefixDA << " : Flat file generated : " << flatFile << "\n"; + cout << "\n" << fPrefixDA.Data() << " : Flat file generated : " << flatFile.Data() << "\n"; if (!outputFile.IsNull()) { ofstream out(outputFile.Data()); @@ -181,7 +179,7 @@ void AliMUONGain::MakePedStoreForGain(TString shuttleFile) if (fIndex==1) { mode = "RECREATE"; } - TFile* histoFile = new TFile(fRootDataFileName, mode.Data(), "MUON Tracking Gains"); + TFile* histoFile = new TFile(fRootDataFileName.Data(), mode.Data(), "MUON Tracking Gains"); // second argument should be the injected charge, taken from config crocus file // put also info about run number could be usefull @@ -217,13 +215,13 @@ TString AliMUONGain::WriteGainHeader(Int_t nInit, Int_t nEntries, Int_t nbpf2, I stream<<"//=======================================================" << endl; - stream<<"// Calibration file calculated by " << fprefixDA <AsString("l") < no condition on a2 + Double_t goodA2Max = 1.E-01; // Table for uncalibrated buspatches and manus THashList* uncalBuspatchManuTable = new THashList(1000,2); @@ -284,8 +284,8 @@ void AliMUONGain::MakeGainStore(TString shuttleFile) // Fit with a polynomial fct // store the result in a flat file. - if(fIndex==0)cout << " Root data file = " << fRootDataFileName << endl; - TFile* histoFile = new TFile(fRootDataFileName); + if(fIndex==0)cout << " Root data file = " << fRootDataFileName.Data() << endl; + TFile* histoFile = new TFile(fRootDataFileName.Data()); AliMUON2DMap* map[11]; AliMUONVCalibParam* ped[11]; @@ -318,7 +318,7 @@ void AliMUONGain::MakeGainStore(TString shuttleFile) for ( Int_t i=0 ; i<11 ; i++) {injCharge[i]=0.;injChargeErr[i]=1.;}; // some print - cout<<"\n ******** MUONTRKda for Gain computing (Last Run = " << fRunNumber << ") ********\n" << endl; + cout<<"\n ******** MUONTRKGAINda for Gain computing (Last Run = " << fRunNumber << ") ********\n" << endl; cout<<" * Date : " << fDate->AsString("l") << "\n" << endl; cout << " Entries = " << nEntries << " DAC values \n" << endl; for (Int_t i = 0; i < nEntries; ++i) { @@ -333,8 +333,8 @@ void AliMUONGain::MakeGainStore(TString shuttleFile) // print out in .log file (*fFilcout)<<"\n\n//=================================================" << endl; - (*fFilcout)<<"// MUONTRKda: Gain Computing Run = " << fRunNumber << endl; - (*fFilcout)<<"// RootDataFile = "<< fRootDataFileName << endl; + (*fFilcout)<<"// MUONTRKGAINda: Gain Computing Run = " << fRunNumber << endl; + (*fFilcout)<<"// RootDataFile = "<< fRootDataFileName.Data() << endl; (*fFilcout)<<"//=================================================" << endl; (*fFilcout)<<"//* Date : " << fDate->AsString("l") << "\n" << endl; @@ -344,9 +344,9 @@ void AliMUONGain::MakeGainStore(TString shuttleFile) FILE *pfilen = 0; if(fPrintLevel>1) { - sprintf(filename,"%s.param",fprefixDA); - cout << " Second fit parameter file = " << filename << "\n"; - pfilen = fopen (filename,"w"); + filename=Form("%s.param",fPrefixDA.Data()); + cout << " Second fit parameter file = " << filename.Data() << "\n"; + pfilen = fopen (filename.Data(),"w"); fprintf(pfilen,"//===================================================================\n"); fprintf(pfilen,"// BP MANU CH. par[0] [1] [2] [3] xlim P(chi2) p1 P(chi2)2 p2\n"); @@ -367,7 +367,7 @@ void AliMUONGain::MakeGainStore(TString shuttleFile) FILE *pfilep = 0; if(fPrintLevel>1) { - sprintf(filename,"%s.peak",fprefixDA); + filename=Form("%s.peak",fPrefixDA.Data()); cout << " File containing Peak mean values = " << filename << "\n"; pfilep = fopen (filename,"w"); @@ -393,7 +393,7 @@ void AliMUONGain::MakeGainStore(TString shuttleFile) Int_t q = 0; Int_t p1 =0; Int_t p2 =0; - Double_t gain=0; + Double_t gain=10.; // max value (= bad value) Double_t capa=0.2; // internal capacitor (pF) // plot out @@ -402,8 +402,8 @@ void AliMUONGain::MakeGainStore(TString shuttleFile) TTree* tg = 0x0; if(fPlotLevel>0) { - sprintf(fHistoFileName,"%s.root",fprefixDA); - gainFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking gains"); + fHistoFileName=Form("%s.root",fPrefixDA.Data()); + gainFile = new TFile(fHistoFileName.Data(),"RECREATE","MUON Tracking gains"); tg = new TTree("tg","TTree avec class Manu_DiMu"); tg->Branch("bp",&busPatchId, "busPatchId/I"); @@ -490,16 +490,22 @@ void AliMUONGain::MakeGainStore(TString shuttleFile) // 1. - linear fit over gAlinbpf1 points - Double_t par[4] = {0.,0.5,0.,kADCMax}; + Double_t par[4] = {0.,0.5,0.,ADCMax()}; Int_t nbs = nEntries - fnInit; if(nbs < fnbpf1)fnbpf1=nbs; Int_t fitproceed=1; + Int_t nbpf2Dynamic=nbpf2; for (Int_t j = 0; j < nbs; ++j) { Int_t k = j + fnInit; x[j] = pedMean[k]; - if(x[j]<=0. || x[j]== kADCMax)fitproceed=0; + if(x[j]<=0.){fitproceed=0; break;} + if(x[j]== ADCMax()) + { + if(j < nbs-1){fitproceed=0; break;} + else nbpf2Dynamic=nbpf2-1; + } xErr[j] = pedSigma[k]; y[j] = injCharge[k]; yErr[j] = injChargeErr[k]; @@ -512,7 +518,7 @@ void AliMUONGain::MakeGainStore(TString shuttleFile) if(fitproceed) { - TF1 *f1 = new TF1("f1",funcLin,0.,kADCMax,2); + TF1 *f1 = new TF1("f1",funcLin,0.,ADCMax(),2); graphErr = new TGraphErrors(fnbpf1, x, y, xErr, yErr); f1->SetParameters(0,0); @@ -536,9 +542,9 @@ void AliMUONGain::MakeGainStore(TString shuttleFile) // 2. - Translation : new origin (xLim, yLim) + parabolic fit over nbf2 points - if(nbpf2 > 1) + if(nbpf2Dynamic > 1) { - for (Int_t j = 0; j < nbpf2; j++) + for (Int_t j = 0; j < nbpf2Dynamic; j++) { Int_t k = j + (fnInit + fnbpf1) - 1; xp[j] = pedMean[k] - xLim; @@ -548,8 +554,8 @@ void AliMUONGain::MakeGainStore(TString shuttleFile) ypErr[j] = injChargeErr[k]; } - TF1 *f2 = new TF1("f2",funcParabolic,0.,kADCMax,1); - graphErr = new TGraphErrors(nbpf2, xp, yp, xpErr, ypErr); + TF1 *f2 = new TF1("f2",funcParabolic,0.,ADCMax(),1); + graphErr = new TGraphErrors(nbpf2Dynamic, xp, yp, xpErr, ypErr); graphErr->Fit(f2,"RQ"); chi2P2 = f2->GetChisquare(); @@ -559,7 +565,7 @@ void AliMUONGain::MakeGainStore(TString shuttleFile) graphErr=0; delete f2; - prChi2P2 = TMath::Prob(chi2P2, nbpf2-1); + prChi2P2 = TMath::Prob(chi2P2, nbpf2Dynamic-1); a2 = par[0]; } @@ -604,7 +610,7 @@ void AliMUONGain::MakeGainStore(TString shuttleFile) q=0; par[1]=0.5; a1=0.5; p1=0; par[2]=0.; a2=0.; p2=0; - threshold=kADCMax; + threshold=ADCMax(); // bad calibration counter char bpmanuname[256]; @@ -633,13 +639,14 @@ void AliMUONGain::MakeGainStore(TString shuttleFile) { // if(q==0 and nplot < 100) // if(p1>1 && p2==0 and nplot < 100) - if(p1>10 && p2>10 and nplot < 100) + // if(p1>10 && p2>10 and nplot < 100) // if(p1>=1 and p1<=2 and nplot < 100) // if((p1==1 || p2==1) and nplot < 100) + if(nbpf2Dynamic #include #include @@ -49,26 +49,25 @@ ClassImp(AliMUONPedestal) //______________________________________________________________________________ AliMUONPedestal::AliMUONPedestal() : TObject(), -fN(0), +//fN(0), fNEvents(0), fRunNumber(0), fNChannel(0), fNManu(0), -fNManu_config(0), +fNManuConfig(0), fConfig(1), fErrorBuspatchTable(new AliMUON2DMap(kFALSE)), fManuBuspatchTable(new AliMUON2DMap(kFALSE)), fManuBPoutofconfigTable(new AliMUON2DMap(kFALSE)), fDate(new TTimeStamp()), fFilcout(0), +fHistoFileName(), fPedestalStore(new AliMUON2DMap(kTRUE)), -fIndex(-1) +fIndex(-1), +fPrefixDA() { /// Default constructor - sprintf(fHistoFileName," "); - sprintf(fprefixDA," "); } -// AliMUONPedestal& operator=(const AliMUONPedestal& other); Copy ctor //______________________________________________________________________________ AliMUONPedestal::~AliMUONPedestal() @@ -81,26 +80,48 @@ AliMUONPedestal::~AliMUONPedestal() } //______________________________________________________________________________ -void AliMUONPedestal::Load_config(char* dbfile) +const char* +AliMUONPedestal::GetHistoFileName() const +{ + /// Return the name of file we use to store histograms + return fHistoFileName.Data(); +} + +//______________________________________________________________________________ +void AliMUONPedestal::LoadConfig(const char* dbfile) { /// Load MUONTRK configuration from ascii file "dbfile" (in DetDB) Int_t manuId; Int_t busPatchId; - ifstream fileinit(dbfile,ios::in); - while (!fileinit.eof()) + ifstream filein(dbfile,ios::in); + + // check if the 1st caracter of the 1st line is # (Config read from the OCDB => OffLine) + string line; + getline(filein, line, '\n'); + cout << " line 1: " << line ; + if ( int(line[0]) == 35 ) // ascii code of # character + { + cout << " ==> 1st caracter = " << line[0] << " (ascii code =" << int(line[0]) << ")" << endl; + } + else + { filein.clear(); filein.seekg(0); // rewind + cout << " ==> rewind configuration file: "<< dbfile << endl; + } + + while (!filein.eof()) { - fileinit >> busPatchId >> manuId; + filein >> busPatchId >> manuId; AliMUONErrorCounter* manuCounter; AliMUONVCalibParam* ped = static_cast(fPedestalStore ->FindObject(busPatchId, manuId)); if (!ped) { - fNManu_config++; + fNManuConfig++; fNChannel+=64; - ped = new AliMUONCalibParamND(2, kNChannels,busPatchId, manuId, -1.); // put default wise -1, not connected channel + ped = new AliMUONCalibParamND(2, AliMpConstants::ManuNofChannels(),busPatchId, manuId, -1.); // put default wise -1, not connected channel fPedestalStore ->Add(ped); if (!(manuCounter = static_cast(fManuBuspatchTable->FindObject(busPatchId,manuId)))) @@ -130,7 +151,7 @@ void AliMUONPedestal::MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, I else {fNManu++;} fNChannel+=64; // put default wise -1, not connected channel - ped = new AliMUONCalibParamND(2, kNChannels,busPatchId, manuId, -1.); + ped = new AliMUONCalibParamND(2, AliMpConstants::ManuNofChannels(),busPatchId, manuId, -1.); fPedestalStore ->Add(ped); } @@ -164,6 +185,8 @@ void AliMUONPedestal::MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, I //______________________________________________________________________________ void AliMUONPedestal::Finalize() { + /// final polishing of the store + Double_t pedMean; Double_t pedSigma; Int_t busPatchId; @@ -232,20 +255,20 @@ void AliMUONPedestal::Finalize() ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)eventCounter - pedMean*pedMean))); if(manuId == 0) { - ped->SetValueAsDouble(channelId, 0, kADCMax); - ped->SetValueAsDouble(channelId, 1, kADCMax); + ped->SetValueAsDouble(channelId, 0, ADCMax()); + ped->SetValueAsDouble(channelId, 1, ADCMax()); } if(occupancy>1) { - ped->SetValueAsDouble(channelId, 0, kADCMax); - ped->SetValueAsDouble(channelId, 1, kADCMax); - if(channelId==0)ped->SetValueAsDouble(channelId, 0, kADCMax+occupancy); + ped->SetValueAsDouble(channelId, 0, ADCMax()); + ped->SetValueAsDouble(channelId, 1, ADCMax()); + if(channelId==0)ped->SetValueAsDouble(channelId, 0, ADCMax()+occupancy); } } else { - ped->SetValueAsDouble(channelId, 0, kADCMax); - ped->SetValueAsDouble(channelId, 1, kADCMax); + ped->SetValueAsDouble(channelId, 0, ADCMax()); + ped->SetValueAsDouble(channelId, 1, ADCMax()); } } } @@ -256,13 +279,13 @@ void AliMUONPedestal::MakeASCIIoutput(ostream& out) const /// put pedestal store in the output stream out<<"//===========================================================================" << endl; - out<<"// Pedestal file calculated by "<< fprefixDA << endl; + out<<"// Pedestal file calculated by "<< fPrefixDA.Data() << endl; out<<"//===========================================================================" << endl; out<<"// * Run : " << fRunNumber << endl; out<<"// * Date : " << fDate->AsString("l") <CreateIterator()); - AliMUONVCalibParam* ped; - while ( ( ped = dynamic_cast(next() ) ) ) +// out<<"//"<ID0(); - Int_t manuId = ped->ID1(); - Double_t pedMean = ped->ValueAsDouble(0, 0); // check pedestal value for channelId=0 - - if(pedMean>kADCMax) + TIter next(fPedestalStore ->CreateIterator()); + AliMUONVCalibParam* ped; + while ( ( ped = dynamic_cast(next() ) ) ) { - occupancy=pedMean-kADCMax; - ped->SetValueAsDouble(0, 0, kADCMax); - out<<"// BusPatch = "<< busPatchId <<"\t ManuId = "<< manuId << "\t occupancy = " << occupancy <ID0(); + Int_t manuId = ped->ID1(); + Double_t pedMean = ped->ValueAsDouble(0, 0); // check pedestal value for channelId=0 - if (manuId==0 || (fConfig && static_cast(fManuBPoutofconfigTable->FindObject(busPatchId,manuId)))) - { - out<<"// BusPatch = "<< busPatchId <<"\t ManuId = "<< manuId << "\t missing in the mapping" << endl; + if(pedMean>ADCMax()) + { + writitle++; + if(writitle==1){ + out<<"//"<SetValueAsDouble(0, 0, ADCMax()); + out<<"// BusPatch = "<< busPatchId <<"\t ManuId = "<< manuId << "\t occupancy = " << occupancy <(fManuBPoutofconfigTable->FindObject(busPatchId,manuId)))) + { + writitle++; + if(writitle==1){ + out<<"//"<=0) return; // Pedestal run (fIndex=-1) Double_t pedMean; @@ -348,16 +381,16 @@ void AliMUONPedestal::MakeControlHistos() TH1F* pedMeanHisto = 0; TH1F* pedSigmaHisto = 0; - sprintf(fHistoFileName,"%s.root",fprefixDA); + fHistoFileName=Form("%s.root",fPrefixDA.Data()); histoFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking pedestals"); Char_t name[255]; Char_t title[255]; sprintf(name,"pedmean_allch"); sprintf(title,"Pedestal mean all channels"); - Int_t nx = kADCMax+1; + Int_t nx = ADCMax()+1; Int_t xmin = 0; - Int_t xmax = kADCMax; + Int_t xmax = ADCMax(); pedMeanHisto = new TH1F(name,title,nx,xmin,xmax); pedMeanHisto->SetDirectory(histoFile); diff --git a/MUON/AliMUONPedestal.h b/MUON/AliMUONPedestal.h index 73b2351c769..47ca993c5d4 100644 --- a/MUON/AliMUONPedestal.h +++ b/MUON/AliMUONPedestal.h @@ -12,18 +12,17 @@ /// // Author Alberto Baldisseri, JL Charvet -#include - -#include "AliMpConstants.h" +#ifndef ROOT_TObject +# include +#endif +#ifndef ROOT_TString +# include +#endif class AliMUONVStore; class TTimeStamp; -// global variables -const Int_t kNChannels = AliMpConstants::ManuNofChannels(); -const Int_t kADCMax = 4095; - class AliMUONPedestal : public TObject { public: @@ -39,20 +38,20 @@ class AliMUONPedestal : public TObject /// output .log file of DAs void SetAlifilcout(ofstream* stream) {fFilcout = stream;} /// return date and time - TTimeStamp* GetDate() {return fDate;} + TTimeStamp* GetDate() const {return fDate;} /// Count parity errors per Buspatch - AliMUONVStore* GetErrorBuspatchTable() {return fErrorBuspatchTable;} + AliMUONVStore* GetErrorBuspatchTable() const {return fErrorBuspatchTable;} /// return the name of DAPedestal .root file - Char_t* GetHistoFileName() {return fHistoFileName;} + const char* GetHistoFileName() const; /// load MuonTrk configuration from ascii dbfile - void Load_config(char* dbfile); + void LoadConfig(const char* dbfile); /// sum pedestal values for mean and sigma determination void MakePed(Int_t bp,Int_t manu,Int_t ch,Int_t charge); /// set config flag void SetconfigDA(Int_t ind) {fConfig = ind;} /// set specific DA prefixname - void SetprefixDA(char* folder) {sprintf(fprefixDA,"%s",folder);} + void SetprefixDA(const char* folder) { fPrefixDA=folder;} /// set the index of calibration runs void SetAliIndex(Int_t ind) {fIndex = ind;} /// Compute the pedestal data (mean, sigma) @@ -62,13 +61,15 @@ class AliMUONPedestal : public TObject /// Fill Histograms void MakeControlHistos(); - protected: - Int_t fN; ///< + Int_t ADCMax() const { return 4095; } + +protected: + // Int_t fN; ///< Int_t fNEvents; ///< Number of events Int_t fRunNumber; ///< run number Int_t fNChannel; ///< Nb of channels (pads) Int_t fNManu; ///< Nb of Manu - Int_t fNManu_config; ///< Nb of Manu in the current detector configuration + Int_t fNManuConfig; ///< Nb of Manu in the current detector configuration Int_t fConfig; ///< flag 1(0) for reading(or not) configuration ascii file AliMUONVStore* fErrorBuspatchTable; ///< Table for buspatches with parity errors AliMUONVStore* fManuBuspatchTable; ///< Occupancy rate for each (buspatch, manu) @@ -76,18 +77,20 @@ class AliMUONPedestal : public TObject TTimeStamp* fDate; ///< date ofstream* fFilcout; ///< .log output file - Char_t fHistoFileName[256]; ///< .root histo file - AliMUONVStore* fPedestalStore; ///< + TString fHistoFileName; ///< .root histo file + AliMUONVStore* fPedestalStore; ///< data container: (Pedmean,sigma) values for each (BP,manuId) Int_t fIndex; ///< calibration run index - Char_t fprefixDA[256]; ///< specific DA prefixname + TString fPrefixDA; ///< specific DA prefixname + static const Int_t fgkADCMax; ///< max channel count + private: /// Not implemented AliMUONPedestal(const AliMUONPedestal& rhs); /// Not implemented AliMUONPedestal& operator = (const AliMUONPedestal& rhs); - ClassDef(AliMUONPedestal,3) // + ClassDef(AliMUONPedestal,4) // Pedestal computing for DA }; #endif diff --git a/MUON/MUONTRKGAINda.cxx b/MUON/MUONTRKGAINda.cxx index 8d71f04cdd1..073fee51031 100644 --- a/MUON/MUONTRKGAINda.cxx +++ b/MUON/MUONTRKGAINda.cxx @@ -1,46 +1,46 @@ /* - Contact: Jean-Luc Charvet - Link: http://aliceinfo.cern.ch/static/Offline/dimuon/muon_html/README_Mchda + Contact: Jean-Luc Charvet + Link: http://aliceinfo.cern.ch/static/Offline/dimuon/muon_html/README_mchda.html + Reference Runs: 92796-92798-92800-92801-92803-92804-92807-92807-92809-92810-92811 Run Type: CALIBRATION DA Type: LDC - Number of events needed: 400 events for each calibration run - Input Files: Rawdata file (DATE format) - Output Files: local dir (not persistent) -> MUONTRKGAINda_.par - FXS -> run<#>_MCH__GAINS + Number of events needed: 400 events for each calibration run (11) + Input Files: mutrkcalibvalues and config_ldc-MTRK-S3-0 + Output Files: local dir (not persistent) -> MUONTRKGAINda.par FXS -> run<#>_MCH__GAINS Trigger types used: -*/ + */ /************************************************************************** -* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * -* * -* Author: The ALICE Off-line Project. * -* Contributors are mentioned in the code where appropriate. * -* * -* Permission to use, copy, modify and distribute this software and its * -* documentation strictly for non-commercial purposes is hereby granted * -* without fee, provided that the above copyright notice appears in all * -* copies and that both the copyright notice and this permission notice * -* appear in the supporting documentation. The authors make no claims * -* about the suitability of this software for any purpose. It is * -* provided "as is" without express or implied warranty. * -**************************************************************************/ + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ /* $Id$ */ /* ------------------------------------------------------------------------- - 2009-10-06 New version: MUONTRKGAINda.cxx,v 1.3 + 2009-11-05 New version: MUONTRKGAINda.cxx,v 1.4 ------------------------------------------------------------------------- - + Version for MUONTRKGAINda MUON tracking (A. Baldisseri, J.-L. Charvet) - - + + Rem: AliMUON2DMap stores all channels, even those which are not connected if pedMean == -1, channel not connected to a pad - - -*/ + + + */ extern "C" { #include } @@ -94,497 +94,390 @@ extern "C" { #include "AliMUONErrorCounter.h" // main routine -int main(Int_t argc, Char_t **argv) +int main(Int_t argc, const char** argv) { - - Int_t status=0; - TStopwatch timers; - timers.Start(kTRUE); - - // needed for streamer application - gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", - "*", - "TStreamerInfo", - "RIO", - "TStreamerInfo()"); - - // needed for Minuit plugin - gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", - "Minuit", - "TMinuitMinimizer", - "Minuit", - "TMinuitMinimizer(const char*)"); - - Char_t prefixDA[256]="MUONTRKGAINda"; // program prefix - - Int_t skipEvents = 0; - Int_t maxEvents = 1000000; - Int_t maxDateEvents = 1000000; - Char_t inputFile[256]=""; - - Int_t nDateEvents = 0; - Int_t nGlitchErrors= 0; - Int_t nParityErrors= 0; - Int_t nPaddingErrors= 0; - - TString logOutputFile; - - Char_t flatFile[256]=""; - TString shuttleFile; - - Int_t nEventsRecovered = 0; - Int_t nEvents = 0; - UInt_t runNumber = 0; - ofstream filcout; - Int_t nIndex = -1; - - // For DA Gain - Int_t printLevel = 0; // printout (default=0, =1 =>.ped , => .peak & .param) - Int_t plotLevel = 1; // plotout (default=1 => tree , =2 tree+Tgraph+fit) - Int_t injCharge; - - Int_t nEntries = daqDA_ECS_getTotalIteration(); // usually = 11 = Nb of calibration runs - Int_t nInit=1; // = 0 all DAC values ; = 1 DAC=0 excluded (default=1) - Int_t nbpf1=6; // nb of points for linear fit (default=6) - - - // decode the input line - for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name - { - Char_t* arg; - - arg = argv[i]; - if (arg[0] != '-') - { - // If only one argument and no "-" => DA calling from ECS - if (argc == 2) - { - sprintf(inputFile,argv[i]); - } - continue; - } - switch (arg[1]) - { - case 'f' : - i++; - sprintf(inputFile,argv[i]); - break; - case 'a' : - i++; - shuttleFile = argv[i]; - break; - case 's' : - i++; - skipEvents=atoi(argv[i]); - break; - case 'm' : - i++; - sscanf(argv[i],"%d",&maxDateEvents); - break; - case 'n' : - i++; - sscanf(argv[i],"%d",&maxEvents); - break; - case 'h' : - i++; - printf("\n******************* %s usage **********************",argv[0]); - printf("\nOnline (called from ECS) : %s (no inline options)\n",argv[0]); - printf("\n%s -options, the available options are :",argv[0]); - printf("\n-h help (this screen)"); - printf("\n"); - printf("\n Input"); - printf("\n-f (default = %s)",inputFile); - printf("\n"); - printf("\n Output"); - printf("\n-a (default = %s)",shuttleFile.Data()); - printf("\n"); - printf("\n Options"); - printf("\n-m (default = %d)",maxDateEvents); - printf("\n-s (default = %d)",skipEvents); - printf("\n-n (default = %d)",maxEvents); - - printf("\n\n"); - exit(-1); - default : - printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]); - argc = 2; exit(-1); // exit if error - } // end of switch - } // end of for i - - - //Gain object - AliMUONGain* muonGain = new AliMUONGain(); - muonGain->SetprefixDA(prefixDA); - muonGain->SetAliRootDataFileName(); // MUONTRKGAINda_data.root - // Char_t* RootDataFileName=muonGain->GetRootDataFileName();// MUONTRKGAINda_data.root - // cout << " Root data file = " << RootDataFileName << endl; - - // Reading current iteration - nIndex = daqDA_ECS_getCurrentIteration(); - if(nIndex<0)nIndex=0; // compute gain directly from existing root data file (OFFLINE only) - - if(nIndex==0) // compute gain from existing root data file: MUONTRKGAINda_data.root (OFFLINE only) - { - sprintf(flatFile,"%s_data.log",prefixDA); - logOutputFile=flatFile; - filcout.open(logOutputFile.Data()); - muonGain->SetAlifilcout(&filcout); - - sprintf(flatFile,"%s_data.par",prefixDA); - if(shuttleFile.IsNull())shuttleFile=flatFile; - - muonGain->SetAliPrintLevel(printLevel); - muonGain->SetAliPlotLevel(plotLevel); - muonGain->SetAliIndex(nIndex); // fIndex - muonGain->SetAliInit(nInit); // fnInit - muonGain->SetAliNbpf1(nbpf1); // fnbpf1 - muonGain->MakeGainStore(shuttleFile); - // ALI_AMORE instructions below are commented (not used OFFLINE) JLC 30/09/09 - // #ifdef ALI_AMORE - // std::ifstream in(shuttleFile.Data()); - // ostringstream stringout; - // char line[1024]; - // while ( in.getline(line,1024) ) - // stringout << line << "\n"; - // in.close(); - - // amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender); - // TObjString gaindata(stringout.str().c_str()); - // status = amoreDA.Send("Gains",&gaindata); - // if ( status ) - // cout << "Warning: Failed to write Pedestals in the AMORE database : " << status << endl; - // else - // cout << "amoreDA.Send(Gains) ok" << endl; - // #else - // cout << "Warning: MCH DA not compiled with AMORE support" << endl; - // #endif - } - - if(nIndex>0) // normal case: reading calibration runs before computing gains (ONLINE or OFFLINE) - { - UShort_t manuId; - UChar_t channelId; - UShort_t charge; - - // DAC values stored in array vDAC (reading dbfile in DETDB) - // Int_t vDAC[11] = {0,200,400,800,1200,1600,2000,2500,3000,3500,4000} - Int_t nConfig = 1; // flag to read or not configuration ascii file in detDB - Int_t vDAC[11]; // DAC values - Char_t *dbfile; - dbfile="mutrkcalibvalues"; - cout << "\n *** Copy: " << dbfile << " from DetDB to working directory *** \n" << endl; - status=daqDA_DB_getFile(dbfile,dbfile); - ifstream filein(dbfile,ios::in); Int_t k=0, kk; - while (k> kk >> vDAC[k] ; k++; } - injCharge=vDAC[nIndex-1]; - - - filein >> nInit; // = 0 all DAC values fitted ; = 1 DAC=0 excluded (default=1) - filein >> nbpf1; // nb of points for linear fit (default=6) - filein >> printLevel; // printout (default=0, =1 =>.ped /run, =2 => .peak & .param) - filein >> plotLevel; // plotout (default=1 => tree , =2 tree+Tgraph+fit) - filein >> nConfig; //nConfig (default=1 => read config in DetDB, otherwise =0) - - cout << "nInit=" << nInit << " Nb linear pts=" << nbpf1 << " Print level=" << printLevel << " Plot Level=" << plotLevel << " Config= " << nConfig << endl; - - muonGain->SetAliPrintLevel(printLevel); - muonGain->SetAliPlotLevel(plotLevel); - muonGain->SetconfigDA(nConfig); - - if(nConfig) - { - // Laod configuration ascii file from DetDB - Char_t dbfil[256]=""; - sprintf(dbfil,"config_%s",getenv("DATE_ROLE_NAME")); - cout << "\n *** Copy ascii config file: " << dbfil << " from DetDB to working directory and reading ...*** \n" << endl; - status=daqDA_DB_getFile(dbfil,dbfil); - muonGain->Load_config(dbfil); - } - - - // Rawdeader, RawStreamHP - AliRawReader* rawReader = AliRawReader::Create(inputFile); - AliMUONRawStreamTrackerHP* rawStream = new AliMUONRawStreamTrackerHP(rawReader); - rawStream->DisableWarnings(); - rawStream->EnabbleErrorLogger(); - - cout << "\n" << prefixDA << " : Reading data from file " << inputFile << endl; - - while (rawReader->NextEvent()) - { - if (nDateEvents >= maxDateEvents) break; - if (nEvents >= maxEvents) break; - if (nDateEvents>0 && nDateEvents % 100 == 0) - cout<<"Cumulated: DATE events = " << nDateEvents << " Used events = " << nEvents << endl; - - // check shutdown condition - if (daqDA_checkShutdown()) - break; - - //Skip events - while (skipEvents) + Int_t status=0; + TStopwatch timers; + timers.Start(kTRUE); + + const char* prefixDA = "MUONTRKGAINda"; // program prefix + printf(" ######## Begin execution : %s ######## \n\n",prefixDA); + + TString inputFile; + // decode the input line + if (argc!=2) { printf("Wrong number of arguments\n"); return -1; } + + inputFile = argv[1]; + + // needed for streamer application + gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", + "*", + "TStreamerInfo", + "RIO", + "TStreamerInfo()"); + // needed for Minuit plugin + gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", + "Minuit", + "TMinuitMinimizer", + "Minuit", + "TMinuitMinimizer(const char*)"); + Int_t skipEvents = 0; + Int_t maxEvents = 1000000; + Int_t maxDateEvents = 1000000; + + Int_t nDateEvents = 0; + Int_t nGlitchErrors= 0; + Int_t nParityErrors= 0; + Int_t nPaddingErrors= 0; + Int_t nEventsRecovered = 0; + Int_t nEvents = 0; + + TString logOutputFile; + Char_t flatFile[256]=""; + TString shuttleFile; + + UInt_t runNumber = 0; + ofstream filcout; + Int_t nIndex = -1; + + // For DA Gain + Int_t nEntries = daqDA_ECS_getTotalIteration(); // usually = 11 = Nb of calibration runs + Int_t nInit=1; // = 0 all DAC values ; = 1 DAC=0 excluded (default=1) + Int_t nbpf1=6; // nb of points for linear fit (default=6) + Int_t printLevel = 0; // printout (default=0, =1 =>.ped , => .peak & .param) + Int_t plotLevel = 1; // plotout (default=1 => tree , =2 tree+Tgraph+fit) + Int_t nbev=0; + Int_t injCharge; + + // Reading current iteration + nIndex = daqDA_ECS_getCurrentIteration(); + if(nIndex<0 || nIndex>nEntries) {printf("\n Failed: nIndex = %d\n",nIndex); return -1 ;} + + //Gain object + AliMUONGain* muonGain = new AliMUONGain(); + muonGain->SetprefixDA(prefixDA); + muonGain->SetAliRootDataFileName(); // MUONTRKGAINda_data.root + + UShort_t manuId; + UChar_t channelId; + UShort_t charge; + + // DAC values stored in array vDAC (reading dbfile in DETDB) + // Int_t vDAC[11] = {0,200,400,800,1200,1600,2000,2500,3000,3500,4000} + Int_t nConfig = 1; // flag to read or not configuration ascii file in detDB + Int_t vDAC[11]; // DAC values + Char_t dbfile[256]=""; + sprintf(dbfile,"mutrkcalibvalues"); + status=daqDA_DB_getFile(dbfile,dbfile); + if(status) {printf(" Failed : input file %s is missing, status = %d\n",dbfile,status); return -1; } + + ifstream filein(dbfile,ios::in); Int_t k=0, kk; + while (k> kk >> vDAC[k] ; k++; } + injCharge=vDAC[nIndex-1]; + + filein >> nInit; // = 0 all DAC values fitted ; = 1 DAC=0 excluded (default=1) + filein >> nbpf1; // nb of points for linear fit (default=6) + filein >> printLevel; // printout (default=0, =1 =>.ped /run, =2 => .peak & .param) + filein >> plotLevel; // plotout (default=1 => tree , =2 tree+Tgraph+fit) + filein >> nConfig; //nConfig (default=1 => read config in DetDB, otherwise =0) + filein >> nbev; // Nb of events to read (default = 0 => reading all events) + if(nbev>0)maxEvents=nbev; + + printf(" *** Copy: %s from DetDB to working directory *** Config= %d\n",dbfile,nConfig); + printf(" Input parameters: nInit= %d Nb linear pts= %d Print level= %d Plot Level= %d",nInit,nbpf1,printLevel,plotLevel); + if(nbev==0)printf("\n"); + else printf(" Nb_max evt = %d\n",maxEvents); + + muonGain->SetAliPrintLevel(printLevel); + muonGain->SetAliPlotLevel(plotLevel); + muonGain->SetconfigDA(nConfig); + + if(nConfig) + { + // Laod configuration ascii file from DetDB + sprintf(dbfile,"config_%s",getenv("DATE_ROLE_NAME")); + status=daqDA_DB_getFile(dbfile,dbfile); + if(status) {printf(" Failed : Configuration file %s is missing, status = %d\n",dbfile,status); return -1; } + else printf(" *** Copy ascii config file: %s from DetDB to working directory and reading ...*** \n",dbfile); + muonGain->LoadConfig(dbfile); + } + + // Rawdeader, RawStreamHP + AliRawReader* rawReader = AliRawReader::Create(inputFile.Data()); + AliMUONRawStreamTrackerHP* rawStream = new AliMUONRawStreamTrackerHP(rawReader); + rawStream->DisableWarnings(); + rawStream->EnabbleErrorLogger(); + + cout << "\n" << prefixDA << " : Reading data from file " << inputFile.Data() << endl; + + while (rawReader->NextEvent()) + { + if (nDateEvents >= maxDateEvents) break; + if (nEvents >= maxEvents) break; + if (nDateEvents>0 && nDateEvents % 100 == 0) + cout<<"Cumulated: DATE events = " << nDateEvents << " Used events = " << nEvents << endl; + + // check shutdown condition + if (daqDA_checkShutdown()) + break; + //Skip events + while (skipEvents) + { + rawReader->NextEvent(); + skipEvents--; + } + + Int_t eventType = rawReader->GetType(); + runNumber = rawReader->GetRunNumber(); + + // Output log file initialisations + if(nDateEvents==0) + { + sprintf(flatFile,"%s.log",prefixDA); + logOutputFile=flatFile; + + filcout.open(logOutputFile.Data()); + filcout<<"//=================================================" << endl; + filcout<<"// " << prefixDA << " for run = " << runNumber << " (DAC=" << injCharge << ")" << endl; + filcout<<"//=================================================" << endl; + filcout<<"// * Date : " << muonGain->GetDate()->AsString("l") << "\n" << endl; + + cout<<"\n ******** " << prefixDA << " for run = " << runNumber << " (Index= " << nIndex << "/" << nEntries << " DAC=" << injCharge << ") ********\n" << endl; + cout<<" * Date : " << muonGain->GetDate()->AsString("l") << "\n" << endl; + } + + muonGain->SetAlifilcout(&filcout); + + nDateEvents++; + if (eventType != PHYSICS_EVENT) + continue; // for the moment + + // First lopp over DDL's to find good events + // Error counters per event (counters in the decoding lib are for each DDL) + Bool_t eventIsErrorMessage = kFALSE; + int eventGlitchErrors = 0; + int eventParityErrors = 0; + int eventPaddingErrors = 0; + rawStream->First(); + do + { + if (rawStream->IsErrorMessage()) eventIsErrorMessage = kTRUE; + eventGlitchErrors += rawStream->GetGlitchErrors(); + eventParityErrors += rawStream->GetParityErrors(); + eventPaddingErrors += rawStream->GetPaddingErrors(); + } while(rawStream->NextDDL()); + + AliMUONRawStreamTrackerHP::AliBusPatch* busPatch; + if (!eventIsErrorMessage) + { + // Good events (no error) -> compute pedestal for all channels + rawStream->First(); + while( (busPatch = (AliMUONRawStreamTrackerHP::AliBusPatch*) rawStream->Next())) { - rawReader->NextEvent(); - skipEvents--; + for(int i = 0; i < busPatch->GetLength(); ++i) + { + busPatch->GetData(i, manuId, channelId, charge); + muonGain->MakePed(busPatch->GetBusPatchId(), (Int_t)manuId, (Int_t)channelId, (Int_t)charge); + } } - - Int_t eventType = rawReader->GetType(); - runNumber = rawReader->GetRunNumber(); - - // Output log file initialisations - if(nDateEvents==0) - { - sprintf(flatFile,"%s.log",prefixDA); - logOutputFile=flatFile; - - filcout.open(logOutputFile.Data()); - filcout<<"//=================================================" << endl; - filcout<<"// " << prefixDA << " for run = " << runNumber << " (DAC=" << injCharge << ")" << endl; - filcout<<"//=================================================" << endl; - filcout<<"// * Date : " << muonGain->GetDate()->AsString("l") << "\n" << endl; - - cout<<"\n ******** " << prefixDA << " for run = " << runNumber << " (Index= " << nIndex << "/" << nEntries << " DAC=" << injCharge << ") ********\n" << endl; - cout<<" * Date : " << muonGain->GetDate()->AsString("l") << "\n" << endl; - } - - muonGain->SetAlifilcout(&filcout); - - nDateEvents++; - if (eventType != PHYSICS_EVENT) - continue; // for the moment - - // First lopp over DDL's to find good events - // Error counters per event (counters in the decoding lib are for each DDL) - Bool_t eventIsErrorMessage = kFALSE; - int eventGlitchErrors = 0; - int eventParityErrors = 0; - int eventPaddingErrors = 0; - rawStream->First(); - do - { - if (rawStream->IsErrorMessage()) eventIsErrorMessage = kTRUE; - eventGlitchErrors += rawStream->GetGlitchErrors(); - eventParityErrors += rawStream->GetParityErrors(); - eventPaddingErrors += rawStream->GetPaddingErrors(); - } while(rawStream->NextDDL()); - - AliMUONRawStreamTrackerHP::AliBusPatch* busPatch; - if (!eventIsErrorMessage) + nEvents++; + } + else + { + // Events with errors + if (eventParityErrors && !eventGlitchErrors&& !eventPaddingErrors) { - // Good events (no error) -> compute pedestal for all channels - rawStream->First(); + // Recover parity errors -> compute pedestal for all good buspatches + if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(), + ATTR_ORBIT_BC )) + { + filcout <<"Event recovered -> Period:"<GetEventId() ) + <<" Orbit:"<GetEventId() ) + <<" BunchCrossing:"<GetEventId() )< nbInRun:"<GetEventId() ) + <<" burstNb:"<GetEventId() ) + <<" nbInBurst:"<GetEventId() )<First(); while( (busPatch = (AliMUONRawStreamTrackerHP::AliBusPatch*) rawStream->Next())) - { - for(int i = 0; i < busPatch->GetLength(); ++i) - { - busPatch->GetData(i, manuId, channelId, charge); - muonGain->MakePed(busPatch->GetBusPatchId(), (Int_t)manuId, (Int_t)channelId, (Int_t)charge); - } - } + { + // Check the buspatch -> if error not use it in the pedestal calculation + int errorCount = 0; + for(int i = 0; i < busPatch->GetLength(); ++i) + { + if (!busPatch->IsParityOk(i)) errorCount++; + } + if (!errorCount) + { + // Good buspatch + for(int i = 0; i < busPatch->GetLength(); ++i) + { + busPatch->GetData(i, manuId, channelId, charge); + muonGain->MakePed(busPatch->GetBusPatchId(), (Int_t)manuId, (Int_t)channelId, (Int_t)charge); + } + } + else + { + char bpname[256]; + AliMUONErrorCounter* errorCounter; + // Bad buspatch -> not used (just print) + filcout<<"bpId "<GetBusPatchId()<<" words "<GetLength() + <<" parity errors "<GetBusPatchId()); + if (!(errorCounter = (AliMUONErrorCounter*) (muonGain->GetErrorBuspatchTable()->FindObject(bpname)))) + { + // New buspatch + errorCounter = new AliMUONErrorCounter(busPatch->GetBusPatchId()); + errorCounter->SetName(bpname); + muonGain->GetErrorBuspatchTable()->Add(errorCounter); + } + else + { + // Existing buspatch + errorCounter->Increment(); + } + // errorCounter->Print(); + } // end of if (!errorCount) + } // end of while( (busPatch = (AliMUONRawStreamTrackerHP ... nEvents++; - } - else + nEventsRecovered++; + } //end of if (eventParityErrors && !eventGlitchErrors&& !eventPaddingErrors) + else { - // Events with errors - if (eventParityErrors && !eventGlitchErrors&& !eventPaddingErrors) - { - // Recover parity errors -> compute pedestal for all good buspatches - if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(), - ATTR_ORBIT_BC )) - { - filcout <<"Event recovered -> Period:"<GetEventId() ) - <<" Orbit:"<GetEventId() ) - <<" BunchCrossing:"<GetEventId() )< nbInRun:"<GetEventId() ) - <<" burstNb:"<GetEventId() ) - <<" nbInBurst:"<GetEventId() )<First(); - while( (busPatch = (AliMUONRawStreamTrackerHP::AliBusPatch*) rawStream->Next())) - { - // Check the buspatch -> if error not use it in the pedestal calculation - int errorCount = 0; - for(int i = 0; i < busPatch->GetLength(); ++i) - { - if (!busPatch->IsParityOk(i)) errorCount++; - } - if (!errorCount) - { - // Good buspatch - for(int i = 0; i < busPatch->GetLength(); ++i) - { - busPatch->GetData(i, manuId, channelId, charge); - muonGain->MakePed(busPatch->GetBusPatchId(), (Int_t)manuId, (Int_t)channelId, (Int_t)charge); - } - } - else - { - char bpname[256]; - AliMUONErrorCounter* errorCounter; - // Bad buspatch -> not used (just print) - filcout<<"bpId "<GetBusPatchId()<<" words "<GetLength() - <<" parity errors "<GetBusPatchId()); - if (!(errorCounter = (AliMUONErrorCounter*) (muonGain->GetErrorBuspatchTable()->FindObject(bpname)))) - { - // New buspatch - errorCounter = new AliMUONErrorCounter(busPatch->GetBusPatchId()); - errorCounter->SetName(bpname); - muonGain->GetErrorBuspatchTable()->Add(errorCounter); - } - else - { - // Existing buspatch - errorCounter->Increment(); - } - // errorCounter->Print(); - } // end of if (!errorCount) - } // end of while( (busPatch = (AliMUONRawStreamTrackerHP ... - nEvents++; - nEventsRecovered++; - } //end of if (eventParityErrors && !eventGlitchErrors&& !eventPaddingErrors) - else - { - // Fatal errors reject the event - if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(), - ATTR_ORBIT_BC )) - { - filcout <<"Event rejected -> Period:"<GetEventId() ) - <<" Orbit:"<GetEventId() ) - <<" BunchCrossing:"<GetEventId() )< nbInRun:"<GetEventId() ) - <<" burstNb:"<GetEventId() ) - <<" nbInBurst:"<GetEventId() )<GetGlitchErrors() && !rawStream->GetPaddingErrors() ... - filcout<<"Number of errors : Glitch "<IsErrorMessage()) - - if (eventGlitchErrors) nGlitchErrors++; - if (eventParityErrors) nParityErrors++; - if (eventPaddingErrors) nPaddingErrors++; - - } // while (rawReader->NextEvent()) - delete rawReader; - delete rawStream; - - // process and store mean peak values in .root file - sprintf(flatFile,"%s.par",prefixDA); - if(shuttleFile.IsNull())shuttleFile=flatFile; - injCharge=vDAC[nIndex-1]; - muonGain->SetAliIndex(nIndex); // fIndex - muonGain->SetAliInjCharge(injCharge); - muonGain->SetAliNEvents(nEvents); - muonGain->SetAliRunNumber(runNumber); - muonGain->MakePedStoreForGain(shuttleFile); - - - // writing some counters - cout << endl; - cout << prefixDA << " : Nb of DATE events = " << nDateEvents << endl; - cout << prefixDA << " : Nb of Glitch errors = " << nGlitchErrors << endl; - cout << prefixDA << " : Nb of Parity errors = " << nParityErrors << endl; - cout << prefixDA << " : Nb of Padding errors = " << nPaddingErrors << endl; - cout << prefixDA << " : Nb of events recovered = " << nEventsRecovered<< endl; - cout << prefixDA << " : Nb of events without errors = " << nEvents-nEventsRecovered<< endl; - cout << prefixDA << " : Nb of events used = " << nEvents << endl; - - filcout << endl; - filcout << prefixDA << " : Nb of DATE events = " << nDateEvents << endl; - filcout << prefixDA << " : Nb of Glitch errors = " << nGlitchErrors << endl; - filcout << prefixDA << " : Nb of Parity errors = " << nParityErrors << endl; - filcout << prefixDA << " : Nb of Padding errors = " << nPaddingErrors << endl; - filcout << prefixDA << " : Nb of events recovered = " << nEventsRecovered<< endl; - filcout << prefixDA << " : Nb of events without errors = " << nEvents-nEventsRecovered<< endl; - filcout << prefixDA << " : Nb of events used = " << nEvents << endl; - - // Computing gain - if(nIndex==nEntries) - { - muonGain->SetAliInit(nInit); // fnInit - muonGain->SetAliEntries(nEntries); // fnEntries - muonGain->SetAliNbpf1(nbpf1); // fnbpf1 - muonGain->MakeGainStore(shuttleFile); + // Fatal errors reject the event + if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(), + ATTR_ORBIT_BC )) + { + filcout <<"Event rejected -> Period:"<GetEventId() ) + <<" Orbit:"<GetEventId() ) + <<" BunchCrossing:"<GetEventId() )< nbInRun:"<GetEventId() ) + <<" burstNb:"<GetEventId() ) + <<" nbInBurst:"<GetEventId() )<GetGlitchErrors() && !rawStream->GetPaddingErrors() ... + filcout<<"Number of errors : Glitch "<IsErrorMessage()) + + if (eventGlitchErrors) nGlitchErrors++; + if (eventParityErrors) nParityErrors++; + if (eventPaddingErrors) nPaddingErrors++; + + } // while (rawReader->NextEvent()) + delete rawReader; + delete rawStream; + + // process and store mean peak values in .root file + sprintf(flatFile,"%s.par",prefixDA); + if(shuttleFile.IsNull())shuttleFile=flatFile; + injCharge=vDAC[nIndex-1]; + muonGain->SetAliIndex(nIndex); // fIndex + muonGain->SetAliInjCharge(injCharge); + muonGain->SetAliNEvents(nEvents); + muonGain->SetAliRunNumber(runNumber); + muonGain->MakePedStoreForGain(shuttleFile); + + + // writing some counters + cout << endl; + cout << prefixDA << " : Nb of DATE events = " << nDateEvents << endl; + cout << prefixDA << " : Nb of Glitch errors = " << nGlitchErrors << endl; + cout << prefixDA << " : Nb of Parity errors = " << nParityErrors << endl; + cout << prefixDA << " : Nb of Padding errors = " << nPaddingErrors << endl; + cout << prefixDA << " : Nb of events recovered = " << nEventsRecovered<< endl; + cout << prefixDA << " : Nb of events without errors = " << nEvents-nEventsRecovered<< endl; + cout << prefixDA << " : Nb of events used = " << nEvents << endl; + + filcout << endl; + filcout << prefixDA << " : Nb of DATE events = " << nDateEvents << endl; + filcout << prefixDA << " : Nb of Glitch errors = " << nGlitchErrors << endl; + filcout << prefixDA << " : Nb of Parity errors = " << nParityErrors << endl; + filcout << prefixDA << " : Nb of Padding errors = " << nPaddingErrors << endl; + filcout << prefixDA << " : Nb of events recovered = " << nEventsRecovered<< endl; + filcout << prefixDA << " : Nb of events without errors = " << nEvents-nEventsRecovered<< endl; + filcout << prefixDA << " : Nb of events used = " << nEvents << endl; + + // Computing gain + if(nIndex==nEntries) + { + muonGain->SetAliInit(nInit); // fnInit + muonGain->SetAliEntries(nEntries); // fnEntries + muonGain->SetAliNbpf1(nbpf1); // fnbpf1 + muonGain->MakeGainStore(shuttleFile); #ifdef ALI_AMORE - std::ifstream in(shuttleFile.Data()); - ostringstream stringout; - char line[1024]; - while ( in.getline(line,1024) ) - stringout << line << "\n"; - in.close(); + std::ifstream in(shuttleFile.Data()); + ostringstream stringout; + char line[1024]; + while ( in.getline(line,1024) ) + stringout << line << "\n"; + in.close(); - amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender); - TObjString gaindata(stringout.str().c_str()); - status = amoreDA.Send("Gains",&gaindata); - if ( status ) - cout << "Warning: Failed to write Pedestals in the AMORE database : " << status << endl; - else - cout << "amoreDA.Send(Gains) ok" << endl; + amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender); + TObjString gaindata(stringout.str().c_str()); + status = amoreDA.Send("Gains",&gaindata); + if ( status ) + cout << "Warning: Failed to write Pedestals in the AMORE database : " << status << endl; + else + cout << "amoreDA.Send(Gains) ok" << endl; #else - cout << "Warning: MCH DA not compiled with AMORE support" << endl; + cout << "Warning: MCH DA not compiled with AMORE support" << endl; #endif - } - -// ouput files - filcout << endl; - filcout << prefixDA << " : Root data file : " << muonGain->GetRootDataFileName() << endl; - filcout << prefixDA << " : Output logfile : " << logOutputFile << endl; - filcout << prefixDA << " : Gain Histo file : " << muonGain->GetHistoFileName() << endl; - filcout << prefixDA << " : Gain file (to SHUTTLE) : " << shuttleFile << endl; - -// Copying files to local DB folder defined by DAQ_DETDB_LOCAL - Char_t *dir; - dir= getenv("DAQ_DETDB_LOCAL"); - unsigned int nLastVersions = 90; - cout << "\n *** Local DataBase: " << dir << " (Max= " << nLastVersions << ") ***" << endl; - status = daqDA_localDB_storeFile(logOutputFile.Data(),nLastVersions); - printf(" Store file : %s status = %d\n",logOutputFile.Data(),status); - if(nIndex==nEntries) - { - status = daqDA_localDB_storeFile(muonGain->GetRootDataFileName(),nLastVersions); - printf(" Store file : %s status = %d\n",muonGain->GetRootDataFileName(),status); - status = daqDA_localDB_storeFile(muonGain->GetHistoFileName(),nLastVersions); - printf(" Store file : %s status = %d\n",muonGain->GetHistoFileName(),status); - status = daqDA_localDB_storeFile(shuttleFile.Data(),nLastVersions); - printf(" Store file : %s status = %d\n",shuttleFile.Data(),status); - } - - } // end (nIndex>0) - -// ouput files + } + + // ouput files + filcout << endl; + filcout << prefixDA << " : Root data file : " << muonGain->GetRootDataFileName() << endl; + filcout << prefixDA << " : Output logfile : " << logOutputFile << endl; + filcout << prefixDA << " : Gain Histo file : " << muonGain->GetHistoFileName() << endl; + filcout << prefixDA << " : Gain file (to SHUTTLE) : " << shuttleFile << endl; + + // Copying files to local DB folder defined by DAQ_DETDB_LOCAL + Char_t *dir; + dir= getenv("DAQ_DETDB_LOCAL"); + unsigned int nLastVersions = 90; + printf("\n *** Local DataBase: %s (Max= %d) ***\n",dir,nLastVersions); + status = daqDA_localDB_storeFile(logOutputFile.Data(),nLastVersions); + if(status)printf(" Store file : %s status = %d\n",logOutputFile.Data(),status); + if(nIndex==nEntries) + { + status = daqDA_localDB_storeFile(muonGain->GetRootDataFileName(),nLastVersions); + if(status)printf(" Store file : %s status = %d\n",muonGain->GetRootDataFileName(),status); + status = daqDA_localDB_storeFile(muonGain->GetHistoFileName(),nLastVersions); + if(status)printf(" Store file : %s status = %d\n",muonGain->GetHistoFileName(),status); + status = daqDA_localDB_storeFile(shuttleFile.Data(),nLastVersions); + if(status)printf(" Store file : %s status = %d\n",shuttleFile.Data(),status); + } + + + // ouput files cout << endl; cout << prefixDA << " : Root data file : " << muonGain->GetRootDataFileName() << endl; cout << prefixDA << " : Output logfile : " << logOutputFile << endl; cout << prefixDA << " : Gain Histo file : " << muonGain->GetHistoFileName() << endl; cout << prefixDA << " : Gain file (to SHUTTLE) : " << shuttleFile << endl; - - + + filcout.close(); + // Transferring to OCDB via the SHUTTLE - printf("\n ***** STORE FILE in FES ****** \n"); - // be sure that env variable DAQDALIB_PATH is set in script file // gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger"); - + printf("\n ***** STORE FILE in FES ****** \n"); status = daqDA_FES_storeFile(shuttleFile.Data(),"GAINS"); - if (status) - { - printf(" Failed to export file : %d\n",status); - } + if (status) { printf(" Failed to export file : %s , status = %d\n",shuttleFile.Data(),status); return -1; } else printf(" %s successfully exported to FES \n",shuttleFile.Data()); - - - filcout.close(); + + printf("\n ######## End execution : %s ######## \n",prefixDA); timers.Stop(); printf("\nExecution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime()); return status; diff --git a/MUON/MUONTRKPEDda.cxx b/MUON/MUONTRKPEDda.cxx index c07efd54fec..5b19d67fa54 100644 --- a/MUON/MUONTRKPEDda.cxx +++ b/MUON/MUONTRKPEDda.cxx @@ -1,13 +1,13 @@ /* -Contact: Jean-Luc Charvet -Link: http://aliceinfo.cern.ch/static/Offline/dimuon/muon_html/README_Mchda -Run Type: PEDESTAL - DA Type: LDC - Number of events needed: 400 events for pedestal run - Input Files: Rawdata file (DATE format) - Output Files: local dir (not persistent) -> MUONTRKPEDda_.ped - FXS -> run<#>_MCH__PEDESTALS - Trigger types used: + Contact: Jean-Luc Charvet + Link: http://aliceinfo.cern.ch/static/Offline/dimuon/muon_html/README_mchda.html + Reference Run: + Run Type: PEDESTAL + DA Type: LDC + Number of events needed: 400 events for pedestal run + Input Files: mutrkpedvalues and config_ldc-MTRK-S3-0 + Output Files: local dir (not persistent) -> MUONTRKPEDda.ped FXS -> run<#>_MCH__PEDESTALS + Trigger types used: */ /************************************************************************** @@ -29,7 +29,7 @@ Run Type: PEDESTAL /* ------------------------------------------------------------------------- - 2009-10-06 New version: MUONTRKPEDda.cxx,v 1.3 + 2009-11-05 New version: MUONTRKPEDda.cxx,v 1.4 ------------------------------------------------------------------------- Version for MUONTRKPEDda MUON tracking @@ -95,34 +95,33 @@ extern "C" { // main routine -int main(Int_t argc, Char_t **argv) +int main(Int_t argc, const char **argv) { - Int_t status=0; TStopwatch timers; timers.Start(kTRUE); + const char* prefixDA = "MUONTRKPEDda"; // program prefix + printf(" ######## Begin execution : %s ######## \n\n",prefixDA); + // needed for streamer application gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*", "TStreamerInfo", "RIO", "TStreamerInfo()"); - // needed for Minuit plugin gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", "Minuit", "TMinuitMinimizer", "Minuit", "TMinuitMinimizer(const char*)"); - - Char_t prefixDA[256]="MUONTRKPEDda"; // program prefix // cout << argv[0]; Int_t skipEvents = 0; Int_t maxEvents = 1000000; Int_t maxDateEvents = 1000000; - Char_t inputFile[256]=""; + TString inputFile; Int_t nDateEvents = 0; Int_t nGlitchErrors= 0; @@ -138,12 +137,13 @@ int main(Int_t argc, Char_t **argv) Int_t nEventsRecovered = 0; Int_t nEvents = 0; UInt_t runNumber = 0; + Int_t nConfig = 1; ofstream filcout; // decode the input line for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name { - Char_t* arg; + const char* arg = argv[i]; arg = argv[i]; if (arg[0] != '-') @@ -151,7 +151,7 @@ int main(Int_t argc, Char_t **argv) // If only one argument and no "-" => DA calling from ECS if (argc == 2) { - sprintf(inputFile,argv[i]); + inputFile=argv[i]; } continue; } @@ -159,7 +159,8 @@ int main(Int_t argc, Char_t **argv) { case 'f' : i++; - sprintf(inputFile,argv[i]); + inputFile=argv[i]; + nConfig=0; break; case 'a' : i++; @@ -181,11 +182,12 @@ int main(Int_t argc, Char_t **argv) i++; printf("\n******************* %s usage **********************",argv[0]); printf("\nOnline (called from ECS) : %s (no inline options)\n",argv[0]); + printf("\n%s can be used locally only with options (without DiMuon configuration file)",argv[0]); printf("\n%s -options, the available options are :",argv[0]); printf("\n-h help (this screen)"); printf("\n"); printf("\n Input"); - printf("\n-f (default = %s)",inputFile); + printf("\n-f (default = %s)",inputFile.Data()); printf("\n"); printf("\n Output"); printf("\n-a (default = %s)",shuttleFile.Data()); @@ -213,26 +215,32 @@ int main(Int_t argc, Char_t **argv) AliMUONPedestal* muonPedestal = new AliMUONPedestal(); muonPedestal->SetprefixDA(prefixDA); - // Reading configuration status via "mutrkpedvalues" file located in DetDB - // config=1: config ascii file read from DetDB, otherwise: config=0 - Int_t nConfig = 1; - Char_t *dbfile; - dbfile="mutrkpedvalues"; - cout << "\n *** Copy: " << dbfile << " from DetDB to working directory *** \n" << endl; + Char_t dbfile[256]=""; + // nConfig=1 : Reading configuration (or not) status via "mutrkpedvalues" file located in DetDB + if(nConfig) + { + sprintf(dbfile,"mutrkpedvalues"); status=daqDA_DB_getFile(dbfile,dbfile); + if(status) {printf(" Failed : input file %s is missing, status = %d\n",dbfile,status); return -1; } ifstream filein(dbfile,ios::in); filein >> nConfig; - cout << " Config= " << nConfig << endl; + printf(" *** Copy: %s from DetDB to working directory *** Config= %d\n",dbfile,nConfig); + } + else + { + printf(" *** Config= %d: no configuration ascii file is used \n",nConfig); + } muonPedestal->SetconfigDA(nConfig); + // nConfig=1: configuration ascii file read from DetDB if(nConfig) { - // MuonTrk Configuration ascii file (initCROCUS.dat -> ascii file = mutrkconfig) - Char_t dbfil[256]=""; - sprintf(dbfil,"config_%s",getenv("DATE_ROLE_NAME")); - cout << "\n *** Copy ascii config file: " << dbfil << " from DetDB to working directory and reading ...*** \n" << endl; - status=daqDA_DB_getFile(dbfil,dbfil); - muonPedestal->Load_config(dbfil); + // MuonTrk Configuration ascii file (initCROCUS.dat -> ascii file = config_$DATE_ROLE_NAME) + sprintf(dbfile,"config_%s",getenv("DATE_ROLE_NAME")); + status=daqDA_DB_getFile(dbfile,dbfile); + if(status) {printf(" Failed : Configuration file %s is missing, status = %d\n",dbfile,status); return -1; } + else printf(" *** Copy ascii config file: %s from DetDB to working directory and reading ...*** \n",dbfile); + muonPedestal->Load_config(dbfile); } // Rawdeader, RawStreamHP @@ -241,7 +249,7 @@ int main(Int_t argc, Char_t **argv) rawStream->DisableWarnings(); rawStream->EnabbleErrorLogger(); - cout << "\n" << prefixDA << " : Reading data from file " << inputFile << endl; + printf("\n %s : Reading data from file %s\n",prefixDA,inputFile.Data()); while (rawReader->NextEvent()) { @@ -478,26 +486,21 @@ int main(Int_t argc, Char_t **argv) unsigned int nLastVersions=90; cout << "\n *** Local DataBase: " << dir << " (Max= " << nLastVersions << ") ***" << endl; status = daqDA_localDB_storeFile(muonPedestal->GetHistoFileName(),nLastVersions); - printf(" Store file : %s status = %d\n",muonPedestal->GetHistoFileName(),status); + if(status)printf(" Store file : %s status = %d\n",muonPedestal->GetHistoFileName(),status); status = daqDA_localDB_storeFile(shuttleFile.Data(),nLastVersions); - printf(" Store file : %s status = %d\n",shuttleFile.Data(),status); + if(status)printf(" Store file : %s status = %d\n",shuttleFile.Data(),status); status = daqDA_localDB_storeFile(logOutputFile.Data(),nLastVersions); - printf(" Store file : %s status = %d\n",logOutputFile.Data(),status); + if(status)printf(" Store file : %s status = %d\n",logOutputFile.Data(),status); - // Transferring to OCDB via the SHUTTLE - printf("\n ***** STORE FILE in FES ****** \n"); - - // be sure that env variable DAQDALIB_PATH is set in script file - // gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger"); + filcout.close(); + // Transferring to OCDB via the SHUTTLE (be sure that env variable DAQDALIB_PATH is set) + printf("\n ***** STORE FILE in FES ****** \n"); status = daqDA_FES_storeFile(shuttleFile.Data(),"PEDESTALS"); - if (status) - { - printf(" Failed to export file : %d\n",status); - } + if (status) { printf(" Failed to export file : %s , status = %d\n",shuttleFile.Data(),status); return -1; } else printf(" %s successfully exported to FES \n",shuttleFile.Data()); - filcout.close(); + printf("\n ######## End execution : %s ######## \n",prefixDA); timers.Stop(); printf("\nExecution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime()); return status; diff --git a/MUON/READMEmchda.txt b/MUON/READMEmchda.txt index 9431413ace2..ad643d05523 100644 --- a/MUON/READMEmchda.txt +++ b/MUON/READMEmchda.txt @@ -21,26 +21,28 @@ The Muon tracking chambers needs three types of calibration in order to work pro The front-end electronics performs an online zero suppression using a threshold level. Those threshold levels for all channels (~ 1 million) have to be computed in a dedicated -PEDESTALS runs. During this runs the zero suppression is OFF and the pedestal level and the noise is obtained for each channel. The threshold for the FEE is obtained adding the pedestal -level to 3 sigmas of the noise. +PEDESTALS runs. During this runs the zero suppression is OFF and the pedestal level and the noise is obtained for each channel. The threshold for the FEE is obtained adding the pedestal level to 3 sigmas of the noise. The typical ECS sequence for pedestals is : - Switch ON the electronics LV - Boot the CROCUS - Configuration +- Saving Configuration in an ascii file then transferring in the File eXchange Server (FXS) - Zero suppression OFF - Data taking (typically 400 events) - The DA computes the mean and sigma (it runs in each LDC) - The DA writes one ASCII file per LDC with the results in the File Exchange Server -Then the SHUTTLE process the ASCII files and store the result on the OCDB +Then the SHUTTLE process the ASCII files and store the result on the OCDB (Keyword=PEDESTALS) +Only configuration files corresponding to a change of the Muon Tracker configuration are written in the FXS (Keyword=CONFIG). + \subsection da_ss2 Electronics gain In order to perform the required spatial resolution or the tracking chambers (~ 100 microns), we need to calibrate the gain of each channel. The gain is computed using dedicated runs where -a signal is send to the chambers FEE. +a signal (DAC) is send to the chambers FEE. The typical ECS sequence for calibration is : @@ -48,12 +50,11 @@ The typical ECS sequence for calibration is : - Boot the CROCUS - Configuration - Zero suppression OFF -- Loop of 10 data taking (typically 400 events) each with a different signal +- Loop of 11 data taking (typically 400 events) each with a different signal (DAC=0-200- 400-800-1200-1600-2000-2500-3000-3500-4000) - The DA computes the mean and sigma (it runs in each LDC) for each run -- The DA write one ASCII file per LDC with the results in the File Exchange Server at the -end of the 10 runs sequence +- At the end of the last run, the DA computes, by using a fitting procedure, linear and parabolic gain parameters, and writes results in one ASCII file per LDC. Every ascii files are transferred in the FXS. -Then the SHUTTLE process the ASCII files and store the result on the OCDB +Then the SHUTTLE process the ASCII files and store the result on the OCDB (KEYWORD=GAINS) \subsection da_ss3 Occupancy @@ -63,55 +64,95 @@ For PHYSICS (or STANDALONE) runs, the MUONTRKOCCda, which is a monitoring DA, ke \section da_s2 Using the DA Online +\subsection da_ss1 Pedestals + +The syntax is: MUONTRKPEDda.exe "raw data file" + +Two input files located in the DAQ Detector database (DetDB) are needed: + +- muontrkpedvalues containing only one parameter "config" + config = 1 if configuration file has to be used (OnLine case) + config - 0 if not (OffLine case for the time being) + +- config_ldc-MTRK-S3-0 : typical configuration file corresponding to MuonTracker Station 3 if (for example) DA is running on ldc-MTRK-S3-0 + +\subsection da_ss2 Electonics gain + +The syntax is: MUONTRKGAINda.exe "raw data file" + +Two input files located in the DAQ Detector database (DetDB) are needed: + +- muontrkcalibvalues: which attributes to each the run index (1->11) its corrresponding DAC value. The other parameters are used to tune the fit procedure (for expert). The last parameter indicates the number of events to be read: if "0" all events in the run are read, if not the parameter indicates the maximum number of events to be read. +Default values are listed below + +\verbatim +1 0 +2 200 +3 400 +4 800 +5 1200 +6 1600 +7 2000 +8 2500 +9 3000 +10 3500 +11 4000 +1 +6 +0 +1 +1 +0 +\verbatim + + - config_ldc-MTRK-S3-0 : configuration file corresponding to MuonTracker station 3 if (for example) DA is running on ldc-MTRK-S3-0 + + +\section da_s3 Using the DA Offline + +The DAs normally runs with a RAW data DATE format as input +The development of an Offline version is under way. + +Nevertheless, Pedestal runs can be analysed locally, but without detector configuration file. If you get a file in root format (e.g. from alien), you can de-rootify it using the + "deroot" program which is part of aliroot. +Note that PED and GAIN DAs work with ROOT input files as well. + You have a line command help. To have it just type : \verbatim > MUONTRKPEDda.exe -h ******************* ./MUONTRKPEDda.exe usage ********************** +Online (called from ECS) : ./MUONTRKPEDda.exe (no inline options) + +./MUONTRKPEDda.exe can be used locally only with options (without DiMuon configuration file) ./MUONTRKPEDda.exe -options, the available options are : --h help (this screen) +-h help (this screen) Input --f (default = ) +-f (default = ) Output --a (default = ) +-a (default = MUONTRKPEDda.ped) Options --b (default = .) --c (default = 1) --d (default = 1) --g (default = 0) --i (default = 6) --l (default = 0) --m (default = 1000000) --s (default = 0) --n (default = 1000000) --r root file data for gain(default = MUONTRKda_gain.data) --e (default = ped) --e make gain & create a new root file --e make gain & update root file --e make gain & compute gains +-m (default = 1000000) +-s (default = 0) +-n (default = 1000000) + \endverbatim - -\section da_s3 Using the DA Offline - -The DAs normally runs with a RAW data DATE format as input - If you get a file in root format (e.g. from alien), you can de-rootify it using the - "deroot" program which is part of aliroot. Note that PED and GAIN DAs work with ROOT input files as well. \section da_s4 In case of trouble Please contact : -Jean-Luc Charvet : jean-luc.charvet@cea.fr +Jean-Luc Charvet : jean-luc.charvet@cern.ch or Alberto Baldisseri : a.baldisseri@cea.fr or Laurent Aphecetche : laurent.aphecetche@subatech.in2p3.fr (for OCC DA) -This chapter is defined in the READMEMchda.txt file. +This chapter is defined in the READMEmchda.txt file. */