CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/SimG4CMS/ShowerLibraryProducer/plugins/HcalForwardLibWriter.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    HcalForwardLibWriter
00004 // Class:      HcalForwardLibWriter
00005 // 
00013 //
00014 // Original Author:  Taylan Yetkin,510 1-004,+41227672815,
00015 //         Created:  Thu Feb  9 13:02:38 CET 2012
00016 // $Id: HcalForwardLibWriter.cc,v 1.4 2013/03/21 09:49:05 sunanda Exp $
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   //register shower library products with label
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   //HFShowerPhotonCollection emCollnphot;
00056   //std::vector<HFShowerPhotonCollection> emCollnphot;
00057   //std::vector<int> emCollnPhoton;
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     int momBin = fFileHandle[i].momentum;
00068     energyBin.push_back(momBin);
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   //std::auto_ptr< std::vector<int> > product_em_nphot(new std::vector<int>(emCollnPhoton));
00136   std::auto_ptr<HFShowerPhotonCollection> product_had(new HFShowerPhotonCollection(hadColl));
00137   //std::auto_ptr<std::vector<int> > product_had_nphot(new std::vector<int>(hadCollnPhoton));
00138   iEvent.put(product_info, "HFShowerLibraryEventInfo");   
00139   iEvent.put(product_emsss, "emParticles");
00140   iEvent.put(product_had, "hadParticles");
00141   //iEvent.put(product_em_nphot, "emParticles");
00142   //iEvent.put(product_had_nphot, "hadParticles");
00143 
00144 }
00145 
00146 void HcalForwardLibWriter::beginJob() {}
00147 
00148 void HcalForwardLibWriter::endJob() { }
00149 
00150 void HcalForwardLibWriter::beginRun(edm::Run&, edm::EventSetup const&) { }
00151 
00152 void HcalForwardLibWriter::endRun(edm::Run&, edm::EventSetup const&) { }
00153 
00154 void HcalForwardLibWriter::beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&) { }
00155 
00156 void HcalForwardLibWriter::endLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&) { }
00157 
00158 void HcalForwardLibWriter::readUserData() {
00159   std::cout << " using " <<std::endl;
00160   std::ifstream input(fDataFile.c_str());
00161   if (input.fail()) {
00162     throw cms::Exception("MissingFile")
00163       << "Cannot find file" << fDataFile.c_str();
00164   }
00165   std::string fFileName, fPID;
00166   int fMom;
00167   while (!input.eof()) {
00168     input >> fFileName >> fPID >> fMom;
00169     std::cout << " using " <<  fFileName << " fPID" << fPID << " fMom" << fMom  << std::endl;
00170     if (!input.fail()) {
00171       std::cout << " using " <<  fFileName << " " << fPID << " " << fMom  << std::endl;
00172       FileHandle aFile;
00173       aFile.name = fFileName;
00174       aFile.id = fPID;
00175       aFile.momentum = fMom;
00176       fFileHandle.push_back(aFile);
00177     } else {
00178       input.clear();
00179     }
00180     input.ignore(999, '\n');
00181   }
00182 }
00183 
00184 void HcalForwardLibWriter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00185   edm::ParameterSetDescription desc;
00186   desc.setUnknown();
00187   descriptions.addDefault(desc);
00188 }
00189 //define this as a plug-in
00190 DEFINE_FWK_MODULE(HcalForwardLibWriter);