diff --git a/Detector/DetCRD/CMakeLists.txt b/Detector/DetCRD/CMakeLists.txt index 9b8942ee0781a16a2f7c7bb0a5313d5e12334f11..6062572c26a34c19e31d081837ea89cddedd8dd9 100644 --- a/Detector/DetCRD/CMakeLists.txt +++ b/Detector/DetCRD/CMakeLists.txt @@ -8,6 +8,7 @@ gaudi_add_module(DetCRD src/Calorimeter/LongCrystalBarBarrelCalorimeter32Polygon_v01.cpp src/Calorimeter/LongCrystalBarEndcapCalorimeter_v01.cpp src/Calorimeter/LongCrystalBarEndcapCalorimeter_v02.cpp + src/Calorimeter/LongCrystalBarEndcapCalorimeter_v03.cpp src/Calorimeter/CRDEcal_Short_v02.cpp src/Calorimeter/CRDEcal_Endcap_Short_v01.cpp src/Calorimeter/RotatedPolyhedraBarrelCalorimeter_v01_geo.cpp diff --git a/Detector/DetCRD/compact/CRD_common_v01/Ecal_Crystal_Endcap_v01_03.xml b/Detector/DetCRD/compact/CRD_common_v01/Ecal_Crystal_Endcap_v01_03.xml new file mode 100755 index 0000000000000000000000000000000000000000..e7a16833ce200b7b956c6540ad7115ba1faaf757 --- /dev/null +++ b/Detector/DetCRD/compact/CRD_common_v01/Ecal_Crystal_Endcap_v01_03.xml @@ -0,0 +1,85 @@ +<lccdd> + <define> + <!-- <constant name="Ecal_endcap_inner_radius" value="2.5*mm"/> + <constant name="Ecal_endcap_inner_radius" value="2.5*mm"/> --> + <constant name="Ecal_endcap_nlayers" value="28"/> + <constant name="Ecal_scintillator_thickness" value="10*mm"/> + <constant name="Ecal_deadarea_thickness" value="8.5*mm"/> + <constant name="Ecal_module_safety" value="0.5*mm"/> + </define> + + <detectors> + <detector id="DetID_ECAL_ENDCAP" name="EcalEndcap" type="LongCrystalBarEndcapCalorimeter_v03" readout="EcalEndcapsCollection" vis="CyanVis" calorimeterType="EMC_ENDCAP"> + <comment>Electromagnetic Calorimeter Endcap</comment> + + <envelope vis="SeeThrough"> + <shape type="BooleanShape" operation="Subtraction" material="Air"> + <shape type="BooleanShape" operation="Subtraction" material="Air"> + <!-- <shape type="Tube" rmin="0.0" rmax="Ecal_endcap_outer_radius - env_safety" dz="Ecal_endcap_zmax"/> --> + <!--there is a thin plane in envolop --> + <!-- <shape type="Tube" rmin="0.0" rmax="Ecal_endcap_outer_radius + env_safety" dz="Ecal_endcap_zmin"/> --> + <shape type="PolyhedraRegular" numsides="256" rmin="0.0" rmax="Hcal_barrel_inner_radius - 5*mm" dz="Ecal_endcap_zmax*2"/> + <shape type="PolyhedraRegular" numsides="256" rmin="0.0" rmax="Hcal_barrel_inner_radius - 5*mm" dz="Ecal_endcap_zmin*2"/> + </shape> + <!-- <shape type="Box" dx="Ecal_endcap_inner_radius" dy="Ecal_endcap_inner_radius" dz="Ecal_endcap_zmax + env_safety"/> --> + <shape type="Tube" rmin="0.0" rmax="Ecal_endcap_inner_radius" dz="Ecal_endcap_zmax + env_safety"/> + </shape> + <rotation x="0" y="0" z="0"/> + <!-- <rotation x="0" y="0" z="11.25"/> --> + </envelope> + + <type_flags type=" DetType_CALORIMETER + DetType_ENDCAP + DetType_EMC " /> + + <material name="CarbonFiber"/> + + <dimensions numsides="Ecal_x_module" > <!-- 0:cube 1:isosceles trapezoid 2:right trapezoid --> + <dimensions id="0" module_type="0" module_number="3" x_offset="768*mm" y_offset="768*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="326*mm" dim_y="326*mm" dim_z="300*mm"/> + <dimensions id="1" module_type="0" module_number="2" x_offset="1069*mm" y_offset="1069*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="276*mm" dim_y="276*mm" dim_z="300*mm"/> + <dimensions id="2" module_type="0" module_number="1" x_offset="1305.5*mm" y_offset="1305.5*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="197*mm" dim_y="197*mm" dim_z="300*mm"/> + <dimensions id="0" module_type="20" module_number="3" x_offset="768*mm" y_offset="768*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="326*mm" dim_y="326*mm" dim_z="300*mm"/> + <dimensions id="1" module_type="20" module_number="2" x_offset="1069*mm" y_offset="1069*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="276*mm" dim_y="276*mm" dim_z="300*mm"/> + <dimensions id="2" module_type="20" module_number="1" x_offset="1305.5*mm" y_offset="1305.5*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="197*mm" dim_y="197*mm" dim_z="300*mm"/> + + <dimensions id="3" module_type="1" module_number="4" x_offset="570.5*mm" y_offset="0*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="574*mm" dim_x2="495*mm" dim_y1="441*mm" dim_y2="441*mm" dim_z="300*mm" /> + <dimensions id="4" module_type="2" module_number="4" x_offset="570.5*mm" y_offset="0*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="574*mm" dim_x2="495*mm" dim_y1="441*mm" dim_y2="441*mm" dim_z="300*mm" /> + <dimensions id="3" module_type="21" module_number="4" x_offset="570.5*mm" y_offset="0*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="574*mm" dim_x2="495*mm" dim_y1="441*mm" dim_y2="441*mm" dim_z="300*mm" /> + <dimensions id="4" module_type="22" module_number="4" x_offset="570.5*mm" y_offset="0*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="574*mm" dim_x2="495*mm" dim_y1="441*mm" dim_y2="441*mm" dim_z="300*mm" /> + + <dimensions id="5" module_type="3" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/> + <dimensions id="6" module_type="4" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/> + <dimensions id="7" module_type="5" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/> + <dimensions id="8" module_type="6" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/> + <dimensions id="9" module_type="7" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/> + <dimensions id="10" module_type="8" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/> + <dimensions id="11" module_type="9" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/> + <dimensions id="12" module_type="10" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/> + + <dimensions id="13" module_type="11" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/> + <dimensions id="14" module_type="12" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/> + <dimensions id="15" module_type="13" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/> + <dimensions id="16" module_type="14" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/> + <dimensions id="17" module_type="15" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/> + <dimensions id="18" module_type="16" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/> + <dimensions id="19" module_type="17" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/> + <dimensions id="20" module_type="18" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/> + + </dimensions> + + <layer repeat="Ecal_endcap_nlayers" vis="CyanVis" material="G4_BGO" thickness = "Ecal_scintillator_thickness"> + <slice material="G4_BGO" thickness = "Ecal_scintillator_thickness" sensitive = "yes" limits="cal_limits" vis="CyanVis" /> + </layer> + </detector> + </detectors> + + <readouts> + <readout name="EcalEndcapsCollection"> + <segmentation type="NoSegmentation"/> + <id>system:5,module:1,part:7,stave:7,type:4,dlayer:4,slayer:1,bar:7</id> + </readout> + </readouts> + +</lccdd> + + + + diff --git a/Detector/DetCRD/compact/TDR_CaloTest/TDR_longEcalEndcap.xml b/Detector/DetCRD/compact/TDR_CaloTest/TDR_longEcalEndcap.xml new file mode 100755 index 0000000000000000000000000000000000000000..4d62fdd93a51ac988bc6a5848892358e6610186c --- /dev/null +++ b/Detector/DetCRD/compact/TDR_CaloTest/TDR_longEcalEndcap.xml @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="UTF-8"?> +<lccdd xmlns:compact="http://www.lcsim.org/schemas/compact/1.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/compact/1.0/compact.xsd"> + <info name="TDR_o1_v01" + title="CepC reference detctor for TDR" + author="" + url="http://cepc.ihep.ac.cn" + status="developing" + version="v01"> + <comment>CepC reference detector simulation models used for TDR </comment> + </info> + + <includes> + <gdmlFile ref="${DD4hepINSTALL}/DDDetectors/compact/elements.xml"/> + <gdmlFile ref="../CRD_common_v02/materials.xml"/> + </includes> + + <define> + <constant name="world_size" value="10*m"/> + <constant name="world_x" value="world_size"/> + <constant name="world_y" value="world_size"/> + <constant name="world_z" value="world_size"/> + + <include ref="${DD4hepINSTALL}/DDDetectors/compact/detector_types.xml"/> + </define> + + <include ref="./TDR_Dimensions_v01_01.xml"/> + + <!--TODO: vertex cooling--> + <!-- <include ref="../CRD_common_v02/Beampipe_v01_03.xml"/> --> + <!--preliminary vertex and tracker, to update/--> + <!-- <include ref="../CRD_common_v02/VXD_StaggeredLadder_v02_01.xml"/> --> + <!-- <include ref="../CRD_common_v02/FTD_SkewRing_v01_05.xml"/> --> + <!-- <include ref="../CRD_common_v02/SIT_SimplePixel_v01_03.xml"/> --> + <!--include ref="../CRD_common_v01/TPC_Simple_v10_02.xml"/--> + <!--use 10 rows clustering version/--> + <!-- <include ref="../CRD_common_v02/TPC_ModularEndcap_o1_v02.xml"/> --> + <!-- <include ref="../CRD_common_v01/SET_SimplePixel_v01_01.xml"/> --> + + <!-- <include ref="../CRD_common_v01/Ecal_Crystal_Barrel_v01_02.xml"/> --> + <include ref="../CRD_common_v01/Ecal_Crystal_Endcap_v01_02.xml"/> + <!-- <include ref="../CRD_common_v01/SHcalGlass_Barrel_v05.xml"/> --> + <!-- <include ref="../CRD_common_v01/SHcalGlass_Endcaps_v01.xml"/> --> + + <!--Lumical to update--> + <!-- <include ref="../CRD_common_v01/Lumical_o1_v01.xml"/> --> + <!--preliminary Magnet, to update/--> + <!-- <include ref="../CRD_common_v02/Coil_Simple_v01_02.xml"/> --> + <!--preliminary Muon, obselete/--> + <!--include ref="../CRD_common_v02/Yoke_Polyhedra_Barrel_v01_01.xml"/> + <include ref="../CRD_common_v02/Yoke_Polyhedra_Endcaps_v01_01.xml"/--> + + <!--muon detector--> + <!-- <include ref="../CRD_common_v01/Muon_Barrel_v01_01.xml"/> --> + <!-- <include ref="../CRD_common_v01/Muon_Endcap_v01_01.xml"/> --> + + <fields> + <field name="InnerSolenoid" type="solenoid" + inner_field="Field_nominal_value" + outer_field="0" + zmax="SolenoidCoil_half_length" + inner_radius="SolenoidCoil_center_radius" + outer_radius="Solenoid_outer_radius"> + </field> + <field name="OuterSolenoid" type="solenoid" + inner_field="0" + outer_field="Field_outer_nominal_value" + zmax="SolenoidCoil_half_length" + inner_radius="Solenoid_outer_radius" + outer_radius="Yoke_barrel_inner_radius"> + </field> + </fields> + +</lccdd> diff --git a/Detector/DetCRD/compact/TDR_CaloTest/TDR_onlyLongEcal.xml b/Detector/DetCRD/compact/TDR_CaloTest/TDR_onlyLongEcal.xml new file mode 100644 index 0000000000000000000000000000000000000000..0843ba0e4919c0ca686f34bfcb243dfbfa0193bf --- /dev/null +++ b/Detector/DetCRD/compact/TDR_CaloTest/TDR_onlyLongEcal.xml @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="UTF-8"?> +<lccdd xmlns:compact="http://www.lcsim.org/schemas/compact/1.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/compact/1.0/compact.xsd"> + <info name="TDR_o1_v01" + title="CepC reference detctor for TDR" + author="" + url="http://cepc.ihep.ac.cn" + status="developing" + version="v01"> + <comment>CepC reference detector simulation models used for TDR </comment> + </info> + + <includes> + <gdmlFile ref="${DD4hepINSTALL}/DDDetectors/compact/elements.xml"/> + <gdmlFile ref="../CRD_common_v02/materials.xml"/> + </includes> + + <define> + <constant name="world_size" value="10*m"/> + <constant name="world_x" value="world_size"/> + <constant name="world_y" value="world_size"/> + <constant name="world_z" value="world_size"/> + + <include ref="${DD4hepINSTALL}/DDDetectors/compact/detector_types.xml"/> + </define> + + <include ref="./TDR_Dimensions_v01_01.xml"/> + + <!--TODO: vertex cooling--> + <!--include ref="../CRD_common_v02/Beampipe_v01_03.xml"/--> + <!--preliminary vertex and tracker, to update/--> + <!--include ref="../CRD_common_v02/VXD_StaggeredLadder_v02_01.xml"/> + <include ref="../CRD_common_v02/FTD_SkewRing_v01_05.xml"/> + <include ref="../CRD_common_v02/SIT_SimplePixel_v01_03.xml"/--> + <!--include ref="../CRD_common_v01/TPC_Simple_v10_02.xml"/--> + <!--use 10 rows clustering version/--> + <!--include ref="../CRD_common_v02/TPC_ModularEndcap_o1_v02.xml"/> + <include ref="../CRD_common_v01/SET_SimplePixel_v01_01.xml"/--> + + <include ref="../CRD_common_v01/Ecal_Crystal_Barrel_v01_02.xml"/> + <include ref="../CRD_common_v01/Ecal_Crystal_Endcap_v01_01.xml"/> + <!--include ref="../CRD_common_v01/SHcalSc04_Barrel_v04_01.xml"/--> + <!--include ref="../CRD_common_v01/SHcalSc04_Endcaps_v02.xml"/--> + + <!--Lumical to update--> + <!--include ref="../CRD_common_v01/Lumical_o1_v01.xml"/--> + <!--preliminary Magnet, to update/--> + <!--include ref="../CRD_common_v02/Coil_Simple_v01_02.xml"/--> + <!--preliminary Muon, obselete/--> + <!--include ref="../CRD_common_v02/Yoke_Polyhedra_Barrel_v01_01.xml"/> + <include ref="../CRD_common_v02/Yoke_Polyhedra_Endcaps_v01_01.xml"/--> + + <!--muon detector--> + <!--include ref="../CRD_common_v01/Muon_Barrel_v01_01.xml"/--> + <!--include ref="../CRD_common_v01/Muon_Endcap_v01_01.xml"/--> + + <fields> + <field name="InnerSolenoid" type="solenoid" + inner_field="0" + outer_field="0" + zmax="SolenoidCoil_half_length" + inner_radius="SolenoidCoil_center_radius" + outer_radius="Solenoid_outer_radius"> + </field> + <field name="OuterSolenoid" type="solenoid" + inner_field="0" + outer_field="0" + zmax="SolenoidCoil_half_length" + inner_radius="Solenoid_outer_radius" + outer_radius="Yoke_barrel_inner_radius"> + </field> + </fields> + +</lccdd> diff --git a/Detector/DetCRD/compact/TDR_o1_v01/TDR_Dimensions_v01_01.xml b/Detector/DetCRD/compact/TDR_o1_v01/TDR_Dimensions_v01_01.xml index 6141a55826c934d94f1965a19606867f23630449..ea9d8d90df5fd06e5423fa9809ae8094cd03ade0 100644 --- a/Detector/DetCRD/compact/TDR_o1_v01/TDR_Dimensions_v01_01.xml +++ b/Detector/DetCRD/compact/TDR_o1_v01/TDR_Dimensions_v01_01.xml @@ -162,7 +162,7 @@ <constant name="Ecal_barrel_symmetry" value="32"/> <constant name="Ecal_Tpc_gap" value="Ecal_barrel_inner_radius-TPC_outer_radius"/> - <constant name="Ecal_endcap_inner_radius" value="400*mm"/> + <constant name="Ecal_endcap_inner_radius" value="350*mm"/> <constant name="Ecal_endcap_outer_radius" value="Ecal_barrel_outer_radius"/> <constant name="Ecal_endcap_zmin" value="2930*mm"/> <constant name="Ecal_endcap_thickness" value="Ecal_barrel_thickness"/> diff --git a/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01-onlyEcal.xml b/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01-onlyEcal.xml new file mode 100644 index 0000000000000000000000000000000000000000..d67ce50cb20ec782c12dfc4b8fef7f52365d383d --- /dev/null +++ b/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01-onlyEcal.xml @@ -0,0 +1,51 @@ +<?xml version="1.0" encoding="UTF-8"?> +<lccdd xmlns:compact="http://www.lcsim.org/schemas/compact/1.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/compact/1.0/compact.xsd"> + <info name="TDR_o1_v01" + title="CepC reference detctor for TDR" + author="" + url="http://cepc.ihep.ac.cn" + status="developing" + version="v01"> + <comment>CepC reference detector simulation models used for TDR </comment> + </info> + + <includes> + <gdmlFile ref="${DD4hepINSTALL}/DDDetectors/compact/elements.xml"/> + <gdmlFile ref="../CRD_common_v02/materials.xml"/> + </includes> + + <define> + <constant name="world_size" value="10*m"/> + <constant name="world_x" value="world_size"/> + <constant name="world_y" value="world_size"/> + <constant name="world_z" value="world_size"/> + + <include ref="${DD4hepINSTALL}/DDDetectors/compact/detector_types.xml"/> + </define> + + <include ref="./TDR_Dimensions_v01_01.xml"/> + + <include ref="../CRD_common_v01/Ecal_Crystal_Barrel_v01_02.xml"/> + <!--preliminary EcalEndcaps/--> + <include ref="../CRD_common_v02/EcalEndcaps_Polyhedra_v01_01.xml"/> + + <fields> + <field name="InnerSolenoid" type="solenoid" + inner_field="Field_nominal_value" + outer_field="0" + zmax="SolenoidCoil_half_length" + inner_radius="SolenoidCoil_center_radius" + outer_radius="Solenoid_outer_radius"> + </field> + <field name="OuterSolenoid" type="solenoid" + inner_field="0" + outer_field="Field_outer_nominal_value" + zmax="SolenoidCoil_half_length" + inner_radius="Solenoid_outer_radius" + outer_radius="Yoke_barrel_inner_radius"> + </field> + </fields> + +</lccdd> diff --git a/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01.xml b/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01.xml index c92582589828e3b3d87e572ea0ca4d400e6e442d..4ddc0ae2f2ff11ab9d78900490f4bcf3f8fdee3c 100644 --- a/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01.xml +++ b/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01.xml @@ -42,7 +42,7 @@ <!--include ref="../CRD_common_v01/OTKEndcap_v01_01.xml"/--> <include ref="../CRD_common_v01/Ecal_Crystal_Barrel_v01_02.xml"/> - <include ref="../CRD_common_v01/Ecal_Crystal_Endcap_v01_02.xml"/> + <include ref="../CRD_common_v01/Ecal_Crystal_Endcap_v01_03.xml"/> <include ref="../CRD_common_v01/SHcalGlass_Barrel_v05.xml"/> <include ref="../CRD_common_v01/SHcalGlass_Endcaps_v01.xml"/> diff --git a/Detector/DetCRD/src/Calorimeter/LongCrystalBarEndcapCalorimeter_v03.cpp b/Detector/DetCRD/src/Calorimeter/LongCrystalBarEndcapCalorimeter_v03.cpp new file mode 100755 index 0000000000000000000000000000000000000000..1d69fea7362a2d53940aee50c5bd3ebe2ca5c10d --- /dev/null +++ b/Detector/DetCRD/src/Calorimeter/LongCrystalBarEndcapCalorimeter_v03.cpp @@ -0,0 +1,734 @@ +#include "DD4hep/DetFactoryHelper.h" +#include "DD4hep/DetType.h" +#include "XML/Layering.h" +#include "XML/Utilities.h" +#include "DDRec/DetectorData.h" +#include "DDSegmentation/BitField64.h" +#include "DDSegmentation/Segmentation.h" +#include "DDSegmentation/MultiSegmentation.h" +#include "DetIdentifier/CEPCDetectorData.h" +// #include "LcgeoExceptions.h" + +using namespace std; + +using dd4hep::BUILD_ENVELOPE; +using dd4hep::BitField64; +using dd4hep::Box; +using dd4hep::Trapezoid; +using dd4hep::Trap; +using dd4hep::EightPointSolid; +using dd4hep::DetElement; +using dd4hep::DetType; +using dd4hep::Detector; +using dd4hep::Layering; +using dd4hep::Material; +using dd4hep::PlacedVolume; +using dd4hep::Position; +using dd4hep::Readout; +using dd4hep::Ref_t; +using dd4hep::RotationX; +using dd4hep::RotationY; +using dd4hep::RotationZ; +using dd4hep::RotationZYX; +using dd4hep::Segmentation; +using dd4hep::SensitiveDetector; +using dd4hep::Transform3D; +using dd4hep::Translation3D; +using dd4hep::Volume; +using dd4hep::_toString; + +using dd4hep::rec::LayeredCalorimeterData; + +static Ref_t create_detector(Detector& theDetector, xml_h element, SensitiveDetector sens) { + xml_det_t x_det = element; + Layering layering(x_det); +// xml_dim_t dim = x_det.dimensions(); + string det_name = x_det.nameStr(); + +// Material air = theDetector.air(); + Material stavesMaterial = theDetector.material(x_det.materialStr()); +// int numSides = dim.numsides(); + + int det_id = x_det.id(); + + DetElement sdet(det_name,det_id); + + PlacedVolume pVol; + + // --- create an envelope volume and position it into the world --------------------- + + Volume envelope = dd4hep::xml::createPlacedEnvelope( theDetector, element , sdet ) ; + // envelopePlv.addPhysVolID("system",x_det.id()); +// sdet.setTypeFlag( DetType::CALORIMETER | DetType::ENDCAP | DetType::HADRONIC ) ; + +// if( theDetector.buildType() == BUILD_ENVELOPE ) return sdet ; + //----------------------------------------------------------------------------------- + + sens.setType("calorimeter"); + + dd4hep::rec::ECALSystemInfoData* ecalSystemInfoData = new dd4hep::rec::ECALSystemInfoData; + ecalSystemInfoData->systemNumber = det_id; + + DetElement stave_det("module0stave0part0",det_id); + + double EcalEndcap_inner_radius = theDetector.constant<double>("Ecal_endcap_inner_radius"); + double EcalEndcap_outer_radius = theDetector.constant<double>("Ecal_endcap_outer_radius"); + double EcalEndcap_min_z = theDetector.constant<double>("Ecal_endcap_zmin"); + double EcalEndcap_max_z = theDetector.constant<double>("Ecal_endcap_zmax"); + + double EcalEndcap_deadarea_thickness = theDetector.constant<double>("Ecal_deadarea_thickness"); + + int endcapID = 0; + + double dim_x = 0.001; + double dim_x1 = 0.001; + double dim_x2 = 0.001; + double dim_y = 0.001; + double dim_y1 = 0.001; + double dim_y2 = 0.001; + double dim_z = 0.001; + double box_half_x= 0.001; + double box_half_y= 0.001; + double box_half_z= 0.001; + double trap_half_x1= 0.001; + double trap_half_x2= 0.001; + double trap_half_y1= 0.001; + double trap_half_y2= 0.001; + double trap_half_z= 0.001; + + double pos_x = 0; + double pos_y = 0; + double pos_z = 0; + double EndcapModule_center_pos_x = 0; + double EndcapModule_center_pos_y = 0; + double EndcapModule_center_pos_z = 0; + + int all_module0 = 0; + int all_module1 = 0; + int all_module2 = 0; + int all_module3 = 0; + + for(xml_coll_t c(x_det.child(_U(dimensions)),_U(dimensions)); c; ++c) { + xml_comp_t l(c); + int N_bar = 0; + double volume_bar = 0; + + int module_type = l.attr<int>(_Unicode(module_type)); + int module_tag = l.attr<int>(_Unicode(id)); + int module_number = l.attr<int>(_Unicode(module_number)); + + if(module_type == 0 || module_type == 20){ + dim_x = l.attr<double>(_Unicode(dim_x)); + dim_y = l.attr<double>(_Unicode(dim_y)); + dim_z = l.attr<double>(_Unicode(dim_z)); + pos_x = l.attr<double>(_Unicode(x_offset)); + pos_y = l.attr<double>(_Unicode(y_offset)); + pos_z = l.attr<double>(_Unicode(z_offset)); + box_half_x = dim_x/2.0; + box_half_y = dim_y/2.0; + box_half_z = dim_z/2.0; + } + else if(module_type == 1 || module_type == 2 || module_type == 21 || module_type == 22){ + dim_x1 = l.attr<double>(_Unicode(dim_x1)); + dim_x2 = l.attr<double>(_Unicode(dim_x2)); + dim_y1 = l.attr<double>(_Unicode(dim_y1)); + dim_y2 = l.attr<double>(_Unicode(dim_y2)); + dim_z = l.attr<double>(_Unicode(dim_z)); + pos_x = l.attr<double>(_Unicode(x_offset)); + pos_y = l.attr<double>(_Unicode(y_offset)); + pos_z = l.attr<double>(_Unicode(z_offset)); + trap_half_x1 = dim_x1/2; + trap_half_x2 = dim_x2/2; + trap_half_y1 = dim_y1/2; + trap_half_y2 = dim_y2/2; + trap_half_z = dim_z/2; + } + else if(module_type == 3 || module_type == 4 || module_type == 5 || module_type == 6 + || module_type == 7 || module_type == 8 || module_type == 9 || module_type == 10){ + dim_x1 = l.attr<double>(_Unicode(dim_x1)); + dim_x2 = l.attr<double>(_Unicode(dim_x2)); + dim_x = l.attr<double>(_Unicode(dim_y1)); + dim_y = l.attr<double>(_Unicode(dim_y1)); + dim_y1 = l.attr<double>(_Unicode(dim_y1)); + dim_y2 = l.attr<double>(_Unicode(dim_y2)); + dim_z = l.attr<double>(_Unicode(dim_z)); + pos_x = l.attr<double>(_Unicode(x_offset)); + pos_y = l.attr<double>(_Unicode(y_offset)); + pos_z = l.attr<double>(_Unicode(z_offset)); + trap_half_x1 = dim_x1; + trap_half_x2 = dim_x2; + trap_half_y1 = dim_y1; + trap_half_y2 = dim_y2; + trap_half_z = dim_z; + } + else { + dim_x = l.attr<double>(_Unicode(dim_x)); + dim_y = l.attr<double>(_Unicode(dim_y)); + dim_z = l.attr<double>(_Unicode(dim_z)); + pos_x = l.attr<double>(_Unicode(x_offset)); + pos_y = l.attr<double>(_Unicode(y_offset)); + pos_z = l.attr<double>(_Unicode(z_offset)); + } + + + std::cout << "module_type: " << module_type << std::endl; + std::cout << "module_number: " << module_number << std::endl; + std::cout << "dim_x: " << dim_x << std::endl; + std::cout << "dim_x1: " << dim_x1 << std::endl; + std::cout << "dim_x2: " << dim_x2 << std::endl; + std::cout << "dim_y: " << dim_y << std::endl; + std::cout << "dim_y1: " << dim_y1 << std::endl; + std::cout << "dim_y2: " << dim_y2 << std::endl; + std::cout << "dim_z: " << dim_z << std::endl; + std::cout << "pos_x: " << pos_x << std::endl; + std::cout << "pos_y: " << pos_y << std::endl; + std::cout << "pos_z: " << pos_z << std::endl; + + + Box EndcapModule(box_half_x,box_half_y,box_half_z); + Trapezoid EndcapTrapIso(trap_half_x1, trap_half_x2, trap_half_y1, trap_half_y2, trap_half_z); + Trap EndcapTrapRight(trap_half_y1, trap_half_z, trap_half_x1, trap_half_x2); + double vertices[] = {-dim_x, -dim_x, -dim_x, dim_y, dim_y, dim_y, dim_y, -dim_x, -dim_x, -dim_x, -dim_x, dim_x, dim_x, dim_x, dim_x, -dim_x}; + EightPointSolid EndcapPrism(dim_z/2, vertices); + + string envelopeVol_name = det_name+_toString(endcapID,"_EndcapModule%d"); + string envelopeVolTrapIso_name = det_name+_toString(endcapID,"_EndcapModule%d"); + string envelopeVolTrapRight_name = det_name+_toString(endcapID,"_EndcapModule%d"); + string envelopeVolPrism_name = det_name+_toString(endcapID,"_EndcapModule%d"); + + Volume envelopeVol(envelopeVol_name,EndcapModule,stavesMaterial); + Volume envelopeVolTrapIso(envelopeVolTrapIso_name,EndcapTrapIso,stavesMaterial); + Volume envelopeVolTrapRight(envelopeVolTrapRight_name,EndcapTrapRight,stavesMaterial); + Volume envelopeVolPrism(envelopeVolPrism_name,EndcapPrism,stavesMaterial); + + envelopeVol.setAttributes(theDetector,x_det.regionStr(),x_det.limitsStr(),x_det.visStr()); + envelopeVolTrapIso.setAttributes(theDetector,x_det.regionStr(),x_det.limitsStr(),x_det.visStr()); + envelopeVolTrapRight.setAttributes(theDetector,x_det.regionStr(),x_det.limitsStr(),x_det.visStr()); + envelopeVolPrism.setAttributes(theDetector,x_det.regionStr(),x_det.limitsStr(),x_det.visStr()); + + double layer_pos_z = -dim_z/2; + int layer_num = 1; + std::vector<dd4hep::rec::ECALModuleInfoData::LayerInfo> layerInfos; + layerInfos.clear(); + + for(xml_coll_t m(x_det,_U(layer)); m; ++m){ // loop over layers + xml_comp_t x_layer = m; + int repeat = x_layer.repeat(); + double layer_thickness = x_layer.thickness(); + string layer_name = (module_type == 0 || module_type == 20) ? envelopeVol_name+_toString(0,"_Layer%d") : (module_type == 1 || module_type == 2 || module_type == 21 || module_type == 22) ? envelopeVolTrapIso_name+_toString(1,"_Layer%d") + : (module_type == 3 || module_type == 4 || module_type == 5 || module_type == 6 || module_type == 7 || module_type == 8 || module_type == 9 || module_type == 10) ? envelopeVolTrapRight_name+_toString(2,"_Layer%d") + : envelopeVolPrism_name+_toString(3,"_Layer%d"); + DetElement layer(stave_det, layer_name, det_id); + Material layer_material = theDetector.material(x_layer.materialStr()); + + if(module_type == 0 || module_type == 20){ // for cube first place bar then place layer + double rot_layer = 0; + double active_layer_dim_x = box_half_x - EcalEndcap_deadarea_thickness; + double active_layer_dim_y = box_half_y - EcalEndcap_deadarea_thickness; + double active_layer_dim_z = layer_thickness/2.0; + + Volume layer_vol(layer_name, Box(active_layer_dim_x, active_layer_dim_y, active_layer_dim_z), layer_material); + + for (int ihardware = 0; ihardware < int(active_layer_dim_y*2/layer_thickness); ihardware++){ + string hardware_name = layer_name + _toString(ihardware,"_hardware%d"); + Material hardware_material = layer_material; + DetElement hardware(layer, _toString(ihardware,"hardware%d"), det_id); + Volume hardware_vol(hardware_name,Box(active_layer_dim_x, layer_thickness / 2.0, layer_thickness/2.0), hardware_material); + hardware_vol.setSensitiveDetector(sens); + hardware_vol.setAttributes(theDetector,x_layer.regionStr(),x_layer.limitsStr(),x_layer.visStr()); + PlacedVolume hardware_phv = layer_vol.placeVolume(hardware_vol,Position(0, -active_layer_dim_y + layer_thickness/2 + layer_thickness*ihardware, 0)); + hardware_phv.addPhysVolID("bar",ihardware); + hardware.setPlacement(hardware_phv); + } + + layer_vol.setAttributes(theDetector,x_layer.regionStr(),x_layer.limitsStr(),x_layer.visStr()); + layer_pos_z += layer_thickness / 2.0; + + for (int j = 0; j < repeat; j++){ + if(module_type == 0) rot_layer = (j%2==0)? -M_PI/2 : M_PI; + else rot_layer = (j%2==0)? -M_PI/2 : 0; + PlacedVolume layer_phv = envelopeVol.placeVolume(layer_vol, Transform3D(RotationZYX(rot_layer, 0, 0), Position(0,0,layer_pos_z))); + + dd4hep::rec::ECALModuleInfoData::LayerInfo layerInfo; + if(j%2==0){ + layerInfo.dlayerNumber = layer_num; + layerInfo.slayerNumber = 0; + layerInfo.barNumber = int(active_layer_dim_y*2/layer_thickness); + layer_phv.addPhysVolID("slayer", 0).addPhysVolID("dlayer", layer_num); + } + else{ + layerInfo.dlayerNumber = layer_num; + layerInfo.slayerNumber = 1; + layerInfo.barNumber = int(active_layer_dim_y*2/layer_thickness); + layer_phv.addPhysVolID("slayer", 1).addPhysVolID("dlayer", layer_num); + ++layer_num; + } + + layer.setPlacement(layer_phv); + layer_pos_z += layer_thickness; + layerInfos.push_back(layerInfo); + } + + N_bar = N_bar + int(active_layer_dim_y*2/layer_thickness)*repeat; + volume_bar = volume_bar + active_layer_dim_x*2*2*active_layer_dim_y*layer_thickness*repeat; + } + else{ //for trap first place layer then place bar + layer_pos_z += layer_thickness / 2.0; + double rot_layer = 0; + double delta_layer = 0; + for (int j = 0; j < repeat; j++){ + + delta_layer = (module_type == 1 || module_type == 2 || module_type == 21 || module_type == 22) ? layer_thickness*(trap_half_x1 - trap_half_x2)/dim_z + : (module_type == 3 || module_type == 4 || module_type == 5 || module_type == 6 || module_type == 7 || module_type == 8 || module_type == 9 || module_type == 10) ? layer_thickness*(dim_x2 - dim_x1)/dim_z + : layer_thickness*(dim_x-dim_y)/dim_z; + + double active_layer_dim_x = (module_type == 1 || module_type == 2 || module_type == 21 || module_type == 22) ? trap_half_y1 - EcalEndcap_deadarea_thickness + : (module_type == 3 || module_type == 4 || module_type == 5 || module_type == 6 || module_type == 7 || module_type == 8 || module_type == 9 || module_type == 10) ? trap_half_x1/2 - EcalEndcap_deadarea_thickness + j*delta_layer/2 + : (dim_x+dim_y)/2 - EcalEndcap_deadarea_thickness + j*delta_layer/2; + double active_layer_dim_y = (module_type == 1 || module_type == 2 || module_type == 21 || module_type == 22) ? trap_half_x1 - EcalEndcap_deadarea_thickness - j*delta_layer + : (module_type == 3 || module_type == 4 || module_type == 5 || module_type == 6 || module_type == 7 || module_type == 8 || module_type == 9 || module_type == 10) ? layer_thickness/2.0 + : (dim_x+dim_y)/2 - EcalEndcap_deadarea_thickness + j*delta_layer/2; + double active_layer_dim_z = (module_type == 1 || module_type == 2 || module_type == 21 || module_type == 22) ? layer_thickness/2.0 + : (module_type == 3 || module_type == 4 || module_type == 5 || module_type == 6 || module_type == 7 || module_type == 8 || module_type == 9 || module_type == 10) ? trap_half_y1/2 - EcalEndcap_deadarea_thickness + : layer_thickness/2.0; + + Volume layer_vol(layer_name, Box(active_layer_dim_x, active_layer_dim_y, active_layer_dim_z), layer_material); + int hardware_num = 0; + + if(module_type == 1 || module_type == 21){ + hardware_num = (j%2==0) ? int(active_layer_dim_x*2/layer_thickness) : int(active_layer_dim_y*2/layer_thickness); + } + else if(module_type == 2 || module_type == 22){ + hardware_num = (j%2==0) ? int(active_layer_dim_y*2/layer_thickness) : int(active_layer_dim_x*2/layer_thickness); + } + else if(module_type == 3 || module_type == 4 || module_type == 5 || module_type == 6){ + hardware_num = (j%2==0) ? int(active_layer_dim_z*2/layer_thickness) : int(active_layer_dim_x*2/layer_thickness); + } + else if(module_type == 7 || module_type == 8 || module_type == 9 || module_type == 10){ + hardware_num = (j%2==0) ? int(active_layer_dim_x*2/layer_thickness) : int(active_layer_dim_z*2/layer_thickness); + } + else { + hardware_num = (j%2==0) ? int(active_layer_dim_x*2/layer_thickness) : int(active_layer_dim_y*2/layer_thickness); + } + + double hardware_x = 0; + double hardware_y = 0; + double hardware_z = 0; + double hardware_x_pos = 0; + double hardware_y_pos = 0; + double hardware_z_pos = 0; + + for (int ihardware = 0; ihardware < hardware_num; ihardware++){ + string hardware_name = layer_name + _toString(ihardware,"_hardware%d"); + Material hardware_material = layer_material; + DetElement hardware(layer, _toString(j,"layer%d") + _toString(ihardware,"hardware%d"), det_id); + if(module_type == 1 || module_type == 21){ + hardware_x = (j%2==0) ? layer_thickness / 2.0 : active_layer_dim_x; + hardware_y = (j%2==0) ? active_layer_dim_y : layer_thickness / 2.0; + hardware_z = layer_thickness/2.0; + } + else if(module_type == 2 || module_type == 22){ + hardware_x = (j%2==0) ? active_layer_dim_x : layer_thickness / 2.0; + hardware_y = (j%2==0) ? layer_thickness / 2.0 : active_layer_dim_y; + hardware_z = layer_thickness/2.0; + } + else if(module_type == 3 || module_type == 4 || module_type == 5 || module_type == 6){ + hardware_x = (j%2==0) ? active_layer_dim_x : layer_thickness / 2.0; + hardware_y = layer_thickness / 2.0; + hardware_z = (j%2==0) ? layer_thickness / 2.0 : active_layer_dim_z; + } + else if(module_type == 7 || module_type == 8 || module_type == 9 || module_type == 10){ + hardware_x = (j%2==0) ? layer_thickness / 2.0 : active_layer_dim_x; + hardware_y = layer_thickness / 2.0; + hardware_z = (j%2==0) ? active_layer_dim_z : layer_thickness / 2.0; + } + else if(module_type == 11 || module_type == 13 || module_type == 15 || module_type == 17){ + hardware_x = (j%2==1) ? layer_thickness / 2.0 : active_layer_dim_x; + hardware_y = (j%2==1) ? active_layer_dim_y : layer_thickness / 2.0; + hardware_z = layer_thickness / 2.0; + } + else if(module_type == 12 || module_type == 14 || module_type == 16 || module_type == 18){ + hardware_x = (j%2==1) ? active_layer_dim_x : layer_thickness / 2.0; + hardware_y = (j%2==1) ? layer_thickness / 2.0 : active_layer_dim_y; + hardware_z = layer_thickness / 2.0; + } + Volume hardware_vol(hardware_name,Box(hardware_x, hardware_y, hardware_z), hardware_material); + hardware_vol.setSensitiveDetector(sens); + hardware_vol.setAttributes(theDetector,x_layer.regionStr(),x_layer.limitsStr(),x_layer.visStr()); + + volume_bar = volume_bar + hardware_x*2*2*hardware_y*hardware_z*2; + + if(module_type== 1){ + hardware_x_pos = (j%2==0) ? active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware : 0; + hardware_y_pos = (j%2==0) ? 0 : -active_layer_dim_y + layer_thickness/2 + layer_thickness*ihardware; + hardware_z_pos = 0; + } + else if(module_type== 2){ + hardware_x_pos = (j%2==0) ? 0 : active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware; + hardware_y_pos = (j%2==0) ? active_layer_dim_y - layer_thickness/2 - layer_thickness*ihardware: 0 ; + hardware_z_pos = 0; + } + if(module_type== 21){ + hardware_x_pos = (j%2==0) ? active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware : 0; + hardware_y_pos = (j%2==0) ? 0 : active_layer_dim_y - layer_thickness/2 - layer_thickness*ihardware; + hardware_z_pos = 0; + } + else if(module_type== 22){ + hardware_x_pos = (j%2==0) ? 0 : -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware; + hardware_y_pos = (j%2==0) ? active_layer_dim_y - layer_thickness/2 - layer_thickness*ihardware: 0 ; + hardware_z_pos = 0; + } + + else if(module_type == 3){ + hardware_x_pos = (j%2==0) ? 0 : active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware; + hardware_y_pos = 0; + hardware_z_pos = (j%2==0) ? -active_layer_dim_z + layer_thickness/2 + layer_thickness*ihardware : 0; + } + else if(module_type == 4){ + hardware_x_pos = (j%2==0) ? 0 : -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware; + hardware_y_pos = 0; + hardware_z_pos = (j%2==0) ? active_layer_dim_z - layer_thickness/2 - layer_thickness*ihardware : 0; + } + else if(module_type == 5){ + hardware_x_pos = (j%2==0) ? 0 : active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware; + hardware_y_pos = 0; + hardware_z_pos = (j%2==0) ? active_layer_dim_z - layer_thickness/2 - layer_thickness*ihardware : 0; + } + else if(module_type == 6){ + hardware_x_pos = (j%2==0) ? 0 : -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware; + hardware_y_pos = 0; + hardware_z_pos = (j%2==0) ? -active_layer_dim_z + layer_thickness/2 + layer_thickness*ihardware : 0; + } + + else if(module_type == 7){ + hardware_x_pos = (j%2==0) ? active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware : 0; + hardware_y_pos = 0; + hardware_z_pos = (j%2==0) ? 0 : active_layer_dim_z - layer_thickness/2 - layer_thickness*ihardware; + } + else if(module_type == 8){ + hardware_x_pos = (j%2==0) ? -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware : 0; + hardware_y_pos = 0; + hardware_z_pos = (j%2==0) ? 0 : -active_layer_dim_z + layer_thickness/2 + layer_thickness*ihardware; + } + else if(module_type == 9){ + hardware_x_pos = (j%2==0) ? active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware : 0; + hardware_y_pos = 0; + hardware_z_pos = (j%2==0) ? 0 : -active_layer_dim_z + layer_thickness/2 + layer_thickness*ihardware; + } + else if(module_type == 10){ + hardware_x_pos = (j%2==0) ? -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware : 0; + hardware_y_pos = 0; + hardware_z_pos = (j%2==0) ? 0 : active_layer_dim_z - layer_thickness/2 - layer_thickness*ihardware; + } + + + else if(module_type == 11){ + hardware_x_pos = (j%2==1) ? active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware : 0; + hardware_y_pos = (j%2==1) ? 0 : active_layer_dim_y - layer_thickness/2 - layer_thickness*ihardware; + hardware_z_pos = 0; + } + else if(module_type == 12){ + hardware_x_pos = (j%2==1) ? 0 : -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware; + hardware_y_pos = (j%2==1) ? active_layer_dim_y - layer_thickness/2 - layer_thickness*ihardware: 0 ; + hardware_z_pos = 0; + } + else if(module_type == 13){ + hardware_x_pos = (j%2==1) ? -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware : 0; + hardware_y_pos = (j%2==1) ? 0 : -active_layer_dim_y + layer_thickness/2 + layer_thickness*ihardware; + hardware_z_pos = 0; + } + else if(module_type == 14){ + hardware_x_pos = (j%2==1) ? 0 : active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware; + hardware_y_pos = (j%2==1) ? -active_layer_dim_y + layer_thickness/2 + layer_thickness*ihardware: 0 ; + hardware_z_pos = 0; + } + else if(module_type == 15){ + hardware_x_pos = (j%2==1) ? active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware : 0; + hardware_y_pos = (j%2==1) ? 0 : -active_layer_dim_y + layer_thickness/2 + layer_thickness*ihardware; + hardware_z_pos = 0; + } + else if(module_type == 16){ + hardware_x_pos = (j%2==1) ? 0 : -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware; + hardware_y_pos = (j%2==1) ? -active_layer_dim_y + layer_thickness/2 + layer_thickness*ihardware: 0 ; + hardware_z_pos = 0; + } + else if(module_type == 17){ + hardware_x_pos = (j%2==1) ? -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware : 0; + hardware_y_pos = (j%2==1) ? 0 : active_layer_dim_y - layer_thickness/2 - layer_thickness*ihardware; + hardware_z_pos = 0; + } + else if(module_type == 18){ + hardware_x_pos = (j%2==1) ? 0 : active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware; + hardware_y_pos = (j%2==1) ? active_layer_dim_y - layer_thickness/2 - layer_thickness*ihardware: 0 ; + hardware_z_pos = 0; + } + + PlacedVolume hardware_phv = layer_vol.placeVolume(hardware_vol,Position(hardware_x_pos, hardware_y_pos, hardware_z_pos)); + hardware_phv.addPhysVolID("bar", ihardware); + hardware.setPlacement(hardware_phv); + } + + layer_vol.setAttributes(theDetector,x_layer.regionStr(),x_layer.limitsStr(),x_layer.visStr()); + rot_layer = M_PI/2; + PlacedVolume layer_phv; + layer_phv = (module_type == 1 || module_type == 2 || module_type == 21 || module_type == 22) ? envelopeVolTrapIso.placeVolume(layer_vol, Transform3D(RotationZYX(rot_layer, 0, 0), Position(0,0,layer_pos_z))) + : (module_type>=3 && module_type<=10) ? envelopeVolTrapRight.placeVolume(layer_vol, Transform3D(RotationZYX( 0, 0, 0), Position( -(dim_x2 - dim_x1)/2 + j*delta_layer/2 + EcalEndcap_deadarea_thickness, layer_pos_z, 0))) + : (module_type>=11 && module_type<=14) ? envelopeVolPrism.placeVolume(layer_vol, Position(-dim_x + active_layer_dim_x + EcalEndcap_deadarea_thickness, -dim_x + active_layer_dim_y + EcalEndcap_deadarea_thickness, layer_pos_z)) + : envelopeVolPrism.placeVolume(layer_vol, Transform3D(RotationZYX( rot_layer, 0, 0), Position(-dim_x + active_layer_dim_x + EcalEndcap_deadarea_thickness, -dim_x + active_layer_dim_y + EcalEndcap_deadarea_thickness, layer_pos_z))); + + dd4hep::rec::ECALModuleInfoData::LayerInfo layerInfo; + if(j%2==0){ + layerInfo.dlayerNumber = layer_num; + layerInfo.slayerNumber = 0; + layerInfo.barNumber = hardware_num; + layer_phv.addPhysVolID("slayer", 0).addPhysVolID("dlayer", layer_num); + } + else{ + layerInfo.dlayerNumber = layer_num; + layerInfo.slayerNumber = 1; + layerInfo.barNumber = hardware_num; + layer_phv.addPhysVolID("slayer", 1).addPhysVolID("dlayer", layer_num); + ++layer_num; + } + layer.setPlacement(layer_phv); + layer_pos_z += layer_thickness; + layerInfos.push_back(layerInfo); + N_bar = N_bar + hardware_num; + } + } + } + + std::cout << "N_bar: " << N_bar << std::endl; + std::cout << "volume_bar: " << volume_bar << std::endl; + + int sector_sum = 0; + if(module_type==1 || module_type==2 || module_type == 21 || module_type == 22) sector_sum = module_number; + else if(module_type>=11 && module_type<=18) sector_sum = module_number; + else sector_sum = module_number*2 + 1; + + for (int sector_num=0;sector_num<sector_sum;sector_num++){ + if(module_type>=3 && module_type<=6 && sector_num<module_number) continue; + if(module_type>=7 && module_type<=10 && sector_num>module_number) continue; + + double EndcapModule_pos_x = 0; + double EndcapModule_pos_y = 0; + double EndcapModule_pos_z = pos_z; + double rot_EM = 0; + double rot_ES = 0; + double rot_EZ = 0; + double rot_EY = 0; + double rot_EX = 0; + + if(module_type==0 || module_type==20){ + if(sector_num<module_number){ + EndcapModule_pos_x = pos_x; + EndcapModule_pos_y = pos_y + (module_number-sector_num)*dim_y; + } + else if(sector_num==module_number){ + EndcapModule_pos_x = pos_x; + EndcapModule_pos_y = pos_y; + } + else{ + EndcapModule_pos_x = pos_x + (sector_num-module_number)*dim_x; + EndcapModule_pos_y = pos_y; + } + } + else if(module_type==1 || module_type==2 || module_type == 21 || module_type == 22){ + EndcapModule_pos_x = pos_x + sector_num*dim_y2; + EndcapModule_pos_y = pos_y; + } + else if(module_type>=3 && module_type<=10){ + if(sector_num<module_number){ + EndcapModule_pos_x = pos_y; + EndcapModule_pos_y = pos_x + (module_number-sector_num)*dim_y; + } + else if(sector_num==module_number){ + EndcapModule_pos_x = pos_x; + EndcapModule_pos_y = pos_y; + } + else{ + EndcapModule_pos_x = pos_x + (sector_num-module_number)*dim_x; + EndcapModule_pos_y = pos_y; + } + } + else{ + EndcapModule_pos_x = pos_x; + EndcapModule_pos_y = pos_y; + } + + + for(int stave_num=0;stave_num<4;stave_num++){ + if((module_type==1 || module_type==21) && (stave_num==1 || stave_num==3)) continue; + if((module_type==2 || module_type==22) && (stave_num==0 || stave_num==2)) continue; + if((module_type==3 || module_type==5) && (stave_num==2 || stave_num==3)) continue; + if((module_type==4 || module_type==6) && (stave_num==0 || stave_num==1)) continue; + if((module_type==7 || module_type==9) && (stave_num==1 || stave_num==2)) continue; + if((module_type==8 || module_type==10) && (stave_num==0 || stave_num==3)) continue; + + // Set the ID. The ID is composed of the module number, the stave number, the part number. + int stave_id = 0; + int part_id = 0; + if(module_type == 0 || module_type == 20){ + if(stave_num==0 && sector_num<=module_number) { stave_id = 7 + module_tag; part_id = 10 - sector_num; } + if(stave_num==0 && sector_num>module_number) { stave_id = sector_num + 4 + 2*module_tag; part_id = 7 + module_tag; } + if(stave_num==1 && sector_num<=module_number) { stave_id = 3 - module_tag; part_id = 10 - sector_num; } + if(stave_num==1 && sector_num>module_number) { stave_id = 6 - 2*module_tag - sector_num; part_id = 7 + module_tag; } + if(stave_num==2 && sector_num<=module_number) { stave_id = 3 - module_tag; part_id = sector_num; } + if(stave_num==2 && sector_num>module_number) { stave_id = 6 - 2*module_tag - sector_num; part_id = 3 - module_tag; } + if(stave_num==3 && sector_num<=module_number) { stave_id = 7 + module_tag; part_id = sector_num; } + if(stave_num==3 && sector_num>module_number) { stave_id = sector_num + 4 + 2*module_tag; part_id = 3 - module_tag; } + } + else if(module_type == 1 || module_type == 2 || module_type == 21 || module_type == 22){ + if(stave_num==0) { stave_id = 7 + sector_num; part_id = 5; } + if(stave_num==1) { stave_id = 5; part_id = 7 + sector_num; } + if(stave_num==2) { stave_id = 3 - sector_num; part_id = 5; } + if(stave_num==3) { stave_id = 5; part_id = 3 - sector_num; } + } + else if(module_type >= 3 && module_type <= 6){ + if(stave_num==0) { stave_id = 2 + sector_num; part_id = 6; } + if(stave_num==1) { stave_id = 8 - sector_num; part_id = 6; } + if(stave_num==2) { stave_id = 8 - sector_num; part_id = 4; } + if(stave_num==3) { stave_id = 2 + sector_num; part_id = 4; } + } + else if(module_type >= 7 && module_type <= 10){ + if(stave_num==0) { stave_id = 6; part_id = 10 - sector_num; } + if(stave_num==1) { stave_id = 4; part_id = 10 - sector_num; } + if(stave_num==2) { stave_id = 4; part_id = sector_num; } + if(stave_num==3) { stave_id = 6; part_id = sector_num; } + } + else { + if(stave_num==0) { stave_id = 6; part_id = 6; } + if(stave_num==1) { stave_id = 4; part_id = 6; } + if(stave_num==2) { stave_id = 4; part_id = 4; } + if(stave_num==3) { stave_id = 6; part_id = 4; } + } + + double rot_FZ = 0; + double rot_FY = 0; + double rot_FX = 0; + + if(module_type==0 || module_type==20){ + EndcapModule_center_pos_x = (stave_num == 0) ? EndcapModule_pos_x : (stave_num == 1) ? -EndcapModule_pos_x : (stave_num == 2) ? -EndcapModule_pos_x : EndcapModule_pos_x; + EndcapModule_center_pos_y = (stave_num == 0) ? EndcapModule_pos_y : (stave_num == 1) ? EndcapModule_pos_y : (stave_num == 2) ? -EndcapModule_pos_y : -EndcapModule_pos_y; + } + else if(module_type==1 || module_type==2 || module_type == 21 || module_type == 22){ + EndcapModule_center_pos_x = (stave_num == 0) ? EndcapModule_pos_x : (stave_num == 1) ? EndcapModule_pos_y : (stave_num == 2) ? -EndcapModule_pos_x : EndcapModule_pos_y; + EndcapModule_center_pos_y = (stave_num == 0) ? EndcapModule_pos_y : (stave_num == 1) ? EndcapModule_pos_x : (stave_num == 2) ? -EndcapModule_pos_y : -EndcapModule_pos_x; + } + else{ + EndcapModule_center_pos_x = (stave_num == 0) ? EndcapModule_pos_x : (stave_num == 1) ? -EndcapModule_pos_x : (stave_num == 2) ? -EndcapModule_pos_x : EndcapModule_pos_x; + EndcapModule_center_pos_y = (stave_num == 0) ? EndcapModule_pos_y : (stave_num == 1) ? EndcapModule_pos_y : (stave_num == 2) ? -EndcapModule_pos_y : -EndcapModule_pos_y; + } + + rot_ES = (stave_num == 0) ? M_PI/2 : (stave_num == 1) ? 0 : (stave_num == 2) ? M_PI/2 : 0; + if(sector_num<=module_number) rot_EX = (stave_num == 0) ? M_PI : (stave_num == 1) ? 0 : (stave_num == 2) ? 0 : M_PI; + else rot_EX = (stave_num == 0) ? M_PI+M_PI/2 : (stave_num == 1) ? 0-M_PI/2 : (stave_num == 2) ? 0+M_PI/2 : M_PI-M_PI/2; + rot_EZ = (stave_num == 0) ? 0 : (stave_num == 1) ? 0 : (stave_num == 2) ? 0 : 0; + + + for(int module_num=0;module_num<2;module_num++) { + + if(module_num==0 && module_type==20) continue; + if(module_num==1 && module_type==0) continue; + if(module_num==0 && (module_type==21 || module_type==22)) continue; + if(module_num==1 && (module_type==1 || module_type==2)) continue; + if(module_num==0 && (module_type==5 || module_type==6 || module_type==9 || module_type==10)) continue; + if(module_num==1 && (module_type==3 || module_type==4 || module_type==7 || module_type==8)) continue; + if(module_num==0 && stave_num==0 && (module_type==12 || module_type==13 || module_type==14 || module_type==15 || module_type==16 || module_type==17 || module_type==18)) continue; + if(module_num==0 && stave_num==1 && (module_type==11 || module_type==13 || module_type==14 || module_type==15 || module_type==16 || module_type==17 || module_type==18)) continue; + if(module_num==0 && stave_num==2 && (module_type==11 || module_type==12 || module_type==14 || module_type==15 || module_type==16 || module_type==17 || module_type==18)) continue; + if(module_num==0 && stave_num==3 && (module_type==11 || module_type==12 || module_type==13 || module_type==15 || module_type==16 || module_type==17 || module_type==18)) continue; + if(module_num==1 && stave_num==0 && (module_type==11 || module_type==12 || module_type==13 || module_type==14 || module_type==16 || module_type==17 || module_type==18)) continue; + if(module_num==1 && stave_num==1 && (module_type==11 || module_type==12 || module_type==13 || module_type==14 || module_type==15 || module_type==17 || module_type==18)) continue; + if(module_num==1 && stave_num==2 && (module_type==11 || module_type==12 || module_type==13 || module_type==14 || module_type==15 || module_type==16 || module_type==18)) continue; + if(module_num==1 && stave_num==3 && (module_type==11 || module_type==12 || module_type==13 || module_type==14 || module_type==15 || module_type==16 || module_type==17)) continue; + + int module_id = (module_num==0)? 0:1; + + if(module_type>=3 && module_type<=10){ + if(sector_num<=module_number) rot_EM = (module_id==0)?M_PI*3/2: M_PI/2; + else rot_EM = (module_id==0)?M_PI*3/2: M_PI/2; + if(sector_num>module_number) rot_EY = (module_id==0)? rot_EX+M_PI : rot_EX; + else rot_EY = rot_EX; + } + else rot_EM = (module_id==0)?M_PI:0; + + EndcapModule_center_pos_z = (module_id==0)? -EndcapModule_pos_z:EndcapModule_pos_z; + + PlacedVolume env_phv; + + dd4hep::rec::ECALModuleInfoData ecalmoduleInfoData; + ecalmoduleInfoData.moduleNumber = module_id; + ecalmoduleInfoData.staveNumber = stave_id; + ecalmoduleInfoData.partNumber = part_id; + ecalmoduleInfoData.LayerInfos = layerInfos; + ecalSystemInfoData->ModuleInfos.push_back(ecalmoduleInfoData); + if(module_type==0 || module_type==20){ + env_phv = envelope.placeVolume(envelopeVol, + Transform3D(RotationX(rot_EM), + Translation3D(EndcapModule_center_pos_x, + EndcapModule_center_pos_y, + EndcapModule_center_pos_z))); + env_phv.addPhysVolID("system",det_id).addPhysVolID("module", module_id).addPhysVolID("type", module_tag).addPhysVolID("part", part_id).addPhysVolID("stave", stave_id); + all_module0++; + } + else if(module_type==1 || module_type==2 || module_type == 21 || module_type == 22){ + env_phv = envelope.placeVolume(envelopeVolTrapIso, + Transform3D(RotationZYX(rot_ES, 0, rot_EM), + Position(EndcapModule_center_pos_x, + EndcapModule_center_pos_y, + EndcapModule_center_pos_z))); + env_phv.addPhysVolID("system",det_id).addPhysVolID("module", module_id).addPhysVolID("type", module_tag).addPhysVolID("part", part_id).addPhysVolID("stave", stave_id); + all_module1++; + } + else if(module_type>=3 && module_type<=10){ + if(sector_num==module_number){ + continue; + } + else{ + env_phv = envelope.placeVolume(envelopeVolTrapRight, + Transform3D(RotationZYX(rot_EZ, rot_EY, rot_EM), + Position(EndcapModule_center_pos_x, + EndcapModule_center_pos_y, + EndcapModule_center_pos_z))); + env_phv.addPhysVolID("system",det_id).addPhysVolID("module", module_id).addPhysVolID("type", module_tag).addPhysVolID("part", part_id).addPhysVolID("stave", stave_id); + all_module2++; + } + } + else{ + if(module_id==0){ + rot_FZ = (stave_num == 0) ? M_PI/2 : (stave_num == 1) ? 0: (stave_num == 2) ? -M_PI/2 : M_PI; + } + else{ + rot_FZ = (stave_num == 0) ? M_PI : (stave_num == 1) ? -M_PI/2 : (stave_num == 2) ? 0 : M_PI/2; + } + rot_FY = (stave_num == 0) ? 0 : (stave_num == 1) ? 0 : (stave_num == 2) ? 0 : 0; + rot_FX = (module_id==0)?M_PI:0; + + env_phv = envelope.placeVolume(envelopeVolPrism, + Transform3D(RotationZYX(rot_FZ, rot_FY, rot_FX), + Position(EndcapModule_center_pos_x, + EndcapModule_center_pos_y, + EndcapModule_center_pos_z))); + env_phv.addPhysVolID("system",det_id).addPhysVolID("module", module_id).addPhysVolID("type", module_tag).addPhysVolID("part", part_id).addPhysVolID("stave", stave_id); + + all_module3++; + } + + DetElement sd = (module_id==0&&part_id==0&&stave_id==0) ? stave_det : stave_det.clone(_toString(module_id,"module%d")+_toString(stave_id,"stave%d")+_toString(part_id,"part%d")); + sd.setPlacement(env_phv); + } + } + } + endcapID++; + } + cout<<"EndcapModule0: "<<all_module0<<endl; + cout<<"EndcapModule1: "<<all_module1<<endl; + cout<<"EndcapModule2: "<<all_module2<<endl; + cout<<"EndcapModule3: "<<all_module3<<endl; + + sdet.addExtension<dd4hep::rec::ECALSystemInfoData>(ecalSystemInfoData); + return sdet; +} + +DECLARE_DETELEMENT(LongCrystalBarEndcapCalorimeter_v03, create_detector) \ No newline at end of file diff --git a/Detector/DetIdentifier/include/DetIdentifier/CEPCDetectorData.h b/Detector/DetIdentifier/include/DetIdentifier/CEPCDetectorData.h index 2cf98d3d2045807cea2f5edfc92acc5216cbf523..e95b62b206ae6fcf1b10fffe32586967663a4423 100644 --- a/Detector/DetIdentifier/include/DetIdentifier/CEPCDetectorData.h +++ b/Detector/DetIdentifier/include/DetIdentifier/CEPCDetectorData.h @@ -186,6 +186,41 @@ namespace dd4hep { return io; }; + + + /** Simple data structure with key parameters for + * reconstruction of long crystal bar ECAL + * + * @author Weizheng Song + * @date Nov, 20, 2024 + * @version $Id: $ + */ + struct ECALModuleInfoStruct { + int moduleNumber; + int staveNumber; + int partNumber; + + struct LayerInfo { + LayerInfo() : + dlayerNumber(-1), + slayerNumber(-1), + barNumber(-1){ + } + int dlayerNumber; + int slayerNumber; + int barNumber; + }; + std::vector<LayerInfo> LayerInfos; + }; + typedef StructExtension<ECALModuleInfoStruct> ECALModuleInfoData; + + struct ECALSystemInfoStruct { + int systemNumber; + + std::vector<ECALModuleInfoStruct> ModuleInfos; + }; + typedef StructExtension<ECALSystemInfoStruct> ECALSystemInfoData; + } } diff --git a/Digitization/DigiCalo/src/EcalDigiAlg.cpp b/Digitization/DigiCalo/src/EcalDigiAlg.cpp index f901df324ecfc52417b0ee7af3db908a4ae9917f..f6c0e5a1ee451761b3714f563494f1bf01fc193d 100644 --- a/Digitization/DigiCalo/src/EcalDigiAlg.cpp +++ b/Digitization/DigiCalo/src/EcalDigiAlg.cpp @@ -109,6 +109,7 @@ StatusCode EcalDigiAlg::initialize() t_SimCont->Branch("step_T1", &m_step_T1); t_SimCont->Branch("step_T2", &m_step_T2); t_SimBar->Branch("totE_Truth", &totE_Truth); + t_SimBar->Branch("totE_Truth_MIP", &totE_Truth_MIP); t_SimBar->Branch("totE_Digi", &totE_Digi); t_SimBar->Branch("mean_CT", &mean_CT); t_SimBar->Branch("ECALTemp", &ECALTemp); @@ -179,6 +180,12 @@ StatusCode EcalDigiAlg::initialize() f_DarkNoise = new TF1("f_DarkNoise", "pow([0]*x, x-1) * exp(-[0]*x) / TMath::Factorial(x)"); f_DarkNoise->SetParameter(0, fEcalSiPMCT); + //ADC non-linearity: a simplified quadratic function, with maximum non-linearity 1% + f_ADCNonLin = new TF1("f_ADCNonLin", "pol2", 0, fADC); + f_ADCNonLin->SetParameter(0, fADCNonLin/2.); + f_ADCNonLin->SetParameter(1, -4*fADCNonLin/fADC); + f_ADCNonLin->SetParameter(2, 4*fADCNonLin/fADC/fADC); + g_CryLYRatio_vs_TID = new TGraph(); float TID [8] = {50, 230.043, 731.681, 3448.96, 118953, 1.01164e+7, 1.02341e+8, 2.04907e+8}; float CryLYRatio_TID[8] = {0.99, 0.774091, 0.689545, 0.633636, 0.588636, 0.549091, 0.401818, 0.374545}; @@ -220,6 +227,8 @@ StatusCode EcalDigiAlg::execute() if(_nEvt<_Nskip){ _nEvt++; return StatusCode::SUCCESS; } Clear(); + totE_Truth=0; + totE_Digi=0; for(int icol=0; icol<_inputSimHitCollection.size(); icol++){ try{ @@ -242,7 +251,9 @@ StatusCode EcalDigiAlg::execute() if(_Debug>=1) std::cout<<"digi, input sim hit size="<< SimHitCol->size() <<std::endl; + totE_Truth=0; + totE_Truth_MIP=0; totE_Digi=0; mean_CT = 0; for (int i = 1; i < 10; i++) @@ -497,10 +508,10 @@ StatusCode EcalDigiAlg::execute() //cout<<", SiPM gain "<<sEcalSiPMGainMean<<endl; totQ1_Digi = EnergyDigi(ScinGen*totQ1_Att/(totQ1_Att+totQ2_Att), sEcalCryIntLY, sEcalSiPMGainMean, sEcalSiPMDCR, - f_SiPMResponse, f_SiPMSigmaDet, f_SiPMSigmaRecp, f_SiPMSigmaRecm, f_AsymGauss, f_DarkNoise, + f_SiPMResponse, f_SiPMSigmaDet, f_SiPMSigmaRecp, f_SiPMSigmaRecm, f_AsymGauss, f_DarkNoise, f_ADCNonLin, outLO1, outNDC1, outNDetPE1, outPedestal1, outADC1, outADCGain1)/1000; totQ2_Digi = EnergyDigi(ScinGen*totQ2_Att/(totQ1_Att+totQ2_Att), sEcalCryIntLY, sEcalSiPMGainMean, sEcalSiPMDCR, - f_SiPMResponse, f_SiPMSigmaDet, f_SiPMSigmaRecp, f_SiPMSigmaRecm, f_AsymGauss, f_DarkNoise, + f_SiPMResponse, f_SiPMSigmaDet, f_SiPMSigmaRecp, f_SiPMSigmaRecm, f_AsymGauss, f_DarkNoise, f_ADCNonLin, outLO2, outNDC2, outNDetPE2, outPedestal2, outADC2, outADCGain2)/1000; } else{ @@ -584,10 +595,11 @@ StatusCode EcalDigiAlg::execute() m_barCol.push_back(hitbar); if(hitbar.getQ1()>=0 && hitbar.getQ2()>=0) totE_Digi += (hitbar.getQ1() + hitbar.getQ2()); - //if(totQ1_Att>(fEcalMIPEnergy*fEcalMIP_Thre/1000.) && totQ2_Att>(fEcalMIPEnergy*fEcalMIP_Thre/1000.)){ - // // cout<<"Truth Energy:"<<totQ1_Att<<" "<<totQ2_Att<<endl; - // totE_Truth+=(totQ1_Att+totQ2_Att); - //} + if (totQ1_Att > (0.001 * fEcalMIPEnergy * fEcalMIP_Thre) && totQ2_Att > (0.001 * fEcalMIPEnergy * fEcalMIP_Thre)) + { +// cout << "Truth Energy:" << totQ1_Att << " " << totQ2_Att << endl; + totE_Truth_MIP += (totQ1_Att + totQ2_Att); + } if(_writeNtuple){ @@ -647,6 +659,7 @@ StatusCode EcalDigiAlg::execute() { std::cout<<"End Loop: Bar Digitalization!"<<std::endl; std::cout<<"Total Truth Energy: "<<totE_Truth<<std::endl; + std::cout << "Total Truth Energy with " << (double) fEcalMIP_Thre << " MIP Threshold: " << totE_Truth_MIP << std::endl; std::cout<<"Total Digi Energy: "<<totE_Digi<<std::endl; } @@ -674,12 +687,12 @@ StatusCode EcalDigiAlg::finalize() info() << "Processed " << _nEvt << " events " << endmsg; map_readout_decoder.clear(); delete m_cellIDConverter, m_geosvc; - delete f_SiPMResponse, f_SiPMSigmaDet, f_SiPMSigmaRecp, f_SiPMSigmaRecm, f_AsymGauss, f_DarkNoise, g_SiPMDCR_vs_NIEL, g_CryLYRatio_vs_TID; + delete f_SiPMResponse, f_SiPMSigmaDet, f_SiPMSigmaRecp, f_SiPMSigmaRecm, f_AsymGauss, f_DarkNoise, f_ADCNonLin, g_SiPMDCR_vs_NIEL, g_CryLYRatio_vs_TID; return GaudiAlgorithm::finalize(); } float EcalDigiAlg::EnergyDigi(float ScinGen, float sEcalCryIntLY, float sEcalSiPMGainMean, float sEcalSiPMDCR, - TF1* f_SiPMResponse, TF1* f_SiPMSigmaDet, TF1* f_SiPMSigmaRecp, TF1* f_SiPMSigmaRecm, TF1* f_AsymGauss, TF1* f_DarkNoise, + TF1* f_SiPMResponse, TF1* f_SiPMSigmaDet, TF1* f_SiPMSigmaRecp, TF1* f_SiPMSigmaRecm, TF1* f_AsymGauss, TF1* f_DarkNoise, TF1* f_ADCNonLin, int& outLO, int& outNDC, int& outNDetPE, float& outPedestal, float& outADC, float& outADCGain) { // float sEcalSiPMPDE = rndm.Gaus(fEcalSiPMPDE, fEcalSiPMPDEFlu * fEcalSiPMPDE); @@ -776,6 +789,7 @@ float EcalDigiAlg::EnergyDigi(float ScinGen, float sEcalCryIntLY, float sEcalSiP float NRec = f_AsymGauss->GetRandom(); sADC = NRec * sEcalSiPMGainMean + sPedestal; } + sADC = (f_ADCNonLin->Eval(sADC)+1) * sADC; outPedestal = sPedestal; outADCGain = sADC; sPedestal = fPedestal + sEcalSiPMDCR * fEcalTimeInterval * (1 + mean_CT) * sEcalSiPMGainMean; @@ -820,6 +834,7 @@ float EcalDigiAlg::EnergyDigi(float ScinGen, float sEcalCryIntLY, float sEcalSiP float NRec = f_AsymGauss->GetRandom(); sADC = NRec * sEcalSiPMGainMean + sPedestal; } + sADC = (f_ADCNonLin->Eval(sADC)+1) * sADC; outPedestal = sPedestal; outADCGain = sADC; sPedestal = fPedestal + sEcalSiPMDCR * fEcalTimeInterval * (1 + mean_CT) * sEcalSiPMGainMean; @@ -868,6 +883,7 @@ float EcalDigiAlg::EnergyDigi(float ScinGen, float sEcalCryIntLY, float sEcalSiP float NRec = f_AsymGauss->GetRandom(); sADC = NRec * sEcalSiPMGainMean + sPedestal; } + sADC = (f_ADCNonLin->Eval(sADC)+1) * sADC; outPedestal = sPedestal; outADCGain = sADC; sPedestal = fPedestal + sEcalSiPMDCR * fEcalTimeInterval * (1 + mean_CT) * sEcalSiPMGainMean; @@ -992,7 +1008,7 @@ edm4hep::MutableSimCalorimeterHit EcalDigiAlg::find(const std::vector<edm4hep::M } void EcalDigiAlg::Clear(){ - totE_Truth = -99; + totE_Truth = -99; totE_Digi = -99; mean_CT = -99; ECALTemp = -99; diff --git a/Digitization/DigiCalo/src/EcalDigiAlg.h b/Digitization/DigiCalo/src/EcalDigiAlg.h index 6977e799e7f6259b784ec59efcc9b2f8da779bca..4a7a8d13aeb34ef442c529b565b7ffdbdfd47b1f 100644 --- a/Digitization/DigiCalo/src/EcalDigiAlg.h +++ b/Digitization/DigiCalo/src/EcalDigiAlg.h @@ -63,7 +63,7 @@ public: edm4hep::MutableSimCalorimeterHit find(const std::vector<edm4hep::MutableSimCalorimeterHit>& m_col, unsigned long long& cellid) const; // double Digitization(double edepCry, double fCrosstalkChannel); float EnergyDigi(float ScinGen, float sEcalCryMipLY, float sEcalSiPMGainMean, float sEcalSiPMDCR, - TF1* f_SiPMResponse, TF1* f_SiPMSigmaDet, TF1* f_SiPMSigmaRecp, TF1* f_SiPMSigmaRecm, TF1* f_AsymGauss, TF1* f_DarkNoise, + TF1* f_SiPMResponse, TF1* f_SiPMSigmaDet, TF1* f_SiPMSigmaRecp, TF1* f_SiPMSigmaRecm, TF1* f_AsymGauss, TF1* f_DarkNoise, TF1* f_ADCNonLin, int& outLO, int& outNDC, int& outNDetPE, float& outPedestal, float& outADC, float& outADCGain); void Clear(); @@ -81,7 +81,7 @@ protected: TTree* t_SimCont; TTree* t_SimBar; - double totE_Truth, totE_Digi; + double totE_Truth, totE_Truth_MIP, totE_Digi; double mean_CT, ECALTemp; FloatVec m_step_t; // yyy: time of each step FloatVec m_step_x, m_step_y, m_step_z, m_step_E, m_step_T1, m_step_T2, m_stepBar_x, m_stepBar_y, m_stepBar_z; @@ -109,6 +109,7 @@ protected: TF1* f_SiPMSigmaRecm = nullptr; TF1* f_AsymGauss = nullptr; TF1* f_DarkNoise = nullptr; + TF1* f_ADCNonLin = nullptr; TGraph* g_SiPMDCR_vs_NIEL = nullptr; TGraph* g_CryLYRatio_vs_TID = nullptr; @@ -163,6 +164,7 @@ protected: mutable Gaudi::Property<int> fSiPMDigiVerbose{this, "SiPMDigiVerbose", 1, "SiPM Digitization verbose. 0:w/o response, w/o correction; 1:w/ response, w/o correction; 2:w/ response, w/ simple correction; 3:w/ response, w/ full correction;"}; mutable Gaudi::Property<float> fGainRatio_12{this, "GainRatio_12", 50, "Gain-1 over Gain-2"}; mutable Gaudi::Property<float> fGainRatio_23{this, "GainRatio_23", 60, "Gain-2 over Gain-3"}; + mutable Gaudi::Property<float> fADCNonLin{this, "ADCNonLinearity", 0.01, "ADC non-linearity"}; mutable Gaudi::Property<float> fEcalMIPEnergy{this, "EcalMIPEnergy", 8.9, "MIP energy deposit in 1cm BGO (MeV/MIP)"}; mutable Gaudi::Property<float> fEcalCryMipLY{this, "EcalCryMipLY", 200, "Detected light yield (p.e./MIP)"}; mutable Gaudi::Property<float> fEcalCryIntLY{this, "EcalCryIntLY", 8200, "Intrinsic light yield (ph/MeV)"}; diff --git a/Digitization/DigiCalo/src/HcalDigiAlg.cpp b/Digitization/DigiCalo/src/HcalDigiAlg.cpp index 35332c9e57409d0c91da78fa58c5d5856ab4cd67..4fa904b7cfe21ef51650de1be928ec565e102652 100644 --- a/Digitization/DigiCalo/src/HcalDigiAlg.cpp +++ b/Digitization/DigiCalo/src/HcalDigiAlg.cpp @@ -83,9 +83,9 @@ StatusCode HcalDigiAlg::initialize() for(auto& link : name_CaloMCPAsso){ if(!link.empty()) _outputCaloMCPAssoCol.push_back( new CaloParticleAssoType(link, Gaudi::DataHandle::Writer, this) ); - } - - + } + + // --- Ntuple if(_writeNtuple){ std::string s_outfile = _filename; m_wfile = new TFile(s_outfile.c_str(), "recreate"); @@ -266,7 +266,7 @@ StatusCode HcalDigiAlg::execute() //printf(" Step #%d: En %.2f, rotate angle %.2f, tile pos after rotation (%.2f, %.2f, %.2f), ", iCont, conb.getEnergy(), rotPhi, rot_tilepos.x(), rot_tilepos.y(), rot_tilepos.z()); //printf("rel pos after rotation (%.2f, %.2f, %.2f) \n", (rot_steppos-rot_tilepos).x(), (rot_steppos-rot_tilepos).y(), (rot_steppos-rot_tilepos).z()); //printf(" Project to bin (%d, %d), LY %.3f \n", ibinx, ibiny, GSTileResMap->GetBinContent( ibinx, ibiny )); - + Npe_att += conb.getEnergy() / _MIPCali * GSTileResMap->GetBinContent( ibinx, ibiny ) * fLY_tempScale; m_step_LY.push_back(GSTileResMap->GetBinContent( ibinx, ibiny )); } diff --git a/README.md b/README.md index 12cca584ab9a0a257721584a10880455cba9ac19..b3b51f89febcd2830a2aadcdc95e9695b506f339 100644 --- a/README.md +++ b/README.md @@ -38,3 +38,7 @@ $ ./run.sh Examples/options/helloalg.py * Reconstruction: Reconstruction +## CyberPFA-5.0.1-dev (developing) +* Based on CEPCSW tag tdr 24.12.0 + + diff --git a/Reconstruction/JetClustering/CMakeLists.txt b/Reconstruction/JetClustering/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..aee47b8b5c0162b316c8520cca5c9101b001d3f0 --- /dev/null +++ b/Reconstruction/JetClustering/CMakeLists.txt @@ -0,0 +1,26 @@ +# Set the CMake module path if necessary + +set(FASTJET_ROOT "/cvmfs/sft.cern.ch/lcg/views/LCG_103/x86_64-centos7-gcc11-opt/") +set(INCLUDE_DIRS "${FASTJET_ROOT}/include") +set(LIBRARY_DIRS "${FASTJET_ROOT}/lib") +find_library(FASTJET_LIB fastjet PATHS ${LIBRARY_DIRS}) + +# Modules +gaudi_add_module(JetClustering + SOURCES src/JetClustering.cpp + LINK GearSvc + Gaudi::GaudiKernel + k4FWCore::k4FWCore + DetInterface + DataHelperLib + ${GEAR_LIBRARIES} + ${GSL_LIBRARIES} + ${ROOT_LIBRARIES} + ${FASTJET_LIB} + EDM4HEP::edm4hep EDM4HEP::edm4hepDict +) +install(TARGETS JetClustering + EXPORT CEPCSWTargets + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib + COMPONENT dev) diff --git a/Reconstruction/JetClustering/src/JetClustering.cpp b/Reconstruction/JetClustering/src/JetClustering.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8f76634dfd991a3d4db624695c93993ae3a7d62b --- /dev/null +++ b/Reconstruction/JetClustering/src/JetClustering.cpp @@ -0,0 +1,187 @@ +#include "JetClustering.h" + +#include "GaudiKernel/DataObject.h" +#include "GaudiKernel/IHistogramSvc.h" +#include "GaudiKernel/MsgStream.h" +#include "GaudiKernel/SmartDataPtr.h" + +#include "DetInterface/IGeomSvc.h" +#include "DD4hep/Detector.h" +#include "DD4hep/DD4hepUnits.h" +#include "CLHEP/Units/SystemOfUnits.h" +#include <math.h> +#include "fastjet/ClusterSequence.hh" +#include "fastjet/PseudoJet.hh" +//time measurement +#include <chrono> +#include "TLorentzVector.h" + +using namespace fastjet; +using namespace std; + +DECLARE_COMPONENT( JetClustering ) + +//------------------------------------------------------------------------------ +JetClustering::JetClustering( const string& name, ISvcLocator* pSvcLocator ) + : Algorithm( name, pSvcLocator ) { + + declareProperty("InputPFOs", m_PFOColHdl, "Handle of the Input PFO collection"); + declareProperty("Algorithm", m_algo, "Jet clustering algorithm"); + declareProperty("nJets", m_nJets, "Number of jets to be clustered"); + declareProperty("R", m_R, "Jet clustering radius"); + declareProperty("OutputFile", m_outputFile, "Output file name"); + +} + +//------------------------------------------------------------------------------ +StatusCode JetClustering::initialize(){ + + _nEvt = 0; + + // Create a new TTree + _file = TFile::Open(m_outputFile.value().c_str(), "RECREATE"); + _tree = new TTree("jets", "jets"); + _tree->Branch("jet1_px", &jet1_px, "jet1_px/D"); + _tree->Branch("jet1_py", &jet1_py, "jet1_py/D"); + _tree->Branch("jet1_pz", &jet1_pz, "jet1_pz/D"); + _tree->Branch("jet1_E", &jet1_E, "jet1_E/D"); + _tree->Branch("jet1_costheta", &jet1_costheta, "jet1_costheta/D"); + _tree->Branch("jet1_phi", &jet1_phi, "jet1_phi/D"); + _tree->Branch("jet1_pt", &jet1_pt, "jet1_pt/D"); + _tree->Branch("jet1_nconstituents", &jet1_nconstituents, "jet1_nconstituents/I"); + _tree->Branch("jet2_px", &jet2_px, "jet2_px/D"); + _tree->Branch("jet2_py", &jet2_py, "jet2_py/D"); + _tree->Branch("jet2_pz", &jet2_pz, "jet2_pz/D"); + _tree->Branch("jet2_E", &jet2_E, "jet2_E/D"); + _tree->Branch("jet2_costheta", &jet2_costheta, "jet2_costheta/D"); + _tree->Branch("jet2_phi", &jet2_phi, "jet2_phi/D"); + _tree->Branch("jet2_pt", &jet2_pt, "jet2_pt/D"); + _tree->Branch("jet2_nconstituents", &jet2_nconstituents, "jet2_nconstituents/I"); + _tree->Branch("constituents_E1tot", &constituents_E1tot, "constituents_E1tot/D"); + _tree->Branch("constituents_E2tot", &constituents_E2tot, "constituents_E2tot/D"); + _tree->Branch("mass", &mass, "mass/D"); + _tree->Branch("mass_allpfo", &mass_allpfo, "mass_allpfo/D"); + _tree->Branch("ymerge", ymerge, "ymerge[6]/D"); + + return StatusCode::SUCCESS; + +} + +//------------------------------------------------------------------------------ +StatusCode JetClustering::execute(){ + + const edm4hep::ReconstructedParticleCollection* PFO = nullptr; + try { + PFO = m_PFOColHdl.get(); + } + catch ( GaudiException &e ){ + info() << "Collection " << m_PFOColHdl.fullKey() << " is unavailable in event " << _nEvt << endmsg; + return StatusCode::SUCCESS; + } + // Check if the collection is empty + if ( PFO->size() == 0 ) { + info() << "Collection " << m_PFOColHdl.fullKey() << " is empty in event " << _nEvt << endmsg; + return StatusCode::SUCCESS; + } + //initial indces + CleanVars(); + + //resize particles. there are many particles are empty, maybe upstream bugs + TLorentzVector p4_allpfo; + vector<PseudoJet> input_particles; + for(const auto& pfo : *PFO){ + if ( isnan(pfo.getMomentum()[0]) || isnan(pfo.getMomentum()[1]) || isnan(pfo.getMomentum()[2]) || pfo.getEnergy() == 0) { + info() << "Particle " << _particle_index << " px: " << pfo.getMomentum()[0] << " py: " << pfo.getMomentum()[1] << " pz: " << pfo.getMomentum()[2] << " E: " << pfo.getEnergy() << endmsg; + _particle_index++; + continue; + } + else{ + input_particles.push_back(PseudoJet(pfo.getMomentum()[0], pfo.getMomentum()[1], pfo.getMomentum()[2], pfo.getEnergy())); + TLorentzVector p4_pfo; + p4_pfo.SetPxPyPzE( pfo.getMomentum()[0], pfo.getMomentum()[1], pfo.getMomentum()[2], pfo.getEnergy() ); + p4_allpfo += p4_pfo; + _particle_index++; + debug() << "Particle " << _particle_index << " px: "<<pfo.getMomentum()[0]<<" py: "<<pfo.getMomentum()[1]<<" pz: "<<pfo.getMomentum()[2]<<" E: "<<pfo.getEnergy()<<endmsg; + } + } + mass_allpfo = p4_allpfo.M(); + + // create a jet definition + int nJets = m_nJets; + double R = m_R; + + JetDefinition jet_def(ee_kt_algorithm); + //JetDefinition jet_def(antikt_algorithm, R); + + // run the clustering, extract the jets + //std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); + + ClusterSequence clust_seq(input_particles, jet_def); + + vector<PseudoJet> jets = sorted_by_pt(clust_seq.exclusive_jets(nJets)); + + std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); + + //_time = std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() / 1000000.0; + + //info() << "FastJet clustering done in seconds: " << _time << endmsg; + + //string jet_def_str = jet_def.description(); + //debug() << "Clustering with " << jet_def_str << " for " << nJets << " jets with R = " << R << endmsg; + + // print the jets + info() << " px py pz E costheta phi " << endmsg; + for (unsigned i = 0; i < jets.size(); i++) { + info() << " jet " << i << " " << jets[i].px() << " " << jets[i].py() << " " << jets[i].pz() << " " << jets[i].E() << " " << jets[i].cos_theta() << " " << jets[i].phi() << endmsg; + vector<PseudoJet> constituents = jets[i].constituents(); + for (unsigned j = 0; j < constituents.size(); j++) { + if ( i == 1 )constituents_E1tot += constituents[j].E(); + if ( i == 2 )constituents_E2tot += constituents[j].E(); + info() << " constituent " << j << " " << constituents[j].px() << " " << constituents[j].py() << " " << constituents[j].pz() << " " << constituents[j].E() << " " << constituents[j].cos_theta() << " " << constituents[j].phi() << endmsg; + } + } + info() << "Total energy of constituents: " << constituents_E1tot << " " << constituents_E2tot << endmsg; + + + double _ymin[20]; + for(int i=1; i<6;i++){ + _ymin[i-1] = clust_seq.exclusive_ymerge (i); + info() << " -log10(y" << i << i+1 << ") = " << -log10(_ymin[i-1]) << endmsg; + } + + + mass = (jets[0] + jets[1]).m(); + + // fill the tree + jet1_px = jets[0].px(); + jet1_py = jets[0].py(); + jet1_pz = jets[0].pz(); + jet1_E = jets[0].E(); + jet1_costheta = jets[0].cos_theta(); + jet1_phi = jets[0].phi(); + jet1_pt = jets[0].pt(); + jet1_nconstituents = jets[0].constituents().size(); + jet2_px = jets[1].px(); + jet2_py = jets[1].py(); + jet2_pz = jets[1].pz(); + jet2_E = jets[1].E(); + jet2_costheta = jets[1].cos_theta(); + jet2_phi = jets[1].phi(); + jet2_pt = jets[1].pt(); + jet2_nconstituents = jets[1].constituents().size(); + for(int i=0; i<6; i++){ + ymerge[i] = _ymin[i]; + } + _tree->Fill(); + + _nEvt++; + return StatusCode::SUCCESS; + +} + +//------------------------------------------------------------------------------ +StatusCode JetClustering::finalize(){ + debug() << "Finalizing..." << endmsg; + _file->Write(); + return StatusCode::SUCCESS; +} diff --git a/Reconstruction/JetClustering/src/JetClustering.h b/Reconstruction/JetClustering/src/JetClustering.h new file mode 100644 index 0000000000000000000000000000000000000000..5df65947cb8644828cd35736f1f9e06e9238ed09 --- /dev/null +++ b/Reconstruction/JetClustering/src/JetClustering.h @@ -0,0 +1,76 @@ +#ifndef JetClustering_h +#define JetClustering_h 1 + +#include "UTIL/ILDConf.h" +#include "k4FWCore/DataHandle.h" +#include "GaudiKernel/Algorithm.h" +#include <random> +#include "GaudiKernel/NTuple.h" +#include "TFile.h" +#include "TTree.h" + +#include "edm4hep/ReconstructedParticleData.h" +#include "edm4hep/ReconstructedParticleCollection.h" +#include "edm4hep/ReconstructedParticle.h" + +class JetClustering : public Algorithm { + public: + // Constructor of this form must be provided + JetClustering( const std::string& name, ISvcLocator* pSvcLocator ); + + // Three mandatory member functions of any algorithm + StatusCode initialize() override; + StatusCode execute() override; + StatusCode finalize() override; + + private: + DataHandle<edm4hep::ReconstructedParticleCollection> m_PFOColHdl{"PandoraPFOs", Gaudi::DataHandle::Reader, this}; + Gaudi::Property<std::string> m_algo{this, "Algorithm", "ee_kt_algorithm"}; + Gaudi::Property<int> m_nJets{this, "nJets", 2}; + Gaudi::Property<double> m_R{this, "R", 0.6}; + Gaudi::Property<std::string> m_outputFile{this, "OutputFile", "JetClustering.root"}; + + int _nEvt; + int _particle_index; + int _jet_index; + int _nparticles; + double _time; + + TFile* _file; + TTree* _tree; + double jet1_px, jet1_py, jet1_pz, jet1_E; + double jet2_px, jet2_py, jet2_pz, jet2_E; + double jet1_costheta, jet1_phi; + double jet2_costheta, jet2_phi; + double jet1_pt, jet2_pt; + int jet1_nconstituents, jet2_nconstituents; + double constituents_E1tot; + double constituents_E2tot; + double ymerge[6]; + double mass; + double mass_allpfo; + + void CleanVars(){ + + _particle_index = 0; + _jet_index = 0; + _nparticles = 0; + _time = 0; + + jet1_px = jet1_py = jet1_pz = jet1_E = 0; + jet2_px = jet2_py = jet2_pz = jet2_E = 0; + jet1_costheta = jet1_phi = 0; + jet2_costheta = jet2_phi = 0; + jet1_pt = jet2_pt = 0; + jet1_nconstituents = jet2_nconstituents = 0; + constituents_E1tot = constituents_E2tot = 0; + for(int i=0; i<6; i++){ + ymerge[i] = 0; + } + mass = 0; + mass_allpfo = 0; + } + +}; +#endif + diff --git a/Reconstruction/RecPFACyber/CMakeLists.txt b/Reconstruction/RecPFACyber/CMakeLists.txt index e448bd169043d8c04daafb526da2991b8aca3d06..5209dcef1784cfef3e0e2d3d8b95989c06c4a2f9 100644 --- a/Reconstruction/RecPFACyber/CMakeLists.txt +++ b/Reconstruction/RecPFACyber/CMakeLists.txt @@ -24,6 +24,8 @@ gaudi_add_library(CrystalCaloRecLib ${ROOT_LIBRARIES} ${TMVA_LIBRARIES} EDM4HEP::edm4hep EDM4HEP::edm4hepDict + ${DD4hep_COMPONENT_LIBRARIES} + DetIdentifier ) diff --git a/Reconstruction/RecPFACyber/include/Algorithm/GlobalClusteringAlg.h b/Reconstruction/RecPFACyber/include/Algorithm/GlobalClusteringAlg.h index af64b125ab71e974bd26d7f58bfb333186586aab..3d9a770a0bcb292490180d2aa826c3d2249c0bd6 100644 --- a/Reconstruction/RecPFACyber/include/Algorithm/GlobalClusteringAlg.h +++ b/Reconstruction/RecPFACyber/include/Algorithm/GlobalClusteringAlg.h @@ -6,7 +6,6 @@ #include "time.h" #include <TTimeStamp.h> #include <ctime> - #include <cstdlib> using namespace Cyber; diff --git a/Reconstruction/RecPFACyber/include/Algorithm/HoughClusteringAlg.h b/Reconstruction/RecPFACyber/include/Algorithm/HoughClusteringAlg.h index 581c6fb99d9b39773a7f8da6d898eaf0bf000979..d1f838a2932ccf1ab27f1e0dd55c2d73a7e3d846 100644 --- a/Reconstruction/RecPFACyber/include/Algorithm/HoughClusteringAlg.h +++ b/Reconstruction/RecPFACyber/include/Algorithm/HoughClusteringAlg.h @@ -36,8 +36,12 @@ public: private: - std::vector<Cyber::CaloHalfCluster*> p_HalfClusterV; - std::vector<Cyber::CaloHalfCluster*> p_HalfClusterU; + std::vector<Cyber::CaloHalfCluster*> barrel_HalfClusterV; // Barrel ECAL, V: bars parallel to z axis + std::vector<Cyber::CaloHalfCluster*> barrel_HalfClusterU; // Barrel ECAL, U: bars perpendicular to z axis + std::vector<Cyber::CaloHalfCluster*> endcap0_HalfClusterV; // Endcap ECAL at z~-2900mm, V: bars parallel to x axis + std::vector<Cyber::CaloHalfCluster*> endcap0_HalfClusterU; // Endcap ECAL at z~-2900mm, U: bars parallel to y axis + std::vector<Cyber::CaloHalfCluster*> endcap1_HalfClusterV; // Endcap ECAL at z~2900mm, V: bars parallel to x axis + std::vector<Cyber::CaloHalfCluster*> endcap1_HalfClusterU; // Endcap ECAL at z~2900mm, U: bars parallel to y axis std::vector<const Cyber::Calo1DCluster*> m_localMaxVCol; std::vector<const Cyber::Calo1DCluster*> m_localMaxUCol; diff --git a/Reconstruction/RecPFACyber/include/Algorithm/TrackExtrapolatingAlg.h b/Reconstruction/RecPFACyber/include/Algorithm/TrackExtrapolatingAlg.h index 6760c894fbec4024b8df6b8e4537ea5f1a86b3c3..1f42fb49aaa807a2981d8865a0f5b48f88dd6c09 100644 --- a/Reconstruction/RecPFACyber/include/Algorithm/TrackExtrapolatingAlg.h +++ b/Reconstruction/RecPFACyber/include/Algorithm/TrackExtrapolatingAlg.h @@ -27,14 +27,16 @@ public: // Get points in each plane of layer StatusCode GetLayerRadius(std::vector<float> & ECAL_layer_radius, std::vector<float> & HCAL_layer_radius); + StatusCode GetLayerZ(std::vector<float> & ECAL_layer_z, std::vector<float> & HCAL_layer_z); // If the track reach barrel ECAL bool IsReachECAL(Cyber::Track * track); // Get track state at calorimeter StatusCode GetTrackStateAtCalo(Cyber::Track * track, Cyber::TrackState & trk_state_at_calo); // get extrapolated points - StatusCode ExtrapolateByRadius( const std::vector<float> & ECAL_layer_radius, std::vector<float> & HCAL_layer_radius, - const Cyber::TrackState & CALO_trk_state, Cyber::Track* p_track); + StatusCode Extrapolate( const std::vector<float> & ECAL_layer_radius, const std::vector<float> & ECAL_layer_z, + const std::vector<float> & HCAL_layer_radius, const std::vector<float> & HCAL_layer_z, + const Cyber::TrackState & CALO_trk_state, Cyber::Track* p_track); // Get the radius rho float GetRho(const Cyber::TrackState & trk_state); // Get coordinates of the center of the circle @@ -44,11 +46,14 @@ public: // If the charged particle return back bool IsReturn(float rho, TVector2 & center); - std::vector<float> GetDeltaPhi(float rho, TVector2 center, float alpha0, vector<float> layer_radius, const Cyber::TrackState & CALO_trk_state); + StatusCode GetDeltaPhi( float rho, TVector2 center, float alpha0, + const std::vector<float> & layer_radius, const std::vector<float> & layer_z, + const Cyber::TrackState & CALO_trk_state, + vector<float> & barrel_delta_phi, vector<float> & endcap_delta_phi); std::vector<TVector3> GetExtrapoPoints(std::string calo_name, float rho, TVector2 center, float alpha0, const Cyber::TrackState & CALO_trk_state, - const std::vector<float>& delta_phi); + const std::vector<float>& barrel_delta_phi, const std::vector<float>& endcap_delta_phi); // Get phi0 of extrapolated points. Note that this phi0 is not same as the definition of the phi0 in TrackState, but will be stored in TrackState float GetExtrapolatedPhi0(float Kappa, float ECAL_phi0, TVector2 center, TVector3 ext_point); diff --git a/Reconstruction/RecPFACyber/include/CyberDataCol.h b/Reconstruction/RecPFACyber/include/CyberDataCol.h index 893b1f5adaa1c94b1ca5c63570907d3f2984aad0..5719eeb85ffe52086940cf42b31a93a8f33206b5 100644 --- a/Reconstruction/RecPFACyber/include/CyberDataCol.h +++ b/Reconstruction/RecPFACyber/include/CyberDataCol.h @@ -1,3 +1,14 @@ +//============================================================= +// CyberPFA: a PFA developed for CEPC referenece detector +// Ver. CyberPFA-5.0.1(2025.01.09) +//------------------------------------------------------------- +// Data Collection with CyberPFA EDM +//------------------------------------------------------------- +// Author: Fangyi Guo, Yang Zhang, Weizheng Song, Shengsen Sun +// (IHEP, CAS) +// Contact: guofangyi@ihep.ac.cn, +// sunss@ihep.ac.cn +//============================================================= #ifndef _PANDORAPLUS_DATA_H #define _PANDORAPLUS_DATA_H #include <iostream> diff --git a/Reconstruction/RecPFACyber/include/CyberPFAlg.h b/Reconstruction/RecPFACyber/include/CyberPFAlg.h index 83f1c256a5c28efa893c48b41a86b0a94dc2cb96..c333c5a92588f3792f7df39078cdea3fbf680b35 100644 --- a/Reconstruction/RecPFACyber/include/CyberPFAlg.h +++ b/Reconstruction/RecPFACyber/include/CyberPFAlg.h @@ -1,3 +1,12 @@ +//============================================================= +// CyberPFA: a PFA developed for CEPC referenece detector +// Ver. CyberPFA-5.0.1(2025.01.09) +//------------------------------------------------------------- +// Author: Fangyi Guo, Yang Zhang, Weizheng Song, Shengsen Sun +// (IHEP, CAS) +// Contact: guofangyi@ihep.ac.cn, +// sunss@ihep.ac.cn +//============================================================= #ifndef PANDORAPLUS_ALG_H #define PANDORAPLUS_ALG_H @@ -8,6 +17,7 @@ #include <DDRec/CellIDPositionConverter.h> #include <DD4hep/Segmentations.h> #include "DetInterface/IGeomSvc.h" +#include "DetIdentifier/CEPCDetectorData.h" #include <CrystalEcalSvc/ICrystalEcalSvc.h> #include "k4FWCore/PodioDataSvc.h" @@ -73,7 +83,6 @@ public: /** Called after data processing for clean up. */ virtual StatusCode finalize() ; - protected: @@ -86,7 +95,7 @@ protected: dd4hep::Detector* m_dd4hep; dd4hep::rec::CellIDPositionConverter* m_cellIDConverter; dd4hep::VolumeManager m_volumeManager; - + std::map<std::tuple<int, int, int, int, int>, int> barNumberMapEndcapMap; //DataCollection: moved into execute() to ensure everything can be cleand after one event. //CyberDataCol m_DataCol; @@ -191,10 +200,10 @@ protected: //Raw bars and hits TTree* t_SimBar; float m_totE_EcalSim, m_totE_HcalSim; - FloatVec m_simBar_x, m_simBar_y, m_simBar_z, m_simBar_T1, m_simBar_T2, m_simBar_Q1, m_simBar_Q2; + FloatVec m_simBar_x, m_simBar_y, m_simBar_z, m_simBar_length, m_simBar_nBarInLayer, m_simBar_T1, m_simBar_T2, m_simBar_Q1, m_simBar_Q2; FloatVec m_simBar_truthMC_tag, m_simBar_truthMC_pid, m_simBar_truthMC_px, m_simBar_truthMC_py, m_simBar_truthMC_pz, m_simBar_truthMC_E, - m_simBar_truthMC_EPx, m_simBar_truthMC_EPy, m_simBar_truthMC_EPz, m_simBar_truthMC_weight; - IntVec m_simBar_dlayer, m_simBar_stave, m_simBar_slayer, m_simBar_module, m_simBar_bar; + m_simBar_truthMC_EPx, m_simBar_truthMC_EPy, m_simBar_truthMC_EPz, m_simBar_truthMC_weight; + IntVec m_simBar_dlayer, m_simBar_stave, m_simBar_slayer, m_simBar_module, m_simBar_bar, m_simBar_system; FloatVec m_HcalHit_x, m_HcalHit_y, m_HcalHit_z, m_HcalHit_E, m_HcalHit_truthMC_tag, m_HcalHit_truthMC_pid, m_HcalHit_truthMC_px, m_HcalHit_truthMC_py, m_HcalHit_truthMC_pz, m_HcalHit_truthMC_E, m_HcalHit_truthMC_EPx, m_HcalHit_truthMC_EPy, m_HcalHit_truthMC_EPz, m_HcalHit_truthMC_weight; diff --git a/Reconstruction/RecPFACyber/include/Objects/Calo1DCluster.h b/Reconstruction/RecPFACyber/include/Objects/Calo1DCluster.h index e37529e1ec94e3349b91f8b228c4a665934d9f68..9cfc55fb55ded26b3970095ff7ce0ea197ee8e0c 100644 --- a/Reconstruction/RecPFACyber/include/Objects/Calo1DCluster.h +++ b/Reconstruction/RecPFACyber/include/Objects/Calo1DCluster.h @@ -28,7 +28,7 @@ namespace Cyber{ bool isNeighbor(const Cyber::CaloUnit* m_bar) const; bool inCluster(const Cyber::CaloUnit* iBar) const; - void sortByPos() { std::sort(Bars.begin(), Bars.end()); } + void sortByPos() { std::sort(Bars.begin(), Bars.end(), compPos); } double getEnergy() const; TVector3 getPos() const; @@ -65,6 +65,7 @@ namespace Cyber{ int getDlayer() const { if(Bars.size()>0) return Bars[0]->getDlayer(); return -99; } int getSlayer() const { if(Bars.size()>0) return Bars[0]->getSlayer(); return -99; } + int getSystem() const { if(Bars.size()>0) return Bars[0]->getSystem(); return -99; } std::vector< std::vector<int> > getTowerID() const { return towerID; } private: @@ -73,12 +74,15 @@ namespace Cyber{ double Energy; TVector3 pos; - std::vector< std::vector<int> > towerID; //[module, stave] + std::vector< std::vector<int> > towerID; //[system, module, stave, part] std::vector< const Cyber::Calo1DCluster* > CousinClusters; std::vector< const Cyber::Calo1DCluster* > ChildClusters; std::vector< std::pair<edm4hep::MCParticle, float> > MCParticleWeight; + + static bool compPos( const Cyber::CaloUnit* hit1, const Cyber::CaloUnit* hit2 ) + { return *hit1 < *hit2; } }; } #endif diff --git a/Reconstruction/RecPFACyber/include/Objects/Calo2DCluster.h b/Reconstruction/RecPFACyber/include/Objects/Calo2DCluster.h index e73719e152d8d78f0e77200fbb0a8c2c99cea463..8f21ac79d62cc68c0a039bb5f269f11c773eee49 100644 --- a/Reconstruction/RecPFACyber/include/Objects/Calo2DCluster.h +++ b/Reconstruction/RecPFACyber/include/Objects/Calo2DCluster.h @@ -46,14 +46,14 @@ namespace Cyber { void setShowerUCol(std::vector<const Calo1DCluster*> _sh) { barShowerUCol=_sh; } void setShowerVCol(std::vector<const Calo1DCluster*> _sh) { barShowerVCol=_sh; } void addUnit(const Calo1DCluster* _1dcluster); - void addTowerID(int _m, int _p, int _s) { std::vector<int> id(3); id[0] = _m; id[1] = _p; id[2] = _s; towerID.push_back(id); } + void addTowerID(int _sys, int _m, int _s, int _p) { std::vector<int> id(4); id[0] = _sys; id[1] = _m; id[2] = _s; id[3] = _p; towerID.push_back(id); } void addTowerID(std::vector<int> id) { towerID.push_back(id); } void setTowerID(std::vector<int> id) { towerID.clear(); towerID.push_back(id); } void setPos( TVector3 _vec ) { pos = _vec; } void setPos( double _x, double _y, double _z ) { pos.SetXYZ(_x, _y, _z); } private: - std::vector< std::vector<int> > towerID; //[module, stave] + std::vector< std::vector<int> > towerID; //[system, module, stave, part] TVector3 pos = TVector3(0.,0.,0.); std::vector<const CaloHit*> hits; diff --git a/Reconstruction/RecPFACyber/include/Objects/Calo3DCluster.h b/Reconstruction/RecPFACyber/include/Objects/Calo3DCluster.h index 98443e2b70237694b2abb8b404c2a9305633cd81..d5a513497527b2295afe507f3117916002f27962 100644 --- a/Reconstruction/RecPFACyber/include/Objects/Calo3DCluster.h +++ b/Reconstruction/RecPFACyber/include/Objects/Calo3DCluster.h @@ -58,6 +58,7 @@ namespace Cyber { int getType() const { return type; } double getEnergyScale() const { return Escale; } + void setAxis(TVector3 _axis ) { axis = _axis; } void setCaloHits( std::vector<const Cyber::CaloHit*> _hits ) { hits = _hits; } void setCaloHitsFrom2DCluster(); void setTowers(std::vector<const Calo3DCluster*> _t) { m_towers = _t; } diff --git a/Reconstruction/RecPFACyber/include/Objects/CaloHalfCluster.h b/Reconstruction/RecPFACyber/include/Objects/CaloHalfCluster.h index bff03f0bbe30f94a8bd02263d844bbe5d7baa05b..7dff502962f7c70fc70547047c8dbb32a4e76d24 100644 --- a/Reconstruction/RecPFACyber/include/Objects/CaloHalfCluster.h +++ b/Reconstruction/RecPFACyber/include/Objects/CaloHalfCluster.h @@ -72,7 +72,7 @@ namespace Cyber { void setHoughPars(double _a, double _r) { Hough_alpha=_a; Hough_rho=_r; } void setIntercept(double _in) { Hough_intercept=_in; } void mergeHalfCluster( const CaloHalfCluster* clus ); - void addTowerID(int _m, int _p, int _s) { std::vector<int> id(3); id[0] = _m; id[1] = _p; id[2] = _s; towerID.push_back(id); } + void addTowerID(int _sys, int _m, int _s, int _p) { std::vector<int> id(4); id[0] = _sys; id[1] = _m; id[2] = _s; id[3] = _p; towerID.push_back(id); } void addTowerID(std::vector<int> id) { towerID.push_back(id); } void setTowerID(std::vector<int> id) { towerID.clear(); towerID.push_back(id); } void addAssociatedTrack(const Cyber::Track* _track){ m_TrackCol.push_back(_track); } @@ -83,7 +83,7 @@ namespace Cyber { private: int type; // yyy: new definition: track: 10000, Hough: 100, cone: 1, merge: sum them - std::vector< std::vector<int> > towerID; //[module, part, stave] + std::vector< std::vector<int> > towerID; //[system, module, stave, part] int slayer; mutable TVector3 axis = TVector3(99999., 99999., 99999.); mutable double trk_dr; diff --git a/Reconstruction/RecPFACyber/include/Objects/CaloHit.h b/Reconstruction/RecPFACyber/include/Objects/CaloHit.h index 2b8917f8df9a7765f0c5ab4d77a7762a3c943dd1..32582667c5c5e2a1054168ab855549f791003e47 100644 --- a/Reconstruction/RecPFACyber/include/Objects/CaloHit.h +++ b/Reconstruction/RecPFACyber/include/Objects/CaloHit.h @@ -14,7 +14,7 @@ namespace Cyber{ CaloHit() {}; ~CaloHit() { Clear(); }; - void Clear() { cellID=0; position.SetXYZ(0.,0.,0.); energy=-1; module=-1; layer=-1; ParentShower=nullptr; } + void Clear() { cellID=0; position.SetXYZ(0.,0.,0.); energy=-1; system = -1; module=-1; layer=-1; ParentShower=nullptr; } std::shared_ptr<CaloHit> Clone() const; void setOriginHit( edm4hep::CalorimeterHit& _hit ) { m_hit = _hit; } @@ -22,15 +22,17 @@ namespace Cyber{ double getEnergy() const { return energy; } int getLayer() const {return layer;} int getModule() const {return module;} + int getSystem() const {return system;} std::vector< std::pair<edm4hep::MCParticle, float> > getLinkedMCP() const { return MCParticleWeight; } edm4hep::MCParticle getLeadingMCP() const; float getLeadingMCPweight() const; edm4hep::CalorimeterHit getOriginHit() const { return m_hit; } void setcellID(unsigned long long _id) { cellID=_id; } - void setcellID(int _m, int _l) { module=_m; layer=_l; } + void setcellID(int _s, int _m, int _l) { system=_s; module=_m; layer=_l; } void setEnergy(double _en) { energy=_en; } void setPosition( TVector3 _vec ) { position=_vec; } + void setSystem(int _s) { system = _s; } void setModule(int _m ) { module = _m; } void setLayer(int _l) { layer = _l; } void setParentShower( Cyber::Calo2DCluster* _p ) { ParentShower=_p; } @@ -38,6 +40,7 @@ namespace Cyber{ void setLinkedMCP( std::vector<std::pair<edm4hep::MCParticle, float>> _pairVec ) { MCParticleWeight.clear(); MCParticleWeight = _pairVec; } private: + int system; int module; int layer; unsigned long long cellID; diff --git a/Reconstruction/RecPFACyber/include/Objects/CaloUnit.h b/Reconstruction/RecPFACyber/include/Objects/CaloUnit.h index 0530e65a1dfe85c6d2655771dc5eb84259e19bd9..5c1904eb4fa09bb3aa48c3c0ec24687e356364b1 100644 --- a/Reconstruction/RecPFACyber/include/Objects/CaloUnit.h +++ b/Reconstruction/RecPFACyber/include/Objects/CaloUnit.h @@ -10,8 +10,8 @@ namespace Cyber{ class CaloUnit{ public: - CaloUnit(unsigned long long _cellID, int _system, int _module, int _slayer, int _dlayer, int _stave, int _bar, TVector3 _pos, double _Q1, double _Q2, double _T1, double _T2) - : cellID(_cellID), system(_system), module(_module), stave(_stave), dlayer(_dlayer), slayer(_slayer), bar(_bar), position(_pos), Q1(_Q1), Q2(_Q2), T1(_T1), T2(_T2) {}; + CaloUnit(unsigned long long _cellID, int _system, int _module, int _slayer, int _dlayer, int _stave, int _part, int _bar, TVector3 _pos, double _Q1, double _Q2, double _T1, double _T2) + : cellID(_cellID), system(_system), module(_module), stave(_stave), part(_part), dlayer(_dlayer), slayer(_slayer), bar(_bar), position(_pos), Q1(_Q1), Q2(_Q2), T1(_T1), T2(_T2) {}; CaloUnit() {}; ~CaloUnit() { Clear(); }; void Clear() { position.SetXYZ(0.,0.,0.); Q1=-1; Q2=-1; T1=-99; T2=-99; } @@ -19,14 +19,20 @@ namespace Cyber{ inline bool operator < (const CaloUnit &x) const { if(x.cellID==cellID) return false; - if(slayer==0) return ( (stave<x.stave) || (stave==x.stave && bar<x.bar) ); - else{ - if( module==Nmodule && x.module==0 ) return true; - else if( module==0 && x.module==Nmodule ) return false; + if(system==System_Barrel){ + if(slayer==0) return ( (stave<x.stave) || (stave==x.stave && bar<x.bar) ); else{ - return ( (module<x.module) || (module==x.module && bar<x.bar) ); + if( module==Nmodule && x.module==0 ) return true; + else if( module==0 && x.module==Nmodule ) return false; + else{ + return ( (module<x.module) || (module==x.module && bar<x.bar) ); + } } } + else{ + if(slayer==0) return (position.x() < x.getPosition().x()); + else return (position.y() < x.getPosition().y()); + } } inline bool operator == (const CaloUnit &x) const{ @@ -36,6 +42,7 @@ namespace Cyber{ int getSystem() const { return system; } int getModule() const { return module; } int getStave() const { return stave; } + int getPart() const { return part; } int getDlayer() const { return dlayer; } int getSlayer() const { return slayer; } int getBar() const { return bar; } @@ -44,6 +51,7 @@ namespace Cyber{ double getT1() const { return T1; } double getT2() const { return T2; } double getBarLength() const {return barLength; } + int getNBarInLayer() const { return nBarInLayer; } TVector3 getPosition() const { return position; } double getEnergy() const { return (Q1+Q2); } @@ -67,8 +75,11 @@ namespace Cyber{ void setQ(double _q1, double _q2) { Q1=_q1; Q2=_q2; } void setT(double _t1, double _t2) { T1=_t1; T2=_t2; } void setBarLength(double _barLength) { barLength=_barLength; } + void setNBarInLayer(int _nBarInLayer) { nBarInLayer=_nBarInLayer; } std::shared_ptr<CaloUnit> Clone() const; + static int System_Barrel; + static int System_Endcap; static int Nmodule; static int Nstave; static int Nlayer; @@ -77,6 +88,8 @@ namespace Cyber{ static int NbarZ; static float barsize; static float ecal_innerR; + static float ecal_endcap_deadarea; + static float ecal_endcap_barsize; private: unsigned long long cellID; @@ -96,6 +109,7 @@ namespace Cyber{ double barLength; std::vector< std::pair<edm4hep::MCParticle, float> > MCParticleWeight; + int nBarInLayer; }; } diff --git a/Reconstruction/RecPFACyber/include/Objects/HoughObject.h b/Reconstruction/RecPFACyber/include/Objects/HoughObject.h index ea56a8144af862d19737de7d5c4d21fc0b5171c1..3e88e23a25cf2a45a5bd06920cce59e003e82c2d 100644 --- a/Reconstruction/RecPFACyber/include/Objects/HoughObject.h +++ b/Reconstruction/RecPFACyber/include/Objects/HoughObject.h @@ -11,7 +11,7 @@ namespace Cyber { class HoughObject{ public: HoughObject() {}; - HoughObject( const Cyber::Calo1DCluster* _localmax, double _cellSize, double _ecal_inner_radius, double _phi=0.); + HoughObject( const Cyber::Calo1DCluster* _localmax, double _cellSize, double _ecal_inner_radius); ~HoughObject() { }; @@ -34,12 +34,13 @@ namespace Cyber { //int getModule() const { return (m_local_max->getTowerID())[0][0]; } int getSlayer() const { return m_local_max->getSlayer(); } + int getSystem() const { return m_local_max->getBars()[0]->getSystem(); } double getE() const { return m_local_max->getEnergy(); } double getCellSize() const { return m_cell_size; } const Cyber::Calo1DCluster* getLocalMax() const { return m_local_max; } void setCellSize(double _cs) { m_cell_size=_cs; } - void setCenterPoint(double& _ecal_inner_radius, double _phi=0.); + void setCenterPoint(double& _ecal_inner_radius); void setHoughLine(TF1& line1, TF1& line2); diff --git a/Reconstruction/RecPFACyber/include/Tools/CaloHitsCreator.h b/Reconstruction/RecPFACyber/include/Tools/CaloHitsCreator.h index ea07735f0257773277676348842462151570f333..b4ffdeecb6af7c702d6c52c418ec47b4d69db0c4 100644 --- a/Reconstruction/RecPFACyber/include/Tools/CaloHitsCreator.h +++ b/Reconstruction/RecPFACyber/include/Tools/CaloHitsCreator.h @@ -21,7 +21,8 @@ namespace Cyber{ std::vector<DataHandle<edm4hep::CalorimeterHitCollection>*>& r_CaloHitCols, std::map<std::string, dd4hep::DDSegmentation::BitFieldCoder*>& map_decoder, std::map<std::string, DataHandle<edm4hep::MCRecoCaloParticleAssociationCollection>*>& map_CaloParticleAssoCol, - const dd4hep::VolumeManager& m_volumeManager ); + const dd4hep::VolumeManager& m_volumeManager, + std::map<std::tuple<int, int, int, int, int>, int>& barNumberMapEndcapMap ); //StatusCode CreateMCParticleCaloHitsAsso( std::vector<DataHandle<edm4hep::CalorimeterHitCollection>*>& r_CaloHitCols, // DataHandle<edm4hep::MCRecoCaloParticleAssociationCollection>* r_MCParticleRecoCaloCol ); diff --git a/Reconstruction/RecPFACyber/script/ana.py b/Reconstruction/RecPFACyber/script/ana.py index e5706e97ebd9971fee78b0d3b77f3646d5fe2898..cbbde0813887ffd98282372d9e5a35ec1d0c91b2 100644 --- a/Reconstruction/RecPFACyber/script/ana.py +++ b/Reconstruction/RecPFACyber/script/ana.py @@ -14,13 +14,14 @@ cepcswdatatop ="/cvmfs/cepcsw.ihep.ac.cn/prototype/releases/data/latest" ########## Podio Input ################### from Configurables import PodioInput inp = PodioInput("InputReader") -inp.collections = [ "CyberPFO", "MCParticle" ] +inp.collections = [ "CyberPFO", "CyberPFOPID", "MCParticle" ] ########################################## from Configurables import GenMatch genmatch = GenMatch("GenMatch") +genmatch.InputPFOs = "CyberPFOPID" genmatch.nJets = 2 genmatch.R = 0.6 genmatch.OutputFile = "Jets_TDR_o1_v01.root" diff --git a/Reconstruction/RecPFACyber/script/digi.py b/Reconstruction/RecPFACyber/script/digi.py index c8ab8e683a5bc865ecbf45cfe349c34af5698391..5dd53b0426032e48c692c1d6ad807d967844e0c4 100644 --- a/Reconstruction/RecPFACyber/script/digi.py +++ b/Reconstruction/RecPFACyber/script/digi.py @@ -86,16 +86,18 @@ EcalDigi.EcalSiPMPDE = 0.25 # NDL-EQR06, PDE 0.25 EcalDigi.EcalSiPMDCR = 0 # NDL-EQR06, dark count rate 2500000 [Hz] EcalDigi.EcalTimeInterval = 0. # Time interval 0.000002 [s]. DCR*TimeInterval = dark count noise EcalDigi.EcalSiPMCT = 0. # SiPM crosstalk Probability 12% -EcalDigi.EcalSiPMGainMean = 50 # 50 [ADC/p.e.] +EcalDigi.EcalSiPMGainMean = 5 # 5 [ADC/p.e.] EcalDigi.EcalSiPMGainSigma = 0.08 # 0.08 #EcalDigi.EcalSiPMNoiseSigma = 0 # 0 # ADC EcalDigi.ADC = 8192 # 13-bit, 8192 EcalDigi.ADCSwitch = 8000 # 8000 EcalDigi.Pedestal = 50 # Pedestal 50 ADC -EcalDigi.GainRatio_12 = 50 # Gain ratio 50 -EcalDigi.GainRatio_23 = 60 # Gain ratio 60 -#EcalDigi.EcalNoiseADCSigma = 4 # 4 +EcalDigi.GainRatio_12 = 30 # Gain ratio 30 +EcalDigi.GainRatio_23 = 10 # Gain ratio 10 +EcalDigi.EcalASICNoiseSigma = 4 +EcalDigi.EcalFEENoiseSigma = 5 +EcalDigi.ADCNonLinearity = 0 # ADC non-linearity 0 # temperature control EcalDigi.UseCryTemp = 0 EcalDigi.UseCryTempCor = 0 diff --git a/Reconstruction/RecPFACyber/script/rec.py b/Reconstruction/RecPFACyber/script/rec.py index 3e2257cc2507f4764fc21242a015b9783573e54f..20706f0849b9d20141ca31e11860373d96799862 100644 --- a/Reconstruction/RecPFACyber/script/rec.py +++ b/Reconstruction/RecPFACyber/script/rec.py @@ -39,12 +39,12 @@ inp = PodioInput("InputReader") inp.collections = [ "ECALBarrel", "ECALBarrelParticleAssoCol", -# "ECALEndcaps", -# "ECALEndcapsParticleAssoCol", + "ECALEndcaps", + "ECALEndcapsParticleAssoCol", "HCALBarrel", "HCALBarrelParticleAssoCol", -# "HCALEndcaps", -# "HCALEndcapsParticleAssoCol", + "HCALEndcaps", + "HCALEndcapsParticleAssoCol", "MCParticle", "CompleteTracks", "CompleteTracksParticleAssociation", @@ -75,18 +75,12 @@ CyberPFAlg.HcalNeutralCalib = 4.0 CyberPFAlg.MCParticleCollection = "MCParticle" CyberPFAlg.TrackCollections = ["CompleteTracks"] CyberPFAlg.MCRecoTrackParticleAssociationCollection = "CompleteTracksParticleAssociation" -#CyberPFAlg.ECalCaloHitCollections = ["ECALBarrel","ECALEndcaps"] -#CyberPFAlg.ECalReadOutNames = ["EcalBarrelCollection","EcalEndcapsCollection"] -#CyberPFAlg.ECalMCPAssociationName = ["ECALBarrelParticleAssoCol", "ECALEndcapsParticleAssoCol"] -#CyberPFAlg.HCalCaloHitCollections = ["HCALBarrel", "HCALEndcaps"] -#CyberPFAlg.HCalReadOutNames = ["HcalBarrelCollection", "HcalEndcapsCollection"] -#CyberPFAlg.HCalMCPAssociationName = ["HCALBarrelParticleAssoCol", "HCALEndcapsParticleAssoCol"] -CyberPFAlg.ECalCaloHitCollections = ["ECALBarrel"] -CyberPFAlg.ECalReadOutNames = ["EcalBarrelCollection"] -CyberPFAlg.ECalMCPAssociationName = ["ECALBarrelParticleAssoCol"] -CyberPFAlg.HCalCaloHitCollections = ["HCALBarrel"] -CyberPFAlg.HCalReadOutNames = ["HcalBarrelCollection"] -CyberPFAlg.HCalMCPAssociationName = ["HCALBarrelParticleAssoCol"] +CyberPFAlg.ECalCaloHitCollections = ["ECALBarrel","ECALEndcaps"] +CyberPFAlg.ECalReadOutNames = ["EcalBarrelCollection","EcalEndcapsCollection"] +CyberPFAlg.ECalMCPAssociationName = ["ECALBarrelParticleAssoCol", "ECALEndcapsParticleAssoCol"] +CyberPFAlg.HCalCaloHitCollections = ["HCALBarrel", "HCALEndcaps"] +CyberPFAlg.HCalReadOutNames = ["HcalBarrelCollection", "HcalEndcapsCollection"] +CyberPFAlg.HCalMCPAssociationName = ["HCALBarrelParticleAssoCol", "HCALEndcapsParticleAssoCol"] ##--- Output collections --- CyberPFAlg.OutputPFO = "outputPFO"; @@ -113,8 +107,8 @@ CyberPFAlg.AlgParNames = [ ["InputECALBars","OutputECAL1DClusters","OutputECALHa ["OutputAxisName"], #6 ["ReadinAxisName", "OutputClusName", "OutputTowerName"], #9 ["ReadinHFClusterName", "ReadinTowerName","OutputClusterName"], #11 - ["InputHCALHits", "OutputHCALClusters"], #12 - ["DoECALClustering","DoHCALClustering","InputHCALHits","OutputHCALClusters"], #15 + ["OutputHCALClusters"], #12 + ["DoECALClustering","DoHCALClustering","OutputHCALClusters"], #15 ["ReadinECALClusterName", "ReadinHCALClusterName", "OutputCombPFO"], #16 ["ECALChargedCalib", "HCALChargedCalib", "ECALNeutralCalib", "HCALNeutralCalib"] ]#17 CyberPFAlg.AlgParTypes = [ ["string","string","string"],#1 @@ -125,8 +119,8 @@ CyberPFAlg.AlgParTypes = [ ["string","string","string"],#1 ["string"], #6 ["string","string","string"], #9 ["string","string","string"], #11 - ["string", "string"], #12 - ["bool","bool","string","string"], #15 + ["string"], #12 + ["bool","bool","string"], #15 ["string","string","string"], #16 ["double","double", "double","double"] ]#17 CyberPFAlg.AlgParValues = [ ["BarCol","Cluster1DCol","HalfClusterCol"],#1 @@ -137,8 +131,8 @@ CyberPFAlg.AlgParValues = [ ["BarCol","Cluster1DCol","HalfClusterCol"],#1 ["MergedAxis"], #6 ["MergedAxis","ESHalfCluster","ESTower"], #9 ["ESHalfCluster","ESTower","EcalCluster"], #11 - ["HCALBarrel", "SimpleHCALCluster"], #12 - ["0","1","HCALBarrel","HCALCluster"], #15 + ["SimpleHCALCluster"], #12 + ["0","1","HCALCluster"], #15 ["EcalCluster", "SimpleHCALCluster", "outputPFO"], #16 ["1.26","4.", "1.", "4."] ]#17 diff --git a/Reconstruction/RecPFACyber/script/tracking.py b/Reconstruction/RecPFACyber/script/tracking.py index dfb749c291d30fa6ffd1f4b83a021c78fa3cf018..fd4fcc0dbf5f0c614c9e06ef2a7cfeb1937c03d6 100644 --- a/Reconstruction/RecPFACyber/script/tracking.py +++ b/Reconstruction/RecPFACyber/script/tracking.py @@ -6,7 +6,7 @@ from Configurables import k4DataSvc dsvc = k4DataSvc("EventDataSvc", input="CaloDigi_TDR_o1_v01.root") from Configurables import RndmGenSvc, HepRndm__Engine_CLHEP__RanluxEngine_ -seed = [1024] +seed = [12340] # rndmengine = HepRndm__Engine_CLHEP__RanluxEngine_() # The default engine in Gaudi rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_("RndmGenSvc.Engine") # The default engine in Geant4 rndmengine.SetSingleton = True @@ -51,13 +51,19 @@ podioinput = PodioInput("PodioReader", collections=[ "VXDCollection", "SITCollection", "TPCCollection", +# "SETCollection", "OTKBarrelCollection", "FTDCollection", "MuonBarrelCollection", "MuonEndcapCollection" ]) -# digitization + +################## +# Digitization +################## + +## Config ## vxdhitname = "VXDTrackerHits" sithitname = "SITTrackerHits" gashitname = "TPCTrackerHits" @@ -65,17 +71,14 @@ sethitname = "OTKBarrelTrackerHits" setspname = "OTKBarrelSpacePoints" ftdhitname = "FTDTrackerHits" ftdspname = "FTDSpacePoints" -from Configurables import SmearDigiTool +from Configurables import SmearDigiTool,SiTrackerDigiAlg + +## VXD ## vxdtool = SmearDigiTool("VXD") vxdtool.ResolutionU = [0.005] vxdtool.ResolutionV = [0.005] -vxdtool.UsePlanarTag = True -vxdtool.ParameterizeResolution = False -vxdtool.ParametersU = [5.60959e-03, 5.74913e-03, 7.03433e-03, 1.99516, -663.952, 3.752e-03, 0, -0.0704734, 0.0454867e-03, 1.07359] -vxdtool.ParametersV = [5.60959e-03, 5.74913e-03, 7.03433e-03, 1.99516, -663.952, 3.752e-03, 0, -0.0704734, 0.0454867e-03, 1.07359] #vxdtool.OutputLevel = DEBUG -from Configurables import SiTrackerDigiAlg digiVXD = SiTrackerDigiAlg("VXDDigi") digiVXD.SimTrackHitCollection = "VXDCollection" digiVXD.TrackerHitCollection = vxdhitname @@ -83,46 +86,46 @@ digiVXD.TrackerHitAssociationCollection = "VXDTrackerHitAssociation" digiVXD.DigiTool = "SmearDigiTool/VXD" #digiVXD.OutputLevel = DEBUG -from Configurables import PlanarDigiAlg -digiSIT = PlanarDigiAlg("SITDigi") -digiSIT.IsStrip = False +## SIT ## +sittool = SmearDigiTool("SIT") +sittool.ResolutionU = [0.0098] +sittool.ResolutionV = [0.0433] +#sittool.OutputLevel = DEBUG + +digiSIT = SiTrackerDigiAlg("SITDigi") digiSIT.SimTrackHitCollection = "SITCollection" digiSIT.TrackerHitCollection = sithitname digiSIT.TrackerHitAssociationCollection = "SITTrackerHitAssociation" -digiSIT.ResolutionU = [0.0098] -digiSIT.ResolutionV = [0.0433] -digiSIT.UsePlanarTag = True -digiSIT.ParameterizeResolution = False -digiSIT.ParametersU = [2.29655e-03, 0.965899e-03, 0.584699e-03, 17.0856, 84.566, 12.4695e-03, -0.0643059, 0.168662, 1.87998e-03, 0.514452] -digiSIT.ParametersV = [1.44629e-02, 2.20108e-03, 1.03044e-02, 4.39195e+00, 3.29641e+00, 1.55167e+18, -5.41954e+01, 5.72986e+00, -6.80699e-03, 5.04095e-01] +digiSIT.DigiTool = "SmearDigiTool/SIT" #digiSIT.OutputLevel = DEBUG -digiSET = PlanarDigiAlg("SETDigi") -digiSET.IsStrip = False -digiSET.SimTrackHitCollection = "OTKBarrelCollection" -digiSET.TrackerHitCollection = sethitname -digiSET.TrackerHitAssociationCollection = "OTKBarrelTrackerHitAssociation" -digiSET.ResolutionU = [0.010] -digiSET.ResolutionV = [1.000] -digiSET.UsePlanarTag = True -digiSET.ParameterizeResolution = False -digiSET.ParametersU = [2.29655e-03, 0.965899e-03, 0.584699e-03, 17.0856, 84.566, 12.4695e-03, -0.0643059, 0.168662, 1.87998e-03, 0.514452] -digiSET.ParametersV = [1.44629e-02, 2.20108e-03, 1.03044e-02, 4.39195e+00, 3.29641e+00, 1.55167e+18, -5.41954e+01, 5.72986e+00, -6.80699e-03, 5.04095e-01] -#digiSET.OutputLevel = DEBUG - -digiFTD = PlanarDigiAlg("FTDDigi") -digiFTD.IsStrip = False +## OTKBarrel ## +otkbtool = SmearDigiTool("OTKBarrel") +otkbtool.ResolutionU = [0.010] +otkbtool.ResolutionV = [1.000] +#otkbtool.OutputLevel = DEBUG + +digiOTKB = SiTrackerDigiAlg("OTKBarrelDigi") +digiOTKB.SimTrackHitCollection = "OTKBarrelCollection" +digiOTKB.TrackerHitCollection = sethitname +digiOTKB.TrackerHitAssociationCollection = "OTKBarrelTrackerHitAssociation" +digiOTKB.DigiTool = "SmearDigiTool/OTKBarrel" +#digiOTKB.OutputLevel = DEBUG + +## FTD ## +ftdtool = SmearDigiTool("FTD") +ftdtool.ResolutionU = [0.0072] +ftdtool.ResolutionV = [0.086] +#ftdtool.OutputLevel = DEBUG + +digiFTD = SiTrackerDigiAlg("FTDDigi") digiFTD.SimTrackHitCollection = "FTDCollection" digiFTD.TrackerHitCollection = ftdhitname digiFTD.TrackerHitAssociationCollection = "FTDTrackerHitAssociation" -digiFTD.ResolutionU = [0.0072] -digiFTD.ResolutionV = [0.086] -digiFTD.UsePlanarTag = True -digiFTD.ParameterizeResolution = False -digiFTD.ParametersU = [2.29655e-03, 0.965899e-03, 0.584699e-03, 17.0856, 84.566, 12.4695e-03, -0.0643059, 0.168662, 1.87998e-03, 0.514452] -digiFTD.ParametersV = [1.44629e-02, 2.20108e-03, 1.03044e-02, 4.39195e+00, 3.29641e+00, 1.55167e+18, -5.41954e+01, 5.72986e+00, -6.80699e-03, 5.04095e-01] +digiFTD.DigiTool = "SmearDigiTool/FTD" #digiFTD.OutputLevel = DEBUG +## TPC ## from Configurables import TPCDigiAlg digiTPC = TPCDigiAlg("TPCDigi") digiTPC.TPCCollection = "TPCCollection" @@ -137,6 +140,7 @@ digiTPC.TPCTrackerHitsCol = gashitname #digiTPC.N_eff = 30 #digiTPC.OutputLevel = DEBUG + ## Muon Detector ## from Configurables import MuonDigiAlg digiMuon = MuonDigiAlg("MuonDigiAlg") @@ -146,8 +150,11 @@ digiMuon.MuonBarrelTrackerHits = "MuonBarrelTrackerHits" digiMuon.MuonEndcapTrackerHits = "MuonEndcapTrackerHits" digiMuon.WriteNtuple = 0 digiMuon.OutFileName = "Digi_MUON.root" +######################################### -# tracking +################ +# Tracking +################ from Configurables import KalTestTool # Close multiple scattering and smooth, used by clupatra kt010 = KalTestTool("KalTest010") @@ -266,41 +273,19 @@ tmt.MuonTagEfficiency = 0.95 # muon true tag efficiency, default is 1.0 (100%) tmt.MuonDetTanTheta = 1.2 # muon det barrel/endcap separation tan(theta) #tmt.OutputLevel = DEBUG -#from Configurables import ReadDigiAlg -#readtrk = ReadDigiAlg("ReadDigiAlg") -#readtrk.SiTracks = "SubsetTracks" -#readtrk.TPCTracks = "ClupatraTracks" -#readtrk.FullTracks = "CompleteTracks" -#readtrk.TPCTracksAssociation = "ClupatraTracksParticleAssociation" -#readtrk.FullTracksAssociation = "CompleteTracksParticleAssociation" -#readtrk.OutFileName = "TrackAnaTuple_mu.root" - # output from Configurables import PodioOutput out = PodioOutput("outputalg") out.filename = "Tracking_TDR_o1_v01.root" -out.outputCommands = ["drop *", - "keep ECALBarrel", - "keep ECALBarrelParticleAssoCol", - "keep HCALBarrel", - "keep HCALBarrelParticleAssoCol", - "keep ECALEndcaps", - "keep HCALEndcaps", - "keep ECALEndcapsParticleAssoCol", - "keep HCALEndcapsParticleAssoCol", - "keep MCParticle", - "keep CompleteTracks", - "keep CompleteTracksParticleAssociation", - "keep RecTofCollection", - "keep DndxTracks" ] +out.outputCommands = ["keep *"] # ApplicationMgr from Configurables import ApplicationMgr mgr = ApplicationMgr( - TopAlg = [podioinput, digiVXD, digiSIT, digiSET, digiFTD, digiTPC, digiMuon, tracking, forward, subset, clupatra, full, tpr, tpc_dndx, tof, tmt, out], + TopAlg = [podioinput, digiVXD, digiSIT, digiOTKB, digiFTD, digiTPC, digiMuon, tracking, forward, subset, clupatra, full, tpr, tpc_dndx, tof, tmt, out], EvtSel = 'NONE', EvtMax = 10, ExtSvc = [rndmengine, rndmgensvc, dsvc, evtseeder, geosvc, gearsvc, tracksystemsvc, pidsvc], - #HistogramPersistency = 'ROOT', - OutputLevel = INFO + HistogramPersistency = 'ROOT', + OutputLevel = ERROR ) diff --git a/Reconstruction/RecPFACyber/src/Algorithm/AxisMergingAlg.cpp b/Reconstruction/RecPFACyber/src/Algorithm/AxisMergingAlg.cpp index 0bc5f5cc924746e8e6b8216fc430e7517909c44b..ae2a1cbd486f60c88ee9de31533eacb5b83ae006 100644 --- a/Reconstruction/RecPFACyber/src/Algorithm/AxisMergingAlg.cpp +++ b/Reconstruction/RecPFACyber/src/Algorithm/AxisMergingAlg.cpp @@ -190,7 +190,6 @@ cout<<endl; tmp_goodAxis.push_back( m_newAxisUCol[ic] ); } - else { tmp_badAxis.push_back( m_newAxisUCol[ic] ); } @@ -573,11 +572,74 @@ StatusCode AxisMergingAlg::BranchMerging( std::vector<Cyber::CaloHalfCluster*>& double hough_rho = p_axis->getHoughRho(); double hough_alpha = p_axis->getHoughAlpha(); - // V plane - if(m_axis->getSlayer()==1){ - double x0 = m_axis->getEnergyCenter().x(); - double y0 = m_axis->getEnergyCenter().y(); - double distance = TMath::Abs( x0*TMath::Cos(hough_alpha) + y0*TMath::Sin(hough_alpha) - hough_rho ); + //Barrel + if( m_axis->getTowerID()[0][0] == Cyber::CaloUnit::System_Barrel ){ + // V plane + if(m_axis->getSlayer()==1){ + double x0 = m_axis->getEnergyCenter().x(); + double y0 = m_axis->getEnergyCenter().y(); + double distance = TMath::Abs( x0*TMath::Cos(hough_alpha) + y0*TMath::Sin(hough_alpha) - hough_rho ); + + //cout << " yyy:V rho = " << hough_rho << ", alpha = " << hough_alpha << ", x0 = " << x0 << ", y0 = " << y0 << endl; + //cout << " distanceV = " << distance << endl; + + if (distance<settings.map_floatPars["th_branch_distance"]){ + m_axisCol[iax]->mergeHalfCluster( m_axisCol[jax] ); + int axis_type = m_axisCol[iax]->getType() + m_axisCol[jax]->getType(); + m_axisCol[iax]->setType(axis_type); + m_axisCol.erase(m_axisCol.begin()+jax); + jax--; + if(iax>jax+1) iax--; + // cout << " yyy: axis " << jax << " is merged into axis " << iax << endl; + } + } + + // U plane + else{ + int m_module = m_axis->getEnergyCenterTower()[1]; + //cout << " yyy:branceU: m_module = " << m_module << endl; + int p_module = p_axis->getTowerID()[0][1]; + //cout << " yyy:branceU: p_module = " << p_module << endl; + // Do not merge the two axis in two different modules + //if (m_module != p_module) continue; + + TVector3 t_pos = m_axis->getEnergyCenter(); + // cout << " yyy:branceU: t_pos = " << t_pos.x() << ", " << t_pos.y() << ", " << t_pos.z() << endl; + t_pos.RotateZ( TMath::TwoPi()/Cyber::CaloUnit::Nmodule*(int(Cyber::CaloUnit::Nmodule*3./4.)-m_module) ); + // cout << " yyy:branceU: t_pos after rotate to module 6 = " << t_pos.x() << ", " << t_pos.y() << ", " << t_pos.z() << endl; + double x0 = t_pos.x(); + double y0 = t_pos.z(); + double distance = TMath::Abs( x0*TMath::Cos(hough_alpha) + y0*TMath::Sin(hough_alpha) - hough_rho ); + + //cout << " yyy:U rho = " << hough_rho << ", alpha = " << hough_alpha << ", x0 = " << x0 << ", z0 = " << y0 << endl; + //cout << " distanceU = " << distance << endl; + + if (distance<settings.map_floatPars["th_branch_distance"]){ + m_axisCol[iax]->mergeHalfCluster( m_axisCol[jax] ); + int axis_type = m_axisCol[iax]->getType() + m_axisCol[jax]->getType(); + m_axisCol[iax]->setType(axis_type); + m_axisCol.erase(m_axisCol.begin()+jax); + //cout << " yyy: axis " << jax << " is merged into axis " << iax << endl; + jax--; + if(iax>jax+1) iax--; + } + } + } + + //Endcaps + else if(m_axis->getTowerID()[0][0] == Cyber::CaloUnit::System_Endcap) { + // V plane + double x0, y0, distance; + if(m_axis->getSlayer()==1){ + x0 = m_axis->getEnergyCenter().z(); + y0 = m_axis->getEnergyCenter().y(); + distance = TMath::Abs( x0*TMath::Cos(hough_alpha) + y0*TMath::Sin(hough_alpha) - hough_rho ); + } + else{ + x0 = m_axis->getEnergyCenter().z(); + y0 = m_axis->getEnergyCenter().x(); + distance = TMath::Abs( x0*TMath::Cos(hough_alpha) + y0*TMath::Sin(hough_alpha) - hough_rho ); + } //cout << " yyy:V rho = " << hough_rho << ", alpha = " << hough_alpha << ", x0 = " << x0 << ", y0 = " << y0 << endl; //cout << " distanceV = " << distance << endl; @@ -592,40 +654,10 @@ StatusCode AxisMergingAlg::BranchMerging( std::vector<Cyber::CaloHalfCluster*>& // cout << " yyy: axis " << jax << " is merged into axis " << iax << endl; } } - - // U plane else{ - int m_module = m_axis->getEnergyCenterTower()[0]; - //cout << " yyy:branceU: m_module = " << m_module << endl; - int p_module = p_axis->getTowerID()[0][0]; - //cout << " yyy:branceU: p_module = " << p_module << endl; - // Do not merge the two axis in two different modules - //if (m_module != p_module) continue; - - TVector3 t_pos = m_axis->getEnergyCenter(); - // cout << " yyy:branceU: t_pos = " << t_pos.x() << ", " << t_pos.y() << ", " << t_pos.z() << endl; - t_pos.RotateZ( TMath::TwoPi()/Cyber::CaloUnit::Nmodule*(int(Cyber::CaloUnit::Nmodule*3./4.)-m_module) ); - // cout << " yyy:branceU: t_pos after rotate to module 6 = " << t_pos.x() << ", " << t_pos.y() << ", " << t_pos.z() << endl; - double x0 = t_pos.x(); - double y0 = t_pos.z(); - double distance = TMath::Abs( x0*TMath::Cos(hough_alpha) + y0*TMath::Sin(hough_alpha) - hough_rho ); - - //cout << " yyy:U rho = " << hough_rho << ", alpha = " << hough_alpha << ", x0 = " << x0 << ", z0 = " << y0 << endl; - //cout << " distanceU = " << distance << endl; - - if (distance<settings.map_floatPars["th_branch_distance"]){ - m_axisCol[iax]->mergeHalfCluster( m_axisCol[jax] ); - int axis_type = m_axisCol[iax]->getType() + m_axisCol[jax]->getType(); - m_axisCol[iax]->setType(axis_type); - m_axisCol.erase(m_axisCol.begin()+jax); - //cout << " yyy: axis " << jax << " is merged into axis " << iax << endl; - jax--; - if(iax>jax+1) iax--; - } - - + std::cout<<"ERROR in AxisMergingAlg: Unknown system ID: "<<m_axis->getTowerID()[0][0]<<std::endl; } - + p_axis=nullptr; } m_axis=nullptr; @@ -805,10 +837,7 @@ StatusCode AxisMergingAlg::ConeMerging( std::vector<Cyber::CaloHalfCluster*>& m_ //cout<<" Merge! "<<endl; m_axisCol[iax]->mergeHalfCluster( m_axisCol[jax] ); - if(m_axisCol[iax]->getType()==1 || m_axisCol[jax]->getType()==1 || m_axisCol[iax]->getType()==5 || m_axisCol[jax]->getType()==5) m_axisCol[iax]->setType(5); - else if(m_axisCol[iax]->getType()==3 || m_axisCol[jax]->getType()==3 || m_axisCol[iax]->getType()==6 || m_axisCol[jax]->getType()==6) m_axisCol[iax]->setType(6); - else if(m_axisCol[iax]->getType()==4 || m_axisCol[jax]->getType()==4) m_axisCol[iax]->setType(4); - else m_axisCol[iax]->setType(7); + m_axisCol[iax]->setType( m_axisCol[iax]->getType() + m_axisCol[jax]->getType() ); //delete m_axisCol[jax]; m_axisCol[jax]=nullptr; m_axisCol.erase(m_axisCol.begin()+jax); @@ -852,11 +881,8 @@ StatusCode AxisMergingAlg::ConeMerging( std::vector<Cyber::CaloHalfCluster*>& m_ relDis <= settings.map_floatPars["relP_Dis"] && relDis>=0 ){ m_axisCol[iax]->mergeHalfCluster( m_axisCol[jax] ); - if(m_axisCol[iax]->getType()==1 || m_axisCol[jax]->getType()==1 || m_axisCol[iax]->getType()==5 || m_axisCol[jax]->getType()==5) m_axisCol[iax]->setType(5); - else if(m_axisCol[iax]->getType()==3 || m_axisCol[jax]->getType()==3 || m_axisCol[iax]->getType()==6 || m_axisCol[jax]->getType()==6) m_axisCol[iax]->setType(6); - else if(m_axisCol[iax]->getType()==4 || m_axisCol[jax]->getType()==4) m_axisCol[iax]->setType(4); - else m_axisCol[iax]->setType(7); - + m_axisCol[iax]->setType( m_axisCol[iax]->getType()+m_axisCol[jax]->getType() ); + //delete m_axisCol[jax]; m_axisCol[jax]=nullptr; m_axisCol.erase(m_axisCol.begin()+jax); jax--; diff --git a/Reconstruction/RecPFACyber/src/Algorithm/ConeClustering2DAlg.cpp b/Reconstruction/RecPFACyber/src/Algorithm/ConeClustering2DAlg.cpp index 05feb26dddbc66cf8deff076d3f19bd00f520bfc..38ea6252a1ed3d82071912c4054f3504c2a5da65 100644 --- a/Reconstruction/RecPFACyber/src/Algorithm/ConeClustering2DAlg.cpp +++ b/Reconstruction/RecPFACyber/src/Algorithm/ConeClustering2DAlg.cpp @@ -190,20 +190,38 @@ TVector2 ConeClustering2DAlg::GetProjectedAxis( const Cyber::CaloHalfCluster* m_ TVector2 ConeClustering2DAlg::GetProjectedRelR( const Cyber::Calo1DCluster* m_shower1, const Cyber::Calo1DCluster* m_shower2 ){ TVector2 paxis1, paxis2; - if(m_shower1->getSlayer()==1){ //For V-bars - paxis1.Set(m_shower1->getPos().x(), m_shower1->getPos().y()); - paxis2.Set(m_shower2->getPos().x(), m_shower2->getPos().y()); + if(m_shower1->getTowerID()[0][0]==Cyber::CaloUnit::System_Barrel){ + + if(m_shower1->getSlayer()==1){ //For V-bars + paxis1.Set(m_shower1->getPos().x(), m_shower1->getPos().y()); + paxis2.Set(m_shower2->getPos().x(), m_shower2->getPos().y()); + } + else{ + float rotAngle = -m_shower1->getTowerID()[0][1]*TMath::TwoPi()/Cyber::CaloUnit::Nmodule; + TVector3 raw_pos1 = m_shower1->getPos(); + TVector3 raw_pos2 = m_shower2->getPos(); + raw_pos1.RotateZ(rotAngle); raw_pos2.RotateZ(rotAngle); + paxis1.Set(raw_pos1.y(), raw_pos1.z()); + paxis2.Set(raw_pos2.y(), raw_pos2.z()); + + //paxis1.Set( sqrt(m_shower1->getPos().x()*m_shower1->getPos().x()+m_shower1->getPos().y()*m_shower1->getPos().y()), m_shower1->getPos().z()); + //paxis2.Set( sqrt(m_shower2->getPos().x()*m_shower2->getPos().x()+m_shower2->getPos().y()*m_shower2->getPos().y()), m_shower2->getPos().z()); + } + } + + else if(m_shower1->getTowerID()[0][0]==Cyber::CaloUnit::System_Endcap){ + if(m_shower1->getSlayer()==1){ + paxis1.Set(m_shower1->getPos().z(), m_shower1->getPos().y()); + paxis2.Set(m_shower2->getPos().z(), m_shower2->getPos().y()); + } + else{ + paxis1.Set(m_shower1->getPos().z(), m_shower1->getPos().x()); + paxis2.Set(m_shower2->getPos().z(), m_shower2->getPos().x()); + } } + else{ - float rotAngle = -m_shower1->getTowerID()[0][0]*TMath::TwoPi()/Cyber::CaloUnit::Nmodule; - TVector3 raw_pos1 = m_shower1->getPos(); - TVector3 raw_pos2 = m_shower2->getPos(); - raw_pos1.RotateZ(rotAngle); raw_pos2.RotateZ(rotAngle); - paxis1.Set(raw_pos1.y(), raw_pos1.z()); - paxis2.Set(raw_pos2.y(), raw_pos2.z()); - - //paxis1.Set( sqrt(m_shower1->getPos().x()*m_shower1->getPos().x()+m_shower1->getPos().y()*m_shower1->getPos().y()), m_shower1->getPos().z()); - //paxis2.Set( sqrt(m_shower2->getPos().x()*m_shower2->getPos().x()+m_shower2->getPos().y()*m_shower2->getPos().y()), m_shower2->getPos().z()); + std::cout<<"Error in ConeClustering2DAlg: Unknown system ID: "<<m_shower1->getTowerID()[0][0]<<std::endl; } return paxis2 - paxis1; diff --git a/Reconstruction/RecPFACyber/src/Algorithm/EnergySplittingAlg.cpp b/Reconstruction/RecPFACyber/src/Algorithm/EnergySplittingAlg.cpp index 3708f8e910652eaebce03bdc6481e85a240fc072..3aced5c8e4441c999656103723a359e1736c971a 100644 --- a/Reconstruction/RecPFACyber/src/Algorithm/EnergySplittingAlg.cpp +++ b/Reconstruction/RecPFACyber/src/Algorithm/EnergySplittingAlg.cpp @@ -85,7 +85,7 @@ for(int ih=0; ih<p_HalfClusterU.size(); ih++){ for(int icl=0; icl<tmp_axisUCol.size(); icl++){ cout<<" Axis #"<<icl<<": cluster En "<<tmp_axisUCol[icl]->getEnergy()<<", type "<<tmp_axisUCol[icl]->getType()<<endl; for(auto ish : tmp_axisUCol[icl]->getCluster()){ - printf(" Shower layer %d, Pos+E (%.3f, %.3f, %.3f, %.3f), Address %p \n", ish->getDlayer(), ish->getPos().x(), ish->getPos().y(), ish->getPos().z(), ish->getEnergy(), ish ); + printf(" Shower layer %d, Pos+E (%.3f, %.3f, %.3f, %.3f), Address \n", ish->getDlayer(), ish->getPos().x(), ish->getPos().y(), ish->getPos().z(), ish->getEnergy()); } } } @@ -96,7 +96,7 @@ for(int ih=0; ih<p_HalfClusterV.size(); ih++){ for(int icl=0; icl<tmp_axisVCol.size(); icl++){ cout<<" Axis #"<<icl<<": cluster En "<<tmp_axisVCol[icl]->getEnergy()<<", type "<<tmp_axisVCol[icl]->getType()<<endl; for(auto ish : tmp_axisVCol[icl]->getCluster()){ - printf(" Shower layer %d, Pos+E (%.3f, %.3f, %.3f, %.3f), Address %p \n", ish->getDlayer(), ish->getPos().x(), ish->getPos().y(), ish->getPos().z(), ish->getEnergy(), ish ); + printf(" Shower layer %d, Pos+E (%.3f, %.3f, %.3f, %.3f), Address \n", ish->getDlayer(), ish->getPos().x(), ish->getPos().y(), ish->getPos().z(), ish->getEnergy() ); } } } @@ -158,6 +158,16 @@ cout<<"Empty half cluster energy "<<tmp_totE_U<<", "<<tmp_totE_V<<endl; //for(int i1d=0; i1d<m_1dShowerUCol.size(); i1d++) tmp_En += m_1dShowerUCol[i1d]->getEnergy(); //cout<<" HalfClusterU #"<<ih<<": total En after energy splitting "<<tmp_En<<endl; +//cout<<" After energy splitting: 1D cluster size "<<m_1dShowerUCol.size()<<", print check"<<endl; +//for(int i1d=0; i1d<m_1dShowerUCol.size(); i1d++){ +// auto ish = m_1dShowerUCol[i1d]; +// printf(" Shower layer %d, Pos+E (%.3f, %.3f, %.3f, %.3f), Nbars %d, NSeed %d, MC map size %d \n", ish->getDlayer(), ish->getPos().x(), ish->getPos().y(), ish->getPos().z(), ish->getEnergy(), ish->getBars().size(), ish->getNseeds(), ish->getLinkedMCP().size() ); +// //printf(", cover tower size: %d: ", ish->getTowerID().size()); +// //for(int atw=0; atw<ish->getTowerID().size(); atw++) printf("[%d, %d, %d], ", ish->getTowerID()[atw][0], ish->getTowerID()[atw][1], ish->getTowerID()[atw][2] ); +// //cout<<endl; +//} +//cout<<endl; + //Clean showers without seed. for(int ic=0; ic<m_1dShowerUCol.size(); ic++){ if(m_1dShowerUCol[ic]->getNseeds()==0){ @@ -175,15 +185,36 @@ cout<<"Empty half cluster energy "<<tmp_totE_U<<", "<<tmp_totE_V<<endl; //tmp_En = 0.; //for(int i1d=0; i1d<m_1dShowerUCol.size(); i1d++) tmp_En += m_1dShowerUCol[i1d]->getEnergy(); //cout<<" HalfClusterU #"<<ih<<": total En after shower cleaning "<<tmp_En<<endl; +//cout<<" After shower cleaning: 1D cluster size "<<m_1dShowerUCol.size()<<", print check"<<endl; +//for(int i1d=0; i1d<m_1dShowerUCol.size(); i1d++){ +// auto ish = m_1dShowerUCol[i1d]; +// printf(" Shower layer %d, Pos+E (%.3f, %.3f, %.3f, %.3f), Nbars %d, NSeed %d, MC map size %d \n", ish->getDlayer(), ish->getPos().x(), ish->getPos().y(), ish->getPos().z(), ish->getEnergy(), ish->getBars().size(), ish->getNseeds(), ish->getLinkedMCP().size() ); +// //printf(", cover tower size: %d: ", ish->getTowerID().size()); +// //for(int atw=0; atw<ish->getTowerID().size(); atw++) printf("[%d, %d, %d], ", ish->getTowerID()[atw][0], ish->getTowerID()[atw][1], ish->getTowerID()[atw][2] ); +// //cout<<endl; +//} +//cout<<endl; // Longitudinal linking: update clusters' energy. std::vector<std::shared_ptr<Cyber::CaloHalfCluster>> tmp_newClus; tmp_newClus.clear(); LongitudinalLinking(m_1dShowerUCol, m_axisUCol, tmp_newClus); m_newClusUCol.insert(m_newClusUCol.end(), tmp_newClus.begin(), tmp_newClus.end()); -//double tmp_En = 0.; +//tmp_En = 0.; //for(int acl=0; acl<tmp_newClus.size(); acl++) tmp_En += tmp_newClus[acl]->getEnergy(); //cout<<" HalfClusterU #"<<ih<<": total En after LongiLinking "<<tmp_En<<endl; +//cout<<" After Longitudinally linking: HalfCluster U size "<<tmp_newClus.size()<<", print check"<<endl; +//for(int icl=0; icl<tmp_newClus.size(); icl++){ +// cout<<" In HFClusU #"<<icl<<": shower size = "<<tmp_newClus[icl]->getCluster().size()<<endl; +// for(auto ish : tmp_newClus[icl]->getCluster()){ +// printf(" Shower layer %d, Pos+E (%.3f, %.3f, %.3f, %.3f), Nbars %d, NSeed %d, MC map size %d \n", ish->getDlayer(), ish->getPos().x(), ish->getPos().y(), ish->getPos().z(), ish->getEnergy(), ish->getBars().size(), ish->getNseeds(), ish->getLinkedMCP().size() ); +// //printf(", cover tower size: %d: ", ish->getTowerID().size()); +// //for(int atw=0; atw<ish->getTowerID().size(); atw++) printf("[%d, %d, %d], ", ish->getTowerID()[atw][0], ish->getTowerID()[atw][1], ish->getTowerID()[atw][2] ); +// //cout<<endl; +// } +//} +//cout<<endl; + tmp_newClus.clear(); } @@ -301,8 +332,8 @@ for(int icl=0; icl<m_newClusVCol.size(); icl++){ //cout<<endl; } } - - +*/ +/* float totE_U = 0.; float totE_V = 0.; for(auto iter : m_newClusUCol) totE_U += iter->getEnergy(); @@ -311,30 +342,30 @@ printf(" Before split to tower: HalfCluster size: (%d, %d), energy (%.3f, %.3 cout<<" Loop print HalfClusterU: "<<endl; for(int icl=0; icl<m_newClusUCol.size(); icl++){ cout<<" In HFClusU #"<<icl<<": shower size = "<<m_newClusUCol[icl]->getCluster().size()<<", En = "<<m_newClusUCol[icl]->getEnergy()<<", type "<<m_newClusUCol[icl]->getType(); - printf(", Position (%.3f, %.3f, %.3f), address %p ",m_newClusUCol[icl]->getPos().x(), m_newClusUCol[icl]->getPos().y(), m_newClusUCol[icl]->getPos().z(), m_newClusUCol[icl]); + printf(", Position (%.3f, %.3f, %.3f), address ",m_newClusUCol[icl]->getPos().x(), m_newClusUCol[icl]->getPos().y(), m_newClusUCol[icl]->getPos().z()); printf(", cousin size %d, address: ", m_newClusUCol[icl]->getHalfClusterCol("CousinCluster").size()); - for(int ics=0; ics<m_newClusUCol[icl]->getHalfClusterCol("CousinCluster").size(); ics++) printf("%p, ", m_newClusUCol[icl]->getHalfClusterCol("CousinCluster")[ics]); + //for(int ics=0; ics<m_newClusUCol[icl]->getHalfClusterCol("CousinCluster").size(); ics++) printf("%p, ", m_newClusUCol[icl]->getHalfClusterCol("CousinCluster")[ics]); printf(", track size %d, address: ", m_newClusUCol[icl]->getAssociatedTracks().size()); - for(int itrk=0; itrk<m_newClusUCol[icl]->getAssociatedTracks().size(); itrk++) printf("%p, ", m_newClusUCol[icl]->getAssociatedTracks()[itrk]); + //for(int itrk=0; itrk<m_newClusUCol[icl]->getAssociatedTracks().size(); itrk++) printf("%p, ", m_newClusUCol[icl]->getAssociatedTracks()[itrk]); cout<<endl; - for(auto ish : m_newClusUCol[icl]->getCluster()){ - printf(" Shower layer %d, Pos+E (%.3f, %.3f, %.3f, %.3f), Nbars %d, NSeed %d, seedID [%d, %d, %d, %d], Address %p \n", ish->getDlayer(), ish->getPos().x(), ish->getPos().y(), ish->getPos().z(), ish->getEnergy(), ish->getBars().size(), ish->getNseeds(), ish->getSeeds()[0]->getModule(), ish->getSeeds()[0]->getPart(), ish->getSeeds()[0]->getStave(), ish->getSeeds()[0]->getBar(), ish ); - } + //for(auto ish : m_newClusUCol[icl]->getCluster()){ + // printf(" Shower layer %d, Pos+E (%.3f, %.3f, %.3f, %.3f), Nbars %d, NSeed %d, seedID [%d, %d, %d, %d], Address %p \n", ish->getDlayer(), ish->getPos().x(), ish->getPos().y(), ish->getPos().z(), ish->getEnergy(), ish->getBars().size(), ish->getNseeds(), ish->getSeeds()[0]->getModule(), ish->getSeeds()[0]->getPart(), ish->getSeeds()[0]->getStave(), ish->getSeeds()[0]->getBar(), ish ); + //} } cout<<endl; cout<<" Loop print HalfClusterV: "<<endl; for(int icl=0; icl<m_newClusVCol.size(); icl++){ cout<<" In HFClusV #"<<icl<<": shower size = "<<m_newClusVCol[icl]->getCluster().size()<<", En = "<<m_newClusVCol[icl]->getEnergy()<<", type "<<m_newClusVCol[icl]->getType(); - printf(", Position (%.3f, %.3f, %.3f), address %p ",m_newClusVCol[icl]->getPos().x(), m_newClusVCol[icl]->getPos().y(), m_newClusVCol[icl]->getPos().z(), m_newClusVCol[icl]); + printf(", Position (%.3f, %.3f, %.3f), address ",m_newClusVCol[icl]->getPos().x(), m_newClusVCol[icl]->getPos().y(), m_newClusVCol[icl]->getPos().z()); printf(", cousin size %d, address: ", m_newClusVCol[icl]->getHalfClusterCol("CousinCluster").size()); - for(int ics=0; ics<m_newClusVCol[icl]->getHalfClusterCol("CousinCluster").size(); ics++) printf("%p, ", m_newClusVCol[icl]->getHalfClusterCol("CousinCluster")[ics]); + //for(int ics=0; ics<m_newClusVCol[icl]->getHalfClusterCol("CousinCluster").size(); ics++) printf("%p, ", m_newClusVCol[icl]->getHalfClusterCol("CousinCluster")[ics]); printf(", track size %d, address: ", m_newClusVCol[icl]->getAssociatedTracks().size()); - for(int itrk=0; itrk<m_newClusVCol[icl]->getAssociatedTracks().size(); itrk++) printf("%p, ", m_newClusVCol[icl]->getAssociatedTracks()[itrk]); + //for(int itrk=0; itrk<m_newClusVCol[icl]->getAssociatedTracks().size(); itrk++) printf("%p, ", m_newClusVCol[icl]->getAssociatedTracks()[itrk]); cout<<endl; - for(auto ish : m_newClusVCol[icl]->getCluster()){ - printf(" Shower layer %d, Pos+E (%.3f, %.3f, %.3f, %.3f), Nbars %d, NSeed %d, seedID [%d, %d, %d, %d], Address %p \n", ish->getDlayer(), ish->getPos().x(), ish->getPos().y(), ish->getPos().z(), ish->getEnergy(), ish->getBars().size(), ish->getNseeds(), ish->getSeeds()[0]->getModule(), ish->getSeeds()[0]->getPart(), ish->getSeeds()[0]->getStave(), ish->getSeeds()[0]->getBar(), ish ); - } + //for(auto ish : m_newClusVCol[icl]->getCluster()){ + // printf(" Shower layer %d, Pos+E (%.3f, %.3f, %.3f, %.3f), Nbars %d, NSeed %d, seedID [%d, %d, %d, %d], Address %p \n", ish->getDlayer(), ish->getPos().x(), ish->getPos().y(), ish->getPos().z(), ish->getEnergy(), ish->getBars().size(), ish->getNseeds(), ish->getSeeds()[0]->getModule(), ish->getSeeds()[0]->getPart(), ish->getSeeds()[0]->getStave(), ish->getSeeds()[0]->getBar(), ish ); + //} } cout<<endl; */ @@ -392,7 +423,7 @@ StatusCode EnergySplittingAlg::LongitudinalLinking( std::vector<std::shared_ptr< //cout<<" In LongitudinalLinking: input 1DShower total energy : "<<tmp_totE<<". old axis size "<<m_oldClusCol.size()<<endl; //cout<<" Print all 1DShower (address)"<<endl; //for(int i=0; i<m_showers.size(); i++){ -// printf(" Shower #%d, pos+E [%.3f, %.3f, %.3f, %.3f], address %p \n", i, m_showers[i]->getPos().x(), m_showers[i]->getPos().y(), m_showers[i]->getPos().z(), m_showers[i]->getEnergy(), m_showers[i] ); +// printf(" Shower #%d, pos+E [%.3f, %.3f, %.3f, %.3f], Nbars %d, address \n", i, m_showers[i]->getPos().x(), m_showers[i]->getPos().y(), m_showers[i]->getPos().z(), m_showers[i]->getBars().size(), m_showers[i]->getEnergy() ); //} //Update old Hough clusters @@ -414,7 +445,7 @@ StatusCode EnergySplittingAlg::LongitudinalLinking( std::vector<std::shared_ptr< if( fl_inTower && m_showers[js].get()->getDlayer() == m_shower->getDlayer() && m_showers[js].get()->getSeeds().size()==1 && - (m_showers[js].get()->getSeeds()[0]->getPosition()-m_shower->getPos()).Mag()<10 ) + (m_showers[js].get()->getSeeds()[0]->getPosition()-m_shower->getPos()).Mag()<Cyber::CaloUnit::barsize ) {m_selshower = m_showers[js].get(); fl_foundshower=true; break; } } if(fl_foundshower && m_selshower!=NULL) m_newClus->addUnit( m_selshower ); @@ -432,15 +463,15 @@ StatusCode EnergySplittingAlg::LongitudinalLinking( std::vector<std::shared_ptr< //tmp_totE = 0.; //for(int i=0; i<m_newClusCol.size(); i++) tmp_totE += m_newClusCol[i]->getEnergy(); //cout<<" In Longi-Linking: raw new HFCluster size : "<<m_newClusCol.size()<<", totE "<<tmp_totE<<endl; -/* -cout<<" Print 1DShower in new HFCluster"<<endl; -for(int ih=0; ih<m_newClusCol.size(); ih++){ - cout<<" In new HFCluster #"<<ih<<endl; - for(int i=0; i<m_newClusCol[ih]->getCluster().size(); i++){ - printf(" Shower #%d, pos+E [%.3f, %.3f, %.3f, %.3f], address %p \n", i, m_newClusCol[ih]->getCluster()[i]->getPos().x(), m_newClusCol[ih]->getCluster()[i]->getPos().y(), m_newClusCol[ih]->getCluster()[i]->getPos().z(), m_newClusCol[ih]->getCluster()[i]->getEnergy(), m_newClusCol[ih]->getCluster()[i] ); - } -} -*/ + +//cout<<" Print 1DShower in new HFCluster"<<endl; +//for(int ih=0; ih<m_newClusCol.size(); ih++){ +// cout<<" In new HFCluster #"<<ih<<endl; +// for(int i=0; i<m_newClusCol[ih]->getCluster().size(); i++){ +// printf(" Shower #%d, pos+E [%.3f, %.3f, %.3f, %.3f], address \n", i, m_newClusCol[ih]->getCluster()[i]->getPos().x(), m_newClusCol[ih]->getCluster()[i]->getPos().y(), m_newClusCol[ih]->getCluster()[i]->getPos().z(), m_newClusCol[ih]->getCluster()[i]->getEnergy() ); +// } +//} + std::vector<const Cyber::Calo1DCluster*> m_leftshowers; m_leftshowers.clear(); for(int ish=0; ish<m_showers.size(); ish++){ @@ -480,15 +511,15 @@ for(int ih=0; ih<m_newClusCol.size(); ih++){ for(int icl=0; icl<m_newClusCol.size(); icl++) m_newClusCol[icl].get()->mergeClusterInLayer(); } -/* -cout<<" Print 1DShower in new HFCluster"<<endl; -for(int ih=0; ih<m_newClusCol.size(); ih++){ - cout<<" In new HFCluster #"<<ih<<endl; - for(int i=0; i<m_newClusCol[ih]->getCluster().size(); i++){ - printf(" Shower #%d, pos+E [%.3f, %.3f, %.3f, %.3f], address %p \n", i, m_newClusCol[ih]->getCluster()[i]->getPos().x(), m_newClusCol[ih]->getCluster()[i]->getPos().y(), m_newClusCol[ih]->getCluster()[i]->getPos().z(), m_newClusCol[ih]->getCluster()[i]->getEnergy(), m_newClusCol[ih]->getCluster()[i] ); - } -} -*/ + +//cout<<" Print 1DShower in new HFCluster"<<endl; +//for(int ih=0; ih<m_newClusCol.size(); ih++){ +// cout<<" In new HFCluster #"<<ih<<endl; +// for(int i=0; i<m_newClusCol[ih]->getCluster().size(); i++){ +// printf(" Shower #%d, pos+E [%.3f, %.3f, %.3f, %.3f], address \n", i, m_newClusCol[ih]->getCluster()[i]->getPos().x(), m_newClusCol[ih]->getCluster()[i]->getPos().y(), m_newClusCol[ih]->getCluster()[i]->getPos().z(), m_newClusCol[ih]->getCluster()[i]->getEnergy() ); +// } +//} + return StatusCode::SUCCESS; } @@ -541,9 +572,11 @@ StatusCode EnergySplittingAlg::HalfClusterToTowers( std::vector<Cyber::CaloHalfC std::map<std::vector<int>, Cyber::Calo1DCluster* > tmp_1DClusMaps; tmp_1DClusMaps.clear(); for(int ib=0; ib<p_shower->getBars().size(); ib++){ - std::vector<int> towerID(2); - towerID[0] = p_shower->getBars()[ib]->getModule(); - towerID[1] = p_shower->getBars()[ib]->getStave(); + std::vector<int> towerID(4); + towerID[0] = p_shower->getBars()[ib]->getSystem(); + towerID[1] = p_shower->getBars()[ib]->getModule(); + towerID[2] = p_shower->getBars()[ib]->getStave(); + towerID[3] = p_shower->getBars()[ib]->getPart(); if(tmp_1DClusMaps.find(towerID)!=tmp_1DClusMaps.end()){ tmp_1DClusMaps[towerID]->addUnit(p_shower->getBars()[ib]); @@ -640,9 +673,11 @@ StatusCode EnergySplittingAlg::HalfClusterToTowers( std::vector<Cyber::CaloHalfC std::map<std::vector<int>, Cyber::Calo1DCluster* > tmp_1DClusMaps; tmp_1DClusMaps.clear(); for(int ib=0; ib<p_shower->getBars().size(); ib++){ - std::vector<int> towerID(2); - towerID[0] = p_shower->getBars()[ib]->getModule(); - towerID[1] = p_shower->getBars()[ib]->getStave(); + std::vector<int> towerID(4); + towerID[0] = p_shower->getBars()[ib]->getSystem(); + towerID[1] = p_shower->getBars()[ib]->getModule(); + towerID[2] = p_shower->getBars()[ib]->getStave(); + towerID[3] = p_shower->getBars()[ib]->getPart(); if(tmp_1DClusMaps.find(towerID)!=tmp_1DClusMaps.end()){ tmp_1DClusMaps[towerID]->addUnit(p_shower->getBars()[ib]); @@ -876,14 +911,14 @@ cout<<endl; cout<<" Loop print HalfClusterU: "<<endl; for(int icl=0; icl<m_HFClusUInTower.size(); icl++){ cout<<" In HFClusU #"<<icl<<": shower size = "<<m_HFClusUInTower[icl]->getCluster().size()<<", En = "<<m_HFClusUInTower[icl]->getEnergy()<<", type "<<m_HFClusUInTower[icl]->getType(); - printf(", Position (%.3f, %.3f, %.3f), address %p ",m_HFClusUInTower[icl]->getPos().x(), m_HFClusUInTower[icl]->getPos().y(), m_HFClusUInTower[icl]->getPos().z(), m_HFClusUInTower[icl]); + printf(", Position (%.3f, %.3f, %.3f), ",m_HFClusUInTower[icl]->getPos().x(), m_HFClusUInTower[icl]->getPos().y(), m_HFClusUInTower[icl]->getPos().z()); printf(", cousin size %d, address: ", m_HFClusUInTower[icl]->getHalfClusterCol("CousinCluster").size()); - for(int ics=0; ics<m_HFClusUInTower[icl]->getHalfClusterCol("CousinCluster").size(); ics++) printf("%p, ", m_HFClusUInTower[icl]->getHalfClusterCol("CousinCluster")[ics]); + //for(int ics=0; ics<m_HFClusUInTower[icl]->getHalfClusterCol("CousinCluster").size(); ics++) printf("%p, ", m_HFClusUInTower[icl]->getHalfClusterCol("CousinCluster")[ics]); printf(", track size %d, address: ", m_HFClusUInTower[icl]->getAssociatedTracks().size()); - for(int itrk=0; itrk<m_HFClusUInTower[icl]->getAssociatedTracks().size(); itrk++) printf("%p, ", m_HFClusUInTower[icl]->getAssociatedTracks()[itrk]); + //for(int itrk=0; itrk<m_HFClusUInTower[icl]->getAssociatedTracks().size(); itrk++) printf("%p, ", m_HFClusUInTower[icl]->getAssociatedTracks()[itrk]); cout<<endl; for(auto ish : m_HFClusUInTower[icl]->getCluster()){ - printf(" Shower layer %d, Pos+E (%.3f, %.3f, %.3f, %.3f), Nbars %d, NSeed %d, Address %p \n", ish->getDlayer(), ish->getPos().x(), ish->getPos().y(), ish->getPos().z(), ish->getEnergy(), ish->getBars().size(), ish->getNseeds(), ish ); + printf(" Shower layer %d, Pos+E (%.3f, %.3f, %.3f, %.3f), Nbars %d, NSeed %d \n", ish->getDlayer(), ish->getPos().x(), ish->getPos().y(), ish->getPos().z(), ish->getEnergy(), ish->getBars().size(), ish->getNseeds() ); } } cout<<endl; @@ -891,14 +926,14 @@ cout<<endl; cout<<" Loop print HalfClusterV: "<<endl; for(int icl=0; icl<m_HFClusVInTower.size(); icl++){ cout<<" In HFClusV #"<<icl<<": shower size = "<<m_HFClusVInTower[icl]->getCluster().size()<<", En = "<<m_HFClusVInTower[icl]->getEnergy()<<", type "<<m_HFClusVInTower[icl]->getType(); - printf(", Position (%.3f, %.3f, %.3f), address %p ",m_HFClusVInTower[icl]->getPos().x(), m_HFClusVInTower[icl]->getPos().y(), m_HFClusVInTower[icl]->getPos().z(), m_HFClusVInTower[icl]); + printf(", Position (%.3f, %.3f, %.3f), ",m_HFClusVInTower[icl]->getPos().x(), m_HFClusVInTower[icl]->getPos().y(), m_HFClusVInTower[icl]->getPos().z()); printf(", cousin size %d, address: ", m_HFClusVInTower[icl]->getHalfClusterCol("CousinCluster").size()); - for(int ics=0; ics<m_HFClusVInTower[icl]->getHalfClusterCol("CousinCluster").size(); ics++) printf("%p, ", m_HFClusVInTower[icl]->getHalfClusterCol("CousinCluster")[ics]); + //for(int ics=0; ics<m_HFClusVInTower[icl]->getHalfClusterCol("CousinCluster").size(); ics++) printf("%p, ", m_HFClusVInTower[icl]->getHalfClusterCol("CousinCluster")[ics]); printf(", track size %d, address: ", m_HFClusVInTower[icl]->getAssociatedTracks().size()); - for(int itrk=0; itrk<m_HFClusVInTower[icl]->getAssociatedTracks().size(); itrk++) printf("%p, ", m_HFClusVInTower[icl]->getAssociatedTracks()[itrk]); + //for(int itrk=0; itrk<m_HFClusVInTower[icl]->getAssociatedTracks().size(); itrk++) printf("%p, ", m_HFClusVInTower[icl]->getAssociatedTracks()[itrk]); cout<<endl; for(auto ish : m_HFClusVInTower[icl]->getCluster()){ - printf(" Shower layer %d, Pos+E (%.3f, %.3f, %.3f, %.3f), Nbars %d, NSeed %d, Address %p \n", ish->getDlayer(), ish->getPos().x(), ish->getPos().y(), ish->getPos().z(), ish->getEnergy(), ish->getBars().size(), ish->getNseeds(), ish ); + printf(" Shower layer %d, Pos+E (%.3f, %.3f, %.3f, %.3f), Nbars %d, NSeed %d \n", ish->getDlayer(), ish->getPos().x(), ish->getPos().y(), ish->getPos().z(), ish->getEnergy(), ish->getBars().size(), ish->getNseeds() ); } } cout<<endl; @@ -1017,7 +1052,10 @@ StatusCode EnergySplittingAlg::ClusterSplitting(const Cyber::Calo1DCluster* m_cl double Eexp[Nshower]; double Eexp_tot=0; for(int is=0;is<Nshower;is++){ Eexp[is] = Eseed[is]*GetShowerProfile(m_cluster->getBars()[ibar]->getPosition(), SeedPos[is] ); Eexp_tot+= Eexp[is];} - for(int is=0;is<Nshower;is++) weight[ibar][is] = Eexp[is]/Eexp_tot; + for(int is=0;is<Nshower;is++){ + weight[ibar][is] = Eexp[is]/Eexp_tot; + if(weight[ibar][is]<1e-5) weight[ibar][is] = 0.; + } } @@ -1040,10 +1078,11 @@ StatusCode EnergySplittingAlg::ClusterSplitting(const Cyber::Calo1DCluster* m_cl double _Emax = -99; for(int ib=0;ib<Nbars;ib++){ - double barEn = (m_cluster->getBars()[ib]->getQ1()*weight[ib][is] + m_cluster->getBars()[ib]->getQ2()*weight[ib][is])/2.; + double barEn = m_cluster->getBars()[ib]->getEnergy() * weight[ib][is]; //cout<<" bar#"<<ib<<" barID "<<m_cluster->getBars()[ib]->getBar()<<" En: "<<barEn<<endl; - if(barEn<settings.map_floatPars["Eth_unit"]) continue; - + if(barEn<settings.map_floatPars["Eth_unit"]){ + continue; + } auto bar = m_cluster->getBars()[ib]->Clone(); bar->setQ( bar->getQ1()*weight[ib][is], bar->getQ2()*weight[ib][is] ); if( bar->getEnergy()>_Emax ) { _Emax=bar->getEnergy(); iseed=icount; } @@ -1052,7 +1091,7 @@ StatusCode EnergySplittingAlg::ClusterSplitting(const Cyber::Calo1DCluster* m_cl m_bkCol.map_BarCol["bkBar"].push_back( bar ); //cout<<" Found seed: iseed="<<iseed<<", icount="<<icount<<endl; } - if(iseed<0) { std::cout<<"ERROR: Can not find seed(max energy bar) in this shower! Nbars = "<<Nbars<<". Please Check!"<<std::endl; continue; } + if(iseed<0) { std::cout<<"ERROR: Can not find seed(max energy bar) in this shower! Nbars = "<<Nbars<<", icount "<<icount<<", maxEn "<<_Emax<<". Please Check!"<<std::endl; continue; } //if( (Bars[iseed]->getPosition()-SeedPos[is]).Mag()>15 ) { std::cout<<"ERROR: MaxEnergy bar is too far with original seed! Please Check! iSeed = "<<iseed<<std::endl; } std::shared_ptr<Cyber::Calo1DCluster> shower = std::make_shared<Cyber::Calo1DCluster>(); @@ -1060,7 +1099,6 @@ StatusCode EnergySplittingAlg::ClusterSplitting(const Cyber::Calo1DCluster* m_cl shower->addSeed(Bars[iseed]); shower->setIDInfo(); - outshCol.push_back(shower); } @@ -1168,7 +1206,7 @@ StatusCode EnergySplittingAlg::MergeToClosestCluster( Cyber::Calo1DCluster* iclu int cLedge = iclus->getLeftEdge(); int cRedge = iclus->getRightEdge(); -//printf("ClusterMerging: input cluster layer %d, energy %.4f, edge [%d, %d]\n", iclus->getDlayer(), iclus->getEnergy(), cLedge, cRedge); +//printf("ClusterMerging: input cluster system %d, layer %d, energy %.4f, Nbars %d, edge [%d, %d]\n",iclus->getSystem(), iclus->getDlayer(), iclus->getEnergy(), iclus->getBars().size(), cLedge, cRedge); //Find the closest cluster with iclus. int minD = 99; @@ -1184,11 +1222,11 @@ StatusCode EnergySplittingAlg::MergeToClosestCluster( Cyber::Calo1DCluster* iclu //int dis = (cLedge-iRedge>0 ? cLedge-iRedge : iLedge-cRedge ); int dis = min( abs(cLedge-iRedge), abs(iLedge-cRedge) ); -//printf(" Loop in clusterCol #%d: range [%d, %d], distance %d, energy ratio %.3f \n", icl, iLedge, iRedge, dis, iclus->getEnergy()/clusvec[icl]->getEnergy()); +//printf(" Loop in clusterCol #%d: Nbars %d, range [%d, %d], distance %d, energy ratio %.3f \n", icl, clusvec[icl].get()->getBars().size(), iLedge, iRedge, dis, iclus->getEnergy()/clusvec[icl]->getEnergy()); if(dis>10) continue; //Don't merge to a too far cluster. if(dis<minD){ minD = dis; index=icl; } } -//cout<<"Selected closest cluster #"<<index<<endl; +//cout<<"Selected closest cluster #"<<index<<", minD "<<minD<<endl; if(index<0) return StatusCode::FAILURE; diff --git a/Reconstruction/RecPFACyber/src/Algorithm/EnergyTimeMatchingAlg.cpp b/Reconstruction/RecPFACyber/src/Algorithm/EnergyTimeMatchingAlg.cpp index f08cb99f5418b67adf3c1f67e00ae90a678b6f5d..0746be2331184baff3b498e2b577e252be861e81 100644 --- a/Reconstruction/RecPFACyber/src/Algorithm/EnergyTimeMatchingAlg.cpp +++ b/Reconstruction/RecPFACyber/src/Algorithm/EnergyTimeMatchingAlg.cpp @@ -673,18 +673,24 @@ vector<vector<double>> EnergyTimeMatchingAlg::GetClusterChi2Map( std::vector<std double wi_E = settings.map_floatPars["chi2Wi_E"]/(settings.map_floatPars["chi2Wi_E"] + settings.map_floatPars["chi2Wi_T"]); double wi_T = settings.map_floatPars["chi2Wi_T"]/(settings.map_floatPars["chi2Wi_E"] + settings.map_floatPars["chi2Wi_T"]); + //Rotate angle and tower center position for ECAL Barrel TVector3 m_vec(0,0,0); double rotAngle = -999; TVector3 Ctower(0,0,0); + int system = -1; for(int ish=0; ish<barShowerUCol.size(); ish++){ if(barShowerUCol[ish].size()==0) continue; rotAngle = -(barShowerUCol[ish][0]->getBars())[0]->getModule()*TMath::TwoPi()/Cyber::CaloUnit::Nmodule; Ctower.SetX( (barShowerUCol[ish][0]->getBars())[0]->getPosition().x() ); Ctower.SetY( (barShowerUCol[ish][0]->getBars())[0]->getPosition().y() ); + system = (barShowerUCol[ish][0]->getBars())[0]->getSystem(); + break; } for(int ish=0; ish<barShowerVCol.size(); ish++){ if(barShowerVCol[ish].size()==0) continue; Ctower.SetZ( (barShowerVCol[ish][0]->getBars())[0]->getPosition().z() ); + system = (barShowerVCol[ish][0]->getBars())[0]->getSystem(); + break; } Ctower.RotateZ(rotAngle); @@ -718,13 +724,27 @@ vector<vector<double>> EnergyTimeMatchingAlg::GetClusterChi2Map( std::vector<std double Ex = showerX->getEnergy(); double Ey = showerY->getEnergy(); double chi2_E = pow(fabs(Ex-Ey)/settings.map_floatPars["sigmaE"], 2); - double PosTx = C*(showerY->getT1()-showerY->getT2())/(2*settings.map_floatPars["nMat"]) + showerY->getPos().z(); - double chi2_tx = pow( fabs(PosTx-showerX->getPos().z())/settings.map_floatPars["sigmaPos"], 2 ); - double PosTy = C*(showerX->getT1()-showerX->getT2())/(2*settings.map_floatPars["nMat"]); - m_vec = showerY->getPos(); - m_vec.RotateZ(rotAngle); - double chi2_ty = pow( fabs(PosTy - (m_vec-Ctower).x() )/settings.map_floatPars["sigmaPos"], 2); + double PosTx, chi2_tx, PosTy, chi2_ty; + if(system == Cyber::CaloUnit::System_Barrel){ + PosTx = C*(showerY->getT1()-showerY->getT2())/(2*settings.map_floatPars["nMat"]) + showerY->getPos().z(); + chi2_tx = pow( fabs(PosTx-showerX->getPos().z())/settings.map_floatPars["sigmaPos"], 2 ); + + PosTy = C*(showerX->getT1()-showerX->getT2())/(2*settings.map_floatPars["nMat"]); + m_vec = showerY->getPos(); + m_vec.RotateZ(rotAngle); + chi2_ty = pow( fabs(PosTy - (m_vec-Ctower).x() )/settings.map_floatPars["sigmaPos"], 2); + } + else if(system == Cyber::CaloUnit::System_Endcap){ + PosTx = C*(showerY->getT1()-showerY->getT2())/(2*settings.map_floatPars["nMat"]) + showerY->getPos().x(); + chi2_tx = pow( fabs(PosTx-showerX->getPos().x())/settings.map_floatPars["sigmaPos"], 2 ); + + PosTy = C*(showerX->getT1()-showerX->getT2())/(2*settings.map_floatPars["nMat"]) + showerX->getPos().y(); + chi2_ty = pow( fabs(PosTy - showerY->getPos().y() )/settings.map_floatPars["sigmaPos"], 2); + } + else{ + std::cout<<"ERROR in EnergyTimeMatchingAlg: Unknown system ID: "<<system<<endl; + } if(chi2_E<min_chi2E) min_chi2E=chi2_E; if(chi2_tx<min_chi2tx) min_chi2tx=chi2_tx; @@ -1071,31 +1091,57 @@ StatusCode EnergyTimeMatchingAlg::GetMatchedShowersL0( const Cyber::Calo1DCluste //if(barShowerU->getTowerID().size()==0) { barShowerU->setIDInfo(); } int _layer = barShowerU->getDlayer(); - int _module = barShowerU->getTowerID()[0][0]; - float rotAngle = -_module*TMath::TwoPi()/Cyber::CaloUnit::Nmodule; - - for(int ibar=0;ibar<NbarsX;ibar++){ - double En_x = barShowerU->getBars()[ibar]->getEnergy(); - TVector3 m_vecx = barShowerU->getBars()[ibar]->getPosition(); - m_vecx.RotateZ(rotAngle); - - for(int jbar=0;jbar<NbarsY;jbar++){ - double En_y = barShowerV->getBars()[jbar]->getEnergy(); - TVector3 m_vecy = barShowerV->getBars()[jbar]->getPosition(); - m_vecy.RotateZ(rotAngle); - - TVector3 p_hit(m_vecy.x(), (m_vecx.y()+m_vecy.y())/2., m_vecx.z() ); - p_hit.RotateZ(-rotAngle); - double m_Ehit = En_x*En_y/barShowerV->getEnergy() + En_x*En_y/barShowerU->getEnergy(); - //Create new CaloHit - std::shared_ptr<Cyber::CaloHit> hit = std::make_shared<Cyber::CaloHit>(); - hit->setcellID(_module, _layer); - hit->setPosition(p_hit); - hit->setEnergy(m_Ehit); - m_digiCol.push_back(hit.get()); - m_bkCol.map_CaloHit["bkHit"].push_back( hit ); + int _module = barShowerU->getTowerID()[0][1]; + int _system = barShowerU->getTowerID()[0][0]; + if(_system == Cyber::CaloUnit::System_Barrel){ + float rotAngle = -_module*TMath::TwoPi()/Cyber::CaloUnit::Nmodule; + + for(int ibar=0;ibar<NbarsX;ibar++){ + double En_x = barShowerU->getBars()[ibar]->getEnergy(); + TVector3 m_vecx = barShowerU->getBars()[ibar]->getPosition(); + m_vecx.RotateZ(rotAngle); + + for(int jbar=0;jbar<NbarsY;jbar++){ + double En_y = barShowerV->getBars()[jbar]->getEnergy(); + TVector3 m_vecy = barShowerV->getBars()[jbar]->getPosition(); + m_vecy.RotateZ(rotAngle); + + TVector3 p_hit(m_vecy.x(), (m_vecx.y()+m_vecy.y())/2., m_vecx.z() ); + p_hit.RotateZ(-rotAngle); + double m_Ehit = En_x*En_y/barShowerV->getEnergy() + En_x*En_y/barShowerU->getEnergy(); + //Create new CaloHit + std::shared_ptr<Cyber::CaloHit> hit = std::make_shared<Cyber::CaloHit>(); + hit->setcellID(_system, _module, _layer); + hit->setPosition(p_hit); + hit->setEnergy(m_Ehit); + m_digiCol.push_back(hit.get()); + m_bkCol.map_CaloHit["bkHit"].push_back( hit ); + } } } + else{ + + for(int ibar=0;ibar<NbarsX;ibar++){ + double En_x = barShowerU->getBars()[ibar]->getEnergy(); + TVector3 m_vecx = barShowerU->getBars()[ibar]->getPosition(); + + for(int jbar=0;jbar<NbarsY;jbar++){ + double En_y = barShowerV->getBars()[jbar]->getEnergy(); + TVector3 m_vecy = barShowerV->getBars()[jbar]->getPosition(); + + TVector3 p_hit(m_vecx.x(), m_vecy.y(), (m_vecx.z()+m_vecy.z())/2. ); + double m_Ehit = En_x*En_y/barShowerV->getEnergy() + En_x*En_y/barShowerU->getEnergy(); + //Create new CaloHit + std::shared_ptr<Cyber::CaloHit> hit = std::make_shared<Cyber::CaloHit>(); + hit->setcellID(_system, _module, _layer); + hit->setPosition(p_hit); + hit->setEnergy(m_Ehit); + m_digiCol.push_back(hit.get()); + m_bkCol.map_CaloHit["bkHit"].push_back( hit ); + } + } + + } outsh->addUnit( barShowerU ); outsh->addUnit( barShowerV ); diff --git a/Reconstruction/RecPFACyber/src/Algorithm/GlobalClusteringAlg.cpp b/Reconstruction/RecPFACyber/src/Algorithm/GlobalClusteringAlg.cpp index 47086387910564ded6176ec616e19cfc65e56c5b..2eab8d9903cccebfd471d2aba728b8d126a0e308 100644 --- a/Reconstruction/RecPFACyber/src/Algorithm/GlobalClusteringAlg.cpp +++ b/Reconstruction/RecPFACyber/src/Algorithm/GlobalClusteringAlg.cpp @@ -34,17 +34,22 @@ StatusCode GlobalClusteringAlg::RunAlgorithm( CyberDataCol& m_datacol ){ //cout<<" When begin clustering: "<<ctime(&time_cb)<<endl; //Threshold and scale factor (Todo) for bars. +//double totE = 0.; +//double totE_rest = 0.; for(int ibar=0; ibar<m_bars.size(); ibar++) { if(m_bars.at(ibar)->getEnergy()>settings.map_floatPars["unit_threshold"]) { m_processbars.push_back(m_bars.at(ibar)); + //totE += m_bars.at(ibar)->getEnergy(); } else { m_restbars.push_back(m_bars.at(ibar)); + //totE_rest += m_bars.at(ibar)->getEnergy(); } } +//cout<<"Input bar after threshold: "<<m_processbars.size()<<", totE "<<totE<<", rest E "<<totE_rest<<endl; //Clustering Clustering(m_processbars, m_1dclusters); @@ -54,7 +59,6 @@ StatusCode GlobalClusteringAlg::RunAlgorithm( CyberDataCol& m_datacol ){ m_datacol.map_1DCluster["bk1DCluster"].insert(m_datacol.map_1DCluster["bk1DCluster"].end(), m_1dclusters.begin(), m_1dclusters.end()); m_datacol.map_HalfCluster["bkHalfCluster"].insert(m_datacol.map_HalfCluster["bkHalfCluster"].end(), m_halfclusters.begin(), m_halfclusters.end()); - std::vector<std::shared_ptr<Cyber::CaloHalfCluster>> m_HalfClusterV; m_HalfClusterV.clear(); std::vector<std::shared_ptr<Cyber::CaloHalfCluster>> m_HalfClusterU; m_HalfClusterU.clear(); for(int i=0; i<m_halfclusters.size() && m_halfclusters[i]; i++){ @@ -65,11 +69,11 @@ StatusCode GlobalClusteringAlg::RunAlgorithm( CyberDataCol& m_datacol ){ m_HalfClusterV.push_back(m_halfclusters[i]); } -//printf(" GlobalClustering: RestBarCol size %d, 1DCluster size %d, HalfCluster size (%d, %d) \n", m_restbars.size(), m_1dclusters.size(), m_HalfClusterU.size(), m_HalfClusterV.size()); -//for(int ic=0; ic<m_HalfClusterU.size(); ic++) cout<<m_HalfClusterU[ic]->getEnergy()<<'\t'; -//cout<<endl; -//for(int ic=0; ic<m_HalfClusterV.size(); ic++) cout<<m_HalfClusterV[ic]->getEnergy()<<'\t'; -//cout<<endl; + //printf(" GlobalClustering: RestBarCol size %d, 1DCluster size %d, HalfCluster size (%d, %d) \n", m_restbars.size(), m_1dclusters.size(), m_HalfClusterU.size(), m_HalfClusterV.size()); + //for(int ic=0; ic<m_HalfClusterU.size(); ic++) cout<<m_HalfClusterU[ic]->getEnergy()<<'\t'; + //cout<<endl; + //for(int ic=0; ic<m_HalfClusterV.size(); ic++) cout<<m_HalfClusterV[ic]->getEnergy()<<'\t'; + //cout<<endl; //Write results into DataCol. diff --git a/Reconstruction/RecPFACyber/src/Algorithm/HcalClusteringAlg.cpp b/Reconstruction/RecPFACyber/src/Algorithm/HcalClusteringAlg.cpp index a7a97680828c12d34397cced5e8d63b6a1009b83..6bb6341851b33e377ce5c9ef1fd4da06e0f3e080 100644 --- a/Reconstruction/RecPFACyber/src/Algorithm/HcalClusteringAlg.cpp +++ b/Reconstruction/RecPFACyber/src/Algorithm/HcalClusteringAlg.cpp @@ -7,7 +7,7 @@ using namespace Cyber; StatusCode HcalClusteringAlg::ReadSettings(Cyber::Settings& m_settings){ settings = m_settings; - if(settings.map_stringPars.find("InputHCALHits")==settings.map_stringPars.end()) settings.map_stringPars["InputHCALHits"] = "HCALBarrel"; + if(settings.map_stringVecPars.find("InputHCALHits")==settings.map_stringVecPars.end()) settings.map_stringVecPars["InputHCALHits"] = {"HCALBarrel", "HCALEndcaps"}; if(settings.map_stringPars.find("OutputHCALClusters")==settings.map_stringPars.end()) settings.map_stringPars["OutputHCALClusters"] = "HCALCluster"; //Set initial values @@ -39,8 +39,10 @@ StatusCode HcalClusteringAlg::RunAlgorithm( CyberDataCol& m_datacol ){ std::vector<Cyber::CaloHit*> m_hcalHits; m_hcalHits.clear(); - for(int ih=0; ih<m_datacol.map_CaloHit[settings.map_stringPars["InputHCALHits"]].size(); ih++) - m_hcalHits.push_back( m_datacol.map_CaloHit[settings.map_stringPars["InputHCALHits"]][ih].get() ); + for(int icl=0; icl<settings.map_stringVecPars["InputHCALHits"].size(); icl++){ + for(int ih=0; ih<m_datacol.map_CaloHit[settings.map_stringVecPars["InputHCALHits"][icl]].size(); ih++) + m_hcalHits.push_back( m_datacol.map_CaloHit[settings.map_stringVecPars["InputHCALHits"][icl]][ih].get() ); + } std::vector<std::shared_ptr<Cyber::Calo3DCluster>> m_clusterCol; m_clusterCol.clear(); diff --git a/Reconstruction/RecPFACyber/src/Algorithm/HoughClusteringAlg.cpp b/Reconstruction/RecPFACyber/src/Algorithm/HoughClusteringAlg.cpp index dec300f17f22c17962151cb0d6f9f22dd6f877a0..5c6aeb1ffd2502694d534aa42d429ede88cc06eb 100644 --- a/Reconstruction/RecPFACyber/src/Algorithm/HoughClusteringAlg.cpp +++ b/Reconstruction/RecPFACyber/src/Algorithm/HoughClusteringAlg.cpp @@ -40,6 +40,16 @@ StatusCode HoughClusteringAlg::ReadSettings(Cyber::Settings& m_settings){ settings.map_floatPars["bin_width_alphaU"] = ( settings.map_floatPars["alpha_highU"] - settings.map_floatPars["alpha_lowU"] ) / (double)settings.map_intPars["Nbins_alphaU"]; // double bin_width_alphaU = (alpha_highU - alpha_lowU) / (double)Nbins_alphaU; + // alpha in endcap. Works for both V and U planes + if(settings.map_floatPars.find("alpha_low_endcap")==settings.map_floatPars.end()) + settings.map_floatPars["alpha_low_endcap"] = 0.; + if(settings.map_floatPars.find("alpha_high_endcap")==settings.map_floatPars.end()) + settings.map_floatPars["alpha_high_endcap"] = TMath::Pi(); + if(settings.map_intPars.find("Nbins_alpha_endcap")==settings.map_intPars.end()) + settings.map_intPars["Nbins_alpha_endcap"] = 3000; + if(settings.map_floatPars.find("bin_width_alpha_endcap")==settings.map_floatPars.end()) + settings.map_floatPars["bin_width_alpha_endcap"] = ( settings.map_floatPars["alpha_high_endcap"] - settings.map_floatPars["alpha_low_endcap"] ) / (double)settings.map_intPars["Nbins_alpha_endcap"]; + // rho if(settings.map_floatPars.find("rho_low")==settings.map_floatPars.end()) settings.map_floatPars["rho_low"] = -50.; @@ -79,37 +89,59 @@ StatusCode HoughClusteringAlg::ReadSettings(Cyber::Settings& m_settings){ } StatusCode HoughClusteringAlg::Initialize( CyberDataCol& m_datacol ){ - p_HalfClusterU.clear(); - p_HalfClusterV.clear(); + barrel_HalfClusterU.clear(); + barrel_HalfClusterV.clear(); + endcap0_HalfClusterV.clear(); + endcap0_HalfClusterU.clear(); + endcap1_HalfClusterV.clear(); + endcap1_HalfClusterU.clear(); + + for(int ih=0; ih<m_datacol.map_HalfCluster["HalfClusterColU"].size(); ih++){ + if(m_datacol.map_HalfCluster["HalfClusterColU"][ih].get()->getBars()[0]->getSystem()==Cyber::CaloUnit::System_Barrel){ + barrel_HalfClusterU.push_back( m_datacol.map_HalfCluster["HalfClusterColU"][ih].get() ); + } + else if ((m_datacol.map_HalfCluster["HalfClusterColU"][ih].get()->getBars()[0]->getSystem()==Cyber::CaloUnit::System_Endcap) + && (m_datacol.map_HalfCluster["HalfClusterColU"][ih].get()->getBars()[0]->getModule()==0)){ + endcap0_HalfClusterU.push_back( m_datacol.map_HalfCluster["HalfClusterColU"][ih].get() ); + } + else if ((m_datacol.map_HalfCluster["HalfClusterColU"][ih].get()->getBars()[0]->getSystem()==Cyber::CaloUnit::System_Endcap) + && (m_datacol.map_HalfCluster["HalfClusterColU"][ih].get()->getBars()[0]->getModule()==1)){ + endcap1_HalfClusterU.push_back( m_datacol.map_HalfCluster["HalfClusterColU"][ih].get() ); + } + } + for(int ih=0; ih<m_datacol.map_HalfCluster["HalfClusterColV"].size(); ih++){ + if(m_datacol.map_HalfCluster["HalfClusterColV"][ih].get()->getBars()[0]->getSystem()==Cyber::CaloUnit::System_Barrel){ + barrel_HalfClusterV.push_back( m_datacol.map_HalfCluster["HalfClusterColV"][ih].get() ); + } + else if ((m_datacol.map_HalfCluster["HalfClusterColV"][ih].get()->getBars()[0]->getSystem()==Cyber::CaloUnit::System_Endcap) + && (m_datacol.map_HalfCluster["HalfClusterColV"][ih].get()->getBars()[0]->getModule()==0)){ + endcap0_HalfClusterV.push_back( m_datacol.map_HalfCluster["HalfClusterColV"][ih].get() ); + } + else if ((m_datacol.map_HalfCluster["HalfClusterColV"][ih].get()->getBars()[0]->getSystem()==Cyber::CaloUnit::System_Endcap) + && (m_datacol.map_HalfCluster["HalfClusterColV"][ih].get()->getBars()[0]->getModule()==1)){ + endcap1_HalfClusterV.push_back( m_datacol.map_HalfCluster["HalfClusterColV"][ih].get() ); + } + } - for(int ih=0; ih<m_datacol.map_HalfCluster["HalfClusterColU"].size(); ih++) - p_HalfClusterU.push_back( m_datacol.map_HalfCluster["HalfClusterColU"][ih].get() ); - for(int ih=0; ih<m_datacol.map_HalfCluster["HalfClusterColV"].size(); ih++) - p_HalfClusterV.push_back( m_datacol.map_HalfCluster["HalfClusterColV"][ih].get() ); +//cout << "yyy: Number of barrel_HalfClusterU: " << barrel_HalfClusterU.size() << endl; +//cout << "yyy: Number of barrel_HalfClusterV: " << barrel_HalfClusterV.size() << endl; - //p_HalfClusterU = m_datacol.map_HalfCluster["HalfClusterColU"]; - //p_HalfClusterV = m_datacol.map_HalfCluster["HalfClusterColV"]; return StatusCode::SUCCESS; } StatusCode HoughClusteringAlg::RunAlgorithm( CyberDataCol& m_datacol ){ + if(barrel_HalfClusterV.size()==0 && endcap0_HalfClusterV.size()==0 && endcap1_HalfClusterV.size()==0){ + std::cout<<" HoughClusteringAlg: No HalfClusterV in present data collection! "<<std::endl; + } + if(barrel_HalfClusterU.size()==0 && endcap0_HalfClusterU.size()==0 && endcap1_HalfClusterU.size()==0){ + std::cout<<" HoughClusteringAlg: No HalfClusterU in present data collection! "<<std::endl; + } - //if( (p_HalfClusterU.size()+p_HalfClusterV.size())<1 ){ - // std::cout << "HoughClusteringAlg: No HalfCluster input"<<std::endl; - // return StatusCode::SUCCESS; - //} - - - if(p_HalfClusterV.size()==0){ std::cout<<" HoughClusteringAlg: No HalfClusterV in present data collection! "<<std::endl; } - if(p_HalfClusterU.size()==0){ std::cout<<" HoughClusteringAlg: No HalfClusterU in present data collection! "<<std::endl; } - - - //std::vector<const Cyber::CaloHalfCluster*> m_refHFClusVCol; m_refHFClusVCol.clear(); - // Processing V(xy) plane - for(int it=0; it<p_HalfClusterV.size(); it++){ // process each HalfCluster respectively + // Processing V bar in barrel (V bar parallel to z axis) + for(int it=0; it<barrel_HalfClusterV.size(); it++){ // process each HalfCluster respectively m_localMaxVCol.clear(); - std::vector<const Cyber::Calo1DCluster*> tmp_localMaxVCol = p_HalfClusterV[it]->getLocalMaxCol(settings.map_stringPars["ReadinLocalMaxName"]); + std::vector<const Cyber::Calo1DCluster*> tmp_localMaxVCol = barrel_HalfClusterV[it]->getLocalMaxCol(settings.map_stringPars["ReadinLocalMaxName"]); for(int il=0; il<tmp_localMaxVCol.size(); il++){ if(tmp_localMaxVCol[il]->getDlayer()<=settings.map_intPars["th_Layers"]) @@ -117,11 +149,9 @@ StatusCode HoughClusteringAlg::RunAlgorithm( CyberDataCol& m_datacol ){ } if(m_localMaxVCol.size()<settings.map_intPars["th_peak"]){ - //std::cout << " yyy: m_localMaxVCol.size()<th_peak, continue" << std::endl; continue; } - std::vector<Cyber::HoughObject> m_HoughObjectsV; m_HoughObjectsV.clear(); for(int il=0; il<m_localMaxVCol.size(); il++){ Cyber::HoughObject m_obj(m_localMaxVCol[il], Cyber::CaloUnit::barsize, Cyber::CaloUnit::ecal_innerR); @@ -131,16 +161,16 @@ StatusCode HoughClusteringAlg::RunAlgorithm( CyberDataCol& m_datacol ){ HoughTransformation(m_HoughObjectsV); // cout<<" HoughClusteringAlg: Creating hough_spaceV"<<endl; - Cyber::HoughSpace hough_spaceV(settings.map_floatPars["alpha_lowV"], settings.map_floatPars["alpha_highV"], - settings.map_floatPars["bin_width_alphaV"], settings.map_intPars["Nbins_alphaV"], - settings.map_floatPars["rho_low"], settings.map_floatPars["rho_high"], - settings.map_floatPars["bin_width_rho"], settings.map_intPars["Nbins_rho"]); + Cyber::HoughSpace hough_spaceV( settings.map_floatPars["alpha_lowV"], settings.map_floatPars["alpha_highV"], + settings.map_floatPars["bin_width_alphaV"], settings.map_intPars["Nbins_alphaV"], + settings.map_floatPars["rho_low"], settings.map_floatPars["rho_high"], + settings.map_floatPars["bin_width_rho"], settings.map_intPars["Nbins_rho"]); FillHoughSpace(m_HoughObjectsV, hough_spaceV); //Create output HoughClusters m_longiClusVCol.clear(); - ClusterFinding(m_HoughObjectsV, hough_spaceV, m_longiClusVCol ); + ClusterFinding(m_HoughObjectsV, hough_spaceV, m_longiClusVCol); CleanClusters(m_longiClusVCol); m_datacol.map_HalfCluster["bkHalfCluster"].insert( m_datacol.map_HalfCluster["bkHalfCluster"].end(), m_longiClusVCol.begin(), m_longiClusVCol.end() ); @@ -161,19 +191,18 @@ StatusCode HoughClusteringAlg::RunAlgorithm( CyberDataCol& m_datacol ){ m_constHoughCluster.push_back(m_longiClusVCol[ic].get()); - p_HalfClusterV[it]->setLocalMax("HoughLocalMax", m_houghMax); - p_HalfClusterV[it]->setLocalMax(settings.map_stringPars["LeftLocalMaxName"], left_localMaxVCol); - p_HalfClusterV[it]->setHalfClusters(settings.map_stringPars["OutputLongiClusName"], m_constHoughCluster); + barrel_HalfClusterV[it]->setLocalMax("HoughLocalMax", m_houghMax); + barrel_HalfClusterV[it]->setLocalMax(settings.map_stringPars["LeftLocalMaxName"], left_localMaxVCol); + barrel_HalfClusterV[it]->setHalfClusters(settings.map_stringPars["OutputLongiClusName"], m_constHoughCluster); m_houghMax.clear(); left_localMaxVCol.clear(); - } // end of V plane - + } - // Processing U(r-phi) plane - for(int it=0; it<p_HalfClusterU.size(); it++){ // process each HalfCluster respectively + // Processing U bar in barrel (U bar perpendicular to z axis) + for(int it=0; it<barrel_HalfClusterU.size(); it++){ // process each HalfCluster respectively m_localMaxUCol.clear(); - std::vector<const Cyber::Calo1DCluster*> tmp_localMaxUCol = p_HalfClusterU[it]->getLocalMaxCol(settings.map_stringPars["ReadinLocalMaxName"]); + std::vector<const Cyber::Calo1DCluster*> tmp_localMaxUCol = barrel_HalfClusterU[it]->getLocalMaxCol(settings.map_stringPars["ReadinLocalMaxName"]); for(int il=0; il<tmp_localMaxUCol.size(); il++){ if(tmp_localMaxUCol[il]->getDlayer()<=settings.map_intPars["th_Layers"]) @@ -222,145 +251,312 @@ StatusCode HoughClusteringAlg::RunAlgorithm( CyberDataCol& m_datacol ){ for(int ic=0; ic<m_longiClusUCol.size(); ic++) m_constHoughCluster.push_back(m_longiClusUCol[ic].get()); - p_HalfClusterU[it]->setLocalMax("HoughLocalMax", m_houghMax); - p_HalfClusterU[it]->setLocalMax(settings.map_stringPars["LeftLocalMaxName"], left_localMaxUCol); - p_HalfClusterU[it]->setHalfClusters(settings.map_stringPars["OutputLongiClusName"], m_constHoughCluster); + barrel_HalfClusterU[it]->setLocalMax("HoughLocalMax", m_houghMax); + barrel_HalfClusterU[it]->setLocalMax(settings.map_stringPars["LeftLocalMaxName"], left_localMaxUCol); + barrel_HalfClusterU[it]->setHalfClusters(settings.map_stringPars["OutputLongiClusName"], m_constHoughCluster); m_houghMax.clear(); left_localMaxUCol.clear(); } // end of U plane + // Processing V bar in endcap 0 (V bar parallel to x axis, endcap 0 at z~-2900mm) + for(int it=0; it<endcap0_HalfClusterV.size(); it++){ // process each HalfCluster respectively + m_localMaxVCol.clear(); + std::vector<const Cyber::Calo1DCluster*> tmp_localMaxVCol = endcap0_HalfClusterV[it]->getLocalMaxCol(settings.map_stringPars["ReadinLocalMaxName"]); + for(int il=0; il<tmp_localMaxVCol.size(); il++){ + if(tmp_localMaxVCol[il]->getDlayer()<=settings.map_intPars["th_Layers"]) + m_localMaxVCol.push_back(tmp_localMaxVCol[il]); + } + if(m_localMaxVCol.size()<settings.map_intPars["th_peak"]){ + continue; + } + std::vector<Cyber::HoughObject> m_HoughObjectsV; m_HoughObjectsV.clear(); + for(int il=0; il<m_localMaxVCol.size(); il++){ + Cyber::HoughObject m_obj(m_localMaxVCol[il], Cyber::CaloUnit::barsize, Cyber::CaloUnit::ecal_innerR); + m_HoughObjectsV.push_back(m_obj); + } + HoughTransformation(m_HoughObjectsV); -/* - for(int it=0; it<p_HalfClusterU.size(); it++){ + // cout<<" HoughClusteringAlg: Creating hough_spaceV"<<endl; + Cyber::HoughSpace hough_spaceV(settings.map_floatPars["alpha_low_endcap"], settings.map_floatPars["alpha_high_endcap"], + settings.map_floatPars["bin_width_alpha_endcap"], settings.map_intPars["Nbins_alpha_endcap"], + settings.map_floatPars["rho_low"], settings.map_floatPars["rho_high"], + settings.map_floatPars["bin_width_rho"], settings.map_intPars["Nbins_rho"]); + + FillHoughSpace(m_HoughObjectsV, hough_spaceV); + + //Create output HoughClusters + m_longiClusVCol.clear(); + ClusterFinding(m_HoughObjectsV, hough_spaceV, m_longiClusVCol); + + CleanClusters(m_longiClusVCol); + m_datacol.map_HalfCluster["bkHalfCluster"].insert( m_datacol.map_HalfCluster["bkHalfCluster"].end(), m_longiClusVCol.begin(), m_longiClusVCol.end() ); + + std::vector<const Cyber::CaloHalfCluster*> m_constHoughCluster; m_constHoughCluster.clear(); + std::vector<const Cyber::Calo1DCluster*> left_localMaxVCol; left_localMaxVCol.clear(); + std::vector<const Cyber::Calo1DCluster*> m_houghMax; m_houghMax.clear(); + for(int is=0; is<tmp_localMaxVCol.size(); is++){ + bool fl_incluster = false; + for(int ic=0; ic<m_longiClusVCol.size(); ic++){ + std::vector<const Cyber::Calo1DCluster*> p_showers = m_longiClusVCol[ic]->getCluster(); + if( find(p_showers.begin(), p_showers.end(), tmp_localMaxVCol[is])!=p_showers.end() ) { fl_incluster = true; break; } + } + if(!fl_incluster && find(left_localMaxVCol.begin(), left_localMaxVCol.end(), tmp_localMaxVCol[is])==left_localMaxVCol.end() ) left_localMaxVCol.push_back(tmp_localMaxVCol[is]); + m_houghMax.push_back( tmp_localMaxVCol[is] ); + } + for(int ic=0; ic<m_longiClusVCol.size(); ic++) + m_constHoughCluster.push_back(m_longiClusVCol[ic].get()); + + endcap0_HalfClusterV[it]->setLocalMax("HoughLocalMax", m_houghMax); + endcap0_HalfClusterV[it]->setLocalMax(settings.map_stringPars["LeftLocalMaxName"], left_localMaxVCol); + endcap0_HalfClusterV[it]->setHalfClusters(settings.map_stringPars["OutputLongiClusName"], m_constHoughCluster); + m_houghMax.clear(); + left_localMaxVCol.clear(); + } + + + // Processing U bar in endcap 0 (U bar parallel to y axis, endcap 0 at z~-2900mm) + for(int it=0; it<endcap0_HalfClusterU.size(); it++){ // process each HalfCluster respectively m_localMaxUCol.clear(); - std::vector<const Cyber::Calo1DCluster*> tmp_localMaxUCol = p_HalfClusterU[it]->getLocalMaxCol(settings.map_stringPars["ReadinLocalMaxName"]); + std::vector<const Cyber::Calo1DCluster*> tmp_localMaxUCol = endcap0_HalfClusterU[it]->getLocalMaxCol(settings.map_stringPars["ReadinLocalMaxName"]); for(int il=0; il<tmp_localMaxUCol.size(); il++){ - if(tmp_localMaxUCol[il]->getDlayer()<=settings.map_intPars["th_Layers"]) + if(tmp_localMaxUCol[il]->getDlayer()<=settings.map_intPars["th_Layers"]) m_localMaxUCol.push_back(tmp_localMaxUCol[il]); } if(m_localMaxUCol.size()<settings.map_intPars["th_peak"]){ - continue; - } -//cout<<" HoughClusteringAlg: Find Hough axis in HalfCluster "<<it<<". Local maximum size U = "<<m_localMaxUCol.size()<<endl; + continue; + } - std::map<int, std::vector<Cyber::HoughObject> > map_HoughObjectsU_module; map_HoughObjectsU_module.clear(); - std::map<int, std::vector<Cyber::HoughObject> > map_HoughObjectsU_crack; map_HoughObjectsU_crack.clear(); - + std::vector<Cyber::HoughObject> m_HoughObjectsU; m_HoughObjectsU.clear(); for(int il=0; il<m_localMaxUCol.size(); il++){ - int module = m_localMaxUCol[il]->getTowerID()[0][0]; Cyber::HoughObject m_obj(m_localMaxUCol[il], Cyber::CaloUnit::barsize, Cyber::CaloUnit::ecal_innerR); - map_HoughObjectsU_module[module].push_back(m_obj); - } - for(int iref=0; iref<m_refHFClusVCol.size(); iref++){ - double tmp_phi = m_refHFClusVCol[iref]->getPos().Phi(); // yyy: tmp_phi ranges from -pi to pi -//cout<<" Ref HFCluster phi: "<<tmp_phi<<endl; - double intPart, fracPart; - fracPart = modf((tmp_phi+TMath::Pi())/(TMath::Pi()/4.), &intPart); // yyy: tmp_phi + TMath::Pi() ranges from 0 to 2pi -//cout<<" Int part "<<intPart<<", frac part "<<fracPart<<endl; - if(fracPart<0.489 || fracPart>0.711) continue; //Not in crack region. - - int iCrack = intPart+2; - if(iCrack>=8) iCrack = iCrack-8; -//cout<<" Crack No: "<<iCrack<<endl; - - for(int il=0; il<m_localMaxUCol.size(); il++){ - if( (m_localMaxUCol[il]->getTowerID()[0][0]==iCrack && m_localMaxUCol[il]->getTowerID()[0][1]==4) || - (iCrack!=7 && m_localMaxUCol[il]->getTowerID()[0][0]==iCrack+1 && m_localMaxUCol[il]->getTowerID()[0][1]==1) || - (iCrack==7 && m_localMaxUCol[il]->getTowerID()[0][0]==0 && m_localMaxUCol[il]->getTowerID()[0][1]==1)){ - Cyber::HoughObject m_obj(m_localMaxUCol[il], Cyber::CaloUnit::barsize, Cyber::CaloUnit::ecal_innerR, tmp_phi); - map_HoughObjectsU_crack[iCrack].push_back(m_obj); - } - } - + m_HoughObjectsU.push_back(m_obj); } -//cout<<" Module HoughObject: "<<endl; -//for(auto iter: map_HoughObjectsU_module) -//printf(" Module #%d: object size %d \n", iter.first, iter.second.size()); -//cout<<" Crack HoughObject: "<<endl; -//for(auto iter: map_HoughObjectsU_crack) -//printf(" Crack #%d: object size %d \n", iter.first, iter.second.size()); + HoughTransformation(m_HoughObjectsU); + // cout<<" HoughClusteringAlg: Creating hough_spaceU"<<endl; + Cyber::HoughSpace hough_spaceU(settings.map_floatPars["alpha_low_endcap"], settings.map_floatPars["alpha_high_endcap"], + settings.map_floatPars["bin_width_alpha_endcap"], settings.map_intPars["Nbins_alpha_endcap"], + settings.map_floatPars["rho_low"], settings.map_floatPars["rho_high"], + settings.map_floatPars["bin_width_rho"], settings.map_intPars["Nbins_rho"]); - //Do hough transformation for HoughObjects - for(auto &imodule: map_HoughObjectsU_module) HoughTransformation(imodule.second); - for(auto &icrack: map_HoughObjectsU_crack) HoughTransformation(icrack.second); - - //Fill Hough space - std::map<int, Cyber::HoughSpace> hough_spacesU_module; - std::map<int, Cyber::HoughSpace> hough_spacesU_crack; - for(auto &imodule: map_HoughObjectsU_module){ - Cyber::HoughSpace hspaceU(settings.map_floatPars["alpha_lowU"], settings.map_floatPars["alpha_highU"], - settings.map_floatPars["bin_width_alphaU"], settings.map_intPars["Nbins_alphaU"], - settings.map_floatPars["rho_low"], settings.map_floatPars["rho_high"], - settings.map_floatPars["bin_width_rho"], settings.map_intPars["Nbins_rho"]); - FillHoughSpace(imodule.second, hspaceU); - hough_spacesU_module[imodule.first] = hspaceU; - } - for(auto &icrack: map_HoughObjectsU_crack){ - Cyber::HoughSpace hspaceU(settings.map_floatPars["alpha_lowU"], settings.map_floatPars["alpha_highU"], - settings.map_floatPars["bin_width_alphaU"], settings.map_intPars["Nbins_alphaU"], - settings.map_floatPars["rho_low"], settings.map_floatPars["rho_high"], - settings.map_floatPars["bin_width_rho"], settings.map_intPars["Nbins_rho"]); - FillHoughSpace(icrack.second, hspaceU); - hough_spacesU_crack[icrack.first] = hspaceU; - } -//cout<<" Module Hough space size: "<<hough_spacesU_module.size()<<endl; -//cout<<" Crack Hough space size: "<<hough_spacesU_module.size()<<endl; + FillHoughSpace(m_HoughObjectsU, hough_spaceU); + //Create output HoughClusters m_longiClusUCol.clear(); - for(auto &imodule: map_HoughObjectsU_module) - ClusterFinding(imodule.second, hough_spacesU_module[imodule.first], m_longiClusUCol ); - for(auto &icrack: map_HoughObjectsU_crack) - ClusterFinding(icrack.second, hough_spacesU_crack[icrack.first], m_longiClusUCol ); + ClusterFinding(m_HoughObjectsU, hough_spaceU, m_longiClusUCol); -//cout<<" Hough axis size: "<<m_longiClusUCol.size()<<endl; CleanClusters(m_longiClusUCol); m_datacol.map_HalfCluster["bkHalfCluster"].insert( m_datacol.map_HalfCluster["bkHalfCluster"].end(), m_longiClusUCol.begin(), m_longiClusUCol.end() ); -//cout<<" Hough axis size after cleaning: "<<m_longiClusUCol.size()<<endl; -//cout<<" Print axis "<<endl; -//for(int i=0; i<m_longiClusUCol.size(); i++){ -// printf(" Axis #%d: hit size %d, type %d, address %p \n", i, m_longiClusUCol[i]->getCluster().size(), m_longiClusUCol[i]->getType(), m_longiClusUCol[i].get() ); -//} std::vector<const Cyber::CaloHalfCluster*> m_constHoughCluster; m_constHoughCluster.clear(); std::vector<const Cyber::Calo1DCluster*> left_localMaxUCol; left_localMaxUCol.clear(); std::vector<const Cyber::Calo1DCluster*> m_houghMax; m_houghMax.clear(); for(int is=0; is<tmp_localMaxUCol.size(); is++){ - bool fl_incluster = false; + bool fl_incluster = false; for(int ic=0; ic<m_longiClusUCol.size(); ic++){ std::vector<const Cyber::Calo1DCluster*> p_showers = m_longiClusUCol[ic]->getCluster(); if( find(p_showers.begin(), p_showers.end(), tmp_localMaxUCol[is])!=p_showers.end() ) { fl_incluster = true; break; } } if(!fl_incluster && find(left_localMaxUCol.begin(), left_localMaxUCol.end(), tmp_localMaxUCol[is])==left_localMaxUCol.end() ) left_localMaxUCol.push_back(tmp_localMaxUCol[is]); - else m_houghMax.push_back( tmp_localMaxUCol[is] ); + m_houghMax.push_back( tmp_localMaxUCol[is] ); + } + for(int ic=0; ic<m_longiClusUCol.size(); ic++) + m_constHoughCluster.push_back(m_longiClusUCol[ic].get()); + + endcap0_HalfClusterU[it]->setLocalMax("HoughLocalMax", m_houghMax); + endcap0_HalfClusterU[it]->setLocalMax(settings.map_stringPars["LeftLocalMaxName"], left_localMaxUCol); + endcap0_HalfClusterU[it]->setHalfClusters(settings.map_stringPars["OutputLongiClusName"], m_constHoughCluster); + m_houghMax.clear(); + left_localMaxUCol.clear(); + } + + + // Processing V bar in endcap 1 (V bar parallel to x axis, endcap 1 at z~2900mm) + for(int it=0; it<endcap1_HalfClusterV.size(); it++){ // process each HalfCluster respectively + m_localMaxVCol.clear(); + std::vector<const Cyber::Calo1DCluster*> tmp_localMaxVCol = endcap1_HalfClusterV[it]->getLocalMaxCol(settings.map_stringPars["ReadinLocalMaxName"]); + + for(int il=0; il<tmp_localMaxVCol.size(); il++){ + if(tmp_localMaxVCol[il]->getDlayer()<=settings.map_intPars["th_Layers"]) + m_localMaxVCol.push_back(tmp_localMaxVCol[il]); + } + //cout << "yyy: Number of localMaxVCol: " << m_localMaxVCol.size() << endl; + + if(m_localMaxVCol.size()<settings.map_intPars["th_peak"]){ + continue; + } + + std::vector<Cyber::HoughObject> m_HoughObjectsV; m_HoughObjectsV.clear(); + for(int il=0; il<m_localMaxVCol.size(); il++){ + Cyber::HoughObject m_obj(m_localMaxVCol[il], Cyber::CaloUnit::barsize, Cyber::CaloUnit::ecal_innerR); + m_HoughObjectsV.push_back(m_obj); + } + //cout << "yyy: Number of HoughObjectsV: " << m_HoughObjectsV.size() << endl; + + HoughTransformation(m_HoughObjectsV); + + // cout<<" HoughClusteringAlg: Creating hough_spaceV"<<endl; + Cyber::HoughSpace hough_spaceV(settings.map_floatPars["alpha_low_endcap"], settings.map_floatPars["alpha_high_endcap"], + settings.map_floatPars["bin_width_alpha_endcap"], settings.map_intPars["Nbins_alpha_endcap"], + settings.map_floatPars["rho_low"], settings.map_floatPars["rho_high"], + settings.map_floatPars["bin_width_rho"], settings.map_intPars["Nbins_rho"]); + + FillHoughSpace(m_HoughObjectsV, hough_spaceV); + + //Create output HoughClusters + m_longiClusVCol.clear(); + ClusterFinding(m_HoughObjectsV, hough_spaceV, m_longiClusVCol); + //cout << "yyy: Number of longiClusVCol: " << m_longiClusVCol.size() << endl; + + CleanClusters(m_longiClusVCol); + //cout << "yyy: Number of longiClusVCol after cleaning: " << m_longiClusVCol.size() << endl; + m_datacol.map_HalfCluster["bkHalfCluster"].insert( m_datacol.map_HalfCluster["bkHalfCluster"].end(), m_longiClusVCol.begin(), m_longiClusVCol.end() ); + + std::vector<const Cyber::CaloHalfCluster*> m_constHoughCluster; m_constHoughCluster.clear(); + std::vector<const Cyber::Calo1DCluster*> left_localMaxVCol; left_localMaxVCol.clear(); + std::vector<const Cyber::Calo1DCluster*> m_houghMax; m_houghMax.clear(); + for(int is=0; is<tmp_localMaxVCol.size(); is++){ + bool fl_incluster = false; + for(int ic=0; ic<m_longiClusVCol.size(); ic++){ + std::vector<const Cyber::Calo1DCluster*> p_showers = m_longiClusVCol[ic]->getCluster(); + if( find(p_showers.begin(), p_showers.end(), tmp_localMaxVCol[is])!=p_showers.end() ) { fl_incluster = true; break; } + } + if(!fl_incluster && find(left_localMaxVCol.begin(), left_localMaxVCol.end(), tmp_localMaxVCol[is])==left_localMaxVCol.end() ) left_localMaxVCol.push_back(tmp_localMaxVCol[is]); + m_houghMax.push_back( tmp_localMaxVCol[is] ); + } + for(int ic=0; ic<m_longiClusVCol.size(); ic++) + m_constHoughCluster.push_back(m_longiClusVCol[ic].get()); + + endcap1_HalfClusterV[it]->setLocalMax("HoughLocalMax", m_houghMax); + endcap1_HalfClusterV[it]->setLocalMax(settings.map_stringPars["LeftLocalMaxName"], left_localMaxVCol); + endcap1_HalfClusterV[it]->setHalfClusters(settings.map_stringPars["OutputLongiClusName"], m_constHoughCluster); + m_houghMax.clear(); + left_localMaxVCol.clear(); + } + + + // Processing U bar in endcap 1 (U bar parallel to y axis, endcap 1 at z~2900mm) + for(int it=0; it<endcap1_HalfClusterU.size(); it++){ // process each HalfCluster respectively + m_localMaxUCol.clear(); + std::vector<const Cyber::Calo1DCluster*> tmp_localMaxUCol = endcap1_HalfClusterU[it]->getLocalMaxCol(settings.map_stringPars["ReadinLocalMaxName"]); + + for(int il=0; il<tmp_localMaxUCol.size(); il++){ + if(tmp_localMaxUCol[il]->getDlayer()<=settings.map_intPars["th_Layers"]) + m_localMaxUCol.push_back(tmp_localMaxUCol[il]); } + if(m_localMaxUCol.size()<settings.map_intPars["th_peak"]){ + continue; + } + + std::vector<Cyber::HoughObject> m_HoughObjectsU; m_HoughObjectsU.clear(); + for(int il=0; il<m_localMaxUCol.size(); il++){ + Cyber::HoughObject m_obj(m_localMaxUCol[il], Cyber::CaloUnit::barsize, Cyber::CaloUnit::ecal_innerR); + m_HoughObjectsU.push_back(m_obj); + } + + HoughTransformation(m_HoughObjectsU); + + // cout<<" HoughClusteringAlg: Creating hough_spaceU"<<endl; + Cyber::HoughSpace hough_spaceU(settings.map_floatPars["alpha_low_endcap"], settings.map_floatPars["alpha_high_endcap"], + settings.map_floatPars["bin_width_alpha_endcap"], settings.map_intPars["Nbins_alpha_endcap"], + settings.map_floatPars["rho_low"], settings.map_floatPars["rho_high"], + settings.map_floatPars["bin_width_rho"], settings.map_intPars["Nbins_rho"]); + + FillHoughSpace(m_HoughObjectsU, hough_spaceU); + + //Create output HoughClusters + m_longiClusUCol.clear(); + ClusterFinding(m_HoughObjectsU, hough_spaceU, m_longiClusUCol); + + CleanClusters(m_longiClusUCol); + m_datacol.map_HalfCluster["bkHalfCluster"].insert( m_datacol.map_HalfCluster["bkHalfCluster"].end(), m_longiClusUCol.begin(), m_longiClusUCol.end() ); + + std::vector<const Cyber::CaloHalfCluster*> m_constHoughCluster; m_constHoughCluster.clear(); + std::vector<const Cyber::Calo1DCluster*> left_localMaxUCol; left_localMaxUCol.clear(); + std::vector<const Cyber::Calo1DCluster*> m_houghMax; m_houghMax.clear(); + for(int is=0; is<tmp_localMaxUCol.size(); is++){ + bool fl_incluster = false; + for(int ic=0; ic<m_longiClusUCol.size(); ic++){ + std::vector<const Cyber::Calo1DCluster*> p_showers = m_longiClusUCol[ic]->getCluster(); + if( find(p_showers.begin(), p_showers.end(), tmp_localMaxUCol[is])!=p_showers.end() ) { fl_incluster = true; break; } + } + if(!fl_incluster && find(left_localMaxUCol.begin(), left_localMaxUCol.end(), tmp_localMaxUCol[is])==left_localMaxUCol.end() ) left_localMaxUCol.push_back(tmp_localMaxUCol[is]); + m_houghMax.push_back( tmp_localMaxUCol[is] ); + } for(int ic=0; ic<m_longiClusUCol.size(); ic++) m_constHoughCluster.push_back(m_longiClusUCol[ic].get()); - p_HalfClusterU[it]->setLocalMax("HoughLocalMax", m_houghMax); - p_HalfClusterU[it]->setLocalMax(settings.map_stringPars["LeftLocalMaxName"], left_localMaxUCol); - p_HalfClusterU[it]->setHalfClusters(settings.map_stringPars["OutputLongiClusName"], m_constHoughCluster); + endcap1_HalfClusterU[it]->setLocalMax("HoughLocalMax", m_houghMax); + endcap1_HalfClusterU[it]->setLocalMax(settings.map_stringPars["LeftLocalMaxName"], left_localMaxUCol); + endcap1_HalfClusterU[it]->setHalfClusters(settings.map_stringPars["OutputLongiClusName"], m_constHoughCluster); m_houghMax.clear(); - left_localMaxUCol.clear(); + left_localMaxUCol.clear(); + } +/* +int Ncl_hough = 0; +int Ncl_trk = 0; +int Naxis_hough = 0; +int Naxis_trk = 0; +double Etot_hough = 0.; +double Etot_trk = 0.; +for(int i=0; i<barrel_HalfClusterU.size(); i++){ + //printf(" HalfClusterU #%d: energy %.4f, Hough axis size %d \n", i, barrel_HalfClusterU[i]->getEnergy(), barrel_HalfClusterU[i]->getHalfClusterCol(settings.map_stringPars["OutputLongiClusName"]).size() ); + if(barrel_HalfClusterU[i]->getHalfClusterCol(settings.map_stringPars["OutputLongiClusName"]).size()!=0){ + Ncl_hough++; + Naxis_hough += barrel_HalfClusterU[i]->getHalfClusterCol(settings.map_stringPars["OutputLongiClusName"]).size(); + Etot_hough += barrel_HalfClusterU[i]->getEnergy(); + } - } // end of U plane -*/ + if(barrel_HalfClusterU[i]->getHalfClusterCol("TrackAxis").size()!=0){ + Ncl_trk++; + Naxis_trk += barrel_HalfClusterU[i]->getHalfClusterCol("TrackAxis").size(); + Etot_trk += barrel_HalfClusterU[i]->getEnergy(); + } +} +cout<<"ClusterU number with Hough axis: "<<Ncl_hough<<", total Hough axis size: "<<Naxis_hough<<", total energy of cluster with Hough axis: "<<Etot_hough<<endl; +cout<<"ClusterU number with track axis: "<<Ncl_trk<<", total Track axis size: "<<Naxis_trk<<", total energy of cluster with Track axis: "<<Etot_trk<<endl; +Ncl_hough = 0; +Ncl_trk = 0; +Naxis_hough = 0; +Naxis_trk = 0; +Etot_hough = 0.; +Etot_trk = 0.; +for(int i=0; i<barrel_HalfClusterV.size(); i++){ + //printf("HalfClusterV #%d: energy %.4f, Hough axis size %d \n", i, barrel_HalfClusterV[i]->getEnergy(), barrel_HalfClusterV[i]->getHalfClusterCol(settings.map_stringPars["OutputLongiClusName"]).size() ); + if(barrel_HalfClusterV[i]->getHalfClusterCol(settings.map_stringPars["OutputLongiClusName"]).size()!=0){ + Ncl_hough++; + Naxis_hough += barrel_HalfClusterV[i]->getHalfClusterCol(settings.map_stringPars["OutputLongiClusName"]).size(); + Etot_hough += barrel_HalfClusterV[i]->getEnergy(); + } + if(barrel_HalfClusterV[i]->getHalfClusterCol("TrackAxis").size()!=0){ + Ncl_trk++; + Naxis_trk += barrel_HalfClusterV[i]->getHalfClusterCol("TrackAxis").size(); + Etot_trk += barrel_HalfClusterV[i]->getEnergy(); + } +} +cout<<"ClusterV number with Hough axis: "<<Ncl_hough<<", total Hough axis size: "<<Naxis_hough<<", total energy of cluster with Hough axis: "<<Etot_hough<<endl; +cout<<"ClusterV number with track axis: "<<Ncl_trk<<", total Track axis size: "<<Naxis_trk<<", total energy of cluster with Track axis: "<<Etot_trk<<endl; +*/ return StatusCode::SUCCESS; } StatusCode HoughClusteringAlg::ClearAlgorithm(){ - p_HalfClusterV.clear(); - p_HalfClusterU.clear(); + barrel_HalfClusterV.clear(); + barrel_HalfClusterU.clear(); + endcap0_HalfClusterV.clear(); + endcap0_HalfClusterU.clear(); + endcap1_HalfClusterV.clear(); + endcap1_HalfClusterU.clear(); m_localMaxVCol.clear(); m_localMaxUCol.clear(); m_longiClusVCol.clear(); @@ -373,178 +569,81 @@ StatusCode HoughClusteringAlg::ClearAlgorithm(){ StatusCode HoughClusteringAlg::HoughTransformation(std::vector<Cyber::HoughObject>& Hobjects){ if(Hobjects.size()<settings.map_intPars["th_peak"]) return StatusCode::SUCCESS; - // range of alpha of different lines - double range12[2] = {0, 0}; - double range34[2] = {0, 0}; - for(int iobj=0; iobj<Hobjects.size(); iobj++){ int t_slayer = Hobjects[iobj].getSlayer(); - //SetLineRange(t_module, t_slayer, range12, range34); + int t_system = Hobjects[iobj].getSystem(); double point_Phi = Hobjects[iobj].getCenterPoint().Phi(); double alpha_min, alpha_max; - if(t_slayer==0){ - if(point_Phi<TMath::PiOver2()){ - alpha_min = TMath::PiOver2(); + // Set range of alpha for Hough band. The range is different for different systems(Barrel/Endcap) and slayers(U/V) + // Barrel ECAL + if(t_system==Cyber::CaloUnit::System_Barrel){ + // U plane + if(t_slayer==0){ + alpha_min = 0; alpha_max = TMath::Pi(); } - else{ - alpha_min = 0; - alpha_max = TMath::PiOver2(); + // V plane + else{ + if( point_Phi < 5*TMath::Pi()/8. && point_Phi >= TMath::PiOver2() ){ + alpha_min = -0.1; + alpha_max = TMath::PiOver4(); + } + else if(point_Phi>3*TMath::Pi()/8. && point_Phi<TMath::PiOver2()){ + alpha_min = 7.*TMath::Pi()/4.; + alpha_max = 2*TMath::Pi(); + } + else{ + alpha_min = floor(4*point_Phi/TMath::Pi() - 1.5)*TMath::PiOver4() - TMath::PiOver4(); + alpha_max = floor(4*point_Phi/TMath::Pi() - 1.5)*TMath::PiOver4() + TMath::PiOver4(); + } + + if(alpha_min<=0 && alpha_max<=0){ + alpha_min += 2*TMath::Pi(); + alpha_max += 2*TMath::Pi(); + } } } + // Endcap ECAL + else if(t_system==Cyber::CaloUnit::System_Endcap){ + alpha_min = 0; + alpha_max = TMath::Pi(); + } else{ - if( point_Phi < 5*TMath::Pi()/8. && point_Phi >= TMath::PiOver2() ){ - alpha_min = -0.1; - alpha_max = TMath::PiOver4(); - } - else if(point_Phi>3*TMath::Pi()/8. && point_Phi<TMath::PiOver2()){ - alpha_min = 7.*TMath::Pi()/4.; - alpha_max = 2*TMath::Pi(); - } - else{ - alpha_min = floor(4*point_Phi/TMath::Pi() - 1.5)*TMath::PiOver4() - TMath::PiOver4(); - alpha_max = floor(4*point_Phi/TMath::Pi() - 1.5)*TMath::PiOver4() + TMath::PiOver4(); - } - - if(alpha_min<=0 && alpha_max<=0){ - alpha_min += 2*TMath::Pi(); - alpha_max += 2*TMath::Pi(); - } + cout << " HoughClusteringAlg: Unknown system ID: " << t_system << endl; + return StatusCode::FAILURE; } + // Create Hough lines. The range between TF1 line1("line1", "[0]*cos(x)+[1]*sin(x)", alpha_min, alpha_max); TF1 line2("line2", "[0]*cos(x)+[1]*sin(x)", alpha_min, alpha_max); - //TF1 line3("line3", "[0]*cos(x)+[1]*sin(x)", range34[0], range34[1]); - //TF1 line4("line4", "[0]*cos(x)+[1]*sin(x)", range34[0], range34[1]); - - if(t_slayer==0){ - line1.SetParameters( Hobjects[iobj].getUpperPoint().X(), Hobjects[iobj].getUpperPoint().Y() ); - line2.SetParameters( Hobjects[iobj].getLowerPoint().X(), Hobjects[iobj].getLowerPoint().Y() ); - //line3.SetParameters( Hobjects[iobj].getPointUL().X(), Hobjects[iobj].getPointUL().Y() ); - //line4.SetParameters( Hobjects[iobj].getPointDR().X(), Hobjects[iobj].getPointDR().Y() ); - } - else if(t_slayer==1){ - //if(t_module % 2 == 0){ - line1.SetParameters( Hobjects[iobj].getUpperPoint().X(), Hobjects[iobj].getUpperPoint().Y() ); - line2.SetParameters( Hobjects[iobj].getLowerPoint().X(), Hobjects[iobj].getLowerPoint().Y() ); - //line3.SetParameters( Hobjects[iobj].getPointUL().X(), Hobjects[iobj].getPointUL().Y() ); - //line4.SetParameters( Hobjects[iobj].getPointDR().X(), Hobjects[iobj].getPointDR().Y() ); - //}else{ - // line1.SetParameters( Hobjects[iobj].getPointU().X(), Hobjects[iobj].getPointU().Y() ); - // line2.SetParameters( Hobjects[iobj].getPointD().X(), Hobjects[iobj].getPointD().Y() ); - // line3.SetParameters( Hobjects[iobj].getPointL().X(), Hobjects[iobj].getPointL().Y() ); - // line4.SetParameters( Hobjects[iobj].getPointR().X(), Hobjects[iobj].getPointR().Y() ); - //} - } + + // Set the parameters of the lines. + line1.SetParameters( Hobjects[iobj].getUpperPoint().X(), Hobjects[iobj].getUpperPoint().Y() ); + line2.SetParameters( Hobjects[iobj].getLowerPoint().X(), Hobjects[iobj].getLowerPoint().Y() ); Hobjects[iobj].setHoughLine(line1, line2); - } - - return StatusCode::SUCCESS; -} // HoughTransformation() end - -/* -StatusCode HoughClusteringAlg::SetLineRange(int module, int slayer, double *range12, double* range34){ - // range12: ur, dl, u, d - // range34: ul, dr, l, r - if(slayer == 0){ - range12[0] = 0.; - range12[1] = TMath::Pi()/2.; - range34[0] = TMath::Pi()/2.; - range34[1] = TMath::Pi(); - } - else if(slayer == 1){ - switch(module){ - case 0:{ - range12[0] = -0.1; - range12[1] = TMath::Pi()/4.; - range34[0] = 7.*TMath::Pi()/4.; - range34[1] = range34[0] + TMath::Pi()/4.; - break; - } - case 1:{ - range12[0] = TMath::Pi()/4.; - range12[1] = range12[0] + TMath::Pi()/4.; - range34[0] = 0; - range34[1] = range34[0] + TMath::Pi()/4.; - break; - } - case 2:{ - range12[0] = TMath::Pi()/4.; - range12[1] = range12[0] + TMath::Pi()/4.; - range34[0] = TMath::Pi()/2; - range34[1] = range34[0] + TMath::Pi()/4.; - break; - } - case 3:{ - range12[0] = TMath::Pi()/2.; - range12[1] = range12[0] + TMath::Pi()/4.; - range34[0] = 3.*TMath::Pi()/4.; - range34[1] = range34[0] + TMath::Pi()/4.; - break; - } - case 4:{ - range12[0] = TMath::Pi(); - range12[1] = range12[0] + TMath::Pi()/4.; - range34[0] = 3.*TMath::Pi()/4.; - range34[1] = range34[0] + TMath::Pi()/4.; - break; - } - case 5:{ - range12[0] = 5.*TMath::Pi()/4.; - range12[1] = range12[0] + TMath::Pi()/4.; - range34[0] = TMath::Pi(); - range34[1] = range34[0] + TMath::Pi()/4.; - break; - } - case 6:{ - range12[0] = 5.*TMath::Pi()/4.; - range12[1] = range12[0] + TMath::Pi()/4.; - range34[0] = 3.*TMath::Pi()/2.; - range34[1] = range34[0] + TMath::Pi()/4.; - break; - } - case 7:{ - range12[0] = 3.*TMath::Pi()/2.; - range12[1] = range12[0] + TMath::Pi()/4.; - range34[0] = 7.*TMath::Pi()/4.; - range34[1] = range34[0] + TMath::Pi()/4.; - break; - } - default:{ - cout << "Wrong module: module = " << module << endl; - } - } - } + //cout << " yyy: HoughTransformation: HoughObject " << iobj << " has been transformed." << endl; + //cout << " alpha_min: " << alpha_min << " alpha_max: " << alpha_max << endl; + //cout << " line1: " << line1.GetParameter(0) << " " << line1.GetParameter(1) << endl; + //cout << " line2: " << line2.GetParameter(0) << " " << line2.GetParameter(1) << endl; + } return StatusCode::SUCCESS; -} // SetLineRange() end -*/ +} StatusCode HoughClusteringAlg::FillHoughSpace(vector<Cyber::HoughObject>& Hobjects, Cyber::HoughSpace& Hspace){ - - // Fill Hough space - // Loop Hough objects for(int ih=0; ih<Hobjects.size(); ih++){ TF1 line1 = Hobjects[ih].getHoughLine1(); TF1 line2 = Hobjects[ih].getHoughLine2(); - //TF1 line3 = Hobjects[ih].getHoughLine3(); - //TF1 line4 = Hobjects[ih].getHoughLine4(); - // line1 and line2 share the same range in alpha, so does line3 and line4 double range_min, range_max; line1.GetRange(range_min, range_max); // Get bin num in alpha axis int bin_min = Hspace.getAlphaBin(range_min); int bin_max = Hspace.getAlphaBin(range_max); - //int bin_34_min = Hspace.getAlphaBin(range_34_min); - //int bin_34_max = Hspace.getAlphaBin(range_34_max); - //if (bin_12_max == bin_34_min) bin_34_min ++; - //if (bin_34_max == bin_12_min) bin_12_min ++; - // Loop for alpha bins, line1 and line2 for(int ialpha=bin_min; ialpha<=bin_max; ialpha++) { @@ -575,41 +674,12 @@ StatusCode HoughClusteringAlg::FillHoughSpace(vector<Cyber::HoughObject>& Hobjec for(int irho=nbin_rho_min; irho<=nbin_rho_max; irho++){ Hspace.AddBinHobj(ialpha, irho, ih); } - } // end loop alpha bin, line1 and line2 -/* // Loop for alpha bins, line3 and line4 - for(int ialpha=bin_34_min; ialpha<=bin_34_max; ialpha++) { - // The lines should be monotone at this range - double line3_rho1 = line3.Eval( Hspace.getAlphaBinLowEdge(ialpha) ); - double line3_rho2 = line3.Eval( Hspace.getAlphaBinUpEdge(ialpha) ); - double line4_rho1 = line4.Eval( Hspace.getAlphaBinLowEdge(ialpha) ); - double line4_rho2 = line4.Eval( Hspace.getAlphaBinUpEdge(ialpha) ); - - double line3_rho_min = TMath::Min(line3_rho1, line3_rho2); - double line3_rho_max = TMath::Max(line3_rho1, line3_rho2);; - double line4_rho_min = TMath::Min(line4_rho1, line4_rho2); - double line4_rho_max = TMath::Max(line4_rho1, line4_rho2); + } - if(line3_rho_min>line3_rho_max || line4_rho_min>line4_rho_max){ - cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; - } - - double rho_min = TMath::Min( line3_rho_min, line4_rho_min); - double rho_max = TMath::Max( line3_rho_max, line4_rho_max); - - if(rho_max<settings.map_floatPars["rho_low"] || rho_min>settings.map_floatPars["rho_high"]) continue; - - int nbin_rho_min = TMath::Max( int(ceil( (rho_min-settings.map_floatPars["rho_low"]) / settings.map_floatPars["bin_width_rho"] )), 1 ); - int nbin_rho_max = TMath::Min( int(ceil( (rho_max-settings.map_floatPars["rho_low"]) / settings.map_floatPars["bin_width_rho"] )), settings.map_intPars["Nbins_rho"] ); - - for(int irho=nbin_rho_min; irho<=nbin_rho_max; irho++){ - Hspace.AddBinHobj(ialpha, irho, ih); - } - } // end loop alpha bin, line3 and line4 -*/ - } // End loop Hough objects + } return StatusCode::SUCCESS; -} // FillHoughSpace() end +} StatusCode HoughClusteringAlg::ClusterFinding(vector<Cyber::HoughObject>& Hobjects, Cyber::HoughSpace& Hspace, @@ -711,7 +781,7 @@ StatusCode HoughClusteringAlg::CleanClusters( std::vector<std::shared_ptr<Cyber: } } - // Remove repeated tracks + // Remove repeated axes for(int ic=0; ic<m_longiClusCol.size(); ic++){ for(int jc=0; jc<m_longiClusCol.size(); jc++){ if(ic>=m_longiClusCol.size()) ic--; @@ -735,31 +805,31 @@ StatusCode HoughClusteringAlg::CleanClusters( std::vector<std::shared_ptr<Cyber: } // Overlap with other clusters: - if(m_longiClusCol.size()>=2){ - for(int ic=0; ic<m_longiClusCol.size()-1; ic++){ - for(int jc=ic+1; jc<m_longiClusCol.size(); jc++){ - if(ic>=m_longiClusCol.size()) ic--; - - double delta_alpha = TMath::Abs(m_longiClusCol[ic].get()->getHoughAlpha() - m_longiClusCol[jc].get()->getHoughAlpha()); - if( (delta_alpha > settings.map_floatPars["th_dAlpha1"]) - && (delta_alpha < 2*TMath::Pi()-settings.map_floatPars["th_dAlpha1"]) ) continue; - - double m_ratio1 = m_longiClusCol[ic].get()->OverlapRatioE(m_longiClusCol[jc].get()); - double m_ratio2 = m_longiClusCol[jc].get()->OverlapRatioE(m_longiClusCol[ic].get()); - - if(m_ratio1>settings.map_floatPars["th_overlapE"] && m_longiClusCol[ic].get()->getEnergy()<m_longiClusCol[jc].get()->getEnergy()){ - //delete m_longiClusCol[ic]; m_longiClusCol[ic] = NULL; - m_longiClusCol.erase( m_longiClusCol.begin()+ic ); - ic--; - break; - } + if(m_longiClusCol.size()>=2){ + for(int ic=0; ic<m_longiClusCol.size()-1; ic++){ + for(int jc=ic+1; jc<m_longiClusCol.size(); jc++){ + if(ic>=m_longiClusCol.size()) ic--; - if(m_ratio2>settings.map_floatPars["th_overlapE"] && m_longiClusCol[jc].get()->getEnergy()<m_longiClusCol[ic].get()->getEnergy()){ - //delete m_longiClusCol[jc]; m_longiClusCol[jc] = NULL; - m_longiClusCol.erase( m_longiClusCol.begin()+jc ); - jc--; - } - }} + double delta_alpha = TMath::Abs(m_longiClusCol[ic].get()->getHoughAlpha() - m_longiClusCol[jc].get()->getHoughAlpha()); + if( (delta_alpha > settings.map_floatPars["th_dAlpha1"]) + && (delta_alpha < 2*TMath::Pi()-settings.map_floatPars["th_dAlpha1"]) ) continue; + + double m_ratio1 = m_longiClusCol[ic].get()->OverlapRatioE(m_longiClusCol[jc].get()); + double m_ratio2 = m_longiClusCol[jc].get()->OverlapRatioE(m_longiClusCol[ic].get()); + + if(m_ratio1>settings.map_floatPars["th_overlapE"] && m_longiClusCol[ic].get()->getEnergy()<m_longiClusCol[jc].get()->getEnergy()){ + //delete m_longiClusCol[ic]; m_longiClusCol[ic] = NULL; + m_longiClusCol.erase( m_longiClusCol.begin()+ic ); + ic--; + break; + } + + if(m_ratio2>settings.map_floatPars["th_overlapE"] && m_longiClusCol[jc].get()->getEnergy()<m_longiClusCol[ic].get()->getEnergy()){ + //delete m_longiClusCol[jc]; m_longiClusCol[jc] = NULL; + m_longiClusCol.erase( m_longiClusCol.begin()+jc ); + jc--; + } + }} } // If two cluster are close to each other, and E_small/E_large < threshold, delete the small ones @@ -789,6 +859,6 @@ StatusCode HoughClusteringAlg::CleanClusters( std::vector<std::shared_ptr<Cyber: } return StatusCode::SUCCESS; -} // CleanClusters() end +} #endif diff --git a/Reconstruction/RecPFACyber/src/Algorithm/LocalMaxFindingAlg.cpp b/Reconstruction/RecPFACyber/src/Algorithm/LocalMaxFindingAlg.cpp index 2c2968c2b056074dd32e13df2e4dc458fbff26e3..2adf2b98de56694701681156b2f981e160b6b0d7 100644 --- a/Reconstruction/RecPFACyber/src/Algorithm/LocalMaxFindingAlg.cpp +++ b/Reconstruction/RecPFACyber/src/Algorithm/LocalMaxFindingAlg.cpp @@ -42,6 +42,7 @@ StatusCode LocalMaxFindingAlg::RunAlgorithm( CyberDataCol& m_datacol){ m_datacol.map_1DCluster["bk1DCluster"].push_back(iter); } p_HalfClusU->at(iu).get()->setLocalMax(settings.map_stringPars["OutputLocalMaxName"], tmp_localMax); +//printf(" HalfClusterU #%d: energy %.3f, localMax size %d \n", iu, p_HalfClusU->at(iu).get()->getEnergy(), tmp_localMax.size()); m_1dClusCol.clear(); ptr_localMax.clear(); } @@ -59,6 +60,7 @@ StatusCode LocalMaxFindingAlg::RunAlgorithm( CyberDataCol& m_datacol){ m_datacol.map_1DCluster["bk1DCluster"].push_back(iter); } p_HalfClusV->at(iv).get()->setLocalMax(settings.map_stringPars["OutputLocalMaxName"], tmp_localMax); +//printf(" HalfClusterV #%d: energy %.3f, localMax size %d \n", iv, p_HalfClusV->at(iv).get()->getEnergy(), tmp_localMax.size()); m_1dClusCol.clear(); ptr_localMax.clear(); } @@ -127,22 +129,36 @@ StatusCode LocalMaxFindingAlg::GetLocalMaxBar( std::vector<const Cyber::CaloUnit std::vector<const Cyber::CaloUnit*> LocalMaxFindingAlg::getNeighbors( const Cyber::CaloUnit* seed, std::vector<const Cyber::CaloUnit*>& barCol){ std::vector<const Cyber::CaloUnit*> m_neighbor; m_neighbor.clear(); for(int i=0;i<barCol.size();i++){ - bool fl_neighbor = false; - if( seed->getModule()==barCol[i]->getModule() && - seed->getStave()==barCol[i]->getStave() && - seed->getDlayer()==barCol[i]->getDlayer() && - seed->getSlayer()==barCol[i]->getSlayer() && - abs( seed->getBar()-barCol[i]->getBar() )==1 ) fl_neighbor=true; - else if( seed->getStave()==barCol[i]->getStave() && - ( ( seed->getModule()-barCol[i]->getModule()==1 && seed->isAtLowerEdgePhi() && barCol[i]->isAtUpperEdgePhi() ) || - ( barCol[i]->getModule()-seed->getModule()==1 && seed->isAtUpperEdgePhi() && barCol[i]->isAtLowerEdgePhi() ) ) ) fl_neighbor=true; - else if( seed->getModule()==barCol[i]->getModule() && - ( ( seed->getStave()-barCol[i]->getStave()==1 && seed->isAtLowerEdgeZ() && barCol[i]->isAtUpperEdgeZ() ) || - ( barCol[i]->getStave()-seed->getStave()==1 && seed->isAtUpperEdgeZ() && barCol[i]->isAtLowerEdgeZ() ) ) ) fl_neighbor=true; - - if(fl_neighbor) m_neighbor.push_back(barCol[i]); + //bool fl_neighbor = false; + //if( seed->getSystem()==barCol[i]->getSystem() && + // seed->getModule()==barCol[i]->getModule() && + // seed->getStave()==barCol[i]->getStave() && + // seed->getDlayer()==barCol[i]->getDlayer() && + // seed->getSlayer()==barCol[i]->getSlayer() && + // abs( seed->getBar()-barCol[i]->getBar() )==1 ) fl_neighbor=true; + //else if( seed->getSystem()==barCol[i]->getSystem() && seed->getStave()==barCol[i]->getStave() && + // ( ( seed->getModule()-barCol[i]->getModule()==1 && seed->isAtLowerEdgePhi() && barCol[i]->isAtUpperEdgePhi() ) || + // ( barCol[i]->getModule()-seed->getModule()==1 && seed->isAtUpperEdgePhi() && barCol[i]->isAtLowerEdgePhi() ) ) ) fl_neighbor=true; + //else if( seed->getSystem()==barCol[i]->getSystem() && seed->getModule()==barCol[i]->getModule() && + // ( ( seed->getStave()-barCol[i]->getStave()==1 && seed->isAtLowerEdgeZ() && barCol[i]->isAtUpperEdgeZ() ) || + // ( barCol[i]->getStave()-seed->getStave()==1 && seed->isAtUpperEdgeZ() && barCol[i]->isAtLowerEdgeZ() ) ) ) fl_neighbor=true; + + bool fl_neighbor = seed->isNeighbor( barCol[i] ); + if(fl_neighbor){ + if(seed->getSystem()==CaloUnit::System_Barrel && seed->getSlayer()==0 && seed->getModule()!=barCol[i]->getModule()) continue; + if(seed->getSystem()==CaloUnit::System_Barrel && seed->getSlayer()==1 && seed->getStave()!=barCol[i]->getStave()) continue; + if(seed->getSystem()==CaloUnit::System_Endcap && seed->getSlayer()==0 && seed->getPart()!=barCol[i]->getPart() ) continue; + if(seed->getSystem()==CaloUnit::System_Endcap && seed->getSlayer()==1 && seed->getStave()!=barCol[i]->getStave() ) continue; + m_neighbor.push_back(barCol[i]); + } + } + if(m_neighbor.size()>2){ + std::cout<<"WARNING: "<<m_neighbor.size()<<" hits in neighborCol!!"<<std::endl; + printf("Seed cellID: ( %d, %d, %d, %d, %d, %d, %d), position (%.3f, %.3f, %.3f) \n", seed->getSystem(), seed->getModule(), seed->getStave(), seed->getPart(), seed->getDlayer(), seed->getSlayer(), seed->getBar(), seed->getPosition().x(), seed->getPosition().y(), seed->getPosition().z()); + for(int i=0; i<m_neighbor.size(); i++) + printf("Bar #%d cellID: ( %d, %d, %d, %d, %d, %d, %d), position (%.3f, %.3f, %.3f) \n", i, m_neighbor[i]->getSystem(), m_neighbor[i]->getModule(), m_neighbor[i]->getStave(), m_neighbor[i]->getPart(), m_neighbor[i]->getDlayer(), m_neighbor[i]->getSlayer(), m_neighbor[i]->getBar(), m_neighbor[i]->getPosition().x(), m_neighbor[i]->getPosition().y(), m_neighbor[i]->getPosition().z()); + } - if(m_neighbor.size()>2) std::cout<<"WARNING: more than 2 hits in neighborCol!!"<<std::endl; return m_neighbor; } diff --git a/Reconstruction/RecPFACyber/src/Algorithm/PFOReclusteringAlg.cpp b/Reconstruction/RecPFACyber/src/Algorithm/PFOReclusteringAlg.cpp index c87a00bc8bad9ea6b46c0d1a3f600c25e440b165..996c56e3d4ffda6fbfbcd6bafe2da4bbd5f1aae0 100644 --- a/Reconstruction/RecPFACyber/src/Algorithm/PFOReclusteringAlg.cpp +++ b/Reconstruction/RecPFACyber/src/Algorithm/PFOReclusteringAlg.cpp @@ -68,7 +68,6 @@ StatusCode PFOReclusteringAlg::RunAlgorithm( CyberDataCol& m_datacol ){ // } // cout<<"-----Charged cluster Ecal total energy: "<<totE_Ecal<<", Hcal total energy: "<<totE_Hcal<<endl; - //If P_trk > E_cluster, merge nearby neutral PFO into the charged. ReCluster_MergeToChg(m_chargedPFOs, m_neutralPFOs); @@ -523,7 +522,7 @@ StatusCode PFOReclusteringAlg::ReCluster_SplitFromChg( std::vector< std::shared_ std::shared_ptr<Cyber::Calo2DCluster> m_2dclus = std::make_shared<Cyber::Calo2DCluster>(); m_2dclus->addShowerU(m_1dclus_u.get()); m_2dclus->addShowerV(m_1dclus_v.get()); - m_2dclus->addTowerID(0., 0., 0.); + m_2dclus->addTowerID(0., 0., 0., 0.); m_2dclus->setPos(tmp_pos); // -- Create Half cluster U/V diff --git a/Reconstruction/RecPFACyber/src/Algorithm/TrackClusterConnectingAlg.cpp b/Reconstruction/RecPFACyber/src/Algorithm/TrackClusterConnectingAlg.cpp index c4a6864749f231b7919c72ed556d389227d11e28..853fda17f6a3aba5756aa78c0f928775dd0f56ee 100644 --- a/Reconstruction/RecPFACyber/src/Algorithm/TrackClusterConnectingAlg.cpp +++ b/Reconstruction/RecPFACyber/src/Algorithm/TrackClusterConnectingAlg.cpp @@ -48,18 +48,18 @@ StatusCode TrackClusterConnectingAlg::Initialize( CyberDataCol& m_datacol ){ } m_bkCol.EnergyCorrSvc = m_datacol.EnergyCorrSvc; - -//cout<<"Readin Track size: "<<m_tracks.size()<<", ECAL cluster size: "<<m_EcalClusters.size()<<", HCAL cluster size "<<m_HcalClusters.size()<<endl; -//cout<<"Print track"<<endl; -//for(int i=0; i<m_tracks.size(); i++) -// cout<<"Track #"<<i<<": P = "<<m_tracks[i]->getMomentum()<<", Pt = "<<m_tracks[i]->getPt()<<endl; -//cout<<"Print all ECAL cluster "<<endl; -//for(int ic=0; ic<m_EcalClusters.size(); ic++){ -// cout<<" ECAL Cluster #"<<ic<<": En = "<<m_EcalClusters[ic]->getLongiE()<<", track size "<<m_EcalClusters[ic]->getAssociatedTracks().size(); -// if(m_EcalClusters[ic]->getAssociatedTracks().size()>0) cout<<", Leading track P = "<<m_EcalClusters[ic]->getAssociatedTracks()[0]->getMomentum()<<endl; -// else cout<<endl; -//} - +/* +cout<<"Readin Track size: "<<m_tracks.size()<<", ECAL cluster size: "<<m_EcalClusters.size()<<", HCAL cluster size "<<m_HcalClusters.size()<<endl; +cout<<"Print track"<<endl; +for(int i=0; i<m_tracks.size(); i++) + cout<<"Track #"<<i<<": P = "<<m_tracks[i]->getMomentum()<<", Pt = "<<m_tracks[i]->getPt()<<endl; +cout<<"Print all ECAL cluster "<<endl; +for(int ic=0; ic<m_EcalClusters.size(); ic++){ + cout<<" ECAL Cluster #"<<ic<<": En = "<<m_EcalClusters[ic]->getLongiE()<<", track size "<<m_EcalClusters[ic]->getAssociatedTracks().size(); + if(m_EcalClusters[ic]->getAssociatedTracks().size()>0) cout<<", Leading track P = "<<m_EcalClusters[ic]->getAssociatedTracks()[0]->getMomentum()<<endl; + else cout<<endl; +} +*/ return StatusCode::SUCCESS; }; @@ -107,6 +107,7 @@ StatusCode TrackClusterConnectingAlg::RunAlgorithm( CyberDataCol& m_datacol ){ //3. Add HCAL clusters into the PFObject. std::sort(m_PFObjects.begin(), m_PFObjects.end(), compTrkP); HcalExtrapolatingMatch(m_HcalClusters, m_PFObjects); + //cout<<" TrackClusterConnectingAlg: PFO size after HCAL matching: "<<m_PFObjects.size()<<endl; //for(int i=0; i<m_PFObjects.size(); i++){ // cout<<" PFO #"<<i<<": track size "<<m_PFObjects[i]->getTracks().size()<<", leading P "<<m_PFObjects[i]->getTrackMomentum(); diff --git a/Reconstruction/RecPFACyber/src/Algorithm/TrackExtrapolatingAlg.cpp b/Reconstruction/RecPFACyber/src/Algorithm/TrackExtrapolatingAlg.cpp index 8f0effa6889a74f139c3bcceedeffccd09c7bf2c..2f5639a730950f5ae292ab00a64cadc1720903fe 100644 --- a/Reconstruction/RecPFACyber/src/Algorithm/TrackExtrapolatingAlg.cpp +++ b/Reconstruction/RecPFACyber/src/Algorithm/TrackExtrapolatingAlg.cpp @@ -25,6 +25,11 @@ StatusCode TrackExtrapolatingAlg::ReadSettings(Settings& m_settings){ settings.map_floatPars["ECAL_layer_width"] = 10; if(settings.map_floatPars.find("ECAL_half_length")==settings.map_floatPars.end()) settings.map_floatPars["ECAL_half_length"] = 2900; + if(settings.map_floatPars.find("ECAL_endcap_zmin")==settings.map_floatPars.end()) + settings.map_floatPars["ECAL_endcap_zmin"] = 2930; + if(settings.map_floatPars.find("ECAL_endcap_zmax")==settings.map_floatPars.end()) + settings.map_floatPars["ECAL_endcap_zmax"] = 3230; // 2930+300 + // HCAL parameters if(settings.map_floatPars.find("HCAL_innermost_distance")==settings.map_floatPars.end()) settings.map_floatPars["HCAL_innermost_distance"] = 2140; @@ -38,6 +43,10 @@ StatusCode TrackExtrapolatingAlg::ReadSettings(Settings& m_settings){ settings.map_floatPars["HCAL_sensitive_distance"] = 22.81; // distance between sensitive material and front face of each layer if(settings.map_floatPars.find("HCAL_half_length")==settings.map_floatPars.end()) settings.map_floatPars["HCAL_half_length"] = 3230; + if(settings.map_floatPars.find("HCAL_endcap_zmin")==settings.map_floatPars.end()) + settings.map_floatPars["HCAL_endcap_zmin"] = 3260; + if(settings.map_floatPars.find("HCAL_endcap_zmax")==settings.map_floatPars.end()) + settings.map_floatPars["HCAL_endcap_zmax"] = 4575; // 3260 + (3455-2140) if(settings.map_intPars.find("Nmodule")==settings.map_intPars.end()) settings.map_intPars["Nmodule"] = 32; @@ -59,23 +68,23 @@ StatusCode TrackExtrapolatingAlg::Initialize( CyberDataCol& m_datacol ){ StatusCode TrackExtrapolatingAlg::RunAlgorithm( CyberDataCol& m_datacol ){ -//std::cout<<"---oooOO0OOooo--- Excuting TrackExtrapolatingAlg ---oooOO0OOooo---"<<std::endl; - std::vector<std::shared_ptr<Cyber::Track>>* p_tracks = &(m_datacol.TrackCol); - - std::vector<float> ECAL_layer_radius; // Layer radius from ECAL innermost distance to outermost distance; spacing: ECAL_layer_width/2 + // (Barrel) Layer radius from ECAL(HCAL) innermost distance to outermost distance; spacing: ECAL_layer_width/2 + std::vector<float> ECAL_layer_radius; std::vector<float> HCAL_layer_radius; GetLayerRadius(ECAL_layer_radius, HCAL_layer_radius); + // (Endcap) Layer z from ECAL innermost distance to outermost distance; spacing: ECAL_layer_width/2 + std::vector<float> ECAL_layer_z; + std::vector<float> HCAL_layer_z; + GetLayerZ(ECAL_layer_z, HCAL_layer_z); for(int itrk=0; itrk<p_tracks->size(); itrk++){ // Only tracks that reach ECAL should be processed. if(!IsReachECAL( p_tracks->at(itrk).get() )) continue; - // get track state at calorimeter Cyber::TrackState CALO_trk_state; GetTrackStateAtCalo(p_tracks->at(itrk).get(), CALO_trk_state); - - ExtrapolateByRadius(ECAL_layer_radius, HCAL_layer_radius, CALO_trk_state, p_tracks->at(itrk).get()); + Extrapolate(ECAL_layer_radius, ECAL_layer_z, HCAL_layer_radius, HCAL_layer_z, CALO_trk_state, p_tracks->at(itrk).get()); } // end loop tracks @@ -110,6 +119,24 @@ StatusCode TrackExtrapolatingAlg::GetLayerRadius(std::vector<float> & ECAL_layer return StatusCode::SUCCESS; } +StatusCode TrackExtrapolatingAlg::GetLayerZ(std::vector<float> & ECAL_layer_z, std::vector<float> & HCAL_layer_z){ + // ECAL + float tmp_ecal_z = settings.map_floatPars["ECAL_endcap_zmin"] + 0.5*settings.map_floatPars["ECAL_layer_width"]; + while(tmp_ecal_z < settings.map_floatPars["ECAL_endcap_zmax"]){ + ECAL_layer_z.push_back(tmp_ecal_z); + tmp_ecal_z += 0.5 * settings.map_floatPars["ECAL_layer_width"]; + } + + // HCAL + float tmp_hcal_z = settings.map_floatPars["HCAL_endcap_zmin"] + 0.5*settings.map_floatPars["HCAL_layer_width"]; + while(tmp_hcal_z < settings.map_floatPars["HCAL_endcap_zmax"]){ + HCAL_layer_z.push_back(tmp_hcal_z); + tmp_hcal_z += 0.5 * settings.map_floatPars["HCAL_layer_width"]; + } + + return StatusCode::SUCCESS; +} + // ...oooOO0OOooo......oooOO0OOooo......oooOO0OOooo... bool TrackExtrapolatingAlg::IsReachECAL(Cyber::Track * track){ @@ -129,10 +156,10 @@ bool TrackExtrapolatingAlg::IsReachECAL(Cyber::Track * track){ // The track has no track state at calorimeter return false; } - if( Abs(Abs(t_vec.Z())-settings.map_floatPars["ECAL_half_length"]) < 1.0 ){ - // The track escape from endcap - return false; - } + // if( Abs(Abs(t_vec.Z())-settings.map_floatPars["ECAL_half_length"]) < 1.0 ){ + // // The track escape from endcap + // return false; + // } return true; } @@ -156,7 +183,7 @@ bool TrackExtrapolatingAlg::IsReachECAL(Cyber::Track * track){ double rho = GetRho(IP_trk_state); double r_max = TMath::Sqrt(ref_point.X()*ref_point.X() + ref_point.Y()*ref_point.Y()) + rho*2; - if(r_max<settings.map_floatPars["ECAL_innermost_distance"]){ return false; } + // if(r_max<settings.map_floatPars["ECAL_innermost_distance"]){ return false; } return true; } @@ -199,18 +226,23 @@ StatusCode TrackExtrapolatingAlg::GetTrackStateAtCalo(Cyber::Track * track, // ...oooOO0OOooo......oooOO0OOooo......oooOO0OOooo... -StatusCode TrackExtrapolatingAlg::ExtrapolateByRadius( const std::vector<float> & ECAL_layer_radius, std::vector<float> & HCAL_layer_radius, - const Cyber::TrackState & CALO_trk_state, Cyber::Track* p_track){ +StatusCode TrackExtrapolatingAlg::Extrapolate( const std::vector<float> & ECAL_layer_radius, const std::vector<float> & ECAL_layer_z, + const std::vector<float> & HCAL_layer_radius, const std::vector<float> & HCAL_layer_z, + const Cyber::TrackState & CALO_trk_state, Cyber::Track* p_track){ // Extrapolate points to circles with specific radius float rho = GetRho(CALO_trk_state); TVector2 center = GetCenterOfCircle(CALO_trk_state, rho); float alpha0 = GetRefAlpha0(CALO_trk_state, center); - std::vector<float> ECAL_delta_phi = GetDeltaPhi(rho, center, alpha0, ECAL_layer_radius, CALO_trk_state); - std::vector<float> HCAL_delta_phi = GetDeltaPhi(rho, center, alpha0, HCAL_layer_radius, CALO_trk_state); + std::vector<float> ECAL_barrel_delta_phi, ECAL_endcap_delta_phi; + GetDeltaPhi(rho, center, alpha0, ECAL_layer_radius, ECAL_layer_z, CALO_trk_state, ECAL_barrel_delta_phi, ECAL_endcap_delta_phi); + std::vector<float> HCAL_barrel_delta_phi, HCAL_endcap_delta_phi; + GetDeltaPhi(rho, center, alpha0, HCAL_layer_radius, HCAL_layer_z, CALO_trk_state, HCAL_barrel_delta_phi, HCAL_endcap_delta_phi); - std::vector<TVector3> ECAL_ext_points = GetExtrapoPoints("ECAL", rho, center, alpha0, CALO_trk_state, ECAL_delta_phi); - std::vector<TVector3> HCAL_ext_points = GetExtrapoPoints("HCAL", rho, center, alpha0, CALO_trk_state, HCAL_delta_phi); + std::vector<TVector3> ECAL_ext_points = GetExtrapoPoints("ECAL", rho, center, alpha0, CALO_trk_state, + ECAL_barrel_delta_phi, ECAL_endcap_delta_phi); + std::vector<TVector3> HCAL_ext_points = GetExtrapoPoints("HCAL", rho, center, alpha0, CALO_trk_state, + HCAL_barrel_delta_phi, HCAL_endcap_delta_phi); // Sort Extrapolated points std::vector<TrackState> t_ECAL_states; @@ -271,9 +303,10 @@ float TrackExtrapolatingAlg::GetRefAlpha0(const Cyber::TrackState & trk_state, c // ...oooOO0OOooo......oooOO0OOooo......oooOO0OOooo... -std::vector<float> TrackExtrapolatingAlg::GetDeltaPhi(float rho, TVector2 center, float alpha0, vector<float> layer_radius, const Cyber::TrackState & CALO_trk_state){ - std::vector<float> delta_phi; - +StatusCode TrackExtrapolatingAlg::GetDeltaPhi(float rho, TVector2 center, float alpha0, +const std::vector<float> & layer_radius, const std::vector<float> & layer_z, const Cyber::TrackState & CALO_trk_state, +vector<float> & barrel_delta_phi, vector<float> & endcap_delta_phi){ + // Barrel for(int il=0; il<layer_radius.size(); il++){ float param0 = (Power(layer_radius[il], 2) - center.Mod2() - Power(rho, 2)) / (2 * rho * center.Mod()); if(Abs(param0)>1) continue; @@ -292,10 +325,10 @@ std::vector<float> TrackExtrapolatingAlg::GetDeltaPhi(float rho, TVector2 center while(layer_delta_phi2<-Pi()) layer_delta_phi2 = layer_delta_phi2 + 2*Pi(); if(CALO_trk_state.Kappa < 0){ - delta_phi.push_back(layer_delta_phi1); + barrel_delta_phi.push_back(layer_delta_phi1); } else if(CALO_trk_state.Kappa > 0){ - delta_phi.push_back(layer_delta_phi2); + barrel_delta_phi.push_back(layer_delta_phi2); } else{ std::cout << "TrackExtrapolatingAlg: Error! Kappa=0!" << std::endl; @@ -303,7 +336,24 @@ std::vector<float> TrackExtrapolatingAlg::GetDeltaPhi(float rho, TVector2 center } - return delta_phi; + // Endcap + float z0 = CALO_trk_state.referencePoint.Z() + CALO_trk_state.Z0; + for(int iz=0; iz<layer_z.size(); iz++){ + float layer_delta_phi = ( layer_z[iz] - z0 ) / ( rho * CALO_trk_state.tanLambda ); + + if(CALO_trk_state.Kappa < 0){ + endcap_delta_phi.push_back(layer_delta_phi); + } + else if(CALO_trk_state.Kappa > 0){ + endcap_delta_phi.push_back(-layer_delta_phi); + } + else{ + std::cout << "TrackExtrapolatingAlg: Error! Kappa=0!" << std::endl; + } + + } + + return StatusCode::SUCCESS; } @@ -311,33 +361,89 @@ std::vector<float> TrackExtrapolatingAlg::GetDeltaPhi(float rho, TVector2 center std::vector<TVector3> TrackExtrapolatingAlg::GetExtrapoPoints(std::string calo_name, float rho, TVector2 center, float alpha0, const Cyber::TrackState & CALO_trk_state, - const std::vector<float>& delta_phi){ - std::vector<TVector3> ext_points; - for(int ip=0; ip<delta_phi.size(); ip++){ - float x = center.X() + (rho*Cos(alpha0+delta_phi[ip])); - float y = center.Y() + (rho*Sin(alpha0+delta_phi[ip])); + const std::vector<float>& barrel_delta_phi, const std::vector<float>& endcap_delta_phi){ + std::vector<TVector3> barrel_ext_points; + for(int ip=0; ip<barrel_delta_phi.size(); ip++){ + float x = center.X() + (rho*Cos(alpha0+barrel_delta_phi[ip])); + float y = center.Y() + (rho*Sin(alpha0+barrel_delta_phi[ip])); float z; if(CALO_trk_state.Kappa > 0){ z = CALO_trk_state.referencePoint.Z() + CALO_trk_state.Z0 - - (delta_phi[ip]*rho*CALO_trk_state.tanLambda); + (barrel_delta_phi[ip]*rho*CALO_trk_state.tanLambda); }else{ z = CALO_trk_state.referencePoint.Z() + CALO_trk_state.Z0 + - (delta_phi[ip]*rho*CALO_trk_state.tanLambda); + (barrel_delta_phi[ip]*rho*CALO_trk_state.tanLambda); } - + TVector3 extp(x,y,z); + if(calo_name=="ECAL"){ - if(Abs(z)>settings.map_floatPars["ECAL_half_length"]) continue; - if(Sqrt(x*x+y*y) > settings.map_floatPars["ECAL_outermost_distance"]) continue; - if(Sqrt(x*x+y*y) < settings.map_floatPars["ECAL_innermost_distance"]) continue; + if( Abs(z)<settings.map_floatPars["ECAL_half_length"] && + Sqrt(x*x+y*y) < settings.map_floatPars["ECAL_outermost_distance"] && + Sqrt(x*x+y*y) > settings.map_floatPars["ECAL_innermost_distance"]){ + barrel_ext_points.push_back(extp); + } } else if(calo_name=="HCAL"){ - if(Abs(z)>settings.map_floatPars["HCAL_half_length"]) continue; - if(Sqrt(x*x+y*y) > settings.map_floatPars["HCAL_outermost_distance"]) continue; + if( Abs(z)<settings.map_floatPars["HCAL_half_length"] && + Sqrt(x*x+y*y) < settings.map_floatPars["HCAL_outermost_distance"] && + Sqrt(x*x+y*y) > settings.map_floatPars["HCAL_innermost_distance"]){ + barrel_ext_points.push_back(extp); + } } else continue; - + } + + std::vector<TVector3> endcap_ext_points; + for(int ip=0; ip<endcap_delta_phi.size(); ip++){ + float x = center.X() + (rho*Cos(alpha0+endcap_delta_phi[ip])); + float y = center.Y() + (rho*Sin(alpha0+endcap_delta_phi[ip])); + float z; + if(CALO_trk_state.Kappa > 0){ + z = CALO_trk_state.referencePoint.Z() + CALO_trk_state.Z0 - + (endcap_delta_phi[ip]*rho*CALO_trk_state.tanLambda); + }else{ + z = CALO_trk_state.referencePoint.Z() + CALO_trk_state.Z0 + + (endcap_delta_phi[ip]*rho*CALO_trk_state.tanLambda); + } TVector3 extp(x,y,z); - ext_points.push_back(extp); + + if(calo_name=="ECAL"){ + if( Abs(z)>settings.map_floatPars["ECAL_endcap_zmin"] && + Abs(z)<settings.map_floatPars["ECAL_endcap_zmax"] && + Sqrt(x*x+y*y) < settings.map_floatPars["ECAL_outermost_distance"]){ + endcap_ext_points.push_back(extp); + } + } + else if(calo_name=="HCAL"){ + if( Abs(z)>settings.map_floatPars["HCAL_endcap_zmin"] && + Abs(z)<settings.map_floatPars["HCAL_endcap_zmax"] && + Sqrt(x*x+y*y) < settings.map_floatPars["HCAL_outermost_distance"]){ + endcap_ext_points.push_back(extp); + } + } + else{ + std::cout << "TrackExtrapolatingAlg: Error! Wrong calorimeter name!" << std::endl; + } + } + + std::vector<TVector3> ext_points; + if(barrel_ext_points.size()>0 && endcap_ext_points.size()==0){ + ext_points = barrel_ext_points; + } + else if(barrel_ext_points.size()==0 && endcap_ext_points.size()>0){ + ext_points = endcap_ext_points; + } + else if(barrel_ext_points.size()>0 && endcap_ext_points.size()>0){ + ext_points = barrel_ext_points; + + float barrel_delta_z = TMath::Abs(barrel_ext_points[barrel_ext_points.size()-1].Z() - barrel_ext_points[barrel_ext_points.size()-2].Z()); + float endcap_barrel_delta_z = TMath::Abs(endcap_ext_points[0].Z() - barrel_ext_points[barrel_ext_points.size()-1].Z()); + if(endcap_barrel_delta_z < barrel_delta_z){ + ext_points.insert(ext_points.end(), endcap_ext_points.begin(), endcap_ext_points.end()); + } + } + else{ + std::cout << "TrackExtrapolatingAlg: Error! No extrapolated points!" << std::endl; } return ext_points; diff --git a/Reconstruction/RecPFACyber/src/Algorithm/TrackMatchingAlg.cpp b/Reconstruction/RecPFACyber/src/Algorithm/TrackMatchingAlg.cpp index 05ec8a4bd398c03a9a0e511929f8b7d7988eef9f..48b5c7f528a7914e5aefc65f468b3e1811edfc89 100644 --- a/Reconstruction/RecPFACyber/src/Algorithm/TrackMatchingAlg.cpp +++ b/Reconstruction/RecPFACyber/src/Algorithm/TrackMatchingAlg.cpp @@ -47,31 +47,28 @@ StatusCode TrackMatchingAlg::Initialize( CyberDataCol& m_datacol ){ StatusCode TrackMatchingAlg::RunAlgorithm( CyberDataCol& m_datacol ){ - std::cout << "---oooOO0OOooo---Excuting TrackMatchingAlg---oooOO0OOooo---"<<std::endl; + //std::cout << "---oooOO0OOooo---Excuting TrackMatchingAlg---oooOO0OOooo---"<<std::endl; // Associate tracks to HalfClusters. // This association is a many-to-many relationship: // One HalCluster may have multiple tracks; // One track may pass through multiple HalfClusters. -//cout<<"track size: "<<m_TrackCol.size()<<", HFClusterU size "<<p_HalfClusterU->size()<<", HFClusterV size "<<p_HalfClusterV->size()<<endl; + //cout<<"track size: "<<m_TrackCol.size()<<", HFClusterU size "<<p_HalfClusterU->size()<<", HFClusterV size "<<p_HalfClusterV->size()<<endl; + for(int itrk=0; itrk<m_TrackCol.size(); itrk++){ // loop tracks -//printf(" In track %d: Ptrack %.3f, track state size %d \n", itrk, m_TrackCol[itrk]->getMomentum(), m_TrackCol[itrk]->getTrackStates("Ecal").size()); if(m_TrackCol[itrk]->getTrackStates("Ecal").size()==0) continue; // Get extrapolated points of the track. These points are sorted by the track std::vector<TVector3> extrapo_points; GetExtrpoECALPoints(m_TrackCol[itrk], extrapo_points); -//printf(" In track %d: extrapolated point size %d \n", itrk, extrapo_points.size()); if(extrapo_points.size()==0) continue; double pT = TMath::Abs(1. / m_TrackCol[itrk]->getTrackStates("Ecal")[0].Kappa); if (pT >= settings.map_floatPars["ConeMatchingCut_pT"]){ -//std::cout << "For track " << itrk << ", pT = " << pT <<", match directly" << std::endl; - for(int ihc=0; ihc<p_HalfClusterV->size(); ihc++){ // loop HalfClusterV // Get local max of the HalfCluster std::vector<const Cyber::Calo1DCluster*> localMaxColV = p_HalfClusterV->at(ihc).get()->getLocalMaxCol(settings.map_stringPars["ReadinLocalMaxName"]); -//cout<<" In HalfClusterV #"<<ihc<<": localMax size "<<localMaxColV.size()<<endl; + // Track axis candidate. std::shared_ptr<Cyber::CaloHalfCluster> t_track_axis = std::make_shared<Cyber::CaloHalfCluster>(); CreateTrackAxis(extrapo_points, localMaxColV, t_track_axis.get()); @@ -79,7 +76,7 @@ StatusCode TrackMatchingAlg::RunAlgorithm( CyberDataCol& m_datacol ){ // If the track does not match the Halfcluster, the track axis candidate will have no 1DCluster if(t_track_axis->getCluster().size()==0) continue; -//cout<<" Created a track axis"<<endl; + t_track_axis->addAssociatedTrack(m_TrackCol[itrk]); t_track_axis->setType(10000); //Track-type axis. m_TrackCol[itrk]->addAssociatedHalfClusterV( p_HalfClusterV->at(ihc).get() ); @@ -90,7 +87,6 @@ StatusCode TrackMatchingAlg::RunAlgorithm( CyberDataCol& m_datacol ){ for(int ihc=0; ihc<p_HalfClusterU->size(); ihc++){ // loop HalfClusterU // Get local max of the HalfCluster std::vector<const Cyber::Calo1DCluster*> localMaxColU = p_HalfClusterU->at(ihc).get()->getLocalMaxCol(settings.map_stringPars["ReadinLocalMaxName"]); -//cout<<" In HalfClusterU #"<<ihc<<": localMax size "<<localMaxColU.size()<<endl; // Track axis candidate. std::shared_ptr<Cyber::CaloHalfCluster> t_track_axis = std::make_shared<Cyber::CaloHalfCluster>(); @@ -100,7 +96,6 @@ StatusCode TrackMatchingAlg::RunAlgorithm( CyberDataCol& m_datacol ){ if(t_track_axis->getCluster().size()==0) continue; -//cout<<" Created a track axis"<<endl; t_track_axis->addAssociatedTrack(m_TrackCol[itrk]); t_track_axis->setType(10000); //Track-type axis. m_TrackCol[itrk]->addAssociatedHalfClusterU( p_HalfClusterU->at(ihc).get() ); @@ -109,8 +104,6 @@ StatusCode TrackMatchingAlg::RunAlgorithm( CyberDataCol& m_datacol ){ } // end loop HalfClusterU } else{ // pT < settings.map_floatPars["ConeMatchingCut_pT"] -//std::cout << "For track " << itrk << ", pT = " << pT <<", using Cone method" << std::endl; - // Get local max and HalfCluster near the extrapolated points std::vector<Cyber::CaloHalfCluster*> t_nearbyHalfClustersV; t_nearbyHalfClustersV.clear(); std::vector<Cyber::CaloHalfCluster*> t_nearbyHalfClustersU; t_nearbyHalfClustersU.clear(); @@ -124,22 +117,6 @@ StatusCode TrackMatchingAlg::RunAlgorithm( CyberDataCol& m_datacol ){ LongiConeLinking(extrapo_points, t_nearbyLocalMaxV, t_cone_axisV); CreatConeAxis(m_datacol, m_TrackCol[itrk], t_nearbyHalfClustersV, t_cone_axisV); - // U plane - // Sort local max by their modules - //std::map<int, std::vector<const Cyber::Calo1DCluster*> > m_orderedLocalMaxU; // key: module of the bar - //m_orderedLocalMaxU.clear(); - //for(int is=0; is<t_nearbyLocalMaxU.size(); is++) - // m_orderedLocalMaxU[t_nearbyLocalMaxU[is]->getTowerID()[0][0]].push_back(t_nearbyLocalMaxU[is]); - //// linking - //std::vector<const Cyber::Calo1DCluster*> merged_cone_axisU; merged_cone_axisU.clear(); - //for (auto it = m_orderedLocalMaxU.begin(); it != m_orderedLocalMaxU.end(); ++it){ - // std::vector<const Cyber::Calo1DCluster*> moduled_localMaxU = it->second; - // std::vector<const Cyber::Calo1DCluster*> t_cone_axisU; t_cone_axisU.clear(); - // LongiConeLinking(extrapo_points, moduled_localMaxU, t_cone_axisU); - // merged_cone_axisU.insert(merged_cone_axisU.end(), t_cone_axisU.begin(), t_cone_axisU.end()); - //} - //CreatConeAxis(m_datacol, m_TrackCol[itrk], t_nearbyHalfClustersU, merged_cone_axisU); - // U plane std::vector<const Cyber::Calo1DCluster*> t_cone_axisU; t_cone_axisU.clear(); LongiConeLinking(extrapo_points, t_nearbyLocalMaxU, t_cone_axisU); @@ -147,9 +124,7 @@ StatusCode TrackMatchingAlg::RunAlgorithm( CyberDataCol& m_datacol ){ } - - - } // end loop tracks + } //Loop track to check the associated cluster: merge clusters if they are associated to the same track. std::vector<Cyber::CaloHalfCluster*> tmp_deleteClus; tmp_deleteClus.clear(); @@ -157,17 +132,8 @@ StatusCode TrackMatchingAlg::RunAlgorithm( CyberDataCol& m_datacol ){ std::vector<Cyber::CaloHalfCluster*> m_matchedUCol = itrk->getAssociatedHalfClustersU(); std::vector<Cyber::CaloHalfCluster*> m_matchedVCol = itrk->getAssociatedHalfClustersV(); - // std::cout << "yyy: Before merge, m_matchedVCol.size() = " << m_matchedVCol.size() << std::endl; for(int imc=0; imc<m_matchedVCol.size(); imc++){ - // std::cout<<" yyy: m_matchedVCol["<<imc<<"]->getCluster().size()="<<m_matchedVCol[imc]->getCluster().size()<<std::endl; - // std::cout<<" yyy: m_matchedVCol["<<imc<<"]->getAssociatedTracks().size()=" << m_matchedVCol[imc]->getAssociatedTracks().size() << std::endl; int N_trk_axis = m_matchedVCol[imc]->getHalfClusterMap()[settings.map_stringPars["OutputLongiClusName"]].size() ; - // std::cout<<" yyy: m_matchedVCol["<<imc<<"]->getHalfClusterMap()[TrackAxis].size()="<< N_trk_axis << std::endl; - for(int itk=0; itk<N_trk_axis; itk++){ - // std::cout<<" yyy: for TrackAxis " << itk - // << ", Nlm = " << m_matchedVCol[imc]->getHalfClusterMap()["TrackAxis"][itk]->getCluster().size() - // << ", N trk = " << m_matchedVCol[imc]->getHalfClusterMap()["TrackAxis"][itk]->getAssociatedTracks().size() << std::endl; - } } if( m_matchedUCol.size()>1 ){ @@ -183,20 +149,6 @@ StatusCode TrackMatchingAlg::RunAlgorithm( CyberDataCol& m_datacol ){ } } - ///////////////////////////////////////////// - // if(m_matchedVCol.size()>0){ - // // std::cout<<"yyy: After merge, m_matchedVCol[0]->getCluster().size()=" << m_matchedVCol[0]->getCluster().size() << std::endl; - // // std::cout<<"yyy: After merge, m_matchedVCol[0]->getAssociatedTracks().size()=" << m_matchedVCol[0]->getAssociatedTracks().size() << std::endl; - // int N_trk_axis = m_matchedVCol[0]->getHalfClusterMap()["TrackAxis"].size() ; - // // std::cout<<"yyy: After merge, m_matchedVCol[0]->getHalfClusterMap()[TrackAxis].size()="<< N_trk_axis << std::endl; - // for(int nn=0; nn<N_trk_axis; nn++){ - // std::cout<<"yyy: for TrackAxis " << nn - // << ", Nlm = " << m_matchedVCol[0]->getHalfClusterMap()["TrackAxis"][nn]->getCluster().size() - // << ", N trk = " << m_matchedVCol[0]->getHalfClusterMap()["TrackAxis"][nn]->getAssociatedTracks().size() << std::endl; - - // } - // } - ///////////////////////////////////////////// } //Check vector: clean the merged clusters @@ -214,7 +166,12 @@ StatusCode TrackMatchingAlg::RunAlgorithm( CyberDataCol& m_datacol ){ } } - +//for(int ic=0; ic<p_HalfClusterU->size(); ic++){ +//printf("HalfClusterU #%d: energy %.4f, track axis size %d \n", ic, p_HalfClusterU->at(ic)->getEnergy(), p_HalfClusterU->at(ic)->getHalfClusterCol(settings.map_stringPars["OutputLongiClusName"]).size() ); +//} +//for(int ic=0; ic<p_HalfClusterV->size(); ic++){ +//printf("HalfClusterV #%d: energy %.4f, track axis size %d \n", ic, p_HalfClusterV->at(ic)->getEnergy(), p_HalfClusterV->at(ic)->getHalfClusterCol(settings.map_stringPars["OutputLongiClusName"]).size() ); +//} return StatusCode::SUCCESS; } @@ -246,34 +203,67 @@ StatusCode TrackMatchingAlg::CreateTrackAxis(vector<TVector3>& extrapo_points, s if(localMaxCol.size()==0 || extrapo_points.size()==0) return StatusCode::SUCCESS; int t_slayer = localMaxCol[0]->getSlayer(); + int t_system = localMaxCol[0]->getSystem(); - if(t_slayer==1){ // V plane (xy plane) - for(int ipt=0; ipt<extrapo_points.size(); ipt++){ - for(int ilm=0; ilm<localMaxCol.size(); ilm++){ - // distance from the extrpolated point to the center of the local max bar - TVector3 distance = extrapo_points[ipt] - localMaxCol[ilm]->getPos(); - if( TMath::Abs(distance.Z()) < (localMaxCol[ilm]->getBars()[0]->getBarLength())/2. && - distance.Perp() < Cyber::CaloUnit::barsize ) { - t_track_axis->addUnit(localMaxCol[ilm]); - } - else { continue; } - }} + if(t_system==Cyber::CaloUnit::System_Barrel){ // Barrel + if(t_slayer==1){ // V plane (xy plane) + for(int ipt=0; ipt<extrapo_points.size(); ipt++){ + for(int ilm=0; ilm<localMaxCol.size(); ilm++){ + // distance from the extrpolated point to the center of the local max bar + TVector3 distance = extrapo_points[ipt] - localMaxCol[ilm]->getPos(); + if( TMath::Abs(distance.Z()) < (localMaxCol[ilm]->getBars()[0]->getBarLength())/2. && + distance.Perp() < Cyber::CaloUnit::barsize ) { + t_track_axis->addUnit(localMaxCol[ilm]); + } + else { continue; } + }} + } + else{ // U plane (r-phi plane) + for(int ipt=0; ipt<extrapo_points.size(); ipt++){ + for(int ilm=0; ilm<localMaxCol.size(); ilm++){ + TVector3 lm_pos = localMaxCol[ilm]->getPos(); + float barLength = localMaxCol[ilm]->getBars()[0]->getBarLength(); + if( fabs(extrapo_points[ipt].z()-lm_pos.z()) < Cyber::CaloUnit::barsize && + fabs(extrapo_points[ipt].Phi()-lm_pos.Phi()) < barLength/2./Cyber::CaloUnit::ecal_innerR && + fabs(extrapo_points[ipt].Perp()-lm_pos.Perp()) < Cyber::CaloUnit::barsize ){ + t_track_axis->addUnit(localMaxCol[ilm]); + } + else { continue; } + }} + } } - else{ // U plane (r-phi plane) - for(int ipt=0; ipt<extrapo_points.size(); ipt++){ - for(int ilm=0; ilm<localMaxCol.size(); ilm++){ - TVector3 lm_pos = localMaxCol[ilm]->getPos(); - float barLength = localMaxCol[ilm]->getBars()[0]->getBarLength(); - if( fabs(extrapo_points[ipt].z()-lm_pos.z()) < Cyber::CaloUnit::barsize && - fabs(extrapo_points[ipt].Phi()-lm_pos.Phi()) < barLength/2./Cyber::CaloUnit::ecal_innerR && - fabs(extrapo_points[ipt].Perp()-lm_pos.Perp()) < Cyber::CaloUnit::barsize ){ - t_track_axis->addUnit(localMaxCol[ilm]); - } - else { continue; } - }} + else if(t_system==Cyber::CaloUnit::System_Endcap){ // Endcap + if(t_slayer==0){ // U plane + for(int ipt=0; ipt<extrapo_points.size(); ipt++){ + for(int ilm=0; ilm<localMaxCol.size(); ilm++){ + TVector3 lm_pos = localMaxCol[ilm]->getPos(); + float barLength = localMaxCol[ilm]->getBars()[0]->getBarLength(); + TVector3 distance = extrapo_points[ipt] - lm_pos; + if( fabs(distance.z()) < Cyber::CaloUnit::barsize && + fabs(distance.x()) < Cyber::CaloUnit::barsize && + fabs(distance.y()) < barLength/2.){ + t_track_axis->addUnit(localMaxCol[ilm]); + } + else { continue; } + }} + } + else{ // V plane + for(int ipt=0; ipt<extrapo_points.size(); ipt++){ + for(int ilm=0; ilm<localMaxCol.size(); ilm++){ + TVector3 lm_pos = localMaxCol[ilm]->getPos(); + float barLength = localMaxCol[ilm]->getBars()[0]->getBarLength(); + TVector3 distance = extrapo_points[ipt] - lm_pos; + if( fabs(distance.z()) < Cyber::CaloUnit::barsize && + fabs(distance.y()) < Cyber::CaloUnit::barsize && + fabs(distance.x()) < barLength/2.){ + t_track_axis->addUnit(localMaxCol[ilm]); + } + else { continue; } + }} + } } + -//std::cout << "end calling CreateTrackAxis()" << std::endl; return StatusCode::SUCCESS; } @@ -282,46 +272,73 @@ StatusCode TrackMatchingAlg::GetNearby(const std::vector<std::shared_ptr<Cyber:: const std::vector<TVector3>& extrapo_points, std::vector<Cyber::CaloHalfCluster*>& t_nearbyHalfClusters, std::vector<const Cyber::Calo1DCluster*>& t_nearbyLocalMax){ - // std::cout << "calling TrackMatchingAlg::GetNearby()" << std::endl; + if(p_HalfCluster->size()==0 || extrapo_points.size()==0) return StatusCode::SUCCESS; std::set<Cyber::CaloHalfCluster*> set_nearbyHalfClusters; int slayer = p_HalfCluster->at(0).get()->getSlayer(); + if(slayer==1){ // V plane for(int ihc=0; ihc<p_HalfCluster->size(); ihc++){ + int system = p_HalfCluster->at(ihc).get()->getBars()[0]->getSystem(); std::vector<const Cyber::Calo1DCluster*> localMaxCol = p_HalfCluster->at(ihc).get()->getLocalMaxCol(settings.map_stringPars["ReadinLocalMaxName"]); +//cout<<" HFclus #"<<ihc<<": system "<<system<<", localMax size "<<localMaxCol.size()<<endl; for(int ilm=0; ilm<localMaxCol.size(); ilm++){ for(int ipt=0; ipt<extrapo_points.size(); ipt++){ TVector3 distance(extrapo_points[ipt] - localMaxCol[ilm]->getPos()); - if(TMath::Abs(distance.Z()) < (localMaxCol[ilm]->getBars()[0]->getBarLength())/2. && - distance.Perp() < settings.map_floatPars["ConeNearByDistance"] ){ - t_nearbyLocalMax.push_back(localMaxCol[ilm]); - set_nearbyHalfClusters.insert(p_HalfCluster->at(ihc).get()); - break; + float barLength = localMaxCol[ilm]->getBars()[0]->getBarLength(); + if(system==Cyber::CaloUnit::System_Barrel){ // Barrel + if(TMath::Abs(distance.Z()) < barLength/2. && + distance.Perp() < settings.map_floatPars["ConeNearByDistance"] ){ + t_nearbyLocalMax.push_back(localMaxCol[ilm]); + set_nearbyHalfClusters.insert(p_HalfCluster->at(ihc).get()); + break; + } + } + else if(system==Cyber::CaloUnit::System_Endcap){ + if( TMath::Sqrt(distance.z()*distance.z() + distance.y()*distance.y()) < settings.map_floatPars["ConeNearByDistance"] && + fabs(distance.x()) < barLength/2.){ + t_nearbyLocalMax.push_back(localMaxCol[ilm]); + set_nearbyHalfClusters.insert(p_HalfCluster->at(ihc).get()); + break; + } } }} - } - }else{ // U plane + } + else if(slayer==0){ for(int ihc=0; ihc<p_HalfCluster->size(); ihc++){ + int system = p_HalfCluster->at(ihc).get()->getBars()[0]->getSystem(); std::vector<const Cyber::Calo1DCluster*> localMaxCol = p_HalfCluster->at(ihc).get()->getLocalMaxCol(settings.map_stringPars["ReadinLocalMaxName"]); +//cout<<" HFclus #"<<ihc<<": system "<<system<<", localMax size "<<localMaxCol.size()<<endl; for(int ilm=0; ilm<localMaxCol.size(); ilm++){ for(int ipt=0; ipt<extrapo_points.size(); ipt++){ TVector3 lm_pos = localMaxCol[ilm]->getPos(); float barLength = localMaxCol[ilm]->getBars()[0]->getBarLength(); - if( fabs(extrapo_points[ipt].z()-lm_pos.z()) < settings.map_floatPars["ConeNearByDistance"] && - fabs(extrapo_points[ipt].Phi()-lm_pos.Phi()) < barLength/2./Cyber::CaloUnit::ecal_innerR && - fabs(extrapo_points[ipt].Perp()-lm_pos.Perp()) < settings.map_floatPars["ConeNearByDistance"] ){ - t_nearbyLocalMax.push_back(localMaxCol[ilm]); - set_nearbyHalfClusters.insert(p_HalfCluster->at(ihc).get()); - break; + TVector3 distance = extrapo_points[ipt] - lm_pos; + if(system==Cyber::CaloUnit::System_Barrel){ // Barrel + if( fabs(extrapo_points[ipt].z()-lm_pos.z()) < settings.map_floatPars["ConeNearByDistance"] && + fabs(extrapo_points[ipt].Phi()-lm_pos.Phi()) < barLength/2./Cyber::CaloUnit::ecal_innerR && + fabs(extrapo_points[ipt].Perp()-lm_pos.Perp()) < settings.map_floatPars["ConeNearByDistance"] ){ + t_nearbyLocalMax.push_back(localMaxCol[ilm]); + set_nearbyHalfClusters.insert(p_HalfCluster->at(ihc).get()); + break; + } + } + else if(system==Cyber::CaloUnit::System_Endcap){ + if( TMath::Sqrt(distance.z()*distance.z() + distance.x()*distance.x()) < settings.map_floatPars["ConeNearByDistance"] && + fabs(distance.y()) < barLength/2.){ + t_nearbyLocalMax.push_back(localMaxCol[ilm]); + set_nearbyHalfClusters.insert(p_HalfCluster->at(ihc).get()); + break; + } } }} } } + t_nearbyHalfClusters.assign(set_nearbyHalfClusters.begin(), set_nearbyHalfClusters.end()); - return StatusCode::SUCCESS; } @@ -329,25 +346,28 @@ StatusCode TrackMatchingAlg::GetNearby(const std::vector<std::shared_ptr<Cyber:: StatusCode TrackMatchingAlg::LongiConeLinking(const std::vector<TVector3>& extrapo_points, std::vector<const Cyber::Calo1DCluster*>& nearbyLocalMax, std::vector<const Cyber::Calo1DCluster*>& cone_axis){ - // std::cout<<"yyy: calling longiConeLinking()"<<std::endl; if(nearbyLocalMax.size()==0 || extrapo_points.size()==0) return StatusCode::SUCCESS; - - // Seed finding int slayer = nearbyLocalMax[0]->getSlayer(); - // int min_point = settings.map_intPars["Max_Seed_Point"]; // if (extrapo_points.size()<min_point) min_point = extrapo_points.size(); + std::vector<const Cyber::Calo1DCluster*> barrel_localMax, endcap_localMax; + for(int ilm=0; ilm<nearbyLocalMax.size(); ilm++){ + if(nearbyLocalMax[ilm]->getSystem()==Cyber::CaloUnit::System_Barrel) barrel_localMax.push_back(nearbyLocalMax[ilm]); + else if(nearbyLocalMax[ilm]->getSystem()==Cyber::CaloUnit::System_Endcap) endcap_localMax.push_back(nearbyLocalMax[ilm]); + } + // Seed finding for barrel + std::vector<const Cyber::Calo1DCluster*> barrel_cone_axis; if(slayer==1){ // If V plane // for(int ip=0; ip<min_point; ip++){ for(int ip=0; ip<extrapo_points.size(); ip++){ double min_distance = 99999; int seed_candidate_index = -1; - for(int il=0;il<nearbyLocalMax.size(); il++){ - TVector3 distance = extrapo_points[ip] - nearbyLocalMax[il]->getPos(); + for(int il=0;il<barrel_localMax.size(); il++){ + TVector3 distance = extrapo_points[ip] - barrel_localMax[il]->getPos(); double distance_2d = distance.Perp(); - if(TMath::Abs(distance.Z()) < (nearbyLocalMax[il]->getBars()[0]->getBarLength())/2. + if(TMath::Abs(distance.Z()) < (barrel_localMax[il]->getBars()[0]->getBarLength())/2. && distance_2d < settings.map_floatPars["ConeSeedDistance"] && distance_2d < min_distance) { @@ -357,8 +377,8 @@ StatusCode TrackMatchingAlg::LongiConeLinking(const std::vector<TVector3>& extra } if (seed_candidate_index<0) continue; - cone_axis.push_back(nearbyLocalMax[seed_candidate_index]); - nearbyLocalMax.erase(nearbyLocalMax.begin() + seed_candidate_index); + barrel_cone_axis.push_back(barrel_localMax[seed_candidate_index]); + barrel_localMax.erase(barrel_localMax.begin() + seed_candidate_index); break; } } @@ -368,9 +388,9 @@ StatusCode TrackMatchingAlg::LongiConeLinking(const std::vector<TVector3>& extra double min_distance = 99999; int seed_candidate_index = -1; - for(int il=0;il<nearbyLocalMax.size(); il++){ - TVector3 lm_pos = nearbyLocalMax[il]->getPos(); - float barLength = nearbyLocalMax[il]->getBars()[0]->getBarLength(); + for(int il=0;il<barrel_localMax.size(); il++){ + TVector3 lm_pos = barrel_localMax[il]->getPos(); + float barLength = barrel_localMax[il]->getBars()[0]->getBarLength(); float distance_2d = sqrt( pow(extrapo_points[ip].z()-lm_pos.z(), 2) + pow(extrapo_points[ip].Perp()-lm_pos.Perp(), 2) ); if( fabs(extrapo_points[ip].Phi()-lm_pos.Phi()) < barLength/2./Cyber::CaloUnit::ecal_innerR && distance_2d < settings.map_floatPars["ConeSeedDistance"] && @@ -382,61 +402,138 @@ StatusCode TrackMatchingAlg::LongiConeLinking(const std::vector<TVector3>& extra } if (seed_candidate_index<0) continue; - cone_axis.push_back(nearbyLocalMax[seed_candidate_index]); - nearbyLocalMax.erase(nearbyLocalMax.begin() + seed_candidate_index); + barrel_cone_axis.push_back(barrel_localMax[seed_candidate_index]); + barrel_localMax.erase(barrel_localMax.begin() + seed_candidate_index); + break; + } + } + + // Seed finding for endcap + std::vector<const Cyber::Calo1DCluster*> endcap_cone_axis; + if(slayer==0){ // U plane (bars parralel to y-axis) + // for(int ip=0; ip<min_point; ip++){ + for(int ip=0; ip<extrapo_points.size(); ip++){ + double min_distance = 99999; + int seed_candidate_index = -1; + + for(int il=0;il<endcap_localMax.size(); il++){ + TVector3 lm_pos = endcap_localMax[il]->getPos(); + float barLength = endcap_localMax[il]->getBars()[0]->getBarLength(); + TVector3 distance = extrapo_points[ip] - lm_pos; + double distance_2d = sqrt( distance.z()*distance.z() + distance.x()*distance.x() ); + if( fabs(distance.y()) < barLength/2. && + distance_2d < settings.map_floatPars["ConeSeedDistance"] && + distance_2d < min_distance) + { + seed_candidate_index = il; + min_distance = distance_2d; + } + } + if (seed_candidate_index<0) continue; + + endcap_cone_axis.push_back(endcap_localMax[seed_candidate_index]); + endcap_localMax.erase(endcap_localMax.begin() + seed_candidate_index); break; } } + else{ // V plane (bars parralel to x-axis) + // for(int ip=0; ip<min_point; ip++){ + for(int ip=0; ip<extrapo_points.size(); ip++){ + double min_distance = 99999; + int seed_candidate_index = -1; - if (cone_axis.size() == 0) return StatusCode::SUCCESS; + for(int il=0;il<endcap_localMax.size(); il++){ + TVector3 lm_pos = endcap_localMax[il]->getPos(); + float barLength = endcap_localMax[il]->getBars()[0]->getBarLength(); + TVector3 distance = extrapo_points[ip] - lm_pos; + double distance_2d = sqrt( distance.z()*distance.z() + distance.y()*distance.y() ); + if( fabs(distance.x()) < barLength/2. && + distance_2d < settings.map_floatPars["ConeSeedDistance"] && + distance_2d < min_distance) + { + seed_candidate_index = il; + min_distance = distance_2d; + } + } + if (seed_candidate_index<0) continue; - // std::cout<<" yyy: after seed-finding, cone_axis.size()="<<cone_axis.size()<<endl; + endcap_cone_axis.push_back(endcap_localMax[seed_candidate_index]); + endcap_localMax.erase(endcap_localMax.begin() + seed_candidate_index); + break; + } - // Linking - while(nearbyLocalMax.size()>0){ - // std::cout<<" yyy: nearbyLocalMax.size()="<<nearbyLocalMax.size()<<", linking it!"<<std::endl; - const Cyber::Calo1DCluster* shower_in_axis = cone_axis.back(); + } + + if (barrel_cone_axis.size()==0 && endcap_cone_axis.size()==0) return StatusCode::SUCCESS; + + // Linking for barrel + while(barrel_localMax.size()>0){ + if(barrel_cone_axis.size()==0) break; + const Cyber::Calo1DCluster* shower_in_axis = barrel_cone_axis.back(); if(!shower_in_axis) break; if(isStopLinking(extrapo_points, shower_in_axis)) break; - // std::cout<<" yyy: looking for a lm to link"<<std::endl; + double min_distance = 9999; + int shower_candidate_index = -1; + + for(int il=0; il<barrel_localMax.size(); il++){ + TVector2 relR = GetProjectedRelR(shower_in_axis, barrel_localMax[il]); //Return vec: 1->2. + TVector2 clusaxis = GetProjectedAxis(extrapo_points, shower_in_axis); + + double delta_phi = relR.DeltaPhi(clusaxis); + double delta_distance = (relR - (clusaxis*2)).Mod(); - double min_delta = 9999; + if( delta_phi<settings.map_floatPars["th_ConeTheta"] + && relR.Mod()<settings.map_floatPars["th_ConeR"] + && delta_distance<min_distance){ + shower_candidate_index = il; + min_distance = delta_distance; + } + } + if (shower_candidate_index<0) break; + + barrel_cone_axis.push_back(barrel_localMax[shower_candidate_index]); + barrel_localMax.erase(barrel_localMax.begin() + shower_candidate_index); + } + + + // Linking for endcap + while(endcap_localMax.size()>0){ + if(endcap_cone_axis.size()==0) break; + const Cyber::Calo1DCluster* shower_in_axis = endcap_cone_axis.back(); + if(!shower_in_axis) break; + if(isStopLinking(extrapo_points, shower_in_axis)) break; + + double min_distance = 9999; int shower_candidate_index = -1; - for(int il=0; il<nearbyLocalMax.size(); il++){ - TVector2 relR = GetProjectedRelR(shower_in_axis, nearbyLocalMax[il]); //Return vec: 1->2. + for(int il=0; il<endcap_localMax.size(); il++){ + TVector2 relR = GetProjectedRelR(shower_in_axis, endcap_localMax[il]); //Return vec: 1->2. TVector2 clusaxis = GetProjectedAxis(extrapo_points, shower_in_axis); double delta_phi = relR.DeltaPhi(clusaxis); double delta_distance = (relR - (clusaxis*2)).Mod(); - // std::cout<<" yyy: for nearbyLocalMax["<<il<<"], "<<std::endl - // <<" shower_in_axis=("<<shower_in_axis->getPos().x()<<", " - // <<shower_in_axis->getPos().y()<<", " - // <<shower_in_axis->getPos().z()<<")"<<std::endl - // <<" nearbyLocalMax=("<<nearbyLocalMax[il]->getPos().x()<<", " - // <<nearbyLocalMax[il]->getPos().y()<<", " - // <<nearbyLocalMax[il]->getPos().z()<<")"<<std::endl - // <<" relR = ("<<relR.X()<<", "<<relR.Y()<<")"<<std::endl - // <<" clusaxis = ("<<clusaxis.X()<<", "<<clusaxis.Y()<<")"<<std::endl - // <<" delta_phi = "<<delta_phi<<", delta_distance="<<delta_distance<<std::endl; - if( delta_phi<settings.map_floatPars["th_ConeTheta"] && relR.Mod()<settings.map_floatPars["th_ConeR"] - && delta_distance<min_delta) - { - // std::cout<<" yyy: nearbyLocalMax["<<il<<"] renewed"<<std::endl; + && delta_distance<min_distance){ shower_candidate_index = il; - min_delta = delta_distance; + min_distance = delta_distance; } } if (shower_candidate_index<0) break; - cone_axis.push_back(nearbyLocalMax[shower_candidate_index]); - nearbyLocalMax.erase(nearbyLocalMax.begin() + shower_candidate_index); + endcap_cone_axis.push_back(endcap_localMax[shower_candidate_index]); + endcap_localMax.erase(endcap_localMax.begin() + shower_candidate_index); } - + + cone_axis.insert(cone_axis.end(), barrel_cone_axis.begin(), barrel_cone_axis.end()); + cone_axis.insert(cone_axis.end(), endcap_cone_axis.begin(), endcap_cone_axis.end()); + + // nearbyLocalMax.clear(); + // nearbyLocalMax.insert(nearbyLocalMax.end(), barrel_localMax.begin(), barrel_localMax.end()); + // nearbyLocalMax.insert(nearbyLocalMax.end(), endcap_localMax.begin(), endcap_localMax.end()); + return StatusCode::SUCCESS; } @@ -444,102 +541,168 @@ StatusCode TrackMatchingAlg::LongiConeLinking(const std::vector<TVector3>& extra bool TrackMatchingAlg::isStopLinking( const std::vector<TVector3>& extrapo_points, const Cyber::Calo1DCluster* final_cone_hit){ - double slayer = final_cone_hit->getSlayer(); - if(slayer==1){ - TVector3 f_distance = extrapo_points.back() - final_cone_hit->getPos(); - double f_distance_2d = f_distance.Perp(); - for(int i=0; i<extrapo_points.size(); i++){ - TVector3 distance = extrapo_points[i] - final_cone_hit->getPos(); - double distance_2d = distance.Perp(); - if (distance_2d < f_distance_2d) return false; + int slayer = final_cone_hit->getSlayer(); + int system = final_cone_hit->getSystem(); + if(system==Cyber::CaloUnit::System_Barrel){ + if(slayer==1){ + TVector3 f_distance = extrapo_points.back() - final_cone_hit->getPos(); + double f_distance_2d = f_distance.Perp(); + for(int i=0; i<extrapo_points.size(); i++){ + TVector3 distance = extrapo_points[i] - final_cone_hit->getPos(); + double distance_2d = distance.Perp(); + if (distance_2d < f_distance_2d) return false; + } + } + else{ + TVector3 lm_pos = final_cone_hit->getPos(); + float f_distance_2d = sqrt( pow(extrapo_points.back().z()-lm_pos.z(), 2) + pow(extrapo_points.back().Perp()-lm_pos.Perp(), 2) ); + for(int i=0; i<extrapo_points.size(); i++){ + float distance_2d = sqrt( pow(extrapo_points[i].z()-lm_pos.z(), 2) + pow(extrapo_points[i].Perp()-lm_pos.Perp(), 2) ); + if (distance_2d < f_distance_2d) return false; + } } } - else{ - - - TVector3 lm_pos = final_cone_hit->getPos(); - float barLength = final_cone_hit->getBars()[0]->getBarLength(); - float f_distance_2d = sqrt( pow(extrapo_points.back().z()-lm_pos.z(), 2) + pow(extrapo_points.back().Perp()-lm_pos.Perp(), 2) ); - for(int i=0; i<extrapo_points.size(); i++){ - float distance_2d = sqrt( pow(extrapo_points[i].z()-lm_pos.z(), 2) + pow(extrapo_points[i].Perp()-lm_pos.Perp(), 2) ); - if (distance_2d < f_distance_2d) return false; + else if(system==Cyber::CaloUnit::System_Endcap){ + if(slayer==0){ + TVector3 lm_pos = final_cone_hit->getPos(); + TVector3 f_distance = extrapo_points.back() - lm_pos; + double f_distance_2d = sqrt( f_distance.z()*f_distance.z() + f_distance.x()*f_distance.x() ); + for(int i=0; i<extrapo_points.size(); i++){ + TVector3 distance = extrapo_points[i] - lm_pos; + double distance_2d = sqrt( distance.z()*distance.z() + distance.x()*distance.x() ); + if (distance_2d < f_distance_2d) return false; + } + } + else{ + TVector3 lm_pos = final_cone_hit->getPos(); + TVector3 f_distance = extrapo_points.back() - lm_pos; + double f_distance_2d = sqrt( f_distance.z()*f_distance.z() + f_distance.y()*f_distance.y() ); + for(int i=0; i<extrapo_points.size(); i++){ + TVector3 distance = extrapo_points[i] - lm_pos; + double distance_2d = sqrt( distance.z()*distance.z() + distance.y()*distance.y() ); + if (distance_2d < f_distance_2d) return false; + } } } - // std::cout<<" yyy: calling isStopLinking(): stop!"<<std::endl; + return true; } TVector2 TrackMatchingAlg::GetProjectedRelR( const Cyber::Calo1DCluster* m_shower1, const Cyber::Calo1DCluster* m_shower2 ){ - TVector2 paxis1, paxis2; - if(m_shower1->getSlayer()==1){ //For V-bars - paxis1.Set(m_shower1->getPos().x(), m_shower1->getPos().y()); - paxis2.Set(m_shower2->getPos().x(), m_shower2->getPos().y()); - return paxis2 - paxis1; - } - else{ //For U-bars - //if (m_shower1->getTowerID()[0][0] != m_shower2->getTowerID()[0][0]) - // std::cout << "warning: In GetProjectedRelR(), modules are different!" << std::endl; - TVector3 vec = m_shower2->getPos() - m_shower1->getPos(); - - TVector2 vec2d(vec.Perp(), vec.z()); - - return vec2d; + if(m_shower1->getSystem()==Cyber::CaloUnit::System_Barrel){ // For Barrel + if(m_shower1->getSlayer()==1){ //For V-bars + TVector3 vec = m_shower2->getPos() - m_shower1->getPos(); + TVector2 vec2d(vec.x(), vec.y()); + return vec2d; + } + else{ //For U-bars + TVector3 vec = m_shower2->getPos() - m_shower1->getPos(); + TVector2 vec2d(vec.Perp(), vec.z()); + return vec2d; + } } - - + else if(m_shower1->getSystem()==Cyber::CaloUnit::System_Endcap){ // For Endcap + if(m_shower1->getSlayer()==0){ //For U-bars + TVector3 vec = m_shower2->getPos() - m_shower1->getPos(); + TVector2 vec2d(vec.z(), vec.x()); + return vec2d; + } + else{ //For V-bars + TVector3 vec = m_shower2->getPos() - m_shower1->getPos(); + TVector2 vec2d(vec.z(), vec.y()); + return vec2d; + } + } } TVector2 TrackMatchingAlg::GetProjectedAxis(const std::vector<TVector3>& extrapo_points, const Cyber::Calo1DCluster* m_shower){ int min_index=0; TVector2 distance(999., 999.); - if( m_shower->getSlayer()==1 ){ // V plane - for(int i=0; i<extrapo_points.size(); i++){ - TVector2 t_distance(m_shower->getPos().x()-extrapo_points[i].x(), m_shower->getPos().y()-extrapo_points[i].y()); - if(t_distance.Mod()<distance.Mod()){ - distance = t_distance; - min_index = i; + if(m_shower->getSystem()==Cyber::CaloUnit::System_Barrel){ + if( m_shower->getSlayer()==1 ){ // V plane + for(int i=0; i<extrapo_points.size(); i++){ + TVector2 t_distance(m_shower->getPos().x()-extrapo_points[i].x(), m_shower->getPos().y()-extrapo_points[i].y()); + if(t_distance.Mod()<distance.Mod()){ + distance = t_distance; + min_index = i; + } } - } - if(min_index < extrapo_points.size()-1){ - TVector2 axis(extrapo_points[min_index+1].x()-extrapo_points[min_index].x(), extrapo_points[min_index+1].y()-extrapo_points[min_index].y()); - return axis; - }else{ - TVector2 axis(extrapo_points[min_index].x()-extrapo_points[min_index-1].x(), extrapo_points[min_index].y()-extrapo_points[min_index-1].y()); - return axis; - } + if(min_index < extrapo_points.size()-1){ + TVector2 axis(extrapo_points[min_index+1].x()-extrapo_points[min_index].x(), extrapo_points[min_index+1].y()-extrapo_points[min_index].y()); + return axis; + }else{ + TVector2 axis(extrapo_points[min_index].x()-extrapo_points[min_index-1].x(), extrapo_points[min_index].y()-extrapo_points[min_index-1].y()); + return axis; + } - }else{ // U plane - for(int i=0; i<extrapo_points.size(); i++){ - TVector3 dist3d = m_shower->getPos() - extrapo_points[i]; - //dist3d.RotateZ( TMath::Pi()/4.*(6-m_shower->getTowerID()[0][0]) ); - TVector2 t_distance(dist3d.Perp(), dist3d.z()); - if(t_distance.Mod()<distance.Mod()){ - distance = t_distance; - min_index = i; + }else{ // U plane + for(int i=0; i<extrapo_points.size(); i++){ + TVector3 dist3d = m_shower->getPos() - extrapo_points[i]; + //dist3d.RotateZ( TMath::Pi()/4.*(6-m_shower->getTowerID()[0][0]) ); + TVector2 t_distance(dist3d.Perp(), dist3d.z()); + if(t_distance.Mod()<distance.Mod()){ + distance = t_distance; + min_index = i; + } + } + + if(min_index < extrapo_points.size()-1){ + TVector3 vec = extrapo_points[min_index+1] - extrapo_points[min_index]; + TVector2 axis(vec.Perp(), vec.z()); + return axis; + }else{ + TVector3 vec = extrapo_points[min_index] - extrapo_points[min_index-1]; + TVector2 axis(vec.Perp(), vec.z()); + return axis; } } + } + else if (m_shower->getSystem()==Cyber::CaloUnit::System_Endcap){ + if( m_shower->getSlayer()==0 ){ // U plane + for(int i=0; i<extrapo_points.size(); i++){ + TVector3 dist3d = m_shower->getPos() - extrapo_points[i]; + TVector2 t_distance(dist3d.z(), dist3d.x()); + if(t_distance.Mod()<distance.Mod()){ + distance = t_distance; + min_index = i; + } + } - if(min_index < extrapo_points.size()-1){ - double dx = extrapo_points[min_index+1].x() - extrapo_points[min_index].x(); - double dy = extrapo_points[min_index+1].y() - extrapo_points[min_index].y(); - double dz = extrapo_points[min_index+1].z() - extrapo_points[min_index].z(); - TVector3 vec(dx, dy, dz); - //vec.RotateZ( TMath::Pi()/4.*(6-m_shower->getTowerID()[0][0]) ); - TVector2 axis(vec.Perp(), vec.z()); - return axis; - }else{ - double dx = extrapo_points[min_index].x() - extrapo_points[min_index-1].x(); - double dy = extrapo_points[min_index].y() - extrapo_points[min_index-1].y(); - double dz = extrapo_points[min_index].z() - extrapo_points[min_index-1].z(); - TVector3 vec(dx, dy, dz); - //vec.RotateZ( TMath::Pi()/4.*(6-m_shower->getTowerID()[0][0]) ); - TVector2 axis(vec.Perp(), vec.z()); - return axis; + if(min_index < extrapo_points.size()-1){ + TVector3 vec = extrapo_points[min_index+1] - extrapo_points[min_index]; + TVector2 axis(vec.z(), vec.x()); + return axis; + }else{ + TVector3 vec = extrapo_points[min_index] - extrapo_points[min_index-1]; + TVector2 axis(vec.z(), vec.x()); + return axis; + } + + }else{ // V plane + for(int i=0; i<extrapo_points.size(); i++){ + TVector3 dist3d = m_shower->getPos() - extrapo_points[i]; + TVector2 t_distance(dist3d.z(), dist3d.y()); + if(t_distance.Mod()<distance.Mod()){ + distance = t_distance; + min_index = i; + } + } + + if(min_index < extrapo_points.size()-1){ + TVector3 vec = extrapo_points[min_index+1] - extrapo_points[min_index]; + TVector2 axis(vec.z(), vec.y()); + return axis; + }else{ + TVector3 vec = extrapo_points[min_index] - extrapo_points[min_index-1]; + TVector2 axis(vec.z(), vec.y()); + return axis; + } } } + } @@ -547,24 +710,20 @@ TVector2 TrackMatchingAlg::GetProjectedAxis(const std::vector<TVector3>& extrapo StatusCode TrackMatchingAlg::CreatConeAxis(CyberDataCol& m_datacol, Cyber::Track* track, std::vector<Cyber::CaloHalfCluster*>& nearbyHalfClusters, std::vector<const Cyber::Calo1DCluster*>& cone_axis){ - // std::cout<<"yyy: Calling CreateConeAxis()"<<std::endl; if(nearbyHalfClusters.size()==0 || cone_axis.size()==0) return StatusCode::SUCCESS; for(int ihc=0; ihc<nearbyHalfClusters.size(); ihc++){ std::vector<const Cyber::Calo1DCluster*> localMaxCol = nearbyHalfClusters[ihc]->getLocalMaxCol(settings.map_stringPars["ReadinLocalMaxName"]); - // std::cout<<" yyy: for nearbyHalfClusters["<<ihc<<"], localMax are:" // Track axis candidate. // Cyber::CaloHalfCluster* t_track_axis = new Cyber::CaloHalfCluster(); std::shared_ptr<Cyber::CaloHalfCluster> t_track_axis = std::make_shared<Cyber::CaloHalfCluster>(); for(int ica=0; ica<cone_axis.size(); ica++){ if( find(localMaxCol.begin(), localMaxCol.end(), cone_axis[ica]) != localMaxCol.end()){ t_track_axis->addUnit(cone_axis[ica]); - // std::cout<<" add Unit from cone_axis to track_axis: " << cone_axis[ica]->getPos().x() << ", " - // << cone_axis[ica]->getPos().y() << ", " << cone_axis[ica]->getPos().z() << std::endl; } } - // // If the track does not match the Halfcluster, the track axis candidate will have no 1DCluster + // If the track does not match the Halfcluster, the track axis candidate will have no 1DCluster if(t_track_axis->getCluster().size()==0) continue; @@ -573,26 +732,12 @@ StatusCode TrackMatchingAlg::CreatConeAxis(CyberDataCol& m_datacol, Cyber::Track if(nearbyHalfClusters[ihc]->getSlayer()==1){ track->addAssociatedHalfClusterV( nearbyHalfClusters[ihc] ); - // std::cout<<" yyy: track->addAssociatedHalfClusterV"<<std::endl; } else{ track->addAssociatedHalfClusterU( nearbyHalfClusters[ihc] ); - // std::cout<<" yyy: track->addAssociatedHalfClusterU"<<std::endl; } m_datacol.map_HalfCluster["bkHalfCluster"].push_back(t_track_axis); nearbyHalfClusters[ihc]->addHalfCluster(settings.map_stringPars["OutputLongiClusName"], t_track_axis.get()); - // std::cout<<" yyy: nearbyHalfClusters["<<ihc<<"]->addHalfCluster, bars in the nearbyHalfClusters:"<<std::endl; - // for(int ii=0; ii<nearbyHalfClusters[ihc]->getCluster().size(); ii++){ - // std::cout<<" "<<nearbyHalfClusters[ihc]->getCluster()[ii]->getPos().x()<<", " - // <<nearbyHalfClusters[ihc]->getCluster()[ii]->getPos().y()<<", " - // <<nearbyHalfClusters[ihc]->getCluster()[ii]->getPos().z()<<std::endl; - // } - // std::cout<<" bars in the t_track_axis:"<<std::endl; - // for(int ii=0; ii<t_track_axis->getCluster().size(); ii++){ - // std::cout<<" "<<t_track_axis->getCluster()[ii]->getPos().x()<<", " - // <<t_track_axis->getCluster()[ii]->getPos().y()<<", " - // <<t_track_axis->getCluster()[ii]->getPos().z()<<std::endl; - // } diff --git a/Reconstruction/RecPFACyber/src/Algorithm/TruthClusteringAlg.cpp b/Reconstruction/RecPFACyber/src/Algorithm/TruthClusteringAlg.cpp index ea4b7c117c69cb2e5481c7c96c8e05b75c43b98e..22011c5302400bc700ebe6588efa889033f0adc0 100644 --- a/Reconstruction/RecPFACyber/src/Algorithm/TruthClusteringAlg.cpp +++ b/Reconstruction/RecPFACyber/src/Algorithm/TruthClusteringAlg.cpp @@ -15,8 +15,8 @@ StatusCode TruthClusteringAlg::ReadSettings(Settings& m_settings){ if(settings.map_stringPars.find("InputECALBars")==settings.map_stringPars.end()) settings.map_stringPars["InputECALBars"] = "BarCol"; - if(settings.map_stringPars.find("InputHCALHits")==settings.map_stringPars.end()) - settings.map_stringPars["InputHCALHits"] = "HCALBarrel"; + if(settings.map_stringVecPars.find("InputHCALHits")==settings.map_stringVecPars.end()) + settings.map_stringVecPars["InputHCALHits"] = {"HCALBarrel", "HCALEndcaps"}; if(settings.map_stringPars.find("OutputECAL1DClusters")==settings.map_stringPars.end()) settings.map_stringPars["OutputECAL1DClusters"] = "TruthCluster1DCol"; if(settings.map_stringPars.find("OutputECALHalfClusters")==settings.map_stringPars.end()) @@ -44,7 +44,10 @@ StatusCode TruthClusteringAlg::Initialize( CyberDataCol& m_datacol ){ m_TrackCol = m_datacol.TrackCol; m_bars = m_datacol.map_BarCol[settings.map_stringPars["InputECALBars"]]; - m_hits = m_datacol.map_CaloHit[settings.map_stringPars["InputHCALHits"]]; + for(int icl=0; icl<settings.map_stringVecPars["InputHCALHits"].size(); icl++){ + m_hits.insert(m_hits.end(), m_datacol.map_CaloHit[settings.map_stringVecPars["InputHCALHits"][icl]].begin(), m_datacol.map_CaloHit[settings.map_stringVecPars["InputHCALHits"][icl]].end()); + //m_hits = m_datacol.map_CaloHit[settings.map_stringPars["InputHCALHits"]]; + } return StatusCode::SUCCESS; }; diff --git a/Reconstruction/RecPFACyber/src/CyberDataCol.cpp b/Reconstruction/RecPFACyber/src/CyberDataCol.cpp index d6e2216fb2f390e4b679ba23277bd1b3cb773aa8..98106f7ad23971b58918d4ec2b2efc43ac2e415c 100644 --- a/Reconstruction/RecPFACyber/src/CyberDataCol.cpp +++ b/Reconstruction/RecPFACyber/src/CyberDataCol.cpp @@ -1,3 +1,14 @@ +//============================================================= +// CyberPFA: a PFA developed for CEPC referenece detector +// Ver. CyberPFA-5.0.1(2025.01.09) +//------------------------------------------------------------- +// Data Collection with CyberPFA EDM +//------------------------------------------------------------- +// Author: Fangyi Guo, Yang Zhang, Weizheng Song, Shengsen Sun +// (IHEP, CAS) +// Contact: guofangyi@ihep.ac.cn, +// sunss@ihep.ac.cn +//============================================================= #ifndef _PANDORAPLUS_DATA_C #define _PANDORAPLUS_DATA_C diff --git a/Reconstruction/RecPFACyber/src/CyberPFAlg.cpp b/Reconstruction/RecPFACyber/src/CyberPFAlg.cpp index cf64cb4c184e468f0d49f55de71b734ff19db9df..354cb1289eb28f165e981051ff0b120e959ea522 100644 --- a/Reconstruction/RecPFACyber/src/CyberPFAlg.cpp +++ b/Reconstruction/RecPFACyber/src/CyberPFAlg.cpp @@ -1,3 +1,13 @@ +//============================================================= +// CyberPFA: a PFA developed for CEPC referenece detector +// Ver. CyberPFA-5.0.1(2025.01.09) +//------------------------------------------------------------- +// Author: Fangyi Guo, Yang Zhang, Weizheng Song, Shengsen Sun +// (IHEP, CAS) +// Contact: guofangyi@ihep.ac.cn, +// sunss@ihep.ac.cn +//============================================================= + #ifndef PANDORAPLUS_ALG_C #define PANDORAPLUS_ALG_C @@ -9,6 +19,8 @@ using namespace std; using namespace dd4hep; +int Cyber::CaloUnit::System_Barrel = 20; +int Cyber::CaloUnit::System_Endcap = 29; int Cyber::CaloUnit::Nmodule = 32; int Cyber::CaloUnit::Nstave = 15; int Cyber::CaloUnit::Nlayer = 14; @@ -19,6 +31,8 @@ int Cyber::CaloUnit::NbarZ = 36; //int Cyber::CaloUnit::over_module_set = 2; float Cyber::CaloUnit::barsize = 10.; //mm float Cyber::CaloUnit::ecal_innerR = 1830; //mm +float Cyber::CaloUnit::ecal_endcap_deadarea = 8.5; //mm +float Cyber::CaloUnit::ecal_endcap_barsize = 10.; //mm DECLARE_COMPONENT( CyberPFAlg ) @@ -155,6 +169,7 @@ StatusCode CyberPFAlg::initialize() if(type_AlgPars.value()[ialg].at(ipar)=="int") m_settings.map_intPars[name_AlgPars.value()[ialg].at(ipar)] = std::stoi( (string)value_AlgPars.value()[ialg].at(ipar) ); if(type_AlgPars.value()[ialg].at(ipar)=="double") m_settings.map_floatPars[name_AlgPars.value()[ialg].at(ipar)] = std::stod( (string)value_AlgPars.value()[ialg].at(ipar) ); if(type_AlgPars.value()[ialg].at(ipar)=="string") m_settings.map_stringPars[name_AlgPars.value()[ialg].at(ipar)] = value_AlgPars.value()[ialg].at(ipar) ; + //if(type_AlgPars.value()[ialg].at(ipar)=="stringVec") m_settings.map_stringVecPars[name_AlgPars.value()[ialg].at(ipar)] = value_AlgPars.value()[ialg].at(ipar) ; if(type_AlgPars.value()[ialg].at(ipar)=="bool") m_settings.map_boolPars[name_AlgPars.value()[ialg].at(ipar)] = (bool)std::stoi( (string)value_AlgPars.value()[ialg].at(ipar) ); } @@ -168,10 +183,21 @@ StatusCode CyberPFAlg::initialize() m_dd4hep = m_geosvc->lcdd(); if ( !m_dd4hep ) throw "CyberPFAlg :Failed to get dd4hep::Detector ..."; - + m_cellIDConverter = new dd4hep::rec::CellIDPositionConverter(*m_dd4hep); m_volumeManager = m_dd4hep->volumeManager(); + dd4hep::rec::ECALSystemInfoData* EcalEndcapData = m_geosvc->getDD4HepGeo().child("EcalEndcap").extension<dd4hep::rec::ECALSystemInfoData>(); + + for(int imodule=0; imodule<EcalEndcapData->ModuleInfos.size(); imodule++){ + dd4hep::rec::ECALModuleInfoStruct tmp_module = EcalEndcapData->ModuleInfos[imodule]; + for(int ilayer=0; ilayer<tmp_module.LayerInfos.size(); ilayer++){ + dd4hep::rec::ECALModuleInfoStruct::LayerInfo layer = tmp_module.LayerInfos[ilayer]; + std::tuple<int, int, int, int, int> tmp_key = std::make_tuple(tmp_module.moduleNumber, tmp_module.staveNumber, tmp_module.partNumber, layer.dlayerNumber, layer.slayerNumber); + barNumberMapEndcapMap[tmp_key] = layer.barNumber; + } + } + m_energycorsvc = service<ICrystalEcalSvc>("CrystalEcalEnergyCorrectionSvc"); if ( !m_energycorsvc ) throw "CyberPFAlg :Failed to find CrystalEcalEnergyCorrectionSvc ..."; //m_energycorsvc->initialize(); @@ -236,6 +262,8 @@ StatusCode CyberPFAlg::initialize() t_SimBar->Branch("simBar_x", &m_simBar_x); t_SimBar->Branch("simBar_y", &m_simBar_y); t_SimBar->Branch("simBar_z", &m_simBar_z); + t_SimBar->Branch("simBar_length", &m_simBar_length); + t_SimBar->Branch("simBar_nBarInLayer", &m_simBar_nBarInLayer); t_SimBar->Branch("simBar_T1", &m_simBar_T1); t_SimBar->Branch("simBar_T2", &m_simBar_T2); t_SimBar->Branch("simBar_Q1", &m_simBar_Q1); @@ -245,6 +273,7 @@ StatusCode CyberPFAlg::initialize() t_SimBar->Branch("simBar_stave", &m_simBar_stave); t_SimBar->Branch("simBar_slayer", &m_simBar_slayer); t_SimBar->Branch("simBar_bar", &m_simBar_bar); + t_SimBar->Branch("simBar_system", &m_simBar_system); t_SimBar->Branch("simBar_truthMC_tag", &m_simBar_truthMC_tag); t_SimBar->Branch("simBar_truthMC_pid", &m_simBar_truthMC_pid); t_SimBar->Branch("simBar_truthMC_px", &m_simBar_truthMC_px); @@ -699,7 +728,7 @@ StatusCode CyberPFAlg::execute() m_pMCParticleCreator->CreateMCParticle( m_DataCol, *r_MCParticleCol ); if(m_useMCPTrk) m_pTrackCreator->CreateTracksFromMCParticle(m_DataCol, *r_MCParticleCol); else m_pTrackCreator->CreateTracks( m_DataCol, r_TrackCols, r_MCPTrkAssoCol ); - m_pCaloHitsCreator->CreateCaloHits( m_DataCol, r_CaloHitCols, map_readout_decoder, map_CaloMCPAssoCols, m_volumeManager); + m_pCaloHitsCreator->CreateCaloHits( m_DataCol, r_CaloHitCols, map_readout_decoder, map_CaloMCPAssoCols, m_volumeManager, barNumberMapEndcapMap); //Perform PFA algorithm m_algorithmManager.RunAlgorithm( m_DataCol ); @@ -756,6 +785,8 @@ StatusCode CyberPFAlg::execute() m_simBar_x.push_back(p_hitbar->getPosition().x()); m_simBar_y.push_back(p_hitbar->getPosition().y()); m_simBar_z.push_back(p_hitbar->getPosition().z()); + m_simBar_length.push_back(p_hitbar->getBarLength()); + m_simBar_nBarInLayer.push_back(p_hitbar->getNBarInLayer()); m_simBar_Q1.push_back(p_hitbar->getQ1()); m_simBar_Q2.push_back(p_hitbar->getQ2()); m_simBar_T1.push_back(p_hitbar->getT1()); @@ -785,7 +816,9 @@ StatusCode CyberPFAlg::execute() std::vector<Cyber::CaloHit*> m_hcalHitsCol; m_hcalHitsCol.clear(); for(int ih=0; ih<m_DataCol.map_CaloHit["HCALBarrel"].size(); ih++) m_hcalHitsCol.push_back( m_DataCol.map_CaloHit["HCALBarrel"][ih].get() ); - + for(int ih=0; ih<m_DataCol.map_CaloHit["HCALEndcaps"].size(); ih++) + m_hcalHitsCol.push_back( m_DataCol.map_CaloHit["HCALEndcaps"][ih].get() ); + m_totE_HcalSim = 0.; for(int ihit=0; ihit<m_hcalHitsCol.size(); ihit++){ m_HcalHit_x.push_back( m_hcalHitsCol[ihit]->getPosition().x() ); @@ -1295,13 +1328,13 @@ StatusCode CyberPFAlg::execute() m_HalfClusterV_truthMC_weight.push_back(iter.second); } - // 1DClusters (hits) - for(int ilm=0; ilm<m_halfclusterV[i]->getCluster().size(); ilm++){ + // Bars (hits) + for(int ilm=0; ilm<m_halfclusterV[i]->getBars().size(); ilm++){ m_HalfClusterV_hit_tag.push_back(i); - m_HalfClusterV_hit_x.push_back( m_halfclusterV[i]->getCluster()[ilm]->getPos().x() ); - m_HalfClusterV_hit_y.push_back( m_halfclusterV[i]->getCluster()[ilm]->getPos().y() ); - m_HalfClusterV_hit_z.push_back( m_halfclusterV[i]->getCluster()[ilm]->getPos().z() ); - m_HalfClusterV_hit_E.push_back( m_halfclusterV[i]->getCluster()[ilm]->getEnergy() ); + m_HalfClusterV_hit_x.push_back( m_halfclusterV[i]->getBars()[ilm]->getPosition().x() ); + m_HalfClusterV_hit_y.push_back( m_halfclusterV[i]->getBars()[ilm]->getPosition().y() ); + m_HalfClusterV_hit_z.push_back( m_halfclusterV[i]->getBars()[ilm]->getPosition().z() ); + m_HalfClusterV_hit_E.push_back( m_halfclusterV[i]->getBars()[ilm]->getEnergy() ); } } for(int i=0; i<m_halfclusterU.size(); i++){ @@ -1324,13 +1357,13 @@ StatusCode CyberPFAlg::execute() m_HalfClusterU_truthMC_weight.push_back(iter.second); } - // 1DClusters (hits) - for(int ilm=0; ilm<m_halfclusterU[i]->getCluster().size(); ilm++){ + // Bars (hits) + for(int ilm=0; ilm<m_halfclusterU[i]->getBars().size(); ilm++){ m_HalfClusterU_hit_tag.push_back(i); - m_HalfClusterU_hit_x.push_back( m_halfclusterU[i]->getCluster()[ilm]->getPos().x() ); - m_HalfClusterU_hit_y.push_back( m_halfclusterU[i]->getCluster()[ilm]->getPos().y() ); - m_HalfClusterU_hit_z.push_back( m_halfclusterU[i]->getCluster()[ilm]->getPos().z() ); - m_HalfClusterU_hit_E.push_back( m_halfclusterU[i]->getCluster()[ilm]->getEnergy() ); + m_HalfClusterU_hit_x.push_back( m_halfclusterU[i]->getBars()[ilm]->getPosition().x() ); + m_HalfClusterU_hit_y.push_back( m_halfclusterU[i]->getBars()[ilm]->getPosition().y() ); + m_HalfClusterU_hit_z.push_back( m_halfclusterU[i]->getBars()[ilm]->getPosition().z() ); + m_HalfClusterU_hit_E.push_back( m_halfclusterU[i]->getBars()[ilm]->getEnergy() ); } } t_HalfCluster->Fill(); @@ -1374,7 +1407,6 @@ StatusCode CyberPFAlg::execute() m_HalfClusterV_nTrk.push_back(m_HFClusV[ic]->getAssociatedTracks().size()); m_totEn_V += m_HFClusV[ic]->getEnergy(); } - t_Tower->Fill(); } @@ -1387,7 +1419,7 @@ StatusCode CyberPFAlg::execute() m_totE_Ecal = 0.; m_totE_Hcal = 0.; m_Nclus_Ecal = m_EcalClusterCol.size(); - m_Nclus_Hcal = m_HcalClusterCol.size(); + m_Nclus_Hcal = m_SimpleHcalClusterCol.size(); for(int icl=0; icl<m_EcalClusterCol.size(); icl++){ m_EcalClus_x.push_back(m_EcalClusterCol[icl]->getShowerCenter().x()); m_EcalClus_y.push_back(m_EcalClusterCol[icl]->getShowerCenter().y()); @@ -1395,9 +1427,9 @@ StatusCode CyberPFAlg::execute() m_EcalClus_E.push_back(m_EcalClusterCol[icl]->getLongiE()); m_EcalClus_nTrk.push_back(m_EcalClusterCol[icl]->getAssociatedTracks().size()); - double tmp_phi = std::atan2(m_EcalClusterCol[icl]->getShowerCenter().y(), m_EcalClusterCol[icl]->getShowerCenter().x())* 180.0 / M_PI; - if (tmp_phi < 0) tmp_phi += 360.0; - double tmp_theta = std::atan2(m_EcalClusterCol[icl]->getShowerCenter().z(), m_EcalClusterCol[icl]->getShowerCenter().Perp())* 180.0 / M_PI + 90; + //double tmp_phi = std::atan2(m_EcalClusterCol[icl]->getShowerCenter().y(), m_EcalClusterCol[icl]->getShowerCenter().x())* 180.0 / M_PI; + //if (tmp_phi < 0) tmp_phi += 360.0; + //double tmp_theta = std::atan2(m_EcalClusterCol[icl]->getShowerCenter().z(), m_EcalClusterCol[icl]->getShowerCenter().Perp())* 180.0 / M_PI + 90; //cout<<" Theta: "<<tmp_theta<<" Phi: "<<tmp_phi<<endl; //m_EcalClus_Escale.push_back(m_energycorsvc->energyCorrection(m_EcalClusterCol[icl]->getLongiE(), tmp_phi, tmp_theta)); m_EcalClus_Escale.push_back(m_EcalClusterCol[icl]->getLongiE()); @@ -1611,9 +1643,9 @@ StatusCode CyberPFAlg::execute() pfo_ecal_clus_z.push_back(t_ecal_clusters[ie]->getShowerCenter().z()); pfo_ecal_clus_E.push_back(t_ecal_clusters[ie]->getLongiE()); - double tmp_phi = std::atan2(t_ecal_clusters[ie]->getShowerCenter().y(), t_ecal_clusters[ie]->getShowerCenter().x())* 180.0 / M_PI; - if (tmp_phi < 0) tmp_phi += 360.0; - double tmp_theta = std::atan2(t_ecal_clusters[ie]->getShowerCenter().z(), t_ecal_clusters[ie]->getShowerCenter().Perp())* 180.0 / M_PI + 90; + //double tmp_phi = std::atan2(t_ecal_clusters[ie]->getShowerCenter().y(), t_ecal_clusters[ie]->getShowerCenter().x())* 180.0 / M_PI; + //if (tmp_phi < 0) tmp_phi += 360.0; + //double tmp_theta = std::atan2(t_ecal_clusters[ie]->getShowerCenter().z(), t_ecal_clusters[ie]->getShowerCenter().Perp())* 180.0 / M_PI + 90; pfo_ecal_clus_Escale.push_back(t_ecal_clusters[ie]->getLongiE()); } @@ -1709,6 +1741,8 @@ void CyberPFAlg::ClearBar(){ m_simBar_x.clear(); m_simBar_y.clear(); m_simBar_z.clear(); + m_simBar_length.clear(); + m_simBar_nBarInLayer.clear(); m_simBar_T1.clear(); m_simBar_T2.clear(); m_simBar_Q1.clear(); diff --git a/Reconstruction/RecPFACyber/src/Objects/Calo1DCluster.cc b/Reconstruction/RecPFACyber/src/Objects/Calo1DCluster.cc index 9e99f9307f6a9a70b68fafca266dddedfd9a5b6b..46705b93cd3ad0744e5b25cbaa16fc67394ad329 100644 --- a/Reconstruction/RecPFACyber/src/Objects/Calo1DCluster.cc +++ b/Reconstruction/RecPFACyber/src/Objects/Calo1DCluster.cc @@ -100,9 +100,9 @@ namespace Cyber{ } if(sigmaz!=0) return sigmaz; //sLayer=1, bars along z-axis. - else if(sigmax==0 && sigmaz==0) return sigmay; //Module 2, 6 - else if(sigmay==0 && sigmaz==0) return sigmax; //Module 0, 4 - else if(sigmax!=0 && sigmay!=0 && sigmaz==0) return sqrt(sigmax*sigmax+sigmay*sigmay); //Module 1, 3, 5, 7; + else if(sigmax==0 && sigmaz==0) return sigmay; + else if(sigmay==0 && sigmaz==0) return sigmax; + else if(sigmax!=0 && sigmay!=0 && sigmaz==0) return sqrt(sigmax*sigmax+sigmay*sigmay); else return 0.; } @@ -150,25 +150,37 @@ namespace Cyber{ } int Calo1DCluster::getLeftEdge(){ - std::sort(Bars.begin(), Bars.end()); + std::sort(Bars.begin(), Bars.end(), compPos); if(Bars.size()==0) return -99; int edge = -99; - if( Bars[0]->getSlayer()==0 ) edge = Bars[0]->getBar() + Bars[0]->getStave()*Cyber::CaloUnit::NbarZ; - if( Bars[0]->getSlayer()==1 ){ - if(Bars[0]->getModule()%2==0) edge = Bars[0]->getBar() + Bars[0]->getModule()*(CaloUnit::NbarPhi_even[Bars[0]->getDlayer()]); - else edge = Bars[0]->getBar() + Bars[0]->getModule()*(CaloUnit::NbarPhi_odd[Bars[0]->getDlayer()]); + if( Bars[0]->getSystem() == CaloUnit::System_Barrel ){ + if( Bars[0]->getSlayer()==0 ) edge = Bars[0]->getBar() + Bars[0]->getStave()*Cyber::CaloUnit::NbarZ; + if( Bars[0]->getSlayer()==1 ){ + if(Bars[0]->getModule()%2==0) edge = Bars[0]->getBar() + Bars[0]->getModule()*(CaloUnit::NbarPhi_even[Bars[0]->getDlayer()-1]); + else edge = Bars[0]->getBar() + Bars[0]->getModule()*(CaloUnit::NbarPhi_odd[Bars[0]->getDlayer()-1]); + } + } + if( Bars[0]->getSystem() == CaloUnit::System_Endcap ){ + if( Bars[0]->getSlayer()==0 ) edge = Bars[0]->getBar() + Bars[0]->getStave()*Bars[0]->getNBarInLayer(); + else if( Bars[0]->getSlayer()==1 ) edge = Bars[0]->getBar() + Bars[0]->getPart()*Bars[0]->getNBarInLayer(); } return edge; } int Calo1DCluster::getRightEdge(){ - std::sort(Bars.begin(), Bars.end()); + std::sort(Bars.begin(), Bars.end(), compPos); if(Bars.size()==0) return -99; int edge = -99; - if( Bars[Bars.size()-1]->getSlayer()==0 ) edge = Bars[Bars.size()-1]->getBar() + Bars[Bars.size()-1]->getStave()*CaloUnit::NbarZ; - if( Bars[Bars.size()-1]->getSlayer()==1 ){ - if(Bars[Bars.size()-1]->getModule()%2==0) edge = Bars[Bars.size()-1]->getBar() + Bars[Bars.size()-1]->getModule()*(CaloUnit::NbarPhi_even[Bars[Bars.size()-1]->getDlayer()]); - else edge = Bars[Bars.size()-1]->getBar() + Bars[Bars.size()-1]->getModule()*(CaloUnit::NbarPhi_odd[Bars[Bars.size()-1]->getDlayer()]); + if( Bars[Bars.size()-1]->getSystem() == CaloUnit::System_Barrel ){ + if( Bars[Bars.size()-1]->getSlayer()==0 ) edge = Bars[Bars.size()-1]->getBar() + Bars[Bars.size()-1]->getStave()*CaloUnit::NbarZ; + if( Bars[Bars.size()-1]->getSlayer()==1 ){ + if(Bars[Bars.size()-1]->getModule()%2==0) edge = Bars[Bars.size()-1]->getBar() + Bars[Bars.size()-1]->getModule()*(CaloUnit::NbarPhi_even[Bars[Bars.size()-1]->getDlayer()]); + else edge = Bars[Bars.size()-1]->getBar() + Bars[Bars.size()-1]->getModule()*(CaloUnit::NbarPhi_odd[Bars[Bars.size()-1]->getDlayer()]); + } + } + if( Bars[Bars.size()-1]->getSystem() == CaloUnit::System_Endcap ){ + if( Bars[Bars.size()-1]->getSlayer()==0 ) edge = Bars[Bars.size()-1]->getBar() + Bars[Bars.size()-1]->getStave()*Bars[Bars.size()-1]->getNBarInLayer(); + else if( Bars[Bars.size()-1]->getSlayer()==1 ) edge = Bars[Bars.size()-1]->getBar() + Bars[Bars.size()-1]->getPart()*Bars[Bars.size()-1]->getNBarInLayer(); } return edge; } @@ -176,9 +188,11 @@ namespace Cyber{ void Calo1DCluster::addUnit(const Cyber::CaloUnit* _bar ) { Bars.push_back(_bar); - std::vector<int> id(2); - id[0] = _bar->getModule(); - id[1] = _bar->getStave(); + std::vector<int> id(4); + id[0] = _bar->getSystem(); + id[1] = _bar->getModule(); + id[2] = _bar->getStave(); + id[3] = _bar->getPart(); if(find(towerID.begin(), towerID.end(), id)==towerID.end()) towerID.push_back(id); } @@ -190,9 +204,11 @@ namespace Cyber{ void Calo1DCluster::setIDInfo() { for(int i=0; i<Bars.size(); i++){ - std::vector<int> id(2); - id[0] = Bars[i]->getModule(); - id[1] = Bars[i]->getStave(); + std::vector<int> id(4); + id[0] = Bars[i]->getSystem(); + id[1] = Bars[i]->getModule(); + id[2] = Bars[i]->getStave(); + id[3] = Bars[i]->getPart(); if(find(towerID.begin(), towerID.end(), id)==towerID.end()) towerID.push_back(id); } } diff --git a/Reconstruction/RecPFACyber/src/Objects/Calo2DCluster.cc b/Reconstruction/RecPFACyber/src/Objects/Calo2DCluster.cc index bc91695bcd6d161b0251e97aad67849f8cf64cbd..15e9672e1f5f53ae11043b67130906adef19a263 100644 --- a/Reconstruction/RecPFACyber/src/Objects/Calo2DCluster.cc +++ b/Reconstruction/RecPFACyber/src/Objects/Calo2DCluster.cc @@ -103,17 +103,23 @@ namespace Cyber{ if( pos.x()!=0 || pos.y()!=0 || pos.z()!=0 || towerID.size()==0 ) return pos; TVector3 m_pos(0., 0., 0.); - float rotAngle = -towerID[0][0]*TMath::TwoPi()/Cyber::CaloUnit::Nmodule; - TVector3 m_vecX(0., 0., 0.); + TVector3 m_vecX(0., 0., 0.); TVector3 m_vecY(0., 0., 0.); for(int m=0; m<barShowerUCol.size(); m++) m_vecX += barShowerUCol[m]->getPos(); m_vecX *= (1./barShowerUCol.size()); for(int m=0; m<barShowerVCol.size(); m++) m_vecY += barShowerVCol[m]->getPos(); m_vecY *= (1./barShowerVCol.size()); - m_vecX.RotateZ(rotAngle); - m_vecY.RotateZ(rotAngle); - m_pos.SetXYZ( m_vecY.x(), (m_vecX.y()+m_vecY.y())/2 , m_vecX.z() ); - m_pos.RotateZ(-rotAngle); + if(towerID[0][0]==CaloUnit::System_Barrel ){ + float rotAngle = -towerID[0][1]*TMath::TwoPi()/Cyber::CaloUnit::Nmodule; + m_vecX.RotateZ(rotAngle); + m_vecY.RotateZ(rotAngle); + m_pos.SetXYZ( m_vecY.x(), (m_vecX.y()+m_vecY.y())/2 , m_vecX.z() ); + m_pos.RotateZ(-rotAngle); + return m_pos; + } + if(towerID[0][0]==CaloUnit::System_Endcap){ + m_pos.SetXYZ(m_vecX.x(), m_vecY.y(), (m_vecX.z()+m_vecY.z())/2.); + } return m_pos; } diff --git a/Reconstruction/RecPFACyber/src/Objects/Calo3DCluster.cc b/Reconstruction/RecPFACyber/src/Objects/Calo3DCluster.cc index 2ddce73e2856657dacd0e43852599351c204bdc1..eb642f53d5efb7f7ffd1e246f93ff52b4b8fc747 100644 --- a/Reconstruction/RecPFACyber/src/Objects/Calo3DCluster.cc +++ b/Reconstruction/RecPFACyber/src/Objects/Calo3DCluster.cc @@ -53,7 +53,8 @@ namespace Cyber{ m_clus->addAssociatedTrack(iter); m_clus->setEnergyScale(Escale); m_clus->setLinkedMCP(MCParticleWeight); - m_clus->FitAxis(); + //m_clus->FitAxis(); + m_clus->setAxis(axis); return m_clus; } diff --git a/Reconstruction/RecPFACyber/src/Objects/CaloHalfCluster.cc b/Reconstruction/RecPFACyber/src/Objects/CaloHalfCluster.cc index 68889cd38df04cf3f961f77ba48d177fab5c8f32..7a817c7580b8552ab7e99f9feac76f8aabbddc79 100644 --- a/Reconstruction/RecPFACyber/src/Objects/CaloHalfCluster.cc +++ b/Reconstruction/RecPFACyber/src/Objects/CaloHalfCluster.cc @@ -289,16 +289,26 @@ namespace Cyber{ } else{ track->clear(); - double barAngle = (barShowerCol[0]->getTowerID()[0][0]+Cyber::CaloUnit::Nmodule/4.)*2*TMath::Pi()/Cyber::CaloUnit::Nmodule; + double barAngle = (barShowerCol[0]->getTowerID()[0][1]+Cyber::CaloUnit::Nmodule/4.)*2*TMath::Pi()/Cyber::CaloUnit::Nmodule; double posErr = Cyber::CaloUnit::barsize/sqrt(12); if(barAngle>=TMath::TwoPi()) barAngle = barAngle-TMath::TwoPi(); - track->setBarAngle(barAngle); - for(int is=0; is<barShowerCol.size(); is++){ - TVector3 b_pos = barShowerCol[is]->getPos(); - track->setGlobalPoint(0, b_pos.x(), posErr, b_pos.y(), posErr, b_pos.z(), posErr); - track->setGlobalPoint(1, b_pos.x(), posErr, b_pos.y(), posErr, b_pos.z(), posErr); - } + if(barShowerCol[0]->getTowerID()[0][0] == Cyber::CaloUnit::System_Barrel){ + track->setBarAngle(barAngle); + for(int is=0; is<barShowerCol.size(); is++){ + TVector3 b_pos = barShowerCol[is]->getPos(); + track->setGlobalPoint(0, b_pos.x(), posErr, b_pos.y(), posErr, b_pos.z(), posErr); + track->setGlobalPoint(1, b_pos.x(), posErr, b_pos.y(), posErr, b_pos.z(), posErr); + } + } + else if(barShowerCol[0]->getTowerID()[0][0] == Cyber::CaloUnit::System_Endcap){ + for(int is=0; is<barShowerCol.size(); is++){ + TVector3 b_pos = barShowerCol[is]->getPos(); + track->setPoint(0, b_pos.x(), posErr, b_pos.z(), posErr); + track->setPoint(1, b_pos.y(), posErr, b_pos.z(), posErr); + } + } + track->fitTrack(); double fitPhi = track->getPhi(); double fitTheta = track->getTheta(); diff --git a/Reconstruction/RecPFACyber/src/Objects/CaloUnit.cc b/Reconstruction/RecPFACyber/src/Objects/CaloUnit.cc index 649e777ee5a5503893a1e6a782cd7c4255d17083..41934d95c7e32977668b01618383bb7066312315 100644 --- a/Reconstruction/RecPFACyber/src/Objects/CaloUnit.cc +++ b/Reconstruction/RecPFACyber/src/Objects/CaloUnit.cc @@ -9,16 +9,51 @@ namespace Cyber{ bool CaloUnit::isNeighbor(const CaloUnit* x) const { if( cellID==x->getcellID() ) return false; if( system!=x->getSystem() || dlayer!=x->getDlayer() || slayer!=x->getSlayer() ) return false; + if( system==System_Endcap){ // endcap + if( module!=x->getModule() ) return false; + if( slayer==0){ + if(isAtLowerEdgeZ()){ + if( ( ( getPosition().x()-x->getPosition().x() <= 2*ecal_endcap_barsize + 2*ecal_endcap_deadarea && getPosition().x()-x->getPosition().x()>1e-6) + || ( x->getPosition().x()-getPosition().x() <= ecal_endcap_barsize + 1e-6 && x->getPosition().x()-getPosition().x()>1e-6) ) + && fabs(getPosition().y()-x->getPosition().y()) <= (getBarLength() + x->getBarLength())/2. + 2*ecal_endcap_deadarea + ecal_endcap_barsize) return true; + } + else if(isAtUpperEdgeZ()){ + if( ( (getPosition().x()-x->getPosition().x() <= ecal_endcap_barsize + 1e-6 && getPosition().x()-x->getPosition().x()>1e-6) + || (x->getPosition().x()-getPosition().x() <= 2*ecal_endcap_barsize + 2*ecal_endcap_deadarea && x->getPosition().x()-getPosition().x()>1e-6) ) + && fabs(getPosition().y()-x->getPosition().y()) <= (getBarLength() + x->getBarLength())/2. + 2*ecal_endcap_deadarea + ecal_endcap_barsize) return true; + } + else{ + if(fabs(getPosition().x()-x->getPosition().x()) <= ecal_endcap_barsize + 1e-6 + && fabs(getPosition().y()-x->getPosition().y()) <= (getBarLength() + x->getBarLength())/2. + 2*ecal_endcap_deadarea + 2*ecal_endcap_barsize) return true; + } + } + if( slayer==1) { + if(isAtLowerEdgePhi()){ + if( ( (getPosition().y()-x->getPosition().y() <= 2*ecal_endcap_barsize + 2*ecal_endcap_deadarea && getPosition().y()-x->getPosition().y()>1e-6) + || ( x->getPosition().y()-getPosition().y() <= ecal_endcap_barsize + 1e-6 && x->getPosition().y()-getPosition().y()>1e-6) ) + && fabs(getPosition().x()-x->getPosition().x()) <= (getBarLength() + x->getBarLength())/2. + 2*ecal_endcap_deadarea + ecal_endcap_barsize) return true; + } + else if(isAtUpperEdgePhi()){ + if( ( (getPosition().y()-x->getPosition().y() <= ecal_endcap_barsize + 1e-6 && getPosition().y()-x->getPosition().y()>1e-6) + || (x->getPosition().y()-getPosition().y() <= 2*ecal_endcap_barsize + 2*ecal_endcap_deadarea && x->getPosition().y()-getPosition().y()>1e-6) ) + && fabs(getPosition().x()-x->getPosition().x()) <= (getBarLength() + x->getBarLength())/2. + 2*ecal_endcap_deadarea + ecal_endcap_barsize) return true; + } + else{ + if(fabs(getPosition().y()-x->getPosition().y()) <= ecal_endcap_barsize + 1e-6 + && fabs(getPosition().x()-x->getPosition().x()) <= (getBarLength() + x->getBarLength())/2. + 2*ecal_endcap_deadarea + 2*ecal_endcap_barsize) return true; + } + } + } + else{ //barrel + if( module==x->getModule() && stave==x->getStave() && fabs(bar - x->getBar())==1 ) return true; + if( slayer==0 && stave==x->getStave() && (fabs(module-x->getModule())<=1 || fabs(module-x->getModule())==Nmodule-1 ) && fabs(bar - x->getBar())<=1 ) return true; + if( slayer==1 && module==x->getModule() && fabs(stave-x->getStave())<=1 && fabs(bar - x->getBar())<=1 ) return true; - if( module==x->getModule() && stave==x->getStave() && fabs(bar - x->getBar())==1 ) return true; - if( slayer==0 && stave==x->getStave() && (fabs(module-x->getModule())<=1 || fabs(module-x->getModule())==Nmodule-1 ) && fabs(bar - x->getBar())<=1 ) return true; - if( slayer==1 && module==x->getModule() && fabs(stave-x->getStave())<=1 && fabs(bar - x->getBar())<=1 ) return true; - - if( isAtLowerEdgeZ() && x->isAtUpperEdgeZ() && x->getStave()==stave-1 && (fabs(x->getModule()-module)<=1 || fabs(x->getModule()-module)==Nmodule-1 ) ) return true; - if( isAtUpperEdgeZ() && x->isAtLowerEdgeZ() && x->getStave()==stave+1 && (fabs(x->getModule()-module)<=1 || fabs(x->getModule()-module)==Nmodule-1 ) ) return true; - if( isAtLowerEdgePhi() && x->isAtUpperEdgePhi() && (x->getModule()==module-1 || (x->getModule() - module)==Nmodule-1 ) && fabs(x->getStave()-stave)<=1 ) return true; - if( isAtUpperEdgePhi() && x->isAtLowerEdgePhi() && (x->getModule()==module+1 || (module - x->getModule())==Nmodule-1 ) && fabs(x->getStave()-stave)<=1 ) return true; - + if( isAtLowerEdgeZ() && x->isAtUpperEdgeZ() && x->getStave()==stave-1 && (fabs(x->getModule()-module)<=1 || fabs(x->getModule()-module)==Nmodule-1 ) ) return true; + if( isAtUpperEdgeZ() && x->isAtLowerEdgeZ() && x->getStave()==stave+1 && (fabs(x->getModule()-module)<=1 || fabs(x->getModule()-module)==Nmodule-1 ) ) return true; + if( isAtLowerEdgePhi() && x->isAtUpperEdgePhi() && (x->getModule()==module-1 || (x->getModule() - module)==Nmodule-1 ) && fabs(x->getStave()-stave)<=1 ) return true; + if( isAtUpperEdgePhi() && x->isAtLowerEdgePhi() && (x->getModule()==module+1 || (module - x->getModule())==Nmodule-1 ) && fabs(x->getStave()-stave)<=1 ) return true; + } return false; } @@ -26,18 +61,31 @@ namespace Cyber{ if( cellID==x->getcellID() ) return false; if( system!=x->getSystem() || slayer!=x->getSlayer() ) return false; if( abs(dlayer-x->getDlayer())!=1) return false; - if( slayer==0 ) - { - if( stave==x->getStave() && (fabs(module-x->getModule())<=1 || fabs(module-x->getModule())==Nmodule-1 ) && fabs(bar - x->getBar())<=1 ) return true; - if( isAtLowerEdgeZ() && x->isAtUpperEdgeZ() && x->getStave()==stave-1 && (fabs(x->getModule()-module)<=1 || fabs(x->getModule()-module)==Nmodule-1 ) ) return true; - if( isAtUpperEdgeZ() && x->isAtLowerEdgeZ() && x->getStave()==stave+1 && (fabs(x->getModule()-module)<=1 || fabs(x->getModule()-module)==Nmodule-1 ) ) return true; + if( system==System_Endcap ){ // endcap + if( slayer==0 ){ + if(fabs(getPosition().x()-x->getPosition().x()) <= ecal_endcap_barsize + 1e-6 + && fabs(getPosition().y()-x->getPosition().y()) <= (getBarLength() + x->getBarLength())/2. + 2*ecal_endcap_deadarea + 2*ecal_endcap_barsize) return true; + } + if( slayer==1 ){ + if(fabs(getPosition().y()-x->getPosition().y()) <= ecal_endcap_barsize + 1e-6 + && fabs(getPosition().x()-x->getPosition().x()) <= (getBarLength() + x->getBarLength())/2. + 2*ecal_endcap_deadarea + 2*ecal_endcap_barsize) return true; + } } - if( slayer==1 ) - { - if(module==x->getModule() && fabs(stave-x->getStave())<=1 && fabs(bar - x->getBar())<=1 ) return true; - if( isAtLowerEdgePhi() && x->isAtUpperEdgePhi() && (x->getModule()==module-1 || (x->getModule() - module)==Nmodule-1 ) && fabs(x->getStave()-stave)<=1 ) return true; - if( isAtUpperEdgePhi() && x->isAtLowerEdgePhi() && (x->getModule()==module+1 || (module - x->getModule())==Nmodule-1 ) && fabs(x->getStave()-stave)<=1 ) return true; + else{ + if( slayer==0 ) + { + if( stave==x->getStave() && (fabs(module-x->getModule())<=1 || fabs(module-x->getModule())==Nmodule-1 ) && fabs(bar - x->getBar())<=1 ) return true; + if( isAtLowerEdgeZ() && x->isAtUpperEdgeZ() && x->getStave()==stave-1 && (fabs(x->getModule()-module)<=1 || fabs(x->getModule()-module)==Nmodule-1 ) ) return true; + if( isAtUpperEdgeZ() && x->isAtLowerEdgeZ() && x->getStave()==stave+1 && (fabs(x->getModule()-module)<=1 || fabs(x->getModule()-module)==Nmodule-1 ) ) return true; + } + if( slayer==1 ) + { + if(module==x->getModule() && fabs(stave-x->getStave())<=1 && fabs(bar - x->getBar())<=1 ) return true; + if( isAtLowerEdgePhi() && x->isAtUpperEdgePhi() && (x->getModule()==module-1 || (x->getModule() - module)==Nmodule-1 ) && fabs(x->getStave()-stave)<=1 ) return true; + if( isAtUpperEdgePhi() && x->isAtLowerEdgePhi() && (x->getModule()==module+1 || (module - x->getModule())==Nmodule-1 ) && fabs(x->getStave()-stave)<=1 ) return true; + } } + return false; } @@ -49,11 +97,16 @@ namespace Cyber{ bool CaloUnit::isAtUpperEdgePhi() const{ bool isEdge = false; - if(module%2==0){ - if(slayer==1 && bar==NbarPhi_even[dlayer]-1) isEdge = true; + if( system==System_Endcap ){ + if(slayer==1 && bar==nBarInLayer-1) isEdge = true; } else{ - if(slayer==1 && bar==NbarPhi_odd[dlayer]-1) isEdge = true; + if(module%2==0){ + if(slayer==1 && bar==NbarPhi_even[dlayer-1]) isEdge = true; + } + else{ + if(slayer==1 && bar==NbarPhi_odd[dlayer-1]) isEdge = true; + } } return isEdge; } @@ -65,7 +118,12 @@ namespace Cyber{ bool CaloUnit::isAtUpperEdgeZ() const{ - return ( slayer==0 && bar==NbarZ-1 ); + if( system==System_Endcap ){ + return ( slayer==0 && bar==nBarInLayer-1 ); + } + else{ + return ( slayer==0 && bar==NbarZ-1 ); + } } /* diff --git a/Reconstruction/RecPFACyber/src/Objects/HoughObject.cc b/Reconstruction/RecPFACyber/src/Objects/HoughObject.cc index f4f77f7dfbf5d8263d529b1d14641f5c992110e8..0c5beb99dd57a939c1b2152dabb793968ecf4be3 100644 --- a/Reconstruction/RecPFACyber/src/Objects/HoughObject.cc +++ b/Reconstruction/RecPFACyber/src/Objects/HoughObject.cc @@ -5,57 +5,43 @@ namespace Cyber{ - HoughObject::HoughObject( const Cyber::Calo1DCluster* _localmax, double _cellSize, double _ecal_inner_radius, double _phi){ + HoughObject::HoughObject( const Cyber::Calo1DCluster* _localmax, double _cellSize, double _ecal_inner_radius){ m_local_max = _localmax; setCellSize(_cellSize); - setCenterPoint(_ecal_inner_radius, _phi); + setCenterPoint(_ecal_inner_radius); } - void HoughObject::setCenterPoint(double& _ecal_inner_radius, double _phi){ - if(m_local_max->getSlayer()==0){ - TVector3 tmp_vec = m_local_max->getPos(); - m_center_point.Set(tmp_vec.Perp(), tmp_vec.z()); - -/* if(_phi==0) - m_center_point.Set( (m_local_max->getDlayer()-1)*20. + _ecal_inner_radius + m_cell_size*0.5, m_local_max->getPos().z() ); + void HoughObject::setCenterPoint(double& _ecal_inner_radius){ + if(m_local_max->getBars()[0]->getSystem()==CaloUnit::System_Barrel){ // barrel bars + if(m_local_max->getSlayer()==0){ // bars perpendicular to z axis + TVector3 tmp_vec = m_local_max->getPos(); + m_center_point.Set(tmp_vec.Perp(), tmp_vec.z()); + } + else if(m_local_max->getSlayer()==1){ // bars parallel to z axis + m_center_point.Set(m_local_max->getPos().x(), m_local_max->getPos().y()); + } else{ - double intPart, fracPart; - fracPart = modf((_phi+TMath::Pi())/(TMath::Pi()/4.), &intPart); // yyy: _phi + TMath::Pi() ranges from 0 to 2pi - if(fracPart<0.489 || fracPart>0.711) //Not in crack region. - m_center_point.Set( (m_local_max->getDlayer()-1)*20. + _ecal_inner_radius + m_cell_size*0.5, m_local_max->getPos().z() ); - else{ - int iCrack = intPart+2; - if(iCrack>=8) iCrack = iCrack-8; - - double tmp_phi = _phi; - while(tmp_phi<0.) tmp_phi += TMath::Pi() / 4.; - while(tmp_phi>=TMath::Pi() / 4.) tmp_phi -= TMath::Pi() / 4.; - - int imodule = m_local_max->getTowerID()[0][0]; - if(imodule==iCrack){ - double Rref = _ecal_inner_radius/cos( tmp_phi ); - m_center_point.Set( (m_local_max->getDlayer()-1)*20. + Rref + m_cell_size*0.5 , - m_local_max->getPos().z()); - } - else{ - double Rref = _ecal_inner_radius/cos( TMath::Pi() / 4. - tmp_phi ); - m_center_point.Set( (m_local_max->getDlayer()-1)*20. + Rref + m_cell_size*0.5 , - m_local_max->getPos().z()); - } - - } + std::cout<<"Error: Slayer="<<m_local_max->getSlayer()<<", do not use setCenterPoint()!"<<std::endl; } -*/ } - else if(m_local_max->getSlayer()==1){ - m_center_point.Set(m_local_max->getPos().x(), m_local_max->getPos().y()); + else if(m_local_max->getBars()[0]->getSystem()==CaloUnit::System_Endcap){ // endcap bars + if(m_local_max->getSlayer()==0){ // bars parrallel to y axis + m_center_point.Set(m_local_max->getPos().z(), m_local_max->getPos().x()); + } + else if(m_local_max->getSlayer()==1){ // bars parallel to x axis + m_center_point.Set(m_local_max->getPos().z(), m_local_max->getPos().y()); + } + else{ + std::cout<<"Error: Slayer="<<m_local_max->getSlayer()<<", do not use setCenterPoint()!"<<std::endl; + } } else{ - std::cout<<"Error: Slayer="<<m_local_max->getSlayer()<<", do not use setCenterPoint()!"<<std::endl; + std::cout<<"Error: System="<<m_local_max->getBars()[0]->getSystem()<<", do not use setCenterPoint()!"<<std::endl; } + } diff --git a/Reconstruction/RecPFACyber/src/Tools/CaloHitsCreator.cpp b/Reconstruction/RecPFACyber/src/Tools/CaloHitsCreator.cpp index 6eb324dd7379ea33a47d02fdfad46efea52fc0c4..cad19fbedcd9f28d9e30da1dd1c1a5721cedd8e6 100644 --- a/Reconstruction/RecPFACyber/src/Tools/CaloHitsCreator.cpp +++ b/Reconstruction/RecPFACyber/src/Tools/CaloHitsCreator.cpp @@ -12,7 +12,8 @@ namespace Cyber{ std::vector<DataHandle<edm4hep::CalorimeterHitCollection>*>& r_CaloHitCols, std::map<std::string, dd4hep::DDSegmentation::BitFieldCoder*>& map_decoder, std::map<std::string, DataHandle<edm4hep::MCRecoCaloParticleAssociationCollection>*>& map_CaloParticleAssoCol, - const dd4hep::VolumeManager& m_volumeManager ) + const dd4hep::VolumeManager& m_volumeManager, + std::map<std::tuple<int, int, int, int, int>, int>& barNumberMapEndcapMap ) { if(r_CaloHitCols.size()==0 || settings.map_stringVecPars.at("CaloHitCollections").size()==0) StatusCode::SUCCESS; @@ -103,7 +104,7 @@ namespace Cyber{ m_bar->setcellID( map_decoder["ECALBarrel"]->get(id, "system"), map_decoder["ECALBarrel"]->get(id, "module"), map_decoder["ECALBarrel"]->get(id, "stave"), - -1, + -1, //empty 'part' for barrel. map_decoder["ECALBarrel"]->get(id, "dlayer"), map_decoder["ECALBarrel"]->get(id, "slayer"), map_decoder["ECALBarrel"]->get(id, "bar")); @@ -122,6 +123,7 @@ namespace Cyber{ const_MCPCaloAssoCol = nullptr; } + m_barCol.clear(); if( m_DataCol.collectionMap_CaloHit.find("ECALEndcaps") != m_DataCol.collectionMap_CaloHit.end() ){ const edm4hep::MCRecoCaloParticleAssociationCollection* const_MCPCaloAssoCol = map_CaloParticleAssoCol["ECALEndcaps"]->get(); auto CaloHits = m_DataCol.collectionMap_CaloHit["ECALEndcaps"]; @@ -163,6 +165,7 @@ namespace Cyber{ map_decoder["ECALEndcaps"]->get(id, "dlayer"), map_decoder["ECALEndcaps"]->get(id, "slayer"), map_decoder["ECALEndcaps"]->get(id, "bar")); + m_bar->setNBarInLayer(barNumberMapEndcapMap[std::make_tuple(m_bar->getModule(), m_bar->getStave(), m_bar->getPart(), m_bar->getDlayer(), m_bar->getSlayer())]); m_bar->setPosition(hit.second[0].getPosition()); m_bar->setBarLength(hit.second[0].getBarLength()); m_bar->setQ( hit.second[0].getEnergy(), hit.second[1].getEnergy() ); @@ -175,8 +178,9 @@ namespace Cyber{ } m_DataCol.map_BarCol["BarCol"].insert( m_DataCol.map_BarCol["BarCol"].end(), m_barCol.begin(), m_barCol.end() ); - const_MCPCaloAssoCol = nullptr; + const_MCPCaloAssoCol = nullptr; } + } return StatusCode::SUCCESS; }; diff --git a/Reconstruction/RecPFACyber/src/Tools/OutputCreator.cpp b/Reconstruction/RecPFACyber/src/Tools/OutputCreator.cpp index 3ee25ae3115a2784043461407a6e697878c13093..43ed4967d6a6ee5c9f31e6ad909ed7ba58e49fa8 100644 --- a/Reconstruction/RecPFACyber/src/Tools/OutputCreator.cpp +++ b/Reconstruction/RecPFACyber/src/Tools/OutputCreator.cpp @@ -33,23 +33,6 @@ namespace Cyber{ //PFO std::vector<std::shared_ptr<Cyber::PFObject>> p_pfos = m_DataCol.map_PFObjects[settings.map_stringPars.at("OutputPFO")]; -/* -cout<<endl; -cout<<"Calibration const: "<<settings.map_floatPars.at("ECALNeutralCalib")<<", "<<settings.map_floatPars.at("ECALChargedCalib")<<", "<<settings.map_floatPars.at("HCALNeutralCalib")<<", "<<settings.map_floatPars.at("HCALChargedCalib")<<endl; -std::cout<<" Input PFO size: "<<p_pfos.size()<<std::endl; - double totE_Ecal = 0; - double totE_Hcal = 0; - for(int i=0; i<p_pfos.size(); i++){ - double ecalcalib = p_pfos[i]->getTracks().size()==0 ? settings.map_floatPars.at("ECALNeutralCalib") : settings.map_floatPars.at("ECALChargedCalib"); - double hcalcalib = p_pfos[i]->getTracks().size()==0 ? settings.map_floatPars.at("HCALNeutralCalib") : settings.map_floatPars.at("HCALChargedCalib"); - cout<<" PFO #"<<i<<": track size "<<p_pfos[i]->getTracks().size()<<", leading P "<<p_pfos[i]->getTrackMomentum(); - cout<<", ECAL cluster size "<<p_pfos[i]->getECALClusters().size()<<", totE "<<p_pfos[i]->getECALClusterEnergy()*ecalcalib; - cout<<", HCAL cluster size "<<p_pfos[i]->getHCALClusters().size()<<", totE "<<p_pfos[i]->getHCALClusterEnergy()*hcalcalib<<endl; - totE_Ecal += p_pfos[i]->getECALClusterEnergy()*ecalcalib; - totE_Hcal += p_pfos[i]->getHCALClusterEnergy()*hcalcalib; - } - cout<<"-----Neutral cluster Ecal total energy: "<<totE_Ecal<<", Hcal total energy: "<<totE_Hcal<<endl; -*/ for(int ip=0; ip<p_pfos.size(); ip++){ auto m_pfo = m_pfocol->create(); @@ -192,27 +175,6 @@ std::cout<<" Input PFO size: "<<p_pfos.size()<<std::endl; } //printf(" Create PFO #%d: charge %.1f, p4 (%.7f, %.7f, %.7f, %.7f), mass %.3f \n", ip, m_pfo.getCharge(), m_pfo.getMomentum().x, m_pfo.getMomentum().y, m_pfo.getMomentum().z, m_pfo.getEnergy(), m_pfo.getMass() ); } -/* -double totE = 0; -for(int i=0; i<m_pfocol->size(); i++){ - auto m_pfo = m_pfocol->at(i); - if(m_pfo.getCharge()!=0) continue; - cout<<" PFO #"<<i<<": track size "<<m_pfo.tracks_size()<<", cluster size "<<m_pfo.clusters_size()<<", energy "<<m_pfo.getEnergy()<<endl; - totE += m_pfo.getEnergy(); -} -cout<<"-----Neutral cluster total energy: "<<totE<<endl; -totE = 0; -for(int i=0; i<m_pfocol->size(); i++){ - auto m_pfo = m_pfocol->at(i); - if(m_pfo.getCharge()==0) continue; - cout<<" PFO #"<<i<<": track size "<<m_pfo.tracks_size()<<", leading P "<<sqrt(m_pfo.getMomentum().x*m_pfo.getMomentum().x + m_pfo.getMomentum().y*m_pfo.getMomentum().y + m_pfo.getMomentum().z*m_pfo.getMomentum().z); - cout<<", cluster size "<<m_pfo.clusters_size()<<", energy "<<m_pfo.getEnergy()<<endl; - totE += m_pfo.getEnergy(); -} -cout<<"-----Charged cluster Ecal total energy: "<<totE<<endl; - -std::cout<<" Created PFO size: "<<m_pfocol->size()<<std::endl; -*/ return StatusCode::SUCCESS; } diff --git a/Service/CrystalEcalSvc/src/CrystalEcalEnergyCorrectionSvc.cpp b/Service/CrystalEcalSvc/src/CrystalEcalEnergyCorrectionSvc.cpp index c7fa1e865bdac12a636f11e9516721fb4597ac1f..502f068f9f57614685a3de5b1f1e701dfb2eb523 100755 --- a/Service/CrystalEcalSvc/src/CrystalEcalEnergyCorrectionSvc.cpp +++ b/Service/CrystalEcalSvc/src/CrystalEcalEnergyCorrectionSvc.cpp @@ -2,6 +2,9 @@ #define XTALECALENERGYCORRECTIONSvc_C #include "CrystalEcalEnergyCorrectionSvc.h" +#include <iostream> +#include <sstream> +#include <iomanip> DECLARE_COMPONENT(CrystalEcalEnergyCorrectionSvc) @@ -19,28 +22,52 @@ StatusCode CrystalEcalEnergyCorrectionSvc::initialize() { // read correction file std::string m_correctionFile = _correctionFile; + if(m_correctionFile.empty()){ + error() << "CrystalEcalEnergyCorrectionSvc error: can not find correction map file! " << endmsg; + return StatusCode::FAILURE; + } file = TFile::Open(m_correctionFile.c_str()); - + if(!file->IsOpen()){ + error() << "CrystalEcalEnergyCorrectionSvc error: can not find correction map file! " << endmsg; + return StatusCode::FAILURE; + } // phi - treePhi = (TTree*)(file->Get("scalePhi")); - treePhi->SetBranchAddress("phi", &_phiAngle); - treePhi->SetBranchAddress("scale", &_phiScale); - for(int i = 0; i < treePhi->GetEntries(); i++) { - treePhi->GetEntry(i); - phiAngle.push_back(_phiAngle); - phiScale.push_back(_phiScale); + barrelPhiCorrection = (TTree*)(file->Get("scalePhi")); + barrelPhiCorrection->SetBranchAddress("phi", &_barrelPhiAngle); + barrelPhiCorrection->SetBranchAddress("scale", &_barrelPhiScale); + for(int i = 0; i < barrelPhiCorrection->GetEntries(); i++) { + barrelPhiCorrection->GetEntry(i); + //barrelPhiAngle.push_back(_barrelPhiAngle); + barrelPhiScale.push_back(_barrelPhiScale); } //theta - treeTheta = (TTree*)(file->Get("scaleTheta")); - treeTheta->SetBranchAddress("theta", &_thetaAngle); - treeTheta->SetBranchAddress("scale", &_thetaScale); - for(int i = 0; i < treeTheta->GetEntries(); i++) { - treeTheta->GetEntry(i); - thetaAngle.push_back(_thetaAngle); - thetaScale.push_back(_thetaScale); + barrelThetaCorrection = (TTree*)(file->Get("scaleTheta")); + barrelThetaCorrection->SetBranchAddress("theta", &_barrelThetaAngle); + barrelThetaCorrection->SetBranchAddress("scale", &_barrelThetaScale); + for(int i = 0; i < barrelThetaCorrection->GetEntries(); i++) { + barrelThetaCorrection->GetEntry(i); + //barrelThetaAngle.push_back(_barrelThetaAngle); + barrelThetaScale.push_back(_barrelThetaScale); + } + + // endcap + endcapCorrection = (TTree*)(file->Get("EcalEndcapEnergyCorrection")); + endcapCorrection->SetBranchAddress("theta", &_endcapTheta); + endcapCorrection->SetBranchAddress("phi", &_endcapPhi); + endcapCorrection->SetBranchAddress("mpv", &_endcapScale); + for(int i = 0; i < endcapCorrection->GetEntries(); i++) { + endcapCorrection->GetEntry(i); + + std::string stringTheta = doubleToString(_endcapTheta); + //std::cout<<"theta: "<<stringTheta<<std::endl; + std::string stringPhi = doubleToString(_endcapPhi); + //std::cout<<"phi: "<<stringPhi<<std::endl; + endcapCorrectionMap[std::make_tuple(stringTheta, stringPhi)] = _endcapScale; } + + StatusCode sc = Service::initialize(); return sc; } @@ -49,10 +76,13 @@ StatusCode CrystalEcalEnergyCorrectionSvc::finalize() { file->Close(); - phiAngle.clear(); - phiScale.clear(); - thetaAngle.clear(); - thetaScale.clear(); + //barrelPhiAngle.clear(); + barrelPhiScale.clear(); + //barrelThetaAngle.clear(); + barrelThetaScale.clear(); + // endcapTheta.clear(); + // endcapPhi.clear(); + // endcapScale.clear(); StatusCode sc = Service::finalize(); return sc; @@ -61,9 +91,23 @@ StatusCode CrystalEcalEnergyCorrectionSvc::finalize() { double CrystalEcalEnergyCorrectionSvc::energyCorrection(double energy, double phi, double theta) { // energy: GeV, phi: 0-360, theta: 0-180 //std::cout<<"Before correction: "<<energy<<" phi "<<phi<<" theta "<<theta<<std::endl; + double energyCor = 0; + + // ##### endcap correction ##### + if(theta <36 || theta > 144) { + double tmpTheta = theta; + if(tmpTheta>90) tmpTheta = 90 - (tmpTheta-90); + double tmpPhi = phi; + + std::string stringTheta = doubleToString(tmpTheta); + std::string stringPhi = doubleToString(tmpPhi); + //std::cout<<" endcap correction factor: "<<endcapCorrectionMap[std::make_tuple(stringTheta, stringPhi)]<<std::endl; + energyCor = energy/endcapCorrectionMap[std::make_tuple(stringTheta, stringPhi)]; + return energyCor; + } // ##### mpv deviation ##### - double energyCor = 0; + energyCor = energy / (mpvCorrectionFactor[3]/(mpvCorrectionFactor[0] + mpvCorrectionFactor[1]*energy + mpvCorrectionFactor[2]*energy*energy) + mpvCorrectionFactor[4]); //std::cout<<"After MPV correction: "<<energyCor<<std::endl; @@ -80,8 +124,8 @@ double CrystalEcalEnergyCorrectionSvc::energyCorrection(double energy, double ph if(iPhiStart == jPhiEnd) { int binNumber = jPhiEnd*angleBinNumber + abs((tmpPhi-phiCorrectionAngleStart[iPhiStart])/(angleRangePhi/angleBinNumber)); - //std::cout<<" phi correction factor: "<<phiScale.at(binNumber)<<std::endl; - energyCor = energyCor/phiScale.at(binNumber); + //std::cout<<" phi correction factor: "<<barrelPhiScale.at(binNumber)<<std::endl; + energyCor = energyCor/barrelPhiScale.at(binNumber); } //std::cout<<"After phi correction: "<<energyCor<<std::endl; @@ -98,8 +142,8 @@ double CrystalEcalEnergyCorrectionSvc::energyCorrection(double energy, double ph if(iThetaStart == jThetaEnd) { int binNumber = jThetaEnd*angleBinNumber + abs((tmpTheta-thetaCorrectionAngleStart[iThetaStart])/(angleRangeTheta/angleBinNumber)); - //std::cout<<" theta correction factor: "<<thetaScale.at(binNumber)<<std::endl; - energyCor = energyCor/thetaScale.at(binNumber); + //std::cout<<" theta correction factor: "<<barrelThetaScale.at(binNumber)<<std::endl; + energyCor = energyCor/barrelThetaScale.at(binNumber); } //std::cout<<"After theta correction: "<<energyCor<<std::endl; @@ -107,4 +151,11 @@ double CrystalEcalEnergyCorrectionSvc::energyCorrection(double energy, double ph //msg() << "corection done!" << endmsg; return energyCor; } + +std::string CrystalEcalEnergyCorrectionSvc::doubleToString(double number) { + std::ostringstream oss; + oss << std::fixed << std::setprecision(1) << number; + return oss.str(); +} + #endif diff --git a/Service/CrystalEcalSvc/src/CrystalEcalEnergyCorrectionSvc.h b/Service/CrystalEcalSvc/src/CrystalEcalEnergyCorrectionSvc.h index 71aa3922e8860e28fa07842a53d0df99efc35b09..8f58878d6d0d9e6ae9db7f0e2f17f8e9afa19a7a 100755 --- a/Service/CrystalEcalSvc/src/CrystalEcalEnergyCorrectionSvc.h +++ b/Service/CrystalEcalSvc/src/CrystalEcalEnergyCorrectionSvc.h @@ -19,6 +19,7 @@ public: StatusCode finalize() override; double energyCorrection(double energy, double phi, double theta) override; + std::string doubleToString(double number); static double thetaCorrectionAngleStart[7]; static double thetaCorrectionAngleEnd[7]; @@ -31,14 +32,23 @@ public: static int moduleNumberPhi; private: - mutable Gaudi::Property<std::string> _correctionFile{this, "CorrectionFile", "/cefs/higgs/songwz/summer24/CEPCSW_301/CEPCSW/workArea/scale.root", "position of energy correction file"}; - + mutable Gaudi::Property<std::string> _correctionFile{this, "CorrectionFile", "", "position of energy correction file"}; + TFile* file; - TTree* treePhi; - TTree* treeTheta; - double _phiAngle, _phiScale, _thetaAngle, _thetaScale; - std::vector<double> phiAngle, phiScale, thetaAngle, thetaScale; - + TTree* barrelPhiCorrection; + TTree* barrelThetaCorrection; + TTree* endcapCorrection; + double _barrelPhiAngle, _barrelPhiScale, _barrelThetaAngle, _barrelThetaScale; + std::vector<double> barrelPhiAngle, barrelPhiScale, barrelThetaAngle, barrelThetaScale; + double _endcapTheta, _endcapPhi, _endcapScale; + // std::vector<double> endcapTheta, endcapPhi, endcapScale; + + std::map<std::tuple<std::string, std::string>, double> endcapCorrectionMap; + // TTree* treePhi; + // TTree* treeTheta; + // double _phiAngle, _phiScale, _thetaAngle, _thetaScale; + // std::vector<double> phiAngle, phiScale, thetaAngle, thetaScale; + }; #endif