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.15 by lantonel, Wed Feb 13 12:51:49 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 +    objectsToPlot.push_back(tempInputCollection);
52 +    allNecessaryObjects.push_back(tempInputCollection);
53 +    vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
54 +    
55 +    for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
56 +
57 +      histogram tempHistogram;
58 +      tempHistogram.inputCollection = tempInputCollection;
59 +      tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
60 +      tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
61 +      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
62 +      tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
63 +      if(histogramList_.at(currentHistogram).exists("function"))
64 +        tempHistogram.function = histogramList_.at(currentHistogram).getParameter<string>("function");
65 +      else
66 +        tempHistogram.function = "";
67 +      
68 +      histograms.push_back(tempHistogram);
69 +
70 +    }
71 +  }
72 +  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object
73 +  sort( objectsToPlot.begin(), objectsToPlot.end() );
74 +  objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
75 +
76 +
77 +
78  
79    channel tempChannel;
80    //loop over all channels (event selections)
# Line 50 | Line 97 | OSUAnalysis::OSUAnalysis (const edm::Par
97      }
98  
99  
100 +
101 +
102      //create cutFlow for this channel
103      cutFlows_.push_back (new CutFlow (fs_, channelName));
104  
105      //book a directory in the output file with the name of the channel
106      TFileDirectory subDir = fs_->mkdir( channelName );
107      directories.push_back(subDir);
59    std::map<std::string, TH1D*> histoMap;
60    oneDHists_.push_back(histoMap);
108  
109 <    //gen histograms
110 <    oneDHists_.at(currentChannel)["genD0"] = directories.at(currentChannel).make<TH1D> ("genD0",channelLabel+" channel: Gen d_{0}; d_{0} [cm] ", 1000, -1, 1);
111 <    oneDHists_.at(currentChannel)["genAbsD0"] = directories.at(currentChannel).make<TH1D> ("genAbsD0",channelLabel+" channel: Gen d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
112 <    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);
109 >    std::map<std::string, TH1D*> oneDhistoMap;
110 >    oneDHists_.push_back(oneDhistoMap);
111 >    std::map<std::string, TH2D*> twoDhistoMap;
112 >    twoDHists_.push_back(twoDhistoMap);
113  
114  
115 +    //book all histograms included in the configuration
116 +    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
117 +      histogram currentHistogram = histograms.at(currentHistogramIndex);
118 +      int numBinsElements = currentHistogram.bins.size();
119 +      int numInputVariables = currentHistogram.inputVariables.size();
120  
102    //get list of cuts for this channel
103    vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
121  
105    vector<string> tempInputCollections;
122  
123 +      if(numBinsElements != 3 && numBinsElements !=6) {
124 +        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
125 +        exit(0);
126 +      }
127 +      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
128 +        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
129 +        exit(0);
130 +      }
131 +      else if(numBinsElements == 3){
132 +        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));
133 +      }
134 +      else if(numBinsElements == 6){
135 +        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));
136 +
137 +      }
138 +
139 +
140 +    }
141 +    //book a histogram for the number of each object type to be plotted
142 +    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
143 +      string currentObject = objectsToPlot.at(currentObjectIndex);
144 +      int maxNum = 10;
145 +      if(currentObject == "mcparticles") maxNum = 50;
146 +      else if(currentObject == "primaryvertexs") maxNum = 50;
147 +      currentObject.at(0) = toupper(currentObject.at(0));
148 +      string histoName = "num" + currentObject;
149 +      oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
150 +    }
151 +
152 +
153 +    //get list of cuts for this channel
154 +    vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
155  
156      //loop over and parse all cuts
157      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
# Line 112 | Line 160 | OSUAnalysis::OSUAnalysis (const edm::Par
160       //store input collection for cut
161        string inputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
162        tempCut.inputCollection = inputCollection;
115
116      tempInputCollections.push_back(inputCollection);
163        allNecessaryObjects.push_back(inputCollection);
164  
165        //split cut string into parts and store them
166        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
167        std::vector<string> cutStringVector = splitString(cutString);
168 +      if(cutStringVector.size()!=3){
169 +        std::cout << "Error: Didn't find three elements in the following cut string: '" <<cutString << "'\n";
170 +        exit(0);
171 +      }
172 +
173        tempCut.variable = cutStringVector.at(0);// variable to cut on
174        tempCut.comparativeOperator = cutStringVector.at(1);// comparison to make
175        tempCut.cutValue = atof(cutStringVector.at(2).c_str());// threshold value to pass cut
# Line 126 | Line 177 | OSUAnalysis::OSUAnalysis (const edm::Par
177        //get number of objects required to pass cut for event to pass
178        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
179        std::vector<string> numberRequiredVector = splitString(numberRequiredString);
180 +      if(numberRequiredVector.size()!=2){
181 +        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
182 +        exit(0);
183 +      }
184  
185        // determine number required if comparison contains "="
186        int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
# Line 156 | Line 211 | OSUAnalysis::OSUAnalysis (const edm::Par
211        tempChannel.cuts.push_back(tempCut);
212  
213  
214 +
215      }//end loop over cuts
216  
161    //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;
217  
218      channels.push_back(tempChannel);
219      tempChannel.cuts.clear();
220  
221    }//end loop over channels
222  
223 +
224    //make unique vector of objects we need to cut on (so we make sure to get them from the event)
225    sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
226    allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
# Line 247 | Line 300 | OSUAnalysis::analyze (const edm::Event &
300      event.getByLabel (superclusters_, superclusters);
301  
302  
303 +  //get pile-up event weight
304 +  double puScaleFactor = 0;
305 +  if(datasetType_ != "data")
306 +    puScaleFactor = puWeight_->at (events->at (0).numTruePV);
307 +  else
308 +    puScaleFactor = 1.00;
309 +
310 +
311    //loop over all channels
312  
313    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
# Line 272 | Line 333 | OSUAnalysis::analyze (const edm::Event &
333          individualFlags[currentObject].push_back (vector<bool> ());
334          cumulativeFlags[currentObject].push_back (vector<bool> ());
335  
336 +
337          if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
338          else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
339          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
# Line 287 | Line 349 | OSUAnalysis::analyze (const edm::Event &
349          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
350  
351  
352 +
353        }
354  
355  
# Line 310 | Line 373 | OSUAnalysis::analyze (const edm::Event &
373        cut currentCut = currentChannel.cuts.at(currentCutIndex);
374        int numberPassing = 0;
375  
376 <      for (uint object = 0; object != cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).size() ; object++)
377 <          if(cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).at(object)) numberPassing++;
376 >      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++)
377 >          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
378  
379  
380        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
# Line 321 | Line 384 | OSUAnalysis::analyze (const edm::Event &
384  
385      }
386  
387 <    cutFlows_.at(currentChannelIndex)->fillCutFlow();
325 <
387 >    cutFlows_.at(currentChannelIndex)->fillCutFlow(puScaleFactor);
388  
389  
390      if(!eventPassedAllCuts)continue;
391  
392  
331    TVector3 vertexPosition;
332    vector<bool> vertexFlags = cumulativeFlags["primaryvertexs"].back();
393  
394 +
395 +    //set position of primary vertex in event, in order to calculate quantities relative to it
396 +    primaryVertex_ = 0;
397 +    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back();
398      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
399        if(!vertexFlags.at(vertexIndex)) continue;
400 <
337 <      vertexPosition.SetXYZ (primaryvertexs->at(vertexIndex).x,primaryvertexs->at(vertexIndex).y,primaryvertexs->at(vertexIndex).z);
400 >      primaryVertex_ = new BNprimaryvertex (primaryvertexs->at (vertexIndex));
401        break;
402      }
403  
341    vector<bool> mcparticleFlags = cumulativeFlags["mcparticles"].back();
342
343    for (uint mcparticleIndex = 0; mcparticleIndex != mcparticleFlags.size(); mcparticleIndex++){
344      if(!mcparticleFlags.at(mcparticleIndex)) continue;
345
346      double vx = mcparticles->at(mcparticleIndex).vx - vertexPosition.X (),
347             vy = mcparticles->at(mcparticleIndex).vy - vertexPosition.Y (),
348             vz = mcparticles->at(mcparticleIndex).vz - vertexPosition.Z (),
349             px = mcparticles->at(mcparticleIndex).px,
350             py = mcparticles->at(mcparticleIndex).py,
351             pt = mcparticles->at(mcparticleIndex).pt,
352             d0;
353
354      d0 = (-vx * py + vy * px) / pt;
355      oneDHists_.at(currentChannelIndex)["genD0"]->Fill (d0);
356      oneDHists_.at(currentChannelIndex)["genAbsD0"]->Fill (fabs (d0));
357      oneDHists_.at(currentChannelIndex)["genDZ"]->Fill (vz);
358      oneDHists_.at(currentChannelIndex)["genAbsDZ"]->Fill (fabs (vz));
359    }
360
361    vector<bool> electronFlags = cumulativeFlags["electrons"].back();
362    int electronCounter = 0;
363
364    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
365      if(!electronFlags.at(electronIndex)) continue;
404  
405  
406 <      electronCounter++;
407 <      oneDHists_.at(currentChannelIndex)["electronPt"]->Fill (electrons->at(electronIndex).pt);
408 <      oneDHists_.at(currentChannelIndex)["electronEta"]->Fill (electrons->at(electronIndex).eta);
409 <      oneDHists_.at(currentChannelIndex)["electronD0"]->Fill (electrons->at(electronIndex).correctedD0Vertex);
410 <      oneDHists_.at(currentChannelIndex)["electronDz"]->Fill (electrons->at(electronIndex).correctedDZ);
411 <      oneDHists_.at(currentChannelIndex)["electronAbsD0"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex));
412 <      oneDHists_.at(currentChannelIndex)["electronDZ"]->Fill (electrons->at(electronIndex).correctedDZ);
413 <      oneDHists_.at(currentChannelIndex)["electronAbsDZ"]->Fill (fabs(electrons->at(electronIndex).correctedDZ));
414 <      oneDHists_.at(currentChannelIndex)["electronD0Sig"]->Fill (electrons->at(electronIndex).correctedD0Vertex / electrons->at(electronIndex).tkD0err);
415 <      oneDHists_.at(currentChannelIndex)["electronAbsD0Sig"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex) / electrons->at(electronIndex).tkD0err);
416 <      oneDHists_.at(currentChannelIndex)["electronIso"]->Fill (electrons->at(electronIndex).puChargedHadronIso / electrons->at(electronIndex).pt);
417 <      oneDHists_.at(currentChannelIndex)["electronFbrem"]->Fill (electrons->at(electronIndex).fbrem);
418 <      oneDHists_.at(currentChannelIndex)["electronMVATrig"]->Fill (electrons->at(electronIndex).mvaTrigV0);
419 <      oneDHists_.at(currentChannelIndex)["electronMVANonTrig"]->Fill (electrons->at(electronIndex).mvaNonTrigV0);
420 <
406 >    //filling histograms
407 >    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
408 >      histogram currentHistogram = histograms.at(histogramIndex);
409 >
410 >      if(currentHistogram.inputVariables.size() == 1){
411 >        TH1D* histo;
412 >        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
413 >        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
414 >        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
415 >        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
416 >        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
417 >        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
418 >        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
419 >        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
420 >        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
421 >        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
422 >        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
423 >        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
424 >        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
425 >        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
426 >      }
427 >      else if(currentHistogram.inputVariables.size() == 2){
428 >        TH2D* histo;
429 >        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
430 >        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
431 >        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
432 >        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
433 >        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
434 >        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
435 >        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
436 >        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
437 >        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
438 >        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
439 >        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
440 >        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
441 >        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
442 >        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
443 >      }
444      }
384    oneDHists_.at(currentChannelIndex)["numElectrons"]->Fill (electronCounter);
385
445  
387    vector<bool> muonFlags = cumulativeFlags["muons"].back();
388    int muonCounter = 0;
446  
447 +    //fills histograms with the sizes of collections
448 +    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
449 +      string currentObject = objectsToPlot.at(currentObjectIndex);
450 +      string tempCurrentObject = currentObject;
451 +      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
452 +      string histoName = "num" + tempCurrentObject;
453 +
454 +      if(currentObject == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),puScaleFactor);
455 +      else if(currentObject == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),puScaleFactor);
456 +      else if(currentObject == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),puScaleFactor);
457 +      else if(currentObject == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),puScaleFactor);
458 +      else if(currentObject == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),puScaleFactor);
459 +      else if(currentObject == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),puScaleFactor);
460 +      else if(currentObject == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),puScaleFactor);
461 +      else if(currentObject == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),puScaleFactor);
462 +      else if(currentObject == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),puScaleFactor);
463 +      else if(currentObject == "primaryvertexs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(primaryvertexs->size(),puScaleFactor);
464 +      else if(currentObject == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),puScaleFactor);
465 +      else if(currentObject == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),puScaleFactor);
466 +      else if(currentObject == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),puScaleFactor);
467  
391    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
392      if(!muonFlags.at(muonIndex)) continue;
393      muonCounter++;
394
395      oneDHists_.at(currentChannelIndex)["muonPt"]->Fill (muons->at(muonIndex).pt);
396      oneDHists_.at(currentChannelIndex)["muonEta"]->Fill (muons->at(muonIndex).eta);
397      oneDHists_.at(currentChannelIndex)["muonD0"]->Fill (muons->at(muonIndex).correctedD0Vertex);
398      oneDHists_.at(currentChannelIndex)["muonDz"]->Fill (muons->at(muonIndex).correctedDZ);
399      oneDHists_.at(currentChannelIndex)["muonAbsD0"]->Fill (fabs(muons->at(muonIndex).correctedD0Vertex));
400      oneDHists_.at(currentChannelIndex)["muonDZ"]->Fill (muons->at(muonIndex).correctedDZ);
401      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);
468      }
406    oneDHists_.at(currentChannelIndex)["numMuons"]->Fill (muonCounter);
407
408
409
410
411
469    } //end loop over channel
470  
471 <  masterCutFlow_->fillCutFlow();
471 >  masterCutFlow_->fillCutFlow(puScaleFactor);
472 >
473  
474  
475   }
# Line 746 | Line 804 | OSUAnalysis::valueLookup (const BNmuon*
804    else if(variable == "numberOfMatchedStations") value = object->numberOfMatchedStations;
805    else if(variable == "time_ndof") value = object->time_ndof;
806  
807 +  //user-defined variables
808 +  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
809 +  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
810 +  else if(variable == "detIso") value = (object->trackIso) / object->pt;
811 +  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
812 +  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
813 +  else if(variable == "tightID") {
814 +    value = object->isGlobalMuon > 0            \
815 +      && object->isPFMuon > 0                   \
816 +      && object->normalizedChi2 < 10            \
817 +      && object->numberOfValidMuonHits > 0      \
818 +      && object->numberOfMatchedStations > 1    \
819 +      && fabs(object->correctedD0Vertex) < 0.2  \
820 +      && fabs(object->correctedDZ) < 0.5        \
821 +      && object->numberOfValidPixelHits > 0     \
822 +      && object->numberOfLayersWithMeasurement > 5;
823 +    
824 +
825 +  }
826 +  else if(variable == "tightIDdisplaced"){
827 +    value = object->isGlobalMuon > 0            \
828 +      && object->isPFMuon > 0                   \
829 +      && object->normalizedChi2 < 10            \
830 +      && object->numberOfValidMuonHits > 0      \
831 +      && object->numberOfMatchedStations > 1    \
832 +      && object->numberOfValidPixelHits > 0     \
833 +      && object->numberOfLayersWithMeasurement > 5;
834 +  }
835 +
836    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
837  
838    value = applyFunction(function, value);
# Line 915 | Line 1002 | OSUAnalysis::valueLookup (const BNelectr
1002    else if(variable == "eidHyperTight4MC") value = object->eidHyperTight4MC;
1003    else if(variable == "passConvVeto") value = object->passConvVeto;
1004  
1005 +  //user-defined variables
1006 +  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1007 +  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1008 +  else if(variable == "detIso") value = (object->trackIso) / object->pt;
1009 +  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1010 +
1011  
1012    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1013  
# Line 1275 | Line 1368 | OSUAnalysis::valueLookup (const BNmcpart
1368    else if(variable == "grandMother11Status") value = object->grandMother11Status;
1369    else if(variable == "grandMother11Charge") value = object->grandMother11Charge;
1370  
1371 +  //user-defined variables
1372 +  else if (variable == "d0"){
1373 +    double vx = object->vx - primaryVertex_->x,
1374 +      vy = object->vy - primaryVertex_->y,
1375 +      px = object->px,
1376 +      py = object->py,
1377 +      pt = object->pt;
1378 +    value = (-vx * py + vy * px) / pt;
1379 +  }
1380 +  else if (variable == "dz"){
1381 +    double vx = object->vx - primaryVertex_->x,
1382 +      vy = object->vy - primaryVertex_->y,
1383 +      vz = object->vz - primaryVertex_->z,
1384 +      px = object->px,
1385 +      py = object->py,
1386 +      pz = object->pz,
1387 +      pt = object->pt;
1388 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
1389 +  }
1390 +
1391 +
1392 +
1393    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1394  
1395    value = applyFunction(function, value);
# Line 1435 | Line 1550 | OSUAnalysis::valueLookup (const BNsuperc
1550   double
1551   OSUAnalysis::applyFunction(string function, double value){
1552  
1553 <  if(function == "abs") value = abs(value);
1553 >  if(function == "abs") value = fabs(value);
1554  
1555  
1556    return value;
# Line 1457 | Line 1572 | void OSUAnalysis::setObjectFlags(cut &cu
1572  
1573        decision = evaluateComparison(value,currentCut.comparativeOperator,currentCut.cutValue);
1574      }
1575 <    individualFlags[inputType].at(currentCutIndex).push_back(decision);
1575 >    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
1576  
1577  
1578      //set flags for objects that pass each cut AND all the previous cuts
1579      bool previousCumulativeFlag = true;
1580      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
1581 <      if(previousCumulativeFlag && individualFlags[inputType].at(previousCutIndex).at(object)) previousCumulativeFlag = true;
1581 >      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
1582        else{ previousCumulativeFlag = false; break;}
1583      }
1584 <    cumulativeFlags[inputType].at(currentCutIndex).push_back(previousCumulativeFlag && decision);
1584 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
1585  
1586    }
1587  
1588   }
1589  
1590  
1591 + template <class InputCollection>
1592 + void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
1593 +
1594 +  for (uint object = 0; object != inputCollection->size(); object++){
1595 +
1596 +    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
1597 +
1598 +    double value = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(0), parameters.function);
1599 +    histo->Fill(value,puScaleFactor);
1600 +
1601 +  }
1602 +
1603 + }
1604 +
1605 + template <class InputCollection>
1606 + void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
1607 +
1608 +  for (uint object = 0; object != inputCollection->size(); object++){
1609 +
1610 +    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
1611 +
1612 +    double valueX = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(0), parameters.function);
1613 +    double valueY = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(1), parameters.function);
1614 +    histo->Fill(valueX,valueY,puScaleFactor);
1615 +
1616 +  }
1617 +
1618 + }
1619 +
1620  
1621  
1622  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines