| 1 | # $Id: dataAcess.py,v 1.3 2003/06/26 11:54:13 dressel Exp $
|
|---|
| 2 | # -------------------------------------------------------------------
|
|---|
| 3 | # GEANT4 tag $Name: $
|
|---|
| 4 | # -------------------------------------------------------------------
|
|---|
| 5 | #
|
|---|
| 6 | import os
|
|---|
| 7 | import shelve
|
|---|
| 8 | import myLiz
|
|---|
| 9 | import dpsManip
|
|---|
| 10 | import detector
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 | class ExperimentalData(object):
|
|---|
| 15 | def __init__(self):
|
|---|
| 16 | tiara_dir = os.environ["TIARA_BASE"]
|
|---|
| 17 | if not tiara_dir:
|
|---|
| 18 | print "dataAcess.ExperimentalData: TIARA_BASE not defined run tiara...sh first"
|
|---|
| 19 | dataFile = tiara_dir + "/data/expDataConverted/TiaraData2.xml"
|
|---|
| 20 | print "display.ExperimentalData.dataFile:" ,dataFile
|
|---|
| 21 | self.dataTree = myLiz.tf.create (dataFile,"xml",1,0)
|
|---|
| 22 |
|
|---|
| 23 | def getDataDPS(self, she, detector):
|
|---|
| 24 | energy = she["energy"]
|
|---|
| 25 | shieldWidth = she["shieldWidth"]
|
|---|
| 26 | dataName = "Tiara-" + energy + "c" + shieldWidth + \
|
|---|
| 27 | "-" + detector
|
|---|
| 28 | if shieldWidth == "25" or shieldWidth == "50":
|
|---|
| 29 | dataName += "a"
|
|---|
| 30 | dataName += ".pnt"
|
|---|
| 31 | print dataName
|
|---|
| 32 | pData = self.dataTree.findDataPointSet(dataName)
|
|---|
| 33 | dpsManip.setDPSErrorsToZero(pData, 0)
|
|---|
| 34 | return pData
|
|---|
| 35 |
|
|---|
| 36 | def getScaledDataaDPS(self, she, detname, df):
|
|---|
| 37 | pDataO = self.getDataDPS(she, detname)
|
|---|
| 38 | pData = dpsManip.createScaledDPS(0,
|
|---|
| 39 | pDataO,
|
|---|
| 40 | df,
|
|---|
| 41 | "scaled_" + pDataO.title (),
|
|---|
| 42 | 0.000001)
|
|---|
| 43 | return pData
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 | class MC_Data(object):
|
|---|
| 48 | def __init__(self, she, mcTree):
|
|---|
| 49 | self.she = she
|
|---|
| 50 | self.energy = self.she["energy"]
|
|---|
| 51 | self.shield = self.she["shieldWidth"]
|
|---|
| 52 | self.mcTree = mcTree
|
|---|
| 53 | self.coli = 0
|
|---|
| 54 | if self.shield == "25" or \
|
|---|
| 55 | self.shield == "50":
|
|---|
| 56 | self.coli = 1
|
|---|
| 57 | self.baseName = self.energy + "c" + self.shield +\
|
|---|
| 58 | "_detector_"
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 | def getGeneratedHisto(self):
|
|---|
| 62 | name = "source_detector"
|
|---|
| 63 | hGen = self.mcTree.findH1D(name)
|
|---|
| 64 | return hGen
|
|---|
| 65 |
|
|---|
| 66 | def getMcPlot(self, detector, histo):
|
|---|
| 67 | mcName = "detector_" + detector + histo
|
|---|
| 68 | print mcName
|
|---|
| 69 | hMc = self.mcTree.findH1D(mcName)
|
|---|
| 70 | return hMc
|
|---|
| 71 |
|
|---|
| 72 | def getScale(self, atColiExit):
|
|---|
| 73 | coli = 0
|
|---|
| 74 | if atColiExit==1:
|
|---|
| 75 | coli = 0
|
|---|
| 76 | else:
|
|---|
| 77 | coli = self.coli
|
|---|
| 78 |
|
|---|
| 79 | nPeakNeutrons = self.she["generatorTally"].measures[1].sum
|
|---|
| 80 | scale = detector.detScale(nPeakNeutrons, self.energy, coli)
|
|---|
| 81 | print "CompPlot.getScale: scaling with:", scale
|
|---|
| 82 | return scale
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 | def getScaledMcDPS(self, atColiExit, det, df, histo = ""):
|
|---|
| 86 | dname = self.baseName + det.name
|
|---|
| 87 | if histo:
|
|---|
| 88 | dname += "_" + histo
|
|---|
| 89 |
|
|---|
| 90 | scale = self.getScale (atColiExit)
|
|---|
| 91 | hMc = self.getMcPlot (det.name, histo )
|
|---|
| 92 | binEdges = dpsManip.getBinEdges(hMc)
|
|---|
| 93 | dScaled = dpsManip.getScaledDPS(hMc, scale/det.volume,
|
|---|
| 94 | df, dname + "scaled")
|
|---|
| 95 | dLethScaled = dpsManip.dLogWeightDPS (dScaled,
|
|---|
| 96 | df,
|
|---|
| 97 | dname + "df_dlgE",
|
|---|
| 98 | binEdges)
|
|---|
| 99 | return dLethScaled
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 | def getScaledGeneratedDPS(self, atColiExit, det, df, histo = ""):
|
|---|
| 103 | dname = self.baseName + det.name
|
|---|
| 104 | if histo:
|
|---|
| 105 | dname += "_" + histo
|
|---|
| 106 | scale = self.getScale (atColiExit)
|
|---|
| 107 | hGen = self.getGeneratedHisto()
|
|---|
| 108 | binEdges = dpsManip.getBinEdges(hGen)
|
|---|
| 109 | dGenScaled = dpsManip.getScaledDPS(hGen,
|
|---|
| 110 | scale/detector.sourceDetectorVolume,
|
|---|
| 111 | df,
|
|---|
| 112 | dname + "GenScaled")
|
|---|
| 113 | dGenLethScaled = dpsManip.dLogWeightDPS(dGenScaled, df,
|
|---|
| 114 | dname + "gen, df_dlgE",
|
|---|
| 115 | binEdges)
|
|---|
| 116 |
|
|---|
| 117 | return dGenLethScaled
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 | class ExpMcPlot(object):
|
|---|
| 122 | """Prepare and hold source information for a plot.
|
|---|
| 123 |
|
|---|
| 124 | Hold experimental and Monte Carlo data to plot in one diagram.
|
|---|
| 125 | """
|
|---|
| 126 | def __init__(self, shelveName, dist, detType="ring", histo = ""):
|
|---|
| 127 | path = os.path.dirname(shelveName)
|
|---|
| 128 | shelveFile = os.path.basename(shelveName)
|
|---|
| 129 | self.tt = myLiz.tf.create ()
|
|---|
| 130 | self.df = myLiz.af.createDataPointSetFactory (self.tt)
|
|---|
| 131 |
|
|---|
| 132 | self.she = shelve.open(shelveName,"r")
|
|---|
| 133 | xmlFile = self.she["xmlStoreName"]
|
|---|
| 134 | if path:
|
|---|
| 135 | xmlFile = path + "/" + xmlFile
|
|---|
| 136 | self.mcTree = myLiz.tf.create (xmlFile, "xml", 1, 0)
|
|---|
| 137 | self.det = detector.Detector(dist,detType)
|
|---|
| 138 | self.expData = ExperimentalData()
|
|---|
| 139 | self.mcData = MC_Data(self.she, self.mcTree)
|
|---|
| 140 |
|
|---|
| 141 | self.pDataDPS = self.expData.getScaledDataaDPS(self.she,
|
|---|
| 142 | self.det.name,
|
|---|
| 143 | self.df)
|
|---|
| 144 |
|
|---|
| 145 | self.pMcDPS = self.mcData.getScaledMcDPS(atColiExit=1,
|
|---|
| 146 | det=self.det,
|
|---|
| 147 | df=self.df,
|
|---|
| 148 | histo="")
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 | self.pGenDPS = self.mcData.getScaledGeneratedDPS(atColiExit=1,
|
|---|
| 152 | det=self.det,
|
|---|
| 153 | df=self.df,
|
|---|
| 154 | histo="")
|
|---|
| 155 |
|
|---|
| 156 | self.regions = []
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 | def display(self):
|
|---|
| 160 | if "pl" not in dir(myLiz):
|
|---|
| 161 | myLiz.pf = myLiz.af.createPlotterFactory ()
|
|---|
| 162 | myLiz.pl = myLiz.pf.create()
|
|---|
| 163 | region = myLiz.pl.currentRegion()
|
|---|
| 164 | self.regions.append(region)
|
|---|
| 165 | region.plot (self.pDataDPS,"markers overlay")
|
|---|
| 166 | region.plot (self.pMcDPS,"markers overlay")
|
|---|
| 167 | myLiz.pl.refresh ()
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|