CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoRomanPot/RecoFP420/plugins/ReconstructerFP420.cc

Go to the documentation of this file.
00001 
00002 // File: ReconstructerFP420.cc
00003 // Date: 11.2007
00004 // Description: ReconstructerFP420 for FP420
00005 // Modifications: 
00007 #include <memory>
00008 #include <string>
00009 #include "FWCore/Framework/interface/Frameworkfwd.h"
00010 #include "FWCore/Framework/interface/EDProducer.h"
00011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00012 #include "FWCore/Framework/interface/Event.h"
00013 #include "FWCore/Framework/interface/MakerMacros.h"
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 
00017 #include "RecoRomanPot/RecoFP420/interface/ReconstructerFP420.h"
00018 #include "DataFormats/FP420Cluster/interface/TrackCollectionFP420.h"
00019 #include "DataFormats/FP420Cluster/interface/RecoCollectionFP420.h"
00020 
00021 //#include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00022 //#include "HepMC/GenEvent.h"
00023 
00024 #include <iostream> 
00025 using namespace std;
00026 
00027 //
00028 namespace cms
00029 {
00030   ReconstructerFP420::ReconstructerFP420(const edm::ParameterSet& conf):conf_(conf)     {
00031     
00032     edm::LogInfo ("ReconstructerFP420 ") <<"Enter the FP420 Reco constructer";
00033 
00034 
00035     verbosity = conf_.getUntrackedParameter<int>("VerbosityLevel");
00036     if (verbosity > 0) {
00037       std::cout << "Constructor of  ReconstructerFP420" << std::endl;
00038     }
00039 
00040 
00041     std::string alias ( conf.getParameter<std::string>("@module_label") );
00042     
00043     produces<RecoCollectionFP420>().setBranchAlias( alias );
00044     
00045     trackerContainers.clear();
00046     trackerContainers = conf.getParameter<std::vector<std::string> >("ROUList");
00047     VtxFlag                = conf.getParameter<int>("VtxFlagGenRec");
00048     m_genReadoutName        = conf.getParameter<string>("genReadoutName");
00049     
00050     
00051     // Initialization:
00052     sFP420RecoMain_ = new FP420RecoMain(conf_);
00053     
00054   }
00055   
00056   // Virtual destructor needed.
00057   ReconstructerFP420::~ReconstructerFP420() {
00058     if (verbosity > 0) {
00059       std::cout << "ReconstructerFP420:delete FP420RecoMain" << std::endl;
00060     }
00061     delete sFP420RecoMain_;
00062   }  
00063   
00064   //Get at the beginning
00065   void ReconstructerFP420::beginJob() {
00066     if (verbosity > 0) {
00067       std::cout << "ReconstructerFP420:BeginJob method " << std::endl;
00068     }
00069   }
00070   
00071   
00072   void ReconstructerFP420::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00073   {
00074     //  beginJob;
00075     // be lazy and include the appropriate namespaces
00076     using namespace edm; 
00077     using namespace std;   
00078     
00079     // Get input
00080 
00081     // Vtx info:
00082     
00083     // define GEN Vtx of Signal
00084     double vtxGenX = 0.;
00085     double vtxGenY = 0.;
00086     double vtxGenZ = 0.;
00087 
00088     /*
00089     if(VtxFlag == 1) {
00090       
00091       Handle<HepMCProduct> EvtHandle;
00092       try{
00093         iEvent.getByLabel(m_genReadoutName,EvtHandle);
00094       }catch(const Exception&){
00095         if(verbosity>0){
00096           std::cout << "no HepMCProduct found"<< std::endl;
00097         }
00098       }
00099       
00100       const HepMC::GenEvent* evt = EvtHandle->GetEvent() ;
00101       HepMC::GenParticle* proton1 = 0;
00102       HepMC::GenParticle* proton2 = 0;  
00103       double partmomcut=4000.;
00104       double pz1max = 0.;
00105       double pz2min = 0.;
00106       for ( HepMC::GenEvent::particle_const_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p ) {
00108         double pz = (*p)->momentum().pz();
00109         //      if (((*p)->pdg_id() == ipdgproton)&&((*p)->status() == 1)&&(pz > partmomcut)){
00110         if( pz > partmomcut){
00111           if(pz > pz1max){
00112             proton1 = *p;pz1max=pz;
00113           }
00114         } 
00115         //      else if(( (*p)->pdg_id() == ipdgproton)&&((*p)->status() == 1)&&(pz < -1.*partmomcut)) {
00116         else if(pz < -1.*partmomcut) {
00117           if(pz < pz2min){
00118             proton2 = *p;pz2min=pz;
00119           }
00120         }
00121         
00122       }// for
00123       if(proton1 && !proton2){
00124         vtxGenX = (proton1)->production_vertex()->position().x();
00125         vtxGenY = (proton1)->production_vertex()->position().y();
00126         vtxGenZ = (proton1)->production_vertex()->position().z();
00127       }
00128       else if(proton2 && !proton1){
00129         vtxGenX = (proton2)->production_vertex()->position().x();
00130         vtxGenY = (proton2)->production_vertex()->position().y();
00131         vtxGenZ = (proton2)->production_vertex()->position().z();
00132       }
00133       else if(proton1 && proton2){
00134         if(abs((proton1)->momentum().pz()) >= abs((proton2)->momentum().pz()) ) {
00135           vtxGenX = (proton1)->production_vertex()->position().x();
00136           vtxGenY = (proton1)->production_vertex()->position().y();
00137           vtxGenZ = (proton1)->production_vertex()->position().z();
00138         }
00139         else {
00140           vtxGenX = (proton2)->production_vertex()->position().x();
00141           vtxGenY = (proton2)->production_vertex()->position().y();
00142           vtxGenZ = (proton2)->production_vertex()->position().z();
00143         }
00144       }
00145     }// if(VtxFlag == 1 
00146 
00147 */
00148     
00149     double VtxX = 0.;
00150     double VtxY = 0.;
00151     double VtxZ = 0.;
00152     if(VtxFlag == 1) {
00153       VtxX = vtxGenX;// mm
00154       VtxY = vtxGenY;// mm
00155       VtxZ = vtxGenZ;// mm
00156     }
00157     
00158     
00159 
00160 
00161     // track collection:
00162     //A
00163     //   edm::Handle<ClusterCollectionFP420> icf_simhit;
00164     /*
00165     Handle<ClusterCollectionFP420> cf_simhit;
00166     std::vector<const ClusterCollectionFP420 *> cf_simhitvec;
00167     for(uint32_t i = 0; i< trackerContainers.size();i++){
00168       iEvent.getByLabel( trackerContainers[i], cf_simhit);
00169       cf_simhitvec.push_back(cf_simhit.product());   }
00170     std::auto_ptr<ClusterCollectionFP420 > input(new DigiCollectionFP420(cf_simhitvec));
00171     */   
00172     
00173     //B
00174     
00175       Handle<TrackCollectionFP420> input;
00176       iEvent.getByLabel( trackerContainers[0] , input);
00177 
00178 
00179        
00180     
00181     // Step C: create empty output collection
00182     std::auto_ptr<RecoCollectionFP420> toutput(new RecoCollectionFP420);
00183     
00184     
00185     
00186     //    put zero to container info from the beginning (important! because not any detID is updated with coming of new event     !!!!!!   
00187     // clean info of container from previous event
00188     
00189     std::vector<RecoFP420> collector;
00190     collector.clear();
00191     RecoCollectionFP420::Range inputRange;
00192     inputRange.first = collector.begin();
00193     inputRange.second = collector.end();
00194     
00195     unsigned int detID = 0;
00196     toutput->putclear(inputRange,detID);
00197     
00198     unsigned  int StID = 1;
00199     toutput->putclear(inputRange,StID);
00200     StID = 2;
00201     toutput->putclear(inputRange,StID);
00202     
00203     
00204     //                                                                                                                      !!!!!!   
00205     // if we want to keep Reco container/Collection for one event --->   uncomment the line below and vice versa
00206     toutput->clear();   //container_.clear() --> start from the beginning of the container
00207     
00208     //                                RUN now:                                                                                 !!!!!!     
00209     //   startFP420RecoMain_.run(input, toutput);
00210     sFP420RecoMain_->run(input, toutput, VtxX, VtxY, VtxZ);
00211     // std::cout <<"=======           ReconstructerFP420:                    end of produce     " << endl;
00212     
00213         // Step D: write output to file
00214     if (verbosity > 0) {
00215       std::cout << "ReconstructerFP420: iEvent.put(toutput)" << std::endl;
00216     }
00217         iEvent.put(toutput);
00218     if (verbosity > 0) {
00219       std::cout << "ReconstructerFP420: iEvent.put(toutput) DONE" << std::endl;
00220     }
00221   }//produce
00222   
00223 } // namespace cms
00224 
00225