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
00031
00032
00033
00034 #include "DataFormats/FP420Digi/interface/DigiCollectionFP420.h"
00035 #include "DataFormats/FP420Digi/interface/HDigiFP420.h"
00036
00037
00038
00039
00040
00041 #include "FWCore/Framework/interface/EventSetup.h"
00042 #include "FWCore/Framework/interface/ESHandle.h"
00043 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00044 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00045 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00046 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
00047
00048
00049
00050
00051
00052
00053
00054 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #include "FWCore/ServiceRegistry/interface/Service.h"
00070 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00071 #include "FWCore/Utilities/interface/Exception.h"
00072 #include "CLHEP/Random/RandomEngine.h"
00073
00074
00075 #include "G4SDManager.hh"
00076 #include "G4Step.hh"
00077 #include "G4Track.hh"
00078 #include "G4VProcess.hh"
00079 #include "G4HCofThisEvent.hh"
00080 #include "G4UserEventAction.hh"
00081 #include "G4TransportationManager.hh"
00082 #include "G4ProcessManager.hh"
00083
00084 #include <cstdlib>
00085 #include <vector>
00086
00087 using namespace std;
00088
00089
00090
00091
00092
00093
00094 namespace cms
00095 {
00096 DigitizerFP420::DigitizerFP420(const edm::ParameterSet& conf):conf_(conf),stripDigitizer_(new FP420DigiMain(conf)) {
00097
00098
00099 std::string alias ( conf.getParameter<std::string>("@module_label") );
00100
00101
00102
00103 produces<DigiCollectionFP420>().setBranchAlias( alias );
00104
00105 trackerContainers.clear();
00106 trackerContainers = conf.getParameter<std::vector<std::string> >("ROUList");
00107
00108 verbosity = conf_.getUntrackedParameter<int>("VerbosityLevel");
00109 dn0 = conf_.getParameter<int>("NumberFP420Detectors");
00110 sn0 = conf_.getParameter<int>("NumberFP420Stations");
00111 pn0 = conf_.getParameter<int>("NumberFP420SPlanes");
00112 rn0 = 7;
00113
00114 theFP420NumberingScheme = new FP420NumberingScheme();
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 if(verbosity>0) {
00130 std::cout << "Creating a DigitizerFP420" << std::endl;
00131 std::cout << "DigitizerFP420: dn0=" << dn0 << " sn0=" << sn0 << " pn0=" << pn0 << " rn0=" << rn0 << std::endl;
00132 std::cout << "DigitizerFP420:trackerContainers.size()=" << trackerContainers.size() << std::endl;
00133
00134 }
00135 }
00136
00137
00138 DigitizerFP420::~DigitizerFP420() {
00139 if(verbosity>0) {
00140 std::cout << "Destroying a DigitizerFP420" << std::endl;
00141 }
00142 delete stripDigitizer_;
00143
00144 }
00145
00146
00147
00148
00149 void DigitizerFP420::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
00150
00151 using namespace edm;
00152 using namespace std;
00153
00154 if(verbosity>0) {
00155 std::cout <<" ===" << std::endl;
00156 std::cout <<" ============== DigitizerFP420: start produce= " << std::endl;
00157 std::cout <<" ===" << std::endl;
00158 }
00159
00160
00161
00162
00163
00164
00165
00166
00167 edm::Handle<CrossingFrame<PSimHit> > cf_simhit;
00168 std::vector<const CrossingFrame<PSimHit> *> cf_simhitvec;
00169 for(uint32_t i = 0; i< trackerContainers.size();i++){
00170 iEvent.getByLabel("mix",trackerContainers[i],cf_simhit);
00171 cf_simhitvec.push_back(cf_simhit.product()); }
00172 std::auto_ptr<MixCollection<PSimHit> > allTrackerHits(new MixCollection<PSimHit>(cf_simhitvec));
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00209
00210 std::auto_ptr<DigiCollectionFP420> output(new DigiCollectionFP420);
00211
00212
00213
00214
00215 SimHitMap.clear();
00216
00217
00218 if(verbosity>0) {
00219 std::cout <<" ===" << std::endl;
00220 std::cout <<" ============== DigitizerFP420: MixCollection treatment= " << std::endl;
00221 std::cout <<" ===" << std::endl;
00222 }
00223
00224 MixCollection<PSimHit>::iterator isim;
00225 for (isim=allTrackerHits->begin(); isim!= allTrackerHits->end();isim++) {
00226 unsigned int unitID = (*isim).detUnitId();
00227 int det, zside, sector, zmodule;
00228 FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
00229
00230
00231 unsigned int intindex = theFP420NumberingScheme->FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
00232
00233
00234
00235 if(verbosity>0) {
00236 double losenergy = (*isim).energyLoss();
00237 std::cout <<" ===" << std::endl;
00238 std::cout <<" ============== DigitizerFP420: losenergy= " << losenergy << std::endl;
00239 std::cout <<" === for intindex = " << intindex << std::endl;
00240 }
00241
00242 SimHitMap[intindex].push_back((*isim));
00243
00244
00245 }
00246
00247
00248 if(verbosity>0) {
00249 std::cout <<" ===" << std::endl;
00250 std::cout <<" ============== DigitizerFP420: put zero to container " << std::endl;
00251 std::cout <<" ===" << std::endl;
00252 }
00253
00254
00255 for (int det=1; det<dn0; det++) {
00256 for (int sector=1; sector<sn0; sector++) {
00257 for (int zmodule=1; zmodule<pn0; zmodule++) {
00258 for (int zside=1; zside<rn0; zside++) {
00259
00260 unsigned int detID = theFP420NumberingScheme->FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
00261
00262
00263 std::vector<HDigiFP420> collector;
00264 collector.clear();
00265 DigiCollectionFP420::Range inputRange;
00266 inputRange.first = collector.begin();
00267 inputRange.second = collector.end();
00268 output->putclear(inputRange,detID);
00269 }
00270 }
00271 }
00272 }
00273
00274
00275 output->clear();
00276
00277
00278
00279
00280 if(verbosity>0) {
00281 std::cout <<" ===" << std::endl;
00282 std::cout <<" ============== DigitizerFP420: start loop over det iu " << std::endl;
00283 std::cout <<" ============== DigitizerFP420: SimHitMap.size()= " << SimHitMap.size() << std::endl;
00284 std::cout <<" ===" << std::endl;
00285 }
00286 bool first = true;
00287
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00307
00308
00309 for(unsigned int i = 0; i < SimHitMap.size(); i++ ) {
00310 vector<PSimHit>::const_iterator simHitIter = SimHitMap[i].begin();
00311 vector<PSimHit>::const_iterator simHitIterEnd = SimHitMap[i].end();
00312 for (;simHitIter != simHitIterEnd; ++simHitIter) {
00313 const PSimHit ihit = *simHitIter;
00314 unsigned int unitID = ihit.detUnitId();
00315 if(verbosity>0 || verbosity==-50) std::cout <<" ====== DigitizerFP420: unitID= " << unitID << "Hit number i= " << i << std::endl;
00316 int det, zside, sector, zmodule;
00317 FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330 unsigned int iu = theFP420NumberingScheme->FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
00331 if(verbosity>0 || verbosity==-50) std::cout <<"for Hits iu = " << iu <<" sector = " << sector <<" zmodule = " << zmodule <<" zside = " << zside << " det=" << det << std::endl;
00332
00333
00334
00335 if(verbosity>0) {
00336 unsigned int index = theFP420NumberingScheme->FP420NumberingScheme::packFP420Index(det, zside, sector, zmodule);
00337 std::cout << " DigitizerFP420: index = " << index << " iu = " << iu << std::endl;
00338 }
00339
00340
00341
00342 G4ThreeVector bfield( 0., 0., 0.0 );
00343
00344
00345
00346 if(verbosity>0) {
00347 std::cout <<" ===" << std::endl;
00348 std::cout <<" ============== DigitizerFP420: call run for iu= " << iu << std::endl;
00349 std::cout <<" ===" << std::endl;
00350 }
00351 collector.clear();
00352
00353 collector= stripDigitizer_->run( SimHitMap[iu],
00354 bfield,
00355 iu
00356 );
00357
00358
00359
00360
00361 if(verbosity>0) {
00362 std::cout <<" ===" << std::endl;
00363 std::cout <<" ===" << std::endl;
00364 std::cout <<"======= DigitizerFP420: collector size = " << collector.size() << std::endl;
00365 std::cout <<" ===" << std::endl;
00366 std::cout <<" ===" << std::endl;
00367 }
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377 if (collector.size()>0){
00378 if(verbosity>0) {
00379 std::cout <<" ============= DigitizerFP420:collector start!!!!!!!!!!!!!!" << std::endl;
00380 }
00381 DigiCollectionFP420::Range outputRange;
00382 outputRange.first = collector.begin();
00383 outputRange.second = collector.end();
00384
00385 if ( first ) {
00386
00387 first = false;
00388 unsigned int detID0= 0;
00389 output->put(outputRange,detID0);
00390 }
00391
00392
00393 output->put(outputRange,iu);
00394
00395 }
00396
00397
00398
00399
00400
00401
00402 }
00403 }
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428 if(verbosity==-50) {
00429
00430 for (int det=1; det<dn0; det++) {
00431 for (int sector=1; sector<sn0; sector++) {
00432 for (int zmodule=1; zmodule<pn0; zmodule++) {
00433 for (int zside=1; zside<rn0; zside++) {
00434 unsigned int iu = theFP420NumberingScheme->FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
00435 int layer = theFP420NumberingScheme->FP420NumberingScheme::unpackLayerIndex(rn0,zside);
00436 int orient = theFP420NumberingScheme->FP420NumberingScheme::unpackOrientation(rn0,zside);
00437 std::cout << "****DigitizerFP420:check2" << std::endl;
00438
00439
00440 int newdet, newzside, newsector, newzmodule;
00441 theFP420NumberingScheme->FP420NumberingScheme::unpackMYIndex(iu, rn0, pn0, sn0, newdet, newzside, newsector, newzmodule);
00442 std::cout <<" newdet = " << newdet <<" newsector = " << newsector <<" newzmodule = " << newzmodule <<" newzside = " << newzside << std::endl;
00443
00444 collector.clear();
00445 DigiCollectionFP420::Range outputRange;
00446
00447 outputRange = output->get(iu);
00448
00449
00450 std::vector<HDigiFP420> collector;
00451
00452 DigiCollectionFP420::ContainerIterator sort_begin = outputRange.first;
00453 DigiCollectionFP420::ContainerIterator sort_end = outputRange.second;
00454 for ( ;sort_begin != sort_end; ++sort_begin ) {
00455 collector.push_back(*sort_begin);
00456 }
00457
00458 std::cout <<" ===" << std::endl;
00459 std::cout <<"====== collector size = " << collector.size() << std::endl;
00460 if(collector.size()>0) {
00461 std::cout <<" iu = " << iu <<" sector = " << sector <<" zmodule = " << zmodule <<" zside = " << zside << " det=" << det <<" layer = " << layer <<" orient = " << orient << std::endl;
00462 std::cout <<" ===" << std::endl;
00463 }
00464 vector<HDigiFP420>::const_iterator simHitIter = collector.begin();
00465 vector<HDigiFP420>::const_iterator simHitIterEnd = collector.end();
00466 for (;simHitIter != simHitIterEnd; ++simHitIter) {
00467 const HDigiFP420 istrip = *simHitIter;
00468 std::cout << " strip number=" << istrip.strip() << " adc=" << istrip.adc() << std::endl;
00469 std::cout <<" channel =" << istrip.channel() <<" V " << istrip.stripV() <<" VW " << istrip.stripVW() << std::endl;
00470 std::cout <<" ===" << std::endl;
00471 std::cout <<" ===" << std::endl;
00472 std::cout <<" ===================================================" << std::endl;
00473 }
00474
00475
00476
00477 }
00478 }
00479 }
00480 }
00481
00482
00483
00484 }
00485
00486
00487
00488
00489
00490
00491 if(verbosity>0) {
00492 std::cout << "DigitizerFP420 recoutput" << std::endl;
00493 }
00494
00495 iEvent.put(output);
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509 }
00510
00511 }
00512
00513
00514
00515
00516