CMS 3D CMS Logo

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