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