CMS 3D CMS Logo

MuonTiming.cc
Go to the documentation of this file.
2 
7 
10 
12 
13 #include <string>
14 #include "TMath.h"
15 using namespace std;
16 using namespace edm;
17 
18 
19 
22 
23  // Input booleans
24 
25  // the services:
26  theService = new MuonServiceProxy(parameters.getParameter<ParameterSet>("ServiceParameters"));
27  theMuonCollectionLabel_ = consumes<edm::View<reco::Muon> > (parameters.getParameter<edm::InputTag>("MuonCollection"));
28 
29  tnbins_ = parameters.getParameter<int>("tnbins");
30  tnbinsrpc_ = parameters.getParameter<int>("tnbinsrpc");
31  terrnbins_ = parameters.getParameter<int>("terrnbins");
32  terrnbinsrpc_ = parameters.getParameter<int>("terrnbinsrpc");
33  ndofnbins_ = parameters.getParameter<int>("ndofnbins");
34  ptnbins_ = parameters.getParameter<int>("ptnbins");
35  etanbins_ = parameters.getParameter<int>("etanbins");
36  tmax_ = parameters.getParameter<double>("tmax");
37  tmaxrpc_ = parameters.getParameter<double>("tmaxrpc");
38  terrmax_ = parameters.getParameter<double>("terrmax");
39  terrmaxrpc_ = parameters.getParameter<double>("terrmaxrpc");
40  ndofmax_ = parameters.getParameter<double>("ndofmax");
41  ptmax_ = parameters.getParameter<double>("ptmax");
42  etamax_ = parameters.getParameter<double>("etamax");
43  tmin_ = parameters.getParameter<double>("tmin");
44  tminrpc_ = parameters.getParameter<double>("tminrpc");
45  terrmin_ = parameters.getParameter<double>("terrmin");
46  terrminrpc_ = parameters.getParameter<double>("terrminrpc");
47  ndofmin_ = parameters.getParameter<double>("ndofmin");
48  ptmin_ = parameters.getParameter<double>("ptmin");
49  etamin_ = parameters.getParameter<double>("etamin");
50 
51  etaBarrelMin_ = parameters.getParameter<double>("etaBarrelMin");
52  etaBarrelMax_ = parameters.getParameter<double>("etaBarrelMax");
53  etaEndcapMin_ = parameters.getParameter<double>("etaEndcapMin");
54  etaEndcapMax_ = parameters.getParameter<double>("etaEndcapMax");
55  etaOverlapMin_ = parameters.getParameter<double>("etaOverlapMin");
56  etaOverlapMax_ = parameters.getParameter<double>("etaOverlapMax");
57 
58  theFolder_ = parameters.getParameter<string>("folder");
59 }
60 
61 
63  delete theService;
64 }
65 
67  edm::Run const & /*iRun*/,
68  edm::EventSetup const & /* iSetup */){
69 
70  ibooker.cd();
71  ibooker.setCurrentFolder(theFolder_);
72 
73  EtaName_.push_back("_Overlap"); EtaName_.push_back("_Barrel"); EtaName_.push_back("_Endcap");
74  ObjectName_.push_back("Sta_"); ObjectName_.push_back("Glb_");
75 
76  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
77  /*std::array<MonitorElement*, 1> timeNDofv_;
78  std::array<MonitorElement*, 1> timeAtIpInOutv_;
79  std::array<MonitorElement*, 1> timeAtIpInOutRPCv_;
80  std::array<MonitorElement*, 1> timeAtIpInOutErrv_;
81  std::array<MonitorElement*, 1> timeAtIpInOutErrRPCv_;*/
82  //Only creating so far the timing information for STA muons, however the code can be extended to also Glb by just setting the limit of this loop to 2
83  for(unsigned int iObjectName=0; iObjectName<1; iObjectName++) {
84  timeNDof_[iEtaRegion][iObjectName] = ibooker.book1D(ObjectName_[iObjectName] + "timenDOF" + EtaName_[iEtaRegion], "muon time ndof", ndofnbins_, 0, ndofmax_);
85  timeAtIpInOut_[iEtaRegion][iObjectName] = ibooker.book1D(ObjectName_[iObjectName] + "timeAtIpInOut" + EtaName_[iEtaRegion], "muon time", tnbins_, tmin_, tmax_);
86  timeAtIpInOutRPC_[iEtaRegion][iObjectName] = ibooker.book1D(ObjectName_[iObjectName] + "timeAtIpInOutRPC" + EtaName_[iEtaRegion], "muon rpc time", tnbinsrpc_, tminrpc_, tmaxrpc_);
87  timeAtIpInOutErr_[iEtaRegion][iObjectName] = ibooker.book1D(ObjectName_[iObjectName] + "timeAtIpInOutErr" + EtaName_[iEtaRegion], "muon time error", terrnbins_, terrmin_, terrmax_);
88  timeAtIpInOutErrRPC_[iEtaRegion][iObjectName] = ibooker.book1D(ObjectName_[iObjectName] + "timeAtIpInOutRPCErr" + EtaName_[iEtaRegion], "muon rpc time error", terrnbinsrpc_, terrminrpc_, terrmaxrpc_);
89  timeNDof_[iEtaRegion][iObjectName]->setAxisTitle("Time nDof");
90  timeAtIpInOut_[iEtaRegion][iObjectName]->setAxisTitle("Combined time [ns]");
91  timeAtIpInOutErr_[iEtaRegion][iObjectName]->setAxisTitle("Combined time Error [ns]");
92  timeAtIpInOutRPC_[iEtaRegion][iObjectName]->setAxisTitle("RPC time [ns]");
93  timeAtIpInOutErrRPC_[iEtaRegion][iObjectName]->setAxisTitle("RPC time Error [ns]");
94  }
95  /*
96  timeNDof_[iEtaregion] = timeNDofv_);
97  timeAtIpInOut_.push_back(timeAtIpInOutv_);
98  timeAtIpInOutRPC_.push_back(timeAtIpInOutRPCv_);
99  timeAtIpInOutErr_.push_back(timeAtIpInOutErrv_);
100  timeAtIpInOutErrRPC_.push_back(timeAtIpInOutErrRPCv_);
101  */
102  }
103 
104  //Only creating so far the timing information for STA muons, however the code can be extended to also Glb by just setting the limit of this loop to 2
105  for(unsigned int iObjectName=0; iObjectName<1; iObjectName++) {
106  etaptVeto_[iObjectName] = ibooker.book2D(ObjectName_[iObjectName] + "etapt", "Eta and Pt distribution for muons not passing the veto", ptnbins_, ptmin_, ptmax_, etanbins_, etamin_, etamax_);
107  etaVeto_[iObjectName] = ibooker.book1D(ObjectName_[iObjectName] + "eta", "Eta distribution for muons not passing the veto", etanbins_, etamin_, etamax_);
108  ptVeto_[iObjectName] = ibooker.book1D(ObjectName_[iObjectName] + "pt", "Pt distribution for muons not passing the veto", ptnbins_, ptmin_, ptmax_);
109  yields_[iObjectName] = ibooker.book1D(ObjectName_[iObjectName] + "yields", "Number of muons passing/not passing the different conditions", 10, 0, 10);
110  yields_[iObjectName]->setBinLabel(1, "Not valid time");
111  yields_[iObjectName]->setBinLabel(2, "Valid time");
112  yields_[iObjectName]->setBinLabel(3, "Not Combined time");
113  yields_[iObjectName]->setBinLabel(4, "Combined time");
114  yields_[iObjectName]->setBinLabel(5, "Not RPC time");
115  yields_[iObjectName]->setBinLabel(6, "RPC time");
116  yields_[iObjectName]->setBinLabel(7, "Combined not RPC");
117  yields_[iObjectName]->setBinLabel(8, "RPC not Combined");
118  yields_[iObjectName]->setBinLabel(9, "Not passing veto");
119  yields_[iObjectName]->setBinLabel(10, "Passing veto");
120  etaptVeto_[iObjectName]->setAxisTitle("p_{T} [GeV]");
121  etaptVeto_[iObjectName]->setAxisTitle("#eta#", 2);
122  ptVeto_[iObjectName]->setAxisTitle("p_{T} [GeV]");
123  etaVeto_[iObjectName]->setAxisTitle("#eta");
124  }
125 
126 }
127 
128 
129 
131 
132  LogTrace(metname_)<<"[MuonTiming] Analyze the mu";
133  theService->update(iSetup);
134 
135  // Take the muon container
137  iEvent.getByToken(theMuonCollectionLabel_,muons);
138 
139 
140  if(!muons.isValid()) return;
141 
142  for (edm::View<reco::Muon>::const_iterator muon = muons->begin(); muon != muons->end(); ++muon){
143  const reco::MuonTime time = muon->time();
144  const reco::MuonTime rpcTime = muon->rpcTime();
145  //Only creating so far the timing information for STA muons
146  if(!muon->isStandAloneMuon() || muon->isGlobalMuon()) continue;
148  //Select whether it's a global or standalone muon
149  object_ theObject = sta;
150  if(muon->isGlobalMuon()) {track = muon->combinedMuon(); theObject = glb;}
151  else {track = muon->standAloneMuon(); theObject = sta;}
152 
153  //These definitions have been taken from Piotr Traczyk
154  bool cmbok =(time.nDof > 7);
155  bool rpcok =(rpcTime.nDof > 1 && rpcTime.timeAtIpInOutErr == 0);
156  bool veto = false;
157  if (rpcok) {
158  if ((fabs(rpcTime.timeAtIpInOut) > 10) && !(cmbok && fabs(time.timeAtIpInOut)<10)) veto=true;
159  else if (cmbok && (time.timeAtIpInOut > 20 || time.timeAtIpInOut<-45)) veto=true;
160  }
161 
162  //std::cout << time.timeAtIpInOut << std::endl;
163  //Filling the yields histogram
164  if(muon->isTimeValid()) yields_[theObject]->Fill(1);
165  else yields_[theObject]->Fill(0);
166 
167  if(cmbok) yields_[theObject]->Fill(3);
168  else yields_[theObject]->Fill(2);
169 
170  if(rpcok) yields_[theObject]->Fill(5);
171  else yields_[theObject]->Fill(4);
172 
173  if(cmbok && !rpcok) yields_[theObject]->Fill(6);
174  if(!cmbok && rpcok) yields_[theObject]->Fill(7);
175 
176  if(veto) yields_[theObject]->Fill(8);
177  else yields_[theObject]->Fill(9);
178 
179  //Starting now with the pt and eta for vetoed and not vetoed muons
180  if(veto) {
181  etaptVeto_[theObject]->Fill(track->pt(), track->eta());
182  etaVeto_[theObject]->Fill(track->eta());
183  ptVeto_[theObject]->Fill(track->pt());
184  }
185 
186  //Check the eta region of the muon
187  eta_ theEta = barrel;
188  if(fabs(track->eta()) >= etaBarrelMin_ && fabs(track->eta()) <= etaBarrelMax_) theEta = barrel;
189  if(fabs(track->eta()) >= etaOverlapMin_ && fabs(track->eta()) <= etaOverlapMax_) theEta = overlap;
190  if(fabs(track->eta()) >= etaEndcapMin_ && fabs(track->eta()) <= etaEndcapMax_) theEta = endcap;
191  timeNDof_[theEta][theObject]->Fill(time.nDof);
192  timeAtIpInOut_[theEta][theObject]->Fill(time.timeAtIpInOut);
193  timeAtIpInOutRPC_[theEta][theObject]->Fill(rpcTime.timeAtIpInOut);
194  timeAtIpInOutErr_[theEta][theObject]->Fill(time.timeAtIpInOutErr);
195  timeAtIpInOutErrRPC_[theEta][theObject]->Fill(rpcTime.timeAtIpInOutErr);
196 
197  }
198 }
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
void cd(void)
Definition: DQMStore.cc:269
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: MuonTiming.cc:66
double glb
Definition: hdecay.h:105
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
virtual ~MuonTiming()
Destructor.
Definition: MuonTiming.cc:62
bool overlap(const reco::Muon &muon1, const reco::Muon &muon2, double pullX=1.0, double pullY=1.0, bool checkAdjacentChambers=false)
int iEvent
Definition: GenABIO.cc:230
void analyze(const edm::Event &, const edm::EventSetup &) override
Inizialize parameters for histo binning.
Definition: MuonTiming.cc:130
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
float timeAtIpInOutErr
Definition: MuonTime.h:15
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
int nDof
number of muon stations used
Definition: MuonTime.h:10
bool isValid() const
Definition: HandleBase.h:74
#define LogTrace(id)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
MuonTiming(const edm::ParameterSet &)
Constructor.
Definition: MuonTiming.cc:20
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
float timeAtIpInOut
Definition: MuonTime.h:14
Definition: Run.h:42