Presentation is loading. Please wait.

Presentation is loading. Please wait.

14 - 10 - Utilizzo del codice GEANT4 in campo medico LNS (Mon 12-Oct-2009 ---- Wed 14-Oct-2009) Gestione ed analisi dei dati prodotti.

Similar presentations


Presentation on theme: "14 - 10 - Utilizzo del codice GEANT4 in campo medico LNS (Mon 12-Oct-2009 ---- Wed 14-Oct-2009) Gestione ed analisi dei dati prodotti."— Presentation transcript:

1 14 - 10 - 2009dirosa@lns.infn.it1 Utilizzo del codice GEANT4 in campo medico LNS (Mon 12-Oct-2009 ---- Wed 14-Oct-2009) Gestione ed analisi dei dati prodotti Francesco Di Rosa

2 14 - 10 - 2009dirosa@lns.infn.it2 I.Overview of basic Analysis a)Generic and simple Output in Geant4 b)Analysis of ASCII files II.Overview of advanced Analysis a)Downloading the AIDA utility package b)Turning on the analysis package c)Loading the package d)Producing/Analyzing first histograms e)The packages: JAS, ROOT, PAW, OpenScientist III.Few examples of Analysis a)JAS b)ROOT c)PAW IV.Conclusion Outline

3 14 - 10 - 2009dirosa@lns.infn.it3 Geant4 does not attempt to provide its own data analysis tools, focusing instead on its central mission as a simulation toolkit The Geant4 user is expected to provide his own code to output results to an appropriate analysis format The Geant4 simple output: the simplest possible output format here G4Cout ASCII *. TXT (Row, Matrices, Line) *. CSV (Comma-Separated Values), *. PIPPO (What you want!!!!!!!!! Exe: mixed formats) The resulting files can be analyzed by tools such as: Excel, OpenOffice, Gnuplot, Matlab, OriginLab I. a) Generic and simple Output in Geant4

4 14 - 10 - 2009dirosa@lns.infn.it4 An Example of G4COUT (good for test and verify) I. a) Generic and simple Output in Geant4 Lung Interface!! G4cout " << " " << std::setw( 6) << edep << " " " << " " << std::setw( 2) << particleCharge << " " " << " " << std::setw( 2) << kineticEnergy << " " << G4endl;

5 14 - 10 - 2009dirosa@lns.infn.it5 std::ofstream myfile(“File_di_OUTPUT”, std::ios::app); myfile << edep << '\t' <<particleCharge<<'\t' << kineticEnergy << '\n' << G4endl; controlloTally=evtNb; An Example of ASCII File (Save As……) I. a) Generic and simple Output in Geant4

6 14 - 10 - 2009dirosa@lns.infn.it6 I. a) Generic and simple Output in Geant4 PDD

7 14 - 10 - 2009dirosa@lns.infn.it7 Excel Comes from a small company called MicroSoft Part of Microsoft Office (very common software) From the “Data” menu, select “Get External Data”…“Import Data…” Select the file using the extension (*.*) The Text Import Wizard will come up Check the “Delimited” box Hit “Next” Check the “Comma” box The bottom part of the Wizard should now show your data nicely separated into appropriate columns. Hit “Finish” You will see a dialog titled “Import Data” which will ask where to put the data. Accept the defaults: Existing worksheet: =$A$1 Hit “OK” The data should now show up in the spreadsheet (see the next slide) I. b) Analysis of ASCII files

8 14 - 10 - 2009dirosa@lns.infn.it8 I. b) Analysis of ASCII files Importing data in Excel

9 14 - 10 - 2009dirosa@lns.infn.it9 Plotting with Excel Select at least one item in the filled data area. From the “Insert” menu, select “Chart…” Select Chart type: “Histogram” Hit “Finish” You’re done I. b) Analysis of ASCII files Now that the data is in the spreadsheet, you can plot it as follows:

10 14 - 10 - 2009dirosa@lns.infn.it10 OpenOffice OpenOffice.org is a multiplatform and multilingual office suite and an open-source projectmultiplatformmultilingualoffice suiteopen-source Compatible with all other major office suites, the product is free to download, use, and distribute http://www.openoffice.org/ http://www.openoffice.org/ From the “File” menu, Select “Open…” In the “File type” box, select “Text CSV” Then select your file Typology ………………………………………. I. b) Analysis of ASCII files

11 14 - 10 - 2009dirosa@lns.infn.it11 Importing Data from a.csv File Into OpenOffice Once you select your file: The Text Import dialog will come up Check the “Comma” box The bottom part of the dialog should now show your data nicely separated into appropriate columns, then Hit “OK” I. b) Analysis of ASCII files The data should now show up in the spreadsheet (maybe)

12 14 - 10 - 2009dirosa@lns.infn.it12 Plotting with OpenOffice Now that the data is in the spreadsheet, you can plot it as follows: Select at least one item in the filled data area. From the “Insert” menu, select “Chart…” The defaults should be fine Hit “Next” I. b) Analysis of ASCII files Select the Icon for “Line” chart Hit “Create” You’re done!

13 14 - 10 - 2009dirosa@lns.infn.it13 “Gnuplot is a portable command-line driven interactive data and function plotting utility for UNIX, IBM OS/2, MS Windows, DOS, Macintosh, VMS, Atari and many other platforms.” “The software is copyrighted but freely distributed (i.e., you don't have to pay for it)” http://www.gnuplot.info/ See the demo page (http://gnuplot.sourceforge.net/demo_4.2/)http://gnuplot.sourceforge.net/demo_4.2/ I. b) Analysis of ASCII files Gnuplot

14 14 - 10 - 2009dirosa@lns.infn.it14 1) Choose the data Folder 2) LOAD the output file 3) In the workspace appear your data I. b) Analysis of ASCII files 4. One-click with right mouse bottom on Workspace 5. Select Plot Catalog and prefer the Chart type 6. You’re done… :-/ Plotting with MatLab

15 14 - 10 - 2009dirosa@lns.infn.it15 I.Overview of basic Analysis a)Generic and simple Output in Geant4 b)Analysis of ASCII files II.Overview of advanced Analysis a)Downloading the AIDA utility package b)Turning on the analysis package c)Loading the package d)Producing/Analyzing first histograms e)The packages: JAS, ROOT, PAW, OpenScientist III.Few examples of Analysis a)JAS b)ROOT c)PAW IV.Conclusion Outline

16 14 - 10 - 2009dirosa@lns.infn.it16 While the Geant4 collaboration does not maintain any data analysis system, many data analysis tool developers have interfaced their systems to Geant4 and each of the following has an active Geant4 user community II. Overview of advanced Analysis (AIDA) ROOT is an Object Oriented Data Analysis Framework. It is heavily used in High Energy Physics. Freely available at http://root.cern.ch/http://root.cern.ch/ AIDA (Analysis Interface for Data Analysis) is an interface standard used by several advanced data analysis tools. It provides a single standard way to create your data Commands to:instantiate/fill an nTuple instantiate/fill a Histogram You can switch from one AIDA-compliant tool to another without having to change how you book and fill your histograms (http://aida.freehep.org/)http://aida.freehep.org/

17 14 - 10 - 2009dirosa@lns.infn.it17 AIDA Example AIDAAIDA User code (e.g. GEANT4) Analysis tool 1 Analysis tool 2 Analysis tool 3 Use same code with any AIDA-compliant analysis tool II. Overview of advanced Analysis (AIDA)

18 14 - 10 - 2009dirosa@lns.infn.it18 Now, you have just AIDA installed…… But….. If you DO NOT have AIDA installed, then (will take ~5-10 min): 1.Create AIDA directory under "geant4/work" directory mkdir geant4/work/AIDA 2.Download "osc_batch-v16r0-XX-i386-gcc_401.zip" into "AIDA" folder from http://aida.freehep.org http://aida.freehep.org –WindowsXX = CYGWIN –LinuxXX = Linux –MACOSXX = Darwin 3.Decompress the file 4.Go into “osc_batch/v16r2” directory cd osc_batch/v16r0 5.Setup the AIDA environment source aida-setup.csh or source aida-setup.sh 6.Done! II. a) Downloading & Setting the AIDA utility package

19 14 - 10 - 2009dirosa@lns.infn.it19 G4ANALYSIS_USE Set variable –setenv G4ANALYSIS_USE 1 (csh) –export G4ANALYSIS_USE=1 (bash o setup) Is it on? (linux commands) –1 (on) or 0 (off) –“echo”echo $G4ANALYSIS_USE –“env” env then look for G4ANALYSIS_USE II. b) Turning on the Analysis Package

20 14 - 10 - 2009dirosa@lns.infn.it20 Required files #include  Define AnalysisManager.cc  Create & Fill AnalysisManager.hh II. b) Loading the analysis package I

21 14 - 10 - 2009dirosa@lns.infn.it21 II. b) Loading the analysis package II: AnalysisManager.cc (create) From Hadrontherapy Example

22 14 - 10 - 2009dirosa@lns.infn.it22 …………. A01AnalysisManager::A01AnalysisManager() :analysisFactory(0), hFactory(0), tFactory(0) { // Hooking an AIDA compliant analysis system. analysisFactory = AIDA_createAnalysisFactory(); if(analysisFactory) { ITreeFactory* treeFactory = analysisFactory->createTreeFactory(); tree = treeFactory->create("A01.aida","xml",false,true,"compress=yes"); hFactory = analysisFactory->createHistogramFactory(*tree); tFactory = analysisFactory->createTupleFactory(*tree); delete treeFactory; // Will not delete the ITree. } …….. II. b) Loading the analysis package II: AnalysisManager.cc (create) From Extended Example A01

23 14 - 10 - 2009dirosa@lns.infn.it23 … std::string opts = "compress=no"; fTree = treeFactory->create("AnaEx01.aida","xml",false,true,opts); ….. // Create an histo factory that will create histo in the tree : AIDA::IHistogramFactory* histoFactory = fAIDA- >createHistogramFactory(*fTree); if (histoFactory) { fEAbs = histoFactory->createHistogram1D("EAbs",100,0,100); fLAbs = histoFactory->createHistogram1D("LAbs",100,0,100); … delete histoFactory; } … II. b) Loading the analysis package II: AnalysisManager.cc (create) From Extended Example AnaEx01: create histograms

24 14 - 10 - 2009dirosa@lns.infn.it24 … // Get a tuple factory : AIDA::ITupleFactory* tupleFactory = fAIDA->createTupleFactory(*fTree); if (tupleFactory) { // Create a tuple : fTuple = tupleFactory->create("AnaEx01","AnaEx01", "double EAbs,double LAbs,double EGap,double LGap"); delete tupleFactory; } … II. b) Loading the analysis package III: AnalysisManager.cc (create) From Extended Example AnaEx01: create ntuples

25 14 - 10 - 2009dirosa@lns.infn.it25 II. b) Loading the analysis package IV: AnalysisManager.cc (fill) From Hadrontherapy Example

26 14 - 10 - 2009dirosa@lns.infn.it26 … if (CHC) { G4int n_hit = CHC->entries(); for (G4int i=0;i<n_hit;i++) { G4double EAbs = (*CHC)[i]->GetEdepAbs(); G4double LAbs = (*CHC)[i]->GetTrakAbs(); … fEAbs->fill(EAbs); fLAbs->fill(LAbs); … fTuple->fill(0,EAbs); fTuple->fill(1,LAbs); … fTuple->addRow(); } }… II. b) Loading the analysis package IV: AnalysisManager.cc (fill) From Extened Example AnaEx01: fill histograms and ntuples

27 14 - 10 - 2009dirosa@lns.infn.it27 II. c) Producing/Analyzing first histograms  Copy example into your work area (hadrontherapy)  Go into example directory: cd hadrontherapy  Compile: gmake or make  Run: ~/geant4/work/bin/Linux-g++/……  A new file should appear: hadronterapy.root (.hbk,.aida) ANALYSIS  Start JAS (…ROOT,AIDA,HBOOK)  Open the file: File  “Open File” then select XX.root  Double click on “Blue Folder”  Double click on histogram of interest Homework assignment

28 14 - 10 - 2009dirosa@lns.infn.it28 I.Overview of basic Analysis a)Generic and simple Output in Geant4 b)Analysis of ASCII files II.Overview of advanced Analysis a)Downloading the AIDA utility package b)Turning on the analysis package c)Loading the package d)Producing/Analyzing first histograms e)The packages: JAS, ROOT, PAW, OpenScientist III.Few examples of Analysis a)JAS b)ROOT c)PAW IV.Conclusion Outline

29 14 - 10 - 2009dirosa@lns.infn.it29 Java Analysis Studio: JAS (all files) The Root of Everything: ROOT (root files) Physics Analysis Workstation: PAW (hbook files) OpenScientist (all files) III. Few examples of advanced analysis

30 14 - 10 - 2009dirosa@lns.infn.it30 –Written entirely in Java (really portable) –Originally targeted at offline analysis (but also used extensively for online monitoring) –Rich, easy to use GUI Can view trees, plots, HTML pages with embedded active objects –Built-in editor/compiler for writing analysis code Based on open source JEdit editor (pure Java editor, syntax highlighting, auto indent, parenthesis matching, etc.) –Local and Client-Server Operation Access local or remote analysis objects Can send analysis code to the data and ship back only the results III a) Java Analysis Studio (JAS, http://jas.freehep.org/jas3) Java Analysis Studio (JAS)

31 14 - 10 - 2009dirosa@lns.infn.it31 Start jas Open the file: File  “Open File” then select OUTPUT.aida Double click on “Blue Folder” (OUTPUT.aida) Double click on histogram and then the ones of interest Double click on tuples then “Yellow Folder” III a) Java Analysis Studio (Example)

32 14 - 10 - 2009dirosa@lns.infn.it32 Built-in HTML viewer with embeddable “objects” (plots, buttons, etc.). Pages can display histograms. User can control layout, add, remove plots. Tree area provides access to analysis objects. Each item has popup menu and double- click action. Plot Widget, shows data in real time, optimized for fast refresh performance. III a) Java Analysis Studio (GUI)

33 14 - 10 - 2009dirosa@lns.infn.it33 III b) ROOT (http://root.cern.ch/ - http://www.mi.infn.it/~palombo/lazzaro/ )http://root.cern.ch/http://www.mi.infn.it/~palombo/lazzaro/ In AnaEx01AnalysisManager.cc  Verify or type the following lines std::string opts = “export=root"; fTree = treeFactory->create("AnaEx01.root",“ROOT",false,true,opts); Start root Launch browser: new TBrowser() Open the file: File  “Open” then select nameFile.root Double click on “Yellow Folder” (ROOT Files) Double click on “Yellow Folder” (file.root) Double click on “Yellow Folder” (histograms) and then the ones of interest Double click on “Yellow Folder” (tuples) then right-mouse on “nameFile” and select Start Viewer Drag variables of interest into (X,Y,Z) (Ex: X=EAbs and Y=Labs) Select Draw Icon (bottom left corner) Create a cut: double click on E() then type: EGapcut (alias) and EGap<20 (expression) Drag cut into Scissor Select Draw Icon (bottom left corner) Can enable or disable the cut by double clicking on it

34 14 - 10 - 2009dirosa@lns.infn.it34 III b) ROOT (Hist Browser)

35 14 - 10 - 2009dirosa@lns.infn.it35 III b) ROOT ( TGhtml web browser plug-in) URL You can browse a root file You can execute a script

36 14 - 10 - 2009dirosa@lns.infn.it36 III b) ROOT (Macro Manager/Editor plug-in) Click on button to execute script

37 14 - 10 - 2009dirosa@lns.infn.it37 III b) ROOT (Math libraries)

38 14 - 10 - 2009dirosa@lns.infn.it38 III c) Physics Analysis Workstation (PAW, cernlib) PAW is no longer supported: you are on your own!!! In AnaEx01AnalysisManager.cc  Verify or type the following lines std::string opts = “export=hbook"; fTree = treeFactory->create("AnaEx01.hbook",“HBOOK",false,true,opts); Should get: AnaEx01.hbook Start paw++ Open file: h/file 0 [filepath]/AnaEx01.hbook Double click on logical unit 1 (lun1) Double click on histograms or ntuple Select a variable and double lick in (X,Y,Z) (Ex: X=EAbs and Y=Labs) Click on Plot Click on Cut Editor … Left box = variable, middle box = expression, right box = value (Ex: EGap<20) Click on Plot

39 14 - 10 - 2009dirosa@lns.infn.it39 Conclusion The Geant4 user is expected to provide his own code to output results to an appropriate analysis format Geant4 does not attempt to provide its own data analysis tools, focusing instead on its central mission as a simulation toolkit Several analysis tools are available Real Conclusion Use Whatever Analysis Tool You Like Use as it suits your needs

40 14 - 10 - 2009dirosa@lns.infn.it40 MORE INFORMATIONS ABOUT AIDA

41 14 - 10 - 2009dirosa@lns.infn.it41 n -Tuple (The term originated as an abstraction of the sequence: single, double, triple, quadruple, quintuple, n-tuple) Let us consider the following example A Data Summary Tape contains 10000 events. Each event consists of many variables (200) for which we would like to make some distributions according to various selection criteria One possibility is to create and fill 200 histograms on an event-by-event basis while reading the DST An alternative solution is to create one Ntuple Instead of histograming the 200 variables directly, and therefore losing the exact values of the variables for each event and their correlations, the variables are first stored in an Ntuple. An Ntuple is like a table where the 200 variables mentioned above are the columns and each event is a row Let us use Example

42 14 - 10 - 2009dirosa@lns.infn.it42 Factory – “a building or set of buildings with facilities for manufacturing” (Webster Dictionary). O bjects in AIDA are created by Factories or internally by other objects. User should newer utilize “new”.  static IAnalysisFactory create ()  IHistogramFactory createHistogramFactory (ITree tree)  IFunctionFactory createFunctionFactory (ITree tree)  ITupleFactory createTupleFactory (ITree tree)  ITreeFactory createTreeFactory ()  IPlotterFactory createPlotterFactory ()  IDataPointSetFactory createDataPointSetFactory (ITree tree)  IFitFactory createFitFactory () AIDA Factories – IAnalysisFactory

43 14 - 10 - 2009dirosa@lns.infn.it43 Creates 1D, 2D, 3D IHistograms, IClouds, IProfiles: –IHistogram1D createHistogram1D (String name, String title, int nBins, double lowerEdge, double upperEdge, String options ) –IHistogram1D createHistogram1D (String name, String title, int nBins, double[] binEdges, String options ) –Options: “type=efficiency” – create efficiency histogram. –Options: “autoconvert=true” – to enable auto conversion for Clouds. Does operations on those objects: –Copy and Arithmetic operations add/subtract/divide/multiply IHistogram1D add (String name, IHistogram1D h1, IHistogram1D h2) –Projections and Slices of 2D and 3D Objects: 2D -> 1D, 3D -> 2D IHistogram1D projectionX (String name, IHistogram2D h2D) IHistogram1D sliceX (String name, IHistogram2D h2D, int index) AIDA Factories – IHistogramFactory

44 14 - 10 - 2009dirosa@lns.infn.it44 IHistogram (1D-3D) Binned histogram: IHistogram1D, 2D, 3DIHistogram1D –“fill” methods (with/without weight) –Histogram info: entries, mean, rms, axis –Bin info: centre, entries, height, error –Histogram arithmetic: add, multiply, divide –Convenience methods, like coordinate-to- index conversion

45 14 - 10 - 2009dirosa@lns.infn.it45 ITuple ITuple - interface to the DataITuple –“get/set” methods for double, float, int, … –Information about columns: min, max, mean, rms –Navigating: start(), next(), skip(int nRows) –Project ITuple into 1D, 2D, 3D histogram –New features for AIDA 3.0: Support for complex internal structures (subfolders) Chaining of ITuples

46 14 - 10 - 2009dirosa@lns.infn.it46 ICloud Unbinned collection of points: ICloud1D, 2D, 3DICloud1D –Can represent scatter plot, dynamically rebinnable histogram –Can be converted to a binned histogram –Standard “get/set” methods for entries –Collection info: lower, upper, mean, rms

47 14 - 10 - 2009dirosa@lns.infn.it47 IFunction and Fitting Fitting: IFunction, IFitFunction –IFunction – simple interface, allows to set parameters and get function value –IFitFunction – fit function to a histogram Extends IFunction Various fit control methods: step size, bounds, etc. Allows to perform fit and get results AIDA 2.2 fitting functionality fairly limited –AIDA 3.0 (Under discussion) extended functionality

48 14 - 10 - 2009dirosa@lns.infn.it48 ITree –directory-like structure (Unix directory convention) Methods like: cd, ls, mkdir, etc. –AIDA analysis objects (tuples, histograms, clouds, ets.) exist within ITree directories –“save/restore” functionality, hides storage details from the user Compatible with database or file storage Can support multiple file formats Mount/Unmount functionality (like unix) allows multiple stores to be seamlessly merged AIDA XML format is defined for data interchange


Download ppt "14 - 10 - Utilizzo del codice GEANT4 in campo medico LNS (Mon 12-Oct-2009 ---- Wed 14-Oct-2009) Gestione ed analisi dei dati prodotti."

Similar presentations


Ads by Google