Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:09:42

0001 #include "DQMOffline/Muon/interface/MuonTiming.h"
0002 
0003 #include "DataFormats/Common/interface/Handle.h"
0004 #include "DataFormats/MuonReco/interface/Muon.h"
0005 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0006 #include "DataFormats/MuonReco/interface/MuonEnergy.h"
0007 
0008 #include "DataFormats/TrackReco/interface/Track.h"
0009 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0010 
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 
0013 #include <string>
0014 #include "TMath.h"
0015 using namespace std;
0016 using namespace edm;
0017 
0018 MuonTiming::MuonTiming(const edm::ParameterSet& pSet) {
0019   const edm::ParameterSet& parameters = pSet;
0020 
0021   // Input booleans
0022 
0023   // the services:
0024   theMuonCollectionLabel_ = consumes<edm::View<reco::Muon> >(parameters.getParameter<edm::InputTag>("MuonCollection"));
0025 
0026   tnbins_ = parameters.getParameter<int>("tnbins");
0027   tnbinsrpc_ = parameters.getParameter<int>("tnbinsrpc");
0028   terrnbins_ = parameters.getParameter<int>("terrnbins");
0029   terrnbinsrpc_ = parameters.getParameter<int>("terrnbinsrpc");
0030   ndofnbins_ = parameters.getParameter<int>("ndofnbins");
0031   ptnbins_ = parameters.getParameter<int>("ptnbins");
0032   etanbins_ = parameters.getParameter<int>("etanbins");
0033   tmax_ = parameters.getParameter<double>("tmax");
0034   tmaxrpc_ = parameters.getParameter<double>("tmaxrpc");
0035   terrmax_ = parameters.getParameter<double>("terrmax");
0036   terrmaxrpc_ = parameters.getParameter<double>("terrmaxrpc");
0037   ndofmax_ = parameters.getParameter<double>("ndofmax");
0038   ptmax_ = parameters.getParameter<double>("ptmax");
0039   etamax_ = parameters.getParameter<double>("etamax");
0040   tmin_ = parameters.getParameter<double>("tmin");
0041   tminrpc_ = parameters.getParameter<double>("tminrpc");
0042   terrmin_ = parameters.getParameter<double>("terrmin");
0043   terrminrpc_ = parameters.getParameter<double>("terrminrpc");
0044   ndofmin_ = parameters.getParameter<double>("ndofmin");
0045   ptmin_ = parameters.getParameter<double>("ptmin");
0046   etamin_ = parameters.getParameter<double>("etamin");
0047 
0048   etaBarrelMin_ = parameters.getParameter<double>("etaBarrelMin");
0049   etaBarrelMax_ = parameters.getParameter<double>("etaBarrelMax");
0050   etaEndcapMin_ = parameters.getParameter<double>("etaEndcapMin");
0051   etaEndcapMax_ = parameters.getParameter<double>("etaEndcapMax");
0052   etaOverlapMin_ = parameters.getParameter<double>("etaOverlapMin");
0053   etaOverlapMax_ = parameters.getParameter<double>("etaOverlapMax");
0054 
0055   theFolder_ = parameters.getParameter<string>("folder");
0056 }
0057 
0058 MuonTiming::~MuonTiming() {}
0059 
0060 void MuonTiming::bookHistograms(DQMStore::IBooker& ibooker,
0061                                 edm::Run const& /*iRun*/,
0062                                 edm::EventSetup const& /* iSetup */) {
0063   ibooker.cd();
0064   ibooker.setCurrentFolder(theFolder_);
0065 
0066   EtaName_.push_back("_Overlap");
0067   EtaName_.push_back("_Barrel");
0068   EtaName_.push_back("_Endcap");
0069   ObjectName_.push_back("Sta_");
0070   ObjectName_.push_back("Glb_");
0071 
0072   for (unsigned int iEtaRegion = 0; iEtaRegion < 3; iEtaRegion++) {
0073     /*std::array<MonitorElement*, 1> timeNDofv_;
0074     std::array<MonitorElement*, 1> timeAtIpInOutv_;
0075     std::array<MonitorElement*, 1> timeAtIpInOutRPCv_;
0076     std::array<MonitorElement*, 1> timeAtIpInOutErrv_;
0077     std::array<MonitorElement*, 1> timeAtIpInOutErrRPCv_;*/
0078     //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
0079     for (unsigned int iObjectName = 0; iObjectName < 1; iObjectName++) {
0080       timeNDof_[iEtaRegion][iObjectName] = ibooker.book1D(
0081           ObjectName_[iObjectName] + "timenDOF" + EtaName_[iEtaRegion], "muon time ndof", ndofnbins_, 0, ndofmax_);
0082       timeAtIpInOut_[iEtaRegion][iObjectName] = ibooker.book1D(
0083           ObjectName_[iObjectName] + "timeAtIpInOut" + EtaName_[iEtaRegion], "muon time", tnbins_, tmin_, tmax_);
0084       timeAtIpInOutRPC_[iEtaRegion][iObjectName] =
0085           ibooker.book1D(ObjectName_[iObjectName] + "timeAtIpInOutRPC" + EtaName_[iEtaRegion],
0086                          "muon rpc time",
0087                          tnbinsrpc_,
0088                          tminrpc_,
0089                          tmaxrpc_);
0090       timeAtIpInOutErr_[iEtaRegion][iObjectName] =
0091           ibooker.book1D(ObjectName_[iObjectName] + "timeAtIpInOutErr" + EtaName_[iEtaRegion],
0092                          "muon time error",
0093                          terrnbins_,
0094                          terrmin_,
0095                          terrmax_);
0096       timeAtIpInOutErrRPC_[iEtaRegion][iObjectName] =
0097           ibooker.book1D(ObjectName_[iObjectName] + "timeAtIpInOutRPCErr" + EtaName_[iEtaRegion],
0098                          "muon rpc time error",
0099                          terrnbinsrpc_,
0100                          terrminrpc_,
0101                          terrmaxrpc_);
0102       timeNDof_[iEtaRegion][iObjectName]->setAxisTitle("Time nDof");
0103       timeAtIpInOut_[iEtaRegion][iObjectName]->setAxisTitle("Combined time [ns]");
0104       timeAtIpInOutErr_[iEtaRegion][iObjectName]->setAxisTitle("Combined time Error [ns]");
0105       timeAtIpInOutRPC_[iEtaRegion][iObjectName]->setAxisTitle("RPC time [ns]");
0106       timeAtIpInOutErrRPC_[iEtaRegion][iObjectName]->setAxisTitle("RPC time Error [ns]");
0107     }
0108     /*
0109     timeNDof_[iEtaregion] = timeNDofv_);
0110     timeAtIpInOut_.push_back(timeAtIpInOutv_);
0111     timeAtIpInOutRPC_.push_back(timeAtIpInOutRPCv_);
0112     timeAtIpInOutErr_.push_back(timeAtIpInOutErrv_);
0113     timeAtIpInOutErrRPC_.push_back(timeAtIpInOutErrRPCv_);
0114     */
0115   }
0116 
0117   //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
0118   for (unsigned int iObjectName = 0; iObjectName < 1; iObjectName++) {
0119     etaptVeto_[iObjectName] = ibooker.book2D(ObjectName_[iObjectName] + "etapt",
0120                                              "Eta and Pt distribution for muons not passing the veto",
0121                                              ptnbins_,
0122                                              ptmin_,
0123                                              ptmax_,
0124                                              etanbins_,
0125                                              etamin_,
0126                                              etamax_);
0127     etaVeto_[iObjectName] = ibooker.book1D(ObjectName_[iObjectName] + "eta",
0128                                            "Eta distribution for muons not passing the veto",
0129                                            etanbins_,
0130                                            etamin_,
0131                                            etamax_);
0132     ptVeto_[iObjectName] = ibooker.book1D(
0133         ObjectName_[iObjectName] + "pt", "Pt distribution for muons not passing the veto", ptnbins_, ptmin_, ptmax_);
0134     yields_[iObjectName] = ibooker.book1D(
0135         ObjectName_[iObjectName] + "yields", "Number of muons passing/not passing the different conditions", 10, 0, 10);
0136     yields_[iObjectName]->setBinLabel(1, "Not valid time");
0137     yields_[iObjectName]->setBinLabel(2, "Valid time");
0138     yields_[iObjectName]->setBinLabel(3, "Not Combined time");
0139     yields_[iObjectName]->setBinLabel(4, "Combined time");
0140     yields_[iObjectName]->setBinLabel(5, "Not RPC time");
0141     yields_[iObjectName]->setBinLabel(6, "RPC time");
0142     yields_[iObjectName]->setBinLabel(7, "Combined not RPC");
0143     yields_[iObjectName]->setBinLabel(8, "RPC not Combined");
0144     yields_[iObjectName]->setBinLabel(9, "Not passing veto");
0145     yields_[iObjectName]->setBinLabel(10, "Passing veto");
0146     etaptVeto_[iObjectName]->setAxisTitle("p_{T} [GeV]");
0147     etaptVeto_[iObjectName]->setAxisTitle("#eta#", 2);
0148     ptVeto_[iObjectName]->setAxisTitle("p_{T} [GeV]");
0149     etaVeto_[iObjectName]->setAxisTitle("#eta");
0150   }
0151 }
0152 
0153 void MuonTiming::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0154   LogTrace(metname_) << "[MuonTiming] Analyze the mu";
0155 
0156   // Take the muon container
0157   edm::Handle<edm::View<reco::Muon> > muons;
0158   iEvent.getByToken(theMuonCollectionLabel_, muons);
0159 
0160   if (!muons.isValid())
0161     return;
0162 
0163   for (edm::View<reco::Muon>::const_iterator muon = muons->begin(); muon != muons->end(); ++muon) {
0164     const reco::MuonTime time = muon->time();
0165     const reco::MuonTime rpcTime = muon->rpcTime();
0166     //Only creating so far the timing information for STA muons
0167     if (!muon->isStandAloneMuon() || muon->isGlobalMuon())
0168       continue;
0169     reco::TrackRef track;
0170     //Select whether it's a global or standalone muon
0171     object_ theObject = sta;
0172     if (muon->isGlobalMuon()) {
0173       track = muon->combinedMuon();
0174       theObject = glb;
0175     } else {
0176       track = muon->standAloneMuon();
0177       theObject = sta;
0178     }
0179 
0180     //These definitions have been taken from Piotr Traczyk
0181     bool cmbok = (time.nDof > 7);
0182     bool rpcok = (rpcTime.nDof > 1 && rpcTime.timeAtIpInOutErr == 0);
0183     bool veto = false;
0184     if (rpcok) {
0185       if ((fabs(rpcTime.timeAtIpInOut) > 10) && !(cmbok && fabs(time.timeAtIpInOut) < 10))
0186         veto = true;
0187       else if (cmbok && (time.timeAtIpInOut > 20 || time.timeAtIpInOut < -45))
0188         veto = true;
0189     }
0190 
0191     //std::cout << time.timeAtIpInOut << std::endl;
0192     //Filling the yields histogram
0193     if (muon->isTimeValid())
0194       yields_[theObject]->Fill(1);
0195     else
0196       yields_[theObject]->Fill(0);
0197 
0198     if (cmbok)
0199       yields_[theObject]->Fill(3);
0200     else
0201       yields_[theObject]->Fill(2);
0202 
0203     if (rpcok)
0204       yields_[theObject]->Fill(5);
0205     else
0206       yields_[theObject]->Fill(4);
0207 
0208     if (cmbok && !rpcok)
0209       yields_[theObject]->Fill(6);
0210     if (!cmbok && rpcok)
0211       yields_[theObject]->Fill(7);
0212 
0213     if (veto)
0214       yields_[theObject]->Fill(8);
0215     else
0216       yields_[theObject]->Fill(9);
0217 
0218     //Starting now with the pt and eta for vetoed and not vetoed muons
0219     if (veto) {
0220       etaptVeto_[theObject]->Fill(track->pt(), track->eta());
0221       etaVeto_[theObject]->Fill(track->eta());
0222       ptVeto_[theObject]->Fill(track->pt());
0223     }
0224 
0225     //Check the eta region of the muon
0226     eta_ theEta = barrel;
0227     if (fabs(track->eta()) >= etaBarrelMin_ && fabs(track->eta()) <= etaBarrelMax_)
0228       theEta = barrel;
0229     if (fabs(track->eta()) >= etaOverlapMin_ && fabs(track->eta()) <= etaOverlapMax_)
0230       theEta = overlap;
0231     if (fabs(track->eta()) >= etaEndcapMin_ && fabs(track->eta()) <= etaEndcapMax_)
0232       theEta = endcap;
0233     timeNDof_[theEta][theObject]->Fill(time.nDof);
0234     timeAtIpInOut_[theEta][theObject]->Fill(time.timeAtIpInOut);
0235     timeAtIpInOutRPC_[theEta][theObject]->Fill(rpcTime.timeAtIpInOut);
0236     timeAtIpInOutErr_[theEta][theObject]->Fill(time.timeAtIpInOutErr);
0237     timeAtIpInOutErrRPC_[theEta][theObject]->Fill(rpcTime.timeAtIpInOutErr);
0238   }
0239 }