CMS 3D CMS Logo

HcalGainsCheck.cc
Go to the documentation of this file.
2 
4  rootfile = ps.getUntrackedParameter<std::string>("rootfile", "null");
5  outfile = ps.getUntrackedParameter<std::string>("outFile", "null");
6  dumpupdate = ps.getUntrackedParameter<std::string>("dumpUpdateGainsTo", "null");
7  dumprefs = ps.getUntrackedParameter<std::string>("dumpRefGainsTo", "null");
8  emapflag = ps.getUntrackedParameter<bool>("checkEmap", false);
9  validategainsflag = ps.getUntrackedParameter<bool>("validateGains", false);
10  epsilon = ps.getUntrackedParameter<double>("deltaG", 1000000);
11  m_tok1 = esConsumes<HcalGains, HcalGainsRcd>(edm::ESInputTag("", "update"));
12  m_tok2 = esConsumes<HcalGains, HcalGainsRcd>(edm::ESInputTag("", "reference"));
13  m_tokmap = esConsumes<HcalElectronicsMap, HcalElectronicsMapRcd>(edm::ESInputTag("", "reference"));
14 }
15 
17  f = new TFile(rootfile.c_str(), "RECREATE");
18 
19  //book histos:
20  ocMapUp = new TH2F("ocMapUp", "occupancy_map_updated_gains", 83, -41.5, 41.5, 72, 0.5, 72.5);
21  ocMapRef = new TH2F("ocMapRef", "occupancy_map_updated_gains", 83, -41.5, 41.5, 72, 0.5, 72.5);
22  // valMapUp;
23  // valMapRef;
24 
25  diffUpRefCap0 = new TH1F("diffUpRefCap0", "difference_update_reference_Cap0", 100, -0.5, 0.5);
26  ratioUpRefCap0 = new TH1F("ratioUpRefCap0", "ration_update_reference_Cap0", 100, 0.5, 1.5);
27  gainsUpCap0 = new TH1F("gainsUpCap0", "gains_update_Cap0", 100, 0.0, 0.6);
28  gainsRefCap0 = new TH1F("gainsRefCap0", "gains_reference_Cap0", 100, 0.0, 0.6);
29 
30  diffUpRefCap1 = new TH1F("diffUpRefCap1", "difference_update_reference_Cap1", 100, -0.5, 0.5);
31  ratioUpRefCap1 = new TH1F("ratioUpRefCap1", "ration_update_reference_Cap1", 100, 0.5, 1.5);
32  gainsUpCap1 = new TH1F("gainsUpCap1", "gains_update_Cap1", 100, 0.0, 0.6);
33  gainsRefCap1 = new TH1F("gainsRefCap1", "gains_reference_Cap1", 100, 0.0, 0.6);
34 
35  diffUpRefCap2 = new TH1F("diffUpRefCap2", "difference_update_reference_Cap2", 100, -0.5, 0.5);
36  ratioUpRefCap2 = new TH1F("ratioUpRefCap2", "ration_update_reference_Cap2", 100, 0.5, 1.5);
37  gainsUpCap2 = new TH1F("gainsUpCap2", "gains_update_Cap2", 100, 0.0, 0.6);
38  gainsRefCap2 = new TH1F("gainsRefCap2", "gains_reference_Cap2", 100, 0.0, 0.6);
39 
40  diffUpRefCap3 = new TH1F("diffUpRefCap3", "difference_update_reference_Cap3", 100, -0.5, 0.5);
41  ratioUpRefCap3 = new TH1F("ratioUpRefCap3", "ration_update_reference_Cap3", 100, 0.5, 1.5);
42  gainsUpCap3 = new TH1F("gainsUpCap3", "gains_update_Cap3", 100, 0.0, 0.6);
43  gainsRefCap3 = new TH1F("gainsRefCap3", "gains_reference_Cap3", 100, 0.0, 0.6);
44 
45  // gainsUpCap0vsEta = new TGraph("gainsUpCap0vsEta","gains_update_Cap0_vsEta",100,-41,0.6);
46  // gainsRefCap0vsEta = new TGraph("gainsRefCap0vsEta","gains_reference_Cap0_vsEta",100,0.0,0.6);
47 }
48 
50  using namespace edm::eventsetup;
51  bool epsilonflag = false;
52  bool notequalsflag = false;
53  // get new gains
54  const HcalGains* myNewGains = &es.getData(m_tok1);
55 
56  // get reference gains
57  const HcalGains* myRefGains = &es.getData(m_tok2);
58 
59  // get e-map from reference
60  const HcalElectronicsMap* myRefEMap = &es.getData(m_tokmap);
61 
62  // dump gains:
63  if (dumpupdate != "null") {
64  std::ofstream outStream(dumpupdate.c_str());
65  std::cout << "--- Dumping Gains - update ---" << std::endl;
66  HcalDbASCIIIO::dumpObject(outStream, (*myNewGains));
67  }
68  if (dumprefs != "null") {
69  std::ofstream outStream2(dumprefs.c_str());
70  std::cout << "--- Dumping Gains - reference ---" << std::endl;
71  HcalDbASCIIIO::dumpObject(outStream2, (*myRefGains));
72  }
73  // get the list of all channels
74  std::vector<DetId> listNewChan = myNewGains->getAllChannels();
75  std::vector<DetId> listRefChan = myRefGains->getAllChannels();
76 
77  std::vector<DetId>::const_iterator cell;
78 
79  //plots: occupancy map, value map, difference, ratio, gains:
80  for (std::vector<DetId>::const_iterator it = listRefChan.begin(); it != listRefChan.end(); it++) {
81  HcalGenericDetId myId(*it);
82  // ocMapRef->Fill(myId->);
83 
84  float valCap0 = myRefGains->getValues(*it)->getValue(0);
85  float valCap1 = myRefGains->getValues(*it)->getValue(1);
86  float valCap2 = myRefGains->getValues(*it)->getValue(2);
87  float valCap3 = myRefGains->getValues(*it)->getValue(3);
88 
89  gainsRefCap0->Fill(valCap0);
90  gainsRefCap1->Fill(valCap1);
91  gainsRefCap2->Fill(valCap2);
92  gainsRefCap3->Fill(valCap3);
93 
94  cell = std::find(listNewChan.begin(), listNewChan.end(), (*it));
95  if (cell != listNewChan.end()) //found
96  {
97  float valCap0up = myNewGains->getValues(*it)->getValue(0);
98  float valCap1up = myNewGains->getValues(*it)->getValue(1);
99  float valCap2up = myNewGains->getValues(*it)->getValue(2);
100  float valCap3up = myNewGains->getValues(*it)->getValue(3);
101 
102  diffUpRefCap0->Fill(valCap0up - valCap0);
103  diffUpRefCap1->Fill(valCap1up - valCap1);
104  diffUpRefCap2->Fill(valCap2up - valCap2);
105  diffUpRefCap3->Fill(valCap3up - valCap3);
106 
107  if (fabs(valCap0up - valCap0) > epsilon)
108  epsilonflag = true;
109  if (fabs(valCap1up - valCap1) > epsilon)
110  epsilonflag = true;
111  if (fabs(valCap2up - valCap2) > epsilon)
112  epsilonflag = true;
113  if (fabs(valCap3up - valCap3) > epsilon)
114  epsilonflag = true;
115 
116  if (valCap0up != valCap0)
117  notequalsflag = true;
118  if (valCap1up != valCap1)
119  notequalsflag = true;
120  if (valCap2up != valCap2)
121  notequalsflag = true;
122  if (valCap3up != valCap3)
123  notequalsflag = true;
124 
125  ratioUpRefCap0->Fill(valCap0up / valCap0);
126  ratioUpRefCap1->Fill(valCap1up / valCap1);
127  ratioUpRefCap2->Fill(valCap2up / valCap2);
128  ratioUpRefCap3->Fill(valCap3up / valCap3);
129  }
130  }
131  for (std::vector<DetId>::const_iterator it = listNewChan.begin(); it != listNewChan.end(); it++) {
132  float valCap0 = myNewGains->getValues(*it)->getValue(0);
133  float valCap1 = myNewGains->getValues(*it)->getValue(1);
134  float valCap2 = myNewGains->getValues(*it)->getValue(2);
135  float valCap3 = myNewGains->getValues(*it)->getValue(3);
136 
137  gainsUpCap0->Fill(valCap0);
138  gainsUpCap1->Fill(valCap1);
139  gainsUpCap2->Fill(valCap2);
140  gainsUpCap3->Fill(valCap3);
141  }
142 
143  if (epsilon != 1000000) {
144  if (epsilonflag)
145  throw cms::Exception("DataDoesNotMatch") << "Values differ by more than deltaG" << std::endl;
146  } else {
147  std::cout << "These gains do not differ by more than deltaG" << std::endl;
148  }
149 
150  if (validategainsflag) {
151  if (notequalsflag)
152  throw cms::Exception("DataDoesNotMatch") << "Values do not match" << std::endl;
153  } else {
154  std::cout << "These gains are identical" << std::endl;
155  }
156 
157  // go through list of valid channels from reference, look up if conditions exist for update
158  // push back into new vector the corresponding updated conditions,
159  // or if it doesn't exist, the reference
160 
161  if (outfile != "null") {
162  HcalGains* resultGains = new HcalGains(myRefGains->topo());
163  for (std::vector<DetId>::const_iterator it = listRefChan.begin(); it != listRefChan.end(); it++) {
164  DetId mydetid = *it;
165  HcalGenericDetId myId(*it);
166  cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
167  if (cell == listNewChan.end()) // not present in new list, take old conditions
168  {
169  const HcalGain* item = myRefGains->getValues(mydetid);
170  std::cout << "o";
171  resultGains->addValues(*item);
172  } else // present in new list, take new conditions
173  {
174  const HcalGain* item = myNewGains->getValues(mydetid);
175  std::cout << "n";
176  resultGains->addValues(*item);
177  }
178  }
179  std::cout << std::endl;
180 
181  std::vector<DetId> listResult = resultGains->getAllChannels();
182  // get the e-map list of channels
183  if (emapflag) {
184  std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
185  // look up if emap channels are all present in pedestals, if not then cerr
186  for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++) {
187  DetId mydetid = DetId(it->rawId());
188  if (std::find(listResult.begin(), listResult.end(), mydetid) == listResult.end()) {
189  std::cout << "Conditions not found for DetId = " << HcalGenericDetId(it->rawId()) << std::endl;
190  }
191  }
192  }
193 
194  // dump the resulting list of pedestals into a file
195  // std::ostringstream filename3;
196  // filename3 << "test_combined.txt";
197  std::ofstream outStream3(outfile.c_str());
198  std::cout << "--- Dumping Gains - the combined ones ---" << std::endl;
199  HcalDbASCIIIO::dumpObject(outStream3, (*resultGains));
200  }
201  // const float* values = myped->getValues (channelID);
202  // if (values) std::cout << "pedestals for channel " << channelID << ": "
203  // << values [0] << '/' << values [1] << '/' << values [2] << '/' << values [3] << std::endl;
204 }
205 
206 // ------------ method called once each job just after ending the event loop ------------
208  if (rootfile != "null") {
209  f->Write();
210  }
211  f->Close();
212 }
213 
TH1F * diffUpRefCap1
void endJob() override
edm::ESGetToken< HcalElectronicsMap, HcalElectronicsMapRcd > m_tokmap
TH1F * diffUpRefCap3
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TH1F * ratioUpRefCap2
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
TH1F * diffUpRefCap2
const Item * getValues(DetId fId, bool throwOnFail=true) const
TH1F * diffUpRefCap0
T getUntrackedParameter(std::string const &, T const &) const
const HcalTopology * topo() const
void analyze(const edm::Event &ev, const edm::EventSetup &es) override
void beginJob() override
std::vector< DetId > getAllChannels() const
bool getData(T &iHolder) const
Definition: EventSetup.h:122
HcalGainsCheck(edm::ParameterSet const &ps)
std::string dumpupdate
TH1F * ratioUpRefCap3
TH1F * ratioUpRefCap0
float getValue(int fCapId) const
get value for capId = 0..3
Definition: HcalGain.h:21
Definition: DetId.h:17
edm::ESGetToken< HcalGains, HcalGainsRcd > m_tok1
std::string outfile
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
std::vector< HcalGenericDetId > allPrecisionId() const
TH1F * ratioUpRefCap1
std::string dumprefs
bool addValues(const Item &myItem)
std::string rootfile
edm::ESGetToken< HcalGains, HcalGainsRcd > m_tok2