CMS 3D CMS Logo

GEMHitsValidation.cc
Go to the documentation of this file.
5 #include <exception>
6 using namespace std;
8 {
9  InputTagToken_ = consumes<edm::PSimHitContainer>(cfg.getParameter<edm::InputTag>("simInputLabel"));
10  detailPlot_ = cfg.getParameter<bool>("detailPlot");
11 }
12 
13 
15  const GEMGeometry* GEMGeometry_ = initGeometry(iSetup);
16  if ( GEMGeometry_ == nullptr) {
17  std::cout<<"geometry is wrong! Terminated."<<std::endl;
18  return;
19  }
20 
21  ibooker.setCurrentFolder("MuonGEMHitsV/GEMHitsTask");
22  edm::LogInfo("MuonGEMHitsValidation")<<"+++ Info : # of region : "<<nRegion()<<std::endl;
23  edm::LogInfo("MuonGEMHitsValidation")<<"+++ Info : # of stations : "<<nStation()<<std::endl;
24  edm::LogInfo("MuonGEMHitsValidation")<<"+++ Info : # of eta partition : "<< nPart()<<std::endl;
25 
26  LogDebug("MuonGEMHitsValidation")<<"+++ Info : finish to get geometry information from ES.\n";
27 
28 
29  LogDebug("MuonGEMHitsValidation")<<"+++ Region independant part.\n";
30  // Region independant.
31  for( auto& station : GEMGeometry_->regions()[0]->stations() ){
32  int st = station->station();
33  // TOF and Energy loss part are indepent from Region.
34  // Labeling TOF and Energy loss
35  TString hist_name_for_tofMu = TString::Format("gem_sh_simple_tofMuon_st%s",getStationLabel(st).c_str());
36  TString hist_name_for_elossMu = TString::Format("gem_sh_simple_energylossMuon_st%s",getStationLabel(st).c_str());
37  TString hist_label_for_tofMu = TString::Format("SimHit TOF(Muon only) station : station %s ; Time of flight [ns] ; entries",getStationLabel(st).c_str());
38  TString hist_label_for_elossMu = TString::Format("SimHit energy loss(Muon only) : station %s ; Energy loss [eV] ; entries",getStationLabel(st).c_str());
39  // set tof's range.
40  double tof_min, tof_max;
41  if( st == 1 ) { tof_min = 18; tof_max = 22; }
42  else { tof_min = 26; tof_max = 30; }
43  gem_sh_simple_tofMu[ hist_name_for_tofMu.Hash() ] = ibooker.book1D( hist_name_for_tofMu.Data(), hist_label_for_tofMu.Data(), 40,tof_min,tof_max);
44  gem_sh_simple_elossMu[ hist_name_for_elossMu.Hash() ] = ibooker.book1D( hist_name_for_elossMu.Data(), hist_label_for_elossMu.Data(), 60,0.,6000.);
45  }
46 
47  LogDebug("MuonGEMHitsValidation")<<"+++ Region+Station part.\n";
48  // Regions, Region+station
49  for( auto& region : GEMGeometry_->regions() ){
50  int re = region->region();
51  TString title_suffix = getSuffixTitle( re ) ;
52  TString histname_suffix = getSuffixName( re) ;
53  LogDebug("MuonGEMHitsValidation")<<"+++ SimpleZR Occupancy\n";
54  TString simpleZR_title = TString::Format("ZR Occupancy%s; |Z|(cm); R(cm)", title_suffix.Data());
55  TString simpleZR_histname = TString::Format("hit_simple_zr%s", histname_suffix.Data());
56 
57  MonitorElement* simpleZR = getSimpleZR(ibooker, simpleZR_title, simpleZR_histname);
58  if ( simpleZR != nullptr) {
59  Hit_simple_zr[ simpleZR_histname.Hash() ] = simpleZR;
60  }
61 
62  for( auto& station : region->stations() ){
63  int st = station->station();
64  TString title_suffix2 = getSuffixTitle( re, st) ;
65  TString histname_suffix2 = getSuffixName( re, st) ;
66  LogDebug("MuonGEMHitsValidation")<<"+++ dcEta Occupancy\n";
67  TString dcEta_title = TString::Format("Occupancy for detector component %s;;#eta-partition",title_suffix2.Data());
68  TString dcEta_histname = TString::Format("hit_dcEta%s",histname_suffix2.Data());
69  MonitorElement* dcEta = getDCEta(ibooker, station, dcEta_title, dcEta_histname);
70  if ( dcEta != nullptr) {
71  Hit_dcEta[ dcEta_histname.Hash() ] = dcEta;
72  }
73  }
74  }
75 
76 
77  LogDebug("MuonGEMHitsValidation")<<"+++ Begining Detail Plots\n";
78  if( detailPlot_ ){
79  for( auto& region : GEMGeometry_->regions() ){
80  for( auto& station : region->stations() ){
81  for( auto& ring : station->rings()){
82  GEMDetId id;
83  if ( ring->ring() != 1 ) break ; // Only Ring1 is interesting.
84  string name_suffix = getSuffixName(region->region(), station->station());
85  string title_suffix= getSuffixTitle(region->region(), station->station());
86 
87  TString hist_name = TString::Format("gem_sh_xy%s",name_suffix.c_str());
88  TString hist_title = TString::Format("Simhit Global XY Plots at %s",title_suffix.c_str());
89  MonitorElement* temp = ibooker.book2D( (hist_name+"_even").Data(), (hist_title +" even").Data(),nBinXY_,-360,360,nBinXY_,-360,360);
90  if ( temp != nullptr ) {
91  LogDebug("MuonGEMHitsValidation")<<"ME can be acquired!";
92  }
93  else {
94  LogDebug("MuonGEMHitsValidation")<<"ME can not be acquired!";
95  return ;
96  }
97  gem_sh_xy_st_ch[ (hist_name+"_even").Hash()] = temp;
98 
99  MonitorElement* temp2 = ibooker.book2D( (hist_name+"_odd").Data(), (hist_title+" odd").Data(),nBinXY_,-360,360,nBinXY_,-360,360);
100  if ( temp2 != nullptr ) {
101  LogDebug("MuonGEMHitsValidation")<<"ME can be acquired!";
102  }
103  else {
104  LogDebug("MuonGEMHitsValidation")<<"ME can not be acquired!";
105  return ;
106  }
107  gem_sh_xy_st_ch[ (hist_name+"_odd").Hash()] = temp2;
108  }
109  }
110  }
111  for( unsigned int region_num = 0 ; region_num < nRegion() ; region_num++ ) {
112  for( unsigned int station_num = 0 ; station_num < nStation() ; station_num++) {
113  for( unsigned int layer_num = 0 ; layer_num < 2 ; layer_num++) {
114  gem_sh_zr[region_num][station_num][layer_num] = BookHistZR(ibooker,"gem_sh","SimHit",region_num,station_num,layer_num);
115  gem_sh_xy[region_num][station_num][layer_num] = BookHistXY(ibooker,"gem_sh","SimHit",region_num,station_num,layer_num);
116 
117  int re = ((unsigned int)region_num)*2-1;
118  std::string suffixname = getSuffixName( re, station_num+1, layer_num+1);
119  std::string suffixtitle = getSuffixTitle( re, station_num+1, layer_num+1);
120  std::string hist_name_for_tof = std::string("gem_sh_tof_")+suffixname;
121  std::string hist_name_for_tofMu = std::string("gem_sh_tofMuon_")+suffixname;
122  std::string hist_name_for_eloss = std::string("gem_sh_energyloss_")+suffixname;
123  std::string hist_name_for_elossMu = std::string("gem_sh_energylossMuon_")+suffixname;
124  std::string hist_label_for_xy = "SimHit occupancy : region"+suffixtitle+" ; globalX [cm]; globalY[cm]";
125  std::string hist_label_for_tof = "SimHit TOF : region"+suffixtitle+ " ; Time of flight [ns] ; entries";
126  std::string hist_label_for_tofMu = "SimHit TOF(Muon only) : "+suffixtitle+" ; Time of flight [ns] ; entries";
127  std::string hist_label_for_eloss = "SimHit energy loss : "+suffixtitle + " ; Energy loss [eV] ; entries";
128  std::string hist_label_for_elossMu = "SimHit energy loss(Muon only) : "+suffixtitle+" ; Energy loss [eV] ; entries";
129 
130  double tof_min, tof_max;
131  if( station_num == 0 ) { tof_min = 18; tof_max = 22; }
132  else { tof_min = 26; tof_max = 30; }
133  gem_sh_tof[region_num][station_num][layer_num] = ibooker.book1D( hist_name_for_tof.c_str(), hist_label_for_tof.c_str(), 40,tof_min,tof_max);
134  gem_sh_tofMu[region_num][station_num][layer_num] = ibooker.book1D( hist_name_for_tofMu.c_str(), hist_label_for_tofMu.c_str(), 40,tof_min,tof_max);
135  gem_sh_eloss[region_num][station_num][layer_num] = ibooker.book1D( hist_name_for_eloss.c_str(), hist_label_for_eloss.c_str(), 60,0.,6000.);
136  gem_sh_elossMu[region_num][station_num][layer_num] = ibooker.book1D( hist_name_for_elossMu.c_str(), hist_label_for_elossMu.c_str(), 60,0.,6000.);
137  }
138  }
139  }
140  }
141 }
142 
143 
145 }
146 
147 
149  const edm::EventSetup& iSetup)
150 {
151  const GEMGeometry* GEMGeometry_ = initGeometry( iSetup) ;
152 
154  e.getByToken(InputTagToken_, GEMHits);
155  if (!GEMHits.isValid()) {
156  edm::LogError("GEMHitsValidation") << "Cannot get GEMHits by Token simInputTagToken";
157  return ;
158  }
159 
160  for (auto hits=GEMHits->begin(); hits!=GEMHits->end(); hits++) {
161 
162  const GEMDetId id(hits->detUnitId());
163  Int_t region = (Int_t) id.region();
164  Int_t station = (Int_t) id.station();
165  Int_t layer = (Int_t) id.layer();
166  Int_t chamber = (Int_t) id.chamber();
167  Int_t nroll = (Int_t) id.roll();
168 
169  //Int_t even_odd = id.chamber()%2;
170  if ( GEMGeometry_->idToDet(hits->detUnitId()) == nullptr) {
171  std::cout<<"simHit did not matched with GEMGeometry."<<std::endl;
172  continue;
173  }
174  //const LocalPoint p0(0., 0., 0.);
175  //const GlobalPoint Gp0(GEMGeometry_->idToDet(hits->detUnitId())->surface().toGlobal(p0));
176  const LocalPoint hitLP(hits->localPosition());
177 
178  const GlobalPoint hitGP(GEMGeometry_->idToDet(hits->detUnitId())->surface().toGlobal(hitLP));
179  Float_t g_r = hitGP.perp();
180  Float_t g_x = hitGP.x();
181  Float_t g_y = hitGP.y();
182  Float_t g_z = hitGP.z();
183  Float_t energyLoss = hits->energyLoss();
184  Float_t timeOfFlight = hits->timeOfFlight();
185 
186  int layer_num = layer-1;
187  int binX = (chamber-1)*2+layer_num;
188  int binY = nroll;
189 
190  //const LocalPoint hitEP(hits->entryPoint());
191 
192  TString histname_suffix = getSuffixName( region) ;
193  TString simple_zr_histname = TString::Format("hit_simple_zr%s",histname_suffix.Data());
194  LogDebug("GEMHitsValidation")<<simple_zr_histname<<std::endl;
195  Hit_simple_zr[ simple_zr_histname.Hash() ] ->Fill(fabs(g_z), g_r);
196 
197  histname_suffix = getSuffixName( region, station);
198  TString dcEta_histname = TString::Format("hit_dcEta%s", histname_suffix.Data());
199  LogDebug("GEMHitsValidation")<<dcEta_histname<<std::endl;
200  Hit_dcEta[ dcEta_histname.Hash() ]->Fill(binX, binY);
201 
202  TString tofMu = TString::Format("gem_sh_simple_tofMuon_st%s",getStationLabel(station).c_str());
203  TString elossMu = TString::Format("gem_sh_simple_energylossMuon_st%s",getStationLabel(station).c_str());
204 
205  if (abs(hits-> particleType()) == 13){
206  LogDebug("GEMHitsValidation")<<tofMu<<std::endl;
207  gem_sh_simple_tofMu[ tofMu.Hash() ]->Fill( timeOfFlight );
208  LogDebug("GEMHitsValidation")<<elossMu<<std::endl;
209  gem_sh_simple_elossMu[ elossMu.Hash() ]->Fill( energyLoss*1.e9 );
210  }
211 
212  if( detailPlot_ ){
213  // First, fill variable has no condition.
214  LogDebug("GEMHitsValidation")<<"gzgr"<<std::endl;
215  gem_sh_zr[(int)(region/2.+0.5)][station-1][layer_num]->Fill(g_z,g_r);
216  LogDebug("GEMHitsValidation")<<"gxgy"<<std::endl;
217  gem_sh_xy[(int)(region/2.+0.5)][station-1][layer_num]->Fill(g_x,g_y);
218  gem_sh_tof[(int)(region/2.+0.5)][station-1][layer_num]->Fill(timeOfFlight);
219  gem_sh_eloss[(int)(region/2.+0.5)][station-1][layer_num]->Fill(energyLoss*1.e9);
220  if (abs(hits-> particleType()) == 13) {
221  gem_sh_tofMu[(int)(region/2.+0.5)][station-1][layer_num]->Fill(timeOfFlight);
222  gem_sh_elossMu[(int)(region/2.+0.5)][station-1][layer_num]->Fill(energyLoss*1.e9);
223  }
224  std::string chamber ="";
225  if ( id.chamber() %2 == 1 ) chamber = "odd";
226  else chamber = "even";
227  TString hist_name = TString::Format("gem_sh_xy%s",(getSuffixName( id.region(), station)+"_"+chamber).c_str());
228 
229  LogDebug("GEMHitsValidation")<<hist_name<<std::endl;
230  gem_sh_xy_st_ch[hist_name.Hash()]->Fill( g_x, g_y);
231  }
232  }
233 }
234 
#define LogDebug(id)
unsigned int nRegion()
T getParameter(std::string const &) const
MonitorElement * gem_sh_tof[2][3][2]
unsigned int nStation()
std::unordered_map< UInt_t, MonitorElement * > gem_sh_xy_st_ch
T perp() const
Definition: PV3DBase.h:72
unsigned int nPart()
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)
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
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_sh_eloss[2][3][2]
std::string getSuffixTitle(int region, int station, int layer)
const GEMGeometry * initGeometry(const edm::EventSetup &)
MonitorElement * gem_sh_zr[2][3][2]
void Fill(long long x)
std::string getSuffixName(int region, int station, int layer)
std::unordered_map< UInt_t, MonitorElement * > gem_sh_simple_elossMu
const std::vector< const GEMRegion * > & regions() const
Return a vector of all GEM regions.
Definition: GEMGeometry.cc:43
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::string Hash
Definition: Types.h:45
std::unordered_map< UInt_t, MonitorElement * > gem_sh_simple_tofMu
bool isValid() const
Definition: HandleBase.h:74
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::unordered_map< UInt_t, MonitorElement * > Hit_dcEta
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
virtual const GeomDet * idToDet(DetId) const override
Definition: GEMGeometry.cc:38
MonitorElement * gem_sh_tofMu[2][3][2]
std::unordered_map< UInt_t, MonitorElement * > Hit_simple_zr
MonitorElement * getDCEta(DQMStore::IBooker &, const GEMStation *, TString, TString)
return(e1-e2)*(e1-e2)+dp *dp
MonitorElement * gem_sh_elossMu[2][3][2]
edm::EDGetToken InputTagToken_
void analyze(const edm::Event &e, const edm::EventSetup &) override
std::string getStationLabel(int i)
MonitorElement * gem_sh_xy[2][3][2]
double timeOfFlight(DetId id, const CaloGeometry *geo, bool debug=false)
Definition: CaloSimInfo.cc:15
GEMHitsValidation(const edm::ParameterSet &)
Definition: Run.h:42