test
CMS 3D CMS Logo

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