CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
HcalPedestalsCheck Class Reference

#include <HcalPedestalsCheck.h>

Inheritance diagram for HcalPedestalsCheck:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

void analyze (const edm::Event &ev, const edm::EventSetup &es) override
 
 HcalPedestalsCheck (edm::ParameterSet const &ps)
 
 ~HcalPedestalsCheck () override
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
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
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Attributes

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

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 &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- 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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
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 HcalPedestalsCheck.h.

Constructor & Destructor Documentation

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

Definition at line 3 of file HcalPedestalsCheck.cc.

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

4 {
5  outfile = ps.getUntrackedParameter<std::string>("outFile","null");
6  dumprefs = ps.getUntrackedParameter<std::string>("dumpRefPedsTo","null");
7  dumpupdate = ps.getUntrackedParameter<std::string>("dumpUpdatePedsTo","null");
8  checkemapflag = ps.getUntrackedParameter<bool>("checkEmap",true);
9  validatepedestalsflag = ps.getUntrackedParameter<bool>("validatePedestals",false);
10  epsilon = ps.getUntrackedParameter<double>("deltaP",0);
11 }
HcalPedestalsCheck::~HcalPedestalsCheck ( )
override

Definition at line 13 of file HcalPedestalsCheck.cc.

14 {
15 }

Member Function Documentation

void HcalPedestalsCheck::analyze ( const edm::Event ev,
const edm::EventSetup es 
)
override

Definition at line 17 of file HcalPedestalsCheck.cc.

References HcalCondObjectContainer< Item >::addValues(), HcalElectronicsMap::allPrecisionId(), checkemapflag, gather_cfg::cout, DEFINE_FWK_MODULE, HcalDbASCIIIO::dumpObject(), dumprefs, dumpupdate, epsilon, Exception, spr::find(), edm::EventSetup::get(), HcalCondObjectContainer< Item >::getAllChannels(), HcalCondObjectContainer< Item >::getValues(), HcalPedestals::isADC(), outfile, edm::ESHandle< T >::product(), HcalCondObjectContainerBase::topo(), validatepedestalsflag, and MuonErrorMatrixValues_cff::values.

18 {
19  using namespace edm::eventsetup;
20 
21  // get fake pedestals from file ("new pedestals")
23  es.get<HcalPedestalsRcd>().get("update",newPeds);
24  const HcalPedestals* myNewPeds = newPeds.product();
25 
26  // get DB pedestals from Frontier/OrcoX ("reference")
28  es.get<HcalPedestalsRcd>().get("reference",refPeds);
29  const HcalPedestals* 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  // dump pedestals:
37  if(!(dumprefs=="null")){
38  std::ofstream outStream(dumprefs.c_str());
39  std::cout << "--- Dumping Pedestals - reference ---" << std::endl;
40  HcalDbASCIIIO::dumpObject (outStream, (*myRefPeds) );
41  }
42  if(!(dumpupdate=="null")){
43  std::ofstream outStream2(dumpupdate.c_str());
44  std::cout << "--- Dumping Pedestals - updated ---" << std::endl;
45  HcalDbASCIIIO::dumpObject (outStream2, (*myNewPeds) );
46  }
47 
49  std::vector<DetId> listNewChan = myNewPeds->getAllChannels();
50  std::vector<DetId> listRefChan = myRefPeds->getAllChannels();
51  std::vector<DetId>::iterator cell;
52  bool failflag = false;
53  for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++)
54  {
55  DetId mydetid = *it;
56  cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
57  if (cell == listNewChan.end()) // not present in new list, take old pedestals
58  {
59  throw cms::Exception("DataDoesNotMatch") << "Channel missing";
60  failflag = true;
61  break;
62  }
63  else // present in new list, take new pedestals
64  {
65  const float* values = (myNewPeds->getValues( mydetid ))->getValues();
66  const float* oldvalue = (myRefPeds->getValues( mydetid ))->getValues();
67  if( (*oldvalue != *values) || (*(oldvalue + 1)!=*(values+1)) || (*(oldvalue + 2)!=*(values+2)) || (*(oldvalue + 3)!=*(values+3)) ){
68  throw cms::Exception("DataDoesNotMatch") << "Value does not match";
69  failflag = true;
70  break;
71  }
72  // compare the values of the pedestals for valid channels between update and reference
73 
74  listNewChan.erase(cell); // fix 25.02.08
75  }
76  }
77  if(!failflag) std::cout << "These are identical" << std::endl;
78  }
79 
80  if(epsilon!=0){
81  std::vector<DetId> listNewChan = myNewPeds->getAllChannels();
82  std::vector<DetId> listRefChan = myRefPeds->getAllChannels();
83  std::vector<DetId>::iterator cell;
84  bool failflag = false;
85  for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++)
86  {
87  DetId mydetid = *it;
88  cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
89  if (cell == listNewChan.end())
90  {
91  continue;
92  }
93  else
94  {
95  const float* values = (myNewPeds->getValues( mydetid ))->getValues();
96  const float* oldvalue = (myRefPeds->getValues( mydetid ))->getValues();
97  if( (fabs(*oldvalue-*values)>epsilon) || (fabs(*(oldvalue+1)-*(values+1))>epsilon) || (fabs(*(oldvalue+2)-*(values+2))>epsilon) || (fabs(*(oldvalue+3)-*(values+3))>epsilon) ){
98  throw cms::Exception("DataDoesNotMatch") << "Values differ by more than deltaP";
99  failflag = true;
100  break;
101  }
102  listNewChan.erase(cell); // fix 25.02.08
103  }
104  }
105  if(!failflag) std::cout << "These are identical to within deltaP" << std::endl;
106  }
107  if(!(outfile=="null"))
108  {
109  // first get the list of all channels from the update
110  std::vector<DetId> listNewChan = myNewPeds->getAllChannels();
111 
112  // go through list of valid channels from reference, look up if pedestals exist for update
113  // push back into new vector the corresponding updated pedestals,
114  // or if it doesn't exist, the reference
115  HcalPedestals *resultPeds = new HcalPedestals(myRefPeds->topo(), myRefPeds->isADC() );
116  std::vector<DetId> listRefChan = myRefPeds->getAllChannels();
117  std::vector<DetId>::iterator cell;
118  for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++)
119  {
120  DetId mydetid = *it;
121  cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
122  if (cell == listNewChan.end()) // not present in new list, take old pedestals
123  {
124  // bool addValue (DetId fId, const float fValues [4]);
125  const HcalPedestal* item = myRefPeds->getValues(mydetid);
126  std::cout << "o";
127  resultPeds->addValues(*item);
128  }
129  else // present in new list, take new pedestals
130  {
131  const HcalPedestal* item = myNewPeds->getValues(mydetid);
132  std::cout << "n";
133  resultPeds->addValues(*item);
134  // compare the values of the pedestals for valid channels between update and reference
135  listNewChan.erase(cell); // fix 25.02.08
136  }
137  }
138 
139 
140  for (std::vector<DetId>::iterator it = listNewChan.begin(); it != listNewChan.end(); it++) // fix 25.02.08
141  {
142  DetId mydetid = *it;
143  const HcalPedestal* item = myNewPeds->getValues(mydetid);
144  std::cout << "N";
145  resultPeds->addValues(*item);
146  }
147 
148 
149  std::cout << std::endl;
150 
151  std::vector<DetId> listResult = resultPeds->getAllChannels();
152  // get the e-map list of channels
153  std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
154  // look up if emap channels are all present in pedestals, if not then cerr
155  if(checkemapflag){
156  for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++)
157  {
158  DetId mydetid = DetId(it->rawId());
159  HcalGenericDetId mygenid(it->rawId());
160  // std::cout << "id = " << mygenid << ", hashed id = " << mygenid.hashedId() << std::endl;
161  if (std::find(listResult.begin(), listResult.end(), mydetid ) == listResult.end())
162  {
163  std::cout << "Conditions not found for DetId = " << HcalGenericDetId(it->rawId()) << std::endl;
164  }
165  }
166  }
167 
168  // dump the resulting list of pedestals into a file
169  std::ofstream outStream3(outfile.c_str());
170  std::cout << "--- Dumping Pedestals - the combined ones ---" << std::endl;
171  HcalDbASCIIIO::dumpObject (outStream3, (*resultPeds) );
172  }
173 
174  // const float* values = myped->getValues (channelID);
175  // if (values) std::cout << "pedestals for channel " << channelID << ": "
176  // << values [0] << '/' << values [1] << '/' << values [2] << '/' << values [3] << std::endl;
177 
178 }
bool isADC() const
Definition: HcalPedestals.h:28
const Item * getValues(DetId fId, bool throwOnFail=true) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::vector< DetId > getAllChannels() const
std::vector< HcalGenericDetId > allPrecisionId() const
Definition: DetId.h:18
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
T get() const
Definition: EventSetup.h:71
bool addValues(const Item &myItem)
T const * product() const
Definition: ESHandle.h:86
const HcalTopology * topo() const

Member Data Documentation

bool HcalPedestalsCheck::checkemapflag
private

Definition at line 57 of file HcalPedestalsCheck.h.

Referenced by analyze(), and HcalPedestalsCheck().

std::string HcalPedestalsCheck::dumprefs
private

Definition at line 54 of file HcalPedestalsCheck.h.

Referenced by analyze(), and HcalPedestalsCheck().

std::string HcalPedestalsCheck::dumpupdate
private

Definition at line 55 of file HcalPedestalsCheck.h.

Referenced by analyze(), and HcalPedestalsCheck().

double HcalPedestalsCheck::epsilon
private
std::string HcalPedestalsCheck::outfile
private

Definition at line 53 of file HcalPedestalsCheck.h.

Referenced by analyze(), and HcalPedestalsCheck().

bool HcalPedestalsCheck::validatepedestalsflag
private

Definition at line 56 of file HcalPedestalsCheck.h.

Referenced by analyze(), and HcalPedestalsCheck().