CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BaseTreeFiller.cc
Go to the documentation of this file.
4 
6 
7 #include <TList.h>
8 #include <TObjString.h>
9 
11 
13 
15  if (external_) {
17  iEvent.getByToken(srcToken_, view);
18  passingProbes_.clear();
19  for (size_t i = 0, n = view->size(); i < n; ++i) passingProbes_.push_back(view->refAt(i));
20  }
21 
22 }
23 
24 void tnp::ProbeFlag::fill(const reco::CandidateBaseRef &probe) const {
25  if (external_) {
26  value_ = (std::find(passingProbes_.begin(), passingProbes_.end(), probe) != passingProbes_.end());
27  } else {
28  value_ = bool(cut_(*probe));
29  }
30 }
31 
33  // make trees as requested
35  tree_ = fs->make<TTree>(name,name);
36 
37  // add the branches
38  addBranches_(tree_, iConfig, iC, "");
39 
40  // set up weights, if needed
41  if (iConfig.existsAs<double>("eventWeight")) {
42  weightMode_ = Fixed;
43  weight_ = iConfig.getParameter<double>("eventWeight");
44  } else if (iConfig.existsAs<edm::InputTag>("eventWeight")) {
45  weightMode_ = External;
46  weightSrcToken_ = iC.consumes<double>(iConfig.getParameter<edm::InputTag>("eventWeight"));
47  } else {
48  weightMode_ = None;
49  }
50  if (weightMode_ != None) {
51  tree_->Branch("weight", &weight_, "weight/F");
52  }
53 
54  addRunLumiInfo_ = iConfig.existsAs<bool>("addRunLumiInfo") ? iConfig.getParameter<bool>("addRunLumiInfo") : false;
55  if (addRunLumiInfo_) {
56  tree_->Branch("run", &run_, "run/i");
57  tree_->Branch("lumi", &lumi_, "lumi/i");
58  tree_->Branch("event", &event_, "event/i");
59  }
60  addEventVariablesInfo_ = iConfig.existsAs<bool>("addEventVariablesInfo") ? iConfig.getParameter<bool>("addEventVariablesInfo") : false;
61  if (addEventVariablesInfo_) {
62  recVtxsToken_ = iC.consumes<reco::VertexCollection>(edm::InputTag("offlinePrimaryVertices"));
63  beamSpotToken_ = iC.consumes<reco::BeamSpot>(edm::InputTag("offlineBeamSpot"));
64  metToken_ = iC.consumes<reco::CaloMETCollection>(edm::InputTag("met"));
65  tcmetToken_ = iC.consumes<reco::METCollection>(edm::InputTag("tcMet"));
66  pfmetToken_ = iC.consumes<reco::PFMETCollection>(edm::InputTag("pfMet"));
67  tree_->Branch("event_nPV" ,&mNPV_ ,"mNPV/I");
68  tree_->Branch("event_met_calomet" ,&mMET_ ,"mMET/F");
69  tree_->Branch("event_met_calosumet" ,&mSumET_ ,"mSumET/F");
70  tree_->Branch("event_met_calometsignificance",&mMETSign_ ,"mMETSign/F");
71  tree_->Branch("event_met_tcmet" ,&mtcMET_ ,"mtcMET/F");
72  tree_->Branch("event_met_tcsumet" ,&mtcSumET_ ,"mtcSumET/F");
73  tree_->Branch("event_met_tcmetsignificance",&mtcMETSign_ ,"mtcMETSign/F");
74  tree_->Branch("event_met_pfmet" ,&mpfMET_ ,"mpfMET/F");
75  tree_->Branch("event_met_pfsumet" ,&mpfSumET_ ,"mpfSumET/F");
76  tree_->Branch("event_met_pfmetsignificance",&mpfMETSign_ ,"mpfMETSign/F");
77  tree_->Branch("event_PrimaryVertex_x" ,&mPVx_ ,"mPVx/F");
78  tree_->Branch("event_PrimaryVertex_y" ,&mPVy_ ,"mPVy/F");
79  tree_->Branch("event_PrimaryVertex_z" ,&mPVz_ ,"mPVz/F");
80  tree_->Branch("event_BeamSpot_x" ,&mBSx_ ,"mBSx/F");
81  tree_->Branch("event_BeamSpot_y" ,&mBSy_ ,"mBSy/F");
82  tree_->Branch("event_BeamSpot_z" ,&mBSz_ ,"mBSz/F");
83  }
84 
85  ignoreExceptions_ = iConfig.existsAs<bool>("ignoreExceptions") ? iConfig.getParameter<bool>("ignoreExceptions") : false;
86 }
87 
89  addEventVariablesInfo_(false),
90  tree_(0)
91 {
92  addBranches_(main.tree_, iConfig, iC, branchNamePrefix);
93 }
94 
95 void
96 tnp::BaseTreeFiller::addBranches_(TTree *tree, const edm::ParameterSet &iConfig, edm::ConsumesCollector & iC, const std::string &branchNamePrefix) {
97  // set up variables
99  //.. the ones that are strings
100  std::vector<std::string> stringVars = variables.getParameterNamesForType<std::string>();
101  for (std::vector<std::string>::const_iterator it = stringVars.begin(), ed = stringVars.end(); it != ed; ++it) {
102  vars_.push_back(tnp::ProbeVariable(branchNamePrefix + *it, variables.getParameter<std::string>(*it)));
103  }
104  //.. the ones that are InputTags
105  std::vector<std::string> inputTagVars = variables.getParameterNamesForType<edm::InputTag>();
106  for (std::vector<std::string>::const_iterator it = inputTagVars.begin(), ed = inputTagVars.end(); it != ed; ++it) {
107  vars_.push_back(tnp::ProbeVariable(branchNamePrefix + *it, iC.consumes<edm::ValueMap<float> >(variables.getParameter<edm::InputTag>(*it))));
108  }
109  // set up flags
111  //.. the ones that are strings
112  std::vector<std::string> stringFlags = flags.getParameterNamesForType<std::string>();
113  for (std::vector<std::string>::const_iterator it = stringFlags.begin(), ed = stringFlags.end(); it != ed; ++it) {
114  flags_.push_back(tnp::ProbeFlag(branchNamePrefix + *it, flags.getParameter<std::string>(*it)));
115  }
116  //.. the ones that are InputTags
117  std::vector<std::string> inputTagFlags = flags.getParameterNamesForType<edm::InputTag>();
118  for (std::vector<std::string>::const_iterator it = inputTagFlags.begin(), ed = inputTagFlags.end(); it != ed; ++it) {
119  flags_.push_back(tnp::ProbeFlag(branchNamePrefix + *it, iC.consumes<edm::View<reco::Candidate> >(flags.getParameter<edm::InputTag>(*it))));
120  }
121 
122  // then make all the variables in the trees
123  for (std::vector<tnp::ProbeVariable>::iterator it = vars_.begin(), ed = vars_.end(); it != ed; ++it) {
124  tree->Branch(it->name().c_str(), it->address(), (it->name()+"/F").c_str());
125  }
126 
127  for (std::vector<tnp::ProbeFlag>::iterator it = flags_.begin(), ed = flags_.end(); it != ed; ++it) {
128  tree->Branch(it->name().c_str(), it->address(), (it->name()+"/I").c_str());
129  }
130 
131 }
132 
134 
136  run_ = iEvent.id().run();
137  lumi_ = iEvent.id().luminosityBlock();
138  event_ = iEvent.id().event();
139 
140  for (std::vector<tnp::ProbeVariable>::const_iterator it = vars_.begin(), ed = vars_.end(); it != ed; ++it) {
141  it->init(iEvent);
142  }
143  for (std::vector<tnp::ProbeFlag>::const_iterator it = flags_.begin(), ed = flags_.end(); it != ed; ++it) {
144  it->init(iEvent);
145  }
146  if (weightMode_ == External) {
148  iEvent.getByToken(weightSrcToken_, weight);
149  weight_ = *weight;
150  }
151 
152  if (addEventVariablesInfo_) {
156  iEvent.getByToken(recVtxsToken_,recVtxs);
157  mNPV_ = 0;
158  mPVx_ = 100.0;
159  mPVy_ = 100.0;
160  mPVz_ = 100.0;
161 
162  for(unsigned int ind=0;ind<recVtxs->size();ind++) {
163  if (!((*recVtxs)[ind].isFake()) && ((*recVtxs)[ind].ndof()>4)
164  && (fabs((*recVtxs)[ind].z())<=24.0) &&
165  ((*recVtxs)[ind].position().Rho()<=2.0) ) {
166  mNPV_++;
167  if(mNPV_==1) { // store the first good primary vertex
168  mPVx_ = (*recVtxs)[ind].x();
169  mPVy_ = (*recVtxs)[ind].y();
170  mPVz_ = (*recVtxs)[ind].z();
171  }
172  }
173  }
174 
175 
178  iEvent.getByToken(beamSpotToken_, beamSpot);
179  mBSx_ = beamSpot->position().X();
180  mBSy_ = beamSpot->position().Y();
181  mBSz_ = beamSpot->position().Z();
182 
183 
186  iEvent.getByToken(metToken_,met);
187  if (met->size() == 0) {
188  mMET_ = -1;
189  mSumET_ = -1;
190  mMETSign_ = -1;
191  }
192  else {
193  mMET_ = (*met)[0].et();
194  mSumET_ = (*met)[0].sumEt();
195  mMETSign_ = (*met)[0].significance();
196  }
197 
200  iEvent.getByToken(tcmetToken_, tcmet);
201  if (tcmet->size() == 0) {
202  mtcMET_ = -1;
203  mtcSumET_ = -1;
204  mtcMETSign_ = -1;
205  }
206  else {
207  mtcMET_ = (*tcmet)[0].et();
208  mtcSumET_ = (*tcmet)[0].sumEt();
209  mtcMETSign_ = (*tcmet)[0].significance();
210  }
211 
214  iEvent.getByToken(pfmetToken_, pfmet);
215  if (pfmet->size() == 0) {
216  mpfMET_ = -1;
217  mpfSumET_ = -1;
218  mpfMETSign_ = -1;
219  }
220  else {
221  mpfMET_ = (*pfmet)[0].et();
222  mpfSumET_ = (*pfmet)[0].sumEt();
223  mpfMETSign_ = (*pfmet)[0].significance();
224  }
225  }
226 
227 }
228 
230  for (std::vector<tnp::ProbeVariable>::const_iterator it = vars_.begin(), ed = vars_.end(); it != ed; ++it) {
231  if (ignoreExceptions_) {
232  try{ it->fill(probe); } catch(cms::Exception &ex ){}
233  } else {
234  it->fill(probe);
235  }
236  }
237 
238  for (std::vector<tnp::ProbeFlag>::const_iterator it = flags_.begin(), ed = flags_.end(); it != ed; ++it) {
239  if (ignoreExceptions_) {
240  try{ it->fill(probe); } catch(cms::Exception &ex ){}
241  } else {
242  it->fill(probe);
243  }
244  }
245  if (tree_) tree_->Fill();
246 }
248  TList *list = tree_->GetUserInfo();
249  list->Add(new TObjString(pset.dump().c_str()));
250 }
RunNumber_t run() const
Definition: EventID.h:42
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
int i
Definition: DBlmapReader.cc:9
tuple met
____________________________________________________________________________||
Definition: CaloMET_cfi.py:4
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:184
void init(const edm::Event &iEvent) const
To be called at the beginning of the event (will fetch Candidate View if needed)
void writeProvenance(const edm::ParameterSet &pset) const
std::string dump(unsigned int indent=0) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
void fill(const reco::CandidateBaseRef &probe) const
To be called for each item.
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
~ProbeFlag()
Destructor (does nothing)
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:43
std::vector< reco::MET > METCollection
collection of MET objects
Definition: METCollection.h:23
float float float z
void fill(const reco::CandidateBaseRef &probe) const
To be called once per probe, to fill the values for this probe.
A variable for the probe: can be a string expression or an external ValueMap&lt;float&gt; ...
int main(int argc, char **argv)
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:192
~BaseTreeFiller()
Destructor, does nothing but it&#39;s out-of-line as we have complex data members.
int iEvent
Definition: GenABIO.cc:230
void init(const edm::Event &iEvent) const
To be called once per event, to load possible external variables.
~ProbeVariable()
Destructor (does nothing)
void addBranches_(TTree *tree, const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC, const std::string &branchNamePrefix="")
std::vector< reco::CaloMET > CaloMETCollection
collection of CaloMET objects
edm::EventID id() const
Definition: EventBase.h:56
std::vector< reco::PFMET > PFMETCollection
collection of PFMET objects
void event_()
volatile std::atomic< bool > shutdown_flag false
int weight
Definition: histoStyle.py:50
BaseTreeFiller(const char *name, const edm::ParameterSet &config, edm::ConsumesCollector &&iC)
specify the name of the TTree, and the configuration for it
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run