12 #ifndef COSMICSREMOVALANA_H 13 #define COSMICSREMOVALANA_H 89 void FillMCInfo( std::vector<recob::Hit>
const& hitlist,
90 std::vector<hit_origin_t> & hitOrigins,
91 std::vector<sim::MCHitCollection>
const& mchitCollectionVector,
92 std::map<int,const simb::MCTruth* >
const& trackIDToTruthMap);
97 std::vector<size_t>
const& track_indices_this_hit,
98 std::vector< std::vector< const anab::CosmicTag* > >
const& tags_per_cluster,
99 std::vector<bool> & hitsAccounted_per_tag,
100 std::vector<bool> & hitsAllTags);
105 std::vector<size_t>
const& cluster_indices_this_hit,
106 std::vector< std::vector< const anab::CosmicTag* > >
const& tags_per_cluster,
107 std::vector<bool> & hitsAccounted_per_tag,
108 std::vector<bool> & hitsAllTags);
211 tEventTree = (TTree*)tfs->
make<TTree>(
"CosmicEventTree",
"CosmicEventTree");
213 tEventTree->Branch(
"event", &cEventVals,
"runNumber/I:eventNumber/I:nHitsTotal_Unknown/I:nHitsTotal_Cosmic/I:nHitsTotal_NonCosmic/I:qTotal_Unknown/F:qTotal_Cosmic/F:qTotal_NonCosmic/F:nHitsTrack/I:nHitsTrack_Cosmic/I:nHitsTrack_NonCosmic/I:qTrack/F:qTrack_Cosmic/F:qTrack_NonCosmic/F:nHitsCluster/I:nHitsCluster_Cosmic/I:nHitsCluster_NonCosmic/I:qCluster/F:qCluster_Cosmic/F:qCluster_NonCosmic/F:TotalTaggedCharge_Cosmic/F:TotalTaggedCharge_NonCosmic/F:TotalTaggedHits_Cosmic/I:TotalTaggedHits_NonCosmic/I");
238 std::vector<recob::Hit>
const& hitVector(*hitListHandle);
240 std::vector<hit_origin_t> hitOrigins(hitVector.size());
245 std::vector<sim::MCHitCollection>
const& mchitcolVector(*mchitListHandle);
250 std::vector<simb::MCParticle>
const& mcParticleVector(*mcParticleHandle);
256 std::vector< const simb::MCTruth* >
261 std::map<int,const simb::MCTruth* > trackIDToTruthMap;
262 for(
size_t p_iter=0; p_iter<mcParticleVector.size(); p_iter++)
263 trackIDToTruthMap[ mcParticleVector[p_iter].TrackId() ] = particle_to_truth[p_iter];
265 FillMCInfo(hitVector, hitOrigins, mchitcolVector, trackIDToTruthMap);
269 std::vector<recob::Track>
const& trackVector(*trackListHandle);
273 std::vector<recob::Cluster>
const& clusterVector(*clusterListHandle);
277 std::vector< std::vector<size_t> >
283 std::vector< std::vector<size_t> >
287 std::vector< art::Handle< std::vector<anab::CosmicTag> > > cosmicTagHandlesVector(
fCosmicTagAssocLabel.size());
288 std::vector< art::Handle< art::Assns<recob::Track,anab::CosmicTag> > > assnTrackTagHandlesVector(
fCosmicTagAssocLabel.size());
289 std::vector< std::vector< const anab::CosmicTag* > > tags_per_track(trackVector.size(), std::vector<const anab::CosmicTag*>(
fCosmicTagAssocLabel.size()));
290 std::vector< art::Handle< art::Assns<recob::Cluster,anab::CosmicTag> > > assnClusterTagHandlesVector(
fCosmicTagAssocLabel.size());
291 std::vector< std::vector< const anab::CosmicTag* > > tags_per_cluster(clusterVector.size(), std::vector<const anab::CosmicTag*>(
fCosmicTagAssocLabel.size()));
295 catch(...){
continue; }
298 for(
auto const& pair : *assnTrackTagHandlesVector[label_i])
299 tags_per_track.at(pair.first.key())[label_i] = &(*(pair.second));
304 for(
auto const& pair : *assnClusterTagHandlesVector[label_i])
305 tags_per_cluster.at(pair.first.key())[label_i] = &(*(pair.second));
310 std::vector< std::vector<bool> > hitsAccounted(hitVector.size(),std::vector<bool>(
fCosmicTagAssocLabel.size(),
false));
311 std::vector<bool> hitsAllTags(hitVector.size(),
false);
313 for(
size_t hit_iter=0; hit_iter<hitVector.size(); hit_iter++){
315 float charge = hitVector[hit_iter].Integral();
318 if(track_indices_per_hit[hit_iter].size()!=0)
322 track_indices_per_hit[hit_iter],
324 hitsAccounted[hit_iter],
327 if(cluster_indices_per_hit[hit_iter].size()!=0)
331 cluster_indices_per_hit[hit_iter],
333 hitsAccounted[hit_iter],
390 std::vector<hit_origin_t> & hitOrigins,
391 std::vector<sim::MCHitCollection>
const& mchitCollectionVector,
392 std::map<int,const simb::MCTruth* >
const& trackIdToTruthMap){
394 auto const* ts = lar::providerFrom<detinfo::DetectorClocksService>();
396 for(
size_t itr=0; itr<hitlist.size(); itr++){
400 std::vector<int> trackIDs;
401 std::vector<double>
energy;
403 for(
auto const& mchit : mchitCollectionVector[this_hit.
Channel()] ){
405 trackIDs.push_back(mchit.PartTrackId());
406 energy.push_back(mchit.PartEnergy());
410 if(trackIDs.size()==0){
417 float cosmic_energy=0;
418 float non_cosmic_energy=0;
420 for(
size_t iter=0; iter<trackIDs.size(); iter++){
421 auto map_element = trackIdToTruthMap.find(std::abs(trackIDs[iter]));
422 if(map_element==trackIdToTruthMap.end())
continue;
423 int origin = map_element->second->Origin();
425 non_cosmic_energy += energy[iter];
427 cosmic_energy += energy[iter];
430 if(non_cosmic_energy > cosmic_energy){
448 std::vector<size_t>
const& track_indices_this_hit,
449 std::vector< std::vector< const anab::CosmicTag* > >
const& tags_per_track,
450 std::vector<bool> & hitsAccounted_per_tag,
451 std::vector<bool> & hitsAllTags){
454 cEventVals.
qTrack += charge;
466 if(hitsAccounted_per_tag[nCT])
continue;
468 for(
auto const& track_index : track_indices_this_hit){
469 if(!tags_per_track[track_index][nCT])
continue;
473 hitsAccounted_per_tag[nCT] =
true;
474 hitsAllTags[hit_iter] =
true;
494 std::vector<size_t>
const& cluster_indices_this_hit,
495 std::vector< std::vector< const anab::CosmicTag* > >
const& tags_per_cluster,
496 std::vector<bool> & hitsAccounted_per_tag,
497 std::vector<bool> & hitsAllTags){
512 if(hitsAccounted_per_tag[nCT])
continue;
514 for(
auto const& cluster_index : cluster_indices_this_hit){
515 if(!tags_per_cluster[cluster_index][nCT])
continue;
516 const anab::CosmicTag* currentTag(tags_per_cluster[cluster_index][nCT]);
519 hitsAccounted_per_tag[nCT] =
true;
520 hitsAllTags[hit_iter] =
true;
void analyze(const art::Event &evt)
read access to event
CosmicRemovalAna(fhicl::ParameterSet const &pset)
std::string fMCHitsModuleLabel
int TotalTaggedHits_NonCosmic
void FillMCInfo(std::vector< recob::Hit > const &hitlist, std::vector< hit_origin_t > &hitOrigins, std::vector< sim::MCHitCollection > const &mchitCollectionVector, std::map< int, const simb::MCTruth * > const &trackIDToTruthMap)
void FillAllTagsInfo(recob::Hit const &hit, hit_origin_t const &origin)
void FillClusterInfo(size_t const &hit_iter, hit_origin_t const &origin, float const &charge, std::vector< size_t > const &cluster_indices_this_hit, std::vector< std::vector< const anab::CosmicTag * > > const &tags_per_cluster, std::vector< bool > &hitsAccounted_per_tag, std::vector< bool > &hitsAllTags)
Declaration of signal hit object.
cEventProperties_t cEventVals
float TotalTaggedCharge_NonCosmic
std::vector< const U * > GetAssociatedVectorOneP(art::Handle< art::Assns< T, U > > h, art::Handle< std::vector< T > > index_p)
Definition of basic raw digits.
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
std::string fTrackModuleLabel
std::vector< float > cTaggedCharge_NonCosmic
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::string fHitsModuleLabel
#define DEFINE_ART_MODULE(klass)
Provides recob::Track data product.
std::vector< int > cTaggedHits_Cosmic
std::string fClusterModuleLabel
void InitEventTree(int run_number, int event_number)
int TotalTaggedHits_Cosmic
EventNumber_t event() const
EDAnalyzer(Table< Config > const &config)
Declaration of cluster object.
std::vector< int > cTaggedHits_NonCosmic
std::vector< float > fCosmicScoreThresholds
Detector simulation of raw signals on wires.
float PeakTime() const
Time of the signal peak, in tick units.
std::string fMCModuleLabel
T * make(ARGS...args) const
Utility object to perform functions of association.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
float TotalTaggedCharge_Cosmic
std::vector< std::vector< size_t > > GetAssociatedVectorManyI(art::Handle< art::Assns< T, U > > h, art::Handle< std::vector< T > > index_p)
std::vector< float > cTaggedCharge_Cosmic
2D representation of charge deposited in the TDC/wire plane
void FillTrackInfo(size_t const &hit_iter, hit_origin_t const &origin, float const &charge, std::vector< size_t > const &track_indices_this_hit, std::vector< std::vector< const anab::CosmicTag * > > const &tags_per_cluster, std::vector< bool > &hitsAccounted_per_tag, std::vector< bool > &hitsAllTags)
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
int nHitsCluster_NonCosmic
art framework interface to geometry description
constexpr Point origin()
Returns a origin position with a point of the specified type.
std::vector< std::string > fCosmicTagAssocLabel