CMS 3D CMS Logo

GEMRecHitTrackMatch.cc
Go to the documentation of this file.
9 #include <TMath.h>
10 #include <TH1F.h>
11 
12 using namespace std;
14 {
15  std::string simInputLabel_ = ps.getUntrackedParameter<std::string>("simInputLabel");
16  simHitsToken_ = consumes<edm::PSimHitContainer>(edm::InputTag(simInputLabel_,"MuonGEMHits"));
17  simTracksToken_ = consumes< edm::SimTrackContainer >(ps.getParameter<edm::InputTag>("simTrackCollection"));
18  simVerticesToken_ = consumes< edm::SimVertexContainer >(ps.getParameter<edm::InputTag>("simVertexCollection"));
19 
20  gem_recHitToken_ = consumes<GEMRecHitCollection>(ps.getParameter<edm::InputTag>("gemRecHitInput"));
21 
22  detailPlot_ = ps.getParameter<bool>("detailPlot");
23  cfg_ = ps;
24 }
25 
27  edm::LogInfo("GEMRecHitTrackMatch")<<"GEM RecHitTrackMatch :: bookHistograms"<<std::endl;
29  iSetup.get<MuonGeometryRecord>().get(hGeom);
30  const GEMGeometry& geom = *hGeom;
31  edm::LogInfo("GEMRecHitTrackMatch")<<"GEM RecHitTrackMatch :: about to set the geometry"<<std::endl;
32  setGeometry(geom);
33  edm::LogInfo("GEMRecHitTrackMatch")<<"GEM RecHitTrackMatch :: successfully set the geometry"<<std::endl;
34  edm::LogInfo("GEMRecHitTrackMatch")<<"GEM RecHitTrackMatch :: geom = "<<&geom<<std::endl;
35 
36  ibooker.setCurrentFolder("MuonGEMRecHitsV/GEMRecHitsTask");
37  edm::LogInfo("GEMRecHitTrackMatch")<<"ibooker set current folder\n";
38 
39  const float PI=TMath::Pi();
40 
41  using namespace GEMDetLabel;
42 
43  nstation = geom.regions()[0]->stations().size();
44  for( unsigned int j=0 ; j<nstation ; j++) {
45  string track_eta_name = string("track_eta")+s_suffix.at(j);
46  string track_eta_title = string("track_eta")+";SimTrack |#eta|;# of tracks";
47  track_eta[j] = ibooker.book1D(track_eta_name.c_str(), track_eta_title.c_str(),140,minEta_,maxEta_);
48 
49  for ( unsigned int k = 0 ; k < c_suffix.size() ; k++) {
50  string suffix = string(s_suffix[j])+ string(c_suffix[k]);
51  string track_phi_name = string("track_phi")+suffix;
52  string track_phi_title = string("track_phi")+suffix+";SimTrack #phi;# of tracks";
53  track_phi[j][k] = ibooker.book1D(track_phi_name.c_str(), track_phi_title.c_str(),200,-PI,PI);
54  }
55 
56 
57  for( unsigned int i=0 ; i < l_suffix.size(); i++) {
58  string suffix = string(s_suffix[j])+string(l_suffix[i]);
59  string rh_eta_name = string("rh_eta")+suffix;
60  string rh_eta_title = rh_eta_name+"; tracks |#eta|; # of tracks";
61  rh_eta[i][j] = ibooker.book1D( rh_eta_name.c_str(), rh_eta_title.c_str(), 140, minEta_, maxEta_) ;
62 
63  string rh_sh_eta_name = string("rh_sh_eta")+suffix;
64  string rh_sh_eta_title = rh_sh_eta_name+"; tracks |#eta|; # of tracks";
65  rh_sh_eta[i][j] = ibooker.book1D( rh_sh_eta_name.c_str(), rh_sh_eta_title.c_str(), 140, minEta_, maxEta_) ;
66 
67  for ( unsigned int k = 0 ; k < c_suffix.size() ; k++) {
68  suffix = string(s_suffix[j])+string(l_suffix[i])+ string(c_suffix[k]);
69  string rh_phi_name = string("rh_phi")+suffix;
70  string rh_phi_title = rh_phi_name+"; tracks #phi; # of tracks";
71  rh_phi[i][j][k] = ibooker.book1D( (rh_phi_name).c_str(), rh_phi_title.c_str(), 200, -PI,PI) ;
72 
73  string rh_sh_phi_name = string("rh_sh_phi")+suffix;
74  string rh_sh_phi_title = rh_sh_phi_name+"; tracks #phi; # of tracks";
75  rh_sh_phi[i][j][k] = ibooker.book1D( (rh_sh_phi_name).c_str(), rh_sh_phi_title.c_str(), 200,-PI,PI) ;
76 
77  }
78  }
79  }
80 }
81 
83 
85 {
86  edm::LogInfo("GEMRecHitTrackMatch")<<"GEM RecHitTrackMatch :: analyze"<<std::endl;
88  iSetup.get<MuonGeometryRecord>().get(hGeom);
89  const GEMGeometry& geom = *hGeom;
90 
93  //edm::Handle<edm::SimVertexContainer> sim_vertices;
94  iEvent.getByToken(simHitsToken_, simhits);
95  iEvent.getByToken(simTracksToken_, sim_tracks);
96  //iEvent.getByToken(simVerticesToken_, sim_vertices);
97  //if ( !simhits.isValid() || !sim_tracks.isValid() || !sim_vertices.isValid()) return;
98  if ( !simhits.isValid() || !sim_tracks.isValid() ) return;
99 
100  //const edm::SimVertexContainer & sim_vert = *sim_vertices.product();
101  const edm::SimTrackContainer & sim_trks = *sim_tracks.product();
102 
103  MySimTrack track_;
104  for (auto& t: sim_trks)
105  {
106  if (!isSimTrackGood(t))
107  { continue; }
108 
109  // match hits and rechits to this SimTrack
110 
111  const SimHitMatcher& match_sh = SimHitMatcher( t, iEvent, geom, cfg_, simHitsToken_, simTracksToken_, simVerticesToken_);
112  const GEMRecHitMatcher& match_rh = GEMRecHitMatcher( match_sh, iEvent, geom, cfg_ ,gem_recHitToken_);
113 
114  track_.pt = t.momentum().pt();
115  //std::cout << "SimTrack pt value : " << track_.pt << "\n";
116  track_.phi = t.momentum().phi();
117  track_.eta = t.momentum().eta();
118  std::fill( std::begin(track_.hitOdd), std::end(track_.hitOdd),false);
119  std::fill( std::begin(track_.hitEven), std::end(track_.hitEven),false);
120 
121  for ( int i= 0 ; i< 3 ; i++) {
122  for ( int j= 0 ; j<2 ; j++) {
123  track_.gem_sh[i][j] = false;
124  track_.gem_rh[i][j] = false;
125  }
126  }
127 
128  // ** GEM SimHits ** //
129  const auto gem_sh_ids_ch = match_sh.chamberIdsGEM();
130  for(auto d: gem_sh_ids_ch)
131  {
132  const GEMDetId id(d);
133  if ( id.chamber() %2 ==0 ) track_.hitEven[id.station()-1] = true;
134  else if ( id.chamber() %2 ==1 ) track_.hitOdd[id.station()-1] = true;
135  else { edm::LogInfo("GEMRecHitTrackMatch")<<"Error to get chamber id"<<std::endl; }
136 
137  track_.gem_sh[ id.station()-1][ (id.layer()-1)] = true;
138 
139  }
140  // ** GEM RecHits ** //
141  const auto gem_rh_ids_ch = match_rh.chamberIds();
142 
143  for(auto d: gem_rh_ids_ch)
144  {
145  const GEMDetId id(d);
146  track_.gem_rh[ id.station()-1][ (id.layer()-1)] = true;
147  }
148 
149  FillWithTrigger( track_eta, fabs(track_.eta)) ;
150  FillWithTrigger( track_phi, fabs(track_.eta), track_.phi, track_.hitOdd, track_.hitEven);
151 
152 
153  FillWithTrigger( rh_sh_eta, track_.gem_sh , fabs( track_.eta) );
154  FillWithTrigger( rh_eta, track_.gem_rh , fabs( track_.eta) );
155 
156  // Separate station.
157 
158  FillWithTrigger( rh_sh_phi, track_.gem_sh ,fabs(track_.eta), track_.phi , track_.hitOdd, track_.hitEven);
159  FillWithTrigger( rh_phi, track_.gem_rh ,fabs(track_.eta), track_.phi , track_.hitOdd, track_.hitEven);
160 
161 
162  /*
163 
164  // Calculation of the localXY efficiency
165  GlobalPoint gp_track(match_sh.propagatedPositionGEM());
166 
167  float track_angle = gp_track.phi().degrees();
168  if (track_angle < 0.) track_angle += 360.;
169  const int track_region = (gp_track.z() > 0 ? 1 : -1);
170 
171  // closest chambers in phi
172  const auto mypair = getClosestChambers(track_region, track_angle);
173 
174  GEMDetId detId_first(mypair.first);
175  GEMDetId detId_second(mypair.second);
176 
177  // assignment of local even and odd chambers (there is always an even and an odd chamber)
178  bool firstIsOdd = detId_first.chamber() & 1;
179 
180  GEMDetId detId_even_L1(firstIsOdd ? detId_second : detId_first);
181  GEMDetId detId_odd_L1(firstIsOdd ? detId_first : detId_second);
182 
183  auto even_partition = theGEMGeometry->idToDetUnit(detId_even_L1)->surface();
184  auto odd_partition = theGEMGeometry->idToDetUnit(detId_odd_L1)->surface();
185 
186  LocalPoint p0(0.,0.,0.);
187  GlobalPoint gp_even_partition = even_partition.toGlobal(p0);
188  GlobalPoint gp_odd_partition = odd_partition.toGlobal(p0);
189 
190  LocalPoint lp_track_even_partition = even_partition.toLocal(gp_track);
191  LocalPoint lp_track_odd_partition = odd_partition.toLocal(gp_track);
192 
193  // track chamber local x is the same as track partition local x
194  track_.gem_lx_even = lp_track_even_partition.x();
195  track_.gem_lx_odd = lp_track_odd_partition.x();
196 
197  // track chamber local y is the same as track partition local y
198  // corrected for partition's local y WRT chamber
199  track_.gem_ly_even = lp_track_even_partition.y() + (gp_even_partition.perp() - radiusCenter_);
200  track_.gem_ly_odd = lp_track_odd_partition.y() + (gp_odd_partition.perp() - radiusCenter_);
201 
202  GEMDetId id_ch_even_L1(detId_even_L1.region(), detId_even_L1.ring(), detId_even_L1.station(), 1, detId_even_L1.chamber(), 0);
203  GEMDetId id_ch_odd_L1(detId_odd_L1.region(), detId_odd_L1.ring(), detId_odd_L1.station(), 1, detId_odd_L1.chamber(), 0);
204  GEMDetId id_ch_even_L2(detId_even_L1.region(), detId_even_L1.ring(), detId_even_L1.station(), 2, detId_even_L1.chamber(), 0);
205  GEMDetId id_ch_odd_L2(detId_odd_L1.region(), detId_odd_L1.ring(), detId_odd_L1.station(), 2, detId_odd_L1.chamber(), 0);
206 
207  if(gem_sh_ids_ch.count(id_ch_even_L1)!=0) track_.has_gem_sh_l1 |= 2;
208  if(gem_sh_ids_ch.count(id_ch_odd_L1)!=0) track_.has_gem_sh_l1 |= 1;
209  if(gem_sh_ids_ch.count(id_ch_even_L2)!=0) track_.has_gem_sh_l2 |= 2;
210  if(gem_sh_ids_ch.count(id_ch_odd_L2)!=0) track_.has_gem_sh_l2 |= 1;
211 
212  // check if track has dg
213  if(gem_dg_ids_ch.count(id_ch_even_L1)!=0){
214  track_.has_gem_dg_l1 |= 2;
215  track_.has_gem_pad_l1 |= 2;
216  }
217  if(gem_dg_ids_ch.count(id_ch_odd_L1)!=0){
218  track_.has_gem_dg_l1 |= 1;
219  track_.has_gem_pad_l1 |= 1;
220  }
221  if(gem_dg_ids_ch.count(id_ch_even_L2)!=0){
222  track_.has_gem_dg_l2 |= 2;
223  track_.has_gem_pad_l2 |= 2;
224  }
225  if(gem_dg_ids_ch.count(id_ch_odd_L2)!=0){
226  track_.has_gem_dg_l2 |= 1;
227  track_.has_gem_pad_l2 |= 1;
228  }
229  dg_lx_even->Fill( track_.gem_lx_even);
230  dg_lx_odd->Fill( track_.gem_lx_odd);
231  dg_ly_even->Fill( track_.gem_ly_even);
232  dg_ly_odd->Fill( track_.gem_ly_odd);
233 
234  if ( track_.has_gem_dg_l1 /2 >= 1 ) {
235  dg_lx_even_l1->Fill ( track_.gem_lx_even);
236  dg_ly_even_l1->Fill ( track_.gem_ly_even);
237  }
238  if ( track_.has_gem_dg_l1 %2 == 1 ) {
239  dg_lx_odd_l1->Fill ( track_.gem_lx_odd);
240  dg_ly_odd_l1->Fill ( track_.gem_ly_odd);
241  }
242  if ( track_.has_gem_dg_l2 /2 >=1 ) {
243  dg_lx_even_l2->Fill ( track_.gem_lx_even);
244  dg_ly_even_l2->Fill ( track_.gem_ly_even);
245  }
246  if ( track_.has_gem_dg_l2 %2 == 1 ) {
247  dg_lx_odd_l2->Fill ( track_.gem_lx_odd);
248  dg_ly_odd_l2->Fill ( track_.gem_ly_odd);
249  }
250  if ( track_.has_gem_dg_l1 /2 >=1 || track_.has_gem_dg_l2 /2 >=1 ) {
251  dg_lx_even_l1or2->Fill ( track_.gem_lx_even);
252  dg_ly_even_l1or2->Fill ( track_.gem_ly_even);
253  }
254  if ( track_.has_gem_dg_l1 %2 ==1 || track_.has_gem_dg_l2 %2 ==1 ) {
255  dg_lx_odd_l1or2->Fill ( track_.gem_lx_odd);
256  dg_ly_odd_l1or2->Fill ( track_.gem_ly_odd);
257  }
258  if ( track_.has_gem_dg_l1 /2 >=1 && track_.has_gem_dg_l2 /2 >=1 ) {
259  dg_lx_even_l1and2->Fill ( track_.gem_lx_even);
260  dg_ly_even_l1and2->Fill ( track_.gem_ly_even);
261  }
262  if ( track_.has_gem_dg_l1 %2 ==1 && track_.has_gem_dg_l2 %2 ==1 ) {
263  dg_lx_odd_l1and2->Fill ( track_.gem_lx_odd);
264  dg_ly_odd_l1and2->Fill ( track_.gem_ly_odd);
265  }
266 */
267 
268  }
269 }
const double Pi
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::set< unsigned int > chamberIds() const
unsigned int nstation
Definition: GEMTrackMatch.h:80
static const std::array< std::string, 4 > l_suffix
Definition: GEMDetLabel.h:4
MonitorElement * rh_phi[4][3][3]
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
MonitorElement * track_phi[3][3]
edm::ParameterSet cfg_
Definition: GEMTrackMatch.h:63
std::set< unsigned int > chamberIdsGEM() const
GEM chamber detIds with SimHits.
edm::EDGetToken simHitsToken_
Definition: GEMTrackMatch.h:64
edm::EDGetToken simVerticesToken_
Definition: GEMTrackMatch.h:66
MonitorElement * rh_sh_phi[4][3][3]
bool hitOdd[3]
Definition: GEMTrackMatch.h:38
Float_t eta
Definition: GEMTrackMatch.h:27
void setGeometry(const GEMGeometry &geom)
GEMRecHitTrackMatch(const edm::ParameterSet &ps)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
MonitorElement * rh_sh_eta[4][3]
static const std::array< std::string, 2 > s_suffix
Definition: GEMDetLabel.h:5
int iEvent
Definition: GenABIO.cc:230
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
edm::EDGetToken simTracksToken_
Definition: GEMTrackMatch.h:65
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:106
#define end
Definition: vmac.h:39
edm::EDGetToken gem_recHitToken_
bool isValid() const
Definition: HandleBase.h:74
#define PI
Definition: QcdUeDQM.h:36
int k[5][pyjets_maxn]
bool hitEven[3]
Definition: GEMTrackMatch.h:39
Float_t pt
Definition: GEMTrackMatch.h:27
T const * product() const
Definition: Handle.h:81
MonitorElement * track_eta[3]
void FillWithTrigger(MonitorElement *me[3], Float_t eta)
#define begin
Definition: vmac.h:32
T get() const
Definition: EventSetup.h:68
void analyze(const edm::Event &e, const edm::EventSetup &) override
MonitorElement * rh_eta[4][3]
Float_t phi
Definition: GEMTrackMatch.h:27
bool isSimTrackGood(const SimTrack &)
bool gem_rh[3][2]
Definition: GEMTrackMatch.h:37
bool gem_sh[3][2]
Definition: GEMTrackMatch.h:34
std::vector< SimTrack > SimTrackContainer
static const std::array< std::string, 3 > c_suffix
Definition: GEMDetLabel.h:6
Definition: Run.h:44