CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CastorDigiMonitor.cc
Go to the documentation of this file.
5 
6 //****************************************************//
7 //********** CastorDigiMonitor: ******************//
8 //********** Author: Dmytro Volyanskyy *************//
9 //********** Date : 29.08.2008 (first version) ******//
10 //****************************************************//
14 //==================================================================//
15 //======================= Constructor ==============================//
16 //==================================================================//
18  {
19 
20  doPerChannel_ = false;
21 
22  }
23 
24 
25 //==================================================================//
26 //======================= Destructor ===============================//
27 //==================================================================//
29  {
30 
31  }
32 
33 
34 //==================================================================//
35 //=========================== reset ===============================//
36 //==================================================================//
38  {
39 
40  }
41 
42 //==================================================================//
43 //=========================== setup ===============================//
44 //==================================================================//
46  {
47 
49 
50  if(fVerbosity>0) { std::cout << "CastorDigiMonitor::setup (start)" << std::endl; }
51 
52  //set base folder
53  baseFolder_ = rootFolder_+"CastorDigiMonitor";
54 
55  doPerChannel_ = ps.getUntrackedParameter<bool>("DigiPerChannel", false);
56  doFCpeds_ = ps.getUntrackedParameter<bool>("DigiInFC", true);
57 
58  ievt_=0;
59 
60  outputFile_ = ps.getUntrackedParameter<std::string>("PedestalFile", "");
61  if ( outputFile_.size() != 0 )
62  {
63  if(fVerbosity>0) { std::cout << "Castor Pedestal Calibrations will be saved to " << outputFile_.c_str() << std::endl; }
64  }
65 
66 
67  if(fVerbosity>0) { std::cout << "CastorDigiMonitor::setup (end)" << std::endl; }
68 
69  return;
70 }
71 
72 
73 //==================================================================//
74 //=========================== beginRun =============================//
75 //==================================================================//
77  {
78  if(fVerbosity>0) std::cout << "CastorDigiMonitor::beginRun (start)" << std::endl;
79 
80  if ( m_dbe !=NULL )
81  {
83  meEVT_ = m_dbe->bookInt("Digi Task Event Number");
84  meEVT_->Fill(ievt_);
85 
87 
89  std::string type = "Castor Digis ADC counts";
90  castHists.ALLPEDS = m_dbe->book1D(type,type,130,0,130);
91 
93  //type = "Castor Pedestal Mean Reference Values - from CondDB";
94  //castHists.PEDESTAL_REFS = m_dbe->book1D(type,type,50,0,50);
95  //type = "Castor Pedestal RMS Reference Values - from CondDB";
96  //castHists.WIDTH_REFS = m_dbe->book1D(type,type,20,0,10);
102 
103  std::string s2 = "QIE_capID+er+dv";
104  std::string s3 = "qieError2D";
105  h2digierr = m_dbe->book2DD(s3,s2,16,0.5,16.5, 14,0.5,14.5);
106  }
107  else
108  {
109  if(fVerbosity>0) std::cout << "CastorDigiMonitor::setup - NO DQMStore service" << std::endl;
110  }
111 
112 
113  if(fVerbosity>0) std::cout << "CastorDigiMonitor::beginRun (end)" << std::endl;
114 
115  return;
116 }
117 
118 
119 //==================================================================//
120 //=========================== processEvent ========================//
121 //==================================================================//
123  {
124  if(fVerbosity>0) std::cout << "CastorDigiMonitor::processEvent (begin)"<< std::endl;
125 
126  if(!m_dbe) {
127  if(fVerbosity>0) std::cout<<"CastorDigiMonitor::processEvent DQMStore is not instantiated!!!"<<std::endl;
128  return;
129  }
130 
131  //if(!shape_) shape_ = cond.getCastorShape(); // this one is generic
132 
133  meEVT_->Fill(ievt_);
134 
135  CaloSamples tool;
136 
137  if(castorDigis.size()>0) {
138 
139  for (CastorDigiCollection::const_iterator j=castorDigis.begin(); j!=castorDigis.end(); j++){
140  const CastorDataFrame digi = (const CastorDataFrame)(*j);
141 
142 
143  detID_.clear(); capID_.clear(); pedVals_.clear();
144 
145 
147 
148  // const CastorCalibrations& calibrations = cond.getCastorCalibrations(digi.id().rawId());
149  // const CastorPedestal* ped = cond.getPedestal(digi.id());
150  // const CastorPedestalWidth* pedw = cond.getPedestalWidth(digi.id());
153  // const CastorPedestal* ped = cond.getPedestal(digi.id());
154  // const CastorPedestalWidth* pedw = cond.getPedestalWidth(digi.id());
155 
156  /*
158  if(doFCpeds_){
159  channelCoder_ = cond.getCastorCoder(digi.id());
160  CastorCoderDb coderDB(*channelCoder_, *shape_);
161  coderDB.adc2fC(digi,tool);
162  }
163 
164 
166  for(int capID=0; capID<4; capID++){
168  float pedvalue=0;
169  if(ped) pedvalue=ped->getValue(capID);
170  castHists.PEDESTAL_REFS->Fill(pedvalue);
171  PEDESTAL_REFS->Fill(pedvalue);
175  float width=0;
176  if(pedw) width = pedw->getWidth(capID);
177  castHists.WIDTH_REFS->Fill(width);
178  WIDTH_REFS->Fill(width);
179  }
180  */
181 
182 
184 
185  // if(ievt_ %1000 == 0 ) // PK: skip limited number of events
186  // {
187  for (int i=0; i<digi.size(); i++) {
188  if(doFCpeds_) pedVals_.push_back(tool[i]); // default is FALSE
189  else pedVals_.push_back(digi.sample(i).adc());
190  detID_.push_back(digi.id());
191  capID_.push_back(digi.sample(i).capid());
192  castHists.ALLPEDS->Fill(pedVals_[i]);
193  }
194 
195  // }
196 
198  // if( ievt_%100 == 0 && doPerChannel_) perChanHists(detID_,capID_,pedVals_,castHists.PEDVALS, baseFolder_);
199  if( doPerChannel_) perChanHists(detID_,capID_,pedVals_,castHists.PEDVALS, baseFolder_); // PK: no special event selection done
200  int capid1 = digi.sample(0).capid();
201  for (int i=1; i<digi.size(); i++) {
202  int module = digi.id().module();
203  int sector = digi.id().sector();
204  if(capid1 < 3) capid1++;
205  else capid1 = 0;
206  int capid = digi.sample(i).capid();
207  int dv = digi.sample(i).dv();
208  int er = digi.sample(i).er();
209  int err = (capid != capid1) | er<<1 | (!dv)<<2; // =0
210  if(err !=0) h2digierr->Fill(sector,module);
211 // if(err != 0 && fVerbosity>0)
212 // std::cout<<"event/idigi=" <<ievt_<<"/" <<i<< " cap_cap1_dv_er: " <<
213 // capid <<"="<< capid1 <<" "<< dv <<" "<< er<<" "<< err << std::endl;
214  capid1 = capid;
215  }
216  }
217  }
218  else {
219  if(fVerbosity>0) std::cout << "CastorPSMonitor::processEvent NO Castor Digis !!!" << std::endl;
220  }
221 
222  if (showTiming) {
223  cpu_timer.stop(); std::cout << " TIMER::CastorDigi -> " << cpu_timer.cpuTime() << std::endl;
225  }
226 
227  ievt_++;
228 
229  if(fVerbosity>0) std::cout << "CastorDigiMonitor::processEvent (end)"<< std::endl;
230 
231 
232  return;
233  }
234 
235 
236 //==================================================================//
237 //======================= done =====================================//
238 //==================================================================//
240 {
241  if(m_dbe!=NULL && h2digierr!=NULL)
242  {
243  if(fVerbosity>0)
244  {
245  long int hdigierrEntr = h2digierr->getEntries();
246  std::cout << "CastorDigiMonitor: capId,er,dv summary (entries=" << hdigierrEntr << "):" << std::endl;
247  }
248  }
249  else
250  edm::LogWarning("CastorDigiMonitor") << "DQMStore or histogram not available";
251 
252  return;
253 }
254 
255 
256 //==================================================================//
257 //======================= perChanHists ============================//
258 //==================================================================//
260 void CastorDigiMonitor::perChanHists( const std::vector<HcalCastorDetId>& detID, const std::vector<int>& capID, const std::vector<float>& peds,
261  std::map<HcalCastorDetId, std::map<int, MonitorElement*> > &toolP,
263  std::string baseFolder)
264  {
265 
266  if(m_dbe) m_dbe->setCurrentFolder(baseFolder);
267 
269  for(unsigned int d=0; d<detID.size(); d++){
270  HcalCastorDetId detid = detID[d];
271  int capid = capID[d];
272  float pedVal = peds[d];
274  bool gotit=false;
275  if(REG[detid]) gotit=true;
276 
277  if(gotit){
279  std::map<int, MonitorElement*> _mei = toolP[detid];
280  if(_mei[capid]==NULL){
281  if(fVerbosity>0) std::cout<<"CastorDigiMonitor::perChanHists This histo is NULL!!??"<< std::endl;
282  }
283  else _mei[capid]->Fill(pedVal);
284 
290  }
291  else{
292  if(m_dbe){
293  std::map<int,MonitorElement*> insertP; //-- Pedestal values in ADC
295 
297  for(int i=0; i<4; i++){
298  char name[1024];
299  sprintf(name,"Castor Digi Value (ADC) zside=%d module=%d sector=%d CAPID=%d",
300  detid.zside(),detid.module(),detid.sector(),i);
301  insertP[i] = m_dbe->book1D(name,name,10,-0.5,9.5);
302 
306  }
307 
308  insertP[capid]->Fill(pedVal);
310  toolP[detid] = insertP;
312  }
313  REG[detid] = true;
314  }
315  }
316 }
317 
type
Definition: HCALResponse.h:21
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
edm::CPUTimer cpu_timer
virtual void setup(const edm::ParameterSet &ps, DQMStore *dbe)
void start()
Definition: CPUTimer.cc:74
int sector() const
get the sector (1-16)
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:954
void setup(const edm::ParameterSet &ps, DQMStore *dbe)
MonitorElement * book2DD(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D double histogram.
Definition: DQMStore.cc:1126
int adc() const
get the ADC sample
Definition: HcalQIESample.h:22
const HcalQIESample & sample(int i) const
access a sample
std::vector< CastorDataFrame >::const_iterator const_iterator
bool dv() const
is the Data Valid bit set?
Definition: HcalQIESample.h:28
void reset()
Definition: CPUTimer.cc:107
#define NULL
Definition: scimark2.h:8
int module() const
get the module (1-2 for EM, 1-12 for HAD)
double getEntries(void) const
get # of entries
void perChanHists(const std::vector< HcalCastorDetId > &detID, const std::vector< int > &capID, const std::vector< float > &peds, std::map< HcalCastorDetId, std::map< int, MonitorElement * > > &toolP, std::string baseFolder)
tuple s2
Definition: indexGen.py:106
struct CastorDigiMonitor::@274 castHists
void Fill(long long x)
MonitorElement * h2digierr
std::string baseFolder_
int j
Definition: DBlmapReader.cc:9
MonitorElement * meEVT_
Times stop()
Definition: CPUTimer.cc:94
const_iterator end() const
void beginRun(const edm::EventSetup &iSetup)
double cpuTime() const
Definition: CPUTimer.cc:158
int capid() const
get the Capacitor id
Definition: HcalQIESample.h:26
std::vector< float > pedVals_
std::vector< HcalCastorDetId > detID_
size_type size() const
std::vector< int > capID_
void processEvent(const CastorDigiCollection &cast, const CastorDbService &cond)
std::string rootFolder_
std::string outputFile_
tuple cout
Definition: gather_cfg.py:121
const HcalCastorDetId & id() const
MonitorElement * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:861
int size() const
total number of samples in the digi
Definition: vlib.h:208
bool er() const
is the error bit set?
Definition: HcalQIESample.h:30
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:667
std::map< HcalCastorDetId, bool > REG
const_iterator begin() const