Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-17 22:59:07

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