CMS 3D CMS Logo

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