123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691 |
- #include <iostream>
- #include <vector>
- #include <map>
- #include <utility>
- #include <numeric>
- #include <limits>
- #include <TSystem.h>
- #include "filval/filval.hpp"
- #include "filval/root/filval.hpp"
- #include <boost/range/combine.hpp>
- #include <boost/format.hpp>
- #include "analysis/TrackingNtuple.h"
- #include "analysis/obj_types.cpp"
- #include "analysis/common.hpp"
- using namespace std;
- using namespace fv;
- using namespace fv::root;
- typedef std::pair<std::vector<float>,std::vector<float>> pair_vec;
- #define HIT_TYPE_PIXEL 0
- #define HIT_TYPE_GLUED 1
- #define HIT_TYPE_STRIP 2
- #define PIXEL_BARREL 1
- #define PIXEL_ENDCAP 2
- std::map<int,string> subdet_names = {{1, "BPIX"}, {2, "FPIX"}};
- typedef std::tuple<PixRecHit, SimHit> HitPair;
- void setup_hit_pair_functions(){
- func<pair_vec(vector<HitPair>)>("calc_dphi_v_eta",
- FUNC(([](const vector<HitPair>& hit_pairs){
- vector<float> dphis;
- vector<float> etas;
- for(auto hit_pair : hit_pairs){
- auto& pixrec_hit = std::get<PixRecHit>(hit_pair);
- auto& sim_hit = std::get<SimHit>(hit_pair);
- dphis.push_back(atan2(sim_hit.x, sim_hit.y) - atan2(pixrec_hit.x, pixrec_hit.y));
- etas.push_back(pseudorapidity(pixrec_hit));
- }
- return std::make_pair(etas, dphis);
- })));
- func<pair_vec(vector<HitPair>)>("calc_dr_v_eta",
- FUNC(([](const vector<HitPair>& hit_pairs){
- vector<float> drs;
- vector<float> etas;
- for(auto hit_pair : hit_pairs){
- auto& pixrec_hit = std::get<PixRecHit>(hit_pair);
- auto& sim_hit = std::get<SimHit>(hit_pair);
- drs.push_back(displacement(pixrec_hit, sim_hit));
- etas.push_back(pseudorapidity(pixrec_hit));
- }
- return std::make_pair(etas, drs);
- })));
- func<pair_vec(vector<HitPair>)>("calc_dz_v_eta",
- FUNC(([](const vector<HitPair>& hit_pairs){
- vector<float> dzs;
- vector<float> etas;
- for(auto hit_pair : hit_pairs){
- auto& pixrec_hit = std::get<PixRecHit>(hit_pair);
- auto& sim_hit = std::get<SimHit>(hit_pair);
- dzs.push_back(sim_hit.z - pixrec_hit.z);
- etas.push_back(pseudorapidity(pixrec_hit));
- }
- return std::make_pair(etas, dzs);
- })));
- func<pair_vec(vector<HitPair>)>("calc_drho_v_eta",
- FUNC(([](const vector<HitPair>& hit_pairs){
- vector<float> drhos;
- vector<float> etas;
- for(auto hit_pair : hit_pairs){
- auto& pixrec_hit = std::get<PixRecHit>(hit_pair);
- auto& sim_hit = std::get<SimHit>(hit_pair);
- drhos.push_back(rho(sim_hit) - rho(pixrec_hit));
- etas.push_back(pseudorapidity(pixrec_hit));
- }
- return std::make_pair(etas, drhos);
- })));
- }
- vector<string> seedTypes =
- {"initialStepSeeds",
- "highPtTripletStepSeeds",
- "mixedTripletStepSeeds",
- "pixelLessStepSeeds",
- "tripletElectronSeeds",
- "pixelPairElectronSeeds",
- "stripPairElectronSeeds"};
- Value<vector<SuperCluster>>* super_clusters;
- Value<vector<Seed>>* seeds;
- Value<vector<PixRecHit>>* pixrec_hits;
- Value<vector<Track>>* tracks;
- Value<vector<SimHit>>* sim_hits;
- Value<vector<SimTrack>>* sim_tracks;
- void register_objects(TrackingDataSet& tds){
- super_clusters = register_super_clusters(tds);
- seeds = register_seeds(tds);
- pixrec_hits = register_pixrec_hits(tds);
- tracks = register_tracks(tds);
- sim_hits = register_sim_hits(tds);
- sim_tracks = register_sim_tracks(tds);
- }
- template<typename A>
- bool in_det(const A& hit, const unsigned int& det, const unsigned int& lay){
- return hit.det == det && hit.lay == lay;
- }
- void setup_skipped_layer_hit_pairs(TrackingDataSet& tds){
- /* Finds SimHit/RecHit pairs
- */
- auto find_matched_nth_hit_in_layer_with_skip =
- func<vector<HitPair>(vector<Seed>,
- vector<PixRecHit>,
- vector<SimHit>,
- vector<Track>,
- vector<SimTrack>,
- int, int, int, bool)>("find_matched_nth_hit_in_layer_with_skip",
- FUNC(([](const vector<Seed>& seeds,
- const vector<PixRecHit>& pixrec_hits,
- const vector<SimHit>& sim_hits,
- const vector<Track>& tracks,
- const vector<SimTrack>& sim_tracks,
- const unsigned int&& det,
- const unsigned int&& pix_layer,
- const unsigned int&& skip,
- const bool&& first){
- vector<HitPair> matched_hits;
- for(const Track &trk : tracks){ // loop over all tracks
- const Seed &seed = seeds[trk.seedIdx];
- // Require seed's source algorithm is one of those in seedTypes
- if(seed.algoOriginal < 0 || seed.algoOriginal >= seedTypes.size()) continue;
- // Require seed w/ at least 2 hits
- if(seed.hitIdx.size() < 2) continue;
- // take only pixel hits for now
- if(seed.hitType[0] != HIT_TYPE_PIXEL || seed.hitType[1] != HIT_TYPE_PIXEL) continue;
- const PixRecHit &rec_hit1 = pixrec_hits[seed.hitIdx[0]];
- const PixRecHit &rec_hit2 = pixrec_hits[seed.hitIdx[1]];
- if(first){ // Looking at first hit in the pair
- if(in_det(rec_hit1, det, pix_layer) && in_det(rec_hit2, det, pix_layer+1+skip)){
- // We have the RecHit we want to work with, now find a properly* matched SimHit
- if(rec_hit1.simHitIdx.size() == 0) continue; // if rechit is matched to no simhits, give up.
- if(trk.simTrkIdx.size() == 0) continue; // if track is matched to no simtracks, give up.
- const int &simTrkIdx = trk.simTrkIdx[0]; // get first matched track
- for(const int& simHitIdx : sim_tracks[simTrkIdx].simHitIdx){ // loop over SimHits from SimTrack
- if(simHitIdx == rec_hit1.simHitIdx[0]) // take first matched simhit (should be the closest one)
- matched_hits.push_back({rec_hit1, sim_hits[rec_hit1.simHitIdx[0]]});
- }
- }
- }else{ // Looking at second hit in the pair
- if(in_det(rec_hit2, det, pix_layer) && in_det(rec_hit1, det, pix_layer-1-skip)){
- // We have the RecHit we want to work with, now find a properly* matched SimHit
- if(rec_hit2.simHitIdx.size() == 0) continue; // if rechit is matched to no simhits, give up.
- if(trk.simTrkIdx.size() == 0) continue; // if track is matched to no simtracks, give up.
- const int &simTrkIdx = trk.simTrkIdx[0]; // get first matched track
- for(const int& simHitIdx : sim_tracks[simTrkIdx].simHitIdx){ // loop over SimHits from SimTrack
- if(simHitIdx == rec_hit1.simHitIdx[0]) // take first matched simhit (should be the closest one)
- matched_hits.push_back({rec_hit2, sim_hits[rec_hit2.simHitIdx[0]]});
- }
- }
- }
- }
- return matched_hits;
- })));
- auto pix_barrel = constant("PIXEL_BARREL", PIXEL_BARREL);
- auto pix_endcap = constant("PIXEL_ENDCAP", PIXEL_ENDCAP);
- auto L1 = constant("L1", 1);
- auto L2 = constant("L2", 2);
- auto skip_zero = constant("skip_zero", 0);
- auto skip_one = constant("skip_one", 1);
- auto first = constant("first", true);
- auto second = constant("second", false);
- // First hit on 1st/2nd bpix layers and second hit in 2nd/3rd
- auto first_hits_in_B1_skip_zero = fv::tup_apply(find_matched_nth_hit_in_layer_with_skip,
- fv::tuple(seeds, pixrec_hits, sim_hits, tracks, sim_tracks, pix_barrel, L1, skip_zero, first), "first_hits_in_B1_skip_zero");
- auto first_hits_in_B2_skip_zero = fv::tup_apply(find_matched_nth_hit_in_layer_with_skip,
- fv::tuple(seeds, pixrec_hits, sim_hits, tracks, sim_tracks, pix_barrel, L2, skip_zero, first), "first_hits_in_B2_skip_zero");
- // First hit on 1st/2nd fpix layers and second hit in 2nd/3rd
- auto first_hits_in_F1_skip_zero = fv::tup_apply(find_matched_nth_hit_in_layer_with_skip,
- fv::tuple(seeds, pixrec_hits, sim_hits, tracks, sim_tracks, pix_endcap, L1, skip_zero, first), "first_hits_in_F1_skip_zero");
- auto first_hits_in_F2_skip_zero = fv::tup_apply(find_matched_nth_hit_in_layer_with_skip,
- fv::tuple(seeds, pixrec_hits, sim_hits, tracks, sim_tracks, pix_endcap, L2, skip_zero, first), "first_hits_in_F2_skip_zero");
- // First hit on 1st/2nd fpix layers and second hit in 3rd/4th
- auto first_hits_in_B1_skip_one = fv::tup_apply(find_matched_nth_hit_in_layer_with_skip,
- fv::tuple(seeds, pixrec_hits, sim_hits, tracks, sim_tracks, pix_barrel, L1, skip_one, first), "first_hits_in_B1_skip_one");
- auto first_hits_in_B2_skip_one = fv::tup_apply(find_matched_nth_hit_in_layer_with_skip,
- fv::tuple(seeds, pixrec_hits, sim_hits, tracks, sim_tracks, pix_barrel, L2, skip_one, first), "first_hits_in_B2_skip_one");
- // First hit on 1st fpix layer and second hit in 3rd layer
- auto first_hits_in_F1_skip_one = fv::tup_apply(find_matched_nth_hit_in_layer_with_skip,
- fv::tuple(seeds, pixrec_hits, sim_hits, tracks, sim_tracks, pix_endcap, L1, skip_one, first), "first_hits_in_F1_skip_one");
- TH2Params params_dz = {"$\\eta$", 100, -4, 4,
- "$\\Delta z$(rad)", 50, -.01, .01};
- auto calc_dz_v_eta = lookup_function<pair_vec(vector<HitPair>)>("calc_dz_v_eta");
- tds.register_container<ContainerTH2Many<float>>("dz_v_eta_first_hits_in_B1_skip_zero",
- fv::apply(calc_dz_v_eta, first_hits_in_B1_skip_zero),
- "First Hit in BPIX-L1 - Skip 0", params_dz);
- tds.register_container<ContainerTH2Many<float>>("dz_v_eta_first_hits_in_B2_skip_zero",
- fv::apply(calc_dz_v_eta, first_hits_in_B2_skip_zero),
- "First Hit in BPIX-L2 - Skip 0", params_dz);
- tds.register_container<ContainerTH2Many<float>>("dz_v_eta_first_hits_in_F1_skip_zero",
- fv::apply(calc_dz_v_eta, first_hits_in_F1_skip_zero),
- "First Hit in FPIX-L1 - Skip 0", params_dz);
- tds.register_container<ContainerTH2Many<float>>("dz_v_eta_first_hits_in_F2_skip_zero",
- fv::apply(calc_dz_v_eta, first_hits_in_F2_skip_zero),
- "First Hit in FPIX-L2 - Skip 0", params_dz);
- tds.register_container<ContainerTH2Many<float>>("dz_v_eta_first_hits_in_B1_skip_one",
- fv::apply(calc_dz_v_eta, first_hits_in_B1_skip_one),
- "First Hit in BPIX-L1 - Skip 1", params_dz);
- tds.register_container<ContainerTH2Many<float>>("dz_v_eta_first_hits_in_B2_skip_one",
- fv::apply(calc_dz_v_eta, first_hits_in_B2_skip_one),
- "First Hit in BPIX-L2 - Skip 1", params_dz);
- tds.register_container<ContainerTH2Many<float>>("dz_v_eta_first_hits_in_F1_skip_one",
- fv::apply(calc_dz_v_eta, first_hits_in_F1_skip_one),
- "First Hit in FPIX-L1 - Skip 1", params_dz);
- }
- void setup_first_hit_pairs(TrackingDataSet& tds){
- auto find_matched_nth_hit_in_layer =
- func<vector<HitPair>(vector<Seed>,
- vector<PixRecHit>,
- vector<SimHit>,
- vector<Track>,
- vector<SimTrack>,
- int, int, int)>("find_matched_nth_hit_in_layer",
- FUNC(([](const vector<Seed>& seeds,
- const vector<PixRecHit>& pixrec_hits,
- const vector<SimHit>& sim_hits,
- const vector<Track>& tracks,
- const vector<SimTrack>& sim_tracks,
- const unsigned int&& det,
- const unsigned int&& pix_layer,
- const unsigned int&& hit_number){
- vector<HitPair> matched_hits;
- for(const Track &trk : tracks){ // loop over all tracks
- const Seed &seed = seeds[trk.seedIdx];
- if(seed.hitIdx.size() <= hit_number) continue; // looking for hit_number'th hit
- if(seed.algoOriginal < 0 || seed.algoOriginal >= seedTypes.size()) continue;
- if(seed.hitType[hit_number] != HIT_TYPE_PIXEL) continue; // take only pixel hits for now
- const PixRecHit &rec_hit = pixrec_hits[seed.hitIdx[hit_number]];
- if(rec_hit.det == det && rec_hit.lay == pix_layer){
- // We have the RecHit we want to work with, now find a properly* matched SimHit
- if(rec_hit.simHitIdx.size() == 0) continue; // if rechit is matched to no simhits, give up.
- if(trk.simTrkIdx.size() == 0) continue; // if rechit is matched to no simhits, give up.
- const int &simTrkIdx = trk.simTrkIdx[0]; // get first matched track
- for(const int& simHitIdx : sim_tracks[simTrkIdx].simHitIdx){ // loop over SimHits from SimTrack
- if(simHitIdx == rec_hit.simHitIdx[0]) // take first matched simhit (should be the closest one)
- matched_hits.push_back({rec_hit, sim_hits[rec_hit.simHitIdx[0]]});
- }
- }
- }
- return matched_hits;
- })));
- auto barrel_val = constant("PIXEL_BARREL", PIXEL_BARREL);
- auto endcap_val = constant("PIXEL_ENDCAP", PIXEL_ENDCAP);
- auto first_hit = constant("1st", 0);
- auto second_hit = constant("2nd", 1);
- // First hits on inner three bpix layers
- auto first_hits_in_B1 = fv::tup_apply(find_matched_nth_hit_in_layer,
- fv::tuple(seeds, pixrec_hits, sim_hits, tracks, sim_tracks, barrel_val, constant("L1", 1), first_hit), "first_hits_in_B1");
- auto first_hits_in_B2 = fv::tup_apply(find_matched_nth_hit_in_layer,
- fv::tuple(seeds, pixrec_hits, sim_hits, tracks, sim_tracks, barrel_val, constant("L2", 2), first_hit), "first_hits_in_B2");
- // Second hits on outer three bpix layers
- auto second_hits_in_B2 = fv::tup_apply(find_matched_nth_hit_in_layer,
- fv::tuple(seeds, pixrec_hits, sim_hits, tracks, sim_tracks, barrel_val, constant("L2", 2), second_hit), "second_hits_in_B2");
- auto second_hits_in_B3 = fv::tup_apply(find_matched_nth_hit_in_layer,
- fv::tuple(seeds, pixrec_hits, sim_hits, tracks, sim_tracks, barrel_val, constant("L3", 3), second_hit), "second_hits_in_B3");
- auto second_hits_in_B4 = fv::tup_apply(find_matched_nth_hit_in_layer,
- fv::tuple(seeds, pixrec_hits, sim_hits, tracks, sim_tracks, barrel_val, constant("L4", 4), second_hit), "second_hits_in_B4");
- auto first_hits_in_F1 = fv::tup_apply(find_matched_nth_hit_in_layer,
- fv::tuple(seeds, pixrec_hits, sim_hits, tracks, sim_tracks, endcap_val, constant("L1", 1), first_hit), "first_hits_in_F1");
- auto first_hits_in_F2 = fv::tup_apply(find_matched_nth_hit_in_layer,
- fv::tuple(seeds, pixrec_hits, sim_hits, tracks, sim_tracks, endcap_val, constant("L2", 2), first_hit), "first_hits_in_F2");
- auto second_hits_in_F2 = fv::tup_apply(find_matched_nth_hit_in_layer,
- fv::tuple(seeds, pixrec_hits, sim_hits, tracks, sim_tracks, endcap_val, constant("L2", 2), second_hit), "second_hits_in_F2");
- auto second_hits_in_F3 = fv::tup_apply(find_matched_nth_hit_in_layer,
- fv::tuple(seeds, pixrec_hits, sim_hits, tracks, sim_tracks, endcap_val, constant("L3", 3), second_hit), "second_hits_in_F3");
- // Even vs Odd Ladders
- auto even = constant("even", false);
- auto odd = constant("odd", true);
- auto select_even_odd_ladder_blade_hit_pairs =
- func<vector<HitPair>(vector<HitPair>, bool)>("select_even_odd_ladder_blade_hit_pairs",
- FUNC(([](const vector<HitPair>& hit_pairs,
- const bool &&odd){
- vector<HitPair> even_pairs;
- for(const HitPair &hit_pair : hit_pairs){ // loop over all seeds
- if(std::get<PixRecHit>(hit_pair).ladder_blade % 2 == odd){
- even_pairs.push_back(hit_pair);
- }
- }
- return even_pairs;
- })));
- auto first_hits_in_B1_even_ladder = fv::tup_apply(select_even_odd_ladder_blade_hit_pairs,
- fv::tuple(first_hits_in_B1, even), "first_hits_in_B1_even_ladder");
- auto first_hits_in_B1_odd_ladder = fv::tup_apply(select_even_odd_ladder_blade_hit_pairs,
- fv::tuple(first_hits_in_B1, odd), "first_hits_in_B1_odd_ladder");
- auto first_hits_in_B2_even_ladder = fv::tup_apply(select_even_odd_ladder_blade_hit_pairs,
- fv::tuple(first_hits_in_B2, even), "first_hits_in_B2_even_ladder");
- auto first_hits_in_B2_odd_ladder = fv::tup_apply(select_even_odd_ladder_blade_hit_pairs,
- fv::tuple(first_hits_in_B2, odd), "first_hits_in_B2_odd_ladder");
- //Plots for dPhi of collections defined above
- auto calc_dphi_v_eta = lookup_function<pair_vec(vector<HitPair>)>("calc_dphi_v_eta");
- TH2Params params_dphi = {"$\\eta$", 100, -4, 4,
- "$\\Delta \\phi$(rad)", 50, -.0015, .0015};
- tds.register_container<ContainerTH2Many<float>>("dphi_v_eta_first_hits_in_B1",
- fv::apply(calc_dphi_v_eta, first_hits_in_B1),
- "First Hit in BPIX-L1", params_dphi);
- tds.register_container<ContainerTH2Many<float>>("dphi_v_eta_first_hits_in_B2",
- fv::apply(calc_dphi_v_eta, first_hits_in_B2),
- "First Hit in BPIX-L2", params_dphi);
- tds.register_container<ContainerTH2Many<float>>("dphi_v_eta_first_hits_in_B1_even_ladder",
- fv::apply(calc_dphi_v_eta, first_hits_in_B1_even_ladder),
- "First Hit in BPIX-L1 - Even Ladders", params_dphi);
- tds.register_container<ContainerTH2Many<float>>("dphi_v_eta_first_hits_in_B1_odd_ladder",
- fv::apply(calc_dphi_v_eta, first_hits_in_B1_odd_ladder),
- "First Hit in BPIX-L1 - Odd Ladders", params_dphi);
- tds.register_container<ContainerTH2Many<float>>("dphi_v_eta_first_hits_in_B2_even_ladder",
- fv::apply(calc_dphi_v_eta, first_hits_in_B2_even_ladder),
- "First Hit in BPIX-L2 - Even Ladders", params_dphi);
- tds.register_container<ContainerTH2Many<float>>("dphi_v_eta_first_hits_in_B2_odd_ladder",
- fv::apply(calc_dphi_v_eta, first_hits_in_B2_odd_ladder),
- "First Hit in BPIX-L2 - Odd Ladders", params_dphi);
- tds.register_container<ContainerTH2Many<float>>("dphi_v_eta_second_hits_in_B2",
- fv::apply(calc_dphi_v_eta, second_hits_in_B2),
- "Second Hit in BPIX-L2", params_dphi);
- tds.register_container<ContainerTH2Many<float>>("dphi_v_eta_second_hits_in_B3",
- fv::apply(calc_dphi_v_eta, second_hits_in_B3),
- "Second Hit in BPIX-L3", params_dphi);
- tds.register_container<ContainerTH2Many<float>>("dphi_v_eta_second_hits_in_B4",
- fv::apply(calc_dphi_v_eta, second_hits_in_B4),
- "Second Hit in BPIX-L4", params_dphi);
- tds.register_container<ContainerTH2Many<float>>("dphi_v_eta_first_hits_in_F1",
- fv::apply(calc_dphi_v_eta, first_hits_in_F1),
- "First Hit in FPIX-L1", params_dphi);
- tds.register_container<ContainerTH2Many<float>>("dphi_v_eta_first_hits_in_F2",
- fv::apply(calc_dphi_v_eta, first_hits_in_F2),
- "First Hit in FPIX-L2", params_dphi);
- tds.register_container<ContainerTH2Many<float>>("dphi_v_eta_second_hits_in_F2",
- fv::apply(calc_dphi_v_eta, second_hits_in_F2),
- "Second Hit in FPIX-L2", params_dphi);
- tds.register_container<ContainerTH2Many<float>>("dphi_v_eta_second_hits_in_F3",
- fv::apply(calc_dphi_v_eta, second_hits_in_F3),
- "Second Hit in FPIX-L3", params_dphi);
- //Plots for dr of collections defined above
- auto calc_dr_v_eta = lookup_function<pair_vec(vector<HitPair>)>("calc_dr_v_eta");
- TH2Params params_dr = {"$\\eta$", 100, -4, 4,
- "$\\Delta \\r$(rad)", 50, 0, .006};
- tds.register_container<ContainerTH2Many<float>>("dr_v_eta_first_hits_in_B1",
- fv::apply(calc_dr_v_eta, first_hits_in_B1),
- "First Hit in BPIX-L1", params_dr);
- tds.register_container<ContainerTH2Many<float>>("dr_v_eta_first_hits_in_B2",
- fv::apply(calc_dr_v_eta, first_hits_in_B2),
- "First Hit in BPIX-L2", params_dr);
- tds.register_container<ContainerTH2Many<float>>("dr_v_eta_first_hits_in_B1_even_ladder",
- fv::apply(calc_dr_v_eta, first_hits_in_B1_even_ladder),
- "First Hit in BPIX-L1 - Even Ladders", params_dr);
- tds.register_container<ContainerTH2Many<float>>("dr_v_eta_first_hits_in_B1_odd_ladder",
- fv::apply(calc_dr_v_eta, first_hits_in_B1_odd_ladder),
- "First Hit in BPIX-L1 - Odd Ladders", params_dr);
- tds.register_container<ContainerTH2Many<float>>("dr_v_eta_first_hits_in_B2_even_ladder",
- fv::apply(calc_dr_v_eta, first_hits_in_B2_even_ladder),
- "First Hit in BPIX-L2 - Even Ladders", params_dr);
- tds.register_container<ContainerTH2Many<float>>("dr_v_eta_first_hits_in_B2_odd_ladder",
- fv::apply(calc_dr_v_eta, first_hits_in_B2_odd_ladder),
- "First Hit in BPIX-L2 - Odd Ladders", params_dr);
- tds.register_container<ContainerTH2Many<float>>("dr_v_eta_second_hits_in_B2",
- fv::apply(calc_dr_v_eta, second_hits_in_B2),
- "Second Hit in BPIX-L2", params_dr);
- tds.register_container<ContainerTH2Many<float>>("dr_v_eta_second_hits_in_B3",
- fv::apply(calc_dr_v_eta, second_hits_in_B3),
- "Second Hit in BPIX-L3", params_dr);
- tds.register_container<ContainerTH2Many<float>>("dr_v_eta_second_hits_in_B4",
- fv::apply(calc_dr_v_eta, second_hits_in_B4),
- "Second Hit in BPIX-L4", params_dr);
- tds.register_container<ContainerTH2Many<float>>("dr_v_eta_first_hits_in_F1",
- fv::apply(calc_dr_v_eta, first_hits_in_F1),
- "First Hit in FPIX-L1", params_dr);
- tds.register_container<ContainerTH2Many<float>>("dr_v_eta_first_hits_in_F2",
- fv::apply(calc_dr_v_eta, first_hits_in_F2),
- "First Hit in FPIX-L2", params_dr);
- tds.register_container<ContainerTH2Many<float>>("dr_v_eta_second_hits_in_F2",
- fv::apply(calc_dr_v_eta, second_hits_in_F2),
- "Second Hit in FPIX-L2", params_dr);
- tds.register_container<ContainerTH2Many<float>>("dr_v_eta_second_hits_in_F3",
- fv::apply(calc_dr_v_eta, second_hits_in_F3),
- "Second Hit in FPIX-L3", params_dr);
- //Plots for dz of collections defined above
- auto calc_dz_v_eta = lookup_function<pair_vec(vector<HitPair>)>("calc_dz_v_eta");
- TH2Params params_dz = {"$\\eta$", 100, -4, 4,
- "$\\Delta z$(rad)", 50, -.01, .01};
- tds.register_container<ContainerTH2Many<float>>("dz_v_eta_first_hits_in_B1",
- fv::apply(calc_dz_v_eta, first_hits_in_B1),
- "First Hit in BPIX-L1", params_dz);
- tds.register_container<ContainerTH2Many<float>>("dz_v_eta_first_hits_in_B2",
- fv::apply(calc_dz_v_eta, first_hits_in_B2),
- "First Hit in BPIX-L2", params_dz);
- tds.register_container<ContainerTH2Many<float>>("dz_v_eta_first_hits_in_B1_even_ladder",
- fv::apply(calc_dz_v_eta, first_hits_in_B1_even_ladder),
- "First Hit in BPIX-L1 - Even Ladders", params_dz);
- tds.register_container<ContainerTH2Many<float>>("dz_v_eta_first_hits_in_B1_odd_ladder",
- fv::apply(calc_dz_v_eta, first_hits_in_B1_odd_ladder),
- "First Hit in BPIX-L1 - Odd Ladders", params_dz);
- tds.register_container<ContainerTH2Many<float>>("dz_v_eta_first_hits_in_B2_even_ladder",
- fv::apply(calc_dz_v_eta, first_hits_in_B2_even_ladder),
- "First Hit in BPIX-L2 - Even Ladders", params_dz);
- tds.register_container<ContainerTH2Many<float>>("dz_v_eta_first_hits_in_B2_odd_ladder",
- fv::apply(calc_dz_v_eta, first_hits_in_B2_odd_ladder),
- "First Hit in BPIX-L2 - Odd Ladders", params_dz);
- tds.register_container<ContainerTH2Many<float>>("dz_v_eta_second_hits_in_B2",
- fv::apply(calc_dz_v_eta, second_hits_in_B2),
- "Second Hit in BPIX-L2", params_dz);
- tds.register_container<ContainerTH2Many<float>>("dz_v_eta_second_hits_in_B3",
- fv::apply(calc_dz_v_eta, second_hits_in_B3),
- "Second Hit in BPIX-L3", params_dz);
- tds.register_container<ContainerTH2Many<float>>("dz_v_eta_second_hits_in_B4",
- fv::apply(calc_dz_v_eta, second_hits_in_B4),
- "Second Hit in BPIX-L4", params_dz);
- //Plots for drho of collections defined above
- auto calc_drho_v_eta = lookup_function<pair_vec(vector<HitPair>)>("calc_drho_v_eta");
- TH2Params params_drho = {"$\\eta$", 100, -4, 4,
- "$\\Delta \\rho$(cm)", 50, -.01, .01};
- tds.register_container<ContainerTH2Many<float>>("drho_v_eta_first_hits_in_F1",
- fv::apply(calc_drho_v_eta, first_hits_in_F1),
- "First Hit in FPIX-L1", params_drho);
- tds.register_container<ContainerTH2Many<float>>("drho_v_eta_first_hits_in_F2",
- fv::apply(calc_drho_v_eta, first_hits_in_F2),
- "First Hit in FPIX-L2", params_drho);
- tds.register_container<ContainerTH2Many<float>>("drho_v_eta_second_hits_in_F2",
- fv::apply(calc_drho_v_eta, second_hits_in_F2),
- "Second Hit in FPIX-L2", params_drho);
- tds.register_container<ContainerTH2Many<float>>("drho_v_eta_second_hits_in_F3",
- fv::apply(calc_drho_v_eta, second_hits_in_F3),
- "Second Hit in FPIX-L3", params_drho);
- }
- void sc_value_hists_for_lb(TrackingDataSet& tds, std::function<bool(int)>& parity_check,
- const std::string& label){
- auto relabel = [label](const std::string&& base){
- return base + "_" + label;
- };
- auto pix_barrel = constant("PIXEL_BARREL", PIXEL_BARREL);
- auto pix_endcap = constant("PIXEL_ENDCAP", PIXEL_ENDCAP);
- auto first_hit = constant("1st", 0);
- auto second_hit = constant("2nd", 1);
- auto L1 = constant("L1", 1);
- auto L2 = constant("L2", 2);
- auto L3 = constant("L3", 3);
- auto L4 = constant("L4", 4);
- auto dRz = constant("dRz", true);
- auto dPhi = constant("dPhi", false);
- auto pcheck = constant(label, parity_check);
- auto sc_hit_residuals = lookup_function<
- pair_vec(vector<SuperCluster>, int, int, int, bool, std::function<bool(int)>)>("sc_hit_residuals");
- // First hits on inner three bpix layers
- auto sc_first_hits_in_B1_dz = fv::tup_apply(sc_hit_residuals,
- fv::tuple(super_clusters, pix_barrel, L1, first_hit, dRz, pcheck), relabel("sc_first_hits_in_B1_dz"));
- auto sc_first_hits_in_B2_dz = fv::tup_apply(sc_hit_residuals,
- fv::tuple(super_clusters, pix_barrel, L2, first_hit, dRz, pcheck), relabel("sc_first_hits_in_B2_dz"));
- auto sc_first_hits_in_B3_dz = fv::tup_apply(sc_hit_residuals,
- fv::tuple(super_clusters, pix_barrel, L3, first_hit, dRz, pcheck), relabel("sc_first_hits_in_B3_dz"));
- auto sc_first_hits_in_B1_dphi = fv::tup_apply(sc_hit_residuals,
- fv::tuple(super_clusters, pix_barrel, L1, first_hit, dPhi, pcheck), relabel("sc_first_hits_in_B1_dphi"));
- auto sc_first_hits_in_B2_dphi = fv::tup_apply(sc_hit_residuals,
- fv::tuple(super_clusters, pix_barrel, L2, first_hit, dPhi, pcheck), relabel("sc_first_hits_in_B2_dphi"));
- auto sc_first_hits_in_B3_dphi = fv::tup_apply(sc_hit_residuals,
- fv::tuple(super_clusters, pix_barrel, L3, first_hit, dPhi, pcheck), relabel("sc_first_hits_in_B3_dphi"));
- // Second hits on outer three bpix layers
- auto sc_second_hits_in_B2_dz = fv::tup_apply(sc_hit_residuals,
- fv::tuple(super_clusters, pix_barrel, L2, second_hit, dRz, pcheck), relabel("sc_second_hits_in_B2_dz"));
- auto sc_second_hits_in_B3_dz = fv::tup_apply(sc_hit_residuals,
- fv::tuple(super_clusters, pix_barrel, L3, second_hit, dRz, pcheck), relabel("sc_second_hits_in_B3_dz"));
- auto sc_second_hits_in_B4_dz = fv::tup_apply(sc_hit_residuals,
- fv::tuple(super_clusters, pix_barrel, L4, second_hit, dRz, pcheck), relabel("sc_second_hits_in_B4_dz"));
- auto sc_second_hits_in_B2_dphi = fv::tup_apply(sc_hit_residuals,
- fv::tuple(super_clusters, pix_barrel, L2, second_hit, dPhi, pcheck), relabel("sc_second_hits_in_B2_dphi"));
- auto sc_second_hits_in_B3_dphi = fv::tup_apply(sc_hit_residuals,
- fv::tuple(super_clusters, pix_barrel, L3, second_hit, dPhi, pcheck), relabel("sc_second_hits_in_B3_dphi"));
- auto sc_second_hits_in_B4_dphi = fv::tup_apply(sc_hit_residuals,
- fv::tuple(super_clusters, pix_barrel, L4, second_hit, dPhi, pcheck), relabel("sc_second_hits_in_B4_dphi"));
- TH2Params params_dz = {"$\\eta$", 100, -4, 4,
- "$\\delta z$(cm)", 100, -0.7, 0.7};
- tds.register_container<ContainerTH2Many<float>>(relabel("sc_first_hits_in_B1_dz"),
- sc_first_hits_in_B1_dz,
- "First Hit in BPIX-L1", params_dz);
- tds.register_container<ContainerTH2Many<float>>(relabel("sc_first_hits_in_B2_dz"),
- sc_first_hits_in_B2_dz,
- "First Hit in BPIX-L2", params_dz);
- tds.register_container<ContainerTH2Many<float>>(relabel("sc_first_hits_in_B3_dz"),
- sc_first_hits_in_B3_dz,
- "First Hit in BPIX-L3", params_dz);
- tds.register_container<ContainerTH2Many<float>>(relabel("sc_second_hits_in_B2_dz"),
- sc_second_hits_in_B2_dz,
- "Second Hit in BPIX-L2", params_dz);
- tds.register_container<ContainerTH2Many<float>>(relabel("sc_second_hits_in_B3_dz"),
- sc_second_hits_in_B3_dz,
- "Second Hit in BPIX-L3", params_dz);
- tds.register_container<ContainerTH2Many<float>>(relabel("sc_second_hits_in_B4_dz"),
- sc_second_hits_in_B4_dz,
- "Second Hit in BPIX-L4", params_dz);
- TH2Params params_dphi = {"$\\eta$", 100, -4, 4,
- "$\\delta \\phi$(rad)", 500, -0.7, 0.7};
- tds.register_container<ContainerTH2Many<float>>(relabel("sc_first_hits_in_B1_dphi"),
- sc_first_hits_in_B1_dphi,
- "First Hit in BPIX-L1", params_dphi);
- tds.register_container<ContainerTH2Many<float>>(relabel("sc_first_hits_in_B2_dphi"),
- sc_first_hits_in_B2_dphi,
- "First Hit in BPIX-L2", params_dphi);
- tds.register_container<ContainerTH2Many<float>>(relabel("sc_first_hits_in_B3_dphi"),
- sc_first_hits_in_B3_dphi,
- "First Hit in BPIX-L3", params_dphi);
- tds.register_container<ContainerTH2Many<float>>(relabel("sc_second_hits_in_B2_dphi"),
- sc_second_hits_in_B2_dphi,
- "Second Hit in BPIX-L2", params_dphi);
- tds.register_container<ContainerTH2Many<float>>(relabel("sc_second_hits_in_B3_dphi"),
- sc_second_hits_in_B3_dphi,
- "Second Hit in BPIX-L3", params_dphi);
- tds.register_container<ContainerTH2Many<float>>(relabel("sc_second_hits_in_B4_dphi"),
- sc_second_hits_in_B4_dphi,
- "Second Hit in BPIX-L4", params_dphi);
- }
- void setup_sc_residuals(TrackingDataSet& tds){
- func<pair_vec(vector<SuperCluster>,
- int, int, int, bool,
- std::function<bool(int)>)>("sc_hit_residuals",
- FUNC(([](const vector<SuperCluster>& super_clusters,
- const int&& det,
- const int&& pix_layer,
- const int&& hit_number,
- const bool&& sel_dRz,
- const std::function<bool(int)>& pcheck){
- vector<float> residuals;
- vector<float> etas;
- for(const SuperCluster& super_cluster : super_clusters){ // loop over all supser-clusters
- float dRz, dPhi;
- int ladder_blade;
- unsigned int nSeeds = super_cluster.charge.size();
- for(unsigned int seedIdx=0; seedIdx<nSeeds; seedIdx++){ // loop over all seeds associated w/ sc
- if(hit_number == 0){
- if(super_cluster.lay1[seedIdx] != pix_layer || super_cluster.subDet1[seedIdx] != det) continue;
- dRz = super_cluster.dRz1[seedIdx];
- dPhi = super_cluster.dPhi1[seedIdx];
- ladder_blade = super_cluster.ladder_blade1[seedIdx];
- }else{
- if(super_cluster.lay2[seedIdx] != pix_layer || super_cluster.subDet2[seedIdx] != det) continue;
- dRz = super_cluster.dRz2[seedIdx];
- dPhi = super_cluster.dPhi2[seedIdx];
- ladder_blade = super_cluster.ladder_blade2[seedIdx];
- }
- DEBUG("New Seed, Idx: " << seedIdx << endl
- << "\tdRz: " << dRz << endl
- << "\tdPhi: " << dPhi << endl);
- if(!pcheck(ladder_blade)) continue;
- if(sel_dRz)
- residuals.push_back(dRz);
- else
- residuals.push_back(dPhi);
- etas.push_back(pseudorapidityP(super_cluster));
- }
- }
- return std::make_pair(etas,residuals);
- })));
- std::function<bool(int)> even = [](const int& t){ return !(t%2); };
- std::function<bool(int)> odd = [](const int& t){ return (t%2); };
- std::function<bool(int)> both = [](const int&){ return true; };
- sc_value_hists_for_lb(tds, even, "even");
- sc_value_hists_for_lb(tds, odd, "odd");
- sc_value_hists_for_lb(tds, both, "either");
- }
- void run_analysis(const vector<fv::util::DataFileDescriptor>& dfds, const string output_filename, bool silent){
- gSystem->Load("libfilval.so");
- auto replace_suffix = [](const std::string& input, const std::string& new_suffix){
- return input.substr(0, input.find_last_of(".")) + new_suffix;
- };
- string log_filename = replace_suffix(output_filename, ".log");
- fv::util::Log::init_logger(log_filename, fv::util::LogPriority::kLogInfo);
- TrackingDataSet tds(output_filename, dfds, "trackingNtuple/tree");
- /* tds.set_max_events(10); */
- register_objects(tds);
- setup_hit_pair_functions();
- setup_first_hit_pairs(tds);
- setup_skipped_layer_hit_pairs(tds);
- setup_sc_residuals(tds);
- tds.process(silent);
- tds.save_all();
- }
- int main(int argc, char * argv[]){
- fv::util::ArgParser args(argc, argv);
- bool silent = args.cmdOptionExists("-s");
- string output_filename = args.cmdOptionExists("-o") ? args.getCmdOption("-o") : "output.root";
- if(args.cmdOptionExists("-F")){
- auto file_list = fv::util::read_input_list(args.getCmdOption("-F"));
- run_analysis(file_list, output_filename, silent);
- }else if(args.cmdOptionExists("-f")){
- string input_filename = args.getCmdOption("-f");
- string data_label = args.cmdOptionExists("-l") ? args.getCmdOption("-l") : "";
- string data_category = args.cmdOptionExists("-c") ? args.getCmdOption("-c") : "";
- fv::util::DataFileDescriptor dfd(input_filename, data_label, data_category);
- run_analysis(std::vector<fv::util::DataFileDescriptor>({dfd}), output_filename, silent);
- }else {
- cout << "Usage: ./tracking_validation (-s) {-o output_filename} -F datafiles.txt" << endl;
- cout << " ./tracking_validation (-s) {-l DATA_LABEL} {-c DATA_CATEGORY} {-o output_filename} -f treefile.root" << endl;
- }
- return 0;
- }
|