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(edm::ParameterSet const &ps)
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
~HcalPedestalsCheck() override
edm::ESGetToken< HcalPedestals, HcalPedestalsRcd > m_tok2
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const Item * getValues(DetId fId, bool throwOnFail=true) const
T getUntrackedParameter(std::string const &, T const &) const
const HcalTopology * topo() const
std::vector< DetId > getAllChannels() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ESGetToken< HcalElectronicsMap, HcalElectronicsMapRcd > m_tokmap
Definition: DetId.h:17
bool isADC() const
Definition: HcalPedestals.h:30
void analyze(const edm::Event &ev, const edm::EventSetup &es) override
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
std::vector< HcalGenericDetId > allPrecisionId() const
edm::ESGetToken< HcalPedestals, HcalPedestalsRcd > m_tok1
bool addValues(const Item &myItem)