CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions
ZntupleToTreeConverter.cc File Reference
#include <memory>
#include <string>
#include <vector>
#include <sstream>
#include <fstream>
#include <iostream>
#include <TH1F.h>
#include <TROOT.h>
#include <TFile.h>
#include <TSystem.h>
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/FWLite/interface/Event.h"
#include "DataFormats/PatCandidates/interface/Muon.h"
#include "FWCore/FWLite/interface/FWLiteEnabler.h"
#include "DataFormats/FWLite/interface/Handle.h"
#include "PhysicsTools/FWLite/interface/TFileService.h"
#include "MuonAnalysis/MomentumScaleCalibration/interface/RootTreeHandler.h"

Go to the source code of this file.

Functions

lorentzVector fromPtEtaPhiToPxPyPz (const double *ptEtaPhiE)
 
int main (int argc, char *argv[])
 

Function Documentation

lorentzVector fromPtEtaPhiToPxPyPz ( const double *  ptEtaPhiE)

Definition at line 24 of file ZntupleToTreeConverter.cc.

References funct::cos(), funct::exp(), fastsim::Constants::muMass, funct::sin(), mathSSE::sqrt(), and createJobs::tmp.

24  {
25  double muMass = 0.105658;
26  double px = ptEtaPhiE[0] * cos(ptEtaPhiE[2]);
27  double py = ptEtaPhiE[0] * sin(ptEtaPhiE[2]);
28  double tmp = 2 * atan(exp(-ptEtaPhiE[1]));
29  double pz = ptEtaPhiE[0] * cos(tmp) / sin(tmp);
30  double E = sqrt(px * px + py * py + pz * pz + muMass * muMass);
31 
32  // lorentzVector corrMu(px,py,pz,E);
33  // To fix memory leaks, this is to be substituted with
34  // std::unique_ptr<lorentzVector> corrMu(new lorentzVector(px, py, pz, E));
35 
36  return lorentzVector(px, py, pz, E);
37 }
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
static double constexpr muMass
Muon mass [GeV].
Definition: Constants.h:14
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
T sqrt(T t)
Definition: SSEVec.h:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
tmp
align.sh
Definition: createJobs.py:716
int main ( int  argc,
char *  argv[] 
)

===============================================================================================================================================================================================


variant2: for each run define phi-averaged A for normalization channel (Dref,16) and then, divide Rijk on it, i.e. get RRijk

eta=27

eta=25

eta=23

eta=22

eta=21

eta=26

eta=24

eta=19

eta=17

eta=25

eta=23

eta=22

eta=21

eta=26

eta=24

eta=20

eta=19

eta=18

eta=27 L1=1

eta=25 L1=1

eta=23 L1=1

eta=22 L1=1

eta=21 L1=1

eta=29 L1=1

eta=26 L1=1

eta=24 L1=1

eta=20 L1=1

eta=19 L1=1

eta=18 L1=1

eta=17 L1=1

eta=28 L7=1

eta=27 L7=1

eta=25 L7=1

eta=23 L7=1

eta=22 L7=1

eta=21 L7=1

eta=26 L7=1

eta=24 L7=1

eta=20 L7=1

eta=19 L7=1

eta=18 L7=1

eta=17 L7=1

eta=27

eta=25

eta=23

eta=22

eta=21

eta=26

eta=24

eta=19

eta=17

eta=25

eta=23

eta=22

eta=21

eta=26

eta=24

eta=20

eta=19

eta=18

eta=27 L1=1

eta=25 L1=1

eta=23 L1=1

eta=22 L1=1

eta=21 L1=1

eta=26 L1=1

eta=24 L1=1

eta=20 L1=1

eta=19 L1=1

eta=18 L1=1

eta=17 L1=1

eta=28 L7=1

eta=27 L7=1

eta=25 L7=1

eta=23 L7=1

eta=22 L7=1

eta=21 L7=1

eta=26 L7=1

eta=24 L7=1

eta=20 L7=1

eta=19 L7=1

eta=18 L7=1

eta=17 L7=1

eta=27

eta=28

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

RBX:

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

RBX:

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

RBX:

Prepare maps of good/bad channels:

Prepare maps of good/bad channels:

Prepare maps of good/bad channels:

Prepare maps of good/bad channels:

Definition at line 39 of file ZntupleToTreeConverter.cc.

References fwlite::Event::atEnd(), gather_cfg::cout, FWLiteEnabler::enable(), ev, beamvalidation::exit(), MillePedeFileConverter_cfg::fileName, fromPtEtaPhiToPxPyPz(), fwlite::Handle< T >::getByLabel(), mps_fire::i, iEvent, fwlite::Handle< T >::isValid(), TFileDirectory::make(), TFileDirectory::mkdir(), AlCaHLTBitMon_QueryRunRegistry::string, TrackerOfflineValidation_Standalone_cff::TFileService, and fwlite::Event::toBegin().

39  {
40  if (argc != 2) {
41  std::cout << "Please provide the name of the file with file: or rfio: as needed" << std::endl;
42  exit(1);
43  }
45  if (fileName.find("file:") != 0 && fileName.find("rfio:") != 0) {
46  std::cout << "Please provide the name of the file with file: or rfio: as needed" << std::endl;
47  exit(1);
48  }
49 
50  // ----------------------------------------------------------------------
51  // First Part:
52  //
53  // * enable FWLite
54  // * book the histograms of interest
55  // * open the input file
56  // ----------------------------------------------------------------------
57 
58  // load framework libraries
59  gSystem->Load("libFWCoreFWLite");
61 
62  // book a set of histograms
63  fwlite::TFileService fs = fwlite::TFileService("analyzeBasics.root");
64  TFileDirectory theDir = fs.mkdir("analyzeBasic");
65  TH1F* muonPt_ = theDir.make<TH1F>("muonPt", "pt", 100, 0., 300.);
66  TH1F* muonEta_ = theDir.make<TH1F>("muonEta", "eta", 100, -3., 3.);
67  TH1F* muonPhi_ = theDir.make<TH1F>("muonPhi", "phi", 100, -5., 5.);
68 
69  // open input file (can be located on castor)
70  TFile* inFile = TFile::Open(fileName.c_str());
71 
72  // TFile* inFile = TFile::Open("rfio:/castor/cern.ch/user/f/fabozzi/36XSkimData/run_139791-140159/NtupleLoose_139791-140159_v2.root");
73  // TFile* inFile = TFile::Open("rfio:/castor/cern.ch/user/f/fabozzi/36XSkimData/run_140160-140182/NtupleLoose_140160-140182.root");
74  // TFile* inFile = TFile::Open("rfio:/castor/cern.ch/user/f/fabozzi/36XSkimData/run_140183-140399/NtupleLoose_140183-140399.root");
75  // TFile* inFile = TFile::Open("rfio:/castor/cern.ch/user/d/degrutto/36XSkimData/run_140440-141961/NtupleLoose_140440-141961.root");
76  // TFile* inFile = TFile::Open("rfio:/castor/cern.ch/user/d/degrutto/36XSkimData/run_142035-142664/NtupleLoose_142035-142664.root");
77 
78  // ----------------------------------------------------------------------
79  // Second Part:
80  //
81  // * loop the events in the input file
82  // * receive the collections of interest via fwlite::Handle
83  // * fill the histograms
84  // * after the loop close the input file
85  // ----------------------------------------------------------------------
86 
87  // Create the RootTreeHandler to save the events in the root tree
88  RootTreeHandler treeHandler;
89  // MuonPairVector pairVector;
90  std::vector<MuonPair> pairVector;
91 
92  // loop the events
93  unsigned int iEvent = 0;
94  fwlite::Event ev(inFile);
95  for (ev.toBegin(); !ev.atEnd(); ++ev, ++iEvent) {
96  // simple event counter
97  if (iEvent > 0 && iEvent % 100 == 0) {
98  std::cout << " processing event: " << iEvent << std::endl;
99  }
100 
101  // Handle to the muon collection
108  muon1pt.getByLabel(ev, "goodZToMuMuEdmNtupleLoose", "zGoldenDau1Pt");
109  muon1eta.getByLabel(ev, "goodZToMuMuEdmNtupleLoose", "zGoldenDau1Eta");
110  muon1phi.getByLabel(ev, "goodZToMuMuEdmNtupleLoose", "zGoldenDau1Phi");
111  muon2pt.getByLabel(ev, "goodZToMuMuEdmNtupleLoose", "zGoldenDau2Pt");
112  muon2eta.getByLabel(ev, "goodZToMuMuEdmNtupleLoose", "zGoldenDau2Eta");
113  muon2phi.getByLabel(ev, "goodZToMuMuEdmNtupleLoose", "zGoldenDau2Phi");
114 
115  if (!muon1pt.isValid())
116  continue;
117  if (!muon1eta.isValid())
118  continue;
119  if (!muon1phi.isValid())
120  continue;
121  if (!muon2pt.isValid())
122  continue;
123  if (!muon2eta.isValid())
124  continue;
125  if (!muon2phi.isValid())
126  continue;
127  // std::cout << "muon1pt = " << muon1pt->size() << std::endl;
128 
129  // loop muon collection and fill histograms
130  if (muon1pt->size() != muon2pt->size()) {
131  std::cout << "Error: size of muon1 and muon2 is different. Skipping event" << std::endl;
132  continue;
133  }
134  for (unsigned i = 0; i < muon1pt->size(); ++i) {
135  muonPt_->Fill((*muon1pt)[i]);
136  muonEta_->Fill((*muon1eta)[i]);
137  muonPhi_->Fill((*muon1phi)[i]);
138  muonPt_->Fill((*muon2pt)[i]);
139  muonEta_->Fill((*muon2eta)[i]);
140  muonPhi_->Fill((*muon2phi)[i]);
141 
142  double muon1[3] = {(*muon1pt)[i], (*muon1eta)[i], (*muon1phi)[i]};
143  double muon2[3] = {(*muon2pt)[i], (*muon2eta)[i], (*muon2phi)[i]};
144 
145  // pairVector.push_back( std::make_pair( fromPtEtaPhiToPxPyPz(muon1), fromPtEtaPhiToPxPyPz(muon2) ) );
146  pairVector.push_back(
147  MuonPair(fromPtEtaPhiToPxPyPz(muon1), fromPtEtaPhiToPxPyPz(muon2), MuScleFitEvent(0, 0, 0, 0, 0, 0)));
148  }
149  }
150  size_t namePos = fileName.find_last_of('/');
151  treeHandler.writeTree(("tree_" + fileName.substr(namePos + 1, fileName.size())).c_str(), &pairVector);
152 
153  // close input file
154  inFile->Close();
155 
156  // ----------------------------------------------------------------------
157  // Third Part:
158  //
159  // * never forget to free the memory of objects you created
160  // ----------------------------------------------------------------------
161 
162  // in this example there is nothing to do
163 
164  // that's it!
165  return 0;
166 }
bool isValid() const
Definition: Handle.h:60
bool ev
lorentzVector fromPtEtaPhiToPxPyPz(const double *ptEtaPhiE)
Definition: TreeDump.cc:24
int iEvent
Definition: GenABIO.cc:224
static void enable()
enable automatic library loading
T * make(const Args &...args) const
make new ROOT object
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
tuple argc
Definition: dir2webdir.py:39
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=nullptr, const char *iProcessLabel=nullptr)
Definition: Handle.h:100
tuple cout
Definition: gather_cfg.py:144