00001
00002
00003
00004
00005
00007
00008
00009 #include <memory>
00010
00011 #include "DataFormats/Common/interface/DetSetVector.h"
00012
00013
00014
00015
00016
00017 #include "FWCore/Framework/interface/Frameworkfwd.h"
00018 #include "FWCore/Framework/interface/EDProducer.h"
00019
00020 #include "FWCore/Framework/interface/Event.h"
00021 #include "FWCore/Framework/interface/MakerMacros.h"
00022
00023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00024 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00025 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00026 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
00027 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
00029 #include "SimRomanPot/SimFP420/interface/DigitizerFP420.h"
00030 #include "DataFormats/FP420Digi/interface/DigiCollectionFP420.h"
00031 #include "DataFormats/FP420Digi/interface/HDigiFP420.h"
00032
00033
00034
00035
00036
00037 #include "FWCore/Framework/interface/EventSetup.h"
00038 #include "FWCore/Framework/interface/ESHandle.h"
00039 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00040 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00041 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00042 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
00043
00044
00045
00046
00047
00048
00049
00050 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 #include "FWCore/ServiceRegistry/interface/Service.h"
00066 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00067 #include "FWCore/Utilities/interface/Exception.h"
00068 #include "CLHEP/Random/RandomEngine.h"
00069
00070
00071 #include "G4SDManager.hh"
00072 #include "G4Step.hh"
00073 #include "G4Track.hh"
00074 #include "G4VProcess.hh"
00075 #include "G4HCofThisEvent.hh"
00076 #include "G4UserEventAction.hh"
00077 #include "G4TransportationManager.hh"
00078 #include "G4ProcessManager.hh"
00079
00080 #include <cstdlib>
00081 #include <vector>
00082
00083 using namespace std;
00084
00085
00086
00087
00088
00089
00090 namespace cms
00091 {
00092 DigitizerFP420::DigitizerFP420(const edm::ParameterSet& conf):conf_(conf),stripDigitizer_(new FP420DigiMain(conf)) {
00093
00094
00095 std::string alias ( conf.getParameter<std::string>("@module_label") );
00096
00097
00098
00099 produces<DigiCollectionFP420>().setBranchAlias( alias );
00100
00101 trackerContainers.clear();
00102 trackerContainers = conf.getParameter<std::vector<std::string> >("ROUList");
00103
00104 verbosity = conf_.getUntrackedParameter<int>("VerbosityLevel");
00105 dn0 = conf_.getParameter<int>("NumberFP420Detectors");
00106 sn0 = conf_.getParameter<int>("NumberFP420Stations");
00107 pn0 = conf_.getParameter<int>("NumberFP420SPlanes");
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 if(verbosity>0) {
00123 std::cout << "Creating a DigitizerFP420" << std::endl;
00124 std::cout << "DigitizerFP420: dn0=" << dn0 << " sn0=" << sn0 << " pn0=" << pn0 << std::endl;
00125 std::cout << "DigitizerFP420:trackerContainers.size()=" << trackerContainers.size() << std::endl;
00126
00127 }
00128 }
00129
00130
00131 DigitizerFP420::~DigitizerFP420() {
00132 if(verbosity>0) {
00133 std::cout << "Destroying a DigitizerFP420" << std::endl;
00134 }
00135 delete stripDigitizer_;
00136
00137 }
00138
00139
00140
00141
00142 void DigitizerFP420::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
00143
00144 using namespace edm;
00145 using namespace std;
00146
00147 if(verbosity>0) {
00148 std::cout <<" ===" << std::endl;
00149 std::cout <<" ============== DigitizerFP420: start produce= " << std::endl;
00150 std::cout <<" ===" << std::endl;
00151 }
00152
00153
00154
00155
00156
00157
00158 edm::Handle<CrossingFrame<PSimHit> > cf_simhit;
00159 std::vector<const CrossingFrame<PSimHit> *> cf_simhitvec;
00160 for(uint32_t i = 0; i< trackerContainers.size();i++){
00161 iEvent.getByLabel("mix",trackerContainers[i],cf_simhit);
00162 cf_simhitvec.push_back(cf_simhit.product()); }
00163 std::auto_ptr<MixCollection<PSimHit> > allTrackerHits(new MixCollection<PSimHit>(cf_simhitvec));
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00193
00194 std::auto_ptr<DigiCollectionFP420> output(new DigiCollectionFP420);
00195
00196
00197
00198
00199 SimHitMap.clear();
00200
00201
00202 if(verbosity>0) {
00203 std::cout <<" ===" << std::endl;
00204 std::cout <<" ============== DigitizerFP420: MixCollection treatment= " << std::endl;
00205 std::cout <<" ===" << std::endl;
00206 }
00207
00208 MixCollection<PSimHit>::iterator isim;
00209 for (isim=allTrackerHits->begin(); isim!= allTrackerHits->end();isim++) {
00210 unsigned int unitID = (*isim).detUnitId();
00211 int det, zside, sector, zmodule, sScale = 2*(pn0-1), dScale = 2*(pn0-1)*(sn0-1);
00212 FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
00213 int zScale=2; unsigned int intindex = dScale*(det - 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
00214 if(verbosity>0) {
00215 double losenergy = (*isim).energyLoss();
00216 std::cout <<" ===" << std::endl;
00217 std::cout <<" ============== DigitizerFP420: losenergy= " << losenergy << std::endl;
00218 std::cout <<" === for intindex = " << intindex << std::endl;
00219 }
00220
00221 SimHitMap[intindex].push_back((*isim));
00222
00223 }
00224
00225
00226 if(verbosity>0) {
00227 std::cout <<" ===" << std::endl;
00228 std::cout <<" ============== DigitizerFP420: put zero to container " << std::endl;
00229 std::cout <<" ===" << std::endl;
00230 }
00231
00232
00233 for (int det=1; det<dn0; det++) {
00234 for (int sector=1; sector<sn0; sector++) {
00235 for (int zmodule=1; zmodule<pn0; zmodule++) {
00236 for (int zside=1; zside<3; zside++) {
00237 int sScale = 2*(pn0-1), dScale = 2*(pn0-1)*(sn0-1);
00238
00239
00240 int zScale=2; unsigned int detID = dScale*(det - 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
00241 std::vector<HDigiFP420> collector;
00242 collector.clear();
00243 DigiCollectionFP420::Range inputRange;
00244 inputRange.first = collector.begin();
00245 inputRange.second = collector.end();
00246 output->putclear(inputRange,detID);
00247 }
00248 }
00249 }
00250 }
00251
00252
00253 output->clear();
00254
00255
00256
00257
00258 if(verbosity>0) {
00259 std::cout <<" ===" << std::endl;
00260 std::cout <<" ============== DigitizerFP420: start loop over det iu " << std::endl;
00261 std::cout <<" ===" << std::endl;
00262 }
00263 bool first = true;
00264 for (int det=1; det<dn0; det++) {
00265 for (int sector=1; sector<sn0; sector++) {
00266 for (int zmodule=1; zmodule<pn0; zmodule++) {
00267 for (int zside=1; zside<3; zside++) {
00268
00269 int sScale = 2*(pn0-1), dScale = 2*(pn0-1)*(sn0-1);
00270
00271
00272
00273 int zScale=2; unsigned int iu = dScale*(det - 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
00274
00275 if(verbosity>0) {
00276 int index = FP420NumberingScheme::packFP420Index(det, zside, sector, zmodule);
00277 std::cout << " DigitizerFP420:2 run loop index = " << index << " iu = " << iu << std::endl;
00278 }
00279
00280
00281
00282 G4ThreeVector bfield( 0., 0., 0.0 );
00283
00284
00285
00286 if(verbosity>0) {
00287 std::cout <<" ===" << std::endl;
00288 std::cout <<" ============== DigitizerFP420: call run for iu= " << iu << std::endl;
00289 std::cout <<" ===" << std::endl;
00290 }
00291 collector.clear();
00292
00293 collector= stripDigitizer_->run( SimHitMap[iu],
00294 bfield,
00295 iu
00296 );
00297
00298
00299
00300
00301 if(verbosity>0) {
00302 std::cout <<" ===" << std::endl;
00303 std::cout <<" ===" << std::endl;
00304 std::cout <<"======= DigitizerFP420: collector size = " << collector.size() << std::endl;
00305 std::cout <<" ===" << std::endl;
00306 std::cout <<" ===" << std::endl;
00307 }
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317 if (collector.size()>0){
00318 if(verbosity>0) {
00319 std::cout <<" ============= DigitizerFP420:collector start!!!!!!!!!!!!!!" << std::endl;
00320 }
00321 DigiCollectionFP420::Range outputRange;
00322 outputRange.first = collector.begin();
00323 outputRange.second = collector.end();
00324
00325 if ( first ) {
00326
00327 first = false;
00328 unsigned int detID0= 0;
00329 output->put(outputRange,detID0);
00330 }
00331
00332
00333 output->put(outputRange,iu);
00334
00335 }
00336
00337 }
00338 }
00339 }
00340 }
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350 if(verbosity>0) {
00351
00352 for (int det=1; det<dn0; det++) {
00353 for (int sector=1; sector<sn0; sector++) {
00354 for (int zmodule=1; zmodule<pn0; zmodule++) {
00355 for (int zside=1; zside<3; zside++) {
00356 int sScale = 2*(pn0-1), dScale = 2*(pn0-1)*(sn0-1);
00357 int zScale=2; unsigned int iu = dScale*(det - 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
00358 collector.clear();
00359 DigiCollectionFP420::Range outputRange;
00360
00361 outputRange = output->get(iu);
00362
00363
00364 std::vector<HDigiFP420> collector;
00365
00366 DigiCollectionFP420::ContainerIterator sort_begin = outputRange.first;
00367 DigiCollectionFP420::ContainerIterator sort_end = outputRange.second;
00368 for ( ;sort_begin != sort_end; ++sort_begin ) {
00369 collector.push_back(*sort_begin);
00370 }
00371
00372 std::cout <<" ===" << std::endl;
00373 std::cout <<" ===" << std::endl;
00374 std::cout <<"=======DigitizerFP420:check of re-new collector size = " << collector.size() << std::endl;
00375 std::cout <<" iu = " << iu << std::endl;
00376 std::cout <<" ===" << std::endl;
00377 vector<HDigiFP420>::const_iterator simHitIter = collector.begin();
00378 vector<HDigiFP420>::const_iterator simHitIterEnd = collector.end();
00379 for (;simHitIter != simHitIterEnd; ++simHitIter) {
00380 const HDigiFP420 istrip = *simHitIter;
00381
00382 std::cout << "DigitizerFP420:check: HDigiFP420:: zside = " << zside << " det=" << det << std::endl;
00383 std::cout << " strip number=" << istrip.strip() << " adc=" << istrip.adc() << std::endl;
00384 std::cout <<" ===" << std::endl;
00385 std::cout <<" ===" << std::endl;
00386 std::cout <<" ===" << std::endl;
00387 std::cout <<" =======================" << std::endl;
00388 }
00389
00390
00391
00392 }
00393 }
00394 }
00395 }
00396
00397
00398
00399 }
00400
00401
00402
00403
00404
00405
00406 if(verbosity>0) {
00407 std::cout << "DigitizerFP420 recoutput" << std::endl;
00408 }
00409
00410 iEvent.put(output);
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424 }
00425
00426 }
00427
00428
00429
00430
00431