Public Member Functions | Private Member Functions | Private Attributes | List of all members
hit::MCHitFinder Class Reference
Inheritance diagram for hit::MCHitFinder:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Member Functions

 MCHitFinder (fhicl::ParameterSet const &p)
 
- Public Member Functions inherited from art::EDProducer
 EDProducer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDProducer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Producer
virtual ~Producer () noexcept
 
 Producer (fhicl::ParameterSet const &)
 
 Producer (Producer const &)=delete
 
 Producer (Producer &&)=delete
 
Produceroperator= (Producer const &)=delete
 
Produceroperator= (Producer &&)=delete
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void produce (art::Event &e) override
 

Private Attributes

std::string fLArG4ModuleName
 
bool fVerbose
 
bool fMakeMCWire
 

Additional Inherited Members

- Public Types inherited from art::EDProducer
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
- Public Types inherited from art::detail::Producer
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 
- Static Public Member Functions inherited from art::EDProducer
static void commitEvent (EventPrincipal &ep, Event &e)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 29 of file MCHitFinder_module.cc.

Constructor & Destructor Documentation

hit::MCHitFinder::MCHitFinder ( fhicl::ParameterSet const &  p)
explicit

Definition at line 43 of file MCHitFinder_module.cc.

44  : EDProducer{p}
45  {
46  fLArG4ModuleName = p.get<std::string>("LArG4ModuleName");
47  fMakeMCWire = p.get<bool>("MakeMCWire");
48  fVerbose = p.get<bool>("Verbose");
49  produces< std::vector< sim::MCHitCollection> >();
50  if(fMakeMCWire)
51  produces< std::vector< sim::MCWireCollection> >();
52  }
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
p
Definition: test.py:223
std::string fLArG4ModuleName

Member Function Documentation

void hit::MCHitFinder::produce ( art::Event e)
overrideprivatevirtual

Implements art::EDProducer.

Definition at line 54 of file MCHitFinder_module.cc.

55  {
56 
58 
59  const unsigned int nch = geo->Nchannels();
60 
61  std::unique_ptr< std::vector<sim::MCHitCollection> > hits_v ( new std::vector<sim::MCHitCollection>() );
62  std::unique_ptr< std::vector<sim::MCWireCollection> > wires_v ( new std::vector<sim::MCWireCollection>() );
63 
64  hits_v->reserve(nch);
65  wires_v->reserve(nch);
66  for(size_t ch=0; ch<nch; ++ch) {
67 
68  hits_v->push_back(sim::MCHitCollection(ch));
69  wires_v->push_back(sim::MCWireCollection(ch));
70 
71  }
72 
74  e.getByLabel(fLArG4ModuleName,simchArray);
75  if(!simchArray.isValid())
76  throw cet::exception(__PRETTY_FUNCTION__)
77  << "Did not find sim::SimChannel with a label: " << fLArG4ModuleName.c_str() << std::endl;
78 
79  // Loop over SimChannel
80  for(size_t simch_index=0; simch_index<simchArray->size(); ++simch_index) {
81 
82  const art::Ptr<sim::SimChannel> simch_ptr(simchArray,simch_index);
83 
84  size_t ch = simch_ptr->Channel();
85 
86  if(ch >= hits_v->size())
87 
88  throw cet::exception(__PRETTY_FUNCTION__)
89  << "Channel number " << ch << " exceeds total # of channels: " << nch << std::endl;
90 
91  auto &mchits = hits_v->at(ch);
92  auto &mcwires = wires_v->at(ch);
93 
94  std::map<sim::MCEnDep,sim::MCWire> edep_wire_map;
95  auto tdc_ide_map = simch_ptr->TDCIDEMap();
96 
97  ////////////////////////////////////////////////////////////
98  // Loop over stored data for a particular sim::SimChannel //
99  ////////////////////////////////////////////////////////////
100 
101  //
102  // Read & Convert
103  //
104  if(fVerbose)
105  std::cout<<std::endl<<"Processing Ch: "<<ch<<std::endl;
106 
107  for(auto const& tdc_ide_pair : tdc_ide_map) {
108 
109  auto const& tdc = tdc_ide_pair.first;
110  auto const& ide_v = tdc_ide_pair.second;
111 
112  for(auto const& ide : ide_v) {
113  sim::MCEnDep edep;
114  edep.SetVertex(ide.x,ide.y,ide.z);
115  edep.SetEnergy(ide.energy);
116  edep.SetTrackId(ide.trackID);
117 
118  sim::MCWire wire;
119  wire.SetStartTDC(tdc);
120 
121  auto edep_iter = edep_wire_map.insert(std::make_pair(edep,wire));
122 
123  //auto edep_iter = edep_wire_map.find(edep);
124 
125  auto last_tdc = (edep_iter).first->second.StartTDC() + (edep_iter).first->second.size() - 1;
126 
127  if(fVerbose) {
128 
129  if( edep_iter.second ) std::cout<<std::endl;
130 
131  std::cout<<" Track: "<<ide.trackID
132  <<" Vtx: " <<ide.x << " " << ide.y << " " <<ide.z << " " <<ide.energy
133  << " ... @ TDC = "<<tdc<<" ... "<<ide.numElectrons << std::endl;
134  }
135 
136  if( !(edep_iter.second) ) {
137 
138  if( last_tdc+1 != tdc ) {
139  /*
140  std::cerr
141  << "Found discontinuous TDC! "
142  << " Last (ADC @ TDC): " << (*(edep_iter.first->second.rbegin())) << " @ " << last_tdc
143  << " while current (ADC @ TDC): " << (ide.numElectrons * detp->ElectronsToADC()) << " @ " << tdc
144  << " ... skipping to store!"
145  << std::endl;
146  */
147  continue;
148  }
149  }
150  (edep_iter).first->second.push_back(ide.numElectrons);
151  }// Done looping over IDEs in a particular TDC
152  }// Done looping over TDC
153 
154  //
155  // Store
156  //
157  for(auto const& edep_wire_pair : edep_wire_map) {
158 
159  auto const& edep = edep_wire_pair.first;
160  auto const& wire = edep_wire_pair.second;
161 
162  // Create MCHit
164  float vtx[3] = {float(edep.Vertex()[0]),
165  float(edep.Vertex()[1]),
166  float(edep.Vertex()[2])};
167  hit.SetParticleInfo(vtx, edep.Energy(), edep.TrackId());
168 
169  double max_time = 0;
170  double qsum = 0;
171  double qmax = 0;
172  for(size_t wire_index=0; wire_index < wire.size(); ++wire_index) {
173 
174  auto q = wire.at(wire_index);
175 
176  qsum += q;
177 
178  if( q > qmax) { qmax = q; max_time = wire.StartTDC() + wire_index; }
179 
180  }
181  hit.SetCharge(qsum,qmax);
182  hit.SetTime(max_time,0);
183 
184  mchits.push_back(hit);
185 
186  if(!fMakeMCWire) continue;
187 
188  mcwires.push_back(wire);
189  } // End looping over all MCEnDep-MCWire pairs
190  } // End looping over all SimChannels
191 
192  e.removeCachedProduct(simchArray);
193 
194  std::sort((*hits_v).begin(),(*hits_v).end());
195  e.put(std::move(hits_v));
196 
197  if(fMakeMCWire) {
198  std::sort((*wires_v).begin(),(*wires_v).end());
199  e.put(std::move(wires_v));
200  }
201 
202  }
void SetCharge(float qsum, float amp)
Setter function for charge/amplitude.
Definition: MCHit.h:54
void SetEnergy(float e)
Definition: MCDataHolder.h:39
void SetParticleInfo(const float vtx[], const float energy, const int trackId)
Setter function for partile info.
Definition: MCHit.h:64
void SetTime(const float peak, const float width)
Setter function for time.
Definition: MCHit.h:57
void SetStartTDC(const unsigned int start)
Setter function for time.
Definition: MCWire.h:42
void SetTrackId(unsigned int id)
Definition: MCDataHolder.h:41
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
bool isValid() const noexcept
Definition: Handle.h:191
unsigned int StartTDC() const
Getter for start time.
Definition: MCWire.h:56
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
unsigned int TrackId() const
Definition: MCDataHolder.h:47
def move(depos, offset)
Definition: depos.py:107
void SetVertex(float x, float y, float z)
Definition: MCDataHolder.h:32
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
std::string fLArG4ModuleName
bool removeCachedProduct(Handle< PROD > &) const
Definition: DataViewImpl.h:927
float Energy() const
Definition: MCDataHolder.h:45
LArSoft geometry interface.
Definition: ChannelGeo.h:16
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
const std::array< float, 3 > & Vertex() const
Definition: MCDataHolder.h:43

Member Data Documentation

std::string hit::MCHitFinder::fLArG4ModuleName
private

Definition at line 36 of file MCHitFinder_module.cc.

bool hit::MCHitFinder::fMakeMCWire
private

Definition at line 38 of file MCHitFinder_module.cc.

bool hit::MCHitFinder::fVerbose
private

Definition at line 37 of file MCHitFinder_module.cc.


The documentation for this class was generated from the following file: