CMS 3D CMS Logo

HcalForwardLibWriter.cc
Go to the documentation of this file.
2 
3 #include "TFile.h"
4 #include "TTree.h"
5 
7  edm::ParameterSet theParms = iConfig.getParameter<edm::ParameterSet>("HcalForwardLibWriterParameters");
8  edm::FileInPath fp = theParms.getParameter<edm::FileInPath>("FileName");
9  nbins = theParms.getParameter<int>("Nbins");
10  nshowers = theParms.getParameter<int>("Nshowers");
11  bsize = theParms.getParameter<int>("BufSize");
12  splitlevel = theParms.getParameter<int>("SplitLevel");
13  compressionAlgo = theParms.getParameter<int>("CompressionAlgo");
14  compressionLevel = theParms.getParameter<int>("CompressionLevel");
15 
16  std::string pName = fp.fullPath();
17  if (pName.find('.') == 0)
18  pName.erase(0, 2);
19  theDataFile = pName;
20  readUserData();
21 
22  fs->file().cd();
23  fs->file().SetCompressionAlgorithm(compressionAlgo);
24  fs->file().SetCompressionLevel(compressionLevel);
25 
26  LibTree = new TTree("HFSimHits", "HFSimHits");
27 
28  //https://root.cern/root/html534/TTree.html
29  // TBranch*Branch(const char* name, const char* classname, void** obj, Int_t bufsize = 32000, Int_t splitlevel = 99)
30  LibTree->Branch("emParticles", "HFShowerPhotons-emParticles", &emColl, bsize, splitlevel);
31  LibTree->Branch("hadParticles", "HFShowerPhotons-hadParticles", &hadColl, bsize, splitlevel);
32 }
33 
35 
37  // Event info
38  std::vector<double> en;
39  double momBin[16] = {2, 3, 5, 7, 10, 15, 20, 30, 50, 75, 100, 150, 250, 350, 500, 1000};
40  en.reserve(nbins);
41  for (int i = 0; i < nbins; ++i)
42  en.push_back(momBin[i]);
43 
44  //shower photons
45  int n = theFileHandle.size();
46  // cycle over files ++++++++++++++++++++++++++++++++++++++++++++++++++++
47  for (int i = 0; i < n; ++i) {
48  std::string fn = theFileHandle[i].name;
49  std::string particle = theFileHandle[i].id;
50 
51  // std::cout << "*** Input file " << i << " " << fn << std::endl;
52 
53  TFile* theFile = new TFile(fn.c_str(), "READ");
54  TTree* theTree = (TTree*)gDirectory->Get("g4SimHits/CherenkovPhotons");
55  int nphot = 0;
56 
57  const int size = 10000;
58  if (nshowers > size) {
59  edm::LogError("HcalForwardLibWriter") << "Too big Nshowers number";
60  return;
61  }
62 
63  float x[size] = {0.};
64  float y[size] = {0.};
65  float z[size] = {0.};
66  float t[size] = {0.};
67  float lambda[size] = {0.};
68  int fiberId[size] = {0};
69  float primZ; // added
70 
71  theTree->SetBranchAddress("nphot", &nphot);
72  theTree->SetBranchAddress("x", &x);
73  theTree->SetBranchAddress("y", &y);
74  theTree->SetBranchAddress("z", &z);
75  theTree->SetBranchAddress("t", &t);
76  theTree->SetBranchAddress("lambda", &lambda);
77  theTree->SetBranchAddress("fiberId", &fiberId);
78  theTree->SetBranchAddress("primZ", &primZ); // added
79  int nentries = int(theTree->GetEntries());
80  int ngood = 0;
81  int nbytes = 0;
82  // cycle over showers ====================================================
83  for (int iev = 0; iev < nentries; iev++) {
84  nbytes += theTree->GetEntry(iev);
85  if (primZ < 990.)
86  continue; // exclude showers with interactions in front of HF (1m of air)
87  ngood++;
88  if (ngood > nshowers)
89  continue;
90  if (particle == "electron") {
91  emColl.clear();
92  } else {
93  hadColl.clear();
94  }
95  float nphot_long = 0;
96  float nphot_short = 0;
97  // cycle over photons in shower -------------------------------------------
98  for (int iph = 0; iph < nphot; ++iph) {
99  if (fiberId[iph] == 1) {
100  nphot_long++;
101  } else {
102  nphot_short++;
103  z[iph] = -z[iph];
104  }
105 
106  HFShowerPhoton::Point pos(x[iph], y[iph], z[iph]);
107  HFShowerPhoton aPhoton(pos, t[iph], lambda[iph]);
108  if (particle == "electron") {
109  emColl.push_back(aPhoton);
110  } else {
111  hadColl.push_back(aPhoton);
112  }
113  }
114  // end of cycle over photons in shower -------------------------------------------
115 
116  // if(iev>0) LibTree->SetBranchStatus("HFShowerLibInfo",0);
117  if (particle == "electron") {
118  LibTree->SetBranchStatus("hadParticles", false);
119  } else {
120  LibTree->SetBranchStatus("emParticles", false);
121  }
122  LibTree->Fill();
123  if (particle == "electron") {
124  emColl.clear();
125  } else {
126  hadColl.clear();
127  }
128  }
129  // end of cycle over showers ====================================================
130  theFile->Close();
131  }
132  // end of cycle over files ++++++++++++++++++++++++++++++++++++++++++++++++++++
133 }
134 
136 
138  fs->file().cd();
139  LibTree->Write();
140  LibTree->Print();
141 }
142 
144  std::ifstream input(theDataFile.c_str());
145  if (input.fail()) {
146  return 0;
147  }
148  std::string theFileName, thePID;
149  int mom;
150  int k = 0;
151  while (!input.eof()) {
152  input >> theFileName >> thePID >> mom;
153  if (!input.fail()) {
154  FileHandle aFile;
155  aFile.name = theFileName;
156  aFile.id = thePID;
157  aFile.momentum = mom;
158  theFileHandle.push_back(aFile);
159  ++k;
160  } else {
161  input.clear();
162  }
163  input.ignore(999, '\n');
164  }
165  return k;
166 }
167 //define this as a plug-in
DDAxes::y
mps_fire.i
i
Definition: mps_fire.py:428
input
static const std::string input
Definition: EdmProvDump.cc:48
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
iev
const HitContainer *__restrict__ const TkSoA *__restrict__ const Quality *__restrict__ const CAHitNtupletGeneratorKernelsGPU::HitToTuple *__restrict__ int32_t int iev
Definition: CAHitNtupletGeneratorKernelsImpl.h:862
HcalForwardLibWriter::hadColl
HFShowerPhotonCollection hadColl
Definition: HcalForwardLibWriter.h:60
HcalForwardLibWriter::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: HcalForwardLibWriter.cc:36
HcalForwardLibWriter::HcalForwardLibWriter
HcalForwardLibWriter(const edm::ParameterSet &)
Definition: HcalForwardLibWriter.cc:6
TFileService::file
TFile & file() const
return opened TFile
Definition: TFileService.h:37
pos
Definition: PixelAliasList.h:18
personalPlayback.fp
fp
Definition: personalPlayback.py:523
HcalForwardLibWriter::endJob
void endJob() override
Definition: HcalForwardLibWriter.cc:137
HcalForwardLibWriter::splitlevel
int splitlevel
Definition: HcalForwardLibWriter.h:45
HcalForwardLibWriter::compressionLevel
int compressionLevel
Definition: HcalForwardLibWriter.h:47
DDAxes::x
HcalForwardLibWriter::compressionAlgo
int compressionAlgo
Definition: HcalForwardLibWriter.h:46
HcalForwardLibWriter::theFile
TFile * theFile
Definition: HcalForwardLibWriter.h:49
HcalForwardLibWriter::theTree
TTree * theTree
Definition: HcalForwardLibWriter.h:50
edm::FileInPath
Definition: FileInPath.h:61
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
DDAxes::z
HcalForwardLibWriter::theFileHandle
std::vector< FileHandle > theFileHandle
Definition: HcalForwardLibWriter.h:56
dqmdumpme.k
k
Definition: dqmdumpme.py:60
HcalForwardLibWriter::LibTree
TTree * LibTree
Definition: HcalForwardLibWriter.h:52
HcalForwardLibWriter
Definition: HcalForwardLibWriter.h:27
HFShowerPhoton::Point
math::XYZPointF Point
point in the space
Definition: HFShowerPhoton.h:16
edm::ParameterSet
Definition: ParameterSet.h:47
HcalForwardLibWriter::FileHandle::name
std::string name
Definition: HcalForwardLibWriter.h:30
HcalForwardLibWriter::FileHandle::momentum
int momentum
Definition: HcalForwardLibWriter.h:32
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:58
HcalForwardLibWriter::nbins
int nbins
Definition: HcalForwardLibWriter.h:42
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
HcalForwardLibWriter.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HcalForwardLibWriter::theDataFile
std::string theDataFile
Definition: HcalForwardLibWriter.h:55
HcalForwardLibWriter::~HcalForwardLibWriter
~HcalForwardLibWriter() override
Definition: HcalForwardLibWriter.cc:34
HcalForwardLibWriter::readUserData
int readUserData()
Definition: HcalForwardLibWriter.cc:143
HcalForwardLibWriter::bsize
int bsize
Definition: HcalForwardLibWriter.h:44
HFShowerPhoton
Definition: HFShowerPhoton.h:13
HcalForwardLibWriter::beginJob
void beginJob() override
Definition: HcalForwardLibWriter.cc:135
personalPlayback.fn
fn
Definition: personalPlayback.py:515
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
HcalForwardLibWriter::FileHandle
Definition: HcalForwardLibWriter.h:29
HcalForwardLibWriter::emColl
HFShowerPhotonCollection emColl
Definition: HcalForwardLibWriter.h:59
HcalForwardLibWriter::fs
edm::Service< TFileService > fs
Definition: HcalForwardLibWriter.h:54
edm::Event
Definition: Event.h:73
HcalForwardLibWriter::FileHandle::id
std::string id
Definition: HcalForwardLibWriter.h:31
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
HcalForwardLibWriter::nshowers
int nshowers
Definition: HcalForwardLibWriter.h:43
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443