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