CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTSegment2DSLPhiQuality.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * $Date: 2009/11/04 17:22:32 $
5  * $Revision: 1.10 $
6  * \author S. Bolognesi and G. Cerminara - INFN Torino
7  */
8 
11 
16 
20 
27 
28 #include "Histograms.h"
29 #include "TStyle.h"
30 #include "TFile.h"
31 
32 #include <iostream>
33 #include <map>
34 //#include "utils.C"
35 
36 using namespace std;
37 using namespace edm;
38 //TStyle * mystyle;
39 
40 
41 // Constructor
43  // Get the debug parameter for verbose output
44  debug = pset.getUntrackedParameter<bool>("debug");
46 
47  // the name of the simhit collection
48  simHitLabel = pset.getUntrackedParameter<InputTag>("simHitLabel");
49  // the name of the 4D rec hit collection
50  segment4DLabel = pset.getUntrackedParameter<InputTag>("segment4DLabel");
51 
52  //sigma resolution on position
53  sigmaResPos = pset.getParameter<double>("sigmaResPos");
54  //sigma resolution on angle
55  sigmaResAngle = pset.getParameter<double>("sigmaResAngle");
56  doall = pset.getUntrackedParameter<bool>("doall", false);
57  local = pset.getUntrackedParameter<bool>("local", false);
58 
59  // Create the root file
60  //theFile = new TFile(rootFileName.c_str(), "RECREATE");
61  //theFile->cd();
62  // ----------------------
63  // get hold of back-end interface
64  dbe_ = 0;
65  dbe_ = Service<DQMStore>().operator->();
66  if ( dbe_ ) {
67  if (debug) {
68  dbe_->setVerbose(1);
69  } else {
70  dbe_->setVerbose(0);
71  }
72  }
73  if ( dbe_ ) {
74  if ( debug ) dbe_->showDirStructure();
75  }
76 
77  // Book the histos
78  h2DHitSuperPhi = new HRes2DHit ("SuperPhi",dbe_,doall,local);
79  if(doall) h2DHitEff_SuperPhi = new HEff2DHit ("SuperPhi",dbe_);
80 }
81 
82 // Destructor
84 }
85 
87  edm::EventSetup const& c){
88 }
89 
90 
91 
92 
94  // Write the histos to file
95  //theFile->cd();
96  //h2DHitSuperPhi->Write();
97 
98  if(doall) h2DHitEff_SuperPhi->ComputeEfficiency();
99  //h2DHitEff_SuperPhi->Write();
100 
101  //if ( rootFileName.size() != 0 && dbe_ ) dbe_->save(rootFileName);
102  //theFile->Close();
103 }
104 
105 // The real analysis
106 void DTSegment2DSLPhiQuality::analyze(const Event & event, const EventSetup& eventSetup){
107  //theFile->cd();
108 
109  // Get the DT Geometry
110  ESHandle<DTGeometry> dtGeom;
111  eventSetup.get<MuonGeometryRecord>().get(dtGeom);
112 
113  // Get the SimHit collection from the event
115  event.getByLabel(simHitLabel, simHits); //FIXME: second string to be removed
116 
117  //Map simHits by chamber
118  map<DTChamberId, PSimHitContainer > simHitsPerCh;
119  for(PSimHitContainer::const_iterator simHit = simHits->begin();
120  simHit != simHits->end(); simHit++){
121  // Create the id of the chamber (the simHits in the DT known their wireId)
122  DTChamberId chamberId = (((DTWireId(simHit->detUnitId())).layerId()).superlayerId()).chamberId();
123  // Fill the map
124  simHitsPerCh[chamberId].push_back(*simHit);
125  }
126 
127  // Get the 4D rechits from the event
129  event.getByLabel(segment4DLabel, segment4Ds);
130 
131  if(!segment4Ds.isValid()) {
132  if(debug) cout << "[DTSegment2DSLPhiQuality]**Warning: no 4D Segments with label: " << segment4DLabel
133  << " in this event, skipping!" << endl;
134  return;
135  }
136 
137  // Loop over all chambers containing a segment
139  for (chamberId = segment4Ds->id_begin();
140  chamberId != segment4Ds->id_end();
141  ++chamberId){
142 
143  //------------------------- simHits ---------------------------//
144  //Get simHits of each chamber
145  PSimHitContainer simHits = simHitsPerCh[(*chamberId)];
146 
147  // Map simhits per wire
148  map<DTWireId, PSimHitContainer > simHitsPerWire = DTHitQualityUtils::mapSimHitsPerWire(simHits);
149  map<DTWireId, const PSimHit*> muSimHitPerWire = DTHitQualityUtils::mapMuSimHitsPerWire(simHitsPerWire);
150  int nMuSimHit = muSimHitPerWire.size();
151  if(nMuSimHit == 0 || nMuSimHit == 1) {
152  if(debug && nMuSimHit == 1)
153  cout << "[DTSegment2DSLPhiQuality] Only " << nMuSimHit << " mu SimHit in this chamber, skipping!" << endl;
154  continue; // If no or only one mu SimHit is found skip this chamber
155  }
156  if(debug)
157  cout << "=== Chamber " << (*chamberId) << " has " << nMuSimHit << " SimHits" << endl;
158 
159  //Find outer and inner mu SimHit to build a segment
160  pair<const PSimHit*, const PSimHit*> inAndOutSimHit = DTHitQualityUtils::findMuSimSegment(muSimHitPerWire);
161 
162  //Find direction and position of the sim Segment in Chamber RF
163  pair<LocalVector, LocalPoint> dirAndPosSimSegm = DTHitQualityUtils::findMuSimSegmentDirAndPos(inAndOutSimHit,
164  (*chamberId),&(*dtGeom));
165 
166  LocalVector simSegmLocalDir = dirAndPosSimSegm.first;
167  LocalPoint simSegmLocalPos = dirAndPosSimSegm.second;
168  const DTChamber* chamber = dtGeom->chamber(*chamberId);
169  GlobalPoint simSegmGlobalPos = chamber->toGlobal(simSegmLocalPos);
170 
171  //Atan(x/z) angle and x position in SL RF
172  float angleSimSeg = DTHitQualityUtils::findSegmentAlphaAndBeta(simSegmLocalDir).first;
173  float posSimSeg = simSegmLocalPos.x();
174  //Position (in eta,phi coordinates) in lobal RF
175  float etaSimSeg = simSegmGlobalPos.eta();
176  float phiSimSeg = simSegmGlobalPos.phi();
177 
178  if(debug)
179  cout<<" Simulated segment: local direction "<<simSegmLocalDir<<endl
180  <<" local position "<<simSegmLocalPos<<endl
181  <<" angle "<<angleSimSeg<<endl;
182 
183  //---------------------------- recHits --------------------------//
184  // Get the range of rechit for the corresponding chamberId
185  bool recHitFound = false;
186  DTRecSegment4DCollection::range range = segment4Ds->get(*chamberId);
187  int nsegm = distance(range.first, range.second);
188  if(debug)
189  cout << " Chamber: " << *chamberId << " has " << nsegm
190  << " 4D segments" << endl;
191 
192  if (nsegm!=0) {
193  // Find the best RecHit: look for the 4D RecHit with the phi angle closest
194  // to that of segment made of SimHits.
195  // RecHits must have delta alpha and delta position within 5 sigma of
196  // the residual distribution (we are looking for residuals of segments
197  // usefull to the track fit) for efficency purpose
198  const DTRecSegment2D* bestRecHit = 0;
199  bool bestRecHitFound = false;
200  double deltaAlpha = 99999;
201 
202  // Loop over the recHits of this chamberId
203  for (DTRecSegment4DCollection::const_iterator segment4D = range.first;
204  segment4D!=range.second;
205  ++segment4D){
206  // Check the dimension
207  if((*segment4D).dimension() != 4) {
208  if(debug) cout << "[DTSegment2DSLPhiQuality]***Error: This is not 4D segment!!!" << endl;
209  continue;
210  }
211 
212  //Get 2D superPhi segments from 4D segments
213  const DTChamberRecSegment2D* phiSegment2D = (*segment4D).phiSegment();
214  if((*phiSegment2D).dimension() != 2) {
215  if(debug) cout << "[DTSegment2DQuality]***Error: This is not 2D segment!!!" << endl;
216  abort();
217  }
218 
219  // Segment Local Direction and position (in Chamber RF)
220  LocalVector recSegDirection = (*phiSegment2D).localDirection();
221 
222  float recSegAlpha = DTHitQualityUtils::findSegmentAlphaAndBeta(recSegDirection).first;
223  if(debug)
224  cout << " RecSegment direction: " << recSegDirection << endl
225  << " position : " << (*phiSegment2D).localPosition() << endl
226  << " alpha : " << recSegAlpha << endl;
227 
228  if(fabs(recSegAlpha - angleSimSeg) < deltaAlpha) {
229  deltaAlpha = fabs(recSegAlpha - angleSimSeg);
230  bestRecHit = &(*phiSegment2D);
231  bestRecHitFound = true;
232  }
233  } // End of Loop over all 4D RecHits of this chambers
234 
235  if(bestRecHitFound) {
236  // Best rechit direction and position in Chamber RF
237  LocalPoint bestRecHitLocalPos = bestRecHit->localPosition();
238  LocalVector bestRecHitLocalDir = bestRecHit->localDirection();
239 
240  LocalError bestRecHitLocalPosErr = bestRecHit->localPositionError();
241  LocalError bestRecHitLocalDirErr = bestRecHit->localDirectionError();
242 
243  float angleBestRHit = DTHitQualityUtils::findSegmentAlphaAndBeta(bestRecHitLocalDir).first;
244  if(fabs(angleBestRHit - angleSimSeg) < 5*sigmaResAngle &&
245  fabs(bestRecHitLocalPos.x() - posSimSeg) < 5*sigmaResPos) {
246  recHitFound = true;
247  }
248 
249  // Fill Residual histos
250  h2DHitSuperPhi->Fill(angleSimSeg,
251  angleBestRHit,
252  posSimSeg,
253  bestRecHitLocalPos.x(),
254  etaSimSeg,
255  phiSimSeg,
256  sqrt(bestRecHitLocalPosErr.xx()),
257  sqrt(bestRecHitLocalDirErr.xx())
258  );
259  }
260  } //end of if(nsegm!=0)
261 
262  // Fill Efficiency plot
263  if(doall) {h2DHitEff_SuperPhi->Fill(etaSimSeg,
264  phiSimSeg,
265  posSimSeg,
266  angleSimSeg,
267  recHitFound);}
268  } // End of loop over chambers
269 }
270 
271 
272 // Fit a histogram in the range (minfit, maxfit) with a gaussian and
273 // draw it in the range (min, max)
T getParameter(std::string const &) const
virtual LocalError localPositionError() const
local position error in SL frame
DTSegment2DSLPhiQuality(const edm::ParameterSet &pset)
Constructor.
T getUntrackedParameter(std::string const &, T const &) const
float xx() const
Definition: LocalError.h:24
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:52
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup)
Perform the real analysis.
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:68
identifier iterator
Definition: RangeMap.h:138
virtual LocalError localDirectionError() const
the local direction error (xx,xy,yy) in SL frame: only xx is not 0.
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) ...
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:45
T sqrt(T t)
Definition: SSEVec.h:46
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)
Find the angles from a segment direction:
DQMStore * dbe_
virtual LocalPoint localPosition() const
local position in SL frame
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:75
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &c)
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)
#define debug
Definition: MEtoEDMFormat.h:34
T x() const
Definition: PV3DBase.h:61
virtual ~DTSegment2DSLPhiQuality()
Destructor.