Skip to content

Instantly share code, notes, and snippets.

@simonthor
Created March 14, 2025 20:57
Show Gist options
  • Save simonthor/79f2da139b9e5bf8608d33f097b798ca to your computer and use it in GitHub Desktop.
Save simonthor/79f2da139b9e5bf8608d33f097b798ca to your computer and use it in GitHub Desktop.
Automated file creation of event display check files (edanew.C, rootlogon.C, .lst file)
EdbEDA *gEDA;
void edanew(){
int ibrick=0; // Brick number, not used
int tsrun =10; // Runnumber for Total scan
int sbrun =-1; // Run number for Scanback, assuming ver=1
int sfrun =-1; // Run number for Scanforth
int sfrun2=-1; // Run number for Scanforth
int use_microtrack=0; // if 1, read also microtrack in Scanback/forth data.
int dovertexing = 0; // Do vertexing or not.
char listfile[] = "TODOlstFile"; // The file that contains the initial tracks to plot
char textfile[] = ""; // filename of text file for reading tracks
char textfile2[] = "";
char textfile3[] = "";
gEDA=new EdbEDA("lnk_alignTFD_finealign.def",100,"nseg>=2&&((abs(s.eX-TODOVertX)<800.)&&(abs(s.eY-TODOVertY)<800.))",0);
if(sbrun>0) gEDA->GetTrackSet("SB")->ReadPredictionScan(ibrick, 1,sbrun, use_microtrack);
if(sfrun>0) gEDA->GetTrackSet("SF")->ReadPredictionScan(ibrick, 1,sfrun, use_microtrack);
if(sfrun2>0){
EdbEDATrackSet *set = gEDA->AddTrackSet("SF2");
set->ReadPredictionScan(ibrick, 1,sfrun2, use_microtrack);
set->SetTrackAttribute(kWhite);
}
if(dovertexing) gEDA->GetTrackSet("TS")->DoVertexing(NULL,3);
if(strlen(listfile)) gEDA->GetTrackSet("TS")->ReadListFile(listfile);
if(strlen(textfile)) gEDA->GetTrackSet("MN")->ReadTextTracks(textfile);
if(strlen(textfile2)) gEDA->AddTrackSet("MN2")->ReadTextTracks(textfile2);
if(strlen(textfile3)) gEDA->AddTrackSet("MN3")->ReadTextTracks(textfile3);
gEDA->Run(); // Load all data and open the GUI
gEDA->SetScaleZ(0.99); // Scale the Z axis
gEDA->SetBeamAngle(TODOBeamX,TODOBeamY); //(66641.8,48788.6)<82>??l
}
# Prepare the files for event display checks
# Author: Simon Thor
# Imports
from glob import glob
import pandas as pd
from argparse import ArgumentParser
def main():
arguments = ArgumentParser(add_help=True)
arguments.add_argument("-i", "--input", type=str, help="Input .csv file with event information. The second column must be the one that contains the zone number. Columns before that should be deleted.", default="FASERnu TFD and display checks.csv")
arguments.add_argument("--lst-folder", type=str, help="Folder with lst files", default="../data/lst-files/")
arguments.add_argument("--output-folder", type=str, help="Folder containing the vertXXXXX_pXXX-XXX vertex candidate folders", default="../data/real-data/")
arguments.add_argument("--template", type=str, help="Location of template file for edanew.C", default="edanew_template.C")
arguments.add_argument("--rootlogon", type=str, help="Location of rootlogon.C file", default="../data/real-data/rootlogon.C")
arguments.add_argument("--name", type=str, help="Name of the person doing the event display check", default="Simon")
args = arguments.parse_args()
input_file = args.input
lst_folder = args.lst_folder
output_folder = args.output_folder
template_file = args.template
rootlogon_file = args.rootlogon
name = args.name
# %%
events_to_check = pd.read_csv(input_file, header=None).convert_dtypes()
# Only select events with zone 1 (column 1) and lst file is uploaded (column 15) but display check is not done yet (column 17)
events_to_check = events_to_check[
# TFD done
(events_to_check.iloc[:, 14] == "1")
# lst file uploaded
& (events_to_check.iloc[:, 15] == "1")
# event display check assigned to me
& (events_to_check.iloc[:, 16] == name)
# event display check has not been done yet
& events_to_check.iloc[:, 18].isna()
]
# %% [markdown]
# ## Make edanew.C files for event display checks
# Iterate through all events that should be checked and prepare the files
for i, track_file_info in events_to_check.iterrows():
# Find the matching lst file by using the plate and subarea information
vertex_plate = str(track_file_info.iloc[2]).zfill(3)
vertex_subarea = str(track_file_info.iloc[3]).zfill(2)
zone = track_file_info.iloc[1]
# Find the lst file that has the string "vert{vertex_subarea}{vertex_plate}" in it
lst_file = f"F222_zone{zone}_p{vertex_plate}_{track_file_info.iloc[4]:.1f}_{track_file_info.iloc[5]:.1f}.lst"
beam_axis = (track_file_info.iloc[8], track_file_info.iloc[9])
with open(template_file, "r") as f:
edanew_template = f.read()
edanew_filled = (
edanew_template
.replace("TODOVertX", str(track_file_info.iloc[4]))
.replace("TODOVertY", str(track_file_info.iloc[5]))
.replace("TODOlstFile", lst_file)
.replace("TODOBeamX", str(beam_axis[0]))
.replace("TODOBeamY", str(beam_axis[1]))
)
# Get the output folder:
folder = glob(f"{output_folder}vert{vertex_subarea}{vertex_plate}*/reco*/v*/")
if len(folder) != 1:
print(f"There are {len(folder)} vXX folders in vert{vertex_subarea}{vertex_plate}. Should be only one. Skipping.")
continue
# Write the edanew.C, .lst and rootlogon.C files to the folder
folder = folder[0]
with open(folder + "edanew.C", "w") as f:
f.write(edanew_filled)
with open(f"{lst_folder}{lst_file}", "r") as f:
lst_file_contents = f.read()
with open(folder + lst_file, "w") as f:
f.write(lst_file_contents)
with open(rootlogon_file, "r") as f:
rootlogon = f.read()
with open(folder + "rootlogon.C", "w") as f:
f.write(rootlogon)
print(f"Prepared files for vert{vertex_subarea}{vertex_plate}")
if __name__ == "__main__":
main()
void rootlogon(){
gSystem->Load("libvt");
gSystem->Load("libEmath");
gSystem->Load("libEdb");
gSystem->Load("libEbase");
gSystem->Load("libEdr");
gSystem->Load("libEIO");
gSystem->Load("libShower");
gSystem->Load("libScan");
gSystem->Load("libEDA");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment