CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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,labelGEMHits,iC,true,false,false,false);
83 
84 
85  theNavigationType = pSet.getParameter<string>("NavigationType");
86 
87  theEstimator = new Chi2MeasurementEstimator(theMaxChi2,theNSigma);
88 }
89 
90 
92 {
93  LogTrace("DTDQM|DTMonitorModule|DTChamberEfficiency")
94  << "DTChamberEfficiency: destructor called";
95 
96  // free memory
97  delete theService;
98  delete theMeasurementExtractor;
99  delete theEstimator;
100 }
101 
103 {
104  // Get the DT Geometry
105  setup.get<MuonGeometryRecord>().get(dtGeom);
106 
107  setup.get<IdealMagneticFieldRecord>().get(magfield);
108  setup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry);
109 
110  return;
111 }
112 
113 
114 void DTChamberEfficiency::bookHistograms(DQMStore::IBooker & ibooker, edm::Run const & iRun, edm::EventSetup const & context) {
115 
116  LogTrace("DTDQM|DTMonitorModule|DTChamberEfficiency")
117  << "DTChamberEfficiency: booking histos";
118 
119  // Create the monitor elements
120  ibooker.setCurrentFolder("DT/05-ChamberEff/Task");
121 
122  for(int wheel=-2;wheel<=2;wheel++){
123 
124  vector<MonitorElement *> histos;
125 
126  stringstream wheel_str; wheel_str << wheel;
127 
128  histos.push_back(ibooker.book2D("hCountSectVsChamb_All_W"+ wheel_str.str(),
129  "Countings for wheel " + wheel_str.str(),14,1.,15.,4,1.,5.));
130 
131  histos.push_back(ibooker.book2D("hCountSectVsChamb_Qual_W"+ wheel_str.str(),
132  "Countings for wheel " + wheel_str.str(),14,1.,15.,4,1.,5.));
133 
134 
135  histos.push_back(ibooker.book2D("hExtrapSectVsChamb_W"+ wheel_str.str(),
136  "Extrapolations for wheel " + wheel_str.str(),14,1.,15.,4,1.,5.));
137 
138  histosPerW.push_back(histos);
139  }
140 
141  return;
142 }
143 
145  const EventSetup& eventSetup)
146 {
147 
148  LogTrace("DTDQM|DTMonitorModule|DTChamberEfficiency") <<
149  "--- [DTChamberEfficiency] Event analysed #Run: " <<
150  event.id().run() << " #Event: " << event.id().event() << endl;
151 
152  theService->update(eventSetup);
153  theMeasurementExtractor->setEvent(event);
154 
155  //Read tracks from event
157  event.getByToken(theTracksToken_, tracks);
158 
159  if(tracks.isValid()) { // check the validity of the collection
160 
161  //loop over the muons
162  for(reco::TrackCollection::const_iterator track = tracks->begin(); track!=tracks->end(); ++track) {
163 
164 
165  reco::TransientTrack trans_track(*track,magfield.product(),theTrackingGeometry);
166  const int recHitsize = (int)trans_track.recHitsSize();
167  if(recHitsize < theMinNrec) continue;
168 
169  // printout the DT rechits used by the track
170  if (debug) {
171  LogTrace("DTDQM|DTMonitorModule|DTChamberEfficiency") << "--- New track" << endl;
172  set<DTChamberId> chAlrUsed;
173  for(trackingRecHit_iterator rHit = trans_track.recHitsBegin();
174  rHit != trans_track.recHitsEnd(); ++rHit) {
175  DetId rHitid = (*rHit)->geographicalId();
176  if(!(rHitid.det() == DetId::Muon && rHitid.subdetId() == MuonSubdetId::DT)) continue;
177  DTChamberId wId(rHitid.rawId());
178  if(chAlrUsed.find(wId) != chAlrUsed.end()) continue;
179  chAlrUsed.insert(wId);
180  LogTrace("DTDQM|DTMonitorModule|DTChamberEfficiency") << " " << wId << endl;
181  }
182  }
183 
184  // Get the layer on which the seed relies
185  DetId id = trans_track.track().innerDetId();
186  const DetLayer *initialLayer = theService->detLayerGeometry()->idToLayer(id);
187 
188  TrajectoryStateOnSurface init_fs = trans_track.innermostMeasurementState();
189  const FreeTrajectoryState *init_fs_free = init_fs.freeState();
190 
191  //get the list of compatible layers
192  vector<const DetLayer*> layer_list = compatibleLayers(*theService->muonNavigationSchool(), initialLayer,*init_fs_free,alongMomentum);
193  vector<const DetLayer*> layer_list_2 = compatibleLayers(*theService->muonNavigationSchool(), initialLayer,*init_fs_free,oppositeToMomentum);
194 
195  layer_list.insert(layer_list.end(),layer_list_2.begin(),layer_list_2.end());
196 
197  set<DTChamberId> alreadyCheckedCh;
198 
199  //loop over the list of compatible layers
200  for(int i=0;i< (int)layer_list.size();i++) {
201 
202  //propagate the track to the i-th layer
203  TrajectoryStateOnSurface tsos = propagator()->propagate(init_fs,layer_list.at(i)->surface());
204  if(!tsos.isValid()) continue;
205 
206  //determine the chambers kinematically compatible with the track on the i-th layer
207  vector<DetWithState> dss = layer_list.at(i)->compatibleDets(tsos, *propagator(), *theEstimator);
208 
209  if(dss.size() == 0) continue;
210 
211  // get the first det (it's the most compatible)
212  const DetWithState detWithState = dss.front();
213  const DetId idDetLay = detWithState.first->geographicalId();
214 
215  // check if this is a DT and the track has the needed quality
216  if(!chamberSelection(idDetLay,trans_track)) continue;
217 
218  DTChamberId DTid = (DTChamberId) idDetLay;
219 
220  // check if the chamber has already been counted
221  if(alreadyCheckedCh.find(DTid) != alreadyCheckedCh.end()) continue;
222  alreadyCheckedCh.insert(DTid);
223 
224  // get the compatible measurements
225  MeasurementContainer detMeasurements_initial = theMeasurementExtractor->measurements(layer_list.at(i),
226  detWithState.first,
227  detWithState.second,
228  *theEstimator, event);
229  LogTrace("DTDQM|DTMonitorModule|DTChamberEfficiency") << " chamber: " << DTid
230  << " has: " << detMeasurements_initial.size() << " comp. meas." << endl;
231 
232 
233  //we want to be more picky about the quality of the segments:
234  //exclude the segments with less than 12 hits
235  MeasurementContainer detMeasurements = segQualityCut(detMeasurements_initial);
236 
237  // get the histos for this chamber
238  vector<MonitorElement *> histos = histosPerW[DTid.wheel()+2];
239  // fill them
240  if (detMeasurements_initial.size() != 0) histos[0]->Fill(DTid.sector(),DTid.station(),1.);
241  if (detMeasurements.size() != 0) histos[1]->Fill(DTid.sector(),DTid.station(),1.);
242  histos[2]->Fill(DTid.sector(),DTid.station(),1.);
243 
244 
245  }
246  }
247  } else {
248  LogInfo("DTDQM|DTMonitorModule|DTChamberEfficiency") << "[DTChamberEfficiency] Collection: " << theTracksLabel_
249  << " is not valid!" << endl;
250  }
251  return;
252 }
253 
254 bool DTChamberEfficiency::chamberSelection(const DetId& idDetLay, reco::TransientTrack& trans_track) const
255 {
256  //check that we have a muon and that is a DT detector
257  if(!(idDetLay.det() == DetId::Muon && idDetLay.subdetId() == MuonSubdetId::DT)) return false;
258 
259  if(trans_track.recHitsSize() == 2)
260  if(trans_track.recHit(0)->geographicalId() == idDetLay ||
261  trans_track.recHit(1)->geographicalId() == idDetLay) return false;
262 
263  return true;
264 }
265 
267 {
268 
270 
271  for(MeasurementContainer::const_iterator mescont_Itr = seg_list.begin();
272  mescont_Itr != seg_list.end(); ++mescont_Itr){
273 
274  //get the rechits of the segment
275  TransientTrackingRecHit::ConstRecHitContainer recHit_list = mescont_Itr->recHit()->transientHits();
276 
277  //loop over the rechits and get the number of hits
278  int nhit_seg(0);
279  for(TransientTrackingRecHit::ConstRecHitContainer::const_iterator recList_Itr = recHit_list.begin();
280  recList_Itr != recHit_list.end(); ++recList_Itr){
281 
282  nhit_seg += (int)(*recList_Itr)->transientHits().size();
283  }
284 
285  DTChamberId tmpId = (DTChamberId)mescont_Itr->recHit()->hit()->geographicalId();
286 
287  if(tmpId.station() < 4 && nhit_seg >= 12) result.push_back(*mescont_Itr);
288  if(tmpId.station() == 4 && nhit_seg >= 8) result.push_back(*mescont_Itr);
289  }
290 
291  return result;
292 }
293 
294 vector<const DetLayer*> DTChamberEfficiency::compatibleLayers(const NavigationSchool& navigationSchool, const DetLayer *initialLayer,
295  const FreeTrajectoryState& fts, PropagationDirection propDir)
296 {
297 
298 vector<const DetLayer*> detLayers;
299 
300 if(theNavigationType == "Standard"){
301  // ask for compatible layers
302  detLayers = navigationSchool.compatibleLayers(*initialLayer,fts,propDir);
303  // I have to fit by hand the first layer until the seedTSOS is defined on the first rechit layer
304  // In fact the first layer is not returned by initialLayer->compatibleLayers.
305 
306  detLayers.insert(detLayers.begin(),initialLayer);
307 
308  }
309  else if (theNavigationType == "Direct"){
310 
311  DirectMuonNavigation navigation(ESHandle<MuonDetLayerGeometry>(&*theService->detLayerGeometry()));
312  detLayers = navigation.compatibleLayers(fts,propDir);
313  }
314  else
315  LogError("DTDQM|DTMonitorModule|DTChamberEfficiency") << "No Properly Navigation Selected!!"<<endl;
316 
317  return detLayers;
318 }
319 
321  return theService->propagator("SteppingHelixPropagatorAny");
322 }
323 
324 // Local Variables:
325 // show-trailing-whitespace: t
326 // truncate-lines: t
327 // End:
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
MeasurementContainer segQualityCut(const MeasurementContainer &seg_list) const
DTChamberEfficiency(const edm::ParameterSet &pset)
void dqmBeginRun(const edm::Run &, const edm::EventSetup &)
tuple magfield
Definition: HLT_ES_cff.py:2311
size_t recHitsSize() const
number of RecHits
PropagationDirection
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.
tuple result
Definition: query.py:137
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:75
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:274
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
tuple tracks
Definition: testEve_cfg.py:39
std::vector< TrajectoryMeasurement > MeasurementContainer
const T & get() const
Definition: EventSetup.h:56
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup)
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
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
Definition: Run.h:43