CMS 3D CMS Logo

TSelector.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: __subsys__/__pkgname__
4 // Class: __class__
5 //
6 /*
7 
8  Description: [one line class summary]
9 
10  Implementation:
11  [Notes on implementation]
12 */
13 //
14 // Original Author: __author__
15 // Created: __date__
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <iostream>
22 
23 #include "TCanvas.h"
24 // user include files
25 #include "__subsys__/__pkgname__/interface/__class__.h"
28 
29 @example_track#include "DataFormats/TrackReco/interface/Track.h"
30 @example_track#include "DataFormats/TrackReco/interface/TrackFwd.h"
31 //
32 // constants shared between the Selector and the Workers
33 //
34 @example_trackconst char* const kPt = "pt";
35 //const char* const kA = "a";
36 
37 //===============================================
38 //A worker processes the events.
39 // A new worker is created each time the events are processed
40 //===============================================
41 
42 // ------------ constructed for each PROOF Node ------------
43 // The arguments are
44 // fromSelector: these are copies of values set in the selector and sent to all workers
45 // out: these are the items which will be passed back to the selector (e.g. histograms)
46 __class__Worker::__class__Worker(const TList* fromSelector, TList& out) {
47  //h_a = new TH1F( kA , "a" , 100, 0, 20 );
48  //out.Add(h_a);
49 @example_track h_pt = new TH1F(kPt, "P_t", 100, 0, 100);
50 @example_track out.Add(h_pt);
51 }
52 
54 
55 // ------------ method called for each event ------------
57  using namespace edm;
58 @example_track using reco::TrackCollection;
59 @example_track
60 @example_track Handle<TrackCollection> tracks;
61 @example_track iEvent.getByLabel("ctfWithMaterialTracks", tracks);
62 @example_track for (const auto& track : *tracks) {
63 @example_track h_pt->Fill(track.pt());
64 @example_track }
65 
66  //using namespace edmtest;
67  //edm::Handle<ThingCollection> hThings;
68  //iEvent.getByLabel("Thing", hThings);
69  //for (const auto& thing : *hThings) {
70  // h_a ->Fill(it->a);
71  //}
72 }
73 
74 // ------------ called after processing the events ------------
75 // The argument is the same as for the constructor
77 
78 //===============================================
79 //Only one Selector is made per job. It gets all the results from each worker.
80 //===============================================
82 
84 
85 // ------------ called just before all workers are constructed ------------
86 void __class__::begin(TList*& toWorkers) {}
87 
88 // ------------ called after all workers have finished ------------
89 // The argument 'fromWorkers' contains the accumulated output of all Workers
90 void __class__::terminate(TList& fromWorkers) {
91  using namespace std;
92  auto canvas = std::make_unique<TCanvas>();
93  //{
94  // TObject* hist = fromWorkers.FindObject(kA);
95  // if (nullptr != hist) {
96  // hist->Draw();
97  // canvas->SaveAs("a.jpg");
98  // } else {
99  // cout << "no '" << kA << "' histogram" << endl;
100  // }
101  //
102 @example_track
103 @example_track {
104 @example_track TObject* hist = fromWorkers.FindObject(kPt);
105 @example_track if (nullptr != hist) {
106 @example_track hist->Draw();
107 @example_track canvas->SaveAs("pt.jpg");
108 @example_track } else {
109 @example_track cout << "no '" << kPt << "' histogram" << endl;
110 @example_track }
111 @example_track }
112 }
void process(const edm::Event &iEvent)
Definition: TSelector.cc:56
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
example_track example_track example_trackconst char *const kPt
Definition: TSelector.cc:34
example_track TH1F * h_pt
Definition: TSelector.h:31
__class__()
Definition: Skeleton.cc:29
int iEvent
Definition: GenABIO.cc:224
void begin(TList *&) override
Definition: TSelector.cc:86
__shared__ Hist hist
void postProcess(TList &)
Definition: TSelector.cc:76
auto const & tracks
cannot be loose
virtual ~__class__()
HLT enums.
bool include(const CollT &coll, const ItemT &item)
def canvas(sub, attr)
Definition: svgfig.py:482
void terminate(TList &) override
Definition: TSelector.cc:90
__class__Worker(const TList *, TList &)
Definition: TSelector.cc:46