CMS 3D CMS Logo

TruthTOA Class Reference

Inheritance diagram for TruthTOA:

edm::EDAnalyzer

List of all members.

Public Member Functions

 TruthTOA (const edm::ParameterSet &)
 ~TruthTOA ()

Private Types

typedef std::pair< int,
std::size_t > 
counter_buffer_pair_t
typedef std::map< int,
std::size_t > 
counter_buffer_t
typedef std::pair< int, intcounter_index_pair_t
typedef std::map< int, intcounter_index_t
typedef std::pair
< counter_info_t, std::size_t > 
counter_pair_t
typedef std::map
< counter_info_t, std::size_t > 
counter_t
typedef std::set< intsint
typedef std::vector< double > vdouble
typedef std::vector
< edm::ParameterSet
vParameterSet
typedef std::vector< std::string > vstring
typedef std::vector< vstringvvstring

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
virtual void beginJob (const edm::EventSetup &)
void Count (int barcode=0, int pdgId=0)
virtual void endJob ()
void InitCounter ()
void UpdateCounter ()

Private Attributes

bool antiparticles_
counter_t counter_
counter_buffer_t counter_buffer_
counter_index_t counter_index_
int matchedHits_
edm::ESHandle< ParticleDataTablepdt_
std::string rootFile_
bool status_
TrackHistory tracer_
edm::InputTag trackingTruth_
vvstring vetoList_

Classes

struct  counter_info_t


Detailed Description

Definition at line 39 of file TruthTOA.cc.


Member Typedef Documentation

typedef std::pair<int,std::size_t> TruthTOA::counter_buffer_pair_t [private]

Definition at line 103 of file TruthTOA.cc.

typedef std::map<int,std::size_t> TruthTOA::counter_buffer_t [private]

Definition at line 102 of file TruthTOA.cc.

typedef std::pair<int,int> TruthTOA::counter_index_pair_t [private]

Definition at line 100 of file TruthTOA.cc.

typedef std::map<int,int> TruthTOA::counter_index_t [private]

Definition at line 99 of file TruthTOA.cc.

typedef std::pair<counter_info_t,std::size_t> TruthTOA::counter_pair_t [private]

Definition at line 106 of file TruthTOA.cc.

typedef std::map<counter_info_t,std::size_t> TruthTOA::counter_t [private]

Definition at line 105 of file TruthTOA.cc.

typedef std::set<int> TruthTOA::sint [private]

Definition at line 57 of file TruthTOA.cc.

typedef std::vector<double> TruthTOA::vdouble [private]

Definition at line 58 of file TruthTOA.cc.

typedef std::vector<edm::ParameterSet> TruthTOA::vParameterSet [private]

Definition at line 61 of file TruthTOA.cc.

typedef std::vector<std::string> TruthTOA::vstring [private]

Definition at line 59 of file TruthTOA.cc.

typedef std::vector<vstring> TruthTOA::vvstring [private]

Definition at line 60 of file TruthTOA.cc.


Constructor & Destructor Documentation

TruthTOA::TruthTOA ( const edm::ParameterSet config  )  [explicit]

Definition at line 121 of file TruthTOA.cc.

References antiparticles_, edm::ParameterSet::getUntrackedParameter(), i, matchedHits_, python::EventAnalyzer_cfg::pset, rootFile_, status_, trackingTruth_, and vetoList_.

00121                                                 : tracer_(config)
00122 {
00123     trackingTruth_ = config.getUntrackedParameter<edm::InputTag> ( "trackingTruth" );
00124 
00125     matchedHits_ = config.getUntrackedParameter<int> ( "matchedHits" );
00126 
00127     rootFile_ = config.getUntrackedParameter<std::string> ( "rootFile" );
00128 
00129     antiparticles_ = config.getUntrackedParameter<bool> ( "antiparticles" );
00130 
00131     status_ = config.getUntrackedParameter<bool> ( "status2" );
00132 
00133     edm::ParameterSet pset = config.getUntrackedParameter<edm::ParameterSet> ( "veto" );
00134 
00135     vstring vetoListNames = pset.getParameterNames();
00136 
00137     vetoList_.reserve(vetoListNames.size());
00138 
00139     for (std::size_t i=0; i < vetoListNames.size(); i++)
00140         vetoList_.push_back(pset.getUntrackedParameter<vstring> (vetoListNames[i]));
00141 }

TruthTOA::~TruthTOA (  ) 

Definition at line 144 of file TruthTOA.cc.

00144 { }


Member Function Documentation

void TruthTOA::analyze ( const edm::Event event,
const edm::EventSetup setup 
) [private, virtual]

Implements edm::EDAnalyzer.

Definition at line 148 of file TruthTOA.cc.

References Count(), TrackHistory::depth(), TrackHistory::evaluate(), TrackHistory::genParticle(), index, InitCounter(), matchedHits_, status_, tracer_, track, trackingTruth_, and UpdateCounter().

00149 {
00150     // Tracking particle information
00151     edm::Handle<TrackingParticleCollection>  TPCollection;
00152     event.getByLabel(trackingTruth_, TPCollection);
00153 
00154     // Set the history depth
00155     if (status_)
00156         tracer_.depth(-2);
00157     else
00158         tracer_.depth(-1);
00159 
00160     // Initialize and reset the temporal counters
00161     InitCounter();
00162 
00163     // Loop over the track collection.
00164     for (std::size_t index = 0; index < TPCollection->size(); index++)
00165     {
00166         // Get a pointer to a track per each track in collection
00167         TrackingParticleRef track(TPCollection, index);
00168 
00169         // If the track is not fake then get the orginal particles
00170         if ((*track).matchedHit() >= matchedHits_)
00171         {
00172             if ( tracer_.evaluate(track) )
00173             {
00174                 const HepMC::GenParticle * particle = tracer_.genParticle();
00175                 // If the origin can be determined then take the first particle as the original
00176                 if (particle)
00177                     Count(particle->barcode(), particle->pdg_id());
00178             }
00179             else
00180                 Count(0,0);
00181         }
00182     }
00183     UpdateCounter();
00184 }

void TruthTOA::beginJob ( const edm::EventSetup setup  )  [private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 188 of file TruthTOA.cc.

References edm::EventSetup::getData(), and pdt_.

00189 {
00190     // Get the particles table.
00191     setup.getData( pdt_ );
00192 }

void TruthTOA::Count ( int  barcode = 0,
int  pdgId = 0 
) [private]

Definition at line 298 of file TruthTOA.cc.

References counter_buffer_, counter_index_, and it.

Referenced by analyze().

00299 {
00300     counter_buffer_t::iterator it = counter_buffer_.find(barcode);
00301 
00302     if ( it != counter_buffer_.end() )
00303     {
00304         it->second++;
00305     }
00306     else
00307     {
00308         counter_buffer_.insert( counter_buffer_pair_t(barcode, 1) );
00309         counter_index_.insert( counter_index_pair_t(barcode, pdgId) );
00310     }
00311 }

void TruthTOA::endJob ( void   )  [private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 196 of file TruthTOA.cc.

References begin, counter_, GenMuonPlsPt100GeV_cfg::cout, end, lat::endl(), file, find(), i, it, gen_jpsi2muons_cfg::ParticleID, pdt_, rootFile_, reco::JTATagInfo::tracks(), v, and vetoList_.

00197 {
00198     TFile file(rootFile_.c_str(), "RECREATE");
00199     file.cd();
00200 
00201     double vetoedVals;
00202     double totalVals;
00203 
00204     std::cout << "List of all long lived particle found" << std::endl;
00205     for ( counter_t::iterator it = counter_.begin(); it != counter_.end(); it++)
00206     {
00207         if ( !it->first.pdgId )
00208             std::cout << " fake tracks -> " << it->second << std::endl;
00209         else
00210             std::cout << " particle " <<pdt_->particle(HepPDT::ParticleID(it->first.pdgId))->name();
00211         std::cout << " associated to " << it->first.tracks << " tracks -> " << it->second << std::endl;
00212     }
00213 
00214     std::multimap<double, std::string> particleTypes;
00215 
00216     for (std::size_t cid = 0; cid < vetoList_.size(); cid++)
00217     {
00218         particleTypes.clear();
00219         vetoedVals = 0;
00220         totalVals = 0;
00221 
00222         for (counter_t::iterator it = counter_.begin(); it != counter_.end(); it++)
00223         {
00224             std::ostringstream particle;
00225 
00226             if ( !it->first.pdgId )
00227                 particle << "Fake" << std::endl;
00228             else
00229                 particle << pdt_->particle(HepPDT::ParticleID(it->first.pdgId))->name();
00230 
00231             if (
00232                 std::find (
00233                     vetoList_[cid].begin(),
00234                     vetoList_[cid].end(),
00235                     particle.str()
00236                 ) == vetoList_[cid].end()
00237             )
00238             {
00239                 particle << "#" << it->first.tracks;
00240                 particleTypes.insert(std::pair<double,std::string>(it->second, particle.str()));
00241                 totalVals += it->second;
00242             }
00243             else
00244             {
00245                 vetoedVals += it->second;
00246                 totalVals += it->second;
00247             }
00248         }
00249 
00250         std::cout << "Veto list #" << cid << std::endl;
00251         std::cout << " number of vetoed tracks " << vetoedVals << std::endl;
00252         std::cout << " total number of tracks " << totalVals << std::endl;
00253         std::cout << " % of vetoed tracks " << ((vetoedVals/totalVals) * 100) << std::endl;
00254 
00255         std::ostringstream hName, hTitle;
00256 
00257         hTitle << "Track origins for the whole track collection";
00258         hName  << "TrackingParticleCollection";
00259 
00260         for (std::size_t v=0; v < vetoList_[cid].size(); v++)
00261         {
00262             hTitle << "_" << vetoList_[cid][v];
00263             hName << "_" << vetoList_[cid][v];
00264         }
00265 
00266         // creating and saving the pie
00267         TH1D histogram(
00268             hName.str().c_str(),
00269             hTitle.str().c_str(),
00270             particleTypes.size(),
00271             0.,
00272             Double_t(particleTypes.size())
00273         );
00274 
00275         // creating and saving the histogram
00276         int i = 1;
00277         std::cout << "Particle size " <<  particleTypes.size() << std::endl;
00278 
00279         std::map<double, std::string>::const_iterator it;
00280 
00281         for (it = particleTypes.begin(); it != particleTypes.end(); it++, i++)
00282         {
00283             histogram.GetXaxis()->SetBinLabel(i, it->second.c_str());
00284             histogram.SetBinContent(i, Double_t(it->first));
00285         }
00286 
00287         histogram.Write();
00288         file.Flush();
00289     }
00290 }

void TruthTOA::InitCounter (  )  [private]

Definition at line 292 of file TruthTOA.cc.

References counter_buffer_, and counter_index_.

Referenced by analyze().

00293 {
00294     counter_buffer_.clear();
00295     counter_index_.clear();
00296 }

void TruthTOA::UpdateCounter (  )  [private]

Definition at line 314 of file TruthTOA.cc.

References funct::abs(), antiparticles_, counter_, counter_buffer_, counter_index_, and info.

Referenced by analyze().

00315 {
00316     counter_buffer_t::const_iterator csi = counter_buffer_.begin();
00317 
00318     std::size_t particleType;
00319 
00320     for (; csi != counter_buffer_.end(); csi++)
00321     {
00322         if (antiparticles_)
00323             particleType = counter_index_[csi->first];
00324         else
00325             particleType = abs(counter_index_[csi->first]);
00326         if ( !particleType )
00327         {
00328             counter_info_t info (particleType, 1);
00329             counter_t::iterator ci = counter_.find( info );
00330             if ( ci != counter_.end() )
00331                 ci->second += csi->second;
00332             else
00333                 counter_.insert( counter_pair_t (info, csi->second) );
00334         }
00335         else
00336         {
00337             counter_info_t info = counter_info_t (particleType, csi->second);
00338             counter_t::iterator ci = counter_.find( info );
00339             if ( ci != counter_.end() )
00340                 ci->second++;
00341             else
00342                 counter_.insert( counter_pair_t (info, 1) );
00343         }
00344     }
00345 }


Member Data Documentation

bool TruthTOA::antiparticles_ [private]

Definition at line 66 of file TruthTOA.cc.

Referenced by TruthTOA(), and UpdateCounter().

counter_t TruthTOA::counter_ [private]

Definition at line 108 of file TruthTOA.cc.

Referenced by endJob(), and UpdateCounter().

counter_buffer_t TruthTOA::counter_buffer_ [private]

Definition at line 110 of file TruthTOA.cc.

Referenced by Count(), InitCounter(), and UpdateCounter().

counter_index_t TruthTOA::counter_index_ [private]

Definition at line 109 of file TruthTOA.cc.

Referenced by Count(), InitCounter(), and UpdateCounter().

int TruthTOA::matchedHits_ [private]

Definition at line 55 of file TruthTOA.cc.

Referenced by analyze(), and TruthTOA().

edm::ESHandle<ParticleDataTable> TruthTOA::pdt_ [private]

Definition at line 112 of file TruthTOA.cc.

Referenced by beginJob(), and endJob().

std::string TruthTOA::rootFile_ [private]

Definition at line 65 of file TruthTOA.cc.

Referenced by endJob(), and TruthTOA().

bool TruthTOA::status_ [private]

Definition at line 66 of file TruthTOA.cc.

Referenced by analyze(), and TruthTOA().

TrackHistory TruthTOA::tracer_ [private]

Definition at line 68 of file TruthTOA.cc.

Referenced by analyze().

edm::InputTag TruthTOA::trackingTruth_ [private]

Definition at line 63 of file TruthTOA.cc.

Referenced by analyze(), and TruthTOA().

vvstring TruthTOA::vetoList_ [private]

Definition at line 70 of file TruthTOA.cc.

Referenced by endJob(), and TruthTOA().


The documentation for this class was generated from the following file:
Generated on Tue Jun 9 18:34:37 2009 for CMSSW by  doxygen 1.5.4