CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTSegment4DQuality.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * $Date: 2007/10/25 11:58:37 $
5  * $Revision: 1.1 $
6  * \author S. Bolognesi and G. Cerminara - INFN Torino
7  */
8 
9 #include "DTSegment4DQuality.h"
11 
16 
20 
25 
26 #include "Histograms.h"
27 
28 #include "TFile.h"
29 
30 #include <iostream>
31 #include <map>
32 
33 
34 using namespace std;
35 using namespace edm;
36 
37 // Book the histos
38 
39 // Constructor
41  // Get the debug parameter for verbose output
42  debug = pset.getUntrackedParameter<bool>("debug");
44 
45  rootFileName = pset.getUntrackedParameter<string>("rootFileName");
46  // the name of the simhit collection
47  simHitLabel = pset.getUntrackedParameter<string>("simHitLabel", "SimG4Object");
48  // the name of the 4D rec hit collection
49  segment4DLabel = pset.getUntrackedParameter<string>("segment4DLabel");
50 
51  //sigma resolution on position
52  sigmaResX = pset.getParameter<double>("sigmaResX");
53  sigmaResY = pset.getParameter<double>("sigmaResY");
54  //sigma resolution on angle
55  sigmaResAlpha = pset.getParameter<double>("sigmaResAlpha");
56  sigmaResBeta = pset.getParameter<double>("sigmaResBeta");
57 
58  // Create the root file
59  theFile = new TFile(rootFileName.c_str(), "RECREATE");
60  theFile->cd();
61 
62  h4DHit= new HRes4DHit ("All");
63  h4DHit_W0= new HRes4DHit ("W0");
64  h4DHit_W1= new HRes4DHit ("W1");
65  h4DHit_W2= new HRes4DHit ("W2");
66 
67  hEff_All= new HEff4DHit ("All");
68  hEff_W0= new HEff4DHit ("W0");
69  hEff_W1= new HEff4DHit ("W1");
70  hEff_W2= new HEff4DHit ("W2");
71 }
72 
73 // Destructor
75 
76 }
77 
79  // Write the histos to file
80  theFile->cd();
81 
82  h4DHit->Write();
83  h4DHit_W0->Write();
84  h4DHit_W1->Write();
85  h4DHit_W2->Write();
86 
87  hEff_All->ComputeEfficiency();
88  hEff_W0->ComputeEfficiency();
89  hEff_W1->ComputeEfficiency();
90  hEff_W2->ComputeEfficiency();
91 
92  hEff_All->Write();
93  hEff_W0->Write();
94  hEff_W1->Write();
95  hEff_W2->Write();
96 
97  theFile->Close();
98 }
99 
100 // The real analysis
101  void DTSegment4DQuality::analyze(const Event & event, const EventSetup& eventSetup){
102  theFile->cd();
103 
104  // Get the DT Geometry
105  ESHandle<DTGeometry> dtGeom;
106  eventSetup.get<MuonGeometryRecord>().get(dtGeom);
107 
108  // Get the SimHit collection from the event
110  event.getByLabel(simHitLabel, "MuonDTHits", simHits); //FIXME: second string to be removed
111 
112  //Map simHits by chamber
113  map<DTChamberId, PSimHitContainer > simHitsPerCh;
114  for(PSimHitContainer::const_iterator simHit = simHits->begin();
115  simHit != simHits->end(); simHit++){
116  // Create the id of the chamber (the simHits in the DT known their wireId)
117  DTChamberId chamberId = (((DTWireId(simHit->detUnitId())).layerId()).superlayerId()).chamberId();
118  // Fill the map
119  simHitsPerCh[chamberId].push_back(*simHit);
120  }
121 
122  // Get the 4D rechits from the event
124  event.getByLabel(segment4DLabel, segment4Ds);
125 
126  // Loop over all chambers containing a segment
128  for (chamberId = segment4Ds->id_begin();
129  chamberId != segment4Ds->id_end();
130  ++chamberId){
131 
132  if((*chamberId).station() == 4)
133  continue; //use DTSegment2DQuality to analyze MB4 performaces
134 
135  //------------------------- simHits ---------------------------//
136  //Get simHits of each chamber
137  PSimHitContainer simHits = simHitsPerCh[(*chamberId)];
138 
139  // Map simhits per wire
140  map<DTWireId, PSimHitContainer > simHitsPerWire = DTHitQualityUtils::mapSimHitsPerWire(simHits);
141  map<DTWireId, const PSimHit*> muSimHitPerWire = DTHitQualityUtils::mapMuSimHitsPerWire(simHitsPerWire);
142  int nMuSimHit = muSimHitPerWire.size();
143  if(nMuSimHit == 0 || nMuSimHit == 1) {
144  if(debug && nMuSimHit == 1)
145  cout << "[DTSegment4DQuality] Only " << nMuSimHit << " mu SimHit in this chamber, skipping!" << endl;
146  continue; // If no or only one mu SimHit is found skip this chamber
147  }
148  if(debug)
149  cout << "=== Chamber " << (*chamberId) << " has " << nMuSimHit << " SimHits" << endl;
150 
151  //Find outer and inner mu SimHit to build a segment
152  pair<const PSimHit*, const PSimHit*> inAndOutSimHit = DTHitQualityUtils::findMuSimSegment(muSimHitPerWire);
153 
154  //Find direction and position of the sim Segment in Chamber RF
155  pair<LocalVector, LocalPoint> dirAndPosSimSegm = DTHitQualityUtils::findMuSimSegmentDirAndPos(inAndOutSimHit,
156  (*chamberId),&(*dtGeom));
157 
158  LocalVector simSegmLocalDir = dirAndPosSimSegm.first;
159  LocalPoint simSegmLocalPos = dirAndPosSimSegm.second;
160  const DTChamber* chamber = dtGeom->chamber(*chamberId);
161  GlobalPoint simSegmGlobalPos = chamber->toGlobal(simSegmLocalPos);
162  GlobalVector simSegmGlobalDir = chamber->toGlobal(simSegmLocalDir);
163 
164  //phi and theta angle of simulated segment in Chamber RF
165  float alphaSimSeg = DTHitQualityUtils::findSegmentAlphaAndBeta(simSegmLocalDir).first;
166  float betaSimSeg = DTHitQualityUtils::findSegmentAlphaAndBeta(simSegmLocalDir).second;
167  //x,y position of simulated segment in Chamber RF
168  float xSimSeg = simSegmLocalPos.x();
169  float ySimSeg = simSegmLocalPos.y();
170  //Position (in eta,phi coordinates) in lobal RF
171  float etaSimSeg = simSegmGlobalPos.eta();
172  float phiSimSeg = simSegmGlobalPos.phi();
173 
174  if(debug)
175  cout<<" Simulated segment: local direction "<<simSegmLocalDir<<endl
176  <<" local position "<<simSegmLocalPos<<endl
177  <<" alpha "<<alphaSimSeg<<endl
178  <<" beta "<<betaSimSeg<<endl;
179 
180  //---------------------------- recHits --------------------------//
181  // Get the range of rechit for the corresponding chamberId
182  bool recHitFound = false;
183  DTRecSegment4DCollection::range range = segment4Ds->get(*chamberId);
184  int nsegm = distance(range.first, range.second);
185  if(debug)
186  cout << " Chamber: " << *chamberId << " has " << nsegm
187  << " 4D segments" << endl;
188 
189  if (nsegm!=0) {
190  // Find the best RecHit: look for the 4D RecHit with the phi angle closest
191  // to that of segment made of SimHits.
192  // RecHits must have delta alpha and delta position within 5 sigma of
193  // the residual distribution (we are looking for residuals of segments
194  // usefull to the track fit) for efficency purpose
195  const DTRecSegment4D* bestRecHit = 0;
196  bool bestRecHitFound = false;
197  double deltaAlpha = 99999;
198 
199  // Loop over the recHits of this chamberId
200  for (DTRecSegment4DCollection::const_iterator segment4D = range.first;
201  segment4D!=range.second;
202  ++segment4D){
203  // Check the dimension
204  if((*segment4D).dimension() != 4) {
205  if(debug)cout << "[DTSegment4DQuality]***Error: This is not 4D segment!!!" << endl;
206  continue;
207  }
208  // Segment Local Direction and position (in Chamber RF)
209  LocalVector recSegDirection = (*segment4D).localDirection();
210  //LocalPoint recSegPosition = (*segment4D).localPosition();
211 
212  float recSegAlpha = DTHitQualityUtils::findSegmentAlphaAndBeta(recSegDirection).first;
213  if(debug)
214  cout << " RecSegment direction: " << recSegDirection << endl
215  << " position : " << (*segment4D).localPosition() << endl
216  << " alpha : " << recSegAlpha << endl
217  << " beta : " << DTHitQualityUtils::findSegmentAlphaAndBeta(recSegDirection).second << endl;
218 
219  if(fabs(recSegAlpha - alphaSimSeg) < deltaAlpha) {
220  deltaAlpha = fabs(recSegAlpha - alphaSimSeg);
221  bestRecHit = &(*segment4D);
222  bestRecHitFound = true;
223  }
224  } // End of Loop over all 4D RecHits
225 
226  if(bestRecHitFound) {
227  // Best rechit direction and position in Chamber RF
228  LocalPoint bestRecHitLocalPos = bestRecHit->localPosition();
229  LocalVector bestRecHitLocalDir = bestRecHit->localDirection();
230  // Errors on x and y
231  LocalError bestRecHitLocalPosErr = bestRecHit->localPositionError();
232  LocalError bestRecHitLocalDirErr = bestRecHit->localDirectionError();
233 
234  float alphaBestRHit = DTHitQualityUtils::findSegmentAlphaAndBeta(bestRecHitLocalDir).first;
235  float betaBestRHit = DTHitQualityUtils::findSegmentAlphaAndBeta(bestRecHitLocalDir).second;
236  // Errors on alpha and beta
237 
238  // Get position and direction using the rx projection (so in SL
239  // reference frame). Note that x (and y) are swapped wrt to Chamber
240  // frame
241  //if (bestRecHit->hasZed() ) {
242  const DTSLRecSegment2D * zedRecSeg = bestRecHit->zSegment();
243  LocalPoint bestRecHitLocalPosRZ = zedRecSeg->localPosition();
244  LocalVector bestRecHitLocalDirRZ = zedRecSeg->localDirection();
245  // Errors on x and y
246  LocalError bestRecHitLocalPosErrRZ = zedRecSeg->localPositionError();
247  LocalError bestRecHitLocalDirErrRZ = zedRecSeg->localDirectionError();
248 
249  float alphaBestRHitRZ = DTHitQualityUtils::findSegmentAlphaAndBeta(bestRecHitLocalDirRZ).first;
250 
251  // Get SimSeg position and Direction in rZ SL frame
252  const DTSuperLayer* sl = dtGeom->superLayer(zedRecSeg->superLayerId());
253  LocalPoint simSegLocalPosRZTmp = sl->toLocal(simSegmGlobalPos);
254  LocalVector simSegLocalDirRZ = sl->toLocal(simSegmGlobalDir);
255  LocalPoint simSegLocalPosRZ =
256  simSegLocalPosRZTmp + simSegLocalDirRZ*(-simSegLocalPosRZTmp.z()/(cos(simSegLocalDirRZ.theta())));
257  float alphaSimSegRZ = DTHitQualityUtils::findSegmentAlphaAndBeta(simSegLocalDirRZ).first;
258 
259  if (debug) cout <<
260  "RZ SL: recPos " << bestRecHitLocalPosRZ <<
261  "recDir " << bestRecHitLocalDirRZ <<
262  "recAlpha " << alphaBestRHitRZ << endl <<
263  "RZ SL: simPos " << simSegLocalPosRZ <<
264  "simDir " << simSegLocalDirRZ <<
265  "simAlpha " << alphaSimSegRZ << endl ;
266  //}
267 
268 
269  if(fabs(alphaBestRHit - alphaSimSeg) < 5*sigmaResAlpha &&
270  fabs(betaBestRHit - betaSimSeg) < 5*sigmaResBeta &&
271  fabs(bestRecHitLocalPos.x() - xSimSeg) < 5*sigmaResX &&
272  fabs(bestRecHitLocalPos.y() - ySimSeg) < 5*sigmaResY) {
273  recHitFound = true;
274  }
275 
276  // Fill Residual histos
277  HRes4DHit *histo=0;
278 
279  if((*chamberId).wheel() == 0)
280  histo = h4DHit_W0;
281  else if(abs((*chamberId).wheel()) == 1)
282  histo = h4DHit_W1;
283  else if(abs((*chamberId).wheel()) == 2)
284  histo = h4DHit_W2;
285 
286  histo->Fill(alphaSimSeg,
287  alphaBestRHit,
288  betaSimSeg,
289  betaBestRHit,
290  xSimSeg,
291  bestRecHitLocalPos.x(),
292  ySimSeg,
293  bestRecHitLocalPos.y(),
294  etaSimSeg,
295  phiSimSeg,
296  bestRecHitLocalPosRZ.x(),
297  simSegLocalPosRZ.x(),
298  alphaBestRHitRZ,
299  alphaSimSegRZ,
300  sqrt(bestRecHitLocalDirErr.xx()),
301  sqrt(bestRecHitLocalDirErr.yy()),
302  sqrt(bestRecHitLocalPosErr.xx()),
303  sqrt(bestRecHitLocalPosErr.yy()),
304  sqrt(bestRecHitLocalDirErrRZ.xx()),
305  sqrt(bestRecHitLocalPosErrRZ.xx())
306  );
307 
308  h4DHit->Fill(alphaSimSeg,
309  alphaBestRHit,
310  betaSimSeg,
311  betaBestRHit,
312  xSimSeg,
313  bestRecHitLocalPos.x(),
314  ySimSeg,
315  bestRecHitLocalPos.y(),
316  etaSimSeg,
317  phiSimSeg,
318  bestRecHitLocalPosRZ.x(),
319  simSegLocalPosRZ.x(),
320  alphaBestRHitRZ,
321  alphaSimSegRZ,
322  sqrt(bestRecHitLocalDirErr.xx()),
323  sqrt(bestRecHitLocalDirErr.yy()),
324  sqrt(bestRecHitLocalPosErr.xx()),
325  sqrt(bestRecHitLocalPosErr.yy()),
326  sqrt(bestRecHitLocalDirErrRZ.xx()),
327  sqrt(bestRecHitLocalPosErrRZ.xx())
328  );
329  }
330  } //end of if(nsegm!=0)
331 
332  // Fill Efficiency plot
333  HEff4DHit *heff = 0;
334 
335  if((*chamberId).wheel() == 0)
336  heff = hEff_W0;
337  else if(abs((*chamberId).wheel()) == 1)
338  heff = hEff_W1;
339  else if(abs((*chamberId).wheel()) == 2)
340  heff = hEff_W2;
341  heff->Fill(etaSimSeg, phiSimSeg, xSimSeg, ySimSeg, alphaSimSeg, betaSimSeg, recHitFound);
342  hEff_All->Fill(etaSimSeg, phiSimSeg, xSimSeg, ySimSeg, alphaSimSeg, betaSimSeg, recHitFound);
343  } // End of loop over chambers
344  }
T getParameter(std::string const &) const
virtual LocalError localPositionError() const
local position error in SL frame
T getUntrackedParameter(std::string const &, T const &) const
float xx() const
Definition: LocalError.h:19
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:53
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
T y() const
Definition: PV3DBase.h:57
#define abs(x)
Definition: mlp_lapack.h:159
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:64
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup)
Perform the real analysis.
identifier iterator
Definition: RangeMap.h:139
virtual LocalError localDirectionError() const
the local direction error (xx,xy,yy) in SL frame: only xx is not 0.
virtual ~DTSegment4DQuality()
Destructor.
tuple histo
Definition: trackerHits.py:12
static std::map< DTWireId, const PSimHit * > mapMuSimHitsPerWire(const std::map< DTWireId, edm::PSimHitContainer > &simHitWireMap)
Create a map between the Mu SimHits and corresponding MuBarWireId ;.
Geom::Theta< T > theta() const
Definition: PV3DBase.h:69
virtual LocalError localPositionError() const
Local position error in Chamber frame.
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) ...
virtual LocalVector localDirection() const
Local direction in Chamber frame.
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:46
DTSegment4DQuality(const edm::ParameterSet &pset)
Constructor.
float yy() const
Definition: LocalError.h:21
T sqrt(T t)
Definition: SSEVec.h:28
void Fill(float simDirectionAlpha, float recDirectionAlpha, float simDirectionBeta, float recDirectionBeta, float simX, float recX, float simY, float recY, float simEta, float simPhi, float recYRZ, float simYRZ, float recBetaRZ, float simBetaRZ, float sigmaAlpha, float sigmaBeta, float sigmaX, float sigmaY, float sigmaBetaRZ, float sigmaYRZ)
Definition: Histograms.h:860
T z() const
Definition: PV3DBase.h:58
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
A set of histograms for efficiency 4D RecHits.
Definition: Histograms.h:1076
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
virtual LocalPoint localPosition() const
Local position in Chamber frame.
static std::pair< double, double > findSegmentAlphaAndBeta(const LocalVector &direction)
Find the angles from a segment direction:
DTSuperLayerId superLayerId() const
The id of the superlayer on which reside the segment.
virtual LocalPoint localPosition() const
local position in SL frame
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
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...
const T & get() const
Definition: EventSetup.h:55
tuple simHits
Definition: trackerHits.py:16
T eta() const
Definition: PV3DBase.h:70
virtual LocalVector localDirection() const
the local direction in SL frame
tuple cout
Definition: gather_cfg.py:41
std::vector< PSimHit > PSimHitContainer
static std::map< DTWireId, edm::PSimHitContainer > mapSimHitsPerWire(const edm::PSimHitContainer &simhits)
#define debug
Definition: MEtoEDMFormat.h:34
T x() const
Definition: PV3DBase.h:56
void Fill(float etaSimSegm, float phiSimSegm, float xSimSegm, float ySimSegm, float alphaSimSegm, float betaSimSegm, bool fillRecHit)
Definition: Histograms.h:1170
virtual LocalError localDirectionError() const
Local direction error in the Chamber frame.