CMS 3D CMS Logo

pftools::TreeUtility Class Reference

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

#include <RecoParticleFlow/PFClusterTools/interface/TreeUtility.h>

List of all members.

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)
std::vector< ParticleDepositPtrextractParticles (TFile &f)
unsigned getCalibratablesFromRootFile (TChain &tree, std::vector< Calibratable > &toBeFilled)
void recreateFromRootFile (TFile &f)
void recreateFromRootFile (TFile &file, std::vector< DetectorElementPtr > &elements, std::vector< ParticleDepositPtr > &toBeFilled)
 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.

Todo:
Remove recreateFromRootFile(TFile& file) as this is only useful for testing purposes!
Author:
Jamie Ballin
Date:
April 2008

Definition at line 25 of file TreeUtility.h.


Constructor & Destructor Documentation

TreeUtility::TreeUtility (  ) 

Definition at line 9 of file TreeUtility.cc.

00009                          {
00010 }

TreeUtility::~TreeUtility (  )  [virtual]

Definition at line 12 of file TreeUtility.cc.

00012                           {
00013 }


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 41 of file TreeUtility.cc.

References c, pftools::Calibratable::cand_energyEcal_, pftools::Calibratable::cand_energyHcal_, pftools::Calibratable::cand_eta_, pftools::Calibratable::cand_phi_, pftools::Calibratable::cands_num_, 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_, count, GenMuonPlsPt100GeV_cfg::cout, lat::endl(), pftools::CalibratableElement::energy_, pftools::CalibratableElement::eta_, PFCANDIDATE, PFELEMENT, pftools::CalibratableElement::phi_, 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_, UNDEFINED, and dimuonsSequences_cff::veto.

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

00045                                                              {
00046 
00047         std::cout << __PRETTY_FUNCTION__ << std::endl;
00048         std::cout << "WARNING: Using fabs() for eta value assignments!\n";
00049         std::cout << "Input Calibratable has size " << input.size() << "\n"; 
00050         std::cout << "Cutting on > 1 PFCandidate.\n";
00051         
00052         //neither of these two are supported yet
00053         if (target == UNDEFINED || target == PFELEMENT)
00054                 return 0;
00055         unsigned count(0);
00056         for (std::vector<Calibratable>::const_iterator cit = input.begin(); cit
00057                         != input.end(); ++cit) {
00058                 Calibratable c = *cit;
00059                 ParticleDepositPtr pd(new ParticleDeposit());
00060                 bool veto(false);
00061                 if (c.sim_isMC_) {
00062                         pd->setTruthEnergy(c.sim_energyEvent_);
00063                         pd->setEta(fabs(c.sim_eta_));
00064                         pd->setPhi(c.sim_phi_);
00065                         //TODO:: sort this out
00066                         if (c.sim_energyEvent_== 0)
00067                                 veto = true;
00068                 }
00069                 
00070                 if(c.cands_num_ > 1)
00071                         veto = true;
00072 
00073                 if (target == CLUSTER) {
00074                         if (c.cluster_ecal_.size() == 0 && c.cluster_hcal_.size() ==0)
00075                                 veto = true;
00076                         //                      if (c.cluster_numEcal_ > 1|| c.cluster_numHcal_ > 1)
00077                         //                              veto = true;
00078                         //TODO: using fabs for eta! WARNING!!!
00079                         Deposition decal(ecal, fabs(c.cluster_meanEcal_.eta_),
00080                                         c.cluster_meanEcal_.phi_, c.cluster_energyEcal_, 0);
00081                         Deposition dhcal(hcal, fabs(c.cluster_meanHcal_.eta_),
00082                                         c.cluster_meanHcal_.phi_, c.cluster_energyHcal_, 0);
00083                         Deposition doffset(offset, fabs(c.cluster_meanEcal_.eta_),
00084                                         c.cluster_meanEcal_.phi_, 0.001, 0);
00085 
00086                                 pd->addTruthDeposition(decal);
00087                                 pd->addRecDeposition(decal);
00088 
00089                                 pd->addTruthDeposition(dhcal);
00090                                 pd->addRecDeposition(dhcal);
00091 
00092 
00093                         if (includeOffset) {
00094                                 pd->addTruthDeposition(doffset);
00095                                 pd->addRecDeposition(doffset);
00096                         }
00097 
00098                 }
00099 
00100                 else if (target == PFCANDIDATE) {
00101                         //                      if(c.cands_num_ != 1)
00102                         //                              veto = true;
00103                         Deposition decal(ecal, c.cand_eta_, c.cand_phi_,
00104                                         c.cand_energyEcal_, 0);
00105                         Deposition dhcal(hcal, c.cand_eta_, c.cand_phi_,
00106                                         c.cand_energyHcal_, 0);
00107                         Deposition doffset(offset, c.cand_eta_, c.cand_phi_, 1.0, 0);
00108 
00109                         pd->addTruthDeposition(decal);
00110                         pd->addTruthDeposition(dhcal);
00111                         pd->addRecDeposition(decal);
00112                         pd->addRecDeposition(dhcal);
00113 
00114                         if (includeOffset) {
00115                                 pd->addTruthDeposition(doffset);
00116                                 pd->addRecDeposition(doffset);
00117                         }
00118                 }
00119 
00120                 else if (target == RECHIT) {
00121                         if (c.rechits_ecal_.size() == 0&& c.rechits_hcal_.size() == 0)
00122                         veto = true;
00123                         Deposition decal(ecal, c.rechits_meanEcal_.eta_,
00124                                         c.rechits_meanEcal_.phi_, c.rechits_meanEcal_.energy_
00125                                         * c.rechits_ecal_.size(), 0);
00126                         Deposition dhcal(hcal, c.rechits_meanHcal_.eta_,
00127                                         c.rechits_meanHcal_.phi_, c.rechits_meanHcal_.energy_
00128                                         * c.rechits_hcal_.size(), 0);
00129                         Deposition doffset(offset, c.rechits_meanEcal_.eta_,
00130                                         c.rechits_meanEcal_.phi_, 1.0, 0);
00131 
00132                         pd->addTruthDeposition(decal);
00133                         pd->addTruthDeposition(dhcal);
00134                         pd->addRecDeposition(decal);
00135                         pd->addRecDeposition(dhcal);
00136 
00137                         if (includeOffset) {
00138                                 pd->addTruthDeposition(doffset);
00139                                 pd->addRecDeposition(doffset);
00140                         }
00141 
00142                 }
00143                 if (!veto)
00144                 toBeFilled.push_back(pd);
00145         
00146                 ++count;
00147         }
00148         
00149         return toBeFilled.size();
00150 
00151 }

std::vector< ParticleDepositPtr > TreeUtility::extractParticles ( TFile &  f  ) 

Definition at line 249 of file TreeUtility.cc.

References GenMuonPlsPt100GeV_cfg::cout, ReconstructionGR_cff::ecal, pftools::ECAL, bookConverter::elements, pftools::HCAL, ReconstructionGR_cff::hcal, and recreateFromRootFile().

00249                                                                     {
00250         DetectorElementPtr ecal(new DetectorElement(ECAL, 1.0));
00251         DetectorElementPtr hcal(new DetectorElement(HCAL, 1.0));
00252         std::vector<DetectorElementPtr> elements;
00253         elements.push_back(ecal);
00254         elements.push_back(hcal);
00255         std::cout << "Made detector elements...\n";
00256         std::cout << "Recreating from root file...\n";
00257         std::vector<ParticleDepositPtr> particles;
00258         recreateFromRootFile(f, elements, particles);
00259         return particles;
00260 }

unsigned TreeUtility::getCalibratablesFromRootFile ( TChain &  tree,
std::vector< Calibratable > &  toBeFilled 
)

Definition at line 15 of file TreeUtility.cc.

References c, GenMuonPlsPt100GeV_cfg::cout, and python::tagInventory::entries.

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

00016                                                      {
00017 
00018 //      f.cd("extraction");
00019 //      TTree* tree = (TTree*) f.Get("extraction/Extraction");
00020 //      if (tree == 0) {
00021 //              PFToolsException me("Couldn't open tree!");
00022 //              throw me;
00023 //      }
00024 //      std::cout << "Successfully opened file. Getting branches..."<< std::endl;
00025         CalibratablePtr calib_ptr(new Calibratable());
00026         //TBranch* calibBr = tree.GetBranch("Calibratable");
00027         //spwBr->SetAddress(&spw);
00028         tree.SetBranchAddress("Calibratable", &calib_ptr);
00029         
00030         std::cout << "Looping over tree's "<< tree.GetEntries() << " entries...\n";
00031         for (unsigned entries(0); entries < tree.GetEntries(); entries++) {
00032                 tree.GetEntry(entries);
00033                 Calibratable c(*calib_ptr);
00034                 toBeFilled.push_back(c);
00035         }
00036 
00037         return tree.GetEntries();
00038 
00039 }

void TreeUtility::recreateFromRootFile ( TFile &  f  ) 

Definition at line 235 of file TreeUtility.cc.

References GenMuonPlsPt100GeV_cfg::cout, ReconstructionGR_cff::ecal, pftools::ECAL, bookConverter::elements, pftools::HCAL, ReconstructionGR_cff::hcal, and recreateFromRootFile().

00235                                                {
00236 
00237         DetectorElementPtr ecal(new DetectorElement(ECAL, 1.0));
00238         DetectorElementPtr hcal(new DetectorElement(HCAL, 1.0));
00239         std::vector<DetectorElementPtr> elements;
00240         elements.push_back(ecal);
00241         elements.push_back(hcal);
00242         std::cout << "Made detector elements...\n";
00243         std::cout << "Recreating from root file...\n";
00244         std::vector<ParticleDepositPtr> particles;
00245         recreateFromRootFile(f, elements, particles);
00246         std::cout << "Finished.\n";
00247 }

void TreeUtility::recreateFromRootFile ( TFile &  file,
std::vector< DetectorElementPtr > &  elements,
std::vector< ParticleDepositPtr > &  toBeFilled 
)

Definition at line 153 of file TreeUtility.cc.

References GenMuonPlsPt100GeV_cfg::cout, ReconstructionGR_cff::ecal, pftools::ECAL, lat::endl(), python::tagInventory::entries, pftools::HCAL, ReconstructionGR_cff::hcal, it, me, pftools::OFFSET, offset, and tree.

Referenced by extractParticles(), and recreateFromRootFile().

00155                                                            {
00156 
00157         std::cout << __PRETTY_FUNCTION__
00158                         << ": This method is highly specific to detector element types and may fail if their definitions change. Please be advised of this limitation!\n";
00159         typedef boost::shared_ptr<SingleParticleWrapper> SingleParticleWrapperPtr;
00160         DetectorElementPtr ecal;
00161         DetectorElementPtr hcal;
00162         DetectorElementPtr offset;
00163         SingleParticleWrapperPtr spw_ptr(new SingleParticleWrapper);
00164         //SingleParticleWrapper* spw = new SingleParticleWrapper;
00165 
00166         for (std::vector<DetectorElementPtr>::iterator it = elements.begin(); it
00167                         != elements.end(); ++it) {
00168                 DetectorElementPtr de = *it;
00169                 if (de->getType() == ECAL)
00170                         ecal = de;
00171                 if (de->getType() == HCAL)
00172                         hcal = de;
00173                 if (de->getType() == OFFSET)
00174                         offset = de;
00175 
00176         }
00177         if (offset == 0) {
00178                 std::cout
00179                                 << "Offset element NOT found in input collection; no 'a' coefficient will be added to ParticleDeposits.\n";
00180         }
00181 
00182         std::cout << "Initialised detector elements."<< std::endl;
00183 
00184         if (offset != 0)
00185                 std::cout << "\t"<< *offset << "\n";
00186         std::cout << "\t"<< *ecal << "\n";
00187         std::cout << "\t"<< *hcal << "\n";
00188         file.ls();
00189         TTree* tree = (TTree*) file.Get("CaloData");
00190         tree->ls();
00191         if (tree == 0) {
00192                 PFToolsException me("Couldn't open tree!");
00193                 throw me;
00194         }
00195         std::cout << "Opened Tree CaloData...\n";
00196 
00197         std::cout << "Assigning branch: \n";
00198         TBranch* spwBr = tree->GetBranch("SingleParticleWrapper");
00199         //spwBr->SetAddress(&spw);
00200         spwBr->SetAddress(&spw_ptr);
00201         std::cout << "Looping over entries...\n";
00202         for (unsigned entries(0); entries < tree->GetEntries(); entries++) {
00203 
00204                 tree->GetEntry(entries);
00205 
00206                 ParticleDepositPtr pd(new ParticleDeposit(spw_ptr->trueEnergy, spw_ptr->etaEcal, spw_ptr->phiEcal));
00207 
00208                 if (offset != 0) {
00209                         Deposition dOffset(offset, spw_ptr->etaEcal, spw_ptr->phiEcal, 1.0);
00210                         pd->addRecDeposition(dOffset);
00211                         pd->addTruthDeposition(dOffset);
00212                 }
00213                 Deposition dE(ecal, spw_ptr->etaEcal, spw_ptr->phiEcal, spw_ptr->eEcal);
00214                 Deposition dH(hcal, spw_ptr->etaEcal, spw_ptr->phiEcal, spw_ptr->eHcal);
00215 
00216                 //RecDepositions are what the detector element should detect
00217                 //when well calibrated
00218                 //yet includes detector effects
00219 
00220                 pd->addRecDeposition(dE);
00221                 pd->addRecDeposition(dH);
00222 
00223                 //TruthDepositions are the true MC particle energy depositions
00224                 //Here we set the same as rec depositions - they aren't used in this test case.
00225 
00226                 pd->addTruthDeposition(dE);
00227                 pd->addTruthDeposition(dH);
00228 
00229                 //std::cout << *pd << std::endl;
00230                 toBeFilled.push_back(pd);
00231 
00232         }
00233 
00234 }


Member Data Documentation

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

Definition at line 49 of file TreeUtility.h.


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:50:07 2009 for CMSSW by  doxygen 1.5.4