Go to the documentation of this file.00001 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00002 #include "FWCore/Framework/interface/Event.h"
00003 #include "FWCore/Framework/interface/ESHandle.h"
00004 #include "FWCore/Framework/interface/MakerMacros.h"
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00007 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00008 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00009 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00010 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00011 #include "FastSimulation/CaloRecHitsProducer/interface/CaloRecHitsProducer.h"
00012 #include "FastSimulation/CaloRecHitsProducer/interface/HcalRecHitsMaker.h"
00013 #include "FastSimulation/CaloRecHitsProducer/interface/EcalBarrelRecHitsMaker.h"
00014 #include "FastSimulation/CaloRecHitsProducer/interface/EcalEndcapRecHitsMaker.h"
00015 #include "FastSimulation/CaloRecHitsProducer/interface/EcalPreshowerRecHitsMaker.h"
00016 #include "Geometry/CaloTopology/interface/HcalTopology.h"
00017 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00018 #include "FWCore/Framework/interface/EventSetup.h"
00019
00020
00021 #include "FastSimulation/Utilities/interface/RandomEngine.h"
00022
00023
00024
00025 CaloRecHitsProducer::CaloRecHitsProducer(edm::ParameterSet const & p)
00026 : EcalPreshowerRecHitsMaker_(NULL),EcalBarrelRecHitsMaker_(NULL), EcalEndcapRecHitsMaker_(NULL), HcalRecHitsMaker_(NULL)
00027 {
00028
00029
00030 edm::Service<edm::RandomNumberGenerator> rng;
00031 if ( ! rng.isAvailable() ) {
00032 throw cms::Exception("Configuration")
00033 << "CaloRecHitsProducer requires the RandomGeneratorService\n"
00034 "which is not present in the configuration file.\n"
00035 "You must add the service in the configuration file\n"
00036 "or remove the module that requires it";
00037 }
00038 random = new RandomEngine(&(*rng));
00039 theInputRecHitCollectionTypes = p.getParameter<std::vector<unsigned> >("InputRecHitCollectionTypes");
00040 theOutputRecHitCollections = p.getParameter<std::vector<std::string> >("OutputRecHitCollections");
00041 doDigis_ = p.getParameter<bool>("doDigis");
00042 doMiscalib_ = p.getParameter<bool>("doMiscalib");
00043 edm::ParameterSet RecHitsParameters = p.getParameter<edm::ParameterSet>("RecHitsFactory");
00044
00045 for ( unsigned input=0; input<theInputRecHitCollectionTypes.size(); ++input ) {
00046
00047 switch ( theInputRecHitCollectionTypes[input] ) {
00048
00049 case 1:
00050 {
00051
00052 if (theOutputRecHitCollections.size()&&theOutputRecHitCollections[input].size())
00053 produces<ESRecHitCollection>(theOutputRecHitCollections[input]);
00054 else
00055 produces<ESRecHitCollection>();
00056
00057 if (doDigis_)
00058 std::cout << " The digitization of the preshower is not implemented " << std::endl;
00059
00060 EcalPreshowerRecHitsMaker_ = new EcalPreshowerRecHitsMaker(RecHitsParameters,random);
00061 }
00062 break;
00063
00064 case 2:
00065 {
00066
00067 if (theOutputRecHitCollections.size()&&theOutputRecHitCollections[input].size())
00068 produces<EBRecHitCollection>(theOutputRecHitCollections[input]);
00069 else
00070 produces<EBRecHitCollection>();
00071
00072 if (doDigis_) produces<EBDigiCollection>();
00073 EcalBarrelRecHitsMaker_ = new EcalBarrelRecHitsMaker(RecHitsParameters,random);
00074 }
00075 break;
00076
00077 case 3:
00078 {
00079
00080 if (theOutputRecHitCollections.size()&&theOutputRecHitCollections[input].size())
00081 produces<EERecHitCollection>(theOutputRecHitCollections[input]);
00082 else
00083 produces<EERecHitCollection>();
00084 if (doDigis_) produces<EEDigiCollection>();
00085 EcalEndcapRecHitsMaker_ = new EcalEndcapRecHitsMaker(RecHitsParameters,random);
00086 }
00087 break;
00088
00089 case 4:
00090 {
00091
00092 if (theOutputRecHitCollections.size()&&theOutputRecHitCollections[input].size())
00093 produces<HBHERecHitCollection>(theOutputRecHitCollections[input]);
00094 else
00095 produces<HBHERecHitCollection>();
00096
00097 if (doDigis_) produces<HBHEDigiCollection>();
00098 HcalRecHitsMaker_ = new HcalRecHitsMaker(RecHitsParameters,4,random);
00099 }
00100 break;
00101
00102 case 5:
00103 {
00104
00105 if (theOutputRecHitCollections.size()&&theOutputRecHitCollections[input].size())
00106 produces<HORecHitCollection>(theOutputRecHitCollections[input]);
00107 else
00108 produces<HORecHitCollection>();
00109
00110 if (doDigis_) produces<HODigiCollection>();
00111
00112 HcalRecHitsMaker_ = new HcalRecHitsMaker(RecHitsParameters,5,random);
00113 }
00114 break;
00115
00116 case 6:
00117 {
00118
00119 if (theOutputRecHitCollections.size()&&theOutputRecHitCollections[input].size())
00120 produces<HFRecHitCollection>(theOutputRecHitCollections[input]);
00121 else
00122 produces<HFRecHitCollection>();
00123 if(doDigis_) produces<HFDigiCollection>();
00124
00125 HcalRecHitsMaker_ = new HcalRecHitsMaker(RecHitsParameters,6,random);
00126 }
00127 break;
00128
00129 default:
00130
00131 break;
00132
00133 }
00134
00135 }
00136
00137 }
00138
00139 CaloRecHitsProducer::~CaloRecHitsProducer()
00140 {
00141 if ( random ) {
00142 delete random;
00143 }
00144 }
00145
00146 void
00147 CaloRecHitsProducer::beginRun(edm::Run & run, const edm::EventSetup & es) {
00148
00149 for ( unsigned input=0; input<theInputRecHitCollectionTypes.size(); ++input ) {
00150 switch ( theInputRecHitCollectionTypes[input] ) {
00151 case 1:
00152 {
00153
00154 EcalPreshowerRecHitsMaker_->init(es);
00155 }
00156 break;
00157 case 2:
00158 {
00159
00160 EcalBarrelRecHitsMaker_->init(es,doDigis_,doMiscalib_);
00161 }
00162 break;
00163 case 3:
00164 {
00165
00166 EcalEndcapRecHitsMaker_->init(es,doDigis_,doMiscalib_);
00167 }
00168 break;
00169 case 4:
00170 case 5:
00171 case 6:
00172 {
00173 HcalRecHitsMaker_->init(es,doDigis_,doMiscalib_);
00174 }
00175 break;
00176 default:
00177 break;
00178 }
00179 }
00180 }
00181
00182 void CaloRecHitsProducer::endJob()
00183 {
00184
00185 if (EcalBarrelRecHitsMaker_) delete EcalBarrelRecHitsMaker_;
00186 if (EcalEndcapRecHitsMaker_) delete EcalEndcapRecHitsMaker_;
00187 if (EcalPreshowerRecHitsMaker_) delete EcalPreshowerRecHitsMaker_;
00188 if (HcalRecHitsMaker_) delete HcalRecHitsMaker_;
00189 }
00190
00191 void CaloRecHitsProducer::produce(edm::Event & iEvent, const edm::EventSetup & es)
00192 {
00193 edm::ESHandle<HcalTopology> topo;
00194 es.get<IdealGeometryRecord>().get( topo );
00195
00196
00197
00198
00199 for ( unsigned input=0; input<theInputRecHitCollectionTypes.size(); ++input ) {
00200 switch ( theInputRecHitCollectionTypes[input] ) {
00201 case 1:
00202 {
00203
00204 std::auto_ptr<ESRecHitCollection> reces(new ESRecHitCollection);
00205 EcalPreshowerRecHitsMaker_->loadEcalPreshowerRecHits(iEvent,*reces);
00206 if ( theOutputRecHitCollections.size()&& theOutputRecHitCollections[input].size())
00207 iEvent.put(reces,theOutputRecHitCollections[input]);
00208 else
00209 iEvent.put(reces);
00210 break;
00211 }
00212
00213 case 2:
00214 {
00215
00216 std::auto_ptr<EBRecHitCollection> receb(new EBRecHitCollection);
00217 std::auto_ptr<EBDigiCollection> digieb(new EBDigiCollection(1));
00218 EcalBarrelRecHitsMaker_->loadEcalBarrelRecHits(iEvent,*receb,*digieb);
00219
00220 if ( theOutputRecHitCollections.size()&&theOutputRecHitCollections[input].size())
00221 iEvent.put(receb,theOutputRecHitCollections[input]);
00222 else
00223 iEvent.put(receb);
00224
00225 if(doDigis_)
00226 iEvent.put(digieb);
00227 }
00228 break;
00229 case 3:
00230 {
00231
00232 std::auto_ptr<EERecHitCollection> recee(new EERecHitCollection);
00233 std::auto_ptr<EEDigiCollection> digiee(new EEDigiCollection(1));
00234 EcalEndcapRecHitsMaker_->loadEcalEndcapRecHits(iEvent,*recee,*digiee);
00235
00236 if ( theOutputRecHitCollections.size()&& theOutputRecHitCollections[input].size())
00237 iEvent.put(recee,theOutputRecHitCollections[input]);
00238 else
00239 iEvent.put(recee);
00240
00241 if(doDigis_)
00242 iEvent.put(digiee);
00243 }
00244 break;
00245 case 4:
00246 {
00247
00248 std::auto_ptr<HBHERecHitCollection> rec1(new HBHERecHitCollection);
00249 std::auto_ptr<HBHEDigiCollection> digihbhe(new HBHEDigiCollection);
00250 HcalRecHitsMaker_->loadHcalRecHits(iEvent,(*topo),*rec1,*digihbhe);
00251 if ( theOutputRecHitCollections.size()&& theOutputRecHitCollections[input].size())
00252 iEvent.put(rec1,theOutputRecHitCollections[input]);
00253 else
00254 iEvent.put(rec1);
00255
00256 if(doDigis_)
00257 iEvent.put(digihbhe);
00258 }
00259 break;
00260 case 5:
00261 {
00262
00263 std::auto_ptr<HORecHitCollection> rec2(new HORecHitCollection);
00264 std::auto_ptr<HODigiCollection> digiho(new HODigiCollection);
00265
00266 HcalRecHitsMaker_->loadHcalRecHits(iEvent,(*topo),*rec2,*digiho);
00267 if(theOutputRecHitCollections.size()&& theOutputRecHitCollections[input].size())
00268 iEvent.put(rec2,theOutputRecHitCollections[input]);
00269 else
00270 iEvent.put(rec2);
00271 if(doDigis_)
00272 iEvent.put(digiho);
00273 }
00274 break;
00275 case 6:
00276 {
00277
00278 std::auto_ptr<HFRecHitCollection> rec3(new HFRecHitCollection);
00279 std::auto_ptr<HFDigiCollection> digihf(new HFDigiCollection);
00280 HcalRecHitsMaker_->loadHcalRecHits(iEvent,(*topo),*rec3,*digihf);
00281 if(theOutputRecHitCollections.size()&& theOutputRecHitCollections[input].size())
00282 iEvent.put(rec3,theOutputRecHitCollections[input]);
00283 else
00284 iEvent.put(rec3);
00285 if(doDigis_)
00286 iEvent.put(digihf);
00287 }
00288 break;
00289 default:
00290 break;
00291 }
00292 }
00293 }
00294
00295 DEFINE_FWK_MODULE(CaloRecHitsProducer);