1 |
//--------------------------------------------------------------------------------------------------
|
2 |
// $Id: TrackToTrackAssociator.h,v 1.1 2008/09/27 05:48:25 loizides Exp $
|
3 |
//
|
4 |
// TrackToTrackAssociator
|
5 |
//
|
6 |
// Base class for all more specific candidate producers.
|
7 |
//
|
8 |
// Authors: C.Paus
|
9 |
//--------------------------------------------------------------------------------------------------
|
10 |
|
11 |
#ifndef MITEDM_PRODUCERS_TRACKTOTRACKASSOCIATOR_H
|
12 |
#define MITEDM_PRODUCERS_TRACKTOTRACKASSOCIATOR_H
|
13 |
|
14 |
#include <vector>
|
15 |
#include <iostream>
|
16 |
#include <TString.h>
|
17 |
#include "FWCore/Framework/interface/Frameworkfwd.h"
|
18 |
#include "FWCore/Framework/interface/EDProducer.h"
|
19 |
#include "FWCore/Framework/interface/Event.h"
|
20 |
#include "FWCore/Framework/interface/MakerMacros.h"
|
21 |
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
22 |
|
23 |
namespace mitedm
|
24 |
{
|
25 |
class TrackToTrackAssociator : public edm::EDProducer
|
26 |
{
|
27 |
public:
|
28 |
explicit TrackToTrackAssociator(const edm::ParameterSet&);
|
29 |
~TrackToTrackAssociator() {}
|
30 |
|
31 |
protected:
|
32 |
void beginJob(const edm::EventSetup&) {}
|
33 |
void produce(edm::Event&, const edm::EventSetup&);
|
34 |
void endJob() {}
|
35 |
|
36 |
// generic accessors to make the code more simple
|
37 |
void PrintErrorAndExit(const char *msg) const;
|
38 |
template <typename TYPE>
|
39 |
bool GetProduct(const std::string name, edm::Handle<TYPE> &product,
|
40 |
const edm::Event &event, bool ignore = true) const;
|
41 |
|
42 |
std::string fromTracksName_; //name of tracks which are association keys
|
43 |
std::string toTracksName_; //name of tracks which are association values
|
44 |
};
|
45 |
|
46 |
//------------------------------------------------------------------------------------------------
|
47 |
template <typename TYPE>
|
48 |
inline bool TrackToTrackAssociator::GetProduct(const std::string edmName, edm::Handle<TYPE> &product,
|
49 |
const edm::Event &evt, bool ignore) const
|
50 |
{
|
51 |
// Try to access data collection from EDM file. We check if we really get just one
|
52 |
// product with the given name. If not we print an error and exit.
|
53 |
|
54 |
try {
|
55 |
evt.getByLabel(edm::InputTag(edmName),product);
|
56 |
if (! product.isValid())
|
57 |
throw edm::Exception(edm::errors::Configuration, "TrackToTrackAssociator::GetProduct()\n")
|
58 |
<< "Cannot get collection with label " << edmName << std::endl;
|
59 |
} catch (...) {
|
60 |
if (ignore)
|
61 |
return false;
|
62 |
else {
|
63 |
edm::LogError("TrackToTrackAssociator") << "Cannot get collection with label "
|
64 |
<< edmName << std::endl;
|
65 |
PrintErrorAndExit(Form("Cannot get collection with label %s", edmName.c_str()));
|
66 |
}
|
67 |
}
|
68 |
return true;
|
69 |
}
|
70 |
}
|
71 |
#endif
|