1 |
#include "TrkUpgradeAnalysis/VHbb/interface/MCInfoPlotSet.h"
|
2 |
|
3 |
#include <stdexcept>
|
4 |
#include <sstream>
|
5 |
|
6 |
#include <TDirectory.h>
|
7 |
#include <TH1F.h>
|
8 |
|
9 |
|
10 |
trkupgradeanalysis::MCInfoPlotSet::MCInfoPlotSet()
|
11 |
: histogramHaveBeenBooked_(false)
|
12 |
{
|
13 |
// No operation besides the initialiser list.
|
14 |
}
|
15 |
|
16 |
void trkupgradeanalysis::MCInfoPlotSet::book( TDirectory* pDirectory )
|
17 |
{
|
18 |
if( histogramHaveBeenBooked_ ) throw std::runtime_error( "trkupgradeanalysis::MCInfoPlotSet::book() - histograms have already been booked" );
|
19 |
|
20 |
//
|
21 |
// Note that the root file which TDirectory is part of takes ownership of all
|
22 |
// of these objects, so I don't need to (and shouldn't) delete them when I'm
|
23 |
// finished.
|
24 |
//
|
25 |
|
26 |
|
27 |
pEventString_=new TH1F( "mcEventType", "Event type from MC", 10, 0.5, 10.5 );
|
28 |
pEventString_->SetDirectory(pDirectory);
|
29 |
|
30 |
histogramHaveBeenBooked_=true;
|
31 |
}
|
32 |
|
33 |
void trkupgradeanalysis::MCInfoPlotSet::fill( const VHbbEventAuxInfo& eventAuxInfo )
|
34 |
{
|
35 |
if( !histogramHaveBeenBooked_ ) throw std::runtime_error( "trkupgradeanalysis::MCInfoPlotSet::book() - histograms have not been booked" );
|
36 |
|
37 |
std::stringstream eventStringStream;
|
38 |
|
39 |
std::vector<VHbbEventAuxInfo::ParticleMCInfo> zMCInfo=eventAuxInfo.mcZ;
|
40 |
std::vector<VHbbEventAuxInfo::ParticleMCInfo> higgsMCInfo=eventAuxInfo.mcH;
|
41 |
|
42 |
for( std::vector<VHbbEventAuxInfo::ParticleMCInfo>::const_iterator higgsInfo=higgsMCInfo.begin(); higgsInfo!=higgsMCInfo.end(); ++higgsInfo )
|
43 |
{
|
44 |
if( higgsInfo->dauid.size()==1 && std::abs(higgsInfo->dauid[0])==25 ) continue;
|
45 |
|
46 |
eventStringStream << "H->(";
|
47 |
for( std::vector<int>::const_iterator daughterID=higgsInfo->dauid.begin(); daughterID!=higgsInfo->dauid.end(); ++daughterID )
|
48 |
{
|
49 |
if( daughterID!=higgsInfo->dauid.begin() ) eventStringStream << ",";
|
50 |
eventStringStream << *daughterID;
|
51 |
}
|
52 |
eventStringStream << ") ";
|
53 |
}
|
54 |
|
55 |
for( std::vector<VHbbEventAuxInfo::ParticleMCInfo>::const_iterator zInfo=zMCInfo.begin(); zInfo!=zMCInfo.end(); ++zInfo )
|
56 |
{
|
57 |
if( zInfo->dauid.empty() ) continue;
|
58 |
if( zInfo->dauid.size()==1 && std::abs(zInfo->dauid[0])==23 ) continue;
|
59 |
if( zInfo->dauid.size()==2 && std::abs(zInfo->dauid[0])==23 && std::abs(zInfo->dauid[1])==25 ) continue;
|
60 |
|
61 |
eventStringStream << "Z->(";
|
62 |
for( std::vector<int>::const_iterator daughterID=zInfo->dauid.begin(); daughterID!=zInfo->dauid.end(); ++daughterID )
|
63 |
{
|
64 |
if( *daughterID==23 ) continue;
|
65 |
if( zInfo->dauid.size()>2 && *daughterID==22 ) continue;
|
66 |
if( daughterID!=zInfo->dauid.begin() ) eventStringStream << ",";
|
67 |
eventStringStream << *daughterID;
|
68 |
}
|
69 |
eventStringStream << ") ";
|
70 |
}
|
71 |
|
72 |
// Now that I've created the string describing the MC truth type of the event, see
|
73 |
// if it's already been used. If so find out which bin it's being plotted in. Note that
|
74 |
// "binNumber" here isn't strictly speaking the bin number, it's the x-coord used to fill
|
75 |
// the correct bin.
|
76 |
int binNumber=0;
|
77 |
std::map<std::string,int>::const_iterator iBinNumber=stringToBinMap_.find( eventStringStream.str() );
|
78 |
if( iBinNumber==stringToBinMap_.end() )
|
79 |
{
|
80 |
// hasn't been plotted before, so I need to create an entry in the map
|
81 |
// and use the next available bin.
|
82 |
binNumber=stringToBinMap_.size()+1;
|
83 |
stringToBinMap_[eventStringStream.str()]=binNumber;
|
84 |
|
85 |
// Give the histogram bin the correct label
|
86 |
pEventString_->GetXaxis()->SetBinLabel( binNumber, eventStringStream.str().c_str() );
|
87 |
}
|
88 |
else binNumber=iBinNumber->second;
|
89 |
|
90 |
pEventString_->Fill( binNumber );
|
91 |
}
|
92 |
|