Skip to content

Commit

Permalink
[ng] Fix selected events
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed May 29, 2024
1 parent e9e85da commit 467124c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 108 deletions.
2 changes: 1 addition & 1 deletion firebird-ng/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firebird",
"version": "0.0.2",
"version": "0.0.3",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
42 changes: 4 additions & 38 deletions firebird-ng/src/app/geometry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import {build} from 'jsrootdi/geom';
import {BehaviorSubject} from "rxjs";
import {RootGeometryProcessor} from "./root-geometry.processor";
import {UserConfigService} from "./user-config.service";

// constants.ts
export const DEFAULT_GEOMETRY = 'epic-central-optimized';
Expand All @@ -24,41 +25,8 @@ export class GeometryService {

rootGeometryProcessor = new RootGeometryProcessor();

constructor() {
this.loadGeoConfig();
}

private stateSubject = new BehaviorSubject<any>(this.loadGeoConfig());
state$ = this.stateSubject.asObservable();
constructor(private settings: UserConfigService) {

saveGeoConfig(state: any) {
localStorage.setItem('geometrySettings', JSON.stringify(state));
this.stateSubject.next(state);
}

loadGeoConfig(): any {
const settings = localStorage.getItem('geometrySettings');

let config = settings ? JSON.parse(settings) : {
selectedGeometry: DEFAULT_GEOMETRY,
geoOptEnabled: true,
selectedEvent: 'Central detector',
geoPostEnabled: true
};

if(!config?.selectedGeometry) {
config.selectedGeometry = DEFAULT_GEOMETRY;
}

if(!config?.selectedEvent) {
config.selectedEvent = "Default events";
}

return config;
}

getState() {
return this.stateSubject.value;
}


Expand All @@ -68,10 +36,8 @@ export class GeometryService {
// let url: string = 'https://eic.github.io/epic/artifacts/tgeo/epic_full.root';
// >oO let objectName = 'default';

let settings = this.getState();

const url = settings.selectedGeometry !== DEFAULT_GEOMETRY?
settings.selectedGeometry:
const url = this.settings.selectedGeometry.value !== DEFAULT_GEOMETRY?
this.settings.selectedGeometry.value:
'https://eic.github.io/epic/artifacts/tgeo/epic_full.root';

console.time('[GeoSrv]: Total load geometry time');
Expand Down
5 changes: 3 additions & 2 deletions firebird-ng/src/app/input-config/input-config.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ <h5 class="card-title">Geometry Source</h5>
<h5 class="card-title">Events Source</h5>
<div class="form-group">
<select class="form-control" [formControl]="selectedEventSource">
<option value="epic-central-optimized">No events (may upload later)</option>
<option value="epic-central-optimized">Open house events</option>
<option value="no-events">No events (may upload later)</option>
<option value="https://firebird-eic.org/py8_all_dis-cc_beam-5x41_minq2-100_nevt-5.evt.json.zip">Test events</option>
<option value="https://firebird-eic.org/dirc_event.json.zip">DIRC optical (load DIRC only geometry)</option>
<option value="https://firebird-eic.org/py8_all_dis-cc_beam-5x41_minq2-100_nevt-5.evt.json.zip">Pyth8 All(300MeV+) DIC-CC 5x41 minQ2-100 5 events</option>
</select>
</div>
Expand Down
46 changes: 1 addition & 45 deletions firebird-ng/src/app/input-config/input-config.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,8 @@ export class InputConfigComponent implements OnInit {
onlyCentralDetector: FormControl<boolean | null> = new FormControl(true);

constructor(private configService: UserConfigService) {



// this.selectedGeometry.valueChanges.subscribe(
// value => this.configService.selectedGeometry.value=value??""
// );
// this.configService.selectedGeometry.changes$.subscribe(
// value => this.selectedGeometry.setValue(value, { emitEvent: false })
// );
// this.geoForm = this.fb.group(this.stateFromConfig());
//
// this.geoForm.valueChanges.subscribe(value => {
// this.geometryService.saveGeoConfig(value);
// console.log(value);
// });
}

//geoForm: FormGroup;

//
// constructor(private fb: FormBuilder, private configService: UserConfigService) {
// this.geoForm = this.fb.group(this.stateFromConfig());
//
// this.geoForm.valueChanges.subscribe(value => {
// this.geometryService.saveGeoConfig(value);
// console.log(value);
// });
// }
//
// stateFromConfig(): any {
// return {
// selectedGeometry: this.configService.selectedGeometry,
// geoOptEnabled: [false],
// selectedEvent: ['Central detector'],
// geoPostEnabled: [false]
// }
// }
//

bindConfigToControl<Type>(control: FormControl<Type | null>, config: ConfigProperty<Type> ) {
control.setValue(config.value, { emitEvent: false })
Expand All @@ -78,15 +42,7 @@ export class InputConfigComponent implements OnInit {
ngOnInit(): void {
//this.selectedGeometry.setValue(this.configService.selectedGeometry.value, { emitEvent: false })
this.bindConfigToControl(this.selectedGeometry, this.configService.selectedGeometry);
this.bindConfigToControl(this.selectedEventSource, this.configService.eventSource);
this.bindConfigToControl(this.onlyCentralDetector, this.configService.onlyCentralDetector);
// const savedSettings = this.geometryService.getState();
// if (savedSettings) {
// this.geoForm.setValue(savedSettings);
// }
//
// this.geometryService.state$.subscribe(state => {
// this.geoForm.setValue(state, { emitEvent: false });
// });
}

}
43 changes: 21 additions & 22 deletions firebird-ng/src/app/main-display/main-display.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ import {Line2} from "three/examples/jsm/lines/Line2";
import {LineGeometry} from "three/examples/jsm/lines/LineGeometry";
import {IoOptionsComponent} from "./io-options/io-options.component";
import {ThreeEventProcessor} from "../three-event.processor";
import {UserConfigService} from "../user-config.service";
// import { LineMaterial } from 'three/addons/lines/LineMaterial.js';


@Component({
selector: 'app-test-experiment',
templateUrl: './main-display.component.html',
imports: [PhoenixUIModule, IoOptionsComponent, HttpClientModule ],
imports: [PhoenixUIModule, IoOptionsComponent],
standalone: true,
styleUrls: ['./main-display.component.scss']
})
Expand Down Expand Up @@ -75,7 +76,7 @@ export class MainDisplayComponent implements OnInit {
private eventDisplay: EventDisplayService,
private controller: GameControllerService,
private route: ActivatedRoute,
private http: HttpClient) {
private settings: UserConfigService) {
this.threeFacade = new PhoenixThreeFacade(this.eventDisplay);
}

Expand Down Expand Up @@ -307,19 +308,17 @@ export class MainDisplayComponent implements OnInit {
camera.updateProjectionMatrix();
}

downloadFile() {

this.http.get('https://firebird-eic.org/py9_all_dis-cc_beam-5x41_minq2-100_nevt-5.evt.json.zip', {
observe: 'response'
}).subscribe(response => {
console.log(response.headers); // Log response headers
}, error => {
console.log('CORS error:', error);
});
}
ngOnInit() {


ngOnInit() {
let eventSource = this.settings.eventSource.value;
let eventConfig = {eventFile: "https://firebird-eic.org/py8_all_dis-cc_beam-5x41_minq2-100_nevt-5.evt.json.zip", eventType: "zip"};
if( eventSource != "no-events" && !eventSource.endsWith("edm4hep.json")) {
let eventType = eventSource.endsWith("zip") ? "zip" : "json";
let eventFile = eventSource;
eventConfig = {eventFile, eventType};
}

// Create the event display configuration
const configuration: Configuration = {
Expand All @@ -337,14 +336,15 @@ export class MainDisplayComponent implements OnInit {

phoenixMenuRoot: this.phoenixMenuRoot,
// Event data to load by default
defaultEventFile: {
// (Assuming the file exists in the `src/assets` directory of the app)
//eventFile: 'assets/herwig_18x275_5evt.json',
//eventFile: 'assets/events/py8_all_dis-cc_beam-18x275_minq2-1000_nevt-20.evt.json',
//eventFile: 'assets/events/py8_dis-cc_mixed.json.zip',
eventFile: 'https://firebird-eic.org/py8_all_dis-cc_beam-5x41_minq2-100_nevt-5.evt.json.zip',
eventType: 'zip' // or zip
},
defaultEventFile: eventConfig
// defaultEventFile: {
// // (Assuming the file exists in the `src/assets` directory of the app)
// //eventFile: 'assets/herwig_18x275_5evt.json',
// //eventFile: 'assets/events/py8_all_dis-cc_beam-18x275_minq2-1000_nevt-20.evt.json',
// //eventFile: 'assets/events/py8_dis-cc_mixed.json.zip',
// eventFile: 'https://firebird-eic.org/py8_all_dis-cc_beam-5x41_minq2-100_nevt-5.evt.json.zip',
// eventType: 'zip' // or zip
// },
}

// Initialize the event display
Expand All @@ -371,8 +371,7 @@ export class MainDisplayComponent implements OnInit {
gui.add(this, "produceRenderOrder");
gui.add(this, "logGamepadStates").name( 'Log controls' );
gui.add(this, "logCamera").name( 'Log camera' );
gui.add(this, "downloadFile").name( 'downloadFile' );
gui.add(this, "updateProjectionMatrix").name( 'Update Projection Matrix' );
gui.add(this, "updateProjectionMatrix").name( 'Try to screw up the camera =)' );
gui.close();

// Set default clipping
Expand Down

0 comments on commit 467124c

Please sign in to comment.