15 #include <g4hough/SvtxVertexMap.h>
16 #include <g4hough/SvtxVertex.h>
17 #include <g4hough/SvtxTrackMap.h>
18 #include <g4hough/SvtxTrack.h>
26 #include <calobase/RawTowerGeomContainer.h>
27 #include <calobase/RawTowerContainer.h>
28 #include <calobase/RawTower.h>
29 #include <calobase/RawCluster.h>
30 #include <calobase/RawClusterContainer.h>
37 #include <TProfile2D.h>
48 cout <<
"Class constructor called " << endl;
120 _energy_dphi_emc =
new TH2D(
"energy_dphi_emc",
"", 300,0.0,30.0, 100,-1.0,1.0);
121 _energy_dphi_hci =
new TH2D(
"energy_dphi_hci",
"", 300,0.0,30.0, 100,-1.0,1.0);
122 _energy_dphi_hco =
new TH2D(
"energy_dphi_hco",
"", 300,0.0,30.0, 100,-1.0,1.0);
127 _energy_deta_emc =
new TH2D(
"energy_deta_emc",
"", 300,0.0,30.0, 100,-1.0,1.0);
128 _energy_deta_hci =
new TH2D(
"energy_deta_hci",
"", 300,0.0,30.0, 100,-1.0,1.0);
129 _energy_deta_hco =
new TH2D(
"energy_deta_hco",
"", 300,0.0,30.0, 100,-1.0,1.0);
136 _towers_3x3_emc =
new TProfile2D(
"towers_3x3_emc",
"", 3,-1.5,1.5, 3,-1.5,1.5, 0.0,9998.0,
"");
137 _towers_5x5_emc =
new TProfile2D(
"towers_5x5_emc",
"", 5,-2.5,2.5, 5,-2.5,2.5, 0.0,9998.0,
"");
138 _towers_7x7_emc =
new TProfile2D(
"towers_7x7_emc",
"", 7,-3.5,3.5, 7,-3.5,3.5, 0.0,9998.0,
"");
139 _towers_9x9_emc =
new TProfile2D(
"towers_9x9_emc",
"", 9,-4.5,4.5, 9,-4.5,4.5, 0.0,9998.0,
"");
145 for (
int i = 0;
i < 10; ++
i )
148 _tower_energy_emc[
i] =
new TH2D(Form(
"tower_energy_emc_%d",
i),
"", 300,0.0,30.0, 100,0.0,2.0);
153 _towers_3x3_hci =
new TProfile2D(
"towers_3x3_hci",
"", 3,-1.5,1.5, 3,-1.5,1.5, 0.0,9998.0,
"");
154 _towers_5x5_hci =
new TProfile2D(
"towers_5x5_hci",
"", 5,-2.5,2.5, 5,-2.5,2.5, 0.0,9998.0,
"");
155 _towers_7x7_hci =
new TProfile2D(
"towers_7x7_hci",
"", 7,-3.5,3.5, 7,-3.5,3.5, 0.0,9998.0,
"");
156 _towers_9x9_hci =
new TProfile2D(
"towers_9x9_hci",
"", 9,-4.5,4.5, 9,-4.5,4.5, 0.0,9998.0,
"");
162 for (
int i = 0;
i < 10; ++
i )
165 _tower_energy_hci[
i] =
new TH2D(Form(
"tower_energy_hci_%d",
i),
"", 300,0.0,30.0, 100,0.0,2.0);
170 _towers_3x3_hco =
new TProfile2D(
"towers_3x3_hco",
"", 3,-1.5,1.5, 3,-1.5,1.5, 0.0,9998.0,
"");
171 _towers_5x5_hco =
new TProfile2D(
"towers_5x5_hco",
"", 5,-2.5,2.5, 5,-2.5,2.5, 0.0,9998.0,
"");
172 _towers_7x7_hco =
new TProfile2D(
"towers_7x7_hco",
"", 7,-3.5,3.5, 7,-3.5,3.5, 0.0,9998.0,
"");
173 _towers_9x9_hco =
new TProfile2D(
"towers_9x9_hco",
"", 9,-4.5,4.5, 9,-4.5,4.5, 0.0,9998.0,
"");
175 for (
int i = 0;
i < 10; ++
i )
178 _tower_energy_hco[
i] =
new TH2D(Form(
"tower_energy_hco_%d",
i),
"", 300,0.0,30.0, 100,0.0,2.0);
206 cout <<
"------------------------------------------------------------------------------------" << endl;
207 cout <<
"Now processing event number " <<
nevents << endl;
220 cerr <<
PHWHERE <<
" ERROR: Can't find G4TruthInfo" << endl;
225 SvtxTrackMap* trackmap = findNode::getClass<SvtxTrackMap>(topNode,
"SvtxTrackMap");
228 cerr <<
PHWHERE <<
" ERROR: Can't find SvtxTrackMap" << endl;
233 SvtxVertexMap* vertexmap = findNode::getClass<SvtxVertexMap>(topNode,
"SvtxVertexMap");
236 cerr <<
PHWHERE <<
" ERROR: Can't find SvtxVertexMap" << endl;
241 bool clusters_available =
true;
242 RawClusterContainer *emc_clustercontainer = findNode::getClass<RawClusterContainer>(topNode,
"CLUSTER_CEMC");
243 RawClusterContainer *hci_clustercontainer = findNode::getClass<RawClusterContainer>(topNode,
"CLUSTER_HCALIN");
244 RawClusterContainer *hco_clustercontainer = findNode::getClass<RawClusterContainer>(topNode,
"CLUSTER_HCALOUT");
245 if ( !emc_clustercontainer || !hci_clustercontainer || !hco_clustercontainer )
249 cerr <<
PHWHERE <<
" WARNING: Can't find cluster nodes" << endl;
250 cerr <<
PHWHERE <<
" emc_clustercontainer " << emc_clustercontainer << endl;
251 cerr <<
PHWHERE <<
" hci_clustercontainer " << hci_clustercontainer << endl;
252 cerr <<
PHWHERE <<
" hco_clustercontainer " << hco_clustercontainer << endl;
254 clusters_available =
false;
259 RawTowerGeomContainer *emc_towergeo = findNode::getClass<RawTowerGeomContainer>(topNode,
"TOWERGEOM_CEMC");
260 RawTowerGeomContainer *hci_towergeo = findNode::getClass<RawTowerGeomContainer>(topNode,
"TOWERGEOM_HCALIN");
261 RawTowerGeomContainer *hco_towergeo = findNode::getClass<RawTowerGeomContainer>(topNode,
"TOWERGEOM_HCALOUT");
262 if ( !emc_towergeo || !hci_towergeo || !hco_towergeo )
266 cerr <<
PHWHERE <<
" WARNING: Can't find tower geometry nodes" << endl;
267 cerr <<
PHWHERE <<
" emc_towergeo " << emc_towergeo << endl;
268 cerr <<
PHWHERE <<
" hci_towergeo " << hci_towergeo << endl;
269 cerr <<
PHWHERE <<
" hco_towergeo " << hco_towergeo << endl;
275 RawTowerContainer *emc_towercontainer = findNode::getClass<RawTowerContainer>(topNode,
"TOWER_CALIB_CEMC");
276 RawTowerContainer *hci_towercontainer = findNode::getClass<RawTowerContainer>(topNode,
"TOWER_CALIB_HCALIN");
277 RawTowerContainer *hco_towercontainer = findNode::getClass<RawTowerContainer>(topNode,
"TOWER_CALIB_HCALOUT");
278 if ( !emc_towercontainer || !hci_towercontainer || !hco_towercontainer )
282 cerr <<
PHWHERE <<
" WARNING: Can't find tower container nodes" << endl;
283 cerr <<
PHWHERE <<
" emc_towercontainer " << emc_towercontainer << endl;
284 cerr <<
PHWHERE <<
" hci_towercontainer " << hci_towercontainer << endl;
285 cerr <<
PHWHERE <<
" hco_towercontainer " << hco_towercontainer << endl;
331 cout <<
"Eval stack memory addresses..." << endl;
332 cout << &svtxevalstack << endl;
333 cout << &emc_caloevalstack << endl;
334 cout << &hci_caloevalstack << endl;
335 cout << &hco_caloevalstack << endl;
336 cout <<
"Evaluator addresses..." << endl;
337 cout << trackeval << endl;
338 cout << emc_rawclustereval << endl;
339 cout << hci_rawclustereval << endl;
340 cout << hco_rawclustereval << endl;
343 if (
verbosity > 0 ) cout <<
"Now going to loop over truth partcles..." << endl;
353 int particleID = g4particle->
get_pid();
355 if ( trutheval->
get_embed(g4particle) <= 0 && fabs(particleID) == 11 &&
verbosity > 0 )
357 cout <<
"NON EMBEDDED ELECTRON!!! WHEE!!! " << particleID <<
" " << iter->first << endl;
360 if ( trutheval->
get_embed(g4particle) <= 0 )
continue;
361 bool iselectron = fabs(particleID) == 11;
362 bool ispion = fabs(particleID) == 211;
363 if (
verbosity > 0 ) cout <<
"embedded particle ID is " << particleID <<
" ispion " << ispion <<
" iselectron " << iselectron <<
" " << iter->first << endl;
368 float truept = sqrt(pow(g4particle->
get_px(),2)+pow(g4particle->
get_py(),2));
369 float true_energy = g4particle->
get_e();
373 if (!track)
continue;
374 float recopt = track->
get_pt();
379 cout <<
"truept is " << truept << endl;
380 cout <<
"recopt is " << recopt << endl;
381 cout <<
"true energy is " << true_energy << endl;
392 if ( emc_rawclustereval ) emc_bestcluster = emc_rawclustereval->
best_cluster_from(g4particle);
393 if ( hci_rawclustereval ) hci_bestcluster = hci_rawclustereval->
best_cluster_from(g4particle);
394 if ( hco_rawclustereval ) hco_bestcluster = hco_rawclustereval->
best_cluster_from(g4particle);
398 cout <<
"Cluster addresses from best cluster " << endl;
399 cout << emc_bestcluster << endl;
400 cout << hci_bestcluster << endl;
401 cout << hco_bestcluster << endl;
407 if ( !emc_bestcluster && emc_clusters.size() ) emc_bestcluster = emc_clusters[0];
408 if ( !hci_bestcluster && hci_clusters.size() ) hci_bestcluster = hci_clusters[0];
409 if ( !hco_bestcluster && hco_clusters.size() ) hco_bestcluster = hco_clusters[0];
413 cout <<
"Cluster addresses from my (very bad) association " << endl;
414 cout << emc_bestcluster << endl;
415 cout << hci_bestcluster << endl;
416 cout << hco_bestcluster << endl;
420 vector<RawTower*> emc_towers_from_bestcluster =
get_ordered_towers(emc_bestcluster,emc_towercontainer);
421 vector<RawTower*> hci_towers_from_bestcluster =
get_ordered_towers(hci_bestcluster,hci_towercontainer);
422 vector<RawTower*> hco_towers_from_bestcluster =
get_ordered_towers(hco_bestcluster,hco_towercontainer);
436 float emc_energy_best = -9999;
437 float hci_energy_best = -9999;
438 float hco_energy_best = -9999;
441 float emc_energy_track = -9999;
442 float hci_energy_track = -9999;
443 float hco_energy_track = -9999;
445 if (
verbosity > 2 ) cout <<
"Now attempting to get the energies..." << endl;
448 if ( emc_bestcluster ) emc_energy_best = emc_bestcluster->
get_energy();
449 if ( hci_bestcluster ) hci_energy_best = hci_bestcluster->
get_energy();
450 if ( hco_bestcluster ) hco_energy_best = hco_bestcluster->
get_energy();
454 cout <<
"emc_energy_best is " << emc_energy_best << endl;
455 cout <<
"hci_energy_best is " << hci_energy_best << endl;
456 cout <<
"hco_energy_best is " << hco_energy_best << endl;
466 cout <<
"emc_energy_track is " << emc_energy_track << endl;
467 cout <<
"hci_energy_track is " << hci_energy_track << endl;
468 cout <<
"hco_energy_track is " << hco_energy_track << endl;
481 cout <<
"emc_energy_track is " << emc_energy_track << endl;
482 cout <<
"hci_energy_track is " << hci_energy_track << endl;
483 cout <<
"hco_energy_track is " << hco_energy_track << endl;
489 float emc_dphi_track = -9999;
490 float hci_dphi_track = -9999;
491 float hco_dphi_track = -9999;
496 float emc_deta_track = -9999;
497 float hci_deta_track = -9999;
498 float hco_deta_track = -9999;
511 float assoc_dphi = 0.1;
512 float assoc_deta = 0.1;
513 bool good_emc_assoc = fabs(emc_dphi_track) < assoc_dphi && fabs(emc_deta_track) < assoc_deta;
514 bool good_hci_assoc = fabs(hci_dphi_track) < assoc_dphi && fabs(hci_deta_track) < assoc_deta;
515 bool good_hco_assoc = fabs(hco_dphi_track) < assoc_dphi && fabs(hco_deta_track) < assoc_deta;
522 cout <<
"emc_energy_best is " << emc_energy_best << endl;
523 cout <<
"hci_energy_best is " << hci_energy_best << endl;
524 cout <<
"hco_energy_best is " << hco_energy_best << endl;
525 cout <<
"emc_energy_track is " << emc_energy_track << endl;
526 cout <<
"hci_energy_track is " << hci_energy_track << endl;
527 cout <<
"hco_energy_track is " << hco_energy_track << endl;
528 cout <<
"emc_dphi_track is " << emc_dphi_track << endl;
529 cout <<
"hci_dphi_track is " << hci_dphi_track << endl;
530 cout <<
"hco_dphi_track is " << hco_dphi_track << endl;
531 cout <<
"emc_deta_track is " << emc_deta_track << endl;
532 cout <<
"hci_deta_track is " << hci_deta_track << endl;
533 cout <<
"hco_deta_track is " << hco_deta_track << endl;
536 float hct_energy_track = 0;
537 if ( hci_energy_track >= 0 ) hct_energy_track += hci_energy_track;
538 if ( hco_energy_track >= 0 ) hct_energy_track += hco_energy_track;
540 float total_energy_dumb = 0;
541 if ( emc_energy_track >= 0 ) total_energy_dumb += emc_energy_track;
542 if ( hci_energy_track >= 0 ) total_energy_dumb += hci_energy_track;
543 if ( hco_energy_track >= 0 ) total_energy_dumb += hco_energy_track;
545 float total_energy_smart = 0;
546 if ( good_emc_assoc ) total_energy_smart += emc_energy_track;
547 if ( good_hci_assoc ) total_energy_smart += hci_energy_track;
548 if ( good_hco_assoc ) total_energy_smart += hco_energy_track;
552 float emc_eratio = emc_energy_track/true_energy;
553 float hci_eratio = hci_energy_track/true_energy;
554 float hco_eratio = hco_energy_track/true_energy;
555 float hct_eratio = hct_energy_track/true_energy;
556 float tot_dumb_eratio = total_energy_dumb/true_energy;
557 float tot_smart_eratio = total_energy_smart/true_energy;
566 if ( emc_eratio < 0.1 )
576 if ( emc_eratio > 0.1 )
604 cout <<
"End called, " <<
nevents <<
" events processed with " <<
nerrors <<
" errors and " <<
nwarnings <<
" warnings." << endl;
614 if ( clusters == NULL )
return vector<RawCluster*>();
619 map<double,RawCluster*> cluster_map;
620 for (
auto it = range.first;
it != range.second; ++
it )
624 cluster_map.insert(make_pair(energy,cluster));
627 vector<RawCluster*> cluster_list;
628 for (
auto rit = cluster_map.rbegin(); rit != cluster_map.rend(); ++rit )
631 cluster_list.push_back(cluster);
644 if ( towers == NULL )
return vector<RawTower*>();
649 map<double,RawTower*> tower_map;
650 for (
auto it = range.first;
it != range.second; ++
it )
654 tower_map.insert(make_pair(energy,tower));
657 vector<RawTower*> tower_list;
658 for (
auto rit = tower_map.rbegin(); rit != tower_map.rend(); ++rit )
661 tower_list.push_back(tower);
674 if ( cluster == NULL || towers == NULL )
return vector<RawTower*>();
679 multimap<double,RawTower*> tower_map;
680 for (
auto it = range.first;
it != range.second; ++
it )
685 tower_map.insert(make_pair(energy,tower));
688 vector<RawTower*> tower_list;
689 for (
auto rit = tower_map.rbegin(); rit != tower_map.rend(); ++rit )
692 tower_list.push_back(tower);
718 if ( towers.size() == 0 )
return;
728 for (
unsigned int i = 0;
i < towers.size(); ++
i )
741 etabin -= etabin_center;
742 phibin -= phibin_center;
744 if ( phibin > nphi/2 ) phibin -=
nphi;
745 if ( phibin < -nphi/2 ) phibin +=
nphi;
774 double energy_sumtower[10] = {0};
775 double energy_singletower = 0;
776 unsigned int nloop = 10;
777 if ( towers.size() < nloop ) nloop = towers.size();
778 for (
unsigned int i = 0;
i < nloop; ++
i )
781 energy_singletower = towers[
i]->get_energy();
782 energy_sumtower[
i] = energy_singletower;
783 for (
unsigned int j =
i;
j > 0; --
j ) energy_sumtower[
j] += energy_sumtower[
j-1];