Go to the documentation of this file.00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020 #include "SimG4CMS/ShowerLibraryProducer/interface/HcalForwardLibWriter.h"
00021
00022 HcalForwardLibWriter::HcalForwardLibWriter(const edm::ParameterSet& iConfig) {
00023
00024 edm::ParameterSet theParms = iConfig.getParameter<edm::ParameterSet> ("HcalForwardLibWriterParameters");
00025 edm::FileInPath fp = theParms.getParameter<edm::FileInPath> ("FileName");
00026 std::string pName = fp.fullPath();
00027 std::cout<<pName<<std::endl;
00028 fDataFile = pName;
00029 readUserData();
00030
00031
00032 produces<HFShowerPhotonCollection> ("emParticles");
00033 produces<std::vector<HFShowerPhotonCollection> > ("emParticlesss");
00034 produces< std::vector<int> > ("emParticles");
00035 produces<HFShowerPhotonCollection> ("hadParticles");
00036 produces< std::vector<int> > ("hadParticles");
00037 produces<std::vector<HFShowerLibraryEventInfo> > ("HFShowerLibraryEventInfo");
00038 }
00039
00040 HcalForwardLibWriter::~HcalForwardLibWriter() {}
00041
00042 void HcalForwardLibWriter::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
00043
00044 std::vector<double> energyBin;
00045 double energyBin2[12] = {10,15,20,35,50,80,100,150,250,350,500,1000};
00046 for (int z = 0; z< 12; ++z) {energyBin.push_back(energyBin2[z]);}
00047
00048 std::vector<HFShowerLibraryEventInfo> Info;
00049 HFShowerPhotonCollection emColl;
00050 std::vector<HFShowerPhotonCollection> emCollsss;
00051 HFShowerPhotonCollection fakeColl;
00052 HFShowerPhoton afakePhoton(1,3,5,8,480);
00053 fakeColl.push_back(afakePhoton);
00054 HFShowerPhotonCollection hadColl;
00055
00056
00057
00058 std::vector<int> emCollnPhoton;
00059 std::vector<int> hadCollnPhoton;
00060
00061 int n = fFileHandle.size();
00062 for (int i = 0; i < n; ++i) {
00063 std::string fn = fFileHandle[i].name;
00064 std::cout<<fn<<std::endl;
00065 std::string particle = fFileHandle[i].id;
00066
00067
00068
00069
00070 fFile = new TFile(fn.c_str(), "READ");
00071 fTree = (TTree*) fFile->FindObjectAny("CherenkovPhotons");
00072 if(!fTree){
00073 throw cms::Exception("NullPointer")
00074 << "Cannot find TTree with name CherenkovPhotons";
00075 }
00076 int nphot = 0;
00077 float x[10000];
00078 float y[10000];
00079 float z[10000];
00080 float t[10000];
00081 float lambda[10000];
00082 int fiberId[10000];
00083 for (int kk = 0; kk < 10000; ++kk) {
00084 x[kk] = 0.;
00085 y[kk] = 0.;
00086 z[kk] = 0.;
00087 t[kk] = 0.;
00088 lambda[kk] = 0.;
00089 fiberId[kk] = 0;
00090 }
00091 fTree->SetBranchAddress("nphot", &nphot);
00092 fTree->SetBranchAddress("x", &x);
00093 fTree->SetBranchAddress("y", &y);
00094 fTree->SetBranchAddress("z", &z);
00095 fTree->SetBranchAddress("t", &t);
00096 fTree->SetBranchAddress("lambda", &lambda);
00097 fTree->SetBranchAddress("fiberId", &fiberId);
00098 int nentry = int(fTree->GetEntries());
00099 std::cout<<"nenetry " << nentry<<std::endl;
00100 if (particle == "electron") {
00101 for (int iev = 0; iev < nentry; iev++) {
00102 fTree->GetEntry(iev);
00103 std::cout<<"nphot "<<nphot<<std::endl;
00104 emCollnPhoton.push_back(nphot);
00105 for (int iph = 0; iph < nphot; ++iph) {
00106 HFShowerPhoton::Point pos(x[iph], y[iph], z[iph]);
00107 HFShowerPhoton aPhoton(pos, t[iph], lambda[iph]);
00108 emColl.push_back(aPhoton);
00109 }
00110 emCollsss.push_back(emColl);
00111 emColl.clear();
00112 }
00113 }
00114 if (particle == "pion") {
00115 for (int iev = 0; iev < nentry; iev++) {
00116 fTree->GetEntry(iev);
00117 hadCollnPhoton.push_back(nphot);
00118 for (int iph = 0; iph < nphot; ++iph) {
00119 HFShowerPhoton::Point pos(x[iph], y[iph], z[iph]);
00120 HFShowerPhoton aPhoton(pos, t[iph], lambda[iph]);
00121 hadColl.push_back(aPhoton);
00122 }
00123 }
00124 }
00125
00126 }
00127
00128 HFShowerLibraryEventInfo aInfo((n/2)*5000,n/2,5000,1,1,energyBin);
00129 Info.push_back(aInfo);
00130
00131 std::auto_ptr< std::vector<HFShowerLibraryEventInfo> > product_info(new std::vector<HFShowerLibraryEventInfo>(Info) );
00132 std::auto_ptr<HFShowerPhotonCollection > product_em(new HFShowerPhotonCollection(fakeColl));
00133 std::auto_ptr<std::vector<HFShowerPhotonCollection> > product_emsss(new std::vector<HFShowerPhotonCollection>(emCollsss));
00134 std::cout<<"em coll size "<<emCollsss.size()<<std::endl;
00135
00136 std::auto_ptr<HFShowerPhotonCollection> product_had(new HFShowerPhotonCollection(hadColl));
00137
00138 iEvent.put(product_info, "HFShowerLibraryEventInfo");
00139 iEvent.put(product_emsss, "emParticles");
00140 iEvent.put(product_had, "hadParticles");
00141
00142
00143
00144 }
00145
00146 void HcalForwardLibWriter::readUserData() {
00147 std::cout << " using " <<std::endl;
00148 std::ifstream input(fDataFile.c_str());
00149 if (input.fail()) {
00150 throw cms::Exception("MissingFile")
00151 << "Cannot find file" << fDataFile.c_str();
00152 }
00153 std::string fFileName, fPID;
00154 int fMom;
00155 while (!input.eof()) {
00156 input >> fFileName >> fPID >> fMom;
00157 std::cout << " using " << fFileName << " fPID" << fPID << " fMom" << fMom << std::endl;
00158 if (!input.fail()) {
00159 std::cout << " using " << fFileName << " " << fPID << " " << fMom << std::endl;
00160 FileHandle aFile;
00161 aFile.name = fFileName;
00162 aFile.id = fPID;
00163 aFile.momentum = fMom;
00164 fFileHandle.push_back(aFile);
00165 } else {
00166 input.clear();
00167 }
00168 input.ignore(999, '\n');
00169 }
00170 }
00171
00172 void HcalForwardLibWriter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00173 edm::ParameterSetDescription desc;
00174 desc.setUnknown();
00175 descriptions.addDefault(desc);
00176 }
00177
00178 DEFINE_FWK_MODULE(HcalForwardLibWriter);