Gain calibration with cosmic rays
- How it works
- Step 0 : Before start
Make sure `python3` exists and is executable, you can use `python3 --version` to test. And type `pip install colorama` to install missing required packages.(Other packages are basic and should be ready in most environments. If some packages are missing, just install)
And then, run `python3 /work/halld/home/zhikun/codeRelease/runEvio/main.py -h` to view help messages.
If you don't want to type so long, you can add an alias to your `.bashrc` or `.tcshrc`
For example, for `Bash`, add the following line to `.bashrc`
```bash alias runEvio='python3 /work/halld/home/zhikun/codeRelease/runEvio/main.py' ```
and then `source .bashrc`
In the following part, we use `runEvio` for short.
- Step 1 : Python script - Initialize environment
Create an empty folder, and then enter that folder. Type
```bash runEvio -I ```
to initialize environment.
The most important file is `parameters.py`. A template is as follows:
```python
- parameters for running the evio files
- If not neccessary, DO NOT MODIFY!
inputDir = "./evioFiles/" outputDir = "./outputRootFiles/"
- If not neccessary, DO NOT MODIFY!
- type the command you want to run herem do not include the files, you can add other parameters
runCommand = "hd_root -PPLUGINS=cosmicRayTestEvio " fileType = ".evio" #can be changed to ".hddm" or others.
runId = []
- High Voltage Configuration :
- ****************** Attention!!! *****************
hvTemplateFile = 'temp.snap' # please input your current HV config File!
- ****************** Attention!!! *****************
- ECAL:hv:20:-6:v0set 1 1038.047
- Format : ECAL:hv:{X}:{Y}:{itemToConfig}{value}
- No space between {itemToConfig} and {value}
itemToConfig = "v0set 1 " # please include the blank in between inside {itemToConfig} fitResDir = "./DigitHits/res.txt"
- ADC Countes = A * ( hv ) ^ alpha
- Here A is canceled out and not needed
aimADC = 10 alpha = 8 hvCap = 1050 hvBot = 950
- Set config for each channel. If you use detailed settings, please set the following parameters, and run -generateSettings command first. The setting file will be based on the universal settings above.
- And you can modify this file.
- If you use the same settings for all channels, please set the following parameters to None.
- If you use settings for each channel, the settings above for universal settings will be ignored. You can only use part of these settings.
aimADCSettings = None alphaSettings = None hvCapSettings = None hvBotSettings = None
- aimADCSettings = "aimADCSettings.txt"
- alphaSettings = "alphaSettings.txt"
- hvCapSettings = "hvCapSettings.txt"
- hvBotSettings = "hvBotSettings.txt"
- *********** Set specifc Item ***********
- itemSettings = "tripSettings.txt"
itemSettings = None
itemValue = 1
- itemValue = None
```
- Step 2: Process files by `runEvio -run`
If you want to run the `.evio` or `.hddm` files, first link the files that need to be processed to `inputDir`, and type `runEvio -run`. The command is according to `runCommand`. It will process all the files of `fileType`.
- Step 3: Doing fitting using `cosmicExtraction.cpp`
Please be sure to modify the variables defined at the beginning of the file. After running this script, you will find a lot of plots saved in current directory, which are convenient to glance and check. The fitting result will be saved as **`res.txt`**, from which the mean value of the fitting are taken and used in future steps.
- Step 3.5: Use `meanVisualize.cpp` to glance the mean distribution
- Step 4: Generate new HV configure file by `runEvio -C`
This will use the uniform settings of `aimADC`, `alpha`, `hvBot`, and `hvCap`. If you want to set different values for each channel, then enable `aimADCSettings` or others(depending on which variable you want to control, you can enable only 1 or all of them).
If you want to enable this feature, then choose the variables that you want to control and run `runEvio -generateSettings` or `runEvio -G` to generate template setting files.
Examples of setting files are as follows:
```bash
- index column row hvBot column(-20 ~ 20) row(-20 ~ 20)
0 39 39 800.00 20 20 1 39 38 800.00 20 19 2 39 37 800.00 20 18 3 39 36 800.00 20 17 ```
- *Please ONLY modify the values of the forth column***
**ATTENTION: Possible bug - Make sure` hvBot` is smaller than `hvCap`**
Hint: Actually this scripts can also be used to config $\pi^0$ calibration. What we need is simply the result file of same format:
```c++ // index column row mean error sigma chi2/ndf width
0 39 39 7.740 1.739 0.453 17.673 7.740
```
Required components include **index**, **column**, **row** and **mean**. The other components are arbitrary. The order of those arguments is not important. But **you need to make sure that the title of items are listed in the first line of the file as above.** For $\pi^0$ calibration, you can set `aimADCCounts` to $\frac{0.135}{8}*3200=54 ~~\mathrm{ADC counts}$ or another specific proper value.
- Set Other items by modifying `itemToConfig`
Run `runEvio -setHVitem` or `runEvio -S` to uniformly set all `itemToConfig`. If want to set different values for each channel, enable `itemSettings`, generate template file by `runEvio -G`, and modify values for each channel. Make sure the first 4 columns are `index, column, row, value` respectively. You can always add extra information for 5th column and later. Make sure $$ \mathrm{index} = 40 \times(39 - \mathrm{column}) + 39 - \mathrm{row} $$ In other words, index are as follows
<img src="./cosmic_analysis_scripts.assets/detector_view_col_arrow_index.svg" alt="detector_view_col_arrow_index" style="zoom:400%;" />
To compute column and row from index: $$ \mathrm{column} = 39 - \mathrm{index} ~ \%~ 40 \\ \mathrm{row} = 39 - \mathrm{index} ~ //~ 40 ~(\mathrm{Integer ~ Division}) $$
- Plugins
I temporarily name it `cosmicRayTestEvio`. In this plugin, we have several source files and header files including:
| Header File Name | What are included | User Modify Part |
| :------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: |
| `JEventProcessor_cosmicRayTestEvio.h` | namespace cutsConstants
namespace globalVariables(All histograms included, and some array to record information),
and other common templates of plugins | namespace cutsConstants |
| `JEventProcessor_cosmicRayTestEvio.cc` | common templates of plugins | jerror_t JEventProcessor_cosmicRayTestEvio::evnt
**if(addCuts){ .... }** |
| `namespaceFunction.h` | | |
- Python Scripts Details
Hello, welcome to use this scrip. This is a script developed by Zhikun Xi, an undergraduate from Wuhan University, at the end of 2024 and beginning of 2025. This is a python3 based scripts. It is to run all the `.evio` (or whatever kinds, just modify the parameters in `parameters.py`) file with certain plugins and save the root file to a certain folder. And you can then use `hadd allRuns.root *root` to combine all the files for further analysis.
Suggesstions: You should make a new folder and run this command again in order to keep you woking space clean and managable. If you insist not creating a new folder, please backup all the data before getting started.
- Most Important Thing: Check the parameters in `parameters.py`**
To run the script, you should install `colorama` first(pip install colorama). Then, go to an empty folder, and type `/w/halld-scshelf2101/home/zhikun/codeRelease/runEvio/main.py -init ` Then check the file `parameter.py`, put all the files that you want to run in the `inputDir`, then run. After that you will see the root file in `outputDir`
For help, use `-h` option.
- Quick View For All
Every File is in charge of a specific kind of `Action`:
| File | Action | Usage |
| :-------------------------------: | :---------------------: | :----------------------------------------------------------: |
| main.py | -h | Define the basic procedure, and accept the command, the most important skeleton |
| subModule/setupEnvironment.py | -init
-I | Initialize the environments. Specifically, to copy some pre-defined template and create some directories |
| submodule/import_parameters | | Import all the parameters in `parameters.py`. If the working directory doesn't have a `parameters.py` (when the directory has not been initialized yet), use `parameters.py` template located at `/w/halld-scshelf2101/home/zhikun/codeRelease/runEvio/parameters.py`. |
| subModule/runEvioFiles.py | -run
-R | To run all the `.evio` files or `.hddm` files in a command and see all the results |
| subModule/hvConfig.py | -hvConfig
-C | Used for High Voltage Configuration. Pleased Check the parameters in `parameters.py` |
| subModule/generateSettingFiles.py | -generateSettings
-G | |
- Details For Each File:
This is the detailed information about what are done in the scripts. You don't have to read this part unless you want to further understand and develop the script.
- Main.py
This file is defining the action argument that we want to accept. Please look up the usage of `add_argument()`.
- setUpEnvironment.py
Here we have a function `checkInitializationStatus()` called in `main.py`. If this folder has been initialized, then check missing part. If not, initialize.
- runEvioFiles.py
Here we have a function `runAction()` called in `main.py`. But first we need to call `checkInitializationStatus()` to check initialization status. To run this action please first link or copy all the files that you want to run to `inputDir`
- hvConfig.py
Here we have a function `hvConfigureAction()` called in `main.py`. Some functions' details are as follows
| Function | Usage | Return | | :-------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | | `hvConfigureAction()` | A plugin that can be called by `main.py`. It's used to catch any error and print the message. | No return | | `findTemplate():` | Read the current hv configuration file. If found, nothing happens. If not, throw error and exit. | No return | | `calculateVoltage()` | Calculate the voltage of a certain channel. | Return the correcet value of hv according to the input parameters. | | `readResTable()` | Read the the current hv configuration file, and convert it to a dictionary to accelerate procedure. Key is generated by index(in column), and values are the information including `index,column,row,mean` | The dictionaty including the information we need for hv configuration. |
- Root Scripts Details
- cosmicExtraction.cpp