CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CastorPSMonitor.cc
Go to the documentation of this file.
4 
10 
24 
29 
32 
35 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" //-- CastorRecHitCollection
36 
37 //***************************************************//
38 //********** CastorPSMonitor: *******************//
39 //********** Author: D.Volyanskyy/I.Katkov *********//
40 //********** Date : 03.03.2010 (first version) ******//
41 //***************************************************//
45 
46 
47 //==================================================================//
48 //======================= Constructor ==============================//
49 //==================================================================//
51  doPerChannel_ = true;
52  ievt_=0;
55  status=-99;
56  statusRS=-99;
57  statusSaturated=-99;
58 }
59 
60 //==================================================================//
61 //======================= Destructor ==============================//
62 //==================================================================//
64 }
65 
67  {
68 
69  }
70 
71 //==========================================================//
72 //========================= setup ==========================//
73 //==========================================================//
74 
76 
78  baseFolder_ = rootFolder_+"CastorPSMonitor";
79 
81  numberSigma_ = ps.getUntrackedParameter<double>("numberSigma", 1.5);
82  thirdRegionThreshold_ = ps.getUntrackedParameter<double>("thirdRegionThreshold", 300);
83  saturatedThreshold_ = ps.getUntrackedParameter<double>("saturatedThreshold", 0.05); //-- fraction of events in which chargeTS > 127 ADC
84  offline_ = ps.getUntrackedParameter<bool>("OfflineMode", false);
85 
86  if(fVerbosity>0) std::cout << "CastorPSMonitor::setup (start)" << std::endl;
87 
88  ievt_=0; firstTime_ = true;
91  numOK = 0;
92  fraction=0.;
93 
95  for (int row=0; row<14; row++){
96  for (int col=0; col<16; col++){
97  sumDigiForEachChannel[row][col] = 0;
98  saturatedMap [row][col] = 0;
99  }
100  }
101 
102 
103 
104  if(fVerbosity>0) std::cout << "CastorPSMonitor::setup (end)" << std::endl;
105 
106  return;
107 }
108 
109 
110 //=================================================================//
111 //========================== beginRun =============================//
112 //================================================================//
113 void CastorPSMonitor::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
114  {
115  if(fVerbosity>0) std::cout << "CastorPSMonitor::beginRun (start)" << std::endl;
116 
117  if ( m_dbe !=NULL )
118  {
120 
122  meEvt_ = m_dbe->bookInt("PS Event Number");
123  castorDigiHists.meDigi_pulseBX = m_dbe->book1D("CASTOR average pulse in bunch crossings","CASTOR average pulse in bunch crossings", 3600, -0.5, 3600);
124  TH1F* h_meDigi_pulseBX = castorDigiHists.meDigi_pulseBX->getTH1F();
125  h_meDigi_pulseBX->GetXaxis()->SetTitle("orbit");
126 
127  //---- Pulse Shape per sector
128  char name[1024];
129  for(int i=0; i<16; i++)
130  {
131  sprintf(name,"Castor Pulse Shape for sector=%d (in all 14 modules)",i+1);
132  PSsector[i] = m_dbe->book1D(name,name,140,-0.5,139.5);
133  }
134 
136  DigiOccupancyMap = m_dbe->book2D("CASTOR Digi Occupancy Map","CASTOR Digi Occupancy Map",14,0.0,14.0,16,0.0,16.0);
138  ChannelSummaryMap = m_dbe->book2D("CASTOR Digi ChannelSummaryMap","CASTOR Digi ChannelSummaryMap",14,0.0,14.0,20,0.0,20.0); // put 20 instead of 16 to get some space for the legend
139 
142  SaturationSummaryMap = m_dbe->book2D("CASTOR Digi SaturationSummaryMap","CASTOR Digi SaturationSummaryMap",14,0.0,14.0,20,0.0,20.0); // put 20 instead of 16 to get some space for the legend
143 
144 
145 
147  m_dbe->setCurrentFolder(rootFolder_+"EventInfo"); //this is saved in the EventInfo folder so it can appear in the main page of the DQM
148  reportSummary = m_dbe->bookFloat("reportSummary");
149  reportSummaryMap = m_dbe->book2D("reportSummaryMap","CASTOR reportSummaryMap",14,0.0,14.0,16,0.0,16.0);
150  if(offline_){
152  h_reportSummaryMap->SetOption("textcolz");
153  h_reportSummaryMap->GetXaxis()->SetTitle("module");
154  h_reportSummaryMap->GetYaxis()->SetTitle("sector");
155  }
156  m_dbe->setCurrentFolder(rootFolder_+"EventInfo/reportSummaryContents"); //this is saved in the EventInfo folder so it can appear in the main page of the DQM
157  overallStatus = m_dbe->bookFloat("fraction of good channels");
159  }
160 
161  else
162  {
163  if(fVerbosity>0) std::cout << "CastorPSMonitor::beginRun - NO DQMStore service" << std::endl;
164  }
165 
166  if(fVerbosity>0) std::cout << "CastorPSMonitor::beginRun (end)" << std::endl;
167  }
168 
169 //==========================================================//
170 //================== processEvent ==========================//
171 //==========================================================//
172 
173 void CastorPSMonitor::processEvent(const CastorDigiCollection& castorDigis, const CastorDbService& conditions, const std::vector<HcalGenericDetId>& listEMap, int iBunch, float PedSigmaInChannel[14][16])
174  {
175  if(fVerbosity>0) std::cout << "CastorPSMonitor::processEvent (begin)" << std::endl;
176 
177  if(!m_dbe) {
178  if(fVerbosity>0) std::cout <<"CastorPSMonitor::processEvent => DQMStore not instantiated !!!"<<std::endl;
179  return;
180  }
181 
182  meEvt_->Fill(ievt_);
183 
185  ievt_++;
186 
187  status = -99; statusRS = -99; statusSaturated=-99;
188 
190  const CastorQIEShape* shape = conditions.getCastorShape();
191 
192  if(firstTime_)
193  {
194  //===> show the array of sigmas
195  for (int i=0; i<14; i++){
196  for (int k=0; k<16; k++){
197  if(fVerbosity>1) std::cout<< "module:"<<i+1<< " sector:"<<k+1<< " Sigma=" << PedSigmaInChannel[i][k] << std::endl;
198  }
199  }
200  for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++)
201  {
202  HcalGenericDetId mygenid(it->rawId());
203  if(mygenid.isHcalCastorDetId())
204  {
205  NewBunch myBunch;
206  HcalCastorDetId chanid(mygenid.rawId());
207  myBunch.detid = chanid;
208  myBunch.usedflag = false;
210  type = "CASTOR";
211  for(int i = 0; i != 20; i++)
212  {
213  myBunch.tsCapId[i] = 0;
214  myBunch.tsAdc[i] = 0;
215  myBunch.tsfC[i] = 0.0;
216  }
217  Bunches_.push_back(myBunch);
218  }
219  }
220 
221  firstTime_ = false;
222  }
223 
224 
225  if(castorDigis.size()>0) {
227  int firstTS = 0;
228  int lastTS = 9;
229  std::vector<NewBunch>::iterator bunch_it;
230  int numBunches = 0;
231  bool firstDigi = true;
232  bool saturated = false;
233 
235  for(CastorDigiCollection::const_iterator j = castorDigis.begin(); j != castorDigis.end(); j++)
236  {
237 
238  const CastorDataFrame digi = (const CastorDataFrame)(*j);
239  if ( lastTS+1 > digi.size() ) lastTS = digi.size()-1;
240  for(bunch_it = Bunches_.begin(); bunch_it != Bunches_.end(); bunch_it++)
241  if(bunch_it->detid.rawId() == digi.id().rawId()) break;
242  bunch_it->usedflag = true;
243 
244  numBunches++;
245  //
246  //---- Skip noisy channels present in 2009 beam data:
247  // if ( (bunch_it->detid.sector() == 16 && bunch_it->detid.module() == 6) ||
248  // (bunch_it->detid.sector() == 3 && bunch_it->detid.module() == 8) ||
249  // (bunch_it->detid.sector() == 8 && bunch_it->detid.module() == 8) ) continue;
250  //
251 
252  if ( lastTS+1 > digi.size() ) lastTS = digi.size()-1;
253 
255  const CastorCalibrations& calibrations=conditions.getCastorCalibrations(digi.id().rawId());
256 
258  double sumDigi=0.; double sumDigiADC=0.; int bxTS=-9999; saturated = false;
259 
261  for(int ts = firstTS; ts != lastTS+1; ts++)
262  {
263  if (firstDigi) {
264  bxTS = (iBunch+ts-1-digi.presamples());
265  if ( bxTS < 0 ) bxTS += 3563;
266  bxTS = ( bxTS % 3563 ) + 1;
267  if(fVerbosity>1) std::cout << "!!! " << bxTS << " " << iBunch <<" "<< ts << " " << digi.presamples() << std::endl;
268  }
269 
270  const CastorQIECoder* coder = conditions.getCastorCoder(digi.id().rawId());
271  bunch_it->tsCapId[ts] = digi.sample(ts).capid();
272  bunch_it->tsAdc[ts] = digi.sample(ts).adc();
273 
275  double charge_fC = coder->charge(*shape, digi.sample(ts).adc(), digi.sample(ts).capid());
276 
278  bunch_it->tsfC[ts] = charge_fC - calibrations.pedestal(digi.sample(ts).capid());
280  castorDigiHists.meDigi_pulseBX->Fill(static_cast<double>(bxTS),(bunch_it->tsfC[ts])/224.);
282 
283  // PK: do not normalize histograms - now it is normalized
284  PSsector[bunch_it->detid.sector()-1]->Fill(10*(bunch_it->detid.module()-1)+ts, bunch_it->tsfC[ts]/double(ievt_));
285  // PSsector[bunch_it->detid.sector()-1]->Fill(10*(bunch_it->detid.module()-1)+ts, bunch_it->tsfC[ts]);
286 
288  sumDigi += bunch_it->tsfC[ts]; //std::cout<< " signal(fC) in TS:"<<ts << " =" << bunch_it->tsfC[ts] << std::endl;
290  sumDigiADC += bunch_it->tsAdc[ts]; //std::cout<< " signal(ADC) in TS:"<<ts << " =" << bunch_it->tsAdc[ts] << std::endl;
291 
293  if(bunch_it->tsAdc[ts]>126.95) {
294  saturated = true;
295  if(fVerbosity>1)
296  std::cout<< "WARNING: ==> Module:" << bunch_it->detid.module() << " Sector:" << bunch_it->detid.sector() << " SATURATED !!! in TS:"<< ts <<std::endl;
297  }
298 
299  } //-- end of the loop for time slices
300 
302  sumDigiForEachChannel[bunch_it->detid.module()-1][bunch_it->detid.sector()-1] += sumDigi;
303 
305  if(saturated) saturatedMap[bunch_it->detid.module()-1][bunch_it->detid.sector()-1] += 1;
306 
308  DigiOccupancyMap->Fill(bunch_it->detid.module()-1,bunch_it->detid.sector()-1, double(sumDigi/10)); //std::cout<< "=====> sumDigi=" << sumDigi << std::endl;
309 
310 
311  if(fVerbosity>1){
312  std::cout<< "==> Module:" << bunch_it->detid.module() << " Sector:" << bunch_it->detid.sector() << std::endl;
313  std::cout<< "==> Total charge in fC:" << sumDigi << std::endl;
314  std::cout<< "==> Total charge in ADC:" << sumDigiADC << std::endl;
315  }
316 
317  firstDigi = false;
318  } //-- end of the loop over digis
319 
320 
321 
322 
323 
327 
328 
329  // if( ievt_ == 25 || ievt_ % 500 == 0 ) { // no event selection - get all events
330 
331  numOK = 0;
332 
334  for (int sector=0; sector<16; sector++){
335  for (int module=0; module<14; module++){
336 
338  firstRegionThreshold_ = (-1)*(numberSigma_*PedSigmaInChannel[module][sector]);
339  secondRegionThreshold_ = numberSigma_*PedSigmaInChannel[module][sector] ;
340 
341 
343  if(double(sumDigiForEachChannel[module][sector]/(10*ievt_)) < firstRegionThreshold_ )
344  { status = -1.; statusRS=0.; }
345 
348  { status = 0.25; statusRS=0.95; }
349 
352  { status = 1.; statusRS=1.0; }
353 
354  //---- leave it out for the time being
356  // if(double(sumDigiForEachChannel[module][sector]/(10*ievt_)) > thirdRegionThreshold_ )
357  // { status = -0.25; statusRS=0.88 ; }
358 
359  //-- define the fraction of saturated events for a particular channel
360  double fractionSaturated = double(saturatedMap[module][sector])/double(ievt_) ;
362  if(fVerbosity>1) std::cout<< "==> module: " << module << " sector: " << sector << " ==> N_saturation:" << saturatedMap[module][sector] << " events:"<< ievt_ << " fraction:" << fractionSaturated << std::endl;
363 
364  if( fractionSaturated > saturatedThreshold_ )
365  { status = -0.25; statusRS=0.88 ; statusSaturated=-1.0; }
366 
368  if( saturatedMap[module][sector] > 0 && fractionSaturated < saturatedThreshold_ )
369  { statusSaturated= 0; }
370 
372  if( saturatedMap[module][sector] == 0 )
373  { statusSaturated= 1; }
374 
376  ChannelSummaryMap->getTH2F()->SetBinContent(module+1,sector+1,status);
377 
379  reportSummaryMap->getTH2F()->SetBinContent(module+1,sector+1,statusRS);
380 
382  SaturationSummaryMap->getTH2F()->SetBinContent(module+1,sector+1,double(statusSaturated));
383 
385  if ( statusRS > 0.9) numOK++;
386 
387  } //-- end of the loop over the modules
388  } //-- end of the loop over the sectors
389 
391  fraction=double(numOK)/224;
393 
394  // } //-- end of if for the number of events // update ( PK ):
395 
396 
398  for (int sector=16; sector<20; sector++){
399  for (int module=0; module<14; module++){
400  ChannelSummaryMap->getTH2F()->SetBinContent(module+1,sector+1,99);
401  }
402  }
404  for (int sector=16; sector<20; sector++){
405  for (int module=0; module<14; module++){
406  SaturationSummaryMap->getTH2F()->SetBinContent(module+1,sector+1, 99);
407  }
408  }
409 
410 
411 
412 
413 
414  } //-- end of the if castDigi
415 
416  else { if(fVerbosity>0) std::cout<<"CastorPSMonitor::processEvent NO Castor Digis !!!"<<std::endl; }
417 
418 
419  if (showTiming) {
420  cpu_timer.stop(); std::cout << " TIMER::CastorPS -> " << cpu_timer.cpuTime() << std::endl;
422  }
423 
424  if(fVerbosity>0) std::cout << "CastorPSMonitor::processEvent (end)" << std::endl;
425 
426  return;
427  }
type
Definition: HCALResponse.h:21
std::vector< NewBunch > Bunches_
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
TH2F * h_reportSummaryMap
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:971
int presamples() const
number of samples before the sample from the triggered beam crossing (according to the hardware) ...
MonitorElement * SaturationSummaryMap
void processEvent(const CastorDigiCollection &castorDigis, const CastorDbService &conditions, const std::vector< HcalGenericDetId > &listEMap, int iBunch, float PedSigmaInChannel[14][16])
MonitorElement * DigiOccupancyMap
int adc() const
get the ADC sample
Definition: HcalQIESample.h:22
const HcalQIESample & sample(int i) const
access a sample
MonitorElement * meEvt_
std::vector< CastorDataFrame >::const_iterator const_iterator
void beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup)
const CastorCalibrations & getCastorCalibrations(const HcalGenericDetId &fId) const
double tsfC[20]
Definition: CastorBunch.h:13
void reset()
Definition: CPUTimer.cc:107
#define NULL
Definition: scimark2.h:8
MonitorElement * reportSummary
MonitorElement * bookFloat(const char *name)
Book float.
Definition: DQMStore.cc:908
void Fill(long long x)
HcalCastorDetId detid
Definition: CastorBunch.h:8
double sumDigiForEachChannel[14][16]
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
std::string baseFolder_
double saturatedThreshold_
int saturatedMap[14][16]
const CastorQIEShape * getCastorShape() const
float charge(const CastorQIEShape &fShape, unsigned fAdc, unsigned fCapId) const
ADC [0..127] + capid [0..3] -&gt; fC conversion.
double thirdRegionThreshold_
int j
Definition: DBlmapReader.cc:9
void setup(const edm::ParameterSet &ps, DQMStore *dbe)
double tsCapId[20]
Definition: CastorBunch.h:10
MonitorElement * ChannelSummaryMap
bool usedflag
Definition: CastorBunch.h:9
Times stop()
Definition: CPUTimer.cc:94
double secondRegionThreshold_
double pedestal(int fCapId) const
get pedestal for capid=0..3
const_iterator end() const
double cpuTime() const
Definition: CPUTimer.cc:158
struct CastorPSMonitor::@279 castorDigiHists
int capid() const
get the Capacitor id
Definition: HcalQIESample.h:26
double firstRegionThreshold_
MonitorElement * reportSummaryMap
size_type size() const
double tsAdc[20]
Definition: CastorBunch.h:11
std::string rootFolder_
tuple cout
Definition: gather_cfg.py:121
MonitorElement * overallStatus
std::map< int, MonitorElement * > PSsector
TH2F * getTH2F(void) const
const HcalCastorDetId & id() const
MonitorElement * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:878
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1099
int col
Definition: cuy.py:1008
int size() const
total number of samples in the digi
Definition: vlib.h:208
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:684
const_iterator begin() const
Definition: Run.h:41
const CastorQIECoder * getCastorCoder(const HcalGenericDetId &fId) const