CMS 3D CMS Logo

DTLocalTriggerSynchTask.cc
Go to the documentation of this file.
1 /*
2  * \file DTLocalTriggerSynchTask.cc
3  *
4  * \author C. Battilana - CIEMAT
5  *
6 */
7 
9 
10 // Framework
14 
15 // Geometry
21 
22 // tTrigs
25 
26 // DT Digi
29 
30 //Root
31 #include "TH1.h"
32 #include "TAxis.h"
33 
34 #include <sstream>
35 #include <iostream>
36 #include <fstream>
37 
38 using namespace edm;
39 using namespace std;
40 
42  : nevents(0),
43  tTrigSync{DTTTrigSyncFactory::get()->create(ps.getParameter<std::string>("tTrigMode"),
44  ps.getParameter<edm::ParameterSet>("tTrigModeConfig"),
45  consumesCollector())},
46  muonGeomToken_(esConsumes<edm::Transition::BeginRun>()) {
47  edm::LogVerbatim("DTLocalTriggerSynchTask") << "[DTLocalTriggerSynchTask]: Constructor" << endl;
48  tm_Token_ = consumes<L1MuDTChambPhContainer>(ps.getUntrackedParameter<edm::InputTag>("TMInputTag"));
49  seg_Token_ = consumes<DTRecSegment4DCollection>(ps.getUntrackedParameter<edm::InputTag>("SEGInputTag"));
50 
51  bxTime = ps.getParameter<double>("bxTimeInterval"); // CB move this to static const or DB
52  rangeInBX = ps.getParameter<bool>("rangeWithinBX");
53  nBXLow = ps.getParameter<int>("nBXLow");
54  nBXHigh = ps.getParameter<int>("nBXHigh");
55  angleRange = ps.getParameter<double>("angleRange");
56  minHitsPhi = ps.getParameter<int>("minHitsPhi");
57  baseDirectory = ps.getParameter<string>("baseDir");
58 }
59 
61  edm::LogVerbatim("DTLocalTriggerSynchTask") << "[DTLocalTriggerSynchTask]: analyzed " << nevents << " events" << endl;
62 }
63 
65  edm::Run const& iRun,
66  edm::EventSetup const& context) {
67  edm::LogVerbatim("DTLocalTriggerSynchTask") << "[DTLocalTriggerSynchTask]: Book Histograms" << endl;
68 
69  ibooker.setCurrentFolder(baseDir());
70  ibooker.bookFloat("BXTimeSpacing")->Fill(bxTime);
71 
72  tTrigSync->setES(context);
73 
74  std::vector<const DTChamber*>::const_iterator chambIt = muonGeom->chambers().begin();
75  std::vector<const DTChamber*>::const_iterator chambEnd = muonGeom->chambers().end();
76 
77  for (; chambIt != chambEnd; ++chambIt) {
78  bookHistos(ibooker, (*chambIt)->id());
79  triggerHistos[(*chambIt)->id().rawId()]["tTrig_SL1"]->Fill(tTrigSync->offset(DTWireId((*chambIt)->id(), 1, 1, 2)));
80  triggerHistos[(*chambIt)->id().rawId()]["tTrig_SL3"]->Fill(tTrigSync->offset(DTWireId((*chambIt)->id(), 3, 1, 2)));
81  }
82 }
83 
85  muonGeom = &context.getData(muonGeomToken_);
86 }
87 
89  nevents++;
90 
91  for (int i = 0; i < 5; ++i) {
92  for (int j = 0; j < 6; ++j) {
93  for (int k = 0; k < 13; ++k) {
94  phCodeBestTM[j][i][k] = -1;
95  }
96  }
97  }
98 
99  // Get best TM triggers
101  event.getByToken(tm_Token_, l1DTTPGPh);
102  vector<L1MuDTChambPhDigi> const* phTrigs = l1DTTPGPh->getContainer();
103 
104  vector<L1MuDTChambPhDigi>::const_iterator iph = phTrigs->begin();
105  vector<L1MuDTChambPhDigi>::const_iterator iphe = phTrigs->end();
106  for (; iph != iphe; ++iph) {
107  int phwheel = iph->whNum();
108  int phsec = iph->scNum() + 1; // DTTF[0-11] -> DT[1-12] Sector Numbering
109  int phst = iph->stNum();
110  int phcode = iph->code();
111 
112  if (phcode > phCodeBestTM[phwheel + 3][phst][phsec] && phcode < 7) {
113  phCodeBestTM[phwheel + 3][phst][phsec] = phcode;
114  }
115  }
116 
117  //Get best segments (highest number of phi hits)
118  vector<const DTRecSegment4D*> bestSegments4D;
120  event.getByToken(seg_Token_, segments4D);
123 
124  for (chambIdIt = segments4D->id_begin(); chambIdIt != segments4D->id_end(); ++chambIdIt) {
125  DTRecSegment4DCollection::range range = segments4D->get(*chambIdIt);
126  const DTRecSegment4D* best = nullptr;
127  int hitsBest = 0;
128  int hits = 0;
129 
130  for (track = range.first; track != range.second; ++track) {
131  if ((*track).hasPhi()) {
132  hits = (*track).phiSegment()->degreesOfFreedom() + 2;
133  if (hits > hitsBest) {
134  best = &(*track);
135  hitsBest = hits;
136  }
137  }
138  }
139  if (best) {
140  bestSegments4D.push_back(best);
141  }
142  }
143 
144  // Filling histos
145  vector<const DTRecSegment4D*>::const_iterator bestSegIt = bestSegments4D.begin();
146  vector<const DTRecSegment4D*>::const_iterator bestSegEnd = bestSegments4D.end();
147  for (; bestSegIt != bestSegEnd; ++bestSegIt) {
148  float dir = atan((*bestSegIt)->localDirection().x() / (*bestSegIt)->localDirection().z()) * 180 /
149  Geom::pi(); // CB cerca un modo migliore x farlo
150  const DTRecSegment2D* seg2D = (*bestSegIt)->phiSegment();
151  int nHitsPhi = seg2D->degreesOfFreedom() + 2;
152  DTChamberId chambId = (*bestSegIt)->chamberId();
153  map<string, MonitorElement*>& innerME = triggerHistos[chambId.rawId()];
154 
155  if (fabs(dir) < angleRange && nHitsPhi >= minHitsPhi && seg2D->ist0Valid()) {
156  float t0seg = (*bestSegIt)->phiSegment()->t0();
157  float tTrig = (tTrigSync->offset(DTWireId(chambId, 1, 1, 2)) + tTrigSync->offset(DTWireId(chambId, 3, 1, 2))) / 2;
158  float time = tTrig + t0seg;
159  float htime = rangeInBX ? time - int(time / bxTime) * bxTime : time - int(tTrig / bxTime) * bxTime;
160 
161  int wheel = chambId.wheel();
162  int sector = chambId.sector();
163  int station = chambId.station();
164  int scsector = sector > 12 ? sector == 13 ? 4 : 10 : sector;
165 
166  int qualTM = phCodeBestTM[wheel + 3][station][scsector];
167 
168  if (fabs(t0seg) > 0.01) {
169  innerME.find("SEG_TrackCrossingTime")->second->Fill(htime);
170  if (qualTM >= 0)
171  innerME.find("TM_TrackCrossingTimeAll")->second->Fill(htime);
172  if (qualTM == 6)
173  innerME.find("TM_TrackCrossingTimeHH")->second->Fill(htime);
174  }
175  }
176  }
177 }
178 
180  stringstream wheel;
181  wheel << dtChId.wheel();
182  stringstream station;
183  station << dtChId.station();
184  stringstream sector;
185  sector << dtChId.sector();
186  uint32_t chRawId = dtChId.rawId();
187 
188  ibooker.setCurrentFolder(baseDir() + "/Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str());
189 
190  std::vector<string> histoTags = {"SEG_TrackCrossingTime", "TM_TrackCrossingTimeAll", "TM_TrackCrossingTimeHH"};
191 
192  float min = rangeInBX ? 0 : nBXLow * bxTime;
193  float max = rangeInBX ? bxTime : nBXHigh * bxTime;
194  int nbins = static_cast<int>(ceil(rangeInBX ? bxTime : (nBXHigh - nBXLow) * bxTime));
195 
196  for (const auto& histoTag : histoTags) {
197  string histoName =
198  histoTag + (rangeInBX ? "InBX" : "") + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
199  edm::LogVerbatim("DTLocalTriggerSynchTask")
200  << "[DTLocalTriggerSynchTask]: booking " << baseDir() + "/Wheel" << wheel.str() << "/Sector" << sector.str()
201  << "/Station" << station.str() << "/" << histoName << endl;
202 
203  triggerHistos[chRawId][histoTag] = ibooker.book1D(histoName.c_str(), "Track time distribution", nbins, min, max);
204  }
205 
206  string floatTag[2] = {"tTrig_SL1", "tTrig_SL3"};
207 
208  for (int iFloat = 0; iFloat < 2; ++iFloat) {
209  string floatName = floatTag[iFloat] + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
210  triggerHistos[chRawId][floatTag[iFloat]] = ibooker.bookFloat(floatName);
211  }
212 }
213 
214 // Local Variables:
215 // show-trailing-whitespace: t
216 // truncate-lines: t
217 // End:
Log< level::Info, true > LogVerbatim
int station() const
Return the station number.
Definition: DTChamberId.h:42
constexpr int32_t ceil(float num)
bool ist0Valid() const
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
MonitorElement * bookFloat(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:80
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
void analyze(const edm::Event &event, const edm::EventSetup &context) override
Analyze.
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
Beginrun.
edm::ESGetToken< DTGeometry, MuonGeometryRecord > muonGeomToken_
identifier iterator
Definition: RangeMap.h:130
std::unique_ptr< DTTTrigBaseSync > tTrigSync
void Fill(long long x)
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
DTLocalTriggerSynchTask(const edm::ParameterSet &ps)
Constructor.
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Book the histograms.
edm::EDGetTokenT< DTRecSegment4DCollection > seg_Token_
Phi_Container const * getContainer() const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
int degreesOfFreedom() const override
return the DOF of the segment
std::map< uint32_t, std::map< std::string, MonitorElement * > > triggerHistos
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
HLT enums.
int sector() const
Definition: DTChamberId.h:49
void bookHistos(DQMStore::IBooker &, const DTChamberId &dtCh)
Book the histograms.
const std::vector< const DTChamber * > & chambers() const
Return a vector of all Chamber.
Definition: DTGeometry.cc:84
#define get
constexpr double pi()
Definition: Pi.h:31
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
edm::EDGetTokenT< L1MuDTChambPhContainer > tm_Token_
Definition: event.py:1
Definition: Run.h:45
~DTLocalTriggerSynchTask() override
Destructor.