File

src/loaders/trackml-loader.ts

Description

PhoenixLoader for processing and loading an event from TrackML.

Extends

PhoenixLoader

Index

Properties
Methods

Constructor

constructor()

Instiantiate the TrackML loader.

Properties

Private hitData
Type : any

Data containing Hits.

Private particleData
Type : any

Data containing Particles.

Private truthData
Type : any

Data containing truthy Particles.

Protected eventData
Type : any
Inherited from PhoenixLoader
Defined in PhoenixLoader:26

Event data processed by the loader.

Private graphicsLibrary
Type : ThreeManager
Inherited from PhoenixLoader
Defined in PhoenixLoader:22

ThreeService to perform three.js related functions.

Protected labelsObject
Type : literal type
Default value : {}
Inherited from PhoenixLoader
Defined in PhoenixLoader:32

Object containing event object labels.

Protected loadingManager
Type : LoadingManager
Inherited from PhoenixLoader
Defined in PhoenixLoader:28

Loading manager for loadable resources

Protected stateManager
Type : StateManager
Inherited from PhoenixLoader
Defined in PhoenixLoader:30

Loading manager for loadable resources

Private ui
Type : UIManager
Inherited from PhoenixLoader
Defined in PhoenixLoader:24

UIService to perform UI related functions.

Methods

Public getEventData
getEventData(eventNum: string)

Get structured event data from the processed Hits, Truth data and Particles.

Parameters :
Name Type Optional Description
eventNum string No

Event number.

Returns : any
Public processHits
processHits(hits: any)

Process Hits to format and store them.

Parameters :
Name Type Optional Description
hits any No

Hits to be processed.

Returns : void
Public processParticles
processParticles(particles: any)

Process Particles to format and store them.

Parameters :
Name Type Optional Description
particles any No

Particles to be processed.

Returns : void
Public processTruth
processTruth(truth: any)

Process Truth data to format and store it.

Parameters :
Name Type Optional Description
truth any No

Truth data to be processed.

Returns : void
Private addCollection
addCollection(objectCollection: any, collectionName: string, getObject: (object: any) => void, typeName: string, objectGroup: Group, concatonateObjs: boolean)
Inherited from PhoenixLoader
Defined in PhoenixLoader:509

Adds to the event display all the objects inside a collection.

Parameters :
Name Type Optional Description
objectCollection any No

Contains the params for every object of the collection.

collectionName string No

Label to UNIQUELY identify the collection.

getObject function No

Handles reconstructing the objects of the collection.

typeName string No
objectGroup Group No

Group containing the collections of the same object type.

concatonateObjs boolean No

If true, don't process objects individually, but process as a group (e.g. for point hits).

Returns : void
Public addLabelToEventObject
addLabelToEventObject(label: string, collection: string, indexInCollection: number)
Inherited from PhoenixLoader
Defined in PhoenixLoader:726

Add label of event object to the labels object.

Parameters :
Name Type Optional Description
label string No

Label to be saved.

collection string No

Collection the event object is a part of.

indexInCollection number No

Event object's index in collection.

Returns : string

A unique label ID string.

Protected addObjectType
addObjectType(object: any, getObject: any, typeName: string, concatonateObjs: boolean, cuts?: Cut[], extendEventDataTypeUI?: (typeFolder?: GUI,typeFolderPM?: PhoenixMenuNode) => void)
Inherited from PhoenixLoader
Defined in PhoenixLoader:446

Adds to the event display all collections of a given object type.

Parameters :
Name Type Optional Default value Description
object any No

Contains all collections of a given type (Tracks, Jets, CaloClusters...).

getObject any No

Function that handles of reconstructing objects of the given type.

typeName string No

Label for naming the object type.

concatonateObjs boolean No false

If true, don't process objects individually, but process as a group (e.g. for point hits). Default is false.

cuts Cut[] Yes

Filters that can be applied to the objects.

extendEventDataTypeUI function Yes

A callback to add more options to event data type UI folder.

Returns : void
Public addScaleOptions
addScaleOptions(configKey: string, configLabel: string, scaleFunction: (value: number) => void)
Inherited from PhoenixLoader
Defined in PhoenixLoader:760

Get function to add options to scale event object type by.

Parameters :
Name Type Optional Description
configKey string No

Key of the scale configuration option (for dat.GUI menu).

configLabel string No

Label of the scale configuration option.

scaleFunction function No

Function to scale the objects by.

Function which adds scale options to Phoenix menu and dat.GUI menu.

Public buildEventData
buildEventData(eventData: any, graphicsLibrary: ThreeManager, ui: UIManager, infoLogger: InfoLogger)
Inherited from PhoenixLoader
Defined in PhoenixLoader:50

Takes an object that represents ONE event and takes care of adding the different objects to the graphics library and the UI controls.

Parameters :
Name Type Optional Description
eventData any No

Object representing the event.

graphicsLibrary ThreeManager No

Service containing functionality to draw the 3D objects.

ui UIManager No

Service for showing menus and controls to manipulate the geometries.

infoLogger InfoLogger No

Service for logging data to the information panel.

Returns : void
Public getCollection
getCollection(collectionName: string)
Inherited from PhoenixLoader
Defined in PhoenixLoader:126

Get the collection with the given collection name from the event data.

Parameters :
Name Type Optional Description
collectionName string No

Name of the collection to get.

Returns : any

An object containing the collection.

Public getCollections
getCollections()
Inherited from PhoenixLoader
Defined in PhoenixLoader:102

Get list of collections in the event data.

Returns : string[]

List of all collection names.

Protected getCompound
getCompound(params: any, name: string, objectIsTrack: boolean, objectIsCluster: boolean)
Inherited from PhoenixLoader
Defined in PhoenixLoader:574

Process the compound object (e.g. Muon, Electron, Photon) from the given parameters and get it as a group. FIXME. This is currently here and not in PhoenixObjects because we need to handle linked objects.

Parameters :
Name Type Optional Default value Description
params any No

Parameters of the Muon.

name string No ''
objectIsTrack boolean No false
objectIsCluster boolean No false
Returns : Object3D

Muon group containing Clusters and Tracks.

Protected getCompoundCluster
getCompoundCluster(params: any, name: string)
Inherited from PhoenixLoader
Defined in PhoenixLoader:564

Process the compound object of cluster type (e.g. Photon, ..) from the given parameters and get it as a group.

Parameters :
Name Type Optional Default value
params any No
name string No ''
Returns : Object3D
Protected getCompoundTrack
getCompoundTrack(params: any, name: string)
Inherited from PhoenixLoader
Defined in PhoenixLoader:558

Process the compound object of track type (e.g. Muon, Electron, ..) from the given parameters and get it as a group.

Parameters :
Name Type Optional Default value
params any No
name string No ''
Returns : Object3D
getEventMetadata
getEventMetadata()
Inherited from PhoenixLoader
Defined in PhoenixLoader:672

Get metadata associated to the event (experiment info, time, run, event...).

Returns : any[]

Metadata of the event.

Public getEventsList
getEventsList(eventsData: any)
Inherited from PhoenixLoader
Defined in PhoenixLoader:86

Get the list of event names from the event data.

Parameters :
Name Type Optional Description
eventsData any No

Object containing all event data.

Returns : string[]

List of event names.

Public getLabelsObject
getLabelsObject()
Inherited from PhoenixLoader
Defined in PhoenixLoader:749

Get the object containing labels.

Returns : literal type

The labels object.

Private getObjectTypeCollections
getObjectTypeCollections(object: any)
Inherited from PhoenixLoader
Defined in PhoenixLoader:544

Get collection names of a given object type.

Parameters :
Name Type Optional Description
object any No

Contains all collections of a given type (Tracks, Jets, CaloClusters etc.).

Returns : string[]

List of collection names of an object type (Tracks, Jets, CaloClusters etc.).

Protected loadObjectTypes
loadObjectTypes(eventData: any)
Inherited from PhoenixLoader
Defined in PhoenixLoader:147

Receives an object containing the data from an event and parses it to reconstruct the different collections of physics objects.

Parameters :
Name Type Optional Description
eventData any No

Representing ONE event (expressed in the Phoenix format).

Returns : void
import { PhoenixLoader } from './phoenix-loader';

/**
 * PhoenixLoader for processing and loading an event from TrackML.
 */
export class TrackmlLoader extends PhoenixLoader {
  /** Data containing Hits. */
  private hitData: any;
  /** Data containing Particles. */
  private particleData: any;
  /** Data containing truthy Particles. */
  private truthData: any;

  /**
   * Instiantiate the TrackML loader.
   */
  constructor() {
    super();
    this.hitData = [];
    this.particleData = [];
    this.truthData = {};
  }

  /**
   * Process Hits to format and store them.
   * @param hits Hits to be processed.
   */
  public processHits(hits: any) {
    const data = hits.split('\n');
    console.log('Event has this many hits:', data.length);

    let values;
    // format is: hit_id,x,y,z,volume_id,layer_id,module_id
    for (let line = 1; line < data.length; line++) {
      values = data[line].split(',');
      this.hitData[values[0]] = [
        parseFloat(values[1]),
        parseFloat(values[2]),
        parseFloat(values[3]),
      ];
    }
  }

  /**
   * Process Particles to format and store them.
   * @param particles Particles to be processed.
   */
  public processParticles(particles: any) {
    const data = particles.split('\n');
    console.log('Event has this many particles:', data.length);

    let values;
    // format is: particle_id,vx,vy,vz,px,py,pz,q,nhits
    for (let line = 1; line < data.length; line++) {
      values = data[line].split(',');
      this.particleData.push({
        particle_id: parseInt(values[0]),
        vertex_pos: [
          parseFloat(values[1]),
          parseFloat(values[2]),
          parseFloat(values[3]),
        ],
        mom: [
          parseFloat(values[4]),
          parseFloat(values[5]),
          parseFloat(values[6]),
        ],
      });
    }
  }

  /**
   * Process Truth data to format and store it.
   * @param truth Truth data to be processed.
   */
  public processTruth(truth: any) {
    const data = truth.split('\n');
    console.log('Event has this many truth: ', data.length);

    let values;
    // format is: hit_id,particle_id,tx,ty,tz,tpx,tpy,tpz,weight
    for (let line = 1; line < data.length; line++) {
      values = data[line].split(',');
      this.truthData[values[0]] = [
        values[1],
        values[2],
        values[3],
        values[4],
        values[5],
        values[6],
        values[7],
        values[8],
      ];
    }
  }

  /**
   * Get structured event data from the processed Hits, Truth data and Particles.
   * @param eventNum Event number.
   */
  public getEventData(eventNum: string): any {
    const eventData = {
      eventNumber: eventNum,
      runNumber: 0,
      Hits: undefined,
      Tracks: undefined,
    };

    if (this.hitData) {
      eventData.Hits = {};
      eventData.Hits.Reconstructed = [];
      let mod = Math.round(this.hitData.length / 5000);
      if (mod < 1) {
        mod = 1;
      }
      let count = 0;
      for (let i = 1; i < this.hitData.length; i++) {
        if (i % mod) {
          continue;
        }
        eventData.Hits.Reconstructed[count++] = [
          [this.hitData[i][0], this.hitData[i][1], this.hitData[i][2]],
        ];
      }
    }
    console.log(
      'Will show this many hits',
      eventData.Hits.Reconstructed.length,
    );

    if (this.truthData) {
      eventData.Tracks = { Particles: [] };
      if (this.particleData) {
        for (let i = 0; i < this.particleData.length; i++) {
          // Add the relevant data from particle, such as first hit position - we'll add the particle_id because we need it later.
          eventData.Tracks.Particles[i] = {
            particle_id: this.particleData[i].particle_id,
            pos: [this.particleData[i].vertex_pos],
            mom: this.particleData[i].mom,
          };
          // console.log('Just added: ', event_data.Tracks.Particles[i-1]);
        }
      }
      let hitId;
      let particleId;
      const stepSize = parseInt(String(this.truthData.length / 10));
      for (let i = 1; i < this.truthData.length; i++) {
        // Now add the truth data - i.e. add the truth hits which match a particle to the particle (unsorted for the moment)
        hitId = i;
        particleId = parseInt(this.truthData[i][0]);
        for (let j = 0; j < eventData.Tracks.Particles.length; j++) {
          // console.log(event_data.Tracks.Particles[j]);
          if (eventData.Tracks.Particles[j].particle_id === particleId) {
            // Found matching particle - add the truth hit position to the particles positions
            eventData.Tracks.Particles[j].pos.push([
              parseFloat(this.truthData[i][1]),
              parseFloat(this.truthData[i][2]),
              parseFloat(this.truthData[i][3]),
            ]);
          }
        }
        if (i % stepSize === 0) {
          document.getElementById('info').innerHTML =
            'Processed ' +
            (100 * i) / this.truthData.length +
            '% of event data.';
        }
      }
    }

    let numParticleStubs = 0;
    for (let j = 0; j < eventData.Tracks.Particles.length; j++) {
      if (eventData.Tracks.Particles[j].pos.length < 3) {
        // console.log ('Track has less than 3 positions');
        // console.log(event_data.Tracks.Particles[j]);
        numParticleStubs++;
      }
    }
    const events = {};
    events[eventNum] = eventData;
    return eventData;
  }
}

results matching ""

    No results matching ""