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.31 by ahart, Mon Mar 18 10:21:44 2013 UTC vs.
Revision 1.49 by wulsin, Wed Apr 17 15:39:43 2013 UTC

# Line 11 | Line 11 | OSUAnalysis::OSUAnalysis (const edm::Par
11    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
12    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
13    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
14 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
15    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
16    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
17    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
# Line 27 | Line 28 | OSUAnalysis::OSUAnalysis (const edm::Par
28    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
29    histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
30    plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
31 <  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting"))
31 >  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
32 >  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
33 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
34 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau"))
35 >
36   {
37  
38    TH1::SetDefaultSumw2 ();
# Line 35 | Line 40 | OSUAnalysis::OSUAnalysis (const edm::Par
40    //create pile-up reweighting object, if necessary
41    if(datasetType_ != "data") {
42      if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
43 <    muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
44 <    electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
43 >    //    muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
44 >    //    electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
45    }
46 + #ifdef DISPLACED_SUSY
47 +  if (datasetType_ == "signalMC")
48 +    cTauWeight_ = new CTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
49 + #endif
50 +
51  
52    // Construct Cutflow Objects. These store the results of cut decisions and
53    // handle filling cut flow histograms.
# Line 47 | Line 57 | OSUAnalysis::OSUAnalysis (const edm::Par
57    //always get vertex collection so we can assign the primary vertex in the event
58    objectsToGet.push_back("primaryvertexs");
59  
60 <  //always make the plot of number of primary verticex (to check pile-up reweighting)
60 >  //always make the plot of number of primary vertices (to check pile-up reweighting)
61    objectsToPlot.push_back("primaryvertexs");
62  
63    //always get the MC particles to do GEN-matching
# Line 61 | Line 71 | OSUAnalysis::OSUAnalysis (const edm::Par
71  
72      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
73      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
74 +    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
75 +    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
76      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
77 <      objectsToGet.push_back(tempInputCollection);
77 >      if(tempInputCollection.find("secondary")!=std::string::npos){//secondary object
78 >        int spaceIndex = tempInputCollection.find(" ");
79 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
80 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
81 >      }
82 >      else{
83 >        objectsToGet.push_back(tempInputCollection);
84 >      }
85        objectsToPlot.push_back(tempInputCollection);
86        objectsToCut.push_back(tempInputCollection);
87      }
88 <    else{//pair of objects, need to add them both to the things to objectsToGet
89 <      int dashIndex = tempInputCollection.find("-");
90 <      int spaceIndex = tempInputCollection.find(" ");
91 <      int secondWordLength = spaceIndex - dashIndex;
92 <      objectsToGet.push_back(tempInputCollection);
74 <      objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
75 <      objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
76 <      objectsToPlot.push_back(tempInputCollection);
77 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
78 <      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
88 >    else{//pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
89 >      string obj1;
90 >      string obj2;
91 >      getTwoObjs(tempInputCollection, obj1, obj2);
92 >      string obj2ToGet = getObjToGet(obj2);  
93        objectsToCut.push_back(tempInputCollection);
94 <      objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
95 <      objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
94 >      objectsToCut.push_back(obj1);
95 >      objectsToCut.push_back(obj2);  
96 >      objectsToPlot.push_back(tempInputCollection);
97 >      objectsToPlot.push_back(obj1);
98 >      objectsToPlot.push_back(obj2);  
99 >      objectsToGet.push_back(tempInputCollection);
100 >      objectsToGet.push_back(obj1);
101 >      objectsToGet.push_back(obj2ToGet);
102  
103 <      }
103 >    }
104  
105      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
106  
# Line 107 | Line 127 | OSUAnalysis::OSUAnalysis (const edm::Par
127    for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
128  
129      string currentObject = objectsToPlot.at(currentObjectIndex);
130 <    if(currentObject != "muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
130 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
131  
132      histogram tempIdHisto;
133      histogram tempMomIdHisto;
134      histogram tempGmaIdHisto;
135 +    histogram tempIdVsMomIdHisto;
136  
137      tempIdHisto.inputCollection = currentObject;
138      tempMomIdHisto.inputCollection = currentObject;
139      tempGmaIdHisto.inputCollection = currentObject;
140 +    tempIdVsMomIdHisto.inputCollection = currentObject;
141 +
142 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
143  
144      currentObject = currentObject.substr(0, currentObject.size()-1);
145      tempIdHisto.name = currentObject+"GenMatchId";
146      tempMomIdHisto.name = currentObject+"GenMatchMotherId";
147      tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
148 +    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
149  
150      currentObject.at(0) = toupper(currentObject.at(0));
151      tempIdHisto.title = currentObject+" Gen-matched Particle";
152      tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
153      tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
154 +    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
155  
156      int maxNum = 24;
157      vector<double> binVector;
# Line 139 | Line 165 | OSUAnalysis::OSUAnalysis (const edm::Par
165      tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
166      tempGmaIdHisto.bins = binVector;
167      tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
168 +    binVector.push_back(maxNum);
169 +    binVector.push_back(0);
170 +    binVector.push_back(maxNum);
171 +    tempIdVsMomIdHisto.bins = binVector;
172 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
173 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
174  
175      histograms.push_back(tempIdHisto);
176      histograms.push_back(tempMomIdHisto);
177      histograms.push_back(tempGmaIdHisto);
178 <
178 >    histograms.push_back(tempIdVsMomIdHisto);
179    }
180  
181  
150
182    channel tempChannel;
183    //loop over all channels (event selections)
184    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
# Line 184 | Line 215 | OSUAnalysis::OSUAnalysis (const edm::Par
215      twoDHists_.push_back(twoDhistoMap);
216  
217  
218 +
219      //book all histograms included in the configuration
220      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
221        histogram currentHistogram = histograms.at(currentHistogramIndex);
# Line 209 | Line 241 | OSUAnalysis::OSUAnalysis (const edm::Par
241  
242        if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
243  
244 < // bin      particle type
245 < // ---      -------------
246 < //  0        unmatched
247 < //  1        u
248 < //  2        d
249 < //  3        s
250 < //  4        c
251 < //  5        b
252 < //  6        t
253 < //  7        e
254 < //  8        mu
255 < //  9        tau
256 < // 10        nu
257 < // 11        g
258 < // 12        gamma
259 < // 13        Z
260 < // 14        W
261 < // 15        light meson
262 < // 16        K meson
263 < // 17        D meson
264 < // 18        B meson
265 < // 19        light baryon
266 < // 20        strange baryon
267 < // 21        charm baryon
268 < // 22        bottom baryon
269 < // 23        other
244 >      // bin      particle type
245 >      // ---      -------------
246 >      //  0        unmatched
247 >      //  1        u
248 >      //  2        d
249 >      //  3        s
250 >      //  4        c
251 >      //  5        b
252 >      //  6        t
253 >      //  7        e
254 >      //  8        mu
255 >      //  9        tau
256 >      // 10        nu
257 >      // 11        g
258 >      // 12        gamma
259 >      // 13        Z
260 >      // 14        W
261 >      // 15        light meson
262 >      // 16        K meson
263 >      // 17        D meson
264 >      // 18        B meson
265 >      // 19        light baryon
266 >      // 20        strange baryon
267 >      // 21        charm baryon
268 >      // 22        bottom baryon
269 >      // 23        other
270  
271        vector<TString> labelArray;
272        labelArray.push_back("unmatched");
# Line 263 | Line 295 | OSUAnalysis::OSUAnalysis (const edm::Par
295        labelArray.push_back("other");
296  
297        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
298 <        oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
298 >        if(currentHistogram.name.find("GenMatchIdVsMotherId")==std::string::npos) {
299 >          oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
300 >        }
301 >        else {
302 >          twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
303 >          twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
304 >        }
305 >      }
306 >      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=std::string::npos) {
307 >        twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->CenterTitle();
308 >        twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->CenterTitle();
309        }
268    }
310  
311 <    //book a histogram for the number of each object type to be plotted
311 >    }
312  
313 +    // Book a histogram for the number of each object type to be plotted.  
314 +    // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().  
315      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
316        string currentObject = objectsToPlot.at(currentObjectIndex);
317        int maxNum = 10;
318        if(currentObject == "mcparticles") maxNum = 50;
319        else if(currentObject == "primaryvertexs") maxNum = 50;
277      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
278      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
279      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
320  
321 <      currentObject.at(0) = toupper(currentObject.at(0));
321 >      if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
322 >      else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
323 >      else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
324 >      else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
325 >      else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";        
326 >      else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";    
327 >      else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";      
328 >      else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
329 >      else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
330 >      else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
331 >      else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
332 >
333 >      currentObject.at(0) = toupper(currentObject.at(0));  
334        string histoName = "num" + currentObject;
335  
336        if(histoName == "numPrimaryvertexs"){
# Line 294 | Line 346 | OSUAnalysis::OSUAnalysis (const edm::Par
346  
347  
348  
297
349      //get list of cuts for this channel
350      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
351  
# Line 303 | Line 354 | OSUAnalysis::OSUAnalysis (const edm::Par
354        cut tempCut;
355        //store input collection for cut
356        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
357 +      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
358 +      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
359 +      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
360        tempCut.inputCollection = tempInputCollection;
361        if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
362 <        objectsToGet.push_back(tempInputCollection);
362 >        if(tempInputCollection.find("secondary")!=std::string::npos){//secondary object
363 >          int spaceIndex = tempInputCollection.find(" ");
364 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
365 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
366 >        }
367 >        else{
368 >          objectsToGet.push_back(tempInputCollection);
369 >        }
370 >        objectsToCut.push_back(tempInputCollection);
371 >      }
372 >      else{//pair of objects, need to add them both to objectsToGet
373 >        string obj1;
374 >        string obj2;
375 >        getTwoObjs(tempInputCollection, obj1, obj2);
376 >        string obj2ToGet = getObjToGet(obj2);  
377          objectsToCut.push_back(tempInputCollection);
378 <      }
379 <      else{//pair of objects, need to add them both to the things to objectsToGet
312 <        int dashIndex = tempInputCollection.find("-");
313 <        int spaceIndex = tempInputCollection.find(" ");
314 <        int secondWordLength = spaceIndex - dashIndex;
378 >        objectsToCut.push_back(obj1);
379 >        objectsToCut.push_back(obj2);  
380          objectsToGet.push_back(tempInputCollection);
381 <        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
382 <        objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
318 <        objectsToCut.push_back(tempInputCollection);
319 <        objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
320 <        objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
381 >        objectsToGet.push_back(obj1);
382 >        objectsToGet.push_back(obj2ToGet);
383  
384        }
385  
# Line 374 | Line 436 | OSUAnalysis::OSUAnalysis (const edm::Par
436        }
437        tempCut.name = tempCutName;
438  
377
439        tempChannel.cuts.push_back(tempCut);
440  
441  
381
442      }//end loop over cuts
443  
444      channels.push_back(tempChannel);
# Line 454 | Line 514 | OSUAnalysis::analyze (const edm::Event &
514    if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
515      event.getByLabel (superclusters_, superclusters);
516  
517 +  if (useTrackCaloRhoCorr_) {  
518 +    // Used only for pile-up correction of by-hand calculation of isolation energy.  
519 +    // This rho collection is not available in all BEANs.  
520 +    // For description of rho values for different jet reconstruction algorithms, see
521 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms  
522 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
523 +  }
524 +
525 +
526    //get pile-up event weight
527    double scaleFactor = 1.00;
528    if(doPileupReweighting_ && datasetType_ != "data")
529      scaleFactor = puWeight_->at (events->at (0).numTruePV);
530  
531 +  cTauScaleFactor_ = 1.0;
532 + #ifdef DISPLACED_SUSY
533 +  if (datasetType_ == "signalMC")
534 +    cTauScaleFactor_ = cTauWeight_->at (event);
535 + #endif
536 +  scaleFactor *= cTauScaleFactor_;
537  
538    //loop over all channels
539  
# Line 497 | Line 572 | OSUAnalysis::analyze (const edm::Event &
572  
573  
574          if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
575 +
576          else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
577 +
578 +        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
579          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
580          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
581          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 515 | Line 593 | OSUAnalysis::analyze (const edm::Event &
593                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
594                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
595                                                                     "muon-muon pairs");
596 +
597 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
598 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
599 +                                                                   cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
600 +                                                                   "muon-secondary muon pairs");
601 +
602          else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
603                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
604                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
# Line 523 | Line 607 | OSUAnalysis::analyze (const edm::Event &
607                                                                         cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
608                                                                         cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
609                                                                         "electron-muon pairs");
610 <
611 <
610 >        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
611 >                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
612 >                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
613 >                                                                     "track-event pairs");
614 >        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
615 >                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
616 >                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
617 >                                                                        "electron-track pairs");
618 >        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
619 >                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
620 >                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
621 >                                                                    "muon-track pairs");
622 >        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
623 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
624 >                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
625 >                                                                  "muon-tau pairs");
626 >        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
627 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
628 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
629 >                                                                 "tau-tau pairs");
630 >        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
631 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
632 >                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
633 >                                                                 "tau-track pairs");
634 >        
635 >        
636        }
637  
638  
# Line 540 | Line 648 | OSUAnalysis::analyze (const edm::Event &
648      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
649  
650  
543
651      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
652  
653        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 548 | Line 655 | OSUAnalysis::analyze (const edm::Event &
655        int numberPassing = 0;
656  
657        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
658 <          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
658 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
659        }
553
660        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
661        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
556
662        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
663  
664      }
665  
666 +    //     if(datasetType_ != "data") {
667 +    //       scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
668 +    //       scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
669 +    //     }
670 +
671      cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
672  
673  
674  
675      if(!eventPassedAllCuts)continue;
676  
677 +    if (printEventInfo_) {
678 +      // Write information about event to screen, for testing purposes.  
679 +      cout << "Event passed all cuts in channel " <<  currentChannel.name
680 +           << ": run="  << events->at(0).run
681 +           << "  lumi=" << events->at(0).lumi
682 +           << "  event=" << events->at(0).evt
683 +           << endl;  
684 +    }
685  
568    //if(datasetType_ != "data") {
569    //  scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
570    //  scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
571    //}
686  
687      //filling histograms
688      for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
# Line 578 | Line 692 | OSUAnalysis::analyze (const edm::Event &
692          TH1D* histo;
693          histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
694  
581
582
695          if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
696 <         else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
696 >        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
697 >        else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").back(),scaleFactor);
698          else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
699                                                                                         cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
700                                                                                         cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
701 +        else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
702 +                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("secondary muons").back(), \
703 +                                                                                       cumulativeFlags.at("muon-secondary muon pairs").back(),scaleFactor);
704          else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
705          else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
706                                                                                                 cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
707                                                                                                 cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
708          else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
709 <                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
710 <                                                                                              cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
709 >                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
710 >                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
711 >        else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),        
712 >                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),  
713 >                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);      
714 >        else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),        
715 >                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),  
716 >                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);      
717 >        else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),    
718 >                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),      
719 >                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);  
720 >        else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),      
721 >                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),        
722 >                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);    
723 >        else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
724 >                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("tracks").back(),
725 >                                                                                     cumulativeFlags.at("tau-track pairs").back(),scaleFactor);
726 >
727          else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
728          else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
729          else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
# Line 607 | Line 739 | OSUAnalysis::analyze (const edm::Event &
739          TH2D* histo;
740          histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
741  
610
611
742          if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
743          else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
744 +        else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").back(),scaleFactor);
745          else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
746                                                                                         cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
747                                                                                         cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
748 +        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
749 +                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("secondary muons").back(), \
750 +                                                                                       cumulativeFlags.at("muon-secondary muon pairs").back(),scaleFactor);
751          else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
752          else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
753                                                                                                 cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
754                                                                                                 cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
755          else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
756 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
757 <                                                                                               cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
758 <        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
756 >                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
757 >                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
758 >        else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),        
759 >                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),          
760 >                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);      
761 >        else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),        
762 >                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),          
763 >                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);      
764 >        else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),    
765 >                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),      
766 >                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);  
767 >        else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),      
768 >                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),        
769 >                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);    
770 >        else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
771 >                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("tracks").back(),
772 >                                                                                     cumulativeFlags.at("tau-track pairs").back(),scaleFactor);
773 >        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
774          else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
775          else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
776          else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
777 +        else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
778 +                                                                                         cumulativeFlags.at("tracks").back(),cumulativeFlags.at("events").back(),
779 +                                                                                         cumulativeFlags.at("track-event pairs").back(),scaleFactor);  
780          else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
781          else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
782          else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
# Line 634 | Line 786 | OSUAnalysis::analyze (const edm::Event &
786        }
787      }
788  
789 +
790 +
791      //fills histograms with the sizes of collections
792      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
793 +
794        string currentObject = objectsToPlot.at(currentObjectIndex);
795  
796 <      string objectToPlot = "";
796 >      string objectToPlot = "";  
797  
798 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().  
799        if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
800        else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
801 <      else if(currentObject == "electron-muon pairs") objectToPlot = "electronMuonPairs";
801 >      else if(currentObject == "electron-muon pairs")     objectToPlot = "electronMuonPairs";
802 >      else if(currentObject == "electron-track pairs")    objectToPlot = "electronTrackPairs";
803 >      else if(currentObject == "muon-track pairs")        objectToPlot = "muonTrackPairs";      
804 >      else if(currentObject == "muon-tau pairs")          objectToPlot = "muonTauPairs";        
805 >      else if(currentObject == "tau-tau pairs")           objectToPlot = "ditauPairs";
806 >      else if(currentObject == "tau-track pairs")         objectToPlot = "tauTrackPairs";
807 >      else if(currentObject == "track-event pairs")       objectToPlot = "trackEventPairs";  
808 >      else if(currentObject == "muon-secondary muon pairs")       objectToPlot = "muonSecondaryMuonPairs";  
809 >      else if(currentObject == "secondary muons")         objectToPlot = "secondaryMuons";  
810        else objectToPlot = currentObject;
811 +
812        string tempCurrentObject = objectToPlot;
813 <      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
813 >      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));  
814        string histoName = "num" + tempCurrentObject;
815  
651
652
653
816        //set position of primary vertex in event, in order to calculate quantities relative to it
817        if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
818          vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
819 <        int numToPlot = 0;
819 >        int numToPlot = 0;
820          for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
821            if(lastCutFlags.at(currentFlag)) numToPlot++;
822          }
# Line 662 | Line 824 | OSUAnalysis::analyze (const edm::Event &
824            oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
825            oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
826          }
827 <        else
827 >        else {
828            oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
829 +        }
830        }
831        else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
832        else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
833 +      else if(objectToPlot == "secondaryMuons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
834        else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
835 +      else if(objectToPlot == "muonSecondaryMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
836        else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
837        else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
838        else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
839 +      else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
840        else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
841        else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
842        else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
# Line 683 | Line 849 | OSUAnalysis::analyze (const edm::Event &
849        else if(objectToPlot == "primaryvertexs"){
850          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
851          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
852 <      }
687 <
688 <    }
689 <
690 <
852 >      }
853  
854 +    } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
855  
856    } //end loop over channel
857  
858    masterCutFlow_->fillCutFlow(scaleFactor);
859  
860 + } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
861  
862  
699 }
700
863  
864   bool
865   OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
# Line 744 | Line 906 | OSUAnalysis::splitString (string inputSt
906  
907   }
908  
909 +
910 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
911 +  // Set two object strings from the tempInputCollection string,
912 +  // For example, if tempInputCollection is "electron-muon pairs",
913 +  // then obj1 = "electrons" and obj2 = "muons".  
914 +  // Note that the objects have an "s" appended.  
915 +
916 +  int dashIndex = tempInputCollection.find("-");
917 +  int spaceIndex = tempInputCollection.find_last_of(" ");
918 +  int secondWordLength = spaceIndex - dashIndex;
919 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";  
920 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
921 +  
922 + }
923 +
924 +
925 + string OSUAnalysis::getObjToGet(string obj) {
926 +  // Return the string corresponding to the object to get for the given obj string.
927 +  // Right now this only handles the case in which obj contains "secondary",
928 +  // e.g, "secondary muons".  
929 +  // Note that "s" is NOT appended.  
930 +  
931 +  if (obj.find("secondary")==std::string::npos) return obj;  // "secondary" is not found  
932 +  int firstSpaceIndex = obj.find_first_of(" ");  
933 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
934 +
935 + }  
936 +
937 +
938 +
939   double
940   OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
941  
# Line 1040 | Line 1232 | OSUAnalysis::valueLookup (const BNmuon*
1232      if (met)
1233        {
1234          TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1235 <                       p2 (met->px, met->py, 0.0, met->pt);
1235 >          p2 (met->px, met->py, 0.0, met->pt);
1236  
1237          value = (p1 + p2).Mt ();
1238        }
# Line 1160 | Line 1352 | OSUAnalysis::valueLookup (const BNmuon*
1352      value = object->isGlobalMuon > 0                \
1353        && object->isPFMuon > 0                        \
1354        && object->normalizedChi2 < 10                \
1355 <      && object->numberOfValidMuonHits > 0        \
1355 >                                  && object->numberOfValidMuonHits > 0        \
1356        && object->numberOfMatchedStations > 1        \
1357        && fabs(object->correctedD0Vertex) < 0.2        \
1358        && fabs(object->correctedDZ) < 0.5        \
# Line 1170 | Line 1362 | OSUAnalysis::valueLookup (const BNmuon*
1362    else if(variable == "tightIDdisplaced"){
1363      value = object->isGlobalMuon > 0                \
1364        && object->normalizedChi2 < 10                \
1365 <      && object->numberOfValidMuonHits > 0        \
1365 >                                  && object->numberOfValidMuonHits > 0        \
1366        && object->numberOfMatchedStations > 1        \
1367        && object->numberOfValidPixelHits > 0        \
1368        && object->numberOfLayersWithMeasurement > 5;
1369    }
1370  
1371 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1372  
1373 +  else if(variable == "genMatchedPdgId"){
1374 +    int index = getGenMatchedParticleIndex(object);
1375 +    if(index == -1) value = 0;
1376 +    else value = mcparticles->at(index).id;
1377 +  }
1378  
1379    else if(variable == "genMatchedId"){
1380      int index = getGenMatchedParticleIndex(object);
# Line 1188 | Line 1386 | OSUAnalysis::valueLookup (const BNmuon*
1386      if(index == -1) value = 0;
1387      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1388    }
1389 +  else if(variable == "genMatchedMotherIdReverse"){
1390 +    int index = getGenMatchedParticleIndex(object);
1391 +    if(index == -1) value = 23;
1392 +    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1393 +  }
1394    else if(variable == "genMatchedGrandmotherId"){
1395      int index = getGenMatchedParticleIndex(object);
1396      if(index == -1) value = 0;
# Line 1380 | Line 1583 | OSUAnalysis::valueLookup (const BNelectr
1583      if (met)
1584        {
1585          TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1586 <                       p2 (met->px, met->py, 0.0, met->pt);
1586 >          p2 (met->px, met->py, 0.0, met->pt);
1587  
1588          value = (p1 + p2).Mt ();
1589        }
# Line 1546 | Line 1749 | OSUAnalysis::valueLookup (const BNelectr
1749        }
1750    }
1751  
1752 +
1753 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1754 +
1755 +  else if(variable == "genMatchedPdgId"){
1756 +    int index = getGenMatchedParticleIndex(object);
1757 +    if(index == -1) value = 0;
1758 +    else value = mcparticles->at(index).id;
1759 +  }
1760 +
1761 +
1762    else if(variable == "genMatchedId"){
1763      int index = getGenMatchedParticleIndex(object);
1764      if(index == -1) value = 0;
# Line 1556 | Line 1769 | OSUAnalysis::valueLookup (const BNelectr
1769      if(index == -1) value = 0;
1770      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1771    }
1772 +  else if(variable == "genMatchedMotherIdReverse"){
1773 +    int index = getGenMatchedParticleIndex(object);
1774 +    if(index == -1) value = 23;
1775 +    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1776 +  }
1777    else if(variable == "genMatchedGrandmotherId"){
1778      int index = getGenMatchedParticleIndex(object);
1779      if(index == -1) value = 0;
# Line 1654 | Line 1872 | OSUAnalysis::valueLookup (const BNevent*
1872    }
1873    else if(variable == "muonScaleFactor"){
1874      if(datasetType_ != "data")
1875 <      value = muonSFWeight_->at (chosenMuon ()->eta);
1875 >      //      value = muonSFWeight_->at (chosenMuon ()->eta);
1876 >      value = 1.0;
1877      else
1878        value = 1.0;
1879    }
1880    else if(variable == "electronScaleFactor"){
1881      if(datasetType_ != "data")
1882 <      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1882 >      //      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1883 >      value = 1.0;
1884      else
1885        value = 1.0;
1886    }
1887 +  else if(variable == "cTauScaleFactor")
1888 +    value = cTauScaleFactor_;
1889  
1890    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1891  
# Line 1718 | Line 1940 | OSUAnalysis::valueLookup (const BNtau* o
1940    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
1941  
1942  
1943 +
1944 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1945 +
1946 +  else if(variable == "genMatchedPdgId"){
1947 +    int index = getGenMatchedParticleIndex(object);
1948 +    if(index == -1) value = 0;
1949 +    else value = mcparticles->at(index).id;
1950 +  }
1951 +
1952    else if(variable == "genMatchedId"){
1953      int index = getGenMatchedParticleIndex(object);
1954      if(index == -1) value = 0;
# Line 1728 | Line 1959 | OSUAnalysis::valueLookup (const BNtau* o
1959      if(index == -1) value = 0;
1960      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1961    }
1962 +  else if(variable == "genMatchedMotherIdReverse"){
1963 +    int index = getGenMatchedParticleIndex(object);
1964 +    if(index == -1) value = 23;
1965 +    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1966 +  }
1967    else if(variable == "genMatchedGrandmotherId"){
1968      int index = getGenMatchedParticleIndex(object);
1969      if(index == -1) value = 0;
# Line 1824 | Line 2060 | OSUAnalysis::valueLookup (const BNtrack*
2060  
2061    double value = 0.0;
2062    double pMag = sqrt(object->pt * object->pt +
2063 <                         object->pz * object->pz);
2064 <
2063 >                     object->pz * object->pz);
2064 >  
2065    if(variable == "pt") value = object->pt;
2066    else if(variable == "px") value = object->px;
2067    else if(variable == "py") value = object->py;
# Line 1856 | Line 2092 | OSUAnalysis::valueLookup (const BNtrack*
2092    else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2093    else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2094    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2095 +  
2096 +
2097    //user defined variables
2098    else if(variable == "d0wrtBS") value = (object->vx-events->at(0).BSx)*object->py/object->pt - (object->vy-events->at(0).BSy)*object->px/object->pt;
2099    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2100 <  else if(variable == "caloTotDeltaRp5") value =(object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2101 <  else if(variable == "caloTotDeltaRp5ByP") value =( (object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2102 <  else if(variable == "isIso") value = getTrkIsIso(object, tracks.product());
2103 <  else if(variable == "isMatchedDeadEcal") value = getTrkIsMatchedDeadEcal(object);
2104 <  else if(variable == "ptErrorByPt") value = (object->ptError/object->pt);
2105 <  else if(variable == "ptError") value = object->ptError;
2106 <  else if(variable == "ptRes") value = getTrkPtRes(object);
2100 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2101 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2102 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);  
2103 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;  
2104 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2105 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2106 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2107 >  else if(variable == "ptError")                    value = object->ptError;
2108 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2109 >  else if (variable == "d0wrtPV"){      
2110 >    double vx = object->vx - chosenVertex ()->x,        
2111 >      vy = object->vy - chosenVertex ()->y,      
2112 >      px = object->px,  
2113 >      py = object->py,  
2114 >      pt = object->pt;  
2115 >    value = (-vx * py + vy * px) / pt;  
2116 >  }      
2117 >  else if (variable == "dZwrtPV"){      
2118 >    double vx = object->vx - chosenVertex ()->x,        
2119 >      vy = object->vy - chosenVertex ()->y,      
2120 >      vz = object->vz - chosenVertex ()->z,      
2121 >      px = object->px,  
2122 >      py = object->py,  
2123 >      pz = object->pz,  
2124 >      pt = object->pt;  
2125 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);      
2126 >  }    
2127 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2128 >
2129 >  else if(variable == "genMatchedPdgId"){
2130 >    int index = getGenMatchedParticleIndex(object);
2131 >    if(index == -1) value = 0;
2132 >    else value = mcparticles->at(index).id;
2133 >  }
2134  
2135  
2136    else if(variable == "genMatchedId"){
# Line 1878 | Line 2143 | OSUAnalysis::valueLookup (const BNtrack*
2143      if(index == -1) value = 0;
2144      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2145    }
2146 +  else if(variable == "genMatchedMotherIdReverse"){
2147 +    int index = getGenMatchedParticleIndex(object);
2148 +    if(index == -1) value = 23;
2149 +    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2150 +  }
2151    else if(variable == "genMatchedGrandmotherId"){
2152      int index = getGenMatchedParticleIndex(object);
2153      if(index == -1) value = 0;
# Line 2179 | Line 2449 | OSUAnalysis::valueLookup (const BNphoton
2449    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2450  
2451  
2452 +
2453 +
2454 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2455 +
2456 +  else if(variable == "genMatchedPdgId"){
2457 +    int index = getGenMatchedParticleIndex(object);
2458 +    if(index == -1) value = 0;
2459 +    else value = mcparticles->at(index).id;
2460 +  }
2461 +
2462 +
2463 +
2464    else if(variable == "genMatchedId"){
2465      int index = getGenMatchedParticleIndex(object);
2466      if(index == -1) value = 0;
# Line 2189 | Line 2471 | OSUAnalysis::valueLookup (const BNphoton
2471      if(index == -1) value = 0;
2472      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2473    }
2474 +  else if(variable == "genMatchedMotherIdReverse"){
2475 +    int index = getGenMatchedParticleIndex(object);
2476 +    if(index == -1) value = 23;
2477 +    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2478 +  }
2479    else if(variable == "genMatchedGrandmotherId"){
2480      int index = getGenMatchedParticleIndex(object);
2481      if(index == -1) value = 0;
# Line 2237 | Line 2524 | OSUAnalysis::valueLookup (const BNmuon*
2524    double value = 0.0;
2525  
2526    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2527 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2528    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2529    else if(variable == "invMass"){
2530      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2531      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2532      value = (fourVector1 + fourVector2).M();
2533    }
2534 +  else if(variable == "pt"){
2535 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2536 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2537 +    value = (fourVector1 + fourVector2).Pt();
2538 +  }
2539    else if(variable == "threeDAngle")
2540      {
2541        TVector3 threeVector1(object1->px, object1->py, object1->pz);
# Line 2273 | Line 2566 | OSUAnalysis::valueLookup (const BNmuon*
2566    else if(variable == "muon2CorrectedD0Vertex"){
2567      value = object2->correctedD0Vertex;
2568    }
2569 < else if(variable == "muon1timeAtIpInOut"){
2569 >  else if(variable == "muon1timeAtIpInOut"){
2570      value = object1->timeAtIpInOut;
2571    }
2572 < else if(variable == "muon2timeAtIpInOut"){
2572 >  else if(variable == "muon2timeAtIpInOut"){
2573      value = object2->timeAtIpInOut;
2574    }
2575 +  else if(variable == "muon1correctedD0")
2576 +    {
2577 +      value = object1->correctedD0;
2578 +    }
2579 +  else if(variable == "muon2correctedD0")
2580 +    {
2581 +      value = object2->correctedD0;
2582 +    }
2583 +
2584    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2585  
2586    value = applyFunction(function, value);
# Line 2292 | Line 2594 | OSUAnalysis::valueLookup (const BNelectr
2594    double value = 0.0;
2595  
2596    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2597 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2598    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2599    else if(variable == "invMass"){
2600      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2601      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2602      value = (fourVector1 + fourVector2).M();
2603    }
2604 +  else if(variable == "pt"){
2605 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2606 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2607 +    value = (fourVector1 + fourVector2).Pt();
2608 +  }
2609    else if(variable == "threeDAngle")
2610      {
2611        TVector3 threeVector1(object1->px, object1->py, object1->pz);
# Line 2321 | Line 2629 | OSUAnalysis::valueLookup (const BNelectr
2629    else if(variable == "electron2CorrectedD0Vertex"){
2630      value = object2->correctedD0Vertex;
2631    }
2632 +  else if(variable == "electron1CorrectedD0"){
2633 +    value = object1->correctedD0;
2634 +  }
2635 +  else if(variable == "electron2CorrectedD0"){
2636 +    value = object2->correctedD0;
2637 +  }
2638  
2639    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2640  
# Line 2335 | Line 2649 | OSUAnalysis::valueLookup (const BNelectr
2649    double value = 0.0;
2650  
2651    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2652 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2653    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2654    else if(variable == "invMass"){
2655      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2656      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2657      value = (fourVector1 + fourVector2).M();
2658    }
2659 +  else if(variable == "pt"){
2660 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2661 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2662 +    value = (fourVector1 + fourVector2).Pt();
2663 +  }
2664    else if(variable == "threeDAngle")
2665      {
2666        TVector3 threeVector1(object1->px, object1->py, object1->pz);
# Line 2376 | Line 2696 | OSUAnalysis::valueLookup (const BNelectr
2696    else if(variable == "muonDetIso"){
2697      value = (object2->trackIsoDR03) / object2->pt;
2698    }
2699 <  else if(variable == "chargeProduct"){
2700 <    value = object1->charge * object2->charge;
2699 >  else if(variable == "electronRelPFrhoIso"){
2700 >    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
2701 >  }
2702 >  else if(variable == "muonRelPFdBetaIso"){
2703 >    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
2704    }
2705  
2706 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2707 +
2708 +  value = applyFunction(function, value);
2709 +
2710 +  return value;
2711 + }
2712 +
2713 +
2714 + double  
2715 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function){  
2716 +  double electronMass = 0.000511;        
2717 +  double value = 0.0;    
2718 +  TLorentzVector fourVector1(0, 0, 0, 0);        
2719 +  TLorentzVector fourVector2(0, 0, 0, 0);        
2720 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));  
2721 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2722 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);    
2723 +  else if(variable == "invMass"){        
2724 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);    
2725 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );    
2726 +        
2727 +    value = (fourVector1 + fourVector2).M();    
2728 +  }
2729 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}  
2730 +  value = applyFunction(function, value);        
2731 +  return value;  
2732 + }
2733 +
2734 +
2735 +
2736 + double
2737 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function){
2738 +  double pionMass = 0.140;
2739 +  double muonMass = 0.106;
2740 +  double value = 0.0;
2741 +  TLorentzVector fourVector1(0, 0, 0, 0);
2742 +  TLorentzVector fourVector2(0, 0, 0, 0);
2743 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2744 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2745 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2746 +  else if(variable == "invMass"){
2747 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
2748 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
2749 +
2750 +    value = (fourVector1 + fourVector2).M();
2751 +  }
2752  
2753    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2754 +  value = applyFunction(function, value);
2755 +  return value;
2756 + }
2757 +
2758 +
2759 + double
2760 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function){
2761 +  double value = 0.0;
2762 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2763 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2764 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2765 +  else if(variable == "invMass"){
2766 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2767 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2768 +    value = (fourVector1 + fourVector2).M();
2769 +  }
2770  
2771 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2772    value = applyFunction(function, value);
2773 +  return value;
2774 + }
2775 +
2776  
2777 + double
2778 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function){
2779 +  double value = 0.0;
2780 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2781 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2782 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2783 +  else if(variable == "invMass"){
2784 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2785 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2786 +    value = (fourVector1 + fourVector2).M();
2787 +  }
2788 +
2789 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2790 +  value = applyFunction(function, value);
2791    return value;
2792   }
2793  
2794 + double
2795 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function){
2796 +  double value = 0.0;
2797 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2798 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2799 +
2800 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2801 +  value = applyFunction(function, value);
2802 +  return value;
2803 + }
2804 +
2805 +
2806 +
2807 + double
2808 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function){
2809 +
2810 +  double value = 0.0;
2811 +  double pMag = sqrt(object1->pt * object1->pt +
2812 +                     object1->pz * object1->pz);  
2813 +
2814 +  if      (variable == "numPV")                      value = object2->numPV;
2815 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
2816 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
2817 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);  
2818 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;  
2819 +
2820 +  else { std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
2821 +
2822 +  value = applyFunction(function, value);
2823 +
2824 +  return value;
2825 +
2826 + }  
2827  
2828   // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
2829   // Return true iff no other tracks are found in this cone.
# Line 2434 | Line 2870 | OSUAnalysis::getTrkPtTrue (const BNtrack
2870  
2871   }
2872  
2873 + double
2874 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
2875 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.  
2876 +  if (!useTrackCaloRhoCorr_) return -99;  
2877 +  // if (!rhokt6CaloJetsHandle_) {
2878 +  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;  
2879 +  //   return -99;  
2880 +  // }
2881 +  double radDeltaRCone = 0.5;  
2882 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.  
2883 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;  
2884 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);  
2885 +  return caloTotRhoCorrCalo;  
2886 +
2887 + }
2888 +
2889 +
2890 +
2891 +
2892   //creates a map of the dead Ecal channels in the barrel and endcap
2893   //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
2894   //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
# Line 2477 | Line 2932 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
2932    return value;
2933   }
2934  
2935 <
2936 <
2935 > // Returns the smallest DeltaR between the object and any generated true particle in the event.  
2936 > template <class InputObject>
2937 > double OSUAnalysis::getGenDeltaRLowest(InputObject object){
2938 >  double genDeltaRLowest = 999.;
2939 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
2940 >    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
2941 >    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
2942 >  }
2943 >  return genDeltaRLowest;
2944 > }
2945  
2946   double
2947   OSUAnalysis::applyFunction(string function, double value){
# Line 2498 | Line 2961 | OSUAnalysis::applyFunction(string functi
2961  
2962   template <class InputCollection>
2963   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
2964 <
2964 >
2965 >  if (currentCut.inputCollection.find("pair")!=std::string::npos)  {
2966 >    string obj1, obj2;
2967 >    getTwoObjs(currentCut.inputCollection, obj1, obj2);
2968 >    if (inputType==obj1 ||
2969 >        inputType==obj2) {
2970 >      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
2971 >      // and the inputType is a member of the pair.  
2972 >      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.  
2973 >      // For example, if currentCut.inputCollection==electron-muon pairs,
2974 >      // then the flags should not be set here when inputType==muons or inputType==electrons.  
2975 >      return;
2976 >    }  
2977 >  }    
2978  
2979    for (uint object = 0; object != inputCollection->size(); object++){
2980  
2505
2981      bool decision = true;//object passes if this cut doesn't cut on that type of object
2982  
2508
2983      if(currentCut.inputCollection == inputType){
2984  
2985        vector<bool> subcutDecisions;
2986        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
2987          double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
2988          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
2989 +
2990        }
2991        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
2992        else{
# Line 2525 | Line 3000 | void OSUAnalysis::setObjectFlags(cut &cu
3000          decision = tempDecision;
3001        }
3002      }
2528    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3003  
3004 +    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3005  
3006      //set flags for objects that pass each cut AND all the previous cuts
3007      bool previousCumulativeFlag = true;
# Line 2536 | Line 3011 | void OSUAnalysis::setObjectFlags(cut &cu
3011      }
3012      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3013  
2539
3014    }
3015  
3016   }
# Line 2550 | Line 3024 | void OSUAnalysis::setObjectFlags(cut &cu
3024    bool sameObjects = false;
3025    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3026  
3027 <
3027 >  // Get the strings for the two objects that make up the pair.  
3028 >  string obj1Type, obj2Type;
3029 >  getTwoObjs(inputType, obj1Type, obj2Type);
3030 >  bool isTwoTypesOfObject = true;
3031 >  if (obj1Type==obj2Type) isTwoTypesOfObject = false;  
3032 >
3033 >  // Initialize the flags for individual objects to all be false, if the cut is on the pair.  
3034 >  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).  
3035 >  if (currentCut.inputCollection == inputType) {    
3036 >    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
3037 >      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3038 >      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3039 >    }
3040 >    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.  
3041 >      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
3042 >        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3043 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3044 >      }
3045 >    }
3046 >  }
3047 >  
3048    int counter = 0;
3049 +
3050    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3051      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3052  
# Line 2580 | Line 3075 | void OSUAnalysis::setObjectFlags(cut &cu
3075            decision = tempDecision;
3076          }
3077        }
3078 <      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3078 >      // if (decision) isPassObj1.at(object1) = true;
3079 >      // if (decision) isPassObj2.at(object2) = true;
3080 >      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);  
3081 >      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on  
3082 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;  
3083 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;  
3084 >      }  
3085  
3086        //set flags for objects that pass each cut AND all the previous cuts
3087        bool previousCumulativeFlag = true;
# Line 2595 | Line 3096 | void OSUAnalysis::setObjectFlags(cut &cu
3096        else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
3097        else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
3098        cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
3099 <
3099 >      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on  
3100 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);  
3101 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);  
3102 >      }
3103        counter++;
2600    }
2601
2602  }
3104  
3105 +    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3106 +  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3107  
3108   }
3109  
3110  
3111 + bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
3112 +  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3113 +  // all cuts up to currentCutIndex  
3114 +  bool previousCumulativeFlag = true;  
3115 +  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {  
3116 +    if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
3117 +    else {  
3118 +      previousCumulativeFlag = false; break;  
3119 +    }
3120 +  }
3121 +  return previousCumulativeFlag;  
3122 + }  
3123 +
3124 +
3125   template <class InputCollection>
3126   void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3127  
# Line 2627 | Line 3144 | void OSUAnalysis::fill1DHistogram(TH1* h
3144      double value = valueLookup(&inputCollection->at(object), inputVariable, function);
3145      histo->Fill(value,scaleFactor);
3146  
3147 +    if (printEventInfo_) {
3148 +      // Write information about event to screen, for testing purposes.  
3149 +      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;  
3150 +    }
3151 +    
3152    }
2631
3153   }
3154  
3155   template <class InputCollection1, class InputCollection2>
# Line 2637 | Line 3158 | void OSUAnalysis::fill1DHistogram(TH1* h
3158    bool sameObjects = false;
3159    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3160  
3161 <  int pairCounter = 0;
3161 >  int pairCounter = -1;
3162    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3163      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3164  
3165        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3166  
3167 +      pairCounter++;
3168        //only take objects which have passed all cuts and pairs which have passed all cuts
3169        if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3170        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
# Line 2663 | Line 3185 | void OSUAnalysis::fill1DHistogram(TH1* h
3185        double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3186        histo->Fill(value,scaleFactor);
3187  
2666      pairCounter++;
3188      }
3189    }
3190  
# Line 2716 | Line 3237 | void OSUAnalysis::fill2DHistogram(TH2* h
3237    bool sameObjects = false;
3238    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3239  
3240 <  int pairCounter = 0;
3240 >  int pairCounter = -1;
3241    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3242      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3243  
3244        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3245  
3246 +      pairCounter++;
3247 +
3248        //only take objects which have passed all cuts and pairs which have passed all cuts
3249        if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3250        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
# Line 2756 | Line 3279 | void OSUAnalysis::fill2DHistogram(TH2* h
3279  
3280        histo->Fill(valueX,valueY,scaleFactor);
3281  
2759      pairCounter++;
2760
3282      }
3283    }
3284  
# Line 2774 | Line 3295 | int OSUAnalysis::getGenMatchedParticleIn
3295  
3296      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
3297      if(currentDeltaR > 0.05) continue;
3298 < //     cout << std::setprecision(3) << std::setw(20)
3299 < //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
3300 < //          << std::setw(20)
3301 < //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
3302 < //          << std::setw(20)
3303 < //          << "\tdeltaR = " << currentDeltaR
3304 < //          << std::setprecision(1)
3305 < //          << std::setw(20)
3306 < //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
3307 < //          << std::setw(20)
3308 < //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
3309 < //          << std::setw(20)
3310 < //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
3298 >    //     cout << std::setprecision(3) << std::setw(20)
3299 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
3300 >    //          << std::setw(20)
3301 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
3302 >    //          << std::setw(20)
3303 >    //          << "\tdeltaR = " << currentDeltaR
3304 >    //          << std::setprecision(1)
3305 >    //          << std::setw(20)
3306 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
3307 >    //          << std::setw(20)
3308 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
3309 >    //          << std::setw(20)
3310 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
3311      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
3312        bestMatchIndex = mcparticle - mcparticles->begin();
3313        bestMatchDeltaR = currentDeltaR;
3314      }
3315  
3316    }
3317 < //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
3318 < //   else cout << "no match found..." << endl;
3317 >  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
3318 >  //   else cout << "no match found..." << endl;
3319    return bestMatchIndex;
3320  
3321   }
# Line 2885 | Line 3406 | OSUAnalysis::chosenVertex ()
3406    const BNprimaryvertex *chosenVertex = 0;
3407    if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
3408      vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
3409 <                               cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
3409 >      cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
3410      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
3411        if(!vertexFlags.at(vertexIndex)) continue;
3412        chosenVertex = & primaryvertexs->at(vertexIndex);
# Line 2905 | Line 3426 | OSUAnalysis::chosenMET ()
3426    const BNmet *chosenMET = 0;
3427    if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
3428      vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
3429 <                            cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
3429 >      cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
3430      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
3431        if(!metFlags.at(metIndex)) continue;
3432        chosenMET = & mets->at(metIndex);
# Line 2925 | Line 3446 | OSUAnalysis::chosenElectron ()
3446    const BNelectron *chosenElectron = 0;
3447    if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
3448      vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
3449 <                                 cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
3449 >      cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
3450      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
3451        if(!electronFlags.at(electronIndex)) continue;
3452        chosenElectron = & electrons->at(electronIndex);
# Line 2945 | Line 3466 | OSUAnalysis::chosenMuon ()
3466    const BNmuon *chosenMuon = 0;
3467    if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
3468      vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
3469 <                             cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
3469 >      cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
3470      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
3471        if(!muonFlags.at(muonIndex)) continue;
3472        chosenMuon = & muons->at(muonIndex);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines