Commit c3950450 authored by Maximilian Caspar's avatar Maximilian Caspar
Browse files

now you can give your allpix-squared/lib path in LD_LIBRARY_PATH + CRY time...

now you can give your allpix-squared/lib path in LD_LIBRARY_PATH + CRY time now comes from .root (thanks Simon) + documentation
parent 8dfb3c06
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -2,13 +2,13 @@
This example illustrates how the *depositionCosmics* module is used to model the flux of cosmic muons in Allpix Squared. Python analysis code is included to calculate the flux through the detector from the *MCParticle* objects

## Usage
First of all, change into the example directory. Because the time output of the CRY simulation code needs to be known for the analysis, we store the log in a *.txt* file:
First of all, change into the example directory. Run the simulation example from here:
```bash
allpix -c cosmic_flux.conf >> cosmic_flux_log.txt
allpix -c cosmic_flux.conf
```
To analyse the tracks of the *MCParticles*, issue
```bash
python analysis/analysis.py -l PATH_TO_ALLPIX_INSTALL/lib/libAllpixObjects.so
```
The library flag is required when your Allpix installation is not in a standard path.
The library flag is only required when your *allpix-squared/lib* path is not in *LD_LIBRARY_PATH*.
Notice that the analysis script relies on the python modules *uncertainties*, *tqdm*, *matplotlib* and *numpy.*
+6 −4
Original line number Diff line number Diff line
from track import Track
from tqdm import tqdm
from simulatedTime import SimulatedTime
from histogram import Histogram
import argparse
import os
@@ -24,8 +23,8 @@ if args.l is not None: # Try to find Allpix Library
else:  # Look in LD_LIBRARY_PATH
    libraryPaths = os.environ['LD_LIBRARY_PATH'].split(':')
    for p in libraryPaths:
        if p.endswith("lib/libAllpixObjects.so"):
            lib_file_name = p
        if path.isfile(path.join(p, "libAllpixObjects.so")):
            lib_file_name = path.join(p, "libAllpixObjects.so")
            break

if (not os.path.isfile(lib_file_name)):
@@ -42,7 +41,10 @@ McParticle = rootFile.Get('MCParticle')

def getTracks():
    "Load tracks from the ROOT file"
    time = SimulatedTime("cosmic_flux_log.txt").time

    # time is given in ns
    time = float(
        str(rootFile.config.DepositionCosmics.total_time_simulated)) / 1e9
    tracks = []

    for i in tqdm(range(0, McParticle.GetEntries())):
+0 −30
Original line number Diff line number Diff line
import numpy as np
from parse import compile


class SimulatedTime(object):
    def __init__(self, logFile):
        f = open(logFile, 'r')
        lines = f.readlines()
        f.close()

        parser = compile(
            "|{}|  (STATUS) [F:DepositionCosmics] Total simulated time in CRY: {:g}{}")

        lines = [parser.parse(l.strip()) for l in lines]
        resultLines = [l for l in lines if l is not None]
        assert len(resultLines) == 1
        timestamp, time, unit = resultLines[0]
        if unit == 's':
            self.time = time
        elif unit == 'ms':
            self.time = time * 1e-3
        elif unit == 'us':
            self.time = time * 1e-6
        elif unit == 'ns':
            self.time = time * 1e-9


if __name__ == '__main__':
    st = SimulatedTime("../log.txt")
    print(st.time)