CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
Utilities.h File Reference
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include "TMath.h"

Go to the source code of this file.

Functions

void mergeNtuples (const char *ntuplename, const char *filestomerge, const char *outputfile)
 
template<typename T >
std::string numToStr (T num)
 
float processPrediction (float BDTPt, int Quality, float PrelimFit)
 
template<class bidiiter >
bidiiter shuffle (bidiiter begin, bidiiter end, size_t num_random)
 
void sortNtupleByEvent (const char *ntuplename, const char *filenametosort, const char *outputfile)
 

Variables

const Double_t ptscale [31]
 
const std::vector< Double_t > ptScale
 
const Double_t twoJets_scale [16]
 
const std::vector< Double_t > twoJetsScale
 

Function Documentation

void mergeNtuples ( const char *  ntuplename,
const char *  filestomerge,
const char *  outputfile 
)

Definition at line 87 of file Utilities.cc.

88 {
89  TChain chain(ntuplename);
90  chain.Add(filestomerge);
91  chain.Merge(outputfile);
92 }
template<typename T >
std::string numToStr ( T  num)

Definition at line 43 of file Utilities.h.

References pileupDistInMC::num, alignCSCRings::s, contentValuesCheck::ss, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by Tree::addXMLAttributes().

44 {
45 // Convert a number to a string.
46  std::stringstream ss;
47  ss << num;
48  std::string s = ss.str();
49  return s;
50 };
float processPrediction ( float  BDTPt,
int  Quality,
float  PrelimFit 
)

Definition at line 47 of file Utilities.cc.

References RPCpg::pts, and ptscale.

48 {
49 // Discretize and scale the BDTPt prediction
50 
51 
52  // Fix terrible predictions
53  if(BDTPt < 0) BDTPt = PrelimFit;
54  if(BDTPt > 250) BDTPt = PrelimFit;
55 
56  float BDTPt1 = BDTPt;
57  float scaleF = 1.0;
58 
59  // Scale based upon quality
60  if (Quality == 3) scaleF = 1.15;
61  if (Quality == 2) scaleF = 1.3;
62  if (Quality == 1) scaleF = 1.7;
63 
64  BDTPt1 = scaleF*BDTPt1;
65 
66 
67  // Discretize based upon ptscale
68  for (int pts=0; pts<31; pts++)
69  {
70  if (ptscale[pts]<=BDTPt1 && ptscale[pts+1]>BDTPt1)
71  {
72  BDTPt1 = ptscale[pts];
73  break;
74  }
75  }
76 
77  if (BDTPt1 > 140) BDTPt1 = 140;
78  if (BDTPt1 < 0) BDTPt1 = 0;
79 
80  return BDTPt1;
81 }
static const double pts[33]
Definition: Constants.h:30
const Double_t ptscale[31]
Definition: PtAssignment.h:20
template<class bidiiter >
bidiiter shuffle ( bidiiter  begin,
bidiiter  end,
size_t  num_random 
)

Definition at line 26 of file Utilities.h.

References begin, HLT_FULL_cff::distance, alignCSCRings::r, rand(), and std::swap().

Referenced by Forest::prepareRandomSubsample().

27 {
28 // We will end up with the same elements in the collection except that
29 // the first num_random elements will be randomized.
30 
31  size_t left = std::distance(begin, end);
32  while (num_random--) {
33  bidiiter r = begin;
34  std::advance(r, rand()%left);
35  std::swap(*begin, *r);
36  ++begin;
37  --left;
38  }
39  return begin;
40 }
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
#define end
Definition: vmac.h:37
#define begin
Definition: vmac.h:30
Signal rand(Signal arg)
Definition: vlib.cc:442
void sortNtupleByEvent ( const char *  ntuplename,
const char *  filenametosort,
const char *  outputfile 
)

Definition at line 98 of file Utilities.cc.

References f, validate-o2o-wbm::f2, i, cmsHarvester::index, and MainPageGenerator::tree.

99 {
100  //TFile f("../../all_test_redux_post.root");
101  TFile f(filenametosort);
102  TNtuple *tree = (TNtuple*)f.Get(ntuplename);
103  Int_t nentries = (Int_t)tree->GetEntries();
104  //Drawing variable pz with no graphics option.
105  //variable pz stored in array fV1 (see TTree::Draw)
106  tree->Draw("Event","","goff");
107  Int_t *index = new Int_t[nentries];
108  //sort array containing pz in decreasing order
109  //The array index contains the entry numbers in decreasing order
110  TMath::Sort(nentries,tree->GetV1(),index);
111 
112  //open new file to store the sorted Tree
113  //TFile f2("../../test_events_sorted.root","recreate");
114  TFile f2(outputfile,"recreate");
115 
116  //Create an empty clone of the original tree
117  TTree *tsorted = (TTree*)tree->CloneTree(0);
118  for (Int_t i=0;i<nentries;i++) {
119  tree->GetEntry(index[i]);
120  tsorted->Fill();
121  }
122  tsorted->Write();
123  delete [] index;
124 }
int i
Definition: DBlmapReader.cc:9
double f[11][100]

Variable Documentation

const Double_t ptscale[31]

Definition at line 20 of file PtAssignment.h.

Referenced by L1TGMT::bookHistograms(), makeLUT(), and processPrediction().

const std::vector<Double_t> ptScale

Definition at line 32 of file Utilities.cc.

Referenced by CSCTFPtLUT::CSCTFPtLUT(), and CSCTFTrackProducer::produce().

const Double_t twoJets_scale[16]

Definition at line 35 of file Utilities.cc.

const std::vector<Double_t> twoJetsScale

Definition at line 39 of file Utilities.cc.