00001
00002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00003
00004
00005 #include "FastSimulation/Calorimetry/interface/CalorimetryManager.h"
00006 #include "FastSimulation/Event/interface/FSimEvent.h"
00007 #include "FastSimulation/Event/interface/FSimTrack.h"
00008 #include "FastSimulation/ShowerDevelopment/interface/EMECALShowerParametrization.h"
00009 #include "FastSimulation/ShowerDevelopment/interface/EMShower.h"
00010 #include "FastSimulation/ShowerDevelopment/interface/HDShowerParametrization.h"
00011 #include "FastSimulation/ShowerDevelopment/interface/HDShower.h"
00012 #include "FastSimulation/ShowerDevelopment/interface/HFShower.h"
00013 #include "FastSimulation/ShowerDevelopment/interface/HDRShower.h"
00014 #include "FastSimulation/ShowerDevelopment/interface/HSParameters.h"
00015 #include "FastSimulation/CaloGeometryTools/interface/CaloGeometryHelper.h"
00016 #include "FastSimulation/CaloHitMakers/interface/EcalHitMaker.h"
00017 #include "FastSimulation/CaloHitMakers/interface/HcalHitMaker.h"
00018 #include "FastSimulation/CaloHitMakers/interface/PreshowerHitMaker.h"
00019
00020 #include "FastSimulation/Utilities/interface/RandomEngine.h"
00021 #include "FastSimulation/Utilities/interface/GammaFunctionGenerator.h"
00022 #include "FastSimulation/Utilities/interface/LandauFluctuationGenerator.h"
00023 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
00024 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00025 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00026 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00027 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00028
00029
00030 #include <vector>
00031 #include <iostream>
00032
00033
00034 #include "DataFormats/DetId/interface/DetId.h"
00035 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00036
00037
00038 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00039
00040 using namespace edm;
00041
00042 typedef math::XYZVector XYZVector;
00043 typedef math::XYZVector XYZPoint;
00044
00045 std::vector<std::pair<int,float> > CalorimetryManager::myZero_ = std::vector<std::pair<int,float> >
00046 (1,std::pair<int,float>(0,0.));
00047
00048 CalorimetryManager::CalorimetryManager() :
00049 myCalorimeter_(0),
00050 myHistos(0),
00051 random(0),initialized_(false)
00052 {;}
00053
00054 CalorimetryManager::CalorimetryManager(FSimEvent * aSimEvent,
00055 const edm::ParameterSet& fastCalo,
00056 const RandomEngine* engine)
00057 :
00058 mySimEvent(aSimEvent),
00059 random(engine),initialized_(false)
00060
00061 {
00062
00063 aLandauGenerator = new LandauFluctuationGenerator(random);
00064 aGammaGenerator = new GammaFunctionGenerator(random);
00065
00066 readParameters(fastCalo);
00067
00068
00069
00070
00071 EBMapping_.resize(62000);
00072 EEMapping_.resize(20000);
00073 HMapping_.resize(10000);
00074 theDetIds_.resize(10000);
00075
00076 unsigned s=(unfoldedMode_)?5:1;
00077 for(unsigned ic=0;ic<62000;++ic)
00078 {
00079 EBMapping_[ic].reserve(s);
00080 if(ic<20000)
00081 EEMapping_[ic].reserve(s);
00082 if(ic<10000)
00083 HMapping_[ic].reserve(s);
00084 }
00085
00086
00087
00088 myHistos = 0;
00089 #ifdef FAMOSDEBUG
00090 myHistos = Histos::instance();
00091 myHistos->book("h10",140,-3.5,3.5,100,-0.5,99.5);
00092 myHistos->book("h20",150,0,150.,100,-0.5,99.5);
00093 myHistos->book("h100",140,-3.5,3.5,100,0,0.1);
00094 myHistos->book("h110",140,-3.5,3.5,100,0,10.);
00095 myHistos->book("h120",200,-5.,5.,100,0,0.5);
00096
00097 myHistos->book("h200",300,0,3.,100,0.,35.);
00098 myHistos->book("h210",720,-M_PI,M_PI,100,0,35.);
00099 myHistos->book("h212",720,-M_PI,M_PI,100,0,35.);
00100
00101 myHistos->bookByNumber("h30",0,7,300,-3.,3.,100,0.,35.);
00102 myHistos->book("h310",75,-3.,3.,"");
00103 myHistos->book("h400",100,-10.,10.,100,0.,35.);
00104 myHistos->book("h410",720,-M_PI,M_PI);
00105 #endif
00106 myCalorimeter_ =
00107 new CaloGeometryHelper(fastCalo);
00108 myHDResponse_ =
00109 new HCALResponse(fastCalo.getParameter<edm::ParameterSet>("HCALResponse"),
00110 random);
00111 myHSParameters_ =
00112 new HSParameters(fastCalo.getParameter<edm::ParameterSet>("HSParameters"));
00113
00114
00115 }
00116
00117 void CalorimetryManager::clean()
00118 {
00119 unsigned size=firedCellsEB_.size();
00120 for(unsigned ic=0;ic<size;++ic)
00121 {
00122 EBMapping_[firedCellsEB_[ic]].clear();
00123 }
00124 firedCellsEB_.clear();
00125
00126 size=firedCellsEE_.size();
00127 for(unsigned ic=0;ic<size;++ic)
00128 {
00129 EEMapping_[firedCellsEE_[ic]].clear();
00130 }
00131 firedCellsEE_.clear();
00132
00133 size=firedCellsHCAL_.size();
00134 for(unsigned ic=0;ic<size;++ic)
00135 {
00136 HMapping_[firedCellsHCAL_[ic]].clear();
00137 }
00138 firedCellsHCAL_.clear();
00139
00140 ESMapping_.clear();
00141
00142 }
00143
00144 CalorimetryManager::~CalorimetryManager()
00145 {
00146 #ifdef FAMOSDEBUG
00147 myHistos->put("Famos.root");
00148 #endif
00149 if(myCalorimeter_) delete myCalorimeter_;
00150 if(myHDResponse_) delete myHDResponse_;
00151 }
00152
00153 void CalorimetryManager::reconstruct()
00154 {
00155
00156 if(!initialized_)
00157 {
00158 const CaloSubdetectorGeometry* geom=myCalorimeter_->getHcalGeometry();
00159 for(int subdetn=1;subdetn<=4;++subdetn)
00160 {
00161 const std::vector<DetId>& ids(geom->getValidDetIds(DetId::Hcal,subdetn));
00162 for (std::vector<DetId>::const_iterator i=ids.begin(); i!=ids.end(); i++)
00163 {
00164 HcalDetId myDetId(*i);
00165 unsigned hi=myDetId.hashed_index();
00166 theDetIds_[hi]=myDetId;
00167 }
00168 }
00169
00170
00171 if(simulatePreshower_ && !myCalorimeter_->preshowerPresent())
00172 {
00173 std::cout << " WARNING " << std::endl;
00174 std::cout << " The preshower simulation has been turned on; but no preshower geometry is available " << std::endl;
00175 std::cout << " Disabling the preshower simulation " << std::endl;
00176 simulatePreshower_ = false;
00177 }
00178
00179 initialized_=true;
00180 }
00181 clean();
00182
00183 LogInfo("FastCalorimetry") << "Reconstructing " << (int) mySimEvent->nTracks() << " tracks." << std::endl;
00184 for( int fsimi=0; fsimi < (int) mySimEvent->nTracks() ; ++fsimi) {
00185
00186 FSimTrack& myTrack = mySimEvent->track(fsimi);
00187
00188 int pid = abs(myTrack.type());
00189
00190 if (debug_) {
00191 LogDebug("FastCalorimetry") << " ===> pid = " << pid << std::endl;
00192 }
00193
00194
00195
00196 if(myTrack.noEndVertex()) {
00197
00198 if ( pid == 11 || pid == 22 ) {
00199
00200
00201 if ( myTrack.onEcal() )
00202 EMShowerSimulation(myTrack);
00203 else if ( myTrack.onVFcal() )
00204 reconstructHCAL(myTrack);
00205
00206 }
00207
00208
00209
00210 else if ( pid < 1000000 ) {
00211 if ( myTrack.onHcal() || myTrack.onVFcal() )
00212 if(optionHDSim_ == 0 || pid == 13) reconstructHCAL(myTrack);
00213 else HDShowerSimulation(myTrack);
00214
00215 }
00216 }
00217 }
00218
00219
00220
00221
00222 }
00223
00224
00225 void CalorimetryManager::EMShowerSimulation(const FSimTrack& myTrack) {
00226 std::vector<const RawParticle*> thePart;
00227 double X0depth;
00228
00229
00230
00231
00232
00233 myPart = myTrack.ecalEntrance();
00234
00235
00236 if ( myTrack.type() == 22 && myPart.e()<0.055) return;
00237
00238
00239
00240 int onEcal = myTrack.onEcal();
00241 int onHcal = myTrack.onHcal();
00242 int onLayer1 = myTrack.onLayer1();
00243 int onLayer2 = myTrack.onLayer2();
00244
00245
00246 XYZPoint ecalentrance = myPart.vertex().Vect();
00247
00248
00249
00250
00251 PreshowerHitMaker * myPreshower = NULL ;
00252 if(simulatePreshower_ && (onLayer1 || onLayer2))
00253 {
00254 XYZPoint layer1entrance,layer2entrance;
00255 XYZVector dir1,dir2;
00256 if(onLayer1)
00257 {
00258 layer1entrance = XYZPoint(myTrack.layer1Entrance().vertex().Vect());
00259 dir1 = XYZVector(myTrack.layer1Entrance().Vect().Unit());
00260 }
00261 if(onLayer2)
00262 {
00263 layer2entrance = XYZPoint(myTrack.layer2Entrance().vertex().Vect());
00264 dir2 = XYZVector(myTrack.layer2Entrance().Vect().Unit());
00265 }
00266
00267
00268 myPreshower = new PreshowerHitMaker(myCalorimeter_,
00269 layer1entrance,
00270 dir1,
00271 layer2entrance,
00272 dir2,
00273 aLandauGenerator);
00274 }
00275
00276
00277 EMECALShowerParametrization
00278 showerparam(myCalorimeter_->ecalProperties(onEcal),
00279 myCalorimeter_->hcalProperties(onHcal),
00280 myCalorimeter_->layer1Properties(onLayer1),
00281 myCalorimeter_->layer2Properties(onLayer2),
00282 theCoreIntervals_,
00283 theTailIntervals_,
00284 RCFactor_,
00285 RTFactor_);
00286
00287
00288 if ( myTrack.type() == 22 ) {
00289
00290
00291 X0depth = -log(random->flatShoot()) * (9./7.);
00292
00293
00294 double eMass = 0.000510998902;
00295 double xe=0;
00296 double xm=eMass/myPart.e();
00297 double weight = 0.;
00298
00299
00300 do {
00301 xe = random->flatShoot()*(1.-2.*xm) + xm;
00302 weight = 1. - 4./3.*xe*(1.-xe);
00303 } while ( weight < random->flatShoot() );
00304
00305
00306 if ( myPart.e()*xe < 0.055 || myPart.e()*(1.-xe) < 0.055 ) {
00307
00308 if ( myPart.e() > 0.055 ) thePart.push_back(&myPart);
00309
00310 } else {
00311
00312 myElec = (myPart) * xe;
00313 myPosi = (myPart) * (1.-xe);
00314 myElec.setVertex(myPart.vertex());
00315 myPosi.setVertex(myPart.vertex());
00316 thePart.push_back(&myElec);
00317 thePart.push_back(&myPosi);
00318 }
00319
00320 } else {
00321
00322 X0depth = 0.;
00323 if ( myPart.e() > 0.055 ) thePart.push_back(&myPart);
00324
00325 }
00326
00327
00328 if(thePart.size()==0)
00329 {
00330 if(myPreshower==NULL) return;
00331 delete myPreshower;
00332 return;
00333 }
00334
00335
00336 double maxEnergy=-1.;
00337 for(unsigned ip=0;ip < thePart.size();++ip)
00338 if(thePart[ip]->e() > maxEnergy) maxEnergy = thePart[ip]->e();
00339
00340
00341 int size = gridSize_;
00342 if(maxEnergy>100) size=11;
00343
00344
00345
00346
00347 EMShower theShower(random,aGammaGenerator,&showerparam,&thePart);
00348
00349
00350 double depth((X0depth+theShower.getMaximumOfShower())*myCalorimeter_->ecalProperties(onEcal)->radLenIncm());
00351 XYZPoint meanShower=ecalentrance+myPart.Vect().Unit()*depth;
00352
00353
00354
00355
00356 DetId pivot(myCalorimeter_->getClosestCell(meanShower, true, onEcal==1));
00357
00358
00359
00360 EcalHitMaker myGrid(myCalorimeter_,ecalentrance,pivot,onEcal,size,0,random);
00361
00362
00363 myGrid.setPulledPadSurvivalProbability(pulledPadSurvivalProbability_);
00364 myGrid.setCrackPadSurvivalProbability(crackPadSurvivalProbability_);
00365 myGrid.setRadiusFactor(radiusFactor_);
00366 myGrid.setPreshowerPresent(simulatePreshower_);
00367
00368
00369 myGrid.setTrackParameters(myPart.Vect().Unit(),X0depth,myTrack);
00370
00371
00372
00373
00374
00375
00376
00377
00378 if(myPreshower) theShower.setPreshower(myPreshower);
00379
00380 HcalHitMaker myHcalHitMaker(myGrid,(unsigned)0);
00381
00382 theShower.setGrid(&myGrid);
00383 theShower.setHcal(&myHcalHitMaker);
00384
00385 theShower.compute();
00386
00387
00388
00389
00390 std::map<uint32_t,float>::const_iterator mapitr;
00391 std::map<uint32_t,float>::const_iterator endmapitr=myGrid.getHits().end();
00392 for(mapitr=myGrid.getHits().begin();mapitr!=endmapitr;++mapitr)
00393 {
00394 if(onEcal==1)
00395 {
00396 updateMap(EBDetId(mapitr->first).hashedIndex(), mapitr->second,myTrack.id(),EBMapping_,firedCellsEB_);
00397 }
00398
00399 else if(onEcal==2)
00400 updateMap(EEDetId(mapitr->first).hashedIndex(), mapitr->second,myTrack.id(),EEMapping_,firedCellsEE_);
00401
00402 }
00403
00404
00405 endmapitr=myHcalHitMaker.getHits().end();
00406 for(mapitr=myHcalHitMaker.getHits().begin();mapitr!=endmapitr;++mapitr)
00407 {
00408 updateMap(HcalDetId(mapitr->first).hashed_index(),mapitr->second,myTrack.id(),HMapping_,firedCellsHCAL_);
00409
00410 }
00411
00412
00413 if(myPreshower!=0)
00414 {
00415 endmapitr=myPreshower->getHits().end();
00416 for(mapitr=myPreshower->getHits().begin();mapitr!=endmapitr;++mapitr)
00417 {
00418 updateMap(mapitr->first,mapitr->second,myTrack.id(),ESMapping_);
00419
00420 }
00421 delete myPreshower;
00422 }
00423
00424
00425 }
00426
00427
00428
00429
00430 void CalorimetryManager::reconstructECAL(const FSimTrack& track) {
00431 if(debug_) {
00432 XYZTLorentzVector moment = track.momentum();
00433 std::cout << "FASTEnergyReconstructor::reconstructECAL - " << std::endl
00434 << " eta " << moment.eta() << std::endl
00435 << " phi " << moment.phi() << std::endl
00436 << " et " << moment.Et() << std::endl;
00437 }
00438
00439 int hit;
00440
00441 bool central=track.onEcal()==1;
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452 XYZTLorentzVector trackPosition;
00453 if( track.onEcal() ) {
00454 hit=track.onEcal()-1;
00455 trackPosition=track.ecalEntrance().vertex();
00456 } else {
00457 hit=2;
00458 trackPosition=track.vfcalEntrance().vertex();
00459 }
00460
00461 double pathEta = trackPosition.eta();
00462 double pathPhi = trackPosition.phi();
00463 double EGen = track.ecalEntrance().e();
00464
00465
00466 double e=0.;
00467 double sigma=0.;
00468
00469 if(hit == 2 && optionHDSim_ == 2 ) {
00470 std::pair<double,double> response =
00471 myHDResponse_->responseHCAL(0, EGen, pathEta, 0);
00472 e = response.first;
00473 sigma = response.second;
00474 }
00475
00476 double emeas = 0.;
00477
00478 if(sigma>0.)
00479 emeas = random->gaussShoot(e,sigma);
00480
00481
00482 if(debug_)
00483 std::cout << "FASTEnergyReconstructor::reconstructECAL : "
00484 << " on-calo eta, phi = " << pathEta << " " << pathPhi << std::endl
00485 << " Egen = " << EGen << std::endl
00486 << " Eres = " << e << std::endl
00487 << " sigma = " << sigma << std::endl
00488 << " Emeas = " << emeas << std::endl;
00489
00490
00491 if(debug_)
00492 std::cout << "FASTEnergyReconstructor::reconstructECAL : "
00493 << " Track position - " << trackPosition.Vect()
00494 << " bool central - " << central
00495 << " hit - " << hit << std::endl;
00496
00497 DetId detid;
00498 if( hit==2 )
00499 detid = myCalorimeter_->getClosestCell(trackPosition.Vect(),false,central);
00500
00501 HcalDetId hdetid(detid);
00502 if(!hdetid.subdetId()!=HcalForward) return;
00503
00504 if(debug_)
00505 std::cout << "FASTEnergyReconstructor::reconstructECAL : "
00506 << " CellID - " << detid.rawId() << std::endl;
00507
00508 if( hit != 2 || emeas > 0.)
00509 if(!detid.null())
00510 {
00511 updateMap(hdetid.hashed_index(),emeas,track.id(),HMapping_,firedCellsHCAL_);
00512 }
00513
00514 }
00515
00516
00517 void CalorimetryManager::reconstructHCAL(const FSimTrack& myTrack)
00518 {
00519 int hit;
00520 int pid = abs(myTrack.type());
00521
00522
00523
00524
00525
00526 XYZTLorentzVector trackPosition;
00527 if (myTrack.onHcal()) {
00528 trackPosition=myTrack.hcalEntrance().vertex();
00529 hit = myTrack.onHcal()-1;
00530 } else {
00531 trackPosition=myTrack.vfcalEntrance().vertex();
00532 hit = 2;
00533 }
00534
00535 double pathEta = trackPosition.eta();
00536 double pathPhi = trackPosition.phi();
00537
00538
00539 double EGen = myTrack.hcalEntrance().e();
00540 double e = 0.;
00541 double sigma = 0.;
00542 double emeas = 0.;
00543
00544 if(pid == 13) {
00545 std::pair<double,double> response =
00546 myHDResponse_->responseHCAL(0, EGen, pathEta, 2);
00547 emeas = response.first;
00548 if(debug_)
00549 LogDebug("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - MUON !!!" << std::endl;
00550 }
00551 else if( pid == 22 || pid == 11)
00552 {
00553
00554 std::pair<double,double> response =
00555 myHDResponse_->responseHCAL(0, EGen, pathEta, 0);
00556 e = response.first;
00557 sigma = response.second;
00558 emeas = random->gaussShoot(e,sigma);
00559
00560
00561 if(debug_)
00562 LogDebug("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - e/gamma !!!" << std::endl;
00563 }
00564 else {
00565 e = myHDResponse_->getHCALEnergyResponse(EGen,hit);
00566 sigma = myHDResponse_->getHCALEnergyResolution(EGen, hit);
00567
00568 emeas = random->gaussShoot(e,sigma);
00569 }
00570
00571
00572 if(debug_)
00573 LogDebug("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - on-calo "
00574 << " eta = " << pathEta
00575 << " phi = " << pathPhi
00576 << " Egen = " << EGen
00577 << " Eres = " << e
00578 << " sigma = " << sigma
00579 << " Emeas = " << emeas << std::endl;
00580
00581 if(emeas > 0.) {
00582 DetId cell = myCalorimeter_->getClosestCell(trackPosition.Vect(),false,false);
00583 updateMap(HcalDetId(cell).hashed_index(), emeas, myTrack.id(),HMapping_,firedCellsHCAL_);
00584 }
00585 }
00586
00587 void CalorimetryManager::HDShowerSimulation(const FSimTrack& myTrack)
00588 {
00589
00590 XYZTLorentzVector moment = myTrack.momentum();
00591
00592 if(debug_)
00593 LogDebug("FastCalorimetry") << "CalorimetryManager::HDShowerSimulation - track param."
00594 << std::endl
00595 << " eta = " << moment.eta() << std::endl
00596 << " phi = " << moment.phi() << std::endl
00597 << " et = " << moment.Et() << std::endl;
00598
00599 int hit;
00600
00601
00602 XYZTLorentzVector trackPosition;
00603 if ( myTrack.onEcal() ) {
00604 trackPosition=myTrack.ecalEntrance().vertex();
00605 hit = myTrack.onEcal()-1;
00606 myPart = myTrack.ecalEntrance();
00607 } else if ( myTrack.onVFcal()) {
00608 trackPosition=myTrack.vfcalEntrance().vertex();
00609 hit = 2;
00610 myPart = myTrack.vfcalEntrance();
00611 }
00612 else
00613 {
00614 LogDebug("FastCalorimetry") << " The particle is not in the acceptance " << std::endl;
00615 return;
00616 }
00617
00618
00619
00620 int onHCAL = hit + 1;
00621 int onECAL = myTrack.onEcal();
00622
00623 double pathEta = trackPosition.eta();
00624 double pathPhi = trackPosition.phi();
00625
00626
00627 double eGen = myTrack.hcalEntrance().e();
00628 double e = 0.;
00629 double sigma = 0.;
00630
00631 double emeas = 0.;
00632
00633
00634 if(eGen > 0.) {
00635
00636
00637 HDShowerParametrization
00638 theHDShowerparam(myCalorimeter_->ecalProperties(onECAL),
00639 myCalorimeter_->hcalProperties(onHCAL),
00640 myHSParameters_);
00641
00642
00643 XYZPoint caloentrance;
00644 XYZVector direction;
00645 if(myTrack.onEcal())
00646 {
00647 caloentrance = myTrack.ecalEntrance().vertex().Vect();
00648 direction = myTrack.ecalEntrance().Vect().Unit();
00649 }
00650 else if(myTrack.onHcal())
00651 {
00652 caloentrance = myTrack.hcalEntrance().vertex().Vect();
00653 direction = myTrack.hcalEntrance().Vect().Unit();
00654 }
00655 else
00656 {
00657 caloentrance = myTrack.vfcalEntrance().vertex().Vect();
00658 direction = myTrack.vfcalEntrance().Vect().Unit();
00659 }
00660
00661 DetId pivot;
00662 if(myTrack.onEcal())
00663 {
00664 pivot=myCalorimeter_->getClosestCell(caloentrance,
00665 true, myTrack.onEcal()==1);
00666 }
00667 else if(myTrack.onHcal())
00668 {
00669
00670 pivot=myCalorimeter_->getClosestCell(caloentrance,
00671 false, false);
00672 }
00673
00674 EcalHitMaker myGrid(myCalorimeter_,caloentrance,pivot,
00675 pivot.null()? 0 : myTrack.onEcal(),hdGridSize_,1,
00676 random);
00677
00678
00679 myGrid.setTrackParameters(direction,0,myTrack);
00680
00681 HcalHitMaker myHcalHitMaker(myGrid,(unsigned)1);
00682
00683
00684 bool status;
00685 int mip = 2;
00686
00687 if ( !myTrack.onEcal() && !myTrack.onHcal() ) {
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698 HFShower theShower(random,
00699 &theHDShowerparam,
00700 &myGrid,
00701 &myHcalHitMaker,
00702 onECAL,
00703 eGen);
00704
00705
00706
00707 status = theShower.compute();
00708 } else {
00709 if(hdSimMethod_ == 0) {
00710 HDShower theShower(random,
00711 &theHDShowerparam,
00712 &myGrid,
00713 &myHcalHitMaker,
00714 onECAL,
00715 eGen);
00716 status = theShower.compute();
00717 mip = theShower.getmip();
00718 }
00719 else {
00720 HDRShower theShower(random,
00721 &theHDShowerparam,
00722 &myGrid,
00723 &myHcalHitMaker,
00724 onECAL,
00725 eGen);
00726 status = theShower.computeShower();
00727 mip = 2;
00728 }
00729 }
00730
00731 if(status) {
00732
00733
00734 if(optionHDSim_ == 1) {
00735 e = myHDResponse_->getHCALEnergyResponse (eGen, hit);
00736 sigma = myHDResponse_->getHCALEnergyResolution(eGen, hit);
00737 }
00738 else {
00739 std::pair<double,double> response =
00740 myHDResponse_->responseHCAL(mip, eGen, pathEta, 1);
00741 e = response.first;
00742 sigma = response.second;
00743 }
00744
00745 emeas = random->gaussShoot(e,sigma);
00746 double correction = emeas / eGen;
00747
00748 if(debug_)
00749 LogDebug("FastCalorimetry")
00750 << "CalorimetryManager::HDShowerSimulation - on-calo " << std::endl
00751 << " eta = " << pathEta << std::endl
00752 << " phi = " << pathPhi << std::endl
00753 << " Egen = " << eGen << std::endl
00754 << " Eres = " << e << std::endl
00755 << " sigma = " << sigma << std::endl
00756 << " Emeas = " << emeas << std::endl;
00757
00758
00759
00760 std::map<unsigned,float>::const_iterator mapitr;
00761 std::map<unsigned,float>::const_iterator endmapitr;
00762 if(myTrack.onEcal() > 0) {
00763
00764 endmapitr=myGrid.getHits().end();
00765 for(mapitr=myGrid.getHits().begin(); mapitr!=endmapitr; ++mapitr) {
00766 double energy = mapitr->second;
00767 energy *= correction;
00768 if(energy > 0.000001) {
00769 if(onECAL==1)
00770 updateMap(EBDetId(mapitr->first).hashedIndex(),energy,myTrack.id(),EBMapping_,firedCellsEB_);
00771
00772 else if(onECAL==2)
00773 updateMap(EEDetId(mapitr->first).hashedIndex(),energy,myTrack.id(),EEMapping_,firedCellsEE_);
00774
00775 if(debug_)
00776 LogDebug("FastCalorimetry") << " ECAL cell " << mapitr->first << " added, E = "
00777 << energy << std::endl;
00778 }
00779 }
00780 }
00781
00782
00783 endmapitr=myHcalHitMaker.getHits().end();
00784 for(mapitr=myHcalHitMaker.getHits().begin(); mapitr!=endmapitr; ++mapitr) {
00785 double energy = mapitr->second;
00786 energy *= correction;
00787
00788 updateMap(HcalDetId(mapitr->first).hashed_index(),energy,myTrack.id(),HMapping_,firedCellsHCAL_);
00789 if(debug_)
00790 LogDebug("FastCalorimetry") << " HCAL cell "
00791 << mapitr->first << " added E = "
00792 << mapitr->second << std::endl;
00793 }
00794 }
00795 else {
00796
00797
00798
00799
00800 if(myTrack.onHcal() || myTrack.onVFcal())
00801 {
00802 DetId cell = myCalorimeter_->getClosestCell(trackPosition.Vect(),false,false);
00803 updateMap(HcalDetId(cell).hashed_index(),emeas,myTrack.id(),HMapping_,firedCellsHCAL_);
00804 if(debug_)
00805 LogDebug("FastCalorimetry") << " HCAL simple cell "
00806 << cell.rawId() << " added E = "
00807 << emeas << std::endl;
00808 }
00809 }
00810
00811 }
00812
00813 if(debug_)
00814 LogDebug("FastCalorimetry") << std::endl << " FASTEnergyReconstructor::HDShowerSimulation finished "
00815 << std::endl;
00816 }
00817
00818
00819
00820 void CalorimetryManager::readParameters(const edm::ParameterSet& fastCalo) {
00821 edm::ParameterSet ECALparameters = fastCalo.getParameter<edm::ParameterSet>("ECAL");
00822 gridSize_ = ECALparameters.getParameter<int>("GridSize");
00823 spotFraction_ = ECALparameters.getParameter<double>("SpotFraction");
00824 pulledPadSurvivalProbability_ = ECALparameters.getParameter<double>("FrontLeakageProbability");
00825 crackPadSurvivalProbability_ = ECALparameters.getParameter<double>("GapLossProbability");
00826 debug_ = ECALparameters.getUntrackedParameter<bool>("Debug");
00827
00828 theCoreIntervals_ = ECALparameters.getParameter<std::vector<double> >("CoreIntervals");
00829 theTailIntervals_ = ECALparameters.getParameter<std::vector<double> >("TailIntervals");
00830
00831 RCFactor_ = ECALparameters.getParameter<double>("RCFactor");
00832 RTFactor_ = ECALparameters.getParameter<double>("RTFactor");
00833 radiusFactor_ = ECALparameters.getParameter<double>("RadiusFactor");
00834 simulatePreshower_ = ECALparameters.getParameter<bool>("SimulatePreshower");
00835
00836 if(gridSize_ <1) gridSize_= 7;
00837 if(pulledPadSurvivalProbability_ <0. || pulledPadSurvivalProbability_>1 ) pulledPadSurvivalProbability_= 1.;
00838 if(crackPadSurvivalProbability_ <0. || crackPadSurvivalProbability_>1 ) crackPadSurvivalProbability_= 0.9;
00839
00840 LogInfo("FastCalorimetry") << " Fast ECAL simulation parameters " << std::endl;
00841 LogInfo("FastCalorimetry") << " =============================== " << std::endl;
00842 if(simulatePreshower_)
00843 LogInfo("FastCalorimetry") << " The preshower is present " << std::endl;
00844 else
00845 LogInfo("FastCalorimetry") << " The preshower is NOT present " << std::endl;
00846 LogInfo("FastCalorimetry") << " Grid Size : " << gridSize_ << std::endl;
00847 if(spotFraction_>0.)
00848 LogInfo("FastCalorimetry") << " Spot Fraction : " << spotFraction_ << std::endl;
00849 else
00850 {
00851 LogInfo("FastCalorimetry") << " Core of the shower " << std::endl;
00852 for(unsigned ir=0; ir < theCoreIntervals_.size()/2;++ir)
00853 {
00854 LogInfo("FastCalorimetry") << " r < " << theCoreIntervals_[ir*2] << " R_M : " << theCoreIntervals_[ir*2+1] << " ";
00855 }
00856 LogInfo("FastCalorimetry") << std::endl;
00857
00858 LogInfo("FastCalorimetry") << " Tail of the shower " << std::endl;
00859 for(unsigned ir=0; ir < theTailIntervals_.size()/2;++ir)
00860 {
00861 LogInfo("FastCalorimetry") << " r < " << theTailIntervals_[ir*2] << " R_M : " << theTailIntervals_[ir*2+1] << " ";
00862 }
00863 LogInfo("FastCalotimetry") << "Radius correction factor " << radiusFactor_ << std::endl;
00864 LogInfo("FastCalorimetry") << std::endl;
00865 }
00866
00867 LogInfo("FastCalorimetry") << " FrontLeakageProbability : " << pulledPadSurvivalProbability_ << std::endl;
00868 LogInfo("FastCalorimetry") << " GapLossProbability : " << crackPadSurvivalProbability_ << std::endl;
00869
00870
00871 edm::ParameterSet HCALparameters = fastCalo.getParameter<edm::ParameterSet>("HCAL");
00872 optionHDSim_ = HCALparameters.getParameter<int>("SimOption");
00873 hdGridSize_ = HCALparameters.getParameter<int>("GridSize");
00874 hdSimMethod_ = HCALparameters.getParameter<int>("SimMethod");
00875
00876
00877 unfoldedMode_ = fastCalo.getUntrackedParameter<bool>("UnfoldedMode",false);
00878 }
00879
00880
00881 void CalorimetryManager::updateMap(uint32_t cellid,float energy,int id,std::map<uint32_t,std::vector<std::pair<int,float> > > & mymap)
00882 {
00883
00884 std::map<unsigned,std::vector<std::pair<int,float> > >::iterator cellitr;
00885 cellitr = mymap.find(cellid);
00886 if(!unfoldedMode_) id=0;
00887 if( cellitr==mymap.end())
00888 {
00889 std::vector<std::pair<int,float> > myElement;
00890 myElement.push_back(std::pair<int,float> (id,energy));
00891 mymap[cellid]=myElement;
00892 }
00893 else
00894 {
00895 if(!unfoldedMode_)
00896 {
00897 cellitr->second[0].second+=energy;
00898 }
00899 else
00900 cellitr->second.push_back(std::pair<int,float>(id,energy));
00901 }
00902 }
00903
00904 void CalorimetryManager::updateMap(int hi,float energy,int tid,std::vector<std::vector<std::pair<int,float> > > & mymap, std::vector<int>& firedCells)
00905 {
00906
00907 if(!unfoldedMode_)
00908 {
00909
00910 if(mymap[hi].size()==0)
00911 {
00912 firedCells.push_back(hi);
00913 mymap[hi].push_back(std::pair<int,float>(0,energy));
00914 }
00915 else
00916 mymap[hi][0].second+=energy;
00917 }
00918 else
00919 {
00920
00921
00922
00923 if(mymap[hi].size()==0)
00924 {
00925
00926 firedCells.push_back(hi);
00927 }
00928
00929 mymap[hi].push_back(std::pair<int,float>(tid,energy));
00930 }
00931
00932 }
00933
00934 void CalorimetryManager::loadFromEcalBarrel(edm::PCaloHitContainer & c) const
00935 {
00936 unsigned size=firedCellsEB_.size();
00937
00938 for(unsigned ic=0;ic<size;++ic)
00939 {
00940 int hi=firedCellsEB_[ic];
00941 if(!unfoldedMode_)
00942 {
00943 c.push_back(PCaloHit(EBDetId::unhashIndex(hi),EBMapping_[hi][0].second,0.,0));
00944
00945
00946 }
00947 else
00948 {
00949 unsigned npart=EBMapping_[hi].size();
00950 for(unsigned ip=0;ip<npart;++ip)
00951 {
00952 c.push_back(PCaloHit(EBDetId::unhashIndex(hi),EBMapping_[hi][ip].second,0.,
00953 EBMapping_[hi][ip].first));
00954
00955 }
00956 }
00957
00958
00959 }
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977 }
00978
00979
00980 void CalorimetryManager::loadFromEcalEndcap(edm::PCaloHitContainer & c) const
00981 {
00982 unsigned size=firedCellsEE_.size();
00983
00984 for(unsigned ic=0;ic<size;++ic)
00985 {
00986 int hi=firedCellsEE_[ic];
00987 if(!unfoldedMode_)
00988 c.push_back(PCaloHit(EEDetId::unhashIndex(hi),EEMapping_[hi][0].second,0.,0));
00989 else
00990 {
00991 unsigned npart=EEMapping_[hi].size();
00992 for(unsigned ip=0;ip<npart;++ip)
00993 c.push_back(PCaloHit(EEDetId::unhashIndex(hi),EEMapping_[hi][ip].second,0.,
00994 EEMapping_[hi][ip].first));
00995 }
00996
00997
00998 }
00999
01000
01001 }
01002
01003 void CalorimetryManager::loadFromHcal(edm::PCaloHitContainer & c) const
01004 {
01005 unsigned size=firedCellsHCAL_.size();
01006
01007 for(unsigned ic=0;ic<size;++ic)
01008 {
01009 int hi=firedCellsHCAL_[ic];
01010 if(!unfoldedMode_)
01011 c.push_back(PCaloHit(theDetIds_[hi],HMapping_[hi][0].second,0.,0));
01012 else
01013 {
01014 unsigned npart=HMapping_[hi].size();
01015 for(unsigned ip=0;ip<npart;++ip)
01016 c.push_back(PCaloHit(theDetIds_[hi],HMapping_[hi][ip].second,0.,
01017 HMapping_[hi][ip].first));
01018 }
01019
01020
01021 }
01022
01023
01024 }
01025
01026 void CalorimetryManager::loadFromPreshower(edm::PCaloHitContainer & c) const
01027 {
01028 std::map<uint32_t,std::vector<std::pair< int,float> > >::const_iterator cellit;
01029 std::map<uint32_t,std::vector<std::pair <int,float> > >::const_iterator preshEnd=ESMapping_.end();
01030
01031 for(cellit=ESMapping_.begin();cellit!=preshEnd;++cellit)
01032 {
01033 if(!unfoldedMode_)
01034 c.push_back(PCaloHit(cellit->first,cellit->second[0].second,0.,0));
01035 else
01036 {
01037 unsigned npart=cellit->second.size();
01038 for(unsigned ip=0;ip<npart;++ip)
01039 {
01040 c.push_back(PCaloHit(cellit->first,cellit->second[ip].second,0.,cellit->second[ip].first));
01041 }
01042 }
01043 }
01044 }