asalzburger / sms2023-flag

0 stars 1 forks source link

Bottom up OpenDataDetector #9

Open asalzburger opened 1 year ago

asalzburger commented 1 year ago

The idea is to build a single layer of the Open Data Detector first and run it through material recording and mapping in ACTS.

This can be done by modifying three files: https://cernbox.cern.ch/index.php/s/rW4ECrrgI7KoE6F

The result should be this:

Screenshot 2023-07-20 at 16 06 40

The command to run the display is actually:

geoPluginRun -input <path_to_odd>/OpenDataDetector/xml/OpenDataDetector.xml  -interactive -plugin DD4hep_GeometryDisplay -level 8

For visual inspection.

Step by step procedure:

geoPlugin

Acts

asalzburger commented 1 year ago

@H4m5t3r - do you need help for these first steps?

H4m5t3r commented 1 year ago

I couldn't get the geoPluginRun tool to run, but Paul helped me so now I will continue with this.

H4m5t3r commented 1 year ago

@asalzburger Could you write some more instructions for the steps? I know the partly commented parts of the file OpenDataDetector.xml are different pixel layers, but I don't know what I'm supposed to do to create a TrackingGeometry before running the file material_recording.py.

asalzburger commented 1 year ago

I will prepare that for you.

asalzburger commented 1 year ago

Please have a look at: sms2023-flag

This implements a python binding method that creates a single layer TrackingGeometry.

 m.def("createSingleCylinderGeometry",
          [](ActsScalar r, ActsScalar hZ, unsigned binsZ,
             unsigned binsPhi) -> std::shared_ptr<Acts::TrackingGeometry> {
            // Create the cylindrical layer bounds, this defines the shape
            // of the single cylinder
            auto cylinderBounds = std::make_shared<CylinderBounds>(r, hZ);

            // Create the cylindrical layer, this creates the cylindrical
            // representation
            auto cylinderLayer = CylinderLayer::create(
                Transform3::Identity(), cylinderBounds, nullptr, 1.);

            // Create the Material proxy for the mapping, this is a description
            // how the material should be binned for the mapping
            BinUtility zPhiUtility = BinUtility(binsZ, -hZ, +hZ, open, binZ);
            zPhiUtility += BinUtility(binsPhi, -M_PI, M_PI, closed, binPhi);
            auto protoMaterial =
                std::make_shared<ProtoSurfaceMaterial>(zPhiUtility);
            cylinderLayer->assignSurfaceMaterial(protoMaterial);

            // Create the cylinder volume bounds
            auto volumeBounds =
                std::make_shared<CylinderVolumeBounds>(0., 2. * r, 1.25 * hZ);

            // Create the layerArray
            auto layerArrayCreator = LayerArrayCreator(
                LayerArrayCreator::Config(),
                getDefaultLogger("LayerArrayCreator", Logging::VERBOSE));
            auto layerArray = layerArrayCreator.layerArray(
                GeometryContext(), {cylinderLayer}, 0, 2. * r, arbitrary, binR);

            // Create the tracking volume, this is the top level container
            // for the geometry
            auto cylindricalVolume = TrackingVolume::create(
                Transform3::Identity(), volumeBounds, nullptr,
                std::move(layerArray), nullptr, {}, "SingleCylinderVolume");

            return std::make_shared<TrackingGeometry>(cylindricalVolume);
          });

This should be all we need.

asalzburger commented 1 year ago

The TrackingGeometry is a simplified geometry model of the actual full 3D geometry as shown on the picture. We model this one as a single cylinder (the radius and half length need to be adjusted), and we give it a grid in z/phi to allow modelling the material in different bins.

If you take this branch, you should be able to run as a first:

Examples/flag_geometry.py which produces some obj files at output.

Screenshot 2023-08-01 at 23 41 51

This is the output of the L1 layer (it will actually produce 3 layers, but layer L0 and L2 are only virtual layers that do not have material).

This layer L1 is the one where we want to map the material from the ODD Pixel barrel onto.

asalzburger commented 1 year ago

You see in the construction that I have already included the option to chose a binning in z and phi for the material.

Now, the next step is to run the material recording for the ODD detector, for this - as a start - we can try to run the material recording from GDML input (if this doesn't work, we'll have to fiddle a little bit with DD4hep).

I have prepared a flag_material_recording.py which should work for this, it requires, however, a GDML file of the layer above, which you have not at hand (yet).

You can produce this directory from running the geoPlugin, by exporting from the root prompt.


salzburg@andimacbookprom1 root % geoPluginRun -input /Users/salzburg/Documents/work/dev/acts-flug/thirdparty/OpenDataDetector/xml/OpenDataDetector.xml  -interactive -plugin DD4hep_GeometryDisplay -level 8

PersistencyIO    INFO  +++ Set Streamer to dd4hep::OpaqueDataBlock
Info in <TGeoManager::TGeoManager>: Geometry default, Detector Geometry created
Info in <TGeoNavigator::BuildCache>: --- Maximum geometry depth set to 100
CompactLoader    INFO  +++ Processing compact file: /Users/salzburg/Documents/work/dev/acts-flug/thirdparty/OpenDataDetector/xml/OpenDataDetector.xml with flag BUILD_DEFAULT
DD4hep           WARN  ++ STD conditions NOT defined by client. NTP defaults taken.
Warning in <TGeoMixture::ComputeDerivedQuantities>: Mixture PE: sum of weights is: 6
Detector         INFO  *********** Created World volume with size: 1000 1000 1000
Info in <TGeoManager::SetTopVolume>: Top volume is world_volume. Master volume is world_volume
Utilities        INFO  +++ setDetectorTypeFlags for detector: Pixels not set.
Compact          INFO  ++ Converted subdetector:Pixels of type DD4hep_SubdetectorAssembly
Compact          INFO  ++ Converted subdetector:PixelEndcapN of type ODDPixelEndcap [tracker]
Compact          INFO  ++ Converted subdetector:PixelBarrel of type ODDPixelBarrel [tracker]
Compact          INFO  ++ Converted subdetector:PixelEndcapP of type ODDPixelEndcap [tracker]
ParametersPlugin INFO  +++ Applying 2 parameters
ParametersPlugin INFO  +++ PixelEndcapN -> layer_pattern: str = PixelEndcapN\d|PixelEndplate
ParametersPlugin INFO  +++ Applying 2 parameters
ParametersPlugin INFO  +++ PixelEndcapP -> layer_pattern: str = PixelEndcapP\d|PixelEndplate
ParametersPlugin INFO  +++ Applying 2 parameters
ParametersPlugin INFO  +++ PixelBarrel -> layer_pattern: str = PixelLayer\d
Info in <TGeoManager::CheckGeometry>: Fixing runtime shapes...
Info in <TGeoManager::CheckGeometry>: ...Nothing to fix
Info in <TGeoManager::CloseGeometry>: Counting nodes...
Info in <TGeoManager::Voxelize>: Voxelizing...
Info in <TGeoManager::CloseGeometry>: Building cache...
Info in <TGeoManager::CountLevels>: max level = 6, max placements = 30
Info in <TGeoManager::CloseGeometry>: 1175 nodes/ 24 volume UID's in Detector Geometry
Info in <TGeoManager::CloseGeometry>: ----------------modeler ready----------------
Detector         INFO  +++ Patching names of anonymous shapes....
   ------------------------------------------------------------------
  | Welcome to ROOT 6.28/04                        https://root.cern |
  | (c) 1995-2022, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for macosxarm64 on May 08 2023, 02:44:07                   |
  | From tags/v6-28-04@v6-28-04                                      |
  | With Apple clang version 14.0.3 (clang-1403.0.22.14.1)           |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------

Info in <TGeoManager::SetVisLevel>: Automatic visible depth disabled
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
geoPluginRun: [   0.958 sec] Executed dd4hep plugin: 'DD4hep_GeometryDisplay' with args (2) :[ -level 8 ]
root [0] gGeoManager->Export("ODD_Pixel_l0.gdml")
H4m5t3r commented 1 year ago

I have gotten to the point where I run the material recording, but it gives me the following error:

(cern_venv) taleiko@lx9-fuxi101:~/builds/acts/Examples/Scripts/Python$ python3 flag_material_recording.py 
15:47:42    Sequencer      INFO      Create Sequencer (single-threaded)
15:47:42    Sequencer      INFO      Add Reader 'EventGenerator'
15:47:42    Sequencer      INFO      -> OutputParticles 'particles_initial':
15:47:42    Sequencer      INFO         flat_set<Particle, detail::CompareParticleId, void>

**************************************************************
 Geant4 version Name: geant4-11-01-patch-01 [MT]   (10-February-2023)
                       Copyright : Geant4 Collaboration
                      References : NIM A 506 (2003), 250-303
                                 : IEEE-TNS 53 (2006), 270-278
                                 : NIM A 835 (2016), 186-225
                             WWW : http://geant4.org/
**************************************************************

G4GDML: Reading 'ODD_Pixel_l0.gdml'...
G4GDML: Reading definitions...
G4GDML: Reading materials...

-------- EEEE ------- G4Exception-START -------- EEEE -------
*** G4Exception : mat031
      issued by : G4Material::AddElementByMassFraction()
For material PE and added element C_elm massFraction= 2 is wrong 

*** Fatal Exception *** core dump ***
 **** Track information is not available at this moment
 **** Step information is not available at this moment

-------- EEEE -------- G4Exception-END --------- EEEE -------

*** G4Exception: Aborting execution ***
Aborted (core dumped)

Am I doing something wrong?

asalzburger commented 1 year ago

Ha! The gdml file was right, sorry I was super confusing - the reason I called he file l0 is just because we only have one pixel layer, this is then translated into L1 of the Acts::TrackingGeometry. However, I see that the material conversion fails, so we will have to go via DD4Hep. I will update the branch.

asalzburger commented 1 year ago

I have updated the recipe to run the material recording directly from DD4hep->DDG4 (direct Geant4 translation) and not from DD4hep->GDML (as this seems to have problems).

asalzburger commented 1 year ago

There are now three files:

Examples/Scripts/Python/flag_dd4hep_geometry.py
Examples/Scripts/Python/flag_material_recording.py
Examples/Scripts/Python/flag_tracking_geometry.py

Please try to run all of them - does this work?

H4m5t3r commented 1 year ago

Yes, now they all work.

H4m5t3r commented 1 year ago

The resulting plot from the material tracking looks like this: odd_geant4_material_tracking

asalzburger commented 1 year ago
asalzburger commented 1 year ago

Note that I have updated the issue and task list above, the next step should be the material mapping, I have also updated the branch accordingly.

H4m5t3r commented 1 year ago

In the part where I have to use flag_tracking_geometry.py, what are the parameters r and hz and where do I adjust them?

Is it the line

trackingGeometry = acts.createSingleCylinderGeometry(34, 400, 100, 36)

?

H4m5t3r commented 1 year ago

Do you use any specific software for viewing the .obj files?

asalzburger commented 1 year ago

Do you use any specific software for viewing the .obj files?

I use MeshLab

asalzburger commented 1 year ago

In the part where I have to use flag_tracking_geometry.py, what are the parameters r and hz and where do I adjust them?

Is it the line

trackingGeometry = acts.createSingleCylinderGeometry(34, 400, 100, 36)

?

I will update the code accordingly with documentation.

asalzburger commented 1 year ago

I will split the new items into a new task. Can you upload your screenshots here for documentation purpose?

H4m5t3r commented 1 year ago

Which screenshots are we talking about here? These ones from after the material recording?

Screenshot from 2023-08-07 10-58-08 Screenshot from 2023-08-07 13-28-00