#数据分析 #alice #物理 #root #cern #lhc #数据集

恶意

一个小型框架,为分析 ALICE 的公开数据提供合理的默认值

6 个版本

0.3.0 2021 年 2 月 5 日
0.2.1 2020 年 3 月 16 日
0.2.0 2020 年 1 月 17 日
0.1.2 2019 年 6 月 22 日
0.1.0 2018 年 3 月 7 日

#331 in 科学

MPL-2.0 许可证

165KB
3.5K SLoC

恶意

Crates.io 版本 https://docs.rs/malice/

"milli ALICE" 即 恶意 是一个小巧的框架,定义了一些合理的默认值来分析 ALICE 的公开数据。

示例

以下是一个使用 恶意 和该仓库中的其他 crates 的非常简单的分析示例。它测量重建轨迹的伪快度分布。对于更全面但仍很小的示例(包括并发),请查看 simple-analysis

extern crate alice_open_data;
extern crate histogram;
extern crate malice;
extern crate root_io;

use histogram::*;
use root_io::RootFile;

use malice::{Event, DatasetIntoIter as DsIntoIter};
use malice::{default_track_filter, default_event_filter};

fn main() {
    // Iterator over files of the Open Data set
    let files: Vec<_> = alice_open_data::all_files_10h()
        .expect("No data files found. Did you download with alice-open-data?")
        .into_iter()
        .collect();

    // Create an iterator over `malice::event::Event`s
    let events = files
        .iter()
        .map(|path| RootFile::new_from_file(&path).expect("Failed to open file"))
        .map(|rf| rf.items()[0].as_tree().unwrap())
        .flat_map(|tree| match DsIntoIter::new(&tree) {
            Ok(s) => s,
            Err(err) => panic!("An error occured! Message: {}", err),
        });

    // Fold the `malice::event::Events` with the analysis	
    let _analysis_result: SimpleAnalysis = events
        // Apply a sensible default event filter
        .filter(default_event_filter)
        .fold(SimpleAnalysis::new(), |analysis, ev| { analysis.process_event(&ev) });
    // Do something with the result...
}

pub struct SimpleAnalysis {
    // Histogram of the pseudorapidity (eta) distribution of valid tracks
    pub eta_distribution: Histogram<i32, [usize; 1]>,
}

impl SimpleAnalysis {
    fn new() -> SimpleAnalysis {
	// 50 bins from -0.9 to 0.9
	let (neta, eta_min, eta_max) = (50, -0.9, 0.9);
        SimpleAnalysis {
	    eta_distribution: HistogramBuilder::<[usize; 1]>::new()
                .add_equal_width_axis(neta, eta_min, eta_max)
                .build()
                .expect("Error building histogram"),
        }
    }

    // Update the histogram with the given event
    fn process_event(mut self, event: &Event) -> Self
    {
        // Fill only if we have a valid primary vertex
        if let Some(prime_vtx) = event.primary_vertex() {
            self.eta_distribution
                .extend(
                    event.tracks()
		    // Apply a sensible default "cut" on the valid tracks
			.filter(|tr| default_track_filter(&tr, &prime_vtx))
                        .map(|tr| [tr.eta() as f64]));
	};
        self
    }
}

依赖项

~6–20MB
~307K SLoC