ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
(Generate patch)

Comparing UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc (file contents):
Revision 1.16 by lantonel, Fri Feb 15 12:59:53 2013 UTC vs.
Revision 1.17 by lantonel, Thu Feb 21 16:38:25 2013 UTC

# Line 47 | Line 47 | OSUAnalysis::OSUAnalysis (const edm::Par
47    //parse the histogram definitions
48    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
49  
50 <    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string>("inputCollection");
51 <    objectsToPlot.push_back(tempInputCollection);
52 <    allNecessaryObjects.push_back(tempInputCollection);
50 >    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
51 >    if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
52 >    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
53 >      objectsToPlot.push_back(tempInputCollection);
54 >      allNecessaryObjects.push_back(tempInputCollection);
55 >    }
56 >    else{//pair of objects, need to add them both to the things to allNecessaryObjects
57 >      int dashIndex = tempInputCollection.find("-");
58 >      int spaceIndex = tempInputCollection.find(" ");
59 >      int secondWordLength = spaceIndex - dashIndex;
60 >      allNecessaryObjects.push_back(tempInputCollection);
61 >      allNecessaryObjects.push_back(tempInputCollection.substr(0,dashIndex)+"s");
62 >      allNecessaryObjects.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
63 >      objectsToPlot.push_back(tempInputCollection);
64 >      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
65 >      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
66 >      }
67 >
68      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
69      
70      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
# Line 60 | Line 75 | OSUAnalysis::OSUAnalysis (const edm::Par
75        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
76        tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
77        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
63      if(histogramList_.at(currentHistogram).exists("function"))
64        tempHistogram.function = histogramList_.at(currentHistogram).getParameter<string>("function");
65      else
66        tempHistogram.function = "";
78        
79        histograms.push_back(tempHistogram);
80  
# Line 144 | Line 155 | OSUAnalysis::OSUAnalysis (const edm::Par
155        int maxNum = 10;
156        if(currentObject == "mcparticles") maxNum = 50;
157        else if(currentObject == "primaryvertexs") maxNum = 50;
158 +      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
159 +      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
160 +      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
161 +
162        currentObject.at(0) = toupper(currentObject.at(0));
163        string histoName = "num" + currentObject;
164 +
165        if(histoName == "numPrimaryvertexs"){
166          string newHistoName = histoName + "BeforePileupCorrection";
167          oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);    
# Line 162 | Line 178 | OSUAnalysis::OSUAnalysis (const edm::Par
178  
179      //loop over and parse all cuts
180      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
165
181        cut tempCut;
182 <     //store input collection for cut
183 <      string inputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
184 <      tempCut.inputCollection = inputCollection;
185 <      allNecessaryObjects.push_back(inputCollection);
182 >      //store input collection for cut
183 >      string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
184 >      tempCut.inputCollection = tempInputCollection;
185 >      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
186 >        allNecessaryObjects.push_back(tempInputCollection);
187 >      }
188 >      else{//pair of objects, need to add them both to the things to allNecessaryObjects
189 >        int dashIndex = tempInputCollection.find("-");
190 >        int spaceIndex = tempInputCollection.find(" ");
191 >        int secondWordLength = spaceIndex - dashIndex;
192 >        allNecessaryObjects.push_back(tempInputCollection);
193 >        allNecessaryObjects.push_back(tempInputCollection.substr(0,dashIndex)+"s");
194 >        allNecessaryObjects.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
195 >
196 >      }
197 >
198 >
199  
200        //split cut string into parts and store them
201        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
202        std::vector<string> cutStringVector = splitString(cutString);
203 <      if(cutStringVector.size()!=3){
204 <        std::cout << "Error: Didn't find three elements in the following cut string: '" <<cutString << "'\n";
203 >      if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
204 >        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
205          exit(0);
206        }
207 <
208 <      tempCut.variable = cutStringVector.at(0);// variable to cut on
209 <      tempCut.comparativeOperator = cutStringVector.at(1);// comparison to make
210 <      tempCut.cutValue = atof(cutStringVector.at(2).c_str());// threshold value to pass cut
207 >      tempCut.numSubcuts = (cutStringVector.size()+1)/4;
208 >      for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
209 >        int indexOffset = 4 * subcutIndex;
210 >        string currentVariableString = cutStringVector.at(indexOffset);
211 >        if(currentVariableString.find("(")==std::string::npos){
212 >          tempCut.functions.push_back("");//no function was specified
213 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
214 >        }
215 >        else{
216 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
217 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
218 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
219 >        }
220 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
221 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
222 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
223 >      }
224  
225        //get number of objects required to pass cut for event to pass
226        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
# Line 189 | Line 230 | OSUAnalysis::OSUAnalysis (const edm::Par
230          exit(0);
231        }
232  
192      // determine number required if comparison contains "="
233        int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
194      if(numberRequiredVector.at(0) == ">") numberRequiredInt++;
195      else if(numberRequiredVector.at(0) == "<") numberRequiredInt--;
196
234        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
235        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
236  
237 <      if(cuts_.at(currentCut).exists("function")){
201 <        tempCut.function = cuts_.at(currentCut).getParameter<string> ("function");
202 <      }
203 <      else tempCut.function = "";
237 >
238        string tempCutName;
239        if(cuts_.at(currentCut).exists("alias")){
240          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
# Line 208 | Line 242 | OSUAnalysis::OSUAnalysis (const edm::Par
242        else{
243          //construct string for cutflow table
244          bool plural = numberRequiredInt != 1;
245 <        string collectionString = plural ? inputCollection : inputCollection.substr(0, inputCollection.size()-1);
245 >        string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
246          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
247          tempCutName = cutName;
248        }
# Line 221 | Line 255 | OSUAnalysis::OSUAnalysis (const edm::Par
255  
256      }//end loop over cuts
257  
224
258      channels.push_back(tempChannel);
259      tempChannel.cuts.clear();
260  
# Line 335 | Line 368 | OSUAnalysis::analyze (const edm::Event &
368        cut currentCut = currentChannel.cuts.at(currentCutIndex);
369  
370        for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
338
371          string currentObject = allNecessaryObjects.at(currentObjectIndex);
372 +
373          individualFlags[currentObject].push_back (vector<bool> ());
374          cumulativeFlags[currentObject].push_back (vector<bool> ());
375  
# Line 355 | Line 388 | OSUAnalysis::analyze (const edm::Event &
388          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
389          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
390  
391 <
391 >        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(),"muon-muon pairs");
392 >        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(),"electron-electron pairs");
393 >        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(),"electron-muon pairs");
394  
395        }
396  
# Line 365 | Line 400 | OSUAnalysis::analyze (const edm::Event &
400  
401  
402  
368
403      //use cumulative flags to apply cuts at event level
404  
405      bool eventPassedAllCuts = true;
# Line 380 | Line 414 | OSUAnalysis::analyze (const edm::Event &
414        cut currentCut = currentChannel.cuts.at(currentCutIndex);
415        int numberPassing = 0;
416  
417 <      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++)
417 >      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
418            if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
419 <
419 >      }
420  
421        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
422        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
# Line 394 | Line 428 | OSUAnalysis::analyze (const edm::Event &
428      cutFlows_.at(currentChannelIndex)->fillCutFlow(puScaleFactor);
429  
430  
431 +
432      if(!eventPassedAllCuts)continue;
433  
434  
# Line 419 | Line 454 | OSUAnalysis::analyze (const edm::Event &
454          histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
455          if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
456          else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
457 +        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),\
458 +                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(),\
459 +                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
460          else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
461 +        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
462 +                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
463 +                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
464 +        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
465 +                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
466 +                                                                                              cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
467          else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
468          else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
469          else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
# Line 436 | Line 480 | OSUAnalysis::analyze (const edm::Event &
480          histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
481          if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
482          else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
483 +        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
484 +                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
485 +                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
486          else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
487 +        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
488 +                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
489 +                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
490 +        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
491 +                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
492 +                                                                                               cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
493          else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
494          else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
495          else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
# Line 454 | Line 507 | OSUAnalysis::analyze (const edm::Event &
507      //fills histograms with the sizes of collections
508      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
509        string currentObject = objectsToPlot.at(currentObjectIndex);
510 +
511 +      if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
512 +      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
513 +      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
514        string tempCurrentObject = currentObject;
515        tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
516        string histoName = "num" + tempCurrentObject;
517  
518 +
519        if(currentObject == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),puScaleFactor);
520        else if(currentObject == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),puScaleFactor);
521 +      else if(currentObject == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,puScaleFactor);
522        else if(currentObject == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),puScaleFactor);
523 +      else if(currentObject == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,puScaleFactor);
524 +      else if(currentObject == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),puScaleFactor);
525        else if(currentObject == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),puScaleFactor);
526        else if(currentObject == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),puScaleFactor);
527        else if(currentObject == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),puScaleFactor);
# Line 494 | Line 555 | OSUAnalysis::evaluateComparison (double
555    else if(comparison == "<")  return testValue <  cutValue;
556    else if(comparison == "<=") return testValue <= cutValue;
557    else if(comparison == "==") return testValue == cutValue;
558 +  else if(comparison == "=") return testValue == cutValue;
559    else if(comparison == "!=") return testValue != cutValue;
560    else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
561  
# Line 1558 | Line 1620 | OSUAnalysis::valueLookup (const BNsuperc
1620  
1621  
1622   double
1623 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
1624 +
1625 +  double value = 0.0;
1626 +
1627 +  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
1628 +  else if(variable == "invMass"){
1629 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
1630 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
1631 +    value = (fourVector1 + fourVector2).M();
1632 +  }
1633 +
1634 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1635 +
1636 +  value = applyFunction(function, value);
1637 +
1638 +  return value;
1639 + }
1640 +
1641 + double
1642 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
1643 +
1644 +  double value = 0.0;
1645 +
1646 +  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
1647 +  else if(variable == "invMass"){
1648 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
1649 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
1650 +    value = (fourVector1 + fourVector2).M();
1651 +  }
1652 +
1653 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1654 +
1655 +  value = applyFunction(function, value);
1656 +
1657 +  return value;
1658 + }
1659 +
1660 + double
1661 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
1662 +
1663 +  double value = 0.0;
1664 +
1665 +  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
1666 +  else if(variable == "invMass"){
1667 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
1668 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
1669 +    value = (fourVector1 + fourVector2).M();
1670 +  }
1671 +
1672 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1673 +
1674 +  value = applyFunction(function, value);
1675 +
1676 +  return value;
1677 + }
1678 +
1679 +
1680 + double
1681   OSUAnalysis::applyFunction(string function, double value){
1682  
1683    if(function == "abs") value = fabs(value);
# Line 1571 | Line 1691 | OSUAnalysis::applyFunction(string functi
1691   template <class InputCollection>
1692   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
1693  
1574
1694    for (uint object = 0; object != inputCollection->size(); object++){
1695  
1696      bool decision = true;//object passes if this cut doesn't cut on that type of object
1697  
1698      if(currentCut.inputCollection == inputType){
1699  
1700 <      double value = valueLookup(&inputCollection->at(object), currentCut.variable, currentCut.function);
1701 <
1702 <      decision = evaluateComparison(value,currentCut.comparativeOperator,currentCut.cutValue);
1700 >      vector<bool> subcutDecisions;
1701 >      for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
1702 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
1703 >        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
1704 >      }
1705 >      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
1706 >      else{
1707 >        bool tempDecision = true;
1708 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
1709 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
1710 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
1711 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
1712 >            tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
1713 >        }
1714 >        decision = tempDecision;
1715 >      }
1716      }
1717      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
1718  
1587
1719      //set flags for objects that pass each cut AND all the previous cuts
1720      bool previousCumulativeFlag = true;
1721      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
# Line 1598 | Line 1729 | void OSUAnalysis::setObjectFlags(cut &cu
1729   }
1730  
1731  
1732 + template <class InputCollection1, class InputCollection2>
1733 + void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
1734 +                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, string inputType){
1735 +
1736 +
1737 +  bool sameObjects = false;
1738 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
1739 +
1740 +  int counter = 0;  
1741 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
1742 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
1743 +      
1744 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
1745 +
1746 +
1747 +      bool decision = true;//object passes if this cut doesn't cut on that type of object
1748 +
1749 +      if(currentCut.inputCollection == inputType){
1750 +
1751 +        vector<bool> subcutDecisions;
1752 +        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
1753 +          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
1754 +          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
1755 +        }
1756 +
1757 +        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
1758 +        else{
1759 +          bool tempDecision = true;
1760 +          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
1761 +            if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
1762 +              tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
1763 +            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
1764 +              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
1765 +          }
1766 +          decision = tempDecision;
1767 +        }
1768 +      }
1769 +      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
1770 +      
1771 +      //set flags for objects that pass each cut AND all the previous cuts
1772 +      bool previousCumulativeFlag = true;
1773 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
1774 +        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
1775 +        else{ previousCumulativeFlag = false; break;}
1776 +      }
1777 +      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
1778 +
1779 +      counter++;      
1780 +    }
1781 +    
1782 +  }
1783 +
1784 +
1785 + }
1786 +
1787 +
1788   template <class InputCollection>
1789   void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
1790  
# Line 1605 | Line 1792 | void OSUAnalysis::fill1DHistogram(TH1* h
1792  
1793      if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
1794  
1795 <    double value = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(0), parameters.function);
1795 >    string currentString = parameters.inputVariables.at(0);
1796 >    string inputVariable = "";
1797 >    string function = "";
1798 >    if(currentString.find("(")==std::string::npos){
1799 >      inputVariable = currentString;// variable to cut on                                                                                                                                        
1800 >    }
1801 >    else{
1802 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
1803 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
1804 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
1805 >    }
1806 >
1807 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
1808      histo->Fill(value,puScaleFactor);
1809  
1810    }
1811  
1812   }
1813  
1814 + template <class InputCollection1, class InputCollection2>
1815 + void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
1816 +
1817 +  bool sameObjects = false;
1818 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
1819 +
1820 +  int counter = 0;  
1821 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
1822 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
1823 +      
1824 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
1825 +
1826 +      //only take objects which have passed all cuts and pairs which have passed all cuts
1827 +      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
1828 +      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
1829 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(counter)) continue;
1830 +
1831 +      string currentString = parameters.inputVariables.at(0);
1832 +      string inputVariable = "";
1833 +      string function = "";
1834 +      if(currentString.find("(")==std::string::npos){
1835 +        inputVariable = currentString;// variable to cut on                                                                                                          
1836 +      }
1837 +      else{
1838 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
1839 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
1840 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
1841 +      }
1842 +      
1843 +      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
1844 +      histo->Fill(value,puScaleFactor);
1845 +
1846 +      counter++;      
1847 +    }
1848 +  }
1849 +
1850 + }
1851 +
1852 +
1853   template <class InputCollection>
1854   void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
1855  
# Line 1619 | Line 1857 | void OSUAnalysis::fill2DHistogram(TH2* h
1857  
1858      if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
1859  
1860 <    double valueX = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(0), parameters.function);
1861 <    double valueY = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(1), parameters.function);
1860 >    string currentString = parameters.inputVariables.at(0);
1861 >    string inputVariable = "";
1862 >    string function = "";
1863 >    if(currentString.find("(")==std::string::npos){
1864 >      inputVariable = currentString;// variable to cut on                                                                                                                                        
1865 >    }
1866 >    else{
1867 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
1868 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
1869 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
1870 >    }
1871 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
1872 >
1873 >    currentString = parameters.inputVariables.at(1);
1874 >    inputVariable = "";
1875 >    function = "";
1876 >    if(currentString.find("(")==std::string::npos){
1877 >      inputVariable = currentString;// variable to cut on                                                                                                                                        
1878 >    }
1879 >    else{
1880 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
1881 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
1882 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
1883 >    }
1884 >
1885 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
1886 >
1887      histo->Fill(valueX,valueY,puScaleFactor);
1888  
1889    }
1890  
1891   }
1892  
1893 + template <class InputCollection1, class InputCollection2>
1894 + void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
1895 +
1896 +  bool sameObjects = false;
1897 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
1898 +
1899 +  int counter = 0;  
1900 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
1901 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
1902 +      
1903 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
1904 +
1905 +      //only take objects which have passed all cuts and pairs which have passed all cuts
1906 +      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
1907 +      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
1908 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(counter)) continue;
1909 +
1910 +      string currentString = parameters.inputVariables.at(0);
1911 +      string inputVariable = "";
1912 +      string function = "";
1913 +      if(currentString.find("(")==std::string::npos){
1914 +        inputVariable = currentString;// variable to cut on                                                                                                          
1915 +      }
1916 +      else{
1917 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
1918 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
1919 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
1920 +      }
1921 +      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
1922 +
1923 +      currentString = parameters.inputVariables.at(1);
1924 +      inputVariable = "";
1925 +      function = "";
1926 +      if(currentString.find("(")==std::string::npos){
1927 +        inputVariable = currentString;// variable to cut on                                                                                                          
1928 +      }
1929 +      else{
1930 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
1931 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
1932 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
1933 +      }
1934 +      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
1935 +
1936 +
1937 +      histo->Fill(valueX,valueY,puScaleFactor);
1938 +
1939 +      counter++;      
1940 +    }
1941 +  }
1942 +
1943 + }
1944  
1945  
1946  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines