AIDASoft / DD4hep

Detector Description Toolkit for High Energy Physics
http://dd4hep.cern.ch
GNU Lesser General Public License v3.0
49 stars 95 forks source link

MultipoleMagnet quadrupole does not bend charged particles #1115

Closed aciarma closed 1 year ago

aciarma commented 1 year ago

Hi,

I was testing with key4hep the tracking in the magnetic field generated by a MultipoleMagnet element, and it seems like particles are not bent.

I attach a simple setup made of a test beam, a quadrupolar field (quite intense, is the FCCee first final focus quadrupole) the shell of the quadrupole and a screen to see how the particles exit the quadrupole.

Turning on and off the field grants the same result, where the x distribution of the particles is unchanged w.r.t. the start. multipoleFieldTest.zip

I am running on lxplus, sourcing the key4hep nightlies/latest releases.

MarkusFrankATcernch commented 1 year ago

@aciarma Sorry for the late reply, but we first needed to discuss this issue at the DD4hep meeting....

This python setup script you supply is a Gaudi script, which (as far as I know) only invokes the Geant4 geometry conversion. The magnetic field as described in the compact xml is not passed to the Geant4 field tracking (stepper, equation,...). See DDG4/python/DDG4.py: setupTrackingField(...) for how this is done in DDG4/ddsim and how the interaction is done with C++.

Since this field setup is missing, I think unless there is another field definition in Gaudi, Geant4 has no field at all. For this reason the tracks are not bent. If you use Gaudi here, you would have to bent the Gaudi IMagneticFieldSvc implementation to call the DD4hep field implementation and return these field values accordingly.

aciarma commented 1 year ago

Hi Markus,

thank you for the explanation. I thought that the field was imported correctly because I get the message

Compact          INFO  ++ Converted field: Successfully created field QC1L1_field_ED [MultipoleMagnet]

but if I understood correctly this is imported only by DD4hep and not passed down to Gaudi (please correct me if I am wrong).

Could you please give me an example on how to use IMagneticFieldSvc to pass this info to Gaudi?

edit: second question: would the description I gave you work in plain ddsim?

MarkusFrankATcernch commented 1 year ago

I have no example for embedding dd4hep fields into Gaudi (or the reverse). To pass DD4hep fields to Gaudi:

Beware of units!

aciarma commented 1 year ago

I see, but I dont know if I have the time to put my head on developing this feature...

Do you think the field definition I used would work if I use ddsim instead of Gaudi?

  <fields>
    <field name="QC1L1_field_ED" type="MultipoleMagnet" Z="0.0*tesla">
        <position y="0*cm" x="(QC1L1_len/2. + QC1L1_start)" z="0*cm"/>
        <rotation x="0.0" y="0.0" z="0.0"/>
        <coefficient coefficient="0*tesla"/>
        <coefficient coefficient="(-1)*(45.6)*(-0.273)/0.3*tesla/m"/>
        <shape type="Tube" rmin="0.*cm" rmax="QC1_rmin" dz="QC1L1_len/2." />
    </field>
  </fields>
MarkusFrankATcernch commented 1 year ago

Would work. (did not check the coefficient values though!). ddsim does the proper setup of the Geant4 field to support the tracking in Geant4.

But be aware: you must be able to produce the correct output, so that aftwerwards you can do the digitization, reconstruction etc.

aciarma commented 1 year ago

Ok so I might want to give it a try!

I never used ddsim tho, so I dont even have some template steering file I can use. Could you please point me to something I can start from? This would help me a lot (also for my other issue on the world volume :D )

Again, thank you very much for the help

MarkusFrankATcernch commented 1 year ago

Andre is holiday.... @tmadlener Thomas, do you know how to do this?

tmadlener commented 1 year ago

From a quick glance at your steering file it looks like this sould be straight forward to use with ddsim, something along the lines of:

ddsim --enableGun -N 1 \
  --gun.particle e+ --gun.mulitplicity 1000 \
  --compactFile simple_test_field.xml \
  --outputFile output.edm4hep.root

You will have to make sure the the included materials and elements files are using the correct paths, either relative from where you call ddsim or absolute. I tried this locally, and it seems to at least start up, but you reference an additional_materials.xml file that I don't have.

You probably also want to make sure that the particle gun shoots into a direction that is actually meaningful instead of just shooting 1000 random positrons.

aciarma commented 1 year ago

Ok I'll try this, thank you! Eventually I'll need to feed an input file for the particles to shoot (as I do in the steering file). Is it possible in ddsim?

tmadlener commented 1 year ago

In principle ddsim supports a few input formats:

 --inputFiles INPUTFILES [INPUTFILES ...], -I INPUTFILES [INPUTFILES ...]
                        InputFiles for simulation .stdhep, .slcio, .HEPEvt, .hepevt, .pairs, .hepmc, .hepmc.gz, .hepmc.xz, .hepmc.bz2, .hepmc3, .hepmc3.gz, .hepmc3.xz, .hepmc3.bz2, .hepmc3.tree.root files are supported

you would then have to remove the --enableGun, and the --gun.xxx parameters

aciarma commented 1 year ago

Maybe I am sourcing the wrong environment, because if I try a simple

ddsim --compactFile /path/to/mygeom.xml --runType shell

I get few errors terminating with

ImportError: Failed to import libcppyy3_10. Please check that ROOT has been built for Python 3.10

which does not seem to be related to ddsim itself, but rather the environment.

Is there on lxplus a working installation of ddsim I can source to? Now I am sourcing latest/nightlies of key4hep but none is working.

p.s. sorry if this went a bit off-topic. If I need to take the discussion elsewhere please tell me

tmadlener commented 1 year ago

I am not entirely sure what the issue is in your case but I could run this with an ILD compact file on CentOS7 and AlmaLinux9. My best guess would be to try again in a clean shell and then sourcing the key4hep nightlies (/cvmfs/sw-nightlies.hsf.org/key4hep/setup.sh)

aciarma commented 1 year ago

Hi @tmadlener , thank you it did indeed work with an ILD file ($lcgeo_DIR/ILD/compact/ILD_l6_v02/ILD_l6_v02.xml).

It does instead fail if I try to use CLD ($FCCDETECTORS/Detector/DetFCCeeCLD/compact/FCCee_o2_v02/FCCee_o2_v02.xml). I am trying to understand why.