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  * $Date: 2010/04/19 13:59:00 $
6  * $Revision: 1.7 $
7  * \author C. Battilana - CIEMAT
8  *
9 */
10 
12 
13 // Framework
16 
17 // DT trigger
20 
21 // Geometry
28 
29 // tTrigs
32 
33 // DT Digi
36 
37 
38 //Root
39 #include"TH1.h"
40 #include"TAxis.h"
41 
42 #include <sstream>
43 #include <iostream>
44 #include <fstream>
45 
46 
47 using namespace edm;
48 using namespace std;
49 
51 
52  edm::LogVerbatim ("DTLocalTriggerSynchTask") << "[DTLocalTriggerSynchTask]: Constructor" << endl;
53  parameters = ps;
54 
55 }
56 
57 
59 
60  edm::LogVerbatim ("DTLocalTriggerSynchTask") << "[DTLocalTriggerSynchTask]: analyzed " << nevents << " events" << endl;
61 
62 }
63 
64 
66 
67  edm::LogVerbatim ("DTLocalTriggerSynchTask") << "[DTLocalTriggerSynchTask]: BeginJob" << endl;
68 
69  bxTime = parameters.getParameter<double>("bxTimeInterval"); // CB move this to static const or DB
70  rangeInBX = parameters.getParameter<bool>("rangeWithinBX");
71  nBXLow = parameters.getParameter<int>("nBXLow");
72  nBXHigh = parameters.getParameter<int>("nBXHigh");
73  angleRange = parameters.getParameter<double>("angleRange");
74  minHitsPhi = parameters.getParameter<int>("minHitsPhi");
75  baseDirectory = parameters.getParameter<string>("baseDir");
76 
78  dbe->setCurrentFolder(baseDir());
79  dbe->bookFloat("BXTimeSpacing")->Fill(bxTime);
80 
81 }
82 
83 void DTLocalTriggerSynchTask::beginRun(const Run& run, const EventSetup& context) {
84 
85  edm::LogVerbatim ("DTLocalTriggerSynchTask") <<"[DTLocalTriggerSynchTask]: Begin Run"<<endl;
86 
87  context.get<MuonGeometryRecord>().get(muonGeom);
89  parameters.getParameter<edm::ParameterSet>("tTrigModeConfig"));
90  tTrigSync->setES(context);
91 
92 
93  std::vector<DTChamber*>::const_iterator chambIt = muonGeom->chambers().begin();
94  std::vector<DTChamber*>::const_iterator chambEnd = muonGeom->chambers().end();
95 
96  for (; chambIt!=chambEnd; ++chambIt) {
97  bookHistos((*chambIt)->id());
98  triggerHistos[(*chambIt)->id().rawId()]["tTrig_SL1"]->Fill(tTrigSync->offset(DTWireId((*chambIt)->id(),1,1,2)));
99  triggerHistos[(*chambIt)->id().rawId()]["tTrig_SL3"]->Fill(tTrigSync->offset(DTWireId((*chambIt)->id(),3,1,2)));
100  }
101 
102 }
103 
104 
106 
107  edm::LogVerbatim ("DTLocalTriggerSynchTask") << "[DTLocalTriggerSynchTask]: analyzed " << nevents << " events" << endl;
108  dbe->rmdir(baseDir());
109 
110 }
111 
112 
114 
115  nevents++;
116 
117  InputTag inputTagDCC = parameters.getParameter<edm::InputTag>("DCCInputTag");
118  InputTag inputTagDDU = parameters.getParameter<edm::InputTag>("DDUInputTag");
119  InputTag inputTagSEG = parameters.getParameter<edm::InputTag>("SEGInputTag");
120 
121  for (int i=0;i<5;++i){
122  for (int j=0;j<6;++j){
123  for (int k=0;k<13;++k){
124  phCodeBestDCC[j][i][k] = -1;
125  phCodeBestDDU[j][i][k] = -1;
126  }
127  }
128  }
129 
130  // Get best DCC triggers
132  event.getByLabel(inputTagDCC,l1DTTPGPh);
133  vector<L1MuDTChambPhDigi>* phTrigs = l1DTTPGPh->getContainer();
134 
135  vector<L1MuDTChambPhDigi>::const_iterator iph = phTrigs->begin();
136  vector<L1MuDTChambPhDigi>::const_iterator iphe = phTrigs->end();
137  for(; iph !=iphe ; ++iph) {
138 
139  int phwheel = iph->whNum();
140  int phsec = iph->scNum() + 1; // DTTF[0-11] -> DT[1-12] Sector Numbering
141  int phst = iph->stNum();
142  int phcode = iph->code();
143 
144  if(phcode>phCodeBestDCC[phwheel+3][phst][phsec] && phcode<7) {
145  phCodeBestDCC[phwheel+3][phst][phsec]=phcode;
146  }
147 
148  }
149 
150  // Get best DDU triggers
152  event.getByLabel(inputTagDDU,trigsDDU);
154 
155  for (detUnitIt=trigsDDU->begin();detUnitIt!=trigsDDU->end();++detUnitIt){
156 
157  const DTChamberId& id = (*detUnitIt).first;
158  const DTLocalTriggerCollection::Range& range = (*detUnitIt).second;
159 
160  int wh = id.wheel();
161  int sec = id.sector();
162  int st = id.station();
163 
164  for (DTLocalTriggerCollection::const_iterator trigIt = range.first; trigIt!=range.second;++trigIt){
165 
166  int quality = trigIt->quality();
167 
168  if(quality>-1 && quality<7 &&
169  quality>phCodeBestDDU[wh+3][st][sec]) {
170  phCodeBestDDU[wh+3][st][sec]=quality;
171  }
172  }
173  }
174 
175  //Get best segments (highest number of phi hits)
176  vector<const DTRecSegment4D*> bestSegments4D;
178  event.getByLabel(inputTagSEG, segments4D);
181 
182  for (chambIdIt = segments4D->id_begin(); chambIdIt != segments4D->id_end(); ++chambIdIt){
183 
184  DTRecSegment4DCollection::range range = segments4D->get(*chambIdIt);
185  const DTRecSegment4D* best=0;
186  int hitsBest = 0;
187  int hits = 0;
188 
189  for ( track = range.first; track != range.second; ++track){
190  if( (*track).hasPhi() ) {
191  hits = (*track).phiSegment()->degreesOfFreedom()+2;
192  if ( hits>hitsBest ){
193  best = &(*track);
194  hitsBest = hits;
195  }
196  }
197  }
198  if (best) {
199  bestSegments4D.push_back(best);
200  }
201  }
202 
203 
204  // Filling histos
205  vector<const DTRecSegment4D*>::const_iterator bestSegIt = bestSegments4D.begin();
206  vector<const DTRecSegment4D*>::const_iterator bestSegEnd = bestSegments4D.end();
207  for (; bestSegIt!=bestSegEnd; ++bestSegIt ){
208 
209  float dir = atan((*bestSegIt)->localDirection().x()/ (*bestSegIt)->localDirection().z())*180/Geom::pi(); // CB cerca un modo migliore x farlo
210  const DTRecSegment2D* seg2D = (*bestSegIt)->phiSegment();
211  int nHitsPhi = seg2D->degreesOfFreedom()+2;
212  DTChamberId chambId = (*bestSegIt)->chamberId();
213  map<string, MonitorElement*> &innerME = triggerHistos[chambId.rawId()];
214 
215  if (fabs(dir)<angleRange &&
216  nHitsPhi>=minHitsPhi &&
217  seg2D->ist0Valid()){
218 
219  float t0seg = (*bestSegIt)->phiSegment()->t0();
220  float tTrig = (tTrigSync->offset(DTWireId(chambId,1,1,2)) + tTrigSync->offset(DTWireId(chambId,3,1,2)) )/2;
221  float time = tTrig+t0seg;
222  float htime = rangeInBX ? time-int(time/bxTime)*bxTime : time-int(tTrig/bxTime)*bxTime;
223 
224  int wheel = chambId.wheel();
225  int sector = chambId.sector();
226  int station = chambId.station();
227  int scsector = sector>12 ? sector==13 ? 4 : 10 : sector;
228 
229  int qualDCC = phCodeBestDCC[wheel+3][station][scsector];
230  int qualDDU = phCodeBestDDU[wheel+3][station][scsector];
231 
232  if (fabs(t0seg)>0.01) {
233  innerME.find("SEG_TrackCrossingTime")->second->Fill(htime);
234  if ( qualDCC>=0 ) innerME.find("DCC_TrackCrossingTimeAll")->second->Fill(htime);
235  if ( qualDCC==6 ) innerME.find("DCC_TrackCrossingTimeHH")->second->Fill(htime);
236  if ( qualDDU>=0 ) innerME.find("DDU_TrackCrossingTimeAll")->second->Fill(htime);
237  if ( qualDDU==6 ) innerME.find("DDU_TrackCrossingTimeHH")->second->Fill(htime);
238  }
239 
240  }
241  }
242 
243 }
244 
246 
247  stringstream wheel; wheel << dtChId.wheel();
248  stringstream station; station << dtChId.station();
249  stringstream sector; sector << dtChId.sector();
250  uint32_t chRawId = dtChId.rawId();
251 
252  dbe->setCurrentFolder(baseDir() + "/Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str() );
253 
254 
255  string histoTag[5] = { "SEG_TrackCrossingTime", "DCC_TrackCrossingTimeAll", "DCC_TrackCrossingTimeHH", "DDU_TrackCrossingTimeAll", "DDU_TrackCrossingTimeHH" };
256 
257  float min = rangeInBX ? 0 : nBXLow*bxTime;
258  float max = rangeInBX ? bxTime : nBXHigh*bxTime;
259  int nbins = static_cast<int>(ceil( rangeInBX ? bxTime : (nBXHigh-nBXLow)*bxTime));
260 
261  for (int iHisto=0;iHisto<5;++iHisto) {
262  string histoName = histoTag[iHisto] + (rangeInBX ? "InBX" : "") + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
263  edm::LogVerbatim ("DTLocalTriggerSynchTask") << "[DTLocalTriggerSynchTask]: booking "
264  << baseDir() + "/Wheel" << wheel.str()
265  << "/Sector" << sector.str()
266  << "/Station"<< station.str()
267  << "/" << histoName << endl;
268 
269  triggerHistos[chRawId][histoTag[iHisto]] = dbe->book1D(histoName.c_str(),"Track time distribution",nbins,min,max);
270  }
271 
272  string floatTag[2] = { "tTrig_SL1", "tTrig_SL3" };
273 
274  for (int iFloat=0;iFloat<2;++iFloat) {
275  string floatName = floatTag[iFloat] + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
276  triggerHistos[chRawId][floatTag[iFloat]] = dbe->bookFloat(floatName);
277  }
278 
279 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:52
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:722
virtual int degreesOfFreedom() const
return the DOF of the segment
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2535
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
double offset(const DTLayer *layer, const DTWireId &wireId, const GlobalPoint &globalPos)
identifier iterator
Definition: RangeMap.h:138
#define min(a, b)
Definition: mlp_lapack.h:161
MonitorElement * bookFloat(const char *name)
Book float.
Definition: DQMStore.cc:659
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:45
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:45
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
int k[5][pyjets_maxn]
const T & get() const
Definition: EventSetup.h:55
std::vector< DigiType >::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:63
std::pair< const_iterator, const_iterator > Range
dbl *** dir
Definition: mlp_gen.cc:35
int station() const
Return the station number.
Definition: DTChamberId.h:53
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:434
T get(const Candidate &c)
Definition: component.h:56
Definition: Run.h:36
void bookHistos(const DTChamberId &dtCh)
Book the histograms.