From a021100e9efcab6d8ac09ba056f074296d03dbc9 Mon Sep 17 00:00:00 2001 From: Henrike Fleischhack Date: Tue, 2 Mar 2021 15:36:36 -0500 Subject: [PATCH 1/5] Adding sensitivity scripts --- sensitivity/ContinuumSensitivityOptimizer.sh | 125 +++++++ sensitivity/README.md | 5 + .../TotalBackground.extracted_mimrec_open.cfg | 305 ++++++++++++++++++ sensitivity/parseSensitivity.py | 61 ++++ 4 files changed, 496 insertions(+) create mode 100755 sensitivity/ContinuumSensitivityOptimizer.sh create mode 100644 sensitivity/README.md create mode 100644 sensitivity/TotalBackground.extracted_mimrec_open.cfg create mode 100644 sensitivity/parseSensitivity.py diff --git a/sensitivity/ContinuumSensitivityOptimizer.sh b/sensitivity/ContinuumSensitivityOptimizer.sh new file mode 100755 index 0000000..0a7b710 --- /dev/null +++ b/sensitivity/ContinuumSensitivityOptimizer.sh @@ -0,0 +1,125 @@ +#! /bin/bash + +#Author: Carolyn Kierans (mainly), Henrike Fleischhack + +help() { + echo "" + echo "Automated script to paralellize SensitivityOptimizer"; + echo ""; + echo ""; +} + +CMD=( "$@" ) + +THREADS=1 +NICELEVEL=0 + +#Got that one from Carolyn +CFG="TotalBackground.extracted_mimrec_open.cfg" + +#Set paths to continuum source and background sims (and Geometry file) here. +SourceFILE_PATH="/data/slag2/hfleisc1/amego_sims/simfiles/base/background/ContinuumPointSource/" +SOURCEFILES=("FarFieldPointSource_Continuum_0.080MeV_Cos1.0.p.tra.gz" "FarFieldPointSource_Continuum_0.800MeV_Cos1.0.p.tra.gz" "FarFieldPointSource_Continuum_8.000MeV_Cos1.0.p.tra.gz" ) + +BkgFILE="/data/slag2/hfleisc1/amego_sims/simfiles/base/background/FullBackground.tra.gz" + +GEOMETRY="/Home/eud/hfleisc1/amego_software/ComPair/Geometry/AMEGO_Midex/AmegoBase.geo.setup" + +#set output directory here +ODIR="$PWD/Sensitivity/base/" +mkdir -p $ODIR + +#Energy bins, in keV. Picked such that width of the bin = bin center +ENERGY_Low=( 180 250 350 500 650 1000 1750 2500 3500 5000) +ENERGY_High=(530 750 1050 1500 1950 3000 5250 7500 10500 15000) + +# Find the default number of threads +if [[ ${OSTYPE} == darwin* ]]; then + THREADS=`sysctl -n hw.logicalcpu_max` +elif [[ ${OSTYPE} == linux* ]]; then + THREADS=`grep processor /proc/cpuinfo | wc -l` +fi + +# Check if revan exists +if (`test -f ${MEGAlib}/bin/SensitivityOptimizer`); then + echo " " + echo "ERROR: The SensitivityOptimizer executable does not exist. Try to (re-)compile MEGAlib." + echo " " + exit 1; +fi + + +echo " " +echo "Launching mSensitivityOptimizer" +echo " " +echo "Number of threads to use: ${THREADS}" +echo "Nice level: ${NICELEVEL}" +if [[ ${GEOMETRY} != "" ]]; then + echo "Geometry: ${GEOMETRY}" +fi +echo "Revan configuration file: ${CFG}" +echo "Source files: ${SourceFILE_1}" +echo "Bkg file: ${BkgFILE}" +echo "Energies: ${ENERGY_Low[@]}" + +# Now run + +#We produce "signal" sims in three different energy ranges to get good statistics +#(1e8 events total per energy range). +#Set which file to use, energy range and number of simulated signal events here. +for i in ${!ENERGY_Low[@]}; do + SOURCE="${SourceFILE_PATH}" + if (( "${ENERGY_Low[$i]}" < 800)); then + SOURCE+="${SOURCEFILES[0]}" + PLOW=80 + PHIGH=10000 + EVENTS=100000000 + elif (( "${ENERGY_Low[$i]}" < 8000)); then + SOURCE+="${SOURCEFILES[1]}" + PLOW=800 + PHIGH=100000 + EVENTS=100000000 + else + SOURCE+="${SOURCEFILES[2]}" + PLOW=8000 + PHIGH=1000000 + EVENTS=100000000 + fi + + if (( "${ENERGY_Low[$i]}" < 1750 )); then + NARM=8 + else + NARM=12 + fi + +#Adjust the desired observing time (-t 94610000) and simulated bg observing time (-b ... 7200) below. + + echo "Launching SensitivityOptimizer for ${ENERGY_Low[$i]}-${ENERGY_High[$i]}" + CMD="source ${MEGALIB}/bin/source-megalib.sh; SensitivityOptimizer -n $ODIR/Sensitivity_Continuum_" + CMD+="${ENERGY_Low[$i]}-" + CMD+="${ENERGY_High[$i]}_" + CMD+="${PLOW}" + CMD+="keV_R1_bash -t 94610000" + CMD+=" -g ${GEOMETRY}" + CMD+=" -k ${SOURCE} ${EVENTS} 70685.8 2 ${PLOW} ${PHIGH} 0 0" + CMD+=" -b ${BkgFILE} 7200" + CMD+=" -c ${CFG}" + CMD+=" --contegy ${ENERGY_Low[$i]} ${ENERGY_High[$i]}" + CMD+=" --ptheta 0 0 1 --pphi 0 0 1 --csl 2 2 10 --tsl 1 2 20 --ehc 90 90 1 --arm 1 8 $NARM --phi 50 180 7" + CMD+=" --cqf 100 100 1 --fdi 1 4 3 --spd 20 80 7 --pop 10 30 3 --idp 500 700 3" +# CMD+=" --ptheta 0 0 1 --pphi 0 0 1 --csl 2 2 10 --tsl 1 2 20 --ehc 90 90 1 --arm 1 15 29 --phi 0 180 37" +# CMD+=" --cqf 100 100 1 --fdi 1 9 19 --spd 10 100 10 --pop 10 60 11 --idp 100 1000 10" +# comment in the last two lines (and comment out the lines before) to open up the cut space to be optimized + + nohup nice -n ${NICELEVEL} bash -c "${CMD}" > /dev/null & + echo ${CMD} + sleep 0.5 +done + + +# We always wait until all runs have finished +echo "Waiting till all runs have finished..." +wait + + +exit 0; diff --git a/sensitivity/README.md b/sensitivity/README.md new file mode 100644 index 0000000..2ed5c4f --- /dev/null +++ b/sensitivity/README.md @@ -0,0 +1,5 @@ +`ContinuumSensitivityOptimizer.sh`: Example script for how to obtain optimized cuts and expected sensitivity in wide energy bins. + +`parseSensitivity.py`: Script to extract effective area, bg rates, sensitivity from log files produced in the previous step. + +(tba: Script to extract optimized cuts from log files) \ No newline at end of file diff --git a/sensitivity/TotalBackground.extracted_mimrec_open.cfg b/sensitivity/TotalBackground.extracted_mimrec_open.cfg new file mode 100644 index 0000000..e87b8d4 --- /dev/null +++ b/sensitivity/TotalBackground.extracted_mimrec_open.cfg @@ -0,0 +1,305 @@ + + 2 + 29911 + /data/slag2/ckierans/AMEGO/Geometry/AMEGO_Midex/AmegoBase.geo.setup + /data/slag2/ckierans/AMEGO/AMEGOX_SensitivityCalcs/BackgroundSims/TraFiles/R1_Files/TotalBackground_minusTrappedLeptonic.R1.tra.gz + + /data/slag2/ckierans/AMEGO/AMEGOX_SensitivityCalcs/BackgroundSims/TraFiles/R1_Files/TotalBackground_minusTrappedLeptonic.R1.tra.gz + /data/slag2/ComPair/Simulations/AMEGO_20170814/TraFiles/FarFieldPointSource_0.158MeV_Cos0.7.inc1.id1.tra + + + /data/slag2/ckierans/AMEGO/Geometry/AMEGO_Midex/AmegoBase.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + + + + 0 + 4 + 0 + 0.0001 + 5 + 0 + 0 + 1 + 20 + 2 + 2 + 0.5 + false + 2.5 + 0 + + + + + 1 + + + + + 2 + + 1 + 0 + 0 + + + 0 + 0 + 1 + + + 0 + 180 + + 40 + + -180 + 180 + + 80 + + 80 + 100 + + 40 + + 170 + 190 + + 40 + + -5 + 5 + + 50 + + -5 + 5 + + 50 + + 9.99 + 10.01 + + 1 + + + 0 + 0 + + 0 + + + 1 + 10 + MyAnimated.gif + + + 5.2 + 20 + + + 1500 + 128 + 2 + 1 + false + false + 1 + + + 8 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + + 0 + 10000000 + + 0 + + + + 1 + 100 + + + 2 + 10 + + + 0 + 100 + + + 0 + 100 + + + 0 + 100 + + + 0 + 1000000 + + + 0 + 0 + + + 0 + 0 + + + 0 + 0 + + + 0 + 100000 + + + 0 + 100000 + + + 0 + 180 + + 180 + + 0 + 2147480000 + + + 0 + 2147480000 + + + -1000 + 2147483647 + + + 0 + 1 + + + 0 + 180 + + + 0 + 10000 + + + 0 + 1 + ___NotDefined___ + ___NotDefined___ + 0 + + 0 + 0 + -1e+20 + + + + false + 1 + 0 + 0 + 184.56 + -5.78 + 0 + 0 + 100 + + 0 + 180 + + + 0 + 180 + + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + false + 0 + 0 + 10000 + 0 + 0 + 0 + 1000 + 1000 + + + DCalCSI + + + + 3 + 20 + $(MEGALIB)/resource/libraries/IsotopeLibrary_HomelandSecurity_Short.isotopes + 1 + + + false + + 0 + 0 + + + 0 + 180 + + + 0 + 0 + 100 + + 180 + 30 + + + true + + + 180 + 181 + 2000 + 90 + + + + 10 + + diff --git a/sensitivity/parseSensitivity.py b/sensitivity/parseSensitivity.py new file mode 100644 index 0000000..6c8b6b4 --- /dev/null +++ b/sensitivity/parseSensitivity.py @@ -0,0 +1,61 @@ +import glob +import pandas + +#Script to parse through sensitivity output log files +#Output is a table with BG rates, effecitve area, sensitivity for each event type, +#ordered by energy. +#Author: Henrike Fleischhack + + +#Set your input files here +files = glob.glob("Sensitivity/pixel_rightOrbit/*log") + +data = [] + +for f in files: + + res = {} + + #File names should look like Sensitivity_Continuum_90-270_80keV_R1_bash.log + #where the energy bin goes from 90 to 270 keV. + E=int(f.split("_")[3].split("-")[0]) + print(f, E) + res["E"] = E + + with open(f, "r") as fi: + + for line in fi.readlines(): + + if "Best achievable sensitivity - untracked compton" in line: + current = "UC" + + if "Best achievable sensitivity - tracked compton" in line: + current = "TC" + + if "Best achievable sensitivity - pairs" in line: + current = "P" + + if " -> " not in line: + continue + + if "EffectiveArea" in line: + EA = line.split()[2] + res[f"Aeff_{current}"] = EA + + if "Sensitivity" in line: + sens = line.split()[2] + res[f"Sens_{current}"] = sens + if "background" in line: + rate = line.split()[4] + res[f"BG_{current}"] = rate + + data.append(res) + +#dataframe magic +cols = [ f"{i}_{j}" for j in ["UC", "TC", "P" ] for i in ["BG", "Aeff", "Sens"] ] +df = pandas.DataFrame( data ).set_index("E").sort_index()[cols].fillna("") + +print(df) + +#Set your output filename here +df.to_csv("pixel_rightOrbit_sens.csv") From 2a88338206ba430208af9b525261d832e12ad80b Mon Sep 17 00:00:00 2001 From: Henrike Fleischhack Date: Tue, 2 Mar 2021 15:39:56 -0500 Subject: [PATCH 2/5] 'documentation' 'update' --- sensitivity/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sensitivity/README.md b/sensitivity/README.md index 2ed5c4f..1309c63 100644 --- a/sensitivity/README.md +++ b/sensitivity/README.md @@ -2,4 +2,6 @@ `parseSensitivity.py`: Script to extract effective area, bg rates, sensitivity from log files produced in the previous step. +Note: Both scripts have hardcoded paths/filenames, check comments to see what needs to be edited. + (tba: Script to extract optimized cuts from log files) \ No newline at end of file From a7b54931ada48262c5b371cb47bc8b49d602de10 Mon Sep 17 00:00:00 2001 From: Henrike Fleischhack Date: Mon, 19 Apr 2021 15:33:25 -0400 Subject: [PATCH 3/5] Background plotting scripts --- background_spectra/PlotBackground.cxx | 156 +++++++++ background_spectra/README.md | 18 ++ ...RemoveBottomTrackerLeptonicInteractions.py | 113 +++++++ .../mimrec_AMEGOX_PlotBkgSpectrum_C.cfg | 305 ++++++++++++++++++ .../mimrec_AMEGOX_PlotBkgSpectrum_P.cfg | 305 ++++++++++++++++++ .../mimrec_AMEGOX_PlotBkgSpectrum_TC.cfg | 305 ++++++++++++++++++ .../mimrec_AMEGOX_PlotBkgSpectrum_UC.cfg | 305 ++++++++++++++++++ .../mimrec_AMEGOX_PlotBkgSpectrum_all.cfg | 305 ++++++++++++++++++ background_spectra/mimrec_bg_spectra.sh | 28 ++ 9 files changed, 1840 insertions(+) create mode 100644 background_spectra/PlotBackground.cxx create mode 100644 background_spectra/README.md create mode 100644 background_spectra/RemoveBottomTrackerLeptonicInteractions.py create mode 100644 background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_C.cfg create mode 100644 background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_P.cfg create mode 100644 background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_TC.cfg create mode 100644 background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_UC.cfg create mode 100644 background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_all.cfg create mode 100755 background_spectra/mimrec_bg_spectra.sh diff --git a/background_spectra/PlotBackground.cxx b/background_spectra/PlotBackground.cxx new file mode 100644 index 0000000..467b435 --- /dev/null +++ b/background_spectra/PlotBackground.cxx @@ -0,0 +1,156 @@ +void Plot(TString BG); +void PlotBackground(); + +void PlotBackground() { + + vector theBG = {"_all", "_P", "_TC", "_UC", "_C"}; + for (int i=0; iGet("c1"); + TH1D * h_had = (TH1D*)C->GetPrimitive("EnergySpectrum"); + + f = new TFile(TString::Format("LeptonicBackground.spectrum%s.root", BG.Data()).Data()); + C = (TCanvas*)f->Get("c1"); + TH1D * h_lep = (TH1D*)C->GetPrimitive("EnergySpectrum"); + + f = new TFile(TString::Format("PhotonicBackground.spectrum%s.root", BG.Data()).Data()); + C = (TCanvas*)f->Get("c1"); + TH1D * h_pho = (TH1D*)C->GetPrimitive("EnergySpectrum"); + + f = new TFile(TString::Format("TrappedHadronicBackground.spectrum%s.root", BG.Data()).Data()); + C = (TCanvas*)f->Get("c1"); + TH1D * h_thad = (TH1D*)C->GetPrimitive("EnergySpectrum"); + + f = new TFile(TString::Format("TrappedLeptonicBackground.spectrum%s.root", BG.Data()).Data()); + C = (TCanvas*)f->Get("c1"); + TH1D * h_tlep = (TH1D*)C->GetPrimitive("EnergySpectrum"); + + f = new TFile(TString::Format("HadronicBackgroundDecay.spectrum%s.root", BG.Data()).Data()); + C = (TCanvas*)f->Get("c1"); + TH1D * h_had_decay = (TH1D*)C->GetPrimitive("EnergySpectrum"); + + f = new TFile(TString::Format("TrappedHadronicBackgroundDecay.spectrum%s.root", BG.Data()).Data()); + C = (TCanvas*)f->Get("c1"); + TH1D * h_thad_decay = (TH1D*)C->GetPrimitive("EnergySpectrum"); + + + + TCanvas * C_tot = new TCanvas("C_tot","C_tot", 1181, 802); + C_tot->SetLeftMargin(0.15); + C_tot->SetBottomMargin(0.15); + + h_had->SetFillStyle(0); + h_had->SetLineColor(kRed); + h_had->SetLineWidth(2); + h_had->SetTitle(""); + h_had->GetYaxis()->SetTitle("Flux (#gamma/keV/s)"); + h_had->GetXaxis()->SetRangeUser(10, 1e6); + h_had->GetYaxis()->SetTitleSize(0.06); + h_had->GetYaxis()->SetTitleOffset(1.0); + h_had->GetYaxis()->SetLabelSize(0.05); + h_had->GetXaxis()->SetTitleSize(0.06); + h_had->GetXaxis()->SetLabelSize(0.05); + h_had->GetXaxis()->SetTitleOffset(1.1); + + //Convert the x-axis to MeV instead of keV + //for (int i = 0; i < h_had->GetNBins(); i++) { + // h_had->Get + + + double T = 3600; //time in simulated seconds + double scale = 1.0/3600.; //conversion to event rate (per second) + + //Simulations were for 3600 seconds, so divide by time + h_had->Scale(scale); + //Multiply by 1000 to conver to /MeV + //h_had->Scale(1000.); + h_had->GetYaxis()->SetRangeUser(2e-6, 2); + h_had->Draw("hist"); + + h_lep->SetFillStyle(0); + h_lep->SetLineColor(kGreen+1); + h_lep->SetLineWidth(2); + h_lep->Scale(scale); + //h_lep->Scale(1000.); + h_lep->Draw("hist same"); + + h_pho->SetFillStyle(0); + h_pho->SetLineColor(kMagenta); + h_pho->SetLineWidth(2); + h_pho->Scale(scale); + //h_pho->Scale(1000.); + h_pho->Draw("hist same"); + + h_thad->SetFillStyle(0); + h_thad->SetLineColor(kBlue); + h_thad->SetLineWidth(2); + h_thad->Scale(scale); + //h_thad->Scale(1000.); + h_thad->Draw("hist same"); + + h_tlep->SetFillStyle(0); + h_tlep->SetLineColor(kOrange); + h_tlep->SetLineWidth(2); + h_tlep->Scale(scale); + //h_tlep->Scale(1000.); + h_tlep->Draw("hist same"); + + h_had_decay->SetFillStyle(0); + h_had_decay->SetLineColor(kRed+1); + h_had_decay->SetLineStyle(2); + h_had_decay->SetLineWidth(2); + h_had_decay->Scale(scale); + //h_pho->Scale(1000.); + h_had_decay->Draw("hist same"); + + h_thad_decay->SetFillStyle(0); + h_thad_decay->SetLineColor(kBlue+1); + h_thad_decay->SetLineStyle(2); + h_thad_decay->SetLineWidth(2); + h_thad_decay->Scale(scale); + //h_thad_decay->Scale(1000.); + h_thad_decay->Draw("hist same"); + + + TH1D * h_tot = (TH1D*)h_had->Clone("h_tot"); + h_tot->Add(h_lep); + h_tot->Add(h_pho); + h_tot->Add(h_thad); + h_tot->Add(h_tlep); + h_tot->Add(h_had_decay); + h_tot->Add(h_thad_decay); + h_tot->SetLineColor(kBlack); + h_tot->SetLineWidth(2); + h_tot->Draw("hist same"); + + C_tot->SetLogx(); + C_tot->SetLogy(); + gPad->RedrawAxis(); + + TLegend * leg = new TLegend(0.65, 0.59, 0.95, 0.95); + leg->AddEntry(h_had, "Hadrons", "l"); + leg->AddEntry(h_had_decay, "Hadron Activation", "l"); + leg->AddEntry(h_thad, "Trapped Hadrons", "l"); + leg->AddEntry(h_thad_decay, "Trapped Hadron Activation", "l"); + leg->AddEntry(h_lep, "Leptons", "l"); + leg->AddEntry(h_tlep, "Trapped Leptons", "l"); + leg->AddEntry(h_pho, "Photons", "l"); + leg->AddEntry(h_tot, "Total", "l"); + leg->Draw(); + + C_tot->SaveAs(TString::Format("bg_pixel%s.png", BG.Data()).Data() ); + C_tot->SaveAs(TString::Format("bg_pixel%s.pdf", BG.Data()).Data() ); + C_tot->SaveAs(TString::Format("bg_pixel%s.root", BG.Data()).Data() ); + + h_tot->SetName(TString::Format("totalBG%s", BG.Data() ).Data() ); + h_tot->SaveAs(TString::Format("totalBG_pixel%s.root", BG.Data()).Data() ); + +}; + diff --git a/background_spectra/README.md b/background_spectra/README.md new file mode 100644 index 0000000..fab1979 --- /dev/null +++ b/background_spectra/README.md @@ -0,0 +1,18 @@ +Various scripts and config files to obtain simulated background spectra from `.tra` files. + +`RemoveBottomTrackerLeptonicInteractions.py`: This should be called once after the background sims are run. Removes background component of trapped leptonic events that come in via the gap below the ACD. + +`mimrec_bg_spectra.sh`: Runs mimrec over tra files to produce root files with background spectra. Input/output directory, config files and detector geometry are all hardcoded and should be adjusted. This produces one root file per component (TrappedLeptonic, Photonic etc) and event type (Tracked Compton, Pair etc). The spectra are not normalized by exposure time yet! + +`PlotBackground.cxx`: Reads in the root files from the previous step to normalize and plot the spectra and calculate the total background rates (sum over all components). Again, input and output files and simulated time are hardcoded. Output: plots (png, pdf) of the reconstructed background spectrum for each component, root files with said spectra, and root files with just the total background histogram for each event type. Use the `hadd` macro to combine those into one file if desired. + +`mimrec_AMEGOX_PlotBkgSpectrum_all.cfg`: Config file, selecting both Compton and pair events. + +`mimrec_AMEGOX_PlotBkgSpectrum_C.cfg`: Config file, Compton only. + +`mimrec_AMEGOX_PlotBkgSpectrum_P.cfg`: Config file, Pair only. + +`mimrec_AMEGOX_PlotBkgSpectrum_TC.cfg`: Config file, tracked Compton only. + +`mimrec_AMEGOX_PlotBkgSpectrum_UC.cfg`: Config file, untracked Compton only. + diff --git a/background_spectra/RemoveBottomTrackerLeptonicInteractions.py b/background_spectra/RemoveBottomTrackerLeptonicInteractions.py new file mode 100644 index 0000000..bffffba --- /dev/null +++ b/background_spectra/RemoveBottomTrackerLeptonicInteractions.py @@ -0,0 +1,113 @@ +import gzip +import re +import os +import glob + +#trafile = gzip.open('TraFiles_100420/R1_Files/TrappedLeptonicBackground/TrappedLeptonicBackground.p2.inc30.id1.tra.gz', 'rb') +#newtrafile = gzip.open('TrappedLeptonicBackground_mod.p2.inc30.id1.tra.gz', 'wb') + +def RemoveEvents(filename, newtrafilename): + + trafile = gzip.open(filename, 'rb') + print('Reading in file ', filename) + + newtrafile = gzip.open(newtrafilename, 'wb') + + + #Write the first 7 lines of the tra file into the new condensed file + for x in range(7): + line = trafile.readline() + newtrafile.write(line) + + #Read the whole file, and append the event details to new_event. If the position is not consistent with the last tracker layer, save the event into the new trafile + while True: + line = trafile.readline() + if not line: + break + #Find the start of an event with the SE flag + if re.match('SE', line.decode('utf-8')): + new_event = [] + #append SE to be the first element in the new_event list + new_event.append(line) + + #Read the next line and see if it matches with a CO event (since these are the only ones in the TrappedLeptonic file other than unknowns) + line = trafile.readline() + if re.match('ET CO', line.decode('utf-8')): + new_event.append(line) + + + # line = trafile.readline() + # if re.match('ID 5349', line.decode('utf-8')): + # print('found ID 5349') + # new_event.append(line) + + #If it's a compton event, append the next 9 lines of the event details to the new_event list to get to the position info + for x in range(7): + line = trafile.readline() + new_event.append(line) + #Some events have the TQ flag which makes them one line longer, so we have to check for that + if re.match('TQ', line.decode('utf-8')): + for x in range(3): + line = trafile.readline() + new_event.append(line) + else: + for x in range(2): + line = trafile.readline() + new_event.append(line) + + + + #Read the CH line and see if it's consistent with the first event being in the bottom layer of the tracker + line = trafile.readline() + if re.match('CH 0 -?\d+\.\d+ -?\d+\.\d+ 0.75', line.decode('utf-')): + #print('Got a bad one!') + pass + + #If the event isn't consistent, then write it to the new tra file + else: + new_event.append(line) + line = trafile.readline() + while re.match('CH \d ', line.decode('utf-8')): + new_event.append(line) + line = trafile.readline() + #print(new_event) + for i in new_event: + newtrafile.write(i) + + #If you've reached the last event, copy over the final lines of the file to include the FT info + if re.match('EN', line.decode('utf-8')): + newtrafile.write(line) + while True: + line = trafile.readline() + newtrafile.write(line) + if not line: + break + + + + trafile.close() + newtrafile.close() + + return + +###########################################333 + + + + +#Change the path here! +#path = 'TraFiles_040520/R1_Files/TrappedLeptonicBackground/' +path = '/data/slag2/hfleisc1/amego_sims/simfiles/pixel/background/TrappedLeptonicBackground/' +path = '/data/slag2/hfleisc1/amego_sims/simfiles/base/background/TrappedLeptonicBackground/' +path = '/data/slag2/hfleisc1/amego_sims/simfiles/pixel/BG_above_0.01MeV/TrappedLeptonicBackground/' +#for filename in glob.glob(os.path.join(path, 'TrappedLeptonicBackground.p*.inc*.tra.gz')): +for filename in os.listdir(path): + if os.path.isfile(os.path.join(path, filename)): + if re.match('TrappedLeptonicBackground.p\d.inc\d+.id1.tra.gz', filename): + newtrafilename = filename.replace('TrappedLeptonicBackground','TrappedLeptonicBackground_old') + print (filename, newtrafilename) + os.rename( os.path.join(path, filename), os.path.join(path, newtrafilename)) + RemoveEvents(os.path.join(path, newtrafilename), os.path.join(path,filename)) + + + diff --git a/background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_C.cfg b/background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_C.cfg new file mode 100644 index 0000000..3ec782f --- /dev/null +++ b/background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_C.cfg @@ -0,0 +1,305 @@ + + 2 + 29911 + /data/slag2/ckierans/AMEGO/Geometry/AMEGO_Midex/AmegoBase.geo.setup + /net/slag2/ckierans/AMEGO/AMEGOX_SensitivityCalcs/BackgroundSims/TraFiles/R1_Files/PhotonicBackground/PhotonicBackground.tra.gz + + /net/slag2/ckierans/AMEGO/AMEGOX_SensitivityCalcs/BackgroundSims/TraFiles/R1_Files/PhotonicBackground/PhotonicBackground.tra.gz + /data/slag2/ComPair/Simulations/AMEGO_20170814/TraFiles/FarFieldPointSource_0.158MeV_Cos0.7.inc1.id1.tra + + + /data/slag2/ckierans/AMEGO/Geometry/AMEGO_Midex/AmegoBase.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + + + + 0 + 4 + 0 + 0.0001 + 5 + 0 + 0 + 1 + 20 + 2 + 2 + 0.5 + false + 2.5 + 0 + + + + + 1 + + + + + 2 + + 1 + 0 + 0 + + + 0 + 0 + 1 + + + 0 + 180 + + 40 + + -180 + 180 + + 80 + + 80 + 100 + + 40 + + 170 + 190 + + 40 + + -5 + 5 + + 50 + + -5 + 5 + + 50 + + 9.99 + 10.01 + + 1 + + + 0 + 0 + + 0 + + + 1 + 10 + MyAnimated.gif + + + 5.2 + 20 + + + 1500 + 128 + 2 + 1 + false + false + 1 + + + 9 + 1 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + 0 + 10000000 + + 0 + + + + 1 + 100 + + + 2 + 10 + + + 0 + 100 + + + 0 + 100 + + + 0 + 100 + + + 0 + 1000000 + + + 0 + 0 + + + 0 + 0 + + + 0 + 0 + + + 0 + 1000000 + + + 0 + 1000000 + + + 0 + 180 + + 180 + + 0 + 2147480000 + + + 0 + 2147480000 + + + -1000 + 2147483647 + + + 0 + 1 + + + 0 + 180 + + + 0 + 1000000 + + + 0 + 1 + ___NotDefined___ + ___NotDefined___ + 0 + + 0 + 0 + -1e+20 + + + + false + 1 + 0 + 0 + 184.56 + -5.78 + 0 + 0 + 100 + + 0 + 180 + + + 0 + 180 + + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + false + 0 + 0 + 10000 + 0 + 0 + 0 + 1000 + 1000 + + + DCalCSI + + + + 3 + 20 + $(MEGALIB)/resource/libraries/IsotopeLibrary_HomelandSecurity_Short.isotopes + 1 + + + false + + 0 + 0 + + + 0 + 180 + + + 0 + 0 + 100 + + 180 + 30 + + + true + + + 180 + 181 + 2000 + 90 + + + + 10 + + diff --git a/background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_P.cfg b/background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_P.cfg new file mode 100644 index 0000000..3f52055 --- /dev/null +++ b/background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_P.cfg @@ -0,0 +1,305 @@ + + 2 + 29911 + /data/slag2/ckierans/AMEGO/Geometry/AMEGO_Midex/AmegoBase.geo.setup + /net/slag2/ckierans/AMEGO/AMEGOX_SensitivityCalcs/BackgroundSims/TraFiles/R1_Files/PhotonicBackground/PhotonicBackground.tra.gz + + /net/slag2/ckierans/AMEGO/AMEGOX_SensitivityCalcs/BackgroundSims/TraFiles/R1_Files/PhotonicBackground/PhotonicBackground.tra.gz + /data/slag2/ComPair/Simulations/AMEGO_20170814/TraFiles/FarFieldPointSource_0.158MeV_Cos0.7.inc1.id1.tra + + + /data/slag2/ckierans/AMEGO/Geometry/AMEGO_Midex/AmegoBase.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + + + + 0 + 4 + 0 + 0.0001 + 5 + 0 + 0 + 1 + 20 + 2 + 2 + 0.5 + false + 2.5 + 0 + + + + + 1 + + + + + 2 + + 1 + 0 + 0 + + + 0 + 0 + 1 + + + 0 + 180 + + 40 + + -180 + 180 + + 80 + + 80 + 100 + + 40 + + 170 + 190 + + 40 + + -5 + 5 + + 50 + + -5 + 5 + + 50 + + 9.99 + 10.01 + + 1 + + + 0 + 0 + + 0 + + + 1 + 10 + MyAnimated.gif + + + 5.2 + 20 + + + 1500 + 128 + 2 + 1 + false + false + 1 + + + 9 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + + 0 + 10000000 + + 0 + + + + 1 + 100 + + + 2 + 10 + + + 0 + 100 + + + 0 + 100 + + + 0 + 100 + + + 0 + 1000000 + + + 0 + 0 + + + 0 + 0 + + + 0 + 0 + + + 0 + 1000000 + + + 0 + 1000000 + + + 0 + 180 + + 180 + + 0 + 2147480000 + + + 0 + 2147480000 + + + -1000 + 2147483647 + + + 0 + 1 + + + 0 + 180 + + + 0 + 1000000 + + + 0 + 1 + ___NotDefined___ + ___NotDefined___ + 0 + + 0 + 0 + -1e+20 + + + + false + 1 + 0 + 0 + 184.56 + -5.78 + 0 + 0 + 100 + + 0 + 180 + + + 0 + 180 + + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + false + 0 + 0 + 10000 + 0 + 0 + 0 + 1000 + 1000 + + + DCalCSI + + + + 3 + 20 + $(MEGALIB)/resource/libraries/IsotopeLibrary_HomelandSecurity_Short.isotopes + 1 + + + false + + 0 + 0 + + + 0 + 180 + + + 0 + 0 + 100 + + 180 + 30 + + + true + + + 180 + 181 + 2000 + 90 + + + + 10 + + diff --git a/background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_TC.cfg b/background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_TC.cfg new file mode 100644 index 0000000..97c8e4a --- /dev/null +++ b/background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_TC.cfg @@ -0,0 +1,305 @@ + + 2 + 29911 + /data/slag2/ckierans/AMEGO/Geometry/AMEGO_Midex/AmegoBase.geo.setup + /net/slag2/ckierans/AMEGO/AMEGOX_SensitivityCalcs/BackgroundSims/TraFiles/R1_Files/PhotonicBackground/PhotonicBackground.tra.gz + + /net/slag2/ckierans/AMEGO/AMEGOX_SensitivityCalcs/BackgroundSims/TraFiles/R1_Files/PhotonicBackground/PhotonicBackground.tra.gz + /data/slag2/ComPair/Simulations/AMEGO_20170814/TraFiles/FarFieldPointSource_0.158MeV_Cos0.7.inc1.id1.tra + + + /data/slag2/ckierans/AMEGO/Geometry/AMEGO_Midex/AmegoBase.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + + + + 0 + 4 + 0 + 0.0001 + 5 + 0 + 0 + 1 + 20 + 2 + 2 + 0.5 + false + 2.5 + 0 + + + + + 1 + + + + + 2 + + 1 + 0 + 0 + + + 0 + 0 + 1 + + + 0 + 180 + + 40 + + -180 + 180 + + 80 + + 80 + 100 + + 40 + + 170 + 190 + + 40 + + -5 + 5 + + 50 + + -5 + 5 + + 50 + + 9.99 + 10.01 + + 1 + + + 0 + 0 + + 0 + + + 1 + 10 + MyAnimated.gif + + + 5.2 + 20 + + + 1500 + 128 + 2 + 1 + false + false + 1 + + + 9 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + 0 + 10000000 + + 0 + + + + 1 + 100 + + + 2 + 10 + + + 0 + 100 + + + 0 + 100 + + + 0 + 100 + + + 0 + 1000000 + + + 0 + 0 + + + 0 + 0 + + + 0 + 0 + + + 0 + 1000000 + + + 0 + 1000000 + + + 0 + 180 + + 180 + + 0 + 2147480000 + + + 0 + 2147480000 + + + -1000 + 2147483647 + + + 0 + 1 + + + 0 + 180 + + + 0 + 1000000 + + + 0 + 1 + ___NotDefined___ + ___NotDefined___ + 0 + + 0 + 0 + -1e+20 + + + + false + 1 + 0 + 0 + 184.56 + -5.78 + 0 + 0 + 100 + + 0 + 180 + + + 0 + 180 + + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + false + 0 + 0 + 10000 + 0 + 0 + 0 + 1000 + 1000 + + + DCalCSI + + + + 3 + 20 + $(MEGALIB)/resource/libraries/IsotopeLibrary_HomelandSecurity_Short.isotopes + 1 + + + false + + 0 + 0 + + + 0 + 180 + + + 0 + 0 + 100 + + 180 + 30 + + + true + + + 180 + 181 + 2000 + 90 + + + + 10 + + diff --git a/background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_UC.cfg b/background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_UC.cfg new file mode 100644 index 0000000..8b8153d --- /dev/null +++ b/background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_UC.cfg @@ -0,0 +1,305 @@ + + 2 + 29911 + /data/slag2/ckierans/AMEGO/Geometry/AMEGO_Midex/AmegoBase.geo.setup + /net/slag2/ckierans/AMEGO/AMEGOX_SensitivityCalcs/BackgroundSims/TraFiles/R1_Files/PhotonicBackground/PhotonicBackground.tra.gz + + /net/slag2/ckierans/AMEGO/AMEGOX_SensitivityCalcs/BackgroundSims/TraFiles/R1_Files/PhotonicBackground/PhotonicBackground.tra.gz + /data/slag2/ComPair/Simulations/AMEGO_20170814/TraFiles/FarFieldPointSource_0.158MeV_Cos0.7.inc1.id1.tra + + + /data/slag2/ckierans/AMEGO/Geometry/AMEGO_Midex/AmegoBase.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + + + + 0 + 4 + 0 + 0.0001 + 5 + 0 + 0 + 1 + 20 + 2 + 2 + 0.5 + false + 2.5 + 0 + + + + + 1 + + + + + 2 + + 1 + 0 + 0 + + + 0 + 0 + 1 + + + 0 + 180 + + 40 + + -180 + 180 + + 80 + + 80 + 100 + + 40 + + 170 + 190 + + 40 + + -5 + 5 + + 50 + + -5 + 5 + + 50 + + 9.99 + 10.01 + + 1 + + + 0 + 0 + + 0 + + + 1 + 10 + MyAnimated.gif + + + 5.2 + 20 + + + 1500 + 128 + 2 + 1 + false + false + 1 + + + 9 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + 0 + 10000000 + + 0 + + + + 1 + 100 + + + 2 + 10 + + + 0 + 100 + + + 0 + 100 + + + 0 + 100 + + + 0 + 1000000 + + + 0 + 0 + + + 0 + 0 + + + 0 + 0 + + + 0 + 1000000 + + + 0 + 1000000 + + + 0 + 180 + + 180 + + 0 + 2147480000 + + + 0 + 2147480000 + + + -1000 + 2147483647 + + + 0 + 1 + + + 0 + 180 + + + 0 + 1000000 + + + 0 + 1 + ___NotDefined___ + ___NotDefined___ + 0 + + 0 + 0 + -1e+20 + + + + false + 1 + 0 + 0 + 184.56 + -5.78 + 0 + 0 + 100 + + 0 + 180 + + + 0 + 180 + + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + false + 0 + 0 + 10000 + 0 + 0 + 0 + 1000 + 1000 + + + DCalCSI + + + + 3 + 20 + $(MEGALIB)/resource/libraries/IsotopeLibrary_HomelandSecurity_Short.isotopes + 1 + + + false + + 0 + 0 + + + 0 + 180 + + + 0 + 0 + 100 + + 180 + 30 + + + true + + + 180 + 181 + 2000 + 90 + + + + 10 + + diff --git a/background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_all.cfg b/background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_all.cfg new file mode 100644 index 0000000..837935b --- /dev/null +++ b/background_spectra/mimrec_AMEGOX_PlotBkgSpectrum_all.cfg @@ -0,0 +1,305 @@ + + 2 + 29911 + /data/slag2/ckierans/AMEGO/Geometry/AMEGO_Midex/AmegoBase.geo.setup + /net/slag2/ckierans/AMEGO/AMEGOX_SensitivityCalcs/BackgroundSims/TraFiles/R1_Files/PhotonicBackground/PhotonicBackground.tra.gz + + /net/slag2/ckierans/AMEGO/AMEGOX_SensitivityCalcs/BackgroundSims/TraFiles/R1_Files/PhotonicBackground/PhotonicBackground.tra.gz + /data/slag2/ComPair/Simulations/AMEGO_20170814/TraFiles/FarFieldPointSource_0.158MeV_Cos0.7.inc1.id1.tra + + + /data/slag2/ckierans/AMEGO/Geometry/AMEGO_Midex/AmegoBase.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + $(MEGALIB)/resource/examples/geomega/special/Dummy.geo.setup + + + + 0 + 4 + 0 + 0.0001 + 5 + 0 + 0 + 1 + 20 + 2 + 2 + 0.5 + false + 2.5 + 0 + + + + + 1 + + + + + 2 + + 1 + 0 + 0 + + + 0 + 0 + 1 + + + 0 + 180 + + 40 + + -180 + 180 + + 80 + + 80 + 100 + + 40 + + 170 + 190 + + 40 + + -5 + 5 + + 50 + + -5 + 5 + + 50 + + 9.99 + 10.01 + + 1 + + + 0 + 0 + + 0 + + + 1 + 10 + MyAnimated.gif + + + 5.2 + 20 + + + 1500 + 128 + 2 + 1 + false + false + 1 + + + 9 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + + 0 + 10000000 + + 0 + + + + 1 + 100 + + + 2 + 10 + + + 0 + 100 + + + 0 + 100 + + + 0 + 100 + + + 0 + 1000000 + + + 0 + 0 + + + 0 + 0 + + + 0 + 0 + + + 0 + 1000000 + + + 0 + 1000000 + + + 0 + 180 + + 180 + + 0 + 2147480000 + + + 0 + 2147480000 + + + -1000 + 2147483647 + + + 0 + 1 + + + 0 + 180 + + + 0 + 1000000 + + + 0 + 1 + ___NotDefined___ + ___NotDefined___ + 0 + + 0 + 0 + -1e+20 + + + + false + 1 + 0 + 0 + 184.56 + -5.78 + 0 + 0 + 100 + + 0 + 180 + + + 0 + 180 + + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + false + 0 + 0 + 10000 + 0 + 0 + 0 + 1000 + 1000 + + + DCalCSI + + + + 3 + 20 + $(MEGALIB)/resource/libraries/IsotopeLibrary_HomelandSecurity_Short.isotopes + 1 + + + false + + 0 + 0 + + + 0 + 180 + + + 0 + 0 + 100 + + 180 + 30 + + + true + + + 180 + 181 + 2000 + 90 + + + + 10 + + diff --git a/background_spectra/mimrec_bg_spectra.sh b/background_spectra/mimrec_bg_spectra.sh new file mode 100755 index 0000000..f72fa57 --- /dev/null +++ b/background_spectra/mimrec_bg_spectra.sh @@ -0,0 +1,28 @@ +GEO=/Home/eud/hfleisc1/amego_software/ComPair/Geometry/AMEGO_Midex/TradeStudies/Tracker/BasePixelTracker/AmegoBase.geo.setup +#GEO=/Home/eud/hfleisc1/amego_software/ComPair/Geometry/AMEGO_Midex/AmegoBase.geo.setup + +INDIR=$SIMDIR/pixel/BG_above_0.01MeV/ +CWDIR=${PWD} + +ODIR=${CWDIR}/pixel_bg/ +mkdir -p ${ODIR} + +cd $INDIR + +for BG in HadronicBackground HadronicBackgroundDecay TrappedHadronicBackground TrappedHadronicBackgroundDecay LeptonicBackground PhotonicBackground TrappedLeptonicBackground +do + INFILE=${BG}/${BG}.p.tra.gz + if [[ ! -e $INFILE ]] + then + INFILE=${BG}/${BG}.p1.tra.gz + fi + ls $INFILE + ln -s $INFILE . + for TYPE in all P TC UC C + do + CFG=${CWDIR}/mimrec_AMEGOX_PlotBkgSpectrum_${TYPE}.cfg + mimrec -f `basename $INFILE` -g $GEO -c $CFG -s -o ${ODIR}/${BG}.spectrum_${TYPE}.root -n >& ${ODIR}/logSpectrum_${BG}_${TYPE}.txt + done +done + +cd $CWDIR From e6fa1749bee81edcb7d6330bc1d2a32f75439718 Mon Sep 17 00:00:00 2001 From: Henrike Fleischhack Date: Thu, 22 Apr 2021 13:40:29 -0400 Subject: [PATCH 4/5] one more script --- background_spectra/PlotTotalBG.C | 101 +++++++++++++++++++++++++++++++ background_spectra/README.md | 2 + 2 files changed, 103 insertions(+) create mode 100644 background_spectra/PlotTotalBG.C diff --git a/background_spectra/PlotTotalBG.C b/background_spectra/PlotTotalBG.C new file mode 100644 index 0000000..b3dbcf9 --- /dev/null +++ b/background_spectra/PlotTotalBG.C @@ -0,0 +1,101 @@ +{ + TCanvas * c = new TCanvas("c", "c", 1000, 600); + + TFile * theFile = new TFile( "pixel_rightOrbit/totalBG_pixel.root"); + //TFile * theFile = new TFile( "base_wrongOrbit/totalBG_DSSD.root"); + theFile->cd(); + + TH1D* totalBG_all = (TH1D*)theFile->Get("totalBG_all"); + TH1D* totalBG_P = (TH1D*)theFile->Get("totalBG_P"); + TH1D* totalBG_UC = (TH1D*)theFile->Get("totalBG_UC"); + TH1D* totalBG_TC = (TH1D*)theFile->Get("totalBG_TC"); + + totalBG_all->Rebin(10); + totalBG_all->Scale(0.1); + totalBG_P->Rebin(10); + totalBG_P->Scale(0.1); + totalBG_TC->Rebin(10); + totalBG_TC->Scale(0.1); + totalBG_UC->Rebin(10); + totalBG_UC->Scale(0.1); + + totalBG_all->GetXaxis()->SetRangeUser(50, 1e6); + + totalBG_all->SetLineColor(kGray); + totalBG_all->SetLineWidth(3); + totalBG_all->DrawCopy("hist l"); + totalBG_P->SetLineColor(kRed); + totalBG_P->SetLineWidth(3); + totalBG_P->DrawCopy("hist l same "); + totalBG_TC->SetLineWidth(3); + totalBG_UC->SetLineWidth(3); + totalBG_UC->SetLineColor(kBlue); + totalBG_TC->SetLineColor(kGreen); + totalBG_TC->DrawCopy("hist l same "); + totalBG_UC->DrawCopy("hist l same "); + c->SetLogy(); + c->SetLogx(); + + c->SetLeftMargin(0.15); + c->SetRightMargin(0.05); + c->SetBottomMargin(0.15); + c->SetTopMargin(0.05); + + TLegend * legend = new TLegend(0.65,0.7,0.95,0.95); + //legend->SetHeader("The Legend Title","C"); // option "C" allows to center the header + legend->AddEntry(totalBG_all ,"Total BG","l"); + legend->AddEntry(totalBG_P ,"Fake pair events","l"); + legend->AddEntry(totalBG_TC ,"Fake tracked Compton","l"); + legend->AddEntry(totalBG_UC ,"Fake untracked Compton","l"); + legend->Draw(); + + + //TFile * theFile = new TFile( "pixel_rightOrbit/totalBG_pixel.root"); + TFile * theFile2 = new TFile( "pixel_EHCut/totalBG_pixel_EHCut.root"); + theFile2->cd(); + + theFile2->ls(); + + TH1D* totalBG_all_CUT = (TH1D*)theFile2->Get("totalBG_all"); + TH1D* totalBG_P_CUT = (TH1D*)theFile2->Get("totalBG_P"); + TH1D* totalBG_UC_CUT = (TH1D*)theFile2->Get("totalBG_UC"); + TH1D* totalBG_TC_CUT = (TH1D*)theFile2->Get("totalBG_TC"); + + totalBG_all_CUT->Rebin(10); + totalBG_all_CUT->Scale(0.1); + totalBG_P_CUT->Rebin(10); + totalBG_P_CUT->Scale(0.1); + totalBG_TC_CUT->Rebin(10); + totalBG_TC_CUT->Scale(0.1); + totalBG_UC_CUT->Rebin(10); + totalBG_UC_CUT->Scale(0.1); + + + totalBG_all_CUT->SetLineStyle(7); + totalBG_P_CUT->SetLineStyle(7); + totalBG_UC_CUT->SetLineStyle(7); + totalBG_TC_CUT->SetLineStyle(7); + + totalBG_all_CUT->SetLineColor(kGray); + totalBG_all_CUT->SetLineWidth(3); + totalBG_all_CUT->DrawCopy("hist l same"); + totalBG_P_CUT->SetLineColor(kRed); + totalBG_P_CUT->SetLineWidth(3); + totalBG_P_CUT->DrawCopy("hist l same "); + totalBG_TC_CUT->SetLineWidth(3); + totalBG_UC_CUT->SetLineWidth(3); + totalBG_UC_CUT->SetLineColor(kBlue); + totalBG_TC_CUT->SetLineColor(kGreen); + totalBG_TC_CUT->DrawCopy("hist l same "); + totalBG_UC_CUT->DrawCopy("hist l same "); + + + legend->AddEntry(totalBG_all_CUT ,"after horizon cut","l"); +// legend->AddEntry(totalBG_P_CUT ,"Fake pair events","l"); +// legend->AddEntry(totalBG_TC_CUT ,"Fake tracked Compton","l"); +// legend->AddEntry(totalBG_UC_CUT ,"Fake untracked Compton","l"); +// legend->Draw(); + + c->SaveAs("AMEGO-X-Pixel-BG_EHCut.png"); + +} diff --git a/background_spectra/README.md b/background_spectra/README.md index fab1979..4f8807f 100644 --- a/background_spectra/README.md +++ b/background_spectra/README.md @@ -6,6 +6,8 @@ Various scripts and config files to obtain simulated background spectra from `.t `PlotBackground.cxx`: Reads in the root files from the previous step to normalize and plot the spectra and calculate the total background rates (sum over all components). Again, input and output files and simulated time are hardcoded. Output: plots (png, pdf) of the reconstructed background spectrum for each component, root files with said spectra, and root files with just the total background histogram for each event type. Use the `hadd` macro to combine those into one file if desired. +`PlotTotalBG.C`: Root script to plot total Untracked Compton/Tracked Compton/Pair background spectra (summed over all components), using the output from the previous script. + `mimrec_AMEGOX_PlotBkgSpectrum_all.cfg`: Config file, selecting both Compton and pair events. `mimrec_AMEGOX_PlotBkgSpectrum_C.cfg`: Config file, Compton only. From c8d76fa42ab166e5b15d62536edf28c325788916 Mon Sep 17 00:00:00 2001 From: Henrike Fleischhack Date: Thu, 22 Apr 2021 17:06:36 -0400 Subject: [PATCH 5/5] Set simdir --- background_spectra/mimrec_bg_spectra.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/background_spectra/mimrec_bg_spectra.sh b/background_spectra/mimrec_bg_spectra.sh index f72fa57..2670ad0 100755 --- a/background_spectra/mimrec_bg_spectra.sh +++ b/background_spectra/mimrec_bg_spectra.sh @@ -1,6 +1,8 @@ GEO=/Home/eud/hfleisc1/amego_software/ComPair/Geometry/AMEGO_Midex/TradeStudies/Tracker/BasePixelTracker/AmegoBase.geo.setup #GEO=/Home/eud/hfleisc1/amego_software/ComPair/Geometry/AMEGO_Midex/AmegoBase.geo.setup +SIMDIR=/data/slag2/hfleisc1/amego_sims/simfiles/ + INDIR=$SIMDIR/pixel/BG_above_0.01MeV/ CWDIR=${PWD}