CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HitEff.cc
Go to the documentation of this file.
1 // Package: CalibTracker/SiStripHitEfficiency
3 // Class: HitEff
4 // Original Author: Keith Ulmer--University of Colorado
5 // keith.ulmer@colorado.edu
6 //
8 
9 // system include files
10 #include <memory>
11 #include <string>
12 #include <iostream>
13 
18 
48 
60 
63 
64 
65 #include "TMath.h"
66 #include "TH1F.h"
67 
68 //
69 // constructors and destructor
70 //
71 
72 using namespace std;
74  conf_(conf)
75 {
76  layers =conf_.getParameter<int>("Layer");
77  DEBUG = conf_.getParameter<bool>("Debug");
78 }
79 
80 // Virtual destructor needed.
82 
84 
86 
87  traj = fs->make<TTree>("traj","tree of trajectory positions");
88  traj->Branch("TrajGlbX",&TrajGlbX,"TrajGlbX/F");
89  traj->Branch("TrajGlbY",&TrajGlbY,"TrajGlbY/F");
90  traj->Branch("TrajGlbZ",&TrajGlbZ,"TrajGlbZ/F");
91  traj->Branch("TrajLocX",&TrajLocX,"TrajLocX/F");
92  traj->Branch("TrajLocY",&TrajLocY,"TrajLocY/F");
93  traj->Branch("TrajLocErrX",&TrajLocErrX,"TrajLocErrX/F");
94  traj->Branch("TrajLocErrY",&TrajLocErrY,"TrajLocErrY/F");
95  traj->Branch("TrajLocAngleX",&TrajLocAngleX,"TrajLocAngleX/F");
96  traj->Branch("TrajLocAngleY",&TrajLocAngleY,"TrajLocAngleY/F");
97  traj->Branch("ClusterLocX",&ClusterLocX,"ClusterLocX/F");
98  traj->Branch("ClusterLocY",&ClusterLocY,"ClusterLocY/F");
99  traj->Branch("ClusterLocErrX",&ClusterLocErrX,"ClusterLocErrX/F");
100  traj->Branch("ClusterLocErrY",&ClusterLocErrY,"ClusterLocErrY/F");
101  traj->Branch("ClusterStoN",&ClusterStoN,"ClusterStoN/F");
102  traj->Branch("ResX",&ResX,"ResX/F");
103  traj->Branch("ResXSig",&ResXSig,"ResXSig/F");
104  traj->Branch("ModIsBad",&ModIsBad,"ModIsBad/i");
105  traj->Branch("SiStripQualBad",&SiStripQualBad,"SiStripQualBad/i");
106  traj->Branch("withinAcceptance",&withinAcceptance,"withinAcceptance/O");
107  traj->Branch("nHits",&nHits,"nHits/I");
108  traj->Branch("nLostHits",&nLostHits,"nLostHits/I");
109  traj->Branch("chi2",&chi2,"chi2/F");
110  traj->Branch("p",&p,"p/F");
111  traj->Branch("pT",&pT,"pT/F");
112  traj->Branch("trajHitValid", &trajHitValid, "trajHitValid/i");
113  traj->Branch("Id",&Id,"Id/i");
114  traj->Branch("run",&run,"run/i");
115  traj->Branch("event",&event,"event/i");
116  traj->Branch("layer",&whatlayer,"layer/i");
117  traj->Branch("timeDT",&timeDT,"timeDT/F");
118  traj->Branch("timeDTErr",&timeDTErr,"timeDTErr/F");
119  traj->Branch("timeDTDOF",&timeDTDOF,"timeDTDOF/I");
120  traj->Branch("timeECAL",&timeECAL,"timeECAL/F");
121  traj->Branch("dedx",&dedx,"dedx/F");
122  traj->Branch("dedxNOM",&dedxNOM,"dedxNOM/I");
123  traj->Branch("tquality",&tquality,"tquality/I");
124  traj->Branch("istep",&istep,"istep/I");
125  traj->Branch("bunchx",&bunchx,"bunchx/I");
126 
127  events = 0;
128  EventTrackCKF = 0;
129 
130 }
131 
132 
133 void HitEff::analyze(const edm::Event& e, const edm::EventSetup& es){
134  //Retrieve tracker topology from geometry
135  edm::ESHandle<TrackerTopology> tTopoHandle;
136  es.get<IdealGeometryRecord>().get(tTopoHandle);
137  const TrackerTopology* const tTopo = tTopoHandle.product();
138 
139  // bool DEBUG = false;
140 
141  if (DEBUG) cout << "beginning analyze from HitEff" << endl;
142 
143  using namespace edm;
144  using namespace reco;
145  // Step A: Get Inputs
146 
147  int run_nr = e.id().run();
148  int ev_nr = e.id().event();
149  int bunch_nr = e.bunchCrossing();
150 
151  //CombinatoriaTrack
152  edm::Handle<reco::TrackCollection> trackCollectionCKF;
153  edm::InputTag TkTagCKF = conf_.getParameter<edm::InputTag>("combinatorialTracks");
154  e.getByLabel(TkTagCKF,trackCollectionCKF);
155 
156  edm::Handle<std::vector<Trajectory> > TrajectoryCollectionCKF;
157  edm::InputTag TkTrajCKF = conf_.getParameter<edm::InputTag>("trajectories");
158  e.getByLabel(TkTrajCKF,TrajectoryCollectionCKF);
159 
160  // Clusters
161  // get the SiStripClusters from the event
163  e.getByLabel("siStripClusters", theClusters);
164 
165  //get tracker geometry
168  const TrackerGeometry * tkgeom=&(* tracker);
169 
170  //get Cluster Parameter Estimator
171  //std::string cpe = conf_.getParameter<std::string>("StripCPE");
173  es.get<TkStripCPERecord>().get("StripCPEfromTrackAngle", parameterestimator);
174  const StripClusterParameterEstimator &stripcpe(*parameterestimator);
175 
176  // get the SiStripQuality records
177  edm::ESHandle<SiStripQuality> SiStripQuality_;
178  try {
179  es.get<SiStripQualityRcd>().get("forCluster",SiStripQuality_);
180  }
181  catch (...) {
182  es.get<SiStripQualityRcd>().get(SiStripQuality_);
183  }
184 
185  edm::ESHandle<MagneticField> magFieldHandle;
186  es.get<IdealMagneticFieldRecord>().get(magFieldHandle);
187  const MagneticField* magField_ = magFieldHandle.product();
188 
189  // get the list of module IDs with FED-detected errors
190  edm::Handle< DetIdCollection > fedErrorIds;
191  e.getByLabel("siStripDigis", fedErrorIds );
192 
193  ESHandle<MeasurementTracker> measurementTrackerHandle;
194  es.get<CkfComponentsRecord>().get(measurementTrackerHandle);
195 
196  edm::Handle<MeasurementTrackerEvent> measurementTrackerEvent;
197  e.getByLabel("MeasurementTrackerEvent", measurementTrackerEvent);
198 
200  es.get<TrackingComponentsRecord>().get("Chi2",est);
201 
203  es.get<TrackingComponentsRecord>().get("PropagatorWithMaterial",prop);
204  const Propagator* thePropagator = prop.product();
205 
206  events++;
207 
208  // *************** SiStripCluster Collection
209  const edmNew::DetSetVector<SiStripCluster>& input = *theClusters;
210 
211  //go through clusters to write out global position of good clusters for the layer understudy for comparison
212  // Loop through clusters just to print out locations
213  // Commented out to avoid discussion, should really be deleted.
214  /*
215  for (edmNew::DetSetVector<SiStripCluster>::const_iterator DSViter = input.begin(); DSViter != input.end(); DSViter++) {
216  // DSViter is a vector of SiStripClusters located on a single module
217  unsigned int ClusterId = DSViter->id();
218  DetId ClusterDetId(ClusterId);
219  const StripGeomDetUnit * stripdet=(const StripGeomDetUnit*)tkgeom->idToDetUnit(ClusterDetId);
220 
221  edmNew::DetSet<SiStripCluster>::const_iterator begin=DSViter->begin();
222  edmNew::DetSet<SiStripCluster>::const_iterator end =DSViter->end();
223  for(edmNew::DetSet<SiStripCluster>::const_iterator iter=begin;iter!=end;++iter) {
224  //iter is a single SiStripCluster
225  StripClusterParameterEstimator::LocalValues parameters=stripcpe.localParameters(*iter,*stripdet);
226 
227  const Surface* surface;
228  surface = &(tracker->idToDet(ClusterDetId)->surface());
229  LocalPoint lp = parameters.first;
230  GlobalPoint gp = surface->toGlobal(lp);
231  unsigned int layer = checkLayer(ClusterId, tTopo);
232  if(DEBUG) cout << "Found hit in cluster collection layer = " << layer << " with id = " << ClusterId << " local X position = " << lp.x() << " +- " << sqrt(parameters.second.xx()) << " matched/stereo/rphi = " << ((ClusterId & 0x3)==0) << "/" << ((ClusterId & 0x3)==1) << "/" << ((ClusterId & 0x3)==2) << endl;
233  }
234  }
235  */
236 
237  // Tracking
238  const reco::TrackCollection *tracksCKF=trackCollectionCKF.product();
239  if (DEBUG) cout << "number ckf tracks found = " << tracksCKF->size() << endl;
240  //if (tracksCKF->size() == 1 ){
241  if (tracksCKF->size() > 0 && tracksCKF->size()<100) {
242  if (DEBUG) cout << "starting checking good event with < 100 tracks" << endl;
243 
244  EventTrackCKF++;
245 
246  /*
247 
248  //get dEdx info if available
249  Handle<ValueMap<DeDxData> > dEdxUncalibHandle;
250  if (e.getByLabel("dedxMedianCTF", dEdxUncalibHandle)) {
251  const ValueMap<DeDxData> dEdxTrackUncalib = *dEdxUncalibHandle.product();
252 
253  reco::TrackRef itTrack = reco::TrackRef( trackCollectionCKF, 0 );
254  dedx = dEdxTrackUncalib[itTrack].dEdx();
255  dedxNOM = dEdxTrackUncalib[itTrack].numberOfMeasurements();
256  } else {
257  dedx = -999.0; dedxNOM = -999;
258  }
259 
260  */
261 
262  //get muon and ecal timing info if available
264  if(e.getByLabel("muonsWitht0Correction",muH)){
265  const MuonCollection & muonsT0 = *muH.product();
266  if(muonsT0.size()!=0) {
267  MuonTime mt0 = muonsT0[0].time();
268  timeDT = mt0.timeAtIpInOut;
270  timeDTDOF = mt0.nDof;
271 
272  bool hasCaloEnergyInfo = muonsT0[0].isEnergyValid();
273  if (hasCaloEnergyInfo) timeECAL = muonsT0[0].calEnergy().ecal_time;
274  }
275  } else {
276  timeDT = -999.0; timeDTErr = -999.0; timeDTDOF = -999; timeECAL = -999.0;
277  }
278 
279  // actually should do a loop over all the tracks in the event here
280 
281  for (vector<Trajectory>::const_iterator itraj = TrajectoryCollectionCKF.product()->begin();
282  itraj != TrajectoryCollectionCKF.product()->end();
283  itraj++) {
284 
285  // for each track, fill some variables such as number of hits and momentum
286  nHits = itraj->foundHits();
287  nLostHits = itraj->lostHits();
288  chi2 = (itraj->chiSquared()/itraj->ndof());
289  pT = sqrt( ( itraj->lastMeasurement().updatedState().globalMomentum().x() *
290  itraj->lastMeasurement().updatedState().globalMomentum().x()) +
291  ( itraj->lastMeasurement().updatedState().globalMomentum().y() *
292  itraj->lastMeasurement().updatedState().globalMomentum().y()) );
293  p = itraj->lastMeasurement().updatedState().globalMomentum().mag();
294 
295  //Put in code to check track quality
296 
297 
298  std::vector<TrajectoryMeasurement> TMeas=itraj->measurements();
299  vector<TrajectoryMeasurement>::iterator itm;
300  double xloc = 0.;
301  double yloc = 0.;
302  double xErr = 0.;
303  double yErr = 0.;
304  double angleX = -999.;
305  double angleY = -999.;
306  double xglob,yglob,zglob;
307 
308  for (itm=TMeas.begin();itm!=TMeas.end();itm++){
309  auto theInHit = (*itm).recHit();
310 
311  if(DEBUG) cout << "theInHit is valid = " << theInHit->isValid() << endl;
312 
313  unsigned int iidd = theInHit->geographicalId().rawId();
314 
315  unsigned int TKlayers = checkLayer(iidd, tTopo);
316  if (DEBUG) cout << "TKlayer from trajectory: " << TKlayers << " from module = " << iidd << " matched/stereo/rphi = " << ((iidd & 0x3)==0) << "/" << ((iidd & 0x3)==1) << "/" << ((iidd & 0x3)==2) << endl;
317 
318  // If Trajectory measurement from TOB 6 or TEC 9, skip it because it's always valid they are filled later
319  if ( TKlayers == 10 || TKlayers == 22 ) {
320  if (DEBUG) cout << "skipping original TM for TOB 6 or TEC 9" << endl;
321  continue;
322  }
323 
324  // Make vector of TrajectoryAtInvalidHits to hold the trajectories
325  std::vector<TrajectoryAtInvalidHit> TMs;
326 
327  // Make AnalyticalPropagator to use in TAVH constructor
328  AnalyticalPropagator propagator(magField_,anyDirection);
329 
330  // for double sided layers check both sensors--if no hit was found on either sensor surface,
331  // the trajectory measurements only have one invalid hit entry on the matched surface
332  // so get the TrajectoryAtInvalidHit for both surfaces and include them in the study
333  if (isDoubleSided(iidd, tTopo) && ((iidd & 0x3)==0) ) {
334  // do hit eff check twice--once for each sensor
335  //add a TM for each surface
336  TMs.push_back(TrajectoryAtInvalidHit(*itm, tTopo, tkgeom, propagator, 1));
337  TMs.push_back(TrajectoryAtInvalidHit(*itm, tTopo, tkgeom, propagator, 2));
338  } else if ( isDoubleSided(iidd, tTopo) && (!check2DPartner(iidd, TMeas)) ) {
339  // if only one hit was found the trajectory measurement is on that sensor surface, and the other surface from
340  // the matched layer should be added to the study as well
341  TMs.push_back(TrajectoryAtInvalidHit(*itm, tTopo, tkgeom, propagator, 1));
342  TMs.push_back(TrajectoryAtInvalidHit(*itm, tTopo, tkgeom, propagator, 2));
343  if (DEBUG) cout << " found a hit with a missing partner" << endl;
344  } else {
345  //only add one TM for the single surface and the other will be added in the next iteration
346  TMs.push_back(TrajectoryAtInvalidHit(*itm, tTopo, tkgeom, propagator));
347  }
348 
350  //Now check for tracks at TOB6 and TEC9
351 
352  // to make sure we only propagate on the last TOB5 hit check the next entry isn't also in TOB5
353  // to avoid bias, make sure the TOB5 hit is valid (an invalid hit on TOB5 could only exist with a valid hit on TOB6)
354 
355  bool isValid = theInHit->isValid();
356  bool isLast = (itm==(TMeas.end()-1));
357  bool isLastTOB5 = true;
358  if (!isLast) {
359  if ( checkLayer((++itm)->recHit()->geographicalId().rawId(), tTopo) == 9 ) isLastTOB5 = false;
360  else isLastTOB5 = true;
361  --itm;
362  }
363 
364  if ( TKlayers==9 && isValid && isLastTOB5 ) {
365  // if ( TKlayers==9 && itm==TMeas.rbegin()) {
366  // if ( TKlayers==9 && (itm==TMeas.back()) ) { // to check for only the last entry in the trajectory for propagation
367  std::vector< BarrelDetLayer const*> barrelTOBLayers = measurementTrackerHandle->geometricSearchTracker()->tobLayers() ;
368  const DetLayer* tob6 = barrelTOBLayers[barrelTOBLayers.size()-1];
369  const MeasurementEstimator* estimator = est.product();
370  const LayerMeasurements* theLayerMeasurements = new LayerMeasurements(*measurementTrackerHandle, *measurementTrackerEvent);
371  const TrajectoryStateOnSurface tsosTOB5 = itm->updatedState();
372  vector<TrajectoryMeasurement> tmp = theLayerMeasurements->measurements(*tob6, tsosTOB5, *thePropagator, *estimator);
373 
374  if ( !tmp.empty()) {
375  if (DEBUG) cout << "size of TM from propagation = " << tmp.size() << endl;
376 
377  // take the last of the TMs, which is always an invalid hit
378  // if no detId is available, ie detId==0, then no compatible layer was crossed
379  // otherwise, use that TM for the efficiency measurement
380  TrajectoryMeasurement tob6TM(tmp.back());
381  auto tob6Hit = tob6TM.recHit();
382 
383  if (tob6Hit->geographicalId().rawId()!=0) {
384  if (DEBUG) cout << "tob6 hit actually being added to TM vector" << endl;
385  TMs.push_back(TrajectoryAtInvalidHit(tob6TM, tTopo, tkgeom, propagator));
386  }
387  }
388  }
389 
390  bool isLastTEC8 = true;
391  if (!isLast) {
392  if ( checkLayer((++itm)->recHit()->geographicalId().rawId(), tTopo) == 21 ) isLastTEC8 = false;
393  else isLastTEC8 = true;
394  --itm;
395  }
396 
397  if ( TKlayers==21 && isValid && isLastTEC8 ) {
398 
399  std::vector< const ForwardDetLayer*> posTecLayers = measurementTrackerHandle->geometricSearchTracker()->posTecLayers() ;
400  const DetLayer* tec9pos = posTecLayers[posTecLayers.size()-1];
401  std::vector< const ForwardDetLayer*> negTecLayers = measurementTrackerHandle->geometricSearchTracker()->negTecLayers() ;
402  const DetLayer* tec9neg = negTecLayers[negTecLayers.size()-1];
403 
404  const MeasurementEstimator* estimator = est.product();
405  const LayerMeasurements* theLayerMeasurements = new LayerMeasurements(*measurementTrackerHandle, *measurementTrackerEvent);
406  const TrajectoryStateOnSurface tsosTEC9 = itm->updatedState();
407 
408  // check if track on positive or negative z
409  if (!iidd == StripSubdetector::TEC) cout << "there is a problem with TEC 9 extrapolation" << endl;
410 
411  //cout << " tec9 id = " << iidd << " and side = " << tTopo->tecSide(iidd) << endl;
412  vector<TrajectoryMeasurement> tmp;
413  if ( tTopo->tecSide(iidd) == 1 ) {
414  tmp = theLayerMeasurements->measurements(*tec9neg, tsosTEC9, *thePropagator, *estimator);
415  //cout << "on negative side" << endl;
416  }
417  if ( tTopo->tecSide(iidd) == 2 ) {
418  tmp = theLayerMeasurements->measurements(*tec9pos, tsosTEC9, *thePropagator, *estimator);
419  //cout << "on positive side" << endl;
420  }
421 
422  if ( !tmp.empty()) {
423  // take the last of the TMs, which is always an invalid hit
424  // if no detId is available, ie detId==0, then no compatible layer was crossed
425  // otherwise, use that TM for the efficiency measurement
426  TrajectoryMeasurement tec9TM(tmp.back());
427  auto tec9Hit = tec9TM.recHit();
428 
429  unsigned int tec9id = tec9Hit->geographicalId().rawId();
430  if (DEBUG) cout << "tec9id = " << tec9id << " is Double sided = " << isDoubleSided(tec9id, tTopo) << " and 0x3 = " << (tec9id & 0x3) << endl;
431 
432  if (tec9Hit->geographicalId().rawId()!=0) {
433  if (DEBUG) cout << "tec9 hit actually being added to TM vector" << endl;
434  // in tec the hit can be single or doubled sided. whenever the invalid hit at the end of vector of TMs is
435  // double sided it is always on the matched surface, so we need to split it into the true sensor surfaces
436  if (isDoubleSided(tec9id, tTopo)) {
437  TMs.push_back(TrajectoryAtInvalidHit(tec9TM, tTopo, tkgeom, propagator, 1));
438  TMs.push_back(TrajectoryAtInvalidHit(tec9TM, tTopo, tkgeom, propagator, 2));
439  } else
440  TMs.push_back(TrajectoryAtInvalidHit(tec9TM, tTopo, tkgeom, propagator));
441  }
442  } //else cout << "tec9 tmp empty" << endl;
443  }
444 
446 
447  // Modules Constraints
448 
449  for(std::vector<TrajectoryAtInvalidHit>::const_iterator TM=TMs.begin();TM!=TMs.end();++TM) {
450 
451  // --> Get trajectory from combinatedState
452  iidd = TM->monodet_id();
453  if (DEBUG) cout << "setting iidd = " << iidd << " before checking efficiency and ";
454 
455  xloc = TM->localX();
456  yloc = TM->localY();
457 
458  xErr = TM->localErrorX();
459  yErr = TM->localErrorY();
460 
461  angleX = atan( TM->localDxDz() );
462  angleY = atan( TM->localDyDz() );
463 
464  xglob = TM->globalX();
465  yglob = TM->globalY();
466  zglob = TM->globalZ();
467  withinAcceptance = TM->withinAcceptance();
468 
469  trajHitValid = TM->validHit();
470 
471  // reget layer from iidd here, to account for TOB 6 and TEC 9 TKlayers being off
472  TKlayers = checkLayer(iidd, tTopo);
473 
474  if ( (layers == TKlayers) || (layers == 0) ) { // Look at the layer not used to reconstruct the track
475  whatlayer = TKlayers;
476  if (DEBUG) cout << "Looking at layer under study" << endl;
477  TrajGlbX = 0.0; TrajGlbY = 0.0; TrajGlbZ = 0.0; ModIsBad = 2; Id = 0; SiStripQualBad = 0;
478  run = 0; event = 0; TrajLocX = 0.0; TrajLocY = 0.0; TrajLocErrX = 0.0; TrajLocErrY = 0.0;
479  TrajLocAngleX = -999.0; TrajLocAngleY = -999.0; ResX = 0.0; ResXSig = 0.0;
480  ClusterLocX = 0.0; ClusterLocY = 0.0; ClusterLocErrX = 0.0; ClusterLocErrY = 0.0; ClusterStoN = 0.0;
481  bunchx = 0;
482 
483  // RPhi RecHit Efficiency
484 
485  if (input.size() > 0 ) {
486  if (DEBUG) cout << "Checking clusters with size = " << input.size() << endl;
487  int nClusters = 0;
488  std::vector< std::vector<float> > VCluster_info; //fill with X residual, X residual pull, local X, sig(X), local Y, sig(Y), StoN
489  for (edmNew::DetSetVector<SiStripCluster>::const_iterator DSViter = input.begin(); DSViter != input.end(); DSViter++) {
490  // DSViter is a vector of SiStripClusters located on a single module
491  //if (DEBUG) cout << "the ID from the DSViter = " << DSViter->id() << endl;
492  unsigned int ClusterId = DSViter->id();
493  if (ClusterId == iidd) {
494  if (DEBUG) cout << "found (ClusterId == iidd) with ClusterId = " << ClusterId << " and iidd = " << iidd << endl;
495  DetId ClusterDetId(ClusterId);
496  const StripGeomDetUnit * stripdet=(const StripGeomDetUnit*)tkgeom->idToDetUnit(ClusterDetId);
497 
498  for(edmNew::DetSet<SiStripCluster>::const_iterator iter=DSViter->begin();iter!=DSViter->end();++iter) {
499  //iter is a single SiStripCluster
501  float res = (parameters.first.x() - xloc);
502  float sigma = checkConsistency(parameters , xloc, xErr);
503  // The consistency is probably more accurately measured with the Chi2MeasurementEstimator. To use it
504  // you need a TransientTrackingRecHit instead of the cluster
505  //theEstimator= new Chi2MeasurementEstimator(30);
506  //const Chi2MeasurementEstimator *theEstimator(100);
507  //theEstimator->estimate(TM->tsos(), TransientTrackingRecHit);
508 
509  SiStripClusterInfo clusterInfo = SiStripClusterInfo(*iter, es, ClusterId);
510  // signal to noise from SiStripClusterInfo not working in 225. I'll fix this after the interface
511  // redesign in 300 -ku
512  //float cluster_info[7] = {res, sigma, parameters.first.x(), sqrt(parameters.second.xx()), parameters.first.y(), sqrt(parameters.second.yy()), signal_to_noise};
513  std::vector< float > cluster_info;
514  cluster_info.push_back(res);
515  cluster_info.push_back(sigma);
516  cluster_info.push_back(parameters.first.x());
517  cluster_info.push_back(sqrt(parameters.second.xx()));
518  cluster_info.push_back(parameters.first.y());
519  cluster_info.push_back(sqrt(parameters.second.yy()));
520  cluster_info.push_back( clusterInfo.signalOverNoise() );
521  //cluster_info.push_back( clusterInfo.getSignalOverNoise() );
522  VCluster_info.push_back(cluster_info);
523  nClusters++;
524  if (DEBUG) cout << "Have ID match. residual = " << VCluster_info.back()[0] << " res sigma = " << VCluster_info.back()[1] << endl;
525  if (DEBUG) cout << "trajectory measurement compatability estimate = " << (*itm).estimate() << endl;
526  if (DEBUG) cout << "hit position = " << parameters.first.x() << " hit error = " << sqrt(parameters.second.xx()) << " trajectory position = " << xloc << " traj error = " << xErr << endl;
527  }
528  }
529  }
530  float FinalResSig = 1000.0;
531  float FinalCluster[7]= {1000.0, 1000.0, 0.0, 0.0, 0.0, 0.0, 0.0};
532  if (nClusters > 0) {
533  if (DEBUG) cout << "found clusters > 0" << endl;
534  if (nClusters > 1) {
535  //get the smallest one
536  vector< vector<float> >::iterator ires;
537  for (ires=VCluster_info.begin(); ires!=VCluster_info.end(); ires++){
538  if ( abs((*ires)[1]) < abs(FinalResSig)) {
539  FinalResSig = (*ires)[1];
540  for (unsigned int i = 0; i<ires->size(); i++) {
541  if (DEBUG) cout << "filling final cluster. i = " << i << " before fill FinalCluster[i]=" << FinalCluster[i] << " and (*ires)[i] =" << (*ires)[i] << endl;
542  FinalCluster[i] = (*ires)[i];
543  if (DEBUG) cout << "filling final cluster. i = " << i << " after fill FinalCluster[i]=" << FinalCluster[i] << " and (*ires)[i] =" << (*ires)[i] << endl;
544  }
545  }
546  if (DEBUG) cout << "iresidual = " << (*ires)[0] << " isigma = " << (*ires)[1] << " and FinalRes = " << FinalCluster[0] << endl;
547  }
548  }
549  else {
550  FinalResSig = VCluster_info.at(0)[1];
551  for (unsigned int i = 0; i<VCluster_info.at(0).size(); i++) {
552  FinalCluster[i] = VCluster_info.at(0)[i];
553  }
554  }
555  nClusters=0;
556  VCluster_info.clear();
557  }
558 
559  if (DEBUG) cout << "Final residual in X = " << FinalCluster[0] << "+-" << (FinalCluster[0]/FinalResSig) << endl;
560  if (DEBUG) cout << "Checking location of trajectory: abs(yloc) = " << abs(yloc) << " abs(xloc) = " << abs(xloc) << endl;
561  if (DEBUG) cout << "Checking location of cluster hit: yloc = " << FinalCluster[4] << "+-" << FinalCluster[5] << " xloc = " << FinalCluster[2] << "+-" << FinalCluster[3] << endl;
562  if (DEBUG) cout << "Final cluster signal to noise = " << FinalCluster[6] << endl;
563 
564  float exclusionWidth = 0.4;
565  float TOBexclusion = 0.0;
566  float TECexRing5 = -0.89;
567  float TECexRing6 = -0.56;
568  float TECexRing7 = 0.60;
569  //Added by Chris Edelmaier to do TEC bonding exclusion
570  int subdetector = ((iidd>>25) & 0x7);
571  int ringnumber = ((iidd>>5) & 0x7);
572 
573  //New TOB and TEC bonding region exclusion zone
574  if((TKlayers >= 5 && TKlayers < 11)||((subdetector == 6)&&( (ringnumber >= 5)&&(ringnumber <=7) ))) {
575  //There are only 2 cases that we need to exclude for
576  float highzone = 0.0;
577  float lowzone = 0.0;
578  float higherr = yloc + 5.0*yErr;
579  float lowerr = yloc - 5.0*yErr;
580  if(TKlayers >= 5 && TKlayers < 11) {
581  //TOB zone
582  highzone = TOBexclusion + exclusionWidth;
583  lowzone = TOBexclusion - exclusionWidth;
584  } else if (ringnumber == 5) {
585  //TEC ring 5
586  highzone = TECexRing5 + exclusionWidth;
587  lowzone = TECexRing5 - exclusionWidth;
588  } else if (ringnumber == 6) {
589  //TEC ring 6
590  highzone = TECexRing6 + exclusionWidth;
591  lowzone = TECexRing6 - exclusionWidth;
592  } else if (ringnumber == 7) {
593  //TEC ring 7
594  highzone = TECexRing7 + exclusionWidth;
595  lowzone = TECexRing7 - exclusionWidth;
596  }
597  //Now that we have our exclusion region, we just have to properly identify it
598  if((highzone <= higherr)&&(highzone >= lowerr)) withinAcceptance = false;
599  if((lowzone >= lowerr)&&(lowzone <= higherr)) withinAcceptance = false;
600  if((higherr <= highzone)&&(higherr >= lowzone)) withinAcceptance = false;
601  if((lowerr >= lowzone)&&(lowerr <= highzone)) withinAcceptance = false;
602  }
603 
604  // fill ntuple varibles
605  //get global position from module id number iidd
606  TrajGlbX = xglob;
607  TrajGlbY = yglob;
608  TrajGlbZ = zglob;
609  Id = iidd;
610  run = run_nr;
611  event = ev_nr;
612  bunchx = bunch_nr;
613  //if ( SiStripQuality_->IsModuleBad(iidd) ) {
614  if ( SiStripQuality_->getBadApvs(iidd)!=0 ) {
615  SiStripQualBad = 1;
616  if(DEBUG) cout << "strip is bad from SiStripQuality" << endl;
617  } else {
618  SiStripQualBad = 0;
619  if(DEBUG) cout << "strip is good from SiStripQuality" << endl;
620  }
621 
622  //check for FED-detected errors and include those in SiStripQualBad
623  for (unsigned int ii=0;ii< fedErrorIds->size();ii++) {
624  if (iidd == (*fedErrorIds)[ii].rawId() )
625  SiStripQualBad = 1;
626  }
627 
628  TrajLocX = xloc;
629  TrajLocY = yloc;
630  TrajLocErrX = xErr;
631  TrajLocErrY = yErr;
632  TrajLocAngleX = angleX;
633  TrajLocAngleY = angleY;
634  ResX = FinalCluster[0];
635  ResXSig = FinalResSig;
636  if (FinalResSig != FinalCluster[1]) if (DEBUG) cout << "Problem with best cluster selection because FinalResSig = " << FinalResSig << " and FinalCluster[1] = " << FinalCluster[1] << endl;
637  ClusterLocX = FinalCluster[2];
638  ClusterLocY = FinalCluster[4];
639  ClusterLocErrX = FinalCluster[3];
640  ClusterLocErrY = FinalCluster[5];
641  ClusterStoN = FinalCluster[6];
642 
643  if (DEBUG) cout << "before check good" << endl;
644 
645  if ( FinalResSig < 999.0) { //could make requirement on track/hit consistency, but for
646  //now take anything with a hit on the module
647  if (DEBUG) cout << "hit being counted as good " << FinalCluster[0] << " FinalRecHit " <<
648  iidd << " TKlayers " << TKlayers << " xloc " << xloc << " yloc " << yloc << " module " << iidd <<
649  " matched/stereo/rphi = " << ((iidd & 0x3)==0) << "/" << ((iidd & 0x3)==1) << "/" << ((iidd & 0x3)==2) << endl;
650  ModIsBad = 0;
651  traj->Fill();
652  }
653  else {
654  if (DEBUG) cout << "hit being counted as bad ######### Invalid RPhi FinalResX " << FinalCluster[0] << " FinalRecHit " <<
655  iidd << " TKlayers " << TKlayers << " xloc " << xloc << " yloc " << yloc << " module " << iidd <<
656  " matched/stereo/rphi = " << ((iidd & 0x3)==0) << "/" << ((iidd & 0x3)==1) << "/" << ((iidd & 0x3)==2) << endl;
657  ModIsBad = 1;
658  traj->Fill();
659 
660  if (DEBUG) cout << " RPhi Error " << sqrt(xErr*xErr + yErr*yErr) << " ErrorX " << xErr << " yErr " << yErr << endl;
661  } if (DEBUG) cout << "after good location check" << endl;
662  } if (DEBUG) cout << "after list of clusters" << endl;
663  } if (DEBUG) cout << "After layers=TKLayers if" << endl;
664  } if (DEBUG) cout << "After looping over TrajAtValidHit list" << endl;
665  } if (DEBUG) cout << "end TMeasurement loop" << endl;
666  } if (DEBUG) cout << "end of trajectories loop" << endl;
667  }
668 }
669 
671  traj->GetDirectory()->cd();
672  traj->Write();
673 
674  if (DEBUG) cout << " Events Analysed " << events << endl;
675  if (DEBUG) cout << " Number Of Tracked events " << EventTrackCKF << endl;
676 }
677 
679  double error = sqrt(parameters.second.xx() + xerr*xerr);
680  double separation = abs(parameters.first.x() - xx);
681  double consistency = separation/error;
682  return consistency;
683 }
684 
685 bool HitEff::isDoubleSided(unsigned int iidd, const TrackerTopology* tTopo) const {
687  unsigned int subid=strip.subdetId();
688  unsigned int layer = 0;
689  if (subid == StripSubdetector::TIB) {
690 
691  layer = tTopo->tibLayer(iidd);
692  if (layer == 1 || layer == 2) return true;
693  else return false;
694  }
695  else if (subid == StripSubdetector::TOB) {
696 
697  layer = tTopo->tobLayer(iidd) + 4 ;
698  if (layer == 5 || layer == 6) return true;
699  else return false;
700  }
701  else if (subid == StripSubdetector::TID) {
702 
703  layer = tTopo->tidRing(iidd) + 10;
704  if (layer == 11 || layer == 12) return true;
705  else return false;
706  }
707  else if (subid == StripSubdetector::TEC) {
708 
709  layer = tTopo->tecRing(iidd) + 13 ;
710  if (layer == 14 || layer == 15 || layer == 18) return true;
711  else return false;
712  }
713  else
714  return false;
715 }
716 
717 bool HitEff::check2DPartner(unsigned int iidd, const std::vector<TrajectoryMeasurement>& traj) {
718  unsigned int partner_iidd = 0;
719  bool found2DPartner = false;
720  // first get the id of the other detector
721  if ((iidd & 0x3)==1) partner_iidd = iidd+1;
722  if ((iidd & 0x3)==2) partner_iidd = iidd-1;
723  // next look in the trajectory measurements for a measurement from that detector
724  // loop through trajectory measurements to find the partner_iidd
725  for (std::vector<TrajectoryMeasurement>::const_iterator iTM=traj.begin(); iTM!=traj.end(); ++iTM) {
726  if (iTM->recHit()->geographicalId().rawId()==partner_iidd) {
727  found2DPartner = true;
728  }
729  }
730  return found2DPartner;
731 }
732 
733 unsigned int HitEff::checkLayer( unsigned int iidd, const TrackerTopology* tTopo) {
735  unsigned int subid=strip.subdetId();
736  if (subid == StripSubdetector::TIB) {
737 
738  return tTopo->tibLayer(iidd);
739  }
740  if (subid == StripSubdetector::TOB) {
741 
742  return tTopo->tobLayer(iidd) + 4 ;
743  }
744  if (subid == StripSubdetector::TID) {
745 
746  return tTopo->tidWheel(iidd) + 10;
747  }
748  if (subid == StripSubdetector::TEC) {
749 
750  return tTopo->tecWheel(iidd) + 13 ;
751  }
752  return 0;
753 }
754 
755 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:42
virtual LocalValues localParameters(const SiStripCluster &, const GeomDetUnit &) const
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
std::vector< TrajectoryMeasurement > measurements(const DetLayer &layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
int i
Definition: DBlmapReader.cc:9
float TrajGlbZ
Definition: HitEff.h:71
dictionary parameters
Definition: Parameters.py:2
bool check2DPartner(unsigned int iidd, const std::vector< TrajectoryMeasurement > &traj)
Definition: HitEff.cc:717
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
float ClusterLocErrX
Definition: HitEff.h:73
float ClusterLocErrY
Definition: HitEff.h:73
unsigned int tibLayer(const DetId &id) const
ConstRecHitPointer const & recHit() const
float TrajGlbY
Definition: HitEff.h:71
unsigned int tidRing(const DetId &id) const
float TrajLocX
Definition: HitEff.h:72
float ResXSig
Definition: HitEff.h:74
Definition: HitEff.h:44
virtual void analyze(const edm::Event &e, const edm::EventSetup &c)
Definition: HitEff.cc:133
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
unsigned int tecRing(const DetId &id) const
ring id
float chi2
Definition: HitEff.h:77
int ires[2]
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
int bunchCrossing() const
Definition: EventBase.h:62
unsigned int tidWheel(const DetId &id) const
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
HitEff(const edm::ParameterSet &conf)
Definition: HitEff.cc:73
float ClusterStoN
Definition: HitEff.h:73
data_type const * const_iterator
Definition: DetSetNew.h:30
float TrajLocErrX
Definition: HitEff.h:72
int ii
Definition: cuy.py:588
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
bool DEBUG
Definition: HitEff.h:66
unsigned int bunchx
Definition: HitEff.h:78
static std::string const input
Definition: EdmProvDump.cc:44
float p
Definition: HitEff.h:77
float timeECAL
Definition: HitEff.h:81
float signalOverNoise() const
bool isDoubleSided(unsigned int iidd, const TrackerTopology *tTopo) const
Definition: HitEff.cc:685
float timeDTErr
Definition: HitEff.h:79
int nHits
Definition: HitEff.h:76
unsigned int Id
Definition: HitEff.h:75
T sqrt(T t)
Definition: SSEVec.h:48
int timeDTDOF
Definition: HitEff.h:80
float timeAtIpInOutErr
Definition: MuonTime.h:15
virtual ~HitEff()
Definition: HitEff.cc:81
virtual void beginJob()
Definition: HitEff.cc:83
int nDof
number of muon stations used
Definition: MuonTime.h:10
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned int trajHitValid
Definition: HitEff.h:78
unsigned int ModIsBad
Definition: HitEff.h:75
int istep
Definition: HitEff.h:84
float TrajGlbX
Definition: HitEff.h:71
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
bool withinAcceptance
Definition: HitEff.h:75
unsigned int run
Definition: HitEff.h:78
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
float ClusterLocX
Definition: HitEff.h:73
tuple conf
Definition: dbtoconf.py:185
int events
Definition: HitEff.h:63
float TrajLocAngleX
Definition: HitEff.h:72
int dedxNOM
Definition: HitEff.h:82
Definition: DetId.h:18
unsigned int event
Definition: HitEff.h:78
double checkConsistency(const StripClusterParameterEstimator::LocalValues &parameters, double xx, double xerr)
Definition: HitEff.cc:678
unsigned int whatlayer
Definition: HitEff.h:67
const T & get() const
Definition: EventSetup.h:55
unsigned int checkLayer(unsigned int iidd, const TrackerTopology *tTopo)
Definition: HitEff.cc:733
T const * product() const
Definition: ESHandle.h:62
float timeDT
Definition: HitEff.h:79
unsigned int layers
Definition: HitEff.h:65
float pT
Definition: HitEff.h:77
T const * product() const
Definition: Handle.h:81
float ResX
Definition: HitEff.h:74
std::pair< LocalPoint, LocalError > LocalValues
virtual void endJob()
Definition: HitEff.cc:670
unsigned int SiStripQualBad
Definition: HitEff.h:75
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
edm::EventID id() const
Definition: EventBase.h:56
float TrajLocErrY
Definition: HitEff.h:72
float TrajLocAngleY
Definition: HitEff.h:72
float dedx
Definition: HitEff.h:81
tuple cout
Definition: gather_cfg.py:121
float ClusterLocY
Definition: HitEff.h:73
TTree * traj
Definition: HitEff.h:62
unsigned int tecWheel(const DetId &id) const
edm::ParameterSet conf_
Definition: HitEff.h:60
float timeAtIpInOut
Definition: MuonTime.h:14
int EventTrackCKF
Definition: HitEff.h:63
int nLostHits
Definition: HitEff.h:76
float TrajLocY
Definition: HitEff.h:72
int tquality
Definition: HitEff.h:83
unsigned int tobLayer(const DetId &id) const
unsigned int tecSide(const DetId &id) const