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.8 by ahart, Wed Jan 30 22:29:59 2013 UTC vs.
Revision 1.17 by lantonel, Thu Feb 21 16:38:25 2013 UTC

# Line 16 | Line 16 | OSUAnalysis::OSUAnalysis (const edm::Par
16    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
17    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
18    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
19 <
20 <
21 <  channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels"))
19 >  puFile_ (cfg.getParameter<std::string> ("puFile")),
20 >  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
21 >  dataset_ (cfg.getParameter<std::string> ("dataset")),
22 >  datasetType_ (cfg.getParameter<std::string> ("datasetType")),
23 >  channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
24 >  histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
25 >  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents"))
26  
27   {
28 +
29    TH1::SetDefaultSumw2 ();
30  
31 +  //create pile-up reweighting object, if necessary
32 +  if(datasetType_ != "data") puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
33 +
34    // Construct Cutflow Objects. These store the results of cut decisions and
35    // handle filling cut flow histograms.
36    masterCutFlow_ = new CutFlow (fs_);
37    std::vector<TFileDirectory> directories;
38  
39 +  //always get vertex collection so we can assign the primary vertex in the event
40 +  allNecessaryObjects.push_back("primaryvertexs");
41 +  //always make the plot of number of primary verticex (to check pile-up reweighting)
42 +  objectsToPlot.push_back("primaryvertexs");
43 +
44 +  //always get the event collection to do pile-up reweighting
45 +  allNecessaryObjects.push_back("events");
46 +
47 +  //parse the histogram definitions
48 +  for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
49 +
50 +    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
51 +    if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
52 +    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
53 +      objectsToPlot.push_back(tempInputCollection);
54 +      allNecessaryObjects.push_back(tempInputCollection);
55 +    }
56 +    else{//pair of objects, need to add them both to the things to allNecessaryObjects
57 +      int dashIndex = tempInputCollection.find("-");
58 +      int spaceIndex = tempInputCollection.find(" ");
59 +      int secondWordLength = spaceIndex - dashIndex;
60 +      allNecessaryObjects.push_back(tempInputCollection);
61 +      allNecessaryObjects.push_back(tempInputCollection.substr(0,dashIndex)+"s");
62 +      allNecessaryObjects.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
63 +      objectsToPlot.push_back(tempInputCollection);
64 +      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
65 +      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
66 +      }
67 +
68 +    vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
69 +    
70 +    for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
71 +
72 +      histogram tempHistogram;
73 +      tempHistogram.inputCollection = tempInputCollection;
74 +      tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
75 +      tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
76 +      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
77 +      tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
78 +      
79 +      histograms.push_back(tempHistogram);
80 +
81 +    }
82 +  }
83 +  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object
84 +  sort( objectsToPlot.begin(), objectsToPlot.end() );
85 +  objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
86 +
87 +
88 +
89  
90    channel tempChannel;
91    //loop over all channels (event selections)
# Line 50 | Line 108 | OSUAnalysis::OSUAnalysis (const edm::Par
108      }
109  
110  
111 +
112 +
113      //create cutFlow for this channel
114      cutFlows_.push_back (new CutFlow (fs_, channelName));
115  
116      //book a directory in the output file with the name of the channel
117      TFileDirectory subDir = fs_->mkdir( channelName );
118      directories.push_back(subDir);
59    std::map<std::string, TH1D*> histoMap;
60    oneDHists_.push_back(histoMap);
119  
120 <    //gen histograms
121 <    oneDHists_.at(currentChannel)["genD0"] = directories.at(currentChannel).make<TH1D> ("genD0",channelLabel+" channel: Gen d_{0}; d_{0} [cm] ", 1000, -1, 1);
122 <    oneDHists_.at(currentChannel)["genAbsD0"] = directories.at(currentChannel).make<TH1D> ("genAbsD0",channelLabel+" channel: Gen d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
123 <    oneDHists_.at(currentChannel)["genDZ"] = directories.at(currentChannel).make<TH1D> ("genDZ",channelLabel+" channel: Gen d_{z}; d_{z} [cm] ", 1000, -10, 10);
66 <    oneDHists_.at(currentChannel)["genAbsDZ"] = directories.at(currentChannel).make<TH1D> ("genAbsDZ",channelLabel+" channel: Gen d_{z}; |d_{z}| [cm] ", 1000, 0, 10);
67 <
68 <    //muon histograms
69 <    allNecessaryObjects.push_back("muons");
70 <    oneDHists_.at(currentChannel)["muonPt"]  = directories.at(currentChannel).make<TH1D> ("muonPt",channelLabel+" channel: Muon Transverse Momentum; p_{T} [GeV]", 100, 0, 500);
71 <    oneDHists_.at(currentChannel)["muonEta"] = directories.at(currentChannel).make<TH1D> ("muonEta",channelLabel+" channel: Muon Eta; #eta", 100, -5, 5);
72 <    oneDHists_.at(currentChannel)["muonD0"] = directories.at(currentChannel).make<TH1D> ("muonD0",channelLabel+" channel: Muon d_{0}; d_{0} [cm] ", 1000, -1, 1);
73 <    oneDHists_.at(currentChannel)["muonDz"] = directories.at(currentChannel).make<TH1D> ("muonDz",channelLabel+" channel: Muon d_{z}; d_{z} [cm] ", 1000, -20, 20);
74 <    oneDHists_.at(currentChannel)["muonAbsD0"] = directories.at(currentChannel).make<TH1D> ("muonAbsD0",channelLabel+" channel: Muon d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
75 <    oneDHists_.at(currentChannel)["muonDZ"] = directories.at(currentChannel).make<TH1D> ("muonDZ",channelLabel+" channel: Muon d_{z}; d_{z} [cm] ", 1000, -10, 10);
76 <    oneDHists_.at(currentChannel)["muonAbsDZ"] = directories.at(currentChannel).make<TH1D> ("muonAbsDZ",channelLabel+" channel: Muon d_{z}; |d_{z}| [cm] ", 1000, 0, 10);
77 <    oneDHists_.at(currentChannel)["muonD0Sig"] = directories.at(currentChannel).make<TH1D> ("muonD0Sig",channelLabel+" channel: Muon d_{0} Significance; d_{0} / #sigma_{d_{0}} ", 1000, -10.0, 10.0);
78 <    oneDHists_.at(currentChannel)["muonAbsD0Sig"] = directories.at(currentChannel).make<TH1D> ("muonAbsD0Sig",channelLabel+" channel: Muon d_{0} Significance; |d_{0}| / #sigma_{d_{0}} ", 1000, 0, 10.0);
79 <    oneDHists_.at(currentChannel)["muonIso"] = directories.at(currentChannel).make<TH1D> ("muonIso",channelLabel+" channel: Muon Combined Relative Isolation; rel. iso. ", 1000, 0, 1);
80 <    oneDHists_.at(currentChannel)["numMuons"] = directories.at(currentChannel).make<TH1D> ("numMuons",channelLabel+" channel: Number of Selected Muons; # muons", 10, 0, 10);
81 <
82 <
83 <    //electron histograms
84 <    allNecessaryObjects.push_back("electrons");
85 <    oneDHists_.at(currentChannel)["electronPt"]  = directories.at(currentChannel).make<TH1D> ("electronPt",channelLabel+" channel: Electron Transverse Momentum; p_{T} [GeV]", 100, 0, 500);
86 <    oneDHists_.at(currentChannel)["electronEta"] = directories.at(currentChannel).make<TH1D> ("electronEta",channelLabel+" channel: Electron Eta; #eta", 50, -5, 5);
87 <    oneDHists_.at(currentChannel)["electronD0"] = directories.at(currentChannel).make<TH1D> ("electronD0",channelLabel+" channel: Electron d_{0}; d_{0} [cm] ", 1000, -1, 1);
88 <    oneDHists_.at(currentChannel)["electronDz"] = directories.at(currentChannel).make<TH1D> ("electronDz",channelLabel+" channel: Electron d_{z}; d_{z} [cm] ", 1000, -20, 20);
89 <    oneDHists_.at(currentChannel)["electronAbsD0"] = directories.at(currentChannel).make<TH1D> ("electronAbsD0",channelLabel+" channel: Electron d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
90 <    oneDHists_.at(currentChannel)["electronDZ"] = directories.at(currentChannel).make<TH1D> ("electronDZ",channelLabel+" channel: Electron d_{z}; d_{z} [cm] ", 1000, -10, 10);
91 <    oneDHists_.at(currentChannel)["electronAbsDZ"] = directories.at(currentChannel).make<TH1D> ("electronAbsDZ",channelLabel+" channel: Electron d_{z}; |d_{z}| [cm] ", 1000, 0, 10);
92 <    oneDHists_.at(currentChannel)["electronD0Sig"] = directories.at(currentChannel).make<TH1D> ("electronD0Sig",channelLabel+" channel: Electron d_{0} Significance; d_{0} / #sigma_{d_{0}} ", 1000, -10.0, 10.0);
93 <    oneDHists_.at(currentChannel)["electronAbsD0Sig"] = directories.at(currentChannel).make<TH1D> ("electronAbsD0Sig",channelLabel+" channel: Electron d_{0} Significance; |d_{0}| / #sigma_{d_{0}} ", 1000, 0, 10.0);
94 <    oneDHists_.at(currentChannel)["electronIso"] = directories.at(currentChannel).make<TH1D> ("electronIso",channelLabel+" channel: Electron Combined Relative Isolation; rel. iso. ", 1000, 0, 1);
95 <    oneDHists_.at(currentChannel)["electronFbrem"] = directories.at(currentChannel).make<TH1D> ("electronFbrem",channelLabel+" channel: Electron Brem. Energy Fraction; fbrem", 1000, 0, 2);
96 <    oneDHists_.at(currentChannel)["electronMVATrig"] = directories.at(currentChannel).make<TH1D> ("electronMVATrig",channelLabel+" channel: Electron ID MVA Output", 100, -1, 1);
97 <    oneDHists_.at(currentChannel)["electronMVANonTrig"] = directories.at(currentChannel).make<TH1D> ("electronMVANonTrig",channelLabel+" channel: Electron ID MVA Output", 100, -1, 1);
98 <    oneDHists_.at(currentChannel)["numElectrons"] = directories.at(currentChannel).make<TH1D> ("numElectrons",channelLabel+" channel: Number of Selected Electrons; # electrons", 10, 0, 10);
120 >    std::map<std::string, TH1D*> oneDhistoMap;
121 >    oneDHists_.push_back(oneDhistoMap);
122 >    std::map<std::string, TH2D*> twoDhistoMap;
123 >    twoDHists_.push_back(twoDhistoMap);
124  
125  
126 +    //book all histograms included in the configuration
127 +    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
128 +      histogram currentHistogram = histograms.at(currentHistogramIndex);
129 +      int numBinsElements = currentHistogram.bins.size();
130 +      int numInputVariables = currentHistogram.inputVariables.size();
131 +
132  
102    //get list of cuts for this channel
103    vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
133  
134 <    vector<string> tempInputCollections;
134 >      if(numBinsElements != 3 && numBinsElements !=6) {
135 >        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
136 >        exit(0);
137 >      }
138 >      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
139 >        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
140 >        exit(0);
141 >      }
142 >      else if(numBinsElements == 3){
143 >        oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
144 >      }
145 >      else if(numBinsElements == 6){
146 >        twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2),currentHistogram.bins.at(3),currentHistogram.bins.at(4),currentHistogram.bins.at(5));
147 >
148 >      }
149  
150  
151 +    }
152 +    //book a histogram for the number of each object type to be plotted
153 +    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
154 +      string currentObject = objectsToPlot.at(currentObjectIndex);
155 +      int maxNum = 10;
156 +      if(currentObject == "mcparticles") maxNum = 50;
157 +      else if(currentObject == "primaryvertexs") maxNum = 50;
158 +      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
159 +      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
160 +      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
161 +
162 +      currentObject.at(0) = toupper(currentObject.at(0));
163 +      string histoName = "num" + currentObject;
164 +
165 +      if(histoName == "numPrimaryvertexs"){
166 +        string newHistoName = histoName + "BeforePileupCorrection";
167 +        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);    
168 +        newHistoName = histoName + "AfterPileupCorrection";
169 +        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
170 +      }
171 +      else
172 +        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
173 +    }
174 +
175 +
176 +    //get list of cuts for this channel
177 +    vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
178 +
179      //loop over and parse all cuts
180      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
110
181        cut tempCut;
182 <     //store input collection for cut
183 <      string inputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
184 <      tempCut.inputCollection = inputCollection;
182 >      //store input collection for cut
183 >      string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
184 >      tempCut.inputCollection = tempInputCollection;
185 >      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
186 >        allNecessaryObjects.push_back(tempInputCollection);
187 >      }
188 >      else{//pair of objects, need to add them both to the things to allNecessaryObjects
189 >        int dashIndex = tempInputCollection.find("-");
190 >        int spaceIndex = tempInputCollection.find(" ");
191 >        int secondWordLength = spaceIndex - dashIndex;
192 >        allNecessaryObjects.push_back(tempInputCollection);
193 >        allNecessaryObjects.push_back(tempInputCollection.substr(0,dashIndex)+"s");
194 >        allNecessaryObjects.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
195 >
196 >      }
197 >
198  
116      tempInputCollections.push_back(inputCollection);
117      allNecessaryObjects.push_back(inputCollection);
199  
200        //split cut string into parts and store them
201        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
202        std::vector<string> cutStringVector = splitString(cutString);
203 <      tempCut.variable = cutStringVector.at(0);// variable to cut on
204 <      tempCut.comparativeOperator = cutStringVector.at(1);// comparison to make
205 <      tempCut.cutValue = atof(cutStringVector.at(2).c_str());// threshold value to pass cut
203 >      if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
204 >        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
205 >        exit(0);
206 >      }
207 >      tempCut.numSubcuts = (cutStringVector.size()+1)/4;
208 >      for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
209 >        int indexOffset = 4 * subcutIndex;
210 >        string currentVariableString = cutStringVector.at(indexOffset);
211 >        if(currentVariableString.find("(")==std::string::npos){
212 >          tempCut.functions.push_back("");//no function was specified
213 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
214 >        }
215 >        else{
216 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
217 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
218 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
219 >        }
220 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
221 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
222 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
223 >      }
224  
225        //get number of objects required to pass cut for event to pass
226        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
227        std::vector<string> numberRequiredVector = splitString(numberRequiredString);
228 +      if(numberRequiredVector.size()!=2){
229 +        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
230 +        exit(0);
231 +      }
232  
130      // determine number required if comparison contains "="
233        int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
132      if(numberRequiredVector.at(0) == ">") numberRequiredInt++;
133      else if(numberRequiredVector.at(0) == "<") numberRequiredInt--;
134
234        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
235        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
236  
237 <      if(cuts_.at(currentCut).exists("function")){
139 <        tempCut.function = cuts_.at(currentCut).getParameter<string> ("function");
140 <      }
141 <      else tempCut.function = "";
237 >
238        string tempCutName;
239        if(cuts_.at(currentCut).exists("alias")){
240          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
# Line 146 | Line 242 | OSUAnalysis::OSUAnalysis (const edm::Par
242        else{
243          //construct string for cutflow table
244          bool plural = numberRequiredInt != 1;
245 <        string collectionString = plural ? inputCollection : inputCollection.substr(0, inputCollection.size()-1);
245 >        string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
246          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
247          tempCutName = cutName;
248        }
# Line 156 | Line 252 | OSUAnalysis::OSUAnalysis (const edm::Par
252        tempChannel.cuts.push_back(tempCut);
253  
254  
159    }//end loop over cuts
255  
256 <    //make unique vector of all objects that this channel cuts on (so we know to set flags for those)
162 <    sort( tempInputCollections.begin(), tempInputCollections.end() );
163 <    tempInputCollections.erase( unique( tempInputCollections.begin(), tempInputCollections.end() ), tempInputCollections.end() );
164 <    tempChannel.inputCollections = tempInputCollections;
256 >    }//end loop over cuts
257  
258      channels.push_back(tempChannel);
259      tempChannel.cuts.clear();
260  
261    }//end loop over channels
262  
263 +
264    //make unique vector of objects we need to cut on (so we make sure to get them from the event)
265    sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
266    allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
# Line 247 | Line 340 | OSUAnalysis::analyze (const edm::Event &
340      event.getByLabel (superclusters_, superclusters);
341  
342  
343 +  //get pile-up event weight
344 +  double puScaleFactor = 0;
345 +  if(datasetType_ != "data")
346 +    puScaleFactor = puWeight_->at (events->at (0).numTruePV);
347 +  else
348 +    puScaleFactor = 1.00;
349 +
350 +
351    //loop over all channels
352  
353    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
# Line 267 | Line 368 | OSUAnalysis::analyze (const edm::Event &
368        cut currentCut = currentChannel.cuts.at(currentCutIndex);
369  
370        for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
270
371          string currentObject = allNecessaryObjects.at(currentObjectIndex);
372 +
373          individualFlags[currentObject].push_back (vector<bool> ());
374          cumulativeFlags[currentObject].push_back (vector<bool> ());
375  
376 +
377          if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
378          else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
379          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
# Line 286 | Line 388 | OSUAnalysis::analyze (const edm::Event &
388          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
389          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
390  
391 +        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(),"muon-muon pairs");
392 +        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(),"electron-electron pairs");
393 +        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(),"electron-muon pairs");
394  
395        }
396  
# Line 295 | Line 400 | OSUAnalysis::analyze (const edm::Event &
400  
401  
402  
298
403      //use cumulative flags to apply cuts at event level
404  
405      bool eventPassedAllCuts = true;
# Line 310 | Line 414 | OSUAnalysis::analyze (const edm::Event &
414        cut currentCut = currentChannel.cuts.at(currentCutIndex);
415        int numberPassing = 0;
416  
417 <      for (uint object = 0; object != cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).size() ; object++)
418 <          if(cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).at(object)) numberPassing++;
419 <
417 >      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
418 >          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
419 >      }
420  
421        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
422        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
# Line 321 | Line 425 | OSUAnalysis::analyze (const edm::Event &
425  
426      }
427  
428 <    cutFlows_.at(currentChannelIndex)->fillCutFlow();
428 >    cutFlows_.at(currentChannelIndex)->fillCutFlow(puScaleFactor);
429  
430  
431  
432      if(!eventPassedAllCuts)continue;
433  
434  
331    TVector3 vertexPosition;
332    vector<bool> vertexFlags = cumulativeFlags["primaryvertexs"].back();
435  
436 +
437 +    //set position of primary vertex in event, in order to calculate quantities relative to it
438 +    primaryVertex_ = 0;
439 +    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back();
440      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
441        if(!vertexFlags.at(vertexIndex)) continue;
442 <
337 <      vertexPosition.SetXYZ (primaryvertexs->at(vertexIndex).x,primaryvertexs->at(vertexIndex).y,primaryvertexs->at(vertexIndex).z);
442 >      primaryVertex_ = new BNprimaryvertex (primaryvertexs->at (vertexIndex));
443        break;
444      }
445  
341    vector<bool> mcparticleFlags = cumulativeFlags["mcparticles"].back();
446  
343    for (uint mcparticleIndex = 0; mcparticleIndex != mcparticleFlags.size(); mcparticleIndex++){
344      if(!mcparticleFlags.at(mcparticleIndex)) continue;
447  
448 <      double vx = mcparticles->at(mcparticleIndex).vx - vertexPosition.X (),
449 <             vy = mcparticles->at(mcparticleIndex).vy - vertexPosition.Y (),
450 <             vz = mcparticles->at(mcparticleIndex).vz - vertexPosition.Z (),
451 <             px = mcparticles->at(mcparticleIndex).px,
452 <             py = mcparticles->at(mcparticleIndex).py,
453 <             pt = mcparticles->at(mcparticleIndex).pt,
454 <             d0;
455 <
456 <      d0 = (-vx * py + vy * px) / pt;
457 <      oneDHists_.at(currentChannelIndex)["genD0"]->Fill (d0);
458 <      oneDHists_.at(currentChannelIndex)["genAbsD0"]->Fill (fabs (d0));
459 <      oneDHists_.at(currentChannelIndex)["genDZ"]->Fill (vz);
460 <      oneDHists_.at(currentChannelIndex)["genAbsDZ"]->Fill (fabs (vz));
461 <    }
462 <
463 <    vector<bool> electronFlags = cumulativeFlags["electrons"].back();
464 <    int electronCounter = 0;
465 <
466 <    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
467 <      if(!electronFlags.at(electronIndex)) continue;
468 <
469 <
470 <      electronCounter++;
471 <      oneDHists_.at(currentChannelIndex)["electronPt"]->Fill (electrons->at(electronIndex).pt);
472 <      oneDHists_.at(currentChannelIndex)["electronEta"]->Fill (electrons->at(electronIndex).eta);
473 <      oneDHists_.at(currentChannelIndex)["electronD0"]->Fill (electrons->at(electronIndex).correctedD0Vertex);
474 <      oneDHists_.at(currentChannelIndex)["electronDz"]->Fill (electrons->at(electronIndex).correctedDZ);
475 <      oneDHists_.at(currentChannelIndex)["electronAbsD0"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex));
476 <      oneDHists_.at(currentChannelIndex)["electronDZ"]->Fill (electrons->at(electronIndex).correctedDZ);
477 <      oneDHists_.at(currentChannelIndex)["electronAbsDZ"]->Fill (fabs(electrons->at(electronIndex).correctedDZ));
478 <      oneDHists_.at(currentChannelIndex)["electronD0Sig"]->Fill (electrons->at(electronIndex).correctedD0Vertex / electrons->at(electronIndex).tkD0err);
479 <      oneDHists_.at(currentChannelIndex)["electronAbsD0Sig"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex) / electrons->at(electronIndex).tkD0err);
480 <      oneDHists_.at(currentChannelIndex)["electronIso"]->Fill (electrons->at(electronIndex).puChargedHadronIso / electrons->at(electronIndex).pt);
481 <      oneDHists_.at(currentChannelIndex)["electronFbrem"]->Fill (electrons->at(electronIndex).fbrem);
482 <      oneDHists_.at(currentChannelIndex)["electronMVATrig"]->Fill (electrons->at(electronIndex).mvaTrigV0);
483 <      oneDHists_.at(currentChannelIndex)["electronMVANonTrig"]->Fill (electrons->at(electronIndex).mvaNonTrigV0);
484 <
485 <    }
486 <    oneDHists_.at(currentChannelIndex)["numElectrons"]->Fill (electronCounter);
487 <
488 <
489 <    vector<bool> muonFlags = cumulativeFlags["muons"].back();
490 <    int muonCounter = 0;
491 <
492 <
493 <    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
494 <      if(!muonFlags.at(muonIndex)) continue;
495 <      muonCounter++;
496 <
497 <      oneDHists_.at(currentChannelIndex)["muonPt"]->Fill (muons->at(muonIndex).pt);
498 <      oneDHists_.at(currentChannelIndex)["muonEta"]->Fill (muons->at(muonIndex).eta);
499 <      oneDHists_.at(currentChannelIndex)["muonD0"]->Fill (muons->at(muonIndex).correctedD0Vertex);
500 <      oneDHists_.at(currentChannelIndex)["muonDz"]->Fill (muons->at(muonIndex).correctedDZ);
501 <      oneDHists_.at(currentChannelIndex)["muonAbsD0"]->Fill (fabs(muons->at(muonIndex).correctedD0Vertex));
502 <      oneDHists_.at(currentChannelIndex)["muonDZ"]->Fill (muons->at(muonIndex).correctedDZ);
503 <      oneDHists_.at(currentChannelIndex)["muonAbsDZ"]->Fill (fabs(muons->at(muonIndex).correctedDZ));
402 <      oneDHists_.at(currentChannelIndex)["muonD0Sig"]->Fill (muons->at(muonIndex).correctedD0Vertex / muons->at(muonIndex).tkD0err);
403 <      oneDHists_.at(currentChannelIndex)["muonAbsD0Sig"]->Fill (fabs(muons->at(muonIndex).correctedD0Vertex) / muons->at(muonIndex).tkD0err);
404 <      oneDHists_.at(currentChannelIndex)["muonIso"]->Fill (muons->at(muonIndex).puChargedHadronIso / muons->at(muonIndex).pt);
448 >    //filling histograms
449 >    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
450 >      histogram currentHistogram = histograms.at(histogramIndex);
451 >
452 >      if(currentHistogram.inputVariables.size() == 1){
453 >        TH1D* histo;
454 >        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
455 >        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
456 >        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
457 >        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),\
458 >                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(),\
459 >                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
460 >        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
461 >        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
462 >                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
463 >                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
464 >        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
465 >                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
466 >                                                                                              cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
467 >        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
468 >        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
469 >        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
470 >        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
471 >        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
472 >        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
473 >        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
474 >        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
475 >        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
476 >        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
477 >      }
478 >      else if(currentHistogram.inputVariables.size() == 2){
479 >        TH2D* histo;
480 >        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
481 >        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
482 >        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
483 >        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
484 >                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
485 >                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
486 >        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
487 >        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
488 >                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
489 >                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
490 >        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
491 >                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
492 >                                                                                               cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
493 >        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
494 >        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
495 >        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
496 >        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
497 >        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
498 >        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
499 >        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
500 >        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
501 >        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
502 >        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
503 >      }
504      }
406    oneDHists_.at(currentChannelIndex)["numMuons"]->Fill (muonCounter);
407
408
505  
506  
507 +    //fills histograms with the sizes of collections
508 +    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
509 +      string currentObject = objectsToPlot.at(currentObjectIndex);
510 +
511 +      if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
512 +      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
513 +      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
514 +      string tempCurrentObject = currentObject;
515 +      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
516 +      string histoName = "num" + tempCurrentObject;
517 +
518 +
519 +      if(currentObject == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),puScaleFactor);
520 +      else if(currentObject == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),puScaleFactor);
521 +      else if(currentObject == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,puScaleFactor);
522 +      else if(currentObject == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),puScaleFactor);
523 +      else if(currentObject == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,puScaleFactor);
524 +      else if(currentObject == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),puScaleFactor);
525 +      else if(currentObject == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),puScaleFactor);
526 +      else if(currentObject == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),puScaleFactor);
527 +      else if(currentObject == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),puScaleFactor);
528 +      else if(currentObject == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),puScaleFactor);
529 +      else if(currentObject == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),puScaleFactor);
530 +      else if(currentObject == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),puScaleFactor);
531 +      else if(currentObject == "primaryvertexs"){
532 +        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
533 +        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),puScaleFactor);
534 +      }
535 +      else if(currentObject == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),puScaleFactor);
536 +      else if(currentObject == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),puScaleFactor);
537 +      else if(currentObject == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),puScaleFactor);
538  
539 +    }
540    } //end loop over channel
541  
542 <  masterCutFlow_->fillCutFlow();
542 >  masterCutFlow_->fillCutFlow(puScaleFactor);
543 >
544  
545  
546   }
# Line 426 | Line 555 | OSUAnalysis::evaluateComparison (double
555    else if(comparison == "<")  return testValue <  cutValue;
556    else if(comparison == "<=") return testValue <= cutValue;
557    else if(comparison == "==") return testValue == cutValue;
558 +  else if(comparison == "=") return testValue == cutValue;
559    else if(comparison == "!=") return testValue != cutValue;
560    else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
561  
# Line 746 | Line 876 | OSUAnalysis::valueLookup (const BNmuon*
876    else if(variable == "numberOfMatchedStations") value = object->numberOfMatchedStations;
877    else if(variable == "time_ndof") value = object->time_ndof;
878  
879 +  //user-defined variables
880 +  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
881 +  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
882 +  else if(variable == "detIso") value = (object->trackIso) / object->pt;
883 +  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
884 +  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
885 +  else if(variable == "tightID") {
886 +    value = object->isGlobalMuon > 0            \
887 +      && object->isPFMuon > 0                   \
888 +      && object->normalizedChi2 < 10            \
889 +      && object->numberOfValidMuonHits > 0      \
890 +      && object->numberOfMatchedStations > 1    \
891 +      && fabs(object->correctedD0Vertex) < 0.2  \
892 +      && fabs(object->correctedDZ) < 0.5        \
893 +      && object->numberOfValidPixelHits > 0     \
894 +      && object->numberOfLayersWithMeasurement > 5;
895 +    
896 +
897 +  }
898 +  else if(variable == "tightIDdisplaced"){
899 +    value = object->isGlobalMuon > 0            \
900 +      && object->isPFMuon > 0                   \
901 +      && object->normalizedChi2 < 10            \
902 +      && object->numberOfValidMuonHits > 0      \
903 +      && object->numberOfMatchedStations > 1    \
904 +      && object->numberOfValidPixelHits > 0     \
905 +      && object->numberOfLayersWithMeasurement > 5;
906 +  }
907 +
908    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
909  
910    value = applyFunction(function, value);
# Line 915 | Line 1074 | OSUAnalysis::valueLookup (const BNelectr
1074    else if(variable == "eidHyperTight4MC") value = object->eidHyperTight4MC;
1075    else if(variable == "passConvVeto") value = object->passConvVeto;
1076  
1077 +  //user-defined variables
1078 +  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1079 +  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1080 +  else if(variable == "detIso") value = (object->trackIso) / object->pt;
1081 +  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1082 +
1083  
1084    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1085  
# Line 1275 | Line 1440 | OSUAnalysis::valueLookup (const BNmcpart
1440    else if(variable == "grandMother11Status") value = object->grandMother11Status;
1441    else if(variable == "grandMother11Charge") value = object->grandMother11Charge;
1442  
1443 +  //user-defined variables
1444 +  else if (variable == "d0"){
1445 +    double vx = object->vx - primaryVertex_->x,
1446 +      vy = object->vy - primaryVertex_->y,
1447 +      px = object->px,
1448 +      py = object->py,
1449 +      pt = object->pt;
1450 +    value = (-vx * py + vy * px) / pt;
1451 +  }
1452 +  else if (variable == "dz"){
1453 +    double vx = object->vx - primaryVertex_->x,
1454 +      vy = object->vy - primaryVertex_->y,
1455 +      vz = object->vz - primaryVertex_->z,
1456 +      px = object->px,
1457 +      py = object->py,
1458 +      pz = object->pz,
1459 +      pt = object->pt;
1460 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
1461 +  }
1462 +
1463 +
1464 +
1465    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1466  
1467    value = applyFunction(function, value);
# Line 1433 | Line 1620 | OSUAnalysis::valueLookup (const BNsuperc
1620  
1621  
1622   double
1623 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
1624 +
1625 +  double value = 0.0;
1626 +
1627 +  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
1628 +  else if(variable == "invMass"){
1629 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
1630 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
1631 +    value = (fourVector1 + fourVector2).M();
1632 +  }
1633 +
1634 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1635 +
1636 +  value = applyFunction(function, value);
1637 +
1638 +  return value;
1639 + }
1640 +
1641 + double
1642 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
1643 +
1644 +  double value = 0.0;
1645 +
1646 +  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
1647 +  else if(variable == "invMass"){
1648 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
1649 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
1650 +    value = (fourVector1 + fourVector2).M();
1651 +  }
1652 +
1653 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1654 +
1655 +  value = applyFunction(function, value);
1656 +
1657 +  return value;
1658 + }
1659 +
1660 + double
1661 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
1662 +
1663 +  double value = 0.0;
1664 +
1665 +  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
1666 +  else if(variable == "invMass"){
1667 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
1668 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
1669 +    value = (fourVector1 + fourVector2).M();
1670 +  }
1671 +
1672 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1673 +
1674 +  value = applyFunction(function, value);
1675 +
1676 +  return value;
1677 + }
1678 +
1679 +
1680 + double
1681   OSUAnalysis::applyFunction(string function, double value){
1682  
1683 <  if(function == "abs") value = abs(value);
1683 >  if(function == "abs") value = fabs(value);
1684  
1685  
1686    return value;
# Line 1446 | Line 1691 | OSUAnalysis::applyFunction(string functi
1691   template <class InputCollection>
1692   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
1693  
1449
1694    for (uint object = 0; object != inputCollection->size(); object++){
1695  
1696      bool decision = true;//object passes if this cut doesn't cut on that type of object
1697  
1698      if(currentCut.inputCollection == inputType){
1699  
1700 <      double value = valueLookup(&inputCollection->at(object), currentCut.variable, currentCut.function);
1701 <
1702 <      decision = evaluateComparison(value,currentCut.comparativeOperator,currentCut.cutValue);
1700 >      vector<bool> subcutDecisions;
1701 >      for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
1702 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
1703 >        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
1704 >      }
1705 >      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
1706 >      else{
1707 >        bool tempDecision = true;
1708 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
1709 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
1710 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
1711 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
1712 >            tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
1713 >        }
1714 >        decision = tempDecision;
1715 >      }
1716      }
1717 <    individualFlags[inputType].at(currentCutIndex).push_back(decision);
1461 <
1717 >    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
1718  
1719      //set flags for objects that pass each cut AND all the previous cuts
1720      bool previousCumulativeFlag = true;
1721      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
1722 <      if(previousCumulativeFlag && individualFlags[inputType].at(previousCutIndex).at(object)) previousCumulativeFlag = true;
1722 >      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
1723        else{ previousCumulativeFlag = false; break;}
1724      }
1725 <    cumulativeFlags[inputType].at(currentCutIndex).push_back(previousCumulativeFlag && decision);
1725 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
1726 >
1727 >  }
1728 >
1729 > }
1730 >
1731 >
1732 > template <class InputCollection1, class InputCollection2>
1733 > void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
1734 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, string inputType){
1735 >
1736 >
1737 >  bool sameObjects = false;
1738 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
1739 >
1740 >  int counter = 0;  
1741 >  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
1742 >    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
1743 >      
1744 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
1745 >
1746 >
1747 >      bool decision = true;//object passes if this cut doesn't cut on that type of object
1748 >
1749 >      if(currentCut.inputCollection == inputType){
1750 >
1751 >        vector<bool> subcutDecisions;
1752 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
1753 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
1754 >          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
1755 >        }
1756 >
1757 >        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
1758 >        else{
1759 >          bool tempDecision = true;
1760 >          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
1761 >            if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
1762 >              tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
1763 >            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
1764 >              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
1765 >          }
1766 >          decision = tempDecision;
1767 >        }
1768 >      }
1769 >      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
1770 >      
1771 >      //set flags for objects that pass each cut AND all the previous cuts
1772 >      bool previousCumulativeFlag = true;
1773 >      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
1774 >        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
1775 >        else{ previousCumulativeFlag = false; break;}
1776 >      }
1777 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
1778 >
1779 >      counter++;      
1780 >    }
1781 >    
1782 >  }
1783 >
1784 >
1785 > }
1786 >
1787 >
1788 > template <class InputCollection>
1789 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
1790 >
1791 >  for (uint object = 0; object != inputCollection->size(); object++){
1792 >
1793 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
1794 >
1795 >    string currentString = parameters.inputVariables.at(0);
1796 >    string inputVariable = "";
1797 >    string function = "";
1798 >    if(currentString.find("(")==std::string::npos){
1799 >      inputVariable = currentString;// variable to cut on                                                                                                                                        
1800 >    }
1801 >    else{
1802 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
1803 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
1804 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
1805 >    }
1806 >
1807 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
1808 >    histo->Fill(value,puScaleFactor);
1809 >
1810 >  }
1811 >
1812 > }
1813 >
1814 > template <class InputCollection1, class InputCollection2>
1815 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
1816 >
1817 >  bool sameObjects = false;
1818 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
1819 >
1820 >  int counter = 0;  
1821 >  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
1822 >    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
1823 >      
1824 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
1825 >
1826 >      //only take objects which have passed all cuts and pairs which have passed all cuts
1827 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
1828 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
1829 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(counter)) continue;
1830 >
1831 >      string currentString = parameters.inputVariables.at(0);
1832 >      string inputVariable = "";
1833 >      string function = "";
1834 >      if(currentString.find("(")==std::string::npos){
1835 >        inputVariable = currentString;// variable to cut on                                                                                                          
1836 >      }
1837 >      else{
1838 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
1839 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
1840 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
1841 >      }
1842 >      
1843 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
1844 >      histo->Fill(value,puScaleFactor);
1845 >
1846 >      counter++;      
1847 >    }
1848 >  }
1849 >
1850 > }
1851 >
1852 >
1853 > template <class InputCollection>
1854 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
1855 >
1856 >  for (uint object = 0; object != inputCollection->size(); object++){
1857 >
1858 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
1859 >
1860 >    string currentString = parameters.inputVariables.at(0);
1861 >    string inputVariable = "";
1862 >    string function = "";
1863 >    if(currentString.find("(")==std::string::npos){
1864 >      inputVariable = currentString;// variable to cut on                                                                                                                                        
1865 >    }
1866 >    else{
1867 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
1868 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
1869 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
1870 >    }
1871 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
1872 >
1873 >    currentString = parameters.inputVariables.at(1);
1874 >    inputVariable = "";
1875 >    function = "";
1876 >    if(currentString.find("(")==std::string::npos){
1877 >      inputVariable = currentString;// variable to cut on                                                                                                                                        
1878 >    }
1879 >    else{
1880 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
1881 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
1882 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
1883 >    }
1884 >
1885 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
1886 >
1887 >    histo->Fill(valueX,valueY,puScaleFactor);
1888  
1889    }
1890  
1891   }
1892  
1893 + template <class InputCollection1, class InputCollection2>
1894 + void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
1895 +
1896 +  bool sameObjects = false;
1897 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
1898  
1899 +  int counter = 0;  
1900 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
1901 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
1902 +      
1903 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
1904 +
1905 +      //only take objects which have passed all cuts and pairs which have passed all cuts
1906 +      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
1907 +      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
1908 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(counter)) continue;
1909 +
1910 +      string currentString = parameters.inputVariables.at(0);
1911 +      string inputVariable = "";
1912 +      string function = "";
1913 +      if(currentString.find("(")==std::string::npos){
1914 +        inputVariable = currentString;// variable to cut on                                                                                                          
1915 +      }
1916 +      else{
1917 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
1918 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
1919 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
1920 +      }
1921 +      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
1922 +
1923 +      currentString = parameters.inputVariables.at(1);
1924 +      inputVariable = "";
1925 +      function = "";
1926 +      if(currentString.find("(")==std::string::npos){
1927 +        inputVariable = currentString;// variable to cut on                                                                                                          
1928 +      }
1929 +      else{
1930 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
1931 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
1932 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
1933 +      }
1934 +      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
1935 +
1936 +
1937 +      histo->Fill(valueX,valueY,puScaleFactor);
1938 +
1939 +      counter++;      
1940 +    }
1941 +  }
1942 +
1943 + }
1944  
1945  
1946  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines