CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalPedestalMCWidths.cc
Go to the documentation of this file.
1 // Original Author: Steven Won
2 // Created: Fri May 2 15:34:43 CEST 2008
3 // Written to replace the combination of HcalPedestalAnalyzer and HcalPedestalAnalysis
4 // This code runs 1000x faster and produces all outputs from a single run
5 // (ADC, fC in .txt plus an .xml file)
6 //
7 #include <memory>
11 
13  hbheDigiCollectionTag_(ps.getParameter<edm::InputTag>("hbheDigiCollectionTag")),
14  hoDigiCollectionTag_(ps.getParameter<edm::InputTag>("hoDigiCollectionTag")),
15  hfDigiCollectionTag_(ps.getParameter<edm::InputTag>("hfDigiCollectionTag")) {
16 
17  firsttime = true;
18  histflag = ps.getUntrackedParameter<bool>("saveHists",true);
19 }
20 
21 
23 {
25  std::ofstream outfile(widthsfilename.c_str());
26  std::vector<MCWidthsBunch>::iterator bunch_it;
27  for(bunch_it=Bunches.begin(); bunch_it != Bunches.end(); bunch_it++)
28  {
29  if(!bunch_it->usedflag) continue;
30 
31  HcalCovarianceMatrix item(bunch_it->detid.rawId());
32  for(int i = 0; i != 4; i++){
33  for(int j = 0; j != 10; j++){
34  for(int k = 0; k != 10; k++){
35  bunch_it->sig[i][j][k] = (bunch_it->prod[i][j][k]/bunch_it->num[i][j][k]);//-(bunch_it->cap[i]*bunch_it->cap[(i+j)%4]);
36  if(!edm::isNotFinite(bunch_it->sig[i][j][k]))
37  {
38  item.setValue(i,j,k,bunch_it->sig[i][j][k]);
39  }else{
40  item.setValue(i,j,k,0.0);
41  }
42  }
43  }
44  }
45 
46  rawCovItem->addValues(item);
47 
48  if(histflag)
49  {
50  if(bunch_it->detid.subdet() == 1){
51  for(int i = 0; i != 4; i++){
52  for(int j = 0; j != 10; j++){
53  for(int k = j; k != 10; k++)
54  if(!edm::isNotFinite(bunch_it->sig[i][j][k])) HBMeans[j]->Fill(k-j,bunch_it->sig[i][j][k]);
55  }
56  }
57  }
58  if(bunch_it->detid.subdet() == 2){
59  for(int i = 0; i != 4; i++){
60  for(int j = 0; j != 10; j++){
61  for(int k = j; k != 10; k++)
62  if(!edm::isNotFinite(bunch_it->sig[i][j][k])) HEMeans[j]->Fill(k-j,bunch_it->sig[i][j][k]);
63  }
64  }
65  }
66  if(bunch_it->detid.subdet() == 3){
67  for(int i = 0; i != 4; i++){
68  for(int j = 0; j != 10; j++){
69  for(int k = j; k != 10; k++)
70  if(!edm::isNotFinite(bunch_it->sig[i][j][k])) HFMeans[j]->Fill(k-j,bunch_it->sig[i][j][k]);
71  }
72  }
73  }
74  if(bunch_it->detid.subdet() == 4){
75  for(int i = 0; i != 4; i++){
76  for(int j = 0; j != 10; j++){
77  for(int k = j; k != 10; k++)
78  if(!edm::isNotFinite(bunch_it->sig[i][j][k])) HOMeans[j]->Fill(k-j,bunch_it->sig[i][j][k]);
79  }
80  }
81  }
82 
83 
84  }
85  }
86  HcalDbASCIIIO::dumpObject (outfile, (*rawCovItem) );
87 
88  if(histflag)
89  {
90  theFile->cd();
91  std::cout << "Writing histograms..." << std::endl;
92  for(int i = 0; i != 10; i++){
93  HBMeans[i]->Write();
94  HFMeans[i]->Write();
95  HEMeans[i]->Write();
96  HOMeans[i]->Write();
97  }
98  }
99  theFile->Close();
100  std::cout << "ROOT file closed.\n";
101 }
102 
103 // ------------ method called to for each event ------------
104 void
106 {
107  using namespace edm;
108  using namespace std;
109 
113  edm::ESHandle<HcalDbService> conditions;
114  iSetup.get<HcalDbRecord>().get(conditions);
115 
117  iSetup.get<HcalPedestalsRcd>().get(refPeds);
118  const HcalPedestals* myRefPeds = refPeds.product();
119 
120  if(firsttime)
121  {
122  theTopology=new HcalTopology(*(myRefPeds->topo()));
123  runnum = e.id().run();
124  std::string runnum_string;
125  std::stringstream tempstringout;
126  tempstringout << runnum;
127  runnum_string = tempstringout.str();
128  widthsfilename = runnum_string + "-MCwidths.txt";
129  std::string rootfilename = runnum_string + "-MCwidths.root";
130  theFile = new TFile(rootfilename.c_str(), "RECREATE");
131 
132  for(int i = 0; i!= 10; i++)
133  {
134  tempstringout.str("");
135  tempstringout << i;
136  std::string histname3 = tempstringout.str();
137  std::string histname2 = "Mean covariance TS ";
138  std::string histname1 = "HB ";
139  std::string histname = histname1 + histname2 + histname3;
140  HBMeans[i] = new TProfile(histname.c_str(),histname1.c_str(), 10, -0.50, 9.5);
141  histname1 = "HE ";
142  histname = histname1 + histname2 + histname3;
143  HEMeans[i] = new TProfile(histname.c_str(),histname1.c_str(), 10, -0.50, 9.5);
144  histname1 = "HF ";
145  histname = histname1 + histname2 + histname3;
146  HFMeans[i] = new TProfile(histname.c_str(),histname1.c_str(), 10, -0.50, 9.5);
147  histname1 = "HO ";
148  histname = histname1 + histname2 + histname3;
149  HOMeans[i] = new TProfile(histname.c_str(),histname1.c_str(), 10, -0.50, 9.5);
150  }
151 
153  iSetup.get<HcalElectronicsMapRcd>().get(refEMap);
154  const HcalElectronicsMap* myRefEMap = refEMap.product();
155  std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
156  for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++)
157  {
158  HcalGenericDetId mygenid(it->rawId());
159  if(mygenid.isHcalDetId())
160  {
162  HcalDetId chanid(mygenid.rawId());
163  a.detid = chanid;
164  a.usedflag = false;
165  for(int i = 0; i != 4; i++)
166  {
167  for(int j = 0; j != 10; j++){
168  for(int k = 0; k != 10; k++)
169  {
170  a.sig[i][j][k] = 0;
171  a.prod[i][j][k] = 0;
172  a.num[i][j][k] = 0;
173  }}
174  }
175  Bunches.push_back(a);
176  }
177  }
178  firsttime = false;
179  }
180 
181  std::vector<MCWidthsBunch>::iterator bunch_it;
182 
183  for(HBHEDigiCollection::const_iterator j = hbhe->begin(); j != hbhe->end(); j++)
184  {
185  const HBHEDataFrame digi = (const HBHEDataFrame)(*j);
186  for(bunch_it = Bunches.begin(); bunch_it != Bunches.end(); bunch_it++)
187  if(bunch_it->detid.rawId() == digi.id().rawId()) break;
188  DetId searchid(digi.id().rawId());
189  const HcalPedestal* peds = (myRefPeds->getValues( searchid ));
190  bunch_it->usedflag = true;
191  int firstcapid = digi.sample(0).capid();
192  for(int ts = 0; ts != 10; ts++)
193  {
194  for(int j = ts; j != 10; j++){
195  bunch_it->num[firstcapid][ts][j] += 1;
196  bunch_it->prod[firstcapid][ts][j] +=
197  ((digi.sample(j).adc()-peds->getValue(firstcapid))
198  *(digi.sample(ts).adc()-peds->getValue(digi.sample(ts).capid())));
199  }
200  }
201  }
202 
203  for(HODigiCollection::const_iterator j = ho->begin(); j != ho->end(); j++)
204  {
205  const HODataFrame digi = (const HODataFrame)(*j);
206  for(bunch_it = Bunches.begin(); bunch_it != Bunches.end(); bunch_it++)
207  if(bunch_it->detid.rawId() == digi.id().rawId()) break;
208  DetId searchid(digi.id().rawId());
209  const HcalPedestal* peds = (myRefPeds->getValues( searchid ));
210  bunch_it->usedflag = true;
211  int firstcapid = digi.sample(0).capid();
212  for(int ts = 0; ts != 10; ts++)
213  {
214  for(int j = ts; j != 10; j++){
215  bunch_it->num[firstcapid][ts][j] += 1;
216  bunch_it->prod[firstcapid][ts][j] +=
217  ((digi.sample(j).adc()-peds->getValue(firstcapid))
218  *(digi.sample(ts).adc()-peds->getValue(digi.sample(ts).capid())));
219  }
220  }
221  }
222 
223  for(HFDigiCollection::const_iterator j = hf->begin(); j != hf->end(); j++)
224  {
225  const HFDataFrame digi = (const HFDataFrame)(*j);
226  for(bunch_it = Bunches.begin(); bunch_it != Bunches.end(); bunch_it++)
227  if(bunch_it->detid.rawId() == digi.id().rawId()) break;
228  DetId searchid(digi.id().rawId());
229  const HcalPedestal* peds = (myRefPeds->getValues( searchid ));
230  bunch_it->usedflag = true;
231  int firstcapid = digi.sample(0).capid();
232  for(int ts = 0; ts != 10; ts++)
233  {
234  for(int j = ts; j != 10; j++){
235  bunch_it->num[firstcapid][ts][j] += 1;
236  bunch_it->prod[firstcapid][ts][j] +=
237  ((digi.sample(j).adc()-peds->getValue(firstcapid))
238  *(digi.sample(ts).adc()-peds->getValue(digi.sample(ts).capid())));
239  }
240  }
241 
242  }
243 //this is the last brace
244 }
245 
246 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:42
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
int num[4][10][10]
HcalPedestalMCWidths(const edm::ParameterSet &ps)
edm::InputTag hbheDigiCollectionTag_
edm::InputTag hoDigiCollectionTag_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int adc() const
get the ADC sample
Definition: HcalQIESample.h:24
float sig[4][10][10]
std::vector< T >::const_iterator const_iterator
const HcalQIESample & sample(int i) const
access a sample
Definition: HODataFrame.h:40
const HcalDetId & id() const
Definition: HODataFrame.h:23
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
std::vector< MCWidthsBunch > Bunches
const HcalTopology * theTopology
list outfile
Definition: EdgesToViz.py:91
bool isNotFinite(T x)
Definition: isFinite.h:10
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
edm::InputTag hfDigiCollectionTag_
const HcalQIESample & sample(int i) const
access a sample
Definition: HFDataFrame.h:39
int j
Definition: DBlmapReader.cc:9
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup)
std::vector< HcalGenericDetId > allPrecisionId() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
int k[5][pyjets_maxn]
Definition: DetId.h:20
int capid() const
get the Capacitor id
Definition: HcalQIESample.h:28
const HcalQIESample & sample(int i) const
access a sample
Definition: HBHEDataFrame.h:39
float prod[4][10][10]
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
void setValue(int capid, int i, int j, float val)
bool addValues(const HcalCovarianceMatrix &myHcalCovarianceMatrix)
edm::EventID id() const
Definition: EventBase.h:56
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
double a
Definition: hdecay.h:121
const HcalDetId & id() const
Definition: HBHEDataFrame.h:22
tuple cout
Definition: gather_cfg.py:121
const HcalDetId & id() const
Definition: HFDataFrame.h:22