rearranged energy loss settings, added macro script, updated mass plotter
This commit is contained in:
parent
9ae1c99200
commit
2bd5b18f63
34
Armory/aarootscript.C
Normal file
34
Armory/aarootscript.C
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#include "TFile.h"
|
||||||
|
#include "TTree.h"
|
||||||
|
#include "TGraph.h"
|
||||||
|
#include "TLegend.h"
|
||||||
|
#include "TCanvas.h"
|
||||||
|
#include "TH1D.h"
|
||||||
|
#include "TObjArray.h"
|
||||||
|
#include "TBranch.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
void aarootscript() {
|
||||||
|
TFile *f = new TFile("SimAnasen1.root");
|
||||||
|
TTree *tree1 = (TTree*)f->Get("tree1");
|
||||||
|
TTree *tree2 = (TTree*)f->Get("tree2");
|
||||||
|
|
||||||
|
TTreeReader reader("tree");
|
||||||
|
TTreeReaderValue<double> branchValue(reader, "Tb");
|
||||||
|
double totalSum = 0;
|
||||||
|
while (reader.Next()) {
|
||||||
|
totalSum += *branchValue;
|
||||||
|
}
|
||||||
|
std::cout << "Total Sum: " << totalSum << std::endl;
|
||||||
|
|
||||||
|
TTreeReader reader2("tree2");
|
||||||
|
TTreeReaderValue<double> branchValue2(reader2, "Tb");
|
||||||
|
double totalSum2 = 0;
|
||||||
|
while (reader2.Next()) {
|
||||||
|
totalSum2 += *branchValue2;
|
||||||
|
}
|
||||||
|
std::cout << "Total Sum: " << totalSum2 << std::endl;
|
||||||
|
|
||||||
|
std::cout << "Difference: " << totalSum - totalSum2 << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -270,22 +270,6 @@ int main(int argc, char **argv){
|
||||||
visTrackHitPos.push_back(hitPos);
|
visTrackHitPos.push_back(hitPos);
|
||||||
visTrackWires.push_back({anodeID[0], cathodeID[0]});
|
visTrackWires.push_back({anodeID[0], cathodeID[0]});
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
// apply energy loss from vertex to SX3 hit position (for light particle)
|
|
||||||
double dl = (hitPos - vertex).Mag() / 10.0; // path length in cm (positions in mm)
|
|
||||||
double EkinLight = Pb.E() - Pb.M();
|
|
||||||
double dedxLight = elossLight->Eval(EkinLight); // interpolate dE/dx
|
|
||||||
double dE_light = dedxLight * dl * density / 1000.0; // adjust for units (example scaling)
|
|
||||||
if (dE_light < EkinLight) {
|
|
||||||
Pb.SetE(Pb.E() - dE_light);
|
|
||||||
// update momentum to conserve direction
|
|
||||||
double p_new = TMath::Sqrt(Pb.E()*Pb.E() - Pb.M()*Pb.M());
|
|
||||||
TVector3 dir_new = Pb.Vect().Unit() * p_new;
|
|
||||||
Pb.SetPxPyPzE(dir_new.X(), dir_new.Y(), dir_new.Z(), Pb.E());
|
|
||||||
}
|
|
||||||
// update kinetic energy after loss
|
|
||||||
Tb = Pb.E() - Pb.M();*/
|
|
||||||
|
|
||||||
// reconstruct track from PW readings + SX3 hit
|
// reconstruct track from PW readings + SX3 hit
|
||||||
pw->CalTrack(hitPos, anodeID[0], cathodeID[0], false);
|
pw->CalTrack(hitPos, anodeID[0], cathodeID[0], false);
|
||||||
reTheta = pw->GetTrackTheta() * TMath::RadToDeg();
|
reTheta = pw->GetTrackTheta() * TMath::RadToDeg();
|
||||||
|
|
@ -298,22 +282,26 @@ int main(int argc, char **argv){
|
||||||
|
|
||||||
z0 = pw->GetZ0();
|
z0 = pw->GetZ0();
|
||||||
tree->Fill();
|
tree->Fill();
|
||||||
|
//printf("Event %d: Tb before energy loss = %.2f MeV\n", i, Tb);
|
||||||
// apply energy loss from vertex to SX3 hit position (for light particle)
|
// apply energy loss from vertex to SX3 hit position (for light particle)
|
||||||
double dl = (hitPos - vertex).Mag() / 10.0; // path length in cm (positions in mm)
|
double dl = (hitPos - vertex).Mag() / 10; // path length in cm (positions in mm)
|
||||||
double EkinLight = Pb.E() - Pb.M();
|
//printf("Event %d: dl = %f cm\n", i, dl);
|
||||||
|
double EkinLight = Pb.E() - Pb.M();// kinetic energy of light particle before loss
|
||||||
double dedxLight = elossLight->Eval(EkinLight); // interpolate dE/dx
|
double dedxLight = elossLight->Eval(EkinLight); // interpolate dE/dx
|
||||||
|
//printf("Event %d: dE/dx = %f MeV/(mg/cm^2)\n", i, dedxLight);
|
||||||
double dE_light = dedxLight * dl * density / 1000.0; // adjust for units (example scaling)
|
double dE_light = dedxLight * dl * density / 1000.0; // adjust for units (example scaling)
|
||||||
if (dE_light < EkinLight) {
|
//printf("Event %d: dE_light = %f MeV\n", i, dE_light);
|
||||||
Pb.SetE(Pb.E() - dE_light);
|
//if (dE_light < EkinLight) {
|
||||||
// update momentum to conserve direction
|
Pb.SetE(Pb.E() - dE_light); // update energy after loss
|
||||||
double p_new = TMath::Sqrt(Pb.E()*Pb.E() - Pb.M()*Pb.M());
|
double p_new = TMath::Sqrt(Pb.E()*Pb.E() - Pb.M()*Pb.M()); // update momentum to conserve direction
|
||||||
TVector3 dir_new = Pb.Vect().Unit() * p_new;
|
TVector3 dir_new = Pb.Vect().Unit() * p_new; // maintain original direction, adjust magnitude
|
||||||
Pb.SetPxPyPzE(dir_new.X(), dir_new.Y(), dir_new.Z(), Pb.E());
|
Pb.SetPxPyPzE(dir_new.X(), dir_new.Y(), dir_new.Z(), Pb.E()); // update 4-vector with new energy and momentum
|
||||||
}
|
//}
|
||||||
// update kinetic energy after loss
|
// update kinetic energy after loss
|
||||||
Tb = Pb.E() - Pb.M();
|
Tb = Tb - dE_light;
|
||||||
// fill tree2 with energy loss adjusted data
|
// fill tree2 with energy loss adjusted data
|
||||||
tree2->Fill();
|
tree2->Fill();
|
||||||
|
//printf("Event %d: Tb after energy loss = %.2f MeV\n", i, Tb);
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
// no valid SX3 hit: mark clearly invalid
|
// no valid SX3 hit: mark clearly invalid
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
void histcomp() {
|
void histcomp() {
|
||||||
|
gROOT->SetBatch(kTRUE);
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
TFile *f = new TFile("SimAnasen1.root");
|
TFile *f = new TFile("SimAnasen1.root");
|
||||||
|
|
@ -62,14 +63,31 @@ for (int i = 0; i < nBranches; i++) {
|
||||||
//if (h2->GetEntries() > 0) h2->Scale(1.0 / h2->GetEntries());
|
//if (h2->GetEntries() > 0) h2->Scale(1.0 / h2->GetEntries());
|
||||||
|
|
||||||
// Canvas
|
// Canvas
|
||||||
TCanvas *c = new TCanvas("c", name, 800, 600);
|
TCanvas *c = new TCanvas("c", name, 900, 600);
|
||||||
|
|
||||||
|
c->SetRightMargin(0.18);
|
||||||
|
c->Modified();
|
||||||
|
c->Update();
|
||||||
|
|
||||||
h1->SetTitle(name + ";"+name+";Counts");
|
h1->SetTitle(name + ";"+name+";Counts");
|
||||||
h1->Draw("HIST");
|
h1->Draw("HIST");
|
||||||
h2->Draw("HIST SAME");
|
h2->Draw("HIST SAME");
|
||||||
|
|
||||||
|
gPad->Update();
|
||||||
|
|
||||||
|
TPaveStats *st = (TPaveStats*)h1->FindObject("stats");
|
||||||
|
|
||||||
|
st->SetX1NDC(0.85); // New X start (left)
|
||||||
|
st->SetY1NDC(0.5); // New Y start (bottom)
|
||||||
|
st->SetX2NDC(0.98); // New X end (right)
|
||||||
|
st->SetY2NDC(0.8); // New Y end (top)
|
||||||
|
st->Draw();
|
||||||
|
gPad->Modified();
|
||||||
|
gPad->Update();
|
||||||
|
|
||||||
|
|
||||||
// Legend
|
// Legend
|
||||||
TLegend *leg = new TLegend(0.65,0.75,0.88,0.88);
|
TLegend *leg = new TLegend(0.65 + .2,0.75 + .1,0.88 + .1,0.88 + .1);
|
||||||
leg->AddEntry(h1, "tree1", "l");
|
leg->AddEntry(h1, "tree1", "l");
|
||||||
leg->AddEntry(h2, "tree2", "l");
|
leg->AddEntry(h2, "tree2", "l");
|
||||||
leg->Draw();
|
leg->Draw();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user