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