Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-14 00:04:41

0001 // -*- C++ -*-
0002 //
0003 // Package:    __subsys__/__pkgname__
0004 // Class:      __class__
0005 //
0006 /*
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  __author__
0015 //         Created:  __date__
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <iostream>
0022 
0023 #include "TCanvas.h"
0024 // user include files
0025 #include "__subsys__/__pkgname__/interface/__class__.h"
0026 #include "DataFormats/Common/interface/Handle.h"
0027 #include "FWCore/Framework/interface/Event.h"
0028 
0029 @example_track#include "DataFormats/TrackReco/interface/Track.h"
0030 @example_track#include "DataFormats/TrackReco/interface/TrackFwd.h"
0031 //
0032 // constants shared between the Selector and the Workers
0033 //
0034 @example_trackconst char* const kPt = "pt";
0035 //const char* const kA = "a";
0036 
0037 //===============================================
0038 //A worker processes the events.
0039 // A new worker is created each time the events are processed
0040 //===============================================
0041 
0042 // ------------ constructed for each PROOF Node  ------------
0043 // The arguments are
0044 //   fromSelector: these are copies of values set in the selector and sent to all workers
0045 //            out: these are the items which will be passed back to the selector (e.g. histograms)
0046 __class__Worker::__class__Worker(const TList* fromSelector, TList& out) {
0047   //h_a  = new TH1F( kA , "a"  , 100,  0, 20 );
0048   //out.Add(h_a);
0049 @example_track  h_pt = new TH1F(kPt, "P_t", 100, 0, 100);
0050 @example_track  out.Add(h_pt);
0051 }
0052 
0053 __class__Worker::~__class__Worker() {}
0054 
0055 // ------------ method called for each event  ------------
0056 void __class__Worker::process(const edm::Event& iEvent) {
0057   using namespace edm;
0058 @example_track  using reco::TrackCollection;
0059 @example_track
0060 @example_track  Handle<TrackCollection> tracks;
0061 @example_track  iEvent.getByLabel("ctfWithMaterialTracks", tracks);
0062 @example_track  for (const auto& track : *tracks) {
0063 @example_track    h_pt->Fill(track.pt());
0064 @example_track  }
0065 
0066   //using namespace edmtest;
0067   //edm::Handle<ThingCollection> hThings;
0068   //iEvent.getByLabel("Thing", hThings);
0069   //for (const auto& thing : *hThings) {
0070   //  h_a ->Fill(it->a);
0071   //}
0072 }
0073 
0074 // ------------ called after processing the events  ------------
0075 // The argument is the same as for the constructor
0076 void __class__Worker::postProcess(TList& out) {}
0077 
0078 //===============================================
0079 //Only one Selector is made per job. It gets all the results from each worker.
0080 //===============================================
0081 __class__::__class__() {}
0082 
0083 __class__::~__class__() {}
0084 
0085 // ------------ called just before all workers are constructed  ------------
0086 void __class__::begin(TList*& toWorkers) {}
0087 
0088 // ------------ called after all workers have finished  ------------
0089 // The argument 'fromWorkers' contains the accumulated output of all Workers
0090 void __class__::terminate(TList& fromWorkers) {
0091   using namespace std;
0092   auto canvas = std::make_unique<TCanvas>();
0093   //{
0094   //  TObject* hist = fromWorkers.FindObject(kA);
0095   //  if (nullptr != hist) {
0096   //    hist->Draw();
0097   //    canvas->SaveAs("a.jpg");
0098   //  } else {
0099   //    cout << "no '" << kA << "' histogram" << endl;
0100   //  }
0101   //
0102 @example_track
0103 @example_track  {
0104 @example_track    TObject* hist = fromWorkers.FindObject(kPt);
0105 @example_track    if (nullptr != hist) {
0106 @example_track      hist->Draw();
0107 @example_track      canvas->SaveAs("pt.jpg");
0108 @example_track    } else {
0109 @example_track      cout << "no '" << kPt << "' histogram" << endl;
0110 @example_track    }
0111 @example_track  }
0112 }