CMS 3D CMS Logo

GEMSimTrackMatch.cc
Go to the documentation of this file.
7 #include <TMath.h>
8 #include <TH1F.h>
9 
10 using namespace std;
11 using namespace GEMDetLabel;
13 {
14  std::string simInputLabel_ = ps.getUntrackedParameter<std::string>("simInputLabel");
15 
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  detailPlot_ = ps.getParameter<bool>("detailPlot");
20 
21  cfg_ = ps;
22 }
23 
25 {
26  // Mandantory
28  iSetup.get<MuonGeometryRecord>().get(hGeom);
29  const GEMGeometry& geom = *hGeom;
30  setGeometry(geom);
31 
32  ibooker.setCurrentFolder("MuonGEMHitsV/GEMHitsTask");
33  LogDebug("GEMSimTrackMatch")<<"ibooker set current folder\n";
34 
35  const float PI=TMath::Pi();
36 
37  nstation = geom.regions()[0]->stations().size();
38  if ( detailPlot_) {
39  for( unsigned int j=0 ; j<nstation ; j++) {
40  string track_eta_name = string("track_eta")+s_suffix[j];
41  string track_eta_title = string("track_eta")+";SimTrack |#eta|;# of tracks";
42  track_eta[j] = ibooker.book1D(track_eta_name.c_str(), track_eta_title.c_str(),140,minEta_,maxEta_);
43 
44  for ( unsigned int k = 0 ; k<3 ; k++) {
45  string suffix = string(s_suffix[j])+ string(c_suffix[k]);
46  string track_phi_name = string("track_phi")+suffix;
47  string track_phi_title = string("track_phi")+suffix+";SimTrack #phi;# of tracks";
48  track_phi[j][k] = ibooker.book1D(track_phi_name.c_str(), track_phi_title.c_str(),200,-PI,PI);
49  }
50 
51  for( unsigned int i=0 ; i< 4; i++) {
52  string suffix = string(s_suffix[j])+l_suffix[i];
53 
54  string sh_eta_name = string("sh_eta")+suffix;
55  string sh_eta_title = sh_eta_name+"; tracks |#eta|; # of tracks";
56  sh_eta[i][j] = ibooker.book1D( sh_eta_name.c_str(), sh_eta_title.c_str(), 140, minEta_, maxEta_) ;
57 
58  for ( unsigned int k = 0 ; k<3 ; k++) {
59  suffix = string(s_suffix[j])+ string(l_suffix[i])+string(c_suffix[k]);
60  string sh_phi_name = string("sh_phi")+suffix;
61  string sh_phi_title = sh_phi_name+"; tracks #phi; # of tracks";
62  sh_phi[i][j][k] = ibooker.book1D( (sh_phi_name).c_str(), sh_phi_title.c_str(), 200,-PI,PI) ;
63 
64  }
65  }
66  }
67  }
68 }
69 
70 
71 
72 
73 
75 }
76 
78 {
80  iSetup.get<MuonGeometryRecord>().get(hGeom);
81  const GEMGeometry& geom = *hGeom;
82 
83  MySimTrack track_;
87 
88  iEvent.getByToken(simHitsToken_, simhits);
89  iEvent.getByToken(simTracksToken_, sim_tracks);
90  iEvent.getByToken(simVerticesToken_, sim_vertices);
91  if ( !simhits.isValid() || !sim_tracks.isValid() || !sim_vertices.isValid()) return;
92 
93  //const edm::SimVertexContainer & sim_vert = *sim_vertices.product();
94  const edm::SimTrackContainer & sim_trks = *sim_tracks.product();
95 
96 
97  if ( detailPlot_) {
98 
99  for (auto& t: sim_trks)
100  {
101  if (!isSimTrackGood(t))
102  { continue; }
103 
104  track_.pt = t.momentum().pt();
105  track_.phi = t.momentum().phi();
106  track_.eta = t.momentum().eta();
107  std::fill( std::begin(track_.hitOdd), std::end(track_.hitOdd),false);
108  std::fill( std::begin(track_.hitEven), std::end(track_.hitEven),false);
109  for( int i=0 ; i<3 ; i++) {
110  for (int j=0 ; j<2 ; j++) {
111  track_.gem_sh[i][j] = false;
112  }
113  }
114 
115  // match hits to this SimTrack
116  const SimHitMatcher match_sh = SimHitMatcher( t, iEvent, geom, cfg_, simHitsToken_, simTracksToken_, simVerticesToken_ );
117 
118  // check for hit chambers
119  const auto gem_sh_ids_ch = match_sh.chamberIdsGEM();
120 
121  for(auto d: gem_sh_ids_ch)
122  {
123  const GEMDetId id(d);
124  if ( id.chamber() %2 ==0 ) track_.hitEven[id.station()-1] = true;
125  else if ( id.chamber() %2 ==1 ) track_.hitOdd[id.station()-1] = true;
126  else { std::cout<<"Error to get chamber id"<<std::endl;}
127  track_.gem_sh[ id.station()-1][ (id.layer()-1)] = true;
128  }
129  FillWithTrigger( track_eta, fabs(track_.eta)) ;
130  FillWithTrigger( track_phi, fabs(track_.eta), track_.phi, track_.hitOdd, track_.hitEven);
131  FillWithTrigger( sh_eta, track_.gem_sh , fabs( track_.eta) );
132  FillWithTrigger( sh_phi, track_.gem_sh ,fabs(track_.eta), track_.phi , track_.hitOdd, track_.hitEven);
133  }
134  }
135 }
136 
#define LogDebug(id)
const double Pi
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
unsigned int nstation
Definition: GEMTrackMatch.h:80
static const std::array< std::string, 4 > l_suffix
Definition: GEMDetLabel.h:4
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
MonitorElement * track_eta[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
void analyze(const edm::Event &e, const edm::EventSetup &) override
bool hitOdd[3]
Definition: GEMTrackMatch.h:38
Float_t eta
Definition: GEMTrackMatch.h:27
void setGeometry(const GEMGeometry &geom)
static const std::array< std::string, 2 > s_suffix
Definition: GEMDetLabel.h:5
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:118
#define end
Definition: vmac.h:39
bool isValid() const
Definition: HandleBase.h:74
#define PI
Definition: QcdUeDQM.h:36
GEMSimTrackMatch(const edm::ParameterSet &ps)
int k[5][pyjets_maxn]
MonitorElement * track_phi[3][3]
bool hitEven[3]
Definition: GEMTrackMatch.h:39
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
MonitorElement * sh_phi[4][3][3]
Float_t pt
Definition: GEMTrackMatch.h:27
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:279
T const * product() const
Definition: Handle.h:81
MonitorElement * sh_eta[4][3]
const T & get() const
Definition: EventSetup.h:59
void FillWithTrigger(MonitorElement *me[3], Float_t eta)
#define begin
Definition: vmac.h:32
Float_t phi
Definition: GEMTrackMatch.h:27
bool isSimTrackGood(const SimTrack &)
~GEMSimTrackMatch() override
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:43