CMS 3D CMS Logo

TPGntupler.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    TPGntupler
00004 // Class:      TPGntupler
00005 // 
00013 //
00014 // Original Author:  Adam Aurisano
00015 //         Created:  Thur Jan 18 2007
00016 // $Id: TPGntupler.cc,v 1.5 2007/04/24 12:44:27 aurisano Exp $
00017 //
00018 //
00019 
00020 #include "TPGntupler.h"
00021 #include "CalibCalorimetry/CaloTPG/src/CaloTPGTranscoderULUT.h"
00022 #include "TMath.h"
00023 #include <fstream>
00024 
00025 using namespace std;
00026 using namespace edm;
00027 
00028 TPGntupler::TPGntupler(const edm::ParameterSet& iConfig) : 
00029   //now do what ever initialization is needed
00030   file("tpg_ntuple.root", "RECREATE" ),
00031   tree("TPGntuple","Trigger Primitive Ntuple")
00032 {
00033   tree.Branch("run",&run_num,"run/I");
00034   tree.Branch("event",&event_num,"event/I");
00035   tree.Branch("ieta",ieta,"ieta[4176]/I");
00036   tree.Branch("iphi",iphi,"iphi[4176]/I");
00037   tree.Branch("tpg_energy",tpg_energy,"tpg_energy[4176]/F");
00038   tree.Branch("tpg_uncompressed",tpg_uncompressed,"tpg_uncompressed[4176]/F");
00039   tree.Branch("tpg_index",index,"index[4176]/I");
00040   tree.Branch("rec_energy",rec_energy,"rec_energy[4176]/F");
00041 }
00042 
00043 TPGntupler::~TPGntupler()
00044 {
00045   file.cd();
00046   tree.Write();
00047 }
00048 
00049 //
00050 // member functions
00051 //
00052 
00053 // ------------ method called to for each event  ------------
00054 void
00055 TPGntupler::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00056 {
00057   using namespace edm;
00058   using namespace std;
00059 
00060   ofstream out;
00061   out.open("outfile.txt");
00062   char semicolon = 59;
00063 
00064   edm::ESHandle<CaloTPGTranscoder> _transcoder;
00065   iSetup.get<CaloTPGRecord>().get(_transcoder);
00066   // get the appropriate gains, noises, & widths for this event
00067 
00068   Handle<HcalTrigPrimDigiCollection> tpg;
00069   iEvent.getByType(tpg);  
00070 
00071   Handle<HBHERecHitCollection> hbhe_rec;
00072   iEvent.getByType(hbhe_rec);
00073   
00074   Handle<HFRecHitCollection> hf_rec;
00075   iEvent.getByType(hf_rec);
00076 
00077   run_num = iEvent.id().run();
00078   event_num = iEvent.id().event();
00079 
00080   float tpg_e;
00081   float rec_e;
00082   double eta1, eta2;
00083   std::vector<HcalTrigTowerDetId> towerids;
00084   double eta;
00085   Rec_towers.clear();
00086 
00087   for(HBHERecHitCollection::const_iterator hbhe_iter = hbhe_rec->begin(); hbhe_iter != hbhe_rec->end(); ++hbhe_iter)
00088     {
00089       towerids = theTrigTowerGeometry.towerIds(hbhe_iter->id());
00090       assert(towerids.size() == 2 || towerids.size() == 1);
00091       for(unsigned int n = 0; n < towerids.size(); n++)
00092         {
00093           Rec_towers.insert(IdtoEnergy::value_type(towerids[n],hbhe_iter->energy()/towerids.size()));
00094         }
00095     }
00096 
00097   for(HFRecHitCollection::const_iterator hf_iter = hf_rec->begin(); hf_iter != hf_rec->end(); ++hf_iter)
00098     {
00099       towerids = theTrigTowerGeometry.towerIds(hf_iter->id());
00100       assert(towerids.size() == 2 || towerids.size() == 1);
00101       for(unsigned int n = 0; n < towerids.size(); n++)
00102         {
00103           Rec_towers.insert(IdtoEnergy::value_type(towerids[n],hf_iter->energy()/towerids.size()));
00104         }
00105     }
00106 
00107   int ntower = 0;
00108   for(HcalTrigPrimDigiCollection::const_iterator tpg_iter = tpg->begin(); tpg_iter != tpg->end(); ++tpg_iter )
00109     {
00110       tpg_e = 0.0;
00111       rec_e = 0.0;
00112       for(IdtoEnergy::iterator i = Rec_towers.lower_bound(tpg_iter->id()); i != Rec_towers.upper_bound(tpg_iter->id()); ++i)
00113         {
00114           rec_e += i->second;
00115         }
00116       tpg_e = double(tpg_iter->SOI_compressedEt());
00117       ieta[ntower] = tpg_iter->id().ieta();
00118       iphi[ntower] = tpg_iter->id().iphi();
00119       tpg_energy[ntower] = tpg_e;
00120       rec_energy[ntower] = rec_e;
00121       theTrigTowerGeometry.towerEtaBounds(ieta[ntower],eta1,eta2);
00122       eta = (eta1+eta2)/2;
00123       tpg_uncompressed[ntower] = float(_transcoder->hcaletValue(tpg_iter->id().ietaAbs(),int(tpg_e)));
00124       index[ntower] = tpg_iter->id().zside()*(100*tpg_iter->id().ietaAbs()+tpg_iter->id().iphi());
00125       out << "output[" <<index[ntower] << "] = " << ntower << semicolon <<"\n";
00126       ntower++;
00127     }
00128   tree.Fill();
00129   out.close();
00130 }
00131 
00132 // ------------ method called once each job just before starting event loop  ------------
00133 void 
00134 TPGntupler::beginJob(const edm::EventSetup&)
00135 {
00136 }
00137 
00138 // ------------ method called once each job just after ending the event loop  ------------
00139 void 
00140 TPGntupler::endJob() 
00141 {
00142 }

Generated on Tue Jun 9 17:46:30 2009 for CMSSW by  doxygen 1.5.4