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