ISS_132Sn_dp/getPeaks.cpp
2024-08-16 16:24:21 -04:00

130 lines
3.1 KiB
C++

#include "TFile.h"
#include "TTree.h"
#include "TH1F.h"
#include "TStyle.h"
#include "TH2F.h"
#include "TCanvas.h"
#include "TTreeReader.h"
#include "AutoFit.C"
// mod = 0, 1, 2
// row = 1, 2, 3
// pstrip = 0 - 127
#define MAXMOD 3
#define MAXROW 3
#define MAXPStrip 128
const double ExRange[2] = {-0.5, 2.5};
const double ExRel = 0.05; //MeV
TH1F * haha[3][3][128];
TH2F * dudu[3][3];
TH1F * hEx;
void getPeaks(){
TFile * file = new TFile("R9-172_summed_tree.root");
TTree * tree = (TTree *) file->Get("rxtree");
const int nBin = (ExRange[1] - ExRange[0])/ExRel;
for( int i = 0; i < MAXMOD; i++ ){
for( int j = 0; j < MAXROW; j++ ){
dudu[i][j] = new TH2F(Form("dudu_%d%d", i, j+1), Form("%d-%d; pStrip; Ex", i, j+1), 128, 0, 128, nBin, ExRange[0], ExRange[1]);
for( int p = 0; p < MAXPStrip; p ++ ){
haha[i][j][p] = new TH1F(Form("h_%d%d_%d", i, j+1, p), Form("%d-%d-%d", i, j+1, p), nBin, ExRange[0], ExRange[1]);
}
}
}
hEx = new TH1F("hEx", "Ex", 10*nBin, ExRange[0], ExRange[1]);
TTreeReader reader(tree);
TTreeReaderValue<Double_t> Ex = {reader, "Ex"};
TTreeReaderValue<Int_t> mod = {reader, "mod"};
TTreeReaderValue<Int_t> row = {reader, "row"};
TTreeReaderValue<Int_t> pStrip = {reader, "pstrip"};
TTreeReaderValue<Int_t> ebis = {reader, "ebis_on"};
while( reader.Next() ){
if( *ebis == 0 ) continue;
if( *row == 0 ) continue;
int m = *mod;
int r = *row -1;
int p = *pStrip;
// printf("%d %d %d | %f\n", m, r, p, *Ex/1000.);
haha[m][r][p]->Fill(*Ex/1000.);
dudu[m][r]->Fill(p, *Ex/1000);
hEx->Fill( *Ex/1000);
}
gStyle->SetOptStat("");
// TCanvas * canvas = new TCanvas("canvas", "canvas", 2100, 1500);
// haha[0][2][10]->Draw();
// canvas->Divide(3,3);
// canvas->cd(1); dudu[0][0]->Draw("colz");
// canvas->cd(2); dudu[0][1]->Draw("colz");
// canvas->cd(3); dudu[0][2]->Draw("colz");
// canvas->cd(4); dudu[1][0]->Draw("colz");
// canvas->cd(5); dudu[1][1]->Draw("colz");
// canvas->cd(6); dudu[1][2]->Draw("colz");
// canvas->cd(7); dudu[2][0]->Draw("colz");
// canvas->cd(8); dudu[2][1]->Draw("colz");
// canvas->cd(9); dudu[2][2]->Draw("colz");
// hEx->Draw();
// FILE * outList = fopen("fit_result.txt", "w");
// for( int i = 0; i < MAXMOD; i ++ ){
// printf("############################## mod:%d\n", i);
// for( int j = 0; j < MAXROW; j++ ){
// printf("============================== row:%d\n",j);
// for( int k = 0; k < MAXPStrip; k ++ ){
// if( j == 0 && k < 30 ) continue;
// std::vector<double> exList = fitAuto(haha[i][j][k], -1, 0.1, 0.13, 3);
// fprintf(outList, "%d %d %3d", i, j+1, k);
// for( size_t p = 0; p < exList.size(); p++ ) {
// if( 1.8 > exList[p] && exList[p] > 1.2 ) continue;
// fprintf(outList, " %6.3f", exList[p]);
// }
// fprintf(outList, "\n");
// // printf("%3d |", k);
// // for( size_t p = 0; p < exList.size(); p++ ) printf(" %.3f", exList[p]);
// // printf("\n");
// }
// }
// }
// fclose(outList);
}