00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef RecoTOA_H
00010 #define RecoTOA_H
00011
00012
00013 #include <iostream>
00014 #include <map>
00015 #include <memory>
00016 #include <string>
00017 #include <vector>
00018
00019
00020 #include "TFile.h"
00021 #include "TH1D.h"
00022
00023 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00024 #include "DataFormats/VertexReco/interface/Vertex.h"
00025
00026 #include "FWCore/Framework/interface/Frameworkfwd.h"
00027 #include "FWCore/Framework/interface/EDAnalyzer.h"
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/ESHandle.h"
00030 #include "FWCore/Framework/interface/EventSetup.h"
00031 #include "FWCore/Framework/interface/MakerMacros.h"
00032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00033
00034 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00035 #include "SimTracker/TrackHistory/interface/TrackHistory.h"
00036
00037
00038
00039
00040
00041 class RecoTOA : public edm::EDAnalyzer
00042 {
00043
00044 public:
00045
00046 explicit RecoTOA(const edm::ParameterSet&);
00047 ~RecoTOA();
00048
00049 private:
00050
00051 virtual void beginJob(const edm::EventSetup&) ;
00052 virtual void analyze(const edm::Event&, const edm::EventSetup&);
00053 virtual void endJob();
00054
00055
00056
00057 typedef std::set<int> sint;
00058 typedef std::vector<double> vdouble;
00059 typedef std::vector<std::string> vstring;
00060 typedef std::vector<vstring> vvstring;
00061 typedef std::vector<edm::ParameterSet> vParameterSet;
00062
00063 edm::InputTag trackProducer_;
00064
00065 std::string rootFile_;
00066 bool antiparticles_;
00067 bool status_;
00068
00069 vvstring vetoList_;
00070
00071 TrackHistory tracer_;
00072
00073
00074
00075 struct counter_info_t
00076 {
00077 int pdgId;
00078 int tracks;
00079
00080 counter_info_t(int pdgId_, int tracks_)
00081 {
00082 pdgId = pdgId_;
00083 tracks = tracks_;
00084 }
00085
00086 bool operator< (const counter_info_t & i) const
00087 {
00088 if (pdgId < i.pdgId)
00089 return true;
00090 else if (pdgId > i.pdgId)
00091 return false;
00092
00093 if (tracks < i.tracks)
00094 return true;
00095
00096 return false;
00097 }
00098 };
00099
00100 typedef std::map<int,int> counter_index_t;
00101 typedef std::pair<int,int> counter_index_pair_t;
00102
00103 typedef std::map<int,std::size_t> counter_buffer_t;
00104 typedef std::pair<int,std::size_t> counter_buffer_pair_t;
00105
00106 typedef std::map<counter_info_t,std::size_t> counter_t;
00107 typedef std::pair<counter_info_t,std::size_t> counter_pair_t;
00108
00109 counter_t counter_;
00110 counter_index_t counter_index_;
00111 counter_buffer_t counter_buffer_;
00112
00113 edm::ESHandle<HepPDT::ParticleDataTable> pdt_;
00114
00115 void InitCounter();
00116 void UpdateCounter();
00117 void Count(int barcode=0,int pdgId=0);
00118
00119 };
00120
00121
00122 RecoTOA::RecoTOA(const edm::ParameterSet& config) : tracer_(config)
00123 {
00124 trackProducer_ = config.getUntrackedParameter<edm::InputTag> ( "trackProducer" );
00125
00126 rootFile_ = config.getUntrackedParameter<std::string> ( "rootFile" );
00127
00128 antiparticles_ = config.getUntrackedParameter<bool> ( "antiparticles" );
00129
00130 status_ = config.getUntrackedParameter<bool> ( "status2" );
00131
00132 edm::ParameterSet pset = config.getUntrackedParameter<edm::ParameterSet> ( "veto" );
00133
00134 vstring vetoListNames = pset.getParameterNames();
00135
00136 vetoList_.reserve(vetoListNames.size());
00137
00138 for (std::size_t i=0; i < vetoListNames.size(); i++)
00139 vetoList_.push_back(pset.getUntrackedParameter<vstring> (vetoListNames[i]));
00140 }
00141
00142 RecoTOA::~RecoTOA() { }
00143
00144 void
00145 RecoTOA::analyze(const edm::Event& event, const edm::EventSetup& setup)
00146 {
00147
00148 edm::Handle<edm::View<reco::Track> > trackCollection;
00149
00150 event.getByLabel(trackProducer_,trackCollection);
00151
00152
00153 if (status_)
00154 tracer_.depth(-2);
00155 else
00156 tracer_.depth(-1);
00157
00158
00159 tracer_.newEvent(event, setup);
00160
00161
00162 InitCounter();
00163
00164
00165 for (std::size_t index = 0; index < trackCollection->size(); index++)
00166 {
00167
00168 if ( tracer_.evaluate( edm::RefToBase<reco::Track>(trackCollection, index) ))
00169 {
00170
00171 const HepMC::GenParticle * particle = tracer_.genParticle();
00172
00173 if (particle)
00174 Count(particle->barcode(), particle->pdg_id());
00175 }
00176 else
00177 Count(0,0);
00178 }
00179 UpdateCounter();
00180 }
00181
00182
00183 void
00184 RecoTOA::beginJob(const edm::EventSetup& setup)
00185 {
00186
00187 setup.getData( pdt_ );
00188 }
00189
00190
00191 void
00192 RecoTOA::endJob()
00193 {
00194 TFile file(rootFile_.c_str(), "RECREATE");
00195 file.cd();
00196
00197 double vetoedVals;
00198 double totalVals;
00199
00200 std::cout << "List of all long lived particle found" << std::endl;
00201 for ( counter_t::iterator it = counter_.begin(); it != counter_.end(); it++)
00202 {
00203 if ( !it->first.pdgId )
00204 std::cout << " fake tracks -> " << it->second << std::endl;
00205 else
00206 std::cout << " particle " <<pdt_->particle(HepPDT::ParticleID(it->first.pdgId))->name();
00207 std::cout << " associated to " << it->first.tracks << " tracks -> " << it->second << std::endl;
00208 }
00209
00210 std::multimap<double, std::string> particleTypes;
00211
00212 for (std::size_t cid = 0; cid < vetoList_.size(); cid++)
00213 {
00214 particleTypes.clear();
00215 vetoedVals = 0;
00216 totalVals = 0;
00217
00218 for (counter_t::iterator it = counter_.begin(); it != counter_.end(); it++)
00219 {
00220 std::ostringstream particle;
00221
00222 if ( !it->first.pdgId )
00223 particle << "Fake" << std::endl;
00224 else
00225 particle << pdt_->particle(HepPDT::ParticleID(it->first.pdgId))->name();
00226
00227 if (
00228 std::find (
00229 vetoList_[cid].begin(),
00230 vetoList_[cid].end(),
00231 particle.str()
00232 ) == vetoList_[cid].end()
00233 )
00234 {
00235 particle << "#" << it->first.tracks;
00236 particleTypes.insert(std::pair<double,std::string>(it->second, particle.str()));
00237 totalVals += it->second;
00238 }
00239 else
00240 {
00241 vetoedVals += it->second;
00242 totalVals += it->second;
00243 }
00244 }
00245
00246 std::cout << "Veto list #" << cid << std::endl;
00247 std::cout << " number of vetoed tracks " << vetoedVals << std::endl;
00248 std::cout << " total number of tracks " << totalVals << std::endl;
00249 std::cout << " % of vetoed tracks " << ((vetoedVals/totalVals) * 100) << std::endl;
00250
00251 std::ostringstream hName, hTitle;
00252
00253 hTitle << "Track origins for the whole track collection";
00254 hName << "recoTrackCollection";
00255
00256 for (std::size_t v=0; v < vetoList_[cid].size(); v++)
00257 {
00258 hTitle << "_" << vetoList_[cid][v];
00259 hName << "_" << vetoList_[cid][v];
00260 }
00261
00262
00263 TH1D histogram(
00264 hName.str().c_str(),
00265 hTitle.str().c_str(),
00266 particleTypes.size(),
00267 0.,
00268 Double_t(particleTypes.size())
00269 );
00270
00271 int i = 1;
00272
00273 std::cout << "Particle size " << particleTypes.size() << std::endl;
00274
00275 std::map<double, std::string>::const_iterator it;
00276
00277 for (it = particleTypes.begin(); it != particleTypes.end(); it++, i++)
00278 {
00279 histogram.GetXaxis()->SetBinLabel(i, it->second.c_str());
00280 histogram.SetBinContent(i, Double_t(it->first));
00281 }
00282
00283 histogram.Write();
00284 file.Flush();
00285 }
00286 }
00287
00288
00289 void RecoTOA::InitCounter()
00290 {
00291 counter_buffer_.clear();
00292 counter_index_.clear();
00293 }
00294
00295
00296 void RecoTOA::Count(int barcode, int pdgId)
00297 {
00298 counter_buffer_t::iterator it = counter_buffer_.find(barcode);
00299
00300 if ( it != counter_buffer_.end() )
00301 {
00302 it->second++;
00303 }
00304 else
00305 {
00306 counter_buffer_.insert( counter_buffer_pair_t(barcode, 1) );
00307 counter_index_.insert( counter_index_pair_t(barcode, pdgId) );
00308 }
00309 }
00310
00311
00312 void RecoTOA::UpdateCounter()
00313 {
00314 counter_buffer_t::const_iterator csi = counter_buffer_.begin();
00315
00316 std::size_t particleType;
00317
00318 for (; csi != counter_buffer_.end(); csi++)
00319 {
00320 if (antiparticles_)
00321 particleType = counter_index_[csi->first];
00322 else
00323 particleType = abs(counter_index_[csi->first]);
00324 if ( !particleType )
00325 {
00326 counter_info_t info (particleType, 1);
00327 counter_t::iterator ci = counter_.find( info );
00328 if ( ci != counter_.end() )
00329 ci->second += csi->second;
00330 else
00331 counter_.insert( counter_pair_t (info, csi->second) );
00332 }
00333 else
00334 {
00335 counter_info_t info = counter_info_t (particleType, csi->second);
00336 counter_t::iterator ci = counter_.find( info );
00337 if ( ci != counter_.end() )
00338 ci->second++;
00339 else
00340 counter_.insert( counter_pair_t (info, 1) );
00341 }
00342 }
00343 }
00344
00345
00346 DEFINE_FWK_MODULE(RecoTOA);
00347
00348 #endif