Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:29:38

0001 
0002 // Copyright 2020, Jefferson Science Associates, LLC.
0003 // Subject to the terms in the LICENSE file found in the top-level directory.
0004 
0005 #include "SimpleClusterFactory.h"
0006 #include "Hit.h"
0007 
0008 #include <JANA/JEvent.h>
0009 
0010 void SimpleClusterFactory::Init() {
0011     // auto app = GetApplication();
0012     
0013     /// Acquire any parameters
0014     // app->GetParameter("parameter_name", m_destination);
0015     
0016     /// Acquire any services
0017     // m_service = app->GetService<ServiceT>();
0018     
0019     /// Set any factory flags
0020     // SetFactoryFlag(JFactory_Flags_t::NOT_OBJECT_OWNER);
0021 }
0022 
0023 void SimpleClusterFactory::ChangeRun(const std::shared_ptr<const JEvent> & /* event */) {
0024     /// This is automatically run before Process, when a new run number is seen
0025     /// Usually we update our calibration constants by asking a JService
0026     /// to give us the latest data for this run number
0027     
0028     // auto run_nr = event->GetRunNumber();
0029     // m_calibration = m_service->GetCalibrationsForRun(run_nr);
0030 }
0031 
0032 void SimpleClusterFactory::Process(const std::shared_ptr<const JEvent> &event) {
0033 
0034     /// JFactories are local to a thread, so we are free to access and modify
0035     /// member variables here. However, be aware that events are _scattered_ to
0036     /// different JFactory instances, not _broadcast_: this means that JFactory 
0037     /// instances only see _some_ of the events. 
0038     
0039     /// Acquire inputs (This may recursively call other JFactories)
0040     auto hits = event->Get<Hit>();
0041 
0042     /// Do some computation
0043     auto cluster = new Cluster(0,0,0,0,0);
0044     for (auto hit : hits) {
0045         cluster->x_center += hit->x;
0046         cluster->y_center += hit->y;
0047         cluster->E_tot += hit->E;
0048         if (cluster->t_begin > hit->t) cluster->t_begin = hit->t;
0049         if (cluster->t_end < hit->t) cluster->t_end = hit->t;
0050     }
0051     cluster->x_center /= hits.size();
0052     cluster->y_center /= hits.size();
0053 
0054     /// Publish outputs
0055     std::vector<Cluster*> results;
0056     results.push_back(cluster);
0057     Set(results);
0058 }