CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
PdfSystematicsAnalyzer Class Reference
Inheritance diagram for PdfSystematicsAnalyzer:
edm::EDFilter edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

virtual void beginJob () override
 
virtual void endJob () override
 
virtual bool filter (edm::Event &, const edm::EventSetup &) override
 
 PdfSystematicsAnalyzer (const edm::ParameterSet &pset)
 
virtual ~PdfSystematicsAnalyzer ()
 
- Public Member Functions inherited from edm::EDFilter
 EDFilter ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDFilter ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Attributes

unsigned int originalEvents_
 
std::vector< int > pdfStart_
 
std::vector< edm::InputTagpdfWeightTags_
 
unsigned int selectedEvents_
 
std::string selectorPath_
 
std::vector< double > weighted2SelectedEvents_
 
std::vector< double > weightedEvents_
 
std::vector< double > weightedSelectedEvents_
 

Additional Inherited Members

- Public Types inherited from edm::EDFilter
typedef EDFilter ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDFilter
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 5 of file PdfSystematicsAnalyzer.cc.

Constructor & Destructor Documentation

PdfSystematicsAnalyzer::PdfSystematicsAnalyzer ( const edm::ParameterSet pset)

Definition at line 35 of file PdfSystematicsAnalyzer.cc.

35  :
36  selectorPath_(pset.getUntrackedParameter<std::string> ("SelectorPath","")),
37  pdfWeightTags_(pset.getUntrackedParameter<std::vector<edm::InputTag> > ("PdfWeightTags")) {
38 }
T getUntrackedParameter(std::string const &, T const &) const
std::vector< edm::InputTag > pdfWeightTags_
PdfSystematicsAnalyzer::~PdfSystematicsAnalyzer ( )
virtual

Definition at line 41 of file PdfSystematicsAnalyzer.cc.

41 {}

Member Function Documentation

void PdfSystematicsAnalyzer::beginJob ( void  )
overridevirtual

Reimplemented from edm::EDFilter.

Definition at line 44 of file PdfSystematicsAnalyzer.cc.

References i, originalEvents_, pdfStart_, pdfWeightTags_, and selectedEvents_.

44  {
45  originalEvents_ = 0;
46  selectedEvents_ = 0;
47  edm::LogVerbatim("PDFAnalysis") << "PDF uncertainties will be determined for the following sets: ";
48  for (unsigned int i=0; i<pdfWeightTags_.size(); ++i) {
49  edm::LogVerbatim("PDFAnalysis") << "\t" << pdfWeightTags_[i].instance();
50  pdfStart_.push_back(-1);
51  }
52 }
int i
Definition: DBlmapReader.cc:9
std::vector< edm::InputTag > pdfWeightTags_
void PdfSystematicsAnalyzer::endJob ( void  )
overridevirtual

Reimplemented from edm::EDFilter.

Definition at line 55 of file PdfSystematicsAnalyzer.cc.

References i, j, originalEvents_, pdfStart_, pdfWeightTags_, selectedEvents_, mathSSE::sqrt(), weighted2SelectedEvents_, weightedEvents_, and weightedSelectedEvents_.

55  {
56 
57  if (originalEvents_==0) {
58  edm::LogVerbatim("PDFAnalysis") << "NO EVENTS => NO RESULTS";
59  return;
60  }
61  if (selectedEvents_==0) {
62  edm::LogVerbatim("PDFAnalysis") << "NO SELECTED EVENTS => NO RESULTS";
63  return;
64  }
65 
66  edm::LogVerbatim("PDFAnalysis") << "\n>>>> Begin of PDF weight systematics summary >>>>";
67  edm::LogVerbatim("PDFAnalysis") << "Total number of analyzed data: " << originalEvents_ << " [events]";
68  double originalAcceptance = double(selectedEvents_)/originalEvents_;
69  edm::LogVerbatim("PDFAnalysis") << "Total number of selected data: " << selectedEvents_ << " [events], corresponding to acceptance: [" << originalAcceptance*100 << " +- " << 100*sqrt( originalAcceptance*(1.-originalAcceptance)/originalEvents_) << "] %";
70 
71  edm::LogVerbatim("PDFAnalysis") << "\n>>>>> PDF UNCERTAINTIES ON RATE >>>>>>";
72  for (unsigned int i=0; i<pdfWeightTags_.size(); ++i) {
73  bool nnpdfFlag = (pdfWeightTags_[i].instance().substr(0,5)=="NNPDF");
74  unsigned int nmembers = weightedSelectedEvents_.size()-pdfStart_[i];
75  if (i<pdfWeightTags_.size()-1) nmembers = pdfStart_[i+1] - pdfStart_[i];
76  unsigned int npairs = (nmembers-1)/2;
77  edm::LogVerbatim("PDFAnalysis") << "RATE Results for PDF set " << pdfWeightTags_[i].instance() << " ---->";
78 
79  double events_central = weightedSelectedEvents_[pdfStart_[i]];
80  edm::LogVerbatim("PDFAnalysis") << "\tEstimate for central PDF member: " << int(events_central) << " [events]";
81  double events2_central = weighted2SelectedEvents_[pdfStart_[i]];
82  edm::LogVerbatim("PDFAnalysis") << "\ti.e. [" << std::setprecision(4) << 100*(events_central-selectedEvents_)/selectedEvents_ << " +- " <<
83  100*sqrt(events2_central-events_central+selectedEvents_*(1-originalAcceptance))/selectedEvents_
84  << "] % relative variation with respect to original PDF";
85 
86  if (npairs>0) {
87  edm::LogVerbatim("PDFAnalysis") << "\tNumber of eigenvectors for uncertainty estimation: " << npairs;
88  double wplus = 0.;
89  double wminus = 0.;
90  unsigned int nplus = 0;
91  unsigned int nminus = 0;
92  for (unsigned int j=0; j<npairs; ++j) {
93  double wa = weightedSelectedEvents_[pdfStart_[i]+2*j+1]/events_central-1.;
94  double wb = weightedSelectedEvents_[pdfStart_[i]+2*j+2]/events_central-1.;
95  if (nnpdfFlag) {
96  if (wa>0.) {
97  wplus += wa*wa;
98  nplus++;
99  } else {
100  wminus += wa*wa;
101  nminus++;
102  }
103  if (wb>0.) {
104  wplus += wb*wb;
105  nplus++;
106  } else {
107  wminus += wb*wb;
108  nminus++;
109  }
110  } else {
111  if (wa>wb) {
112  if (wa<0.) wa = 0.;
113  if (wb>0.) wb = 0.;
114  wplus += wa*wa;
115  wminus += wb*wb;
116  } else {
117  if (wb<0.) wb = 0.;
118  if (wa>0.) wa = 0.;
119  wplus += wb*wb;
120  wminus += wa*wa;
121  }
122  }
123  }
124  if (wplus>0) wplus = sqrt(wplus);
125  if (wminus>0) wminus = sqrt(wminus);
126  if (nnpdfFlag) {
127  if (nplus>0) wplus /= sqrt(nplus);
128  if (nminus>0) wminus /= sqrt(nminus);
129  }
130  edm::LogVerbatim("PDFAnalysis") << "\tRelative uncertainty with respect to central member: +" << std::setprecision(4) << 100.*wplus << " / -" << std::setprecision(4) << 100.*wminus << " [%]";
131  } else {
132  edm::LogVerbatim("PDFAnalysis") << "\tNO eigenvectors for uncertainty estimation";
133  }
134  }
135 
136  edm::LogVerbatim("PDFAnalysis") << "\n>>>>> PDF UNCERTAINTIES ON ACCEPTANCE >>>>>>";
137  for (unsigned int i=0; i<pdfWeightTags_.size(); ++i) {
138  bool nnpdfFlag = (pdfWeightTags_[i].instance().substr(0,5)=="NNPDF");
139  unsigned int nmembers = weightedEvents_.size()-pdfStart_[i];
140  if (i<pdfWeightTags_.size()-1) nmembers = pdfStart_[i+1] - pdfStart_[i];
141  unsigned int npairs = (nmembers-1)/2;
142  edm::LogVerbatim("PDFAnalysis") << "ACCEPTANCE Results for PDF set " << pdfWeightTags_[i].instance() << " ---->";
143 
144  double acc_central = 0.;
145  double acc2_central = 0.;
146  if (weightedEvents_[pdfStart_[i]]>0) {
147  acc_central = weightedSelectedEvents_[pdfStart_[i]]/weightedEvents_[pdfStart_[i]];
148  acc2_central = weighted2SelectedEvents_[pdfStart_[i]]/weightedEvents_[pdfStart_[i]];
149  }
150  double waverage = weightedEvents_[pdfStart_[i]]/originalEvents_;
151  edm::LogVerbatim("PDFAnalysis") << "\tEstimate for central PDF member acceptance: [" << acc_central*100 << " +- " <<
152  100*sqrt((acc2_central/waverage-acc_central*acc_central)/originalEvents_)
153  << "] %";
154  double xi = acc_central-originalAcceptance;
155  double deltaxi = (acc2_central-(originalAcceptance+2*xi+xi*xi))/originalEvents_;
156  if (deltaxi>0) deltaxi = sqrt(deltaxi); //else deltaxi = 0.;
157  edm::LogVerbatim("PDFAnalysis") << "\ti.e. [" << std::setprecision(4) << 100*xi/originalAcceptance << " +- " << std::setprecision(4) << 100*deltaxi/originalAcceptance << "] % relative variation with respect to the original PDF";
158 
159  if (npairs>0) {
160  edm::LogVerbatim("PDFAnalysis") << "\tNumber of eigenvectors for uncertainty estimation: " << npairs;
161  double wplus = 0.;
162  double wminus = 0.;
163  unsigned int nplus = 0;
164  unsigned int nminus = 0;
165  for (unsigned int j=0; j<npairs; ++j) {
166  double wa = 0.;
167  if (weightedEvents_[pdfStart_[i]+2*j+1]>0) wa = (weightedSelectedEvents_[pdfStart_[i]+2*j+1]/weightedEvents_[pdfStart_[i]+2*j+1])/acc_central-1.;
168  double wb = 0.;
169  if (weightedEvents_[pdfStart_[i]+2*j+2]>0) wb = (weightedSelectedEvents_[pdfStart_[i]+2*j+2]/weightedEvents_[pdfStart_[i]+2*j+2])/acc_central-1.;
170  if (nnpdfFlag) {
171  if (wa>0.) {
172  wplus += wa*wa;
173  nplus++;
174  } else {
175  wminus += wa*wa;
176  nminus++;
177  }
178  if (wb>0.) {
179  wplus += wb*wb;
180  nplus++;
181  } else {
182  wminus += wb*wb;
183  nminus++;
184  }
185  } else {
186  if (wa>wb) {
187  if (wa<0.) wa = 0.;
188  if (wb>0.) wb = 0.;
189  wplus += wa*wa;
190  wminus += wb*wb;
191  } else {
192  if (wb<0.) wb = 0.;
193  if (wa>0.) wa = 0.;
194  wplus += wb*wb;
195  wminus += wa*wa;
196  }
197  }
198  }
199  if (wplus>0) wplus = sqrt(wplus);
200  if (wminus>0) wminus = sqrt(wminus);
201  if (nnpdfFlag) {
202  if (nplus>0) wplus /= sqrt(nplus);
203  if (nminus>0) wminus /= sqrt(nminus);
204  }
205  edm::LogVerbatim("PDFAnalysis") << "\tRelative uncertainty with respect to central member: +" << std::setprecision(4) << 100.*wplus << " / -" << std::setprecision(4) << 100.*wminus << " [%]";
206  } else {
207  edm::LogVerbatim("PDFAnalysis") << "\tNO eigenvectors for uncertainty estimation";
208  }
209  }
210  edm::LogVerbatim("PDFAnalysis") << ">>>> End of PDF weight systematics summary >>>>";
211 
212 }
int i
Definition: DBlmapReader.cc:9
std::vector< edm::InputTag > pdfWeightTags_
std::vector< double > weightedSelectedEvents_
std::vector< double > weightedEvents_
T sqrt(T t)
Definition: SSEVec.h:48
std::vector< double > weighted2SelectedEvents_
int j
Definition: DBlmapReader.cc:9
bool PdfSystematicsAnalyzer::filter ( edm::Event ev,
const edm::EventSetup  
)
overridevirtual

Implements edm::EDFilter.

Definition at line 215 of file PdfSystematicsAnalyzer.cc.

References edm::Event::getByLabel(), i, j, originalEvents_, pdfStart_, pdfWeightTags_, selectedEvents_, selectorPath_, edm::TriggerNames::size(), edm::TriggerNames::triggerIndex(), edm::Event::triggerNames(), triggerResults, trigNames, weighted2SelectedEvents_, weightedEvents_, weightedSelectedEvents_, and create_public_pileup_plots::weights.

Referenced by Vispa.Plugins.Browser.BrowserTabController.BrowserTabController::filter(), Vispa.Plugins.Browser.BrowserTabController.BrowserTabController::find(), Vispa.Plugins.Browser.BrowserTabController.BrowserTabController::setDataAccessor(), and Vispa.Plugins.Browser.BrowserTabController.BrowserTabController::switchCenterView().

215  {
216 
217  edm::Handle<std::vector<double> > weightHandle;
218  for (unsigned int i=0; i<pdfWeightTags_.size(); ++i) {
219  if (!ev.getByLabel(pdfWeightTags_[i], weightHandle)) {
220  if (originalEvents_==0) {
221  edm::LogError("PDFAnalysis") << ">>> WARNING: some weights not found!";
222  edm::LogError("PDFAnalysis") << ">>> But maybe OK, if you are prefiltering!";
223  edm::LogError("PDFAnalysis") << ">>> If things are OK, this warning should disappear after a while!";
224  }
225  return false;
226  }
227  }
228 
229  originalEvents_++;
230 
231  bool selectedEvent = false;
233  if (!ev.getByLabel(edm::InputTag("TriggerResults"), triggerResults)) {
234  edm::LogError("PDFAnalysis") << ">>> TRIGGER collection does not exist !!!";
235  return false;
236  }
237 
238 
239  const edm::TriggerNames & trigNames = ev.triggerNames(*triggerResults);
240  unsigned int pathIndex = trigNames.triggerIndex(selectorPath_);
241  bool pathFound = (pathIndex<trigNames.size()); // pathIndex >= 0, since pathIndex is unsigned
242  if (pathFound) {
243  if (triggerResults->accept(pathIndex)) selectedEvent = true;
244  }
245  //edm::LogVerbatim("PDFAnalysis") << ">>>> Path Name: " << selectorPath_ << ", selected? " << selectedEvent;
246 
247  if (selectedEvent) selectedEvents_++;
248 
249  for (unsigned int i=0; i<pdfWeightTags_.size(); ++i) {
250  if (!ev.getByLabel(pdfWeightTags_[i], weightHandle)) return false;
251  std::vector<double> weights = (*weightHandle);
252  unsigned int nmembers = weights.size();
253  // Set up arrays the first time wieghts are read
254  if (pdfStart_[i]<0) {
255  pdfStart_[i] = weightedEvents_.size();
256  for (unsigned int j=0; j<nmembers; ++j) {
257  weightedEvents_.push_back(0.);
258  weightedSelectedEvents_.push_back(0.);
259  weighted2SelectedEvents_.push_back(0.);
260  }
261  }
262 
263  for (unsigned int j=0; j<nmembers; ++j) {
264  weightedEvents_[pdfStart_[i]+j] += weights[j];
265  if (selectedEvent) {
266  weightedSelectedEvents_[pdfStart_[i]+j] += weights[j];
267  weighted2SelectedEvents_[pdfStart_[i]+j] += weights[j]*weights[j];
268  }
269  }
270 
271  /*
272  printf("\n>>>>>>>>> Run %8d Event %d, members %3d PDF set %s : Weights >>>> \n", ev.id().run(), ev.id().event(), nmembers, pdfWeightTags_[i].instance().data());
273  for (unsigned int i=0; i<nmembers; i+=5) {
274  for (unsigned int j=0; ((j<5)&&(i+j<nmembers)); ++j) {
275  printf(" %2d: %7.4f", i+j, weights[i+j]);
276  }
277  safe_printf("\n");
278  }
279  */
280 
281  }
282 
283  return true;
284 }
int i
Definition: DBlmapReader.cc:9
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:204
std::vector< edm::InputTag > pdfWeightTags_
std::vector< double > weightedSelectedEvents_
Strings::size_type size() const
Definition: TriggerNames.cc:39
std::vector< double > weightedEvents_
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:32
std::vector< double > weighted2SelectedEvents_
int j
Definition: DBlmapReader.cc:9
static std::string const triggerResults
Definition: EdmProvDump.cc:41
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:74

Member Data Documentation

unsigned int PdfSystematicsAnalyzer::originalEvents_
private

Definition at line 15 of file PdfSystematicsAnalyzer.cc.

Referenced by beginJob(), endJob(), and filter().

std::vector<int> PdfSystematicsAnalyzer::pdfStart_
private

Definition at line 17 of file PdfSystematicsAnalyzer.cc.

Referenced by beginJob(), endJob(), and filter().

std::vector<edm::InputTag> PdfSystematicsAnalyzer::pdfWeightTags_
private

Definition at line 14 of file PdfSystematicsAnalyzer.cc.

Referenced by beginJob(), endJob(), and filter().

unsigned int PdfSystematicsAnalyzer::selectedEvents_
private

Definition at line 16 of file PdfSystematicsAnalyzer.cc.

Referenced by beginJob(), endJob(), and filter().

std::string PdfSystematicsAnalyzer::selectorPath_
private

Definition at line 13 of file PdfSystematicsAnalyzer.cc.

Referenced by filter().

std::vector<double> PdfSystematicsAnalyzer::weighted2SelectedEvents_
private

Definition at line 19 of file PdfSystematicsAnalyzer.cc.

Referenced by endJob(), and filter().

std::vector<double> PdfSystematicsAnalyzer::weightedEvents_
private

Definition at line 20 of file PdfSystematicsAnalyzer.cc.

Referenced by endJob(), and filter().

std::vector<double> PdfSystematicsAnalyzer::weightedSelectedEvents_
private

Definition at line 18 of file PdfSystematicsAnalyzer.cc.

Referenced by endJob(), and filter().