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