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