test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalPedestalWidthsCheck.cc
Go to the documentation of this file.
2 
4 {
5  outfile = ps.getUntrackedParameter<std::string>("outFile","null");
6  dumprefs = ps.getUntrackedParameter<std::string>("dumpRefWidthsTo","null");
7  dumpupdate = ps.getUntrackedParameter<std::string>("dumpUpdateWidthsTo","null");
8  checkemapflag = ps.getUntrackedParameter<bool>("checkEmap",false);
9  validateflag = ps.getUntrackedParameter<bool>("validateWidths",false);
10  epsilon = ps.getUntrackedParameter<double>("deltaW",0);
11 }
12 
14 {
15 }
16 
18 {
19  using namespace edm::eventsetup;
20 
21  // get fake pedestals from file ("new pedestals")
23  es.get<HcalPedestalWidthsRcd>().get("update",newPeds);
24  const HcalPedestalWidths* myNewPeds = newPeds.product();
25 
26  // get DB pedestals from Frontier/OrcoX ("reference")
28  es.get<HcalPedestalWidthsRcd>().get("reference",refPeds);
29  const HcalPedestalWidths* 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 
37  // dump pedestals:
38  if(dumpupdate.compare("null")!=0){
39  std::ofstream outStream(dumpupdate.c_str());
40  std::cout << "--- Dumping PedestalWidths - update ---" << std::endl;
41  HcalDbASCIIIO::dumpObject (outStream, (*myNewPeds) );
42  }
43  if(dumprefs.compare("null")!=0){
44  std::ofstream outStream2(dumprefs.c_str());
45  std::cout << "--- Dumping PedestalWidths - reference ---" << std::endl;
46  HcalDbASCIIIO::dumpObject (outStream2, (*myRefPeds) );
47  }
48  // first get the list of all channels from the update
49  std::vector<DetId> listNewChan = myNewPeds->getAllChannels();
50 
51  // go through list of valid channels from reference, look up if pedestals exist for update
52  // push back into new vector the corresponding updated pedestals,
53  // or if it doesn't exist, the reference
54  HcalPedestalWidths *resultPeds = new HcalPedestalWidths(myRefPeds->topo(), myRefPeds->isADC() );
55  std::vector<DetId> listRefChan = myRefPeds->getAllChannels();
56  std::vector<DetId>::iterator cell;
57 
58  if(validateflag){
59  for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++)
60  {
61  DetId mydetid = *it;
62  cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
63  if (cell == listNewChan.end()) // not present in new list, take old pedestals
64  {
65  throw cms::Exception("DataDoesNotMatch")<<"Value not found in reference" << std::endl;
66  }
67  else // present in new list, take new pedestals
68  {
69  const HcalPedestalWidth* first = myNewPeds->getValues( mydetid );
70  const HcalPedestalWidth* second = myRefPeds->getValues( mydetid );
71  const float* newwidth = first->getValues();
72  const float* oldwidth = second->getValues();
73  if( (*newwidth != *oldwidth) || (*(newwidth+1)!=*(oldwidth+1)) || (*(newwidth+2)!=*(oldwidth+2)) || (*(newwidth+3)!=*(oldwidth+3)) || (*(newwidth+4)!=*(oldwidth+4)) || (*(newwidth+5)!=*(oldwidth+5)) || (*(newwidth+6)!=*(oldwidth+6)) || (*(newwidth+7)!=*(oldwidth+7)) || (*(newwidth+8)!=*(oldwidth+8)) || (*(newwidth+9)!=*(oldwidth+9))){
74  throw cms::Exception("DataDoesNotMatch") << "Values are not identical" << std::endl;
75  }
76  listNewChan.erase(cell); // fix 25.02.08
77  }
78  }
79  std::cout << "These are identical" << std::endl;
80  }
81 
82 
83 
84 
85  if(epsilon!=0){
86  for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++)
87  {
88  DetId mydetid = *it;
89  cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
90  if (cell == listNewChan.end()) // not present in new list, take old pedestals
91  {
92  throw cms::Exception("DataDoesNotMatch")<<"Value not found in reference" << std::endl;
93  }
94  else // present in new list, take new pedestals
95  {
96  const HcalPedestalWidth* first = myNewPeds->getValues( mydetid );
97  const HcalPedestalWidth* second = myRefPeds->getValues( mydetid );
98  const float* newwidth = first->getValues();
99  const float* oldwidth = second->getValues();
100  if( fabs(*newwidth-*oldwidth)>epsilon || fabs(*(newwidth+1)-*(oldwidth+1))>epsilon || fabs(*(newwidth+2)-*(oldwidth+2))>epsilon || fabs(*(newwidth+3)-*(oldwidth+3))>epsilon || fabs(*(newwidth+4)-*(oldwidth+4))>epsilon || fabs(*(newwidth+5)-*(oldwidth+5))>epsilon || fabs(*(newwidth+6)-*(oldwidth+6))>epsilon || fabs(*(newwidth+7)-*(oldwidth+7))>epsilon || fabs(*(newwidth+8)-*(oldwidth+8))>epsilon || fabs(*(newwidth+9)-*(oldwidth+9))>epsilon){
101  throw cms::Exception("DataDoesNotMatch") << "Values differ by more than deltaW" << std::endl;
102  }
103  listNewChan.erase(cell); // fix 25.02.08
104  }
105  }
106  std::cout << "These are identical" << std::endl;
107  }
108  if(outfile.compare("null")!=0){
109  for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++)
110  {
111  DetId mydetid = *it;
112  cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
113  if (cell == listNewChan.end()) // not present in new list, take old pedestals
114  {
115  const HcalPedestalWidth* mywidth = myRefPeds->getValues( mydetid );
116  std::cout << "o";
117  resultPeds->addValues( *mywidth );
118  }
119  else // present in new list, take new pedestals
120  {
121  const HcalPedestalWidth* mywidth = myNewPeds->getValues( mydetid );
122  std::cout << "n";
123  resultPeds->addValues( *mywidth );
124 
125  listNewChan.erase(cell); // fix 25.02.08
126  }
127  }
128 
129  for (std::vector<DetId>::iterator it = listNewChan.begin(); it != listNewChan.end(); it++) // fix 25.02.08
130  {
131  DetId mydetid = *it;
132  const HcalPedestalWidth* mywidth = myNewPeds->getValues( mydetid );
133  std::cout << "N";
134  resultPeds->addValues( *mywidth );
135  }
136  // dump the resulting list of pedestals into a file
137  std::ofstream outStream3(outfile.c_str());
138  std::cout << "--- Dumping PedestalWidths - the combined ones ---" << std::endl;
139  HcalDbASCIIIO::dumpObject (outStream3, (*resultPeds) );
140 
141 
142 
143  }
144  std::cout << std::endl;
145  if(checkemapflag){
146  std::vector<DetId> listResult = resultPeds->getAllChannels();
147  // get the e-map list of channels
148  std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
149  // look up if emap channels are all present in pedestals, if not then cerr
150  for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++)
151  {
152  DetId mydetid = DetId(it->rawId());
153  if (std::find(listResult.begin(), listResult.end(), mydetid ) == listResult.end() )
154  {
155  std::cout << "Conditions not found for DetId = " << HcalGenericDetId(it->rawId()) << std::endl;
156  }
157  }
158  }
159 
160 }
161 
162 
163 //vecDetId HcalPedestalWidthsCheck::getMissingDetIds(vector<HcalPedestalWidths> & myPedestalWidths)
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 
178 
T getUntrackedParameter(std::string const &, T const &) const
const float * getValues() const
get value for all capId = 0..3, 10 values in total
void analyze(const edm::Event &ev, const edm::EventSetup &es)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool ev
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
U second(std::pair< T, U > const &p)
std::vector< DetId > getAllChannels() const
Definition: DetId.h:18
const T & get() const
Definition: EventSetup.h:56
HcalPedestalWidthsCheck(edm::ParameterSet const &ps)
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
tuple cout
Definition: gather_cfg.py:145