// @(#)root/html:$Name:  $:$Id: THtml.cxx,v 1.124 2006/11/24 16:01:02 $
// Author: Mathieu Benoit <mailto:mbenoit@umontreal.ca>
/*************************************************************************
 * . Class CTDR_Signal					         *
 *   Written by : Mathieu Benoit                                         *
 *   m.benoit@umontreal.ca						 *
 *************************************************************************/
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include "CTDR_Signal.h"
using namespace std;

ClassImp(CTDR_Signal);

//______________________________________________________________________________
CTDR_Signal::CTDR_Signal(){};

//______________________________________________________________________________
CTDR_Signal::CTDR_Signal(TString nomFichier,int Channel)
{
// This is the constructor of an event using a file created by CTDR_Detecteur
// for a single signal (x and y)

	sigx = new TGraph();
	sigy= new TGraph();
	ifstream Vin(nomFichier,ios::in);
	int i=1;
	double temps,Vxtemp,Vytemp;
	Vin >> temps >> Vxtemp >> Vytemp;
	double VY0=Vytemp;
	double VX0=Vxtemp;
	while(!Vin.eof())
	{
		Vin >> temps >> Vxtemp >> Vytemp;
		sigx->SetPoint(i,temps,Vxtemp-VX0);
		sigy->SetPoint(i,temps,Vytemp-VY0);
		i++;
	};
	Vin.close();

	N=i;
	t=sigx->GetX();
	Vx=sigx->GetY();
	Vy=sigy->GetY();

	this->Channel=Channel;
	TString str;
	str.Form("X Channel %i",Channel);
	sigx->SetTitle(str);
	sigx->GetXaxis()->SetTitle("Time (s)");
	sigx->GetYaxis()->SetTitle("Collected Charge( keV)");
	str.Form("Y Channel %i",Channel);
	sigy->SetTitle(str);
	sigy->GetXaxis()->SetTitle("Time (s)");
	sigy->GetYaxis()->SetTitle("Collected Charge( keV)");
};

//______________________________________________________________________________
CTDR_Signal::CTDR_Signal(double *t,double *Vx,double *Vy,int N, int Channel){
// This is the constructor for a signal given the arrays containing the t,x and y data

	this->t=t;
	this->Vx=Vx;
	this->Vy=Vy;
	this->N=N;
	this->Channel=Channel;
	sigx = new TGraph(N-1,t,Vx);
	sigy = new TGraph(N-1,t,Vy);
	TString str;
	str.Form("X Channel %i",Channel);
	sigx->SetTitle(str);
	sigx->GetXaxis()->SetTitle("Time (s)");
	sigx->GetYaxis()->SetTitle("Collected Charge( keV)");
	str.Form("Y Channel %i",Channel);
	sigy->SetTitle(str);
	sigy->GetXaxis()->SetTitle("Time (s)");
	sigy->GetYaxis()->SetTitle("Collected Charge( keV)");

};

//______________________________________________________________________________
void CTDR_Signal::operator+=(CTDR_Signal another){
// This is an implementation of the addition of a signal to this signal

	int Npas;
	if(this->N < another.GetN()){Npas=another.GetN();}
	else {Npas=this->N;};
	double tmin1,tmin2,tmax1,tmax2,dt,temps;
	tmin1=this->t[1];
	tmax1=this->t[this->N];
	tmin2=another.t[1];
	tmax2=another.t[another.GetN()];
	cout << tmin1 << " " << tmax1 << " " << tmin2 << " " << tmax2 << endl;
	if(tmax1>tmax2)dt=tmax1/(Npas-1);
	else dt=tmax2/(Npas-1);
	temps=0;
	this->t=new double[Npas];
	this->Vx=new double[Npas];
	this->Vy=new double[Npas];
	for(int i=0;i<Npas;i++){
		this->t[i]=temps;
		this->Vx[i]=0;
		this->Vy[i]=0;
		if(temps<tmin1){
			this->Vx[i]+=0;
			this->Vy[i]+=0;
			}
		else if(temps>tmax1){
			this->Vx[i]+=this->sigx->Eval(tmax1);
			this->Vy[i]+=this->sigy->Eval(tmax1);
			}
		else{
			this->Vx[i]+=this->sigx->Eval(temps);
			this->Vy[i]+=this->sigy->Eval(temps);
			};
		if(temps<tmin2){
			this->Vx[i]+=0;
			this->Vy[i]+=0;
			}
		else if(temps>tmax2){
			this->Vx[i]+=another.sigx->Eval(tmax2);
			this->Vy[i]+=another.sigy->Eval(tmax2);
			}
		else{
			this->Vx[i]+=another.sigx->Eval(temps);
			this->Vy[i]+=another.sigy->Eval(temps);
			};
		//cout << "t=" << this->t[i] << " Vx=" << this->Vx[i]  << " Vy=" << this->Vy[i] << endl; 
		temps+=dt;
		};
	this->sigx=new TGraph(Npas-1,t,Vx);
	this->sigy=new TGraph(Npas-1,t,Vy);
	this->N=Npas;


};

//______________________________________________________________________________
void CTDR_Signal::operator=(CTDR_Signal another){
// This is the implementation of the equal method for a signal
	this->Vx=another.GetVx();
	this->Vy=another.GetVy();
	this->t=another.Gett();
	this->Channel=another.GetChannel();
	this->N=another.GetN();
	this->sigx=another.GetGraphX();
	this->sigy=another.GetGraphY();
};

//______________________________________________________________________________
void CTDR_Signal::Trace(){
// This methods allow to vizualize the signal

	TCanvas *can=new TCanvas("Signal X");
	TMultiGraph *multi=new TMultiGraph("multi","Signaux simul#acute{e}s");
	sigx = new TGraph(N-1,t,Vx);
	sigy = new TGraph(N-1,t,Vy);
	multi->Add(sigx);
	multi->Add(sigy);
	multi->Draw("AL");
};

//______________________________________________________________________________
TGraph* CTDR_Signal::GetGraphX(){
// Access method for X channel graph

	return sigx;
};	

//______________________________________________________________________________	
TGraph* CTDR_Signal::GetGraphY(){
// Access method for Y channel graph

	return sigy;
};	

//______________________________________________________________________________
double* CTDR_Signal::GetVx(){
// Access method for X channel Collected charge array

	return Vx;
};

//______________________________________________________________________________
double* CTDR_Signal::GetVy(){
// Access method for Y channel Collected charge array

	return Vy;
};

//______________________________________________________________________________
double* CTDR_Signal::Gett(){
// Access method for time array

	return t;
};

//______________________________________________________________________________
int CTDR_Signal::GetN(){
// Access method for the number of data points

	return N;
};

//______________________________________________________________________________
int CTDR_Signal::GetChannel(){
// Access method for channel number

	return Channel;
};



ROOT page - Class index - Class Hierarchy - Top of the page

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.