27 #include "canvas/Persistency/Common/FindManyP.h" 34 #include "nug4/ParticleNavigation/ParticleList.h" 45 #include <unordered_map> 73 typedef long long int time;
108 produces<std::vector<CRT::Trigger>>();
109 produces<art::Assns<simb::MCParticle,CRT::Trigger>>();
122 const auto & mcp_handle = e.
getValidHandle<std::vector<simb::MCParticle>>(
"largeant");
125 auto const & mcparticles = *(mcp_handle);
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));
134 auto trigCol = std::make_unique<std::vector<CRT::Trigger>>();
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)
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());
154 for(
const auto & crtHitsMappedByModule : crtHitsModuleMap)
157 int module = crtHitsMappedByModule.first;
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){
170 const auto crtHitsMappedByTime = crtHitsMappedByModule.second;
172 mf::LogDebug(
"channels") <<
"Processing channel " << module <<
"\n";
174 std::stringstream ss;
176 mf::LogDebug(
"timeToHitTrackIds") <<
"Constructed readout windows for module " << crtChannel <<
":\n" 181 auto lastTimeStamp=
time(0);
183 for(
auto window : crtHitsMappedByTime)
185 if (i!=0 && (
time(
fDeadtime)+lastTimeStamp)>window.first && lastTimeStamp<window.first)
continue;
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; });
192 if(aboveThresh != hitsInWindow.end()){
194 std::vector<CRT::Hit> hits;
195 std::set<int> trkIDCheck;
196 const time timestamp = window.first;
198 std::set<uint32_t> channelBusy;
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();
205 if(channelBusy.insert(
channel).second){
206 hits.push_back(hitPair.first);
211 int tid = hitPair.second;
215 trkIDCheck.insert(tid);
223 for (
int tid : trkIDCheck){
226 auto search = map_trackID_to_handle_index.find(tid);
227 if (
search != map_trackID_to_handle_index.end()){
231 mf::LogDebug(
"GetAssns") <<
"No matching index... strange";
237 mf::LogDebug(
"GetAssns") <<
"TrackId from particle obtained with index " << index
238 <<
" is : " << particle.
TrackId() <<
" , expected: " << tid;
241 auto const mcptr = makeMCParticlePtr(index);
242 partToTrigger->addSingle(mcptr, makeTrigPtr(trigCol->size()-1));
246 lastTimeStamp=window.first;
248 MF_LOG_DEBUG(
"CreateTrigger") <<
"Creating CRT::Trigger...\n";
256 mf::LogDebug(
"CreateTrigger") <<
"Putting " << trigCol->size() <<
" CRT::Triggers into the event at the end of analyze().\n";
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
void produce(art::Event &e) override
EDProducer(fhicl::ParameterSet const &pset)
CRTSimRefac & operator=(CRTSimRefac const &)=delete
art framework interface to geometry description
#define DEFINE_ART_MODULE(klass)
CRTSimRefac(fhicl::ParameterSet const &p)
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
AuxDetGeo const & AuxDet(unsigned int const ad=0) const
Returns the specified auxiliary detector.
std::vector< AuxDetHit > AuxDetHitCollection
size_t fReadoutWindowSize
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
std::string to_string(ModuleType const mt)