Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:20:51

0001 #include "TFile.h"
0002 #include "TChain.h"
0003 #include "TH2F.h"
0004 #include "TCanvas.h"
0005 #include "TStyle.h"
0006 #include "TRegexp.h"
0007 #include "TGraphErrors.h"
0008 #include "iostream"
0009 #include "vector"
0010 #include "map"
0011 #include "TTreeFormula.h"
0012 #include "GetOptimization.h"
0013 
0014 struct filter {
0015   TString name;
0016   Int_t pathNum;
0017   Int_t direction; // -1: <, 0: bool, 1: >
0018   Double_t hltBarrelCut;
0019   Double_t hltEndcapCut;
0020   Double_t maxCut;
0021 };
0022 
0023 struct path {
0024   std::vector<TString> names;
0025   Int_t nCandsCut;
0026   std::vector<filter> filters;
0027 };
0028 
0029 void GetOptimization() {
0030   struct path thisPath;
0031   std::vector<path> paths;
0032   std::vector<TString> pathNames;
0033   struct filter thisFilter;
0034   std::vector<filter> filters;
0035   std::vector<std::pair<std::vector<TString>,Double_t> > xSections;
0036   std::vector<TString> filenamesBkg;
0037   std::vector<TString> filenamesSig;
0038   /* Parameters */
0039   Int_t nCuts = 120;
0040   Bool_t doBandE = true; // if true, do seperate for cuts in barrel and endcap
0041 
0042   Double_t luminosity = 2.0E33; // in cm^-2 s^-1
0043 
0044   // Cross-sections in mb
0045   filenamesBkg.push_back("../test/QCD-HLTVars-1.root");
0046   // filenamesBkg.push_back("sameXSection");
0047   xSections.push_back(make_pair(filenamesBkg, 2.16E-2));
0048   filenamesBkg.clear();
0049   // filenamesBkg.push_back("newXSection.root");
0050   // ...
0051   // xSections.push_back(make_pair(filenamesBkg, xSection));
0052   // filenamesBkg.clear();
0053   filenamesSig.push_back("../test/ZEE-HLTVars.root");
0054   /* ********** */
0055   // Filters
0056   thisFilter.name = "l1Match";
0057   thisFilter.pathNum = 0;
0058   thisFilter.direction =  0;
0059   thisFilter.hltBarrelCut = 0.;
0060   thisFilter.hltEndcapCut = 0.;
0061   thisFilter.maxCut = 0.;
0062   filters.push_back(thisFilter);
0063   thisFilter.name = "Et";
0064   thisFilter.pathNum = 0;
0065   thisFilter.direction = 1;
0066   thisFilter.hltBarrelCut = 15.;
0067   thisFilter.hltEndcapCut = 15.;
0068   thisFilter.maxCut = 60.;
0069   filters.push_back(thisFilter);
0070   thisFilter.name = "IHcal";
0071   thisFilter.pathNum = 0;
0072   thisFilter.direction = -1;
0073   thisFilter.hltBarrelCut = 3.;
0074   thisFilter.hltEndcapCut = 3.;
0075   thisFilter.maxCut = 6.;
0076   filters.push_back(thisFilter);
0077   thisFilter.name = "pixMatch";
0078   thisFilter.pathNum = 0;
0079   thisFilter.direction = 1;
0080   thisFilter.hltBarrelCut = 0;
0081   thisFilter.hltEndcapCut = 0;
0082   thisFilter.maxCut = 0;
0083   filters.push_back(thisFilter);
0084   thisFilter.name = "Eoverp";
0085   thisFilter.pathNum = 1;
0086   thisFilter.direction = -1;
0087   thisFilter.hltBarrelCut = 1.5;
0088   thisFilter.hltEndcapCut = 2.45;
0089   thisFilter.maxCut = 5.;
0090   filters.push_back(thisFilter);
0091   thisFilter.name = "Itrack";
0092   thisFilter.pathNum = 1;
0093   thisFilter.direction = -1;
0094   thisFilter.hltBarrelCut = 0.06;
0095   thisFilter.hltEndcapCut = 0.06;
0096   thisFilter.maxCut = 0.24;
0097   filters.push_back(thisFilter);
0098   pathNames.push_back("SingleElecsPT.");
0099   pathNames.push_back("SingleElecs.");
0100   thisPath.names = pathNames;
0101   thisPath.nCandsCut = 1;
0102   thisPath.filters = filters;
0103   paths.push_back(thisPath);
0104   pathNames.clear(); 
0105   pathNames.push_back("RelaxedSingleElecsPT.");
0106   pathNames.push_back("RelaxedSingleElecs.");
0107   thisPath.names = pathNames;
0108   thisPath.nCandsCut = 1;
0109   thisPath.filters = filters;
0110   paths.push_back(thisPath);
0111   pathNames.clear();
0112   filters.clear();
0113 
0114   thisFilter.name = "l1Match";
0115   thisFilter.pathNum = 0;
0116   thisFilter.direction =  0;
0117   thisFilter.hltBarrelCut = 0.;
0118   thisFilter.hltEndcapCut = 0.;
0119   thisFilter.maxCut = 0.;
0120   filters.push_back(thisFilter);
0121   thisFilter.name = "Et";
0122   thisFilter.pathNum = 0;
0123   thisFilter.direction = 1;
0124   thisFilter.hltBarrelCut = 10.;
0125   thisFilter.hltEndcapCut = 10.;
0126   thisFilter.maxCut = 40.;
0127   filters.push_back(thisFilter);
0128   thisFilter.name = "IHcal";
0129   thisFilter.pathNum = 0;
0130   thisFilter.direction = -1;
0131   thisFilter.hltBarrelCut = 9.;
0132   thisFilter.hltEndcapCut = 9.;
0133   thisFilter.maxCut = 18.;
0134   filters.push_back(thisFilter);
0135   thisFilter.name = "pixMatch";
0136   thisFilter.pathNum = 0;
0137   thisFilter.direction = 1;
0138   thisFilter.hltBarrelCut = 0;
0139   thisFilter.hltEndcapCut = 0;
0140   thisFilter.maxCut = 0;
0141   filters.push_back(thisFilter);
0142   thisFilter.name = "Eoverp";
0143   thisFilter.pathNum = 1;
0144   thisFilter.direction = -1;
0145   thisFilter.hltBarrelCut = 15000;
0146   thisFilter.hltEndcapCut = 24500;
0147   thisFilter.maxCut = 5.;
0148   filters.push_back(thisFilter);
0149   thisFilter.name = "Itrack";
0150   thisFilter.pathNum = 1;
0151   thisFilter.direction = -1;
0152   thisFilter.hltBarrelCut = 0.4;
0153   thisFilter.hltEndcapCut = 0.4;
0154   thisFilter.maxCut = 0.12;
0155   filters.push_back(thisFilter);
0156   pathNames.push_back("DoubleElecsPT.");
0157   pathNames.push_back("DoubleElecs.");
0158   thisPath.names = pathNames;
0159   thisPath.nCandsCut = 2;
0160   thisPath.filters = filters;
0161   paths.push_back(thisPath);
0162   pathNames.clear(); 
0163   pathNames.push_back("RelaxedDoubleElecsPT.");
0164   pathNames.push_back("RelaxedDoubleElecs.");
0165   thisPath.names = pathNames;
0166   thisPath.nCandsCut = 2;
0167   thisPath.filters = filters;
0168   paths.push_back(thisPath);
0169   pathNames.clear();
0170   filters.clear();
0171 
0172   thisFilter.name = "l1Match";
0173   thisFilter.pathNum = 0;
0174   thisFilter.direction =  0;
0175   thisFilter.hltBarrelCut = 0.;
0176   thisFilter.hltEndcapCut = 0.;
0177   thisFilter.maxCut = 0.;
0178   filters.push_back(thisFilter);
0179   thisFilter.name = "Et";
0180   thisFilter.pathNum = 0;
0181   thisFilter.direction = 1;
0182   thisFilter.hltBarrelCut = 30.;
0183   thisFilter.hltEndcapCut = 30.;
0184   thisFilter.maxCut = 60.;
0185   filters.push_back(thisFilter);
0186   thisFilter.name = "IEcal";
0187   thisFilter.pathNum = 0;
0188   thisFilter.direction = -1;
0189   thisFilter.hltBarrelCut = 1.5;
0190   thisFilter.hltEndcapCut = 1.5;
0191   thisFilter.maxCut = 6.;
0192   filters.push_back(thisFilter);
0193   thisFilter.name = "IHcal";
0194   thisFilter.pathNum = 0;
0195   thisFilter.direction = -1;
0196   thisFilter.hltBarrelCut = 4.;
0197   thisFilter.hltEndcapCut = 6.;
0198   thisFilter.maxCut = 12.;
0199   filters.push_back(thisFilter);
0200   thisFilter.name = "Itrack";
0201   thisFilter.pathNum = 0;
0202   thisFilter.direction = -1;
0203   thisFilter.hltBarrelCut = 1;
0204   thisFilter.hltEndcapCut = 1;
0205   thisFilter.maxCut = 5;
0206   filters.push_back(thisFilter);
0207   pathNames.push_back("SinglePhots.");
0208   thisPath.names = pathNames;
0209   thisPath.nCandsCut = 1;
0210   thisPath.filters = filters;
0211   paths.push_back(thisPath);
0212   pathNames.clear(); 
0213   pathNames.push_back("RelaxedSinglePhots.");
0214   thisPath.names = pathNames;
0215   thisPath.nCandsCut = 1;
0216   thisPath.filters = filters;
0217   paths.push_back(thisPath);
0218   pathNames.clear();
0219   filters.clear();
0220 
0221   thisFilter.name = "l1Match";
0222   thisFilter.pathNum = 0;
0223   thisFilter.direction =  0;
0224   thisFilter.hltBarrelCut = 0.;
0225   thisFilter.hltEndcapCut = 0.;
0226   thisFilter.maxCut = 0.;
0227   filters.push_back(thisFilter);
0228   thisFilter.name = "Et";
0229   thisFilter.pathNum = 0;
0230   thisFilter.direction = 1;
0231   thisFilter.hltBarrelCut = 20.;
0232   thisFilter.hltEndcapCut = 20.;
0233   thisFilter.maxCut = 40.;
0234   filters.push_back(thisFilter);
0235   thisFilter.name = "IEcal";
0236   thisFilter.pathNum = 0;
0237   thisFilter.direction = -1;
0238   thisFilter.hltBarrelCut = 2.5;
0239   thisFilter.hltEndcapCut = 2.5;
0240   thisFilter.maxCut = 5.;
0241   filters.push_back(thisFilter);
0242   thisFilter.name = "IHcal";
0243   thisFilter.pathNum = 0;
0244   thisFilter.direction = -1;
0245   thisFilter.hltBarrelCut = 6.;
0246   thisFilter.hltEndcapCut = 8.;
0247   thisFilter.maxCut = 24.;
0248   filters.push_back(thisFilter);
0249   thisFilter.name = "Itrack";
0250   thisFilter.pathNum = 0;
0251   thisFilter.direction = -1;
0252   thisFilter.hltBarrelCut = 3;
0253   thisFilter.hltEndcapCut = 3;
0254   thisFilter.maxCut = 6;
0255   filters.push_back(thisFilter);
0256   pathNames.push_back("DoublePhots.");
0257   thisPath.names = pathNames;
0258   thisPath.nCandsCut = 2;
0259   thisPath.filters = filters;
0260   paths.push_back(thisPath);
0261   pathNames.clear(); 
0262   pathNames.push_back("RelaxedDoublePhots.");
0263   thisPath.names = pathNames;
0264   thisPath.nCandsCut = 2;
0265   thisPath.filters = filters;
0266   paths.push_back(thisPath);
0267   pathNames.clear();
0268   filters.clear();
0269 
0270   /* *********** */
0271 
0272   Int_t cutNum = 0, pathNum = 0, filterNum = 0, oldFilterNum = 0, fileNum = 0, xSecNum = 0;
0273   Double_t cut = 0.;
0274   Long64_t passSig = 0, totalSig = 0;
0275   Long64_t passBkg = 0, totalBkg = 0;
0276   Double_t effSig = 0., errSig = 0.;
0277   Double_t effBkg = 0., errBkg = 0., rateTotBkg = 0., errTotBkg = 0.;
0278   Double_t conversion = 1.0E-27;
0279   std::vector<std::pair<Double_t,Double_t> > sigPass;
0280   std::vector<std::pair<Double_t,Double_t> > bkgPass;
0281 
0282   TString cutText;
0283   TString cutTextEcap;
0284   TString baseCutText;
0285   TString baseCutTextEcap;
0286   TString cutBasePT1;
0287   TString cutBasePT2;
0288   TString cutBase1;
0289   TString cutBase2;
0290   //  cutBasePT1 = "ElecHLTCutVarsPreTracks_hltCutVars_";
0291   //  cutBasePT2 = "ElecsPT_EGAMMAHLT.obj.";
0292   //  cutBase1 = "";
0293   //  cutBase2 = "Elecs_EGAMMAHLT.obj.";
0294 
0295   std::vector<std::vector<TGraphErrors> > EffVBkg;
0296   std::vector<std::vector<TGraphErrors> > EffVBkgEcap;
0297   std::vector<TGraphErrors> pathEffVBkgs;
0298   TGraphErrors filterEffVBkgs(nCuts);
0299   for (pathNum = 0; pathNum < paths.size(); pathNum++) {
0300     for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) {
0301       //      filterEffVBkgs = new TGraphErrors(nCuts);
0302       pathEffVBkgs.push_back(filterEffVBkgs);
0303     }
0304     EffVBkg.push_back(pathEffVBkgs);
0305     if (doBandE) {
0306       EffVBkgEcap.push_back(pathEffVBkgs);
0307     }
0308   }
0309 
0310   std::vector<std::pair<TChain*,Double_t> > bkgEvents;
0311   for (xSecNum = 0; xSecNum < xSections.size(); xSecNum++) {
0312     TChain *bkgProc = new TChain("Events");
0313     for (fileNum = 0; fileNum < (xSections[xSecNum].first).size(); fileNum++) {
0314       bkgProc->Add((xSections[xSecNum].first)[fileNum]);
0315     }
0316     bkgEvents.push_back(make_pair(bkgProc,xSections[xSecNum].second));
0317   }
0318 
0319   TChain *sigEvents = new TChain("Events");
0320   for (fileNum = 0; fileNum < filenamesSig.size(); fileNum++) {
0321     sigEvents->Add(filenamesSig[fileNum]);
0322   }
0323 
0324   Double_t testX, testY, testdX, testdY;
0325   Double_t thisBCut = 0., thisECut = 0.;
0326   TString pathName, filterName;
0327   for (cutNum = 0; cutNum < nCuts; cutNum++) {
0328     cout<<"Cut "<<cutNum<<endl;
0329     for (pathNum = 0; pathNum < paths.size(); pathNum++) {
0330       for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) {
0331     if ((paths[pathNum].filters)[filterNum].maxCut != 0.) {
0332       cutText = "(Sum$(";
0333       for (oldFilterNum = 0; oldFilterNum < filterNum; oldFilterNum++) { 
0334         pathName = (paths[pathNum].names)[(paths[pathNum].filters)[filterNum].pathNum];
0335         filterName = (paths[pathNum].filters)[oldFilterNum].name;
0336         thisBCut = (paths[pathNum].filters)[oldFilterNum].hltBarrelCut;
0337         thisECut = (paths[pathNum].filters)[oldFilterNum].hltEndcapCut;
0338         if (thisBCut == thisECut) {
0339           cutText += pathName;
0340           cutText += filterName;
0341           switch ((paths[pathNum].filters)[oldFilterNum].direction) {
0342           case -1:
0343             cutText += " < ";
0344             cutText += (paths[pathNum].filters)[oldFilterNum].hltBarrelCut;
0345             break;
0346           case 0:
0347             break;
0348           case 1:
0349             cutText += " > ";
0350             cutText += (paths[pathNum].filters)[oldFilterNum].hltBarrelCut;
0351             break;
0352           default:
0353             cout<<"Invalid value of direction in "<<pathName<<filterName<<endl;
0354             break;
0355           }
0356         }
0357         else {
0358           cutText += "((";
0359           cutText += pathName;
0360           cutText += filterName;
0361               switch ((paths[pathNum].filters)[oldFilterNum].direction) {
0362           case -1:
0363             cutText += " < ";
0364             cutText += thisBCut;
0365             break;
0366           case 0:
0367             break;
0368           case 1:
0369             cutText += " > ";
0370             cutText += thisBCut;
0371             break;
0372           default:
0373             cout<<"Invalid value of direction in "<<pathName<<filterName<<endl;
0374             break;
0375           }
0376           cutText += " && abs(";
0377           cutText += pathName;
0378           cutText += "eta) < 1.5) || (";
0379           cutText += pathName;
0380           cutText += filterName;
0381           switch ((paths[pathNum].filters)[oldFilterNum].direction) {
0382               case -1:
0383                 cutText += " < ";
0384                 cutText += thisECut;
0385                 break;
0386               case 0:
0387                 break;
0388               case 1:
0389                 cutText += " > ";
0390                 cutText += thisECut;
0391                 break;
0392               default:
0393                 cout<<"Invalid value of direction in "<<pathName<<filterName<<endl;
0394                 break;
0395               }
0396           cutText += " && abs(";
0397               cutText += pathName;
0398               cutText += "eta) > 1.5 && abs(";
0399           cutText += pathName;
0400           cutText += "eta) < 2.5))";
0401         }
0402         if (oldFilterNum != filterNum - 1) cutText += " && ";
0403       }
0404       baseCutText = cutText;
0405       pathName = paths[pathNum].names[(paths[pathNum].filters)[filterNum].pathNum];
0406       filterName = (paths[pathNum].filters)[filterNum].name;
0407       cutText += " && ";
0408       cutText += pathName;
0409       cutText += filterName;
0410       cut = (Double_t)cutNum / (Double_t)nCuts * (paths[pathNum].filters)[oldFilterNum].maxCut;
0411       switch ((paths[pathNum].filters)[filterNum].direction) {
0412       case -1:
0413         cutText += " < ";
0414         cutText += cut;
0415         break;
0416       case 0:
0417         break;
0418       case 1:
0419         cutText += " > ";
0420         cutText += cut;
0421         break;
0422       default:
0423         cout<<"Invalid value of direction in "<<pathName<<filterName<<endl;
0424         break;
0425       }
0426       if (doBandE) {
0427         cutTextEcap = cutText;
0428         cutText += " && abs(";
0429         cutText += pathName;
0430         cutText += "eta) < 1.5";
0431         cutTextEcap += " && abs(";
0432         cutTextEcap += pathName;
0433         cutTextEcap += "eta) > 1.5 && abs(";
0434         cutTextEcap += pathName;
0435         cutTextEcap += ") < 2.5";
0436         baseCutText += " && abs(";
0437         baseCutText += pathName;
0438         baseCutTextEcap = baseCutText;
0439         baseCutText += "eta) < 1.5";
0440         baseCutTextEcap += "eta) > 1.5 && abs(";
0441         baseCutTextEcap += pathName;
0442         baseCutTextEcap += "eta) < 2.5";
0443       }
0444       cutText += ") >= ";
0445       cutText += paths[pathNum].nCandsCut;
0446       cutText += ")";
0447       cutTextEcap += ") >= ";
0448       cutTextEcap += paths[pathNum].nCandsCut;
0449       cutTextEcap += ")";
0450       baseCutText += ") >= ";
0451       baseCutText += paths[pathNum].nCandsCut;
0452       baseCutText += ")";
0453       baseCutTextEcap += ") >= ";
0454       baseCutTextEcap += paths[pathNum].nCandsCut;
0455       baseCutTextEcap += ")";
0456    
0457       cout<<cutText<<endl;
0458       cout<<cutTextEcap<<endl;
0459       //      cout<<cutText<<endl;
0460       //      cout<<baseCutText<<endl;
0461       passSig = sigEvents->Draw("",cutText);
0462       totalSig = sigEvents->Draw("",baseCutText);
0463       if (totalSig != 0) {
0464         effSig = (Double_t)passSig / (Double_t)totalSig;
0465         errSig = sqrt(effSig * (1. - effSig) / (Double_t)totalSig);
0466       }
0467       else {
0468         effSig = 0.;
0469         errSig = 0.;
0470       }
0471       rateTotBkg = 0.;
0472       errTotBkg = 0.;
0473       for (xSecNum = 0; xSecNum < bkgEvents.size(); xSecNum++) {
0474         passBkg = bkgEvents[xSecNum].first->Draw("",cutText);
0475         totalBkg = bkgEvents[xSecNum].first->Draw("","");
0476         if (totalBkg != 0) {
0477           effBkg = (Double_t)passBkg / (Double_t)totalBkg;
0478           errBkg = sqrt(effBkg * (1. - effBkg) / (Double_t)totalBkg);
0479         }
0480         else {
0481           effBkg = 0.;
0482           errBkg = 0.;
0483         }
0484         rateTotBkg += effBkg * bkgEvents[xSecNum].second * luminosity * conversion;
0485         errTotBkg = sqrt(errTotBkg * errTotBkg + errBkg * errBkg * bkgEvents[xSecNum].second * luminosity * conversion * bkgEvents[xSecNum].second * luminosity * conversion);
0486       }
0487         
0488       if (cutNum == 6) {
0489         cout<<cutText<<endl;
0490         cout<<rateTotBkg<<" +- "<<errTotBkg<<", "<<effSig<<" +- "<<errSig<<endl;;
0491       }
0492       EffVBkg[pathNum][filterNum].SetPoint(cutNum, rateTotBkg, effSig);
0493       EffVBkg[pathNum][filterNum].SetPointError(cutNum, errTotBkg, errSig);
0494       if (cutNum == 6) {
0495         EffVBkg[pathNum][filterNum].GetPoint(cutNum, testX, testY);
0496         cout<<testX<<", "<<testY<<endl;
0497       }
0498 
0499       if (doBandE) {
0500         passSig = sigEvents->Draw("",cutTextEcap);
0501         totalSig = sigEvents->Draw("",baseCutText);
0502         if (totalSig != 0) {
0503           effSig = (Double_t)passSig / (Double_t)totalSig;
0504           errSig = sqrt(effSig * (1. - effSig) / (Double_t)totalSig);
0505         }
0506         else {
0507           effSig = 0.;
0508           errSig = 0.;
0509         }
0510         rateTotBkg = 0.;
0511         errTotBkg = 0.;
0512         for (xSecNum = 0; xSecNum < bkgEvents.size(); xSecNum++) {
0513           passBkg = bkgEvents[xSecNum].first->Draw("",cutText);
0514           totalBkg = bkgEvents[xSecNum].first->Draw("","");
0515           if (totalBkg != 0) {
0516         effBkg = (Double_t)passBkg / (Double_t)totalBkg;
0517         errBkg = sqrt(effBkg * (1. - effBkg) / (Double_t)totalBkg);
0518           }
0519           else {
0520         effBkg = 0.;
0521         errBkg = 0.;
0522           }
0523           rateTotBkg += effBkg * bkgEvents[xSecNum].second * luminosity * conversion;
0524           errTotBkg = sqrt(errTotBkg * errTotBkg + errBkg * errBkg * bkgEvents[xSecNum].second * luminosity * conversion * bkgEvents[xSecNum].second * luminosity * conversion);
0525         }
0526         
0527         if (cutNum == 6) {
0528           cout<<cutText<<endl;
0529           cout<<rateTotBkg<<" +- "<<errTotBkg<<", "<<effSig<<" +- "<<errSig<<endl;;
0530         }
0531         EffVBkgEcap[pathNum][filterNum].SetPoint(cutNum, rateTotBkg, effSig);
0532         EffVBkgEcap[pathNum][filterNum].SetPointError(cutNum, errTotBkg, errSig);
0533         if (cutNum == 6) {
0534           EffVBkg[pathNum][filterNum].GetPoint(cutNum, testX, testY);
0535           cout<<testX<<", "<<testY<<endl;
0536         }
0537       }
0538     }
0539       }
0540     }
0541   }
0542   TCanvas *myCanvas;
0543   TString tempPathName, canvasTitle, graphTitle, outFilename;
0544   Int_t n;
0545   Int_t nGraphs, curGraph;
0546   for (pathNum = 0; pathNum < paths.size(); pathNum++) {
0547     canvasTitle = "Efficiency vs. Background for ";
0548     tempPathName = paths[pathNum].names[paths[pathNum].filters[(paths[pathNum].filters).size()-1].pathNum];
0549     tempPathName.Resize(tempPathName.Index(".", 1, 0, TString::kExact));
0550     outFilename = "./images/";
0551     outFilename += tempPathName;
0552     outFilename += "EffVBkg.gif";
0553     n = 0;
0554     while (tempPathName.Contains(TRegexp("[a-z][A-Z]")) && n < 10) {
0555       tempPathName.Insert(tempPathName.Index(TRegexp("[a-z][A-Z]"))+1, " ");
0556       n++;
0557     }
0558     canvasTitle += tempPathName;
0559     nGraphs = 0;
0560     for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) {
0561       if ((paths[pathNum].filters)[filterNum].maxCut != 0) nGraphs++;
0562     }
0563     myCanvas = new TCanvas("myCanvas", canvasTitle, 0, 0, 1000, 500*(nGraphs / 2 + 1));
0564     myCanvas->Divide(2,nGraphs / 2 + 1);
0565     curGraph = 0;
0566     for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) {
0567       if ((paths[pathNum].filters)[filterNum].maxCut != 0.) {
0568         myCanvas->cd(curGraph+1);
0569     curGraph++;
0570         graphTitle = "Efficiency vs. Background for ";
0571     graphTitle += (paths[pathNum].filters)[filterNum].name;
0572     graphTitle += " Filter;Background Rate (Hz);Signal Eff.";
0573     EffVBkg[pathNum][filterNum].SetTitle(graphTitle);
0574     EffVBkg[pathNum][filterNum].Draw("AP");
0575       }
0576     }
0577     myCanvas->Print(outFilename);
0578     if (doBandE) {
0579       canvasTitle = "Efficiency vs. Background for ";
0580       tempPathName = paths[pathNum].names[paths[pathNum].filters[(paths[pathNum].filters).size()-1].pathNum];
0581       tempPathName.Resize(tempPathName.Index(".", 1, 0, TString::kExact));
0582       tempPathName += "Endcap";
0583       outFilename = "./images/";
0584       outFilename += tempPathName;
0585       outFilename += "EffVBkg.gif";
0586       n = 0;
0587       while (tempPathName.Contains(TRegexp("[a-z][A-Z]")) && n < 10) {
0588     tempPathName.Insert(tempPathName.Index(TRegexp("[a-z][A-Z]"))+1, " ");
0589     n++;
0590       }
0591       canvasTitle += tempPathName;
0592       nGraphs = 0;
0593       for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) {
0594     if ((paths[pathNum].filters)[filterNum].maxCut != 0) nGraphs++;
0595       }
0596       myCanvas = new TCanvas("myCanvas", canvasTitle, 0, 0, 1000, 500*(nGraphs / 2 + 1));
0597       myCanvas->Divide(2,nGraphs / 2 + 1);
0598       curGraph = 0;
0599       for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) {
0600     if ((paths[pathNum].filters)[filterNum].maxCut != 0.) {
0601       myCanvas->cd(curGraph+1);
0602       curGraph++;
0603       graphTitle = "Efficiency vs. Background for ";
0604       graphTitle += (paths[pathNum].filters)[filterNum].name;
0605       graphTitle += " Filter in Endcap;Background Rate (Hz);Signal Eff.";
0606       EffVBkgEcap[pathNum][filterNum].SetTitle(graphTitle);
0607       EffVBkgEcap[pathNum][filterNum].Draw("AP");
0608     }
0609       }
0610       myCanvas->Print(outFilename);
0611     }
0612   }
0613 
0614   TH1F *timingSig = new TH1F("timingSig", "Timing of Single Electron Filters in Signal Events", 6, 0, 6);
0615   timingSig->SetCanExtend(TH1::kAllAxes);
0616   timingSig->SetStats(0);
0617   TTreeFormula *l1MatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.l1Match",sigEvents);
0618   TTreeFormula *EtTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Et",sigEvents);
0619   TTreeFormula *IHcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.ElecIHcal",sigEvents);
0620   TTreeFormula *pixMatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.pixMatch",sigEvents);
0621   TTreeFormula *EoverpTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Eoverp",sigEvents);
0622   TTreeFormula *ItrackTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.ElecItrack",sigEvents);
0623   Long64_t event = 0;
0624   Double_t avgL1Match = 0.;
0625   Double_t avgEt = 0.;
0626   Double_t avgIHcal = 0.;
0627   Double_t avgPixMatch = 0.;
0628   Double_t avgEoverp = 0.;
0629   Double_t avgItrack = 0.;
0630   for (event = 0; event < sigEvents->GetEntries(); event++) {
0631     sigEvents->LoadTree(event);
0632     avgL1Match = (event*avgL1Match + l1MatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0633     avgEt = (event*avgEt + EtTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0634     avgIHcal = (event*avgIHcal + IHcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0635     avgPixMatch = (event*avgPixMatch + pixMatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0636     avgEoverp = (event*avgEoverp + EoverpTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0637     avgItrack = (event*avgItrack + ItrackTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0638   }
0639   timingSig->Fill("L1 Match", avgL1Match);
0640   timingSig->Fill("Et", avgEt); 
0641   timingSig->Fill("IHcal", avgIHcal); 
0642   timingSig->Fill("Pix Match", avgPixMatch); 
0643   timingSig->Fill("E/p", avgEoverp); 
0644   timingSig->Fill("Itrack", avgItrack); 
0645   timingSig->LabelsDeflate("X");
0646   timingSig->LabelsOption("v");
0647 
0648   TH1F *timingBkg = new TH1F("timingBkg", "Timing of Single Electron Filters in Background Events", 6, 0, 6);
0649   timingBkg->SetCanExtend(TH1::kAllAxes);
0650   timingBkg->SetStats(0);
0651   avgL1Match = 0.;
0652   avgEt = 0.;
0653   avgIHcal = 0.;
0654   avgPixMatch = 0.;
0655   avgEoverp = 0.;
0656   avgItrack = 0.;
0657   for (xSecNum = 0; xSecNum < bkgEvents.size(); xSecNum++) {
0658     delete l1MatchTiming; l1MatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.l1Match",bkgEvents[xSecNum].first);
0659     delete EtTiming; EtTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Et",bkgEvents[xSecNum].first);
0660     delete IHcalTiming; IHcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.ElecIHcal",bkgEvents[xSecNum].first);
0661     delete pixMatchTiming; pixMatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.pixMatch",bkgEvents[xSecNum].first);
0662     delete EoverpTiming; EoverpTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Eoverp",bkgEvents[xSecNum].first);
0663     delete ItrackTiming; ItrackTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.ElecItrack",bkgEvents[xSecNum].first);
0664     event = 0;
0665     for (event = 0; event <  bkgEvents[xSecNum].first->GetEntries(); event++) {
0666       bkgEvents[xSecNum].first->LoadTree(event);
0667       avgL1Match = (event*avgL1Match + l1MatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0668       avgEt = (event*avgEt + EtTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0669       avgIHcal = (event*avgIHcal + IHcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0670       avgPixMatch = (event*avgPixMatch + pixMatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0671       avgEoverp = (event*avgEoverp + EoverpTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0672       avgItrack = (event*avgItrack + ItrackTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0673     }
0674   }
0675   timingBkg->Fill("L1 Match", avgL1Match);
0676   timingBkg->Fill("Et", avgEt); 
0677   timingBkg->Fill("IHcal", avgIHcal); 
0678   timingBkg->Fill("Pix Match", avgPixMatch); 
0679   timingBkg->Fill("E/p", avgEoverp); 
0680   timingBkg->Fill("Itrack", avgItrack); 
0681   timingBkg->LabelsDeflate("X");
0682   timingBkg->LabelsOption("v");
0683 
0684   myCanvas = new TCanvas("myCanvas", "Timing vs. Filter for Isolated Electron Filters", 1000, 500);
0685   myCanvas->Divide(2,1);
0686   myCanvas->cd(1);
0687   timingSig->Draw();
0688   myCanvas->cd(2);
0689   timingBkg->Draw();
0690   myCanvas->Print("images/TimingIso.gif");
0691   delete myCanvas;
0692   delete timingSig;
0693   delete timingBkg;
0694 
0695   timingSig = new TH1F("timingSig", "Timing of Single Photon Filters in Signal Events", 6, 0, 6);
0696   timingSig->SetCanExtend(TH1::kAllAxes);
0697   timingSig->SetStats(0);
0698   delete l1MatchTiming; l1MatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.l1Match",sigEvents);
0699   delete EtTiming; EtTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Et",sigEvents);
0700   TTreeFormula *IEcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.IEcal",sigEvents);
0701   TTreeFormula *PhotIHcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.PhotIHcal",sigEvents);
0702   TTreeFormula *PhotItrackTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.PhotItrack",sigEvents);
0703   event = 0;
0704   avgL1Match = 0.;
0705   avgEt = 0.;
0706   Double_t avgIEcal = 0.;
0707   Double_t avgPhotIHcal = 0.;
0708   Double_t avgPhotItrack = 0.;
0709   for (event = 0; event < sigEvents->GetEntries(); event++) {
0710     sigEvents->LoadTree(event);
0711     avgL1Match = (event*avgL1Match + l1MatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0712     avgEt = (event*avgEt + EtTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0713     avgIEcal = (event*avgIEcal + IEcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0714     avgPhotIHcal = (event*avgPhotIHcal + PhotIHcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0715     avgPhotItrack = (event*avgPhotItrack + PhotItrackTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0716   }
0717   timingSig->Fill("L1 Match", avgL1Match);
0718   timingSig->Fill("Et", avgEt); 
0719   timingSig->Fill("IEcal", avgIEcal); 
0720   timingSig->Fill("IHcal", avgPhotIHcal); 
0721   timingSig->Fill("Itrack", avgPhotItrack); 
0722   timingSig->LabelsDeflate("X");
0723   timingSig->LabelsOption("v");
0724 
0725   timingBkg = new TH1F("timingBkg", "Timing of Single Photon Filters in Background Events", 6, 0, 6);
0726   timingBkg->SetCanExtend(TH1::kAllAxes);
0727   timingBkg->SetStats(0);
0728   avgL1Match = 0.;
0729   avgEt = 0.;
0730   avgIEcal = 0.;
0731   avgPhotIHcal = 0.;
0732   avgPhotItrack = 0.;
0733   for (xSecNum = 0; xSecNum < bkgEvents.size(); xSecNum++) {
0734     delete l1MatchTiming; l1MatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.l1Match",bkgEvents[xSecNum].first);
0735     delete EtTiming; EtTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Et",bkgEvents[xSecNum].first);
0736     delete IEcalTiming; IEcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.IEcal",bkgEvents[xSecNum].first);
0737     delete PhotIHcalTiming; PhotIHcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.PhotIHcal",bkgEvents[xSecNum].first);
0738     delete PhotItrackTiming; PhotItrackTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.PhotItrack",bkgEvents[xSecNum].first);
0739     event = 0;
0740     for (event = 0; event < bkgEvents[xSecNum].first->GetEntries(); event++) {
0741       bkgEvents[xSecNum].first->LoadTree(event);
0742       avgL1Match = (event*avgL1Match + l1MatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0743       avgEt = (event*avgEt + EtTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0744       avgIEcal = (event*avgIEcal + IEcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0745       avgPhotIHcal = (event*avgPhotIHcal + PhotIHcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0746       avgPhotItrack = (event*avgPhotItrack + PhotItrackTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
0747     }
0748   }
0749   timingBkg->Fill("L1 Match", avgL1Match);
0750   timingBkg->Fill("Et", avgEt); 
0751   timingBkg->Fill("IEcal", avgIEcal); 
0752   timingBkg->Fill("IHcal", avgPhotIHcal); 
0753   timingBkg->Fill("Itrack", avgPhotItrack); 
0754   timingBkg->LabelsDeflate("X");
0755   timingBkg->LabelsOption("v");
0756     
0757   myCanvas = new TCanvas("myCanvas", "Timing vs. Filter for Isolated Photon Filters", 1000, 500);
0758   myCanvas->Divide(2,1);
0759   myCanvas->cd(1);
0760   timingSig->Draw();
0761   myCanvas->cd(2);
0762   timingBkg->Draw();
0763   myCanvas->Print("images/TimingIsoPhot.gif");
0764 }