ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/grimes/L1Menu/src/MenuRatePlots.cpp
(Generate patch)

Comparing UserCode/grimes/L1Menu/src/MenuRatePlots.cpp (file contents):
Revision 1.7 by grimes, Tue Jun 18 10:18:23 2013 UTC vs.
Revision 1.13 by grimes, Wed Jul 24 11:48:55 2013 UTC

# Line 4 | Line 4
4   #include "l1menu/ITrigger.h"
5   #include "l1menu/TriggerMenu.h"
6   #include "l1menu/TriggerRatePlot.h"
7 < #include "l1menu/tools.h"
8 < #include "l1menu/ReducedMenuSample.h"
9 < #include "l1menu/IReducedEvent.h"
7 > #include "l1menu/tools/tools.h"
8   #include <TH1F.h>
9 + #include <TDirectory.h>
10 + #include <TKey.h>
11 + #include <iostream>
12  
13   l1menu::MenuRatePlots::MenuRatePlots( const l1menu::TriggerMenu& triggerMenu, TDirectory* pDirectory )
14   {
15          // Before making any histograms make sure errors are done properly
16          TH1::SetDefaultSumw2();
17  
18 +        // This is always useful
19 +        const l1menu::TriggerTable& triggerTable=l1menu::TriggerTable::instance();
20 +
21          // Loop over each of the triggers in the menu, book a histogram for it and then create
22          // a l1menu::TriggerRate plot for it.
23          for( size_t triggerNumber=0; triggerNumber<triggerMenu.numberOfTriggers(); ++triggerNumber )
24          {
25                  std::unique_ptr<l1menu::ITrigger> pTrigger=triggerMenu.getTriggerCopy(triggerNumber);
26                  // Figure out the parameter names of all the possible thresholds.
27 <                const std::vector<std::string> thresholdNames= l1menu::getThresholdNames(*pTrigger);
27 >                const std::vector<std::string> thresholdNames=l1menu::tools::getThresholdNames(*pTrigger);
28 >
29 >                //
30 >                // If there is more than one threshold add a plot where all of the thresholds are scaled together.
31 >                //
32 >                if( thresholdNames.size()>1 )
33 >                {
34 >                        const std::string& mainThreshold=thresholdNames.front();
35 >                        unsigned int numberOfBins=100;
36 >                        float lowerEdge=0;
37 >                        float upperEdge=100;
38 >                        try
39 >                        {
40 >                                numberOfBins=triggerTable.getSuggestedNumberOfBins( pTrigger->name(), mainThreshold );
41 >                                lowerEdge=triggerTable.getSuggestedLowerEdge( pTrigger->name(), mainThreshold );
42 >                                upperEdge=triggerTable.getSuggestedUpperEdge( pTrigger->name(), mainThreshold );
43 >                        }
44 >                        catch( std::exception& error) { /* Do nothing. If no binning suggestions have been set for this trigger use the defaults I set above. */ }
45 >
46 >                        std::unique_ptr<TH1> pHistogram( new TH1F( (pTrigger->name()+"_v_allThresholdsScaled").c_str(), "This title gets changed by TriggerRatePlot anyway", numberOfBins, lowerEdge, upperEdge ) );
47 >                        pHistogram->SetDirectory( pDirectory );
48 >                        // Passing thresholdNames tells the TriggerRatePlot to scale all parameters named in that
49 >                        // vector along with mainThreshold.
50 >                        triggerPlots_.push_back( std::move(l1menu::TriggerRatePlot(*pTrigger,std::move(pHistogram),mainThreshold,thresholdNames)) );
51 >
52 >                }
53  
54                  // When a threshold is tested, I want all the other thresholds to be zero. I'll run through
55                  // and zero all of them now.
# Line 38 | Line 67 | l1menu::MenuRatePlots::MenuRatePlots( co
67                          float upperEdge=100;
68                          try
69                          {
41                                const l1menu::TriggerTable& triggerTable=l1menu::TriggerTable::instance();
70                                  numberOfBins=triggerTable.getSuggestedNumberOfBins( pTrigger->name(), *iThresholdName );
71                                  lowerEdge=triggerTable.getSuggestedLowerEdge( pTrigger->name(), *iThresholdName );
72                                  upperEdge=triggerTable.getSuggestedUpperEdge( pTrigger->name(), *iThresholdName );
# Line 53 | Line 81 | l1menu::MenuRatePlots::MenuRatePlots( co
81          } // end of loop over the triggers in the menu
82   }
83  
84 < void l1menu::MenuRatePlots::addEvent( const l1menu::IEvent& event )
84 > l1menu::MenuRatePlots::MenuRatePlots( const TDirectory* pPreExistingPlotDirectory )
85   {
86 <        // Loop over each of the TriggerRatePlots and add the event to each of them.
87 <        for( auto& ratePlot : triggerPlots_ )
86 >        // Before making any histograms make sure errors are done properly
87 >        TH1::SetDefaultSumw2();
88 >
89 >        // Loop over all of the histograms in the directory.
90 >        TList* pListOfKeys=pPreExistingPlotDirectory->GetListOfKeys();
91 >        std::string oldKeyName;
92 >
93 >        for( int index=0; index<pListOfKeys->GetEntries(); ++index )
94          {
95 <                ratePlot.addEvent( event );
96 <        }
95 >                TKey* pKey=dynamic_cast<TKey*>( pListOfKeys->At(index) );
96 >                // Only use the highest cycle number for each key
97 >                if( oldKeyName==pKey->GetName() ) continue;
98 >                oldKeyName=pKey->GetName();
99 >
100 >                TH1* pHistogram=dynamic_cast<TH1*>( pKey->ReadObj() );
101 >
102 >                if( pHistogram!=NULL )
103 >                {
104 >                        try
105 >                        {
106 >                                l1menu::TriggerRatePlot ratePlotFromHistogram( pHistogram );
107 >                                triggerPlots_.push_back( std::move(ratePlotFromHistogram) );
108 >                        }
109 >                        catch( std::exception& error )
110 >                        {
111 >                                std::cerr << "Couldn't create TriggerRatePlot for " << pHistogram->GetName() << " because: " << error.what() << std::endl;
112 >                        }
113 >
114 >                } // end of "if( dynamic_cast to TH1* successful )"
115 >
116 >        } // end of loop over the keys in the file
117   }
118  
119 < void l1menu::MenuRatePlots::initiateForReducedSample( const l1menu::ReducedMenuSample& sample )
119 > void l1menu::MenuRatePlots::addEvent( const l1menu::IEvent& event )
120   {
121 <        // Loop over each of the TriggerRatePlots and delegate the call to them.
121 >        // Loop over each of the TriggerRatePlots and add the event to each of them.
122          for( auto& ratePlot : triggerPlots_ )
123          {
124 <                ratePlot.initiateForReducedSample( sample );
124 >                ratePlot.addEvent( event );
125          }
126   }
127  
128 < void l1menu::MenuRatePlots::addEvent( const l1menu::IReducedEvent& event )
128 > void l1menu::MenuRatePlots::addSample( const l1menu::ISample& sample )
129   {
130 <        // Loop over each of the TriggerRatePlots and add the event to each of them.
130 >        // Loop over each of the TriggerRatePlots and add the sample to each of them.
131          for( auto& ratePlot : triggerPlots_ )
132          {
133 <                ratePlot.addEvent( event );
133 >                ratePlot.addSample( sample );
134          }
135   }
136  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines