Skip to content

Commit

Permalink
Added support of Z segmentation to ZPlanarTracker class
Browse files Browse the repository at this point in the history
  • Loading branch information
bartosik-hep committed May 26, 2020
1 parent 5ecd83a commit 49db3d4
Showing 1 changed file with 99 additions and 85 deletions.
184 changes: 99 additions & 85 deletions detector/tracker/ZPlanarTracker_geo.cpp
Expand Up @@ -43,19 +43,19 @@ using dd4hep::rec::VolPlane;
using dd4hep::rec::volSurfaceList;

static Ref_t create_element(Detector& theDetector, xml_h e, SensitiveDetector sens) {

xml_det_t x_det = e;
std::string name = x_det.nameStr();

// put the whole detector into an assembly
// - should be replaced by an envelope volume ...

Assembly assembly( name+"_assembly" );

DetElement tracker( name, x_det.id() ) ;

PlacedVolume pv;


// for encoding
std::string cellIDEncoding = sens.readout().idSpec().fieldDescription();
Expand Down Expand Up @@ -84,30 +84,30 @@ static Ref_t create_element(Detector& theDetector, xml_h e, SensitiveDetector se
//========= loop over layer elements in xml ======================================

for(xml_coll_t c(e, _U(layer) ); c; ++c) {

xml_comp_t x_layer( c );

// child elements: ladder and sensitive
xml_comp_t x_sensitive( x_layer.child( _U(sensitive) ));
xml_comp_t x_ladder( x_layer.child( _U(ladder) ));

int layer_id = x_layer.id();
int nLadders = x_layer.attr<double>( _Unicode(nLadders) ) ;

double dphi = 2.*M_PI / double(nLadders);

std::string layername = name+_toString(layer_id,"_layer%d");


// --- create an assembly and DetElement for the layer

Assembly layer_assembly( "layer_assembly" +_toString(layer_id,"_%d") );

DetElement layerDE( tracker , _toString(layer_id,"layer_%d"), x_det.id() );

pv = assembly.placeVolume( layer_assembly );

pv.addPhysVolID("layer", layer_id );
pv.addPhysVolID("layer", layer_id );

layerDE.setPlacement( pv ) ;

Expand All @@ -121,16 +121,23 @@ static Ref_t create_element(Detector& theDetector, xml_h e, SensitiveDetector se

std::string supp_vis = x_ladder.visStr() ;
std::string supp_matS = x_ladder.materialStr() ;

double sens_zhalf = x_sensitive.length();
double sens_offset = x_sensitive.offset();
double sens_distance = x_sensitive.distance();
double sens_thickness = x_sensitive.thickness();
double sens_width = x_sensitive.width();
int sens_nmodules = 1;
try {
sens_nmodules = x_sensitive.nmodules();
} catch (const std::exception& e) {
sens_nmodules = 1;
}
double sens_modlength = sens_zhalf*2.0 / sens_nmodules;

std::string sens_vis = x_sensitive.visStr() ;
std::string sens_matS = x_sensitive.materialStr() ;

double phi0 = x_layer.phi0() ;


Expand All @@ -140,27 +147,27 @@ static Ref_t create_element(Detector& theDetector, xml_h e, SensitiveDetector se
if( supp_zhalf < minZhalf ) minZhalf = supp_zhalf ;

//-----------------------------------
// store the data in an extension to be used for reconstruction
// store the data in an extension to be used for reconstruction
ZPlanarData::LayerLayout thisLayer ;

thisLayer.sensorsPerLadder = 1 ; // for now only one planar sensor
thisLayer.lengthSensor = 2. * sens_zhalf ;
thisLayer.sensorsPerLadder = sens_nmodules ;
thisLayer.lengthSensor = sens_modlength ;

thisLayer.distanceSupport = supp_distance ;
thisLayer.offsetSupport = supp_offset ;
thisLayer.thicknessSupport = supp_thickness ;
thisLayer.zHalfSupport = supp_zhalf ;
thisLayer.widthSupport = supp_width ;
thisLayer.distanceSensitive = sens_distance ;
thisLayer.offsetSensitive = sens_offset ;
thisLayer.thicknessSensitive = sens_thickness ;
thisLayer.zHalfSensitive = sens_zhalf ;
thisLayer.widthSensitive = sens_width ;
thisLayer.widthSupport = supp_width ;

thisLayer.distanceSensitive = sens_distance ;
thisLayer.offsetSensitive = sens_offset ;
thisLayer.thicknessSensitive = sens_thickness ;
thisLayer.zHalfSensitive = sens_zhalf ;
thisLayer.widthSensitive = sens_width ;

thisLayer.ladderNumber = nLadders ;
thisLayer.phi0 = phi0 ;

zPlanarData->layers.push_back( thisLayer ) ;
//-----------------------------------

Expand All @@ -170,8 +177,8 @@ static Ref_t create_element(Detector& theDetector, xml_h e, SensitiveDetector se


//-------
Box sens_box( sens_thickness/2., sens_width/2., sens_zhalf );
Box supp_box( supp_thickness/2., supp_width/2., supp_zhalf );
Box sens_box( sens_thickness/2., sens_width/2., sens_modlength/2.0 );

Volume supp_vol( layername+"_supp", supp_box, supp_mat );
Volume sens_vol( layername+"_sens", sens_box, sens_mat );
Expand All @@ -187,19 +194,19 @@ static Ref_t create_element(Detector& theDetector, xml_h e, SensitiveDetector se
// depending on wether the support is above or below the sensor
double inner_thickness = ( sens_distance > supp_distance ? ( sens_distance - supp_distance ) + sens_thickness/2 : sens_thickness/2 ) ;
double outer_thickness = ( sens_distance > supp_distance ? sens_thickness/2 : ( supp_distance - sens_distance ) + supp_thickness - sens_thickness/2 ) ;

SurfaceType type( SurfaceType::Sensitive ) ;

if( isStripDetector )
if( isStripDetector )
type.setProperty( SurfaceType::Measurement1D , true ) ;

VolPlane surf( sens_vol , type , inner_thickness , outer_thickness , u,v,n ) ; //,o ) ;

//--------------------------------------------

sens.setType("tracker");
sens_vol.setSensitiveDetector(sens);

sens_vol.setAttributes( theDetector, x_det.regionStr(), x_det.limitsStr(), sens_vis );
supp_vol.setAttributes( theDetector, x_det.regionStr(), x_det.limitsStr(), supp_vis );

Expand All @@ -209,87 +216,94 @@ static Ref_t create_element(Detector& theDetector, xml_h e, SensitiveDetector se
for(int j=0; j<nLadders; ++j) {

double phi = phi0 + j * dphi ;

std::string laddername = layername + _toString(j,"_ladder%d");

RotationZYX rot( phi , 0, 0 ) ;


// --- place support -----
double lthick = supp_thickness ;
double radius = supp_distance ;
double offset = supp_offset ;

pv = layer_assembly.placeVolume( supp_vol,Transform3D( rot, Position( ( radius + lthick/2. ) * cos(phi) - offset * sin( phi ) ,
( radius + lthick/2. ) * sin(phi) + offset * cos( phi ) ,
0. ) ));


// --- place sensitive -----
lthick = sens_thickness ;
radius = sens_distance ;
offset = sens_offset ;

pv = layer_assembly.placeVolume( sens_vol,Transform3D( rot, Position( ( radius + lthick/2. ) * cos(phi) - offset * sin( phi ) ,
( radius + lthick/2. ) * sin(phi) + offset * cos( phi ) ,
0. ) ));

//--------- loop over sensors ---------------------------
for(int s=0; s<sens_nmodules; ++s) {

pv = layer_assembly.placeVolume( sens_vol,Transform3D( rot, Position( ( radius + lthick/2. ) * cos(phi) - offset * sin( phi ) ,
( radius + lthick/2. ) * sin(phi) + offset * cos( phi ) ,
-sens_zhalf + sens_modlength*(float(s)+0.5) ) ));

// pv.addPhysVolID("layer", layer_id ).addPhysVolID( "module" , j ).addPhysVolID("sensor", 0 ) ;
pv.addPhysVolID( "module" , j ).addPhysVolID("sensor", 0 ) ;


DetElement ladderDE( layerDE , laddername , x_det.id() );
ladderDE.setPlacement( pv ) ;
// pv.addPhysVolID("layer", layer_id ).addPhysVolID( "module" , j ).addPhysVolID("sensor", 0 ) ;
pv.addPhysVolID( "module" , j ).addPhysVolID("sensor", s ) ;

volSurfaceList( ladderDE )->push_back( surf ) ;
std::string sensorname = layername + _toString(j,"_ladder%d") + _toString(s,"_sensor%d");
DetElement sensorDE( layerDE , sensorname , x_det.id() );
sensorDE.setPlacement( pv ) ;

///////////////////
volSurfaceList( sensorDE )->push_back( surf ) ;

//get cellID and fill map< cellID of surface, vector of cellID of neighbouring surfaces >
///////////////////

//encoding
//get cellID and fill map< cellID of surface, vector of cellID of neighbouring surfaces >

encoder[lcio::LCTrackerCellID::side()] = lcio::ILDDetID::barrel;
encoder[lcio::LCTrackerCellID::layer()] = layer_id;
encoder[lcio::LCTrackerCellID::module()] = nLadders;
encoder[lcio::LCTrackerCellID::sensor()] = 0; // there is no sensor defintion in VertexBarrel at the moment
//encoding

dd4hep::long64 cellID = encoder.lowWord(); // 32 bits
encoder[lcio::LCTrackerCellID::side()] = lcio::ILDDetID::barrel;
encoder[lcio::LCTrackerCellID::layer()] = layer_id;
encoder[lcio::LCTrackerCellID::module()] = j;
encoder[lcio::LCTrackerCellID::sensor()] = s;

//compute neighbours
dd4hep::long64 cellID = encoder.lowWord(); // 32 bits

int n_neighbours_module = 1; // 1 gives the adjacent modules (i do not think we would like to change this)
//compute neighbours

int newmodule=0;
int n_neighbours_ladder = 1; // 1 gives the adjacent modules
int n_neighbours_sensor = 1;
int newladder=0;
int newsensor=0;

for(int imodule=-n_neighbours_module; imodule<=n_neighbours_module; imodule++){ // neighbouring modules

if (imodule==0) continue; // cellID we started with
newmodule = nLadders + imodule;

//compute special case at the boundary
//general computation to allow (if necessary) more then adiacent neighbours (ie: +-2)
if (newmodule < 0) newmodule = nLadders + newmodule;
if (newmodule >= nLadders) newmodule = newmodule - nLadders;
for(int iladder = -n_neighbours_ladder; iladder <= n_neighbours_ladder; iladder++){ // neighbouring ladders
newladder = j + iladder;
//compute special case at the boundary
if (newladder < 0) newladder = nLadders + newladder;
if (newladder >= nLadders) newladder = newladder - nLadders;

//encoding
encoder[lcio::LCTrackerCellID::module()] = newmodule;
encoder[lcio::LCTrackerCellID::sensor()] = 0;
for(int isensor = -n_neighbours_sensor; isensor <= n_neighbours_sensor; isensor++){ // neighbouring sensors
if (iladder==0 && isensor==0) continue; // sensor we started with
newsensor = s + isensor;
// skip sensors outside boundaries
if (newsensor < 0) continue;
if (newsensor >= sens_nmodules) continue;

neighbourSurfacesData->sameLayer[cellID].push_back(encoder.lowWord());

}

///////////////////

//encoding
encoder[lcio::LCTrackerCellID::module()] = newladder;
encoder[lcio::LCTrackerCellID::sensor()] = newsensor;

neighbourSurfacesData->sameLayer[cellID].push_back(encoder.lowWord());
}

}

///////////////////

}

}


// tracker.setVisAttributes(theDetector, x_det.visStr(),laddervol);

// is this needed ??
layer_assembly->GetShape()->ComputeBBox() ;

Expand All @@ -301,19 +315,19 @@ static Ref_t create_element(Detector& theDetector, xml_h e, SensitiveDetector se
double tube_thick = 1.0 * dd4hep::mm ;
double inner_r = minRadius - 1.1 * tube_thick ;
double outer_r = inner_r + tube_thick ;
double z_half = minZhalf ;
double z_half = minZhalf ;

Tube tubeSolid (inner_r, outer_r, z_half ) ;
Volume tube_vol( name+"_inner_cylinder_air", tubeSolid , theDetector.material("Air") ) ;

assembly.placeVolume( tube_vol , Transform3D() ) ;

Vector3D ocyl( inner_r + 0.5*tube_thick , 0. , 0. ) ;

VolCylinder cylSurf( tube_vol , SurfaceType( SurfaceType::Helper ) , 0.5*tube_thick , 0.5*tube_thick , ocyl ) ;

volSurfaceList( tracker )->push_back( cylSurf ) ;

#endif //----------------------------------------------------------------------------------


Expand All @@ -328,11 +342,11 @@ static Ref_t create_element(Detector& theDetector, xml_h e, SensitiveDetector se
assembly.setVisAttributes(theDetector, x_det.visStr());

pv = mother.placeVolume(assembly);

pv.addPhysVolID( "system", x_det.id() ).addPhysVolID("side",0 ) ;

tracker.setPlacement(pv);

assembly->GetShape()->ComputeBBox() ;

return tracker;
Expand Down

0 comments on commit 49db3d4

Please sign in to comment.