Skip to content

Commit

Permalink
Merge pull request #85 from AndrewEdmonds11/multi-crv-coinc-collections
Browse files Browse the repository at this point in the history
Allow bestcrvmc to come from different collections
  • Loading branch information
AndrewEdmonds11 authored May 9, 2023
2 parents 1adc9f4 + 3b282b3 commit 1f01c51
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 5 deletions.
7 changes: 5 additions & 2 deletions fcl/TrkAnaReco.fcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ services : @local::Services.Reco

physics :
{
producers : { @table::TrkAnaReco.producers }
producers : {
@table::TrkAnaReco.producers
@table::TrkAnaReco.MCProducers
}
analyzers : { @table::TrkAnaReco.analyzers }
}

physics.TrkAnaTrigPath : [ @sequence::TrkAnaReco.TrigSequence ]
physics.TrkAnaTrigPath : [ @sequence::TrkAnaReco.MCTrigSequence, @sequence::TrkAnaReco.TrigSequence ]
physics.TrkAnaEndPath : [ @sequence::TrkAnaReco.EndSequence ]

# Include more information (MC, full TrkQual and TrkPID branches)
Expand Down
4 changes: 4 additions & 0 deletions fcl/TrkAnaReco_multipleBestCrv_differentThresholds.fcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "TrkAna/fcl/TrkAnaReco.fcl"

// We want a singles Assns between reco and MC CrvCoincidenceClusters from all different collections
physics.producers.MakeCrvCoincidenceClusterMCAssns.crvCoincidenceTags : [ "SelectRecoMC:CrvCoincidenceClusterFinder", "SelectRecoMC:CrvCoincidenceClusterFinder6PEs" ]
physics.producers.MakeCrvCoincidenceClusterMCAssns.crvCoincidenceMCTags : [ "compressRecoMCs:CrvCoincidenceClusterMatchMC", "compressRecoMCs:CrvCoincidenceClusterMatchMC6PEs" ]

// Define the new BestCrv modules and add them to the path
physics.producers.BestCrv6PEsDeM : @local::BestCrvDeM
physics.producers.BestCrv6PEsDeM.crvCoincidenceTag : "SelectRecoMC:CrvCoincidenceClusterFinder6PEs"
Expand Down
16 changes: 16 additions & 0 deletions fcl/prolog.fcl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ TrkPIDProducers : {
}
TrkPIDProducersPath : [ TrkPIDDeM, TrkPIDDeP ]

MakeCrvCoincidenceClusterMCAssns : {
module_type : "MakeCrvCoincidenceClusterMCAssns"
crvCoincidenceTags : [ "SelectRecoMC:CrvCoincidenceClusterFinder" ]
crvCoincidenceMCTags : [ "compressRecoMCs:CrvCoincidenceClusterMatchMC" ]
}

MakeCrvCoincidenceClusterMCAssnsProducers : {
MakeCrvCoincidenceClusterMCAssns : @local::MakeCrvCoincidenceClusterMCAssns
}
MakeCrvCoincidenceClusterMCAssnsPath : [ MakeCrvCoincidenceClusterMCAssns ]

BestCrv : {
module_type : BestCrvHitDeltaT
Expand Down Expand Up @@ -216,6 +226,7 @@ TrkAnaTreeMaker : {
MCTrajectoryLabel : "compressRecoMCs"
CrvWaveformsModuleLabel : "compressRecoMCs"
CrvDigiModuleLabel : "SelectRecoMC"
CrvCoincidenceClusterMCAssnsTag : "MakeCrvCoincidenceClusterMCAssns"
CrvPlaneY : 2653
FillMCInfo : true
FillTrkQualInfo : true
Expand Down Expand Up @@ -268,6 +279,11 @@ TrkAnaReco : {
TrigSequence : [ PBIWeight, @sequence::TrkQualProducersPath, @sequence::TrkPIDProducersPath, @sequence::BestCrvProducersPath ]
EndSequenceNoMC : [ TrkAnaNeg, TrkAnaPos ]
EndSequence : [ TrkAnaNeg, TrkAnaPos, genCountLogger ]

MCProducers : {
@table::MakeCrvCoincidenceClusterMCAssnsProducers
}
MCTrigSequence : [ @sequence::MakeCrvCoincidenceClusterMCAssnsPath ]
}

END_PROLOG
2 changes: 2 additions & 0 deletions inc/BestCrvAssns.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

#include "Offline/RecoDataProducts/inc/KalSeed.hh"
#include "Offline/RecoDataProducts/inc/CrvCoincidenceCluster.hh"
#include "Offline/MCDataProducts/inc/CrvCoincidenceClusterMC.hh"

namespace mu2e {
// Assns between a KalSeed and a CrvCoincidenceCluster
typedef art::Assns<mu2e::KalSeed, mu2e::CrvCoincidenceCluster> BestCrvAssns;
typedef art::Assns<mu2e::CrvCoincidenceCluster, mu2e::CrvCoincidenceClusterMC> CrvCoincidenceClusterMCAssns;
}
92 changes: 92 additions & 0 deletions src/MakeCrvCoincidenceClusterMCAssns_module.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//
// Module that creates an Assns between a CrvCoincidenceCluster
// and its associated CrvCoincidenceClusterMC
//
// Can take many collections of CrvCoincidenceClusters
//
// Original author: Andy Edmonds 2023-05-02
//

// Framework includes.
#include "art/Framework/Core/EDProducer.h"
#include "art/Framework/Principal/Event.h"
#include "art/Framework/Principal/SubRun.h"
#include "art/Framework/Principal/Handle.h"
#include "art/Framework/Core/ModuleMacros.h"
#include "fhiclcpp/types/Atom.h"
#include "fhiclcpp/types/OptionalAtom.h"
#include "fhiclcpp/types/Table.h"
#include "fhiclcpp/types/OptionalSequence.h"
#include "fhiclcpp/types/Sequence.h"

#include "TrkAna/inc/BestCrvAssns.hh"

// C++ includes.
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

namespace mu2e {

class MakeCrvCoincicdenceClusterMCAssns : public art::EDProducer {

public:
struct Config {
using Name=fhicl::Name;
using Comment=fhicl::Comment;

fhicl::Sequence<art::InputTag> crvCoincidenceTags{Name("crvCoincidenceTags"), Comment("art::InputTags for CrvCoincidenceClusterCollections")};
fhicl::Sequence<art::InputTag> crvCoincidenceMCTags{Name("crvCoincidenceMCTags"), Comment("art::InputTags for CrvCoincidenceClusterMCCollections")};
};
typedef art::EDProducer::Table<Config> Parameters;

explicit MakeCrvCoincicdenceClusterMCAssns(const Parameters& conf);
virtual ~MakeCrvCoincicdenceClusterMCAssns() { }

void beginJob();
void produce(art::Event& e);

private:

// fhicl parameters
std::vector<art::InputTag> _crvCoincidenceTags;
std::vector<art::InputTag> _crvCoincidenceMCTags;
};

MakeCrvCoincicdenceClusterMCAssns::MakeCrvCoincicdenceClusterMCAssns(const Parameters& conf):
art::EDProducer(conf),
_crvCoincidenceTags(conf().crvCoincidenceTags()),
_crvCoincidenceMCTags(conf().crvCoincidenceMCTags())
{
produces<CrvCoincidenceClusterMCAssns>();
}

void MakeCrvCoincicdenceClusterMCAssns::beginJob( ){ }

void MakeCrvCoincicdenceClusterMCAssns::produce(art::Event& event) {

auto outputAssns = std::make_unique<CrvCoincidenceClusterMCAssns>();
for (size_t i_collection = 0; i_collection < _crvCoincidenceTags.size(); ++i_collection) {
const auto& crvCoincidenceHandle = event.getValidHandle<CrvCoincidenceClusterCollection>(_crvCoincidenceTags.at(i_collection));
const auto& crvCoincidenceMCHandle = event.getValidHandle<CrvCoincidenceClusterMCCollection>(_crvCoincidenceMCTags.at(i_collection));

if (crvCoincidenceHandle->size() != crvCoincidenceMCHandle->size()) {
throw cet::exception("MakeCrvCoincicdenceClusterMCAssns") << "CrvCoincidenceCollection and CrvCoincidenceMCCollection have different sizes (" << crvCoincidenceHandle->size() << " != " << crvCoincidenceMCHandle->size() << ")" << std::endl;
}

for(size_t i_crvCoinc = 0; i_crvCoinc != crvCoincidenceHandle->size(); ++i_crvCoinc) {
auto crvCoincPtr = art::Ptr<CrvCoincidenceCluster>(crvCoincidenceHandle, i_crvCoinc);
auto crvCoincMCPtr = art::Ptr<CrvCoincidenceClusterMC>(crvCoincidenceMCHandle, i_crvCoinc);
outputAssns->addSingle(crvCoincPtr, crvCoincMCPtr);
}
}
event.put(std::move(outputAssns));
}
} // end namespace mu2e

// Part of the magic that makes this class a module.
// create an instance of the module. It also registers
using mu2e::MakeCrvCoincicdenceClusterMCAssns;
DEFINE_ART_MODULE(MakeCrvCoincicdenceClusterMCAssns);
16 changes: 13 additions & 3 deletions src/TrkAnaTreeMaker_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ namespace mu2e {
fhicl::Atom<std::string> crvStepLabel{Name("CrvStepLabel"), Comment("CrvStepLabel")};
fhicl::Atom<std::string> crvWaveformsModuleLabel{ Name("CrvWaveformsModuleLabel"), Comment("CrvWaveformsModuleLabel")};
fhicl::Atom<std::string> crvDigiModuleLabel{ Name("CrvDigiModuleLabel"), Comment("CrvDigiModuleLabel")};
fhicl::Atom<art::InputTag> crvMCAssnsTag{ Name("CrvCoincidenceClusterMCAssnsTag"), Comment("art::InputTag for CrvCoincidenceClusterMCAssns")};
// CRV -- other
fhicl::Atom<double> crvPlaneY{Name("CrvPlaneY"),2751.485}; //y of center of the top layer of the CRV-T counters

Expand Down Expand Up @@ -265,10 +266,12 @@ namespace mu2e {
std::string _crvStepLabel;
std::string _crvWaveformsModuleLabel;
std::string _crvDigiModuleLabel;
art::InputTag _crvMCAssnsTag;
double _crvPlaneY;
// CRV (inputs)
std::map<BranchIndex, std::vector<art::Handle<BestCrvAssns>>> _allBestCrvAssns;
art::Handle<CrvCoincidenceClusterMCCollection> _crvCoincidenceMCCollHandle;
art::Handle<CrvCoincidenceClusterMCAssns> _crvMCAssnsHandle;
// CRV (output)
std::vector<CrvHitInfoReco> _crvinfo;
std::map<BranchIndex, std::vector<CrvHitInfoReco>> _allBestCrvs; // there can be more than one of these per candidate/supplement
Expand Down Expand Up @@ -320,6 +323,7 @@ namespace mu2e {
_crvStepLabel(conf().crvStepLabel()),
_crvWaveformsModuleLabel(conf().crvWaveformsModuleLabel()),
_crvDigiModuleLabel(conf().crvDigiModuleLabel()),
_crvMCAssnsTag(conf().crvMCAssnsTag()),
_crvPlaneY(conf().crvPlaneY()),
_infoMCStructHelper(conf().infoMCStructHelper()),
_buffsize(conf().buffsize()),
Expand Down Expand Up @@ -670,7 +674,7 @@ namespace mu2e {
}
_allBestCrvAssns[i_branch] = bestCrvAssnsHandles;
if (_fillmc) {
event.getByLabel(_crvCoincidenceMCModuleLabel, _crvCoincidenceMCCollHandle);
event.getByLabel(_crvMCAssnsTag, _crvMCAssnsHandle);
}
}
}
Expand Down Expand Up @@ -926,8 +930,14 @@ namespace mu2e {
auto bestCrvCoinc = hBestCrvAssns->at(i_kseed).second;
_infoStructHelper.fillCrvHitInfo(bestCrvCoinc, _allBestCrvs.at(i_branch).at(i_bestCrvBranch));
if (_fillmc) {
auto bestCrvCoincMC = art::Ptr<CrvCoincidenceClusterMC>(_crvCoincidenceMCCollHandle, bestCrvCoinc.key());
_infoMCStructHelper.fillCrvHitInfoMC(bestCrvCoincMC, _allBestCrvMCs.at(i_branch).at(i_bestCrvBranch));
// loop through data-MC assns and find bestCrvCoinc (which is an art::Ptr){
for (const auto& i_crvMCAssn : *_crvMCAssnsHandle) {
if (bestCrvCoinc == i_crvMCAssn.first) {
auto bestCrvCoincMC = i_crvMCAssn.second;//art::Ptr<CrvCoincidenceClusterMC>(_crvCoincidenceMCCollHandle, bestCrvCoinc.key());
_infoMCStructHelper.fillCrvHitInfoMC(bestCrvCoincMC, _allBestCrvMCs.at(i_branch).at(i_bestCrvBranch));
break;
}
}
}
}
}
Expand Down

0 comments on commit 1f01c51

Please sign in to comment.