Skip to content

Commit 841140a

Browse files
authored
Merge pull request #615 from sudipbhattarai/showermax-lookup
Shower-max PE response lookup table analysis script
2 parents 6a5212d + 3fab176 commit 841140a

8 files changed

+416
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
energy,xp0,xp1,yp0,yp1,yp2
2+
5,0.00186854,-6.27248e-07,0.000318276,3.09224e-07,1.11394e-07
3+
10,0.0102587,-1.50709e-05,0.0182153,2.54559e-05,-1.01119e-06
4+
50,0.617914,0.00109035,0.734966,-0.000662327,-2.13036e-05
5+
100,2.40497,0.00304654,2.52607,-0.000402899,-2.82908e-05
6+
500,17.2653,0.0150206,17.7501,-0.00199242,-0.000123669
7+
1000,35.8243,0.0354252,36.7149,-0.00443617,-0.000235146
8+
2000,71.2615,0.0664176,73.2177,-0.0101103,-0.000481341
9+
1000,35.8243,0.0354252,36.7149,-0.00443617,-0.000235146
10+
3000,105.66,0.102495,107.507,-0.00432239,-0.000539539
11+
4000,138.983,0.129233,141.393,-0.00765265,-0.000714903
12+
5000,170.902,0.156594,174.967,-0.0165793,-0.00102413
13+
6000,202.591,0.195464,206.781,-0.0185614,-0.00107666
14+
7000,233.861,0.214678,238.794,-0.0255901,-0.00132374
15+
8000,265.736,0.253171,270.522,-0.021348,-0.001311
16+
9000,295.394,0.2864,301.713,-0.0221357,-0.00161815
17+
10000,324.714,0.318387,331.45,-0.0336423,-0.00174544
18+
11000,354.866,0.339425,362.352,-0.00987083,-0.0018857
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
energy,xp0,xp1,yp0,yp1,yp2
2+
5,0.0627517,-1.0543e-06,0.0581547,-0.000192039,1.40549e-06
3+
10,0.148161,-0.000245255,0.151718,-0.00012809,-9.33095e-07
4+
50,1.42496,0.00174349,1.46062,0.000384533,-1.0486e-05
5+
100,3.20275,0.00199171,3.36658,-0.000972939,-3.72528e-05
6+
500,17.7877,0.0168821,18.5357,-0.00305322,-0.000173396
7+
1000,35.7328,0.0391455,37.0105,-0.00385948,-0.000290996
8+
2000,68.9893,0.0654994,70.7129,-0.00186141,-0.000405991
9+
1000,35.7328,0.0391455,37.0105,-0.00385948,-0.000290996
10+
3000,100.729,0.0891212,103.059,-0.00785097,-0.00059099
11+
4000,131.482,0.121328,134.431,-0.00446825,-0.000761432
12+
5000,161.28,0.161656,165.487,-0.0160822,-0.000957194
13+
6000,189.225,0.163666,193.413,-0.0122421,-0.000973039
14+
7000,218.903,0.222023,223.881,-0.0321237,-0.00125839
15+
8000,247.765,0.239203,252.623,-0.0280649,-0.00124614
16+
9000,273.899,0.262618,279.212,0.00200576,-0.0014183
17+
10000,302.462,0.304135,309.125,-0.0166459,-0.00164194
18+
11000,329.102,0.376249,338.584,-0.0376803,-0.00227799
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
energy,xp0,xp1,yp0,yp1,yp2
2+
500,7.61904,0.00705542,7.68358,8.26442e-05,-2.35436e-05
3+
1000,9.84448,0.00476633,9.85678,-0.000641187,-7.83977e-06
4+
2000,10.6694,0.00424422,10.6791,0.000134362,-1.42913e-06
5+
1000,9.84448,0.00476633,9.85678,-0.000641187,-7.83977e-06
6+
3000,10.902,0.00580823,10.7998,-0.000183595,1.279e-05
7+
4000,10.9523,0.00511675,10.9356,-0.000334526,-9.12267e-07
8+
5000,11.1126,0.00453355,11.0124,8.11234e-05,1.29421e-05
9+
6000,11.0563,0.00719545,11.0066,0.000110291,4.91498e-06
10+
7000,11.3055,0.00669282,11.1802,0.000123959,1.57476e-05
11+
8000,11.1125,0.00717593,10.9525,-0.000299558,2.83419e-05
12+
9000,11.2697,0.00621689,11.1181,-0.000846437,2.12847e-05
13+
10000,11.2074,0.00588017,11.126,-0.0010563,1.76701e-05
14+
11000,11.2681,0.00494686,11.1262,0.000572583,2.20093e-05
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
energy,xp0,xp1,yp0,yp1,yp2
2+
1000,0.0325032,5.81897e-05,0.0380673,9.18402e-06,-7.12998e-07
3+
2000,0.664703,0.000268984,0.720299,-7.24534e-05,-1.19415e-05
4+
1000,0.0325032,5.81897e-05,0.0380673,9.18402e-06,-7.12998e-07
5+
3000,1.83493,0.000569759,2.03071,-0.000872436,-3.77283e-05
6+
4000,3.25583,-2.87781e-05,3.35537,6.4597e-05,-2.61931e-05
7+
5000,4.34997,0.00252794,4.64361,-0.00141612,-5.65787e-05
8+
6000,5.83171,0.00972787,5.98878,-0.00104332,-4.09446e-05
9+
7000,7.62846,0.00426204,8.04478,-0.000292948,-8.13441e-05
10+
8000,9.8956,0.00675217,10.3159,0.00146602,-9.63828e-05
11+
9000,11.0889,0.00751149,11.8324,-0.00388285,-0.000106202
12+
10000,13.8775,0.00984104,14.9472,0.00143721,-0.000206724
13+
11000,15.6238,0.0224891,16.3091,-0.00900119,-0.000160528
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
energy,xp0,xp1,yp0,yp1,yp2
2+
500,5.39623,0.00672054,5.5963,-0.000690162,-4.39051e-05
3+
1000,8.70975,0.00426233,8.69977,0.000156259,-7.83212e-06
4+
2000,10.7281,0.00291869,10.8914,0.000375828,-4.35732e-05
5+
1000,8.70975,0.00426233,8.69977,0.000156259,-7.83212e-06
6+
3000,12.4285,0.00493266,12.6518,0.000701055,-4.96781e-05
7+
4000,14.5609,-0.000216201,15.0292,-0.00106373,-0.000120579
8+
5000,17.187,0.00532813,17.9249,0.000601087,-0.000154178
9+
6000,21.536,0.00222366,21.9014,-0.00511615,-0.000135389
10+
7000,23.5107,0.015075,23.7392,-0.00262259,-6.06112e-05
11+
8000,25.8184,0.015339,26.8405,-0.00330766,-0.000222387
12+
9000,28.3697,0.0249847,28.6818,0.0040931,-0.000111408
13+
10000,29.5291,0.0173609,29.3689,-0.00523963,-4.497e-05
14+
11000,30.8697,0.0487093,31.7276,0.00668593,-0.000143964
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// ROOTscript: plot_shower-max_response.C
2+
// -----------------------------------------------------------------------------------
3+
// Author: Sudip Bhattarai
4+
// Date: 01/21/2025
5+
// Purpose: Read the remoll rootfile and use shower-max lookup table to plot the PE response.
6+
// -----------------------------------------------------------------------------------
7+
8+
#include "TChain.h"
9+
#include "TH1.h"
10+
#include "TROOT.h"
11+
#include "TCanvas.h"
12+
#include <iostream>
13+
#include <fstream>
14+
#include <utility>
15+
#include <vector>
16+
#include <string>
17+
#include "./remollToQsim.hh"
18+
#include "./shower-max_resposne_lookup.hh"
19+
20+
// Namespace list to use
21+
using std::cout, std::cerr, std::endl;
22+
using std::vector, std::string;
23+
using std::ifstream, std::ofstream;
24+
using std::pair, std::map;
25+
26+
// Main function
27+
void plot_showermax_response(){
28+
// Genetate random values for x, y, theta, phi
29+
30+
// Get the fit parameters
31+
vector<vector<Double_t>> fit_data_electron = retrieve_fit_data("e-");
32+
vector<vector<Double_t>> fit_data_gamma = retrieve_fit_data("gamma");
33+
vector<vector<Double_t>> fit_data_mu = retrieve_fit_data("mu-");
34+
vector<vector<Double_t>> fit_data_pi = retrieve_fit_data("pi-");
35+
vector<vector<Double_t>> fit_data_neutron = retrieve_fit_data("neutron");
36+
37+
// Make a map of pid and fit_data
38+
map<int, vector<vector<Double_t>>> map_fit_data;
39+
map_fit_data[11] = fit_data_electron;
40+
map_fit_data[-11] = fit_data_electron;
41+
map_fit_data[22] = fit_data_gamma;
42+
map_fit_data[13] = fit_data_mu;
43+
map_fit_data[-13] = fit_data_mu;
44+
map_fit_data[211] = fit_data_pi;
45+
map_fit_data[-211] = fit_data_pi;
46+
map_fit_data[2112] = fit_data_neutron;
47+
48+
// Test pe response
49+
// cout << "PE: " << get_PE_response(map_fit_data[11], 1234, 0, 0) << endl;
50+
51+
// Remoll file path goes here
52+
int goodFileCount = 1; // Number of good (non-corrupted) files
53+
TString rootFile= "~/moller/softwares/remoll-zone/rootfiles/smStack_v23/sm_tqStack_3sector_moller_50k_1001.root";
54+
55+
// Define histograms
56+
TH1D* h_hitRate = new TH1D("hitRate", "Rate weighted hit; hit.r [mm]; rate[GHz/65uA]", 100, 1000, 1200);
57+
TH1D* h_hitRateSmPE = new TH1D("hitRateSmPE", "Rate weighted hit; hit.r [mm]; rate [GHz/65uA/PE]", 100, 1000, 1200);
58+
59+
// Declare TChain
60+
TChain* T = new TChain("T");
61+
T->Add(rootFile);
62+
63+
Long64_t nEntries = T->GetEntries();
64+
cout << "Total number of entries in the chain: " << nEntries << endl;
65+
std::vector<remollGenericDetectorHit_t> *fHit = 0;
66+
// remollEvent_t *fEv = 0;
67+
Double_t fRate = 0;
68+
Float_t energy(-1.0e-12), rate(-1.0e-12),
69+
hitx(-1.0e-12), hity(-1.0e-12), hitr(-1.0e-12), hitpz(-1.0e-12),
70+
pe(0);
71+
Int_t pid(0), det(0);
72+
73+
T->SetBranchAddress("hit", &fHit);
74+
T->SetBranchAddress("rate", &fRate);
75+
// T->SetBranchAddress("ev", &fEv);
76+
77+
//This loop goes over all the events in the root files
78+
for (Long64_t iEvent = 0; iEvent < nEntries; iEvent++){
79+
if (iEvent % (nEntries/10) == 0)
80+
cout << "Analyzed " << iEvent << " events." << endl;
81+
T->GetEntry(iEvent); //Reads all the branches for entry(iEvent) and writes it to the respective variable(fHit or fRate)
82+
83+
//This loop goes over all the hits in the specific event
84+
for (Int_t iHit = 0; iHit < fHit->size(); iHit++){
85+
det = fHit->at(iHit).det;
86+
energy = fHit->at(iHit).e;
87+
pid = fHit->at(iHit).pid;
88+
hitx = fHit->at(iHit).x;
89+
hity = fHit->at(iHit).y;
90+
hitr = fHit->at(iHit).r;
91+
hitpz = fHit->at(iHit).pz;
92+
rate = fRate/1.0e9/goodFileCount; // convert to GHz/uA
93+
94+
//Fill histograms with proper cuts
95+
bool all_cuts = (det == 30 && //det number 30 is SM plane
96+
hitr>1020 && hitr<1180)&&
97+
(pid==11 || pid==-11 || pid==22 || pid==13 || pid==-13 || pid==211 || pid==-211 || pid==2112) && //particle selection
98+
energy>2 && //energy cut
99+
hitpz>0; //particle coming from upstream (pz>0)
100+
101+
if (all_cuts) {
102+
std::pair<double, double> qsimxy = ConvertRemollToQsim(hitx, hity);
103+
pe = get_PE_response(map_fit_data[pid], energy, qsimxy.first, qsimxy.second);
104+
105+
h_hitRate->Fill(hitr, rate);
106+
h_hitRateSmPE->Fill(hitr,rate*pe);
107+
}
108+
}
109+
}
110+
111+
// Print the rate in shower-max for script validation
112+
double rateTotal = h_hitRate->Integral(); // in GHz
113+
cout << "Accepted rate: " << rateTotal << " GHz" << endl;
114+
115+
double cathCurrent = h_hitRateSmPE->Integral()*1e9*1.6e-19*1e9; // in nA
116+
cout << "Cathode current: " << cathCurrent << " nA" << endl;
117+
118+
// Plot the histograms
119+
TCanvas* c1 = new TCanvas("c1", "c1", 1300, 500);
120+
c1->Divide(2, 1);
121+
c1->cd(1);
122+
h_hitRate->Draw("hist E");
123+
c1->cd(2);
124+
h_hitRateSmPE->Draw("hist E");
125+
126+
}
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#ifndef REMOLL_TO_QSIM_HH
2+
#define REMOLL_TO_QSIM_HH
3+
4+
#include <cmath>
5+
#include <vector>
6+
#include <TMath.h>
7+
8+
// Constants for the qsim system
9+
const double RADIUS_CENTER = 1100.0; // mm, radial distance from remoll center to the center of qsim planes
10+
const double QSIM_PLANE_WIDTH = 160.0; // mm, radial dimension of qsim planes
11+
const double QSIM_PLANE_HEIGHT = 265.0; // mm, azimuthal straight dimension of qsim planes
12+
const int N_PLANES = 28; // Number of qsim planes
13+
14+
// Function to calculate the azimuthal angle for each qsim plane
15+
inline std::vector<double> CalculateQsimPlaneAngles() {
16+
std::vector<double> planeAngles;
17+
double deltaPhi = 2 * TMath::Pi() / N_PLANES;
18+
for (int i = 0; i < N_PLANES; ++i) {
19+
planeAngles.push_back(i * deltaPhi);
20+
}
21+
return planeAngles;
22+
}
23+
24+
// Function to convert remoll (x, y) coordinates to qsim plane coordinates
25+
inline std::pair<double, double> ConvertRemollToQsim(double x_remoll, double y_remoll) {
26+
// Calculate the polar coordinates (r, phi) in the remoll system
27+
double r_remoll = std::sqrt(x_remoll * x_remoll + y_remoll * y_remoll);
28+
double phi_remoll = std::atan2(y_remoll, x_remoll); // Angle in radians
29+
30+
// Adjust
31+
32+
// Adjust phi_remoll to be in the range [0, 2pi)
33+
if (phi_remoll < 0) { phi_remoll += 2 * TMath::Pi(); }
34+
35+
// Calculate qsim plane angles
36+
std::vector<double> qsimAngles = CalculateQsimPlaneAngles();
37+
38+
// Determine the closest qsim plane
39+
int closestPlane = 0;
40+
double minDeltaPhi = TMath::Pi(); // Initialize to the largest possible value
41+
42+
for (size_t i = 0; i < qsimAngles.size(); ++i) {
43+
double deltaPhi = std::fabs(phi_remoll - qsimAngles[i]);
44+
deltaPhi = std::min(deltaPhi, 2 * TMath::Pi() - deltaPhi); // Account for circular nature
45+
46+
if (deltaPhi < minDeltaPhi) {
47+
minDeltaPhi = deltaPhi;
48+
closestPlane = i;
49+
}
50+
}
51+
52+
// Calculate the local coordinates on the closest qsim plane
53+
double planeAngle = qsimAngles[closestPlane];
54+
double x_plane_center = RADIUS_CENTER * std::cos(planeAngle);
55+
double y_plane_center = RADIUS_CENTER * std::sin(planeAngle);
56+
57+
// Transform remoll coordinates to the local coordinate system of the qsim plane
58+
double x_local = (x_remoll - x_plane_center) * std::cos(planeAngle) + (y_remoll - y_plane_center) * std::sin(planeAngle);
59+
double y_local = - (x_remoll - x_plane_center) * std::sin(planeAngle) + (y_remoll - y_plane_center) * std::cos(planeAngle);
60+
61+
// Output the results
62+
// std::cout << "Remoll coordinates: (" << x_remoll << ", " << y_remoll << ")\n";
63+
// std::cout << "Closest qsim plane: " << closestPlane + 1 << "\n";
64+
// std::cout << "Qsim local coordinates on plane " << closestPlane + 1 << ": (" << x_local << ", " << y_local << ")\n";
65+
66+
return {x_local, y_local};
67+
}
68+
69+
#endif // REMOLL_TO_QSIM_HH

0 commit comments

Comments
 (0)