hepsim:jas4pp
Differences
This shows you the differences between two versions of the page.
— | hepsim:jas4pp [2024/07/01 21:25] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | |||
+ | {{indexmenu_n> | ||
+ | |||
+ | [[: | ||
+ | |||
+ | ====== | ||
+ | |||
+ | [[https:// | ||
+ | a data-analysis environment for detector and physics studies of future circular colliders. | ||
+ | Jas4PP is a merge of several open-source Java projects, such as [[http:// | ||
+ | |||
+ | |||
+ | The installation does not have external dependencies besides Java. Make sure that Oracle Java8 and above is installed (not OpenJDK). | ||
+ | You can download the Jas4pp program using the [[https:// | ||
+ | Then run these commands to install the package using Linux/Mac with the " | ||
+ | |||
+ | <code bash> | ||
+ | wget https:// | ||
+ | tar -zvxf jas4pp.tgz | ||
+ | cd jas4pp | ||
+ | source ./setup.sh # takes 5 sec for first-time optimization | ||
+ | </ | ||
+ | The last command optimizes Java packages for the Python language. | ||
+ | Now you are ready to run over any file with truth-level and datector-simulation files, such as LCIO and ProMC. Here are the included commands: | ||
+ | |||
+ | |||
+ | |||
+ | <code bash> | ||
+ | jaspp # start Jas4pp with preconfigured HEP plugins (Linux/Mac with bash) | ||
+ | jaspp.bat | ||
+ | fpad # run Jython scripts in a batch mode (Linux/Mac with bash) | ||
+ | fpad_edit | ||
+ | fpad_edit.bat | ||
+ | gconverter | ||
+ | gconverter_gui # same in GUI mode | ||
+ | hs-help | ||
+ | </ | ||
+ | |||
+ | Use these programs for: | ||
+ | |||
+ | * Downloading and searching HepSim data | ||
+ | * Processing ProMC files from HepSim | ||
+ | * Processing ROOT files created by the Delphes program for fast simulation | ||
+ | * Running over SLCIO files with Geant4 simulated / reconstructed events. | ||
+ | * Data analysis (jets, physics vectors, histogram packages) | ||
+ | * Visualization of reconstructed events using Wired4 display | ||
+ | |||
+ | You can find more details in [[https:// | ||
+ | |||
+ | |||
+ | <note tip>Note that you can also use the [[hepsim: | ||
+ | Jas4pp</ | ||
+ | |||
+ | ====== Examples ====== | ||
+ | |||
+ | All examples of Jas4pp are collected in the directory " | ||
+ | |||
+ | <code bash> | ||
+ | fpad examples/ | ||
+ | fpad examples/ | ||
+ | fpad examples/ | ||
+ | </ | ||
+ | The last example from the [[https:// | ||
+ | You can also run these examples as " | ||
+ | |||
+ | |||
+ | Here is an example of how to compare data points with a histogram using DMelt classes. | ||
+ | Run this script as "fpad file.py", | ||
+ | |||
+ | <hidden Click to show the Python code> | ||
+ | <code python> | ||
+ | from java.awt import * | ||
+ | from java.util import Random | ||
+ | from jhplot | ||
+ | |||
+ | c1 = HPlot() | ||
+ | # c1.doc() | ||
+ | c1.setGTitle(" | ||
+ | c1.visible(1) | ||
+ | c1.setAutoRange() | ||
+ | c1.setMarginLeft(85) # make space for Y label | ||
+ | c1.setNameX(" | ||
+ | c1.setNameY(" | ||
+ | |||
+ | h1 = H1D(" | ||
+ | h1.setPenWidthErr(2) # line width | ||
+ | h2 = H1D(" | ||
+ | |||
+ | r=Random() | ||
+ | for i in range(10000): | ||
+ | | ||
+ | | ||
+ | |||
+ | p1=P1D(h2) # convert to X-Y array | ||
+ | c1.draw(h1) | ||
+ | c1.draw(p1) | ||
+ | # c1.drawStatBox(h1) | ||
+ | |||
+ | # set HLabel in the normilised coordinate system | ||
+ | lab=HLabel(" | ||
+ | lab.setColor(Color.blue) | ||
+ | c1.add(lab) | ||
+ | |||
+ | c1.update() | ||
+ | c1.export(" | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Run this example in Jas4pp and look at this image: | ||
+ | |||
+ | <hidden Click to show the image> | ||
+ | {{: | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====== Reading LCIO files ====== | ||
+ | |||
+ | Jas4pp can be used to process LCIO files. This can be done using Java, or Python (Jython). The examples are given in the directory " | ||
+ | <hidden Click to show the Python code> | ||
+ | <code python> | ||
+ | # Example of processing SLCIO files using Jas4pp | ||
+ | # Setup Jas4pp using " | ||
+ | # Then create the directory " | ||
+ | # and run this script as "fpad example.py data" | ||
+ | |||
+ | from org.lcsim.lcio import LCIOReader | ||
+ | from hep.io.sio import SIOReader | ||
+ | from hep.lcio.implementation.sio import SIOLCReader | ||
+ | from hep.lcio.implementation.io import LCFactory | ||
+ | from hep.lcio.event import * | ||
+ | from hep.lcio.io import * | ||
+ | from jhplot import * | ||
+ | from hephysics.particle import LParticle | ||
+ | import math | ||
+ | import os,sys | ||
+ | from java.lang import System; | ||
+ | |||
+ | # get directory name from the argument | ||
+ | filename = sys.argv[1] | ||
+ | |||
+ | # make list of files.. | ||
+ | import glob | ||
+ | files = glob.glob(filename+"/ | ||
+ | factory = LCFactory.getInstance() | ||
+ | |||
+ | nEvent=0 | ||
+ | for f in files: | ||
+ | print "Open file=", | ||
+ | reader = factory.createLCReader() | ||
+ | reader.open(f) | ||
+ | while(1): | ||
+ | evt=reader.readNextEvent() | ||
+ | if (evt == None): break | ||
+ | nEvent=nEvent+1 | ||
+ | # print " file event: ", | ||
+ | if (nEvent%100==0): | ||
+ | col = evt.getCollection(" | ||
+ | colPF = evt.getCollection(" | ||
+ | colCl = evt.getCollection(" | ||
+ | colTr = evt.getCollection(" | ||
+ | colECB = evt.getCollection(" | ||
+ | colHCB = evt.getCollection(" | ||
+ | |||
+ | nMc=col.getNumberOfElements(); | ||
+ | nPF=colPF.getNumberOfElements(); | ||
+ | nCl=colCl.getNumberOfElements(); | ||
+ | nTr=colTr.getNumberOfElements(); | ||
+ | nECB=colECB.getNumberOfElements(); | ||
+ | nHCB=colHCB.getNumberOfElements(); | ||
+ | # now you can access all data here | ||
+ | |||
+ | # manage memory if too much data | ||
+ | del col | ||
+ | del colPF | ||
+ | del colCl | ||
+ | del colTr | ||
+ | del colECB | ||
+ | del colHCB | ||
+ | del evt | ||
+ | |||
+ | reader.close() # close the file | ||
+ | del reader | ||
+ | System.gc() | ||
+ | </ | ||
+ | </ | ||
+ | To process SLCIO files from a directory " | ||
+ | |||
+ | < | ||
+ | fpad example.py data | ||
+ | </ | ||
+ | The script open each file, and access every container in the file. | ||
+ | Note that we explicitly mange memory in case of very large files, forcing the garbage collector for each file. In many cases, this is not needed since JVM takes care of memory leakage. | ||
+ | |||
+ | You can find more examples in [[: | ||
+ | |||
+ | Also, look at concrete example of how to analyze single particles in [[: | ||
+ | |||
+ | |||
+ | ====== | ||
+ | |||
+ | Jas4pp natively reads commonly used objects and data structures from [[https:// | ||
+ | ROOT files can be loaded using the Jas4pp menu [File]-[Open data source]-[Root file] (*.root). | ||
+ | |||
+ | In addition, one can work with ROOT files using Python/ | ||
+ | One can find some examples in the directory " | ||
+ | |||
+ | <hidden Show example of a Python code here> | ||
+ | <code python> | ||
+ | from hep.io.root.interfaces import TTree | ||
+ | from hep.io.root import RootFileReader | ||
+ | |||
+ | reader = RootFileReader(" | ||
+ | |||
+ | tree = reader.get(" | ||
+ | maxevents=tree.getEntries() | ||
+ | |||
+ | leaves = tree.getLeaves() | ||
+ | nrleaves=leaves.size() | ||
+ | |||
+ | print "Nr of events=", | ||
+ | print "Nr of leaves=", | ||
+ | |||
+ | print " | ||
+ | for l in xrange( nrleaves ): | ||
+ | print " | ||
+ | |||
+ | print "Run over events" | ||
+ | f0=leaves.get(0); | ||
+ | f1=leaves.get(1); | ||
+ | f2=leaves.get(2); | ||
+ | for i in xrange(tree.getEntries()): | ||
+ | print f0.getValue(i), | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | |||
+ | The example directory also shows how to read histograms. | ||
+ | Similar examples can be made using Java or Groovy scripting. | ||
+ | |||
+ | The supported ROOT interfaces are: | ||
+ | |||
+ | <hidden show more details on ROOT interfaces here> | ||
+ | TArrayC | ||
+ | TArrayD | ||
+ | TArrayF | ||
+ | TArrayI | ||
+ | TArray | ||
+ | TArrayL | ||
+ | TAttAxis | ||
+ | TAttFill | ||
+ | TAttLine | ||
+ | TAttMarker | ||
+ | TAxis | ||
+ | TBasket | ||
+ | TBranchClones | ||
+ | TBranchElement | ||
+ | TBranch | ||
+ | TBranchObject | ||
+ | TClonesArray | ||
+ | TCollection | ||
+ | TDatime | ||
+ | TDirectory | ||
+ | TFile | ||
+ | TGraph | ||
+ | TH1D | ||
+ | TH1F | ||
+ | TH1 | ||
+ | TH2D | ||
+ | TH2F | ||
+ | TH2 | ||
+ | TKey | ||
+ | TLeafB | ||
+ | TLeafC | ||
+ | TLeafD | ||
+ | TLeafElement | ||
+ | TLeafF | ||
+ | TLeafI | ||
+ | TLeaf | ||
+ | TLeafL | ||
+ | TLeafObject | ||
+ | TLeafO | ||
+ | TLeafS | ||
+ | TList | ||
+ | TMap | ||
+ | TNamed | ||
+ | TObjArray | ||
+ | TObject | ||
+ | TProfile | ||
+ | TSeqCollection | ||
+ | TStreamerBase | ||
+ | TStreamerBasicPointer | ||
+ | TStreamerBasicType | ||
+ | TStreamerElement | ||
+ | TStreamerInfo | ||
+ | TStreamerLoop | ||
+ | TStreamerObjectAny | ||
+ | TStreamerObject | ||
+ | TStreamerObjectPointer | ||
+ | TStreamerString | ||
+ | TString | ||
+ | TTree | ||
+ | </ | ||
+ | |||
+ | One can browser histogram (or ROOT objects) using this: | ||
+ | |||
+ | <code python> | ||
+ | import rootio | ||
+ | rootio.HBrowser(" | ||
+ | rootio.Browser(" | ||
+ | </ | ||
+ | |||
+ | You will see the browsers: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | The script that call these browsers | ||
+ | |||
+ | |||
+ | To read ROOT files from Delphes simulations, | ||
+ | [[https:// | ||
+ | getFloat, getDouble, getInt, and getBool. But first, explore the Delphes ROOT file using the browser shown above. | ||
+ | |||
+ | Here is an example that uses high-level classes to read transverse momentum (PT) and pseudorapidity (ETA) of Monte Carlo particles: | ||
+ | |||
+ | |||
+ | <hidden Click here to show a Python code to read Delphes files> | ||
+ | <code python> | ||
+ | from hep.io.root import RootFileReader | ||
+ | from rootio import * | ||
+ | |||
+ | reader = RootFileReader(" | ||
+ | tree = reader.get(" | ||
+ | maxevents=tree.getEntries() | ||
+ | branches=tree.getBranches() | ||
+ | print "Nr of events=", | ||
+ | print "Nr of branches=", | ||
+ | print " | ||
+ | for l in xrange( branches.size() | ||
+ | print " | ||
+ | |||
+ | particles=tree.getBranch(" | ||
+ | |||
+ | ptEvents=Delphes.getFloat(particles," | ||
+ | etaEvents=Delphes.getFloat(particles," | ||
+ | |||
+ | from jhplot import * | ||
+ | h1 = H1D(" | ||
+ | h2 = H1D(" | ||
+ | for i in xrange(tree.getEntries()): | ||
+ | | ||
+ | for j in xrange(len(pt)): | ||
+ | | ||
+ | | ||
+ | c=HPlot(" | ||
+ | c.visible() | ||
+ | c.setAutoRange() | ||
+ | c.draw(h1) | ||
+ | |||
+ | c.cd(2,1) | ||
+ | c.setAutoRange() | ||
+ | c.draw(h2) | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | {{: | ||
+ | |||
+ | <note warning> | ||
+ | |||
+ | ====== Using GUI mode ====== | ||
+ | |||
+ | |||
+ | You can also run Jas4pp in a GUI mode. You can process scripts that read PROMC and LCIO files from these HepSim pages: | ||
+ | |||
+ | - [[https:// | ||
+ | - [[https:// | ||
+ | |||
+ | |||
+ | Download any of these scripts, and open it using the " | ||
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | |||
+ | ====== Programming with HepSim ====== | ||
+ | |||
+ | |||
+ | Jas4pp can be used to write Jython scripts to validate HepSim ProMC files. Please look at | ||
+ | [[https:// | ||
+ | |||
+ | |||
+ | ====== Java API ====== | ||
+ | |||
+ | |||
+ | ===== Plots and histograms ===== | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | Jas4pp uses histogram packages supported by both DMelt (community edition) or JAIDA (FreeHep). | ||
+ | DMelt provides programming API similar to PyROOT and with classes named conveniently to reduce code verbosity. | ||
+ | |||
+ | Here are a few most common classes: | ||
+ | |||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | The main canvas to show histograms [[http:// | ||
+ | In addition, data are saved in the form of XML (with the extension " | ||
+ | |||
+ | ===== Lorentz particles and Jets ===== | ||
+ | |||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | | ||
+ | | ||
+ | Java implementation of the longitudinally invariant kT and anti-kT clustering algorithms uses the E-scheme to combine particles (p1+p2) and Eta-Phi space (not Rapidity-Phi). Also, Cambridge/ | ||
+ | |||
+ | |||
+ | You can build the standard kt-jets using [[http:// | ||
+ | [[https:// | ||
+ | |||
+ | |||
+ | ====== Visualizing a detector Jas+Wired ====== | ||
+ | |||
+ | You can run Jas+Wired to visualize the simulated events. | ||
+ | <code bash> | ||
+ | ./jaspp | ||
+ | </ | ||
+ | This will start a Jas3-like environment | ||
+ | Then copy the detector geometry file from the [[https:// | ||
+ | <code bash> | ||
+ | wget https:// | ||
+ | </ | ||
+ | This will create a directory " | ||
+ | |||
+ | Now we can visualize the detector as **[File]-[Open data source]-[HepRep]** XML and select the file " | ||
+ | This is how to do this using the command line: | ||
+ | |||
+ | <code bash> | ||
+ | ./ | ||
+ | </ | ||
+ | You will see the detector layout: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Now, we will read the event: Open any *.slcio file you copied from HepSim as | ||
+ | **[File]-[Open data source]-[LCIO]** file. Then click a small button [Go] (top menu bar). It will process | ||
+ | | ||
+ | Now press [Go] again to look at next event. | ||
+ | If you want to see how data records are organized inside the slcio file, | ||
+ | do this **[File]-[New]-[LCSim Event browser]** | ||
+ | |||
+ | |||
+ | Here is an example of how to visualize LCIO files from the [[http:// | ||
+ | |||
+ | <code bash> | ||
+ | wget https:// | ||
+ | ./jaspp pgun_muon1024gev_001_pandora.slcio | ||
+ | </ | ||
+ | |||
+ | Click " | ||
+ | " | ||
+ | Then go to the next event, click "Go next" in the menu. This image illustrates a single electron event: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Similarly, you can view any events form the HepSim directory. The LCIO event file automatically installs | ||
+ | the required detector geometry, i.e. when you open a SLCIO file from the HepSim, you do not need to load the geometry file. The geometry file will be downloaded automatically from HepSim and will be put to " | ||
+ | |||
+ | |||
+ | |||
+ | ====== Visualizing geometry using ROOT ====== | ||
+ | (contribution from N.Nikiforou): | ||
+ | |||
+ | You can also visualize the detector using ROOT. Here are a few steps: | ||
+ | Locate the file detector.gdml inside the file detector.zip (where " | ||
+ | |||
+ | |||
+ | <hidden show more details here> | ||
+ | This file is created using this command during the detector design stage | ||
+ | < | ||
+ | slic -g detector.lcdd -G detector.gdml | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Once you have the GDML file, you can use ROOT to visualize it. You just | ||
+ | need to make sure the ROOT installation has openGL/GDML support (CERN | ||
+ | AFS installations have it for sure). At the ROOT prompt do: | ||
+ | |||
+ | <code cpp> | ||
+ | TGeoManager:: | ||
+ | gGeoManager-> | ||
+ | </ | ||
+ | This should popup an OpenGL display with the detector which you can | ||
+ | clip, pan, rotate etc. You will the image as shown here: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | ====== People ====== | ||
+ | |||
+ | * S.Chekanov (ANL, main developer) | ||
+ | * E.May (ANL, debugging, Wired4) | ||
+ | * Gagik Gavalian (JLab) | ||
+ | |||
+ | |||
+ | ====== Additional help ====== | ||
+ | |||
+ | |||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | |||
+ | |||
+ | |||
+ | --- // | ||
+ | |||