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