CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
pftools::TreeUtility Class Reference

Utility class to create particles and detector elements from a Root file. More...

#include <TreeUtility.h>

Public Member Functions

unsigned convertCalibratablesToParticleDeposits (const std::vector< Calibratable > &input, std::vector< ParticleDepositPtr > &toBeFilled, CalibrationTarget target, DetectorElementPtr offset, DetectorElementPtr ecal, DetectorElementPtr hcal, bool includeOffset=false)
 
void dumpCaloDataToCSV (TChain &chain, std::string csvFilename, double range, bool gaus=false)
 
unsigned getCalibratablesFromRootFile (TChain &tree, std::vector< Calibratable > &toBeFilled)
 
unsigned getParticleDepositsDirectly (TChain &sourceChain, std::vector< ParticleDepositPtr > &toBeFilled, CalibrationTarget target, DetectorElementPtr offset, DetectorElementPtr ecal, DetectorElementPtr hcal, bool includeOffset=false)
 
 TreeUtility ()
 
virtual ~TreeUtility ()
 

Private Attributes

std::map< std::string, unsigned > vetos_
 

Detailed Description

Utility class to create particles and detector elements from a Root file.

Author
Jamie Ballin
Date
April 2008

Definition at line 27 of file TreeUtility.h.

Constructor & Destructor Documentation

TreeUtility::TreeUtility ( )

Definition at line 11 of file TreeUtility.cc.

11  {
12 }
TreeUtility::~TreeUtility ( )
virtual

Definition at line 14 of file TreeUtility.cc.

14  {
15 }

Member Function Documentation

unsigned TreeUtility::convertCalibratablesToParticleDeposits ( const std::vector< Calibratable > &  input,
std::vector< ParticleDepositPtr > &  toBeFilled,
CalibrationTarget  target,
DetectorElementPtr  offset,
DetectorElementPtr  ecal,
DetectorElementPtr  hcal,
bool  includeOffset = false 
)

Definition at line 238 of file TreeUtility.cc.

References EnergyCorrector::c, pftools::Calibratable::cand_energyEcal_, pftools::Calibratable::cand_energyHcal_, pftools::Calibratable::cand_eta_, pftools::Calibratable::cand_phi_, pftools::Calibratable::cands_num_, pftools::CLUSTER, pftools::Calibratable::cluster_ecal_, pftools::Calibratable::cluster_energyEcal_, pftools::Calibratable::cluster_energyHcal_, pftools::Calibratable::cluster_hcal_, pftools::Calibratable::cluster_meanEcal_, pftools::Calibratable::cluster_meanHcal_, KineDebug3::count(), gather_cfg::cout, pftools::CalibratableElement::energy_, pftools::CalibratableElement::eta_, pftools::PFCANDIDATE, pftools::PFELEMENT, pftools::CalibratableElement::phi_, pftools::RECHIT, pftools::Calibratable::rechits_ecal_, pftools::Calibratable::rechits_hcal_, pftools::Calibratable::rechits_meanEcal_, pftools::Calibratable::rechits_meanHcal_, pftools::Calibratable::sim_energyEvent_, pftools::Calibratable::sim_eta_, pftools::Calibratable::sim_isMC_, pftools::Calibratable::sim_phi_, pftools::Calibratable::tb_eta_, pftools::Calibratable::tb_isTB_, pftools::Calibratable::tb_phi_, pftools::UNDEFINED, and TriggerAnalyzer::veto.

Referenced by pftools::Exercises3::calibrateCalibratables().

242  {
243 
244  std::cout << __PRETTY_FUNCTION__ << std::endl;
245  std::cout << "WARNING: Using fabs() for eta value assignments!\n";
246  std::cout << "Input Calibratable has size "<< input.size() << "\n";
247  std::cout << "Cutting on > 1 PFCandidate.\n";
248 
249  //neither of these two are supported yet
250  if (target == UNDEFINED || target == PFELEMENT)
251  return 0;
252  unsigned count(0);
253  for (std::vector<Calibratable>::const_iterator cit = input.begin(); cit
254  != input.end(); ++cit) {
255  Calibratable c = *cit;
257  bool veto(false);
258  if (c.sim_isMC_) {
259  pd->setTruthEnergy(c.sim_energyEvent_);
260  pd->setEta(fabs(c.sim_eta_));
261  pd->setPhi(c.sim_phi_);
262  //TODO:: sort this out
263  if (c.sim_energyEvent_== 0)
264  veto = true;
265  }
266  if (c.tb_isTB_) {
267  pd->setTruthEnergy(c.sim_energyEvent_);
268  pd->setEta(c.tb_eta_);
269  pd->setPhi(c.tb_phi_);
270  veto = false;
271  }
272 
273  if (c.cands_num_ > 1)
274  veto = true;
275 
276  if (target == CLUSTER) {
277  if (c.cluster_ecal_.size() == 0&& c.cluster_hcal_.size() ==0)
278  veto = true;
279  // if (c.cluster_numEcal_ > 1|| c.cluster_numHcal_ > 1)
280  // veto = true;
281  //TODO: using fabs for eta! WARNING!!!
282  Deposition decal(ecal, fabs(c.cluster_meanEcal_.eta_),
284  Deposition dhcal(hcal, fabs(c.cluster_meanHcal_.eta_),
286  Deposition doffset(offset, fabs(c.cluster_meanEcal_.eta_),
287  c.cluster_meanEcal_.phi_, 0.001, 0);
288 
289  pd->addTruthDeposition(decal);
290  pd->addRecDeposition(decal);
291 
292  pd->addTruthDeposition(dhcal);
293  pd->addRecDeposition(dhcal);
294 
295  if (includeOffset) {
296  pd->addTruthDeposition(doffset);
297  pd->addRecDeposition(doffset);
298  }
299 
300  }
301 
302  else if (target == PFCANDIDATE) {
303  // if(c.cands_num_ != 1)
304  // veto = true;
305  Deposition decal(ecal, c.cand_eta_, c.cand_phi_,
306  c.cand_energyEcal_, 0);
307  Deposition dhcal(hcal, c.cand_eta_, c.cand_phi_,
308  c.cand_energyHcal_, 0);
309  Deposition doffset(offset, c.cand_eta_, c.cand_phi_, 1.0, 0);
310 
311  pd->addTruthDeposition(decal);
312  pd->addTruthDeposition(dhcal);
313  pd->addRecDeposition(decal);
314  pd->addRecDeposition(dhcal);
315 
316  if (includeOffset) {
317  pd->addTruthDeposition(doffset);
318  pd->addRecDeposition(doffset);
319  }
320  }
321 
322  else if (target == RECHIT) {
323  if (c.rechits_ecal_.size() == 0&& c.rechits_hcal_.size() == 0)
324  veto = true;
327  * c.rechits_ecal_.size(), 0);
330  * c.rechits_hcal_.size(), 0);
332  c.rechits_meanEcal_.phi_, 1.0, 0);
333 
334  pd->addTruthDeposition(decal);
335  pd->addTruthDeposition(dhcal);
336  pd->addRecDeposition(decal);
337  pd->addRecDeposition(dhcal);
338 
339  if (includeOffset) {
340  pd->addTruthDeposition(doffset);
341  pd->addRecDeposition(doffset);
342  }
343 
344  }
345  if (!veto)
346  toBeFilled.push_back(pd);
347 
348  ++count;
349  }
350 
351  return toBeFilled.size();
352 
353 }
CalibratableElement rechits_meanHcal_
Definition: Calibratable.h:193
Wraps essential single particle calibration data ready for export to a Root file. ...
Definition: Calibratable.h:122
CalibratableElement cluster_meanEcal_
Definition: Calibratable.h:186
std::vector< CalibratableElement > rechits_ecal_
Definition: Calibratable.h:191
static std::string const input
Definition: EdmProvDump.cc:44
boost::shared_ptr< ParticleDeposit > ParticleDepositPtr
CalibratableElement rechits_meanEcal_
Definition: Calibratable.h:193
std::vector< CalibratableElement > rechits_hcal_
Definition: Calibratable.h:191
std::vector< CalibratableElement > cluster_ecal_
Definition: Calibratable.h:184
This class holds an arbitrary energy deposition, specified in terms of angular position, energy, depth (optional) and detector element type.
Definition: Deposition.h:20
std::vector< CalibratableElement > cluster_hcal_
Definition: Calibratable.h:184
CalibratableElement cluster_meanHcal_
Definition: Calibratable.h:186
tuple cout
Definition: gather_cfg.py:145
void TreeUtility::dumpCaloDataToCSV ( TChain &  chain,
std::string  csvFilename,
double  range,
bool  gaus = false 
)

Definition at line 48 of file TreeUtility.cc.

References EnergyCorrector::c, pftools::Calibratable::cands_num_, pftools::Calibratable::cluster_ecal_, pftools::Calibratable::cluster_hcal_, gather_cfg::cout, bTagCalibrationDbCreation::csvFile, g, pftools::Calibratable::recompute(), pftools::Calibratable::sim_energyEvent_, pftools::Calibratable::sim_eta_, and TriggerAnalyzer::veto.

48  {
49 
50  CalibratablePtr calib_ptr(new Calibratable());
51 
52  tree.SetBranchAddress("Calibratable", &calib_ptr);
53  std::ofstream csvFile;
54  csvFile.open(csvFilename.c_str());
55 
56  std::cout << "Looping over tree's "<< tree.GetEntries() << " entries...\n";
57  unsigned writes(0);
58  TFile freq("freq.root", "recreate");
59  TH1F frequencies("f", "f", 50, 0, range);
60  TF1 g("g", "gaus(0)");
61  g.FixParameter(1, range/2.0);
62  g.FixParameter(0, 1),
63  g.FixParameter(2, range/4.0);
64 
65  for (unsigned entries(0); entries < tree.GetEntries(); entries++) {
66  tree.GetEntry(entries);
67  Calibratable c(*calib_ptr);
68  bool veto(false);
69 
70  //Check vetos as usual
71  if (c.cands_num_ > 1)
72  veto = true;
73  if(c.cluster_ecal_.size() == 0 && c.cluster_hcal_.size() == 0)
74  veto = true;
75  if(!veto) {
76  if(frequencies.GetBinContent(static_cast<int>(floor(c.sim_energyEvent_)) + 1) < (3000) * g.Eval(c.sim_energyEvent_) ) {
77  frequencies.Fill(static_cast<int>(floor(c.sim_energyEvent_)));
78  c.recompute();
79  csvFile << c.sim_energyEvent_ << "\t";
80  /*
81  csvFile << c.sim_energyEcal_ << "\t";
82  csvFile << c.sim_energyHcal_ << "\t";
83 
84 
85  csvFile << c.cluster_energyEcal_/range << "\t";
86  csvFile << c.cluster_energyHcal_/range << "\t";
87 
88  CaloWindow newEcalWindow(c.cluster_meanEcal_.eta_, c.cluster_meanEcal_.phi_, 5, 0.01, 3);
89  const std::vector<CalibratableElement>& ecal = c.cluster_ecal_;
90  std::vector<CalibratableElement>::const_iterator cit = ecal.begin();
91  for(; cit != ecal.end(); ++cit) {
92  const CalibratableElement& hit = *cit;
93  bool added = newEcalWindow.addHit(hit.eta_, hit.phi_, hit.energy_);
94  if(!added)
95  veto = true;
96  }
97  */
98 
99  csvFile << fabs(c.sim_eta_/2) << "\n";
100 
101  ++writes;
102  }
103  }
104 
105 
106  }
107  frequencies.Print("frequencies.eps");
108  frequencies.Write();
109  freq.Close();
110  std::cout << "Closing file " << csvFilename << " with " << writes << " entries.\n" << std::endl;
111 
112  csvFile.close();
113 
114 }
Wraps essential single particle calibration data ready for export to a Root file. ...
Definition: Calibratable.h:122
boost::shared_ptr< Calibratable > CalibratablePtr
Definition: TreeUtility.h:26
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
tuple cout
Definition: gather_cfg.py:145
unsigned TreeUtility::getCalibratablesFromRootFile ( TChain &  tree,
std::vector< Calibratable > &  toBeFilled 
)

Definition at line 21 of file TreeUtility.cc.

References EnergyCorrector::c, pftools::Calibratable::cands_num_, pftools::Calibratable::cluster_ecal_, pftools::Calibratable::cluster_hcal_, and gather_cfg::cout.

Referenced by pftools::Exercises3::calibrateCalibratables(), and pftools::CalibCompare::calibrateCalibratables().

22  {
23 
24  // f.cd("extraction");
25  // TTree* tree = (TTree*) f.Get("extraction/Extraction");
26  // if (tree == 0) {
27  // PFToolsException me("Couldn't open tree!");
28  // throw me;
29  // }
30  // std::cout << "Successfully opened file. Getting branches..."<< std::endl;
31  CalibratablePtr calib_ptr(new Calibratable());
32  //TBranch* calibBr = tree.GetBranch("Calibratable");
33  //spwBr->SetAddress(&spw);
34  tree.SetBranchAddress("Calibratable", &calib_ptr);
35 
36  std::cout << "Looping over tree's "<< tree.GetEntries() << " entries...\n";
37  for (unsigned entries(0); entries < tree.GetEntries(); entries++) {
38  tree.GetEntry(entries);
39  Calibratable c(*calib_ptr);
40  if (c.cands_num_ == 1 && (c.cluster_ecal_.size() + c.cluster_hcal_.size()) > 0)
41  toBeFilled.push_back(c);
42  }
43  std::cout << "Done." << std::endl;
44  return tree.GetEntries();
45 
46 }
Wraps essential single particle calibration data ready for export to a Root file. ...
Definition: Calibratable.h:122
boost::shared_ptr< Calibratable > CalibratablePtr
Definition: TreeUtility.h:26
tuple cout
Definition: gather_cfg.py:145
unsigned TreeUtility::getParticleDepositsDirectly ( TChain &  sourceChain,
std::vector< ParticleDepositPtr > &  toBeFilled,
CalibrationTarget  target,
DetectorElementPtr  offset,
DetectorElementPtr  ecal,
DetectorElementPtr  hcal,
bool  includeOffset = false 
)

Definition at line 116 of file TreeUtility.cc.

References EnergyCorrector::c, pftools::Calibratable::cand_energyEcal_, pftools::Calibratable::cand_energyHcal_, pftools::Calibratable::cand_eta_, pftools::Calibratable::cand_phi_, pftools::Calibratable::cands_num_, pftools::CLUSTER, pftools::Calibratable::cluster_ecal_, pftools::Calibratable::cluster_energyEcal_, pftools::Calibratable::cluster_energyHcal_, pftools::Calibratable::cluster_hcal_, pftools::Calibratable::cluster_meanEcal_, pftools::Calibratable::cluster_meanHcal_, KineDebug3::count(), gather_cfg::cout, pftools::CalibratableElement::energy_, pftools::CalibratableElement::eta_, pftools::PFCANDIDATE, pftools::PFELEMENT, pftools::CalibratableElement::phi_, pftools::RECHIT, pftools::Calibratable::rechits_ecal_, pftools::Calibratable::rechits_hcal_, pftools::Calibratable::rechits_meanEcal_, pftools::Calibratable::rechits_meanHcal_, pftools::Calibratable::sim_energyEvent_, pftools::Calibratable::sim_eta_, pftools::Calibratable::sim_isMC_, pftools::Calibratable::sim_phi_, pftools::Calibratable::tb_eta_, pftools::Calibratable::tb_isTB_, pftools::Calibratable::tb_phi_, pftools::UNDEFINED, and TriggerAnalyzer::veto.

119  {
120 
121  CalibratablePtr calib_ptr(new Calibratable());
122  sourceChain.SetBranchAddress("Calibratable", &calib_ptr);
123  std::cout << __PRETTY_FUNCTION__ << std::endl;
124  std::cout << "WARNING: Using fabs() for eta value assignments!\n";
125  std::cout << "Cutting on > 1 PFCandidate.\n";
126  std::cout << "Looping over tree's "<< sourceChain.GetEntries() << " entries...\n";
127  //neither of these two are supported yet
128  if (target == UNDEFINED || target == PFELEMENT)
129  return 0;
130  unsigned count(0);
131 
132  for (unsigned entries(0); entries < sourceChain.GetEntries(); entries++) {
133  sourceChain.GetEntry(entries);
134  Calibratable c(*calib_ptr);
135 
137  bool veto(false);
138  if (c.sim_isMC_) {
139  pd->setTruthEnergy(c.sim_energyEvent_);
140  pd->setEta(fabs(c.sim_eta_));
141  pd->setPhi(c.sim_phi_);
142  //TODO:: sort this out
143  if (c.sim_energyEvent_== 0)
144  veto = true;
145  }
146  if (c.tb_isTB_) {
147  pd->setTruthEnergy(c.sim_energyEvent_);
148  pd->setEta(c.tb_eta_);
149  pd->setPhi(c.tb_phi_);
150  veto = false;
151  }
152 
153  if (c.cands_num_ > 1)
154  veto = true;
155 
156  std::cout << "WARNING: HARD CUT ON 100 GeV SIM PARTICLES!\n";
157  if(c.sim_energyEvent_ > 100)
158  veto = true;
159 
160  if (target == CLUSTER) {
161  if (c.cluster_ecal_.size() == 0 && c.cluster_hcal_.size() ==0)
162  veto = true;
163  // if (c.cluster_numEcal_ > 1|| c.cluster_numHcal_ > 1)
164  // veto = true;
165  //TODO: using fabs for eta! WARNING!!!
166  Deposition decal(ecal, fabs(c.cluster_meanEcal_.eta_),
167  c.cluster_meanEcal_.phi_, c.cluster_energyEcal_, 0);
168  Deposition dhcal(hcal, fabs(c.cluster_meanHcal_.eta_),
169  c.cluster_meanHcal_.phi_, c.cluster_energyHcal_, 0);
170  Deposition doffset(offset, fabs(c.cluster_meanEcal_.eta_),
171  c.cluster_meanEcal_.phi_, 0.001, 0);
172 
173  pd->addTruthDeposition(decal);
174  pd->addRecDeposition(decal);
175 
176  pd->addTruthDeposition(dhcal);
177  pd->addRecDeposition(dhcal);
178 
179  if (includeOffset) {
180  pd->addTruthDeposition(doffset);
181  pd->addRecDeposition(doffset);
182  }
183 
184  }
185 
186  else if (target == PFCANDIDATE) {
187  // if(c.cands_num_ != 1)
188  // veto = true;
189  Deposition decal(ecal, c.cand_eta_, c.cand_phi_,
190  c.cand_energyEcal_, 0);
191  Deposition dhcal(hcal, c.cand_eta_, c.cand_phi_,
192  c.cand_energyHcal_, 0);
193  Deposition doffset(offset, c.cand_eta_, c.cand_phi_, 1.0, 0);
194 
195  pd->addTruthDeposition(decal);
196  pd->addTruthDeposition(dhcal);
197  pd->addRecDeposition(decal);
198  pd->addRecDeposition(dhcal);
199 
200  if (includeOffset) {
201  pd->addTruthDeposition(doffset);
202  pd->addRecDeposition(doffset);
203  }
204  }
205 
206  else if (target == RECHIT) {
207  if (c.rechits_ecal_.size() == 0&& c.rechits_hcal_.size() == 0)
208  veto = true;
209  Deposition decal(ecal, c.rechits_meanEcal_.eta_,
210  c.rechits_meanEcal_.phi_, c.rechits_meanEcal_.energy_
211  * c.rechits_ecal_.size(), 0);
212  Deposition dhcal(hcal, c.rechits_meanHcal_.eta_,
213  c.rechits_meanHcal_.phi_, c.rechits_meanHcal_.energy_
214  * c.rechits_hcal_.size(), 0);
215  Deposition doffset(offset, c.rechits_meanEcal_.eta_,
216  c.rechits_meanEcal_.phi_, 1.0, 0);
217 
218  pd->addTruthDeposition(decal);
219  pd->addTruthDeposition(dhcal);
220  pd->addRecDeposition(decal);
221  pd->addRecDeposition(dhcal);
222 
223  if (includeOffset) {
224  pd->addTruthDeposition(doffset);
225  pd->addRecDeposition(doffset);
226  }
227 
228  }
229  if (!veto)
230  toBeFilled.push_back(pd);
231 
232  ++count;
233  }
234 
235  return toBeFilled.size();
236 }
Wraps essential single particle calibration data ready for export to a Root file. ...
Definition: Calibratable.h:122
boost::shared_ptr< Calibratable > CalibratablePtr
Definition: TreeUtility.h:26
boost::shared_ptr< ParticleDeposit > ParticleDepositPtr
This class holds an arbitrary energy deposition, specified in terms of angular position, energy, depth (optional) and detector element type.
Definition: Deposition.h:20
tuple cout
Definition: gather_cfg.py:145

Member Data Documentation

std::map<std::string, unsigned> pftools::TreeUtility::vetos_
private

Definition at line 51 of file TreeUtility.h.