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