Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pandora plugin to calculate material properties of calorimeters dynamically #432

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

SwathiSasikumar
Copy link
Contributor

BEGINRELEASENOTES

  • PandoraPFA uses LayeredCalorimeterData class from DD4hep to store layer-by-layer information e.g radiation length., essential for shower reconstruction and energy measurement.
  • In this plugin, using another class from DD4hep, MaterialManager, LayeredCalorimeterData object is dynamically built based on the detector geometry ensuring each calorimeter layer correctly reflects its material composition.
  • This plugin can be used for any calorimeter irrespective of its geometry. It is essential to have LayeredCalorimeterData information to run Pandora.
  • The changes in the geometry source file ECalBarrel_NobleLiquid_InclinedTrapezoids_o1_v01_geo.cpp and xml file CLD_o4_v05.xml should also be noted to accommodate the plugin.
    ENDRELEASENOTES

Copy link
Collaborator

@atolosadelgado atolosadelgado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @SwathiSasikumar

Thank you for your PR! It is well-written.

I have one question: Would it be possible or advisable for the plugin to erase any previous data extension? If so, this can be done by adding a few lines I mentioned in the comments, and the detector constructor can be unstaged from the PR

Thank you for your time!

caloData->extent[2] = 0.0; // Barrel-specific value
caloData->extent[3] = half_length;

caloDetElem.addExtension<dd4hep::rec::LayeredCalorimeterData>(caloData);
Copy link
Collaborator

@atolosadelgado atolosadelgado Feb 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you move this line after the print out "Successfully added LayeredCalorimeterData", at the end of the function?

In addition, to be discussed... do you think it is acceptable/advisable to remove any data extension attached by the detector constructor itself? If so, it can be done as follows:

    if( ! caloDetElem->extensions.empty()) {
      dd4hep::printout(PrintLevel::WARNING, LOG_SOURCE, "Removing data extensions from %s", subDetectorName.c_str());
     // delete extensions first, then clear container
     for (auto& p : caloDetElem->extensions) {
         delete p.second;
     }
      caloDetElem->extensions.clear();
    }

This also requires an additional header:

#include <DD4hep/detail/DetectorInterna.h>

This way, the plugin becomes more robust against potential cases where other data extension is hardcoded in the detector constructor (if a previous data extension exists, DD4hep crashes)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this cause a memory leak?

      caloDetElem->extensions.clear();

Copy link
Collaborator

@atolosadelgado atolosadelgado Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you are right, thank you for spotting it!
I changed my suggestion in the original message

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... do you think it is acceptable/advisable to remove any data extension attached

Actually, it is not advisable to remove all extensions. It might make sense to remove the extension of the type we add here. It might also make sense to throw an error and let the user figure out which extension they want to keep. Maybe add a flag to replace or not an existing extension.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add a convenience function in dd4hep to make it easier to remove specific extensions. This issue brought up here will be addressed in a later PR then.

dd4hep::rec::Vector3D ivr1 = dd4hep::rec::Vector3D(0., rad_first, 0); // defining starting vector points of the given layer
dd4hep::rec::Vector3D ivr2 = dd4hep::rec::Vector3D(0., rad_last, 0); // defining end vector points of the given layer

const dd4hep::rec::MaterialVec &materials = matMgr.materialsBetween(ivr1, ivr2); // calling material manager(MM) to get material info between two points
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think it would be good idea to protect against empty vectors?

// skip layer if no materials found
if( materials.empty() ) continue;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think unless rad_first == rad_last it is impossible for there to be no materials between two points? There must at least be the world volume. Or something is more wrong in the geometry than we can protect against here.

@SwathiSasikumar SwathiSasikumar force-pushed the New_PandoraPlugin branch 2 times, most recently from 194a422 to 20b9dfa Compare February 26, 2025 13:49
…levant changes in the xml file to acoomodate the plugin. The layeredCalorimeter information from ECalBarrel_NobleLiquid_InclinedTrapezoids_o1_v01_geo.cpp is removed to accomodate the new plugin
…rheight for calolayer extension instead of scaling back and forth

align some code with the plugin code as well
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants