CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
VoronoiBackgroundProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <iostream>
4 
5 // user include files
6 
10 
13 
15 
17 
22 
25 
26 // For DB entry using JetCorrector to store the vector of float
29 
30 #include "VoronoiAlgorithm.h"
31 
32 using namespace std;
33 //
34 // class declaration
35 //
36 
38  public:
41 
42  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
43 
44  private:
45  virtual void produce(edm::Event&, const edm::EventSetup&);
46 
47  // ----------member data ---------------------------
48 
54  double equalizeR_;
57  bool isCalo_;
59  int etaBins_;
61  std::vector<reco::VoronoiBackground> vvm;
62 
63 };
64 
65 //
66 // constants, enums and typedefs
67 //
68 
69 
70 //
71 // static data member definitions
72 //
73 
74 //
75 // constructors and destructor
76 //
78  voronoi_(0),
79  doEqualize_(iConfig.getParameter<bool>("doEqualize")),
80  equalizeThreshold0_(iConfig.getParameter<double>("equalizeThreshold0")),
81  equalizeThreshold1_(iConfig.getParameter<double>("equalizeThreshold1")),
82  equalizeR_(iConfig.getParameter<double>("equalizeR")),
83  useTextTable_(iConfig.getParameter<bool>("useTextTable")),
84  jetCorrectorFormat_(iConfig.getParameter<bool>("jetCorrectorFormat")),
85  isCalo_(iConfig.getParameter<bool>("isCalo")),
86  tableLabel_(iConfig.getParameter<std::string>("tableLabel")),
87  etaBins_(iConfig.getParameter<int>("etaBins")),
88  fourierOrder_(iConfig.getParameter<int>("fourierOrder"))
89 {
90 
91  src_ = consumes<reco::CandidateView>(iConfig.getParameter<edm::InputTag>("src"));
92  //register your products
93 
94  produces<reco::VoronoiMap>();
95  produces<std::vector<float> >();
96 }
97 
98 
100 {
101 }
102 
103 
104 //
105 // member functions
106 //
107 
108 // ------------ method called to produce the data ------------
109 void
111 {
112  using namespace edm;
113  if(voronoi_ == 0){
114  UECalibration *ue = NULL;
115  if (useTextTable_) {
116  const bool isData = iEvent.isRealData();
117  const char *calibrationFile = NULL;
118  if(isCalo_){
119  if(isData) calibrationFile = "RecoHI/HiJetAlgos/data/ue_calibrations_hermite_calo_data.txt";
120  if(!isData) calibrationFile = "RecoHI/HiJetAlgos/data/ue_calibrations_hermite_calo_mc.txt";
121  }else{
122  if(isData) calibrationFile = "RecoHI/HiJetAlgos/data/ue_calibrations_hermite_pf_data.txt";
123  if(!isData) calibrationFile = "RecoHI/HiJetAlgos/data/ue_calibrations_hermite_pf_mc.txt";
124  }
125  ue = new UECalibration(calibrationFile);
126  }
127  else if (jetCorrectorFormat_) {
129 
130  iSetup.get<JetCorrectionsRecord>().get(tableLabel_,ueHandle);
131 
132  const JetCorrectorParametersCollection *payload = ueHandle.product();
133  std::vector<float> ue_vec = (*payload)[JetCorrectorParametersCollection::L1Offset].record(0).parameters();
134 
135  ue = new UECalibration(ue_vec);
136  }
137  else {
138  edm::ESHandle<UETable> ueHandle;
139 
140  iSetup.get<HeavyIonUERcd>().get(tableLabel_,ueHandle);
141 
142  const UETable *ueTable = ueHandle.product();
143  ue = new UECalibration(ueTable->values);
144  }
145 
147  }
148 
149  voronoi_->clear();
150  vvm.clear();
151 
153  iEvent.getByToken(src_,inputsHandle);
154 
155  for(unsigned int i = 0; i < inputsHandle->size(); ++i){
156  reco::CandidateViewRef ref(inputsHandle,i);
157  voronoi_->push_back_particle(ref->pt(),ref->eta(),ref->phi(),0);
158  }
159 
160  std::vector<double> subtracted_momenta = voronoi_->subtracted_unequalized_perp();
161  std::vector<double> equalized_momenta = voronoi_->subtracted_equalized_perp();
162  std::vector<double> particle_area = voronoi_->particle_area();
163  std::vector<double> voronoi_vn = voronoi_->perp_fourier();
164  std::auto_ptr<std::vector<float> > vnout(new std::vector<float>(voronoi_vn.begin(), voronoi_vn.end()));
165  std::auto_ptr<reco::VoronoiMap> mapout(new reco::VoronoiMap());
166  reco::VoronoiMap::Filler filler(*mapout);
167 
168  for(unsigned int i = 0; i < inputsHandle->size(); ++i){
169  reco::CandidateViewRef ref(inputsHandle,i);
170  const double pre_eq_pt = subtracted_momenta[i];
171  const double post_eq_pt = equalized_momenta[i];
172  const double area = particle_area[i];
173  const double mass_square = ref->massSqr();
174  const double pre_eq_mt = sqrt(mass_square + pre_eq_pt * pre_eq_pt);
175  const double post_eq_mt = sqrt(mass_square + post_eq_pt * post_eq_pt);
176 
177  reco::VoronoiBackground bkg(pre_eq_pt,post_eq_pt,pre_eq_mt,post_eq_mt,area);
178  LogDebug("VoronoiBackgroundProducer")<<"Subtraction --- oldpt : "<<ref->pt()<<" --- newpt : "<<post_eq_pt<<endl;
179  vvm.push_back(bkg);
180  }
181 
182  filler.insert(inputsHandle,vvm.begin(),vvm.end());
183  filler.fill();
184  iEvent.put(vnout);
185  iEvent.put(mapout);
186 
187 }
188 
189 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
190 void
193  desc.setUnknown();
194  descriptions.addDefault(desc);
195 }
196 
197 //define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
std::vector< double > perp_fourier(void)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
#define NULL
Definition: scimark2.h:8
virtual void produce(edm::Event &, const edm::EventSetup &)
bool isRealData() const
Definition: EventBase.h:63
std::vector< double > particle_area(void)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:230
void push_back_particle(const double perp, const double pseudorapidity, const double azimuth, const unsigned int reduced_particle_flow_id)
void addDefault(ParameterSetDescription const &psetDescription)
VoronoiBackgroundProducer(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< reco::VoronoiBackground > vvm
std::vector< float > values
Definition: UETable.h:25
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
edm::EDGetTokenT< reco::CandidateView > src_
std::vector< double > subtracted_unequalized_perp(void)
std::vector< double > subtracted_equalized_perp(void)
Definition: UETable.h:7