CMS 3D CMS Logo

HcalQIEDataCheck.cc
Go to the documentation of this file.
2 
4  outfile = ps.getUntrackedParameter<std::string>("outFile", "null");
5  dumprefs = ps.getUntrackedParameter<std::string>("dumpRefQIEsTo", "null");
6  dumpupdate = ps.getUntrackedParameter<std::string>("dumpUpdateQIEsTo", "null");
7  checkemapflag = ps.getUntrackedParameter<bool>("checkEmap", false);
8  validateflag = ps.getUntrackedParameter<bool>("validateQIEs", false);
9  // epsilon = ps.getUntrackedParameter<double>("deltaQIE",0);
10  m_tok1 = esConsumes<HcalQIEData, HcalQIEDataRcd>(edm::ESInputTag("", "update"));
11  m_tok2 = esConsumes<HcalQIEData, HcalQIEDataRcd>(edm::ESInputTag("", "reference"));
12  m_tokmap = esConsumes<HcalElectronicsMap, HcalElectronicsMapRcd>(edm::ESInputTag("", "reference"));
13 }
14 
16 
18  using namespace edm::eventsetup;
19 
20  const HcalQIEData* myNewQIEs = &es.getData(m_tok1);
21  const HcalQIEData* myRefQIEs = &es.getData(m_tok2);
22  const HcalElectronicsMap* myRefEMap = &es.getData(m_tokmap);
23 
24  if (dumpupdate != "null") {
25  std::ofstream outStream(dumpupdate.c_str());
26  std::cout << "--- Dumping QIEs - update ---" << std::endl;
27  HcalDbASCIIIO::dumpObject(outStream, (*myNewQIEs));
28  }
29  if (dumprefs != "null") {
30  std::ofstream outStream2(dumprefs.c_str());
31  std::cout << "--- Dumping QIEs - reference ---" << std::endl;
32  HcalDbASCIIIO::dumpObject(outStream2, (*myRefQIEs));
33  }
34 
35  // first get the list of all channels from the update
36  std::vector<DetId> listNewChan = myNewQIEs->getAllChannels();
37 
38  HcalQIEData* resultQIEs = new HcalQIEData(myRefQIEs->topo());
39  std::vector<DetId> listRefChan = myRefQIEs->getAllChannels();
40  std::vector<DetId>::iterator cell;
41 
42  if (validateflag) {
43  for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++) {
44  DetId mydetid = *it;
45  cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
46  if (cell == listNewChan.end()) // not present in new list
47  {
48  throw cms::Exception("DataDoesNotMatch") << "Value not found in reference" << std::endl;
49  } else // present in new list
50  {
51  const HcalQIECoder* first = myNewQIEs->getCoder(mydetid);
52  const HcalQIECoder* second = myRefQIEs->getCoder(mydetid);
53  {
54  bool failflag = false;
55  if (first->offset(0, 0) != second->offset(0, 0))
56  failflag = true;
57  if (first->offset(0, 1) != second->offset(0, 1))
58  failflag = true;
59  if (first->offset(0, 2) != second->offset(0, 2))
60  failflag = true;
61  if (first->offset(0, 3) != second->offset(0, 3))
62  failflag = true;
63  if (first->offset(1, 0) != second->offset(1, 0))
64  failflag = true;
65  if (first->offset(1, 1) != second->offset(1, 1))
66  failflag = true;
67  if (first->offset(1, 2) != second->offset(1, 2))
68  failflag = true;
69  if (first->offset(1, 3) != second->offset(1, 3))
70  failflag = true;
71  if (first->offset(2, 0) != second->offset(2, 0))
72  failflag = true;
73  if (first->offset(2, 1) != second->offset(2, 1))
74  failflag = true;
75  if (first->offset(2, 2) != second->offset(2, 2))
76  failflag = true;
77  if (first->offset(2, 3) != second->offset(2, 3))
78  failflag = true;
79  if (first->offset(3, 0) != second->offset(3, 0))
80  failflag = true;
81  if (first->offset(3, 1) != second->offset(3, 1))
82  failflag = true;
83  if (first->offset(3, 2) != second->offset(3, 2))
84  failflag = true;
85  if (first->offset(3, 3) != second->offset(3, 3))
86  failflag = true;
87  if (first->slope(0, 0) != second->slope(0, 0))
88  failflag = true;
89  if (first->slope(0, 1) != second->slope(0, 1))
90  failflag = true;
91  if (first->slope(0, 2) != second->slope(0, 2))
92  failflag = true;
93  if (first->slope(0, 3) != second->slope(0, 3))
94  failflag = true;
95  if (first->slope(1, 0) != second->slope(1, 0))
96  failflag = true;
97  if (first->slope(1, 1) != second->slope(1, 1))
98  failflag = true;
99  if (first->slope(1, 2) != second->slope(1, 2))
100  failflag = true;
101  if (first->slope(1, 3) != second->slope(1, 3))
102  failflag = true;
103  if (first->slope(2, 0) != second->slope(2, 0))
104  failflag = true;
105  if (first->slope(2, 1) != second->slope(2, 1))
106  failflag = true;
107  if (first->slope(2, 2) != second->slope(2, 2))
108  failflag = true;
109  if (first->slope(2, 3) != second->slope(2, 3))
110  failflag = true;
111  if (first->slope(3, 0) != second->slope(3, 0))
112  failflag = true;
113  if (first->slope(3, 1) != second->slope(3, 1))
114  failflag = true;
115  if (first->slope(3, 2) != second->slope(3, 2))
116  failflag = true;
117  if (first->slope(3, 3) != second->slope(3, 3))
118  failflag = true;
119  if (failflag)
120  throw cms::Exception("DataDoesNotMatch") << "Values are do not match";
121  }
122  listNewChan.erase(cell); // fix 25.02.08
123  }
124  }
125  std::cout << "These are identical" << std::endl;
126  }
127 
128  // if(epsilon!=0){
129  //implement compare qies -- different epsilon for slope and offset?
130  // }
131 
132  if (outfile != "null") {
133  for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++) {
134  DetId mydetid = *it;
135  cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
136  if (cell == listNewChan.end()) // not present in new list
137  {
138  const HcalQIECoder* myCoder = myRefQIEs->getCoder(mydetid);
139  std::cout << "o";
140  resultQIEs->addCoder(*myCoder);
141  } else // present in new list
142  {
143  const HcalQIECoder* myCoder = myNewQIEs->getCoder(mydetid);
144  std::cout << "n";
145  resultQIEs->addCoder(*myCoder);
146  listNewChan.erase(cell); // fix 25.02.08
147  }
148  }
149  for (std::vector<DetId>::iterator it = listNewChan.begin(); it != listNewChan.end(); it++) // fix 25.02.08
150  {
151  DetId mydetid = *it;
152  const HcalQIECoder* myCoder = myNewQIEs->getCoder(mydetid);
153  std::cout << "N";
154  resultQIEs->addCoder(*myCoder);
155  }
156 
157  std::ofstream outStream3(outfile.c_str());
158  std::cout << "--- Dumping QIEs - the combined ones ---" << std::endl;
159  resultQIEs->sort();
160  HcalDbASCIIIO::dumpObject(outStream3, (*resultQIEs));
161  }
162 
163  std::cout << std::endl;
164  if (checkemapflag) {
165  std::vector<DetId> listResult = resultQIEs->getAllChannels();
166  // get the e-map list of channels
167  std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
168  for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++) {
169  DetId mydetid = DetId(it->rawId());
170  if (std::find(listResult.begin(), listResult.end(), mydetid) == listResult.end()) {
171  std::cout << "Conditions not found for DetId = " << HcalGenericDetId(it->rawId()) << std::endl;
172  }
173  }
174  }
175 }
176 
HcalQIEDataCheck(edm::ParameterSet const &ps)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ESGetToken< HcalQIEData, HcalQIEDataRcd > m_tok1
edm::ESGetToken< HcalElectronicsMap, HcalElectronicsMapRcd > m_tokmap
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
bool addCoder(const HcalQIECoder &fCoder)
Definition: HcalQIEData.h:41
T getUntrackedParameter(std::string const &, T const &) const
U second(std::pair< T, U > const &p)
const HcalQIECoder * getCoder(DetId fId) const
get QIE parameters
Definition: HcalQIEData.h:37
const HcalTopology * topo() const
std::vector< DetId > getAllChannels() const
bool getData(T &iHolder) const
Definition: EventSetup.h:122
~HcalQIEDataCheck() override
void analyze(const edm::Event &ev, const edm::EventSetup &es) override
Definition: DetId.h:17
void sort()
Definition: HcalQIEData.h:43
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
std::string dumprefs
std::vector< HcalGenericDetId > allPrecisionId() const
std::string outfile
edm::ESGetToken< HcalQIEData, HcalQIEDataRcd > m_tok2
std::string dumpupdate