Warning, /firebird/firebird-ng/src/app/data-pipelines/root-geometry.processor.ts is written in an unsupported language. File is not indexed.
0001 //import { openFile } from '../../../jsroot/core.mjs';
0002 //import * as ROOT from '../../../jsroot/build;
0003 import {
0004 findSingleGeoNode,
0005 } from '../../lib-root-geometry/root-geo-navigation';
0006 import {EditActions, GeoNodeEditRule, removeGeoNode} from "../../lib-root-geometry/root-geo-edit";
0007 import {GeoAttBits} from "../../lib-root-geometry/root-geo-attribute-bits";
0008 import {editGeoNodes} from "../../lib-root-geometry/root-geo-edit";
0009
0010
0011 export class DetectorGeometryFineTuning {
0012 namePattern: string = "";
0013 editRules: GeoNodeEditRule[] = [];
0014 }
0015
0016
0017 function pruneTopLevelDetectors(geoManager: any, removeNames: string[]): any {
0018 const volume = geoManager.fMasterVolume === undefined ? geoManager.fVolume : geoManager.fMasterVolume;
0019 const nodes: any[] = volume?.fNodes?.arr ?? [];
0020 let removedNodes: any[] = [];
0021
0022 // Don't have nodes? Have problems?
0023 if(!nodes.length) {
0024 return {nodes, removedNodes};
0025 }
0026
0027 // Collect nodes to remove
0028 for(let node of nodes) {
0029 let isRemoving = removeNames.some(substr => node.fName.startsWith(substr))
0030 if(isRemoving) {
0031 removedNodes.push(node);
0032 }
0033 }
0034
0035 // Now remove nodes
0036 for(let node of removedNodes) {
0037 removeGeoNode(node);
0038 }
0039
0040 return {nodes, removedNodes}
0041 }
0042
0043 export class RootGeometryProcessor {
0044 /**
0045 * Detectors (top level TGeo nodes) to be removed.
0046 * (!) startsWith function is used for filtering (aka: detector.fName.startsWith(removeDetectorNames[i]) ... )
0047 */
0048 removeDetectorNames: string[] = [
0049 "Lumi",
0050 //"Magnet",
0051 //"B0",
0052 "B1",
0053 "B2",
0054 //"Q0",
0055 //"Q1",
0056 "Q2",
0057 //"BeamPipe",
0058 //"Pipe",
0059 "ForwardOffM",
0060 "Forward",
0061 "Backward",
0062 "Vacuum",
0063 "SweeperMag",
0064 "AnalyzerMag",
0065 "ZDC",
0066 //"LFHCAL",
0067 "HcalFarForward",
0068 "InnerTrackingSupport"
0069 ];
0070
0071 subDetectorsRules: DetectorGeometryFineTuning[] = [
0072 {
0073 namePattern: "*/EcalBarrelScFi*",
0074 editRules: [
0075 {pattern: "*/fiber_grid*", action: EditActions.Remove},
0076 {pattern: "*", action: EditActions.SetGeoBit, geoBit: GeoAttBits.kVisDaughters},
0077 {pattern: "*/*layer*", action: EditActions.SetGeoBit, geoBit: GeoAttBits.kVisThis},
0078 {pattern: "*/*layer*", action: EditActions.UnsetGeoBit, geoBit: GeoAttBits.kVisNone},
0079 {pattern: "*/*layer*", action: EditActions.UnsetGeoBit, geoBit: GeoAttBits.kVisDaughters},
0080 ]
0081 },
0082 {
0083 namePattern: "*/EcalBarrelImaging*",
0084 editRules: [
0085 {pattern: "*/stav*", action: EditActions.RemoveChildren},
0086 {pattern: "*", action: EditActions.SetGeoBit, geoBit: GeoAttBits.kVisDaughters},
0087 ]
0088 },
0089 {
0090 namePattern: "*/DRICH*",
0091 editRules: [
0092 {pattern: "*/DRICH_cooling*", action: EditActions.RemoveSiblings},
0093 ]
0094 },
0095 {
0096 namePattern: "*/DIRC*",
0097 editRules: [
0098 {pattern: "*/Envelope_box*", action: EditActions.RemoveChildren},
0099 {pattern: "*/Envelope_box*", action: EditActions.SetGeoBit, geoBit: GeoAttBits.kVisThis},
0100 {pattern: "*/Envelope_box*", action: EditActions.UnsetGeoBit, geoBit: GeoAttBits.kVisNone},
0101 {pattern: "*/Envelope_box*", action: EditActions.UnsetGeoBit, geoBit: GeoAttBits.kVisDaughters},
0102 {pattern: "*/Envelope_lens_vol*", action: EditActions.Remove},
0103 ]
0104 },
0105 {
0106 namePattern: "*/EcalEndcapN*",
0107 editRules: [
0108 {pattern: "*/crystal*", action: EditActions.RemoveSiblings},
0109 ]
0110 },
0111 {
0112 namePattern: "*/EcalEndcapP_*",
0113 editRules: [
0114 {pattern: "*/EcalEndcapP_layer1_0*", action: EditActions.UnsetGeoBit, geoBit: GeoAttBits.kVisDaughters},
0115 {pattern: "*/EcalEndcapP_layer1_0*", action: EditActions.RemoveChildren},
0116 ]
0117 },
0118 {
0119 namePattern: "*/LFHCAL_*",
0120 editRules: [
0121 {pattern: "*/LFHCAL_8M*", action: EditActions.RemoveChildren},
0122 {pattern: "*/LFHCAL_8M*", action: EditActions.SetGeoBit, geoBit: GeoAttBits.kVisThis},
0123 {pattern: "*/LFHCAL_8M*", action: EditActions.UnsetGeoBit, geoBit: GeoAttBits.kVisNone},
0124 {pattern: "*/LFHCAL_8M*", action: EditActions.UnsetGeoBit, geoBit: GeoAttBits.kVisDaughters},
0125 ]
0126 },
0127 {
0128 namePattern: "*/HcalEndcapPInsert_23*",
0129 editRules: [
0130 {pattern: "*/*layer*slice1_*", action: EditActions.RemoveSiblings},
0131 ]
0132 },
0133 {
0134 namePattern: "*/HcalBarrel*",
0135 editRules: [
0136 {pattern: "*/Tile*", action: EditActions.Remove},
0137 {pattern: "*/ChimneyTile*", action: EditActions.Remove},
0138 ]
0139 },
0140 {
0141 namePattern: "*/EndcapTOF*",
0142 editRules: [
0143 {pattern: "*/suppbar*", action: EditActions.Remove},
0144 {pattern: "*/component*3", action: EditActions.RemoveSiblings},
0145 ]
0146 },
0147
0148 ]
0149
0150 public process(rootGeoManager:any):any {
0151 // Getting main detector nodes
0152 let result = pruneTopLevelDetectors(rootGeoManager, this.removeDetectorNames);
0153 console.log("Filtered top level detectors: ", result);
0154
0155
0156 // >oO analyzeGeoNodes(rootGeoManager, 1);
0157 // Now we go with the fine-tuning of each detector
0158 for(let detector of this.subDetectorsRules) {
0159 let topDetNode = findSingleGeoNode(rootGeoManager, detector.namePattern, 1);
0160 console.log(`Processing ${topDetNode}`);
0161 if(!topDetNode) {
0162 continue;
0163 }
0164 console.time(`Process sub-detector: ${detector.namePattern}`);
0165 for(let rule of detector.editRules) {
0166
0167 editGeoNodes(topDetNode, [rule])
0168 }
0169 console.timeEnd(`Process sub-detector: ${detector.namePattern}`);
0170 }
0171
0172 console.log(`Done processing ${this.subDetectorsRules.length} detectors`);
0173 }
0174 }