CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LHEAnalyzer.cc
Go to the documentation of this file.
1 #include <functional>
2 #include <algorithm>
3 #include <iostream>
4 #include <sstream>
5 #include <utility>
6 #include <string>
7 #include <vector>
8 #include <memory>
9 #include <cmath>
10 
11 #include <boost/bind.hpp>
12 #include <boost/ptr_container/ptr_vector.hpp>
13 
14 #include <TH1.h>
15 
16 #include <HepMC/GenEvent.h>
17 #include <HepMC/SimpleVector.h>
18 
27 
29 
31 
35 
36 using namespace lhef;
37 
38 class LHEAnalyzer : public edm::EDAnalyzer {
39  public:
40  explicit LHEAnalyzer(const edm::ParameterSet &params);
41  virtual ~LHEAnalyzer();
42 
43  protected:
44  virtual void analyze(const edm::Event &event,
45  const edm::EventSetup &es);
46 
47 
48  private:
49  void fillDJRSched(unsigned int min, unsigned int max);
50 
53 
55  double defaultPtCut;
56  double maxEta;
57  bool useEt;
58  double ptFraction;
59 
60  unsigned int binsDelta;
61  double minDelta;
62  double maxDelta;
63  unsigned int binsPt;
64  double minPt;
65  double maxPt;
66  unsigned int minDJR;
67  unsigned int maxDJR;
68 
69  boost::ptr_vector<JetClustering> deltaClustering;
70  std::auto_ptr<JetClustering> ptClustering;
71  std::vector<unsigned int> djrSched;
72 
73  std::vector<TH1*> histoDelta;
74  std::vector<TH1*> histoPt;
75 };
76 
78  sourceLabel(params.getParameter<edm::InputTag>("src")),
79  jetInput(params.getParameter<edm::ParameterSet>("jetInput")),
80  defaultDeltaCut(params.getParameter<double>("defaultDeltaCut")),
81  defaultPtCut(params.getParameter<double>("defaultPtCut")),
82  maxEta(params.getParameter<double>("maxEta")),
83  useEt(params.getParameter<bool>("useEt")),
84  ptFraction(params.getUntrackedParameter<double>("ptFraction", 0.75)),
85  binsDelta(params.getParameter<unsigned int>("binsDelta")),
86  minDelta(params.getParameter<double>("minDelta")),
87  maxDelta(params.getParameter<double>("maxDelta")),
88  binsPt(params.getParameter<unsigned int>("binsPt")),
89  minPt(params.getParameter<double>("minPt")),
90  maxPt(params.getParameter<double>("maxPt")),
91  minDJR(params.getParameter<unsigned int>("minDJR")),
92  maxDJR(params.getParameter<unsigned int>("maxDJR"))
93 {
94  edm::ParameterSet jetClusPSet =
95  params.getParameter<edm::ParameterSet>("jetClustering");
96 
97  for(unsigned int i = 0; i <= binsDelta; i++) {
98  double deltaCut =
100  jetClusPSet.addParameter("coneRadius", deltaCut);
102  tmp.addParameter("algorithm", jetClusPSet);
103  deltaClustering.push_back(
105  }
106 
107  jetClusPSet.addParameter("coneRadius", defaultDeltaCut);
109  tmp.addParameter("algorithm", jetClusPSet);
110  ptClustering.reset(new JetClustering(tmp, minPt * ptFraction));
111 
112  fillDJRSched(minDJR <= 0 ? 1 : minDJR, maxDJR - 1);
113 
115  for(unsigned int i = minDJR; i < maxDJR; i++) {
116  std::ostringstream ss, ss2;
117  ss << (i + 1) << "#rightarrow" << i << " jets";
118  ss2 << i;
119  TH1 *h = fs->make<TH1D>(("delta" + ss2.str()).c_str(),
120  ("DJR " + ss.str()).c_str(),
122  h->SetXTitle("p_{T} [GeV/c^2]");
123  h->SetYTitle("#delta#sigma [mb]");
124 
125  if (i == 0) {
126  h->Delete();
127  h = 0;
128  }
129  histoDelta.push_back(h);
130 
131  std::string what = useEt ? "E" : "p";
132  h = fs->make<TH1D>(("pt" + ss2.str()).c_str(),
133  ("DJR " + ss.str()).c_str(), binsPt,
134  std::log10(minPt), std::log10(maxPt));
135  h->SetXTitle(("log_{10}(" + what +
136  "_{T} [GeV/c^{2}])").c_str());
137  h->SetYTitle("#delta#sigma [mb]");
138 
139  histoPt.push_back(h);
140  }
141 }
142 
144 {
145 }
146 
147 void LHEAnalyzer::fillDJRSched(unsigned int min, unsigned int max)
148 {
149  unsigned int middle = (min + max) / 2;
150 
151  djrSched.push_back(middle);
152 
153  if (min < middle)
154  fillDJRSched(min, middle - 1);
155  if (middle < max)
156  fillDJRSched(middle + 1, max);
157 }
158 
160 {
161  using boost::bind;
162  typedef JetClustering::Jet Jet;
163 
165  event.getByLabel(sourceLabel, hepmc);
166 
167  std::auto_ptr<HepMC::GenEvent> clonedEvent;
168  const HepMC::GenEvent *genEvent = hepmc->GetEvent();
169  if (!genEvent->signal_process_vertex()) {
170  clonedEvent.reset(new HepMC::GenEvent(*genEvent));
171  const HepMC::GenVertex *signalVertex =
172  LHEEvent::findSignalVertex(clonedEvent.get());
173  clonedEvent->set_signal_process_vertex(
174  const_cast<HepMC::GenVertex*>(signalVertex));
175  genEvent = clonedEvent.get();
176  }
177 
178  JetInput::ParticleVector particles = jetInput(genEvent);
179 
180  std::vector<Jet> ptJets = (*ptClustering)(particles);
181  std::sort(ptJets.begin(), ptJets.end(),
182  bind(std::greater<double>(),
183  bind(useEt ? &Jet::et : &Jet::pt, _1),
184  bind(useEt ? &Jet::et : &Jet::pt, _2)));
185 
186  typedef std::pair<int, int> Pair;
187  std::vector<Pair> deltaJets(maxDJR - minDJR + 1,
188  Pair(-1, binsDelta + 1));
189 
190  for(std::vector<unsigned int>::const_iterator djr = djrSched.begin();
191  djr != djrSched.end(); ++djr) {
192 //std::cout << "DJR schedule " << (*djr + 1) << " -> " << *djr << std::endl;
193  int result = -1;
194  for(;;) {
195 //for(int i = minDJR; i <= maxDJR; i++)
196 //std::cout << "+++ " << i << ": (" << deltaJets[i - minDJR].first << ", " << deltaJets[i - minDJR].second << ")" << std::endl;
197  int upper = binsDelta + 1;
198  for(int i = *djr; i >= (int)minDJR; i--) {
199  if (deltaJets[i - minDJR].second <=
200  (int)binsDelta) {
201  upper = deltaJets[i - minDJR].second;
202  break;
203  }
204  }
205  int lower = -1;
206  for(int i = *djr + 1; i <= (int)maxDJR; i++) {
207  if (deltaJets[i - minDJR].first >= 0) {
208  lower = deltaJets[i - minDJR].first;
209  break;
210  }
211  }
212 //std::cout << "\t" << lower << " < " << upper << std::endl;
213 
214  result = (lower + upper + 2) / 2 - 1;
215  if (result == lower)
216  break;
217  else if (result < lower) {
218  result = -1;
219  break;
220  }
221 
222  std::vector<Jet> jets =
223  deltaClustering[result](particles);
224  unsigned int nJets = 0;
225  for(std::vector<Jet>::const_iterator iter =
226  jets.begin(); iter != jets.end(); ++iter)
227  if ((useEt ? iter->et() : iter->pt())
228  > defaultPtCut)
229  nJets++;
230 
231 //std::cout << "\t---(" << *djr << ")--> bin " << result << ": " << nJets << " jets" << std::endl;
232 
233  if (nJets < minDJR)
234  nJets = minDJR;
235  else if (nJets > maxDJR)
236  nJets = maxDJR;
237 
238  for(int j = nJets; j >= (int)minDJR; j--) {
239  if (deltaJets[j - minDJR].first < 0 ||
240  result > deltaJets[j - minDJR].first)
241  deltaJets[j - minDJR].first = result;
242  }
243  for(int j = nJets; j <= (int)maxDJR; j++) {
244  if (deltaJets[j - minDJR].second <
245  (int)binsDelta ||
246  result < deltaJets[j - minDJR].second)
247  deltaJets[j - minDJR].second = result;
248  }
249  }
250 
251 //std::cout << "final " << *djr << ": " << result << std::endl;
252  TH1 *h = histoDelta[*djr - minDJR];
253  h->Fill(h->GetBinCenter(result + 1));
254 
255  h = histoPt[*djr - minDJR];
256  if (*djr >= ptJets.size())
257  h->Fill(-999.0);
258  else if (useEt)
259  h->Fill(std::log10(ptJets[*djr].et()));
260  else
261  h->Fill(std::log10(ptJets[*djr].pt()));
262  }
263 
264  if (minDJR <= 0) {
265  TH1 *h = histoPt[0];
266  if (minDJR >= ptJets.size())
267  h->Fill(-999.0);
268  else if (useEt)
269  h->Fill(std::log10(ptJets[minDJR].et()));
270  else
271  h->Fill(std::log10(ptJets[minDJR].pt()));
272  }
273 }
274 
unsigned int minDJR
Definition: LHEAnalyzer.cc:66
std::auto_ptr< JetClustering > ptClustering
Definition: LHEAnalyzer.cc:70
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< TH1 * > histoDelta
Definition: LHEAnalyzer.cc:73
double maxPt
Definition: LHEAnalyzer.cc:65
double maxEta
Definition: LHEAnalyzer.cc:56
virtual ~LHEAnalyzer()
Definition: LHEAnalyzer.cc:143
JetInput jetInput
Definition: LHEAnalyzer.cc:52
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double defaultDeltaCut
Definition: LHEAnalyzer.cc:54
double minDelta
Definition: LHEAnalyzer.cc:61
double maxDelta
Definition: LHEAnalyzer.cc:62
double minPt
Definition: LHEAnalyzer.cc:64
#define min(a, b)
Definition: mlp_lapack.h:161
double maxEta
double defaultPtCut
Definition: LHEAnalyzer.cc:55
U second(std::pair< T, U > const &p)
unsigned int binsDelta
Definition: LHEAnalyzer.cc:60
const T & max(const T &a, const T &b)
std::vector< unsigned int > djrSched
Definition: LHEAnalyzer.cc:71
virtual void analyze(const edm::Event &event, const edm::EventSetup &es)
Definition: LHEAnalyzer.cc:159
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:139
tuple result
Definition: query.py:137
void fillDJRSched(unsigned int min, unsigned int max)
Definition: LHEAnalyzer.cc:147
int j
Definition: DBlmapReader.cc:9
LHEAnalyzer(const edm::ParameterSet &params)
Definition: LHEAnalyzer.cc:77
tuple genEvent
Definition: MCTruth.py:33
unsigned int maxDJR
Definition: LHEAnalyzer.cc:67
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool first
Definition: L1TdeRCT.cc:79
unsigned int binsPt
Definition: LHEAnalyzer.cc:63
edm::InputTag sourceLabel
Definition: LHEAnalyzer.cc:51
std::vector< TH1 * > histoPt
Definition: LHEAnalyzer.cc:74
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::vector< const HepMC::GenParticle * > ParticleVector
Definition: JetInput.h:17
T * make() const
make new ROOT object
double ptFraction
Definition: LHEAnalyzer.cc:58
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
boost::ptr_vector< JetClustering > deltaClustering
Definition: LHEAnalyzer.cc:69