Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Enable filtering options in the non-DG framework mcpltool #44

Open
willend opened this issue Mar 7, 2019 · 2 comments

Comments

@willend
Copy link
Contributor

willend commented Mar 7, 2019

Having access to the nice "filtering grammar" from the DG code "ess_mcplextra_filterfile" in the general mcpltool (fat version) would be nice.

For now I have implemented a quick and dirty solution / example for McStas specific use, available through the instrument files

https://github.com/McStasMcXtrace/McCode/blob/master/mcstas-comps/examples/MCPL_filter_energy.instr and https://github.com/McStasMcXtrace/McCode/blob/master/mcstas-comps/examples/MCPL_filter_radius.instr

(which for the McStas savvy allows to do to similar filtering operations)

@tkittel
Copy link
Member

tkittel commented Mar 8, 2019

Absolutely, I would like to make some of the mcplextra tools from dgcode available in the mcpl release as well. It won't be part of the mcpltool executable itself though, as that one should not depend on C++ code, but likely in some other optional command line tool.

Great with the McStas instrument examples, we should at some point link them from https://mctools.github.io/mcpl/hooks_mcstas/.

I would like to remind anyone interested in this that it is not difficult to write a simple C programme which does the same as ess_mcplextra_filterfile. Here is the example from https://mctools.github.io/mcpl/usage_c/ without comments, showing how to extract all neutrons with ekin below some threshold:

#include "mcpl.h"
#include <stdio.h>

int main(int argc,char**argv) {
  if (argc!=3) {
    printf("Please supply input and output filenames\n");
    return 1;
  }
  mcpl_file_t fi = mcpl_open_file(argv[1]);
  mcpl_outfile_t fo = mcpl_create_outfile(argv[2]);
  mcpl_transfer_metadata(fi, fo);
  mcpl_hdr_add_comment(fo,"Applied custom filter to select neutrons with ekin<0.1MeV");
  const mcpl_particle_t* particle;
  while ( ( particle = mcpl_read(fi) ) ) {
    if ( particle->pdgcode == 2112 && particle->ekin < 0.1 )
      mcpl_add_particle(fo,particle);
  }
  mcpl_close_outfile(fo);
  mcpl_close_file(fi);
}

@willend
Copy link
Contributor Author

willend commented Mar 8, 2019

Thanks for the comments - and the c-snippet. Really simple indeed.

I will give myself a McCode ticket to remember to document all our MCPL oriented example instruments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants