FSUDAQ/DAQ/Plotting.cpp
2023-02-08 12:00:30 -05:00

178 lines
7.6 KiB
C++

#include "macro.h"
#include "ClassData.h"
#include "TH1.h"
#include "TH2.h"
#include "TStyle.h"
#include "TCanvas.h"
#include "TFile.h"
#include "TChain.h"
#include "TSystem.h"
#include "TTree.h"
#include <iostream>
#include "TApplication.h"
char* path_to_con="/home/bavarians/FSUDAQ_MUSIC/Conversion/";
TH1I * heleft[MaxNChannels];
TH1I * heright[MaxNChannels];
TH1I * MultiEVT;
TH1I * MultiHIT;
TH2F* MapFull ;
TH2F* MapLeft;
TH2F* MapRight;
TH2F* S0A1l;
TH2F* S0grid;
TH2F* S0cath;
TH2F* A1A2;
TH2F* gridcath;
TH2F* MapTime;
//IF SILICON DETECTOR
/*TH1F* E_histo ;
TH1F* dE_histo;
TH2F* dEE;
TH2F* si_de_time ;
TH2F* si_e_time;*/
TCanvas* csegLeft;
TCanvas* csegRight;
TCanvas* c;
TCanvas* cmult;
TCanvas* cmap;
TCanvas* cantime;
#define MAX_MULTI 100
unsigned long long evID ;
unsigned short multi_evt;
unsigned short multi_hit;
unsigned short stp0[MAX_MULTI]; /// 15 bit
unsigned short stp17[MAX_MULTI]; /// 15 bit
unsigned short grid[MAX_MULTI]; /// 15 bit
unsigned short cath[MAX_MULTI] ; /// 15 bit
unsigned short de_l[MAX_MULTI][16] ; /// 15 bit
unsigned short de_r[MAX_MULTI][16] ; /// 15 bit
unsigned short puls[MAX_MULTI][4]; /// 15 bit
unsigned long long e_t[MAX_MULTI]; /// timestamp 47 bit --> to get en sec *2e-9
unsigned short e_f[MAX_MULTI]; /// fine time 10 bit
int main(int argc, char* argv[]){
printf("=====================================\n");
printf("=== Data Visualization ===\n");
printf("=====================================\n");
if (argc < 2) {
printf("Incorrect number of arguments:\n");
printf("%s [RunId] \n", argv[0]);
printf("%s [Number of subfiles] \n", argv[1]);
return 1;
}
if (argc > 1) {
TApplication theApp("App",&argc, argv);
int Rid= atoi(argv[1]);
int Nfiles = atoi(argv[2]);
//"""""""""""""""""""""
//Accesing run
//"""""""""""""""""""""
gSystem->cd(path_to_con);
//FILE * haha[Nfiles]; TString inFileName;
char* inFileName;
TChain* MusicTree = new TChain("tree");
for(int f=0;f<Nfiles;f++){
if(f<10){inFileName= Form("Run_00%i_00%i.root", Rid, f);}
if(f>9 && f<100){inFileName= Form("Run_00%i_0%i.root", Rid, f);}
if(f>99 && f<1000){inFileName= Form("Run_00%i_%i.root", Rid, f);}
printf("input file %s \n", inFileName);
//haha[f] = fopen(inFileName, "r");
MusicTree->Add(inFileName);
}
MusicTree->SetBranchAddress("evID", &evID);
MusicTree->SetBranchAddress("multi_evt",&multi_evt); MusicTree->SetBranchAddress("multi_hit", &multi_hit);
MusicTree->SetBranchAddress("de_l", de_l); MusicTree->SetBranchAddress("de_r", de_r);
MusicTree->SetBranchAddress("stp0", stp0); MusicTree->SetBranchAddress("stp17", stp17);
MusicTree->SetBranchAddress("grid", grid); MusicTree->SetBranchAddress("cath" ,cath);
MusicTree->SetBranchAddress("puls", puls);
MusicTree->SetBranchAddress("e_t",e_t); MusicTree->SetBranchAddress("e_f", e_f);
int nStat = MusicTree->GetEntries();
printf("number of Tree entries %i \n", nStat);
//"""""""""""""""""""""
//Plot definition
//"""""""""""""""""""""
csegLeft= new TCanvas("csegLeft","csegLeft",1600,1600);csegLeft->Divide(4,4);
csegRight= new TCanvas("csegRight","csegRight",1600,1600);csegRight->Divide(4,4);
c= new TCanvas("c","c",1600,1600);c->Divide(2,2);
cmult= new TCanvas("cmult","cmult",1600,1600);cmult->Divide(2,2);
cmap= new TCanvas("cmap","cmap",900,1600);cmap->Divide(1,3);
cantime= new TCanvas("cantime","cantime",400,400);
cantime->cd();
double Er[2]={0., 16000}; double Timer[2]={0., 5000};
double bin_raw=2; double bin_raw_time=0.1;
int Nbins = int((Er[1]-Er[0])/bin_raw);
int NbinsTime = int((Timer[1]-Timer[0])/ bin_raw_time);
S0A1l = new TH2F("S0A1l",";#DeltaE_{0} (a.u.); #DeltaE_{1} left (a.u.)",Nbins, Er[0], Er[1], Nbins, Er[0], Er[1]);
S0cath = new TH2F("S0cath",";cathode (a.u.);#DeltaE_{0} (a.u.)",Nbins, Er[0], Er[1],Nbins, Er[0], Er[1]);
S0grid= new TH2F("S0grid",";grid (a.u.);#DeltaE_{0} (a.u.)", Nbins, Er[0], Er[1],Nbins, Er[0], Er[1]);
A1A2 = new TH2F("A1A2",";#DeltaE_{1} (a.u.);#DeltaE_{2} (a.u.)",Nbins, Er[0], Er[1],Nbins, Er[0], Er[1]);
gridcath= new TH2F("gridcath",";grid (a.u.);cathode (a.u.)", Nbins, Er[0], Er[1],Nbins, Er[0], Er[1]);
MapLeft= new TH2F("MapLeft","Left;Strip;#DeltaE (a.u.)", 18,0,18,Nbins, Er[0], Er[1]);
MapRight = new TH2F("MapRight","Right;Strip;#DeltaE (a.u.)", 18,0,18,Nbins, Er[0], Er[1]);
MapFull = new TH2F("MapFull","Long segments;Strip;#DeltaE (a.u.)", 18,0,17,Nbins, Er[0], Er[1]);
MapTime = new TH2F("MapTime",";Time event (ms); grid = 0 & Pulser = 5+Board*5", NbinsTime,Timer[0],Timer[1],25,0,25);
MultiEVT = new TH1I("MultiEVT",";Event multiplicity", 10, 0, 10);
MultiHIT= new TH1I("MultiHIT",";DAQ Channel Hit multiplicity", 100, 0, 100);
for(int c=0;c<MaxNChannels;c++){
heleft[c]= new TH1I(Form("heleft%0d",c), Form("Left Strip %0d;#DeltaE (a.u.)",c+1), Nbins, Er[0], Er[1]);
heright[c]= new TH1I(Form("heright%0d",c), Form("Right Strip %0d;#DeltaE (a.u.)",c+1), Nbins, Er[0], Er[1]);
}
MusicTree->Draw("multi_evt>>MultiEVT");
MusicTree->Draw("multi_hit>>MultiHIT");
for(int i = 0;i<nStat;i++){
MusicTree->GetEntry(i);
if(multi_evt*multi_hit>0){
for(int ev=0;ev<multi_evt;ev++){
S0grid->Fill(grid[ev],stp0[ev]); S0cath->Fill(cath[ev],stp0[ev]);
gridcath->Fill(grid[ev],cath[ev]);
MapRight->Fill(0.,stp0[ev]); MapLeft->Fill(0.,stp0[ev]);
MapRight->Fill(17,stp17[ev]); MapLeft->Fill(17,stp17[ev]);
A1A2->Fill(de_l[ev][0],de_r[ev][1]); S0A1l->Fill(stp0[ev], de_l[ev][0]);
for( int c = 0; c <MaxNChannels; c++){
heleft[c]->Fill(de_l[ev][c]); heright[c]->Fill(de_r[ev][c]);
MapRight->Fill(c+1,de_r[ev][c]); MapLeft->Fill(c+1,de_l[ev][c]);
if(c%2==0){MapFull->Fill(c+1, de_l[ev][c]);}
if(c%2==1){MapFull->Fill(c+1, de_r[ev][c]);}
}
if(e_t[ev]*ch2ns_value*1e-9<Timer[1]*0.001){
if(grid[ev]>0){MapTime->Fill(e_t[ev]*ch2ns_value*1e-6,0);}
for(int b = 0; b <MaxNBoards;b++){
if( puls[ev][b]>0){MapTime->Fill(e_t[ev]*ch2ns_value*1e-6,5+b*5);}
}
}
}
}
}
printf("Enter Ctrl+C to stop ...");
//"""""""""""""""""""""
//Plotting
//"""""""""""""""""""""
gStyle->SetPalette(kThermometer);
c->cd(1);S0grid->Draw("colz");S0grid->GetXaxis()->CenterTitle();S0grid->GetYaxis()->CenterTitle();
c->cd(2);S0cath->Draw("colz");S0cath->GetXaxis()->CenterTitle();S0cath->GetYaxis()->CenterTitle();
c->cd(3); S0A1l->Draw("colz"); S0A1l->GetXaxis()->CenterTitle(); S0A1l->GetYaxis()->CenterTitle();
c->cd(4);A1A2->Draw("colz");A1A2->GetXaxis()->CenterTitle();A1A2->GetYaxis()->CenterTitle();
cmult->cd(1);gridcath->Draw("colz");gridcath->GetXaxis()->CenterTitle();gridcath->GetYaxis()->CenterTitle();
cantime->cd();MapTime->Draw("colz");MapTime->GetXaxis()->CenterTitle();MapTime->GetYaxis()->CenterTitle();
cmap->cd(1);MapLeft->Draw("colz");MapLeft->GetXaxis()->CenterTitle();MapLeft->GetYaxis()->CenterTitle();
cmap->cd(2);MapRight->Draw("colz");MapRight->GetXaxis()->CenterTitle();MapRight->GetYaxis()->CenterTitle();
cmap->cd(3);MapFull->Draw("colz");MapFull->GetXaxis()->CenterTitle();MapFull->GetYaxis()->CenterTitle();
for( int i = 0; i <MaxNChannels; i++){
csegLeft->cd(i+1); heleft[i]->Draw("h");heleft[i]->GetXaxis()->CenterTitle();
csegRight->cd(i+1); heright[i]->Draw("h");heright[i]->GetXaxis()->CenterTitle();
}
cmult->cd(3);MultiEVT->Draw("h");MultiEVT->GetXaxis()->CenterTitle();
cmult->cd(4);MultiHIT->Draw("h");MultiHIT->GetXaxis()->CenterTitle();
theApp.Run();
return 1;
}
}