Last active
December 14, 2015 12:29
-
-
Save wavewave/5087178 to your computer and use it in GitHub Desktop.
mathematica-data plot using HROOT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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