CMS 3D CMS Logo

GEMRecHitsValidation.cc
Go to the documentation of this file.
5 #include <iomanip>
6 
7 using namespace std;
8 
10 {
11  InputTagToken_ = consumes<edm::PSimHitContainer>(cfg.getParameter<edm::InputTag>("simInputLabel"));
12  InputTagToken_RH = consumes<GEMRecHitCollection>(cfg.getParameter<edm::InputTag>("recHitsInputLabel"));
13  detailPlot_ = cfg.getParameter<bool>("detailPlot");
14 }
15 
16 MonitorElement* GEMRecHitsValidation::BookHist1D( DQMStore::IBooker& ibooker, const char* name, const char* label, unsigned int region_num, unsigned int station_num, unsigned int layer_num, const unsigned int Nbin, const Float_t xMin, const Float_t xMax) {
17  string hist_name = name+getSuffixName( region_num, station_num+1, layer_num+1);
18  string hist_label = label+string(" : ")+getSuffixTitle( region_num, station_num+1, layer_num+1);
19  return ibooker.book1D( hist_name, hist_label,Nbin,xMin,xMax );
20 }
21 
22 MonitorElement* GEMRecHitsValidation::BookHist1D( DQMStore::IBooker& ibooker, const char* name, const char* label, unsigned int region_num, const unsigned int Nbin, const Float_t xMin, const Float_t xMax) {
23  string hist_name = name+getSuffixName( region_num);
24  string hist_label = label+string(" : ")+getSuffixName( region_num ) ;
25  return ibooker.book1D( hist_name, hist_label,Nbin,xMin,xMax );
26 }
27 
29  const GEMGeometry* GEMGeometry_ = initGeometry(iSetup);
30  if ( GEMGeometry_ == nullptr) return ;
31 
32  LogDebug("GEMRecHitsValidation")<<"Geometry is acquired from MuonGeometryRecord\n";
33  ibooker.setCurrentFolder("MuonGEMRecHitsV/GEMRecHitsTask");
34  LogDebug("GEMRecHitsValidation")<<"ibooker set current folder\n";
35 
36 
37  gem_cls_tot = ibooker.book1D("gem_cls_tot","ClusterSize Distribution",11,-0.5,10.5);
38  for( auto& region : GEMGeometry_->regions() ){
39  int re = region->region();
40  TString title_suffix = getSuffixTitle( re) ;
41  TString histname_suffix = getSuffixName( re);
42  TString simpleZR_title = TString::Format("ZR Occupancy%s; |Z|(cm) ; R(cm)",title_suffix.Data());
43  TString simpleZR_histname = TString::Format("rh_simple_zr%s",histname_suffix.Data());
44  auto* simpleZR = getSimpleZR(ibooker, simpleZR_title, simpleZR_histname);
45  if( simpleZR != nullptr) {
46  recHits_simple_zr[simpleZR_histname.Hash() ] = simpleZR;
47  }
48 
49  for( auto& station : region->stations()) {
50  int station_num = station->station();
51  TString title_suffix2 = title_suffix + TString::Format(" Station%d", station_num);
52  TString histname_suffix2 = histname_suffix + TString::Format("_st%d", station_num);
53 
54  TString dcEta_title = TString::Format("Occupancy for detector component %s;;#eta-partition",title_suffix2.Data());
55  TString dcEta_histname = TString::Format("rh_dcEta%s",histname_suffix2.Data());
56  auto* dcEta = getDCEta( ibooker, station, dcEta_title, dcEta_histname);
57  if ( dcEta != nullptr) {
58  recHits_dcEta[ dcEta_histname.Hash() ] = dcEta;
59  }
60  int idx = 0 ;
61  for(unsigned int sCh = 1 ; sCh <= station->superChambers().size() ; sCh++ ) {
62  for( unsigned int Ch =1 ; Ch<=2 ; Ch++) {
63  idx++;
64  TString label = TString::Format("ch%d_la%d",sCh, Ch);
65  recHits_dcEta[ dcEta_histname.Hash() ]->setBinLabel(idx, label.Data());
66  }
67  }
68  }
69  }
70 
71  for( unsigned int region_num = 0 ; region_num <nRegion() ; region_num++ ) {
72  gem_region_pullX[region_num] = BookHist1D(ibooker,"pullX","Pull Of X",region_num,100,-50,50);
73  gem_region_pullY[region_num] = BookHist1D(ibooker,"pullY","Pull Of Y",region_num,100,-50,50);
74  }
75 
76  if(detailPlot_){
77  for( unsigned int region_num = 0 ; region_num <nRegion() ; region_num++ ) {
78  for( int layer_num = 0 ; layer_num < 2 ; layer_num++) {
79  for( unsigned int station_num = 0 ; station_num < nStation() ; station_num++) {
80  gem_cls[region_num][station_num][layer_num] = BookHist1D(ibooker,"cls","ClusterSize Distribution",region_num,station_num,layer_num,11,-0.5,10.5);
81  gem_pullX[region_num][station_num][layer_num] = BookHist1D(ibooker,"pullX","Pull Of X",region_num,station_num,layer_num,100,-50,50);
82  gem_pullY[region_num][station_num][layer_num] = BookHist1D(ibooker,"pullY","Pull Of Y",region_num,station_num,layer_num,100,-50,50);
83  gem_rh_zr[region_num][station_num][layer_num] = BookHistZR(ibooker,"rh","RecHits",region_num,station_num,layer_num);
84  gem_rh_xy[region_num][station_num][layer_num] = BookHistXY(ibooker,"rh","RecHits",region_num,station_num,layer_num);
85  }
86  }
87  }
88  }
89  LogDebug("GEMRecHitsValidation")<<"Booking End.\n";
90 }
91 
92 
94 }
95 
97  const edm::EventSetup& iSetup)
98 {
99  const GEMGeometry* GEMGeometry_ = initGeometry(iSetup);
100  if ( GEMGeometry_ == nullptr) return;
101 
104  e.getByToken( this->InputTagToken_, gemSimHits);
105  e.getByToken( this->InputTagToken_RH,gemRecHits);
106  if (!gemRecHits.isValid()) {
107  edm::LogError("GEMRecHitsValidation") << "Cannot get strips by Token RecHits Token.\n";
108  return ;
109  }
110 
111  for (edm::PSimHitContainer::const_iterator hits = gemSimHits->begin(); hits!=gemSimHits->end(); ++hits) {
112 
113  const GEMDetId id(hits->detUnitId());
114 
115  Int_t sh_region = id.region();
116  //Int_t sh_ring = id.ring();
117  Int_t sh_roll = id.roll();
118  Int_t sh_station = id.station();
119  Int_t sh_layer = id.layer();
120  Int_t sh_chamber = id.chamber();
121 
122  if ( GEMGeometry_->idToDet(hits->detUnitId()) == nullptr) {
123  std::cout<<"simHit did not matched with GEMGeometry."<<std::endl;
124  continue;
125  }
126 
127  if (!(abs(hits-> particleType()) == 13)) continue;
128 
129  //const LocalPoint p0(0., 0., 0.);
130  //const GlobalPoint Gp0(GEMGeometry_->idToDet(hits->detUnitId())->surface().toGlobal(p0));
131  const LocalPoint hitLP(hits->localPosition());
132 
133  const LocalPoint hitEP(hits->entryPoint());
134  Int_t sh_strip = GEMGeometry_->etaPartition(hits->detUnitId())->strip(hitEP);
135 
136  //const GlobalPoint hitGP(GEMGeometry_->idToDet(hits->detUnitId())->surface().toGlobal(hitLP));
137  //Float_t sh_l_r = hitLP.perp();
138  Float_t sh_l_x = hitLP.x();
139  Float_t sh_l_y = hitLP.y();
140  //Float_t sh_l_z = hitLP.z();
141 
142 
143  for (GEMRecHitCollection::const_iterator recHit = gemRecHits->begin(); recHit != gemRecHits->end(); ++recHit){
144  Float_t rh_l_x = recHit->localPosition().x();
145  Float_t rh_l_xErr = recHit->localPositionError().xx();
146  Float_t rh_l_y = recHit->localPosition().y();
147  Float_t rh_l_yErr = recHit->localPositionError().yy();
148  //Int_t detId = (Short_t) (*recHit).gemId();
149  //Int_t bx = recHit->BunchX();
150  Int_t clusterSize = recHit->clusterSize();
151  Int_t firstClusterStrip = recHit->firstClusterStrip();
152 
153  GEMDetId id((*recHit).gemId());
154 
155  Short_t rh_region = (Short_t) id.region();
156  //Int_t rh_ring = (Short_t) id.ring();
157  Short_t rh_station = (Short_t) id.station();
158  Short_t rh_layer = (Short_t) id.layer();
159  Short_t rh_chamber = (Short_t) id.chamber();
160  Short_t rh_roll = (Short_t) id.roll();
161 
162  LocalPoint recHitLP = recHit->localPosition();
163  if ( GEMGeometry_->idToDet((*recHit).gemId()) == nullptr) {
164  std::cout<<"This gem recHit did not matched with GEMGeometry."<<std::endl;
165  continue;
166  }
167  GlobalPoint recHitGP = GEMGeometry_->idToDet((*recHit).gemId())->surface().toGlobal(recHitLP);
168 
169  Float_t rh_g_R = recHitGP.perp();
170  //Float_t rh_g_Eta = recHitGP.eta();
171  //Float_t rh_g_Phi = recHitGP.phi();
172  Float_t rh_g_X = recHitGP.x();
173  Float_t rh_g_Y = recHitGP.y();
174  Float_t rh_g_Z = recHitGP.z();
175  Float_t rh_pullX = (Float_t)(rh_l_x - sh_l_x)/(rh_l_xErr);
176  Float_t rh_pullY = (Float_t)(rh_l_y - sh_l_y)/(rh_l_yErr);
177 
178  std::vector<int> stripsFired;
179  for(int i = firstClusterStrip; i < (firstClusterStrip + clusterSize); i++){
180  stripsFired.push_back(i);
181  }
182 
183  const bool cond1( sh_region == rh_region and sh_layer == rh_layer and sh_station == rh_station);
184  const bool cond2(sh_chamber == rh_chamber and sh_roll == rh_roll);
185  const bool cond3(std::find(stripsFired.begin(), stripsFired.end(), (sh_strip + 1)) != stripsFired.end());
186 
187  if(cond1 and cond2 and cond3){
188  LogDebug("GEMRecHitsValidation")<< " Region : " << rh_region << "\t Station : " << rh_station
189  << "\t Layer : "<< rh_layer << "\n Radius: " << rh_g_R << "\t X : " << rh_g_X << "\t Y : "<< rh_g_Y << "\t Z : " << rh_g_Z << std::endl;
190 
191  int region_num=0 ;
192  if ( rh_region ==-1 ) region_num = 0 ;
193  else if ( rh_region==1) region_num = 1;
194  int layer_num = rh_layer-1;
195  int binX = (rh_chamber-1)*2+layer_num;
196  int binY = rh_roll;
197  int station_num = rh_station -1;
198 
199  // Fill normal plots.
200  TString histname_suffix = TString::Format("_r%d",rh_region);
201  TString simple_zr_histname = TString::Format("rh_simple_zr%s",histname_suffix.Data());
202  LogDebug("GEMRecHitsValidation")<< " simpleZR!\n";
203  recHits_simple_zr[simple_zr_histname.Hash()]->Fill( fabs(rh_g_Z), rh_g_R);
204 
205 
206  histname_suffix = TString::Format("_r%d_st%d",rh_region, rh_station);
207  TString dcEta_histname = TString::Format("rh_dcEta%s",histname_suffix.Data());
208  LogDebug("GEMRecHitsValidation")<< " dcEta\n";
209  recHits_dcEta[dcEta_histname.Hash()]->Fill( binX, binY);
210 
211  gem_cls_tot->Fill(clusterSize);
212  gem_region_pullX[region_num]->Fill(rh_pullX);
213  gem_region_pullY[region_num]->Fill(rh_pullY);
214  LogDebug("GEMRecHitsValidation")<< " Begin detailPlot!\n";
215 
216  if(detailPlot_){
217  gem_cls[region_num][station_num][layer_num]->Fill(clusterSize);
218  gem_pullX[region_num][station_num][layer_num]->Fill(rh_pullX);
219  gem_pullY[region_num][station_num][layer_num]->Fill(rh_pullY);
220  gem_rh_zr[region_num][station_num][layer_num]->Fill(rh_g_Z ,rh_g_R);
221  gem_rh_xy[region_num][station_num][layer_num]->Fill(rh_g_X ,rh_g_Y);
222  }
223  }
224  } //End loop on RecHits
225  } //End loop on SimHits
226 
227 }
#define LogDebug(id)
unsigned int nRegion()
T getParameter(std::string const &) const
MonitorElement * gem_pullX[2][3][2]
unsigned int nStation()
T perp() const
Definition: PV3DBase.h:72
std::unordered_map< UInt_t, MonitorElement * > recHits_dcEta
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
MonitorElement * BookHistZR(DQMStore::IBooker &, const char *name, const char *label, unsigned int region_num, unsigned int station_num, unsigned int layer_num=99)
std::unordered_map< UInt_t, MonitorElement * > recHits_simple_zr
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
T y() const
Definition: PV3DBase.h:63
MonitorElement * gem_region_pullY[2]
MonitorElement * getSimpleZR(DQMStore::IBooker &, TString, TString)
MonitorElement * BookHistXY(DQMStore::IBooker &, const char *name, const char *label, unsigned int region_num, unsigned int station_num, unsigned int layer_num=99)
MonitorElement * gem_rh_xy[2][3][2]
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::string getSuffixTitle(int region, int station, int layer)
MonitorElement * gem_rh_zr[2][3][2]
const GEMEtaPartition * etaPartition(GEMDetId id) const
Return a GEMEtaPartition given its id.
Definition: GEMGeometry.cc:99
const GEMGeometry * initGeometry(const edm::EventSetup &)
MonitorElement * gem_cls[2][3][2]
void Fill(long long x)
std::string getSuffixName(int region, int station, int layer)
MonitorElement * gem_cls_tot
edm::EDGetToken InputTagToken_
const std::vector< const GEMRegion * > & regions() const
Return a vector of all GEM regions.
Definition: GEMGeometry.cc:43
T z() const
Definition: PV3DBase.h:64
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MonitorElement * BookHist1D(DQMStore::IBooker &, const char *name, const char *label, unsigned int region_num, unsigned int station_num, unsigned int layer_num, const unsigned int Nbin, const Float_t xMin, const Float_t xMax)
GEMRecHitsValidation(const edm::ParameterSet &)
void analyze(const edm::Event &e, const edm::EventSetup &) override
bool isValid() const
Definition: HandleBase.h:74
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
virtual const GeomDet * idToDet(DetId) const override
Definition: GEMGeometry.cc:38
MonitorElement * getDCEta(DQMStore::IBooker &, const GEMStation *, TString, TString)
return(e1-e2)*(e1-e2)+dp *dp
MonitorElement * gem_pullY[2][3][2]
MonitorElement * gem_region_pullX[2]
T x() const
Definition: PV3DBase.h:62
edm::EDGetToken InputTagToken_RH
Definition: Run.h:42