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
24 
25 //RecHit
27 
28 #include <iterator>
29 
30 using namespace edm;
31 using namespace std;
32 
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  setup.get<MuonGeometryRecord>().get(dtGeom);
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:
DTSLRecSegment2D
Definition: DTSLRecSegment2D.h:15
DTSuperLayerId
Definition: DTSuperLayerId.h:12
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
DTResolutionAnalysisTask::DTResolutionAnalysisTask
DTResolutionAnalysisTask(const edm::ParameterSet &pset)
Constructor.
Definition: DTResolutionAnalysisTask.cc:33
DTWireId::wire
int wire() const
Return the wire number.
Definition: DTWireId.h:42
MessageLogger.h
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
DTRecHitCollection.h
ALCARECODTCalibSynchCosmicsDQMClient_cff.topHistoFolder
topHistoFolder
Definition: ALCARECODTCalibSynchCosmicsDQMClient_cff.py:5
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
edm::Run
Definition: Run.h:45
relativeConstraints.station
station
Definition: relativeConstraints.py:67
edm
HLT enums.
Definition: AlignableModifier.h:19
DTChamber
Definition: DTChamber.h:24
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
DQMStore.h
DTSuperLayerId::superlayer
int superlayer() const
Return the superlayer number (deprecated method name)
Definition: DTSuperLayerId.h:42
DTResolutionAnalysisTask::dqmBeginRun
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
BeginRun.
Definition: DTResolutionAnalysisTask.cc:54
edm::Handle< DTRecSegment4DCollection >
edm::RangeMap::id_iterator
identifier iterator
Definition: RangeMap.h:130
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
DTResolutionAnalysisTask::analyze
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
To reset the MEs.
Definition: DTResolutionAnalysisTask.cc:92
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DTWireId
Definition: DTWireId.h:12
Service.h
DTResolutionAnalysisTask::~DTResolutionAnalysisTask
~DTResolutionAnalysisTask() override
Destructor.
Definition: DTResolutionAnalysisTask.cc:49
bookHistos
void bookHistos()
Definition: Histogram.h:33
Point3DBase< float, LocalTag >
phase1PixelTopology::layer
constexpr std::array< uint8_t, layerIndexSize > layer
Definition: phase1PixelTopology.h:99
DTGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
DTResolutionAnalysisTask::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
BookHistograms.
Definition: DTResolutionAnalysisTask.cc:59
edm::RangeMap::const_iterator
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
edm::get
T const & get(Event const &event, InputTag const &tag) noexcept(false)
Definition: Event.h:675
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
makeMuonMisalignmentScenario.wheel
wheel
Definition: makeMuonMisalignmentScenario.py:319
Skims_PDWG_cff.prescaleFactor
prescaleFactor
Definition: Skims_PDWG_cff.py:25
DTChamberRecSegment2D
Definition: DTChamberRecSegment2D.h:31
chambers
static char chambers[264][20]
Definition: ReadPGInfo.cc:243
edm::EventSetup
Definition: EventSetup.h:58
DTLayer
Definition: DTLayer.h:25
combine.histos
histos
Definition: combine.py:4
DTChamberId::sector
int sector() const
Definition: DTChamberId.h:49
edm::RangeMap::range
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
DTLayerId::superlayerId
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:45
DTRecSegment2D::specificRecHits
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
Definition: DTRecSegment2D.cc:104
relativeConstraints.chamber
chamber
Definition: relativeConstraints.py:53
EventSetup.h
dqm::implementation::IBooker
Definition: DQMStore.h:43
DTWireId::layerId
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:45
DTResolutionAnalysisTask::bookHistos
void bookHistos(DQMStore::IBooker &ibooker, DTSuperLayerId slId)
Definition: DTResolutionAnalysisTask.cc:205
DTChamberId
Definition: DTChamberId.h:14
DTResolutionAnalysisTask::fillHistos
void fillHistos(DTSuperLayerId slId, float distExtr, float residual)
Definition: DTResolutionAnalysisTask.cc:231
ParameterSet.h
MuonGeometryRecord.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
DTChamberId::wheel
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
edm::InputTag
Definition: InputTag.h:15
DTChamberId::station
int station() const
Return the station number.
Definition: DTChamberId.h:42
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
DTResolutionAnalysisTask.h