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

HCal readout segmentation update #409

Merged
merged 19 commits into from
Dec 3, 2024
Merged

HCal readout segmentation update #409

merged 19 commits into from
Dec 3, 2024

Conversation

Archil-AD
Copy link
Contributor

@Archil-AD Archil-AD commented Nov 9, 2024

BEGINRELEASENOTES

  • HCalBarrel_TileCal_v03.xml and HCalEndcaps_ThreeParts_TileCal_v03.xml files have been created with new readouts: phi-theta and phi-row segmentation
  • Two new segmentation classes are created for HCal: FCCSWHCalPhiTheta_k4geo and FCCSWHCalPhiRow_k4geo
    • New segmentation classes can calculate the global positions of the cells and determine the cell neighbours for TopoClustering

ENDRELEASENOTES

@atolosadelgado
Copy link
Collaborator

atolosadelgado commented Nov 26, 2024

Hi @Archil-AD

Thank you for this PR!

I check that it runs in version 3 and 4 of ALLEGRO. Also I noticed that the corresponding test for ALLEGRO version 04 is missing, could you add these lines in the file test/CMakeLists.txt, after the test for ALLEGRO v03?

#--------------------------------------------------
# test for ALLEGRO o1 v04
if(DCH_INFO_H_EXIST)
SET( test_name "test_ALLEGRO_o1_v04" )
ADD_TEST( t_${test_name} "${CMAKE_INSTALL_PREFIX}/bin/run_test_${PackageName}.sh"
  ddsim --compactFile=${CMAKE_CURRENT_SOURCE_DIR}/../FCCee/ALLEGRO/compact/ALLEGRO_o1_v04/ALLEGRO_o1_v04.xml --runType=batch -G -N=1 --outputFile=testALLEGRO_o1_v04.root --gun.direction "1,1.2,0.2" )
SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION  " Exception;EXCEPTION;ERROR;Error" )
endif()

I have specified a random direction --gun.direction "1,1.2,0.2", but you can specify any other you consider better suited (I think default direction is the Z axis, which is not very useful to test when a particle crosses a detector).

Thank you for your time.

Best,
Alvaro

@Archil-AD
Copy link
Contributor Author

Hi @Archil-AD

Thank you for this PR!

I check that it runs in version 3 and 4 of ALLEGRO. Also I noticed that the corresponding test for ALLEGRO version 04 is missing, could you add these lines in the file test/CMakeLists.txt, after the test for ALLEGRO v03?

#--------------------------------------------------
# test for ALLEGRO o1 v04
if(DCH_INFO_H_EXIST)
SET( test_name "test_ALLEGRO_o1_v04" )
ADD_TEST( t_${test_name} "${CMAKE_INSTALL_PREFIX}/bin/run_test_${PackageName}.sh"
  ddsim --compactFile=${CMAKE_CURRENT_SOURCE_DIR}/../FCCee/ALLEGRO/compact/ALLEGRO_o1_v04/ALLEGRO_o1_v04.xml --runType=batch -G -N=1 --outputFile=testALLEGRO_o1_v04.root --gun.direction "1,1.2,0.2" )
SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION  " Exception;EXCEPTION;ERROR;Error" )
endif()

I have specified a random direction --gun.direction "1,1.2,0.2", but you can specify any other you consider better suited (I think default direction is the Z axis, which is not very useful to test when a particle crosses a detector).

Thank you for your time.

Best, Alvaro

Hi @atolosadelgado ,
thanks a lot. I have added this test.
Best regards,
Archil

@BrieucF
Copy link
Contributor

BrieucF commented Nov 27, 2024

Hi Archil, the test crash because there is a check that two files with the same name can not have different content. In this particular case, I actually don't see why they should have different contents (HCalBarrel_TileCal_v03.xml and HCalEndcaps_ThreeParts_TileCal_v03.xml in ALLEGRO v03 and ALLEGRO v04). Can you check? By the way, for now, in ALLEGRO v04 (which is still under preparation), files that were not modified have been set as symlinks.

@Archil-AD
Copy link
Contributor Author

Hi Archil, the test crash because there is a check that two files with the same name can not have different content. In this particular case, I actually don't see why they should have different contents (HCalBarrel_TileCal_v03.xml and HCalEndcaps_ThreeParts_TileCal_v03.xml in ALLEGRO v03 and ALLEGRO v04). Can you check? By the way, for now, in ALLEGRO v04 (which is still under preparation), files that were not modified have been set as symlinks.

Hi Brieuc, I found that the difference between ALLEGRO v03 vs ALLEGRO v04 was "PhiRow" vs "RowPhi" in the readout name. Now I have created the symlinks of HCalBarrel_TileCal_v03.xml and HCalEndcaps_ThreeParts_TileCal_v03.xml in ALLEGRO v04 from ALLEGRO v03).
many thanks,
Best regards,
Archil

Copy link
Contributor

@giovannimarchiori giovannimarchiori left a comment

Choose a reason for hiding this comment

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

Hello @Archil-AD

thanks a lot for this extremely useful contribution!
I added some suggestions to the phi-row segmentation but similar ones apply to the phi-theta class.
I would suggest:

  • in the top of the .h files to add a bit more of general documentation on the segmentation (maybe pointing also to your presentation on that, but as much as possible self-contained)
  • in the .h files, expand a bit the comments
  • replace hardcoded "row" or "layer" with m_rowID, m_layerID
  • to make the code a bit more generic so that it could work also with a 2-part endcap for instance, or even a 1-part endcap, introducing one more parameter that acts as a switch between barrel and endcap, rather than relying on the number of parts to decide if a system is barrel or endcap

Thanks again, cheers,
Giovanni

*/
inline double offsetPhi() const { return m_offsetPhi; }

/** Get the vector of theta bins (cells) in a give layer.
Copy link
Contributor

Choose a reason for hiding this comment

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

give -> given

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

std::vector<uint64_t> neighbours(const CellID& cID, bool aDiagonal) const;

/** Calculate layer radii and edges in z-axis, then define cell edges in each layer using defineCellEdges().
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

might help to state which member variables are calculated/updated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

* Logic:
* 1) Find theta bin centers that fit within the given layer;
* 2) Define a cell edge in z-axis as the middle of each pair of theta bin centers
* @param[in] layer index
Copy link
Contributor

Choose a reason for hiding this comment

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

might help to state which member variables are calculated/updated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

inline int phiBins() const { return m_phiBins; }

/** Get the coordinate offset in azimuthal angle.
* return The offset in phi.
Copy link
Contributor

Choose a reason for hiding this comment

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

is that the phi coordinate of the center or edge of the cell with phiID = 0? might help to clarify here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's a center. Now this is mentioned.

}

/** Get the coordinate offset in z-axis.
* return The offset in z.
Copy link
Contributor

Choose a reason for hiding this comment

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

can you please write why this is a vector (what is being indexed? layer?) and how is the offset defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the following:
* Offset is the middle position of the Barrel or each section of the Endcap.
* For the Barrel, the vector size is 1, while for the Endcap - number of section.

// get the row number from volumeID (starts from 0!)
int nrow = _decoder->get(vID, "row");
// get the layer number from volumeID
uint layer = _decoder->get(vID,"layer");
Copy link
Contributor

Choose a reason for hiding this comment

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

"layer"->m_layerID (if you add it)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

_decoder->set(cID, m_rowID, idx);
_decoder->set(cID, m_phiID, positionToBin(dd4hep::DDSegmentation::Util::phiFromXYZ(globalPosition), 2 * M_PI / (double)m_phiBins, m_offsetPhi));

// For endcap, the volume ID comes with "type" field information which would screw up the topo-clustering,
Copy link
Contributor

Choose a reason for hiding this comment

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

aren't HCAL barrel and endcap already differentiated by system ID? Is type set to something different from 0 elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, they are already differentiated by systemID.
The "type" is set different from zero in the geo builder:
https://github.com/key4hep/k4geo/blob/main/detector/calorimeter/HCalThreePartsEndcap_o1_v02_geo.cpp#L242

I am not sure if it is used elsewhere, it was already like that and I did not touched it.
I guess this field is set to differentiate different parts of the endcap.

std::vector<int> maxLayerIdEndcap = {-1, 0, 0};
if(m_offsetZ.size() > 1)
{
uint Nl = m_numLayers.size()/3;
Copy link
Contributor

Choose a reason for hiding this comment

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

again, hardcoded 3 ..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed. the code is generalized for N-parts endcap

if(m_radii.empty()) return minMaxLayerId;


std::vector<int> minLayerIdEndcap = {0, 0, 0};
Copy link
Contributor

Choose a reason for hiding this comment

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

the vectors have size=3 because you assume at most 3 parts, right? this could be generalised

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed. the code is generalized for N-parts endcap

int minLayerId = -1;
int maxLayerId = -1;

int currentLayerId = _decoder->get(cID,"layer");
Copy link
Contributor

Choose a reason for hiding this comment

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

m_layerID?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@Archil-AD
Copy link
Contributor Author

Hello @giovannimarchiori ,

many thanks for your comments. I have tried to implement them in the last commit.

Best regards,
Archil


auto pos = positionFromRThetaPhi(radius, theta(cID), phi(cID));

// retrun the position with corrected z corrdinate to match to the geometric center
Copy link
Contributor

Choose a reason for hiding this comment

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

return

Copy link
Contributor

Choose a reason for hiding this comment

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

coordinate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@giovannimarchiori
Copy link
Contributor

Hello @Archil-AD
thanks a lot for all the changes you made, the code looks very good to me. May I ask you one last thing, to also comment the xml files? In particular for the endcap, which is not self-explanatory, it would help if you could add a few comments inline to explain the format of the various rows and what they define.
Thanks a lot!
Cheers,
Giovanni

@Archil-AD
Copy link
Contributor Author

Hello @Archil-AD thanks a lot for all the changes you made, the code looks very good to me. May I ask you one last thing, to also comment the xml files? In particular for the endcap, which is not self-explanatory, it would help if you could add a few comments inline to explain the format of the various rows and what they define. Thanks a lot! Cheers, Giovanni

Hi @giovannimarchiori ,
I have tried to add some description in the xml files.
Best regards,
Archil


if(m_detLayout==0) dd4hep::printout(dd4hep::INFO, "FCCSWHCalPhiRow_k4geo","Barrel configuration found!");
else dd4hep::printout(dd4hep::INFO, "FCCSWHCalPhiRow_k4geo","EndCap configuration found!");

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense here to add some sanity checks of the xml:

  • m_offsetZ.size()==m_offsetR.size()
  • m_dRlayer.size()==m_offsetR.size()
  • m_widthZ.size()==m_offsetR.size()
  • m_offsetZ.size()==1 if barrel
  • m_numLayers.size() % m_offsetZ.size() == 0
  • m_gridSizeRow.size() == sum of contents of m_numLayers
    ?
    And similarly for the FCCSWCHCalPhiRow_k4geo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed, that would help to debug if someone will try to update the xml files.
I have added it.

@giovannimarchiori
Copy link
Contributor

Hello @Archil-AD thanks a lot for all the changes you made, the code looks very good to me. May I ask you one last thing, to also comment the xml files? In particular for the endcap, which is not self-explanatory, it would help if you could add a few comments inline to explain the format of the various rows and what they define. Thanks a lot! Cheers, Giovanni

Hi @giovannimarchiori , I have tried to add some description in the xml files. Best regards, Archil

Excellent! The description is very useful.
I left one last comment about checking that the vectors in the xml have proper sizes, that's it from my side!
Cheers,
Giovanni

// check if all necessary variables are available
if(m_detLayout==-1 || m_offsetZ.empty() || m_widthZ.empty() || m_offsetR.empty() || m_numLayers.empty() || m_dRlayer.empty())
{
dd4hep::printout(dd4hep::ERROR, "FCCSWHCalPhiRow_k4geo","Please check the readout description in the XML file!\n%s",
Copy link
Contributor

Choose a reason for hiding this comment

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

should be PhiTheta... also in following if (..) blocks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for spotting that, I have fixed it

@giovannimarchiori
Copy link
Contributor

OK for me, thanks again!

Copy link
Contributor

@giovannimarchiori giovannimarchiori left a comment

Choose a reason for hiding this comment

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

Approved from my side

@BrieucF BrieucF merged commit 05a200b into key4hep:main Dec 3, 2024
5 of 6 checks passed
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.

5 participants