LDMX-Software / ldmx-sw

The Light Dark Matter eXperiment simulation and reconstruction framework.
https://ldmx-software.github.io
GNU General Public License v3.0
22 stars 20 forks source link

TaggerVetoFilter inefficiency #1146

Closed tomeichlersmith closed 1 year ago

tomeichlersmith commented 1 year ago

Description

This was initially observed when studying the signal generation using this filter. What I observed through some extra debug printouts (and using the StepPrinter user action) was that the primary electron was not entering the target region. This did not "activate" the TargetDarkBremFilter which means it did not know to veto the event. The primary electron was found with $p_z < 0$ and $z < 0$ at its end point, so I think something caused the primary electron to back-scatter. We still see a near-beam-energy total reconstructed energy in the ECal however, so particles are still reaching it.

Initial Hypothesis

Various small scatters bend the primary electron into the magnet which causes a much harder scatter (perhaps electron-nuclear or perhaps just a hard brem). The non-primary products of this hard scatter continue downstream into the ECal while the primary electron recoils back, avoiding the target and thus the TargetDarkBremFilter.

Additional context

https://github.com/LDMX-Software/ldmx-sw/issues/1138#issuecomment-1376305770 https://github.com/LDMX-Software/ldmx-sw/issues/1139

Plan

EinarElen commented 1 year ago

While working on https://github.com/LDMX-Software/SimCore/issues/86, I ran into https://github.com/LDMX-Software/ldmx-sw/issues/1069 quite a lot which really made validating developments hard. Since I was already messing with the photonNuclear process, I decided to try removing the PN process entirely to see what would happen. To my surprise, after 3204 aborted attempts the event passes the filters. I'm presuming this is related to this issue.

Gamma physics change to try this:

void GammaPhysics::ConstructProcess() {
  aParticleIterator->reset();

  // Loop through all of the particles and find the "gamma".
  while ((*aParticleIterator)()) {
    G4ParticleDefinition *particle = aParticleIterator->value();
    G4ProcessManager *pmanager = particle->GetProcessManager();
    G4String particleName = particle->GetParticleName();

    if (particleName == "gamma") {
      // Get the process list associated with the gamma.
      G4ProcessVector *vProcess = pmanager->GetProcessList();

      // Search the list for the process "photoNuclear".  When found,
      // change the calling order so photonNuclear is called before
      // EM processes. The biasing operator needs the photonNuclear
      // process to be called first because the cross-section is
      // needed to bias down other process.
      for (int iProcess = 0; iProcess < vProcess->size(); ++iProcess) {
        G4String processName = (*vProcess)[iProcess]->GetProcessName();
        if (processName == "photonNuclear") {
          pmanager->RemoveProcess(iProcess);
          // pmanager->SetProcessOrderingToFirst((*vProcess)[iProcess],
          //                                     G4ProcessVectorDoItIndex::idxAll);
        }
      }

      // Add the gamma -> mumu to the physics list.
      pmanager->AddDiscreteProcess(&gammaConvProcess);
    }
  }
}

With the config below:

#!/bin/python
from LDMX.Framework import ldmxcfg
det = 14
run = 1
maxEvents = 5
thisPassName = "sim"
detector=f'ldmx-det-v{det}'
p = ldmxcfg.Process(thisPassName)

p.maxEvents = maxEvents
p.maxTriesPerEvent = 100000000000

#import LDMX.SimCore.photonuclear_models as pns
from LDMX.Biasing import ecal
from LDMX.DQM import dqm
from LDMX.SimCore import generators as gen
import LDMX.Ecal.EcalGeometry
import LDMX.Ecal.ecal_hardcoded_conditions
import LDMX.Hcal.HcalGeometry
import LDMX.Hcal.hcal_hardcoded_conditions
from LDMX.SimCore import simulator
from LDMX.Biasing import filters
from LDMX.Biasing import util
from LDMX.Biasing import include as includeBiasing

sim = simulator.simulator('ie')
sim.setDetector(f'ldmx-det-v{det}')

sim.generators = [gen.single_4gev_e_upstream_tagger()]
sim.beamSpotSmear = [20., 80., 0.] #mm
includeBiasing.library()
sim.actions.extend([
    filters.TaggerVetoFilter(),
    # Only consider events where a hard brem occurs
    filters.TargetBremFilter(),
    # Only consider events where a PN reaction happnes in the ECal
    filters.EcalProcessFilter(),
    # Tag all photo-nuclear tracks to persist them to the event.
    util.TrackProcessFilter.photo_nuclear(),
    util.StepPrinter()
])

p.run = run

p.outputFiles = ['PNtest.root']
p.histogramFile = 'PNtesthist.root'
p.logFrequency = 1
p.termLogLevel = 2
p.sequence = [sim, dqm.PhotoNuclearDQM()]

you can reproduce the issue. So, looks like your hypothesis might be right.

StepPrinter details: ``` Starting attempt 3203... Starting attempt 3203... Step 1 { Energy: 4000.51 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: trigger_pad1_bar_volume_PV Weight: 1 Children: } Step 2 { Energy: 10.2733 Track ID: 1 Particle currently in: trigger_pad1_bar_volume_PV Region: trig_scint Next volume: trigger_pad1_bar_volume_PV Weight: 1 Children: 22 } Step 3 { Energy: 10.2208 Track ID: 1 Particle currently in: trigger_pad1_bar_volume_PV Region: trig_scint Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 4 { Energy: 10.2208 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 5 { Energy: 10.2208 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 6 { Energy: 10.2208 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: trigger_pad1_bar_volume_PV Weight: 1 Children: } Step 7 { Energy: 9.86443 Track ID: 1 Particle currently in: trigger_pad1_bar_volume_PV Region: trig_scint Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 8 { Energy: 9.86443 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: trigger_pad1_bar_volume_PV Weight: 1 Children: } Step 9 { Energy: 9.68465 Track ID: 1 Particle currently in: trigger_pad1_bar_volume_PV Region: trig_scint Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 10 { Energy: 9.68465 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 11 { Energy: 9.68465 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 12 { Energy: 9.68465 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 13 { Energy: 9.68465 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 14 { Energy: 9.68465 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: trigger_pad1_bar_volume_PV Weight: 1 Children: } Step 15 { Energy: 9.30644 Track ID: 1 Particle currently in: trigger_pad1_bar_volume_PV Region: trig_scint Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 16 { Energy: 9.30644 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: trigger_pad1_bar_volume_PV Weight: 1 Children: } Step 17 { Energy: 9.0181 Track ID: 1 Particle currently in: trigger_pad1_bar_volume_PV Region: trig_scint Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 18 { Energy: 9.0181 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 19 { Energy: 9.0181 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 20 { Energy: 9.0181 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: trigger_pad1_bar_volume_PV Weight: 1 Children: } Step 21 { Energy: 8.58878 Track ID: 1 Particle currently in: trigger_pad1_bar_volume_PV Region: trig_scint Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 22 { Energy: 8.58878 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: trigger_pad1_bar_volume_PV Weight: 1 Children: } Step 23 { Energy: 8.26831 Track ID: 1 Particle currently in: trigger_pad1_bar_volume_PV Region: trig_scint Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 24 { Energy: 8.26831 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 25 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 26 { Energy: 8.26831 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 27 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 28 { Energy: 8.26831 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 29 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 30 { Energy: 8.26831 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 31 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 32 { Energy: 8.26831 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 33 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 34 { Energy: 8.26831 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 35 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 36 { Energy: 8.26831 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 37 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 38 { Energy: 8.26831 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 39 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 40 { Energy: 8.26831 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 41 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 42 { Energy: 8.26831 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 43 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 44 { Energy: 8.26831 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 45 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 46 { Energy: 8.26831 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 47 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 48 { Energy: 8.26831 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 49 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 50 { Energy: 8.26831 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 51 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 52 { Energy: 8.26831 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 53 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 54 { Energy: 8.26831 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 55 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: ldmx_magnet_PV Weight: 1 Children: } Step 56 { Energy: 8.26831 Track ID: 1 Particle currently in: ldmx_magnet_PV Region: MagnetRegion Next volume: World_PV Weight: 1 Children: } Step 57 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 58 { Energy: 8.26831 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 59 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: ldmx_magnet_PV Weight: 1 Children: } Step 60 { Energy: 8.26831 Track ID: 1 Particle currently in: ldmx_magnet_PV Region: MagnetRegion Next volume: World_PV Weight: 1 Children: } Step 61 { Energy: 8.26831 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: trig_scint_tagger_PV Weight: 1 Children: } Step 62 { Energy: 8.2683 Track ID: 1 Particle currently in: trig_scint_tagger_PV Region: trig_scint Next volume: World_PV Weight: 1 Children: } Step 63 { Energy: 8.2683 Track ID: 1 Particle currently in: World_PV Region: DefaultRegionForTheWorld Next volume: ldmx_magnet_PV Weight: 1 Children: } Step 64 { Energy: 8.2683 Track ID: 1 Particle currently in: ldmx_magnet_PV Region: MagnetRegion Next volume: shim_right_PV Weight: 1 Children: } Step 65 { Energy: 8.0327 Track ID: 1 Particle currently in: shim_right_PV Region: MagnetRegion Next volume: shim_right_PV Weight: 1 Children: 22 } Step 66 { Energy: 7.84064 Track ID: 1 Particle currently in: shim_right_PV Region: MagnetRegion Next volume: shim_right_PV Weight: 1 Children: 22 } Step 67 { Energy: 7.35024 Track ID: 1 Particle currently in: shim_right_PV Region: MagnetRegion Next volume: shim_right_PV Weight: 1 Children: 22 } Step 68 { Energy: 6.04606 Track ID: 1 Particle currently in: shim_right_PV Region: MagnetRegion Next volume: shim_right_PV Weight: 1 Children: } Step 69 { Energy: 5.69689 Track ID: 1 Particle currently in: shim_right_PV Region: MagnetRegion Next volume: shim_right_PV Weight: 1 Children: 22 } Step 70 { Energy: 5.03528 Track ID: 1 Particle currently in: shim_right_PV Region: MagnetRegion Next volume: shim_right_PV Weight: 1 Children: } Step 71 { Energy: 4.4176 Track ID: 1 Particle currently in: shim_right_PV Region: MagnetRegion Next volume: shim_right_PV Weight: 1 Children: } Step 72 { Energy: 3.69235 Track ID: 1 Particle currently in: shim_right_PV Region: MagnetRegion Next volume: shim_right_PV Weight: 1 Children: } Step 73 { Energy: 3.09606 Track ID: 1 Particle currently in: shim_right_PV Region: MagnetRegion Next volume: shim_right_PV Weight: 1 Children: } Step 74 { Energy: 2.47338 Track ID: 1 Particle currently in: shim_right_PV Region: MagnetRegion Next volume: shim_right_PV Weight: 1 Children: } Step 75 { Energy: 1.80446 Track ID: 1 Particle currently in: shim_right_PV Region: MagnetRegion Next volume: shim_right_PV Weight: 1 Children: } Step 76 { Energy: 1.14288 Track ID: 1 Particle currently in: shim_right_PV Region: MagnetRegion Next volume: shim_right_PV Weight: 1 Children: } Step 77 { Energy: 0.559607 Track ID: 1 Particle currently in: shim_right_PV Region: MagnetRegion Next volume: shim_right_PV Weight: 1 Children: 22 } Step 78 { Energy: 0.510999 Track ID: 1 Particle currently in: shim_right_PV Region: MagnetRegion Next volume: shim_right_PV Weight: 1 Children: } ```

As a really dumb way to test that this is the issue, I went ahead and added a global (through the run manager) that was set to false at the start of each event which was set to true if we reached the relevant part of the filter and then just aborted the event in the simulator if it wasn't touched. Obviously, this isn't a solution but it does patch both this and the next events that would have failed for the same reason (at the fourth one, the step printer crashes but... that's a different issue).

EinarElen commented 1 year ago

A simple, albeit not very elegant, solution to this is to make the TaggerVetoFilter an EVENT action as well as a STEPPING action, add a field to the event info which corresponds to whether or not we ever entered the tagger region with the primary that we set in the stepping action and then in the EndOfEventAction just checking this and aborting if it fails. I ran 1000000 such events without a PN process and it worked without issue.

EinarElen commented 1 year ago

Interestingly, this still isn't enough to fix https://github.com/LDMX-Software/ldmx-sw/issues/1069... However, that issue seems to be unrelated, it can fail even when the PN products are present in the output :(