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