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