CMS 3D CMS Logo

CaloRecHitCopy.cc

Go to the documentation of this file.
00001 
00002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/MakerMacros.h"
00005 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00006 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00007 
00008 #include "FastSimulation/CaloRecHitsProducer/interface/CaloRecHitCopy.h"
00009 
00010 #include <iostream>
00011 
00012 CaloRecHitCopy::CaloRecHitCopy(edm::ParameterSet const & p)
00013 
00014 {    
00015 
00016   theInputRecHitCollectionTypes = p.getParameter<std::vector<unsigned> >("InputRecHitCollectionTypes");
00017   theInputRecHitCollections = p.getParameter<std::vector<edm::InputTag> >("InputRecHitCollections");
00018   theOutputRecHitCollections = p.getParameter<std::vector<std::string> >("OutputRecHitCollections");
00019 
00020   theOutputRecHitInstances.resize(theInputRecHitCollectionTypes.size());
00021   
00022   for ( unsigned input=0; input<theInputRecHitCollectionTypes.size(); ++input ) { 
00023 
00024     theOutputRecHitInstances[input] = 
00025       theOutputRecHitCollections[input] == "none" ?
00026       false : true;
00027 
00028     switch ( theInputRecHitCollectionTypes[input] ) { 
00029       
00030     case 1: 
00031       {
00032         //Preshower
00033         if ( !theOutputRecHitInstances[input] ) 
00034           produces<ESRecHitCollection>();
00035         else
00036           produces<ESRecHitCollection>(theOutputRecHitCollections[input]);
00037       }
00038       break;
00039       
00040     case 2:
00041       { 
00042         //Ecal Barrel 
00043         if ( !theOutputRecHitInstances[input] ) 
00044           produces<EBRecHitCollection>();
00045         else
00046           produces<EBRecHitCollection>(theOutputRecHitCollections[input]);
00047       }
00048       break;
00049       
00050     case 3:
00051       { 
00052         //EcalEndcap
00053         if ( !theOutputRecHitInstances[input] ) 
00054           produces<EERecHitCollection>();
00055         else
00056           produces<EERecHitCollection>(theOutputRecHitCollections[input]);
00057       }
00058       break;
00059       
00060     case 4:
00061       { 
00062         //HCAL
00063         if ( !theOutputRecHitInstances[input] ) 
00064           produces<HBHERecHitCollection>();
00065         else
00066           produces<HBHERecHitCollection>(theOutputRecHitCollections[input]);
00067       }
00068       break;
00069       
00070     case 5:
00071       { 
00072         //HO
00073         if ( !theOutputRecHitInstances[input] ) 
00074           produces<HORecHitCollection>();
00075         else
00076           produces<HORecHitCollection>(theOutputRecHitCollections[input]);
00077       }
00078       break;
00079       
00080     case 6:
00081       { 
00082         //HF
00083         if ( !theOutputRecHitInstances[input] ) 
00084           produces<HFRecHitCollection>();
00085         else
00086           produces<HFRecHitCollection>(theOutputRecHitCollections[input]);
00087       }
00088       break;
00089       
00090     default:
00091       // Should not happen
00092       break;
00093       
00094     }
00095     
00096   }
00097   
00098 
00099 }
00100 
00101 CaloRecHitCopy::~CaloRecHitCopy() { }
00102 
00103 void 
00104 CaloRecHitCopy::endJob() { }
00105 
00106 void 
00107 CaloRecHitCopy::produce(edm::Event & iEvent, const edm::EventSetup & es)
00108 {
00109 
00110 
00111   for ( unsigned input=0; input<theInputRecHitCollectionTypes.size(); ++input ) { 
00112 
00113     switch ( theInputRecHitCollectionTypes[input] ) { 
00114       
00115     case 1: 
00116       {
00117         //Preshower
00118         std::auto_ptr< ESRecHitCollection > copiedESRecHitCollection( new ESRecHitCollection );
00119         edm::Handle<ESRecHitCollection> ESRecHits;
00120         iEvent.getByLabel(theInputRecHitCollections[input],ESRecHits);
00121         ESRecHitCollection::const_iterator itES = ESRecHits->begin();
00122         ESRecHitCollection::const_iterator lastES = ESRecHits->end();
00123         for ( ; itES!=lastES; ++itES++ ) {
00124           EcalRecHit aHit(*itES);
00125           copiedESRecHitCollection->push_back(aHit);
00126         }
00127         if ( !theOutputRecHitInstances[input] ) 
00128           iEvent.put(copiedESRecHitCollection);
00129         else
00130           iEvent.put(copiedESRecHitCollection,theOutputRecHitCollections[input]);
00131       }
00132       break;
00133       
00134     case 2: 
00135       {
00136         //Ecal Barrel 
00137         std::auto_ptr< EBRecHitCollection > copiedEBRecHitCollection( new EBRecHitCollection );
00138         edm::Handle<EBRecHitCollection> EBRecHits;
00139         iEvent.getByLabel(theInputRecHitCollections[input],EBRecHits);
00140         EBRecHitCollection::const_iterator itEB = EBRecHits->begin();
00141         EBRecHitCollection::const_iterator lastEB = EBRecHits->end();
00142         for ( ; itEB!=lastEB; ++itEB++ ) {
00143           EcalRecHit aHit(*itEB);
00144           copiedEBRecHitCollection->push_back(aHit);
00145         }
00146         if ( !theOutputRecHitInstances[input] ) 
00147           iEvent.put(copiedEBRecHitCollection);
00148         else
00149           iEvent.put(copiedEBRecHitCollection,theOutputRecHitCollections[input]);
00150       }
00151       break;
00152       
00153     case 3:
00154       {
00155         //EcalEndcap
00156         std::auto_ptr< EERecHitCollection > copiedEERecHitCollection( new EERecHitCollection );
00157         edm::Handle<EERecHitCollection> EERecHits;
00158         iEvent.getByLabel(theInputRecHitCollections[input],EERecHits);
00159         EERecHitCollection::const_iterator itEE = EERecHits->begin();
00160         EERecHitCollection::const_iterator lastEE = EERecHits->end();
00161         for ( ; itEE!=lastEE; ++itEE++ ) {
00162           EcalRecHit aHit(*itEE);
00163           copiedEERecHitCollection->push_back(aHit);
00164         }
00165         if ( !theOutputRecHitInstances[input] ) 
00166           iEvent.put(copiedEERecHitCollection);
00167         else
00168           iEvent.put(copiedEERecHitCollection,theOutputRecHitCollections[input]);
00169       }
00170       break;
00171       
00172     case 4:
00173       {
00174         //HCAL
00175         std::auto_ptr< HBHERecHitCollection > copiedHBHERecHitCollection( new HBHERecHitCollection );
00176         edm::Handle<HBHERecHitCollection> HBHERecHits;
00177         iEvent.getByLabel(theInputRecHitCollections[input],HBHERecHits);
00178         HBHERecHitCollection::const_iterator itHBHE = HBHERecHits->begin();
00179         HBHERecHitCollection::const_iterator lastHBHE = HBHERecHits->end();
00180         for ( ; itHBHE!=lastHBHE; ++itHBHE++ ) {
00181           HBHERecHit aHit(*itHBHE);
00182           copiedHBHERecHitCollection->push_back(aHit);
00183         }
00184         if ( !theOutputRecHitInstances[input] ) 
00185           iEvent.put(copiedHBHERecHitCollection);
00186         else
00187           iEvent.put(copiedHBHERecHitCollection,theOutputRecHitCollections[input]);
00188       }
00189       break;
00190       
00191     case 5:
00192       {
00193         //HO
00194         std::auto_ptr< HORecHitCollection > copiedHORecHitCollection( new HORecHitCollection );
00195         edm::Handle<HORecHitCollection> HORecHits;
00196         iEvent.getByLabel(theInputRecHitCollections[input],HORecHits);
00197         HORecHitCollection::const_iterator itHO = HORecHits->begin();
00198         HORecHitCollection::const_iterator lastHO = HORecHits->end();
00199         for ( ; itHO!=lastHO; ++itHO++ ) {
00200           HORecHit aHit(*itHO);
00201           copiedHORecHitCollection->push_back(aHit);
00202         }
00203         if ( !theOutputRecHitInstances[input] ) 
00204           iEvent.put(copiedHORecHitCollection);
00205         else
00206           iEvent.put(copiedHORecHitCollection,theOutputRecHitCollections[input]);
00207       }
00208       break;
00209       
00210     case 6:
00211       {
00212         //HF
00213         std::auto_ptr< HFRecHitCollection > copiedHFRecHitCollection( new HFRecHitCollection );
00214         edm::Handle<HFRecHitCollection> HFRecHits;
00215         iEvent.getByLabel(theInputRecHitCollections[input],HFRecHits);
00216         HFRecHitCollection::const_iterator itHF = HFRecHits->begin();
00217         HFRecHitCollection::const_iterator lastHF = HFRecHits->end();
00218         for ( ; itHF!=lastHF; ++itHF++ ) {
00219           HFRecHit aHit(*itHF);
00220           copiedHFRecHitCollection->push_back(aHit);
00221         }
00222         if ( !theOutputRecHitInstances[input] ) 
00223           iEvent.put(copiedHFRecHitCollection);
00224         else
00225           iEvent.put(copiedHFRecHitCollection,theOutputRecHitCollections[input]);
00226       }
00227       break;
00228       
00229     default:
00230       // Should not happen
00231       break;
00232       
00233     }
00234     
00235   }
00236 
00237 }
00238 
00239 DEFINE_FWK_MODULE(CaloRecHitCopy);

Generated on Tue Jun 9 17:35:02 2009 for CMSSW by  doxygen 1.5.4