CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTSegment2DQuality.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author S. Bolognesi and G. Cerminara - INFN Torino
5  */
6 
7 #include "DTSegment2DQuality.h"
9 
14 
18 
23 
24 #include "Histograms.h"
25 
26 #include "TFile.h"
27 
30 #include <iostream>
31 #include <map>
32 
33 using namespace std;
34 using namespace edm;
35 
36 // Constructor
38  // Get the debug parameter for verbose output
39  debug = pset.getUntrackedParameter<bool>("debug");
41  // the name of the simhit collection
42  simHitLabel = pset.getUntrackedParameter<InputTag>("simHitLabel");
43  simHitToken_ = consumes<PSimHitContainer>(pset.getUntrackedParameter<InputTag>("simHitLabel"));
44  // the name of the 2D rec hit collection
45  segment2DLabel = pset.getUntrackedParameter<InputTag>("segment2DLabel");
46  segment2DToken_ = consumes<DTRecSegment2DCollection>(pset.getUntrackedParameter<InputTag>("segment2DLabel"));
47 
48  //sigma resolution on position
49  sigmaResPos = pset.getParameter<double>("sigmaResPos");
50  //sigma resolution on angle
51  sigmaResAngle = pset.getParameter<double>("sigmaResAngle");
52 
53  if(debug)
54  cout << "[DTSegment2DQuality] Constructor called " << endl;
55 }
56 
58 
59  // ----------------------
60  // get hold of back-end interface
61  dbe_ = 0;
63  if ( dbe_ ) {
64  if (debug) {
65  dbe_->setVerbose(1);
66  } else {
67  dbe_->setVerbose(0);
68  }
69  }
70  if ( dbe_ ) {
71  if ( debug ) dbe_->showDirStructure();
72  }
73 
74  h2DHitRPhi = new HRes2DHit ("RPhi",dbe_,true,true);
75  h2DHitRZ= new HRes2DHit ("RZ",dbe_,true,true);
76  h2DHitRZ_W0= new HRes2DHit ("RZ_W0",dbe_,true,true);
77  h2DHitRZ_W1= new HRes2DHit ("RZ_W1",dbe_,true,true);
78  h2DHitRZ_W2= new HRes2DHit ("RZ_W2",dbe_,true,true);
79 
80  h2DHitEff_RPhi= new HEff2DHit ("RPhi",dbe_);
81  h2DHitEff_RZ= new HEff2DHit ("RZ",dbe_);
82  h2DHitEff_RZ_W0= new HEff2DHit ("RZ_W0",dbe_);
83  h2DHitEff_RZ_W1= new HEff2DHit ("RZ_W1",dbe_);
84  h2DHitEff_RZ_W2= new HEff2DHit ("RZ_W2",dbe_);
85  if(debug)
86  cout << "[DTSegment2DQuality] hitsos created " << endl;
87 }
88 
89 // Destructor
91 
92 }
93 
95  // Write the histos to file
96  //theFile->cd();
97 
98  //h2DHitRPhi->Write();
99  //h2DHitRZ->Write();
100  //h2DHitRZ_W0->Write();
101  //h2DHitRZ_W1->Write();
102  //h2DHitRZ_W2->Write();
103 
104  h2DHitEff_RPhi->ComputeEfficiency();
105  h2DHitEff_RZ->ComputeEfficiency();
106  h2DHitEff_RZ_W0->ComputeEfficiency();
107  h2DHitEff_RZ_W1->ComputeEfficiency();
108  h2DHitEff_RZ_W2->ComputeEfficiency();
109 
110  //h2DHitEff_RPhi->Write();
111  //h2DHitEff_RZ->Write();
112  //h2DHitEff_RZ_W0->Write();
113  //h2DHitEff_RZ_W1->Write();
114  //h2DHitEff_RZ_W2->Write();
115  //if ( rootFileName.size() != 0 && dbe_ ) dbe_->save(rootFileName);
116 
117  //theFile->Close();
118 }
119 
120 // The real analysis
121 void DTSegment2DQuality::analyze(const Event & event, const EventSetup& eventSetup){
122  //theFile->cd();
123 
124  // Get the DT Geometry
125  ESHandle<DTGeometry> dtGeom;
126  eventSetup.get<MuonGeometryRecord>().get(dtGeom);
127 
128  // Get the SimHit collection from the event
130  event.getByToken(simHitToken_, simHits); //FIXME: second string to be removed
131 
132  //Map simHits by sl
133  map<DTSuperLayerId, PSimHitContainer > simHitsPerSl;
134  for(PSimHitContainer::const_iterator simHit = simHits->begin();
135  simHit != simHits->end(); simHit++){
136  // Create the id of the sl (the simHits in the DT known their wireId)
137  DTSuperLayerId slId = ((DTWireId(simHit->detUnitId())).layerId()).superlayerId();
138  // Fill the map
139  simHitsPerSl[slId].push_back(*simHit);
140  }
141 
142  // Get the 2D rechits from the event
144  event.getByToken(segment2DToken_, segment2Ds);
145 
146  if(!segment2Ds.isValid()) {
147  if(debug) cout << "[DTSegment2DQuality]**Warning: no 2DSegments with label: " << segment2DLabel
148  << " in this event, skipping!" << endl;
149  return;
150  }
151 
152  // Loop over all superlayers containing a segment
153  DTRecSegment2DCollection::id_iterator slId;
154  for (slId = segment2Ds->id_begin();
155  slId != segment2Ds->id_end();
156  ++slId){
157 
158  //------------------------- simHits ---------------------------//
159  //Get simHits of each superlayer
160  PSimHitContainer simHits = simHitsPerSl[(*slId)];
161 
162  // Map simhits per wire
163  map<DTWireId, PSimHitContainer > simHitsPerWire = DTHitQualityUtils::mapSimHitsPerWire(simHits);
164  map<DTWireId, const PSimHit*> muSimHitPerWire = DTHitQualityUtils::mapMuSimHitsPerWire(simHitsPerWire);
165  int nMuSimHit = muSimHitPerWire.size();
166  if(nMuSimHit == 0 || nMuSimHit == 1) {
167  if(debug && nMuSimHit == 1)
168  cout << "[DTSegment2DQuality] Only " << nMuSimHit << " mu SimHit in this SL, skipping!" << endl;
169  continue; // If no or only one mu SimHit is found skip this SL
170  }
171  if(debug)
172  cout << "=== SL " << (*slId) << " has " << nMuSimHit << " SimHits" << endl;
173 
174  //Find outer and inner mu SimHit to build a segment
175  pair<const PSimHit*, const PSimHit*> inAndOutSimHit = DTHitQualityUtils::findMuSimSegment(muSimHitPerWire);
176  //Check that outermost and innermost SimHit are not the same
177  if(inAndOutSimHit.first ==inAndOutSimHit.second ) {
178  cout << "[DTHitQualityUtils]***Warning: outermost and innermost SimHit are the same!" << endl;
179  continue;
180  }
181 
182  //Find direction and position of the sim Segment in SL RF
183  pair<LocalVector, LocalPoint> dirAndPosSimSegm = DTHitQualityUtils::findMuSimSegmentDirAndPos(inAndOutSimHit,
184  (*slId),&(*dtGeom));
185 
186  LocalVector simSegmLocalDir = dirAndPosSimSegm.first;
187  LocalPoint simSegmLocalPos = dirAndPosSimSegm.second;
188  if(debug)
189  cout<<" Simulated segment: local direction "<<simSegmLocalDir<<endl
190  <<" local position "<<simSegmLocalPos<<endl;
191  const DTSuperLayer* superLayer = dtGeom->superLayer(*slId);
192  GlobalPoint simSegmGlobalPos = superLayer->toGlobal(simSegmLocalPos);
193 
194  //Atan(x/z) angle and x position in SL RF
195  float angleSimSeg = DTHitQualityUtils::findSegmentAlphaAndBeta(simSegmLocalDir).first;
196  float posSimSeg = simSegmLocalPos.x();
197  //Position (in eta,phi coordinates) in the global RF
198  float etaSimSeg = simSegmGlobalPos.eta();
199  float phiSimSeg = simSegmGlobalPos.phi();
200 
201 
202  //---------------------------- recHits --------------------------//
203  // Get the range of rechit for the corresponding slId
204  bool recHitFound = false;
205  DTRecSegment2DCollection::range range = segment2Ds->get(*slId);
206  int nsegm = distance(range.first, range.second);
207  if(debug)
208  cout << " Sl: " << *slId << " has " << nsegm
209  << " 2D segments" << endl;
210 
211  if (nsegm!=0) {
212  // Find the best RecHit: look for the 2D RecHit with the angle closest
213  // to that of segment made of SimHits.
214  // RecHits must have delta alpha and delta position within 5 sigma of
215  // the residual distribution (we are looking for residuals of segments
216  // usefull to the track fit) for efficency purpose
217  const DTRecSegment2D* bestRecHit = 0;
218  bool bestRecHitFound = false;
219  double deltaAlpha = 99999;
220 
221  // Loop over the recHits of this slId
222  for (DTRecSegment2DCollection::const_iterator segment2D = range.first;
223  segment2D!=range.second;
224  ++segment2D){
225  // Check the dimension
226  if((*segment2D).dimension() != 2) {
227  if(debug) cout << "[DTSegment2DQuality]***Error: This is not 2D segment!!!" << endl;
228  abort();
229  }
230  // Segment Local Direction and position (in SL RF)
231  LocalVector recSegDirection = (*segment2D).localDirection();
232  LocalPoint recSegPosition = (*segment2D).localPosition();
233 
234  float recSegAlpha = DTHitQualityUtils::findSegmentAlphaAndBeta(recSegDirection).first;
235  if(debug)
236  cout << " RecSegment direction: " << recSegDirection << endl
237  << " position : " << recSegPosition << endl
238  << " alpha : " << recSegAlpha << endl;
239 
240  if(fabs(recSegAlpha - angleSimSeg) < deltaAlpha) {
241  deltaAlpha = fabs(recSegAlpha - angleSimSeg);
242  bestRecHit = &(*segment2D);
243  bestRecHitFound = true;
244  }
245  } // End of Loop over all 2D RecHits
246 
247  if(bestRecHitFound) {
248  // Best rechit direction and position in SL RF
249  LocalPoint bestRecHitLocalPos = bestRecHit->localPosition();
250  LocalVector bestRecHitLocalDir = bestRecHit->localDirection();
251 
252  LocalError bestRecHitLocalPosErr = bestRecHit->localPositionError();
253  LocalError bestRecHitLocalDirErr = bestRecHit->localDirectionError();
254 
255  float angleBestRHit = DTHitQualityUtils::findSegmentAlphaAndBeta(bestRecHitLocalDir).first;
256 
257  if(fabs(angleBestRHit - angleSimSeg) < 5*sigmaResAngle &&
258  fabs(bestRecHitLocalPos.x() - posSimSeg) < 5*sigmaResPos) {
259  recHitFound = true;
260  }
261 
262  // Fill Residual histos
263  HRes2DHit *hRes = 0;
264  if((*slId).superlayer() == 1 || (*slId).superlayer() == 3) { //RPhi SL
265  hRes = h2DHitRPhi;
266  } else if((*slId).superlayer() == 2) { //RZ SL
267  h2DHitRZ->Fill(angleSimSeg,
268  angleBestRHit,
269  posSimSeg,
270  bestRecHitLocalPos.x(),
271  etaSimSeg,
272  phiSimSeg,
273  sqrt(bestRecHitLocalPosErr.xx()),
274  sqrt(bestRecHitLocalDirErr.xx())
275  );
276  if(abs((*slId).wheel()) == 0)
277  hRes = h2DHitRZ_W0;
278  else if(abs((*slId).wheel()) == 1)
279  hRes = h2DHitRZ_W1;
280  else if(abs((*slId).wheel()) == 2)
281  hRes = h2DHitRZ_W2;
282  }
283  hRes->Fill(angleSimSeg,
284  angleBestRHit,
285  posSimSeg,
286  bestRecHitLocalPos.x(),
287  etaSimSeg,
288  phiSimSeg,
289  sqrt(bestRecHitLocalPosErr.xx()),
290  sqrt(bestRecHitLocalDirErr.xx())
291  );
292  }
293  } //end of if(nsegm!=0)
294 
295  // Fill Efficiency plot
296  HEff2DHit *hEff = 0;
297  if((*slId).superlayer() == 1 || (*slId).superlayer() == 3) { //RPhi SL
298  hEff = h2DHitEff_RPhi;
299  } else if((*slId).superlayer() == 2) { //RZ SL
300  h2DHitEff_RZ->Fill(etaSimSeg, phiSimSeg, posSimSeg, angleSimSeg, recHitFound);
301  if(abs((*slId).wheel()) == 0)
302  hEff = h2DHitEff_RZ_W0;
303  else if(abs((*slId).wheel()) == 1)
304  hEff = h2DHitEff_RZ_W1;
305  else if(abs((*slId).wheel()) == 2)
306  hEff = h2DHitEff_RZ_W2;
307  }
308  hEff->Fill(etaSimSeg, phiSimSeg, posSimSeg, angleSimSeg, recHitFound);
309  } // End of loop over superlayers
310 }
311 
312 
313 
314 
315 
316 
T getParameter(std::string const &) const
virtual LocalError localPositionError() const
local position error in SL frame
T getUntrackedParameter(std::string const &, T const &) const
virtual ~DTSegment2DQuality()
Destructor.
float xx() const
Definition: LocalError.h:24
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
virtual void beginRun(const edm::Run &iRun, const edm::EventSetup &setup)
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:47
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
virtual LocalError localDirectionError() const
the local direction error (xx,xy,yy) in SL frame: only xx is not 0.
DTSegment2DQuality(const edm::ParameterSet &pset)
Constructor.
static std::map< DTWireId, const PSimHit * > mapMuSimHitsPerWire(const std::map< DTWireId, edm::PSimHitContainer > &simHitWireMap)
Create a map between the Mu SimHits and corresponding MuBarWireId ;.
static std::pair< const PSimHit *, const PSimHit * > findMuSimSegment(const std::map< DTWireId, const PSimHit * > &mapWireAndMuSimHit)
Find Innermost and outermost SimHit from Mu in a SL (they identify a simulated segment) ...
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup)
Perform the real analysis.
T sqrt(T t)
Definition: SSEVec.h:48
void Fill(float angleSimSegment, float angleRecSegment, float posSimSegment, float posRecSegment, float etaSimSegment, float phiSimSegment, float sigmaPos, float sigmaAngle)
Definition: Histograms.h:388
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void setVerbose(unsigned level)
Definition: DQMStore.cc:631
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:76
static std::pair< double, double > findSegmentAlphaAndBeta(const LocalVector &direction)
DQMStore * dbe_
virtual LocalPoint localPosition() const
local position in SL frame
#define debug
Definition: HDRShower.cc:19
static std::pair< LocalVector, LocalPoint > findMuSimSegmentDirAndPos(const std::pair< const PSimHit *, const PSimHit * > &inAndOutSimHit, const DetId detId, const DTGeometry *muonGeom)
Find direction and position of a segment (in local RF) from outer and inner mu SimHit in the RF of ob...
void Fill(float etaSimSegm, float phiSimSegm, float posSimSegm, float angleSimSegm, bool fillRecHit)
Definition: Histograms.h:529
const T & get() const
Definition: EventSetup.h:55
tuple simHits
Definition: trackerHits.py:16
T eta() const
Definition: PV3DBase.h:76
virtual LocalVector localDirection() const
the local direction in SL frame
tuple cout
Definition: gather_cfg.py:121
std::vector< PSimHit > PSimHitContainer
static std::map< DTWireId, edm::PSimHitContainer > mapSimHitsPerWire(const edm::PSimHitContainer &simhits)
void showDirStructure(void) const
Definition: DQMStore.cc:3332
T x() const
Definition: PV3DBase.h:62
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Definition: Run.h:41