CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalForwardLibWriter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HcalForwardLibWriter
4 // Class: HcalForwardLibWriter
5 //
13 //
14 // Original Author: Taylan Yetkin,510 1-004,+41227672815,
15 // Created: Thu Feb 9 13:02:38 CET 2012
16 // $Id: HcalForwardLibWriter.cc,v 1.5 2013/05/25 17:03:42 chrjones Exp $
17 //
18 //
19 
21 
23 
24  edm::ParameterSet theParms = iConfig.getParameter<edm::ParameterSet> ("HcalForwardLibWriterParameters");
25  edm::FileInPath fp = theParms.getParameter<edm::FileInPath> ("FileName");
26  std::string pName = fp.fullPath();
27  std::cout<<pName<<std::endl;
28  fDataFile = pName;
29  readUserData();
30 
31  //register shower library products with label
32  produces<HFShowerPhotonCollection> ("emParticles");
33  produces<std::vector<HFShowerPhotonCollection> > ("emParticlesss");
34  produces< std::vector<int> > ("emParticles");
35  produces<HFShowerPhotonCollection> ("hadParticles");
36  produces< std::vector<int> > ("hadParticles");
37  produces<std::vector<HFShowerLibraryEventInfo> > ("HFShowerLibraryEventInfo");
38 }
39 
41 
43 
44  std::vector<double> energyBin;
45  double energyBin2[12] = {10,15,20,35,50,80,100,150,250,350,500,1000};
46  for (int z = 0; z< 12; ++z) {energyBin.push_back(energyBin2[z]);}
47 
48  std::vector<HFShowerLibraryEventInfo> Info;
50  std::vector<HFShowerPhotonCollection> emCollsss;
51  HFShowerPhotonCollection fakeColl;
52  HFShowerPhoton afakePhoton(1,3,5,8,480);
53  fakeColl.push_back(afakePhoton);
55  //HFShowerPhotonCollection emCollnphot;
56  //std::vector<HFShowerPhotonCollection> emCollnphot;
57  //std::vector<int> emCollnPhoton;
58  std::vector<int> emCollnPhoton;
59  std::vector<int> hadCollnPhoton;
60 
61  int n = fFileHandle.size();
62  for (int i = 0; i < n; ++i) {
63  std::string fn = fFileHandle[i].name;
64  std::cout<<fn<<std::endl;
65  std::string particle = fFileHandle[i].id;
66  /*
67  int momBin = fFileHandle[i].momentum;
68  energyBin.push_back(momBin);
69  */
70  fFile = new TFile(fn.c_str(), "READ");
71  fTree = (TTree*) fFile->FindObjectAny("CherenkovPhotons");
72  if(!fTree){
73  throw cms::Exception("NullPointer")
74  << "Cannot find TTree with name CherenkovPhotons";
75  }
76  int nphot = 0;
77  float x[10000];
78  float y[10000];
79  float z[10000];
80  float t[10000];
81  float lambda[10000];
82  int fiberId[10000];
83  for (int kk = 0; kk < 10000; ++kk) {
84  x[kk] = 0.;
85  y[kk] = 0.;
86  z[kk] = 0.;
87  t[kk] = 0.;
88  lambda[kk] = 0.;
89  fiberId[kk] = 0;
90  }
91  fTree->SetBranchAddress("nphot", &nphot);
92  fTree->SetBranchAddress("x", &x);
93  fTree->SetBranchAddress("y", &y);
94  fTree->SetBranchAddress("z", &z);
95  fTree->SetBranchAddress("t", &t);
96  fTree->SetBranchAddress("lambda", &lambda);
97  fTree->SetBranchAddress("fiberId", &fiberId);
98  int nentry = int(fTree->GetEntries());
99  std::cout<<"nenetry " << nentry<<std::endl;
100  if (particle == "electron") {
101  for (int iev = 0; iev < nentry; iev++) {
102  fTree->GetEntry(iev);
103  std::cout<<"nphot "<<nphot<<std::endl;
104  emCollnPhoton.push_back(nphot);
105  for (int iph = 0; iph < nphot; ++iph) {
106  HFShowerPhoton::Point pos(x[iph], y[iph], z[iph]);
107  HFShowerPhoton aPhoton(pos, t[iph], lambda[iph]);
108  emColl.push_back(aPhoton);
109  }
110  emCollsss.push_back(emColl);
111  emColl.clear();
112  }
113  }
114  if (particle == "pion") {
115  for (int iev = 0; iev < nentry; iev++) {
116  fTree->GetEntry(iev);
117  hadCollnPhoton.push_back(nphot);
118  for (int iph = 0; iph < nphot; ++iph) {
119  HFShowerPhoton::Point pos(x[iph], y[iph], z[iph]);
120  HFShowerPhoton aPhoton(pos, t[iph], lambda[iph]);
121  hadColl.push_back(aPhoton);
122  }
123  }
124  }
125 
126  }
127 
128  HFShowerLibraryEventInfo aInfo((n/2)*5000,n/2,5000,1,1,energyBin);
129  Info.push_back(aInfo);
130 
131  std::auto_ptr< std::vector<HFShowerLibraryEventInfo> > product_info(new std::vector<HFShowerLibraryEventInfo>(Info) );
132  std::auto_ptr<HFShowerPhotonCollection > product_em(new HFShowerPhotonCollection(fakeColl));
133  std::auto_ptr<std::vector<HFShowerPhotonCollection> > product_emsss(new std::vector<HFShowerPhotonCollection>(emCollsss));
134  std::cout<<"em coll size "<<emCollsss.size()<<std::endl;
135  //std::auto_ptr< std::vector<int> > product_em_nphot(new std::vector<int>(emCollnPhoton));
136  std::auto_ptr<HFShowerPhotonCollection> product_had(new HFShowerPhotonCollection(hadColl));
137  //std::auto_ptr<std::vector<int> > product_had_nphot(new std::vector<int>(hadCollnPhoton));
138  iEvent.put(product_info, "HFShowerLibraryEventInfo");
139  iEvent.put(product_emsss, "emParticles");
140  iEvent.put(product_had, "hadParticles");
141  //iEvent.put(product_em_nphot, "emParticles");
142  //iEvent.put(product_had_nphot, "hadParticles");
143 
144 }
145 
147  std::cout << " using " <<std::endl;
148  std::ifstream input(fDataFile.c_str());
149  if (input.fail()) {
150  throw cms::Exception("MissingFile")
151  << "Cannot find file" << fDataFile.c_str();
152  }
153  std::string fFileName, fPID;
154  int fMom;
155  while (!input.eof()) {
156  input >> fFileName >> fPID >> fMom;
157  std::cout << " using " << fFileName << " fPID" << fPID << " fMom" << fMom << std::endl;
158  if (!input.fail()) {
159  std::cout << " using " << fFileName << " " << fPID << " " << fMom << std::endl;
160  FileHandle aFile;
161  aFile.name = fFileName;
162  aFile.id = fPID;
163  aFile.momentum = fMom;
164  fFileHandle.push_back(aFile);
165  } else {
166  input.clear();
167  }
168  input.ignore(999, '\n');
169  }
170 }
171 
174  desc.setUnknown();
175  descriptions.addDefault(desc);
176 }
177 //define this as a plug-in
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
math::XYZPointF Point
point in the space
std::vector< FileHandle > fFileHandle
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void produce(edm::Event &, const edm::EventSetup &) override
float float float z
int iEvent
Definition: GenABIO.cc:243
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< HFShowerPhoton > HFShowerPhotonCollection
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
HcalForwardLibWriter(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
tuple cout
Definition: gather_cfg.py:121
Definition: DDAxes.h:10