CMS 3D CMS Logo

RPCEfficiencySecond.cc
Go to the documentation of this file.
1 /***************************************
2 Original Author:Camilo Carrillo
3 ****************************************/
4 #include <sstream>
5 
16 
18 
20 
21  folderPath = iConfig.getUntrackedParameter<std::string>("folderPath","RPC/RPCEfficiency/");
22  numberOfDisks_ = iConfig.getUntrackedParameter<int>("NumberOfEndcapDisks", 4);
23  innermostRings_ = iConfig.getUntrackedParameter<int>("NumberOfInnermostEndcapRings", 2);
24 
25  init_ = false;
26 
27 }
28 
30 
32 
34 
35  LogDebug("rpcefficiencysecond")<<"Getting the RPC Geometry";
36  iSetup.get<MuonGeometryRecord>().get(rpcGeo_);
37  init_= true;
38 }
39 
40 
42 
43 
44  rpcdqm::utils rpcUtils;
45  //Barrel
46  std::stringstream folderName;
47  std::stringstream MeName; std::stringstream MeTitle;
48  for (int w =-2; w<=2; w++){
49  folderName.str("");
50  folderName<<folderPath<<"Wheel_"<<w;
51  ibooker.setCurrentFolder(folderName.str());
52  MeName.str("");
53  MeName<<"EffDistroWheel_"<<w;
54  MeTitle.str("");
55  MeTitle<<"Efficiency Distribution for Wheel "<<w;
56  EffDistroW[w+2]=ibooker.book1D(MeName.str(),MeTitle.str(),20,0.5,100.5);
57  MeName.str("");
58  MeName<<"GlobEfficiencyWheel_"<<w;
59  MeTitle.str("");
60  MeTitle<<"Efficiency Wheel "<<w;
61  EffGlobW[w+2]=ibooker.book1D(MeName.str(),MeTitle.str(),206,0.5,206.5);
63  MeName.str("");
64  MeName<<"Efficiency_Roll_vs_Sector_Wheel_"<<w;
65  WheelSummary[w+2] = ibooker.book2D(MeName.str(),MeName.str(),12, 0.5,12.5, 21, 0.5, 21.5);
66  rpcUtils.labelXAxisSector( WheelSummary[w+2] );
67  rpcUtils.labelYAxisRoll( WheelSummary[w+2], 0, w, true);
68  ibooker.setCurrentFolder(folderPath+"Azimutal/");
69  MeName.str("");
70  MeName<<"AzimutalDistroW"<<w;
71  MeTitle.str("");
72  MeTitle<<"Efficiency per Sector Wheel "<<w;
73  sectorEffW[w+2]= ibooker.book1D(MeName.str(),MeTitle.str(),12,0.5,12.5);
74  MeName.str("");
75  MeName<<"AzimutalDistroW"<<w<<"Ex";
76  MeTitle.str("");
77  MeTitle<<"Expected per Sector Wheel "<<w;
78  ExsectorEffW[w+2]= ibooker.book1D(MeName.str(),MeTitle.str(),12,0.5,12.5);
79  MeName.str("");
80  MeName<<"AzimutalDistroW"<<w<<"Oc";
81  MeTitle.str("");
82  MeTitle<<"Occupancy per Sector Wheel "<<w;
83  OcsectorEffW[w+2]= ibooker.book1D(MeName.str(),MeTitle.str(),12,0.5,12.5);
84  ibooker.setCurrentFolder(folderPath+"BarrelPerLayer/");
85  MeName.str("");
86  MeName<<"ExpLayerW"<<w;
87  MeTitle.str("");
88  MeTitle<<"Expected Wheel "<<w;
89  ExpLayerW[w+2]= ibooker.book1D(MeName.str(),MeTitle.str(),6,0.5,6.5);
90  MeName.str("");
91  MeName<<"ObsLayerW"<<w;
92  MeTitle.str("");
93  MeTitle<<"Observed Wheel "<<w;
94  ObsLayerW[w+2]= ibooker.book1D(MeName.str(),MeTitle.str(),6,0.5,6.5);
95  }
96  //EndCap
97  int index = 0;
98  for (int d = (-1 *numberOfDisks_); d<=numberOfDisks_; d++){
99  if (d==0) {continue;}
100  folderName.str("");
101  folderName<<folderPath<<"Disk_"<<d;
102  ibooker.setCurrentFolder(folderName.str());
103  MeName.str("");
104  MeName<<"EffDistroDisk_"<<d;
105  MeTitle.str("");
106  MeTitle<<"Efficiency Distribution Disk "<<d;
107  EffDistroD[index]=ibooker.book1D(MeName.str(),MeTitle.str(),20,0.5,100.5);
108  MeName.str("");
109  MeName<<"GlobEfficiencyDisk_"<<d;
110  MeTitle.str("");
111  MeTitle<<"Efficiency Disk "<<d;
112  EffGlobD[index] = ibooker.book1D(MeName.str(),MeTitle.str(),218,0.5,218.5);
113  ibooker.setCurrentFolder(folderPath);
114  MeName.str("");
115  MeName<<"Efficiency_Roll_vs_Segment_Disk_"<<d;
116  DiskSummary[index] = ibooker.book2D(MeName.str(),MeName.str(),36,0.5,36.5,6,0.5,6.5);
117  rpcUtils.labelXAxisSegment(DiskSummary[index]);
118  rpcUtils.labelYAxisRing(DiskSummary[index], innermostRings_ , true);
119  ibooker.setCurrentFolder(folderPath+"Azimutal/");
120  MeName.str("");
121  MeName<<"GregDistroR2D"<<d;
122  MeTitle.str("");
123  MeTitle<<"Efficiency for Station "<<d<<" Ring 2";
124  GregR2D[index]= ibooker.book1D(MeName.str(),MeTitle.str(),36,0.5,36.5);
125  MeName.str("");
126  MeName<<"GregDistroR3D"<<d;
127  MeTitle.str("");
128  MeTitle<<"Efficiency for Station "<<d<<" Ring 3";
129  GregR3D[index]= ibooker.book1D(MeName.str(),MeTitle.str(),36,0.5,36.5);
130  MeName.str("");
131  MeName<<"OcGregDistroR2D"<<d;
132  MeTitle.str("");
133  MeTitle<<"Occupancy Distribution for Station "<<d<<" Ring 2";
134  OcGregR2D[index]= ibooker.book1D(MeName.str(),MeTitle.str(),36,0.5,36.5);
135  MeName.str("");
136  MeName<<"OcGregDistroR3D"<<d;
137  MeTitle.str("");
138  MeTitle<<"Occupancy Distribution for Station "<<d<<" Ring 3";
139  OcGregR3D[index]= ibooker.book1D(MeName.str(),MeTitle.str(),36,0.5,36.5);
140  MeName.str("");
141  MeName<<"ExGregDistroR2D"<<d;
142  MeTitle.str("");
143  MeTitle<<"Expected Distribution for Station "<<d<<" Ring 2";
144  ExGregR2D[index]= ibooker.book1D(MeName.str(),MeTitle.str(),36,0.5,36.5);
145  MeName.str("");
146  MeName<<"ExGregDistroR3D"<<d;
147  MeTitle.str("");
148  MeTitle<<"Expected Distribution for Station "<<d<<" Ring 3";
149  ExGregR3D[index]= ibooker.book1D(MeName.str(),MeTitle.str(),36,0.5,36.5);
150  index++;
151  }
152 
153 
154 
155  LogDebug("rpcefficiencysecond")<<"Getting the RPC Geometry";
156 
157 
158  //Setting Labels in Summary Label.
159  std::stringstream binLabel;
160  for (int w = -2; w<=2 ;w++){
161  for(int x = 1;x<=12;x++){
162  for(int y = 1;y<=21;y++){
163  WheelSummary[w+2]->setBinContent(x,y,-1);
164  }
165  }
166  }
167  for (int d = 0 ; d<(numberOfDisks_*2); d++){
168  for(int x = 1;x<=36;x++){
169  for(int y = 1;y<=6;y++){
170  DiskSummary[d]->setBinContent(x,y,-1);
171  }
172  }
173  }
174  binLabel.str("");
175  int indexWheel[5];
176  for(int j=0;j<5;j++){
177  indexWheel[j]=0;
178  }
179  int indexDisk[10];
180  for(int j=0;j<10;j++){
181  indexDisk[j]=0;
182  }
183  for(TrackingGeometry::DetContainer::const_iterator it=rpcGeo_->dets().begin(); it!=rpcGeo_->dets().end();it++){
184  if(dynamic_cast< const RPCChamber* >( *it ) != nullptr ){
185  const RPCChamber* ch = dynamic_cast< const RPCChamber* >( *it );
186  std::vector< const RPCRoll*> roles = (ch->rolls());
187  for(std::vector<const RPCRoll*>::const_iterator r = roles.begin();r != roles.end(); ++r){
188  RPCDetId rpcId = (*r)->id();
189  RPCGeomServ rpcsrv(rpcId);
190  // std::string nameRoll = rpcsrv.name();
191  std::string camera = rpcsrv.name();
192  //Breaking down the geometry
193  int region = rpcId.region();
194  int wheel = rpcId.ring(); int ring = rpcId.ring();
195  int sector = rpcId.sector();
196  int station = rpcId.station();
197  int geolayer = rpcId.layer();
198 
199  RPCBookFolderStructure * folderStr = new RPCBookFolderStructure();
200  std::string folder = folderPath + "MuonSegEff/" + folderStr->folderStructure(rpcId);
201 
202 
203  if(region==0){//Barrel
204  std::stringstream meIdRPC, meIdDT; //, bxDistroId;
205 
206 
207  meIdRPC<<folder<<"/RPCDataOccupancyFromDT_"<<rpcId.rawId();
208  meIdDT<<folder<<"/ExpectedOccupancyFromDT_"<<rpcId.rawId();
209  histoRPC = igetter.get(meIdRPC.str());
210  histoDT = igetter.get(meIdDT.str());
211  int NumberWithOutPrediction=0;
212  double p = 0.;
213  double o = 0.;
214  double ef = 0.;
215  double er = 0.;
216  double buffef = 0.;
217  double buffer = 0.;
218  double sumbuffef = 0.;
219  double sumbuffer = 0.;
220  double averageeff = 0.;
221  int NumberStripsPointed = 0;
222  if(histoRPC && histoDT){
223  for(int i=1;i<=int((*r)->nstrips());++i){
224  if(histoDT->getBinContent(i)!=0){
225  LogDebug("rpcefficiencysecond")<<"Inside the If";
226  buffef = double(histoRPC->getBinContent(i))/double(histoDT->getBinContent(i));
227  buffer = sqrt(buffef*(1.-buffef)/double(histoDT->getBinContent(i)));
228  sumbuffef=sumbuffef+buffef;
229  sumbuffer = sumbuffer + buffer*buffer;
230  NumberStripsPointed++;
231  }else{
232  NumberWithOutPrediction++;
233  }
234  LogDebug("rpcefficiencysecond")<<"Strip="<<i<<" RPC="<<histoRPC->getBinContent(i)<<" DT="<<histoDT->getBinContent(i)<<" buffef="<<buffef<<" sumbuffef="<<sumbuffef<<" NumberStripsPointed="<<NumberStripsPointed<<" NumberWithOutPrediction"<<NumberWithOutPrediction;
235  }
236  p=histoDT->getTH1F()->Integral();
237  o=histoRPC->getTH1F()->Integral();
238  if(NumberStripsPointed!=0){
239  averageeff = (sumbuffef/double(NumberStripsPointed))*100.;
240  //averageerr = sqrt(sumbuffer/double(NumberStripsPointed))*100.;
241  }
242  }
243  // int Ring = rpcId.ring();
244  if(p!=0){
245  ef = double(o)/double(p);
246  er = sqrt(ef*(1.-ef)/double(p));
247  }
248  ef=ef*100;
249  er=er*100;
250  //Filling azimutal Wheel Histograms
251  int layer = 0;
252  if(station==1&&geolayer==1) layer = 1;
253  else if(station==1&&geolayer==2) layer = 2;
254  else if(station==2&&geolayer==1) layer = 3;
255  else if(station==2&&geolayer==2) layer = 4;
256  else if(station==3) layer = 5;
257  else if(station==4) layer = 6;
258  ExsectorEffW[wheel+2]->Fill(sector,p); OcsectorEffW[wheel+2]->Fill(sector,o);
259  ExpLayerW[wheel+2]->Fill(layer, p); ObsLayerW[wheel+2]->Fill(layer, o);
260  LogDebug("rpcefficiencysecond")<<"Pigi "<<camera<<" "<<rpcsrv.shortname()<<" "<<(*r)->id();
261  if(p > 100){//We need at least 100 predictions to fill the summary plot
262  int xBin,yBin;
263  xBin= (*r)->id().sector();
264  rpcdqm::utils rollNumber;
265  yBin = rollNumber.detId2RollNr((*r)->id());
266  WheelSummary[wheel+2]->setBinContent(xBin,yBin,averageeff);
267  }
268  EffDistroW[wheel+2]->Fill(averageeff);
269  indexWheel[wheel+2]++;
270  EffGlobW[wheel+2]->setBinContent(indexWheel[wheel+2],ef);
271  EffGlobW[wheel+2]->setBinError(indexWheel[wheel+2],er);
272  EffGlobW[wheel+2]->setBinLabel(indexWheel[wheel+2],camera,1);
273  }else{//EndCap
274  std::stringstream meIdRPC,meIdCSC; //, bxDistroId;
275  std::string meIdPRO;
276  meIdRPC<<folder<<"/RPCDataOccupancyFromCSC_"<<rpcId.rawId();
277  meIdCSC<<folder<<"/ExpectedOccupancyFromCSC_"<<rpcId.rawId();
278  histoRPC= igetter.get(meIdRPC.str());
279  histoCSC= igetter.get(meIdCSC.str());
280 
281  int NumberWithOutPrediction=0;
282  double p = 0;
283  double o = 0;
284  double ef =0;
285  double er =0;
286  double buffef = 0;
287  double buffer = 0;
288  double sumbuffef = 0;
289  double sumbuffer = 0;
290  double averageeff = 0;
291  int NumberStripsPointed = 0;
292  if(histoRPC && histoCSC) {
293  LogDebug("rpcefficiencysecond")<<rpcsrv.name();
294  for(int i=1;i<=int((*r)->nstrips());++i){
295  if(histoCSC->getBinContent(i)!=0){
296  LogDebug("rpcefficiencysecond")<<"Inside the If";
297  buffef = double(histoRPC->getBinContent(i))/double(histoCSC->getBinContent(i));
298  buffer = sqrt(buffef*(1.-buffef)/double(histoCSC->getBinContent(i)));
299  sumbuffef=sumbuffef+buffef;
300  sumbuffer = sumbuffer + buffer*buffer;
301  NumberStripsPointed++;
302  }else{
303  NumberWithOutPrediction++;
304  }
305  LogDebug("rpcefficiencysecond")<<"Strip="<<i<<" RPC="<<histoRPC->getBinContent(i)<<" CSC="<<histoCSC->getBinContent(i)<<" buffef="<<buffef<<" buffer="<<buffer<<" sumbuffef="<<sumbuffef<<" sumbuffer="<<sumbuffer<<" NumberStripsPointed="<<NumberStripsPointed<<" NumberWithOutPrediction"<<NumberWithOutPrediction;
306  }
307  p=histoCSC->getTH1F()->Integral();
308  o=histoRPC->getTH1F()->Integral();
309  if(NumberStripsPointed!=0){
310  averageeff = (sumbuffef/double(NumberStripsPointed))*100.;
311  }
312  }
313  int Disk = station*region;
314  if(Disk > numberOfDisks_ || Disk<-numberOfDisks_){continue;} //remove strange disk numbers!!
315  int dIndex = -1;
316  if(region == -1){
317  dIndex = Disk+numberOfDisks_;
318  }else if(region == 1){
319  dIndex = Disk+numberOfDisks_-1;
320  }
321  if( dIndex<0 || dIndex>= numberOfDisks_*2){continue;} //extra check on disk numering
322  if(p!=0){
323  ef = double(o)/double(p);
324  er = sqrt(ef*(1.-ef)/double(p));
325  }
326  ef=ef*100;
327  er=er*100;
328  if(ring==2){
329  if (ExGregR2D[dIndex] && OcGregR2D[dIndex] ){
330  ExGregR2D[dIndex]->Fill(rpcsrv.segment(),p);
331  OcGregR2D[dIndex]->Fill(rpcsrv.segment(),o);
332  }
333  } else if(ring==3){
334  ExGregR3D[dIndex]->Fill(rpcsrv.segment(),p);
335  OcGregR3D[dIndex]->Fill(rpcsrv.segment(),o);
336  }
337  if(p > 100){ //We need at least 100 predictions to fill the summary plot
338  RPCGeomServ RPCServ((*r)->id());
339  int xBin = RPCServ.segment();
340  int yBin= (ring-1)*3-(*r)->id().roll()+1;
341  DiskSummary[dIndex]->setBinContent(xBin, yBin, averageeff);
342  }
343  if ( EffDistroD[dIndex]){EffDistroD[dIndex]->Fill(averageeff);}
344  indexDisk[dIndex]++;
345  if ( EffGlobD[dIndex]){
346  EffGlobD[dIndex]->setBinContent(indexDisk[dIndex],ef);
347  EffGlobD[dIndex]->setBinError(indexDisk[dIndex],er);
348  EffGlobD[dIndex]->setBinLabel(indexDisk[dIndex],camera,1);
349  }
350  }
351  delete folderStr;
352  }
353  }
354 
355 
356  }
357  double eff,N,err;
358  int k;
359  for (int d = 0; d<(numberOfDisks_*2); d++){
360  for(k=1;k<=36;k++){
361  err=0; eff=0; N=ExGregR2D[d]->getBinContent(k);
362  if(N!=0.){ eff = OcGregR2D[d]->getBinContent(k)/N; err=sqrt(eff*(1-eff)/N);}
363  GregR2D[d]->setBinContent(k,eff); GregR2D[d]->setBinError(k,err);
364  err=0; eff=0; N=ExGregR3D[d]->getBinContent(k);
365  if(N!=0.){ eff = OcGregR3D[d]->getBinContent(k)/N; err=sqrt(eff*(1-eff)/N);}
366  GregR3D[d]->setBinContent(k,eff); GregR3D[d]->setBinError(k,err);
367  }
368  }
369  for (int w =-2; w<=2; w++){
370  for(k=1;k<=12;k++){
371  err=0; eff=0; N=ExsectorEffW[w+2]->getBinContent(k);
372  if(N!=0.){ eff = OcsectorEffW[w+2]->getBinContent(k)/N;err=sqrt(eff*(1-eff)/N);}
373  sectorEffW[w+2]->setBinContent(k,eff); sectorEffW[w+2]->setBinError(k,err);
374  }
375  }
376  //Ranges for Both
377  //Barrel
378  for (int w=-2; w<=2; w++){
379  EffGlobW[w+2]->setAxisRange(-4.,100.,2);
380  EffGlobW[w+2]->setAxisTitle("%",2);
381  }
382  for (int d=0; d<(numberOfDisks_*2); d++){
383  EffGlobD[d]->setAxisRange(-4.,100.,2);
384  EffGlobD[d]->setAxisTitle("%",2);
385  }
386 
387 
388 }
389 
#define LogDebug(id)
MonitorElement * EffGlobW[5]
T getUntrackedParameter(std::string const &, T const &) const
void setBinContent(int binx, double content)
set content of bin (1-D)
const double w
Definition: UKUtility.cc:23
RPCEfficiencySecond(const edm::ParameterSet &)
MonitorElement * histoCSC
void setAxisRange(double xmin, double xmax, int axis=1)
set x-, y- or z-axis range (axis=1, 2, 3 respectively)
TH1F * getTH1F() const
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &) override
#define nullptr
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
MonitorElement * OcGregR3D[10]
MonitorElement * histoDT
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
MonitorElement * OcsectorEffW[5]
void labelXAxisSegment(MonitorElement *myMe)
Definition: utils.h:264
void labelYAxisRoll(MonitorElement *myMe, int region, int ring, bool useRollInfo)
Definition: utils.h:283
MonitorElement * sectorEffW[5]
void Fill(long long x)
edm::ESHandle< RPCGeometry > rpcGeo_
Definition: BoundDisk.h:19
virtual std::string name()
Definition: RPCGeomServ.cc:20
void labelYAxisRing(MonitorElement *myMe, int numberOfRings, bool useRollInfo)
Definition: utils.h:311
MonitorElement * ObsLayerW[5]
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
int ring() const
Definition: RPCDetId.h:72
T sqrt(T t)
Definition: SSEVec.h:18
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
MonitorElement * EffGlobD[10]
const std::vector< const RPCRoll * > & rolls() const
Return the Rolls.
Definition: RPCChamber.cc:68
MonitorElement * EffDistroD[10]
MonitorElement * ExpLayerW[5]
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
MonitorElement * OcGregR2D[10]
virtual std::string shortname()
Definition: RPCGeomServ.cc:208
void labelXAxisSector(MonitorElement *myMe)
Definition: utils.h:249
MonitorElement * get(std::string const &path)
Definition: DQMStore.cc:303
int k[5][pyjets_maxn]
int layer() const
Definition: RPCDetId.h:108
virtual int segment()
Definition: RPCGeomServ.cc:469
int detId2RollNr(const RPCDetId &_id)
Definition: utils.h:31
#define N
Definition: blowfish.cc:9
std::string folderStructure(RPCDetId detId)
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: RPCGeometry.cc:33
MonitorElement * WheelSummary[5]
void beginJob() override
MonitorElement * ExGregR2D[10]
int sector() const
Sector id: the group of chambers at same phi (and increasing r)
Definition: RPCDetId.h:102
MonitorElement * DiskSummary[10]
double getBinContent(int binx) const
get content of bin (1-D)
T get() const
Definition: EventSetup.h:71
MonitorElement * ExsectorEffW[5]
MonitorElement * GregR2D[10]
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
MonitorElement * ExGregR3D[10]
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
MonitorElement * histoRPC
MonitorElement * GregR3D[10]
yBin
Definition: cuy.py:893
MonitorElement * EffDistroW[5]
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63
int station() const
Definition: RPCDetId.h:96