ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/grimes/VHbbAnalysisCode/src/MCInfoPlotSet.cpp
Revision: 1.3
Committed: Wed Aug 15 22:37:47 2012 UTC (12 years, 8 months ago) by grimes
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +16 -0 lines
Log Message:
Long overdue commit with several new files

File Contents

# Content
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 pNumberOfPrimaryVertices_=new TH1F( "numberOfPrimaryVertices", "Number of primary vertices", 71, -0.5, 70.5 );
31 pNumberOfPrimaryVertices_->SetDirectory(pDirectory);
32
33 pNumberOfBunchCrossings_=new TH1F( "numberOfBunchCrossings", "Number of bunch crossings", 71, -0.5, 70.5 );
34 pNumberOfInteractionsPerBunchCrossing_=new TH1F( "numberOfInteractionsPerBunchCrossing", "Number of interactions per bunch crossing", 71, -0.5, 70.5 );
35 pTotalInteractionsPerEvent_=new TH1F( "totalInteractionsPerEvent", "Total number of interactions per event", 71, -0.5, 70.5 );
36 pNumberOfBunchCrossings_->SetDirectory(pDirectory);
37 pNumberOfInteractionsPerBunchCrossing_->SetDirectory(pDirectory);
38 pTotalInteractionsPerEvent_->SetDirectory(pDirectory);
39
40 histogramHaveBeenBooked_=true;
41 }
42
43 void trkupgradeanalysis::MCInfoPlotSet::fill( const VHbbEventAuxInfo& eventAuxInfo )
44 {
45 if( !histogramHaveBeenBooked_ ) throw std::runtime_error( "trkupgradeanalysis::MCInfoPlotSet::book() - histograms have not been booked" );
46
47 std::stringstream eventStringStream;
48
49 std::vector<VHbbEventAuxInfo::ParticleMCInfo> zMCInfo=eventAuxInfo.mcZ;
50 std::vector<VHbbEventAuxInfo::ParticleMCInfo> higgsMCInfo=eventAuxInfo.mcH;
51
52 for( std::vector<VHbbEventAuxInfo::ParticleMCInfo>::const_iterator higgsInfo=higgsMCInfo.begin(); higgsInfo!=higgsMCInfo.end(); ++higgsInfo )
53 {
54 if( higgsInfo->dauid.size()==1 && std::abs(higgsInfo->dauid[0])==25 ) continue;
55
56 std::cout << "H->(";
57 for( size_t index=0; index<higgsInfo->dauid.size() && index<higgsInfo->dauFourMomentum.size(); ++index )
58 {
59 const int& daughterID=higgsInfo->dauid[index];
60 const TLorentzVector& vector=higgsInfo->dauFourMomentum[index];
61 if( index!=0 ) std::cout << ",";
62 std::cout << daughterID << " [" << vector.Pt() << "]";
63 }
64 std::cout << ") ";
65 }
66 std::cout << "\n";
67
68 for( std::vector<VHbbEventAuxInfo::ParticleMCInfo>::const_iterator higgsInfo=higgsMCInfo.begin(); higgsInfo!=higgsMCInfo.end(); ++higgsInfo )
69 {
70 if( higgsInfo->dauid.size()==1 && std::abs(higgsInfo->dauid[0])==25 ) continue;
71
72 eventStringStream << "H->(";
73 for( std::vector<int>::const_iterator daughterID=higgsInfo->dauid.begin(); daughterID!=higgsInfo->dauid.end(); ++daughterID )
74 {
75 if( daughterID!=higgsInfo->dauid.begin() ) eventStringStream << ",";
76 eventStringStream << *daughterID;
77 }
78 eventStringStream << ") ";
79 }
80
81 for( std::vector<VHbbEventAuxInfo::ParticleMCInfo>::const_iterator zInfo=zMCInfo.begin(); zInfo!=zMCInfo.end(); ++zInfo )
82 {
83 if( zInfo->dauid.empty() ) continue;
84 if( zInfo->dauid.size()==1 && std::abs(zInfo->dauid[0])==23 ) continue;
85 if( zInfo->dauid.size()==2 && std::abs(zInfo->dauid[0])==23 && std::abs(zInfo->dauid[1])==25 ) continue;
86
87 eventStringStream << "Z->(";
88 for( std::vector<int>::const_iterator daughterID=zInfo->dauid.begin(); daughterID!=zInfo->dauid.end(); ++daughterID )
89 {
90 if( *daughterID==23 ) continue;
91 if( zInfo->dauid.size()>2 && *daughterID==22 ) continue;
92 if( daughterID!=zInfo->dauid.begin() ) eventStringStream << ",";
93 eventStringStream << *daughterID;
94 }
95 eventStringStream << ") ";
96 }
97
98 // Now that I've created the string describing the MC truth type of the event, see
99 // if it's already been used. If so find out which bin it's being plotted in. Note that
100 // "binNumber" here isn't strictly speaking the bin number, it's the x-coord used to fill
101 // the correct bin.
102 int binNumber=0;
103 std::map<std::string,int>::const_iterator iBinNumber=stringToBinMap_.find( eventStringStream.str() );
104 if( iBinNumber==stringToBinMap_.end() )
105 {
106 // hasn't been plotted before, so I need to create an entry in the map
107 // and use the next available bin.
108 binNumber=stringToBinMap_.size()+1;
109 stringToBinMap_[eventStringStream.str()]=binNumber;
110
111 // Give the histogram bin the correct label
112 pEventString_->GetXaxis()->SetBinLabel( binNumber, eventStringStream.str().c_str() );
113 }
114 else binNumber=iBinNumber->second;
115
116 pEventString_->Fill( binNumber );
117
118 pNumberOfPrimaryVertices_->Fill( eventAuxInfo.pvInfo.nVertices );
119
120 // Loop over the pile up data
121 unsigned int totalNumberOfInteractions=0;
122 unsigned int numberOfBunchCrossings=0;
123 for( std::map<int,unsigned int>::const_iterator iBXInteractionPair=eventAuxInfo.puInfo.pus.begin(); iBXInteractionPair!=eventAuxInfo.puInfo.pus.end(); ++iBXInteractionPair )
124 {
125 const unsigned int& numberOfInteractions=iBXInteractionPair->second;
126 totalNumberOfInteractions+=numberOfInteractions;
127 pNumberOfInteractionsPerBunchCrossing_->Fill( numberOfInteractions );
128 ++numberOfBunchCrossings;
129 }
130 pNumberOfBunchCrossings_->Fill( numberOfBunchCrossings );
131 pTotalInteractionsPerEvent_->Fill( totalNumberOfInteractions );
132
133 }
134