CMS 3D CMS Logo

HcalPedestalsCheck.cc
Go to the documentation of this file.
2 
4  outfile = ps.getUntrackedParameter<std::string>("outFile", "null");
5  dumprefs = ps.getUntrackedParameter<std::string>("dumpRefPedsTo", "null");
6  dumpupdate = ps.getUntrackedParameter<std::string>("dumpUpdatePedsTo", "null");
7  checkemapflag = ps.getUntrackedParameter<bool>("checkEmap", true);
8  validatepedestalsflag = ps.getUntrackedParameter<bool>("validatePedestals", false);
9  epsilon = ps.getUntrackedParameter<double>("deltaP", 0);
10  m_tok1 = esConsumes<HcalPedestals, HcalPedestalsRcd>(edm::ESInputTag("", "update"));
11  m_tok2 = esConsumes<HcalPedestals, HcalPedestalsRcd>(edm::ESInputTag("", "reference"));
12  m_tokmap = esConsumes<HcalElectronicsMap, HcalElectronicsMapRcd>(edm::ESInputTag("", "reference"));
13 }
14 
16 
18  using namespace edm::eventsetup;
19 
20  // get fake pedestals from file ("new pedestals")
21  const HcalPedestals* myNewPeds = &es.getData(m_tok1);
22 
23  // get DB pedestals from Frontier/OrcoX ("reference")
24  const HcalPedestals* myRefPeds = &es.getData(m_tok2);
25 
26  // get e-map from reference
27  const HcalElectronicsMap* myRefEMap = &es.getData(m_tokmap);
28 
29  // dump pedestals:
30  if (!(dumprefs == "null")) {
31  std::ofstream outStream(dumprefs.c_str());
32  std::cout << "--- Dumping Pedestals - reference ---" << std::endl;
33  HcalDbASCIIIO::dumpObject(outStream, (*myRefPeds));
34  }
35  if (!(dumpupdate == "null")) {
36  std::ofstream outStream2(dumpupdate.c_str());
37  std::cout << "--- Dumping Pedestals - updated ---" << std::endl;
38  HcalDbASCIIIO::dumpObject(outStream2, (*myNewPeds));
39  }
40 
42  std::vector<DetId> listNewChan = myNewPeds->getAllChannels();
43  std::vector<DetId> listRefChan = myRefPeds->getAllChannels();
44  std::vector<DetId>::iterator cell;
45  bool failflag = false;
46  for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++) {
47  DetId mydetid = *it;
48  cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
49  if (cell == listNewChan.end()) // not present in new list, take old pedestals
50  {
51  throw cms::Exception("DataDoesNotMatch") << "Channel missing";
52  failflag = true;
53  break;
54  } else // present in new list, take new pedestals
55  {
56  const float* values = (myNewPeds->getValues(mydetid))->getValues();
57  const float* oldvalue = (myRefPeds->getValues(mydetid))->getValues();
58  if ((*oldvalue != *values) || (*(oldvalue + 1) != *(values + 1)) || (*(oldvalue + 2) != *(values + 2)) ||
59  (*(oldvalue + 3) != *(values + 3))) {
60  throw cms::Exception("DataDoesNotMatch") << "Value does not match";
61  failflag = true;
62  break;
63  }
64  // compare the values of the pedestals for valid channels between update and reference
65 
66  listNewChan.erase(cell); // fix 25.02.08
67  }
68  }
69  if (!failflag)
70  std::cout << "These are identical" << std::endl;
71  }
72 
73  if (epsilon != 0) {
74  std::vector<DetId> listNewChan = myNewPeds->getAllChannels();
75  std::vector<DetId> listRefChan = myRefPeds->getAllChannels();
76  std::vector<DetId>::iterator cell;
77  bool failflag = false;
78  for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++) {
79  DetId mydetid = *it;
80  cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
81  if (cell == listNewChan.end()) {
82  continue;
83  } else {
84  const float* values = (myNewPeds->getValues(mydetid))->getValues();
85  const float* oldvalue = (myRefPeds->getValues(mydetid))->getValues();
86  if ((fabs(*oldvalue - *values) > epsilon) || (fabs(*(oldvalue + 1) - *(values + 1)) > epsilon) ||
87  (fabs(*(oldvalue + 2) - *(values + 2)) > epsilon) || (fabs(*(oldvalue + 3) - *(values + 3)) > epsilon)) {
88  throw cms::Exception("DataDoesNotMatch") << "Values differ by more than deltaP";
89  failflag = true;
90  break;
91  }
92  listNewChan.erase(cell); // fix 25.02.08
93  }
94  }
95  if (!failflag)
96  std::cout << "These are identical to within deltaP" << std::endl;
97  }
98  if (!(outfile == "null")) {
99  // first get the list of all channels from the update
100  std::vector<DetId> listNewChan = myNewPeds->getAllChannels();
101 
102  // go through list of valid channels from reference, look up if pedestals exist for update
103  // push back into new vector the corresponding updated pedestals,
104  // or if it doesn't exist, the reference
105  HcalPedestals* resultPeds = new HcalPedestals(myRefPeds->topo(), myRefPeds->isADC());
106  std::vector<DetId> listRefChan = myRefPeds->getAllChannels();
107  std::vector<DetId>::iterator cell;
108  for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++) {
109  DetId mydetid = *it;
110  cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
111  if (cell == listNewChan.end()) // not present in new list, take old pedestals
112  {
113  // bool addValue (DetId fId, const float fValues [4]);
114  const HcalPedestal* item = myRefPeds->getValues(mydetid);
115  std::cout << "o";
116  resultPeds->addValues(*item);
117  } else // present in new list, take new pedestals
118  {
119  const HcalPedestal* item = myNewPeds->getValues(mydetid);
120  std::cout << "n";
121  resultPeds->addValues(*item);
122  // compare the values of the pedestals for valid channels between update and reference
123  listNewChan.erase(cell); // fix 25.02.08
124  }
125  }
126 
127  for (std::vector<DetId>::iterator it = listNewChan.begin(); it != listNewChan.end(); it++) // fix 25.02.08
128  {
129  DetId mydetid = *it;
130  const HcalPedestal* item = myNewPeds->getValues(mydetid);
131  std::cout << "N";
132  resultPeds->addValues(*item);
133  }
134 
135  std::cout << std::endl;
136 
137  std::vector<DetId> listResult = resultPeds->getAllChannels();
138  // get the e-map list of channels
139  std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
140  // look up if emap channels are all present in pedestals, if not then cerr
141  if (checkemapflag) {
142  for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++) {
143  DetId mydetid = DetId(it->rawId());
144  HcalGenericDetId mygenid(it->rawId());
145  // std::cout << "id = " << mygenid << ", hashed id = " << mygenid.hashedId() << std::endl;
146  if (std::find(listResult.begin(), listResult.end(), mydetid) == listResult.end()) {
147  std::cout << "Conditions not found for DetId = " << HcalGenericDetId(it->rawId()) << std::endl;
148  }
149  }
150  }
151 
152  // dump the resulting list of pedestals into a file
153  std::ofstream outStream3(outfile.c_str());
154  std::cout << "--- Dumping Pedestals - the combined ones ---" << std::endl;
155  HcalDbASCIIIO::dumpObject(outStream3, (*resultPeds));
156  }
157 
158  // const float* values = myped->getValues (channelID);
159  // if (values) std::cout << "pedestals for channel " << channelID << ": "
160  // << values [0] << '/' << values [1] << '/' << values [2] << '/' << values [3] << std::endl;
161 }
162 
163 //vecDetId HcalPedestalsCheck::getMissingDetIds(vector<HcalPedestals> & myPedestals)
164 //{
165 // HcalGeometry myHcalGeometry;
166 // // get the valid detid from the various subdetectors
167 // vecDetId validHB = myHcalGeometry.getValidDetIds(Hcal,HcalBarrel); // check these numbers
168 // vecDetId validHE = myHcalGeometry.getValidDetIds(Hcal,HcalEndcap);
169 // vecDetId validHF = myHcalGeometry.getValidDetIds(Hcal,HcalForward);
170 // vecDetId validHO = myHcalGeometry.getValidDetIds(Hcal,HcalOuter);
171 // vecDetId validZDC = myHcalGeometry.getValidDetIds(Calo,2);
172 //
173 // // check if everything is there in pedestals
174 //
175 //
176 //}
177 
HcalPedestalsCheck::outfile
std::string outfile
Definition: HcalPedestalsCheck.h:51
edm::ESInputTag
Definition: ESInputTag.h:87
HcalGenericDetId
Definition: HcalGenericDetId.h:15
HcalPedestalsCheck::validatepedestalsflag
bool validatepedestalsflag
Definition: HcalPedestalsCheck.h:54
HcalPedestalsCheck::m_tokmap
edm::ESGetToken< HcalElectronicsMap, HcalElectronicsMapRcd > m_tokmap
Definition: HcalPedestalsCheck.h:59
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
HcalPedestalsCheck::dumprefs
std::string dumprefs
Definition: HcalPedestalsCheck.h:52
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
HcalCondObjectContainer::getValues
const Item * getValues(DetId fId, bool throwOnFail=true) const
Definition: HcalCondObjectContainer.h:159
HcalElectronicsMap::allPrecisionId
std::vector< HcalGenericDetId > allPrecisionId() const
Definition: HcalElectronicsMap.cc:139
DetId
Definition: DetId.h:17
HcalPedestals
Definition: HcalPedestals.h:20
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
HcalPedestalsCheck::~HcalPedestalsCheck
~HcalPedestalsCheck() override
Definition: HcalPedestalsCheck.cc:15
HcalPedestal
Definition: HcalPedestal.h:15
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
HcalPedestalsCheck::m_tok2
edm::ESGetToken< HcalPedestals, HcalPedestalsRcd > m_tok2
Definition: HcalPedestalsCheck.h:58
HcalCondObjectContainer::getAllChannels
std::vector< DetId > getAllChannels() const
Definition: HcalCondObjectContainer.h:312
HcalCondObjectContainerBase::topo
const HcalTopology * topo() const
Definition: HcalCondObjectContainer.h:22
HcalPedestalsCheck
Definition: HcalPedestalsCheck.h:42
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
edm::EventSetup
Definition: EventSetup.h:58
HcalPedestalsCheck::epsilon
double epsilon
Definition: HcalPedestalsCheck.h:56
HcalPedestalsCheck::HcalPedestalsCheck
HcalPedestalsCheck(edm::ParameterSet const &ps)
Definition: HcalPedestalsCheck.cc:3
HcalPedestalsCheck::m_tok1
edm::ESGetToken< HcalPedestals, HcalPedestalsRcd > m_tok1
Definition: HcalPedestalsCheck.h:57
HcalPedestals::isADC
bool isADC() const
Definition: HcalPedestals.h:30
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
HcalElectronicsMap
Definition: HcalElectronicsMap.h:31
HcalDbASCIIIO::dumpObject
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
HcalPedestalsCheck::analyze
void analyze(const edm::Event &ev, const edm::EventSetup &es) override
Definition: HcalPedestalsCheck.cc:17
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
Exception
Definition: hltDiff.cc:245
HcalPedestalsCheck::checkemapflag
bool checkemapflag
Definition: HcalPedestalsCheck.h:55
HcalCondObjectContainer::addValues
bool addValues(const Item &myItem)
Definition: HcalCondObjectContainer.h:234
HcalPedestalsCheck.h
edm::Event
Definition: Event.h:73
edm::eventsetup
Definition: ES_DDDetector.cc:16
HcalPedestalsCheck::dumpupdate
std::string dumpupdate
Definition: HcalPedestalsCheck.h:53