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