CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RPCOccupancyTest.cc
Go to the documentation of this file.
1 /* \author Anna Cimmino*/
2 //#include <cmath>
3 #include <sstream>
6 
7 // Framework
9 //Geometry
11 
13  edm::LogVerbatim ("rpceventsummary") << "[RPCOccupancyTest]: Constructor";
14 
15  prescaleFactor_ = ps.getUntrackedParameter<int>("DiagnosticPrescale", 1);
16  numberOfDisks_ = ps.getUntrackedParameter<int>("NumberOfEndcapDisks", 4);
17  numberOfRings_ = ps.getUntrackedParameter<int>("NumberOfEndcapRings", 2);
18  testMode_ = ps.getUntrackedParameter<bool>("testMode", false);
19  useRollInfo_ = ps.getUntrackedParameter<bool>("useRollInfo_", false);
20 
21  std::string subsystemFolder = ps.getUntrackedParameter<std::string>("RPCFolder", "RPC");
22  std::string recHitTypeFolder= ps.getUntrackedParameter<std::string>("RecHitTypeFolder", "AllHits");
23 
24  prefixDir_ = subsystemFolder+ "/"+ recHitTypeFolder;
25 
26 }
27 
29  dbe_=0;
30 }
31 
32 void RPCOccupancyTest::beginJob(DQMStore * dbe, std::string workingFolder){
33  edm::LogVerbatim ("rpceventsummary") << "[RPCOccupancyTest]: Begin job ";
34  globalFolder_ = workingFolder;
35  dbe_=dbe;
36 }
37 
39  edm::LogVerbatim ("rpceventsummary") << "[RPCOccupancyTest]: End run";
40  }
41 
42 void RPCOccupancyTest::getMonitorElements(std::vector<MonitorElement *> & meVector, std::vector<RPCDetId> & detIdVector){
43 
44  //Get Occupancy ME for each roll
45  for (unsigned int i = 0 ; i<meVector.size(); i++){
46 
47  bool flag= false;
48 
49  DQMNet::TagList tagList;
50  tagList = meVector[i]->getTags();
51  DQMNet::TagList::iterator tagItr = tagList.begin();
52 
53  while (tagItr != tagList.end() && !flag ) {
54  if((*tagItr) == rpcdqm::OCCUPANCY)
55  flag= true;
56  tagItr++;
57  }
58 
59  if(flag){
60  myOccupancyMe_.push_back(meVector[i]);
61  myDetIds_.push_back(detIdVector[i]);
62  }
63  }
64 }
65 
67 
69 
71 
73 
74  edm::LogVerbatim ("rpceventsummary") <<"[RPCOccupancyTest]: Client Operation";
75 
76  MonitorElement * RPCEvents = dbe_->get(prefixDir_ +"/RPCEvents");
77  if(RPCEvents == 0 ){rpcevents_ = 0;}
78  else{
79  rpcevents_ = RPCEvents ->getBinContent(1);
80  }
81 
82  //Loop on MEs
83  for (unsigned int i = 0 ; i<myOccupancyMe_.size();i++){
85  }//End loop on MEs
86 }
87 
90 
91  MonitorElement* me;
93 
94  std::stringstream histoName;
95  rpcdqm::utils rpcUtils;
96 
97  histoName.str("");
98  histoName<<"Barrel_OccupancyByStations_Normalized";
99  me = dbe_->get( globalFolder_+"/"+ histoName.str());
100  if ( 0!=me ) {
101  dbe_->removeElement(me->getName());
102  }
103  Barrel_OccBySt = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 4, 0.5, 4.5);
104  Barrel_OccBySt -> setBinLabel(1, "St1", 1);
105  Barrel_OccBySt -> setBinLabel(2, "St2", 1);
106  Barrel_OccBySt -> setBinLabel(3, "St3", 1);
107  Barrel_OccBySt -> setBinLabel(4, "St4", 1);
108 
109 
110  histoName.str("");
111  histoName<<"EndCap_OccupancyByRings_Normalized";
112  me = dbe_->get( globalFolder_+"/"+ histoName.str());
113  if ( 0!=me ) {
114  dbe_->removeElement(me->getName());
115  }
116  EndCap_OccByRng = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 4, 0.5, 4.5);
117  EndCap_OccByRng -> setBinLabel(1, "E+/R3", 1);
118  EndCap_OccByRng -> setBinLabel(2, "E+/R2", 1);
119  EndCap_OccByRng -> setBinLabel(3, "E-/R2", 1);
120  EndCap_OccByRng -> setBinLabel(4, "E-/R3", 1);
121 
122 // histoName.str("");
123 // histoName<<"EndCap_OccupancyByDisksAndRings_Normalized";
124 // me = dbe_->get( globalFolder_+"/"+ histoName.str());
125 // if ( 0!=me ) {
126 // dbe_->removeElement(me->getName());
127 // }
128 // EndCap_OccByDisk = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 12, 0, 12);
129 // EndCap_OccByDisk -> setBinLabel(1, "YE-3/R2", 1);
130 // EndCap_OccByDisk -> setBinLabel(2, "YE-2/R2", 1);
131 // EndCap_OccByDisk -> setBinLabel(3, "YE-1/R2", 1);
132 // EndCap_OccByDisk -> setBinLabel(4, "YE+1/R2", 1);
133 // EndCap_OccByDisk -> setBinLabel(5, "YE+2/R2", 1);
134 // EndCap_OccByDisk -> setBinLabel(6, "YE+3/R2", 1);
135 
136 // EndCap_OccByDisk -> setBinLabel(7, "YE-3/R3", 1);
137 // EndCap_OccByDisk -> setBinLabel(8, "YE-2/R3", 1);
138 // EndCap_OccByDisk -> setBinLabel(9, "YE-1/R3", 1);
139 // EndCap_OccByDisk -> setBinLabel(10, "YE+1/R3", 1);
140 // EndCap_OccByDisk -> setBinLabel(11, "YE+2/R3", 1);
141 // EndCap_OccByDisk -> setBinLabel(12, "YE+3/R3", 1);
142 
143  for (int w = -2; w<=2; w++ ){//loop on wheels
144 
145  histoName.str("");
146  histoName<<"AsymmetryLeftRight_Roll_vs_Sector_Wheel"<<w;
147  me = 0;
148  me = dbe_->get( globalFolder_+"/"+ histoName.str());
149  if ( 0!=me ) {
150  dbe_->removeElement(me->getName());
151  }
152 
153  AsyMeWheel[w+2] = dbe_->book2D(histoName.str().c_str(), histoName.str().c_str(), 12, 0.5, 12.5, 21, 0.5, 21.5);
154 
155  rpcUtils.labelXAxisSector(AsyMeWheel[w+2]);
156  rpcUtils.labelYAxisRoll(AsyMeWheel[w+2], 0, w, useRollInfo_);
157 
158 
159  if(testMode_){
160 
161  histoName.str("");
162  histoName<<"OccupancyNormByEvents_Wheel"<<w;
163  me = 0;
164  me = dbe_->get( globalFolder_+"/"+ histoName.str());
165  if ( 0!=me ) {
166  dbe_->removeElement(me->getName());
167  }
168 
169  NormOccupWheel[w+2] = dbe_->book2D(histoName.str().c_str(), histoName.str().c_str(), 12, 0.5, 12.5, 21, 0.5, 21.5);
170 
171  rpcUtils.labelXAxisSector( NormOccupWheel[w+2]);
172  rpcUtils.labelYAxisRoll( NormOccupWheel[w+2], 0, w, useRollInfo_);
173 
174 
175  histoName.str("");
176  histoName<<"AsymmetryLeftRight_Distribution_Wheel"<<w;
177  me = 0;
178  me = dbe_->get( globalFolder_+"/"+ histoName.str());
179  if ( 0!=me ) {
180  dbe_->removeElement(me->getName());
181  }
182  AsyMeDWheel[w+2] = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 20, -0.1, 1.1);
183 
184  histoName.str("");
185  histoName<<"OccupancyNormByEvents_Distribution_Wheel"<<w;
186  me = 0;
187  me = dbe_->get( globalFolder_+"/"+ histoName.str());
188  if ( 0!=me ) {
189  dbe_->removeElement(me->getName());
190  }
191  NormOccupDWheel[w+2] = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 100, 0.0, 0.205);
192  }
193  }//end Barrel
194 
195  for(int d = -numberOfDisks_; d<=numberOfDisks_; d++ ){
196 
197  if (d == 0)continue;
198 
199  int offset = numberOfDisks_;
200  if (d>0) offset --; //used to skip case equale to zero
201 
202  histoName.str("");
203  histoName<<"AsymmetryLeftRight_Ring_vs_Segment_Disk"<<d;
204  me = 0;
205  me = dbe_->get( globalFolder_+"/"+ histoName.str());
206  if ( 0!=me ) {
207  dbe_->removeElement(me->getName());
208  }
209 
210  AsyMeDisk[d+offset] = dbe_->book2D(histoName.str().c_str(), histoName.str().c_str(), 36, 0.5, 36.5, 3*numberOfRings_, 0.5,3*numberOfRings_+ 0.5);
211 
212  rpcUtils.labelXAxisSegment(AsyMeDisk[d+offset]);
213  rpcUtils.labelYAxisRing(AsyMeDisk[d+offset], numberOfRings_, useRollInfo_);
214 
215 
216 
217  if(testMode_){
218 
219  histoName.str("");
220  histoName<<"OccupancyNormByEvents_Disk"<<d;
221  me = 0;
222  me = dbe_->get( globalFolder_+"/"+ histoName.str());
223  if ( 0!=me ) {
224  dbe_->removeElement(me->getName());
225  }
226 
227  NormOccupDisk[d+offset] = dbe_->book2D(histoName.str().c_str(), histoName.str().c_str(), 36, 0.5, 36.5, 3*numberOfRings_, 0.5,3*numberOfRings_+ 0.5);
228 
229  rpcUtils.labelXAxisSegment(NormOccupDisk[d+offset]);
231 
232  histoName.str("");
233  histoName<<"AsymmetryLeftRight_Distribution_Disk"<<d;
234  me = 0;
235  me = dbe_->get( globalFolder_+"/"+ histoName.str());
236  if ( 0!=me ) {
237  dbe_->removeElement(me->getName());
238  }
239  AsyMeDDisk[d+offset] = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 20, -0.1, 1.1);
240 
241 
242 
243  histoName.str("");
244  histoName<<"OccupancyNormByEvents_Distribution_Disk"<<d;
245  me = 0;
246  me = dbe_->get( globalFolder_+"/"+ histoName.str());
247  if ( 0!=me ) {
248  dbe_->removeElement(me->getName());
249  }
250  NormOccupDDisk[d+offset] = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(), 100, 0.0, 0.205);
251  }
252  }//End loop on Endcap
253 }
254 
255 
257 
258 
259 if (!myMe) return;
260 
261  MonitorElement * AsyMe=NULL; //Left Right Asymetry
262  MonitorElement * AsyMeD=NULL;
263  MonitorElement * NormOccup=NULL;
264  MonitorElement * NormOccupD=NULL;
265 
266  if(detId.region() ==0){
267  AsyMe= AsyMeWheel[detId.ring()+2];
268  if(testMode_){
269  NormOccup=NormOccupWheel[detId.ring()+2];
270  AsyMeD= AsyMeDWheel[detId.ring()+2];
271  NormOccupD=NormOccupDWheel[detId.ring()+2];
272  }
273 
274  }else{
275 
276  if( -detId.station() + numberOfDisks_ >= 0 ){
277 
278  if(detId.region()<0){
279  AsyMe= AsyMeDisk[-detId.station() + numberOfDisks_];
280  if(testMode_){
281  NormOccup=NormOccupDisk[-detId.station() + numberOfDisks_];
282  AsyMeD= AsyMeDDisk[-detId.station() + numberOfDisks_];
283  NormOccupD=NormOccupDDisk[-detId.station() + numberOfDisks_];
284  }
285  }else{
286  AsyMe= AsyMeDisk[detId.station() + numberOfDisks_-1];
287  if(testMode_){
288  NormOccup=NormOccupDisk[detId.station() + numberOfDisks_-1];
289  AsyMeD= AsyMeDDisk[detId.station() + numberOfDisks_-1];
290  NormOccupD=NormOccupDDisk[detId.station() + numberOfDisks_-1];
291  }
292  }
293  }
294  }
295 
296 
297  int xBin,yBin;
298  if(detId.region()==0){//Barrel
299  xBin= detId.sector();
300  rpcdqm::utils rollNumber;
301  yBin = rollNumber.detId2RollNr(detId);
302  }else{//Endcap
303  //get segment number
304  RPCGeomServ RPCServ(detId);
305  xBin = RPCServ.segment();
306  (numberOfRings_ == 3 ? yBin= detId.ring()*3-detId.roll()+1 : yBin= (detId.ring()-1)*3-detId.roll()+1);
307  }
308 
309 
310  int stripInRoll=myMe->getNbinsX();
311  float FOccupancy=0;
312  float BOccupancy=0;
313 
314  float totEnt = myMe->getEntries();
315  for(int strip = 1 ; strip<=stripInRoll; strip++){
316  if(strip<=stripInRoll/2) FOccupancy+=myMe->getBinContent(strip);
317  else BOccupancy+=myMe->getBinContent(strip);
318  }
319 
320 
321  float asym = 0;
322  if(totEnt != 0 ) asym = fabs((FOccupancy - BOccupancy )/totEnt);
323 
324  if(AsyMe) AsyMe->setBinContent(xBin,yBin,asym);
325 
326 
327 
328  float normoccup = 1;
329  if(rpcevents_ != 0) normoccup = (totEnt/rpcevents_);
330 
331  if(testMode_){
332  if(NormOccup) NormOccup->setBinContent(xBin,yBin, normoccup);
333  if(AsyMeD) AsyMeD->Fill(asym);
334  if(NormOccupD) NormOccupD->Fill(normoccup);
335  }
336 
337 
338  if(detId.region()==0) {
339  if(Barrel_OccBySt)Barrel_OccBySt -> Fill(detId.station(), normoccup);
340  }else if(detId.region()==1) {
341  if(detId.ring()==3) {
342  EndCap_OccByRng -> Fill(1, normoccup);
343  } else {
344  EndCap_OccByRng -> Fill(2, normoccup);
345  }
346  } else {
347  if(detId.ring()==3) {
348  EndCap_OccByRng -> Fill(4, normoccup);
349  }else {
350  EndCap_OccByRng -> Fill(3, normoccup);
351  }
352  }
353 
354 }
355 
356 
357 
358 
359 
T getUntrackedParameter(std::string const &, T const &) const
const std::string & getName(void) const
get name of ME
int i
Definition: DBlmapReader.cc:9
void setBinContent(int binx, double content)
set content of bin (1-D)
MonitorElement * AsyMeWheel[5]
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:954
tuple yBin
Definition: cuy.py:891
MonitorElement * NormOccupDDisk[10]
void beginJob(DQMStore *, std::string)
void beginRun(const edm::Run &, const edm::EventSetup &)
void labelXAxisSegment(MonitorElement *myMe)
Definition: utils.h:250
MonitorElement * EndCap_OccByRng
void labelYAxisRoll(MonitorElement *myMe, int region, int ring, bool useRollInfo)
Definition: utils.h:268
void getMonitorElements(std::vector< MonitorElement * > &, std::vector< RPCDetId > &)
#define NULL
Definition: scimark2.h:8
double getEntries(void) const
get # of entries
void endRun(const edm::Run &, const edm::EventSetup &)
std::vector< RPCDetId > myDetIds_
void Fill(long long x)
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &c)
MonitorElement * NormOccupDWheel[5]
MonitorElement * Barrel_OccBySt
virtual ~RPCOccupancyTest()
int iEvent
Definition: GenABIO.cc:230
void labelYAxisRing(MonitorElement *myMe, int numberOfRings, bool useRollInfo)
Definition: utils.h:295
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &context)
int roll() const
Definition: RPCDetId.h:120
MonitorElement * NormOccupWheel[5]
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
int ring() const
Definition: RPCDetId.h:72
void removeElement(const std::string &name)
Definition: DQMStore.cc:3143
MonitorElement * AsyMeDisk[10]
std::string globalFolder_
unsigned int offset(bool)
void clientOperation(edm::EventSetup const &c)
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1708
void labelXAxisSector(MonitorElement *myMe)
Definition: utils.h:236
void fillGlobalME(RPCDetId &, MonitorElement *)
virtual int segment()
Definition: RPCGeomServ.cc:467
int detId2RollNr(const RPCDetId &_id)
Definition: utils.h:18
std::vector< uint32_t > TagList
Definition: DQMNet.h:84
MonitorElement * AsyMeDDisk[10]
int sector() const
Sector id: the group of chambers at same phi (and increasing r)
Definition: RPCDetId.h:102
std::string prefixDir_
RPCOccupancyTest(const edm::ParameterSet &ps)
double getBinContent(int binx) const
get content of bin (1-D)
void analyze(const edm::Event &iEvent, const edm::EventSetup &c)
int getNbinsX(void) const
get # of bins in X-axis
std::vector< MonitorElement * > myOccupancyMe_
T w() const
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:1082
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:667
Definition: Run.h:41
MonitorElement * NormOccupDisk[10]
MonitorElement * AsyMeDWheel[5]
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63
int station() const
Definition: RPCDetId.h:96