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 /*
3  * \file DTLocalTriggerSynchTask.cc
4  *
5  * \author C. Battilana - CIEMAT
6  *
7 */
8 
10 
11 // Framework
14 
15 // Geometry
22 
23 // tTrigs
26 
27 // DT Digi
30 
31 
32 //Root
33 #include"TH1.h"
34 #include"TAxis.h"
35 
36 #include <sstream>
37 #include <iostream>
38 #include <fstream>
39 
40 
41 using namespace edm;
42 using namespace std;
43 
45 
46  edm::LogVerbatim ("DTLocalTriggerSynchTask") << "[DTLocalTriggerSynchTask]: Constructor" << endl;
47  parameters = ps;
48  dcc_Token_ = consumes<L1MuDTChambPhContainer>(
49  parameters.getParameter<edm::InputTag>("DCCInputTag"));
50  ddu_Token_ = consumes<DTLocalTriggerCollection>(
51  parameters.getParameter<edm::InputTag>("DDUInputTag"));
52  seg_Token_ = consumes<DTRecSegment4DCollection>(
53  parameters.getParameter<edm::InputTag>("SEGInputTag"));
54 }
55 
56 
58 
59  edm::LogVerbatim ("DTLocalTriggerSynchTask") << "[DTLocalTriggerSynchTask]: analyzed " << nevents << " events" << endl;
60 
61 }
62 
63 
65 
66  edm::LogVerbatim ("DTLocalTriggerSynchTask") << "[DTLocalTriggerSynchTask]: BeginJob" << endl;
67 
68  bxTime = parameters.getParameter<double>("bxTimeInterval"); // CB move this to static const or DB
69  rangeInBX = parameters.getParameter<bool>("rangeWithinBX");
70  nBXLow = parameters.getParameter<int>("nBXLow");
71  nBXHigh = parameters.getParameter<int>("nBXHigh");
72  angleRange = parameters.getParameter<double>("angleRange");
73  minHitsPhi = parameters.getParameter<int>("minHitsPhi");
74  baseDirectory = parameters.getParameter<string>("baseDir");
75 
77  dbe->setCurrentFolder(baseDir());
78  dbe->bookFloat("BXTimeSpacing")->Fill(bxTime);
79 
80 }
81 
82 void DTLocalTriggerSynchTask::beginRun(const Run& run, const EventSetup& context) {
83 
84  edm::LogVerbatim ("DTLocalTriggerSynchTask") <<"[DTLocalTriggerSynchTask]: Begin Run"<<endl;
85 
86  context.get<MuonGeometryRecord>().get(muonGeom);
88  parameters.getParameter<edm::ParameterSet>("tTrigModeConfig"));
89  tTrigSync->setES(context);
90 
91 
92  std::vector<DTChamber*>::const_iterator chambIt = muonGeom->chambers().begin();
93  std::vector<DTChamber*>::const_iterator chambEnd = muonGeom->chambers().end();
94 
95  for (; chambIt!=chambEnd; ++chambIt) {
96  bookHistos((*chambIt)->id());
97  triggerHistos[(*chambIt)->id().rawId()]["tTrig_SL1"]->Fill(tTrigSync->offset(DTWireId((*chambIt)->id(),1,1,2)));
98  triggerHistos[(*chambIt)->id().rawId()]["tTrig_SL3"]->Fill(tTrigSync->offset(DTWireId((*chambIt)->id(),3,1,2)));
99  }
100 
101 }
102 
103 
105 
106  edm::LogVerbatim ("DTLocalTriggerSynchTask") << "[DTLocalTriggerSynchTask]: analyzed " << nevents << " events" << endl;
107  dbe->rmdir(baseDir());
108 
109 }
110 
111 
113 
114  nevents++;
115 
116  InputTag inputTagDCC = parameters.getParameter<edm::InputTag>("DCCInputTag");
117  InputTag inputTagDDU = parameters.getParameter<edm::InputTag>("DDUInputTag");
118  InputTag inputTagSEG = parameters.getParameter<edm::InputTag>("SEGInputTag");
119 
120  for (int i=0;i<5;++i){
121  for (int j=0;j<6;++j){
122  for (int k=0;k<13;++k){
123  phCodeBestDCC[j][i][k] = -1;
124  phCodeBestDDU[j][i][k] = -1;
125  }
126  }
127  }
128 
129  // Get best DCC triggers
131  event.getByToken(dcc_Token_, l1DTTPGPh);
132  vector<L1MuDTChambPhDigi> const* phTrigs = l1DTTPGPh->getContainer();
133 
134  vector<L1MuDTChambPhDigi>::const_iterator iph = phTrigs->begin();
135  vector<L1MuDTChambPhDigi>::const_iterator iphe = phTrigs->end();
136  for(; iph !=iphe ; ++iph) {
137 
138  int phwheel = iph->whNum();
139  int phsec = iph->scNum() + 1; // DTTF[0-11] -> DT[1-12] Sector Numbering
140  int phst = iph->stNum();
141  int phcode = iph->code();
142 
143  if(phcode>phCodeBestDCC[phwheel+3][phst][phsec] && phcode<7) {
144  phCodeBestDCC[phwheel+3][phst][phsec]=phcode;
145  }
146 
147  }
148 
149  // Get best DDU triggers
151  event.getByToken(ddu_Token_, trigsDDU);
153 
154  for (detUnitIt=trigsDDU->begin();detUnitIt!=trigsDDU->end();++detUnitIt){
155 
156  const DTChamberId& id = (*detUnitIt).first;
157  const DTLocalTriggerCollection::Range& range = (*detUnitIt).second;
158 
159  int wh = id.wheel();
160  int sec = id.sector();
161  int st = id.station();
162 
163  for (DTLocalTriggerCollection::const_iterator trigIt = range.first; trigIt!=range.second;++trigIt){
164 
165  int quality = trigIt->quality();
166 
167  if(quality>-1 && quality<7 &&
168  quality>phCodeBestDDU[wh+3][st][sec]) {
169  phCodeBestDDU[wh+3][st][sec]=quality;
170  }
171  }
172  }
173 
174  //Get best segments (highest number of phi hits)
175  vector<const DTRecSegment4D*> bestSegments4D;
177  event.getByToken(seg_Token_, segments4D);
179  DTRecSegment4DCollection::id_iterator chambIdIt;
180 
181  for (chambIdIt = segments4D->id_begin(); chambIdIt != segments4D->id_end(); ++chambIdIt){
182 
183  DTRecSegment4DCollection::range range = segments4D->get(*chambIdIt);
184  const DTRecSegment4D* best=0;
185  int hitsBest = 0;
186  int hits = 0;
187 
188  for ( track = range.first; track != range.second; ++track){
189  if( (*track).hasPhi() ) {
190  hits = (*track).phiSegment()->degreesOfFreedom()+2;
191  if ( hits>hitsBest ){
192  best = &(*track);
193  hitsBest = hits;
194  }
195  }
196  }
197  if (best) {
198  bestSegments4D.push_back(best);
199  }
200  }
201 
202 
203  // Filling histos
204  vector<const DTRecSegment4D*>::const_iterator bestSegIt = bestSegments4D.begin();
205  vector<const DTRecSegment4D*>::const_iterator bestSegEnd = bestSegments4D.end();
206  for (; bestSegIt!=bestSegEnd; ++bestSegIt ){
207 
208  float dir = atan((*bestSegIt)->localDirection().x()/ (*bestSegIt)->localDirection().z())*180/Geom::pi(); // CB cerca un modo migliore x farlo
209  const DTRecSegment2D* seg2D = (*bestSegIt)->phiSegment();
210  int nHitsPhi = seg2D->degreesOfFreedom()+2;
211  DTChamberId chambId = (*bestSegIt)->chamberId();
212  map<string, MonitorElement*> &innerME = triggerHistos[chambId.rawId()];
213 
214  if (fabs(dir)<angleRange &&
215  nHitsPhi>=minHitsPhi &&
216  seg2D->ist0Valid()){
217 
218  float t0seg = (*bestSegIt)->phiSegment()->t0();
219  float tTrig = (tTrigSync->offset(DTWireId(chambId,1,1,2)) + tTrigSync->offset(DTWireId(chambId,3,1,2)) )/2;
220  float time = tTrig+t0seg;
221  float htime = rangeInBX ? time-int(time/bxTime)*bxTime : time-int(tTrig/bxTime)*bxTime;
222 
223  int wheel = chambId.wheel();
224  int sector = chambId.sector();
225  int station = chambId.station();
226  int scsector = sector>12 ? sector==13 ? 4 : 10 : sector;
227 
228  int qualDCC = phCodeBestDCC[wheel+3][station][scsector];
229  int qualDDU = phCodeBestDDU[wheel+3][station][scsector];
230 
231  if (fabs(t0seg)>0.01) {
232  innerME.find("SEG_TrackCrossingTime")->second->Fill(htime);
233  if ( qualDCC>=0 ) innerME.find("DCC_TrackCrossingTimeAll")->second->Fill(htime);
234  if ( qualDCC==6 ) innerME.find("DCC_TrackCrossingTimeHH")->second->Fill(htime);
235  if ( qualDDU>=0 ) innerME.find("DDU_TrackCrossingTimeAll")->second->Fill(htime);
236  if ( qualDDU==6 ) innerME.find("DDU_TrackCrossingTimeHH")->second->Fill(htime);
237  }
238 
239  }
240  }
241 
242 }
243 
245 
246  stringstream wheel; wheel << dtChId.wheel();
247  stringstream station; station << dtChId.station();
248  stringstream sector; sector << dtChId.sector();
249  uint32_t chRawId = dtChId.rawId();
250 
251  dbe->setCurrentFolder(baseDir() + "/Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str() );
252 
253 
254  string histoTag[5] = { "SEG_TrackCrossingTime", "DCC_TrackCrossingTimeAll", "DCC_TrackCrossingTimeHH", "DDU_TrackCrossingTimeAll", "DDU_TrackCrossingTimeHH" };
255 
256  float min = rangeInBX ? 0 : nBXLow*bxTime;
257  float max = rangeInBX ? bxTime : nBXHigh*bxTime;
258  int nbins = static_cast<int>(ceil( rangeInBX ? bxTime : (nBXHigh-nBXLow)*bxTime));
259 
260  for (int iHisto=0;iHisto<5;++iHisto) {
261  string histoName = histoTag[iHisto] + (rangeInBX ? "InBX" : "") + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
262  edm::LogVerbatim ("DTLocalTriggerSynchTask") << "[DTLocalTriggerSynchTask]: booking "
263  << baseDir() + "/Wheel" << wheel.str()
264  << "/Sector" << sector.str()
265  << "/Station"<< station.str()
266  << "/" << histoName << endl;
267 
268  triggerHistos[chRawId][histoTag[iHisto]] = dbe->book1D(histoName.c_str(),"Track time distribution",nbins,min,max);
269  }
270 
271  string floatTag[2] = { "tTrig_SL1", "tTrig_SL3" };
272 
273  for (int iFloat=0;iFloat<2;++iFloat) {
274  string floatName = floatTag[iFloat] + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
275  triggerHistos[chRawId][floatTag[iFloat]] = dbe->bookFloat(floatName);
276  }
277 
278 }
279 
280 // Local Variables:
281 // show-trailing-whitespace: t
282 // truncate-lines: t
283 // End:
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:872
virtual int degreesOfFreedom() const
return the DOF of the segment
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2730
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
double offset(const DTLayer *layer, const DTWireId &wireId, const GlobalPoint &globalPos)
edm::EDGetTokenT< DTLocalTriggerCollection > ddu_Token_
MonitorElement * bookFloat(const char *name)
Book float.
Definition: DQMStore.cc:809
void beginRun(const edm::Run &run, const edm::EventSetup &context)
Begin Run.
edm::ESHandle< DTGeometry > muonGeom
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
virtual void setES(const edm::EventSetup &setup)=0
Pass the Event Setup to the synchronization module at each event.
void analyze(const edm::Event &event, const edm::EventSetup &context)
Analyze.
virtual ~DTLocalTriggerSynchTask()
Destructor.
const T & max(const T &a, const T &b)
DTLocalTriggerSynchTask(const edm::ParameterSet &ps)
Constructor.
int j
Definition: DBlmapReader.cc:9
int nevents
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool ist0Valid() const
edm::EDGetTokenT< DTRecSegment4DCollection > seg_Token_
int k[5][pyjets_maxn]
edm::EDGetTokenT< L1MuDTChambPhContainer > dcc_Token_
const T & get() const
Definition: EventSetup.h:55
std::vector< DTLocalTrigger >::const_iterator const_iterator
std::map< uint32_t, std::map< std::string, MonitorElement * > > triggerHistos
double pi()
Definition: Pi.h:31
int sector() const
Definition: DTChamberId.h:61
std::pair< const_iterator, const_iterator > Range
dbl *** dir
Definition: mlp_gen.cc:35
int station() const
Return the station number.
Definition: DTChamberId.h:51
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
T get(const Candidate &c)
Definition: component.h:55
Definition: Run.h:41
void bookHistos(const DTChamberId &dtCh)
Book the histograms.