CMS 3D CMS Logo

DTChamberEfficiency.cc
Go to the documentation of this file.
1 /******* \class DTEffAnalyzer *******
2  *
3  * Description:
4  *
5  * detailed description
6  *
7  * \author : Mario Pelliccioni, pellicci@cern.ch
8  * $date : 20/11/2008 16:50:57 CET $
9  *
10  * Modification:
11  *
12  *********************************/
13 
14 #include "DTChamberEfficiency.h"
15 
20 
22 
24 
27 
29 
31 
33 
35 
37 
42 
47 
48 #include <cmath>
49 
50 using namespace std;
51 using namespace edm;
52 
54  // Get the debug parameter for verbose output
55  debug = pSet.getUntrackedParameter<bool>("debug", false);
56 
57  LogVerbatim("DTDQM|DTMonitorModule|DTChamberEfficiency") << "DTChamberEfficiency: constructor called";
58 
59  // service parameters
60  ParameterSet serviceParameters = pSet.getParameter<ParameterSet>("ServiceParameters");
61  theService = new MuonServiceProxy(serviceParameters);
62 
63  theTracksLabel_ = pSet.getParameter<InputTag>("TrackCollection");
64  theTracksToken_ = consumes<reco::TrackCollection>(theTracksLabel_);
65 
66  theMaxChi2 = static_cast<unsigned int>(pSet.getParameter<double>("theMaxChi2"));
67  theNSigma = pSet.getParameter<double>("theNSigma");
68  theMinNrec = static_cast<int>(pSet.getParameter<double>("theMinNrec"));
69 
70  labelRPCRecHits = pSet.getParameter<InputTag>("theRPCRecHits");
71 
72  thedt4DSegments = pSet.getParameter<InputTag>("dt4DSegments");
73  thecscSegments = pSet.getParameter<InputTag>("cscSegments");
74 
75  edm::ConsumesCollector iC = consumesCollector();
76 
77  theMeasurementExtractor = new MuonDetLayerMeasurements(
78  thedt4DSegments, thecscSegments, labelRPCRecHits, InputTag(), InputTag(), iC, true, false, false, false);
79 
80  theNavigationType = pSet.getParameter<string>("NavigationType");
81 
82  theEstimator = new Chi2MeasurementEstimator(theMaxChi2, theNSigma);
83 }
84 
86  LogTrace("DTDQM|DTMonitorModule|DTChamberEfficiency") << "DTChamberEfficiency: destructor called";
87 
88  // free memory
89  delete theService;
90  delete theMeasurementExtractor;
91  delete theEstimator;
92 }
93 
95  // Get the DT Geometry
96  setup.get<MuonGeometryRecord>().get(dtGeom);
97 
99  setup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry);
100 
101  return;
102 }
103 
105  edm::Run const& iRun,
106  edm::EventSetup const& context) {
107  LogTrace("DTDQM|DTMonitorModule|DTChamberEfficiency") << "DTChamberEfficiency: booking histos";
108 
109  // Create the monitor elements
110  ibooker.setCurrentFolder("DT/05-ChamberEff/Task");
111 
112  for (int wheel = -2; wheel <= 2; wheel++) {
113  vector<MonitorElement*> histos;
114 
115  stringstream wheel_str;
116  wheel_str << wheel;
117 
118  histos.push_back(ibooker.book2D(
119  "hCountSectVsChamb_All_W" + wheel_str.str(), "Countings for wheel " + wheel_str.str(), 14, 1., 15., 4, 1., 5.));
120 
121  histos.push_back(ibooker.book2D(
122  "hCountSectVsChamb_Qual_W" + wheel_str.str(), "Countings for wheel " + wheel_str.str(), 14, 1., 15., 4, 1., 5.));
123 
124  histos.push_back(ibooker.book2D(
125  "hExtrapSectVsChamb_W" + wheel_str.str(), "Extrapolations for wheel " + wheel_str.str(), 14, 1., 15., 4, 1., 5.));
126 
127  histosPerW.push_back(histos);
128  }
129 
130  return;
131 }
132 
133 void DTChamberEfficiency::analyze(const Event& event, const EventSetup& eventSetup) {
134  LogTrace("DTDQM|DTMonitorModule|DTChamberEfficiency")
135  << "--- [DTChamberEfficiency] Event analysed #Run: " << event.id().run() << " #Event: " << event.id().event()
136  << endl;
137 
138  theService->update(eventSetup);
139  theMeasurementExtractor->setEvent(event);
140 
141  //Read tracks from event
143  event.getByToken(theTracksToken_, tracks);
144 
145  if (tracks.isValid()) { // check the validity of the collection
146 
147  //loop over the muons
148  for (reco::TrackCollection::const_iterator track = tracks->begin(); track != tracks->end(); ++track) {
149  reco::TransientTrack trans_track(*track, magfield.product(), theTrackingGeometry);
150  const int recHitsize = (int)trans_track.recHitsSize();
151  if (recHitsize < theMinNrec)
152  continue;
153 
154  // printout the DT rechits used by the track
155  if (debug) {
156  LogTrace("DTDQM|DTMonitorModule|DTChamberEfficiency") << "--- New track" << endl;
157  set<DTChamberId> chAlrUsed;
158  for (trackingRecHit_iterator rHit = trans_track.recHitsBegin(); rHit != trans_track.recHitsEnd(); ++rHit) {
159  DetId rHitid = (*rHit)->geographicalId();
160  if (!(rHitid.det() == DetId::Muon && rHitid.subdetId() == MuonSubdetId::DT))
161  continue;
162  DTChamberId wId(rHitid.rawId());
163  if (chAlrUsed.find(wId) != chAlrUsed.end())
164  continue;
165  chAlrUsed.insert(wId);
166  LogTrace("DTDQM|DTMonitorModule|DTChamberEfficiency") << " " << wId << endl;
167  }
168  }
169 
170  // Get the layer on which the seed relies
171  DetId id = trans_track.track().innerDetId();
172  const DetLayer* initialLayer = theService->detLayerGeometry()->idToLayer(id);
173 
174  TrajectoryStateOnSurface init_fs = trans_track.innermostMeasurementState();
175  const FreeTrajectoryState* init_fs_free = init_fs.freeState();
176 
177  //get the list of compatible layers
178  vector<const DetLayer*> layer_list =
179  compatibleLayers(*theService->muonNavigationSchool(), initialLayer, *init_fs_free, alongMomentum);
180  vector<const DetLayer*> layer_list_2 =
181  compatibleLayers(*theService->muonNavigationSchool(), initialLayer, *init_fs_free, oppositeToMomentum);
182 
183  layer_list.insert(layer_list.end(), layer_list_2.begin(), layer_list_2.end());
184 
185  set<DTChamberId> alreadyCheckedCh;
186 
187  //loop over the list of compatible layers
188  for (int i = 0; i < (int)layer_list.size(); i++) {
189  //propagate the track to the i-th layer
190  TrajectoryStateOnSurface tsos = propagator()->propagate(init_fs, layer_list.at(i)->surface());
191  if (!tsos.isValid())
192  continue;
193 
194  //determine the chambers kinematically compatible with the track on the i-th layer
195  vector<DetWithState> dss = layer_list.at(i)->compatibleDets(tsos, *propagator(), *theEstimator);
196 
197  if (dss.empty())
198  continue;
199 
200  // get the first det (it's the most compatible)
201  const DetWithState detWithState = dss.front();
202  const DetId idDetLay = detWithState.first->geographicalId();
203 
204  // check if this is a DT and the track has the needed quality
205  if (!chamberSelection(idDetLay, trans_track))
206  continue;
207 
208  DTChamberId DTid = (DTChamberId)idDetLay;
209 
210  // check if the chamber has already been counted
211  if (alreadyCheckedCh.find(DTid) != alreadyCheckedCh.end())
212  continue;
213  alreadyCheckedCh.insert(DTid);
214 
215  // get the compatible measurements
216  MeasurementContainer detMeasurements_initial = theMeasurementExtractor->measurements(
217  layer_list.at(i), detWithState.first, detWithState.second, *theEstimator, event);
218  LogTrace("DTDQM|DTMonitorModule|DTChamberEfficiency")
219  << " chamber: " << DTid << " has: " << detMeasurements_initial.size() << " comp. meas." << endl;
220 
221  //we want to be more picky about the quality of the segments:
222  //exclude the segments with less than 12 hits
223  MeasurementContainer detMeasurements = segQualityCut(detMeasurements_initial);
224 
225  // get the histos for this chamber
226  vector<MonitorElement*> histos = histosPerW[DTid.wheel() + 2];
227  // fill them
228  if (!detMeasurements_initial.empty())
229  histos[0]->Fill(DTid.sector(), DTid.station(), 1.);
230  if (!detMeasurements.empty())
231  histos[1]->Fill(DTid.sector(), DTid.station(), 1.);
232  histos[2]->Fill(DTid.sector(), DTid.station(), 1.);
233  }
234  }
235  } else {
236  LogInfo("DTDQM|DTMonitorModule|DTChamberEfficiency")
237  << "[DTChamberEfficiency] Collection: " << theTracksLabel_ << " is not valid!" << endl;
238  }
239  return;
240 }
241 
242 bool DTChamberEfficiency::chamberSelection(const DetId& idDetLay, reco::TransientTrack& trans_track) const {
243  //check that we have a muon and that is a DT detector
244  if (!(idDetLay.det() == DetId::Muon && idDetLay.subdetId() == MuonSubdetId::DT))
245  return false;
246 
247  if (trans_track.recHitsSize() == 2)
248  if (trans_track.recHit(0)->geographicalId() == idDetLay || trans_track.recHit(1)->geographicalId() == idDetLay)
249  return false;
250 
251  return true;
252 }
253 
256 
257  for (MeasurementContainer::const_iterator mescont_Itr = seg_list.begin(); mescont_Itr != seg_list.end();
258  ++mescont_Itr) {
259  //get the rechits of the segment
260  TransientTrackingRecHit::ConstRecHitContainer recHit_list = mescont_Itr->recHit()->transientHits();
261 
262  //loop over the rechits and get the number of hits
263  int nhit_seg(0);
264  for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator recList_Itr = recHit_list.begin();
265  recList_Itr != recHit_list.end();
266  ++recList_Itr) {
267  nhit_seg += (int)(*recList_Itr)->transientHits().size();
268  }
269 
270  DTChamberId tmpId = (DTChamberId)mescont_Itr->recHit()->hit()->geographicalId();
271 
272  if (tmpId.station() < 4 && nhit_seg >= 12)
273  result.push_back(*mescont_Itr);
274  if (tmpId.station() == 4 && nhit_seg >= 8)
275  result.push_back(*mescont_Itr);
276  }
277 
278  return result;
279 }
280 
281 vector<const DetLayer*> DTChamberEfficiency::compatibleLayers(const NavigationSchool& navigationSchool,
282  const DetLayer* initialLayer,
283  const FreeTrajectoryState& fts,
284  PropagationDirection propDir) {
285  vector<const DetLayer*> detLayers;
286 
287  if (theNavigationType == "Standard") {
288  // ask for compatible layers
289  detLayers = navigationSchool.compatibleLayers(*initialLayer, fts, propDir);
290  // I have to fit by hand the first layer until the seedTSOS is defined on the first rechit layer
291  // In fact the first layer is not returned by initialLayer->compatibleLayers.
292 
293  detLayers.insert(detLayers.begin(), initialLayer);
294 
295  } else if (theNavigationType == "Direct") {
296  DirectMuonNavigation navigation(ESHandle<MuonDetLayerGeometry>(&*theService->detLayerGeometry()));
297  detLayers = navigation.compatibleLayers(fts, propDir);
298  } else
299  LogError("DTDQM|DTMonitorModule|DTChamberEfficiency") << "No Properly Navigation Selected!!" << endl;
300 
301  return detLayers;
302 }
303 
305  return theService->propagator("SteppingHelixPropagatorAny");
306 }
307 
308 // Local Variables:
309 // show-trailing-whitespace: t
310 // truncate-lines: t
311 // End:
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
MeasurementContainer segQualityCut(const MeasurementContainer &seg_list) const
DTChamberEfficiency(const edm::ParameterSet &pset)
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
size_t recHitsSize() const
number of RecHits
PropagationDirection
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
std::vector< const DetLayer * > compatibleLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
const SurfaceType & surface() const
bool chamberSelection(const DetId &idDetLay, reco::TransientTrack &trans_track) const
edm::ESHandle< Propagator > propagator() const
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
FreeTrajectoryState const * freeState(bool withErrors=true) const
std::vector< const DetLayer * > compatibleLayers(const DetLayer &detLayer, Args &&...args) const
Returns all layers compatible.
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
TrackingRecHitRef recHit(size_t i) const
get n-th recHit
std::vector< const DetLayer * > compatibleLayers(const NavigationSchool &navigationSchool, const DetLayer *initialLayer, const FreeTrajectoryState &fts, PropagationDirection propDir)
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 isValid() const
Definition: HandleBase.h:70
#define LogTrace(id)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::vector< ConstRecHitPointer > ConstRecHitContainer
Definition: DetId.h:17
#define debug
Definition: HDRShower.cc:19
std::vector< TrajectoryMeasurement > MeasurementContainer
histos
Definition: combine.py:4
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
HLT enums.
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
int sector() const
Definition: DTChamberId.h:49
T get() const
Definition: EventSetup.h:73
static constexpr int DT
Definition: MuonSubdetId.h:11
int station() const
Return the station number.
Definition: DTChamberId.h:42
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
Definition: event.py:1
Definition: Run.h:45
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46