CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EBOccupancyClient.cc
Go to the documentation of this file.
1 /*
2  * \file EBOccupancyClient.cc
3  *
4  * $Date: 2011/08/30 09:33:51 $
5  * $Revision: 1.43 $
6  * \author G. Della Ricca
7  * \author F. Cossutti
8  *
9 */
10 
11 #include <memory>
12 #include <iostream>
13 #include <fstream>
14 #include <iomanip>
15 #include <math.h>
16 
18 
21 
22 #ifdef WITH_ECAL_COND_DB
26 #endif
27 
30 
32 
34 
35  // cloneME switch
36  cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
37 
38  // verbose switch
39  verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
40 
41  // debug switch
42  debug_ = ps.getUntrackedParameter<bool>("debug", false);
43 
44  // prefixME path
45  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
46 
47  // enableCleanup_ switch
48  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
49 
50  // vector of selected Super Modules (Defaults to all 36).
51  superModules_.reserve(36);
52  for ( unsigned int i = 1; i <= 36; i++ ) superModules_.push_back(i);
53  superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
54 
55  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
56  int ism = superModules_[i];
57  i01_[ism-1] = 0;
58  i02_[ism-1] = 0;
59  }
60 
61  for ( int i=0; i<3; i++) {
62  h01_[i] = 0;
63  h01ProjEta_[i] = 0;
64  h01ProjPhi_[i] = 0;
65  }
66 
67  for ( int i=0; i<2; i++) {
68  h02_[i] = 0;
69  h02ProjEta_[i] = 0;
70  h02ProjPhi_[i] = 0;
71  }
72 
73 }
74 
76 
77 }
78 
80 
82 
83  if ( debug_ ) std::cout << "EBOccupancyClient: beginJob" << std::endl;
84 
85  ievt_ = 0;
86  jevt_ = 0;
87 
88 }
89 
91 
92  if ( debug_ ) std::cout << "EBOccupancyClient: beginRun" << std::endl;
93 
94  jevt_ = 0;
95 
96  this->setup();
97 
98 }
99 
101 
102  if ( debug_ ) std::cout << "EBOccupancyClient: endJob, ievt = " << ievt_ << std::endl;
103 
104  this->cleanup();
105 
106 }
107 
109 
110  if ( debug_ ) std::cout << "EBOccupancyClient: endRun, jevt = " << jevt_ << std::endl;
111 
112  this->cleanup();
113 
114 }
115 
117 
118  dqmStore_->setCurrentFolder( prefixME_ + "/EBOccupancyClient" );
119 
120 }
121 
123 
124  if ( ! enableCleanup_ ) return;
125 
126  if ( cloneME_ ) {
127 
128  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
129  int ism = superModules_[i];
130  if ( i01_[ism-1] ) delete i01_[ism-1];
131  if ( i02_[ism-1] ) delete i02_[ism-1];
132  }
133 
134  for ( int i=0; i<3; ++i ) {
135  if ( h01_[i] ) delete h01_[i];
136  if ( h01ProjEta_[i] ) delete h01ProjEta_[i];
137  if ( h01ProjPhi_[i] ) delete h01ProjPhi_[i];
138  }
139 
140  for ( int i=0; i<2; ++i ) {
141  if ( h02_[i] ) delete h02_[i];
142  if ( h02ProjEta_[i] ) delete h02ProjEta_[i];
143  if ( h02ProjPhi_[i] ) delete h02ProjPhi_[i];
144  }
145 
146  }
147 
148  for ( int i=0; i<3; ++i ) {
149  h01_[i] = 0;
150  h01ProjEta_[i] = 0;
151  h01ProjPhi_[i] = 0;
152  }
153 
154  for ( int i=0; i<2; ++i ) {
155  h02_[i] = 0;
156  h02ProjEta_[i] = 0;
157  h02ProjPhi_[i] = 0;
158  }
159 
160 }
161 
162 #ifdef WITH_ECAL_COND_DB
163 bool EBOccupancyClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
164 
165  status = true;
166 
167  EcalLogicID ecid;
168 
170  std::map<EcalLogicID, MonOccupancyDat> dataset;
171 
172  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
173 
174  int ism = superModules_[i];
175 
176  if ( verbose_ ) {
177  std::cout << " " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
178  std::cout << std::endl;
179  }
180 
181  const float n_min_tot = 1000.;
182  const float n_min_bin = 10.;
183 
184  float num01, num02;
185  float mean01, mean02;
186  float rms01, rms02;
187 
188  for ( int ie = 1; ie <= 85; ie++ ) {
189  for ( int ip = 1; ip <= 20; ip++ ) {
190 
191  num01 = num02 = -1.;
192  mean01 = mean02 = -1.;
193  rms01 = rms02 = -1.;
194 
195  bool update_channel = false;
196 
197  if ( i01_[ism-1] && i01_[ism-1]->GetEntries() >= n_min_tot ) {
198  num01 = i01_[ism-1]->GetBinContent(ie, ip);
199  if ( num01 >= n_min_bin ) update_channel = true;
200  }
201 
202  if ( i02_[ism-1] && i02_[ism-1]->GetEntries() >= n_min_tot ) {
203  num02 = i02_[ism-1]->GetBinEntries(i02_[ism-1]->GetBin(ie, ip));
204  if ( num02 >= n_min_bin ) {
205  mean02 = i02_[ism-1]->GetBinContent(ie, ip);
206  rms02 = i02_[ism-1]->GetBinError(ie, ip);
207  }
208  }
209 
210  if ( update_channel ) {
211 
212  if ( Numbers::icEB(ism, ie, ip) == 1 ) {
213 
214  if ( verbose_ ) {
215  std::cout << "Preparing dataset for " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
216  std::cout << "Digi (" << ie << "," << ip << ") " << num01 << " " << mean01 << " " << rms01 << std::endl;
217  std::cout << "RecHitThr (" << ie << "," << ip << ") " << num02 << " " << mean02 << " " << rms02 << std::endl;
218  std::cout << std::endl;
219  }
220 
221  }
222 
223  o.setEventsOverLowThreshold(int(num01));
224  o.setEventsOverHighThreshold(int(num02));
225 
226  o.setAvgEnergy(mean02);
227 
228  int ic = Numbers::indexEB(ism, ie, ip);
229 
230  if ( econn ) {
231  ecid = LogicID::getEcalLogicID("EB_crystal_number", Numbers::iSM(ism, EcalBarrel), ic);
232  dataset[ecid] = o;
233  }
234 
235  }
236 
237  }
238  }
239 
240  }
241 
242  if ( econn ) {
243  try {
244  if ( verbose_ ) std::cout << "Inserting MonOccupancyDat ..." << std::endl;
245  if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
246  if ( verbose_ ) std::cout << "done." << std::endl;
247  } catch (std::runtime_error &e) {
248  std::cerr << e.what() << std::endl;
249  }
250  }
251 
252  return true;
253 
254 }
255 #endif
256 
258 
259  ievt_++;
260  jevt_++;
261  if ( ievt_ % 10 == 0 ) {
262  if ( debug_ ) std::cout << "EBOccupancyClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
263  }
264 
265  MonitorElement* me;
266 
267  for ( unsigned int i=0; i<superModules_.size(); i++ ) {
268 
269  int ism = superModules_[i];
270 
271  me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT digi occupancy " + Numbers::sEB(ism) );
272  i01_[ism-1] = UtilsClient::getHisto<TH2F*>( me, cloneME_, i01_[ism-1] );
273 
274  me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT rec hit energy " + Numbers::sEB(ism) );
275  i02_[ism-1] = UtilsClient::getHisto<TProfile2D*>( me, cloneME_, i02_[ism-1] );
276 
277  }
278 
279  me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT digi occupancy" );
280  h01_[0] = UtilsClient::getHisto<TH2F*> ( me, cloneME_, h01_[0] );
281 
282  me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT digi occupancy projection eta" );
283  h01ProjEta_[0] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjEta_[0] );
284 
285  me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT digi occupancy projection phi" );
286  h01ProjPhi_[0] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjPhi_[0] );
287 
288  me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT rec hit occupancy" );
289  h01_[1] = UtilsClient::getHisto<TH2F*> ( me, cloneME_, h01_[1] );
290 
291  me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT rec hit occupancy projection eta" );
292  h01ProjEta_[1] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjEta_[1] );
293 
294  me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT rec hit occupancy projection phi" );
295  h01ProjPhi_[1] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjPhi_[1] );
296 
297  me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT TP digi occupancy" );
298  h01_[2] = UtilsClient::getHisto<TH2F*> ( me, cloneME_, h01_[2] );
299 
300  me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT TP digi occupancy projection eta" );
301  h01ProjEta_[2] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjEta_[2] );
302 
303  me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT TP digi occupancy projection phi" );
304  h01ProjPhi_[2] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjPhi_[2] );
305 
306  me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT rec hit thr occupancy" );
307  h02_[0] = UtilsClient::getHisto<TH2F*> ( me, cloneME_, h02_[0] );
308 
309  me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT rec hit thr occupancy projection eta" );
310  h02ProjEta_[0] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h02ProjEta_[0] );
311 
312  me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT rec hit thr occupancy projection phi" );
313  h02ProjPhi_[0] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h02ProjPhi_[0] );
314 
315  me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT TP digi thr occupancy" );
316  h02_[1] = UtilsClient::getHisto<TH2F*> ( me, cloneME_, h02_[1] );
317 
318  me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT TP digi thr occupancy projection eta" );
319  h02ProjEta_[1] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h02ProjEta_[1] );
320 
321  me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT TP digi thr occupancy projection phi" );
322  h02ProjPhi_[1] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h02ProjPhi_[1] );
323 
324 }
325 
Cache logicID vector from database.
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
static std::string sEB(const int ism)
Definition: Numbers.cc:87
std::vector< int > superModules_
virtual ~EBOccupancyClient()
Destructor.
EBOccupancyClient(const edm::ParameterSet &ps)
Constructor.
void setAvgEnergy(float energy)
void beginRun(void)
BeginRun.
void cleanup(void)
Cleanup.
Some &quot;id&quot; conversions.
void setEventsOverLowThreshold(int events)
void beginJob(void)
BeginJob.
static int icEB(const int ism, const int ix, const int iy)
Definition: Numbers.cc:898
static int indexEB(const int ism, const int ie, const int ip)
Definition: Numbers.cc:869
static int iSM(const int ism, const EcalSubdetector subdet)
Definition: Numbers.cc:222
void analyze(void)
Analyze.
TProfile2D * i02_[36]
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1265
Ecal Monitor Utils for Client.
void setup(void)
Setup.
void setEventsOverHighThreshold(int events)
void endRun(void)
EndRun.
void insertDataArraySet(const std::map< EcalLogicID, DATT > *data, IOVT *iov)
tuple cout
Definition: gather_cfg.py:41
tuple status
Definition: ntuplemaker.py:245
static EcalLogicID getEcalLogicID(const char *name, const int id1=EcalLogicID::NULLID, const int id2=EcalLogicID::NULLID, const int id3=EcalLogicID::NULLID)
Definition: LogicID.h:31
void endJob(void)
EndJob.
Definition: RunIOV.h:13
int ism(int ieta, int iphi)
Definition: EcalPyUtils.cc:56
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232