コード例 #1
0
ファイル: lpcAnalysis.py プロジェクト: epp-warwick/lpcm
class lpcAnalyser(object):
  def __init__(self, filename):
    '''
    Constructor
    '''
    self._parser = lpcAnalysisParser(filename)
    self._initReader()
    self._initResiduals()
    self._initPruner()
    self._setOutputFilename()
    self._initPurity()
  def _initReader(self):
    run_parameters = self._parser.getReadParameters()
    if run_parameters['type'] == 'lpcAnalysisPickleReader':
      self._reader = lpcAnalysisPickleReader(**run_parameters['params'])
    else:
      raise ValueError, 'Specified type of reader is not recognised'
  def _initResiduals(self):
    residual_parameters = self._parser.getResidualsParameters()
    if residual_parameters['type'] == 'LPCResiduals':
      tau_range = residual_parameters['params'].pop('tau_range')
      self._residuals = LPCResiduals(**residual_parameters['params'])
      self._residuals_runner = LPCResidualsRunner(self._residuals, tau_range)
    else:
      raise ValueError, 'Specified type of residuals calculator is not recognised'
  def _initPruner(self):
    pruner_parameters = self._parser.getPrunerParameters()
    if pruner_parameters['type'] == 'lpcCurvePruner':
      self._pruner = lpcCurvePruner(self._residuals_runner, **pruner_parameters['params'])
    else:
      raise ValueError, 'Specified type of residuals calculator is not recognised'
  def _setOutputFilename(self):
    misc = self._parser.getMiscParameters()
    self._output_filename = misc['params']['output_filename']
  
  def _initPurity(self):
    self._purity = LPCPurityCalculator(self._residuals_runner)
  
  def runAnalyser(self):
    out_data = []
    while 1:
      try:
        evt = self._reader.getNextEvent()
        self._residuals.setDataPoints(evt[0]['Xi'])
        self._residuals_runner.setLpcCurves(evt[0]['lpc_curve'])
        self._residuals_runner.calculateResiduals(calc_residuals = False, calc_containment_matrix = False)
        remaining_curves = self._pruner.pruneCurves()
        #muon_proton_hits = truth_evt.getParticleHits([13, 2212])
        #eff = LPCEfficiencyCalculator(remaining_curves, evt['data_range'], muon_proton_hits, tau) TODO - move from examples/toytracks 
        voxel_to_pdg_dictionary = evt[1].getParticlesInVoxelDict()
        pur = self._purity.calculatePurity(remaining_curves, evt[0]['data_range'], voxel_to_pdg_dictionary) 
        out_data.append({'voxel_dict': voxel_to_pdg_dictionary, 'pur': pur})
      except EOFError:
        break
    #TODO - factor this out into a class which enters the analysis configuration file
    outfile = open(self._output_filename, 'w')
    cPickle.dump(out_data, outfile, -1)
コード例 #2
0
ファイル: TestLPCResiduals.py プロジェクト: drbenmorgan/lpcm
 def testResidualsRunner(self):
   x = map(lambda x: x + gauss(0,0.005 + 0.3*x*x), arange(-1,1,0.05))
   y = map(lambda x: x + gauss(0,0.005 + 0.3*x*x), arange(-1,1,0.05))
   z = map(lambda x: x + gauss(0,0.005 + 0.3*x*x), arange(-1,1,0.05))
   line = array(zip(x,y,z))
   lpc = LPCImpl(h = 0.2, convergence_at = 0.0001, it = 100, mult = 5)
   lpc_curve = lpc.lpc(X=line)
   residuals_calc = LPCResiduals(line, tube_radius = 0.15)
   residuals_runner = LPCResidualsRunner(lpc.getCurve(), residuals_calc)
   residuals_runner.setTauRange([0.05, 0.07])
   residuals = residuals_runner.calculateResiduals()
   pprint(residuals)
コード例 #3
0
ファイル: lpcAnalysis.py プロジェクト: epp-warwick/lpcm
 def _initResiduals(self):
   residual_parameters = self._parser.getResidualsParameters()
   if residual_parameters['type'] == 'LPCResiduals':
     tau_range = residual_parameters['params'].pop('tau_range')
     self._residuals = LPCResiduals(**residual_parameters['params'])
     self._residuals_runner = LPCResidualsRunner(self._residuals, tau_range)
   else:
     raise ValueError, 'Specified type of residuals calculator is not recognised'
コード例 #4
0
ファイル: toytracks.py プロジェクト: drbenmorgan/lpcm
def LPCEfficiencyCalculator(curves, data_range, particle_hits, tau):
  #first rescale the curves then calculate the proton and muon efficiency
  if data_range is None:
    data_range = 1.0
  muon_hits = array([[h[0][0], h[0][1], h[0][2]] for h in particle_hits[13]]) / data_range
  proton_hits = array([[h[0][0], h[0][1], h[0][2]] for h in particle_hits[2212]]) / data_range
  residuals_calc = LPCResiduals(muon_hits, tube_radius = 0.12)
  residuals_runner = LPCResidualsRunner(curves, residuals_calc)
  residuals_runner.setTauRange([tau])
  muon_residuals = residuals_runner.calculateResiduals(True, False, False)
  muon_coverage = max([len(muon_residuals['curve_residuals'][i]['coverage_indices'][tau]) for i in range(len(curves))])
  muon_efficiency = float(muon_coverage) / len(muon_hits)
  
  residuals_calc.setDataPoints(proton_hits)
  proton_residuals = residuals_runner.calculateResiduals(True, False, False)
  proton_coverage = max([len(proton_residuals['curve_residuals'][i]['coverage_indices'][tau]) for i in range(len(curves))])
  proton_efficiency = float(proton_coverage) / len(proton_hits)
  print 'residuals'
コード例 #5
0
ファイル: toytracks.py プロジェクト: drbenmorgan/lpcm
 '''
 if len(sys.argv) != 2:
   raise ValueError, 'Must supply the name of a configuration file'
 proc = lpcProcessor(sys.argv[1])
 proc.runProcessor()
 metadata_filename = proc.getMetadataFilename()
 lpc_loader = lpcAnalysisPickleReader(metadata_filename)
 #toyLPCPlotter(evt_curves['Xi'], evt_curves['lpc_curve'])
 out_data = []
 while 1:
   try:
     evt = lpc_loader.getEvent()
     #pprint(truth_evt.getParticlesInVoxelDict())
     #now calcualte the residuals
     residuals_calc = LPCResiduals(evt[0]['Xi'], tube_radius = 3.0)
     residuals_runner = LPCResidualsRunner(evt[0]['lpc_curve'], residuals_calc)
     residuals_runner.setTauRange([2.0])
     
     pruner = lpcCurvePruner(residuals_runner, closeness_threshold = 5.0, path_length_threshold = 10.0)
     remaining_curves = pruner.pruneCurves()
     tau = 2.0
     #muon_proton_hits = truth_evt.getParticleHits([13, 2212])
     #eff = LPCEfficiencyCalculator(remaining_curves, evt['data_range'], muon_proton_hits, tau)
     voxel_to_pdg_dictionary = evt[1].getParticlesInVoxelDict()
     pur = LPCPurityCalculator(remaining_curves, evt[0]['data_range'], voxel_to_pdg_dictionary, tau) 
     
     out_data.append({'voxel_dict': voxel_to_pdg_dictionary, 'pur': pur})
     print 'breakpoint'
   except EOFError:
     break