CMS 3D CMS Logo

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