CMS 3D CMS Logo

DTResolutionAnalysisTask.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * \author G. Cerminara - INFN Torino
6  */
7 
9 
10 // Framework
14 //#include "FWCore/Framework/interface/LuminosityBlock.h"
16 
18 
20 
21 //Geometry
23 
24 //RecHit
26 
27 #include <iterator>
28 
29 using namespace edm;
30 using namespace std;
31 
33  : muonGeomToken_(esConsumes<edm::Transition::BeginRun>()) {
34  edm::LogVerbatim("DTDQM|DTMonitorModule|DTResolutionAnalysisTask")
35  << "[DTResolutionAnalysisTask] Constructor called!" << endl;
36 
37  // the name of the 4D rec hits collection
38  recHits4DToken_ = consumes<DTRecSegment4DCollection>(edm::InputTag(pset.getParameter<string>("recHits4DLabel")));
39 
40  prescaleFactor = pset.getUntrackedParameter<int>("diagnosticPrescale", 1);
41  resetCycle = pset.getUntrackedParameter<int>("ResetCycle", -1);
42  // top folder for the histograms in DQMStore
43  topHistoFolder = pset.getUntrackedParameter<string>("topHistoFolder", "DT/02-Segments");
44 
45  thePhiHitsCut = pset.getUntrackedParameter<u_int32_t>("phiHitsCut", 8);
46  theZHitsCut = pset.getUntrackedParameter<u_int32_t>("zHitsCut", 4);
47 }
48 
50  edm::LogVerbatim("DTDQM|DTMonitorModule|DTResolutionAnalysisTask")
51  << "[DTResolutionAnalysisTask] Destructor called!" << endl;
52 }
53 
55  // Get the DT Geometry
56  dtGeom = &setup.getData(muonGeomToken_);
57 }
58 
60  edm::Run const& iRun,
61  edm::EventSetup const& /* iSetup */) {
62  // Book the histograms
63  vector<const DTChamber*> chambers = dtGeom->chambers();
64  for (vector<const DTChamber*>::const_iterator chamber = chambers.begin(); chamber != chambers.end();
65  ++chamber) { // Loop over all chambers
66  DTChamberId dtChId = (*chamber)->id();
67  for (int sl = 1; sl <= 3; ++sl) { // Loop over SLs
68  if (dtChId.station() == 4 && sl == 2)
69  continue;
70  const DTSuperLayerId dtSLId(dtChId, sl);
71  bookHistos(ibooker, dtSLId);
72  }
73  }
74 }
75 /*
76 void DTResolutionAnalysisTask::beginLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& context) {
77  edm::LogVerbatim("DTDQM|DTMonitorModule|DTResolutionAnalysisTask")
78  << "[DTResolutionTask]: Begin of LS transition" << endl;
79 
80  if (resetCycle != -1 && lumiSeg.id().luminosityBlock() % resetCycle == 0) {
81  for (map<DTSuperLayerId, vector<MonitorElement*> >::const_iterator histo = histosPerSL.begin();
82  histo != histosPerSL.end();
83  histo++) {
84  int size = (*histo).second.size();
85  for (int i = 0; i < size; i++) {
86  (*histo).second[i]->Reset();
87  }
88  }
89  }
90 }
91 */
93  edm::LogVerbatim("DTDQM|DTMonitorModule|DTResolutionAnalysisTask")
94  << "[DTResolutionAnalysisTask] Analyze #Run: " << event.id().run() << " #Event: " << event.id().event() << endl;
95 
96  // Get the 4D segment collection from the event
98  event.getByToken(recHits4DToken_, all4DSegments);
99 
100  // check the validity of the collection
101  if (!all4DSegments.isValid())
102  return;
103 
104  // Loop over all chambers containing a segment
106  for (chamberId = all4DSegments->id_begin(); chamberId != all4DSegments->id_end(); ++chamberId) {
107  // Get the range for the corresponding ChamerId
108  DTRecSegment4DCollection::range range = all4DSegments->get(*chamberId);
109 
110  // Get the chamber
111  const DTChamber* chamber = dtGeom->chamber(*chamberId);
112 
113  // Loop over the rechits of this ChamerId
114  for (DTRecSegment4DCollection::const_iterator segment4D = range.first; segment4D != range.second; ++segment4D) {
115  // If Statio != 4 skip RecHits with dimension != 4
116  // For the Station 4 consider 2D RecHits
117  if ((*chamberId).station() != 4 && (*segment4D).dimension() != 4) {
118  edm::LogVerbatim("DTDQM|DTMonitorModule|DTResolutionAnalysisTask")
119  << "[DTResolutionAnalysisTask]***Warning: RecSegment dimension is not 4 but " << (*segment4D).dimension()
120  << "!" << endl;
121  continue;
122  } else if ((*chamberId).station() == 4 && (*segment4D).dimension() != 2) {
123  edm::LogVerbatim("DTDQM|DTMonitorModule|DTResolutionAnalysisTask")
124  << "[DTResolutionAnalysisTask]***Warning: RecSegment dimension is not 2 but " << (*segment4D).dimension()
125  << "!" << endl;
126  continue;
127  }
128 
129  // Get all 1D RecHits at step 3 within the 4D segment
130  vector<DTRecHit1D> recHits1D_S3;
131 
132  // Get 1D RecHits at Step 3 and select only events with
133  // 8 hits in phi and 4 hits in theta (if any)
134 
135  if ((*segment4D).hasPhi()) { // has phi component
136  const DTChamberRecSegment2D* phiSeg = (*segment4D).phiSegment();
137  vector<DTRecHit1D> phiRecHits = phiSeg->specificRecHits();
138 
139  if (phiRecHits.size() < thePhiHitsCut) {
140  continue;
141  }
142  copy(phiRecHits.begin(), phiRecHits.end(), back_inserter(recHits1D_S3));
143  } else {
144  }
145 
146  if ((*segment4D).hasZed()) {
147  const DTSLRecSegment2D* zSeg = (*segment4D).zSegment();
148  vector<DTRecHit1D> zRecHits = zSeg->specificRecHits();
149  if (zRecHits.size() < theZHitsCut) {
150  continue;
151  }
152  copy(zRecHits.begin(), zRecHits.end(), back_inserter(recHits1D_S3));
153  }
154 
155  // Loop over 1D RecHit inside 4D segment
156  for (vector<DTRecHit1D>::const_iterator recHit1D = recHits1D_S3.begin(); recHit1D != recHits1D_S3.end();
157  recHit1D++) {
158  const DTWireId wireId = (*recHit1D).wireId();
159 
160  // Get the layer and the wire position
161  const DTLayer* layer = chamber->superLayer(wireId.superlayerId())->layer(wireId.layerId());
162  float wireX = layer->specificTopology().wirePosition(wireId.wire());
163 
164  // Distance of the 1D rechit from the wire
165  float distRecHitToWire = fabs(wireX - (*recHit1D).localPosition().x());
166 
167  // Extrapolate the segment to the z of the wire
168 
169  // Get wire position in chamber RF
170  LocalPoint wirePosInLay(wireX, (*recHit1D).localPosition().y(), (*recHit1D).localPosition().z());
171  GlobalPoint wirePosGlob = layer->toGlobal(wirePosInLay);
172  LocalPoint wirePosInChamber = chamber->toLocal(wirePosGlob);
173 
174  // Segment position at Wire z in chamber local frame
175  LocalPoint segPosAtZWire = (*segment4D).localPosition() + (*segment4D).localDirection() * wirePosInChamber.z() /
176  cos((*segment4D).localDirection().theta());
177 
178  // Compute the distance of the segment from the wire
179  int sl = wireId.superlayer();
180 
181  double distSegmToWire = -1;
182  if (sl == 1 || sl == 3) {
183  // RPhi SL
184  distSegmToWire = fabs(wirePosInChamber.x() - segPosAtZWire.x());
185  } else if (sl == 2) {
186  // RZ SL
187  distSegmToWire = fabs(wirePosInChamber.y() - segPosAtZWire.y());
188  }
189 
190  if (distSegmToWire > 2.1)
191  edm::LogVerbatim("DTDQM|DTMonitorModule|DTResolutionAnalysisTask")
192  << " Warning: dist segment-wire: " << distSegmToWire << endl;
193 
194  double residual = distRecHitToWire - distSegmToWire;
195  // FIXME: Fill the histos
196  fillHistos(wireId.superlayerId(), distSegmToWire, residual);
197 
198  } // End of loop over 1D RecHit inside 4D segment
199  } // End of loop over the rechits of this ChamerId
200  }
201  // -----------------------------------------------------------------------------
202 }
203 
204 // Book a set of histograms for a given SL
206  edm::LogVerbatim("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << " Booking histos for SL: " << slId << endl;
207 
208  // Compose the chamber name
209  stringstream wheel;
210  wheel << slId.wheel();
211  stringstream station;
212  station << slId.station();
213  stringstream sector;
214  sector << slId.sector();
215  stringstream superLayer;
216  superLayer << slId.superlayer();
217 
218  string slHistoName = "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str() + "_SL" + superLayer.str();
219 
220  ibooker.setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" +
221  station.str());
222  // Create the monitor elements
223  vector<MonitorElement*> histos;
224  // Note the order matters
225  histos.push_back(ibooker.book1D(
226  "hResDist" + slHistoName, "Residuals on the distance from wire (rec_hit - segm_extr) (cm)", 200, -0.4, 0.4));
227  histosPerSL[slId] = histos;
228 }
229 
230 // Fill a set of histograms for a given SL
231 void DTResolutionAnalysisTask::fillHistos(DTSuperLayerId slId, float distExtr, float residual) {
232  vector<MonitorElement*> histos = histosPerSL[slId];
233  histos[0]->Fill(residual);
234 }
235 
236 // Local Variables:
237 // show-trailing-whitespace: t
238 // truncate-lines: t
239 // End:
Log< level::Info, true > LogVerbatim
int station() const
Return the station number.
Definition: DTChamberId.h:42
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
int wire() const
Return the wire number.
Definition: DTWireId.h:42
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
T z() const
Definition: PV3DBase.h:61
identifier iterator
Definition: RangeMap.h:130
~DTResolutionAnalysisTask() override
Destructor.
edm::ESGetToken< DTGeometry, MuonGeometryRecord > muonGeomToken_
constexpr std::array< uint8_t, layerIndexSize > layer
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
To reset the MEs.
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Transition
Definition: Transition.h:12
edm::EDGetTokenT< DTRecSegment4DCollection > recHits4DToken_
std::map< DTSuperLayerId, std::vector< MonitorElement * > > histosPerSL
int superlayer() const
Return the superlayer number (deprecated method name)
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
BookHistograms.
bool isValid() const
Definition: HandleBase.h:70
histos
Definition: combine.py:4
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
HLT enums.
int sector() const
Definition: DTChamberId.h:49
void bookHistos(DQMStore::IBooker &ibooker, DTSuperLayerId slId)
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
BeginRun.
void fillHistos(DTSuperLayerId slId, float distExtr, float residual)
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:45
const std::vector< const DTChamber * > & chambers() const
Return a vector of all Chamber.
Definition: DTGeometry.cc:84
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:45
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
static char chambers[264][20]
Definition: ReadPGInfo.cc:243
DTResolutionAnalysisTask(const edm::ParameterSet &pset)
Constructor.
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:90
Definition: event.py:1
Definition: Run.h:45