#include "TS800CrdcPads.h"
#include "TS800Crdc.h"
#include "nrutil.h"
#include <iostream>
#include <math.h>
#include <TNamed.h>
#include <TList.h>
ClassImp(TS800CrdcPads);
extern short gNumrecError, gNumrecMessage;
TS800CrdcPads::TS800CrdcPads(const TS800CrdcPads &pad) : TObject(pad)
{
((TS800CrdcPads&)pad).Copy(*this);
parent = NULL;
b_cal = NULL;
b_sum = NULL;
fChain = NULL;
fCurrent = 0;
Clear();
}
Int_t TS800CrdcPads::Calibrate(Long64_t entry)
{
if(!fChain){printf("TTree or TChain has not been initialized!!!\n"); return -1;}
Int_t index;
Int_t samples[256];
Bool_t fAddRndm = kTRUE;
Clear();
fCon->parent->b_filled->GetEntry(entry);
fCon->parent->b_channel->GetEntry(entry);
fCon->parent->b_data->GetEntry(entry);
bzero(samples, sizeof(samples));
memset(sum,'\0', sizeof(sum));
for (Int_t f=0; f<fCon->parent->filled; f++) {
index = fCon->parent->channel[f];
if(fAddRndm) sum[index] += (Double_t)((fCon->parent->data[f]+fRandom.Rndm()) - ped[index]);
else sum[index] += (Double_t)( fCon->parent->data[f] - ped[index]);
samples[index]++;
}
for (Int_t ch=0; ch<fCon->parent->channels; ch++) {
if(sum[ch]<0) sum[ch] = sqrt(-1.0);
if (samples[ch] > 0) {
cal[ch] = sum[ch]*slope[ch]/(Double_t)(samples[ch]);
if(cal[ch]<0) cal[ch] = sqrt(-1.0);
if(thresh[ch]>ped[ch] && cal[ch]<(thresh[ch]-ped[ch])) cal[ch] = sqrt(-1.0);
}
}
return 1;
}
void TS800CrdcPads::InitClass(TString iname)
{
name = iname;
sampleWidth = 8;
for (Int_t i=0; i<parent->channels; i++) {
ped[i] = 0;
slope[i] = 1;
thresh[i] = 0;
}
}
void TS800CrdcPads::InitTree(TTree *tree)
{
fChain = tree;
fCurrent = -1;
#ifdef TESTING
fChain->SetMakeClass(1);
#endif
b_cal = fChain->GetBranch(name+".cal[224]");
b_sum = fChain->GetBranch(name+".sum[256]");
}
void TS800CrdcPads::Clear(Option_t*)
{
for (Int_t i=0; i<TS800_FP_CRDC_CHANNELS; i++) cal[i] = sqrt(-1.0);
for (Int_t i=0; i<256; i++) sum[i] = sqrt(-1.0);
}
void TS800CrdcPads::Copy(TObject &pad) const
{
TObject::Copy((TObject&)pad);
for(Int_t i=0; i<TS800_FP_CRDC_CHANNELS; i++) ((TS800CrdcPads&)pad).ped[i] = ped[i];
for(Int_t i=0; i<TS800_FP_CRDC_CHANNELS; i++) ((TS800CrdcPads&)pad).slope[i] = slope[i];
for(Int_t i=0; i<TS800_FP_CRDC_CHANNELS; i++) ((TS800CrdcPads&)pad).thresh[i] = thresh[i];
((TS800CrdcPads&)pad).sampleWidth = sampleWidth;
((TS800CrdcPads&)pad).name = name;
}
void TS800CrdcPads::GetEntry(int i)
{
b_cal->GetEntry(i);
b_sum->GetEntry(i);
}
void TS800CrdcPads::LoadCalibration(Char_t *filename)
{
FILE *file;
char str[200], var[100], *sub, **ap, *argv[10];
Double_t value;
file = fopen(filename, "r");
if (file == NULL) {
cout << "Could not find calibration file " << filename << endl;
return;
}
while (!feof(file)) {
fgets(str, 200, file);
sscanf(str, "set %s %lf", var, &value);
sub = var;
for (ap = argv; (*ap = strsep(&sub, ".")) != NULL;)
if (**ap != '\0')
if (++ap >= &argv[10]) break;
if (strcmp(argv[4], "ped") == 0) ped[strtol(argv[5], NULL, 10)] = value;
if (strcmp(argv[4], "slope") == 0) slope[strtol(argv[5], NULL, 10)] = value;
if (strcmp(argv[4], "thresh") == 0) thresh[strtol(argv[5], NULL, 10)] = value;
}
fclose(file);
cout << "Calibration of " << name << " loaded.\n";
}
Last change: Sun Dec 21 12:38:55 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.