Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions Mu2eKinKal/fcl/prolog.fcl
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ Mu2eKinKal : {
@table::Mu2eKinKal.KKFIT
SampleSurfaces : ["ST_Outer","ST_Front","ST_Back"] # these are additional surfaces; surfaces used in extrapolation are also sampled
# save trajectories in the Detector region
SaveDomains : true
SaveTrajectory : Detector
SaveDomains : true
SaveTrajectory : Detector
}
FitSettings : {
@table::Mu2eKinKal.LHSEEDFIT
Expand Down Expand Up @@ -527,8 +527,8 @@ Mu2eKinKal : {
# Additional width is needed here as straight tracks have worse time resolution
MaxCaloClusterDt: 8
# save the full trajectory
SaveTrajectory: Full
SaveDomains : false # meaningless for Linefit
SaveTrajectory: Full
SaveDomains : false # meaningless for Linefit
}
FitSettings : @local::Mu2eKinKal.CHSEEDFIT
ExtensionSettings : @local::Mu2eKinKal.CHDRIFTEXT
Expand Down Expand Up @@ -573,6 +573,29 @@ Mu2eKinKal : {

Mu2eKinKal : {
@table::Mu2eKinKal

RegrowLH : {
module_type : RegrowLoopHelix
CaloClusterCollection : "CaloClusterMaker"
StrawDigiIndexMap : "SelectReco:StrawDigiMap"
RefitSettings : {
@table::Mu2eKinKal.REGROW
BFieldCorrection : true
}
KKFitSettings: {
@table::Mu2eKinKal.KKFIT
SampleSurfaces : ["ST_Outer","ST_Front","ST_Back"]
AddHits : false
SaveDomains : true
SaveTrajectory : Full
}
ExtrapolationSettings :{
@table::Mu2eKinKal.LHDRIFTXTRAP
BackToTracker: true
}
Extend: false
}

producers : {
# seed fits: these don't use drift information or BField corrections
KLSeedFit: @local::Mu2eKinKal.KLSeedFit
Expand Down Expand Up @@ -608,7 +631,6 @@ Mu2eKinKal.producers.KKUeSeedFit.FitDirection : @local::FitDir.downstream
Mu2eKinKal.producers.KKUmuSeedFit.ModuleSettings.FitParticle : @local::Particle.muminus
Mu2eKinKal.producers.KKUmuSeedFit.FitDirection : @local::FitDir.downstream

# save trajectories in the Detector region for downstream fits, just the T0 segment for the rest
Mu2eKinKal.producers.KKDe.ModuleSettings.FitParticle : @local::Particle.eminus
Mu2eKinKal.producers.KKDe.FitDirection : @local::FitDir.downstream
Mu2eKinKal.producers.KKDmu.ModuleSettings.FitParticle : @local::Particle.muminus
Expand All @@ -621,5 +643,4 @@ Mu2eKinKal.producers.KKUmu.FitDirection : @local::FitDir.upstream
Mu2eKinKal.producers.KKUe.ExtrapolationSettings.BackToTracker : true
Mu2eKinKal.producers.KKUmu.ExtrapolationSettings.BackToTracker : true

#
END_PROLOG
92 changes: 70 additions & 22 deletions Mu2eKinKal/src/RegrowLoopHelix_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ namespace mu2e {
using Comment = fhicl::Comment;
struct RegrowLoopHelixConfig {
fhicl::Atom<int> debug{Name("debug"), Comment("Debug level"), 0};
fhicl::Atom<art::InputTag> kalSeedCollection {Name("KalSeedCollection"), Comment("KalSeed collection to process") };
fhicl::OptionalAtom<art::InputTag> kalSeedCollection {Name("KalSeedCollection"), Comment("KalSeed collection to process") };
fhicl::OptionalAtom<art::InputTag> kalSeedPtrCollection {Name("KalSeedPtrCollection"), Comment("Collection of KalSeedPtrs to process") };
fhicl::Atom<art::InputTag> comboHitCollection {Name("ComboHitCollection"), Comment("Reduced ComboHit collection") };
fhicl::Atom<art::InputTag> caloClusterCollection {Name("CaloClusterCollection"), Comment("CaloCluster collection ") };
fhicl::OptionalAtom<art::InputTag> caloClusterCollection {Name("CaloClusterCollection"), Comment("CaloCluster collection ") };
fhicl::Atom<art::InputTag> indexMap {Name("StrawDigiIndexMap"), Comment("Map between original and reduced ComboHits") };
fhicl::OptionalAtom<art::InputTag> kalSeedMCAssns {Name("KalSeedMCAssns"), Comment("Association to KalSeedMC. If set, regrown KalSeeds will be associated with the same KalSeedMC as the original") };
fhicl::OptionalAtom<bool> copyKalSeedMCs { Name("CopyKalSeedMCs"), Comment("If set, and KalSeedMCs are referenced, create a deep copy of the input") };
fhicl::Table<KKFitConfig> kkfitSettings { Name("KKFitSettings") };
fhicl::Table<KKConfig> fitSettings { Name("RefitSettings") };
fhicl::Atom<bool> extend {Name("Extend"), Comment("Extend the fit") };
Expand Down Expand Up @@ -142,33 +144,45 @@ namespace mu2e {
Config config_; // refit configuration object, containing the fit schedule
KKFIT kkfit_;
art::ProductToken<KalSeedCollection> kseedcol_T_;
art::ProductToken<KalSeedPtrCollection> kseedptrcol_T_;
art::ProductToken<ComboHitCollection> chcol_T_;
art::ProductToken<CaloClusterCollection> cccol_T_;
art::ProductToken<IndexMap> indexmap_T_;
art::InputTag ksmca_T_;
bool fillMCAssns_;
bool fillMCAssns_, copyKalSeedMCs_;
bool extend_;
bool has_cccol_, has_kseedcol_, has_kseedptrcol_;
std::unique_ptr<KKExtrap> extrap_;
};

RegrowLoopHelix::RegrowLoopHelix(const Parameters& settings) : art::EDProducer(settings),
debug_(settings().debug()),
config_(Mu2eKinKal::makeConfig(settings().fitSettings())),
kkfit_(settings().kkfitSettings()),
kseedcol_T_(consumes<KalSeedCollection>(settings().kalSeedCollection())),
chcol_T_(consumes<ComboHitCollection>(settings().comboHitCollection())),
cccol_T_(mayConsume<CaloClusterCollection>(settings().caloClusterCollection())),
indexmap_T_(consumes<IndexMap>(settings().indexMap())),
fillMCAssns_(settings().kalSeedMCAssns(ksmca_T_)),
extend_(settings().extend())
extend_(settings().extend()),
has_cccol_(settings().caloClusterCollection()),
has_kseedcol_(settings().kalSeedCollection()),
has_kseedptrcol_(settings().kalSeedPtrCollection())
{
produces<KKTRKCOL>();
produces<KalSeedCollection>();
if(settings().extrapSettings())extrap_ = make_unique<KKExtrap>(*settings().extrapSettings());
if( fillMCAssns_){
consumes<KalSeedMCAssns>(ksmca_T_);
produces <KalSeedMCAssns>();
// require KalSeedMC copy choice
if(!(settings().copyKalSeedMCs(copyKalSeedMCs_)))
throw cet::exception("RECO")<<"mu2e::RegrowLoopHelix: Specify if KalSeedMC Collection is deep copied or not" << endl;
if(copyKalSeedMCs_){
produces<KalSeedMCCollection>();
}
}
if(has_kseedcol_)kseedcol_T_ = art::ProductToken<KalSeedCollection>(mayConsume<KalSeedCollection>(settings().kalSeedCollection().value()));
if(has_kseedptrcol_)kseedptrcol_T_ = art::ProductToken<KalSeedPtrCollection>(mayConsume<KalSeedPtrCollection>(settings().kalSeedPtrCollection().value()));
if(has_cccol_) cccol_T_ = art::ProductToken<CaloClusterCollection>(mayConsume<CaloClusterCollection>(settings().caloClusterCollection().value()));
}

void RegrowLoopHelix::beginRun(art::Run& run)
Expand All @@ -186,28 +200,47 @@ namespace mu2e {
GeomHandle<mu2e::Tracker> nominalTracker_h;
GeomHandle<Calorimeter> calo_h;
// find input event data
auto kseed_H = event.getValidHandle<KalSeedCollection>(kseedcol_T_);
const auto& kseedcol = *kseed_H;
auto ch_H = event.getValidHandle<ComboHitCollection>(chcol_T_);
const auto& chcol = *ch_H;
auto cc_H = event.getHandle<CaloClusterCollection>(cccol_T_);
auto indexmap_H = event.getValidHandle<IndexMap>(indexmap_T_);
const auto& indexmap = *indexmap_H;
auto KalSeedCollectionPID = event.getProductID<KalSeedCollection>();
auto KalSeedCollectionGetter = event.productGetter(KalSeedCollectionPID);
art::ProductID KalSeedMCCollectionPID;
art::Handle<KalSeedMCAssns> ksmca_H;
// create outputs
unique_ptr<KKTRKCOL> ktrkcol(new KKTRKCOL );
unique_ptr<KalSeedCollection> rgkseedcol(new KalSeedCollection );
std::unique_ptr<KalSeedMCAssns> ksmca;
std::unique_ptr<KalSeedMCAssns> rgksmca;
std::unique_ptr<KalSeedMCCollection> rgksmcc;
// deal with MC
if(fillMCAssns_){
ksmca_H = event.getHandle<KalSeedMCAssns>(ksmca_T_);
if(!ksmca_H)throw cet::exception("RECO")<<"mu2e::RegrowLoopHelix: No KalSeedMCAssns found" << endl;
ksmca = std::unique_ptr<KalSeedMCAssns>(new KalSeedMCAssns);
rgksmca = std::unique_ptr<KalSeedMCAssns>(new KalSeedMCAssns);
if(copyKalSeedMCs_){
rgksmcc = std::unique_ptr<KalSeedMCCollection>(new KalSeedMCCollection);
KalSeedMCCollectionPID = event.getProductID<KalSeedMCCollection>();
}
}
if(!(has_kseedcol_ || has_kseedptrcol_) || (has_kseedcol_ && has_kseedptrcol_))
throw cet::exception("RECO")<<"mu2e::RegrowLoopHelix: exactly 1 of KalSeedCollection or KalSeedPtrCollection must be specified" << endl;

KalSeedPtrCollection kseedptrs;
if(has_kseedptrcol_){
auto kseedptr_H = event.getValidHandle<KalSeedPtrCollection>(kseedptrcol_T_);
kseedptrs = *kseedptr_H;
} else if(has_kseedcol_){
auto kseed_H = event.getValidHandle<KalSeedCollection>(kseedcol_T_);
const auto& kseedcol = *kseed_H;
for(size_t iks = 0; iks < kseedcol.size(); ++iks){
kseedptrs.emplace_back(kseed_H,iks);
}
}
size_t iseed(0);
for (auto const& kseed : kseedcol) {

for (auto const& kseedptr : kseedptrs) {
auto const& kseed = *kseedptr;
if(!kseed.loopHelixFit())throw cet::exception("RECO")<<"mu2e::RegrowLoopHelix: passed KalSeed from non-LoopHelix fit " << endl;
// regrow the components from the seed
PKTRAJPTR trajptr = kseed.loopHelixFitTrajectory();
Expand Down Expand Up @@ -249,17 +282,32 @@ namespace mu2e {
fitflag.merge(TrkFitFlag::Regrown);
auto rgks = kkfit_.createSeed(*ktrk,fitflag,*calo_h,*nominalTracker_h);
rgkseedcol->push_back(rgks);
auto rgksp = art::Ptr<KalSeed>(KalSeedCollectionPID,rgkseedcol->size()-1,KalSeedCollectionGetter);
if(fillMCAssns_){
// find the MC assns
auto ksmcai = (*ksmca_H)[iseed];
auto origksp = art::Ptr<KalSeed>(kseed_H,iseed);
auto ksmca = *ksmca_H;
auto ksmcai= ksmca.end();
for(auto ksmci= ksmca.begin(); ksmci != ksmca.end(); ++ksmci){
if(ksmci->first == kseedptr){
ksmcai = ksmci;
break;
}
}
// test this is the right ptr
if(ksmcai.first != origksp)throw cet::exception("Reco")<<"mu2e::RegrowLoopHelix: wrong KalSeed ptr"<< std::endl;
auto mcseedp = ksmcai.second;
auto rgksp = art::Ptr<KalSeed>(KalSeedCollectionPID,rgkseedcol->size()-1,KalSeedCollectionGetter);
ksmca->addSingle(rgksp,mcseedp);
// add the original too
ksmca->addSingle(origksp,mcseedp);
if(ksmcai == ksmca.end())throw cet::exception("Reco")<<"mu2e::RegrowLoopHelix: can't find MC associated with KalSeed" << std::endl;
if(copyKalSeedMCs_){
// deep-copy the KalSeedMC
rgksmcc->push_back(*ksmcai->second);
auto KalSeedMCCollectionGetter = event.productGetter(KalSeedMCCollectionPID);
auto mcseedp = art::Ptr<KalSeedMC>(KalSeedMCCollectionPID,rgksmcc->size()-1,KalSeedMCCollectionGetter);
rgksmca->addSingle(rgksp,mcseedp);
} else {
// just reference the original KalSeedMC
auto mcseedp = ksmcai->second;
rgksmca->addSingle(rgksp,mcseedp);
// add the original too
rgksmca->addSingle(kseedptr,mcseedp);
}
}
if(debug_ > 5)static_cast<const KinKal::PiecewiseTrajectory<KTRAJ>&>(ktrk->fitTraj()).print(std::cout,2);
ktrkcol->push_back(ktrk.release());
Expand All @@ -269,12 +317,12 @@ namespace mu2e {
if(debug_ > 3)std::cout<< "original seed had " << kseed.hits().size() << " hits, NDOF " << kseed.nDOF()<< " fitcon " << kseed.fitConsistency() << " and status " << kseed.status() << std::endl;
}
}
++iseed;
}
// store output
event.put(move(ktrkcol));
event.put(move(rgkseedcol));
if(fillMCAssns_)event.put(move(ksmca));
if(fillMCAssns_)event.put(move(rgksmca));
if(copyKalSeedMCs_)event.put(move(rgksmcc));
}

void RegrowLoopHelix::endJob()
Expand Down
7 changes: 4 additions & 3 deletions TrkReco/fcl/prolog.fcl
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ TrkReco: { @table::TrkReco
# standard config for reflection selection
SelectReflections: {
module_type : SelectReflections
MaxDeltaT : 20 # ns
MaxDeltaP : 10 # MeV
Surface : TT_Front
MaxDeltaT : 15 # ns
MaxDeltaP : 15 # MeV
# optionally only merge selected candidates
# a simple selector is used here, but any selector implemented as a tool can be used
Selector : {
Expand All @@ -150,7 +151,7 @@ TrkReco: { @table::TrkReco
MinDeltaNHitFraction : 0.0
MinActiveHits : 0
}
SelectBestPair : 0 # select highest-momentum match
SelectBestPair : 3 # select pair with highest # of active hits
debugLevel : 0
}
}
Expand Down
Loading