CMS 3D CMS Logo

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