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