42 double g0,
g1, e0, e1;
49 double ecalECut, hcalECut;
55 options_->
GetOpt(
"correction",
"allowNegativeEnergy", allowNegative);
62 int doEtaCorrection(0);
63 options_->
GetOpt(
"correction",
"doEtaCorrection", doEtaCorrection);
70 double maxEToCorrect(100.0);
75 for (std::vector<std::string>::iterator
i = names->begin();
i 76 != names->end(); ++
i) {
78 std::vector<double> params;
83 std::vector<double> etaParams;
94 std::cout << __PRETTY_FUNCTION__ <<
": finished.\n";
102 std::cout <<
"Welcome to "<< __PRETTY_FUNCTION__ <<
"\n";
117 std::vector<Calibratable> calibVec;
121 std::cout <<
"Got a vector of calibratables of size "<< calibVec.size()
129 std::vector<ParticleDepositPtr> pdVec;
134 TFile* exercises =
new TFile(exercisefile.c_str(),
"recreate");
135 TH1F droppedParticles(
"droppedParticles",
"droppedParticles", 100000, 0,
138 std::cout <<
"Particle deposit vec has "<< pdVec.size() <<
" entries\n";
142 std::cout <<
"Creating calibrator clones and space managers\n";
147 linCal->addDetectorElement(offset);
150 linCal->addDetectorElement(ecal);
151 linCal->addDetectorElement(hcal);
155 boost::shared_ptr<SpaceManager> sm(
new SpaceManager(
"ecalAndHcal"));
156 sm->setBarrelLimit(barrelEta);
157 sm->createCalibrators(*linCal);
160 std::cout <<
"Initialised SpaceManager and calibrators.\n";
175 std::cout <<
"Using a ECAL and HCAL energy cuts of "<< eCut <<
" and " 178 std::cout <<
"Assigning particles to space managers and calibrators.\n";
181 for (std::vector<ParticleDepositPtr>::const_iterator cit = pdVec.begin(); cit
182 != pdVec.end(); ++cit) {
185 pd->getTruthEnergy());
188 std::cout <<
"Couldn't find calibrator for particle?!\n";
193 c->addParticleDeposit(pd);
199 std::cout <<
"Dropped "<< dropped <<
" particles.\n";
204 <<
"Assignments complete, starting calibration and analysis.\n";
207 std::map<SpaceVoxelPtr, CalibratorPtr> * smCalibrators =
208 sm->getCalibrators();
210 TTree
tree(
"CalibratedParticles",
"");
212 tree.Branch(
"Calibratable",
"pftools::Calibratable", &calibrated, 32000, 2);
217 std::cout <<
"*** Performance for ECAL + HCAL calibration ***\n";
220 exercises->mkdir(
"ecalAndHcal");
221 exercises->cd(
"/ecalAndHcal");
223 for (std::map<SpaceVoxelPtr, CalibratorPtr>::iterator it =
224 smCalibrators->begin(); it != smCalibrators->end(); ++it) {
240 droppedParticles.Write();
250 std::map<SpaceVoxelPtr, CalibratorPtr>* smCalibrators = s->getCalibrators();
252 for (std::map<SpaceVoxelPtr, CalibratorPtr>::iterator it =
253 smCalibrators->begin(); it != smCalibrators->end(); ++it) {
256 if (c->hasParticles() >
static_cast<int>(
threshold_)) {
257 std::map<DetectorElementPtr, double> calibs =
258 c->getCalibrationCoefficients();
259 s->assignCalibration(c, calibs);
265 const std::vector<DetectorElementPtr>& detEls) {
269 std::cout <<
"AutoFit option = "<< autoFit <<
"\n";
271 std::vector<double> ecalBarrel;
272 std::vector<double> ecalEndcap;
273 std::vector<double> hcalBarrel;
274 std::vector<double> hcalEndcap;
286 if (
debug_ > 1&& basePlots > 0)
287 std::cout <<
"Option to generate evolution plots invoked.\n";
290 std::cout <<
"Fixing parameters for evolution functions.\n";
296 assert(ecalBarrel.size() == 6 && ecalEndcap.size() == 6);
297 assert(hcalBarrel.size() == 6 && hcalEndcap.size() == 6);
299 for (std::vector<DetectorElementPtr>::const_iterator
i = detEls.begin();
i 300 != detEls.end(); ++
i) {
302 std::cout <<
"Fixing evolution for "<< *d <<
"\n";
315 fBarrel(barrelName.c_str(),
316 "([0]*[5]*x)*([5]*x<[1])+([2]+[3]*exp([4]*[5]*x))*([5]*x>[1])");
318 if (d->getType() ==
ECAL) {
320 for (std::vector<double>::const_iterator dit =
321 ecalBarrel.begin(); dit!= ecalBarrel.end(); ++dit) {
322 fBarrel.FixParameter(count, *dit);
327 if (d->getType() ==
HCAL) {
329 for (std::vector<double>::const_iterator dit =
330 hcalBarrel.begin(); dit!= hcalBarrel.end(); ++dit) {
331 fBarrel.FixParameter(count, *dit);
337 fBarrel.FixParameter(5, 1.0);
339 fBarrel.SetMinimum(0);
340 s->addEvolution(d, BARREL_POS, fBarrel);
343 TH1* slices = s->extractEvolution(d, BARREL_POS, fBarrel,
354 fEndcap(endcapName.c_str(),
355 "([0]*[5]*x)*([5]*x<[1])+([2]+[3]*exp([4]*[5]*x))*([5]*x>[1])");
358 if (d->getType() ==
ECAL) {
360 for (std::vector<double>::const_iterator dit =
361 ecalEndcap.begin(); dit!= ecalEndcap.end(); ++dit) {
362 fEndcap.FixParameter(count, *dit);
367 if (d->getType() ==
HCAL) {
369 for (std::vector<double>::const_iterator dit =
370 hcalEndcap.begin(); dit!= hcalEndcap.end(); ++dit) {
371 fEndcap.FixParameter(count, *dit);
377 fEndcap.FixParameter(5, 1.0);
379 fEndcap.SetMinimum(0);
380 s->addEvolution(d, ENDCAP_POS, fEndcap);
382 TH1* slices = s->extractEvolution(d, ENDCAP_POS, fEndcap,
398 if (c->hasParticles() >
static_cast<int>(
threshold_)) {
399 std::map<DetectorElementPtr, double> calibs = s->getCalibration(c);
401 std::vector<ParticleDepositPtr> csParticles = c->getParticles();
406 std::cout <<
"Using interpolation mode " << mode <<
"\n";
409 for (std::vector<ParticleDepositPtr>::iterator zit = csParticles.begin(); zit
410 != csParticles.end(); ++zit) {
418 for (std::map<DetectorElementPtr, double>::iterator deit =
419 calibs.begin(); deit != calibs.end(); ++deit) {
435 double tempEnergy = pd->getRecEnergy();
437 for (std::map<DetectorElementPtr, double>::iterator deit =
438 calibs.begin(); deit != calibs.end(); ++deit) {
442 de->setCalib(s->interpolateCoefficient(de,
443 pd->getTruthEnergy(), pd->getEta(), pd->getPhi()));
444 else if (mode == 2|| mode == 3|| mode == 4)
445 de->setCalib(s->evolveCoefficient(de, tempEnergy,
446 pd->getEta(), pd->getPhi()));
448 de->setCalib((*deit).second);
451 std::cout <<
"POST ECAL HCAL coeff: " << ecal->getCalib() <<
", " << hcal->getCalib() <<
"\n";
457 crwPos.
b_ = ecal->getCalib();
458 crwPos.
c_ = hcal->getCalib();
469 if (cpCorr !=
NONE) {
475 pd->getEta(), pd->getPhi());
479 pd->getEta(), pd->getPhi());
488 pd->getEta(), pd->getPhi());
490 crwCorr.
b_ = ecal->getCalib();
491 crwCorr.
c_ = hcal->getCalib();
const std::string names[nVars_]
void resetElement3(DetectorElementPtr de)