CMS 3D CMS Logo

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
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Attributes

unsigned int originalEvents_
 
std::vector< int > pdfStart_
 
std::vector< edm::InputTagpdfWeightTags_
 
std::vector< edm::EDGetTokenT< std::vector< double > > > pdfWeightTokens_
 
unsigned int selectedEvents_
 
std::string selectorPath_
 
edm::EDGetTokenT< edm::TriggerResultstriggerResultsToken_
 
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
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- 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::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 6 of file PdfSystematicsAnalyzer.cc.

Constructor & Destructor Documentation

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

Definition at line 39 of file PdfSystematicsAnalyzer.cc.

References GlobalPosition_Frontier_DevDB_cff::tag, and triggerResultsToken_.

39  :
40  selectorPath_(pset.getUntrackedParameter<std::string> ("SelectorPath","")),
41  pdfWeightTags_(pset.getUntrackedParameter<std::vector<edm::InputTag> > ("PdfWeightTags")),
42  pdfWeightTokens_(edm::vector_transform(pdfWeightTags_, [this](edm::InputTag const & tag){return consumes<std::vector<double> >(tag);})),
43  triggerResultsToken_(consumes<edm::TriggerResults>(edm::InputTag("TriggerResults"))) {
44 }
T getUntrackedParameter(std::string const &, T const &) const
std::vector< edm::EDGetTokenT< std::vector< double > > > pdfWeightTokens_
std::vector< edm::InputTag > pdfWeightTags_
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
PdfSystematicsAnalyzer::~PdfSystematicsAnalyzer ( )
virtual

Definition at line 47 of file PdfSystematicsAnalyzer.cc.

47 {}

Member Function Documentation

void PdfSystematicsAnalyzer::beginJob ( void  )
overridevirtual

Reimplemented from edm::EDFilter.

Definition at line 50 of file PdfSystematicsAnalyzer.cc.

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

50  {
51  originalEvents_ = 0;
52  selectedEvents_ = 0;
53  edm::LogVerbatim("PDFAnalysis") << "PDF uncertainties will be determined for the following sets: ";
54  for (unsigned int i=0; i<pdfWeightTags_.size(); ++i) {
55  edm::LogVerbatim("PDFAnalysis") << "\t" << pdfWeightTags_[i].instance();
56  pdfStart_.push_back(-1);
57  }
58 }
std::vector< edm::InputTag > pdfWeightTags_
void PdfSystematicsAnalyzer::endJob ( void  )
overridevirtual

Reimplemented from edm::EDFilter.

Definition at line 61 of file PdfSystematicsAnalyzer.cc.

References mps_fire::i, createfilelist::int, originalEvents_, pdfStart_, pdfWeightTags_, selectedEvents_, mathSSE::sqrt(), weighted2SelectedEvents_, weightedEvents_, weightedSelectedEvents_, and hybridSuperClusters_cfi::xi.

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

Definition at line 221 of file PdfSystematicsAnalyzer.cc.

References edm::HLTGlobalStatus::accept(), DEFINE_FWK_MODULE, edm::Event::getByToken(), mps_fire::i, originalEvents_, pdfStart_, pdfWeightTags_, pdfWeightTokens_, selectedEvents_, selectorPath_, edm::TriggerNames::size(), edm::TriggerNames::triggerIndex(), edm::Event::triggerNames(), triggerResults, triggerResultsToken_, trigNames, weighted2SelectedEvents_, weightedEvents_, weightedSelectedEvents_, and create_public_lumi_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().

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

Member Data Documentation

unsigned int PdfSystematicsAnalyzer::originalEvents_
private

Definition at line 18 of file PdfSystematicsAnalyzer.cc.

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

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

Definition at line 20 of file PdfSystematicsAnalyzer.cc.

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

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

Definition at line 15 of file PdfSystematicsAnalyzer.cc.

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

std::vector<edm::EDGetTokenT<std::vector<double> > > PdfSystematicsAnalyzer::pdfWeightTokens_
private

Definition at line 16 of file PdfSystematicsAnalyzer.cc.

Referenced by filter().

unsigned int PdfSystematicsAnalyzer::selectedEvents_
private

Definition at line 19 of file PdfSystematicsAnalyzer.cc.

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

std::string PdfSystematicsAnalyzer::selectorPath_
private

Definition at line 14 of file PdfSystematicsAnalyzer.cc.

Referenced by filter().

edm::EDGetTokenT<edm::TriggerResults> PdfSystematicsAnalyzer::triggerResultsToken_
private

Definition at line 17 of file PdfSystematicsAnalyzer.cc.

Referenced by filter(), and PdfSystematicsAnalyzer().

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

Definition at line 22 of file PdfSystematicsAnalyzer.cc.

Referenced by endJob(), and filter().

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

Definition at line 23 of file PdfSystematicsAnalyzer.cc.

Referenced by endJob(), and filter().

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

Definition at line 21 of file PdfSystematicsAnalyzer.cc.

Referenced by endJob(), and filter().