Skip to content

Instantly share code, notes, and snippets.

@wavewave
Last active December 14, 2015 12:29
Show Gist options
  • Select an option

  • Save wavewave/5087178 to your computer and use it in GitHub Desktop.

Select an option

Save wavewave/5087178 to your computer and use it in GitHub Desktop.
mathematica-data plot using HROOT
import Data.Mathematica
import Data.Mathematica.Parser
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C
import Data.Attoparsec
import Data.Maybe
import HROOT.Core
import HROOT.Graf
import HROOT.Hist
import HROOT.IO
import HROOT.Math
main :: IO ()
main = do
putStrLn "start mathematica parser"
bstr <- B.readFile "out.dat"
let pr = parseOnly mathdatafile bstr
either putStrLn action pr
action :: [[MExpression]] -> IO ()
action mexpss = do
print (length mexpss)
let r = catMaybes . map match $ mexpss
tcanvas <- newTCanvas "test" "test" 648 480
th2f <- newTH2F "test2" "test2" 100 100 2000 100 100 5000
mapM_ (filleach th2f) . filter (\(x,y,z)->z > (-12.7) ) $ r
draw th2f ""
saveAs tcanvas "test.pdf" "title"
delete th2f
delete tcanvas
-- print mexpss
filleach :: TH2F -> (Double,Double,Double) -> IO ()
filleach h (x,y,z) = do
fill2 h x y
return ()
match :: [MExpression] -> Maybe (Double,Double,Double)
match [MReal x, MReal y, MReal z] = Just (x,y,z)
match _ = Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment