CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTLocalTriggerLutTask.cc
Go to the documentation of this file.
1 /*
2  * \file DTLocalLutTriggerTask.cc
3  *
4  * \author D. Fasanella - INFN Bologna
5  *
6  */
7 
9 
10 // Framework
12 
13 // DT trigger
15 
16 // Geometry
22 
23 //Root
24 #include"TH1.h"
25 #include"TAxis.h"
26 
27 #include <sstream>
28 #include <iostream>
29 #include <math.h>
30 
31 
32 using namespace edm;
33 using namespace std;
34 
36 
37  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: Constructor"<<endl;
38 
39  dcc_Token_ = consumes<L1MuDTChambPhContainer>(
40  ps.getUntrackedParameter<InputTag>("inputTagDCC"));
41  seg_Token_ = consumes<DTRecSegment4DCollection>(
42  ps.getUntrackedParameter<InputTag>("inputTagSEG"));
43 
44  overUnderIn = ps.getUntrackedParameter<bool>("rebinOutFlowsInGraph");
45  detailedAnalysis = ps.getUntrackedParameter<bool>("detailedAnalysis");
46  theGeomLabel = ps.getUntrackedParameter<string>("geomLabel");
47 
48  if (detailedAnalysis){
49  nPhiBins = 401;
50  rangePhi = 10.025;
51  nPhibBins = 401;
52  rangePhiB = 10.025;
53  } else {
54  nPhiBins = 51;
55  rangePhi = 5.1;
56  nPhibBins = 51;
57  rangePhiB = 10.2;
58  }
59 
60  baseFolder = "DT/03-LocalTrigger-DCC/";
61  parameters = ps;
62 
63  nEvents = 0;
64  nLumis = 0;
65 
66 }
67 
68 
70 
71  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: analyzed " << nEvents << " events" << endl;
72  if (trigGeomUtils) { delete trigGeomUtils; }
73 
74 }
75 
77 
78  // Get the geometry
81 }
82 
84 
85  stringstream wheel; wheel << chId.wheel();
86  stringstream sector; sector << chId.sector();
87  stringstream station; station << chId.station();
88 
89  ibooker.setCurrentFolder(topFolder() + "Wheel" + wheel.str() + "/Sector" + sector.str() +
90  "/Station" + station.str() + "/Segment");
91 
92  string chTag = "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
93  std::map<std::string, MonitorElement*> &chambMap = chHistos[chId.rawId()];
94 
95  string hName = "DCC_PhiResidual";
96 
97  chambMap[hName] = ibooker.book1D(hName+chTag,"Trigger local position - Segment local position (correlated triggers)",nPhiBins,-rangePhi,rangePhi);
98  hName = "DCC_PhibResidual";
99 
100  chambMap[hName] = ibooker.book1D(hName+chTag,"Trigger local direction - Segment local direction (correlated triggers)",nPhibBins,-rangePhiB,rangePhiB);
101 
102  if (detailedAnalysis) {
103 
104  hName = "DCC_PhitkvsPhitrig";
105 
106  chambMap[hName] = ibooker.book2D(hName+chTag,"Local position: segment vs trigger",100,-500.,500.,100,-500.,500.);
107  hName = "DCC_PhibtkvsPhibtrig";
108 
109  chambMap[hName] =ibooker.book2D(hName+chTag,"Local direction : segment vs trigger",200,-40.,40.,200,-40.,40.);
110  hName = "DCC_PhibResidualvsTkPos";
111 
112  chambMap[hName] =ibooker.book2D(hName+chTag,"Local direction residual vs Segment Position",100,-500.,500.,200,-10.,10.);
113  hName = "DCC_PhiResidualvsTkPos";
114 
115  chambMap[hName] =ibooker.book2D(hName+chTag,"Local Position residual vs Segment Position",100,-500.,500.,200,-10.,10.);
116 
117  }
118 
119 }
120 
122  edm::Run const & run,
123  edm::EventSetup const & context) {
124 
125  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: bookHistograms" << endl;
126 
127  std::vector<const DTChamber*>::const_iterator chambIt = muonGeom->chambers().begin();
128  std::vector<const DTChamber*>::const_iterator chambEnd = muonGeom->chambers().end();
129 
130  for (; chambIt!=chambEnd; ++chambIt)
131  bookHistos(ibooker,(*chambIt)->id());
132 
133 }
134 
135 
137 
138  nLumis++;
139  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: Begin of LS transition" << endl;
140 
141  if(nLumis%parameters.getUntrackedParameter<int>("ResetCycle") == 0) {
142 
143  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: Cleaning histos" << endl;
144  map<uint32_t, map<string, MonitorElement*> > ::const_iterator chambIt = chHistos.begin();
145  map<uint32_t, map<string, MonitorElement*> > ::const_iterator chambEnd = chHistos.end();
146 
147  for(; chambIt!=chambEnd; ++chambIt) {
148  map<string, MonitorElement*> ::const_iterator histoIt = chambIt->second.begin();
149  map<string, MonitorElement*> ::const_iterator histoEnd = chambIt->second.end();
150  for(; histoIt!=histoEnd; ++ histoIt) {
151  histoIt->second->Reset();
152  }
153  }
154 
155  }
156 
157 }
158 
159 
160 
162 
163  nEvents++;
164 
166  e.getByToken(dcc_Token_, trigHandle);
167  vector<L1MuDTChambPhDigi> const* trigs = trigHandle->getContainer();
168  searchDccBest(trigs);
169 
171  e.getByToken(seg_Token_, segments4D);
172  DTRecSegment4DCollection::id_iterator chamberId;
173 
174  // Preliminary loop finds best 4D Segment and high quality ones
175  vector<const DTRecSegment4D*> best4DSegments;
176 
177  for (chamberId = segments4D->id_begin(); chamberId != segments4D->id_end(); ++chamberId){
178 
179  DTRecSegment4DCollection::range rangeInCh = segments4D->get(*chamberId);
180  DTRecSegment4DCollection::const_iterator trackIt = rangeInCh.first;
181  DTRecSegment4DCollection::const_iterator trackEnd = rangeInCh.second;
182 
183  const DTRecSegment4D* tmpBest = 0;
184  int tmpdof = 0;
185  int dof = 0;
186 
187  for (; trackIt!=trackEnd; ++trackIt){
188 
189  if(trackIt->hasPhi()) {
190  dof = trackIt->phiSegment()->degreesOfFreedom();
191  if (dof>tmpdof) {
192  tmpBest = &(*trackIt);
193  tmpdof = dof;
194  }
195  }
196 
197  }
198 
199  if (tmpBest) best4DSegments.push_back(tmpBest);
200 
201  }
202 
203  vector<const DTRecSegment4D*>::const_iterator bestTrackIt = best4DSegments.begin();
204  vector<const DTRecSegment4D*>::const_iterator bestTrackEnd = best4DSegments.end();
205 
206  for (; bestTrackIt!=bestTrackEnd; ++bestTrackIt) {
207 
208  if((*bestTrackIt)->hasPhi()) {
209 
210  DTChamberId chId = (*bestTrackIt)->chamberId();
211  int nHitsPhi = (*bestTrackIt)->phiSegment()->degreesOfFreedom()+2;
212 
213  int wheel = chId.wheel();
214  int station = chId.station();
215  int scsector = 0;
216  float trackPosPhi, trackPosEta, trackDirPhi, trackDirEta;
217  trigGeomUtils->computeSCCoordinates((*bestTrackIt),scsector,trackPosPhi,trackDirPhi,trackPosEta,trackDirEta);
218 
219  map<string, MonitorElement*> &chMap = chHistos[chId.rawId()];
220 
221  if (trigQualBest[wheel+3][station][scsector] > 3 && // residuals only for correlate triggers
222  trigQualBest[wheel+3][station][scsector] < 7 &&
223  nHitsPhi>=7 ) {
224 
225  float trigPos = trigGeomUtils->trigPos(trigBest[wheel+3][station][scsector]);
226  float trigDir = trigGeomUtils->trigDir(trigBest[wheel+3][station][scsector]);
227  trigGeomUtils->trigToSeg(station,trigPos,trackDirPhi);
228 
229  double deltaPos = trigPos-trackPosPhi;
230  deltaPos = overUnderIn ? max(min(deltaPos,rangePhi-0.01),-rangePhi+0.01) : deltaPos;
231  double deltaDir = trigDir-trackDirPhi;
232  deltaDir = overUnderIn ? max(min(deltaDir,rangePhiB-0.01),-rangePhiB+0.01) : deltaDir;
233  chMap.find("DCC_PhiResidual")->second->Fill(deltaPos);
234  chMap.find("DCC_PhibResidual")->second->Fill(deltaDir);
235 
236  if (detailedAnalysis){
237  chMap.find("DCC_PhitkvsPhitrig")->second->Fill(trigPos,trackPosPhi);
238  chMap.find("DCC_PhibtkvsPhibtrig")->second->Fill(trigDir,trackDirPhi);
239  chMap.find("DCC_PhibResidualvsTkPos")->second->Fill(trackPosPhi,trigDir-trackDirPhi);
240  chMap.find("DCC_PhiResidualvsTkPos")->second->Fill(trackPosPhi,trigPos-trackPosPhi);
241  }
242  }
243  }
244  }
245 }
246 
247 void DTLocalTriggerLutTask::searchDccBest( std::vector<L1MuDTChambPhDigi> const* trigs ) {
248 
249  string histoType ;
250  string histoTag ;
251 
252  // define best quality trigger segment
253  // start from 1 and zero is kept empty
254  for (int st=0;st<=4;++st)
255  for (int wh=0;wh<=5;++wh)
256  for (int sec=0;sec<=12;++sec)
257  trigQualBest[wh][st][sec] = -1;
258 
259  vector<L1MuDTChambPhDigi>::const_iterator trigIt = trigs->begin();
260  vector<L1MuDTChambPhDigi>::const_iterator trigEnd = trigs->end();
261  for(; trigIt!=trigEnd; ++trigIt) {
262 
263  int wh = trigIt->whNum();
264  int sec = trigIt->scNum() + 1; // DTTF -> DT sector range transform
265  int st = trigIt->stNum();
266  int qual = trigIt->code();
267 
268  if(qual>trigQualBest[wh+3][st][sec] && qual<7) {
269  trigQualBest[wh+3][st][sec]=qual;
270  trigBest[wh+3][st][sec] = &(*trigIt);
271  }
272 
273  }
274 }
275 
276 // Local Variables:
277 // show-trailing-whitespace: t
278 // truncate-lines: t
279 // End:
void bookHistos(DQMStore::IBooker &ibooker, DTChamberId chId)
Book histos.
T getUntrackedParameter(std::string const &, T const &) const
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
std::string & topFolder()
Get the top folder.
float trigDir(const L1MuDTChambPhDigi *trig)
Return local direction (trigger RF) for a given trigger primitive.
DTLocalTriggerLutTask(const edm::ParameterSet &ps)
Constructor.
edm::ParameterSet parameters
edm::ESHandle< DTGeometry > muonGeom
edm::EDGetTokenT< DTRecSegment4DCollection > seg_Token_
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
virtual ~DTLocalTriggerLutTask()
Destructor.
edm::EDGetTokenT< L1MuDTChambPhContainer > dcc_Token_
void dqmBeginRun(const edm::Run &, const edm::EventSetup &)
BeginRun.
void trigToSeg(int st, float &x, float dir)
Compute Trigger x coordinate in chamber RF.
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
T min(T a, T b)
Definition: MathUtil.h:58
#define LogTrace(id)
std::map< uint32_t, std::map< std::string, MonitorElement * > > chHistos
DTTrigGeomUtils * trigGeomUtils
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
bookHistograms
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
const T & get() const
Definition: EventSetup.h:56
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
To reset the MEs.
int sector() const
Definition: DTChamberId.h:61
const L1MuDTChambPhDigi * trigBest[6][5][13]
float trigPos(const L1MuDTChambPhDigi *trig)
Return local position (trigger RF) for a given trigger primitive.
int station() const
Return the station number.
Definition: DTChamberId.h:51
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
void computeSCCoordinates(const DTRecSegment4D *track, int &scsec, float &x, float &xdir, float &y, float &ydir)
Compute track coordinates with SC sector numbering.
Definition: Run.h:43
void searchDccBest(std::vector< L1MuDTChambPhDigi > const *trigs)
Find best (highest qual) DCC trigger segments.