Skip to content

Commit 77102eb

Browse files
Add branch for mcsteps that is independent of the track fits
1 parent 3ea9e08 commit 77102eb

5 files changed

Lines changed: 75 additions & 3 deletions

File tree

fcl/prolog.fcl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ EventNtupleMaker : {
319319
ExtraMCStepCollectionTags : []
320320
SurfaceStepCollectionTag : "compressRecoMCs"
321321
FitType : LoopHelix
322+
StepPointMCTags : [ "compressRecoMCs:virtualdetector" ]
322323
}
323324
# instance for processing trigger (digitization) output from simulation
324325
EventNtupleMakerTTMC: {

inc/InfoMCStructHelper.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace mu2e {
7575
void fillExtraMCStepInfos(KalSeedMC const& kseedmc, StepPointMCCollection const& mcsteps,
7676
std::vector<MCStepInfos>& mcsics, std::vector<MCStepSummaryInfo>& mcssis);
7777
void fillSurfaceStepInfos(KalSeedMC const& kseedmc, SurfaceStepCollection const& surfsteps,std::vector<SurfaceStepInfo>& ssic);
78-
78+
void fillStepPointMCInfo(StepPointMCCollection const& mcsteps, MCStepInfos& mcstepinfos);
7979
};
8080
}
8181

inc/MCStepInfo.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ namespace mu2e {
2020
XYZVectorF pos; // particle position at the start of this step
2121
void reset() {*this = MCStepInfo(); }
2222
bool valid() { return vid>=0; }
23+
int pdg = -1; // true PDG code
24+
int startCode = -1; // creation process code
25+
int stopCode = -1; // stop process code
26+
2327
};
2428

2529
using MCStepInfos = std::vector<MCStepInfo>;

src/EventNtupleMaker_module.cc

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,10 @@ namespace mu2e {
182182
fhicl::Atom<art::InputTag> primaryParticleTag{Name("PrimaryParticleTag"), Comment("Tag for PrimaryParticle"), art::InputTag()};
183183
fhicl::Atom<art::InputTag> kalSeedMCTag{Name("KalSeedMCAssns"), Comment("Tag for KalSeedMCAssn"), art::InputTag()};
184184
// extra MC
185-
fhicl::OptionalSequence<art::InputTag> extraMCStepTags{Name("ExtraMCStepCollectionTags"), Comment("Input tags for any other StepPointMCCollections you want written out")};
185+
fhicl::OptionalSequence<art::InputTag> extraMCStepTags{Name("ExtraMCStepCollectionTags"), Comment("Input tags for any other StepPointMCCollections you want written out. This will only write out steps associated with the KalSeed")};
186186
// passive elements and Virtual Detector MC information
187187
fhicl::OptionalAtom<art::InputTag> SurfaceStepsTag{Name("SurfaceStepCollectionTag"), Comment("SurfaceStep Collection")};
188+
fhicl::OptionalSequence<art::InputTag> stepPointMCTags{Name("StepPointMCTags"), Comment("Input tags for any other StepPointMCCollections you want written out. This will write out all steps in the collection")};
188189
// Calo MC
189190
fhicl::Atom<bool> fillCaloMC{ Name("FillCaloMC"),Comment("Fill CaloMC information"), true};
190191
fhicl::Atom<art::InputTag> caloClusterMCTag{Name("CaloClusterMCTag"), Comment("Tag for CaloClusterMCCollection") ,art::InputTag()};
@@ -249,7 +250,7 @@ namespace mu2e {
249250
std::map<size_t,unsigned> _tmap; // map between path and trigger ID. ID should come from trigger itself FIXME!
250251
// MC truth (fcl parameters)
251252
bool _fillmc;
252-
// MC truth inputs
253+
// MC steps (associated with KalSeed)
253254
std::vector<art::InputTag> _extraMCStepTags;
254255
std::vector<art::Handle<StepPointMCCollection>> _extraMCStepCollections;
255256
std::map<BranchIndex, std::map<StepCollIndex, std::vector<MCStepInfos>>> _extraMCStepInfos;
@@ -258,6 +259,11 @@ namespace mu2e {
258259
art::InputTag _surfaceStepsTag;
259260
std::map<BranchIndex, std::vector<std::vector<SurfaceStepInfo>>> _surfaceStepInfos;
260261
art::Handle<SurfaceStepCollection> _surfaceStepsHandle;
262+
// MC steps (all)
263+
std::vector<art::InputTag> _stepPointMCTags;
264+
std::vector<art::Handle<StepPointMCCollection>> _stepPointMCCollections;
265+
std::map<StepCollIndex, MCStepInfos> _stepPointMCInfos;
266+
261267
//
262268
art::Handle<PrimaryParticle> _pph;
263269
art::Handle<KalSeedMCAssns> _ksmcah;
@@ -441,6 +447,11 @@ namespace mu2e {
441447
_surfaceStepInfos[i_branch] = std::vector<std::vector<SurfaceStepInfo>>();
442448
}
443449
}
450+
if(_conf.stepPointMCTags(_stepPointMCTags)){
451+
for (StepCollIndex i_stepPointMCTag = 0; i_stepPointMCTag < _stepPointMCTags.size(); ++i_stepPointMCTag) {
452+
_stepPointMCInfos[i_stepPointMCTag] = MCStepInfos();
453+
}
454+
}
444455
}
445456
}
446457

@@ -566,6 +577,18 @@ namespace mu2e {
566577
}
567578
// helix info
568579
if(_conf.helices()) _ntuple->Branch("helices.",&_hinfos,_buffsize,_splitlevel);
580+
581+
// all MC information
582+
if (_fillmc) {
583+
if(_conf.stepPointMCTags(_stepPointMCTags)){
584+
for(size_t icoll=0;icoll < _stepPointMCTags.size(); ++icoll) {
585+
auto const& tag = _stepPointMCTags[icoll];
586+
auto inst = tag.instance();
587+
std::string branchname = "mcsteps_" + inst + ".";
588+
_ntuple->Branch(branchname.c_str(),&_stepPointMCInfos[icoll],_buffsize,_splitlevel);
589+
}
590+
}
591+
}
569592
}
570593

571594
void EventNtupleMaker::beginSubRun(const art::SubRun & subrun ) {
@@ -675,6 +698,16 @@ namespace mu2e {
675698
}
676699
event.getByLabel(_surfaceStepsTag,_surfaceStepsHandle);
677700

701+
// find extra MCStep collections
702+
_stepPointMCCollections.clear();
703+
for(size_t icoll = 0; icoll < _stepPointMCTags.size(); icoll++){
704+
auto const& tag = _stepPointMCTags[icoll];
705+
art::Handle<StepPointMCCollection> mcstepch;
706+
event.getByLabel(tag,mcstepch);
707+
_stepPointMCCollections.push_back(mcstepch);
708+
}
709+
710+
678711
// loop through all track types
679712
unsigned ntrks(0);
680713
for (BranchIndex i_branch = 0; i_branch < _allBranches.size(); ++i_branch) {
@@ -709,6 +742,10 @@ namespace mu2e {
709742
_extraMCStepSummaryInfos.at(i_branch).at(i_extraMCStepTag).clear();
710743
}
711744
_surfaceStepInfos.at(i_branch).clear();
745+
for (StepCollIndex i_stepPointMCTag = 0; i_stepPointMCTag < _stepPointMCTags.size(); ++i_stepPointMCTag) {
746+
_stepPointMCInfos.at(i_stepPointMCTag).clear();
747+
}
748+
712749

713750
if(_fillcalomc) { _allMCTCHIs.at(i_branch).clear(); }
714751

@@ -875,6 +912,17 @@ namespace mu2e {
875912
}
876913

877914
}
915+
916+
// fill MC information unrelated to any reconstructed object
917+
if (_fillmc) {
918+
// fill MCStepCollection branch
919+
for(size_t icoll = 0; icoll < _stepPointMCTags.size(); icoll++){
920+
auto const& mcsteps = *_stepPointMCCollections[icoll];
921+
auto& mcstepinfos = _stepPointMCInfos[icoll];
922+
_infoMCStructHelper.fillStepPointMCInfo(mcsteps, mcstepinfos);
923+
}
924+
}
925+
878926
// fill this row in the TTree
879927
bool fill = true; // default to fliling event
880928
if(_hastrks && ntrks == 0) { // if we require tracks (_hastrks) but we have none, don't write

src/InfoMCStructHelper.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,4 +434,23 @@ namespace mu2e {
434434
// std::sort(ssic.begin(),ssic.end(),[](const auto& a, const auto& b){return a.time < b.time;});
435435
}
436436

437+
void InfoMCStructHelper::fillStepPointMCInfo(StepPointMCCollection const& mcsteps, MCStepInfos& mcstepinfos) {
438+
GeomHandle<DetectorSystem> det;
439+
MCStepInfo mcstepinfo;
440+
for(auto const& mcstep : mcsteps) {
441+
std::cout << mcstep << std::endl;
442+
mcstepinfo.reset();
443+
mcstepinfo.vid = mcstep.volumeId();
444+
mcstepinfo.time = mcstep.time();
445+
mcstepinfo.de = mcstep.totalEDep();
446+
mcstepinfo.dp = mcstep.postMomentum().mag()- mcstep.momentum().mag();
447+
mcstepinfo.mom = mcstep.momentum();
448+
mcstepinfo.pos = XYZVectorF(det->toDetector(mcstep.position()));
449+
const auto& simParticle = mcstep.simParticle();
450+
mcstepinfo.pdg = simParticle->pdgId();
451+
mcstepinfo.startCode = simParticle->creationCode();
452+
mcstepinfo.stopCode = simParticle->stoppingCode();
453+
mcstepinfos.emplace_back(mcstepinfo);
454+
}
455+
}
437456
}

0 commit comments

Comments
 (0)