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;
63 
64 }
65 
66 
68 
69  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: analyzed " << nEvents << " events" << endl;
70  if (trigGeomUtils) { delete trigGeomUtils; }
71 
72 }
73 
74 
76 
77  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: BeginJob" << endl;
78  nEvents = 0;
79  nLumis = 0;
80 
81 }
82 
84 
85  stringstream wheel; wheel << chId.wheel();
86  stringstream sector; sector << chId.sector();
87  stringstream station; station << chId.station();
88 
89  dbe->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  chambMap[hName] = dbe->book1D(hName+chTag,"Trigger local position - Segment local position (correlated triggers)",nPhiBins,-rangePhi,rangePhi);
97  hName = "DCC_PhibResidual";
98  chambMap[hName] =dbe->book1D(hName+chTag,"Trigger local direction - Segment local direction (correlated triggers)",nPhibBins,-rangePhiB,rangePhiB);
99 
100  if (detailedAnalysis) {
101 
102  hName = "DCC_PhitkvsPhitrig";
103  chambMap[hName] = dbe->book2D(hName+chTag,"Local position: segment vs trigger",100,-500.,500.,100,-500.,500.);
104  hName = "DCC_PhibtkvsPhibtrig";
105  chambMap[hName] =dbe->book2D(hName+chTag,"Local direction : segment vs trigger",200,-40.,40.,200,-40.,40.);
106  hName = "DCC_PhibResidualvsTkPos";
107  chambMap[hName] =dbe->book2D(hName+chTag,"Local direction residual vs Segment Position",100,-500.,500.,200,-10.,10.);
108  hName = "DCC_PhiResidualvsTkPos";
109  chambMap[hName] =dbe->book2D(hName+chTag,"Local Position residual vs Segment Position",100,-500.,500.,200,-10.,10.);
110 
111  }
112 
113 }
114 
115 
116 
118 
119  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: BeginRun" << endl;
120 
123 
124  std::vector<const DTChamber*>::const_iterator chambIt = muonGeom->chambers().begin();
125  std::vector<const DTChamber*>::const_iterator chambEnd = muonGeom->chambers().end();
126 
127  for (; chambIt!=chambEnd; ++chambIt)
128  bookHistos((*chambIt)->id());
129 
130 }
131 
132 
134 
135  nLumis++;
136  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: Begin of LS transition" << endl;
137 
138  if(nLumis%parameters.getUntrackedParameter<int>("ResetCycle") == 0) {
139 
140  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: Cleaning histos" << endl;
141  map<uint32_t, map<string, MonitorElement*> > ::const_iterator chambIt = chHistos.begin();
142  map<uint32_t, map<string, MonitorElement*> > ::const_iterator chambEnd = chHistos.end();
143 
144  for(; chambIt!=chambEnd; ++chambIt) {
145  map<string, MonitorElement*> ::const_iterator histoIt = chambIt->second.begin();
146  map<string, MonitorElement*> ::const_iterator histoEnd = chambIt->second.end();
147  for(; histoIt!=histoEnd; ++ histoIt) {
148  histoIt->second->Reset();
149  }
150  }
151 
152  }
153 
154 }
155 
156 
158 
159  LogVerbatim("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: analyzed " << nEvents << " events" << endl;
160  dbe->rmdir(topFolder());
161 
162 }
163 
164 
166 
167  nEvents++;
168 
170  e.getByToken(dcc_Token_, trigHandle);
171  vector<L1MuDTChambPhDigi> const* trigs = trigHandle->getContainer();
172  searchDccBest(trigs);
173 
175  e.getByToken(seg_Token_, segments4D);
176  DTRecSegment4DCollection::id_iterator chamberId;
177 
178  // Preliminary loop finds best 4D Segment and high quality ones
179  vector<const DTRecSegment4D*> best4DSegments;
180 
181  for (chamberId = segments4D->id_begin(); chamberId != segments4D->id_end(); ++chamberId){
182 
183  DTRecSegment4DCollection::range rangeInCh = segments4D->get(*chamberId);
184  DTRecSegment4DCollection::const_iterator trackIt = rangeInCh.first;
185  DTRecSegment4DCollection::const_iterator trackEnd = rangeInCh.second;
186 
187  const DTRecSegment4D* tmpBest = 0;
188  int tmpdof = 0;
189  int dof = 0;
190 
191  for (; trackIt!=trackEnd; ++trackIt){
192 
193  if(trackIt->hasPhi()) {
194  dof = trackIt->phiSegment()->degreesOfFreedom();
195  if (dof>tmpdof) {
196  tmpBest = &(*trackIt);
197  tmpdof = dof;
198  }
199  }
200 
201  }
202 
203  if (tmpBest) best4DSegments.push_back(tmpBest);
204 
205  }
206 
207  vector<const DTRecSegment4D*>::const_iterator bestTrackIt = best4DSegments.begin();
208  vector<const DTRecSegment4D*>::const_iterator bestTrackEnd = best4DSegments.end();
209 
210  for (; bestTrackIt!=bestTrackEnd; ++bestTrackIt) {
211 
212  if((*bestTrackIt)->hasPhi()) {
213 
214  DTChamberId chId = (*bestTrackIt)->chamberId();
215  int nHitsPhi = (*bestTrackIt)->phiSegment()->degreesOfFreedom()+2;
216 
217  int wheel = chId.wheel();
218  int station = chId.station();
219  int scsector = 0;
220  float trackPosPhi, trackPosEta, trackDirPhi, trackDirEta;
221  trigGeomUtils->computeSCCoordinates((*bestTrackIt),scsector,trackPosPhi,trackDirPhi,trackPosEta,trackDirEta);
222 
223  map<string, MonitorElement*> &chMap = chHistos[chId.rawId()];
224 
225  if (trigQualBest[wheel+3][station][scsector] > 3 && // residuals only for correlate triggers
226  trigQualBest[wheel+3][station][scsector] < 7 &&
227  nHitsPhi>=7 ) {
228 
229  float trigPos = trigGeomUtils->trigPos(trigBest[wheel+3][station][scsector]);
230  float trigDir = trigGeomUtils->trigDir(trigBest[wheel+3][station][scsector]);
231  trigGeomUtils->trigToSeg(station,trigPos,trackDirPhi);
232 
233  double deltaPos = trigPos-trackPosPhi;
234  deltaPos = overUnderIn ? max(min(deltaPos,rangePhi-0.01),-rangePhi+0.01) : deltaPos;
235  double deltaDir = trigDir-trackDirPhi;
236  deltaDir = overUnderIn ? max(min(deltaDir,rangePhiB-0.01),-rangePhiB+0.01) : deltaDir;
237  chMap.find("DCC_PhiResidual")->second->Fill(deltaPos);
238  chMap.find("DCC_PhibResidual")->second->Fill(deltaDir);
239 
240  if (detailedAnalysis){
241  chMap.find("DCC_PhitkvsPhitrig")->second->Fill(trigPos,trackPosPhi);
242  chMap.find("DCC_PhibtkvsPhibtrig")->second->Fill(trigDir,trackDirPhi);
243  chMap.find("DCC_PhibResidualvsTkPos")->second->Fill(trackPosPhi,trigDir-trackDirPhi);
244  chMap.find("DCC_PhiResidualvsTkPos")->second->Fill(trackPosPhi,trigPos-trackPosPhi);
245  }
246  }
247  }
248  }
249 }
250 
251 void DTLocalTriggerLutTask::searchDccBest( std::vector<L1MuDTChambPhDigi> const* trigs ) {
252 
253  string histoType ;
254  string histoTag ;
255 
256  // define best quality trigger segment
257  // start from 1 and zero is kept empty
258  for (int st=0;st<=4;++st)
259  for (int wh=0;wh<=5;++wh)
260  for (int sec=0;sec<=12;++sec)
261  trigQualBest[wh][st][sec] = -1;
262 
263  vector<L1MuDTChambPhDigi>::const_iterator trigIt = trigs->begin();
264  vector<L1MuDTChambPhDigi>::const_iterator trigEnd = trigs->end();
265  for(; trigIt!=trigEnd; ++trigIt) {
266 
267  int wh = trigIt->whNum();
268  int sec = trigIt->scNum() + 1; // DTTF -> DT sector range transform
269  int st = trigIt->stNum();
270  int qual = trigIt->code();
271 
272  if(qual>trigQualBest[wh+3][st][sec] && qual<7) {
273  trigQualBest[wh+3][st][sec]=qual;
274  trigBest[wh+3][st][sec] = &(*trigIt);
275  }
276 
277  }
278 }
279 
280 // Local Variables:
281 // show-trailing-whitespace: t
282 // truncate-lines: t
283 // End:
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:446
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 trigToSeg(int st, float &x, float dir)
Compute Trigger x coordinate in chamber RF.
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
const T & get() const
Definition: EventSetup.h:55
void beginRun(const edm::Run &, const edm::EventSetup &)
BeginRun.
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
To reset the MEs.
int sector() const
Definition: DTChamberId.h:61
void bookHistos(DTChamberId chId)
Book histos.
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:41
void searchDccBest(std::vector< L1MuDTChambPhDigi > const *trigs)
Find best (highest qual) DCC trigger segments.