2 #include "PlotProcessor.h"
16 #include "TMultiGraph.h"
18 #endif // of #ifdef USEROOT
20 #include "EVENT/LCCollection.h"
21 #include "IMPL/ReconstructedParticleImpl.h"
22 #include "EVENT/LCParameters.h"
23 #include "EVENT/LCFloatVec.h"
24 #include "EVENT/LCIntVec.h"
26 #include "util/inc/vector3.h"
27 #include "util/inc/util.h"
35 using std::stringstream;
46 PlotProcessor::PlotProcessor() : marlin::Processor(
"Plot")
48 _description =
"Plots various outputs from the flavour tag" ;
52 registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
54 "Name of the collection of ReconstructedParticles that is the jet" ,
57 vector<string> FlavourTagCollectionNamesDefault;
58 FlavourTagCollectionNamesDefault.push_back(
"FlavourTag");
59 registerProcessorParameter(
"FlavourTagCollections" ,
60 "Name of the LCFloatVec Collections that contain the flavour tags (one purity efficiency plot per tag) (in same order as jet collection)" ,
61 _FlavourTagCollectionNames,
62 FlavourTagCollectionNamesDefault) ;
63 registerInputCollection( LCIO::LCFLOATVEC,
64 "TrueJetFlavourCollection" ,
65 "Name of the output collection of LCIntVec (same order as jets)" ,
66 _TrueJetFlavourColName ,
67 std::string(
"TrueJetFlavour") ) ;
69 registerProcessorParameter(
"OutputFilename" ,
70 "Filename for the output" ,
72 string(
"PlotProcessorOutput") ) ;
75 PlotProcessor::~PlotProcessor()
79 void PlotProcessor::init()
82 cout << _description << endl
83 <<
"-------------------------------------------------" << endl
97 void PlotProcessor::processRunHeader( LCRunHeader* pRun )
104 vector<string> VarNames;
107 set<string> AvailableNames;
108 map<string,unsigned int> IndexOf;
109 for (
size_t i = 0;i < VarNames.size();++i)
111 AvailableNames.insert(VarNames[i]);
112 IndexOf[VarNames[i]] = i;
116 _IndexOfForEachTag.push_back(IndexOf);
119 set<string> RequiredNames;
120 RequiredNames.insert(
"BTag");
121 RequiredNames.insert(
"CTag");
122 RequiredNames.insert(
"BCTag");
124 if (!includes(AvailableNames.begin(),AvailableNames.end(),RequiredNames.begin(),RequiredNames.end()))
129 void PlotProcessor::processEvent( LCEvent* pEvent )
136 if( pJetCollection->getTypeName()!=LCIO::RECONSTRUCTEDPARTICLE )
138 stringstream message;
140 <<
"########################################################################################\n"
141 <<
"# PlotProcessor - #\n"
142 <<
"# The jet collection requested (\"" <<
_JetCollectionName <<
"\") is not of the type \"" << LCIO::RECONSTRUCTEDPARTICLE <<
"\" #\n"
143 <<
"########################################################################################" << endl;
144 throw EventException( message.str() );
150 ReconstructedParticle* pJet;
152 for(
int a=0; a<pJetCollection->getNumberOfElements(); ++a )
156 pJet=
dynamic_cast<ReconstructedParticle*
>( pJetCollection->getElementAt(a) );
169 void PlotProcessor::end()
173 cout <<
"The largest jet energy was " <<
_jetEMax << endl;
203 double CThJ_upper=0.95;
207 const double* mom=pJet->getMomentum();
210 jetMomentum.makeUnit();
211 double cosTheta=jetMomentum.dot( zAxis );
212 if( fabs(cosTheta)<=CThJ_lower || fabs(cosTheta)>=CThJ_upper )
return false;
222 float jetType = *(
dynamic_cast<LCFloatVec*
>(pTrueCollection->getElementAt(jet))->begin());
228 double bTag= (*
dynamic_cast<LCFloatVec*
>(pTagCollection->getElementAt(jet)))[_IndexOfForEachTag[iTag][
"BTag"]];
229 double cTag= (*
dynamic_cast<LCFloatVec*
>(pTagCollection->getElementAt(jet)))[_IndexOfForEachTag[iTag][
"CTag"]];
230 double cTagBBack= (*
dynamic_cast<LCFloatVec*
>(pTagCollection->getElementAt(jet)))[_IndexOfForEachTag[iTag][
"BCTag"]];
238 else if( jetType==
C_JET )
256 stringstream filenameStream;
257 filenameStream << filename <<
".root";
258 TFile rootFile( filenameStream.str().c_str(),
"RECREATE",
"Various plots from the plot processor" );
265 int numberOfPoints=100;
268 vector< pair<double,double> > BTagefficiencyPurityPairs=
_BTagEfficiencyPurity[iTag].eff_pur( numberOfPoints );
269 vector< pair<double,double> > CTagefficiencyPurityPairs=
_CTagEfficiencyPurity[iTag].eff_pur( numberOfPoints );
270 vector< pair<double,double> > BCTagefficiencyPurityPairs=
_BCTagEfficiencyPurity[iTag].eff_pur( numberOfPoints );
274 double BNetEfficiency[100];
275 double BNetPurity[100];
276 double CNetEfficiency[100];
277 double CNetPurity[100];
278 double BCNetEfficiency[100];
279 double BCNetPurity[100];
281 for(
int a=0; a<numberOfPoints; ++a )
283 BNetEfficiency[a]=BTagefficiencyPurityPairs[a].first;
284 BNetPurity[a]=BTagefficiencyPurityPairs[a].second;
285 CNetEfficiency[a]=CTagefficiencyPurityPairs[a].first;
286 CNetPurity[a]=CTagefficiencyPurityPairs[a].second;
287 BCNetEfficiency[a]=BCTagefficiencyPurityPairs[a].first;
288 BCNetPurity[a]=BCTagefficiencyPurityPairs[a].second;
291 TGraph BNetGraph( 99, BNetEfficiency, BNetPurity );
293 TGraph CNetGraph( 99, CNetEfficiency, CNetPurity );
295 TGraph BCNetGraph( 99, BCNetEfficiency, BCNetPurity );
298 TMultiGraph TagGraphs;
300 TagGraphs.Add( &BNetGraph );
301 TagGraphs.Add( &CNetGraph );
302 TagGraphs.Add( &BCNetGraph );
308 pAxis=TagGraphs.GetXaxis();
309 if(pAxis) pAxis->SetTitle(
"Efficiency" );
311 pAxis=TagGraphs.GetYaxis();
312 if(pAxis) pAxis->SetTitle(
"Purity" );
314 rootFile.Add( &TagGraphs );
318 TH1F jetEnergyHistogram(
"jetEnergyHistogram",
"Jet energies", 200, 0, 120 );
319 const vector<double> jetEnergyData=
_jetEnergy.sorted_data();
320 for( vector<double>::const_iterator i=jetEnergyData.begin(); i<jetEnergyData.end(); ++i ) jetEnergyHistogram.Fill( (*i) );
325 #else //of ifdef USEROOT
331 ofile.open( (filename +
".csv").c_str() );
332 if( ofile.is_open() )
337 ofile <<
"E," << n <<
" B Tag,E," << n <<
" C Tag,E," << n <<
" BC Tag,";
341 vector<vector<pair<double,double> > > BTagefficiencyPurityPairs;
342 vector<vector<pair<double,double> > > CTagefficiencyPurityPairs;
343 vector<vector<pair<double,double> > > BCTagefficiencyPurityPairs;
345 int numberOfPoints=100;
355 for(
int a=0; a<numberOfPoints; ++a )
359 ofile << BTagefficiencyPurityPairs[iTag][a].first <<
"," << BTagefficiencyPurityPairs[iTag][a].second <<
",";
360 ofile << CTagefficiencyPurityPairs[iTag][a].first <<
"," << CTagefficiencyPurityPairs[iTag][a].second <<
",";
361 ofile << BCTagefficiencyPurityPairs[iTag][a].first <<
"," << BCTagefficiencyPurityPairs[iTag][a].second <<
",";
369 cerr <<
"########################################################################################\n"
370 <<
"# PlotProcessor - #\n"
371 <<
"# Unable to open file \"" << filename <<
"\" for output #\n"
372 <<
"########################################################################################" << endl;
375 stringstream filenameStream;
376 filenameStream << filename <<
"-JetEnergies.csv";
378 ofile.open( filenameStream.str().c_str() );
379 if( ofile.is_open() )
381 vector< vertex_lcfi::util::bin<double> > binned=
_jetEnergy.binned_data( 200, 0, 120 );
382 ofile <<
"Bin low,Bin High,Frequency" << endl;
384 ofile << (*i).region_low() <<
"," << (*i).region_high() <<
"," << (*i).contents() << endl;
389 cerr <<
"########################################################################################\n"
390 <<
"# PlotProcessor - #\n"
391 <<
"# Unable to open file \"" << filenameStream.str() <<
"\" for output #\n"
392 <<
"########################################################################################" << endl;
394 #endif //of ifdef USEROOT
399 const vector<string>* pCollectionNames=pEvent->getCollectionNames();
401 cout <<
"The available collections are: (name - type)" << endl;
402 for( vector<string>::const_iterator i=pCollectionNames->begin(); i<pCollectionNames->end(); ++i )
404 LCCollection* pCollection=pEvent->getCollection( (*i) );
405 const string typeName=pCollection->getTypeName();
406 cout <<
" " << (*i) <<
" - " << typeName << endl;
std::vector< efficiency_purity< double > > _BCTagEfficiencyPurity
std::vector< efficiency_purity< double > > _CTagEfficiencyPurity
std::vector< efficiency_purity< double > > _BTagEfficiencyPurity
bool _passesJetCuts(lcio::ReconstructedParticle *pJet)
void _fillPlots(LCEvent *pEvent, unsigned int jet)
std::vector< std::string > _FlavourTagCollectionNames
std::string _TrueJetFlavourColName
std::string _OutputFilename
Creates some sample plots from the data calculated by the LCFI vertex package.
void _displayCollectionNames(lcio::LCEvent *pEvent)
histogram_data< double > _jetEnergy
std::string _JetCollectionName
bool _passesEventCuts(lcio::LCEvent *pEvent)
void _outputDataToFile(std::string filename)