CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TkAlCaRecoMonitor.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  */
5 
7 
15 
20 
22 
23 #include <string>
24 //#include <sstream>
25 #include "TLorentzVector.h"
26 
28  conf_ = iConfig;
29  trackProducer_ = consumes<reco::TrackCollection>(conf_.getParameter<edm::InputTag>("TrackProducer"));
30  referenceTrackProducer_ = consumes<reco::TrackCollection>(conf_.getParameter<edm::InputTag>("ReferenceTrackProducer"));
31  jetCollection_ = mayConsume<reco::CaloJetCollection>(conf_.getParameter<edm::InputTag>("CaloJetCollection"));
32 
34 }
35 
37 
39 
40  std::string histname; //for naming the histograms according to algorithm used
41 
42  std::string AlgoName = conf_.getParameter<std::string>("AlgoName");
43  std::string MEFolderName = conf_.getParameter<std::string>("FolderName");
44 
45  daughterMass_ = conf_.getParameter<double>("daughterMass");
46 
47  maxJetPt_ = conf_.getParameter<double>("maxJetPt");
48 
49  dqmStore_->setCurrentFolder(MEFolderName+"/TkAlignmentSpecific");
50  fillInvariantMass_ = conf_.getParameter<bool>("fillInvariantMass");
51  runsOnReco_ = conf_.getParameter<bool>("runsOnReco");
52  useSignedR_ = conf_.getParameter<bool>("useSignedR");
53  fillRawIdMap_ = conf_.getParameter<bool>("fillRawIdMap");
54 
55  //
56  unsigned int MassBin = conf_.getParameter<unsigned int>("MassBin");
57  double MassMin = conf_.getParameter<double>("MassMin");
58  double MassMax = conf_.getParameter<double>("MassMax");
59 
61  histname = "InvariantMass_";
62  invariantMass_ = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, MassBin, MassMin, MassMax);
63  invariantMass_->setAxisTitle("invariant Mass / GeV");
64  }else{
65  invariantMass_ = 0;
66  }
67 
68  unsigned int TrackPtPositiveBin = conf_.getParameter<unsigned int>("TrackPtBin");
69  double TrackPtPositiveMin = conf_.getParameter<double>("TrackPtMin");
70  double TrackPtPositiveMax = conf_.getParameter<double>("TrackPtMax");
71 
72  histname = "TrackPtPositive_";
73  TrackPtPositive_ = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, TrackPtPositiveBin, TrackPtPositiveMin, TrackPtPositiveMax);
74  TrackPtPositive_->setAxisTitle("p_{T} of tracks charge > 0");
75 
76  unsigned int TrackPtNegativeBin = conf_.getParameter<unsigned int>("TrackPtBin");
77  double TrackPtNegativeMin = conf_.getParameter<double>("TrackPtMin");
78  double TrackPtNegativeMax = conf_.getParameter<double>("TrackPtMax");
79 
80  histname = "TrackPtNegative_";
81  TrackPtNegative_ = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, TrackPtNegativeBin, TrackPtNegativeMin, TrackPtNegativeMax);
82  TrackPtNegative_->setAxisTitle("p_{T} of tracks charge < 0");
83 
84  histname = "TrackQuality_";
85  TrackQuality_ = dqmStore_->book1D(histname+AlgoName, histname+AlgoName,
87  TrackQuality_->setAxisTitle("quality");
88  for ( int i = 0; i<reco::TrackBase::qualitySize; ++i){
89  TrackQuality_->getTH1()->GetXaxis()->SetBinLabel(i+1,
91  }
92 
93  unsigned int SumChargeBin = conf_.getParameter<unsigned int>("SumChargeBin");
94  double SumChargeMin = conf_.getParameter<double>("SumChargeMin");
95  double SumChargeMax = conf_.getParameter<double>("SumChargeMax");
96 
97  histname = "SumCharge_";
98  sumCharge_ = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, SumChargeBin, SumChargeMin, SumChargeMax);
99  sumCharge_->setAxisTitle("#SigmaCharge");
100 
101  unsigned int TrackCurvatureBin = conf_.getParameter<unsigned int>("TrackCurvatureBin");
102  double TrackCurvatureMin = conf_.getParameter<double>("TrackCurvatureMin");
103  double TrackCurvatureMax = conf_.getParameter<double>("TrackCurvatureMax");
104 
105  histname = "TrackCurvature_";
106  TrackCurvature_ = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, TrackCurvatureBin, TrackCurvatureMin, TrackCurvatureMax);
107  TrackCurvature_->setAxisTitle("#kappa track");
108 
109  if( runsOnReco_ ){
110 
111  unsigned int JetPtBin = conf_.getParameter<unsigned int>("JetPtBin");
112  double JetPtMin = conf_.getParameter<double>("JetPtMin");
113  double JetPtMax = conf_.getParameter<double>("JetPtMax");
114 
115  histname = "JetPt_";
116  jetPt_ = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, JetPtBin, JetPtMin, JetPtMax);
117  jetPt_->setAxisTitle("jet p_{T} / GeV");
118 
119  unsigned int MinJetDeltaRBin = conf_.getParameter<unsigned int>("MinJetDeltaRBin");
120  double MinJetDeltaRMin = conf_.getParameter<double>("MinJetDeltaRMin");
121  double MinJetDeltaRMax = conf_.getParameter<double>("MinJetDeltaRMax");
122 
123  histname = "MinJetDeltaR_";
124  minJetDeltaR_ = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, MinJetDeltaRBin, MinJetDeltaRMin, MinJetDeltaRMax);
125  minJetDeltaR_->setAxisTitle("minimal Jet #DeltaR / rad");
126  }else{
127  jetPt_ = NULL;
129  }
130 
131  unsigned int MinTrackDeltaRBin = conf_.getParameter<unsigned int>("MinTrackDeltaRBin");
132  double MinTrackDeltaRMin = conf_.getParameter<double>("MinTrackDeltaRMin");
133  double MinTrackDeltaRMax = conf_.getParameter<double>("MinTrackDeltaRMax");
134 
135  histname = "MinTrackDeltaR_";
136  minTrackDeltaR_ = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, MinTrackDeltaRBin, MinTrackDeltaRMin, MinTrackDeltaRMax);
137  minTrackDeltaR_->setAxisTitle("minimal Track #DeltaR / rad");
138 
139  unsigned int TrackEfficiencyBin = conf_.getParameter<unsigned int>("TrackEfficiencyBin");
140  double TrackEfficiencyMin = conf_.getParameter<double>("TrackEfficiencyMin");
141  double TrackEfficiencyMax = conf_.getParameter<double>("TrackEfficiencyMax");
142 
143  histname = "AlCaRecoTrackEfficiency_";
144  AlCaRecoTrackEfficiency_ = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, TrackEfficiencyBin, TrackEfficiencyMin, TrackEfficiencyMax);
145  Labels l_tp, l_rtp;
149 
150  int zBin = conf_.getParameter<unsigned int>("HitMapsZBin"); //300
151  double zMax = conf_.getParameter<double>("HitMapZMax"); //300.0; //cm
152 
153  int rBin = conf_.getParameter<unsigned int>("HitMapsRBin");//120;
154  double rMax = conf_.getParameter<double>("HitMapRMax"); //120.0; //cm
155 
156  histname = "Hits_ZvsR_";
157  double rMin = 0.0;
158  if( useSignedR_ )
159  rMin = -rMax;
160 
161  Hits_ZvsR_ = dqmStore_->book2D(histname+AlgoName, histname+AlgoName, zBin, -zMax, zMax, rBin, rMin, rMax);
162 
163  histname = "Hits_XvsY_";
164  Hits_XvsY_ = dqmStore_->book2D(histname+AlgoName, histname+AlgoName, rBin, -rMax, rMax, rBin, -rMax, rMax);
165 
166  if( fillRawIdMap_){
167  histname = "Hits_perDetId_";
168 
169  //leads to differences in axsis between samples??
170  //int nModules = binByRawId_.size();
171  //Hits_perDetId_ = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, nModules, static_cast<double>(nModules) -0.5, static_cast<double>(nModules) -0.5);
172  Hits_perDetId_ = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, 16601,-0.5, 16600.5 );
173  Hits_perDetId_->setAxisTitle("rawId Bins");
174 
176  // std::stringstream binLabel;
177  // for( std::map<int,int>::iterator it = binByRawId_.begin(); it != binByRawId_.end(); ++it ){
178  // binLabel.str() = "";
179  // binLabel << (*it).first;
180  // Hits_perDetId_->getTH1()->GetXaxis()->SetBinLabel( (*it).second +1, binLabel.str().c_str());
181  // }
182  }
183 }
184 //
185 // -- Analyse
186 //
188 
189  edm::Handle<reco::TrackCollection> trackCollection;
190  iEvent.getByToken(trackProducer_, trackCollection);
191  if (!trackCollection.isValid()){
192  edm::LogError("Alignment")<<"invalid trackcollection encountered!";
193  return;
194  }
195 
196  edm::Handle<reco::TrackCollection> referenceTrackCollection;
197  iEvent.getByToken(referenceTrackProducer_, referenceTrackCollection);
198  if (!trackCollection.isValid()){
199  edm::LogError("Alignment")<<"invalid reference track-collection encountered!";
200  return;
201  }
202 
204  iSetup.get<TrackerDigiGeometryRecord>().get(geometry);
205  if(! geometry.isValid()){
206  edm::LogError("Alignment")<<"invalid geometry found in event setup!";
207  }
208 
209  edm::ESHandle<MagneticField> magneticField;
210  iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
211  if (!magneticField.isValid()){
212  edm::LogError("Alignment")<<"invalid magnetic field configuration encountered!";
213  return;
214  }
215 
217  if(runsOnReco_){
218  iEvent.getByToken(jetCollection_, jets);
219  if(! jets.isValid()){
220  edm::LogError("Alignment")<<"no jet collection found in event!";
221  }
222  }
223  // fill only once - not yet in beginJob since no access to geometry
224  if (fillRawIdMap_ && binByRawId_.empty()) this->fillRawIdMap(*geometry);
225 
226  AlCaRecoTrackEfficiency_->Fill( static_cast<double>((*trackCollection).size()) / (*referenceTrackCollection).size() );
227 
228  double sumOfCharges = 0;
229  for( reco::TrackCollection::const_iterator track = (*trackCollection).begin(); track < (*trackCollection).end(); ++track ){
230  double dR = 0;
231  if(runsOnReco_){
232  double minJetDeltaR = 10; // some number > 2pi
233  for(reco::CaloJetCollection::const_iterator itJet = jets->begin(); itJet != jets->end() ; ++itJet) {
234  jetPt_->Fill( (*itJet).pt() );
235  dR = deltaR((*track),(*itJet));
236  if((*itJet).pt() > maxJetPt_ && dR < minJetDeltaR)
237  minJetDeltaR = dR;
238 
239  //edm::LogInfo("Alignment") <<"> isolated: "<< isolated << " jetPt "<< (*itJet).pt() <<" deltaR: "<< deltaR(*(*it),(*itJet)) ;
240  }
241  minJetDeltaR_->Fill( minJetDeltaR );
242  }
243 
244  double minTrackDeltaR = 10; // some number > 2pi
245  for( reco::TrackCollection::const_iterator track2 = (*trackCollection).begin(); track2 < (*trackCollection).end(); ++track2 ){
246  dR = deltaR((*track),(*track2));
247  if(dR < minTrackDeltaR && dR > 1e-6)
248  minTrackDeltaR = dR;
249  }
250 
251  for ( int i = 0; i<reco::TrackBase::qualitySize; ++i){
252  if( (*track).quality( reco::TrackBase::TrackQuality(i) ) ){
253  TrackQuality_->Fill( i );
254  }
255  }
256 
257  GlobalPoint gPoint((*track).vx(), (*track).vy(), (*track).vz());
258  double B = magneticField->inTesla(gPoint).z();
259  double curv = -(*track).charge()*0.002998*B/(*track).pt();
260  TrackCurvature_->Fill( curv );
261 
262  if( (*track).charge() > 0 )
263  TrackPtPositive_->Fill( (*track).pt() );
264  if( (*track).charge() < 0 )
265  TrackPtNegative_->Fill( (*track).pt() );
266 
267  minTrackDeltaR_->Fill( minTrackDeltaR );
268  fillHitmaps( *track, *geometry );
269  sumOfCharges += (*track).charge();
270  }
271 
272  sumCharge_->Fill( sumOfCharges );
273 
274  if(fillInvariantMass_){
275  if((*trackCollection).size() == 2){
276  TLorentzVector track0((*trackCollection).at(0).px(),(*trackCollection).at(0).py(),(*trackCollection).at(0).pz(),
277  sqrt(((*trackCollection).at(0).p()*(*trackCollection).at(0).p())+daughterMass_*daughterMass_));
278  TLorentzVector track1((*trackCollection).at(1).px(),(*trackCollection).at(1).py(),(*trackCollection).at(1).pz(),
279  sqrt(((*trackCollection).at(1).p()*(*trackCollection).at(1).p())+daughterMass_*daughterMass_));
280  TLorentzVector mother = track0+track1;
281 
282  invariantMass_->Fill( mother.M() );
283  }else{
284  edm::LogInfo("Alignment")<<"wrong number of tracks trackcollection encountered: "<<(*trackCollection).size();
285  }
286  }
287 }
288 
290 {
291  for (trackingRecHit_iterator iHit = track.recHitsBegin(); iHit != track.recHitsEnd(); ++iHit) {
292  if( (*iHit)->isValid() ){
293  const TrackingRecHit *hit = (*iHit);
294  const DetId geoId(hit->geographicalId());
295  const GeomDet* gd = geometry.idToDet(geoId);
296  // since 2_1_X local hit positions are transient. taking center of the hit module for now.
297  // The alternative would be the coarse estimation or a refit.
298  //const GlobalPoint globP( gd->toGlobal( hit->localPosition() ) );
299  const GlobalPoint globP( gd->toGlobal( Local3DPoint(0.,0.,0.) ) );
300  double r = sqrt( globP.x()*globP.x() + globP.y()*globP.y() );
301  if( useSignedR_ )
302  r*= globP.y() / fabs( globP.y() );
303 
304  Hits_ZvsR_->Fill( globP.z(), r );
305  Hits_XvsY_->Fill( globP.x(), globP.y() );
306 
307  if( fillRawIdMap_)
308  Hits_perDetId_->Fill( binByRawId_[ geoId.rawId() ]);
309  }
310  }
311 }
312 
314 {
315  std::vector<int> sortedRawIds;
316  for (std::vector<DetId>::const_iterator iDetId = geometry.detUnitIds().begin();
317  iDetId != geometry.detUnitIds().end(); ++iDetId) {
318  sortedRawIds.push_back((*iDetId).rawId());
319  }
320  std::sort(sortedRawIds.begin(), sortedRawIds.end());
321 
322  int i = 0;
323  for (std::vector<int>::iterator iRawId = sortedRawIds.begin();
324  iRawId != sortedRawIds.end(); ++iRawId){
325  binByRawId_[*iRawId] = i;
326  ++i;
327  }
328 }
329 
330 
332  bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
334  if(outputMEsInRootFile){
335  //dqmStore_->showDirStructure();
336  dqmStore_->save(outputFileName);
337  }
338 }
339 
341 
virtual void beginJob()
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
static std::string qualityName(TrackQuality)
Definition: TrackBase.h:580
virtual void analyze(const edm::Event &, const edm::EventSetup &)
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:971
void fillRawIdMap(const TrackerGeometry &geometry)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
TrackQuality
track quality
Definition: TrackBase.h:133
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
MonitorElement * TrackQuality_
#define NULL
Definition: scimark2.h:8
MonitorElement * minJetDeltaR_
std::map< int, int > binByRawId_
MonitorElement * Hits_XvsY_
MonitorElement * Hits_ZvsR_
void Fill(long long x)
MonitorElement * AlCaRecoTrackEfficiency_
MonitorElement * sumCharge_
int iEvent
Definition: GenABIO.cc:230
virtual void endJob(void)
edm::EDGetTokenT< reco::TrackCollection > trackProducer_
T sqrt(T t)
Definition: SSEVec.h:48
vector< PseudoJet > jets
MonitorElement * invariantMass_
MonitorElement * TrackPtNegative_
TH1 * getTH1(void) const
void fillHitmaps(const reco::Track &track, const TrackerGeometry &geometry)
edm::EDGetTokenT< reco::CaloJetCollection > jetCollection_
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
bool isValid() const
Definition: HandleBase.h:76
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
Definition: DetId.h:18
MonitorElement * Hits_perDetId_
const T & get() const
Definition: EventSetup.h:55
MonitorElement * TrackCurvature_
MonitorElement * jetPt_
edm::ParameterSet conf_
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
ESHandle< TrackerGeometry > geometry
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, const uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE", const bool resetMEsAfterWriting=false)
Definition: DQMStore.cc:2562
MonitorElement * minTrackDeltaR_
virtual const DetIdContainer & detUnitIds() const
Returm a vector of all GeomDetUnit DetIds.
DetId geographicalId() const
bool isValid() const
Definition: ESHandle.h:47
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1099
edm::EDGetTokenT< reco::TrackCollection > referenceTrackProducer_
MonitorElement * TrackPtPositive_
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:684
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
TkAlCaRecoMonitor(const edm::ParameterSet &)
virtual const TrackerGeomDet * idToDet(DetId) const
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:109