diff --git a/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_03.xml b/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_03.xml
new file mode 100644
index 000000000..e3c372fdd
--- /dev/null
+++ b/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_03.xml
@@ -0,0 +1,79 @@
+
+
+
+
+ Test with Drift Chamber
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ system:5,layer:7:9,chamber:8,cellID:32:16
+
+
+
+
diff --git a/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_05.xml b/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_05.xml
new file mode 100644
index 000000000..383019ecb
--- /dev/null
+++ b/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_05.xml
@@ -0,0 +1,79 @@
+
+
+
+
+ Test with Drift Chamber
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ system:5,layer:7:9,chamber:8,cellID:32:16
+
+
+
+
diff --git a/Detector/DetCRD/compact/CRD_common_v01/DC_Stero_v01_01.xml b/Detector/DetCRD/compact/CRD_common_v01/DC_Stero_v01_01.xml
new file mode 100644
index 000000000..fe303a521
--- /dev/null
+++ b/Detector/DetCRD/compact/CRD_common_v01/DC_Stero_v01_01.xml
@@ -0,0 +1,89 @@
+
+
+
+
+ Test with Drift Chamber
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ system:5,layer:7:9,chamber:8,cellID:32:16
+
+
+
+
diff --git a/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_01.xml b/Detector/DetCRD/compact/CRD_common_v01/DC_Straight_v01_01.xml
similarity index 86%
rename from Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_01.xml
rename to Detector/DetCRD/compact/CRD_common_v01/DC_Straight_v01_01.xml
index a1da46679..73594f243 100644
--- a/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_01.xml
+++ b/Detector/DetCRD/compact/CRD_common_v01/DC_Straight_v01_01.xml
@@ -28,7 +28,7 @@
-
+
@@ -42,7 +42,7 @@
-
+
@@ -53,8 +53,10 @@
-
-
+
+
+
+
@@ -78,7 +80,7 @@
-
+
system:5,layer:7:9,chamber:8,cellID:32:16
diff --git a/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_02.xml b/Detector/DetCRD/compact/CRD_common_v01/DC_Straight_v01_02.xml
similarity index 88%
rename from Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_02.xml
rename to Detector/DetCRD/compact/CRD_common_v01/DC_Straight_v01_02.xml
index ae4ccbe02..0b6e8f67e 100644
--- a/Detector/DetCRD/compact/CRD_common_v01/DC_Simple_v01_02.xml
+++ b/Detector/DetCRD/compact/CRD_common_v01/DC_Straight_v01_02.xml
@@ -28,7 +28,7 @@
-
+
@@ -54,7 +54,9 @@
-
+
+
+
@@ -79,7 +81,7 @@
-
+
system:5,layer:7:9,chamber:8,cellID:32:16
diff --git a/Detector/DetCRD/compact/CRD_o1_v01/CRD_Dimensions_v01_01.xml b/Detector/DetCRD/compact/CRD_o1_v01/CRD_Dimensions_v01_01.xml
index cd1e9b2e5..9a79f6fb8 100644
--- a/Detector/DetCRD/compact/CRD_o1_v01/CRD_Dimensions_v01_01.xml
+++ b/Detector/DetCRD/compact/CRD_o1_v01/CRD_Dimensions_v01_01.xml
@@ -84,12 +84,16 @@
+
+
+
+
-
-
-
+
+
+
@@ -99,13 +103,6 @@
-
-
-
-
-
-
-
diff --git a/Detector/DetCRD/compact/CRD_o1_v01/CRD_o1_v01-onlyTracker.xml b/Detector/DetCRD/compact/CRD_o1_v01/CRD_o1_v01-onlyTracker.xml
index b35e32655..d80301fb2 100644
--- a/Detector/DetCRD/compact/CRD_o1_v01/CRD_o1_v01-onlyTracker.xml
+++ b/Detector/DetCRD/compact/CRD_o1_v01/CRD_o1_v01-onlyTracker.xml
@@ -31,7 +31,7 @@
-
+
diff --git a/Detector/DetCRD/compact/CRD_o1_v02/CRD_Dimensions_v01_02.xml b/Detector/DetCRD/compact/CRD_o1_v02/CRD_Dimensions_v01_02.xml
index cd1e9b2e5..9a79f6fb8 100644
--- a/Detector/DetCRD/compact/CRD_o1_v02/CRD_Dimensions_v01_02.xml
+++ b/Detector/DetCRD/compact/CRD_o1_v02/CRD_Dimensions_v01_02.xml
@@ -84,12 +84,16 @@
+
+
+
+
-
-
-
+
+
+
@@ -99,13 +103,6 @@
-
-
-
-
-
-
-
diff --git a/Detector/DetDriftChamber/compact/det.xml b/Detector/DetDriftChamber/compact/det.xml
index fb4bffdee..22548148c 100644
--- a/Detector/DetDriftChamber/compact/det.xml
+++ b/Detector/DetDriftChamber/compact/det.xml
@@ -1,15 +1,13 @@
-
+
- Test with Drift Chamber
+ version="v2">
+ Drift Chamber
@@ -17,51 +15,49 @@
-
+
-
+
-
-
+
+
+
+
+
-
-
+
+
-
-
+
-
-
-
-
+
+
+
+
+
+
-
-
-
+
+
-
-
-
+
+
-
-
-
-
+
+
-
-
@@ -76,7 +72,7 @@
-
+
@@ -86,11 +82,13 @@
-
-
+
+
+
+
-
+
@@ -112,7 +110,7 @@
-
+
system:5,layer:7:9,chamber:8,cellID:32:16
diff --git a/Detector/DetDriftChamber/compact/det_stero.xml b/Detector/DetDriftChamber/compact/det_stero.xml
new file mode 100644
index 000000000..44e919087
--- /dev/null
+++ b/Detector/DetDriftChamber/compact/det_stero.xml
@@ -0,0 +1,129 @@
+
+
+
+
+ Test with Drift Chamber
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ system:5,layer:7:9,chamber:8,cellID:32:16
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp b/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp
index be98c1c14..1ffdd929e 100644
--- a/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp
+++ b/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp
@@ -16,6 +16,9 @@
#include "DDSegmentation/Segmentation.h"
#include "DetSegmentation/GridDriftChamber.h"
+#include
+#include
+
using namespace dd4hep;
using namespace dd4hep::detail;
using namespace dd4hep::rec ;
@@ -27,40 +30,57 @@ static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector,
xml_h e,
dd4hep::SensitiveDetector sens) {
// ------- Lambda functions ---- //
- auto delta_a_func = [](auto x, auto y) { return 0.5 * ( x + y ); };
+ auto delta_b_func = [](auto x, auto y) { return 2 * std::sqrt((x + y) * (x - y)); };
+ auto epsilon_func = [](auto delta_a, auto L) { return std::atan(delta_a / L); };
// =======================================================================
// Parameter Definition
// =======================================================================
+ auto start = std::chrono::steady_clock::now();
+
xml_det_t x_det = e;
xml_coll_t c(x_det,_U(chamber));
xml_comp_t x_chamber = c;
+ xml_coll_t cc(x_det,_U(side));
+ xml_comp_t x_side = cc;
+
std::string det_name = x_det.nameStr();
std::string det_type = x_det.typeStr();
dd4hep::SensitiveDetector sd = sens;
// - global
- double chamber_half_length = theDetector.constant("DC_half_length");
+ double chamber_half_length = theDetector.constant("Gas_half_length");
+ double chamber_length = chamber_half_length*2;
- // - chamber
- double chamber_radius_min = theDetector.constant("SDT_chamber_radius_min");
- double chamber_radius_max = theDetector.constant("SDT_chamber_radius_max");
- double SDT_half_length = theDetector.constant("SDT_chamber_half_length");
+ double alpha = theDetector.constant("Alpha");
+ double Pi = 0;
+ if(0!=alpha) Pi = 0.5*M_PI;
+
+ double safe_distance = theDetector.constant("DC_safe_distance");
+
+ double DC_inner_wall_thickness = theDetector.constant("DC_inner_wall_thickness");
+ double DC_outer_wall_thickness = theDetector.constant("DC_outer_wall_thickness");
+
+ // - chamber gas
+ double DC_rend = theDetector.constant("DC_rend");
+
+ double chamber_radius_min = theDetector.constant("Gas_radius_min");
+ double chamber_radius_max = DC_rend-safe_distance-DC_outer_wall_thickness;
+ double layer_radius_max = chamber_radius_max*std::cos(alpha);
int chamberID = x_chamber.id();
// - layer
- double chamber_layer_width = theDetector.constant("SDT_chamber_layer_width");
- double chamber_cell_width = theDetector.constant("SDT_chamber_cell_width");
- double chamber_layer_rbegin = theDetector.constant("DC_chamber_layer_rbegin");
- double chamber_layer_rend = theDetector.constant("DC_chamber_layer_rend");
- int chamber_layer_number = floor((chamber_layer_rend-chamber_layer_rbegin)/chamber_layer_width);
+ int DC_layer_number = theDetector.constant("DC_layer_number");
- double safe_distance = theDetector.constant("DC_safe_distance");
- double epsilon = theDetector.constant("Epsilon");
+ double layer_width = (layer_radius_max-chamber_radius_min)/DC_layer_number;
+
+ double cell_width = theDetector.constant("DC_cell_width");
+
+ int DC_construct_wire = theDetector.constant("DC_construct_wire");
// =======================================================================
// Detector Construction
@@ -74,106 +94,112 @@ static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector,
if( theDetector.buildType() == BUILD_ENVELOPE ) return sdet ;
+ dd4hep::Material det_mat(theDetector.material(x_det.materialStr()));
+ dd4hep::Material chamber_mat = theDetector.material(x_chamber.materialStr());
- dd4hep::Material det_mat(theDetector.material("Air"));
- dd4hep::Material chamber_mat(theDetector.material("GasHe_90Isob_10"));
-
- // - global
+ /// - global
Assembly det_vol( det_name+"_assembly" ) ;
- // - chamber volume
+ /// - chamber volume
dd4hep::Tube det_chamber_solid(chamber_radius_min, chamber_radius_max, chamber_half_length);
dd4hep::Volume det_chamber_vol(det_name+"_chamber_vol", det_chamber_solid, chamber_mat);
- // - wall
- double chamber_inner_wall_rmin = theDetector.constant("SDT_chamber_inner_wall_radius_min");
- double chamber_inner_wall_rmax = theDetector.constant("SDT_chamber_inner_wall_radius_max");
- double chamber_outer_wall_rmin = theDetector.constant("SDT_chamber_outer_wall_radius_min");
- double chamber_outer_wall_rmax = theDetector.constant("SDT_chamber_outer_wall_radius_max");
+ /// - wall
+ double chamber_inner_wall_rmin = theDetector.constant("DC_inner_wall_radius_min");
+ double chamber_inner_wall_rmax = theDetector.constant("DC_inner_wall_radius_max");
+ double chamber_outer_wall_rmin = chamber_radius_max+safe_distance;
+ double chamber_outer_wall_rmax = chamber_outer_wall_rmin+DC_outer_wall_thickness;
- dd4hep::Material wall_mat(theDetector.material("CarbonFiber"));
+ dd4hep::Material wall_mat(theDetector.material(x_side.materialStr()));
double wall_rmin[2] = {chamber_inner_wall_rmin, chamber_outer_wall_rmin};
double wall_rmax[2] = {chamber_inner_wall_rmax, chamber_outer_wall_rmax};
- // - wire
- dd4hep::Volume module_vol;
- dd4hep::Volume Module_vol;
- for(xml_coll_t c(x_det,_U(module)); c; ++c) {
- xml_comp_t x_module = c;
- double module_rmin = x_module.rmin();
- double module_rmax = x_module.rmax();
- std::string module_name = x_module.nameStr();
- dd4hep::Tube module_solid(module_rmin,module_rmax,chamber_half_length);
- if(x_module.id()==0) {
- module_vol = dd4hep::Volume(module_name,module_solid,det_mat);
- module_vol.setVisAttributes(theDetector.visAttributes(x_module.visStr()));
- } else {
- Module_vol = dd4hep::Volume(module_name,module_solid,det_mat);
- Module_vol.setVisAttributes(theDetector.visAttributes(x_module.visStr()));
- }
-
- for(xml_coll_t l(x_module,_U(tubs)); l; ++l) {
- xml_comp_t x_tube =l;
- double tube_rmin = x_tube.rmin();
- double tube_rmax = x_tube.rmax();
- std::string tube_name = x_tube.nameStr();
- std::string wire_name= module_name + tube_name;
- dd4hep::Material tube_mat = theDetector.material(x_tube.materialStr());
- dd4hep::Tube wire_solid(tube_rmin,tube_rmax,chamber_half_length);
- dd4hep::Volume wire_vol(wire_name,wire_solid,tube_mat);
- dd4hep::Transform3D transform_wire(dd4hep::Rotation3D(),dd4hep::Position(0.,0.,0.));
- dd4hep::PlacedVolume wire_phy;
- if(x_module.id()==0) {
- wire_phy = module_vol.placeVolume(wire_vol,transform_wire);
- } else {
- wire_phy = Module_vol.placeVolume(wire_vol,transform_wire);
- }
- }
- }
-
- // End cap
- double Endcap_rmin = theDetector.constant("DC_Endcap_rmin");
- double Endcap_rmax = theDetector.constant("DC_Endcap_rmax");
- double Endcap_z = theDetector.constant("DC_Endcap_dz");
- dd4hep::Tube det_Endcap_solid(Endcap_rmin,Endcap_rmax,0.5*Endcap_z);
+ /// - construct wires
+ dd4hep::Volume signalWireVolume;
+ dd4hep::Volume fieldWireVolume;
+ for(xml_coll_t dcModule(x_det,_U(module)); dcModule; ++dcModule) {
+ xml_comp_t x_module = dcModule;
+ std::string module_name = x_module.nameStr();
+ dd4hep::Tube module_solid(x_module.rmin(),x_module.rmax(),chamber_half_length);
+ if(0==x_module.id()) {
+ signalWireVolume = dd4hep::Volume(module_name,module_solid,det_mat);
+ signalWireVolume.setVisAttributes(theDetector.visAttributes(x_module.visStr()));
+ } else {
+ fieldWireVolume = dd4hep::Volume(module_name,module_solid,det_mat);
+ fieldWireVolume.setVisAttributes(theDetector.visAttributes(x_module.visStr()));
+ }
+
+ /// construct wire tubes
+ for(xml_coll_t l(x_module,_U(tubs)); l; ++l) {
+ xml_comp_t x_tube =l;
+ std::string wire_name= module_name + x_tube.nameStr();
+ dd4hep::Material tube_mat = theDetector.material(x_tube.materialStr());
+ dd4hep::Tube wire_solid(x_tube.rmin(),x_tube.rmax(),chamber_half_length);
+ dd4hep::Volume wire_vol(wire_name,wire_solid,tube_mat);
+ dd4hep::Transform3D transform_wire(dd4hep::Rotation3D(),dd4hep::Position(0.,0.,0.));
+ if(0==x_module.id()) {
+ signalWireVolume.placeVolume(wire_vol,transform_wire);
+ } else {
+ fieldWireVolume.placeVolume(wire_vol,transform_wire);
+ }
+ }//end of construct tubes
+ }//end of construct wire
+
+ /// construct End cap
+ double endcap_rmin = theDetector.constant("DC_Endcap_rmin");
+ double endcap_rmax = theDetector.constant("DC_Endcap_rmax");
+ double endcap_z = theDetector.constant("DC_Endcap_dz");
+ dd4hep::Tube det_Endcap_solid(endcap_rmin,endcap_rmax,0.5*endcap_z);
dd4hep::Volume det_Endcap_vol(det_name+"Endcap",det_Endcap_solid,det_mat);
det_Endcap_vol.setVisAttributes(theDetector,"YellowVis");
- //Initialize the segmentation
- dd4hep::Readout readout = sd.readout();
- dd4hep::Segmentation geomseg = readout.segmentation();
- dd4hep::Segmentation* _geoSeg = &geomseg;
+ ///Initialize the segmentation
+ auto segmentationDC =
+ dynamic_cast
+ (sd.readout().segmentation().segmentation());
- auto DCHseg = dynamic_cast(_geoSeg->segmentation());
-
- // - layer
+ /// - construct layers
int chamber_id = 0;
- int layerIndex = -1;
- for(int layer_id = 0; layer_id < chamber_layer_number; layer_id++) {
- double rmin,rmax,offset=0;
+ for(int layer_id = 0; layer_id < DC_layer_number; layer_id++) {
dd4hep::Volume* current_vol_ptr = nullptr;
- current_vol_ptr = &det_chamber_vol;
- rmin = chamber_layer_rbegin+(layer_id*chamber_layer_width);
- rmax = rmin+chamber_layer_width;
- layerIndex = layer_id;
+ double layer_rmin = chamber_radius_min+(layer_id*layer_width);
+ double layer_rmax = layer_rmin+layer_width;
+ double rmid_zZero = (layer_rmin+layer_rmax)/2.; // z=0
+ double rmid_zEnd = rmid_zZero/std::cos(alpha/2); // z=endcap
+ int nCell = floor((2. * M_PI * rmid_zZero) / layer_width);
+ int nWire = nCell;
+ if(!DC_construct_wire) nWire =0;
+ double cell_phi = 2*M_PI / nCell;
+ double offset=0;//phi offset of first cell in each layer
+ double sign_eps = 1;// setero angle sign
+ if(0==(layer_id%2)) {
+ offset = 0.;
+ sign_eps = -1;
+ } else {
+ offset = 0.5 * cell_phi;
+ }
+ double epsilon = sign_eps*std::atan(rmid_zZero * std::tan(alpha / 2.0) / chamber_half_length);
+
+ segmentationDC->setGeomParams(chamber_id, layer_id, cell_phi, rmid_zEnd , epsilon, offset);
+ segmentationDC->setWiresInLayer(chamber_id, layer_id, nCell);
- //Construction of drift chamber layers
- double rmid = delta_a_func(rmin,rmax);
- double ilayer_cir = 2 * M_PI * rmid;
- double ncell = ilayer_cir / chamber_layer_width;
- int ncell_layer = floor(ncell);
- int numWire = ncell_layer;
- double layer_Phi = 2*M_PI / ncell_layer;
+ double r_in_test = rmid_zZero*std::cos(alpha / 2.0);
- if(layer_id %2 ==0){ offset = 0.; }
- else { offset = 0.5 * layer_Phi; }
+ double r_in0 = rmid_zZero - layer_width / 2.0;//
+ double r_in = r_in0 / std::cos(alpha / 2.0);//layer min at z=half length
- DCHseg->setGeomParams(chamber_id, layerIndex, layer_Phi, rmid, epsilon, offset);
- DCHseg->setWiresInLayer(chamber_id, layerIndex, numWire);
+ double r_out0 = rmid_zZero + layer_width / 2.0;
+ double r_out = r_out0 / std::cos(alpha / 2.0);
+ double delta_a_in = delta_b_func(r_in, r_in0);
+ double delta_a_out = delta_b_func(r_out, r_out0);
- dd4hep::Tube layer_vol_solid(rmin,rmax,chamber_half_length);
+ double eps_in = epsilon_func(delta_a_in, chamber_length );
+ double eps_out = epsilon_func(delta_a_out, chamber_length );
+
+ /// create hyper layer volume
+ dd4hep::Hyperboloid layer_vol_solid(r_in0, eps_in, r_out0, eps_out, chamber_half_length);
dd4hep::Volume layer_vol(det_name+"_layer_vol",layer_vol_solid,det_mat);
current_vol_ptr = &layer_vol;
@@ -184,46 +210,56 @@ static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector,
sd.setType("tracker");
}
- // - wire vol
- //phi <-------------------> -phi
- // | F8 F7 F6 F5| Only on the outermost layer.
- // | |
- // | S F4|
- // | |
- // | F0 F1 F2 F3|
- // -----------------------
- for(int icell=0; icell< numWire; icell++) {
- double wire_phi = (icell+0.5)*layer_Phi + offset;
+ // - create wire volume
+ //phi <---------------> -phi
+ // | F4 F3| Only on the outermost layer.
+ // | |
+ // | S F2|
+ // | |
+ // | F0 F1|
+ //--------------------
+ // loop over cells
+ for(int icell=0; icell elapsed_seconds = end-start;
+ std::cout << "elapsed time: " << elapsed_seconds.count() << "s\n";
return sdet;
}
diff --git a/Detector/DetSegmentation/include/DetSegmentation/GridDriftChamber.h b/Detector/DetSegmentation/include/DetSegmentation/GridDriftChamber.h
index 0233ccf82..77e9bfa56 100644
--- a/Detector/DetSegmentation/include/DetSegmentation/GridDriftChamber.h
+++ b/Detector/DetSegmentation/include/DetSegmentation/GridDriftChamber.h
@@ -34,7 +34,6 @@ typedef struct CID
{
int chamberID;
int layerID;
-// CID(){}
CID(int i, int j): chamberID(i),layerID(j){}
// the operator < defines the operation used in map
friend bool operator < (const CID &c1, const CID &c2);
@@ -60,23 +59,25 @@ class GridDriftChamber : public Segmentation {
virtual CellID cellID(const Vector3D& aLocalPosition, const Vector3D& aGlobalPosition,
const VolumeID& aVolumeID) const;
virtual double distanceTrackWire(const CellID& cID, const TVector3& hit_start, const TVector3& hit_end) const;
+ virtual double distanceTrackWire2(const CellID& cID, const TVector3& hit_pos) const;
virtual void cellposition(const CellID& cID, TVector3& Wstart, TVector3& Wend) const;
+ virtual void cellposition2(int chamber, int layer, int cell, TVector3& Wstart, TVector3& Wend) const;
TVector3 LineLineIntersect(TVector3& p1, TVector3& p2, TVector3& p3, TVector3& p4) const;
- virtual TVector3 distanceClosestApproach(const CellID& cID, const TVector3& hitPos) const;
+ virtual TVector3 distanceClosestApproach(const CellID& cID, const TVector3& hitPos, TVector3& PCA) const;
virtual TVector3 Line_TrackWire(const CellID& cID, const TVector3& hit_start, const TVector3& hit_end) const;
virtual TVector3 IntersectionTrackWire(const CellID& cID, const TVector3& hit_start, const TVector3& hit_end) const;
virtual TVector3 wirePos_vs_z(const CellID& cID, const double& zpos) const;
+ virtual double Distance(const CellID& cID, const TVector3& pointIn, const TVector3& pointOut, TVector3& hitPosition, TVector3& PCA) const;
+ virtual TVector3 returnPhi0(int chamber,int layer, double z) const;
+
// double phi(const CellID& cID) const;
inline double cell_Size() const { return m_cellSize; }
- inline double epsilon0() const { return m_epsilon0; }
+ inline double epsilon() const { return m_epsilon; }
inline double detectorLength() const { return m_detectorLength; }
- inline double safe_distance() const { return m_safe_distance; }
inline double layer_width() const { return m_layer_width; }
inline double DC_rbegin() const { return m_DC_rbegin; }
inline double DC_rend() const { return m_DC_rend; }
- inline double DC_rmax() const { return m_DC_rmax; }
- inline double DC_rmin() const { return m_DC_rmin; }
inline const std::string& fieldNamePhi() const { return m_phiID; }
inline const std::string& Layerid() const { return layer_id; }
@@ -88,7 +89,13 @@ class GridDriftChamber : public Segmentation {
return hit_phi;
}
- inline void setGeomParams(int chamberID, int layerID, double layerphi, double R, double eps, double offset) {
+ inline double phiFromXY2(const TVector3& aposition) const {
+ double hit_phi = std::atan2(aposition.Y(), aposition.X()) ;
+ if( hit_phi < 0 ) { hit_phi += 2 * M_PI; }
+ return hit_phi;
+ }
+
+ inline void setGeomParams(int chamberID, int layerID, double layerphi, double R, double eps, double offset) {
layer_params.insert(std::pair(vID(chamberID,layerID),LAYER(layerphi,R,eps,offset)));
@@ -135,7 +142,18 @@ class GridDriftChamber : public Segmentation {
_currentRadius = Radius;
m_epsilon = Eps;
m_offset = Offset;
- }
+ }
+
+ inline Vector3D returnPosWire0(double z) const {
+ double alpha = returnAlpha();
+ double t = 0.5 * (1 - 2.0 * z / m_detectorLength);
+ double x = _currentRadius * (1 + t * (std::cos(alpha) - 1));
+ double y = _currentRadius * t * std::sin(alpha);
+
+ Vector3D vec(x, y, z);
+ return vec;
+ }
+
protected:
@@ -152,19 +170,15 @@ class GridDriftChamber : public Segmentation {
}
inline double returnAlpha() const {
- double alpha = 2 * std::asin(m_detectorLength * std::tan(m_epsilon0)/(2 * _currentRadius));
+ double alpha = 2 * std::asin(m_detectorLength * std::tan(m_epsilon)/(2 * _currentRadius));
return alpha;
}
double m_cellSize;
- double m_epsilon0;
double m_detectorLength;
double m_layer_width;
- double m_safe_distance;
double m_DC_rbegin;
double m_DC_rend;
- double m_DC_rmax;
- double m_DC_rmin;
std::string m_phiID;
std::string layer_id;
diff --git a/Detector/DetSegmentation/src/GridDriftChamber.cpp b/Detector/DetSegmentation/src/GridDriftChamber.cpp
index a4302ebf5..5c59f2006 100644
--- a/Detector/DetSegmentation/src/GridDriftChamber.cpp
+++ b/Detector/DetSegmentation/src/GridDriftChamber.cpp
@@ -22,16 +22,12 @@ GridDriftChamber::GridDriftChamber(const BitFieldCoder* decoder) : Segmentation(
_description = "Drift chamber segmentation in the global coordinates";
registerParameter("cell_size", "cell size", m_cellSize, 1., SegmentationParameter::LengthUnit);
- registerParameter("epsilon0", "epsilon", m_epsilon0, 0., SegmentationParameter::AngleUnit, true);
registerParameter("detector_length", "Length of the wire", m_detectorLength, 1., SegmentationParameter::LengthUnit);
registerIdentifier("identifier_phi", "Cell ID identifier for phi", m_phiID, "cellID");
registerIdentifier("layerID", "layer id", layer_id, "layer");
- registerParameter("safe_distance", "safe_distance", m_safe_distance, 0., SegmentationParameter::LengthUnit);
registerParameter("layer_width", "layer_width", m_layer_width, 0., SegmentationParameter::LengthUnit);
registerParameter("DC_rbegin", "DC_rbegin", m_DC_rbegin, 0., SegmentationParameter::LengthUnit);
registerParameter("DC_rend", "DC_rend", m_DC_rend, 0., SegmentationParameter::LengthUnit);
- registerParameter("DC_rmin", "DC_rmin", m_DC_rmin, 0., SegmentationParameter::LengthUnit);
- registerParameter("DC_rmax", "DC_rmax", m_DC_rmax, 0., SegmentationParameter::LengthUnit);
}
Vector3D GridDriftChamber::position(const CellID& /*cID*/) const {
@@ -45,214 +41,293 @@ CellID GridDriftChamber::cellID(const Vector3D& /*localPosition*/, const Vector3
CellID cID = vID;
int chamberID = _decoder->get(cID, "chamber");
+ int layerid = _decoder->get(cID, "layer");
double posx = globalPosition.X;
double posy = globalPosition.Y;
- double radius = sqrt(posx*posx+posy*posy);
-
- int m_DC_layer_number = floor((m_DC_rend-m_DC_rbegin)/m_layer_width);
- double DC_layerdelta = m_layer_width;
-
- int layerid;
- if( radius<= m_DC_rend && radius>= m_DC_rbegin) {
- layerid = floor((radius - m_DC_rbegin)/DC_layerdelta);
- } else if ( radius>= (m_DC_rmin-m_safe_distance) && radius < m_DC_rbegin) {
- layerid = 0;
- } else if ( radius> m_DC_rend && radius <= (m_DC_rmax+m_safe_distance)) {
- layerid = m_DC_layer_number-1;
- }
+ double posz = globalPosition.Z;
updateParams(chamberID,layerid);
+ TVector3 Phi0 = returnPhi0(chamberID,layerid,posz);
+ double phi0 = phiFromXY2(Phi0);
+
double phi_hit = phiFromXY(globalPosition);
double offsetphi= m_offset;
- int _lphi;
+ double _lphi;
- if(phi_hit >= offsetphi) {
- _lphi = (int) ((phi_hit - offsetphi)/ _currentLayerphi);
- }
- else {
- _lphi = (int) ((phi_hit - offsetphi + 2 * M_PI)/ _currentLayerphi);
+ _lphi = phi_hit - phi0 + _currentLayerphi/2.;
+ if(_lphi<0.){
+ _lphi+=2*M_PI;
+ }else if(_lphi>2*M_PI){
+ _lphi=fmod(_lphi,2*M_PI);
}
+ int cellID=floor(_lphi/_currentLayerphi);
- int lphi = _lphi;
- _decoder->set(cID, layer_id, layerid);
- _decoder->set(cID, m_phiID, lphi);
+ _decoder->set(cID, m_phiID, cellID);
return cID;
}
double GridDriftChamber::phi(const CellID& cID) const {
- CellID phiValue = _decoder->get(cID, m_phiID);
- return binToPosition(phiValue, _currentLayerphi, m_offset);
+ CellID phiValue = _decoder->get(cID, m_phiID);
+ return binToPosition(phiValue, _currentLayerphi, m_offset);
}
void GridDriftChamber::cellposition(const CellID& cID, TVector3& Wstart,
- TVector3& Wend) const {
+ TVector3& Wend) const {
+
+ auto chamberIndex = _decoder->get(cID, "chamber");
+ auto layerIndex = _decoder->get(cID, "layer");
+ updateParams(chamberIndex,layerIndex);
+
+ double phi_start = phi(cID);
+ double phi_end = phi_start + returnAlpha();
+
+ Wstart = returnWirePosition(phi_start, -1);
+ Wend = returnWirePosition(phi_end, 1);
+}
+
+TVector3 GridDriftChamber::returnPhi0(int chamber,int layer, double z) const
+{
+ updateParams(chamber,layer);
+
+ double phi_wire_start = binToPosition(0 , _currentLayerphi, m_offset);
+ double phi_wire_end = phi_wire_start + returnAlpha();
+
+ TVector3 wire_start = returnWirePosition(phi_wire_start, -1);
+ TVector3 wire_end = returnWirePosition(phi_wire_end, 1);
+
+ double ratio = fabs(z - wire_start.Z())/fabs(wire_end.Z() - wire_start.Z());
+ double x_pos = ratio * (wire_end.X() - wire_start.X()) + wire_start.X();
+ double y_pos = ratio * (wire_end.Y() - wire_start.Y()) + wire_start.Y();
+
+ return TVector3(x_pos,y_pos,z);
+}
- auto chamberIndex = _decoder->get(cID, "chamber");
- auto layerIndex = _decoder->get(cID, "layer");
- updateParams(chamberIndex,layerIndex);
- double phi_start = phi(cID);
- double phi_mid = phi_start + _currentLayerphi/2.;
- double phi_end = phi_mid + returnAlpha();
+void GridDriftChamber::cellposition2(int chamber,int layer, int cell,
+ TVector3& Wstart, TVector3& Wend) const {
+ updateParams(chamber,layer);
+ double phi_start = binToPosition(cell, _currentLayerphi, m_offset);
+ double phi_end = phi_start + returnAlpha();
- Wstart = returnWirePosition(phi_mid, -1);
- Wend = returnWirePosition(phi_end, 1);
+ Wstart = returnWirePosition(phi_start, -1);
+ Wend = returnWirePosition(phi_end, 1);
}
TVector3 GridDriftChamber::LineLineIntersect(TVector3& p1, TVector3& p2, TVector3& p3, TVector3& p4) const {
- TVector3 p13, p43, p21;
- double d1343, d4321, d1321, d4343, d2121;
- double numer, denom;
- double mua, mub;
- TVector3 pa, pb;
-
- p13.SetX(p1.X() - p3.X());
- p13.SetY(p1.Y() - p3.Y());
- p13.SetZ(p1.Z() - p3.Z());
- p43.SetX(p4.X() - p3.X());
- p43.SetY(p4.Y() - p3.Y());
- p43.SetZ(p4.Z() - p3.Z());
- /* if (ABS(p43.X()) < EPS && ABS(p43.Y()) < EPS && ABS(p43.Z()) < EPS) */
- /* return(FALSE); */
- p21.SetX(p2.X() - p1.X());
- p21.SetY(p2.Y() - p1.Y());
- p21.SetZ(p2.Z() - p1.Z());
- /* if (ABS(p21.X()) < EPS && ABS(p21.Y()) < EPS && ABS(p21.Z()) < EPS) */
- /* return(FALSE); */
-
- d1343 = p13.X() * p43.X() + p13.Y() * p43.Y() + p13.Z() * p43.Z();
- d4321 = p43.X() * p21.X() + p43.Y() * p21.Y() + p43.Z() * p21.Z();
- d1321 = p13.X() * p21.X() + p13.Y() * p21.Y() + p13.Z() * p21.Z();
- d4343 = p43.X() * p43.X() + p43.Y() * p43.Y() + p43.Z() * p43.Z();
- d2121 = p21.X() * p21.X() + p21.Y() * p21.Y() + p21.Z() * p21.Z();
-
- denom = d2121 * d4343 - d4321 * d4321;
- /* if (ABS(denom) < EPS) */
- /* return(FALSE); */
- numer = d1343 * d4321 - d1321 * d4343;
-
- mua = numer / denom;
- mub = (d1343 + d4321 * (mua)) / d4343;
-
- pa.SetX(p1.X() + mua * p21.X());
- pa.SetY(p1.Y() + mua * p21.Y());
- pa.SetZ(p1.Z() + mua * p21.Z());
- pb.SetX(p3.X() + mub * p43.X());
- pb.SetY(p3.Y() + mub * p43.Y());
- pb.SetZ(p3.Z() + mub * p43.Z());
-
- return pb - pa;
+ TVector3 p13, p43, p21;
+ double d1343, d4321, d1321, d4343, d2121;
+ double numer, denom;
+ double mua, mub;
+ TVector3 pa, pb;
+
+ p13.SetX(p1.X() - p3.X());
+ p13.SetY(p1.Y() - p3.Y());
+ p13.SetZ(p1.Z() - p3.Z());
+ p43.SetX(p4.X() - p3.X());
+ p43.SetY(p4.Y() - p3.Y());
+ p43.SetZ(p4.Z() - p3.Z());
+ /* if (ABS(p43.X()) < EPS && ABS(p43.Y()) < EPS && ABS(p43.Z()) < EPS) */
+ /* return(FALSE); */
+ p21.SetX(p2.X() - p1.X());
+ p21.SetY(p2.Y() - p1.Y());
+ p21.SetZ(p2.Z() - p1.Z());
+ /* if (ABS(p21.X()) < EPS && ABS(p21.Y()) < EPS && ABS(p21.Z()) < EPS) */
+ /* return(FALSE); */
+
+ d1343 = p13.X() * p43.X() + p13.Y() * p43.Y() + p13.Z() * p43.Z();
+ d4321 = p43.X() * p21.X() + p43.Y() * p21.Y() + p43.Z() * p21.Z();
+ d1321 = p13.X() * p21.X() + p13.Y() * p21.Y() + p13.Z() * p21.Z();
+ d4343 = p43.X() * p43.X() + p43.Y() * p43.Y() + p43.Z() * p43.Z();
+ d2121 = p21.X() * p21.X() + p21.Y() * p21.Y() + p21.Z() * p21.Z();
+
+ denom = d2121 * d4343 - d4321 * d4321;
+ /* if (ABS(denom) < EPS) */
+ /* return(FALSE); */
+ numer = d1343 * d4321 - d1321 * d4343;
+
+ mua = numer / denom;
+ mub = (d1343 + d4321 * (mua)) / d4343;
+
+ pa.SetX(p1.X() + mua * p21.X());
+ pa.SetY(p1.Y() + mua * p21.Y());
+ pa.SetZ(p1.Z() + mua * p21.Z());
+ pb.SetX(p3.X() + mub * p43.X());
+ pb.SetY(p3.Y() + mub * p43.Y());
+ pb.SetZ(p3.Z() + mub * p43.Z());
+
+ return pb - pa;
}
double GridDriftChamber::distanceTrackWire(const CellID& cID, const TVector3& hit_start,
- const TVector3& hit_end) const {
+ const TVector3& hit_end) const {
- TVector3 Wstart = {0,0,0};
- TVector3 Wend = {0,0,0};
- cellposition(cID,Wstart,Wend);
+ TVector3 Wstart = {0,0,0};
+ TVector3 Wend = {0,0,0};
+ cellposition(cID,Wstart,Wend);
- TVector3 a = (hit_end - hit_start).Unit();
- TVector3 b = (Wend - Wstart).Unit();
- TVector3 c = Wstart - hit_start;
+ TVector3 a = (hit_end - hit_start).Unit();
+ TVector3 b = (Wend - Wstart).Unit();
+ TVector3 c = Wstart - hit_start;
- double num = std::abs(c.Dot(a.Cross(b)));
- double denum = (a.Cross(b)).Mag();
+ double num = std::abs(c.Dot(a.Cross(b)));
+ double denum = (a.Cross(b)).Mag();
- double DCA = 0;
+ double DCA = 0;
- if (denum) {
- DCA = num / denum;
- }
+ if (denum) {
+ DCA = num / denum;
+ }
- return DCA;
+ return DCA;
}
-TVector3 GridDriftChamber::distanceClosestApproach(const CellID& cID, const TVector3& hitPos) const {
- // Distance of the closest approach between a single hit (point) and the closest wire
+double GridDriftChamber::distanceTrackWire2(const CellID& cID, const TVector3& hit_pos) const {
- TVector3 Wstart = {0,0,0};
- TVector3 Wend = {0,0,0};
- cellposition(cID,Wstart,Wend);
+ TVector3 Wstart = {0,0,0};
+ TVector3 Wend = {0,0,0};
+ cellposition(cID,Wstart,Wend);
- TVector3 temp = (Wend + Wstart);
- TVector3 Wmid(temp.X() / 2.0, temp.Y() / 2.0, temp.Z() / 2.0);
+ TVector3 denominator = Wend - Wstart;
+ TVector3 numerator = denominator.Cross(Wstart-hit_pos);
- double hitPhi = hitPos.Phi();
- if (hitPhi < 0) {
- hitPhi = hitPhi + 2 * M_PI;
- }
+ double DCA = numerator.Mag()/denominator.Mag() ;
+
+ return DCA;
+}
- TVector3 PCA = Wstart + ((Wend - Wstart).Unit()).Dot((hitPos - Wstart)) * ((Wend - Wstart).Unit());
- TVector3 dca = hitPos - PCA;
+TVector3 GridDriftChamber::distanceClosestApproach(const CellID& cID, const TVector3& hitPos, TVector3& PCA) const {
+ // Distance of the closest approach between a single hit (point) and the closest wire
- return dca;
+ TVector3 Wstart = {0,0,0};
+ TVector3 Wend = {0,0,0};
+ cellposition(cID,Wstart,Wend);
+
+ TVector3 temp = (Wend + Wstart);
+ TVector3 Wmid(temp.X() / 2.0, temp.Y() / 2.0, temp.Z() / 2.0);
+
+ double hitPhi = hitPos.Phi();
+ if (hitPhi < 0) {
+ hitPhi = hitPhi + 2 * M_PI;
+ }
+
+ PCA = Wstart + ((Wend - Wstart).Unit()).Dot((hitPos - Wstart)) * ((Wend - Wstart).Unit());
+ TVector3 dca = hitPos - PCA;
+
+ return dca;
}
TVector3 GridDriftChamber::Line_TrackWire(const CellID& cID, const TVector3& hit_start, const TVector3& hit_end) const {
- // The line connecting a particle track to the closest wire
- // Returns the vector connecting the both
- TVector3 Wstart = {0,0,0};
- TVector3 Wend = {0,0,0};
- cellposition(cID,Wstart,Wend);
-
- TVector3 P1 = hit_start;
- TVector3 P2 = hit_end;
- TVector3 P3 = Wstart;
- TVector3 P4 = Wend;
-
- TVector3 intersect = LineLineIntersect(P1, P2, P3, P4);
- return intersect;
+ // The line connecting a particle track to the closest wire
+ // Returns the vector connecting the both
+ TVector3 Wstart = {0,0,0};
+ TVector3 Wend = {0,0,0};
+ cellposition(cID,Wstart,Wend);
+
+ TVector3 P1 = hit_start;
+ TVector3 P2 = hit_end;
+ TVector3 P3 = Wstart;
+ TVector3 P4 = Wend;
+
+ TVector3 intersect = LineLineIntersect(P1, P2, P3, P4);
+ return intersect;
}
// Get the wire position for a z
TVector3 GridDriftChamber::wirePos_vs_z(const CellID& cID, const double& zpos) const {
- TVector3 Wstart = {0,0,0};
- TVector3 Wend = {0,0,0};
- cellposition(cID,Wstart,Wend);
+ TVector3 Wstart = {0,0,0};
+ TVector3 Wend = {0,0,0};
+ cellposition(cID,Wstart,Wend);
- double t = (zpos - Wstart.Z())/(Wend.Z()-Wstart.Z());
- double x = Wstart.X()+t*(Wend.X()-Wstart.X());
- double y = Wstart.Y()+t*(Wend.Y()-Wstart.Y());
+ double t = (zpos - Wstart.Z())/(Wend.Z()-Wstart.Z());
+ double x = Wstart.X()+t*(Wend.X()-Wstart.X());
+ double y = Wstart.Y()+t*(Wend.Y()-Wstart.Y());
- TVector3 wireCoord(x, y, zpos);
- return wireCoord;
+ TVector3 wireCoord(x, y, zpos);
+ return wireCoord;
}
TVector3 GridDriftChamber::IntersectionTrackWire(const CellID& cID, const TVector3& hit_start, const TVector3& hit_end) const {
- // Intersection between the particle track and the wire assuming that the track between hit_start and hit_end is linear
+ // Intersection between the particle track and the wire assuming that the track between hit_start and hit_end is linear
- TVector3 Wstart = {0,0,0};
- TVector3 Wend = {0,0,0};
- cellposition(cID,Wstart,Wend);
+ TVector3 Wstart = {0,0,0};
+ TVector3 Wend = {0,0,0};
+ cellposition(cID,Wstart,Wend);
- TVector3 P1 = hit_start;
- TVector3 V1 = hit_end-hit_start;
+ TVector3 P1 = hit_start;
+ TVector3 V1 = hit_end-hit_start;
- TVector3 P2 = Wstart;
- TVector3 V2 = Wend - Wstart;
+ TVector3 P2 = Wstart;
+ TVector3 V2 = Wend - Wstart;
- TVector3 denom = V1.Cross(V2);
- double mag_denom = denom.Mag();
+ TVector3 denom = V1.Cross(V2);
+ double mag_denom = denom.Mag();
- TVector3 intersect(0, 0, 0);
+ TVector3 intersect(0, 0, 0);
- if (mag_denom !=0)
+ if (mag_denom !=0)
{
- TVector3 num = ((P2-P1)).Cross(V2);
- double mag_num = num.Mag();
- double a = mag_num / mag_denom;
+ TVector3 num = ((P2-P1)).Cross(V2);
+ double mag_num = num.Mag();
+ double a = mag_num / mag_denom;
- intersect = P1 + a * V1;
+ intersect = P1 + a * V1;
}
- return intersect;
+ return intersect;
}
+double GridDriftChamber::Distance(const CellID& cID, const TVector3& pointIn, const TVector3& pointOut, TVector3& hitPosition, TVector3& PCA) const {
+
+ //For two lines r=r1+t1.v1 & r=r2+t2.v2
+ //the closest approach is d=|(r2-r1).(v1 x v2)|/|v1 x v2|
+ //the point where closest approach are
+ //t1=(v1 x v2).[(r2-r1) x v2]/[(v1 x v2).(v1 x v2)]
+ //t2=(v1 x v2).[(r2-r1) x v1]/[(v1 x v2).(v1 x v2)]
+ //if v1 x v2=0 means two lines are parallel
+ //d=|(r2-r1) x v1|/|v1|
+
+ double t1,distance,dInOut,dHitIn,dHitOut;
+ //Get wirepoint @ endplate
+ TVector3 west = {0,0,0};
+ TVector3 east = {0,0,0};
+ cellposition(cID,west,east);
+ TVector3 wireLine=east - west;
+ TVector3 hitLine=pointOut - pointIn;
+
+ TVector3 hitXwire=hitLine.Cross(wireLine);
+ TVector3 wire2hit=east-pointOut;
+ //Hitposition is the position on hit line where closest approach
+ //of two lines, but it may out the area from pointIn to pointOut
+ if(hitXwire.Mag()==0){
+ distance=wireLine.Cross(wire2hit).Mag()/wireLine.Mag();
+ hitPosition=pointIn;
+ }else{
+ t1=hitXwire.Dot(wire2hit.Cross(wireLine))/hitXwire.Mag2();
+ hitPosition=pointOut+t1*hitLine;
+
+ dInOut=(pointOut-pointIn).Mag();
+ dHitIn=(hitPosition-pointIn).Mag();
+ dHitOut=(hitPosition-pointOut).Mag();
+ if(dHitIn<=dInOut && dHitOut<=dInOut){ //Between point in & out
+ distance=fabs(wire2hit.Dot(hitXwire)/hitXwire.Mag());
+ }else if(dHitOut>dHitIn){ // out pointIn
+ distance=wireLine.Cross(pointIn-east).Mag()/wireLine.Mag();
+ hitPosition=pointIn;
+ }else{ // out pointOut
+ distance=wireLine.Cross(pointOut-east).Mag()/wireLine.Mag();
+ hitPosition=pointOut;
+ }
+ }
+
+ PCA = west + ((east - west).Unit()).Dot((hitPosition - west)) * ((east - west).Unit());
+
+ return distance;
+}
}
}
diff --git a/Digitisers/DCHDigi/src/DCHDigiAlg.cpp b/Digitisers/DCHDigi/src/DCHDigiAlg.cpp
index 8f5a8cefa..21a840411 100644
--- a/Digitisers/DCHDigi/src/DCHDigiAlg.cpp
+++ b/Digitisers/DCHDigi/src/DCHDigiAlg.cpp
@@ -28,15 +28,15 @@ DCHDigiAlg::DCHDigiAlg(const std::string& name, ISvcLocator* svcLoc)
: GaudiAlgorithm(name, svcLoc),
_nEvt(0)
{
-
+
// Input collections
declareProperty("SimDCHitCollection", r_SimDCHCol, "Handle of the Input SimHit collection");
-
+
// Output collections
declareProperty("DigiDCHitCollection", w_DigiDCHCol, "Handle of Digi DCHit collection");
-
+
declareProperty("AssociationCollection", w_AssociationCol, "Handle of Association collection");
-
+
}
StatusCode DCHDigiAlg::initialize()
@@ -53,7 +53,10 @@ StatusCode DCHDigiAlg::initialize()
return StatusCode::FAILURE;
}
+ fRandom.SetSeed(105105);//FIXME: set by users
+
if(m_WriteAna){
+
NTuplePtr nt( ntupleSvc(), "MyTuples/DCH_digi_evt" );
if ( nt ) m_tuple = nt;
else {
@@ -66,17 +69,28 @@ StatusCode DCHDigiAlg::initialize()
m_tuple->addItem( "simhit_x", m_n_sim, m_simhit_x).ignore();
m_tuple->addItem( "simhit_y", m_n_sim, m_simhit_y).ignore();
m_tuple->addItem( "simhit_z", m_n_sim, m_simhit_z).ignore();
+ m_tuple->addItem( "Simdca" , m_n_sim, m_Simdca ).ignore();
+ m_tuple->addItem( "simhitT", m_n_sim, m_simhitT ).ignore();
+ m_tuple->addItem( "simhitmom", m_n_sim, m_simhitmom ).ignore();
+ m_tuple->addItem( "simPDG", m_n_sim, m_simPDG ).ignore();
m_tuple->addItem( "chamber" , m_n_digi, m_chamber ).ignore();
m_tuple->addItem( "layer" , m_n_digi, m_layer ).ignore();
m_tuple->addItem( "cell" , m_n_digi, m_cell ).ignore();
m_tuple->addItem( "cell_x" , m_n_digi, m_cell_x ).ignore();
m_tuple->addItem( "cell_y" , m_n_digi, m_cell_y ).ignore();
+ m_tuple->addItem( "cell1_x" , m_n_digi, m_cell1_x ).ignore();
+ m_tuple->addItem( "cell1_y" , m_n_digi, m_cell1_y ).ignore();
m_tuple->addItem( "hit_x" , m_n_digi,m_hit_x ).ignore();
m_tuple->addItem( "hit_y" , m_n_digi,m_hit_y ).ignore();
m_tuple->addItem( "hit_z" , m_n_digi,m_hit_z ).ignore();
- m_tuple->addItem( "dca" , m_n_digi,m_dca ).ignore();
+ m_tuple->addItem( "mom_x" , m_n_digi,m_mom_x ).ignore();
+ m_tuple->addItem( "mom_y" , m_n_digi,m_mom_y ).ignore();
+ m_tuple->addItem( "dca" , m_n_digi, m_dca ).ignore();
+ m_tuple->addItem( "poca_x" , m_n_digi, m_poca_x ).ignore();
+ m_tuple->addItem( "poca_y" , m_n_digi, m_poca_y ).ignore();
m_tuple->addItem( "hit_dE" , m_n_digi,m_hit_dE ).ignore();
m_tuple->addItem( "hit_dE_dx", m_n_digi,m_hit_dE_dx ).ignore();
+ m_tuple->addItem( "truthlength", m_n_digi,m_truthlength).ignore();
} else { // did not manage to book the N tuple....
info() << " Cannot book N-tuple:" << long( m_tuple ) << endmsg;
}
@@ -92,7 +106,7 @@ StatusCode DCHDigiAlg::execute()
m_start = clock();
info() << "Processing " << _nEvt << " events " << endmsg;
- m_evt = _nEvt;
+ if(m_WriteAna) m_evt = _nEvt;
edm4hep::TrackerHitCollection* Vec = w_DigiDCHCol.createAndPut();
edm4hep::MCRecoTrackerAssociationCollection* AssoVec = w_AssociationCol.createAndPut();
const edm4hep::SimTrackerHitCollection* SimHitCol = r_SimDCHCol.get();
@@ -102,8 +116,8 @@ StatusCode DCHDigiAlg::execute()
debug()<<"input sim hit size="<< SimHitCol->size() <at(0);
- std::map > id_hits_map;
- //std::map > id_hits_map;
+ std::map> id_hits_map;
+
for( int i = 0; i < SimHitCol->size(); i++ )
{
@@ -111,7 +125,12 @@ StatusCode DCHDigiAlg::execute()
unsigned long long id = SimHit.getCellID();
float sim_hit_mom = sqrt( SimHit.getMomentum()[0]*SimHit.getMomentum()[0] + SimHit.getMomentum()[1]*SimHit.getMomentum()[1] + SimHit.getMomentum()[2]*SimHit.getMomentum()[2] );//GeV
if(sim_hit_mom < m_mom_threshold) continue;
- if(SimHit.getEDep() <= 0) continue;
+ if(sim_hit_mom > m_mom_threshold_high) continue;
+ if(SimHit.getEDep() <= m_edep_threshold) continue;
+
+ //Wire efficiency
+ double hitProb = fRandom.Uniform(1.);
+ if(hitProb > m_wireEff) continue;
if ( id_hits_map.find(id) != id_hits_map.end()) id_hits_map[id].push_back(SimHit);
else
@@ -127,120 +146,128 @@ StatusCode DCHDigiAlg::execute()
}
for(auto iter = id_hits_map.begin(); iter != id_hits_map.end(); iter++)
{
- unsigned long long wcellid = iter->first;
- auto trkHit = Vec->create();
- trkHit.setCellID(wcellid);
- double tot_edep = 0 ;
- double tot_length = 0 ;
- double pos_x = 0 ;
- double pos_y = 0 ;
- double pos_z = 0 ;
- int simhit_size = iter->second.size();
- for(unsigned int i=0; i< simhit_size; i++)
- {
- tot_edep += iter->second.at(i).getEDep();//GeV
- }
- int chamber = m_decoder->get(wcellid, "chamber");
- int layer = m_decoder->get(wcellid, "layer" );
- int cellID = m_decoder->get(wcellid, "cellID" );
- TVector3 Wstart(0,0,0);
- TVector3 Wend (0,0,0);
- m_segmentation->cellposition(wcellid, Wstart, Wend);
- float dd4hep_mm = dd4hep::mm;
- //std::cout<<"dd4hep_mm="<second.at(i).getMomentum()[0]*iter->second.at(i).getMomentum()[0] + iter->second.at(i).getMomentum()[1]*iter->second.at(i).getMomentum()[1] + iter->second.at(i).getMomentum()[2]*iter->second.at(i).getMomentum()[2] );//GeV
- float sim_hit_pt = sqrt( iter->second.at(i).getMomentum()[0]*iter->second.at(i).getMomentum()[0] + iter->second.at(i).getMomentum()[1]*iter->second.at(i).getMomentum()[1] );//GeV
- TVector3 pos(iter->second.at(i).getPosition()[0]*dd4hep_mm, iter->second.at(i).getPosition()[1]*dd4hep_mm, iter->second.at(i).getPosition()[2]*dd4hep_mm);
-
-// TVector3 numerator = denominator.Cross(Wstart-pos) ;
-// float tmp_distance = numerator.Mag()/denominator.Mag() ;
-
- TVector3 sim_mon(iter->second.at(i).getMomentum()[0],iter->second.at(i).getMomentum()[1],iter->second.at(i).getMomentum()[2]);
- float Steplength = iter->second.at(i).getPathLength();
- TVector3 pos_start = pos - 0.5 * Steplength * sim_mon.Unit();
- TVector3 pos_end = pos + 0.5 * Steplength * sim_mon.Unit();
- if(m_Doca) {
- tmp_distance = m_segmentation->distanceTrackWire(wcellid,pos_start,pos_end);
- tmp_distance = tmp_distance/dd4hep_mm; //mm
- } else {
- tmp_distance = (m_segmentation->distanceClosestApproach(wcellid,pos)).Mag();
- tmp_distance = tmp_distance/dd4hep_mm; //mm
- }
-
-
- // std::cout << " Steplength= " << Steplength << std::endl;
- // std::cout<<"tmp_distance="<second.at(i).getPathLength();//mm
- auto asso = AssoVec->create();
- asso.setRec(trkHit);
- asso.setSim(iter->second.at(i));
- asso.setWeight(iter->second.at(i).getEDep()/tot_edep);
-
- if(m_WriteAna && (nullptr!=m_tuple)) { // && min_distance <0.3){
- m_simhit_x[m_n_sim] = pos.x();
- m_simhit_y[m_n_sim] = pos.y();
- m_simhit_z[m_n_sim] = pos.z();
- m_n_sim ++ ;
- }
- }
-
- trkHit.setTime(min_distance*1e3/m_velocity);//m_velocity is um/ns, drift time in ns
- trkHit.setEDep(tot_edep);// GeV
- trkHit.setPosition (edm4hep::Vector3d(pos_x, pos_y, pos_z));//position of closest sim hit
- trkHit.setCovMatrix(std::array{m_res_x, 0, m_res_y, 0, 0, m_res_z});//cov(x,x) , cov(y,x) , cov(y,y) , cov(z,x) , cov(z,y) , cov(z,z) in mm
-
- if(m_WriteAna && (nullptr!=m_tuple)) { // && min_distance <0.3){
- m_chamber [m_n_digi] = chamber;
- m_layer [m_n_digi] = layer ;
- m_cell [m_n_digi] = cellID;
- m_cell_x [m_n_digi] = Wstart.x();
- m_cell_y [m_n_digi] = Wstart.y();
- m_hit_x [m_n_digi] = pos_x;
- m_hit_y [m_n_digi] = pos_y;
- m_hit_z [m_n_digi] = pos_z;
- m_dca [m_n_digi] = min_distance;
- m_hit_dE [m_n_digi] = trkHit.getEDep();
- m_hit_dE_dx[m_n_digi] = tot_edep/tot_length ;
- m_n_digi ++ ;
- }
- }
+ unsigned long long wcellid = iter->first;
+ auto trkHit = Vec->create();
+ trkHit.setCellID(wcellid);
+ double tot_edep = 0 ;
+ double tot_length = 0 ;
+ double pos_x = 0 ;
+ double pos_y = 0 ;
+ double pos_z = 0 ;
+ double momx,momy = 0;
+ int simhit_size = iter->second.size();
+ for(unsigned int i=0; i< simhit_size; i++)
+ {
+ tot_edep += iter->second.at(i).getEDep();//GeV
+ }
+ int chamber = m_decoder->get(wcellid, "chamber");
+ int layer = m_decoder->get(wcellid, "layer" );
+ int cellID = m_decoder->get(wcellid, "cellID" );
+ TVector3 Wstart(0,0,0);
+ TVector3 Wend (0,0,0);
+ m_segmentation->cellposition(wcellid, Wstart, Wend);
+ float dd4hep_mm = dd4hep::mm;
+ if(m_debug) std::cout<<"DCHDigi wcellid ="<second.at(i).getMomentum()[0]*iter->second.at(i).getMomentum()[0] + iter->second.at(i).getMomentum()[1]*iter->second.at(i).getMomentum()[1] + iter->second.at(i).getMomentum()[2]*iter->second.at(i).getMomentum()[2] );//GeV
+ float sim_hit_pt = sqrt( iter->second.at(i).getMomentum()[0]*iter->second.at(i).getMomentum()[0] + iter->second.at(i).getMomentum()[1]*iter->second.at(i).getMomentum()[1] );//GeV
+ TVector3 pos(iter->second.at(i).getPosition()[0]*dd4hep_mm, iter->second.at(i).getPosition()[1]*dd4hep_mm, iter->second.at(i).getPosition()[2]*dd4hep_mm);
+
+ TVector3 sim_mon(iter->second.at(i).getMomentum()[0],iter->second.at(i).getMomentum()[1],iter->second.at(i).getMomentum()[2]);
+ float Steplength = iter->second.at(i).getPathLength();
+ TVector3 pos_start = pos - 0.5 * Steplength * sim_mon.Unit();
+ TVector3 pos_end = pos + 0.5 * Steplength * sim_mon.Unit();
+ tmp_distance = m_segmentation->Distance(wcellid,pos_start,pos_end,hitPosition,PCA);
+ tmp_distance = tmp_distance/dd4hep_mm; //mm
+ sim_distance = tmp_distance;
+
+
+ if(tmp_distance < min_distance){
+ min_distance = tmp_distance;
+ pos_x = hitPosition.x(); //pos.x();
+ pos_y = hitPosition.y(); //pos.y();
+ pos_z = pos.z();
+ momx = iter->second.at(i).getMomentum()[0];
+ momy = iter->second.at(i).getMomentum()[1];
+ }
+ tot_length += iter->second.at(i).getPathLength();//mm
+ auto asso = AssoVec->create();
+ asso.setRec(trkHit);
+ asso.setSim(iter->second.at(i));
+ asso.setWeight(iter->second.at(i).getEDep()/tot_edep);
+ //std::cout<<" asso setRec setSim "<second.at(i)<second.at(i).getTime();
+ m_simhitmom[m_n_sim] = sim_hit_mom;
+ m_simPDG[m_n_sim] = iter->second.at(i).getMCParticle().getPDG();
+ m_n_sim ++ ;
+ }
+ }
+ trkHit.setTime(min_distance*1e3/m_velocity);//m_velocity is um/ns, drift time in ns
+ trkHit.setEDep(tot_edep);// GeV
+ //trkHit.setEdx (tot_edep/tot_length); // GeV/mm
+ trkHit.setPosition (edm4hep::Vector3d(pos_x, pos_y, pos_z));//position of closest sim hit
+ trkHit.setCovMatrix(std::array{m_res_x, 0, m_res_y, 0, 0, m_res_z});//cov(x,x) , cov(y,x) , cov(y,y) , cov(z,x) , cov(z,y) , cov(z,z) in mm
+
+ if(m_WriteAna && (nullptr!=m_tuple)) {
+ m_chamber [m_n_digi] = chamber;
+ m_layer [m_n_digi] = layer ;
+ m_cell [m_n_digi] = cellID;
+ m_cell_x [m_n_digi] = Wstart.x();
+ m_cell_y [m_n_digi] = Wstart.y();
+ m_cell1_x [m_n_digi] = Wend.x();
+ m_cell1_y [m_n_digi] = Wend.y();
+ m_hit_x [m_n_digi] = pos_x;
+ m_hit_y [m_n_digi] = pos_y;
+ m_hit_z [m_n_digi] = pos_z;
+ m_mom_x [m_n_digi] = momx ;
+ m_mom_y [m_n_digi] = momy ;
+ m_dca [m_n_digi] = min_distance;
+ m_poca_x [m_n_digi] = PCA.x();
+ m_poca_y [m_n_digi] = PCA.y();
+ m_hit_dE [m_n_digi] = trkHit.getEDep();
+ //m_hit_dE_dx[m_n_digi] = trkHit.getEdx() ;
+ m_truthlength[m_n_digi] = tot_length ;
+ m_n_digi ++ ;
+ }
+ }
debug()<<"output digi DCHhit size="<< Vec->size() <write();
if ( status.isFailure() ) {
- error() << " Cannot fill N-tuple:" << long( m_tuple ) << endmsg;
- return StatusCode::FAILURE;
+ error() << " Cannot fill N-tuple:" << long( m_tuple ) << endmsg;
+ return StatusCode::FAILURE;
}
}
m_end = clock();
- m_time = (m_end - m_start);
+ if(m_WriteAna){
+ m_time = (m_end - m_start);
+ }
return StatusCode::SUCCESS;
}
StatusCode DCHDigiAlg::finalize()
{
- info() << "Processed " << _nEvt << " events " << endmsg;
- return GaudiAlgorithm::finalize();
+ info() << "Processed " << _nEvt << " events " << endmsg;
+ return GaudiAlgorithm::finalize();
}
diff --git a/Digitisers/DCHDigi/src/DCHDigiAlg.h b/Digitisers/DCHDigi/src/DCHDigiAlg.h
index d6a82961f..946363c1c 100644
--- a/Digitisers/DCHDigi/src/DCHDigiAlg.h
+++ b/Digitisers/DCHDigi/src/DCHDigiAlg.h
@@ -7,6 +7,7 @@
#include "edm4hep/SimTrackerHitCollection.h"
#include "edm4hep/TrackerHitCollection.h"
#include "edm4hep/MCRecoTrackerAssociationCollection.h"
+#include "edm4hep/MCParticle.h"
#include
#include
@@ -15,8 +16,7 @@
#include "DetSegmentation/GridDriftChamber.h"
#include "TVector3.h"
-
-
+#include "TRandom3.h"
class DCHDigiAlg : public GaudiAlgorithm
{
@@ -44,6 +44,8 @@ class DCHDigiAlg : public GaudiAlgorithm
typedef std::vector FloatVec;
int _nEvt ;
+ TRandom3 fRandom;
+
NTuple::Tuple* m_tuple = nullptr ;
NTuple::Item m_evt;
NTuple::Item m_n_sim;
@@ -52,40 +54,56 @@ class DCHDigiAlg : public GaudiAlgorithm
NTuple::Array m_chamber ;
NTuple::Array m_layer ;
NTuple::Array m_cell ;
+ //The position of wire at -z
NTuple::Array m_cell_x ;
NTuple::Array m_cell_y ;
+ //The position of wire at +z
+ NTuple::Array m_cell1_x ;
+ NTuple::Array m_cell1_y ;
+
NTuple::Array m_simhit_x ;
NTuple::Array m_simhit_y ;
NTuple::Array m_simhit_z ;
+ NTuple::Array m_simhitT ;
+ NTuple::Array m_simhitmom ;
+ NTuple::Array m_simPDG ;
NTuple::Array m_hit_x ;
NTuple::Array m_hit_y ;
NTuple::Array m_hit_z ;
+ NTuple::Array m_mom_x ;
+ NTuple::Array m_mom_y ;
NTuple::Array m_dca ;
+ NTuple::Array m_Simdca ;
+ NTuple::Array m_poca_x ;
+ NTuple::Array m_poca_y ;
NTuple::Array m_hit_dE ;
NTuple::Array m_hit_dE_dx ;
+ NTuple::Array m_truthlength ;
clock_t m_start,m_end;
dd4hep::rec::CellIDPositionConverter* m_cellIDConverter;
dd4hep::DDSegmentation::GridDriftChamber* m_segmentation;
dd4hep::DDSegmentation::BitFieldCoder* m_decoder;
-
+
Gaudi::Property m_readout_name{ this, "readout", "DriftChamberHitsCollection"};//readout for getting segmentation
-
+
Gaudi::Property m_res_x { this, "res_x", 0.11};//mm
Gaudi::Property m_res_y { this, "res_y", 0.11};//mm
Gaudi::Property m_res_z { this, "res_z", 1 };//mm
Gaudi::Property m_velocity { this, "drift_velocity", 40};// um/ns
Gaudi::Property m_mom_threshold { this, "mom_threshold", 0};// GeV
+ Gaudi::Property m_mom_threshold_high { this, "mom_threshold_high", 1e9};// GeV
+ Gaudi::Property m_edep_threshold{ this, "edep_threshold", 0};// GeV
Gaudi::Property m_WriteAna { this, "WriteAna", false};
- Gaudi::Property m_Doca { this, "Doca", false};//1:line dca 0:point dca
-
+ Gaudi::Property m_debug{ this, "debug", false};
+ Gaudi::Property m_wireEff{ this, "wireEff", 1.0};
// Input collections
DataHandle r_SimDCHCol{"DriftChamberHitsCollection", Gaudi::DataHandle::Reader, this};
// Output collections
DataHandle w_DigiDCHCol{"DigiDCHitCollection", Gaudi::DataHandle::Writer, this};
DataHandle w_AssociationCol{"DCHitAssociationCollection", Gaudi::DataHandle::Writer, this};
-
};
+
#endif
diff --git a/Reconstruction/PFA/Arbor/src/MarlinArbor.cc b/Reconstruction/PFA/Arbor/src/MarlinArbor.cc
old mode 100755
new mode 100644
diff --git a/Reconstruction/RecGenfitAlg/CMakeLists.txt b/Reconstruction/RecGenfitAlg/CMakeLists.txt
index ee9b04300..f7c5b6961 100644
--- a/Reconstruction/RecGenfitAlg/CMakeLists.txt
+++ b/Reconstruction/RecGenfitAlg/CMakeLists.txt
@@ -2,11 +2,15 @@
if (GenFit_FOUND)
gaudi_add_module(RecGenfitAlg
- SOURCES src/RecGenfitAlgDC.cpp
+ SOURCES src/RecGenfitAlgSDT.cpp
src/GenfitTrack.cpp
+ src/GenfitHit.cpp
src/GenfitField.cpp
src/GenfitFitter.cpp
src/GenfitMaterialInterface.cpp
+ src/LSFitting.cpp
+ src/WireMeasurementDC.cpp
+ src/PlanarMeasurementSDT.cpp
LINK GearSvc
Gaudi::GaudiAlgLib
Gaudi::GaudiKernel
diff --git a/Reconstruction/RecGenfitAlg/src/GenfitField.cpp b/Reconstruction/RecGenfitAlg/src/GenfitField.cpp
index 744084254..e0b8e3548 100644
--- a/Reconstruction/RecGenfitAlg/src/GenfitField.cpp
+++ b/Reconstruction/RecGenfitAlg/src/GenfitField.cpp
@@ -1,4 +1,5 @@
#include "GenfitField.h"
+#include "GenfitUnit.h"
//External
#include "DD4hep/DD4hepUnits.h"
@@ -39,16 +40,21 @@ GenfitField::get(const double& posX, const double& posY, const double& posZ,
{
/// get field from dd4hepField
const dd4hep::Direction& field=m_dd4hepField.magneticField(
- dd4hep::Position(posX/dd4hep::cm,posY/dd4hep::cm,posZ/dd4hep::cm));
- //m_dd4hepField.magneticField(pos,B);
-
- Bx=field.X()/dd4hep::kilogauss;
- By=field.Y()/dd4hep::kilogauss;
- Bz=field.Z()/dd4hep::kilogauss;
-
-// std::cout<<"GenfitField "
-// <