CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/RecoRomanPot/RecoFP420/plugins/ClusterizerFP420.cc

Go to the documentation of this file.
00001 
00002 // File: ClusterizerFP420.cc
00003 // Date: 12.2006
00004 // Description: ClusterizerFP420 for FP420
00005 // Modifications: 
00007 #include <memory>
00008 #include <string>
00009 
00010 #include "FWCore/Framework/interface/Frameworkfwd.h"
00011 #include "FWCore/Framework/interface/EDProducer.h"
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 #include "FWCore/Framework/interface/Event.h"
00014 #include "FWCore/Framework/interface/MakerMacros.h"
00015 #include "FWCore/Framework/interface/EventSetup.h"
00016 #include "FWCore/Framework/interface/ESHandle.h"
00017 
00018 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00019 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00020 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00021 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
00022 
00023 #include "DataFormats/Common/interface/DetSetVector.h"
00024 //#include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00025 
00026 
00027 #include "RecoRomanPot/RecoFP420/interface/ClusterizerFP420.h"
00028 #include "DataFormats/FP420Digi/interface/DigiCollectionFP420.h"
00029 #include "DataFormats/FP420Cluster/interface/ClusterCollectionFP420.h"
00030 #include "RecoRomanPot/RecoFP420/interface/ClusterNoiseFP420.h"
00031 
00032 //Random Number
00033 #include "FWCore/ServiceRegistry/interface/Service.h"
00034 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00035 #include "FWCore/Utilities/interface/Exception.h"
00036 #include "CLHEP/Random/RandomEngine.h"
00037 
00038 #include <cstdlib> 
00039 #include <iostream> 
00040 using namespace std;
00041 
00042 namespace cms
00043 {
00044   ClusterizerFP420::ClusterizerFP420(const edm::ParameterSet& conf):
00045     conf_(conf) {
00046     
00047     
00048     std::string alias ( conf.getParameter<std::string>("@module_label") );
00049     
00050     produces<ClusterCollectionFP420>().setBranchAlias( alias );
00051     
00052     trackerContainers.clear();
00053     trackerContainers = conf.getParameter<std::vector<std::string> >("ROUList");
00054     
00055     verbosity = conf_.getUntrackedParameter<int>("VerbosityLevel");
00056     dn0   = conf_.getParameter<int>("NumberFP420Detectors");
00057     sn0   = conf_.getParameter<int>("NumberFP420Stations");
00058     pn0 = conf_.getParameter<int>("NumberFP420SPlanes");
00059     rn0 = 7;
00060     if (verbosity > 0) {
00061       std::cout << "Creating a ClusterizerFP420" << std::endl;
00062       std::cout << "ClusterizerFP420: dn0=" << dn0 << " sn0=" << sn0 << " pn0=" << pn0 <<  " rn0=" << rn0 << std::endl;
00063     }
00064     
00065     sClusterizerFP420_ = new FP420ClusterMain(conf_,dn0,sn0,pn0,rn0);
00066   }
00067   
00068   // Virtual destructor needed.
00069   ClusterizerFP420::~ClusterizerFP420() { 
00070     delete sClusterizerFP420_;
00071   }  
00072   
00073   //Get at the beginning
00074   void ClusterizerFP420::beginJob() {
00075     if (verbosity > 0) {
00076       std::cout << "BeginJob method " << std::endl;
00077     }
00078     //Getting Calibration data (Noises and BadElectrodes Flag)
00079     //    bool UseNoiseBadElectrodeFlagFromDB_=conf_.getParameter<bool>("UseNoiseBadElectrodeFlagFromDB");  
00080     //    if (UseNoiseBadElectrodeFlagFromDB_==true){
00081     //      iSetup.get<ClusterNoiseFP420Rcd>().get(noise);// AZ: do corrections for noise here
00082     //=========================================================
00083     // 
00084     // Debug: show noise for DetIDs
00085     //       ElectrodNoiseMapIterator mapit = noise->m_noises.begin();
00086     //       for (;mapit!=noise->m_noises.end();mapit++)
00087     //  {
00088     //    unsigned int detid = (*mapit).first;
00089     //    std::cout << "detid " <<  detid << " # Electrode " << (*mapit).second.size()<<std::endl;
00090     //    //ElectrodNoiseVector theElectrodVector =  (*mapit).second;     
00091     //    const ElectrodNoiseVector theElectrodVector =  noise->getElectrodNoiseVector(detid);
00092     
00093     
00094     //    int electrode=0;
00095     //    ElectrodNoiseVectorIterator iter=theElectrodVector.begin();
00096     //    //for(; iter!=theElectrodVector.end(); iter++)
00097     //    {
00098     //      std::cout << " electrode " << electrode++ << " =\t"
00099     //                << iter->getNoise()     << " \t" 
00100     //                << iter->getDisable()   << " \t" 
00101     //                << std::endl;         
00102     //    } 
00103     //       }
00104     //===========================================================
00105     //    }
00106   }
00107   
00108   void ClusterizerFP420::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00109   {
00110     //  beginJob;
00111     // be lazy and include the appropriate namespaces
00112     using namespace edm; 
00113     using namespace std;   
00114     if (verbosity > 0) {
00115       std::cout << "ClusterizerFP420: produce" << std::endl;
00116     }
00117     
00118     // Get input
00119     //A
00120     //   edm::Handle<DigiCollectionFP420> icf_simhit;
00121     /*    
00122     Handle<DigiCollectionFP420> cf_simhit;
00123     std::vector<const DigiCollectionFP420 *> cf_simhitvec;
00124     for(uint32_t i = 0; i< trackerContainers.size();i++){
00125       iEvent.getByLabel( trackerContainers[i], cf_simhit);
00126       cf_simhitvec.push_back(cf_simhit.product());   }
00127     std::auto_ptr<DigiCollectionFP420 > digis(new DigiCollectionFP420(cf_simhitvec));
00128 
00129     std::vector<HDigiFP420> input;
00130     DigiCollectionFP420::iterator isim;
00131     for (isim=digis->begin(); isim!= digis->end();isim++) {
00132       input.push_back(*isim);
00133      }
00134 */    
00135     //B
00136            
00137     Handle<DigiCollectionFP420> input;
00138     try{
00139       //      iEvent.getByLabel( "FP420Digi" , digis);
00140       iEvent.getByLabel( trackerContainers[0] , input);
00141     } catch(const Exception&)
00142       {
00143         // in principal, should never happen, as it's taken care of by Framework
00144         throw cms::Exception("InvalidReference")
00145           << "Invalid reference to DigiCollectionFP420 \n";
00146       }
00147     
00148     if (verbosity > 0) {
00149       std::cout << "ClusterizerFP420: OK1" << std::endl;
00150     }
00151 
00152     // Step C: create empty output collection
00153     std::auto_ptr<ClusterCollectionFP420> soutput(new ClusterCollectionFP420);
00155     /*    
00156    std::vector<SimVertex> input;
00157    Handle<DigiCollectionFP420> digis;
00158    iEvent.getByLabel("FP420Digi",digis);
00159    input.insert(input.end(),digis->begin(),digis->end());
00160 
00161 
00162 
00163     std::vector<HDigiFP420> input;
00164     for(std::vector<HDigiFP420>::const_iterator vsim=digis->begin();
00165         vsim!=digis->end(); ++vsim){
00166       input.push_back(*vsim);
00167     }
00168    theSimTracks.insert(theSimTracks.end(),SimTk->begin(),SimTk->end());
00169 */
00170     //     std::vector<HDigiFP420> input;
00171     //   DigiCollectionFP420  input;
00172        //input.push_back(digis);
00173         //   input.insert(input.end(), digis->begin(), digis->end());
00174 
00175     /*
00176     std::vector<HDigiFP420> input;
00177     input.clear();
00178     DigiCollectionFP420::ContainerIterator sort_begin = digis->begin();
00179     DigiCollectionFP420::ContainerIterator sort_end = digis->end();
00180     for ( ;sort_begin != sort_end; ++sort_begin ) {
00181       input.push_back(*sort_begin);
00182     } // for
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       for (int det=1; det<dn0; det++) {
00189         for (int sector=1; sector<sn0; sector++) {
00190           for (int zmodule=1; zmodule<pn0; zmodule++) {
00191             for (int zside=1; zside<rn0; zside++) {
00192               // intindex is a continues numbering of FP420
00193               unsigned int detID = theFP420NumberingScheme->FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
00194               std::vector<ClusterFP420> collector;
00195               collector.clear();
00196               ClusterCollectionFP420::Range inputRange;
00197               inputRange.first = collector.begin();
00198               inputRange.second = collector.end();
00199               
00200               soutput->putclear(inputRange,detID);
00201               
00202             }//for
00203           }//for
00204         }//for
00205       }//for
00206       
00207     
00208     //                                                                                                                      !!!!!!   
00209     // if we want to keep Cluster container/Collection for one event --->   uncomment the line below and vice versa
00210     soutput->clear();   //container_.clear() --> start from the beginning of the container
00211     
00212     //                                RUN now:                                                                                 !!!!!!     
00213     //  sClusterizerFP420_.run(input, soutput, noise);
00214     if (verbosity > 0) {
00215       std::cout << "ClusterizerFP420: OK2" << std::endl;
00216     }
00217       sClusterizerFP420_->run(input, soutput, noise);
00218 
00219     if (verbosity > 0) {
00220       std::cout << "ClusterizerFP420: OK3" << std::endl;
00221     }
00222 
00223     //  if(collectorZS.data.size()>0){
00224 
00225     //  std::cout <<"=======           ClusterizerFP420:                    end of produce     " <<  std::endl;
00226     
00227         // Step D: write output to file
00228         iEvent.put(soutput);
00229     if (verbosity > 0) {
00230       std::cout << "ClusterizerFP420: OK4" << std::endl;
00231     }
00232   }//produce
00233   
00234 } // namespace cms
00235