CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ESPedestalClient.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <iostream>
3 #include <fstream>
4 #include <string>
5 #include <vector>
6 
9 
11 
12 #include <TH1F.h>
13 
14 using namespace edm;
15 using namespace std;
16 
18 
19  verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
20  debug_ = ps.getUntrackedParameter<bool>("debug", true);
21  prefixME_ = ps.getUntrackedParameter<string>("prefixME", "EcalPreshower");
22  lookup_ = ps.getUntrackedParameter<FileInPath>("LookupTable");
23  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
24  fitPedestal_ = ps.getUntrackedParameter<bool>("fitPedestal", false);
25 
26  for (int i=0; i<2; i++)
27  for (int j=0; j<2; j++)
28  for (int k=0; k<40; k++)
29  for (int m=0; m<40; m++) {
30  hPed_[i][j][k][m] = 0;
31  hTotN_[i][j][k][m] = 0;
32  }
33 
34 }
35 
37 }
38 
40 
41  dqmStore_ = dqmStore;
42 
43  if ( debug_ ) cout << "ESPedestalClient: beginJob" << endl;
44 
45  ievt_ = 0;
46  jevt_ = 0;
47 
48 }
49 
51 
52  if ( debug_ ) cout << "ESPedestalClient: beginRun" << endl;
53 
54  jevt_ = 0;
55 
56  this->setup();
57 }
58 
60 
61  if ( debug_ ) cout << "ESPedestalClient: endJob, ievt = " << ievt_ << endl;
62 
63  // Preform pedestal fit
64  char hname[300];
65  int iz = 0;
66  if (fitPedestal_) {
67 
68  if ( verbose_ ) cout<<"ESPedestalClient: Fit Pedestal"<<endl;
69 
70  for (int i=0; i<nLines_; ++i) {
71 
72  iz = (senZ_[i]==1) ? 0:1;
73 
74  for (int is=0; is<32; ++is) {
75 
76  string dirname = prefixME_ + "/ESPedestalTask/";
77  sprintf(hname, "ADC Z %d P %d X %d Y %d Str %d", senZ_[i], senP_[i], senX_[i], senY_[i], is+1);
78  MonitorElement *meFit = dqmStore_->get(dirname+hname);
79 
80  if (meFit==0) continue;
81  TH1F *rootHisto = meFit->getTH1F();
82  rootHisto->Fit("fg", "Q", "", 500, 1800);
83  rootHisto->Fit("fg", "RQ", "", fg->GetParameter(1)-2.*fg->GetParameter(2),fg->GetParameter(1)+2.*fg->GetParameter(2));
84  hPed_[iz][senP_[i]-1][senX_[i]-1][senY_[i]-1]->setBinContent(is+1, (int)(fg->GetParameter(1)+0.5));
85  hTotN_[iz][senP_[i]-1][senX_[i]-1][senY_[i]-1]->setBinContent(is+1, fg->GetParameter(2));
86 
87  }
88  }
89 
90  } else {
91 
92  if ( verbose_ ) cout<<"ESPedestalClient: Use Histogram Mean"<<endl;
93 
94  for (int i=0; i<nLines_; ++i) {
95 
96  iz = (senZ_[i]==1) ? 0:1;
97 
98  for (int is=0; is<32; ++is) {
99 
100  string dirname = prefixME_ + "/ESPedestalTask/";
101  sprintf(hname, "ADC Z %d P %d X %d Y %d Str %d", senZ_[i], senP_[i], senX_[i], senY_[i], is+1);
102  MonitorElement *meMean = dqmStore_->get(dirname+hname);
103 
104  if (meMean==0) continue;
105  TH1F *rootHisto = meMean->getTH1F();
106 
107  hPed_[iz][senP_[i]-1][senX_[i]-1][senY_[i]-1]->setBinContent(is+1, (int)(rootHisto->GetMean()+0.5));
108  hTotN_[iz][senP_[i]-1][senX_[i]-1][senY_[i]-1]->setBinContent(is+1, rootHisto->GetRMS());
109 
110  }
111  }
112  }
113 
114  this->cleanup();
115 }
116 
118 
119  if ( debug_ ) cout << "ESPedestalClient: endRun, jevt = " << jevt_ << endl;
120 
121  this->cleanup();
122 }
123 
125 
126  // read in look-up table
127  int iz, ip, ix, iy, fed, kchip, pace, bundle, fiber, optorx;
128  ifstream file;
129 
130  file.open(lookup_.fullPath().c_str());
131  if( file.is_open() ) {
132 
133  file >> nLines_;
134 
135  for (int i=0; i<nLines_; ++i) {
136  file>> iz >> ip >> ix >> iy >> fed >> kchip >> pace >> bundle >> fiber >> optorx;
137 
138  senZ_[i] = iz;
139  senP_[i] = ip;
140  senX_[i] = ix;
141  senY_[i] = iy;
142  }
143 
144  } else {
145  cout<<"ESPedestalClient : Look up table file can not be found in "<<lookup_.fullPath().c_str()<<endl;
146  }
147 
148  // define histograms
149  dqmStore_->setCurrentFolder(prefixME_+"/ESPedestalClient");
150 
151  char hname[300];
152  for (int i=0; i<nLines_; ++i) {
153 
154  iz = (senZ_[i]==1) ? 0:1;
155 
156  sprintf(hname, "Ped Z %d P %d X %d Y %d", senZ_[i], senP_[i], senX_[i], senY_[i]);
157  hPed_[iz][senP_[i]-1][senX_[i]-1][senY_[i]-1] = dqmStore_->book1D(hname, hname, 32, 0, 32);
158 
159  sprintf(hname, "Total Noise Z %d P %d X %d Y %d", senZ_[i], senP_[i], senX_[i], senY_[i]);
160  hTotN_[iz][senP_[i]-1][senX_[i]-1][senY_[i]-1] = dqmStore_->book1D(hname, hname, 32, 0, 32);
161  }
162 
163  fg = new TF1("fg", "gaus");
164 
165 }
166 
168 
169  if( ! enableCleanup_ ) return;
170 
171  if ( debug_ ) cout << "ESPedestalClient: cleanup" << endl;
172 
173  for (int i=0; i<2; i++)
174  for (int j=0; j<2; j++)
175  for (int k=0; k<40; k++)
176  for (int m=0; m<40; m++) {
177  hPed_[i][j][k][m] = 0;
178  hTotN_[i][j][k][m] = 0;
179  }
180 
181 }
182 
184 
185  ievt_++;
186  jevt_++;
187 
188 }
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
void beginJob(DQMStore *dqmStore)
list file
Definition: dbtoweb.py:253
ESPedestalClient(const edm::ParameterSet &ps)
static void cleanup(const Factory::MakerMap::value_type &v)
Definition: Factory.cc:12
virtual ~ESPedestalClient()
int j
Definition: DBlmapReader.cc:9
int k[5][pyjets_maxn]
TH1F * getTH1F(void) const
tuple cout
Definition: gather_cfg.py:41