Subversion Repositories f9daq

Compare Revisions

Ignore whitespace Rev 90 → Rev 91

/sipmScan/src/RTUtil.cpp
2,6 → 2,8
#include "TGaxis.h"
#include "TColor.h"
 
#include "include/RTUtil.h"
 
void RTSetStyle(TStyle *style)
{
style->SetStatBorderSize(1);
/sipmScan/src/analysisScan.cpp
84,18 → 84,23
 
double padCenter[NCH][2];
 
// Test if the hit(x,y) lies inside the coordinates of the channel
// file with pad centers (without offset) should be provided
int analysisScan(char* dfile0="test", double c_tdcOffset=97, double tdcCut=5.0, int dbg=0);
 
int position(int, int, int);
 
// ------------------------------------------------------------------------------
 
int analysisScan(char* dfile0="test", double c_tdcOffset=97, double tdcCut=5.0, int dbg=0)
int main()
{
analysisScan();
return 0;
}
 
//const double c_tdcOffset = +98*TDC_BIN; // ns
c_tdcOffset *= TDC_BIN; //ns
int analysisScan(char* dfile0, double c_tdcOffset, double tdcCut, int dbg)
{
 
//const double c_tdcOffset = +97*TDC_BIN; // ns, SiPM4
c_tdcOffset *= TDC_BIN;
printf(" Data to root conversion program\nUsage:\nd2r(input file name <without .dat>, debug on/off, TDC cut +-[ns])\n\n");
printf(" OFFSETS: \n x: %d\n y: %d\n t:%f\n", OFFSETX, OFFSETY, c_tdcOffset);
/sipmScan/sipmScan.ini
19,7 → 19,7
 
16 65520 5040 1
17 45360 5040 1
18 65520 15120 1
18 65520 15120 -2
19 45360 15120 1
20 55440 25200 1
21 75600 25200 1
/sipmScan/examples/biasScan.C
108,6 → 108,7
//canvas02->cd(2);
//h_biasThreshold->GetXaxis()->SetRange(1,5);
h_biasThreshold->Project3D("zy");
h_biasThreshold->SetTitle("");
h_biasThreshold_zy->DrawCopy("colz");
 
TCanvas* canvas03 = new TCanvas("canvas03","",1200, 1200);
221,7 → 222,28
TH1D* h_projection2 = h_threshold->ProjectionY("Ch 38",39,39);
canvas2->cd(2);
//gPad->SetLogy();
h_projection2->Draw();
h_projection2->Draw();
 
TCanvas* canvas21 = new TCanvas("canvas21","",1200,1200);
canvas21->Divide(3,3);
TH3F* h_biasThreshold = (TH3F*) rootfile->Get("h_biasThreshold");
//h_biasThreshold->Draw();
//canvas02->cd(2);
//h_biasThreshold->GetXaxis()->SetRange(1,5);
h_biasThreshold->Project3D("zy");
canvas21->cd(1);
h_biasThreshold_zy->DrawCopy("colz");
canvas21->cd(2);
for (int jk=0; jk<9; jk++){
h_biasThreshold_zy->ProjectionY("_py",jk*2+1,jk*2+1);
canvas21->cd(jk+1);
char histoName[128];
double bias = h_biasThreshold_zy->GetXaxis()->GetBinCenter(jk*2+1);
sprintf(histoName, "Bias = %4.2f V", bias);
h_biasThreshold_zy_py->SetTitle(histoName);
h_biasThreshold_zy_py->DrawCopy();
}
 
}
if(strstr(plopt,"16") != NULL)
/sipmScan/examples/sipm.C
1,3 → 1,15
// *****************************************************************************
// Jozef Stefan Institute
// Dino Tahirovic
// 2012-2014
//
// Options:
// 2d - 1 channel analysis
// s - save an image (png) after drawinv the canvas
// p - save every canvas as page in pdf
//
// *****************************************************************************
 
#include "TROOT.h"
#include "TFile.h"
#include "TBenchmark.h"
352,7 → 364,7
}
// Number of photoelectrons - Poissonian correction
TCanvas* canvas8 = new TCanvas("canvas8","canvas8", 1000,1000);
TCanvas* canvas8 = new TCanvas("canvas8","canvas8", 1600,1600);
canvas8->cd();
gStyle->SetOptStat(0);
char hname[128];
378,24 → 390,20
//TH2F* h_corrected = new TH2F("h_corrected","h_corrected",binsX, minX, maxX, binsY, minY, maxY);
double noise = getNoise(h_2d, 1, 70);
noise = 50;
if(debug) printf("Noise = %f\n", noise);
noise = 61;
printf("[2d scan] Average noise = %f\n", noise);
for(int k=minX; k<=maxX; k++) {
for(int j=minY; j<=maxY; j++) {
double signal = h_2d->GetBinContent(k,j); // detected
//double p = ((signal - noise) > 1) ? (signal-noise) : 1;
double p = signal - noise;
p /= 10000.;
double p0 = 1.0 - p; // events with zero photons
//double eta = (-log(p0) * p0 ) / (1-p0-0.00001);
double eta = -log(p0); // constant of the poissonian statistics
if (debug) printf("p=%f p0=%f log(p0)=%f eta=%f\n",p,p0,log(p0),eta);
//double x = xLowUser + k*(xUpUser - xLowUser) / double(binsX);
double x = h_2d->GetXaxis()->GetBinCenter(k);
//double y = yLowUser + j*(yUpUser-yLowUser)/double(binsY);
double y = h_2d->GetYaxis()->GetBinCenter(j);
if (debug) printf("x=%f y=%f\n", x, y);
h_corrected->Fill(x, y, p);
h_corrected->Fill(x, y, eta);
}
}
//h_corrected->SetTitle("n_pe = - ln P(0);x[mm];y[mm]");
403,25 → 411,28
//gStyle->SetPalette(52,0); // black and white for print
//gStyle->SetPalette(1); //black and white 2nd option
//SetGS(); // inverse
h_corrected->GetZaxis()->SetRangeUser(-0.05,0.30);
h_corrected->SetContour(30);
//h_corrected->GetZaxis()->SetRangeUser(-0.01,0.12);
h_corrected->SetContour(50);
h_corrected->Draw("colz");
// collection efficiency
int nPoints =0;
double efficiency=0;
for (int i=18; i<=58; i++) {
for (int j=19; j<=59; j++) {
for (int i=minX; i<=maxX; i++) {
for (int j=minY; j<=maxY; j++) {
double signal = h_corrected->GetBinContent(i,j);
if(debug) printf("signal %f\n",signal);
efficiency += signal;
if (signal > 0.02) efficiency += signal;
nPoints++;
}
}
printf("Signal sum = %f\n # of points = %d\n",efficiency,nPoints);
if(strstr(plopt, "p") != NULL) {
canvas8->Print("result.pdf");
if(strstr(plopt, "s") != NULL) {
char photo[128];
sprintf(photo, "ps/%s.png", filename);
//canvas8->Print("result.pdf");
canvas8->SaveAs(photo);
}
}
551,7 → 562,7
double noise=0;
int count=0;
for(int j=yStart; j<yEnd; j++) {
double value = histogram->GetBinContent(j,2);
double value = histogram->GetBinContent(j,1);
//if (noise < value) noise = value;
noise += value;
count++;
/sipmScan/examples/tdc.C
1,6 → 1,7
#include "TROOT.h"
#include "TFile.h"
#include "TBenchmark.h"
#include "TH1.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TH3F.h"
10,15 → 11,15
#include "TF1.h"
#include "TGraph.h"
#include "TSpectrum.h"
#include "TAttFill.h"
#include "stdio.h"
 
#include "include/RTUtil.h"
 
//#include "include/RTUtil.h"
 
int tdc(char filename[256] = "test", int chX=0, int chY=0, double rangeLeft=-16, double rangeRight=16, bool debug = false)
int tdc(char filename[256] = "test", int chX=0, int chY=0, double rangeLeft=87, double rangeRight=107, bool debug = false)
{
//const int c_nChannels = 64;
//const double c_xOffset = 2.2; // mm
//const double c_yOffset = 2.3;
int map[8][8]={{32,34,53,55,40,42,61,63},
{48,50,37,39,56,58,45,47},
41,6 → 42,7
}
 
// set draw style
/*
gStyle->SetPalette(1, 0);
gStyle->SetPaperSize(TStyle::kA4);
52,71 → 54,112
gStyle->SetPadColor(0);
gStyle->SetCanvasColor(0);
gStyle->SetStatColor(0);
gStyle->SetOptFit(11);
gStyle->SetOptFit(1111);
gStyle->SetOptStat("ne");
gStyle->SetPadTopMargin(0.15);
gStyle->SetPadBottomMargin(0.15);
gStyle->SetPadRightMargin(0.15);
gStyle->SetPadLeftMargin(0.15);
//gStyle->SetTitleYOffset(1.4);
//gStyle->SetTitleYOffset(1.4);*/
RTSetStyle(gStyle);
TCanvas* canvas1 = new TCanvas("canvas1","canvas1",1000,1000);
TH2F* htdc = (TH2F*) rootfile->Get("htdc");
TH2F* h_tdc = (TH2F*) rootfile->Get("htdc");
canvas1->cd();
htdc->Draw("colz");
h_tdc->Draw("colz");
//TH3F* h_3D = (TH3F*) rootfile->Get("h_correctedTDC");
TH2F* h_correctedTDC = (TH2F*) rootfile->Get("h_correctedTDC");
TCanvas* canvas2 = new TCanvas("canvas2","canvas2",800,800);
TCanvas* canvas2 = new TCanvas("canvas2","canvas2",1000,1000);
canvas2->cd();
h_correctedTDC->Draw("colz");
/*
TH2D* h_correctedTDC = (TH2D*) h_3D->Project3D("xz");
h_correctedTDC->SetTitle("; t [ns]; Channel");
h_correctedTDC->Draw("colz");
TCanvas* canvas3 = new TCanvas("canvas3","canvas3",800,800);
canvas2->cd(2);
TH1D* h_allTDCbins = h_correctedTDC->ProjectionX("", 1, 64);
h_allTDCbins->Draw();
*/
/*
//TH2D* h_correctedTDC = (TH2D*) h_3D->Project3D("xz");
//h_correctedTDC->SetTitle("; t [ns]; Channel");
//h_correctedTDC->Draw("colz");
TCanvas* canvas3 = new TCanvas("canvas3","canvas3",1600,1600);
canvas3->cd();
//TH1D* h_allTDCbins = h_correctedTDC->ProjectionX("", 1, 64);
//h_allTDCbins->Draw();
int binY = map[chX][chY];
TH1D* channelY = h_correctedTDC->ProjectionX("",binY+1,binY+1);
channelY->SetStats(0);
if (debug) printf("%d\n", binY);
//TH1D* channelY = h_correctedTDC->ProjectionX("",binY+1,binY+1);
TH1D* channelY = h_tdc->ProjectionX("",binY+1,binY+1);
channelY->SetStats(1);
char title[256];
sprintf(title,"Channel %d;t [ns];Events", binY);
sprintf(title,";Time [ns];Events");
channelY->SetTitle(title);
channelY->GetYaxis()->SetTitleOffset(1.7);
TAxis* xAxis = h_correctedTDC->GetXaxis();
int range = xAxis->GetBinUpEdge(xAxis->GetLast()+1);
channelY->GetXaxis()->SetRangeUser(-range, range);
//channelY->GetYaxis()->SetTitleOffset(1.7);
//TAxis* xAxis = h_correctedTDC->GetXaxis();
//int range = xAxis->GetBinUpEdge(xAxis->GetLast()+1);
//channelY->GetXaxis()->SetRangeUser(-range, range);
//gStyle->SetOptStat("nemr");
//gStyle->SetOptFit(111);
channelY->GetXaxis()->SetRangeUser(rangeLeft,rangeRight);
channelY->Draw();
 
TF1* f_gaus1 = new TF1("f_gaus1","[0] + gaus(1)", rangeLeft,rangeRight);
TF1* f_gaus2 = new TF1("f_gaus2","[0] + gaus(1) + gaus(4)",-8,8);
f_gaus1->SetParNames("Linear","Norm","#mu","#sigma");
f_gaus2->SetParNames("Linear","Norm1","Mean1","Sigma1","Norm2","Mean2","Sigma2");
Int_t n = channelY->GetMaximum();
Float_t mean = channelY->GetBinCenter(channelY->GetMaximumBin());
f_gaus1->SetParameters(channelY->GetMinimum(), n, mean, 2.0);
channelY->Fit(f_gaus1,"0");
channelY->Fit(f_gaus1,"r");
*/
// Fit function: linear for background c + k*x
// Signal: norm*gaussian(mu,sigma)
TF1* f_gaus1 = new TF1("f_gaus1","[0] +[1]*x + gaus(2)", rangeLeft, rangeRight);
//TF1* f_gaus1 = new TF1("f_gaus1","[0] +[1]*x + gaus(2)");
f_gaus1->SetParNames("Const","Linear","Norm","#mu","#sigma");
//f_gaus1->SetLineColor(kAzure+1);
f_gaus1->SetLineColor(kBlack);
f_gaus1->SetLineWidth(4);
f_gaus1->SetParameter(0, channelY->GetMinimum());
f_gaus1->SetParameter(1, 0.0);
f_gaus1->SetParameter(2, channelY->GetMaximum() - channelY->GetMinimum());
f_gaus1->SetParameter(3, channelY->GetBinCenter(channelY->GetMaximumBin()));
f_gaus1->SetParameter(4, 1.0);
//channelY->Fit(f_gaus1,"qr");
//channelY->Fit(f_gaus1,"r");
//Fit in range +- 3 sigma
//channelY->Fit(f_gaus1,"r","", f_gaus1->GetParameter(2)-3*f_gaus1->GetParameter(3),
// f_gaus1->GetParameter(2)+3*f_gaus1->GetParameter(3));
//channelY->Fit(f_gaus1,"r","", f_gaus1->GetParameter(3)-3*f_gaus1->GetParameter(4),
channelY->Fit(f_gaus1,"","");
//f_gaus1->GetParameter(3)+3*f_gaus1->GetParameter(4));
double N = channelY->GetEntries();
double Nbkg = (rangeRight - rangeLeft)*f_gaus1->GetParameter(0);
double Nsig = N - Nbkg;
printf("\nN = %f, Nsig = %f, Nbkg = %f, SN = %f***\n\n", N, Nsig, Nbkg, Nsig/Nbkg);
/*
//to draw a shaded area above and below an histogram range, we create
//a TGraph object (here we shade bins 60 to 80).
Int_t i;
Int_t n = 2*(80-60);
TGraph *gr = new TGraph(2*n);
for (i=0;i<20;i++) {
Float_t xlow = h1->GetBinLowEdge(60+i);
Float_t xup = h1->GetBinLowEdge(60+i+1);
Float_t y = h1->GetBinContent(60+i);
Float_t yup = 1.1*y;
Float_t ydown= 0.9*y;
gr->SetPoint(2*i, xlow,yup);
gr->SetPoint(2*i+1,xup, yup);
gr->SetPoint(2*n-2*i-1,xlow, ydown);
gr->SetPoint(2*n-2*i-2,xup, ydown);
}
gr->SetFillColor(2);
gr->Draw("lf");*/
 
TH1D* timeWindow = (TH1D*) channelY->Clone();
timeWindow->GetXaxis()->SetRangeUser(92,102);
//timeWindow->SetFillColor(kAzure-1);
timeWindow->SetFillColor(kBlack);
timeWindow->SetFillStyle(3004);
timeWindow->Draw("same");
 
//f_gaus2->SetParameters(-1, n, mean-0.1, 0.01,
// n, mean+0.1, 0.1);
//channelY->Fit(f_gaus2,"0");
//channelY->Fit(f_gaus2,"rl");
// set range to +- 3 sigma
//channelY->Fit(f_gaus,"lr","",f_gaus->GetParameter(2)-3*f_gaus->GetParameter(3),
// f_gaus->GetParameter(2)+3*f_gaus->GetParameter(3));
char drawing[128];
sprintf(drawing, "ps/%sTDC.pdf", filename);
canvas3->SaveAs(drawing);
gPad->Update();
return (0);
}