test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::iter0)myalgo=4;
166  if(track->algo()==reco::TrackBase::iter1)myalgo=5;
167  if(track->algo()==reco::TrackBase::iter2)myalgo=6;
168  if(track->algo()==reco::TrackBase::iter3)myalgo=7;
169  if(track->algo()==reco::TrackBase::iter4)myalgo=8;
170  if(track->algo()==reco::TrackBase::iter5)myalgo=9;
171  if(track->algo()==reco::TrackBase::iter6)myalgo=10;
172  if(track->algo()==reco::TrackBase::iter7)myalgo=11;
173  trkAlgo_[nTracks_] = myalgo;
174 
175  int myquality=-99;
176  if(track->quality(reco::TrackBase::undefQuality))myquality=-1;
177  if(track->quality(reco::TrackBase::loose))myquality=0;
178  if(track->quality(reco::TrackBase::tight))myquality=1;
179  if(track->quality(reco::TrackBase::highPurity))myquality=2;
180  //if(track->quality(reco::TrackBase::confirmed))myquality=3;
181  // if(track->quality(reco::TrackBase::goodIterative))myquality=4;
182  // if(track->quality(reco::TrackBase::qualitySize))myquality=5;
183  trkQuality_[nTracks_]= myquality;
184 
185  if(track->quality(reco::TrackBase::highPurity))isHighPurity_[nTracks_]=1;
186  else isHighPurity_[nTracks_]=0;
187  nTracks_++;
188 
189 
190 
191 
192 
193  }//end loop on tracks
194 
195  for(int d=0;d<nTracks_;++d){
196  if(abs(trkQuality_[d])>5)cout<<"MYQUALITY!!! " <<trkQuality_[d] <<" at track # "<<d<<"/"<< nTracks_<<endl;
197  }
198 
199 
200 
201 
202  rootTree_->Fill();
203 }
204 
205 
206 // ------------ method called once each job before begining the event loop ------------
208 {
209  edm::LogInfo("beginJob") << "Begin Job" << std::endl;
210  // Define TTree for output
211  rootFile_ = new TFile(filename_.c_str(),"recreate");
212  rootTree_ = new TTree("tree","Lhc Track tree");
213 
214  // Track Paramters
215  rootTree_->Branch("run",&run_,"run/I");
216  rootTree_->Branch("event",&event_,"event/I");
217  rootTree_->Branch("goodbx",&goodbx_,"goodbx/O");
218  rootTree_->Branch("goodvtx",&goodvtx_,"goodvtx/O");
219  rootTree_->Branch("nTracks",&nTracks_,"nTracks/I");
220  rootTree_->Branch("pt",&pt_,"pt[nTracks]/D");
221  rootTree_->Branch("eta",&eta_,"eta[nTracks]/D");
222  rootTree_->Branch("phi",&phi_,"phi[nTracks]/D");
223  rootTree_->Branch("chi2",&chi2_,"chi2[nTracks]/D");
224  rootTree_->Branch("chi2ndof",&chi2ndof_,"chi2ndof[nTracks]/D");
225  rootTree_->Branch("charge",&charge_,"charge[nTracks]/I");
226  rootTree_->Branch("qoverp",&qoverp_,"qoverp[nTracks]/D");
227  rootTree_->Branch("dz",&dz_,"dz[nTracks]/D");
228  rootTree_->Branch("dxy",&dxy_,"dxy[nTracks]/D");
229  rootTree_->Branch("xPCA",&xPCA_,"xPCA[nTracks]/D");
230  rootTree_->Branch("yPCA",&yPCA_,"yPCA[nTracks]/D");
231  rootTree_->Branch("zPCA",&zPCA_,"zPCA[nTracks]/D");
232  rootTree_->Branch("isHighPurity",&isHighPurity_,"isHighPurity[nTracks]/I");
233  rootTree_->Branch("trkQuality",&trkQuality_,"trkQuality[nTracks]/I");
234  rootTree_->Branch("trkAlgo",&trkAlgo_,"trkAlgo[nTracks]/I");
235  rootTree_->Branch("nValidHits",&validhits_,"nValidHits[nTracks][7]/I");
236 
237 
238 }
239 
240 // ------------ method called once each job just after ending the event loop ------------
242 {
243  if ( rootFile_ ) {
244  rootFile_->Write();
245  rootFile_->Close();
246  }
247 
248 
249 
250 }
251 
253  run_=-1;
254  event_=-99;
255  nTracks_ = 0;
256  for ( int i=0; i<nMaxtracks_; ++i ) {
257  pt_[i] = 0;
258  eta_[i] = 0;
259  phi_[i] = 0;
260  chi2_[i] = 0;
261  chi2ndof_[i] = 0;
262  charge_[i] = 0;
263  qoverp_[i] = 0;
264  dz_[i] = 0;
265  dxy_[i] = 0;
266  xPCA_[i] = 0;
267  yPCA_[i] = 0;
268  zPCA_[i] = 0;
269  trkQuality_[i] = 0;
270  trkAlgo_[i] = -1;
271  isHighPurity_[i]=-3;
272  for(int j=0;j<7;j++){
273  validhits_[nTracks_][j]=-1*j;
274  }
275  }
276 
277 
278 }
279 
280 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:42
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
int i
Definition: DBlmapReader.cc:9
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_]
virtual void endJob()
double eta_[nMaxtracks_]
int iEvent
Definition: GenABIO.cc:230
virtual void beginJob()
std::string filename_
double phi_[nMaxtracks_]
double chi2ndof_[nMaxtracks_]
double yPCA_[nMaxtracks_]
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
double dxy_[nMaxtracks_]
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
int trkAlgo_[nMaxtracks_]
edm::InputTag PVtxCollectionTag_
virtual void analyze(const edm::Event &, const edm::EventSetup &)
double xPCA_[nMaxtracks_]
edm::EventID id() const
Definition: EventBase.h:56
static const int nMaxtracks_
double chi2_[nMaxtracks_]
int charge_[nMaxtracks_]
tuple cout
Definition: gather_cfg.py:121
LhcTrackAnalyzer(const edm::ParameterSet &)
double pt_[nMaxtracks_]