```markdown # TPC Response Simulator This script varies parameters in `TpcResponseSimulator.y2022.C` and outputs both the TPC simulation results and DAQ results. Use it to interpolate the optimum simulation parameters, and run it again to confirm if the simulation and DAQ results align. To get started: - Copy the directory `~ctsang/macros/daq_TPC23_tuneupProcedure/` to your local directory. - Navigate into that directory and follow the instructions below. ## Usage **0. (Optional) Update the Scripts** Yuri may have updated his analysis script for future years. If necessary, copy the following files from Yuri and place them in the `scripts/` directory: - `dEdxFit.C` - `FitTpcT.C` - `dEdx.C` You also need the following files, but avoid updating them unless absolutely necessary due to modifications made on Yuri's code for compatibility: - `DrawList.C` - Copy and paste lines 376-381 of the included `DrawList.C` to the appropriate place in the updated `DrawList.C`. The `std::cout` format must match exactly for the script to read the average height of histograms. - `FitPDraw.C` - Add the line `gROOT->FindObject("c1")->SaveAs("FitPDraw.png");` at the end to save the PNGs. - `TpcT.C` - Technically no modifications are needed. However, if you have many MuDst files, it may run indefinitely. It's recommended to set limits on the number of files to read, e.g., add `if(NFiles > 50) break;` in the while loop that reads files. **1. Install Snakemake** Follow the instructions at [Snakemake Documentation](https://snakemake.readthedocs.io/en/stable/getting_started/installation.html) for installation. Installation via Conda/mamba is highly recommended. **2. Install Pandas** Install pandas using `pip install pandas`. **3. Modify adc file location Edit `xml/daq_adc2023.xml` to point it to the daq files that you want to study. Modify the bfc chain if needed. Inspect the chain options in all xml files in that directory **4. Modify Parameter List** Edit the list of parameters to run in `parameter.list`. Refer to the meaning of each parameter by opening `scripts/TpcResponseSimulatorTemplate.y2022.C`. Upon execution, a find and replace will be performed on parameters wrapped in brackets, e.g., ``. This will be your initial guess on parameter values. You will refine it in later steps so it does not need to be precise. An educated guess is enough. **5. Run the Script** Execute the script by entering `$>snakemake -j 7`. It will submit jobs to the Condor queue. **6. Compare Simulation with DAQ** Upon completion, compare the simulation with the DAQ using plots in the `pngs/` directory. Pay attention to `pngs/SummarizeParameters.txt`, which lists the simulation parameters and the aggregated output values from simulation and DAQ. Use this information to interpolate the next parameter values for testing. **7. Append Interpolateded Values** Append the estimated optimal value from step 5 to `parameter.list`. No need to remove old parameters. Snakemake will only execute jobs that haven't been done. **8. Repeat** Repeat steps 5-7 until you are satisfied with the agreement. ## Common Questions ### Q: What if I want to vary other parameters from TpcResponseSimulator? A: Modify `scripts/TpcResponseSimulatorTemplate.y2022.C` by placing the parameter name wrapped in angular brackets `<>` in the appropriate place. Then, add that name to `parameter.list` as a new column. ### Q: What if I want the script to generate more output? A: This is more complicated. You need to write a script that accepts output from DAQ and simulation, then create a Snakemake rule that runs your script, and modify the rule "getParameters" to print out results from your script onto `pngs/SummarizeParameters.txt`. ### Q: What if I want to save all the results of DrawList.C as a webpage? A: Run `$>snakemake -j 7 --config GUI=True` instead. Follow the instructions provided by Yuri for saving as webpages. Close all canvases when done saving. Press `.q` and Enter on your terminal until Snakemake informs you explicitly that all jobs are done. ```