Home Calorimeters E-mail Notes Meetings Subsystems Search

Using the Calo Detector Element interface

The Calorimeter (includes SPD, PS, ECAL, HCAL) is described in terms of DetectorElement. This short note summarize the usage of this object.

1- Get the Detector Element object:

One need to get a 'Smart Pointer' to the wanted calorimeter, starting from the LHCb object. The code looks like:

SmartDataPtr<DetectorElement> cave(detDataService(),"/dd/Structure/LHCb" ); 
if ( !cave ) { ...report problem... } 
SmartDataPtr<DeCalorimeter> ecal( cave, "Ecal" ); 
if( !ecal ) { ...report problem...} 
ecal->buildCells(); 

2- Use this object

Then on can use the cell interface to the Calorimeter, with the following functions:

CaloCellID ID ; // This is not correct, a CaloCellID has to be either initialized 
                // with a value (unfrequent), or is just returned by a method, 
                // like data access method. 

// Center position of a specific cell 
  double x = ecal->cellX( ID ) ; 
  double y = ecal->cellY( ID ) ; 
  double z = ecal->cellZ( ID ) ; 
  HepPoint3D center = ecal->cellCenter( ID ) ; 

// Size of a cell (x or y). Note : The size of a non existent cell is zero. 
  double size = ecal->cellSize( ID ) ; 

// Neighbors of a specified cell
   CaloNeighbors neigh = ecal->neighborCells( ID ) ; 

// Cell ID at a given position
   HepPoint3D globalPoint ; 
   CaloCellID anID = ecal->Cell( globalPoint ) ; 

3- Some examples 

The most delicate is to use the neighbors, at least for first time use of C++ features. The following code fragment loops on all neiughbors of a given cell, and gets the x value of all these cells.

   CaloCellID anID ; // Cell ID obtained by some way 
   for ( CaloNeighbors::const_iterator it = ecal->neighborCells(anID).begin(); 
         it != ecal->neighborCells(anID).end(); it++ ) { 
      CaloCellID neighbor = *it; 
      double x = ecal->cellX( neighbor ); 
   } 

This means that one shoud use an iterator variable, and that the CaloCellID is pointed at by this iterator variable. Note that one can use directly *it at argument to the ecal functions. One can also use a 'while' loop, but with some care for the incrementation of the iterator...

    CaloNeighbors::const_iterator it = ecal->neighborCells(anID).begin(); 
    while ( it != ecal->neighborCells(anID).end() ) {
      CaloCellID neighbor = *it++; 
      ... 
    }