#include "TS800Scintillator.h"
#include "TS800.h"
#include <iostream>
#include <math.h>
#include <TBranch.h>
#include <TDirectory.h>
#include <TFile.h>
#include <TH1D.h>
#include <TF1.h>
#include <TMath.h>
#include <TSpline.h>
ClassImp(TS800Scintillator);
TS800Scintillator::TS800Scintillator(const TS800Scintillator & eN) : TObject(eN)
{
((TS800Scintillator&)eN).Copy(*this);
}
void TS800Scintillator::Clear(Option_t*)
{
de_up = 0;
de_down = 0;
time_up = 0;
time_down = 0;
tup = sqrt(-1.0);
tdown = sqrt(-1.0);
de = sqrt(-1.0);
time = sqrt(-1.0);
}
void TS800Scintillator::Calculate(Long64_t entry)
{
Clear();
fCon->b_time_up->GetEntry(entry);
fCon->b_time_down->GetEntry(entry);
fCon->b_de_up->GetEntry(entry);
fCon->b_de_down->GetEntry(entry);
fCon->parent->trigger.b_s800->GetEntry(entry);
fCon->parent->trigger.fRs800 = fRandom.Rndm();
Double_t trigRndm = fCon->parent->trigger.fRs800;
if(parent->fAddRndm){
tup = (Double_t)(fCon->time_up+fRandom.Rndm() - fCon->parent->trigger.s800+trigRndm)*timeSlope;
tdown = (Double_t)(fCon->time_down+fRandom.Rndm() - fCon->parent->trigger.s800+trigRndm)*timeSlope;
de = (Double_t)sqrt((Double_t)((fCon->de_up+fRandom.Rndm())*fCon->de_up) +
(Double_t)((fCon->de_down+fRandom.Rndm())*fCon->de_down));
}else{
tup = (Double_t)(fCon->time_up - fCon->parent->trigger.s800)*timeSlope;
tdown = (Double_t)(fCon->time_down - fCon->parent->trigger.s800)*timeSlope;
de = (Double_t)sqrt((Double_t)(fCon->de_up*fCon->de_up) + (Double_t)(fCon->de_down*fCon->de_down));
}
#ifdef EXPERIMENT_02023
time = (Double_t)(-1*tup);
#else
time = (Double_t)-1*(tup + tdown)/2;
#endif
if(fE1SplineCorr){
Correct(e1Spline);
}
}
void TS800Scintillator::Calibrate(Long64_t entry)
{
printf("* This method is currently empty.\n");
}
void TS800Scintillator::Copy(TObject &eN) const
{
TObject::Copy((TObject&)eN);
((TS800Scintillator&)eN).fRandom.SetSeed(0);
((TS800Scintillator&)eN).e1Spline = e1Spline;
((TS800Scintillator&)eN).fE1SplineCorr = fE1SplineCorr;
((TS800Scintillator&)eN).name = name;
((TS800Scintillator&)eN).avgTimeOffset = avgTimeOffset;
((TS800Scintillator&)eN).timeUpSlope = timeUpSlope;
((TS800Scintillator&)eN).timeDownSlope = timeDownSlope;
((TS800Scintillator&)eN).timeSlope = timeSlope;
}
void TS800Scintillator::Correct(TSpline3 *e1Spline)
{
if(parent->crdc2.calc.x_gravity>fCon->parent->e1.e1Spline->GetXmin() &&
parent->crdc2.calc.x_gravity<fCon->parent->e1.e1Spline->GetXmax()){
time = time + (Double_t)(avgTimeOffset - (-1)*fCon->parent->e1.e1Spline->Eval(parent->crdc2.calc.x_gravity));
}
}
void TS800Scintillator::Correct(Double_t Mean,Double_t Sigma,void *func)
{
TH1D *h_e1Distro = new TH1D("h_e1Distro","h_e1_Distro",3000,-275,-245);
TF1 *fnc = new TF1("fnc",func,-30,30,2);
fnc->SetParameter(0,Mean);
fnc->SetParameter(1,Sigma);
h_e1Distro->FillRandom("fnc",100000);
b_time->Reset();
for (Long64_t i=0; i<fChain->GetEntriesFast(); i++) {
Clear();
b_time_up->GetEntry(i);
parent->trigger.b_s800->GetEntry(i);
tup = time_up - parent->trigger.s800;
time = (Double_t)tup ;
time = h_e1Distro->GetRandom();
b_time->Fill();
}
}
void TS800Scintillator::InitClass(TString iname, TS800* iparent)
{
name = iname;
parent = iparent;
fE1SplineCorr = kFALSE;
avgTimeOffset = 0;
timeDownSlope = 0;
timeSlope = 1.000;
}
void TS800Scintillator::InitTree(TTree *tree)
{
fChain = tree;
fCurrent = -1;
b_de_up = fChain->GetBranch(name+".de_up");
b_de_down = fChain->GetBranch(name+".de_down");
b_time_up = fChain->GetBranch(name+".time_up");
b_time_down = fChain->GetBranch(name+".time_down");
b_tup = fChain->GetBranch(name+".tup");
b_tdown = fChain->GetBranch(name+".tdown");
b_de = fChain->GetBranch(name+".de");
b_time = fChain->GetBranch(name+".time");
}
void TS800Scintillator::GetEntry(int i)
{
}
Bool_t TS800Scintillator::LoadSpline(Char_t *splineFile)
{
TDirectory *cDir = gDirectory;
TFile file(splineFile,"READ");
e1Spline = (TSpline3*)file.FindObjectAny("e1Spline");
file.Close();
cDir->cd();
if(!e1Spline) {printf("Error: e1Spline function not found.\n"); return kFALSE;}
else{printf("Loaded e1Spline correcting function (Spline will be used during scintillator calculations).\n");}
fE1SplineCorr = kTRUE;
return kTRUE;
}
UShort_t* TS800Scintillator::Unpack(UShort_t *p, UShort_t ID)
{
if ((ID/2)*2 == ID) {
de_up = (UShort_t)((*p++)&0xfff);
time_up = (UShort_t)((*p++)&0xfff);
} else {
de_down = (UShort_t)((*p++)&0xfff);
time_down = (UShort_t)((*p++)&0xfff);
}
return p;
}
Last change: Sun Dec 21 12:38:57 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.