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
HcalPedestalWidthsCheck Class Reference

#include <HcalPedestalWidthsCheck.h>

Inheritance diagram for HcalPedestalWidthsCheck:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

void analyze (const edm::Event &ev, const edm::EventSetup &es)
 
 HcalPedestalWidthsCheck (edm::ParameterSet const &ps)
 
 ~HcalPedestalWidthsCheck ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 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
 
void modulesDependentUpon (std::string const &iProcessName, std::string const &iModuleLabel, bool iPrint, std::vector< char const * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Attributes

bool checkemapflag
 
std::string dumprefs
 
std::string dumpupdate
 
double epsilon
 
std::string outfile
 
bool validateflag
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
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 43 of file HcalPedestalWidthsCheck.h.

Constructor & Destructor Documentation

HcalPedestalWidthsCheck::HcalPedestalWidthsCheck ( edm::ParameterSet const &  ps)

Definition at line 3 of file HcalPedestalWidthsCheck.cc.

References checkemapflag, dumprefs, dumpupdate, epsilon, edm::ParameterSet::getUntrackedParameter(), outfile, AlCaHLTBitMon_QueryRunRegistry::string, and validateflag.

4 {
5  outfile = ps.getUntrackedParameter<std::string>("outFile","null");
6  dumprefs = ps.getUntrackedParameter<std::string>("dumpRefWidthsTo","null");
7  dumpupdate = ps.getUntrackedParameter<std::string>("dumpUpdateWidthsTo","null");
8  checkemapflag = ps.getUntrackedParameter<bool>("checkEmap",false);
9  validateflag = ps.getUntrackedParameter<bool>("validateWidths",false);
10  epsilon = ps.getUntrackedParameter<double>("deltaW",0);
11 }
HcalPedestalWidthsCheck::~HcalPedestalWidthsCheck ( )

Definition at line 13 of file HcalPedestalWidthsCheck.cc.

14 {
15 }

Member Function Documentation

void HcalPedestalWidthsCheck::analyze ( const edm::Event ev,
const edm::EventSetup es 
)
virtual

Implements edm::EDAnalyzer.

Definition at line 17 of file HcalPedestalWidthsCheck.cc.

References checkemapflag, gather_cfg::cout, HcalDbASCIIIO::dumpObject(), dumprefs, dumpupdate, epsilon, Exception, spr::find(), plotBeamSpotDB::first, edm::EventSetup::get(), HcalCondObjectContainer< Item >::getAllChannels(), HcalPedestalWidth::getValues(), outfile, edm::second(), and validateflag.

18 {
19  using namespace edm::eventsetup;
20 
21  // get fake pedestals from file ("new pedestals")
23  es.get<HcalPedestalWidthsRcd>().get("update",newPeds);
24  const HcalPedestalWidths* myNewPeds = newPeds.product();
25 
26  // get DB pedestals from Frontier/OrcoX ("reference")
28  es.get<HcalPedestalWidthsRcd>().get("reference",refPeds);
29  const HcalPedestalWidths* myRefPeds = refPeds.product();
30 
31  // get e-map from reference
33  es.get<HcalElectronicsMapRcd>().get("reference",refEMap);
34  const HcalElectronicsMap* myRefEMap = refEMap.product();
35 
36 
37  // dump pedestals:
38  if(dumpupdate.compare("null")!=0){
39  std::ofstream outStream(dumpupdate.c_str());
40  std::cout << "--- Dumping PedestalWidths - update ---" << std::endl;
41  HcalDbASCIIIO::dumpObject (outStream, (*myNewPeds) );
42  }
43  if(dumprefs.compare("null")!=0){
44  std::ofstream outStream2(dumprefs.c_str());
45  std::cout << "--- Dumping PedestalWidths - reference ---" << std::endl;
46  HcalDbASCIIIO::dumpObject (outStream2, (*myRefPeds) );
47  }
48  // first get the list of all channels from the update
49  std::vector<DetId> listNewChan = myNewPeds->getAllChannels();
50 
51  // go through list of valid channels from reference, look up if pedestals exist for update
52  // push back into new vector the corresponding updated pedestals,
53  // or if it doesn't exist, the reference
54  HcalPedestalWidths *resultPeds = new HcalPedestalWidths(myRefPeds->topo(), myRefPeds->isADC() );
55  std::vector<DetId> listRefChan = myRefPeds->getAllChannels();
56  std::vector<DetId>::iterator cell;
57 
58  if(validateflag){
59  for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++)
60  {
61  DetId mydetid = *it;
62  cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
63  if (cell == listNewChan.end()) // not present in new list, take old pedestals
64  {
65  throw cms::Exception("DataDoesNotMatch")<<"Value not found in reference" << std::endl;
66  }
67  else // present in new list, take new pedestals
68  {
69  const HcalPedestalWidth* first = myNewPeds->getValues( mydetid );
70  const HcalPedestalWidth* second = myRefPeds->getValues( mydetid );
71  const float* newwidth = first->getValues();
72  const float* oldwidth = second->getValues();
73  if( (*newwidth != *oldwidth) || (*(newwidth+1)!=*(oldwidth+1)) || (*(newwidth+2)!=*(oldwidth+2)) || (*(newwidth+3)!=*(oldwidth+3)) || (*(newwidth+4)!=*(oldwidth+4)) || (*(newwidth+5)!=*(oldwidth+5)) || (*(newwidth+6)!=*(oldwidth+6)) || (*(newwidth+7)!=*(oldwidth+7)) || (*(newwidth+8)!=*(oldwidth+8)) || (*(newwidth+9)!=*(oldwidth+9))){
74  throw cms::Exception("DataDoesNotMatch") << "Values are not identical" << std::endl;
75  }
76  listNewChan.erase(cell); // fix 25.02.08
77  }
78  }
79  std::cout << "These are identical" << std::endl;
80  }
81 
82 
83 
84 
85  if(epsilon!=0){
86  for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++)
87  {
88  DetId mydetid = *it;
89  cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
90  if (cell == listNewChan.end()) // not present in new list, take old pedestals
91  {
92  throw cms::Exception("DataDoesNotMatch")<<"Value not found in reference" << std::endl;
93  }
94  else // present in new list, take new pedestals
95  {
96  const HcalPedestalWidth* first = myNewPeds->getValues( mydetid );
97  const HcalPedestalWidth* second = myRefPeds->getValues( mydetid );
98  const float* newwidth = first->getValues();
99  const float* oldwidth = second->getValues();
100  if( fabs(*newwidth-*oldwidth)>epsilon || fabs(*(newwidth+1)-*(oldwidth+1))>epsilon || fabs(*(newwidth+2)-*(oldwidth+2))>epsilon || fabs(*(newwidth+3)-*(oldwidth+3))>epsilon || fabs(*(newwidth+4)-*(oldwidth+4))>epsilon || fabs(*(newwidth+5)-*(oldwidth+5))>epsilon || fabs(*(newwidth+6)-*(oldwidth+6))>epsilon || fabs(*(newwidth+7)-*(oldwidth+7))>epsilon || fabs(*(newwidth+8)-*(oldwidth+8))>epsilon || fabs(*(newwidth+9)-*(oldwidth+9))>epsilon){
101  throw cms::Exception("DataDoesNotMatch") << "Values differ by more than deltaW" << std::endl;
102  }
103  listNewChan.erase(cell); // fix 25.02.08
104  }
105  }
106  std::cout << "These are identical" << std::endl;
107  }
108  if(outfile.compare("null")!=0){
109  for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++)
110  {
111  DetId mydetid = *it;
112  cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
113  if (cell == listNewChan.end()) // not present in new list, take old pedestals
114  {
115  const HcalPedestalWidth* mywidth = myRefPeds->getValues( mydetid );
116  std::cout << "o";
117  resultPeds->addValues( *mywidth );
118  }
119  else // present in new list, take new pedestals
120  {
121  const HcalPedestalWidth* mywidth = myNewPeds->getValues( mydetid );
122  std::cout << "n";
123  resultPeds->addValues( *mywidth );
124 
125  listNewChan.erase(cell); // fix 25.02.08
126  }
127  }
128 
129  for (std::vector<DetId>::iterator it = listNewChan.begin(); it != listNewChan.end(); it++) // fix 25.02.08
130  {
131  DetId mydetid = *it;
132  const HcalPedestalWidth* mywidth = myNewPeds->getValues( mydetid );
133  std::cout << "N";
134  resultPeds->addValues( *mywidth );
135  }
136  // dump the resulting list of pedestals into a file
137  std::ofstream outStream3(outfile.c_str());
138  std::cout << "--- Dumping PedestalWidths - the combined ones ---" << std::endl;
139  HcalDbASCIIIO::dumpObject (outStream3, (*resultPeds) );
140 
141 
142 
143  }
144  std::cout << std::endl;
145  if(checkemapflag){
146  std::vector<DetId> listResult = resultPeds->getAllChannels();
147  // get the e-map list of channels
148  std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
149  // look up if emap channels are all present in pedestals, if not then cerr
150  for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++)
151  {
152  DetId mydetid = DetId(it->rawId());
153  if (std::find(listResult.begin(), listResult.end(), mydetid ) == listResult.end() )
154  {
155  std::cout << "Conditions not found for DetId = " << HcalGenericDetId(it->rawId()) << std::endl;
156  }
157  }
158  }
159 
160 }
const float * getValues() const
get value for all capId = 0..3, 10 values in total
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
U second(std::pair< T, U > const &p)
std::vector< DetId > getAllChannels() const
Definition: DetId.h:18
const T & get() const
Definition: EventSetup.h:56
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
tuple cout
Definition: gather_cfg.py:145

Member Data Documentation

bool HcalPedestalWidthsCheck::checkemapflag
private

Definition at line 56 of file HcalPedestalWidthsCheck.h.

Referenced by analyze(), and HcalPedestalWidthsCheck().

std::string HcalPedestalWidthsCheck::dumprefs
private

Definition at line 54 of file HcalPedestalWidthsCheck.h.

Referenced by analyze(), and HcalPedestalWidthsCheck().

std::string HcalPedestalWidthsCheck::dumpupdate
private

Definition at line 55 of file HcalPedestalWidthsCheck.h.

Referenced by analyze(), and HcalPedestalWidthsCheck().

double HcalPedestalWidthsCheck::epsilon
private
std::string HcalPedestalWidthsCheck::outfile
private

Definition at line 53 of file HcalPedestalWidthsCheck.h.

Referenced by analyze(), and HcalPedestalWidthsCheck().

bool HcalPedestalWidthsCheck::validateflag
private

Definition at line 57 of file HcalPedestalWidthsCheck.h.

Referenced by analyze(), and HcalPedestalWidthsCheck().