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.74 by wulsin, Fri May 31 09:05:49 2013 UTC vs.
Revision 1.75 by wulsin, Fri May 31 09:15:04 2013 UTC

# Line 86 | Line 86 | OSUAnalysis::OSUAnalysis (const edm::Par
86  
87        BranchSpecs br;
88        br.inputCollection = tempInputCollection;
89      //      br.name           = branchList.at(iBranch).getParameter<string>("name");
90      // br.title          = branchList.at(iBranch).getParameter<string>("title");
91      // br.bins           = branchList.at(iBranch).getUntrackedParameter<vector<double> >("bins",          defaultValue);
92      // br.variableBinsX  = branchList.at(iBranch).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
93      // br.variableBinsY  = branchList.at(iBranch).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
94      //      br.inputVariables = branchList.at(iBranch).getParameter<vector<string> >("inputVariables");
95      //      br.inputVariable = branchList.at(iBranch).getParameter<string>("inputVariable");  
89        br.inputVariable = branchList.at(iBranch);  
90        TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);  
91        br.name = string(newName.Data());  
92  
93        treeBranches_.push_back(br);
101      //      cout << "Debug:  adding variable to treeVars:  " << br.name << endl;  
94  
95      }  
96  
# Line 415 | Line 407 | OSUAnalysis::OSUAnalysis (const edm::Par
407      //book all histograms included in the configuration
408      for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
409  
418      // Declare TTree.  
410        TTree* newTree = directories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));  
411        BNTrees_.push_back(newTree);  
421      //      map<TString, double> newTreeVar;  
412        
413        for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
414          BranchSpecs currentVar = treeBranches_.at(iBranch);
425        // int numInputVariables = currentVar.inputVariables.size();
426        // if (numInputVariables!=1) {
427        //   cout << "Warning:  no more than one input variable allowed for TTree." << endl;
428        //   continue;
429        // }
430
415          vector<float> newVec;  
432        //      BNTreeBranchVals_[currentVar.name] = newVec;  
416          BNTreeBranchVals_[currentVar.name] = newVec;  
417          BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
418  
# Line 444 | Line 427 | OSUAnalysis::OSUAnalysis (const edm::Par
427          int numBinEdgesX = currentHistogram.variableBinsX.size();
428          int numBinEdgesY = currentHistogram.variableBinsY.size();
429          
447        // Define branch for each histogram, only for 1D hists.  
448        // Initialize all variables to -99.
449        //      if (numInputVariables==1 && currentHistogramIndex <= 0) {
450        // if (numInputVariables==1) {
451        //   TString newTreeVarName = TString(currentHistogram.inputCollection) + "_" + TString(currentHistogram.name);  
452        //   newTreeVarName.ReplaceAll(" ", "_");  // avoid spaces in the name  
453        //   // newTreeVar[newTreeVarName] = -99.;  
454        //   // cout << "Debug 2" << endl;
455        //   // debugVar_ = -99.;  
456        //   // cout << "Debug 3" << endl;
457        //   // //        debugVars_.push_back(-98. + currentHistogramIndex);  
458        //   // BNTreeBranchVals_.push_back(newTreeVar);  
459        //   // cout << "Debug 4" << endl;
460        //   // debugVarsArray_[currentHistogramIndex] = -98. + currentHistogramIndex;  
461        //   // cout << "Debug 5" << endl;
462        //   // debugVars_.push_back(-97.);  
463        //   //   debugVarsMap_[string(newTreeVarName.Data())] = -96. + currentHistogramIndex;
464        //   vector<double> newVec;  
465        //   //   BNTreeBranchVals_[string(newTreeVarName.Data())] = newVec;  
466        //   BNTreeBranchVals_[currentHistogram.name] = newVec;  
467
468        //   //   BNTrees_.back()->Branch(newTreeVarName, &(newTreeVar[newTreeVarName]), TString(newTreeVarName+"/D"));
469        //   //   BNTrees_.back()->Branch(newTreeVarName, &(BNTreeBranchVals_.back().at(newTreeVarName)), TString(newTreeVarName+"/D"));
470        //   //   BNTrees_.back()->Branch(newTreeVarName, &debugVar_, TString(newTreeVarName+"/D"));
471        //   //   BNTrees_.back()->Branch(newTreeVarName, &(debugVars_.back()), TString(newTreeVarName+"/D"));
472        //   //   BNTrees_.back()->Branch(newTreeVarName, &(debugVars_.at(currentHistogramIndex)), TString(newTreeVarName+"/D"));
473        //   //   BNTrees_.back()->Branch(newTreeVarName, &(debugVarsArray_[currentHistogramIndex]), TString(newTreeVarName+"/D"));
474        //   //   cout << "Debug:  About to fill tree with hist name: " << newTreeVarName << "; value: " << debugVarsMap_[string(newTreeVarName.Data())] << endl;  
475        //   //   BNTrees_.back()->Branch(newTreeVarName, &(debugVarsMap_[string(newTreeVarName.Data())]), TString(newTreeVarName+"/D"));  // this works
476        //   //   BNTrees_.back()->Branch(newTreeVarName, &debugVars_);  // this sort of works
477        //   //   BNTrees_.back()->Branch(newTreeVarName, &BNTreeBranchVals_[string(newTreeVarName.Data())]);
478        //   //   BNTrees_.back()->Branch(newTreeVarName, &BNTreeBranchVals_[currentHistogram.name]);
479        //   BNTrees_.back()->Branch(TString(currentHistogram.name), &BNTreeBranchVals_[currentHistogram.name]);
480        // }
481
430          if(numBinsElements == 1){
431            if(numBinEdgesX > 1){
432              if(numBinEdgesY > 1)
# Line 714 | Line 662 | OSUAnalysis::analyze (const edm::Event &
662      event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
663    }
664  
717  //  cout << "Debug 0" << endl;
665    double masterScaleFactor = 1.0;
666  
667    //get pile-up event weight
# Line 738 | Line 685 | OSUAnalysis::analyze (const edm::Event &
685      counterMap passingCounter;
686      cumulativeFlags.clear ();
687  
741    //    debugVars_.clear();  
688      for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
689           iter != BNTreeBranchVals_.end(); iter++) {
690        iter->second.clear();  // clear array
# Line 751 | Line 697 | OSUAnalysis::analyze (const edm::Event &
697        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
698      }
699  
754    //    cout << "Debug 1" << endl;
755
700      //loop over all cuts
701      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
702        cut currentCut = currentChannel.cuts.at(currentCutIndex);
# Line 872 | Line 816 | OSUAnalysis::analyze (const edm::Event &
816      //apply trigger (true if none were specified)
817      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
818  
875    //    cout << "Debug 2" << endl;
876
819      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
820  
821        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 890 | Line 832 | OSUAnalysis::analyze (const edm::Event &
832      }
833      double scaleFactor = masterScaleFactor;
834  
893    //    cout << "Debug 2.1" << endl;
894
835      muonScaleFactor_ = electronScaleFactor_ = 1.0;
836      if(applyLeptonSF_ && datasetType_ != "data"){
837        if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
# Line 935 | Line 875 | OSUAnalysis::analyze (const edm::Event &
875             << endl;
876      }
877  
938    //    cout << "Debug 2.3" << endl;
939
878  
879      //filling histograms
880      for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
# Line 947 | Line 885 | OSUAnalysis::analyze (const edm::Event &
885        }
886        if(eventPassedPreviousCuts.at(currentDir)){
887  
950        //      cout << "Debug 2.3" << endl;
951
888          // Assign BNTree variables
889          for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
890            BranchSpecs brSpecs = treeBranches_.at(iBranch);  
955          // if(brSpecs.inputVariables.size() != 1) {
956          //   cout << "Warning:  tree variables cannot accept more than one variable.  Skipping variable:  " << brSpecs.name << endl;
957          //   continue;
958          // }
891            string coll = brSpecs.inputCollection;  
960          //      cout << "Debug 2.4, inputCollection = " << coll << endl;
961          //      if (cumulativeFlags.count("taus") == 0) {
892            if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
893  
894            if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).at(currentDir));            
# Line 983 | Line 913 | OSUAnalysis::analyze (const edm::Event &
913          } // end loop over histograms  
914                                                                                            
915  
986        //      cout << "Debug 2.5" << endl;
987
988
916          for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
917            histogram currentHistogram = histograms.at(histogramIndex);
918  
# Line 1130 | Line 1057 | OSUAnalysis::analyze (const edm::Event &
1057              else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1058            }
1059            
1133          //      cout << "Debug 2.6" << endl;
1134
1060          }
1061  
1137        //      cout << "Debug 3" << endl;
1138
1062  
1063          //fills histograms with the sizes of collections
1064          for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
# Line 1220 | Line 1143 | OSUAnalysis::analyze (const edm::Event &
1143        }
1144      }
1145  
1223    //    debugVar_ = -999.;  
1224    //    cout << "Debug 4" << endl;
1225
1146      BNTrees_.at(currentChannelIndex)->Fill();  
1147  
1148    } //end loop over channel
1149  
1150    masterCutFlow_->fillCutFlow(masterScaleFactor);
1151  
1232  //  cout << "Debug 5" << endl;
1233
1152  
1153   } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1154  
# Line 3905 | Line 3823 | bool OSUAnalysis::getPreviousCumulativeF
3823  
3824   template <class InputCollection>
3825   void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, vector<bool> flags){
3826 <  // This function is identical to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree  
3909 <
3910 <  //  cout << "Debug:  assignTree 0" << endl;  
3826 >  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree  
3827  
3828    for (uint object = 0; object != inputCollection->size(); object++){
3829  
3914    //    cout << "Debug:  assignTree 1" << endl;  
3915    
3830      if (!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3831  
3918    //    cout << "Debug:  assignTree 2" << endl;  
3919
3832      string inputVariable = parameters.inputVariable;
3833      string function = "";
3922    // if(currentString.find("(")==string::npos){
3923    //   inputVariable = currentString;// variable to cut on
3924    // }
3925    // else{
3926    //   function = currentString.substr(0,currentString.find("("));//function comes before the "("
3927    //   inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3928    //   inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3929    // }  
3930
3834      string stringValue = "";  
3932    //    cout << "Debug:  about to look up var:  " << parameters.name << endl;  
3835      double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3934
3935    //    cout << "Debug:  about to assign tree var:  " << parameters.name << endl;  
3836      BNTreeBranchVals_.at(parameters.name).push_back(value);  
3937    //    cout << "  Debug: finished assign." << endl;  
3837  
3838    }
3839   }
# Line 3963 | Line 3862 | void OSUAnalysis::fill1DHistogram(TH1* h
3862      double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3863      histo->Fill(value,scaleFactor);  
3864  
3966    // TString newTreeVarName = TString(parameters.inputCollection) + "_" + TString(parameters.name);  
3967    // newTreeVarName.ReplaceAll(" ", "_");  // avoid spaces in the name      
3968    //    debugVarsMap_[string(newTreeVarName.Data())] = value;  // this works  
3969    //    BNTreeBranchVals_.at(string(newTreeVarName.Data())).push_back(value);  
3970    //    BNTreeBranchVals_.at(parameters.name).push_back(value);  
3971    //    debugVars_.push_back(value);  
3972
3973    //    debugVarsArray_[0] = value;  
3974    //    cout << "Debug:  setting value of histogram " << parameters.name << ": " << value << endl;  
3975
3865      if (printEventInfo_) {
3866        // Write information about event to screen, for testing purposes.
3867        cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines