go-hep.org/x/hep@v0.38.1/groot/riofs/gendata/gen-tprofile.go (about) 1 // Copyright ©2022 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build ignore 6 7 package main 8 9 import ( 10 "flag" 11 "log" 12 13 "go-hep.org/x/hep/groot/internal/rtests" 14 ) 15 16 var ( 17 root = flag.String("f", "test-tprofile.root", "output ROOT file") 18 ) 19 20 func main() { 21 flag.Parse() 22 23 out, err := rtests.RunCxxROOT("gentprofile", []byte(script), *root) 24 if err != nil { 25 log.Fatalf("could not run ROOT macro:\noutput:\n%v\nerror: %+v", string(out), err) 26 } 27 } 28 29 const script = ` 30 #include "TProfile.h" 31 32 void gentprofile(const char* fname) { 33 auto p1d = new TProfile("p1d","Profile of pz versus px",100,-4,4,0,20); 34 auto p2d = new TProfile2D("p2d","Profile of pz versus px and py",40,-4,4,40,-4,4,0,20); 35 36 Float_t px, py, pz; 37 for (Int_t i=0; i<25000; i++) { 38 gRandom->Rannor(px,py); 39 pz = px*px + py*py; 40 p1d->Fill(px,pz,1); 41 p2d->Fill(px,py,pz,1); 42 } 43 44 auto f = TFile::Open(fname, "RECREATE"); 45 f->WriteTObject(p1d, "p1d"); 46 f->WriteTObject(p2d, "p2d"); 47 48 f->Write(); 49 f->Close(); 50 51 exit(0); 52 } 53 `