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 85 of file Utilities.cc.

86 {
87  TChain chain(ntuplename);
88  chain.Add(filestomerge);
89  chain.Merge(outputfile);
90 }
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 emtf::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  // Fix terrible predictions
52  if(BDTPt < 0) BDTPt = PrelimFit;
53  if(BDTPt > 250) BDTPt = PrelimFit;
54 
55  float BDTPt1 = BDTPt;
56  float scaleF = 1.0;
57 
58  // Scale based upon quality
59  if (Quality == 3) scaleF = 1.15;
60  if (Quality == 2) scaleF = 1.3;
61  if (Quality == 1) scaleF = 1.7;
62 
63  BDTPt1 = scaleF*BDTPt1;
64 
65  // Discretize based upon ptscale
66  for (int pts=0; pts<31; pts++)
67  {
68  if (ptscale[pts]<=BDTPt1 && ptscale[pts+1]>BDTPt1)
69  {
70  BDTPt1 = ptscale[pts];
71  break;
72  }
73  }
74 
75  if (BDTPt1 > 140) BDTPt1 = 140;
76  if (BDTPt1 < 0) BDTPt1 = 0;
77 
78  return BDTPt1;
79 }
const Double_t ptscale[31]
Definition: Utilities.cc:26
static const double pts[33]
Definition: Constants.h:30
template<class bidiiter >
bidiiter shuffle ( bidiiter  begin,
bidiiter  end,
size_t  num_random 
)

Definition at line 26 of file Utilities.h.

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

Referenced by L1TForest::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 96 of file Utilities.cc.

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

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

Variable Documentation

const Double_t ptscale[31]

Definition at line 26 of file Utilities.cc.

Referenced by L1TGMT::bookHistograms(), 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 40 of file Utilities.cc.