#include <fstream>
#include <TCanvas.h>
#include <TTree.h>
#include <TMath.h>
#include <TObject.h>
#include "TScaler.h"
ClassImp(TScaler);
TClonesArray *TScaler::fgScalers = 0;
void TScaler::Clear(Option_t *)
{
startTime = 0;
endTime = 0;
memset(scaler,'\0',sizeof(scaler));
TIter next(fScalers);
TScalerCh *psc;
while((psc = (TScalerCh*)next.Next())) psc->Clear();
}
void TScaler::DrawTotals()
{
}
void TScaler::DumpMap()
{
printf("****************************SCALER DUMP MAP***********************************\n");
Char_t objName[500];
for(Int_t i=0; i<TSCALER_NSCALERS; i++){
TScalerCh *pScaler = (TScalerCh*)fScalers->At(i);
sprintf(objName,"scaler%02i",i);
printf("* %s \t%-20.20s \t%s\n",objName,pScaler->GetName(),pScaler->GetTitle());
}
printf("*............................................................................*\n");
}
Bool_t TScaler::DumpScalers(Option_t *fileName,Option_t *option)
{
if(!b_fScalers){ printf("ERROR: Branch not set.\n"); return kFALSE;}
Char_t *outFileName = (Char_t*)fileName;
Char_t *modeOption = (Char_t*)option;
Char_t objName[500];
Char_t outPut[2000];
ofstream outFile;
if(strcmp(outFileName,"NONE")!=0){
if(strcmp(modeOption,"RECREATE")==0) outFile.open(outFileName,ios::out);
else if(strcmp(modeOption,"UPDATE")==0) outFile.open(outFileName,ios::app);
else return kFALSE;
cout << "Creating File: " << outFileName << endl;
if(!outFile.is_open()) cout << "File Creation FAILED!!!" << endl;
sprintf(outPut,"* ScalerObj \tScaler Name \t Total \tAvg Rate (Actual) sigma (Actual) Avg Rate\n");
outFile << outPut;
sprintf(outPut,"*.................................................................................................*\n");
outFile << outPut;
}
printf("******************************SCALER DUMP*************************************\n");
Double_t avgRate[TSCALER_NSCALERS];
Double_t sigma[TSCALER_NSCALERS];
Double_t rate[TSCALER_NSCALERS];
Double_t vari[TSCALER_NSCALERS];
memset(avgRate,'\0',sizeof(avgRate));
memset(sigma,'\0',sizeof(sigma));
memset(rate,'\0',sizeof(rate));
memset(vari,'\0',sizeof(vari));
Long64_t nEntries = b_fScalers->GetEntries()-1;
for(Int_t i=0; i<nEntries; i++){
b_fScalers->GetEntry(i);
for(Int_t j=0; j<TSCALER_NSCALERS; j++){
TScalerCh *pScaler = (TScalerCh*)fScalers->At(j);
rate[j] += pScaler->rate/(Double_t)nEntries;
}
}
for(Int_t m=0; m<TSCALER_NSCALERS; m++) {avgRate[m] = rate[m];
}
Double_t sum2[TSCALER_NSCALERS];
Double_t sumc[TSCALER_NSCALERS];
memset(sum2,'\0',sizeof(sum2));
memset(sumc,'\0',sizeof(sumc));
for(Int_t i=0; i<nEntries; i++){
b_fScalers->GetEntry(i);
for(Int_t j=0; j<TSCALER_NSCALERS; j++){
TScalerCh *pScaler = (TScalerCh*)fScalers->At(j);
sum2[j] = sum2[j] + (pScaler->rate - avgRate[j])*(pScaler->rate - avgRate[j]);
sumc[j] = sumc[j] + (pScaler->rate - avgRate[j]);
}
}
for(Int_t m=0; m<TSCALER_NSCALERS; m++) {
vari[m] = (sum2[m] - (sumc[m]*sumc[m])/(Double_t)nEntries)/((Double_t)nEntries - 1);
sigma[m] = TMath::Sqrt(vari[m]);
}
b_h_totals->GetEntry(b_fScalers->GetEntries()-1);
TNamed *nTmp = (TNamed*)fEChain->GetUserInfo()->FindObject("Elapsed Run Time");
Double_t eTime = atof(nTmp->GetTitle());
printf("ScalerObj \tScaler Name \t Total \tAvg Rate (Actual) sigma (Actual) Avg Rate\n");
printf("*.................................................................................................*\n");
for(Int_t i=0; i<TSCALER_NSCALERS; i++){
TScalerCh *pScaler = (TScalerCh*)fScalers->At(i);
sprintf(objName,"scaler%02i",i);
Int_t tot = (Int_t)h_totals.GetBinContent(i+1);
printf("* %s \t%-20.20s \t%12i \t%9.2lf \t%9.2lf \t%9.2lf\n",objName,pScaler->GetName(),
tot,avgRate[i],sigma[i],(Double_t)tot/eTime);
if(strcmp(outFileName,"NONE")!=0){
sprintf(outPut,"%s \t%-20.20s \t%12i \t%9.2lf \t%9.2lf \t%9.2lf\n",objName,pScaler->GetName(),
tot,avgRate[i],sigma[i],(Double_t)tot/eTime);
outFile << outPut;
}
}
if(strcmp(outFileName,"NONE")!=0) outFile.close();
printf("*................................................................................................*\n");
return kTRUE;
}
void TScaler::InitBranch(TTree *tree)
{
}
Bool_t TScaler::InitClass()
{
SetNameTitle("scalers","Scalers");
h_totals.SetNameTitle("h_totals","Scaler Totals");
h_totals.SetBins(TSCALER_NSCALERS,0,TSCALER_NSCALERS);
h_totals.Reset();
h_totals.SetFillColor(kRed);
fgScalers = new TClonesArray("TScalerCh",64);
fScalers = fgScalers;
TClonesArray &fSc = *fgScalers;
Char_t chain[500];
for(Int_t i=0; i<TSCALER_NSCALERS; i++){
sprintf(chain,"scaler%02i",i);
h_totals.GetXaxis()->SetBinLabel(i+1,chain);
new(fSc[i]) TScalerCh(chain,chain);
scaler[i] = 0;
}
Clear();
return kTRUE;
}
Int_t TScaler::InitTree(TTree *tree)
{
if(!tree){
printf("ERROR: Tree could not be initialized.\n");
return -1;
}
fEChain = tree;
fChain = (TTree*)fEChain->GetDirectory()->FindObjectAny("scalerT");
if(!fChain){
printf("ERROR: Could not find scaler tree.\n");
return -2;
}
fCurrent = -1;
TScaler *sc = this;
fChain->SetBranchAddress("scalers",&sc);
b_startTime = fChain->GetBranch("startTime");
b_endTime = fChain->GetBranch("endTime");
b_h_totals = fChain->GetBranch("h_totals");
b_fScalers = fChain->GetBranch("fScalers");
return 1;
}
Bool_t TScaler::LoadScalerMap(Char_t *fileName)
{
Int_t scalerCh;
Char_t scalerName[500],
scalerTitle[500];
ifstream file(fileName,ios::in);
if(!file.is_open()) {printf("File could not be opened!!!\n"); return kFALSE;}
Char_t line[1000];
file.getline(line,1000);
while(!isdigit(line[0])){
file.getline(line,1000);
}
while(!file.eof()){
sscanf(line,"%i %s %s",&scalerCh,scalerName,scalerTitle);
#ifdef TSCALER_DEBUG
printf("%02i \t%-20.20s \t%s\n",scalerCh,scalerName,scalerTitle);
#endif
if(scalerCh>TSCALER_NSCALERS){
printf("scalerCh %i is greater that TSCALER_NSCALERS.\n",scalerCh);
return kFALSE;
}
TScalerCh *pScaler = (TScalerCh*)fScalers->At(scalerCh);
pScaler->SetNameTitle(scalerName,scalerTitle);
h_totals.GetXaxis()->SetBinLabel(scalerCh+1,scalerName);
if(!file.eof()) file.getline(line,1000);
}
printf("* Scaler map file loaded. \t\t\t\t\t\t\t [OK]\n");
return kTRUE;
}
UShort_t* TScaler::Unpack(UShort_t *pEvent)
{
UShort_t nScalers;
ULong64_t upper,lower,value;
nScalers = *pEvent;
if(nScalers > TSCALER_NSCALERS) {
printf("Number of scalers %i is greater than TSCALER_NSCALERS %i\n",nScalers,TSCALER_NSCALERS);
return pEvent;
}
for(Int_t j=0; j<10; j++) *pEvent++;
lower = (ULong64_t)*pEvent++;
upper = (ULong64_t)*pEvent++;
endTime = (ULong64_t)(upper<<16|lower);
*pEvent++;
*pEvent++;
*pEvent++;
lower = (ULong64_t)*pEvent++;
upper = (ULong64_t)*pEvent++;
startTime = (ULong64_t)(upper<<16|lower);
*pEvent++;
*pEvent++;
*pEvent++;
for(Int_t i=0; i<nScalers; i++){
TScalerCh *pScalers = (TScalerCh*)fScalers->At(i);
lower = (ULong64_t)*pEvent++;
upper = (ULong64_t)*pEvent++;
value = (ULong64_t)(upper<<16|lower);
scaler[i] = value;
pScalers->counts = scaler[i];
pScalers->rate = (Double_t)scaler[i]/(Double_t)(endTime-startTime);
h_totals.Fill(i,value);
}
#ifdef TSCALER_DEBUG
cout << "nScalers: " << nScalers
<< " endTime: " << endTime
<< " startTime: " << startTime
<< endl;
cout << "Scalers: {";
for(Int_t k=0; k<nScalers; k++) cout << value << ",";
cout << endl;
#endif
return pEvent;
}
Last change: Sun Dec 21 12:38:59 2008
Last generated: 2008-12-21 12:38
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.