Project

General

Profile

save_reco_results.cc

save data code example with instance name - Robert Sulej, 03/22/2016 10:14 AM

 
1
class PMAlgTrackMaker : public art::EDProducer {
2

    
3
    // ...a lot of things ommited...
4

    
5

    
6
    // would be good to have such names collected in one place, so e.g.
7
    // event display or analysis can easier find possible names...
8
    static const std::string kKinksName;
9
};
10
const std::string PMAlgTrackMaker::kKinksName = "kink";
11

    
12
PMAlgTrackMaker::PMAlgTrackMaker(fhicl::ParameterSet const & p)
13
{
14
    produces< std::vector<recob::Track> >();
15

    
16
    produces< std::vector<recob::Vertex> >(); // no instance name for interaction vertices, so it works with no changes for current codes
17
    produces< std::vector<recob::Vertex> >(kKinksName); // collection of kinks on tracks
18

    
19
    produces< art::Assns<recob::Vertex, recob::Track> >(); // no instance name for assns of tracks to interaction vertices
20
    produces< art::Assns<recob::Track, recob::Vertex> >(kKinksName);  // assns of kinks to tracks
21

    
22
    // ...some data products ommited...
23
}
24

    
25
void PMAlgTrackMaker::produce(art::Event& evt)
26
{
27
    std::unique_ptr< std::vector< recob::Track > > tracks(new std::vector< recob::Track >);
28

    
29
    std::unique_ptr< std::vector< recob::Vertex > > vtxs(new std::vector< recob::Vertex >);  // interaction vertices
30
    std::unique_ptr< std::vector< recob::Vertex > > kinks(new std::vector< recob::Vertex >); // kinks on tracks (no new particles start in kinks)
31

    
32
    std::unique_ptr< art::Assns< recob::Vertex, recob::Track > > vtx2trk(new art::Assns< recob::Vertex, recob::Track >); // one or more tracks (particles) start in the vertex
33
    std::unique_ptr< art::Assns< recob::Track, recob::Vertex > > trk2kink(new art::Assns< recob::Track, recob::Vertex >); // one or more kinks on the track
34

    
35
    // ...ommited code doig all the module job...
36

    
37
    auto kid = getProductID< std::vector<recob::Vertex> >(evt, kKinksName);
38
    auto const* kinkGetter = evt.productGetter(kid);
39

    
40
    auto tid = getProductID< std::vector<recob::Track> >(evt);
41
    auto const* trkGetter = evt.productGetter(tid);
42

    
43
    auto ksel = fPMAlgVertexing.getKinks(result); // vector of pairs: kink position - associated track idx
44

    
45
    // ...ommited code which prepares usual (unnamed) interaction vertex collection and vertex -> tracks assns...
46

    
47
    double xyz[3];
48
    for (auto const & k : ksel)
49
    {
50
        xyz[0] = k.first.X(); xyz[1] = k.first.Y(); xyz[2] = k.first.Z();
51

    
52
        size_t kidx = kinks->size();
53
        kinks->push_back(recob::Vertex(xyz, kidx));
54

    
55
        size_t tidx = k.second; // track idx on which this kink was found
56
        art::Ptr<recob::Track> tptr(tid, tidx, trkGetter);
57
        art::Ptr<recob::Vertex> kptr(kid, kidx, kinkGetter);
58
        trk2kink->addSingle(tptr, kptr);
59
    }
60

    
61
    evt.put(std::move(tracks));
62

    
63
    evt.put(std::move(vtxs));
64
    evt.put(std::move(kinks), kKinksName);
65

    
66
    evt.put(std::move(vtx2trk));
67
    evt.put(std::move(trk2kink), kKinksName);
68
}