Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:19

0001 // Copyright 2020, Jefferson Science Associates, LLC.
0002 // Subject to the terms in the LICENSE file found in the top-level directory.
0003 //
0004 // This implements an event source to produce "fake" events. The events will
0005 // contain only one type of object of class "Hit". The JFactory_Cluster
0006 // object will then make Cluster objects from these later.
0007 //
0008 // Note that the "Hit" objects produced inherit from TObject but nothing
0009 // special is needed here to accommodate that.
0010 
0011 #include "JTestRootEventSource.h"
0012 #include "Hit.h"
0013 
0014 #include <JANA/JApplication.h>
0015 #include <JANA/JEvent.h>
0016 
0017 JTestRootEventSource::JTestRootEventSource() {
0018     SetTypeName(NAME_OF_THIS); // Provide JANA with class name
0019     SetCallbackStyle(CallbackStyle::ExpertMode);
0020 }
0021 
0022 JEventSource::Result JTestRootEventSource::Emit(JEvent& event) {
0023     /// Generate an event by inserting objects into "event".
0024     /// (n.b. a normal event source would read these from a file or stream)
0025 
0026     // Configure event and run numbers
0027     static size_t current_event_number = 1;
0028     event.SetEventNumber(current_event_number++);
0029     event.SetRunNumber(222);
0030     
0031     m_bench_utils.set_seed(event.GetEventNumber(), NAME_OF_THIS);
0032     // Spin the CPU a bit to limit the rate
0033     m_bench_utils.consume_cpu_ms(5);
0034 
0035     // Generate hit objects. We use random numbers to give some variation
0036     // and make things look a little more realistic
0037     std::uniform_int_distribution<int>    Hits_dist(3,10);
0038     std::uniform_int_distribution<int>    Chan_dist(-40,400);
0039     std::normal_distribution<double>      E_dist(0.75, 0.3);
0040     std::uniform_real_distribution<float> t_dist(30.0, 80.);
0041     std::vector<Hit*> hits;
0042     auto Nhits = Hits_dist(generator);
0043     for( int i=0; i< Nhits; i++ ) {
0044         hits.push_back(new Hit(Chan_dist(generator), Chan_dist(generator), E_dist(generator), t_dist(generator)));
0045     }
0046 
0047     // Add Hit objects to event
0048     event.Insert(hits);
0049     return Result::Success;
0050 }
0051