hpstr
The Heavy Photon Search Toolkit for Reconstruction (hpstr) provides an interface to physics data from the HPS experiment saved in the LCIO format and converts it into an ROOT based format.
Loading...
Searching...
No Matches
TrackingAnaProcessor.cxx
Go to the documentation of this file.
2#include <iomanip>
3#include "utilities.h"
4
8
11
13
14 std::cout << "Configuring TrackingAnaProcessor" << std::endl;
15 try
16 {
17 debug_ = parameters.getInteger("debug",debug_);
18 seed_ = parameters.getInteger("seed",seed_);
19 trkCollName_ = parameters.getString("trkCollName",trkCollName_);
20 histCfgFilename_ = parameters.getString("histCfg",histCfgFilename_);
21 doTruth_ = (bool) parameters.getInteger("doTruth",doTruth_);
22 truthHistCfgFilename_ = parameters.getString("truthHistCfg",truthHistCfgFilename_);
23 selectionCfg_ = parameters.getString("selectionjson",selectionCfg_);
24 isData_ = parameters.getInteger("isData",isData_);
25 ecalCollName_ = parameters.getString("ecalCollName",ecalCollName_);
26 regionSelections_ = parameters.getVString("regionDefinitions",regionSelections_);
27
28 //Momentum smearing closure test
29 pSmearingFile_ = parameters.getString("pSmearingFile",pSmearingFile_);
30 smearingCfgFile_ = parameters.getString("smearingCfg",smearingCfgFile_);
31
32 // Master switch for smearing (default false for backward compatibility)
33 doSmearing_ = parameters.getInteger("doSmearing", 0) != 0;
34
35 // Factor to multiply smearing parameters by (default 1.0)
36 smearingFactor_ = parameters.getDouble("smearingFactor", 1.0);
37
38 // Require truth match for smearing (default false)
39 requireTruthMatch_ = parameters.getInteger("requireTruthMatch", 0) != 0;
40
41 // Use omega (curvature) smearing instead of p smearing (default false)
42 smearOmega_ = parameters.getInteger("smearOmega", 0) != 0;
43
44 // Explicit smearing lookup variable: "flat", "nHits", "tanLambda", "phi0"
45 // Empty string (default) accepts whatever the JSON specifies
46 smearingVariable_ = parameters.getString("smearingVariable", "");
47 scaleCorrVariable_ = parameters.getString("scaleCorrVariable", "");
48
49 feeClusterEnergyMin_ = parameters.getDouble("feeClusterEnergyMin", feeClusterEnergyMin_);
50 clusterTimeMin_ = parameters.getDouble("clusterTimeMin", clusterTimeMin_);
51 clusterTimeMax_ = parameters.getDouble("clusterTimeMax", clusterTimeMax_);
52 clusterTimeMinMC_ = parameters.getDouble("clusterTimeMinMC", clusterTimeMinMC_);
53 clusterTimeMaxMC_ = parameters.getDouble("clusterTimeMaxMC", clusterTimeMaxMC_);
54 mcTimeOffset_ = parameters.getDouble("mcTimeOffset", mcTimeOffset_);
55
56 }
57 catch (std::runtime_error& error)
58 {
59 std::cout << error.what() << std::endl;
60 }
61
62 if (!isData_)
64}
65
66void TrackingAnaProcessor::setFile(TFile* outFile) {
67 Processor::setFile(outFile);
68 output_tree_ = std::make_unique<TTree>("tracks", "Selected Tracks", 99, outFile);
69 output_tree_->Branch("track.", &track_out_, 100000, 3);
70 output_tree_->Branch("track_smeared.", &track_smeared_out_, 100000, 3);
71 output_tree_->Branch("p_smear_ratio", &p_smear_ratio_out_);
72 output_tree_->Branch("L1_axial", &L1_axial_out_);
73 output_tree_->Branch("L1_stereo", &L1_stereo_out_);
74 output_tree_->Branch("L2_axial", &L2_axial_out_);
75 output_tree_->Branch("L2_stereo", &L2_stereo_out_);
76 output_tree_->Branch("L3_axial", &L3_axial_out_);
77 output_tree_->Branch("L3_stereo", &L3_stereo_out_);
78}
79
81
82 ah_ = std::make_shared<AnaHelpers>();
83
84 //Init histos
86 trkHistos_->loadHistoConfig(histCfgFilename_);
87 trkHistos_->doTrackComparisonPlots(false);
88 trkHistos_->DefineHistos();
89 // Init tree
90 tree->SetBranchAddress(trkCollName_.c_str(), &tracks_, &btracks_);
91
92 if (!selectionCfg_.empty()) {
93 trkSelector_ = std::make_shared<BaseSelector>(name_+"_trkSelector",selectionCfg_);
94 trkSelector_->setDebug(debug_);
95 trkSelector_->LoadSelection();
96 }
97
98 if (doTruth_) {
99 truthHistos_ = new TrackHistos(trkCollName_+"_truthComparison");
100 truthHistos_->loadHistoConfig(histCfgFilename_);
101 truthHistos_->DefineHistos();
102 truthHistos_->loadHistoConfig(truthHistCfgFilename_);
103 truthHistos_->DefineHistos();
104 truthHistos_->doTrackComparisonPlots(false);
105
106 //tree->SetBranchAddress(truthCollName_.c_str(),&truth_tracks_,&btruth_tracks_);
107 }
108
109 // Setup track selections plots
110 for (unsigned int i_reg = 0;
111 i_reg < regionSelections_.size();
112 i_reg++) {
113 std::string regname = AnaHelpers::getFileName(regionSelections_[i_reg],false);
114 std::cout<< "Setting up region "<< regname<<std::endl;
115
116 reg_selectors_[regname] = std::make_shared<BaseSelector>(regname, regionSelections_[i_reg]);
117 reg_selectors_[regname]->setDebug(false);
118 reg_selectors_[regname]->LoadSelection();
119
120 reg_histos_[regname] = std::make_shared<TrackHistos>(regname);
121 reg_histos_[regname]->loadHistoConfig(histCfgFilename_);
122 reg_histos_[regname]->doTrackComparisonPlots(false);
123 reg_histos_[regname]->DefineTrkHitHistos();
124
125 regions_.push_back(regname);
126
127 }
128
129
130
131
132 //Get event header information for trigger
133 tree->SetBranchAddress("EventHeader", &evth_ , &bevth_);
134
135 //Get cluster information for FEEs
136 if (!ecalCollName_.empty())
137 tree->SetBranchAddress(ecalCollName_.c_str(),&ecal_, &becal_);
138
139
140 //Momentum smearing closure test
141 // Determine which smearing file to use (smearingCfg takes precedence)
142 std::string smearingFile = !smearingCfgFile_.empty() ? smearingCfgFile_ : pSmearingFile_;
143
144 if (!smearingFile.empty()) {
145 std::cout<<"Loading smearing config from "<<smearingFile<<std::endl;
146 std::cout<<"Smearing Tool Seed "<<seed_<<std::endl;
147 std::cout<<"Using smearing factor: "<<smearingFactor_<<std::endl;
148 std::cout<<"doSmearing: "<<(doSmearing_ ? "true" : "false")<<std::endl;
149 std::cout<<"smearOmega: "<<(smearOmega_ ? "true" : "false")<<std::endl;
150 // Match PreselectAndCategorize2021: relSmearingP=true (relative), relSmearingZ0=false (absolute)
151 // JSON files will override with their own relSmearingP/relSmearingZ0 values
152 smearingTool_ = std::make_shared<TrackSmearingTool>(smearingFile, true, false, seed_, trkCollName_, smearingFactor_);
153 smearingTool_->setIsData(isData_);
154 smearingTool_->setApplyMeanCorr(isData_);
155 smearingTool_->setDebug(debug_ > 0);
156 smearingTool_->setForcedVariable(smearingVariable_);
157 if (!scaleCorrVariable_.empty())
158 smearingTool_->setScaleCorrVariable(scaleCorrVariable_);
159 smearingTool_->setRequireTruthMatch(requireTruthMatch_);
160 smearingTool_->printConfig();
161
162 psmear_h_ = new TH1D("psmear_h",
163 "psmear_h",200,2,6);
164 psmear_top_h_ = new TH1D("psmear_top_h",
165 "psmear_top_h",200,2,6);
166 psmear_bot_h_ = new TH1D("psmear_bot_h",
167 "psmear_bot_h",200,2,6);
168
169 psmear_vs_nHits_hh_ = new TH2D("psmear_vs_nHits_hh",
170 "psmear_vs_nHits_hh",
171 5,8,13,
172 200,0,6);
173 psmear_vs_nHits_top_hh_ = new TH2D("psmear_vs_nHits_top_hh",
174 "psmear_vs_nHits_top_hh",
175 5,8,13,
176 200,0,6);
177 psmear_vs_nHits_bot_hh_ = new TH2D("psmear_vs_nHits_bot_hh",
178 "psmear_vs_nHits_bot_hh",
179 5,8,13,
180 200,0,6);
181
182
183 psmear_rel_h_ = new TH1D("psmear_rel_h",
184 "psmear_rel_h",200,0,6);
185
186 psmear_vs_nHits_rel_hh_ = new TH2D("psmear_vs_nHits_rel_hh",
187 "psmear_vs_nHits_rel_hh",
188 5,8,13,
189 200,0,6);
190 psmear_vs_nHits_top_rel_hh_ = new TH2D("psmear_vs_nHits_top_rel_hh",
191 "psmear_vs_nHits_top_rel_hh",
192 5,8,13,
193 200,0,6);
194 psmear_vs_nHits_bot_rel_hh_ = new TH2D("psmear_vs_nHits_bot_rel_hh",
195 "psmear_vs_nHits_bot_rel_hh",
196 5,8,13,
197 200,0,6);
198
199 // z0 smearing validation histograms (binning matches Z0_h from feeSmearing_2021.json)
200 z0smear_h_ = new TH1D("z0smear_h", "z0smear_h", 100, -0.5, 0.5);
201 z0smear_top_h_ = new TH1D("z0smear_top_h", "z0smear_top_h", 100, -0.5, 0.5);
202 z0smear_bot_h_ = new TH1D("z0smear_bot_h", "z0smear_bot_h", 100, -0.5, 0.5);
203
204 // omega smearing validation histograms
205 omega_h_ = new TH1D("omega_h", "omega_h", 100, -0.00015, 0.00015);
206 omega_top_h_ = new TH1D("omega_top_h", "omega_top_h", 100, -0.00015, 0.00015);
207 omega_bot_h_ = new TH1D("omega_bot_h", "omega_bot_h", 100, -0.00015, 0.00015);
208 omegasmear_h_ = new TH1D("omegasmear_h", "omegasmear_h", 100, -0.00015, 0.00015);
209 omegasmear_top_h_ = new TH1D("omegasmear_top_h", "omegasmear_top_h", 100, -0.00015, 0.00015);
210 omegasmear_bot_h_ = new TH1D("omegasmear_bot_h", "omegasmear_bot_h", 100, -0.00015, 0.00015);
211 omega_vs_p_hh_ = new TH2D("omega_vs_p_hh", "omega_vs_p_hh", 100, 1.0, 4.5, 100, -0.00015, 0.00015);
212
213 // omega vs tanLambda and phi0 (unsmeared and smeared)
214 omega_vs_tanL_hh_ = new TH2D("omega_vs_tanL_hh", "omega_vs_tanL_hh", 80, -0.08, 0.08, 100, -0.00015, 0.00015);
215 omega_vs_tanL_top_hh_ = new TH2D("omega_vs_tanL_top_hh", "omega_vs_tanL_top_hh", 40, 0.00, 0.08, 100, -0.00015, 0.00015);
216 omega_vs_tanL_bot_hh_ = new TH2D("omega_vs_tanL_bot_hh", "omega_vs_tanL_bot_hh", 40, -0.08, 0.00, 100, -0.00015, 0.00015);
217 omegasmear_vs_tanL_hh_ = new TH2D("omegasmear_vs_tanL_hh", "omegasmear_vs_tanL_hh", 80, -0.08, 0.08, 100, -0.00015, 0.00015);
218 omegasmear_vs_tanL_top_hh_ = new TH2D("omegasmear_vs_tanL_top_hh", "omegasmear_vs_tanL_top_hh", 40, 0.00, 0.08, 100, -0.00015, 0.00015);
219 omegasmear_vs_tanL_bot_hh_ = new TH2D("omegasmear_vs_tanL_bot_hh", "omegasmear_vs_tanL_bot_hh", 40, -0.08, 0.00, 100, -0.00015, 0.00015);
220
221 omega_vs_phi0_hh_ = new TH2D("omega_vs_phi0_hh", "omega_vs_phi0_hh", 80, -0.2, 0.2, 100, -0.00015, 0.00015);
222 omega_vs_phi0_top_hh_ = new TH2D("omega_vs_phi0_top_hh", "omega_vs_phi0_top_hh", 80, -0.2, 0.2, 100, -0.00015, 0.00015);
223 omega_vs_phi0_bot_hh_ = new TH2D("omega_vs_phi0_bot_hh", "omega_vs_phi0_bot_hh", 80, -0.2, 0.2, 100, -0.00015, 0.00015);
224 omegasmear_vs_phi0_hh_ = new TH2D("omegasmear_vs_phi0_hh", "omegasmear_vs_phi0_hh", 80, -0.2, 0.2, 100, -0.00015, 0.00015);
225 omegasmear_vs_phi0_top_hh_ = new TH2D("omegasmear_vs_phi0_top_hh", "omegasmear_vs_phi0_top_hh", 80, -0.2, 0.2, 100, -0.00015, 0.00015);
226 omegasmear_vs_phi0_bot_hh_ = new TH2D("omegasmear_vs_phi0_bot_hh", "omegasmear_vs_phi0_bot_hh", 80, -0.2, 0.2, 100, -0.00015, 0.00015);
227
228 }
229
230
231}
232
234
235 double weight = 1.;
236 // Loop over all the LCIO Tracks and add them to the HPS event.
237 int n_sel_tracks = 0;
238
239
240 //Trigger requirements - Singles 0 and 1.
241 //TODO use cutFlow
242 //if (isData_ && (!evth_->isSingle0Trigger() && !evth_->isSingle1Trigger()))
243 // return true; //true is correct?
244
245 //Ask for 1 cluster p > 1.2 GeV with time [40,70]
246 //TODO Use Cutflow
247
248 double minTime = isData_ ? clusterTimeMin_ : clusterTimeMinMC_;
249 double maxTime = isData_ ? clusterTimeMax_ : clusterTimeMaxMC_;
250
251 if (debug_ > 0) {
252 std::cout << "[TrackingAna] --- new event isData=" << isData_
253 << " feeEnergyMin=" << feeClusterEnergyMin_
254 << " timeWindow=[" << minTime << "," << maxTime << "]"
255 << " nClusters=" << ecal_->size() << std::endl;
256 for (unsigned int iclu = 0; iclu < ecal_->size(); iclu++) {
257 std::cout << " cluster[" << iclu << "]"
258 << " E=" << ecal_->at(iclu)->getEnergy()
259 << " t=" << ecal_->at(iclu)->getTime() << std::endl;
260 }
261 }
262
263 bool foundFeeCluster = false;
264 for (unsigned int iclu = 0; iclu < ecal_->size(); iclu++) {
265 if (ecal_->at(iclu)->getEnergy() > feeClusterEnergyMin_) {
266 foundFeeCluster = true;
267 break;
268 }
269 }
270 if (!foundFeeCluster) {
271 if (debug_ > 0) std::cout << "[TrackingAna] FAIL: no cluster with E > " << feeClusterEnergyMin_ << std::endl;
272 return true;
273 }
274
275 // Require at least one cluster within the time window
276 bool clusterInTime = false;
277 for (unsigned int iclu = 0; iclu < ecal_->size(); iclu++) {
278 double t = ecal_->at(iclu)->getTime();
279 if (t >= minTime && t <= maxTime) {
280 clusterInTime = true;
281 break;
282 }
283 }
284 if (!clusterInTime) {
285 if (debug_ > 0) std::cout << "[TrackingAna] FAIL: no cluster in time window [" << minTime << "," << maxTime << "]" << std::endl;
286 return true;
287 }
288
289 for (int itrack = 0; itrack < tracks_->size(); ++itrack) {
290
291 if (trkSelector_) trkSelector_->getCutFlowHisto()->Fill(0.,weight);
292
293 // Get a track
294 Track* track = tracks_->at(itrack);
295 int n2dhits_onTrack = !track->isKalmanTrack() ? track->getTrackerHitCount() * 2 : track->getTrackerHitCount();
296
297 TVector3 trk_mom;
298 trk_mom.SetX(track->getMomentum()[0]);
299 trk_mom.SetY(track->getMomentum()[1]);
300 trk_mom.SetZ(track->getMomentum()[2]);
301
302 // Decode per-sensor hit layer vector and determine top/bottom
303 bool isTop = track->getTanLambda() > 0;
304 auto layers = ah_->GetTrackHitLayers(track);
305 // Convention from sensor_locations.txt:
306 // Top: even sensor index = axial, odd = stereo
307 // Bottom: even sensor index = stereo, odd = axial
308 bool L1_axial = isTop ? (layers.at(0) == 1) : (layers.at(1) == 1);
309 bool L1_stereo = isTop ? (layers.at(1) == 1) : (layers.at(0) == 1);
310 bool L2_axial = isTop ? (layers.at(2) == 1) : (layers.at(3) == 1);
311 bool L2_stereo = isTop ? (layers.at(3) == 1) : (layers.at(2) == 1);
312 bool L3_axial = isTop ? (layers.at(4) == 1) : (layers.at(5) == 1);
313 bool L3_stereo = isTop ? (layers.at(5) == 1) : (layers.at(4) == 1);
314
315 if (debug_ > 0) {
316 std::cout << "[TrackingAna] track[" << itrack << "]"
317 << " nHits=" << n2dhits_onTrack
318 << " chi2ndf=" << track->getChi2Ndf()
319 << " p=" << trk_mom.Mag()
320 << " tanL=" << track->getTanLambda()
321 << " ecalX=" << track->getPositionAtEcal()[0]
322 << " trkTime=" << track->getTrackTime()
323 << " trkTime-offset=" << track->getTrackTime() - time_offset_
324 << std::endl;
325 }
326
327 //Track Selection
328 if (trkSelector_ && !trkSelector_->passCutGt("n_hits_gt",n2dhits_onTrack,weight)) {
329 if (debug_ > 0) std::cout << "[TrackingAna] FAIL n_hits_gt: " << n2dhits_onTrack << std::endl;
330 continue;
331 }
332
333 if (trkSelector_ && !trkSelector_->passCutLt("chi2ndf_lt",track->getChi2Ndf(),weight)) {
334 if (debug_ > 0) std::cout << "[TrackingAna] FAIL chi2ndf_lt: " << track->getChi2Ndf() << std::endl;
335 continue;
336 }
337
338 if (trkSelector_ && !trkSelector_->passCutGt("p_gt",trk_mom.Mag(),weight)) {
339 if (debug_ > 0) std::cout << "[TrackingAna] FAIL p_gt: " << trk_mom.Mag() << std::endl;
340 continue;
341 }
342
343 if (trkSelector_ && !trkSelector_->passCutLt("p_lt",trk_mom.Mag(),weight)) {
344 if (debug_ > 0) std::cout << "[TrackingAna] FAIL p_lt: " << trk_mom.Mag() << std::endl;
345 continue;
346 }
347
348 if (trkSelector_ && !trkSelector_->passCutLt("trk_ecal_lt",track->getPositionAtEcal()[0],weight)) {
349 if (debug_ > 0) std::cout << "[TrackingAna] FAIL trk_ecal_lt: " << track->getPositionAtEcal()[0] << std::endl;
350 continue;
351 }
352
353 if (trkSelector_ && !trkSelector_->passCutGt("trk_ecal_gt",track->getPositionAtEcal()[0],weight)) {
354 if (debug_ > 0) std::cout << "[TrackingAna] FAIL trk_ecal_gt: " << track->getPositionAtEcal()[0] << std::endl;
355 continue;
356 }
357
358 if (trkSelector_ && !trkSelector_->passCutGt("trk_time_gt",track->getTrackTime()-time_offset_,weight)) {
359 if (debug_ > 0) std::cout << "[TrackingAna] FAIL trk_time_gt: " << track->getTrackTime() - time_offset_ << std::endl;
360 continue;
361 }
362
363 if (trkSelector_ && !trkSelector_->passCutLt("trk_time_lt",track->getTrackTime()-time_offset_,weight)) {
364 if (debug_ > 0) std::cout << "[TrackingAna] FAIL trk_time_lt: " << track->getTrackTime() - time_offset_ << std::endl;
365 continue;
366 }
367
368 if (debug_ > 0) std::cout << "[TrackingAna] PASS all cuts" << std::endl;
369
370 Track* truth_track = nullptr;
371
372 //Get the truth track
373 if (doTruth_) {
374 truth_track = (Track*) track->getTruthLink().GetObject();
375 if (!truth_track)
376 std::cout<<"Warnings::TrackingAnaProcessor::Requested Truth track but couldn't find it in the ntuple"<<std::endl;
377 }
378
379 if(debug_ > 0)
380 {
381 std::cout<<"========================================="<<std::endl;
382 std::cout<<"========================================="<<std::endl;
383 std::cout<<"Track params: "<<std::endl;
384 track->Print();
385 }
386
387 trkHistos_->Fill1DHistograms(track);
388 trkHistos_->Fill2DTrack(track);
389
390 //auto pos = track->getPosition();
391 //std::cout << "X: " << pos[0] << " Y : " << pos[1] << " Z: " << pos[2] << std::endl;
392
393 if (truthHistos_) {
394 truthHistos_->Fill1DHistograms(truth_track);
395 truthHistos_->Fill2DTrack(track);
396 truthHistos_->Fill1DTrackTruth(track, truth_track);
397 }
398
399 n_sel_tracks++;
400
401
402
403 //Fill histograms for FEE smearing analysis
404 trkHistos_->Fill2DHisto("xypos_at_ecal_hh",
405 track->getPositionAtEcal()[0],
406 track->getPositionAtEcal()[1]);
407
408 trkHistos_->Fill3DHisto("p_vs_TanLambda_Phi_hhh",
409 track->getPhi(),
410 track->getTanLambda(),
411 track->getP());
412
413 trkHistos_->Fill2DHisto("p_vs_nHits_hh",
414 track->getTrackerHitCount(),
415 track->getP());
416
417 if (track->getTanLambda() > 0 )
418 trkHistos_->Fill2DHisto("p_vs_nHits_top_hh",
419 track->getTrackerHitCount(),
420 track->getP());
421 else
422 trkHistos_->Fill2DHisto("p_vs_nHits_bot_hh",
423 track->getTrackerHitCount(),
424 track->getP());
425
426 trkHistos_->Fill3DHisto("p_vs_TanLambda_nHits_hhh",
427 track->getTanLambda(),
428 track->getTrackerHitCount(),
429 track->getP());
430
431
432
433 // Track-level quantities for output tree and smearing histograms.
434 // trk_smeared starts as a copy of the original; update* methods modify it in-place.
435 Track trk_smeared = *track;
436 double omega_unsmeared = track->getOmega();
437 double omega_smeared = omega_unsmeared;
438 double p_smear_ratio = 1.0;
439
440 if (smearingTool_) {
441
442 double nhits = track->getTrackerHitCount();
443
444 if (doSmearing_) {
445 if (smearOmega_) {
446 double scale = smearingTool_->updateWithSmearOmega(trk_smeared);
447 // scale = |omega/omega_smeared| = |p_smeared/p_original|
448 omega_smeared = omega_unsmeared / scale;
449 p_smear_ratio = scale;
450 } else {
451 p_smear_ratio = smearingTool_->updateWithSmearP(trk_smeared);
452 }
453 smearingTool_->updateWithSmearZ0(trk_smeared);
454 }
455
456 double pval = trk_smeared.getP();
457 double z0val = trk_smeared.getZ0();
458
459 psmear_h_->Fill(pval);
460 psmear_vs_nHits_hh_->Fill(nhits, pval);
461
462 if (isTop) {
463 psmear_top_h_->Fill(pval);
464 psmear_vs_nHits_top_hh_->Fill(nhits, pval);
465 }
466 else {
467 psmear_bot_h_->Fill(pval);
468 psmear_vs_nHits_bot_hh_->Fill(nhits, pval);
469 }
470
471 psmear_rel_h_->Fill(pval);
472 psmear_vs_nHits_rel_hh_->Fill(nhits, pval);
473
474 if (isTop) {
475 psmear_vs_nHits_top_rel_hh_->Fill(nhits, pval);
476 }
477 else {
478 psmear_vs_nHits_bot_rel_hh_->Fill(nhits, pval);
479 }
480
481 // z0 smearing validation
482 z0smear_h_->Fill(z0val);
483 if (isTop) {
484 z0smear_top_h_->Fill(z0val);
485 }
486 else {
487 z0smear_bot_h_->Fill(z0val);
488 }
489
490 // omega smearing validation
491 double tanL = track->getTanLambda();
492 double phi0 = track->getPhi();
493
494 omega_h_->Fill(omega_unsmeared);
495 omegasmear_h_->Fill(omega_smeared);
496 omega_vs_p_hh_->Fill(track->getP(), omega_unsmeared);
497 omega_vs_tanL_hh_->Fill(tanL, omega_unsmeared);
498 omega_vs_phi0_hh_->Fill(phi0, omega_unsmeared);
499 omegasmear_vs_tanL_hh_->Fill(tanL, omega_smeared);
500 omegasmear_vs_phi0_hh_->Fill(phi0, omega_smeared);
501
502 if (isTop) {
503 omega_top_h_->Fill(omega_unsmeared);
504 omegasmear_top_h_->Fill(omega_smeared);
505 omega_vs_tanL_top_hh_->Fill(tanL, omega_unsmeared);
506 omega_vs_phi0_top_hh_->Fill(phi0, omega_unsmeared);
507 omegasmear_vs_tanL_top_hh_->Fill(tanL, omega_smeared);
508 omegasmear_vs_phi0_top_hh_->Fill(phi0, omega_smeared);
509 }
510 else {
511 omega_bot_h_->Fill(omega_unsmeared);
512 omegasmear_bot_h_->Fill(omega_smeared);
513 omega_vs_tanL_bot_hh_->Fill(tanL, omega_unsmeared);
514 omega_vs_phi0_bot_hh_->Fill(phi0, omega_unsmeared);
515 omegasmear_vs_tanL_bot_hh_->Fill(tanL, omega_smeared);
516 omegasmear_vs_phi0_bot_hh_->Fill(phi0, omega_smeared);
517 }
518
519 } // smearing validation
520
521 // Fill output tree (one entry per selected track)
522 if (output_tree_) {
523 track_out_ = *track; // original, unsmeared
524 track_smeared_out_ = trk_smeared; // smeared (same as original if doSmearing_=false)
525 p_smear_ratio_out_ = p_smear_ratio;
526 L1_axial_out_ = L1_axial;
527 L1_stereo_out_ = L1_stereo;
528 L2_axial_out_ = L2_axial;
529 L2_stereo_out_ = L2_stereo;
530 L3_axial_out_ = L3_axial;
531 L3_stereo_out_ = L3_stereo;
532 output_tree_->Fill();
533 }
534
535 }//Loop on tracks
536
537 trkHistos_->Fill1DHisto("n_tracks_h",n_sel_tracks);
538
539 return true;
540}
541
543
544 if (output_tree_) {
545 outF_->cd();
546 output_tree_->Write();
547 }
548
549 trkHistos_->saveHistos(outF_,trkCollName_);
550 delete trkHistos_;
551 trkHistos_ = nullptr;
552 if (trkSelector_)
553 trkSelector_->getCutFlowHisto()->Write();
554
555 if (truthHistos_) {
556 truthHistos_->saveHistos(outF_,trkCollName_+"_truth");
557 delete truthHistos_;
558 truthHistos_ = nullptr;
559 }
560
561 for (reg_it it = reg_histos_.begin(); it!=reg_histos_.end(); ++it) {
562 std::string dirName = it->first;
563 (it->second)->saveHistos(outF_,dirName);
564 outF_->cd(dirName.c_str());
565 reg_selectors_[it->first]->getCutFlowHisto()->Write();
566 }
567
568 if (smearingTool_) {
569 outF_->cd(trkCollName_.c_str());
570 psmear_h_->Write();
571 psmear_top_h_->Write();
572 psmear_bot_h_->Write();
573
574 psmear_vs_nHits_hh_->Write();
577 delete psmear_h_;
578 delete psmear_top_h_;
579 delete psmear_bot_h_;
580 delete psmear_vs_nHits_hh_;
583
584 psmear_rel_h_->Write();
588 delete psmear_rel_h_;
592
593 // z0 smearing validation histograms
594 z0smear_h_->Write();
595 z0smear_top_h_->Write();
596 z0smear_bot_h_->Write();
597 delete z0smear_h_;
598 delete z0smear_top_h_;
599 delete z0smear_bot_h_;
600
601 // omega smearing validation histograms
602 omega_h_->Write();
603 omega_top_h_->Write();
604 omega_bot_h_->Write();
605 omegasmear_h_->Write();
606 omegasmear_top_h_->Write();
607 omegasmear_bot_h_->Write();
608 omega_vs_p_hh_->Write();
609 omega_vs_tanL_hh_->Write();
610 omega_vs_tanL_top_hh_->Write();
611 omega_vs_tanL_bot_hh_->Write();
612 omegasmear_vs_tanL_hh_->Write();
615 omega_vs_phi0_hh_->Write();
616 omega_vs_phi0_top_hh_->Write();
617 omega_vs_phi0_bot_hh_->Write();
618 omegasmear_vs_phi0_hh_->Write();
621
622 delete omega_h_;
623 delete omega_top_h_;
624 delete omega_bot_h_;
625 delete omegasmear_h_;
626 delete omegasmear_top_h_;
627 delete omegasmear_bot_h_;
628 delete omega_vs_p_hh_;
629 delete omega_vs_tanL_hh_;
635 delete omega_vs_phi0_hh_;
641
642 }
643
644 //trkHistos_->Clear();
645}
646
#define DECLARE_PROCESSOR(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Definition Processor.h:139
static std::string getFileName(std::string filePath, bool withExtension)
Definition AnaHelpers.cxx:5
Definition IEvent.h:7
description
TFile * outF_
Definition Processor.h:125
std::string name_
Definition Processor.h:128
Processor(const std::string &name, Process &process)
Class constructor.
Definition Processor.cxx:10
virtual bool process()
Process the histograms and generate analysis output.
Definition Processor.h:95
virtual void setFile(TFile *outFile)
Set output TFile for AnaProcessors.
Definition Processor.h:88
description
Definition TrackHistos.h:17
Definition Track.h:32
double getZ0() const
Definition Track.h:93
double getP() const
Definition Track.h:293
Insert description here. more details.
bool smearOmega_
Use omega (curvature) smearing instead of p smearing.
std::shared_ptr< TrackSmearingTool > smearingTool_
virtual bool process(IEvent *ievent)
Process the event and put new data products into it.
std::string ecalCollName_
Cluster Collection name.
std::string trkCollName_
Track Collection name.
std::string truthHistCfgFilename_
description
virtual void configure(const ParameterSet &parameters)
Configure the Ana Processor.
bool requireTruthMatch_
Require truth match for smearing.
Track track_out_
original (unsmeared) track
double clusterTimeMax_
maximum cluster time (data)
virtual void finalize()
Callback for the Processor to take any necessary action when the processing of events finishes.
std::map< std::string, std::shared_ptr< TrackHistos > > reg_histos_
description
double smearingFactor_
Factor to multiply smearing parameters by.
std::string scaleCorrVariable_
if set, omega data-mode scale uses pBinned_ means
bool doSmearing_
Master switch for smearing.
std::vector< std::string > regionSelections_
track selections
double clusterTimeMinMC_
minimum cluster time (MC)
virtual void initialize(TTree *tree)
Callback for the Processor to take any necessary action when the processing of events starts.
virtual void setFile(TFile *outFile)
Set output TFile and create the output TTree.
Track track_smeared_out_
smeared track (identical to track_out_ if no smearing)
std::map< std::string, std::shared_ptr< TrackHistos > >::iterator reg_it
description
std::vector< CalCluster * > * ecal_
std::string smearingVariable_
"flat", "nHits", "tanLambda", "phi0" — explicit lookup; "" = JSON default
TrackingAnaProcessor(const std::string &name, Process &process)
Class constructor.
std::string histCfgFilename_
description
TrackHistos * trkHistos_
description
std::map< std::string, std::shared_ptr< BaseSelector > > reg_selectors_
description
double p_smear_ratio_out_
smeared_p / original_p (1 if no smearing)
double clusterTimeMin_
minimum cluster time (data)
double feeClusterEnergyMin_
time offset
TBranch * btracks_
description
double clusterTimeMaxMC_
maximum cluster time (MC)
TrackHistos * truthHistos_
description
std::shared_ptr< AnaHelpers > ah_
std::vector< Track * > * tracks_
std::vector< std::string > regions_
double mcTimeOffset_
time offset applied to MC tracks
std::shared_ptr< BaseSelector > trkSelector_
description
std::unique_ptr< TTree > output_tree_