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
13 
14 // Geometry
21 
22 // tTrigs
25 
26 // DT Digi
29 
30 
31 //Root
32 #include"TH1.h"
33 #include"TAxis.h"
34 
35 #include <sstream>
36 #include <iostream>
37 #include <fstream>
38 
39 
40 using namespace edm;
41 using namespace std;
42 
44  tTrigSync{DTTTrigSyncFactory::get()->create(ps.getParameter<std::string>("tTrigMode"),
45  ps.getParameter<edm::ParameterSet>("tTrigModeConfig"))}
46 {
47 
48 
49  edm::LogVerbatim ("DTLocalTriggerSynchTask") << "[DTLocalTriggerSynchTask]: Constructor" << endl;
50  tm_Token_ = consumes<L1MuDTChambPhContainer>(
51  ps.getParameter<edm::InputTag>("TMInputTag"));
52  seg_Token_ = consumes<DTRecSegment4DCollection>(
53  ps.getParameter<edm::InputTag>("SEGInputTag"));
54 
55  processDDU = ps.getUntrackedParameter<bool>("processDDU",false);
56 
57  if (processDDU)
58  ddu_Token_ = consumes<DTLocalTriggerCollection>(
59  ps.getParameter<edm::InputTag>("DDUInputTag"));
60 
61  bxTime = ps.getParameter<double>("bxTimeInterval"); // CB move this to static const or DB
62  rangeInBX = ps.getParameter<bool>("rangeWithinBX");
63  nBXLow = ps.getParameter<int>("nBXLow");
64  nBXHigh = ps.getParameter<int>("nBXHigh");
65  angleRange = ps.getParameter<double>("angleRange");
66  minHitsPhi = ps.getParameter<int>("minHitsPhi");
67  baseDirectory = ps.getParameter<string>("baseDir");
68 }
69 
70 
72 
73  edm::LogVerbatim ("DTLocalTriggerSynchTask") << "[DTLocalTriggerSynchTask]: analyzed " << nevents << " events" << endl;
74 
75 }
76 
78 
79  edm::LogVerbatim ("DTLocalTriggerSynchTask") <<"[DTLocalTriggerSynchTask]: Book Histograms"<<endl;
80 
81  ibooker.setCurrentFolder(baseDir());
82  ibooker.bookFloat("BXTimeSpacing")->Fill(bxTime);
83 
84  tTrigSync->setES(context);
85 
86 
87  std::vector<const DTChamber*>::const_iterator chambIt = muonGeom->chambers().begin();
88  std::vector<const DTChamber*>::const_iterator chambEnd = muonGeom->chambers().end();
89 
90  for (; chambIt!=chambEnd; ++chambIt) {
91  bookHistos(ibooker,(*chambIt)->id());
92  triggerHistos[(*chambIt)->id().rawId()]["tTrig_SL1"]->Fill(tTrigSync->offset(DTWireId((*chambIt)->id(),1,1,2)));
93  triggerHistos[(*chambIt)->id().rawId()]["tTrig_SL3"]->Fill(tTrigSync->offset(DTWireId((*chambIt)->id(),3,1,2)));
94  }
95 
96 
97 }
98 
99 
101 
102  context.get<MuonGeometryRecord>().get(muonGeom);
103 }
104 
105 
107 
108  nevents++;
109 
110  for (int i=0;i<5;++i){
111  for (int j=0;j<6;++j){
112  for (int k=0;k<13;++k){
113  phCodeBestTM[j][i][k] = -1;
114  phCodeBestDDU[j][i][k] = -1;
115  }
116  }
117  }
118 
119  // Get best TM triggers
121  event.getByToken(tm_Token_, l1DTTPGPh);
122  vector<L1MuDTChambPhDigi> const* phTrigs = l1DTTPGPh->getContainer();
123 
124  vector<L1MuDTChambPhDigi>::const_iterator iph = phTrigs->begin();
125  vector<L1MuDTChambPhDigi>::const_iterator iphe = phTrigs->end();
126  for(; iph !=iphe ; ++iph) {
127 
128  int phwheel = iph->whNum();
129  int phsec = iph->scNum() + 1; // DTTF[0-11] -> DT[1-12] Sector Numbering
130  int phst = iph->stNum();
131  int phcode = iph->code();
132 
133  if(phcode>phCodeBestTM[phwheel+3][phst][phsec] && phcode<7) {
134  phCodeBestTM[phwheel+3][phst][phsec]=phcode;
135  }
136 
137  }
138 
139  // Get best DDU triggers
140  if (processDDU){
142  event.getByToken(ddu_Token_, trigsDDU);
144 
145  for (detUnitIt=trigsDDU->begin();detUnitIt!=trigsDDU->end();++detUnitIt){
146 
147  const DTChamberId& id = (*detUnitIt).first;
148  const DTLocalTriggerCollection::Range& range = (*detUnitIt).second;
149 
150  int wh = id.wheel();
151  int sec = id.sector();
152  int st = id.station();
153 
154  for (DTLocalTriggerCollection::const_iterator trigIt = range.first; trigIt!=range.second;++trigIt){
155 
156  int quality = trigIt->quality();
157 
158  if(quality>-1 && quality<7 &&
159  quality>phCodeBestDDU[wh+wheelArrayShift][st][sec]) {
161  }
162  }
163  }
164  }
165 
166  //Get best segments (highest number of phi hits)
167  vector<const DTRecSegment4D*> bestSegments4D;
169  event.getByToken(seg_Token_, segments4D);
172 
173  for (chambIdIt = segments4D->id_begin(); chambIdIt != segments4D->id_end(); ++chambIdIt){
174 
175  DTRecSegment4DCollection::range range = segments4D->get(*chambIdIt);
176  const DTRecSegment4D* best=nullptr;
177  int hitsBest = 0;
178  int hits = 0;
179 
180  for ( track = range.first; track != range.second; ++track){
181  if( (*track).hasPhi() ) {
182  hits = (*track).phiSegment()->degreesOfFreedom()+2;
183  if ( hits>hitsBest ){
184  best = &(*track);
185  hitsBest = hits;
186  }
187  }
188  }
189  if (best) {
190  bestSegments4D.push_back(best);
191  }
192  }
193 
194 
195  // Filling histos
196  vector<const DTRecSegment4D*>::const_iterator bestSegIt = bestSegments4D.begin();
197  vector<const DTRecSegment4D*>::const_iterator bestSegEnd = bestSegments4D.end();
198  for (; bestSegIt!=bestSegEnd; ++bestSegIt ){
199 
200  float dir = atan((*bestSegIt)->localDirection().x()/ (*bestSegIt)->localDirection().z())*180/Geom::pi(); // CB cerca un modo migliore x farlo
201  const DTRecSegment2D* seg2D = (*bestSegIt)->phiSegment();
202  int nHitsPhi = seg2D->degreesOfFreedom()+2;
203  DTChamberId chambId = (*bestSegIt)->chamberId();
204  map<string, MonitorElement*> &innerME = triggerHistos[chambId.rawId()];
205 
206  if (fabs(dir)<angleRange &&
207  nHitsPhi>=minHitsPhi &&
208  seg2D->ist0Valid()){
209 
210  float t0seg = (*bestSegIt)->phiSegment()->t0();
211  float tTrig = (tTrigSync->offset(DTWireId(chambId,1,1,2)) + tTrigSync->offset(DTWireId(chambId,3,1,2)) )/2;
212  float time = tTrig+t0seg;
213  float htime = rangeInBX ? time-int(time/bxTime)*bxTime : time-int(tTrig/bxTime)*bxTime;
214 
215  int wheel = chambId.wheel();
216  int sector = chambId.sector();
217  int station = chambId.station();
218  int scsector = sector>12 ? sector==13 ? 4 : 10 : sector;
219 
220  int qualTM = phCodeBestTM[wheel+3][station][scsector];
221  int qualDDU = phCodeBestDDU[wheel+3][station][scsector];
222 
223  if (fabs(t0seg)>0.01) {
224  innerME.find("SEG_TrackCrossingTime")->second->Fill(htime);
225  if ( qualTM>=0 ) innerME.find("TM_TrackCrossingTimeAll")->second->Fill(htime);
226  if ( qualTM==6 ) innerME.find("TM_TrackCrossingTimeHH")->second->Fill(htime);
227  if ( processDDU && qualDDU>=0 ) innerME.find("DDU_TrackCrossingTimeAll")->second->Fill(htime);
228  if ( processDDU && qualDDU==6 ) innerME.find("DDU_TrackCrossingTimeHH")->second->Fill(htime);
229  }
230 
231  }
232  }
233 
234 }
235 
237 
238  stringstream wheel; wheel << dtChId.wheel();
239  stringstream station; station << dtChId.station();
240  stringstream sector; sector << dtChId.sector();
241  uint32_t chRawId = dtChId.rawId();
242 
243  ibooker.setCurrentFolder(baseDir() + "/Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str() );
244 
245  std::vector<string> histoTags = { "SEG_TrackCrossingTime", "TM_TrackCrossingTimeAll", "TM_TrackCrossingTimeHH" };
246 
247  if (processDDU) {
248  histoTags.push_back("DDU_TrackCrossingTimeAll");
249  histoTags.push_back("DDU_TrackCrossingTimeHH");
250  }
251 
252  float min = rangeInBX ? 0 : nBXLow*bxTime;
253  float max = rangeInBX ? bxTime : nBXHigh*bxTime;
254  int nbins = static_cast<int>(ceil( rangeInBX ? bxTime : (nBXHigh-nBXLow)*bxTime));
255 
256  for (const auto & histoTag : histoTags) {
257  string histoName = histoTag + (rangeInBX ? "InBX" : "") + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
258  edm::LogVerbatim ("DTLocalTriggerSynchTask") << "[DTLocalTriggerSynchTask]: booking "
259  << baseDir() + "/Wheel" << wheel.str()
260  << "/Sector" << sector.str()
261  << "/Station"<< station.str()
262  << "/" << histoName << endl;
263 
264  triggerHistos[chRawId][histoTag] = ibooker.book1D(histoName.c_str(),"Track time distribution",nbins,min,max);
265  }
266 
267  string floatTag[2] = { "tTrig_SL1", "tTrig_SL3" };
268 
269  for (int iFloat=0;iFloat<2;++iFloat) {
270  string floatName = floatTag[iFloat] + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
271  triggerHistos[chRawId][floatTag[iFloat]] = ibooker.bookFloat(floatName);
272  }
273 
274 }
275 
276 // Local Variables:
277 // show-trailing-whitespace: t
278 // truncate-lines: t
279 // End:
T getParameter(std::string const &) const
const std::vector< const DTChamber * > & chambers() const
Return a vector of all Chamber.
Definition: DTGeometry.cc:102
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
void analyze(const edm::Event &event, const edm::EventSetup &context) override
Analyze.
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
Beginrun.
identifier iterator
Definition: RangeMap.h:135
std::unique_ptr< DTTTrigBaseSync > tTrigSync
edm::EDGetTokenT< DTLocalTriggerCollection > ddu_Token_
void Fill(long long x)
edm::ESHandle< DTGeometry > muonGeom
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
int degreesOfFreedom() const override
return the DOF of the segment
DTLocalTriggerSynchTask(const edm::ParameterSet &ps)
Constructor.
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
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_
int k[5][pyjets_maxn]
std::vector< DigiType >::const_iterator const_iterator
Phi_Container const * getContainer() const
std::map< uint32_t, std::map< std::string, MonitorElement * > > triggerHistos
HLT enums.
int sector() const
Definition: DTChamberId.h:61
T get() const
Definition: EventSetup.h:71
std::pair< const_iterator, const_iterator > Range
void bookHistos(DQMStore::IBooker &, const DTChamberId &dtCh)
Book the histograms.
MonitorElement * bookFloat(Args &&...args)
Definition: DQMStore.h:105
dbl *** dir
Definition: mlp_gen.cc:35
constexpr double pi()
Definition: Pi.h:31
int station() const
Return the station number.
Definition: DTChamberId.h:51
edm::EDGetTokenT< L1MuDTChambPhContainer > tm_Token_
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
T get(const Candidate &c)
Definition: component.h:55
Definition: event.py:1
Definition: Run.h:45
~DTLocalTriggerSynchTask() override
Destructor.