ATLAS_2011_S9126244.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #include "Rivet/Analysis.hh"
00003 #include "Rivet/RivetAIDA.hh"
00004 #include "Rivet/Tools/Logging.hh"
00005 #include "Rivet/Projections/FinalState.hh"
00006 #include "Rivet/Projections/FastJets.hh"
00007 
00008 #include "Rivet/Tools/BinnedHistogram.hh"
00009 
00010 namespace Rivet {
00011 
00012 
00013   struct ATLAS_2011_S9126244_Plots {
00014 
00015     int selectionType; // The third value in the axis code d**-**-**
00016     std::string intermediateHistName;
00017 
00018     // Gap Fraction Vs Delta Y Plot Setup
00019     int m_gapFractionDeltaYHistIndex;
00020     std::vector<double> m_gapFractionDeltaYSlices;
00021     BinnedHistogram<double> _h_gapVsDeltaYVeto;
00022     BinnedHistogram<double> _h_gapVsDeltaYInc;
00023 
00024     // Gap Fraction Vs PtBar Plot Setup
00025     int m_gapFractionPtBarHistIndex;
00026     std::vector<double> m_gapFractionPtBarSlices;
00027     BinnedHistogram<double> _h_gapVsPtBarVeto;
00028     BinnedHistogram<double> _h_gapVsPtBarInc;
00029 
00030     // Gap Fraction Vs Q0 Plot Setup
00031     int m_gapFractionQ0HistIndex;
00032     std::vector<double> m_gapFractionQ0SlicesPtBar;
00033     std::vector<double> m_gapFractionQ0SlicesDeltaY;
00034     std::vector<AIDA::IHistogram1D*> _h_vetoPt;
00035     std::vector<AIDA::IDataPointSet*> _d_vetoPtGapFraction;
00036     std::vector<double> _h_vetoPtTotalSum;
00037 
00038     // Average NJet Vs DeltaY Setup
00039     int m_avgNJetDeltaYHistIndex;
00040     std::vector<double> m_avgNJetDeltaYSlices;
00041     std::vector<AIDA::IProfile1D*> _p_avgJetVsDeltaY;
00042 
00043     // Average NJet Vs PtBar Setup
00044     int m_avgNJetPtBarHistIndex;
00045     std::vector<double> m_avgNJetPtBarSlices;
00046     std::vector<AIDA::IProfile1D*> _p_avgJetVsPtBar;
00047   };
00048 
00049 
00050   class ATLAS_2011_S9126244 : public Analysis {
00051   public:
00052 
00053     /// Constructor
00054     ATLAS_2011_S9126244()
00055       : Analysis("ATLAS_2011_S9126244")
00056     {    }
00057 
00058 
00059   public:
00060 
00061     /// Book histograms and initialise projections before the run
00062     void init() {
00063 
00064       // Initialize the lone projection required
00065       addProjection(FastJets(FinalState(), FastJets::ANTIKT, 0.6), "AntiKtJets06");
00066 
00067       // Make Q0 bins 0->20 then 20 to 195.0 in steps of 5
00068       m_q0BinEdges += 0.0;
00069       for (unsigned int x=0; x<36; x++){
00070         m_q0BinEdges += 20.0 + x*5.0 ;
00071       }
00072 
00073       // Initialize plots for each selection type
00074       m_selectionPlots[0].intermediateHistName = "highestPt";
00075       m_selectionPlots[0].selectionType = 1;
00076       m_selectionPlots[0].m_gapFractionDeltaYHistIndex = 6;
00077       m_selectionPlots[0].m_gapFractionPtBarHistIndex = 1;
00078       m_selectionPlots[0].m_gapFractionQ0HistIndex = 13;
00079       m_selectionPlots[0].m_avgNJetDeltaYHistIndex = 37;
00080       m_selectionPlots[0].m_avgNJetPtBarHistIndex = 26;
00081       m_selectionPlots[0].m_gapFractionDeltaYSlices += 70.0, 90.0, 120.0, 150.0, 180.0, 210.0, 240.0, 270.0;
00082       m_selectionPlots[0].m_gapFractionPtBarSlices += 1.0, 2.0, 3.0, 4.0, 5.0, 6.0;
00083       m_selectionPlots[0].m_gapFractionQ0SlicesPtBar += 70.0, 90.0, 120.0, 150.0, 210.0, 240.0;
00084       m_selectionPlots[0].m_gapFractionQ0SlicesDeltaY += 2.0, 3.0, 4.0, 5.0;
00085       m_selectionPlots[0].m_avgNJetPtBarSlices += 1.0, 2.0, 3.0, 4.0, 5.0;
00086       m_selectionPlots[0].m_avgNJetDeltaYSlices += 70.0, 90.0, 120.0, 150.0, 180.0, 210.0, 240.0, 270.0;
00087       initializePlots(m_selectionPlots[0]);
00088 
00089       m_selectionPlots[1].intermediateHistName = "forwardBackward";
00090       m_selectionPlots[1].selectionType = 2;
00091       m_selectionPlots[1].m_gapFractionDeltaYHistIndex = 6;
00092       m_selectionPlots[1].m_gapFractionPtBarHistIndex = 1;
00093       m_selectionPlots[1].m_gapFractionQ0HistIndex = 13;
00094       m_selectionPlots[1].m_avgNJetDeltaYHistIndex = 37;
00095       m_selectionPlots[1].m_avgNJetPtBarHistIndex = 26;
00096       m_selectionPlots[1].m_gapFractionDeltaYSlices += 70.0, 90.0, 120.0, 150.0, 180.0, 210.0, 240.0, 270.0;
00097       m_selectionPlots[1].m_gapFractionPtBarSlices += 1.0, 2.0, 3.0, 4.0, 5.0, 6.0;
00098       m_selectionPlots[1].m_gapFractionQ0SlicesPtBar += 70.0, 90.0, 120.0, 150.0, 210.0, 240.0;
00099       m_selectionPlots[1].m_gapFractionQ0SlicesDeltaY += 2.0, 3.0, 4.0, 5.0;
00100       m_selectionPlots[1].m_avgNJetPtBarSlices += 1.0, 2.0, 3.0, 4.0, 5.0;
00101       m_selectionPlots[1].m_avgNJetDeltaYSlices += 70.0, 90.0, 120.0, 150.0, 180.0, 210.0, 240.0, 270.0;
00102       initializePlots(m_selectionPlots[1]);
00103 
00104       m_selectionPlots[2].intermediateHistName = "forwardBackward_PtBarVeto";
00105       m_selectionPlots[2].selectionType = 1;
00106       m_selectionPlots[2].m_gapFractionDeltaYHistIndex = 19;
00107       m_selectionPlots[2].m_avgNJetDeltaYHistIndex = 30;
00108       m_selectionPlots[2].m_gapFractionDeltaYSlices += 70.0, 90.0, 120.0, 150.0, 180.0, 210.0, 240.0, 270.0;
00109       m_selectionPlots[2].m_avgNJetDeltaYSlices += 70.0, 90.0, 120.0, 150.0, 180.0, 210.0, 240.0, 270.0;
00110       initializePlots(m_selectionPlots[2]);
00111     }
00112 
00113 
00114     void initializePlots(ATLAS_2011_S9126244_Plots& plots) {
00115 
00116       // Gap Fraction Vs DeltaY
00117       for (int x = 0; x < ((int)plots.m_gapFractionDeltaYSlices.size()-1); x++) {
00118         std::stringstream vetoHistName;
00119         std::stringstream inclusiveHistName;
00120         const BinEdges deltaYEdges = binEdges(plots.m_gapFractionDeltaYHistIndex+x, 1, plots.selectionType);
00121 
00122         vetoHistName << "gapDeltaYVeto_" << plots.intermediateHistName << "_" << x;
00123         inclusiveHistName << "gapDeltaYInclusive_" << plots.intermediateHistName << "_" << x;
00124 
00125         plots._h_gapVsDeltaYVeto.addHistogram(plots.m_gapFractionDeltaYSlices[x], plots.m_gapFractionDeltaYSlices[x+1], bookHistogram1D(vetoHistName.str(), deltaYEdges));
00126         plots._h_gapVsDeltaYInc.addHistogram(plots.m_gapFractionDeltaYSlices[x], plots.m_gapFractionDeltaYSlices[x+1], bookHistogram1D(inclusiveHistName.str(), deltaYEdges));
00127       }
00128 
00129       // Average NJet Vs DeltaY
00130       for (int x = 0; x < ((int)plots.m_avgNJetDeltaYSlices.size()-1); x++) {
00131         plots._p_avgJetVsDeltaY += bookProfile1D(plots.m_avgNJetDeltaYHistIndex+x, 1, plots.selectionType);
00132       }
00133 
00134       // Gap Fraction Vs PtBar
00135       for (int x = 0; x < ((int)plots.m_gapFractionPtBarSlices.size()-1); x++) {
00136 
00137         std::stringstream vetoHistName;
00138         std::stringstream inclusiveHistName;
00139         const BinEdges ptBarEdges = binEdges(plots.m_gapFractionPtBarHistIndex+x, 1, plots.selectionType);
00140 
00141         vetoHistName << "gapPtBarVeto_" << plots.intermediateHistName << "_" << x;
00142         inclusiveHistName << "gapPtBarInclusive_" << plots.intermediateHistName << "_" << x;
00143 
00144         plots._h_gapVsPtBarVeto.addHistogram(plots.m_gapFractionPtBarSlices[x], plots.m_gapFractionPtBarSlices[x+1], bookHistogram1D(vetoHistName.str(), ptBarEdges));
00145         plots._h_gapVsPtBarInc.addHistogram(plots.m_gapFractionPtBarSlices[x], plots.m_gapFractionPtBarSlices[x+1], bookHistogram1D(inclusiveHistName.str(), ptBarEdges));
00146       }
00147 
00148       // Average NJet Vs PtBar
00149       for (int x = 0; x < ((int)plots.m_avgNJetPtBarSlices.size()-1); x++) {
00150         plots._p_avgJetVsPtBar += bookProfile1D(plots.m_avgNJetPtBarHistIndex+x, 1, plots.selectionType);
00151       }
00152 
00153       // Gap fraction Vs Q0
00154       int q0PlotCount = 0;
00155       for (int x = 0; x < ((int)plots.m_gapFractionQ0SlicesPtBar.size()/2); x++) {
00156         for (int y = 0; y < ((int)plots.m_gapFractionQ0SlicesDeltaY.size()/2); y++) {
00157           std::stringstream vetoPtHistName;
00158           std::stringstream vetoPtGapDataPointName;
00159 
00160           vetoPtHistName << "vetoPt_" << plots.intermediateHistName << "_" << q0PlotCount;
00161           vetoPtGapDataPointName << "gapQ0GapFractionDataPoints_" << plots.intermediateHistName << "_" << q0PlotCount;
00162 
00163           plots._h_vetoPt += bookHistogram1D(vetoPtHistName.str(),
00164                                              m_q0BinEdges);
00165           plots._d_vetoPtGapFraction += bookDataPointSet(plots.m_gapFractionQ0HistIndex+q0PlotCount, 1, plots.selectionType);
00166           plots._h_vetoPtTotalSum += 0.0;
00167           q0PlotCount++;
00168         }
00169       }
00170     }
00171 
00172 
00173     /// Perform the per-event analysis
00174     void analyze(const Event& event) {
00175       const double weight = event.weight();
00176 
00177       // Get minimal list of jets needed to be considered
00178       double minimumJetPtBar = 50.0*GeV; //of interval defining jets
00179 
00180       vector<FourMomentum> acceptJets;
00181       foreach (const Jet& jet, applyProjection<FastJets>(event, "AntiKtJets06").jetsByPt(20.0*GeV)) {
00182         if (fabs(jet.momentum().rapidity()) < 4.4) {
00183           acceptJets.push_back(jet.momentum());
00184         }
00185       }
00186 
00187       // If can't form an interval drop out of the analysis early
00188       if (acceptJets.size() < 2) {
00189         return;
00190       }
00191 
00192       // Analyze leading jet case
00193       if ((acceptJets[0].pT() + acceptJets[1].pT())/2.0 > minimumJetPtBar) {
00194         analyzeJets(acceptJets, m_selectionPlots[0], weight, 20.0*GeV);
00195       }
00196 
00197       // Re-order jets to have forward backward selection
00198       unsigned int minRapidityJet = 0;
00199       unsigned int maxRapidityJet = 0;
00200 
00201       for (size_t j=1; j<acceptJets.size(); j++) {
00202         if (acceptJets[j].rapidity() >
00203             acceptJets[maxRapidityJet].rapidity()) {
00204           maxRapidityJet=j;
00205         }
00206 
00207         if (acceptJets[j].rapidity() <
00208             acceptJets[minRapidityJet].rapidity()) {
00209           minRapidityJet=j;
00210         }
00211       }
00212 
00213       vector<FourMomentum> fwdBkwdJets;
00214       fwdBkwdJets.push_back(acceptJets[maxRapidityJet]);
00215       fwdBkwdJets.push_back(acceptJets[minRapidityJet]);
00216 
00217       for (size_t j=0; j<acceptJets.size(); j++) {
00218         if (j==minRapidityJet or j==maxRapidityJet){
00219           continue;
00220         }
00221         fwdBkwdJets.push_back(acceptJets[j]);
00222       }
00223 
00224       if ((fwdBkwdJets[0].pT() + fwdBkwdJets[1].pT())/2.0 > minimumJetPtBar) {
00225         //Use most forward/backward jets in rapidity to define the interval
00226         analyzeJets(fwdBkwdJets, m_selectionPlots[1], weight,
00227                     20.0*GeV);
00228 
00229         //As before but now using PtBar of interval to define veto threshold
00230         analyzeJets(fwdBkwdJets, m_selectionPlots[2], weight,
00231                     (fwdBkwdJets[0].pT()+fwdBkwdJets[1].pT())/2.0);
00232       }
00233     }
00234 
00235 
00236     // Fill plots!
00237     void analyzeJets(vector<FourMomentum>& jets, ATLAS_2011_S9126244_Plots& plots,
00238                      const double weight, double vetoPtThreshold){
00239       // Calculate the interval size, ptBar and veto Pt (if any)
00240       double intervalSize;
00241       double ptBar;
00242       double vetoPt = 0.0*GeV;
00243 
00244       intervalSize = fabs(jets[0].rapidity()-jets[1].rapidity());
00245       ptBar = (jets[0].pT()+jets[1].pT())/2.0;
00246 
00247       double minY;
00248       double maxY;
00249       if (jets[0].rapidity() > jets[1].rapidity()) {
00250         minY = jets[1].rapidity();
00251         maxY = jets[0].rapidity();
00252       } else {
00253         minY = jets[0].rapidity();
00254         maxY = jets[1].rapidity();
00255       }
00256 
00257       for (size_t j=2; j<jets.size(); j++){
00258         if (jets[j].rapidity() > minY &&
00259             jets[j].rapidity() < maxY &&
00260             jets[j].pT() > vetoPt){
00261           vetoPt = jets[j].pT();
00262         }
00263       }
00264 
00265       // Fill the gap fraction vs delta Y histograms
00266       plots._h_gapVsDeltaYInc.fill(ptBar/GeV, intervalSize, weight);
00267       if (vetoPt < vetoPtThreshold) {
00268         plots._h_gapVsDeltaYVeto.fill(ptBar/GeV, intervalSize, weight);
00269       }
00270 
00271       // Fill the gap fraction vs pt Bar histograms
00272       plots._h_gapVsPtBarInc.fill(intervalSize, ptBar/GeV,  weight);
00273       if (vetoPt < vetoPtThreshold) {
00274         plots._h_gapVsPtBarVeto.fill(intervalSize, ptBar/GeV, weight);
00275       }
00276 
00277       // Count the number of veto jets present
00278       int vetoJetsCount=0;
00279       for (size_t j=2; j<jets.size(); j++){
00280         if (jets[j].rapidity() > minY &&
00281             jets[j].rapidity() < maxY &&
00282             jets[j].pT() > vetoPtThreshold){
00283           vetoJetsCount += 1;
00284         }
00285       }
00286 
00287       // Fill the avg NJet, deltaY slices
00288       for (int i=0; i<(int)plots.m_avgNJetPtBarSlices.size()-1; i++) {
00289         if ( intervalSize >= plots.m_avgNJetPtBarSlices[i] &&
00290              intervalSize < plots.m_avgNJetPtBarSlices[i+1]) {
00291          plots._p_avgJetVsPtBar[i]->fill(ptBar/GeV, vetoJetsCount, weight);
00292         }
00293       }
00294 
00295       // Fill the avg NJet, ptBar slices
00296       for (int i=0; i<(int)plots.m_avgNJetDeltaYSlices.size()-1; i++) {
00297         if ( ptBar/GeV >= plots.m_avgNJetDeltaYSlices[i] &&
00298              ptBar/GeV < plots.m_avgNJetDeltaYSlices[i+1] ) {
00299           plots._p_avgJetVsDeltaY[i]->fill(intervalSize, vetoJetsCount, weight);
00300         }
00301       }
00302 
00303       // Fill the veto pt plots
00304       int q0PlotCount = 0;
00305       for (int x=0; x<((int)plots.m_gapFractionQ0SlicesPtBar.size()/2); x++) {
00306         for (int y=0; y<((int)plots.m_gapFractionQ0SlicesDeltaY.size()/2); y++) {
00307           // Check if it should be filled
00308           if ( ptBar/GeV < plots.m_gapFractionQ0SlicesPtBar[x*2] ||
00309                ptBar/GeV >= plots.m_gapFractionQ0SlicesPtBar[x*2+1] ) {
00310             q0PlotCount++;
00311             continue;
00312           }
00313 
00314           if ( intervalSize < plots.m_gapFractionQ0SlicesDeltaY[y*2] ||
00315                intervalSize >= plots.m_gapFractionQ0SlicesDeltaY[y*2+1] ) {
00316             q0PlotCount++;
00317             continue;
00318           }
00319 
00320           plots._h_vetoPt[q0PlotCount]->fill(vetoPt, weight);
00321           plots._h_vetoPtTotalSum[q0PlotCount] += weight;
00322 
00323           q0PlotCount++;
00324         }
00325       }
00326     }
00327 
00328 
00329     /// Derive final distributions for each selection
00330     void finalize() {
00331       foreach (const ATLAS_2011_S9126244_Plots& plots, m_selectionPlots) {
00332         // Calculate the gap fraction for each slice
00333         for (size_t x = 0; x < plots._h_gapVsDeltaYVeto.getHistograms().size(); x++) {
00334           histogramFactory().divide(histoPath(makeAxisCode(plots.m_gapFractionDeltaYHistIndex+x, 1, plots.selectionType)),
00335                                     *(plots._h_gapVsDeltaYVeto.getHistograms()[x]),
00336                                     *(plots._h_gapVsDeltaYInc.getHistograms()[x]));
00337           histogramFactory().destroy(plots._h_gapVsDeltaYVeto.getHistograms()[x]);
00338           histogramFactory().destroy(plots._h_gapVsDeltaYInc.getHistograms()[x]);
00339         }
00340 
00341         for (size_t x = 0; x < plots._h_gapVsPtBarVeto.getHistograms().size(); x++) {
00342           histogramFactory().divide(histoPath(makeAxisCode(plots.m_gapFractionPtBarHistIndex+x, 1, plots.selectionType)),
00343                                     *(plots._h_gapVsPtBarVeto.getHistograms()[x]),
00344                                     *(plots._h_gapVsPtBarInc.getHistograms()[x]));
00345           histogramFactory().destroy(plots._h_gapVsPtBarVeto.getHistograms()[x]);
00346           histogramFactory().destroy(plots._h_gapVsPtBarInc.getHistograms()[x]);
00347         }
00348 
00349         for (size_t h = 0; h < plots._d_vetoPtGapFraction.size(); h++) {
00350           // Get the number of bins needed for this slice
00351           const BinEdges q0Edges = binEdges(plots.m_gapFractionQ0HistIndex+h, 1, plots.selectionType);
00352           finalizeQ0GapFraction(plots._h_vetoPtTotalSum[h],
00353                                 plots._d_vetoPtGapFraction[h],
00354                                 plots._h_vetoPt[h],
00355                                 q0Edges.size());
00356         }
00357       }
00358     }
00359 
00360 
00361     void finalizeQ0GapFraction(double totalWeightSum,
00362                                AIDA::IDataPointSet* gapFractionDP,
00363                                AIDA::IHistogram1D* vetoPtHist,
00364                                int binNumber) {
00365       double vetoPtWeightSum = 0.0;
00366       for (int x = 0; x < binNumber-1; x++) {
00367         vetoPtWeightSum += vetoPtHist->binHeight(x);
00368 
00369         // Alternatively try saving as data points
00370         IDataPoint* currentPoint = gapFractionDP->point(x);
00371         IMeasurement* xCoord = currentPoint->coordinate(0);
00372         IMeasurement* yCoord = currentPoint->coordinate(1);
00373 
00374         // Calculate the efficiency uncertainty
00375         double efficiency = vetoPtWeightSum/totalWeightSum;
00376         double efficiencyError = std::sqrt(efficiency*(1.0-efficiency)/totalWeightSum);
00377         if (totalWeightSum==0.) efficiency = efficiencyError = 0.;
00378 
00379         xCoord->setValue(m_q0BinEdges[x+1]);
00380         xCoord->setErrorPlus(2.5);
00381         xCoord->setErrorMinus(2.5);
00382         yCoord->setValue(efficiency);
00383         yCoord->setErrorPlus(efficiencyError);
00384         yCoord->setErrorMinus(efficiencyError);
00385       }
00386       histogramFactory().destroy(vetoPtHist);
00387     }
00388 
00389 
00390   private:
00391 
00392     // Only need to define the q0 binning here
00393     std::vector<double> m_q0BinEdges;
00394 
00395 
00396   private:
00397 
00398     // Structure containing complete set of plots
00399     ATLAS_2011_S9126244_Plots m_selectionPlots[3];
00400 
00401   };
00402 
00403 
00404 
00405   // The hook for the plugin system
00406   DECLARE_RIVET_PLUGIN(ATLAS_2011_S9126244);
00407 
00408 }