Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-25 02:14:14

0001 // Include-cc file for ntuple dumpers in MkFinder::selectHitIndices
0002 // To be included in cc file, outside of any namespace.
0003 
0004 #include "RecoTracker/MkFitCore/standalone/RntDumper/RntDumper.h"
0005 #include "RecoTracker/MkFitCore/standalone/RntDumper/RntStructs.h"
0006 #include "RecoTracker/MkFitCore/standalone/RntDumper/RntConversions.h"
0007 
0008 #include <ROOT/RNTuple.hxx>
0009 #include <ROOT/RNTupleModel.hxx>
0010 
0011 #include <TTree.h>
0012 
0013 namespace {
0014   using namespace mkfit;
0015 
0016   struct RntIfc_selectHitIndices {
0017     using RNTupleWriter = ROOT::Experimental::RNTupleWriter;
0018 
0019     RntDumper *f_dumper;
0020     const bool f_do_rnt;
0021     const bool f_do_tree;
0022     std::vector<int> f_h_idcs;
0023     std::vector<int> f_h_remap;
0024     int f_h_cnt;
0025 
0026     RNTupleWriter *f_H_writer = nullptr;
0027     TTree *f_H_tree = nullptr;
0028     std::shared_ptr<HeaderLayer> h;
0029     std::shared_ptr<std::vector<CandInfo>> ci;
0030 
0031     RNTupleWriter *f_F_writer = nullptr;
0032     TTree *f_F_tree = nullptr;
0033     std::shared_ptr<HeaderLayer> f;
0034     std::shared_ptr<std::vector<FailedPropInfo>> fpi;
0035 
0036     RntIfc_selectHitIndices(bool rntp, bool treep) : f_do_rnt(rntp), f_do_tree(treep) {
0037       f_dumper = RntDumper::Create("SelHitIdcs.root");
0038 
0039       auto mh = f_dumper->CreateModel();
0040       // Register branches -- entry objects used for both RNTuple and TTree!
0041       h = mh->MakeField<HeaderLayer>("h");
0042       ci = mh->MakeField<std::vector<CandInfo>>("ci");
0043       if (f_do_rnt) {
0044         f_H_writer = f_dumper->WritifyModel(mh, "H_rnt");  // setup for writing
0045       }
0046       if (f_do_tree) {
0047         // printf("Addresses %p %p %p %p\n", h.get(), bso.get(), bsn.get(), lpi.get());
0048         f_H_tree = new TTree("H_tree", "info from selectHitIndices");
0049         f_H_tree->Branch("h", h.get());
0050         f_H_tree->Branch("ci", ci.get());
0051         f_dumper->RegisterTree(f_H_tree);
0052       }
0053 
0054       auto mf = f_dumper->CreateModel();
0055       f = mf->MakeField<HeaderLayer>("f");
0056       fpi = mf->MakeField<std::vector<FailedPropInfo>>("fpi");
0057       if (f_do_rnt) {
0058         f_F_writer = f_dumper->WritifyModel(mf, "F_rnt");  // setup for writing
0059       }
0060       if (f_do_tree) {
0061         // printf("Addresses %p %p %p %p\n", h.get(), bso.get(), bsn.get(), lpi.get());
0062         f_F_tree = new TTree("F_tree", "info on failed propagations from selectHitIndices");
0063         f_F_tree->Branch("f", f.get());
0064         f_F_tree->Branch("fpi", fpi.get());
0065         f_dumper->RegisterTree(f_F_tree);
0066       }
0067     }
0068 
0069     ~RntIfc_selectHitIndices() {}
0070 
0071     void ResetH() {
0072       ci->clear();
0073       f_h_cnt = 0;
0074     }
0075     void ResetF() { fpi->clear(); }
0076 
0077     void InnerIdcsReset(int maxN) {
0078       f_h_idcs.clear();
0079       std::vector<int> v(maxN, -666666);
0080       f_h_remap.swap(v);
0081     }
0082     CandInfo &RegisterGoodProp(int i, const MPlexLV &ctr, const Event *ev, int seed_idx) {
0083       f_h_idcs.push_back(i);
0084       f_h_remap[i] = f_h_cnt;
0085       ++f_h_cnt;
0086       // for (auto i : f_h_idcs) {
0087       //   auto gi = f_h_remap[i];
0088       //   // use i for local access, gi for access into tree vectors
0089       // }
0090 
0091       mini_propagators::State c(ctr, i);
0092       return ci->emplace_back(evsi2ssinfo(ev, seed_idx), state2state(c));
0093     }
0094     void RegisterFailedProp(int i, const MPlexLV &beg, const MPlexLV &end, const Event *ev, int seed_idx) {
0095       mini_propagators::State b(beg, i), e(end, i);
0096       fpi->emplace_back(evsi2ssinfo(ev, seed_idx), state2state(b), state2state(e));
0097     }
0098     int MapHIdx(int i) { return f_h_remap[i]; }
0099 
0100     void FillH() {
0101       for (auto &e : *ci)
0102         e.nan_check();
0103       if (f_do_rnt)
0104         f_H_writer->Fill();
0105       if (f_do_tree)
0106         f_H_tree->Fill();
0107     }
0108     void FillF() {
0109       if (fpi->empty())
0110         return;
0111       for (auto &e : *fpi)
0112         e.nan_check();
0113       if (f_do_rnt)
0114         f_F_writer->Fill();
0115       if (f_do_tree)
0116         f_F_tree->Fill();
0117     }
0118   };
0119 
0120   static RntIfc_selectHitIndices rnt_shi(false, true);
0121 }  // namespace