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

Public Member Functions

 CRTSimRefac (fhicl::ParameterSet const &p)
 
 CRTSimRefac (CRTSimRefac const &)=delete
 
 CRTSimRefac (CRTSimRefac &&)=delete
 
CRTSimRefacoperator= (CRTSimRefac const &)=delete
 
CRTSimRefacoperator= (CRTSimRefac &&)=delete
 
void produce (art::Event &e) override
 
- 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 Types

typedef long long int time
 
typedef unsigned short adc_t
 

Private Attributes

mf::LogInfo logInfo_
 
art::InputTag fSimLabel
 
double fGeVToADC
 
time fIntegrationTime
 
size_t fReadoutWindowSize
 
size_t fDeadtime
 
adc_t fDACThreshold
 

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 51 of file CRTSimRefac_module.cc.

Member Typedef Documentation

typedef unsigned short CRT::CRTSimRefac::adc_t
private

Definition at line 74 of file CRTSimRefac_module.cc.

typedef long long int CRT::CRTSimRefac::time
private

Definition at line 73 of file CRTSimRefac_module.cc.

Constructor & Destructor Documentation

CRT::CRTSimRefac::CRTSimRefac ( fhicl::ParameterSet const &  p)
explicit

Definition at line 96 of file CRTSimRefac_module.cc.

96  : EDProducer{p},
97  logInfo_("CRTSimRefactor"),
98  fSimLabel(p.get<art::InputTag>("SimLabel")),
99  /*fScintillationYield(p.get<double>("ScintillationYield")),
100  fQuantumEff(p.get<double>("QuantumEff")),
101  fDummyGain(p.get<double>("DummyGain")),*/
102  fGeVToADC(p.get<double>("GeVToADC")),
103  fIntegrationTime(p.get<time>("IntegrationTime")),
104  fReadoutWindowSize(p.get<size_t>("ReadoutWindowSize")),
105  fDeadtime(p.get<size_t>("Deadtime")),
106  fDACThreshold(p.get<adc_t>("DACThreshold"))
107 {
108  produces<std::vector<CRT::Trigger>>();
109  produces<art::Assns<simb::MCParticle,CRT::Trigger>>();
110 
111 }
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
unsigned short adc_t
art::InputTag fSimLabel
p
Definition: test.py:223
CRT::CRTSimRefac::CRTSimRefac ( CRTSimRefac const &  )
delete
CRT::CRTSimRefac::CRTSimRefac ( CRTSimRefac &&  )
delete

Member Function Documentation

CRTSimRefac& CRT::CRTSimRefac::operator= ( CRTSimRefac const &  )
delete
CRTSimRefac& CRT::CRTSimRefac::operator= ( CRTSimRefac &&  )
delete
void CRT::CRTSimRefac::produce ( art::Event e)
overridevirtual

Implements art::EDProducer.

Definition at line 114 of file CRTSimRefac_module.cc.

115 {
116 
117 
118  //const auto & crtHits = e.getValidHandle<std::vector<sim::AuxDetHit>>("largeant");
119  auto const allSims = e.getMany<sim::AuxDetHitCollection>();
120 
121  // -- Get all MCParticles to do assns later
122  const auto & mcp_handle = e.getValidHandle<std::vector<simb::MCParticle>>("largeant"); // -- TODO: make this an input tag
123  art::PtrMaker<simb::MCParticle> makeMCParticlePtr{e,mcp_handle.id()};
125  auto const & mcparticles = *(mcp_handle); //dereference the handle
126 
127  // -- Construct map of trackId to MCParticle handle index to do assns later
128  std::unordered_map<int, int> map_trackID_to_handle_index;
129  for (size_t idx = 0; idx < mcparticles.size(); ++idx){
130  int tid = mcparticles[idx].TrackId();
131  map_trackID_to_handle_index.insert(std::make_pair(tid,idx));
132  }
133 
134  auto trigCol = std::make_unique<std::vector<CRT::Trigger>>();
135 
136  std::unique_ptr< art::Assns<simb::MCParticle, CRT::Trigger>> partToTrigger( new art::Assns<simb::MCParticle, CRT::Trigger>);
137 
138  art::PtrMaker<CRT::Trigger> makeTrigPtr(e);
139 
140 
142  std::map<int, std::map<time, std::vector<std::pair<CRT::Hit, int>>>> crtHitsModuleMap;
143  for(auto const& auxHits : allSims){
144  for(const auto & eDep: * auxHits)
145  {
146  const size_t tAvg = eDep.GetEntryT();
147  crtHitsModuleMap[(eDep.GetID())/64][tAvg/fIntegrationTime].emplace_back(CRT::Hit((eDep.GetID())%64, eDep.GetEnergyDeposited()*0.001f*fGeVToADC),eDep.GetTrackID());
148  mf::LogDebug("TrueTimes") << "Assigned true hit at time " << tAvg << " to bin " << tAvg/fIntegrationTime << ".\n";
149  }
150  }
151 
152 
153  // -- For each CRT module
154  for(const auto & crtHitsMappedByModule : crtHitsModuleMap)
155  {
156  int crtChannel = -1;
157  int module = crtHitsMappedByModule.first;
158 
159  std::string modStrng="U"+std::to_string(module+1);
160  if (module>15) modStrng="D"+std::to_string(module+1-16);
161  if ((module+1)==17) crtChannel=22;
162  if ((module+1)==1) crtChannel=24;
163  for (int i=0; i<32; ++i){
164  if (crtChannel==22 || crtChannel==24) break;
165  const auto& det = geom->AuxDet(i);
166  if(det.Name().find(modStrng) != std::string::npos){
167  crtChannel=i; break;
168  }
169  }
170  const auto crtHitsMappedByTime = crtHitsMappedByModule.second;
171 
172  mf::LogDebug("channels") << "Processing channel " << module << "\n";
173 
174  std::stringstream ss;
175 
176  mf::LogDebug("timeToHitTrackIds") << "Constructed readout windows for module " << crtChannel << ":\n"
177  << ss.str() << "\n";
178 
179 
180 
181  auto lastTimeStamp=time(0);
182  int i=0;
183  for(auto window : crtHitsMappedByTime)
184  {
185  if (i!=0 && (time(fDeadtime)+lastTimeStamp)>window.first && lastTimeStamp<window.first) continue;
186  i++;
187  const auto& hitsInWindow = window.second;
188  const auto aboveThresh = std::find_if(hitsInWindow.begin(), hitsInWindow.end(),
189  [this](const auto& hitPair) { return hitPair.first.ADC() > fDACThreshold; });
190 
191 
192 if(aboveThresh != hitsInWindow.end()){
193 
194  std::vector<CRT::Hit> hits;
195  std::set<int> trkIDCheck;
196  const time timestamp = window.first; //Set timestamp before window is changed.
197  const time end = (timestamp+fReadoutWindowSize);
198  std::set<uint32_t> channelBusy; //A std::set contains only unique elements. This set stores channels that have already been read out in
199  //this readout window and so are "busy" and cannot contribute any more hits.
200  for(auto busyCheckWindow : crtHitsMappedByTime ){
201  if (time(busyCheckWindow.first)<timestamp || time(busyCheckWindow.first)>end) continue;
202  for(const auto& hitPair: window.second){
203  const auto channel = hitPair.first.Channel(); //TODO: Get channel number back without needing art::Ptr here.
204  // Maybe store crt::Hits.
205  if(channelBusy.insert(channel).second){
206  hits.push_back(hitPair.first);
207 
208 
209  if (hitPair.first.ADC()>fDACThreshold){
210 
211  int tid = hitPair.second;
212 
213 
214 
215  trkIDCheck.insert(tid);
216 
217 
218  }
219  }
220  }
221  }
222 
223  for (int tid : trkIDCheck){
224  // -- safe index retrieval
225  int index = 0;
226  auto search = map_trackID_to_handle_index.find(tid);
227  if (search != map_trackID_to_handle_index.end()){
228  index = search->second;
229  mf::LogDebug("GetAssns") << "Found index : " << index;
230  } else {
231  mf::LogDebug("GetAssns") << "No matching index... strange";
232  continue;
233  }
234 
235  // -- Sanity check, not needed
236  simb::MCParticle particle = mcparticles[index];
237  mf::LogDebug("GetAssns") << "TrackId from particle obtained with index " << index
238  << " is : " << particle.TrackId() << " , expected: " << tid;
239  mf::LogDebug("GetMCParticle") << particle;
240 
241  auto const mcptr = makeMCParticlePtr(index);
242  partToTrigger->addSingle(mcptr, makeTrigPtr(trigCol->size()-1));
243 
244  }
245  //std::cout<<"Hits Generated:"<<hits.size()<<std::endl;
246  lastTimeStamp=window.first;
247 
248  MF_LOG_DEBUG("CreateTrigger") << "Creating CRT::Trigger...\n";
249  trigCol->emplace_back(crtChannel, timestamp*fIntegrationTime, std::move(hits));
250  } // For each readout with a triggerable hit
251  } // For each time window
252 
253  } //For each CRT module
254 
255  // -- Put Triggers and Assns into the event
256  mf::LogDebug("CreateTrigger") << "Putting " << trigCol->size() << " CRT::Triggers into the event at the end of analyze().\n";
257  e.put(std::move(trigCol));
258  e.put(std::move(partToTrigger));
259 
260 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::string string
Definition: nybbler.cc:12
uint8_t channel
Definition: CRTFragment.hh:201
int TrackId() const
Definition: MCParticle.h:210
const double e
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
Definition: DataViewImpl.h:479
def move(depos, offset)
Definition: depos.py:107
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
Definition: search.py:1
AuxDetGeo const & AuxDet(unsigned int const ad=0) const
Returns the specified auxiliary detector.
std::vector< AuxDetHit > AuxDetHitCollection
Definition: AuxDetHit.h:183
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
#define MF_LOG_DEBUG(id)
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34

Member Data Documentation

adc_t CRT::CRTSimRefac::fDACThreshold
private

Definition at line 89 of file CRTSimRefac_module.cc.

size_t CRT::CRTSimRefac::fDeadtime
private

Definition at line 88 of file CRTSimRefac_module.cc.

double CRT::CRTSimRefac::fGeVToADC
private

Definition at line 80 of file CRTSimRefac_module.cc.

time CRT::CRTSimRefac::fIntegrationTime
private

Definition at line 85 of file CRTSimRefac_module.cc.

size_t CRT::CRTSimRefac::fReadoutWindowSize
private

Definition at line 86 of file CRTSimRefac_module.cc.

art::InputTag CRT::CRTSimRefac::fSimLabel
private

Definition at line 77 of file CRTSimRefac_module.cc.

mf::LogInfo CRT::CRTSimRefac::logInfo_
private

Definition at line 70 of file CRTSimRefac_module.cc.


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