Skip to content
Snippets Groups Projects
Commit 54bc4b36 authored by LEMAIR Louis's avatar LEMAIR Louis
Browse files

*Adding to Nebula a few root data-analysis scripts

        - macro/live/NebulaWall.C is the one for dynamic hit bar display
parent 291536a5
No related branches found
No related tags found
No related merge requests found
Showing
with 616 additions and 0 deletions
void CalcEn(double PosY, double PosZ, double TOF){
double c_light = 299.795;
double mass_neutron = 939.57;
double distance = sqrt(pow(PosY,2)+pow(PosZ,2));
double speed = distance/TOF;
double gamma = 1/sqrt(1-pow(speed,2)/pow(c_light,2));
double energy = (gamma-1)*mass_neutron;
std::cout << "Energy is : " << energy << " MeV" << std::endl;
}
#include "/local/lemair/nptool/NPLib/Detectors/Nebula/TNebulaPhysics.h"
void ChargeDraw(){
TFile* f = TFile::Open("root/analysis/PhysicsTree.root");
TTree* t = (TTree*)f->Get("PhysicsTree");
TNebulaPhysics *Neb_Phys = new TNebulaPhysics();
std::vector<double> Charge;
//std::vector<int>* Efficiency = 0;
double Ch, counter;
//int Eff;
//TBranch* branch_Eff;
TBranch* branch ;
//TH1F *h_Eff = new TH1F("h_Eff","test");
TH1F *h_En = new TH1F("h_En","Charge",160,0,160);
//t->SetBranchAddress("Efficiency",&Efficiency,&branch_Eff);
t->SetBranchAddress("Nebula",&Neb_Phys,&branch);
//int nentries_Eff = branch_Eff->GetEntries();
int nentries_Neb = branch->GetEntries();
for(int i = 0; i < nentries_Neb ; i++){
t->GetEntry(i);
Charge = Neb_Phys->Charge;
int vec_size = Charge.size();
for(int j = 0; j < vec_size; j++){
Ch = Charge[j];
if(Ch>160) cout << "Ch " << Ch << endl;
h_En->Fill(Ch);
}
}
TCanvas *c2 = new TCanvas("c2","Charge",1080,720);
h_En->Draw("");
}
void Colorbyprocess(){
TFile* f = TFile::Open("root/simulation/SimulatedTree.root");
TTree *t = (TTree*)f->Get("SimulatedTree");
//new TCanvas;
//t->Draw("Process");
//new TCanvas;
//t->Draw("El_is_1_and_InEl_is_2");
//new TCanvas;
//t->Draw("Efficiency");
std::vector<std::string>* processname = 0;
const char* name;
std::vector<double>* pos_z_vec = 0;
double pos_z;
TBranch* branch;
TH1F *Inel = new TH1F("Inel","test",3000,10500,12500);
TH1F *El = new TH1F("El","test",3000,10500,12500);
Inel->SetStats(0);
t->SetBranchAddress("Pos_Z",&pos_z_vec);
t->SetBranchAddress("Process",&processname,&branch);
int nentries = branch->GetEntries();
for(int i = 0; i < nentries ; i++){
t->GetEntry(i);
int vec_size = (*processname).size();
for(int j = 0; j < vec_size; j++){
name = ((*processname)[j]).c_str();
pos_z = (*pos_z_vec)[j];
if(strcmp(name,"hadElastic")==0){
El->Fill(pos_z);
}
else if(strcmp(name,"neutronInelastic")==0){
Inel->Fill(pos_z);
}
}
}
TCanvas* c = new TCanvas();
Inel->SetLineColor(kRed);
El->SetLineColor(kBlue);
El->Draw();
Inel->Draw("SAME");
}
#include "TNebulaPhysics.h"
void DrawEn_and_Efficiency(){
TFile* f = TFile::Open("root/analysis/PhysicsTree.root");
TTree* t = (TTree*)f->Get("PhysicsTree");
TCanvas *c1 = new TCanvas("c1","Efficiency",1080,720);
t->Draw("Efficiency");
TNebulaPhysics *Neb_Phys = new TNebulaPhysics();
std::vector<double> NeutronEnergy;
//std::vector<int>* Efficiency = 0;
double En, counter;
//int Eff;
//TBranch* branch_Eff;
TBranch* branch_Nebula;
//TH1F *h_Eff = new TH1F("h_Eff","test");
TH1F *h_En = new TH1F("h_En","Neutrons Retrieved Energy",140,140,210);
//t->SetBranchAddress("Efficiency",&Efficiency,&branch_Eff);
t->SetBranchAddress("Nebula",&Neb_Phys,&branch_Nebula);
//int nentries_Eff = branch_Eff->GetEntries();
int nentries_Neb = branch_Nebula->GetEntries();
for(int i = 0; i < nentries_Neb ; i++){
t->GetEntry(i);
NeutronEnergy = Neb_Phys->NeutronEn;
int vec_size = NeutronEnergy.size();
for(int j = 0; j < vec_size; j++){
En = NeutronEnergy[j];
h_En->Fill(En);
}
}
TCanvas *c2 = new TCanvas("c2","Neutron Energy",1080,720);
h_En->SetLineWidth(6);
h_En->SetLineColor(6);
c2->SetFrameLineColor(0);
h_En->Draw("C9");
}
#include "/local/lemair/nptool/NPLib/Detectors/Nebula/TNebulaPhysics.h"
void EnDraw(){
TFile* f = TFile::Open("root/analysis/PhysicsTree.root");
TTree* t = (TTree*)f->Get("PhysicsTree");
TNebulaPhysics *Neb_Phys = new TNebulaPhysics();
std::vector<double> NeutronEnergy;
//std::vector<int>* Efficiency = 0;
double En, counter;
//int Eff;
//TBranch* branch_Eff;
TBranch* branch_Nebula;
//TH1F *h_Eff = new TH1F("h_Eff","test");
TH1F *h_En = new TH1F("h_En","Retrieved Neutron Energy",140,140,210);
//t->SetBranchAddress("Efficiency",&Efficiency,&branch_Eff);
t->SetBranchAddress("Nebula",&Neb_Phys,&branch_Nebula);
//int nentries_Eff = branch_Eff->GetEntries();
int nentries_Neb = branch_Nebula->GetEntries();
for(int i = 0; i < nentries_Neb ; i++){
t->GetEntry(i);
NeutronEnergy = Neb_Phys->NeutronEn;
int vec_size = NeutronEnergy.size();
for(int j = 0; j < vec_size; j++){
En = NeutronEnergy[j];
h_En->Fill(En);
}
}
TCanvas *c2 = new TCanvas("c2","Neutron Energy",1080,720);
h_En->Draw("");
}
void EnvsLight(){
TFile* f = TFile::Open("root/simulation/SimulatedTree.root");
TTree* t = (TTree*)f->Get("SimulatedTree");
TCanvas *c1 = new TCanvas("c1","Energy vs Light",1080,720);
double En, Light;
TBranch* branch_En;
TBranch* branch_Light;
TH1F *h_En = new TH1F("h_En","Energy",10,0.1,2);
TH1F *h_Light = new TH1F("h_Light","Light",10,0.1,2);
t->SetBranchAddress("Energy", &En, &branch_En);
t->SetBranchAddress("Light", &Light, &branch_Light);
int nentries = t->GetEntries();
for(int i=0 ; i<nentries ; i++){
t->GetEntry(i);
h_En->Fill(En);
h_Light->Fill(Light);
}
h_Light->SetLineColor(2);
h_En->Draw();
h_Light->Draw("SAME");
}
void GetTBrowser(){
TH1F *h1 = new TH1F("h1","Somme des Temps",100,-4,4);
TFile* f = TFile::Open("root/simulation/SimulatedTree.root");
TTree *t = (TTree*)f->Get("SimulatedTree");
TBranch *b = (TBranch*)t->GetBranch("Nebula");
TLeaf *tu = b->GetLeaf("fNebula_Tu_Time");
//Float_t td;
//b->SetAddress("fNebula_Td_Time", &td);
Int_t len = b->GetEntries();
Float_t sum;
for(int i = 0; i < len; i++){
sum = 0;
sum += tu->GetValue(i);
//sum += td;
h1->Fill(sum);
}
}
#include "/local/lemair/nptool/NPLib/Detectors/Nebula/TNebulaPhysics.h"
void PlasticBarTimeAndPosition(){
TFile* f = TFile::Open("root/simulation/SimulatedTree.root");
TTree* t = (TTree*)f->Get("SimulatedTree");
double Time;
//int Eff;
//TBranch* branch_Eff;
TBranch* branch;
//TH1F *h_Eff = new TH1F("h_Eff","test");
TH1F *h_Time = new TH1F("h_Time","PlasticBar_Time",500,55,65);
//t->SetBranchAddress("Efficiency",&Efficiency,&branch_Eff);
t->SetBranchAddress("PlasticBar_Time",&Time,&branch);
//int nentries_Eff = branch_Eff->GetEntries();
int nentries = branch->GetEntries();
for(int i = 0; i < nentries ; i++){
t->GetEntry(i);
h_Time->Fill(Time);
}
TCanvas *c2 = new TCanvas("c2","Neutron Energy",1080,720);
h_Time->Draw("");
}
#include "/local/lemair/nptool/NPLib/Detectors/Nebula/TNebulaPhysics.h"
#include <iostream> // std::cout
#include <algorithm> // std::find
#include <vector>
void EnvsLight(){
TFile* f = TFile::Open("root/simulation/SimulatedTree.root");
TTree* t = (TTree*)f->Get("SimulatedTree");
TCanvas *c1 = new TCanvas("c1","Position Z",1920,1200);
double Energy, Light;
TBranch* branch_En;
TBranch* branch_Li;
TH1F *h_en = new TH1F("h_en","Deposited Energy",100,1,200);
TH1F *h_li = new TH1F("h_li","Deposited Light",100,1,200);
t->SetBranchAddress("PlasticBar_Energy", &Energy, &branch_En);
t->SetBranchAddress("PlasticBar_Light", &Light, &branch_Li);
int nentries = t->GetEntries();
for(int i=0 ; i<nentries ; i++){
t->GetEntry(i);
h_en->Fill(Energy);
h_li->Fill(Light);
}
h_en->SetLineColor(kBlue-7);
h_en->Draw();
h_li->SetLineColor(kRed-7);
h_li->Draw("SAME");
}
#include "/local/lemair/nptool/NPLib/Detectors/Nebula/TNebulaPhysics.h"
#include <iostream> // std::cout
#include <algorithm> // std::find
#include <vector>
void PositionZ(){
TFile* f = TFile::Open("root/simulation/SimulatedTree.root");
TTree* t = (TTree*)f->Get("SimulatedTree");
TCanvas *c1 = new TCanvas("c1","Position Z",1080,720);
vector<double>* PosZ;
int vec_size;
TBranch* branch;
TH1F *h = new TH1F("h","Position Z",2400,10800,12200);
t->SetBranchAddress("Pos_Z", &PosZ, &branch);
int nentries = t->GetEntries();
for(int i=0 ; i<nentries ; i++){
t->GetEntry(i);
vec_size = (*PosZ).size();
for(int j = 0 ; j<vec_size ; j++)
h->Fill((*PosZ)[j]);
}
h->Draw("SAME");
}
void ProcVsKinEn2D(bool DoPads = 1, const char* PartPara = "all"){
TFile *f = TFile::Open("root/simulation/SimulatedTree.root");
TTree *t = (TTree*)f->Get("SimulatedTree");
std::vector<double>* v_kinen = 0;
std::vector<std::string>* v_partname = 0;
std::vector<std::string>* v_procname = 0;
const char* procname;
const char* partname;
double kinEn, prevkinEn;
double kinDiff;
TBranch* branch_kin;
TBranch* branch_proc;
TBranch* branch_part;
TCanvas* c = new TCanvas("c", "Processes by Kinetic Energy", 1920, 1200);
c->SetLeftMargin(0.15);
c->SetRightMargin(0.1);
c->SetTopMargin(0.1);
c->SetBottomMargin(0.1);
int NbBin = 100;
int Xmax = 200;
int Xmin = 0;
int Ymin = 1;
int Ymax = 1e7;
THStack *hs = new THStack("hs","Process CS according to Kinetic Energy");
TH1F *h_neutIn = new TH1F("h_neutIn","Neutron Inelastic",NbBin,Xmin,Xmax);
h_neutIn->GetYaxis()->SetRangeUser(Ymin, Ymax);
TH1F *h_hadEl = new TH1F("h_hadEl","Hadron Elastic",NbBin,Xmin,Xmax);
h_hadEl->GetYaxis()->SetRangeUser(Ymin, Ymax);
TH1F *h_ionIoni = new TH1F("h_ionIoni","Ion Ionization",NbBin,Xmin,Xmax);
h_ionIoni->GetYaxis()->SetRangeUser(Ymin, Ymax);
TH1F *h_hIoni = new TH1F("h_hIoni","Hadron Ionization",NbBin,Xmin,Xmax);
h_hIoni->GetYaxis()->SetRangeUser(Ymin, Ymax);
t->SetBranchAddress("KinEn", &v_kinen, &branch_kin);
t->SetBranchAddress("Process", &v_procname, &branch_proc);
t->SetBranchAddress("Particle", &v_partname, &branch_part);
int nentries = branch_kin->GetEntries();
for(int i = 0; i < nentries ; i++){
kinDiff = 0;
t->GetEntry(i);
int vec_size = (*v_kinen).size();
for(int j = 1; j < vec_size; j++){
procname = ((*v_procname)[j]).c_str();;
partname = ((*v_partname)[j]).c_str();;
prevkinEn = (*v_kinen)[j-1];
kinDiff = prevkinEn - kinEn;
if((strcmp(PartPara, "all")==0 || strcmp(partname, PartPara)==0) &&
strcmp(procname, "Transportation")!=0 &&
kinDiff>0){
if(strcmp(procname, "neutronInelastic")==0) h_neutIn->Fill(kinDiff);
else if(strcmp(procname, "hadElastic")==0) h_hadEl->Fill(kinDiff);
else if(strcmp(procname, "ionIoni")==0) h_ionIoni->Fill(kinDiff);
else if(strcmp(procname, "hIoni")==0) h_hIoni->Fill(kinDiff);
}
}
}
h_neutIn->GetYaxis()->SetTitle("Nb of Hits");
h_neutIn->GetXaxis()->SetTitle("Kinetic Energy (MeV)");
h_hadEl->GetYaxis()->SetTitle("Nb of Hits");
h_hadEl->GetXaxis()->SetTitle("Kinetic Energy (MeV)");
h_hIoni->GetYaxis()->SetTitle("Nb of Hits");
h_hIoni->GetXaxis()->SetTitle("Kinetic Energy (MeV)");
h_ionIoni->GetYaxis()->SetTitle("Nb of Hits");
h_ionIoni->GetXaxis()->SetTitle("Kinetic Energy (MeV)");
hs->Add(h_neutIn);
hs->Add(h_hadEl);
hs->Add(h_ionIoni);
hs->Add(h_hIoni);
if(DoPads){
h_neutIn->SetFillColor(kBlue-7);
h_hadEl->SetFillColor(kRed-7);
h_hIoni->SetFillColor(kYellow-7);
h_ionIoni->SetFillColor(kGreen-7);
hs->Draw("pads");
gPad->Update();
c->cd(1);
gPad->SetLogy(1);
gStyle->SetHistTopMargin(0.);
gStyle->SetOptStat(0);
c->cd(2);
gPad->SetLogy(1);
gStyle->SetHistTopMargin(0.);
gStyle->SetOptStat(0);
c->cd(3);
gPad->SetLogy(1);
gStyle->SetHistTopMargin(0.);
gStyle->SetOptStat(0);
c->cd(4);
gPad->SetLogy(1);
gStyle->SetHistTopMargin(0.);
gStyle->SetOptStat(0);
}
else{
gStyle->SetPalette(60);
hs->Draw("plc");
gPad->SetLogy(1);
hs->SetMinimum(1);
hs->SetMaximum(1e6);
hs->GetYaxis()->SetLimits(1,1e6);
//hs->Draw("plc");
}
}
void ProcVsKinEn3D(){
TFile *f = TFile::Open("root/simulation/SimulatedTree.root");
TTree *t = (TTree*)f->Get("SimulatedTree");
std::vector<double>* v_kinen = 0;
std::vector<std::string>* v_partname = 0;
std::vector<std::string>* v_procname = 0;
const char* procname;
const char* partname;
double kinEn, prevkinEn;
double kinDiff;
TBranch* branch_kin;
TBranch* branch_proc;
TBranch* branch_part;
TCanvas* c = new TCanvas("c", "Processes by Kinetic Energy", 1920, 1200);
c->SetLeftMargin(0.15);
c->SetRightMargin(0.1);
c->SetTopMargin(0.1);
c->SetBottomMargin(0.1);
TH2F *h_process_kin = new TH2F("h_process_kin","Processes by Kinetic Energy",80,0,200,1,0,1);
//h_process_kin->SetCanExtend(TH1::kAllAxes);
h_process_kin->SetStats(0);
t->SetBranchAddress("KinEn", &v_kinen, &branch_kin);
t->SetBranchAddress("Process", &v_procname, &branch_proc);
t->SetBranchAddress("Particle", &v_partname, &branch_part);
int nentries = branch_kin->GetEntries();
for(int i = 0; i < nentries ; i++){
kinDiff = 0;
t->GetEntry(i);
int vec_size = (*v_kinen).size();
for(int j = 1; j < vec_size; j++){
procname = ((*v_procname)[j]).c_str();;
partname = ((*v_partname)[j]).c_str();;
prevkinEn = (*v_kinen)[j-1];
kinDiff = prevkinEn - kinEn;
if(/*strcmp(partname, "neutron")==0 && */
strcmp(procname, "Transportation")!=0 &&
kinDiff>0){
h_process_kin->Fill(kinDiff,procname,1);
}
}
}
//h_process_kin->SetMinimum(-1);
//h_process_kin->SetMaximum();
h_process_kin->GetYaxis()->SetTitle("Process Name");
h_process_kin->GetXaxis()->SetTitle("Kinetic Energy (MeV)");
//gStyle->SetPalette(60);
//gStyle->SetPalette(53);
c->SetFrameFillColor(kAzure-6);
h_process_kin->Draw("COLZ");
c->SetLogz();
}
void DrawProcessGraph(){
TFile* f = TFile::Open("root/simulation/SimulatedTree.root");
TTree *t = (TTree*)f->Get("SimulatedTree");
//new TCanvas;
//t->Draw("Process");
//new TCanvas;
//t->Draw("El_is_1_and_InEl_is_2");
//new TCanvas;
//t->Draw("Efficiency");
std::vector<std::string>* processname = 0;
const char* name;
std::vector<double>* pos_z_vec = 0;
double pos_z;
TBranch* branch;
TCanvas* c = new TCanvas();
c->SetLeftMargin(0.18);
c->SetRightMargin(0.13);
c->SetTopMargin(0.1);
c->SetBottomMargin(0.08);
TH2F *h = new TH2F("h","test",500,9900,10100,2,0,2);
h->SetCanExtend(TH1::kAllAxes);
h->SetStats(0);
t->SetBranchAddress("Pos_Z",&pos_z_vec);
t->SetBranchAddress("Process",&processname,&branch);
int nentries = branch->GetEntries();
for(int i = 0; i < nentries ; i++){
t->GetEntry(i);
int vec_size = (*processname).size();
for(int j = 0; j < vec_size; j++){
name = ((*processname)[j]).c_str();
pos_z = (*pos_z_vec)[j];
if(strcmp(name,"Transportation")!=0){
h->Fill(pos_z,name,1);
}
}
}
//h->SetMaximum(5000);
h->SetMinimum(-1);
h->LabelsDeflate("X");
h->LabelsDeflate("Y");
h->LabelsOption("v");
//h->Draw("LEGO2");
h->Draw("SCAT");
}
#include "/local/lemair/nptool/NPLib/Detectors/Nebula/TNebulaPhysics.h"
#include <iostream> // std::cout
#include <algorithm> // std::find
#include <vector>
void BuildBox(double Z, double X, double Zsize, double Xsize, Color_t color){
TBox* box = new TBox(Z,X,Zsize,Xsize); //(Position of bottom-left corner, Position of top-right corner)
box->SetFillStyle(1001);
box->SetFillColor(color);
box->SetLineColor(kBlack);
box->SetLineWidth(1);
box->Draw("l");
}
void DrawWall(std::vector<int> v_ID){
vector<double> RefZ = {11060, 11181, 11910, 12031};
double RefX = 0;
double Z,X;
int ID;
Color_t color;
for(int sublayer = 0; sublayer < 4; sublayer ++){
for(int XOffset = -15; XOffset<15; XOffset++){
//CHECK IF BAR WAS HIT
ID = 30*sublayer + (XOffset+16);
if(std::find(v_ID.begin(), v_ID.end(), ID)!=v_ID.end()){
color = kOrange-8;
}else{
color = kCyan-8;
}
//DRAW BAR
Z = RefZ[sublayer];
X = RefX + XOffset*121;
BuildBox(Z,X,Z+120,X+120, color);
}
}
}
void NebulaWall(){
//SETTING THE VISUAL INTERFACE
TCanvas* c = new TCanvas("c", "Nebula Walls", 1920, 1200);
gPad->SetPad("pad", "New Pad", 0, 0, 1, 1, /*backgrd color*/ 0, /*line thickness*/ 0, /*stamping style*/ 0);
gPad->DrawFrame(10000,-2000,13500,2000);
c->SetGrid();
c->SetTopMargin(0.05);
c->SetBottomMargin(0.1);
c->SetLeftMargin(0.1);
c->SetRightMargin(0.05);
TFrame* frame = new TFrame(0,0,100,100);
//CONNECTING TO TREE AND DATA ANALYSIS
TFile *f = TFile::Open("root/analysis/PhysicsTree.root");
TTree *t = (TTree*)f->Get("PhysicsTree");
TNebulaPhysics *Neb_Phys = new TNebulaPhysics();
std::vector<int> v_ID;
int vec_size;
TBranch* branch;
t->SetBranchAddress("Nebula", &Neb_Phys, &branch);
int nentries = branch->GetEntries();
for(int i = 0; i < nentries; i++){
t->GetEntry(i);
v_ID = Neb_Phys->DetectorNumber;
vec_size = v_ID.size();
if(vec_size>=4){
DrawWall(v_ID);
gPad->Modified(); gPad->Update(); // make sure it is (re)drawn
gSystem->ProcessEvents(); gSystem->ProcessEvents();
gSystem->Sleep(1000);
cout << "size " << vec_size << endl;
cout << "event " << i << endl << endl;
//for(int j = 0 ; j < vec_size ; j++)
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment