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
RunNumber_t run() const
Definition: EventID.h:38
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:40
int validhits_[nMaxtracks_][7]
int isHighPurity_[nMaxtracks_]
double dz_[nMaxtracks_]
double zPCA_[nMaxtracks_]
edm::InputTag TrackCollectionTag_
int trkQuality_[nMaxtracks_]
double qoverp_[nMaxtracks_]
double eta_[nMaxtracks_]
void endJob() override
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::string filename_
double phi_[nMaxtracks_]
double chi2ndof_[nMaxtracks_]
double yPCA_[nMaxtracks_]
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double dxy_[nMaxtracks_]
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:488
d
Definition: ztail.py:151
~LhcTrackAnalyzer() override
int trkAlgo_[nMaxtracks_]
edm::InputTag PVtxCollectionTag_
std::string algoName() const
Definition: TrackBase.h:529
double xPCA_[nMaxtracks_]
edm::EventID id() const
Definition: EventBase.h:59
fixed size matrix
HLT enums.
static const int nMaxtracks_
double chi2_[nMaxtracks_]
int charge_[nMaxtracks_]
LhcTrackAnalyzer(const edm::ParameterSet &)
double pt_[nMaxtracks_]
void beginJob() override
void analyze(const edm::Event &, const edm::EventSetup &) override