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 //
17 //
18 
20 
22 
23  edm::ParameterSet theParms = iConfig.getParameter<edm::ParameterSet> ("HcalForwardLibWriterParameters");
24  edm::FileInPath fp = theParms.getParameter<edm::FileInPath> ("FileName");
25  std::string pName = fp.fullPath();
26  std::cout<<pName<<std::endl;
27  fDataFile = pName;
28  readUserData();
29 
30  //register shower library products with label
31  produces<HFShowerPhotonCollection> ("emParticles");
32  produces<std::vector<HFShowerPhotonCollection> > ("emParticlesss");
33  produces< std::vector<int> > ("emParticles");
34  produces<HFShowerPhotonCollection> ("hadParticles");
35  produces< std::vector<int> > ("hadParticles");
36  produces<std::vector<HFShowerLibraryEventInfo> > ("HFShowerLibraryEventInfo");
37 }
38 
40 
42 
43  std::vector<double> energyBin;
44  double energyBin2[12] = {10,15,20,35,50,80,100,150,250,350,500,1000};
45  for (int z = 0; z< 12; ++z) {energyBin.push_back(energyBin2[z]);}
46 
47  std::vector<HFShowerLibraryEventInfo> Info;
49  std::vector<HFShowerPhotonCollection> emCollsss;
50  HFShowerPhotonCollection fakeColl;
51  HFShowerPhoton afakePhoton(1,3,5,8,480);
52  fakeColl.push_back(afakePhoton);
54  //HFShowerPhotonCollection emCollnphot;
55  //std::vector<HFShowerPhotonCollection> emCollnphot;
56  //std::vector<int> emCollnPhoton;
57  std::vector<int> emCollnPhoton;
58  std::vector<int> hadCollnPhoton;
59 
60  int n = fFileHandle.size();
61  for (int i = 0; i < n; ++i) {
62  std::string fn = fFileHandle[i].name;
63  std::cout<<fn<<std::endl;
64  std::string particle = fFileHandle[i].id;
65  /*
66  int momBin = fFileHandle[i].momentum;
67  energyBin.push_back(momBin);
68  */
69  fFile = new TFile(fn.c_str(), "READ");
70  fTree = (TTree*) fFile->FindObjectAny("CherenkovPhotons");
71  if(!fTree){
72  throw cms::Exception("NullPointer")
73  << "Cannot find TTree with name CherenkovPhotons";
74  }
75  int nphot = 0;
76  float x[10000];
77  float y[10000];
78  float z[10000];
79  float t[10000];
80  float lambda[10000];
81  int fiberId[10000];
82  for (int kk = 0; kk < 10000; ++kk) {
83  x[kk] = 0.;
84  y[kk] = 0.;
85  z[kk] = 0.;
86  t[kk] = 0.;
87  lambda[kk] = 0.;
88  fiberId[kk] = 0;
89  }
90  fTree->SetBranchAddress("nphot", &nphot);
91  fTree->SetBranchAddress("x", &x);
92  fTree->SetBranchAddress("y", &y);
93  fTree->SetBranchAddress("z", &z);
94  fTree->SetBranchAddress("t", &t);
95  fTree->SetBranchAddress("lambda", &lambda);
96  fTree->SetBranchAddress("fiberId", &fiberId);
97  int nentry = int(fTree->GetEntries());
98  std::cout<<"nenetry " << nentry<<std::endl;
99  if (particle == "electron") {
100  for (int iev = 0; iev < nentry; iev++) {
101  fTree->GetEntry(iev);
102  std::cout<<"nphot "<<nphot<<std::endl;
103  emCollnPhoton.push_back(nphot);
104  for (int iph = 0; iph < nphot; ++iph) {
105  HFShowerPhoton::Point pos(x[iph], y[iph], z[iph]);
106  HFShowerPhoton aPhoton(pos, t[iph], lambda[iph]);
107  emColl.push_back(aPhoton);
108  }
109  emCollsss.push_back(emColl);
110  emColl.clear();
111  }
112  }
113  if (particle == "pion") {
114  for (int iev = 0; iev < nentry; iev++) {
115  fTree->GetEntry(iev);
116  hadCollnPhoton.push_back(nphot);
117  for (int iph = 0; iph < nphot; ++iph) {
118  HFShowerPhoton::Point pos(x[iph], y[iph], z[iph]);
119  HFShowerPhoton aPhoton(pos, t[iph], lambda[iph]);
120  hadColl.push_back(aPhoton);
121  }
122  }
123  }
124 
125  }
126 
127  HFShowerLibraryEventInfo aInfo((n/2)*5000,n/2,5000,1,1,energyBin);
128  Info.push_back(aInfo);
129 
130  std::auto_ptr< std::vector<HFShowerLibraryEventInfo> > product_info(new std::vector<HFShowerLibraryEventInfo>(Info) );
131  std::auto_ptr<HFShowerPhotonCollection > product_em(new HFShowerPhotonCollection(fakeColl));
132  std::auto_ptr<std::vector<HFShowerPhotonCollection> > product_emsss(new std::vector<HFShowerPhotonCollection>(emCollsss));
133  std::cout<<"em coll size "<<emCollsss.size()<<std::endl;
134  //std::auto_ptr< std::vector<int> > product_em_nphot(new std::vector<int>(emCollnPhoton));
135  std::auto_ptr<HFShowerPhotonCollection> product_had(new HFShowerPhotonCollection(hadColl));
136  //std::auto_ptr<std::vector<int> > product_had_nphot(new std::vector<int>(hadCollnPhoton));
137  iEvent.put(product_info, "HFShowerLibraryEventInfo");
138  iEvent.put(product_emsss, "emParticles");
139  iEvent.put(product_had, "hadParticles");
140  //iEvent.put(product_em_nphot, "emParticles");
141  //iEvent.put(product_had_nphot, "hadParticles");
142 
143 }
144 
146  std::cout << " using " <<std::endl;
147  std::ifstream input(fDataFile.c_str());
148  if (input.fail()) {
149  throw cms::Exception("MissingFile")
150  << "Cannot find file" << fDataFile.c_str();
151  }
152  std::string fFileName, fPID;
153  int fMom;
154  while (!input.eof()) {
155  input >> fFileName >> fPID >> fMom;
156  std::cout << " using " << fFileName << " fPID" << fPID << " fMom" << fMom << std::endl;
157  if (!input.fail()) {
158  std::cout << " using " << fFileName << " " << fPID << " " << fMom << std::endl;
159  FileHandle aFile;
160  aFile.name = fFileName;
161  aFile.id = fPID;
162  aFile.momentum = fMom;
163  fFileHandle.push_back(aFile);
164  } else {
165  input.clear();
166  }
167  input.ignore(999, '\n');
168  }
169 }
170 
173  desc.setUnknown();
174  descriptions.addDefault(desc);
175 }
176 //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
static std::string const input
Definition: EdmProvDump.cc:43
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< HFShowerPhoton > HFShowerPhotonCollection
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
HcalForwardLibWriter(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
tuple cout
Definition: gather_cfg.py:121
Definition: DDAxes.h:10