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