00001
00002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004
00005
00006 #include "FastSimulation/Calorimetry/interface/CalorimetryManager.h"
00007 #include "FastSimulation/Event/interface/FSimEvent.h"
00008 #include "FastSimulation/Event/interface/FSimTrack.h"
00009 #include "FastSimulation/ShowerDevelopment/interface/EMECALShowerParametrization.h"
00010 #include "FastSimulation/ShowerDevelopment/interface/EMShower.h"
00011 #include "FastSimulation/ShowerDevelopment/interface/HDShowerParametrization.h"
00012 #include "FastSimulation/ShowerDevelopment/interface/HDShower.h"
00013 #include "FastSimulation/ShowerDevelopment/interface/HFShower.h"
00014 #include "FastSimulation/ShowerDevelopment/interface/HDRShower.h"
00015 #include "FastSimulation/ShowerDevelopment/interface/HSParameters.h"
00016 #include "FastSimulation/CaloGeometryTools/interface/CaloGeometryHelper.h"
00017 #include "FastSimulation/CaloHitMakers/interface/EcalHitMaker.h"
00018 #include "FastSimulation/CaloHitMakers/interface/HcalHitMaker.h"
00019 #include "FastSimulation/CaloHitMakers/interface/PreshowerHitMaker.h"
00020
00021 #include "FastSimulation/Utilities/interface/RandomEngine.h"
00022 #include "FastSimulation/Utilities/interface/GammaFunctionGenerator.h"
00023 #include "FastSimulation/Utilities/interface/LandauFluctuationGenerator.h"
00024 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
00025 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00026 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00027 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00028 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00029 #include "FastSimulation/Event/interface/FSimTrackEqual.h"
00030
00031 #include "FastSimulation/MaterialEffects/interface/MaterialEffects.h"
00032 #include "FastSimulation/MaterialEffects/interface/EnergyLossSimulator.h"
00033
00034 #include "FastSimulation/MaterialEffects/interface/MuonBremsstrahlungSimulator.h"
00035
00036
00037 #include "SimGeneral/GFlash/interface/GflashHadronShowerProfile.h"
00038 #include "SimGeneral/GFlash/interface/GflashPiKShowerProfile.h"
00039 #include "SimGeneral/GFlash/interface/GflashProtonShowerProfile.h"
00040 #include "SimGeneral/GFlash/interface/GflashAntiProtonShowerProfile.h"
00041 #include "SimGeneral/GFlash/interface/GflashTrajectoryPoint.h"
00042 #include "SimGeneral/GFlash/interface/GflashHit.h"
00043 #include "SimGeneral/GFlash/interface/Gflash3Vector.h"
00044
00045 #include <vector>
00046 #include <iostream>
00047
00048
00049 #include "FWCore/ServiceRegistry/interface/Service.h"
00050 #include "DQMServices/Core/interface/DQMStore.h"
00051 #include "DQMServices/Core/interface/MonitorElement.h"
00052
00053
00054 #include "DataFormats/DetId/interface/DetId.h"
00055 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00056
00057
00058 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00059
00060 using namespace edm;
00061
00062 typedef math::XYZVector XYZVector;
00063 typedef math::XYZVector XYZPoint;
00064
00065 std::vector<std::pair<int,float> > CalorimetryManager::myZero_ = std::vector<std::pair<int,float> >
00066 (1,std::pair<int,float>(0,0.));
00067
00068 CalorimetryManager::CalorimetryManager() :
00069 myCalorimeter_(0),
00070
00071 random(0),initialized_(false)
00072 {;}
00073
00074 CalorimetryManager::CalorimetryManager(FSimEvent * aSimEvent,
00075 const edm::ParameterSet& fastCalo,
00076 const edm::ParameterSet& fastMuECAL,
00077 const edm::ParameterSet& fastMuHCAL,
00078 const edm::ParameterSet& parGflash,
00079 const RandomEngine* engine)
00080 :
00081 mySimEvent(aSimEvent),
00082 random(engine), initialized_(false),
00083 theMuonEcalEffects(0), theMuonHcalEffects (0), bFixedLength_(false)
00084
00085 {
00086
00087 aLandauGenerator = new LandauFluctuationGenerator(random);
00088 aGammaGenerator = new GammaFunctionGenerator(random);
00089
00090
00091 theProfile = new GflashHadronShowerProfile(parGflash);
00092 thePiKProfile = new GflashPiKShowerProfile(parGflash);
00093 theProtonProfile = new GflashProtonShowerProfile(parGflash);
00094 theAntiProtonProfile = new GflashAntiProtonShowerProfile(parGflash);
00095
00096 readParameters(fastCalo);
00097
00098
00099
00100
00101 EBMapping_.resize(62000);
00102 EEMapping_.resize(20000);
00103 HMapping_.resize(10000);
00104 theDetIds_.resize(10000);
00105
00106 unsigned s=(unfoldedMode_)?5:1;
00107 for(unsigned ic=0;ic<62000;++ic)
00108 {
00109 EBMapping_[ic].reserve(s);
00110 if(ic<20000)
00111 EEMapping_[ic].reserve(s);
00112 if(ic<10000)
00113 HMapping_[ic].reserve(s);
00114 }
00115
00116
00117
00118 dbe = edm::Service<DQMStore>().operator->();
00119
00120 if (useDQM_){
00121 dbe->setCurrentFolder("EMShower");
00122
00123
00124 dbe->book1D("TransverseShape","Transverse Shape; #rho / Moliere radius; 1/E dE/d#rho",70, 0., 7.);
00125 dbe->book1D("LongitudinalShape","Longitudinal Shape; z / X0; 1/E dE/dz",26, 0.01, 26.01);
00126 dbe->book2D("ShapeRhoZ","2D Shape Ee = 10 GeV; #rho / Moliere radius; z / X0",70, 0., 7., 26, 0.01, 26.01);
00127
00128 dbe->book1D("NumberOfParticles","Number Of Particles entering the Shower; #Particles; #Events", 6, -0.5, 5.5);
00129
00130 dbe->book1D("ParticlesEnergy","Log Particles Energy; log10(E / GeV); #Particles", 30, 0, 3);
00131 }
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 myCalorimeter_ =
00150 new CaloGeometryHelper(fastCalo);
00151 myHDResponse_ =
00152 new HCALResponse(fastCalo.getParameter<edm::ParameterSet>("HCALResponse"),
00153 random);
00154 myHSParameters_ =
00155 new HSParameters(fastCalo.getParameter<edm::ParameterSet>("HSParameters"));
00156
00157
00158
00159 if ( fastMuECAL.getParameter<bool>("PairProduction") ||
00160 fastMuECAL.getParameter<bool>("Bremsstrahlung") ||
00161 fastMuECAL.getParameter<bool>("MuonBremsstrahlung") ||
00162 fastMuECAL.getParameter<bool>("EnergyLoss") ||
00163 fastMuECAL.getParameter<bool>("MultipleScattering") )
00164 theMuonEcalEffects = new MaterialEffects(fastMuECAL,random);
00165
00166
00167
00168 if ( fastMuHCAL.getParameter<bool>("PairProduction") ||
00169 fastMuHCAL.getParameter<bool>("Bremsstrahlung") ||
00170 fastMuHCAL.getParameter<bool>("MuonBremsstrahlung") ||
00171 fastMuHCAL.getParameter<bool>("EnergyLoss") ||
00172 fastMuHCAL.getParameter<bool>("MultipleScattering") )
00173 theMuonHcalEffects = new MaterialEffects(fastMuHCAL,random);
00174
00175
00176 }
00177
00178 void CalorimetryManager::clean()
00179 {
00180 unsigned size=firedCellsEB_.size();
00181 for(unsigned ic=0;ic<size;++ic)
00182 {
00183 EBMapping_[firedCellsEB_[ic]].clear();
00184 }
00185 firedCellsEB_.clear();
00186
00187 size=firedCellsEE_.size();
00188 for(unsigned ic=0;ic<size;++ic)
00189 {
00190 EEMapping_[firedCellsEE_[ic]].clear();
00191 }
00192 firedCellsEE_.clear();
00193
00194 size=firedCellsHCAL_.size();
00195 for(unsigned ic=0;ic<size;++ic)
00196 {
00197 HMapping_[firedCellsHCAL_[ic]].clear();
00198 }
00199 firedCellsHCAL_.clear();
00200
00201 ESMapping_.clear();
00202 muonSimTracks.clear();
00203 }
00204
00205 CalorimetryManager::~CalorimetryManager()
00206 {
00207 if(myCalorimeter_) delete myCalorimeter_;
00208 if(myHDResponse_) delete myHDResponse_;
00209
00210 if ( theMuonEcalEffects ) delete theMuonEcalEffects;
00211 if ( theMuonHcalEffects ) delete theMuonHcalEffects;
00212
00213 if ( theProfile ) delete theProfile;
00214 }
00215
00216 void CalorimetryManager::reconstruct()
00217 {
00218
00219 if(evtsToDebug_.size())
00220 {
00221 std::vector<unsigned int>::const_iterator itcheck=find(evtsToDebug_.begin(),evtsToDebug_.end(),mySimEvent->id().event());
00222 debug_=(itcheck!=evtsToDebug_.end());
00223 if(debug_)
00224 mySimEvent->print();
00225 }
00226
00227 if(!initialized_)
00228 {
00229 const CaloSubdetectorGeometry* geom=myCalorimeter_->getHcalGeometry();
00230 for(int subdetn=1;subdetn<=4;++subdetn)
00231 {
00232 const std::vector<DetId>& ids(geom->getValidDetIds(DetId::Hcal,subdetn));
00233 for (std::vector<DetId>::const_iterator i=ids.begin(); i!=ids.end(); i++)
00234 {
00235 HcalDetId myDetId(*i);
00236 unsigned hi=myDetId.hashed_index();
00237 theDetIds_[hi]=myDetId;
00238 }
00239 }
00240
00241
00242 if(simulatePreshower_ && !myCalorimeter_->preshowerPresent())
00243 {
00244 std::cout << " WARNING " << std::endl;
00245 std::cout << " The preshower simulation has been turned on; but no preshower geometry is available " << std::endl;
00246 std::cout << " Disabling the preshower simulation " << std::endl;
00247 simulatePreshower_ = false;
00248 }
00249
00250 initialized_=true;
00251 }
00252 clean();
00253
00254 LogInfo("FastCalorimetry") << "Reconstructing " << (int) mySimEvent->nTracks() << " tracks." << std::endl;
00255 for( int fsimi=0; fsimi < (int) mySimEvent->nTracks() ; ++fsimi) {
00256
00257 FSimTrack& myTrack = mySimEvent->track(fsimi);
00258
00259 int pid = abs(myTrack.type());
00260
00261 if (debug_) {
00262 LogDebug("FastCalorimetry") << " ===> pid = " << pid << std::endl;
00263 }
00264
00265
00266
00267 if(myTrack.noEndVertex()) {
00268
00269 if ( pid == 11 || pid == 22 ) {
00270
00271
00272 if ( myTrack.onEcal() )
00273 EMShowerSimulation(myTrack);
00274 else if ( myTrack.onVFcal() )
00275 reconstructHCAL(myTrack);
00276
00277 }
00278 else if (pid==13)
00279 {
00280 MuonMipSimulation(myTrack);
00281 }
00282
00283
00284
00285 else if ( pid < 1000000 ) {
00286 if ( myTrack.onHcal() || myTrack.onVFcal() ) {
00287 if(optionHDSim_ == 0 ) reconstructHCAL(myTrack);
00288 else HDShowerSimulation(myTrack);
00289 }
00290 }
00291 }
00292 }
00293
00294
00295
00296
00297 }
00298
00299
00300 void CalorimetryManager::EMShowerSimulation(const FSimTrack& myTrack) {
00301 std::vector<const RawParticle*> thePart;
00302 double X0depth;
00303 if (debug_) {
00304 LogDebug("FastCalorimetry") << " EMShowerSimulation " <<myTrack << std::endl;
00305 }
00306
00307
00308
00309
00310
00311 myPart = myTrack.ecalEntrance();
00312
00313
00314 if ( myTrack.type() == 22 && myPart.e()<0.055) return;
00315
00316
00317
00318 int onEcal = myTrack.onEcal();
00319 int onHcal = myTrack.onHcal();
00320 int onLayer1 = myTrack.onLayer1();
00321 int onLayer2 = myTrack.onLayer2();
00322
00323
00324 XYZPoint ecalentrance = myPart.vertex().Vect();
00325
00326
00327
00328
00329 PreshowerHitMaker * myPreshower = NULL ;
00330 if(simulatePreshower_ && (onLayer1 || onLayer2))
00331 {
00332 XYZPoint layer1entrance,layer2entrance;
00333 XYZVector dir1,dir2;
00334 if(onLayer1)
00335 {
00336 layer1entrance = XYZPoint(myTrack.layer1Entrance().vertex().Vect());
00337 dir1 = XYZVector(myTrack.layer1Entrance().Vect().Unit());
00338 }
00339 if(onLayer2)
00340 {
00341 layer2entrance = XYZPoint(myTrack.layer2Entrance().vertex().Vect());
00342 dir2 = XYZVector(myTrack.layer2Entrance().Vect().Unit());
00343 }
00344
00345
00346 myPreshower = new PreshowerHitMaker(myCalorimeter_,
00347 layer1entrance,
00348 dir1,
00349 layer2entrance,
00350 dir2,
00351 aLandauGenerator);
00352 myPreshower->setMipEnergy(mipValues_[0],mipValues_[1]);
00353 }
00354
00355
00356 EMECALShowerParametrization
00357 showerparam(myCalorimeter_->ecalProperties(onEcal),
00358 myCalorimeter_->hcalProperties(onHcal),
00359 myCalorimeter_->layer1Properties(onLayer1),
00360 myCalorimeter_->layer2Properties(onLayer2),
00361 theCoreIntervals_,
00362 theTailIntervals_,
00363 RCFactor_,
00364 RTFactor_);
00365
00366
00367 if ( myTrack.type() == 22 ) {
00368
00369
00370 X0depth = -log(random->flatShoot()) * (9./7.);
00371
00372
00373 double eMass = 0.000510998902;
00374 double xe=0;
00375 double xm=eMass/myPart.e();
00376 double weight = 0.;
00377
00378
00379 do {
00380 xe = random->flatShoot()*(1.-2.*xm) + xm;
00381 weight = 1. - 4./3.*xe*(1.-xe);
00382 } while ( weight < random->flatShoot() );
00383
00384
00385 if ( myPart.e()*xe < 0.055 || myPart.e()*(1.-xe) < 0.055 ) {
00386
00387 if ( myPart.e() > 0.055 ) thePart.push_back(&myPart);
00388
00389 } else {
00390
00391 myElec = (myPart) * xe;
00392 myPosi = (myPart) * (1.-xe);
00393 myElec.setVertex(myPart.vertex());
00394 myPosi.setVertex(myPart.vertex());
00395 thePart.push_back(&myElec);
00396 thePart.push_back(&myPosi);
00397 }
00398
00399 } else {
00400
00401 X0depth = 0.;
00402 if ( myPart.e() > 0.055 ) thePart.push_back(&myPart);
00403
00404 }
00405
00406
00407 if(thePart.size()==0)
00408 {
00409 if(myPreshower==NULL) return;
00410 delete myPreshower;
00411 return;
00412 }
00413
00414
00415 double maxEnergy=-1.;
00416 for(unsigned ip=0;ip < thePart.size();++ip)
00417 if(thePart[ip]->e() > maxEnergy) maxEnergy = thePart[ip]->e();
00418
00419
00420 int size = gridSize_;
00421 if(maxEnergy>100) size=11;
00422
00423
00424
00425
00426 EMShower theShower(random,aGammaGenerator,&showerparam,&thePart, dbe, NULL, NULL, bFixedLength_);
00427
00428
00429 double maxShower = theShower.getMaximumOfShower();
00430 if (maxShower > 20.) maxShower = 2.;
00431
00432 double depth((X0depth + maxShower) *
00433 myCalorimeter_->ecalProperties(onEcal)->radLenIncm());
00434 XYZPoint meanShower = ecalentrance + myPart.Vect().Unit()*depth;
00435
00436
00437
00438
00439 DetId pivot(myCalorimeter_->getClosestCell(meanShower, true, onEcal==1));
00440
00441 if(pivot.subdetId() == 0) {
00442 edm::LogWarning("CalorimetryManager") << "Pivot for egamma e = " << myTrack.hcalEntrance().e() << " is not found at depth " << depth << " and meanShower coordinates = " << meanShower << std::endl;
00443 if(myPreshower) delete myPreshower;
00444 return;
00445 }
00446
00447 EcalHitMaker myGrid(myCalorimeter_,ecalentrance,pivot,onEcal,size,0,random);
00448
00449
00450 myGrid.setPulledPadSurvivalProbability(pulledPadSurvivalProbability_);
00451 myGrid.setCrackPadSurvivalProbability(crackPadSurvivalProbability_);
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474 if(myTrack.onEcal() == 2)
00475 {
00476 if( (onLayer1 || onLayer2) && myPart.e()<=250.)
00477 {
00478 double maxdepth = X0depth+theShower.getMaximumOfShower();
00479 double newRadiusFactor = radiusFactorEE_ * aTerm/(1.+bTerm*maxdepth);
00480 myGrid.setRadiusFactor(newRadiusFactor);
00481 }
00482 else
00483 {
00484 myGrid.setRadiusFactor(radiusFactorEE_);
00485 }
00486 }
00487 else
00488 {
00489 myGrid.setRadiusFactor(radiusFactorEB_);
00490 }
00491
00492
00493 myGrid.setPreshowerPresent(simulatePreshower_);
00494
00495
00496 myGrid.setTrackParameters(myPart.Vect().Unit(),X0depth,myTrack);
00497
00498
00499
00500
00501
00502
00503
00504
00505 if(myPreshower) theShower.setPreshower(myPreshower);
00506
00507 HcalHitMaker myHcalHitMaker(myGrid,(unsigned)0);
00508
00509 theShower.setGrid(&myGrid);
00510 theShower.setHcal(&myHcalHitMaker);
00511 theShower.compute();
00512
00513
00514
00515 std::map<uint32_t,float>::const_iterator mapitr;
00516 std::map<uint32_t,float>::const_iterator endmapitr=myGrid.getHits().end();
00517 for(mapitr=myGrid.getHits().begin();mapitr!=endmapitr;++mapitr)
00518 {
00519 if(onEcal==1)
00520 {
00521 updateMap(EBDetId(mapitr->first).hashedIndex(), mapitr->second,myTrack.id(),EBMapping_,firedCellsEB_);
00522 }
00523
00524 else if(onEcal==2)
00525 updateMap(EEDetId(mapitr->first).hashedIndex(), mapitr->second,myTrack.id(),EEMapping_,firedCellsEE_);
00526
00527 }
00528
00529
00530 endmapitr=myHcalHitMaker.getHits().end();
00531 for(mapitr=myHcalHitMaker.getHits().begin();mapitr!=endmapitr;++mapitr)
00532 {
00533 updateMap(HcalDetId(mapitr->first).hashed_index(),mapitr->second,myTrack.id(),HMapping_,firedCellsHCAL_);
00534
00535 }
00536
00537
00538 if(myPreshower!=0)
00539 {
00540 endmapitr=myPreshower->getHits().end();
00541 for(mapitr=myPreshower->getHits().begin();mapitr!=endmapitr;++mapitr)
00542 {
00543 updateMap(mapitr->first,mapitr->second,myTrack.id(),ESMapping_);
00544
00545 }
00546 delete myPreshower;
00547
00548 }
00549
00550 }
00551
00552
00553
00554
00555 void CalorimetryManager::reconstructECAL(const FSimTrack& track) {
00556 if(debug_) {
00557 XYZTLorentzVector moment = track.momentum();
00558 std::cout << "FASTEnergyReconstructor::reconstructECAL - " << std::endl
00559 << " eta " << moment.eta() << std::endl
00560 << " phi " << moment.phi() << std::endl
00561 << " et " << moment.Et() << std::endl;
00562 }
00563
00564 int hit;
00565
00566 bool central=track.onEcal()==1;
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577 XYZTLorentzVector trackPosition;
00578 if( track.onEcal() ) {
00579 hit=track.onEcal()-1;
00580 trackPosition=track.ecalEntrance().vertex();
00581 } else {
00582 hit=2;
00583 trackPosition=track.vfcalEntrance().vertex();
00584 }
00585
00586 double pathEta = trackPosition.eta();
00587 double pathPhi = trackPosition.phi();
00588 double EGen = track.ecalEntrance().e();
00589
00590
00591 double e=0.;
00592 double sigma=0.;
00593
00594 if(hit == 2 && optionHDSim_ == 2 ) {
00595 std::pair<double,double> response =
00596 myHDResponse_->responseHCAL(0, EGen, pathEta, 0);
00597 e = response.first;
00598 sigma = response.second;
00599 }
00600
00601 double emeas = 0.;
00602
00603 if(sigma>0.)
00604 emeas = random->gaussShoot(e,sigma);
00605
00606
00607 if(debug_)
00608 std::cout << "FASTEnergyReconstructor::reconstructECAL : "
00609 << " on-calo eta, phi = " << pathEta << " " << pathPhi << std::endl
00610 << " Egen = " << EGen << std::endl
00611 << " Eres = " << e << std::endl
00612 << " sigma = " << sigma << std::endl
00613 << " Emeas = " << emeas << std::endl;
00614
00615
00616 if(debug_)
00617 std::cout << "FASTEnergyReconstructor::reconstructECAL : "
00618 << " Track position - " << trackPosition.Vect()
00619 << " bool central - " << central
00620 << " hit - " << hit << std::endl;
00621
00622 DetId detid;
00623 if( hit==2 )
00624 detid = myCalorimeter_->getClosestCell(trackPosition.Vect(),false,central);
00625
00626 HcalDetId hdetid(detid);
00627 if(!hdetid.subdetId()!=HcalForward) return;
00628
00629 if(debug_)
00630 std::cout << "FASTEnergyReconstructor::reconstructECAL : "
00631 << " CellID - " << detid.rawId() << std::endl;
00632
00633 if( hit != 2 || emeas > 0.)
00634 if(!detid.null())
00635 {
00636 updateMap(hdetid.hashed_index(),emeas,track.id(),HMapping_,firedCellsHCAL_);
00637 }
00638
00639 }
00640
00641
00642 void CalorimetryManager::reconstructHCAL(const FSimTrack& myTrack)
00643 {
00644 int hit;
00645 int pid = abs(myTrack.type());
00646 if (debug_) {
00647 LogDebug("FastCalorimetry") << " reconstructHCAL " << myTrack << std::endl;
00648 }
00649
00650
00651
00652
00653
00654
00655 XYZTLorentzVector trackPosition;
00656 if (myTrack.onHcal()) {
00657 trackPosition=myTrack.hcalEntrance().vertex();
00658 hit = myTrack.onHcal()-1;
00659 } else {
00660 trackPosition=myTrack.vfcalEntrance().vertex();
00661 hit = 2;
00662 }
00663
00664 double pathEta = trackPosition.eta();
00665 double pathPhi = trackPosition.phi();
00666
00667
00668 double EGen = myTrack.hcalEntrance().e();
00669 double e = 0.;
00670 double sigma = 0.;
00671 double emeas = 0.;
00672
00673 if(pid == 13) {
00674
00675 std::pair<double,double> response =
00676 myHDResponse_->responseHCAL(0, EGen, pathEta, 2);
00677 emeas = response.first;
00678 if(debug_)
00679 LogDebug("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - MUON !!!" << std::endl;
00680 }
00681 else if( pid == 22 || pid == 11)
00682 {
00683
00684 std::pair<double,double> response =
00685 myHDResponse_->responseHCAL(0, EGen, pathEta, 0);
00686 e = response.first;
00687 sigma = response.second;
00688 emeas = random->gaussShoot(e,sigma);
00689
00690
00691 if(debug_)
00692 LogDebug("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - e/gamma !!!" << std::endl;
00693 }
00694 else {
00695 e = myHDResponse_->getHCALEnergyResponse(EGen,hit);
00696 sigma = myHDResponse_->getHCALEnergyResolution(EGen, hit);
00697
00698 emeas = random->gaussShoot(e,sigma);
00699 }
00700
00701
00702 if(debug_)
00703 LogDebug("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - on-calo "
00704 << " eta = " << pathEta
00705 << " phi = " << pathPhi
00706 << " Egen = " << EGen
00707 << " Eres = " << e
00708 << " sigma = " << sigma
00709 << " Emeas = " << emeas << std::endl;
00710
00711 if(emeas > 0.) {
00712 DetId cell = myCalorimeter_->getClosestCell(trackPosition.Vect(),false,false);
00713 updateMap(HcalDetId(cell).hashed_index(), emeas, myTrack.id(),HMapping_,firedCellsHCAL_);
00714 }
00715 }
00716
00717 void CalorimetryManager::HDShowerSimulation(const FSimTrack& myTrack)
00718 {
00719
00720 XYZTLorentzVector moment = myTrack.momentum();
00721
00722 if(debug_)
00723 LogDebug("FastCalorimetry")
00724 << "CalorimetryManager::HDShowerSimulation - track param."
00725 << std::endl
00726 << " eta = " << moment.eta() << std::endl
00727 << " phi = " << moment.phi() << std::endl
00728 << " et = " << moment.Et() << std::endl
00729 << " e = " << myTrack.hcalEntrance().e() << std::endl;
00730
00731 if (debug_) {
00732 LogDebug("FastCalorimetry") << " HDShowerSimulation " << myTrack << std::endl;
00733 }
00734
00735
00736 int hit;
00737
00738
00739 XYZTLorentzVector trackPosition;
00740 if ( myTrack.onEcal() ) {
00741 trackPosition=myTrack.ecalEntrance().vertex();
00742 hit = myTrack.onEcal()-1;
00743 myPart = myTrack.ecalEntrance();
00744 } else if ( myTrack.onVFcal()) {
00745 trackPosition=myTrack.vfcalEntrance().vertex();
00746 hit = 2;
00747 myPart = myTrack.vfcalEntrance();
00748 }
00749 else
00750 {
00751 LogDebug("FastCalorimetry") << " The particle is not in the acceptance " << std::endl;
00752 return;
00753 }
00754
00755
00756
00757 int onHCAL = hit + 1;
00758 int onECAL = myTrack.onEcal();
00759
00760 double pathEta = trackPosition.eta();
00761 double pathPhi = trackPosition.phi();
00762
00763
00764 double eint = moment.e();
00765 double eGen = myTrack.hcalEntrance().e();
00766 double e = 0.;
00767 double sigma = 0.;
00768
00769 double emeas = 0.;
00770
00771
00772 if(eGen > 0.) {
00773
00774
00775 HDShowerParametrization
00776 theHDShowerparam(myCalorimeter_->ecalProperties(onECAL),
00777 myCalorimeter_->hcalProperties(onHCAL),
00778 myHSParameters_);
00779
00780
00781 XYZPoint caloentrance;
00782 XYZVector direction;
00783 if(myTrack.onEcal())
00784 {
00785 caloentrance = myTrack.ecalEntrance().vertex().Vect();
00786 direction = myTrack.ecalEntrance().Vect().Unit();
00787 }
00788 else if(myTrack.onHcal())
00789 {
00790 caloentrance = myTrack.hcalEntrance().vertex().Vect();
00791 direction = myTrack.hcalEntrance().Vect().Unit();
00792 }
00793 else
00794 {
00795 caloentrance = myTrack.vfcalEntrance().vertex().Vect();
00796 direction = myTrack.vfcalEntrance().Vect().Unit();
00797 }
00798
00799 if(debug_)
00800 LogDebug("FastCalorimetry")
00801 << "CalorimetryManager::HDShowerSimulation - on-calo 1 "
00802 << std::endl
00803 << " onEcal = " << myTrack.onEcal() << std::endl
00804 << " onHcal = " << myTrack.onHcal() << std::endl
00805 << " onVFcal = " << myTrack.onVFcal() << std::endl
00806 << " position = " << caloentrance << std::endl;
00807
00808
00809 DetId pivot;
00810 if(myTrack.onEcal())
00811 {
00812 pivot=myCalorimeter_->getClosestCell(caloentrance,
00813 true, myTrack.onEcal()==1);
00814 }
00815 else if(myTrack.onHcal())
00816 {
00817
00818 pivot=myCalorimeter_->getClosestCell(caloentrance,
00819 false, false);
00820 }
00821
00822 EcalHitMaker myGrid(myCalorimeter_,caloentrance,pivot,
00823 pivot.null()? 0 : myTrack.onEcal(),hdGridSize_,1,
00824 random);
00825
00826
00827 myGrid.setTrackParameters(direction,0,myTrack);
00828
00829 HcalHitMaker myHcalHitMaker(myGrid,(unsigned)1);
00830
00831
00832 bool status = false;
00833 int mip = 2;
00834
00835 if ( !myTrack.onEcal() && !myTrack.onHcal() ) {
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846 HFShower theShower(random,
00847 &theHDShowerparam,
00848 &myGrid,
00849 &myHcalHitMaker,
00850 onECAL,
00851 eGen);
00852
00853
00854
00855 status = theShower.compute();
00856 } else {
00857 if(hdSimMethod_ == 0) {
00858 HDShower theShower(random,
00859 &theHDShowerparam,
00860 &myGrid,
00861 &myHcalHitMaker,
00862 onECAL,
00863 eGen);
00864 status = theShower.compute();
00865 mip = theShower.getmip();
00866 }
00867 else if (hdSimMethod_ == 1) {
00868 HDRShower theShower(random,
00869 &theHDShowerparam,
00870 &myGrid,
00871 &myHcalHitMaker,
00872 onECAL,
00873 eGen);
00874 status = theShower.computeShower();
00875 mip = 2;
00876 }
00877 else if (hdSimMethod_ == 2 ) {
00878
00879
00880
00881 int particleType = myTrack.type();
00882 theProfile = thePiKProfile;
00883 if(particleType == -2212) theProfile = theAntiProtonProfile;
00884 else if(particleType == 2212) theProfile = theProtonProfile;
00885
00886
00887 int showerType = 99 + myTrack.onEcal();
00888 double globalTime = 150.0;
00889 float charge = (float)(myTrack.charge());
00890 Gflash3Vector gfpos(trackPosition.X(),trackPosition.Y(),trackPosition.Z());
00891 Gflash3Vector gfmom(moment.X(),moment.Y(),moment.Z());
00892
00893 theProfile->initialize(showerType,eGen,globalTime,charge,gfpos,gfmom);
00894 theProfile->loadParameters();
00895 theProfile->hadronicParameterization();
00896
00897
00898 std::vector<GflashHit>& gflashHitList = theProfile->getGflashHitList();
00899 std::vector<GflashHit>::const_iterator spotIter = gflashHitList.begin();
00900 std::vector<GflashHit>::const_iterator spotIterEnd = gflashHitList.end();
00901
00902 Gflash::CalorimeterNumber whichCalor = Gflash::kNULL;
00903
00904 for( ; spotIter != spotIterEnd; spotIter++){
00905
00906 double pathLength = theProfile->getGflashShowino()->getPathLengthAtShower()
00907 + (30*100/eGen)*(spotIter->getTime() - globalTime);
00908
00909 double currentDepth = std::max(0.0,pathLength - theProfile->getGflashShowino()->getPathLengthOnEcal());
00910
00911
00912 GflashTrajectoryPoint trajectoryPoint;
00913 theProfile->getGflashShowino()->getHelix()->getGflashTrajectoryPoint(trajectoryPoint,pathLength);
00914 Gflash3Vector positionAtCurrentDepth = trajectoryPoint.getPosition();
00915
00916 Gflash3Vector lateralDisplacement = positionAtCurrentDepth - spotIter->getPosition()/CLHEP::cm;
00917 double rShower = lateralDisplacement.r();
00918 double azimuthalAngle = lateralDisplacement.phi();
00919
00920 whichCalor = Gflash::getCalorimeterNumber(positionAtCurrentDepth);
00921
00922 if(whichCalor==Gflash::kESPM || whichCalor==Gflash::kENCA) {
00923 bool statusPad = myGrid.getPads(currentDepth,true);
00924 if(!statusPad) continue;
00925 myGrid.setSpotEnergy(1.2*spotIter->getEnergy()/CLHEP::GeV);
00926 myGrid.addHit(rShower/Gflash::intLength[Gflash::kESPM],azimuthalAngle,0);
00927 }
00928 else if(whichCalor==Gflash::kHB || whichCalor==Gflash::kHE) {
00929 bool setHDdepth = myHcalHitMaker.setDepth(currentDepth,true);
00930 if(!setHDdepth) continue;
00931 myHcalHitMaker.setSpotEnergy(1.4*spotIter->getEnergy()/CLHEP::GeV);
00932 myHcalHitMaker.addHit(rShower/Gflash::intLength[Gflash::kHB],azimuthalAngle,0);
00933 }
00934 }
00935 status = true;
00936 }
00937 else {
00938 edm::LogInfo("FastSimulationCalorimetry") << " SimMethod " << hdSimMethod_ <<" is NOT available ";
00939 }
00940 }
00941
00942
00943 if(status) {
00944
00945
00946 if(optionHDSim_ == 1) {
00947 e = myHDResponse_->getHCALEnergyResponse (eGen, hit);
00948 sigma = myHDResponse_->getHCALEnergyResolution(eGen, hit);
00949 }
00950 else {
00951 std::pair<double,double> response =
00952 myHDResponse_->responseHCAL(mip, eGen, pathEta, 1);
00953 e = response.first;
00954 sigma = response.second;
00955 }
00956
00957 emeas = random->gaussShoot(e,sigma);
00958 double correction = emeas / eGen;
00959
00960
00961 respCorr(eint);
00962
00963 if(debug_)
00964 LogDebug("FastCalorimetry")
00965 << "CalorimetryManager::HDShowerSimulation - on-calo 2" << std::endl
00966 << " eta = " << pathEta << std::endl
00967 << " phi = " << pathPhi << std::endl
00968 << " Egen = " << eGen << std::endl
00969 << " Eres = " << e << std::endl
00970 << " sigma = " << sigma << std::endl
00971 << " Emeas = " << emeas << std::endl
00972 << " corr = " << correction << std::endl
00973 << " mip = " << mip << std::endl;
00974
00975
00976
00977 std::map<unsigned,float>::const_iterator mapitr;
00978 std::map<unsigned,float>::const_iterator endmapitr;
00979 if(myTrack.onEcal() > 0) {
00980
00981 endmapitr=myGrid.getHits().end();
00982 for(mapitr=myGrid.getHits().begin(); mapitr!=endmapitr; ++mapitr) {
00983 double energy = mapitr->second;
00984 energy *= correction;
00985 energy *= ecorr;
00986
00987 if(energy > 0.000001) {
00988 if(onECAL==1)
00989 updateMap(EBDetId(mapitr->first).hashedIndex(),energy,myTrack.id(),EBMapping_,firedCellsEB_);
00990
00991 else if(onECAL==2)
00992 updateMap(EEDetId(mapitr->first).hashedIndex(),energy,myTrack.id(),EEMapping_,firedCellsEE_);
00993
00994 if(debug_)
00995 LogDebug("FastCalorimetry") << " ECAL cell " << mapitr->first << " added, E = "
00996 << energy << std::endl;
00997 }
00998 }
00999 }
01000
01001
01002 endmapitr=myHcalHitMaker.getHits().end();
01003 for(mapitr=myHcalHitMaker.getHits().begin(); mapitr!=endmapitr; ++mapitr) {
01004 double energy = mapitr->second;
01005 energy *= correction;
01006 energy *= hcorr;
01007
01008 updateMap(HcalDetId(mapitr->first).hashed_index(),energy,myTrack.id(),HMapping_,firedCellsHCAL_);
01009 if(debug_)
01010 LogDebug("FastCalorimetry") << " HCAL cell "
01011 << mapitr->first << " added E = "
01012 << mapitr->second << std::endl;
01013 }
01014 }
01015 else {
01016
01017
01018
01019
01020 if(myTrack.onHcal() || myTrack.onVFcal())
01021 {
01022 DetId cell = myCalorimeter_->getClosestCell(trackPosition.Vect(),false,false);
01023 updateMap(HcalDetId(cell).hashed_index(),emeas,myTrack.id(),HMapping_,firedCellsHCAL_);
01024 if(debug_)
01025 LogDebug("FastCalorimetry") << " HCAL simple cell "
01026 << cell.rawId() << " added E = "
01027 << emeas << std::endl;
01028 }
01029 }
01030
01031 }
01032
01033 if(debug_)
01034 LogDebug("FastCalorimetry") << std::endl << " FASTEnergyReconstructor::HDShowerSimulation finished "
01035 << std::endl;
01036 }
01037
01038
01039 void CalorimetryManager::MuonMipSimulation(const FSimTrack& myTrack)
01040 {
01041
01042 XYZTLorentzVector moment = myTrack.momentum();
01043
01044
01045 if(!theMuonHcalEffects)
01046 {
01047 if(myTrack.onHcal() || myTrack.onVFcal() )
01048 reconstructHCAL(myTrack);
01049
01050 return;
01051 }
01052
01053 if(debug_)
01054 LogDebug("FastCalorimetry") << "CalorimetryManager::MuonMipSimulation - track param."
01055 << std::endl
01056 << " eta = " << moment.eta() << std::endl
01057 << " phi = " << moment.phi() << std::endl
01058 << " et = " << moment.Et() << std::endl;
01059
01060
01061
01062
01063 XYZTLorentzVector trackPosition;
01064 if ( myTrack.onEcal() ) {
01065 trackPosition=myTrack.ecalEntrance().vertex();
01066
01067 myPart = myTrack.ecalEntrance();
01068 } else if ( myTrack.onVFcal()) {
01069 trackPosition=myTrack.vfcalEntrance().vertex();
01070
01071 myPart = myTrack.vfcalEntrance();
01072 }
01073 else
01074 {
01075 LogDebug("FastCalorimetry") << " The particle is not in the acceptance " << std::endl;
01076 return;
01077 }
01078
01079
01080
01081
01082
01083 int onECAL = myTrack.onEcal();
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094 XYZPoint caloentrance;
01095 XYZVector direction;
01096 if(myTrack.onEcal())
01097 {
01098 caloentrance = myTrack.ecalEntrance().vertex().Vect();
01099 direction = myTrack.ecalEntrance().Vect().Unit();
01100 }
01101 else if(myTrack.onHcal())
01102 {
01103 caloentrance = myTrack.hcalEntrance().vertex().Vect();
01104 direction = myTrack.hcalEntrance().Vect().Unit();
01105 }
01106 else
01107 {
01108 caloentrance = myTrack.vfcalEntrance().vertex().Vect();
01109 direction = myTrack.vfcalEntrance().Vect().Unit();
01110 }
01111
01112 DetId pivot;
01113 if(myTrack.onEcal())
01114 {
01115 pivot=myCalorimeter_->getClosestCell(caloentrance,
01116 true, myTrack.onEcal()==1);
01117 }
01118 else if(myTrack.onHcal())
01119 {
01120
01121 pivot=myCalorimeter_->getClosestCell(caloentrance,
01122 false, false);
01123 }
01124
01125 EcalHitMaker myGrid(myCalorimeter_,caloentrance,pivot,
01126 pivot.null()? 0 : myTrack.onEcal(),hdGridSize_,0,
01127 random);
01128
01129
01130 myGrid.setTrackParameters(direction,0,myTrack);
01131
01132
01133
01134
01135 const std::vector<CaloSegment>& segments=myGrid.getSegments();
01136 unsigned nsegments=segments.size();
01137
01138 int ifirstHcal=-1;
01139 int ilastEcal=-1;
01140
01141 EnergyLossSimulator* energyLossECAL = 0;
01142 if (theMuonEcalEffects) energyLossECAL = theMuonEcalEffects->energyLossSimulator();
01143
01144
01145
01146
01147 for(unsigned iseg=0;iseg<nsegments&&ifirstHcal<0;++iseg)
01148 {
01149
01150
01151 float segmentSizeinX0=segments[iseg].X0length();
01152
01153
01154 float energy=0.0;
01155 if (segmentSizeinX0>0.001 && segments[iseg].material()==CaloSegment::PbWO4 ) {
01156
01157 float charge = (float)(myTrack.charge());
01158 ParticlePropagator theMuon(moment,trackPosition,charge,0);
01159 theMuon.setID(-(int)charge*13);
01160 if ( energyLossECAL ) {
01161 energyLossECAL->updateState(theMuon, segmentSizeinX0);
01162 energy = energyLossECAL->deltaMom().E();
01163 moment -= energyLossECAL->deltaMom();
01164 }
01165 }
01166
01167
01168 if(segments[iseg].material()==CaloSegment::PbWO4)
01169 {
01170 myGrid.getPads(segments[iseg].sX0Entrance()+segmentSizeinX0*0.5);
01171 myGrid.setSpotEnergy(energy);
01172 myGrid.addHit(0.,0.);
01173 ilastEcal=iseg;
01174 }
01175
01176 if(segments[iseg].material()==CaloSegment::HCAL)
01177 {
01178 ifirstHcal=iseg;
01179 }
01180 }
01181
01182
01183
01184 HcalHitMaker myHcalHitMaker(myGrid,(unsigned)2);
01185
01186
01187
01188
01189
01190
01191
01195 int ilastHcal=-1;
01196 float mipenergy=0.0;
01197
01198 EnergyLossSimulator* energyLossHCAL = 0;
01199 if (theMuonHcalEffects) energyLossHCAL = theMuonHcalEffects->energyLossSimulator();
01200
01201
01202
01203
01204 if(ifirstHcal>0 && energyLossHCAL){
01205 for(unsigned iseg=ifirstHcal;iseg<nsegments;++iseg)
01206 {
01207 float segmentSizeinX0=segments[iseg].X0length();
01208 if(segments[iseg].material()==CaloSegment::HCAL) {
01209 ilastHcal=iseg;
01210 if (segmentSizeinX0>0.001) {
01211
01212 float charge = (float)(myTrack.charge());
01213 ParticlePropagator theMuon(moment,trackPosition,charge,0);
01214 theMuon.setID(-(int)charge*13);
01215 energyLossHCAL->updateState(theMuon, segmentSizeinX0);
01216 mipenergy = energyLossHCAL->deltaMom().E();
01217 moment -= energyLossHCAL->deltaMom();
01218 myHcalHitMaker.setSpotEnergy(mipenergy);
01219 myHcalHitMaker.addHit(segments[iseg].entrance());
01220 }
01221 }
01222 }
01223 }
01224
01229
01230
01231
01232
01233
01234 FSimTrack muonTrack(myTrack);
01235 if(energyLossHCAL && ilastHcal>=0) {
01236 math::XYZVector hcalExit=segments[ilastHcal].exit();
01237 muonTrack.setTkPosition(hcalExit);
01238 muonTrack.setTkMomentum(moment);
01239 } else if(energyLossECAL && ilastEcal>=0) {
01240 math::XYZVector ecalExit=segments[ilastEcal].exit();
01241 muonTrack.setTkPosition(ecalExit);
01242 muonTrack.setTkMomentum(moment);
01243 }
01244
01245 muonSimTracks.push_back(muonTrack);
01246
01247
01248
01249 std::map<unsigned,float>::const_iterator mapitr;
01250 std::map<unsigned,float>::const_iterator endmapitr;
01251 if(myTrack.onEcal() > 0) {
01252
01253 endmapitr=myGrid.getHits().end();
01254 for(mapitr=myGrid.getHits().begin(); mapitr!=endmapitr; ++mapitr) {
01255 double energy = mapitr->second;
01256 if(onECAL==1)
01257 {
01258 updateMap(EBDetId(mapitr->first).hashedIndex(),energy,myTrack.id(),EBMapping_,firedCellsEB_);
01259 }
01260 else if(onECAL==2)
01261 {
01262 updateMap(EEDetId(mapitr->first).hashedIndex(),energy,myTrack.id(),EEMapping_,firedCellsEE_);
01263 }
01264
01265 if(debug_)
01266 LogDebug("FastCalorimetry") << " ECAL cell " << mapitr->first << " added, E = "
01267 << energy << std::endl;
01268 }
01269 }
01270
01271
01272 endmapitr=myHcalHitMaker.getHits().end();
01273 for(mapitr=myHcalHitMaker.getHits().begin(); mapitr!=endmapitr; ++mapitr) {
01274 double energy = mapitr->second;
01275 {
01276 updateMap(HcalDetId(mapitr->first).hashed_index(),energy,myTrack.id(),HMapping_,firedCellsHCAL_);
01277 }
01278 if(debug_)
01279 LogDebug("FastCalorimetry") << " HCAL cell "
01280 << mapitr->first << " added E = "
01281 << mapitr->second << std::endl;
01282 }
01283
01284 if(debug_)
01285 LogDebug("FastCalorimetry") << std::endl << " FASTEnergyReconstructor::MipShowerSimulation finished "
01286 << std::endl;
01287 }
01288
01289
01290 void CalorimetryManager::readParameters(const edm::ParameterSet& fastCalo) {
01291
01292 edm::ParameterSet ECALparameters = fastCalo.getParameter<edm::ParameterSet>("ECAL");
01293
01294 evtsToDebug_ = fastCalo.getUntrackedParameter<std::vector<unsigned int> >("EvtsToDebug",std::vector<unsigned>());
01295 debug_ = fastCalo.getUntrackedParameter<bool>("Debug");
01296 useDQM_ = fastCalo.getUntrackedParameter<bool>("useDQM");
01297
01298 bFixedLength_ = ECALparameters.getParameter<bool>("bFixedLength");
01299
01300
01301 gridSize_ = ECALparameters.getParameter<int>("GridSize");
01302 spotFraction_ = ECALparameters.getParameter<double>("SpotFraction");
01303 pulledPadSurvivalProbability_ = ECALparameters.getParameter<double>("FrontLeakageProbability");
01304 crackPadSurvivalProbability_ = ECALparameters.getParameter<double>("GapLossProbability");
01305 theCoreIntervals_ = ECALparameters.getParameter<std::vector<double> >("CoreIntervals");
01306 theTailIntervals_ = ECALparameters.getParameter<std::vector<double> >("TailIntervals");
01307
01308 RCFactor_ = ECALparameters.getParameter<double>("RCFactor");
01309 RTFactor_ = ECALparameters.getParameter<double>("RTFactor");
01310
01311
01312 radiusFactorEE_ = ECALparameters.getParameter<double>("RadiusFactorEE");
01313 radiusFactorEB_ = ECALparameters.getParameter<double>("RadiusFactorEB");
01314
01315 radiusPreshowerCorrections_ = ECALparameters.getParameter<std::vector<double> >("RadiusPreshowerCorrections");
01316 aTerm = 1.+radiusPreshowerCorrections_[1]*radiusPreshowerCorrections_[0];
01317 bTerm = radiusPreshowerCorrections_[0];
01318 mipValues_ = ECALparameters.getParameter<std::vector<double> >("MipsinGeV");
01319 simulatePreshower_ = ECALparameters.getParameter<bool>("SimulatePreshower");
01320
01321 if(gridSize_ <1) gridSize_= 7;
01322 if(pulledPadSurvivalProbability_ <0. || pulledPadSurvivalProbability_>1 ) pulledPadSurvivalProbability_= 1.;
01323 if(crackPadSurvivalProbability_ <0. || crackPadSurvivalProbability_>1 ) crackPadSurvivalProbability_= 0.9;
01324
01325 LogInfo("FastCalorimetry") << " Fast ECAL simulation parameters " << std::endl;
01326 LogInfo("FastCalorimetry") << " =============================== " << std::endl;
01327 if(simulatePreshower_)
01328 LogInfo("FastCalorimetry") << " The preshower is present " << std::endl;
01329 else
01330 LogInfo("FastCalorimetry") << " The preshower is NOT present " << std::endl;
01331 LogInfo("FastCalorimetry") << " Grid Size : " << gridSize_ << std::endl;
01332 if(spotFraction_>0.)
01333 LogInfo("FastCalorimetry") << " Spot Fraction : " << spotFraction_ << std::endl;
01334 else
01335 {
01336 LogInfo("FastCalorimetry") << " Core of the shower " << std::endl;
01337 for(unsigned ir=0; ir < theCoreIntervals_.size()/2;++ir)
01338 {
01339 LogInfo("FastCalorimetry") << " r < " << theCoreIntervals_[ir*2] << " R_M : " << theCoreIntervals_[ir*2+1] << " ";
01340 }
01341 LogInfo("FastCalorimetry") << std::endl;
01342
01343 LogInfo("FastCalorimetry") << " Tail of the shower " << std::endl;
01344 for(unsigned ir=0; ir < theTailIntervals_.size()/2;++ir)
01345 {
01346 LogInfo("FastCalorimetry") << " r < " << theTailIntervals_[ir*2] << " R_M : " << theTailIntervals_[ir*2+1] << " ";
01347 }
01348
01349
01350 LogInfo("FastCalorimetry") << "Radius correction factors: EB & EE " << radiusFactorEB_ << " : "<< radiusFactorEE_ << std::endl;
01351
01352 LogInfo("FastCalorimetry") << std::endl;
01353 if(mipValues_.size()>2) {
01354 LogInfo("FastCalorimetry") << "Improper number of parameters for the preshower ; using 95keV" << std::endl;
01355 mipValues_.clear();
01356 mipValues_.resize(2,0.000095);
01357 }
01358 }
01359
01360 LogInfo("FastCalorimetry") << " FrontLeakageProbability : " << pulledPadSurvivalProbability_ << std::endl;
01361 LogInfo("FastCalorimetry") << " GapLossProbability : " << crackPadSurvivalProbability_ << std::endl;
01362
01363
01364
01365 edm::ParameterSet CalorimeterParam = fastCalo.getParameter<edm::ParameterSet>("CalorimeterProperties");
01366
01367 rsp = CalorimeterParam.getParameter<std::vector<double> >("RespCorrP");
01368 LogInfo("FastCalorimetry") << " RespCorrP (rsp) size " << rsp.size() << std::endl;
01369
01370 if( rsp.size()%3 !=0 ) {
01371 LogInfo("FastCalorimetry")
01372 << " RespCorrP size is wrong -> no corrections applied !!!"
01373 << std::endl;
01374
01375 p_knots.push_back(14000.);
01376 k_e.push_back (1.);
01377 k_h.push_back (1.);
01378 }
01379 else {
01380 for(unsigned i = 0; i < rsp.size(); i += 3) {
01381 LogInfo("FastCalorimetry") << "i = " << i/3 << " p = " << rsp [i]
01382 << " k_e(p) = " << rsp[i+1]
01383 << " k_e(p) = " << rsp[i+2] << std::endl;
01384
01385 p_knots.push_back(rsp[i]);
01386 k_e.push_back (rsp[i+1]);
01387 k_h.push_back (rsp[i+2]);
01388 }
01389 }
01390
01391
01392
01393 edm::ParameterSet HCALparameters = fastCalo.getParameter<edm::ParameterSet>("HCAL");
01394 optionHDSim_ = HCALparameters.getParameter<int>("SimOption");
01395 hdGridSize_ = HCALparameters.getParameter<int>("GridSize");
01396 hdSimMethod_ = HCALparameters.getParameter<int>("SimMethod");
01397
01398
01399 unfoldedMode_ = fastCalo.getUntrackedParameter<bool>("UnfoldedMode",false);
01400 }
01401
01402
01403 void CalorimetryManager::updateMap(uint32_t cellid,float energy,int id,std::map<uint32_t,std::vector<std::pair<int,float> > > & mymap)
01404 {
01405
01406 std::map<unsigned,std::vector<std::pair<int,float> > >::iterator cellitr;
01407 cellitr = mymap.find(cellid);
01408 if(!unfoldedMode_) id=0;
01409 if( cellitr==mymap.end())
01410 {
01411 std::vector<std::pair<int,float> > myElement;
01412 myElement.push_back(std::pair<int,float> (id,energy));
01413 mymap[cellid]=myElement;
01414 }
01415 else
01416 {
01417 if(!unfoldedMode_)
01418 {
01419 cellitr->second[0].second+=energy;
01420 }
01421 else
01422 cellitr->second.push_back(std::pair<int,float>(id,energy));
01423 }
01424 }
01425
01426 void CalorimetryManager::updateMap(int hi,float energy,int tid,std::vector<std::vector<std::pair<int,float> > > & mymap, std::vector<int>& firedCells)
01427 {
01428
01429 if(!unfoldedMode_)
01430 {
01431
01432 if(mymap[hi].size()==0)
01433 {
01434 firedCells.push_back(hi);
01435 mymap[hi].push_back(std::pair<int,float>(0,energy));
01436 }
01437 else
01438 mymap[hi][0].second+=energy;
01439 }
01440 else
01441 {
01442
01443
01444
01445 if(mymap[hi].size()==0)
01446 {
01447
01448 firedCells.push_back(hi);
01449 }
01450
01451 mymap[hi].push_back(std::pair<int,float>(tid,energy));
01452 }
01453
01454 }
01455
01456
01457 void CalorimetryManager::respCorr(double p) {
01458
01459 int sizeP = p_knots.size();
01460
01461 if(sizeP <= 1) {
01462 ecorr = 1.;
01463 hcorr = 1.;
01464 }
01465 else {
01466 int ip = -1;
01467 for (int i = 0; i < sizeP; i++) {
01468 if (p < p_knots[i]) { ip = i; break;}
01469 }
01470 if (ip == 0) {
01471 ecorr = k_e[0];
01472 hcorr = k_h[0];
01473 }
01474 else {
01475 if(ip == -1) {
01476 ecorr = k_e[sizeP-1];
01477 hcorr = k_h[sizeP-1];
01478 }
01479 else {
01480 double x1 = p_knots[ip-1];
01481 double x2 = p_knots[ip];
01482 double y1 = k_e[ip-1];
01483 double y2 = k_e[ip];
01484
01485 if(x1 == x2) {
01486
01487 }
01488
01489 ecorr = (y1 + (y2 - y1) * (p - x1)/(x2 - x1));
01490
01491 y1 = k_h[ip-1];
01492 y2 = k_h[ip];
01493 hcorr = (y1 + (y2 - y1) * (p - x1)/(x2 - x1));
01494
01495 }
01496 }
01497 }
01498
01499 if(debug_)
01500 LogDebug("FastCalorimetry") << " p, ecorr, hcorr = " << p << " "
01501 << ecorr << " " << hcorr << std::endl;
01502
01503 }
01504
01505
01506 void CalorimetryManager::loadFromEcalBarrel(edm::PCaloHitContainer & c) const
01507 {
01508 unsigned size=firedCellsEB_.size();
01509
01510 for(unsigned ic=0;ic<size;++ic)
01511 {
01512 int hi=firedCellsEB_[ic];
01513 if(!unfoldedMode_)
01514 {
01515 c.push_back(PCaloHit(EBDetId::unhashIndex(hi),EBMapping_[hi][0].second,0.,0));
01516
01517
01518 }
01519 else
01520 {
01521 unsigned npart=EBMapping_[hi].size();
01522 for(unsigned ip=0;ip<npart;++ip)
01523 {
01524 c.push_back(PCaloHit(EBDetId::unhashIndex(hi),EBMapping_[hi][ip].second,0.,
01525 EBMapping_[hi][ip].first));
01526
01527 }
01528 }
01529
01530
01531 }
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549 }
01550
01551
01552 void CalorimetryManager::loadFromEcalEndcap(edm::PCaloHitContainer & c) const
01553 {
01554 unsigned size=firedCellsEE_.size();
01555
01556 for(unsigned ic=0;ic<size;++ic)
01557 {
01558 int hi=firedCellsEE_[ic];
01559 if(!unfoldedMode_)
01560 c.push_back(PCaloHit(EEDetId::unhashIndex(hi),EEMapping_[hi][0].second,0.,0));
01561 else
01562 {
01563 unsigned npart=EEMapping_[hi].size();
01564 for(unsigned ip=0;ip<npart;++ip)
01565 c.push_back(PCaloHit(EEDetId::unhashIndex(hi),EEMapping_[hi][ip].second,0.,
01566 EEMapping_[hi][ip].first));
01567 }
01568
01569
01570 }
01571
01572
01573 }
01574
01575 void CalorimetryManager::loadFromHcal(edm::PCaloHitContainer & c) const
01576 {
01577 unsigned size=firedCellsHCAL_.size();
01578
01579 for(unsigned ic=0;ic<size;++ic)
01580 {
01581 int hi=firedCellsHCAL_[ic];
01582 if(!unfoldedMode_)
01583 c.push_back(PCaloHit(theDetIds_[hi],HMapping_[hi][0].second,0.,0));
01584 else
01585 {
01586 unsigned npart=HMapping_[hi].size();
01587 for(unsigned ip=0;ip<npart;++ip)
01588 c.push_back(PCaloHit(theDetIds_[hi],HMapping_[hi][ip].second,0.,
01589 HMapping_[hi][ip].first));
01590 }
01591
01592
01593 }
01594
01595
01596 }
01597
01598 void CalorimetryManager::loadFromPreshower(edm::PCaloHitContainer & c) const
01599 {
01600 std::map<uint32_t,std::vector<std::pair< int,float> > >::const_iterator cellit;
01601 std::map<uint32_t,std::vector<std::pair <int,float> > >::const_iterator preshEnd=ESMapping_.end();
01602
01603 for(cellit=ESMapping_.begin();cellit!=preshEnd;++cellit)
01604 {
01605 if(!unfoldedMode_)
01606 c.push_back(PCaloHit(cellit->first,cellit->second[0].second,0.,0));
01607 else
01608 {
01609 unsigned npart=cellit->second.size();
01610 for(unsigned ip=0;ip<npart;++ip)
01611 {
01612 c.push_back(PCaloHit(cellit->first,cellit->second[ip].second,0.,cellit->second[ip].first));
01613 }
01614 }
01615 }
01616 }
01617
01618
01619
01620
01621 void CalorimetryManager::loadMuonSimTracks(edm::SimTrackContainer &muons) const
01622 {
01623 unsigned size=muons.size();
01624 for(unsigned i=0; i<size;++i)
01625 {
01626 int id=muons[i].trackId();
01627 if(abs(muons[i].type())!=13) continue;
01628
01629
01630 std::vector<FSimTrack>::const_iterator itcheck=find_if(muonSimTracks.begin(),muonSimTracks.end(),FSimTrackEqual(id));
01631 if(itcheck!=muonSimTracks.end())
01632 {
01633 muons[i].setTkPosition(itcheck->trackerSurfacePosition());
01634 muons[i].setTkMomentum(itcheck->trackerSurfaceMomentum());
01635
01636
01637
01638 }
01639
01640
01641
01642
01643
01644
01645
01646 }
01647
01648 }
01649