ROOT logo
#include "Elec.h"
ClassImp(Elec)

Elec::Elec(Double_t x1,Double_t x2 ,Double_t x3,Double_t x4,Double_t x5,Double_t x6,Double_t x7,Double_t x8,Double_t x9,Double_t x10,Int_t met)
{
Cp=x1; Rp=x2; IntTime=x3; Crc=x4; R1rc=x5; R2rc=x6; Ccr=x7; R1cr=x8; R2cr=x9; PeakTime=x10;  Method=met;
}
Elec::~Elec()
{
Clear();
}

Double_t Elec::Trapez(TH1F *histo,Int_t i,Double_t tau)
{
Double_t f1=0,f2=0,h=0,t1=0,t2=0;
 if(i==1)  return(histo->GetBinContent(i)*histo->GetBinWidth(i)/2); else
   {     
 t1=histo->GetBinCenter(i-1); f1=histo->GetBinContent(i-1)*TMath::Exp(t1/tau); 
 t2=histo->GetBinCenter(i);   f2=histo->GetBinContent(i)*TMath::Exp(t2/tau);	
 h=histo->GetBinWidth(i); //printf("tutut %d,t1=%e,t2=%e,f1=%e,f2=%e\n",i,t1,t2,f1,f2);
 return(h*0.5*(f1+f2)); 

   }
}

Double_t Elec::Simpson(TH1F *histo,Int_t i,Double_t tau)
{
Double_t f1=0,f2=0,f3=0,h=0,t1=0,t2=0,t3=0;
 if(i<3 || i%2==0) return(Trapez(histo,i,tau)); else {
 h=histo->GetBinWidth(i);
 t1=histo->GetBinCenter(i-2); f1=histo->GetBinContent(i-2)*TMath::Exp(t1/tau); 
 t2=histo->GetBinCenter(i-1); f2=histo->GetBinContent(i-1)*TMath::Exp(t2/tau);
 t3=histo->GetBinCenter(i);   f3=histo->GetBinContent(i)*TMath::Exp(t3/tau);
 return(h * (0.33333333333*f1 +1.333333333*f2 + 0.3333333333333*f3)-Trapez(histo,i-1,tau));
  }
}

void Elec::Revpreamp(Double_t C, Double_t R, TH1F *histo,Double_t unit)
{
Int_t i;
Double_t tau=R*C*unit;
Float_t prev,nextprev;;
Int_t start;
//start=histo->GetXaxis()->FindBin(0);
prev=histo->GetBinContent(1);
histo->SetBinContent(1,(Float_t) tau*((histo->GetBinContent(2)-histo->GetBinContent(1))/(histo->GetBinWidth(1)) + histo->GetBinContent(1)/tau));
start=2;
//printf("%e %e\n", histo->GetBinWidth(1), tau);
for(i=start;i<histo->GetNbinsX()-1;i++)
  // histo->SetBinContent(i,(Float_t) tau*((histo->GetBinContent(i+1)-histo->GetBinContent(i-1))/(histo->GetBinWidth(i)) + histo->GetBinContent(i)/tau));
{
 nextprev=histo->GetBinContent(i);
 histo->SetBinContent(i,(Float_t) tau*((histo->GetBinContent(i+1)-prev)/(2*histo->GetBinWidth(i)) + histo->GetBinContent(i)/tau));
 prev=nextprev;
}
  
}

void Elec::preamp(Double_t C, Double_t R, TH1F *histo,Double_t cut, Int_t method)
{
static double e_0    = 1.60217733e-19; 
Double_t suma=0;
Double_t tau=R*C;
Double_t t;
Int_t i;
TH1F *whisto=new TH1F();
histo->Copy(*whisto);

if(cut==-1111) cut=histo->GetNbinsX()*histo->GetBinWidth(1);

for(i=1;i<histo->GetNbinsX()-1;i++)
  {
t=whisto->GetBinCenter(i);
  if(t<=cut)
         { 
	   if(method==0) suma+=Trapez(whisto,i,tau);
	   if(method==1) suma+=Simpson(whisto,i,tau);
	 }
       	     histo->SetBinContent(i,(Float_t) (1/C*suma*TMath::Exp(-t/tau)));
	     // printf("%d,t=%e,suma=%e,tau=%e,tapez=%e\n",i,t,suma,tau,Trapez(histo,i,tau));
  }
delete whisto;
}


void Elec::RCshape(Double_t C, Double_t R1, Double_t R2,TH1F *histo, Int_t method)
{
Double_t suma=0;
Double_t tau=(R1*R2)*C/(R1+R2);
Double_t tau1=R1*C;
Double_t t;
Int_t i;
TH1F *whisto=new TH1F();
histo->Copy(*whisto);

for(i=1;i<histo->GetNbinsX()-1;i++)
  {
    t=whisto->GetBinCenter(i);	
    if(method==0)  suma+=Trapez(whisto,i,tau);
    if(method==1)  suma+=Simpson(whisto,i,tau);
    histo->SetBinContent(i,(Float_t) (1/tau1*suma*TMath::Exp(-t/tau)));
  }
delete whisto;
}

void Elec::CRshape(Double_t C, Double_t R1, Double_t R2,TH1F *histo, Int_t method)
{
Double_t suma=0;
Double_t tau=(R1*R2)*C/(R1+R2);
Double_t tau1=R1*C;
Double_t t,f;
Int_t i;
TH1F *whisto=new TH1F();
histo->Copy(*whisto);

for(i=1;i<histo->GetNbinsX()-1;i++)
  {
    t=whisto->GetBinCenter(i);
    f=whisto->GetBinContent(i);	
    if(method==0)  suma+=Trapez(whisto,i,tau);
    if(method==1)  suma+=Simpson(whisto,i,tau);
    histo->SetBinContent(i,f-(1/tau-1/tau1)*suma*TMath::Exp(-t/tau));
  }
delete whisto;
}






 Elec.cxx:1
 Elec.cxx:2
 Elec.cxx:3
 Elec.cxx:4
 Elec.cxx:5
 Elec.cxx:6
 Elec.cxx:7
 Elec.cxx:8
 Elec.cxx:9
 Elec.cxx:10
 Elec.cxx:11
 Elec.cxx:12
 Elec.cxx:13
 Elec.cxx:14
 Elec.cxx:15
 Elec.cxx:16
 Elec.cxx:17
 Elec.cxx:18
 Elec.cxx:19
 Elec.cxx:20
 Elec.cxx:21
 Elec.cxx:22
 Elec.cxx:23
 Elec.cxx:24
 Elec.cxx:25
 Elec.cxx:26
 Elec.cxx:27
 Elec.cxx:28
 Elec.cxx:29
 Elec.cxx:30
 Elec.cxx:31
 Elec.cxx:32
 Elec.cxx:33
 Elec.cxx:34
 Elec.cxx:35
 Elec.cxx:36
 Elec.cxx:37
 Elec.cxx:38
 Elec.cxx:39
 Elec.cxx:40
 Elec.cxx:41
 Elec.cxx:42
 Elec.cxx:43
 Elec.cxx:44
 Elec.cxx:45
 Elec.cxx:46
 Elec.cxx:47
 Elec.cxx:48
 Elec.cxx:49
 Elec.cxx:50
 Elec.cxx:51
 Elec.cxx:52
 Elec.cxx:53
 Elec.cxx:54
 Elec.cxx:55
 Elec.cxx:56
 Elec.cxx:57
 Elec.cxx:58
 Elec.cxx:59
 Elec.cxx:60
 Elec.cxx:61
 Elec.cxx:62
 Elec.cxx:63
 Elec.cxx:64
 Elec.cxx:65
 Elec.cxx:66
 Elec.cxx:67
 Elec.cxx:68
 Elec.cxx:69
 Elec.cxx:70
 Elec.cxx:71
 Elec.cxx:72
 Elec.cxx:73
 Elec.cxx:74
 Elec.cxx:75
 Elec.cxx:76
 Elec.cxx:77
 Elec.cxx:78
 Elec.cxx:79
 Elec.cxx:80
 Elec.cxx:81
 Elec.cxx:82
 Elec.cxx:83
 Elec.cxx:84
 Elec.cxx:85
 Elec.cxx:86
 Elec.cxx:87
 Elec.cxx:88
 Elec.cxx:89
 Elec.cxx:90
 Elec.cxx:91
 Elec.cxx:92
 Elec.cxx:93
 Elec.cxx:94
 Elec.cxx:95
 Elec.cxx:96
 Elec.cxx:97
 Elec.cxx:98
 Elec.cxx:99
 Elec.cxx:100
 Elec.cxx:101
 Elec.cxx:102
 Elec.cxx:103
 Elec.cxx:104
 Elec.cxx:105
 Elec.cxx:106
 Elec.cxx:107
 Elec.cxx:108
 Elec.cxx:109
 Elec.cxx:110
 Elec.cxx:111
 Elec.cxx:112
 Elec.cxx:113
 Elec.cxx:114
 Elec.cxx:115
 Elec.cxx:116
 Elec.cxx:117
 Elec.cxx:118
 Elec.cxx:119
 Elec.cxx:120
 Elec.cxx:121
 Elec.cxx:122
 Elec.cxx:123
 Elec.cxx:124
 Elec.cxx:125
 Elec.cxx:126
 Elec.cxx:127
 Elec.cxx:128
 Elec.cxx:129
 Elec.cxx:130
 Elec.cxx:131