32 |
|
plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")), |
33 |
|
doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")), |
34 |
|
applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")), |
35 |
< |
printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")), |
35 |
> |
applyBtagSF_ (cfg.getParameter<bool> ("applyBtagSF")), |
36 |
> |
minBtag_ (cfg.getParameter<int> ("minBtag")), |
37 |
> |
maxBtag_ (cfg.getParameter<int> ("maxBtag")), |
38 |
> |
printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")), |
39 |
> |
printAllTriggers_ (cfg.getParameter<bool> ("printAllTriggers")), |
40 |
|
useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")), |
41 |
|
stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")), |
42 |
|
GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut")) |
43 |
< |
{ |
43 |
> |
{ |
44 |
|
|
45 |
|
TH1::SetDefaultSumw2 (); |
46 |
|
|
51 |
|
muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_); |
52 |
|
electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_); |
53 |
|
} |
54 |
+ |
if (applyBtagSF_){ |
55 |
+ |
bTagSFWeight_ = new BtagSFWeight; |
56 |
+ |
} |
57 |
|
} |
58 |
|
if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*"))) |
59 |
|
stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_); |
406 |
|
|
407 |
|
//book all histograms included in the configuration |
408 |
|
for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories. |
402 |
– |
|
403 |
– |
TTree* newTree = directories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel)); |
404 |
– |
BNTrees_.push_back(newTree); |
409 |
|
|
410 |
+ |
TTree* newTree = directories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel)); |
411 |
+ |
BNTrees_.push_back(newTree); |
412 |
|
for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){ |
413 |
|
BranchSpecs currentVar = treeBranches_.at(iBranch); |
414 |
|
vector<float> newVec; |
415 |
|
BNTreeBranchVals_[currentVar.name] = newVec; |
416 |
|
BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name)); |
411 |
– |
|
417 |
|
} // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){ |
418 |
|
|
414 |
– |
|
419 |
|
for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){ |
420 |
|
|
421 |
|
histogram currentHistogram = histograms.at(currentHistogramIndex); |
584 |
|
objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() ); |
585 |
|
|
586 |
|
|
587 |
< |
} |
587 |
> |
} // end constructor OSUAnalysis::OSUAnalysis() |
588 |
> |
|
589 |
|
|
590 |
|
OSUAnalysis::~OSUAnalysis () |
591 |
|
{ |
592 |
+ |
|
593 |
|
// Destroying the CutFlow objects causes the cut flow numbers and time |
594 |
|
// information to be printed to standard output. |
595 |
|
for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){ |
689 |
|
iter->second.clear(); // clear array |
690 |
|
} |
691 |
|
|
686 |
– |
|
692 |
|
bool triggerDecision = true; |
693 |
|
if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){ //triggers specified |
694 |
|
triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product()); |
830 |
|
} |
831 |
|
double scaleFactor = masterScaleFactor; |
832 |
|
|
833 |
< |
muonScaleFactor_ = electronScaleFactor_ = 1.0; |
833 |
> |
muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0; |
834 |
|
if(applyLeptonSF_ && datasetType_ != "data"){ |
835 |
|
if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){ |
836 |
|
vector<bool> muonFlags; |
859 |
|
} |
860 |
|
} |
861 |
|
} |
862 |
+ |
if(applyBtagSF_ && datasetType_ != "data"){ |
863 |
+ |
if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){ |
864 |
+ |
vector<bool> jetFlags; |
865 |
+ |
vector<double> jetSFs; |
866 |
+ |
for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){ |
867 |
+ |
if (cumulativeFlags.at("jets").at(i).size()){ |
868 |
+ |
jetFlags = cumulativeFlags.at("jets").at(i); |
869 |
+ |
break; |
870 |
+ |
} |
871 |
+ |
} |
872 |
+ |
for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){ |
873 |
+ |
if(!jetFlags.at(jetIndex)) continue; |
874 |
+ |
double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt); |
875 |
+ |
jetSFs.push_back(jetSFTmp); |
876 |
+ |
} |
877 |
+ |
bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_, maxBtag_ ); |
878 |
+ |
} |
879 |
+ |
} |
880 |
|
scaleFactor *= muonScaleFactor_; |
881 |
|
scaleFactor *= electronScaleFactor_; |
882 |
< |
|
882 |
> |
scaleFactor *= bTagScaleFactor_; |
883 |
|
cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor); |
884 |
|
|
885 |
|
if (printEventInfo_) { |
895 |
|
//filling histograms |
896 |
|
for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel. |
897 |
|
uint currentDir; |
898 |
< |
if(!GetPlotsAfterEachCut_){ currentDir = currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size();}//if GetPlotsAfterEachCut_ is true, set currentDir point to the lat cut. |
898 |
> |
if (!GetPlotsAfterEachCut_) { currentDir = currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut. |
899 |
|
else{ |
900 |
|
currentDir = currentCut; |
901 |
|
} |
926 |
|
else if(coll == "trigobjs") assignTreeBranch(brSpecs,trigobjs.product(), cumulativeFlags.at(coll).at(currentDir)); |
927 |
|
else if(coll == "stops" |
928 |
|
&& datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(), cumulativeFlags.at(coll).at(currentDir)); |
929 |
< |
} // end loop over histograms |
929 |
> |
} // end loop over branches |
930 |
|
|
908 |
– |
|
931 |
|
for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){ |
932 |
|
histogram currentHistogram = histograms.at(histogramIndex); |
933 |
|
|
1123 |
|
} |
1124 |
|
} |
1125 |
|
} // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++) |
1126 |
+ |
|
1127 |
+ |
if (!BNTrees_.at(currentChannelIndex)) { cout << "ERROR: Undefined BNTree. Will likely seg fault." << endl; } |
1128 |
+ |
BNTrees_.at(currentChannelIndex)->Fill(); // only fill if event has passed cuts |
1129 |
+ |
|
1130 |
|
} // end if(eventPassedPreviousCuts.at(currentDir)){ |
1131 |
|
} // end loop over cuts |
1132 |
< |
|
1107 |
< |
BNTrees_.at(currentChannelIndex)->Fill(); |
1108 |
< |
|
1132 |
> |
|
1133 |
|
} // end loop over channel |
1134 |
|
|
1135 |
+ |
|
1136 |
|
masterCutFlow_->fillCutFlow(masterScaleFactor); |
1137 |
|
|
1138 |
|
|
1176 |
|
//initialize to false until a chosen trigger is passed |
1177 |
|
bool triggerDecision = false; |
1178 |
|
|
1179 |
+ |
if (printAllTriggers_) cout << "Printing list of all available triggers (which this event may or may not pass):" << endl; |
1180 |
|
//loop over all triggers defined in the event |
1181 |
|
for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){ |
1182 |
|
|
1183 |
+ |
if (printAllTriggers_) cout << " " << trigger->name << endl; |
1184 |
+ |
|
1185 |
|
//we're only interested in triggers that actually passed |
1186 |
|
if(trigger->pass != 1) continue; |
1187 |
|
|
1194 |
|
if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true; |
1195 |
|
} |
1196 |
|
} |
1197 |
+ |
|
1198 |
+ |
printAllTriggers_ = false; // only print triggers once, not every event |
1199 |
+ |
|
1200 |
|
//if none of the veto triggers fired: |
1201 |
|
//return the OR of all the chosen triggers |
1202 |
|
if (triggersToTest.size() != 0) return triggerDecision; |
2218 |
|
else if(variable == "muonScaleFactor") value = muonScaleFactor_; |
2219 |
|
else if(variable == "electronScaleFactor") value = electronScaleFactor_; |
2220 |
|
else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_; |
2221 |
< |
|
2221 |
> |
else if(variable == "bTagScaleFactor") value = bTagScaleFactor_; |
2222 |
|
else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;} |
2223 |
|
|
2224 |
|
value = applyFunction(function, value); |
3123 |
|
|
3124 |
|
if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi)); |
3125 |
|
else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta); |
3126 |
+ |
else if(variable == "jetEta") value = object2->eta; |
3127 |
+ |
else if(variable == "jetPhi") value = object2->phi; |
3128 |
+ |
else if(variable == "electronEta") value = object1->eta; |
3129 |
+ |
else if(variable == "electronPhi") value = object1->phi; |
3130 |
|
else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi); |
3131 |
|
else if(variable == "invMass"){ |
3132 |
|
TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy); |
3161 |
|
double value = 0.0; |
3162 |
|
|
3163 |
|
if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi)); |
3164 |
+ |
else if(variable == "jetEta") value = object2->eta; |
3165 |
+ |
else if(variable == "jetPhi") value = object2->phi; |
3166 |
+ |
else if(variable == "muonEta") value = object1->eta; |
3167 |
+ |
else if(variable == "muonPhi") value = object1->phi; |
3168 |
|
else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta); |
3169 |
|
else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi); |
3170 |
|
else if(variable == "invMass"){ |
3825 |
|
void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, vector<bool> flags){ |
3826 |
|
// This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree |
3827 |
|
|
3828 |
< |
for (uint object = 0; object != inputCollection->size(); object++){ |
3828 |
> |
if (BNTreeBranchVals_.count(parameters.name)==0) cout << "Error[assignTreeBranch]: trying to assign value to " << parameters.name << " that does not have a branch set up. Will likely seg fault." << endl; |
3829 |
> |
for (uint object = 0; object != inputCollection->size(); object++) { |
3830 |
|
|
3831 |
< |
if (!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue; |
3831 |
> |
if (!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue; |
3832 |
|
|
3833 |
|
string inputVariable = parameters.inputVariable; |
3834 |
|
string function = ""; |