CMS 3D CMS Logo

LhcTrackAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: LhcTrackAnalyzer
4 // Class: LhcTrackAnalyzer
5 //
16 //
17 
18 // updated to 25/2/2009 5.30 pm
19 
20 //
21 //
22 
23 // system include files
24 #include <memory>
25 
26 // user include files
30 
35 
37 
38 #include "TH1F.h"
39 #include "TH2F.h"
40 #include "TFile.h"
41 #include "TROOT.h"
42 #include "TChain.h"
43 #include "TNtuple.h"
53 
58 
59 // Constructor
60 
62 
63 {
64  //now do what ever initialization is needed
65  debug_ = iConfig.getParameter<bool>("Debug");
66  TrackCollectionTag_ = iConfig.getParameter<edm::InputTag>("TrackCollectionTag");
67  PVtxCollectionTag_ = iConfig.getParameter<edm::InputTag>("PVtxCollectionTag");
68  filename_ = iConfig.getParameter<std::string>("OutputFileName");
69 }
70 
71 // Destructor
73  // do anything here that needs to be done at desctruction time
74  // (e.g. close files, deallocate resources etc.)
75 }
76 
77 //
78 // member functions
79 //
80 
81 // ------------ method called to for each event ------------
83  using namespace edm;
84  using namespace reco;
85  using namespace std;
86 
87  //=======================================================
88  // Initialize Root-tuple variables
89  //=======================================================
90 
91  SetVarToZero();
92 
93  //=======================================================
94  // Retrieve the Track information
95  //=======================================================
96 
97  Handle<TrackCollection> trackCollectionHandle;
98  iEvent.getByLabel(TrackCollectionTag_, trackCollectionHandle);
99  Handle<VertexCollection> vertexCollectionHandle;
100  iEvent.getByLabel(PVtxCollectionTag_, vertexCollectionHandle);
101  for (VertexCollection::const_iterator vtx = vertexCollectionHandle->begin(); vtx != vertexCollectionHandle->end();
102  ++vtx) {
103  if (vtx == vertexCollectionHandle->begin()) {
104  if (vtx->isFake())
105  goodvtx_ = false;
106  else
107  goodvtx_ = true;
108  } else
109  break;
110  }
111 
112  goodbx_ = true;
113  // int bx = iEvent.bunchCrossing();
114  //if (bx==51 || bx==2724) goodbx_=true;
115 
116  run_ = iEvent.id().run();
117  event_ = iEvent.id().event();
118 
119  if (debug_)
120  cout << "LhcTrackAnalyzer::analyze() looping over " << trackCollectionHandle->size() << "tracks." << endl;
121 
122  // unsigned int i = 0;
123  for (TrackCollection::const_iterator track = trackCollectionHandle->begin(); track != trackCollectionHandle->end();
124  ++track) {
125  if (nTracks_ >= nMaxtracks_) {
126  std::cout << " LhcTrackAnalyzer::analyze() : Warning - Run " << run_ << " Event " << event_
127  << "\tNumber of tracks: " << trackCollectionHandle->size() << " , greater than " << nMaxtracks_
128  << std::endl;
129  continue;
130  }
131  pt_[nTracks_] = track->pt();
132  eta_[nTracks_] = track->eta();
133  phi_[nTracks_] = track->phi();
134  chi2_[nTracks_] = track->chi2();
135  chi2ndof_[nTracks_] = track->normalizedChi2();
136  charge_[nTracks_] = track->charge();
137  qoverp_[nTracks_] = track->qoverp();
138  dz_[nTracks_] = track->dz();
139  dxy_[nTracks_] = track->dxy();
140  xPCA_[nTracks_] = track->vertex().x();
141  yPCA_[nTracks_] = track->vertex().y();
142  zPCA_[nTracks_] = track->vertex().z();
143  validhits_[nTracks_][0] = track->numberOfValidHits();
144  validhits_[nTracks_][1] = track->hitPattern().numberOfValidPixelBarrelHits();
145  validhits_[nTracks_][2] = track->hitPattern().numberOfValidPixelEndcapHits();
146  validhits_[nTracks_][3] = track->hitPattern().numberOfValidStripTIBHits();
147  validhits_[nTracks_][4] = track->hitPattern().numberOfValidStripTIDHits();
148  validhits_[nTracks_][5] = track->hitPattern().numberOfValidStripTOBHits();
149  validhits_[nTracks_][6] = track->hitPattern().numberOfValidStripTECHits();
150 
151  int myalgo = -88;
152  if (track->algo() == reco::TrackBase::undefAlgorithm)
153  myalgo = 0;
154  if (track->algo() == reco::TrackBase::ctf)
155  myalgo = 1;
156  if (track->algo() == reco::TrackBase::initialStep)
157  myalgo = 4;
159  myalgo = 5;
160  if (track->algo() == reco::TrackBase::pixelPairStep)
161  myalgo = 6;
163  myalgo = 7;
165  myalgo = 8;
166  if (track->algo() == reco::TrackBase::pixelLessStep)
167  myalgo = 9;
168  if (track->algo() == reco::TrackBase::tobTecStep)
169  myalgo = 10;
171  myalgo = 11;
172  // This class is pending the migration to Phase1 tracks
175  throw cms::Exception("Not implemented")
176  << "LhcTrackAnalyzer does not yet support phase1 tracks, encountered one from algo "
177  << reco::TrackBase::algoName(track->algo());
178  }
179  trkAlgo_[nTracks_] = myalgo;
180 
181  int myquality = -99;
182  if (track->quality(reco::TrackBase::undefQuality))
183  myquality = -1;
184  if (track->quality(reco::TrackBase::loose))
185  myquality = 0;
186  if (track->quality(reco::TrackBase::tight))
187  myquality = 1;
188  if (track->quality(reco::TrackBase::highPurity))
189  myquality = 2;
190  //if(track->quality(reco::TrackBase::confirmed))myquality=3;
191  // if(track->quality(reco::TrackBase::goodIterative))myquality=4;
192  // if(track->quality(reco::TrackBase::qualitySize))myquality=5;
193  trkQuality_[nTracks_] = myquality;
194 
195  if (track->quality(reco::TrackBase::highPurity))
196  isHighPurity_[nTracks_] = 1;
197  else
198  isHighPurity_[nTracks_] = 0;
199  nTracks_++;
200 
201  } //end loop on tracks
202 
203  for (int d = 0; d < nTracks_; ++d) {
204  if (abs(trkQuality_[d]) > 5)
205  cout << "MYQUALITY!!! " << trkQuality_[d] << " at track # " << d << "/" << nTracks_ << endl;
206  }
207 
208  rootTree_->Fill();
209 }
210 
211 // ------------ method called once each job before begining the event loop ------------
213  edm::LogInfo("beginJob") << "Begin Job" << std::endl;
214  // Define TTree for output
215  rootFile_ = new TFile(filename_.c_str(), "recreate");
216  rootTree_ = new TTree("tree", "Lhc Track tree");
217 
218  // Track Paramters
219  rootTree_->Branch("run", &run_, "run/I");
220  rootTree_->Branch("event", &event_, "event/I");
221  rootTree_->Branch("goodbx", &goodbx_, "goodbx/O");
222  rootTree_->Branch("goodvtx", &goodvtx_, "goodvtx/O");
223  rootTree_->Branch("nTracks", &nTracks_, "nTracks/I");
224  rootTree_->Branch("pt", &pt_, "pt[nTracks]/D");
225  rootTree_->Branch("eta", &eta_, "eta[nTracks]/D");
226  rootTree_->Branch("phi", &phi_, "phi[nTracks]/D");
227  rootTree_->Branch("chi2", &chi2_, "chi2[nTracks]/D");
228  rootTree_->Branch("chi2ndof", &chi2ndof_, "chi2ndof[nTracks]/D");
229  rootTree_->Branch("charge", &charge_, "charge[nTracks]/I");
230  rootTree_->Branch("qoverp", &qoverp_, "qoverp[nTracks]/D");
231  rootTree_->Branch("dz", &dz_, "dz[nTracks]/D");
232  rootTree_->Branch("dxy", &dxy_, "dxy[nTracks]/D");
233  rootTree_->Branch("xPCA", &xPCA_, "xPCA[nTracks]/D");
234  rootTree_->Branch("yPCA", &yPCA_, "yPCA[nTracks]/D");
235  rootTree_->Branch("zPCA", &zPCA_, "zPCA[nTracks]/D");
236  rootTree_->Branch("isHighPurity", &isHighPurity_, "isHighPurity[nTracks]/I");
237  rootTree_->Branch("trkQuality", &trkQuality_, "trkQuality[nTracks]/I");
238  rootTree_->Branch("trkAlgo", &trkAlgo_, "trkAlgo[nTracks]/I");
239  rootTree_->Branch("nValidHits", &validhits_, "nValidHits[nTracks][7]/I");
240 }
241 
242 // ------------ method called once each job just after ending the event loop ------------
244  if (rootFile_) {
245  rootFile_->Write();
246  rootFile_->Close();
247  }
248 }
249 
251  run_ = -1;
252  event_ = -99;
253  nTracks_ = 0;
254  for (int i = 0; i < nMaxtracks_; ++i) {
255  pt_[i] = 0;
256  eta_[i] = 0;
257  phi_[i] = 0;
258  chi2_[i] = 0;
259  chi2ndof_[i] = 0;
260  charge_[i] = 0;
261  qoverp_[i] = 0;
262  dz_[i] = 0;
263  dxy_[i] = 0;
264  xPCA_[i] = 0;
265  yPCA_[i] = 0;
266  zPCA_[i] = 0;
267  trkQuality_[i] = 0;
268  trkAlgo_[i] = -1;
269  isHighPurity_[i] = -3;
270  for (int j = 0; j < 7; j++) {
271  validhits_[nTracks_][j] = -1 * j;
272  }
273  }
274 }
275 
276 //define this as a plug-in
LhcTrackAnalyzer::debug_
bool debug_
Definition: LhcTrackAnalyzer.h:66
LhcTrackAnalyzer
Definition: LhcTrackAnalyzer.h:53
LhcTrackAnalyzer::qoverp_
double qoverp_[nMaxtracks_]
Definition: LhcTrackAnalyzer.h:87
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11724
reco::TrackBase::tight
Definition: TrackBase.h:153
TrackerGeometry.h
reco::TrackBase::loose
Definition: TrackBase.h:152
ESHandle.h
reco::TrackBase::detachedQuadStep
Definition: TrackBase.h:115
reco::TrackBase::lowPtQuadStep
Definition: TrackBase.h:114
LhcTrackAnalyzer::isHighPurity_
int isHighPurity_[nMaxtracks_]
Definition: LhcTrackAnalyzer.h:95
LhcTrackAnalyzer::charge_
int charge_[nMaxtracks_]
Definition: LhcTrackAnalyzer.h:86
LhcTrackAnalyzer::zPCA_
double zPCA_[nMaxtracks_]
Definition: LhcTrackAnalyzer.h:92
LhcTrackAnalyzer::eta_
double eta_[nMaxtracks_]
Definition: LhcTrackAnalyzer.h:82
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::TrackBase::undefQuality
Definition: TrackBase.h:151
LhcTrackAnalyzer::goodvtx_
bool goodvtx_
Definition: LhcTrackAnalyzer.h:98
gather_cfg.cout
cout
Definition: gather_cfg.py:144
LhcTrackAnalyzer::trkQuality_
int trkQuality_[nMaxtracks_]
Definition: LhcTrackAnalyzer.h:94
reco::TrackBase::lowPtTripletStep
Definition: TrackBase.h:95
LhcTrackAnalyzer::rootFile_
TFile * rootFile_
Definition: LhcTrackAnalyzer.h:70
LhcTrackAnalyzer::chi2_
double chi2_[nMaxtracks_]
Definition: LhcTrackAnalyzer.h:84
EDAnalyzer.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
LhcTrackAnalyzer::~LhcTrackAnalyzer
~LhcTrackAnalyzer() override
Definition: LhcTrackAnalyzer.cc:72
edm::Handle
Definition: AssociativeIterator.h:50
LhcTrackAnalyzer::beginJob
void beginJob() override
Definition: LhcTrackAnalyzer.cc:212
reco::TrackBase::mixedTripletStep
Definition: TrackBase.h:98
LhcTrackAnalyzer::goodbx_
bool goodbx_
Definition: LhcTrackAnalyzer.h:97
MakerMacros.h
LhcTrackAnalyzer::yPCA_
double yPCA_[nMaxtracks_]
Definition: LhcTrackAnalyzer.h:91
Track.h
LhcTrackAnalyzer::endJob
void endJob() override
Definition: LhcTrackAnalyzer.cc:243
TrackFwd.h
LhcTrackAnalyzer::nTracks_
int nTracks_
Definition: LhcTrackAnalyzer.h:78
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
reco::TrackBase::jetCoreRegionalStep
Definition: TrackBase.h:101
Surface.h
LhcTrackAnalyzer::chi2ndof_
double chi2ndof_[nMaxtracks_]
Definition: LhcTrackAnalyzer.h:85
LhcTrackAnalyzer::filename_
std::string filename_
Definition: LhcTrackAnalyzer.h:69
Service.h
GloballyPositioned.h
IdealMagneticFieldRecord.h
LhcTrackAnalyzer::phi_
double phi_[nMaxtracks_]
Definition: LhcTrackAnalyzer.h:83
reco::TrackBase::algoName
std::string algoName() const
Definition: TrackBase.h:550
LhcTrackAnalyzer::nMaxtracks_
static const int nMaxtracks_
Definition: LhcTrackAnalyzer.h:77
LhcTrackAnalyzer::dz_
double dz_[nMaxtracks_]
Definition: LhcTrackAnalyzer.h:88
TFileService.h
LhcTrackAnalyzer::TrackCollectionTag_
edm::InputTag TrackCollectionTag_
Definition: LhcTrackAnalyzer.h:64
TrackerDigiGeometryRecord.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
LhcTrackAnalyzer::LhcTrackAnalyzer
LhcTrackAnalyzer(const edm::ParameterSet &)
Definition: LhcTrackAnalyzer.cc:61
reco::TrackBase::detachedTripletStep
Definition: TrackBase.h:97
LhcTrackAnalyzer::dxy_
double dxy_[nMaxtracks_]
Definition: LhcTrackAnalyzer.h:89
LhcTrackAnalyzer::run_
int run_
Definition: LhcTrackAnalyzer.h:79
reco::TrackBase::undefAlgorithm
Definition: TrackBase.h:90
iEvent
int iEvent
Definition: GenABIO.cc:224
MagneticField.h
LhcTrackAnalyzer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: LhcTrackAnalyzer.cc:82
reco::TrackBase::initialStep
Definition: TrackBase.h:94
edm::EventSetup
Definition: EventSetup.h:58
reco::TrackBase::tobTecStep
Definition: TrackBase.h:100
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
LhcTrackAnalyzer::validhits_
int validhits_[nMaxtracks_][7]
Definition: LhcTrackAnalyzer.h:96
reco::TrackBase::pixelPairStep
Definition: TrackBase.h:96
VertexFwd.h
GeomDet.h
reco::TrackBase::ctf
Definition: TrackBase.h:91
LhcTrackAnalyzer::rootTree_
TTree * rootTree_
Definition: LhcTrackAnalyzer.h:71
LhcTrackAnalyzer::xPCA_
double xPCA_[nMaxtracks_]
Definition: LhcTrackAnalyzer.h:90
reco::TrackBase::highPtTripletStep
Definition: TrackBase.h:113
std
Definition: JetResolutionObject.h:76
LhcTrackAnalyzer::trkAlgo_
int trkAlgo_[nMaxtracks_]
Definition: LhcTrackAnalyzer.h:93
extraflags_cff.vtx
vtx
Definition: extraflags_cff.py:19
Vertex.h
Frameworkfwd.h
Exception
Definition: hltDiff.cc:245
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ztail.d
d
Definition: ztail.py:151
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
LhcTrackAnalyzer.h
LhcTrackAnalyzer::pt_
double pt_[nMaxtracks_]
Definition: LhcTrackAnalyzer.h:81
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
LhcTrackAnalyzer::PVtxCollectionTag_
edm::InputTag PVtxCollectionTag_
Definition: LhcTrackAnalyzer.h:65
edm::Event
Definition: Event.h:73
reco::TrackBase::pixelLessStep
Definition: TrackBase.h:99
edm::InputTag
Definition: InputTag.h:15
LhcTrackAnalyzer::event_
int event_
Definition: LhcTrackAnalyzer.h:80
EncodedEventId.h
reco::TrackBase::highPurity
Definition: TrackBase.h:154
LhcTrackAnalyzer::SetVarToZero
void SetVarToZero()
Definition: LhcTrackAnalyzer.cc:250