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.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
TrackingAnaProcessor.cxx
Go to the documentation of this file.
2#include <iomanip>
3#include "utilities.h"
4#include "AnaHelpers.h"
5
6TrackingAnaProcessor::TrackingAnaProcessor(const std::string& name, Process& process)
7 : Processor(name, process) {
8 }
9
12
14
15 std::cout << "Configuring TrackingAnaProcessor" << std::endl;
16 try
17 {
18 debug_ = parameters.getInteger("debug",debug_);
19 seed_ = parameters.getInteger("seed",seed_);
20 trkCollName_ = parameters.getString("trkCollName",trkCollName_);
21 histCfgFilename_ = parameters.getString("histCfg",histCfgFilename_);
22 doTruth_ = (bool) parameters.getInteger("doTruth",doTruth_);
23 truthHistCfgFilename_ = parameters.getString("truthHistCfg",truthHistCfgFilename_);
24 selectionCfg_ = parameters.getString("selectionjson",selectionCfg_);
25 isData_ = parameters.getInteger("isData",isData_);
26 ecalCollName_ = parameters.getString("ecalCollName",ecalCollName_);
27 regionSelections_ = parameters.getVString("regionDefinitions",regionSelections_);
28
29 //Momentum smearing closure test
30 pSmearingFile_ = parameters.getString("pSmearingFile",pSmearingFile_);
31
32 }
33 catch (std::runtime_error& error)
34 {
35 std::cout << error.what() << std::endl;
36 }
37
38 if (!isData_)
39 time_offset_ = 5.;
40}
41
43
44 //Init histos
49 // Init tree
50 tree->SetBranchAddress(trkCollName_.c_str(), &tracks_, &btracks_);
51
52 if (!selectionCfg_.empty()) {
53 trkSelector_ = std::make_shared<BaseSelector>(name_+"_trkSelector",selectionCfg_);
54 trkSelector_->setDebug(debug_);
55 trkSelector_->LoadSelection();
56 }
57
58 if (doTruth_) {
59 truthHistos_ = new TrackHistos(trkCollName_+"_truthComparison");
65
66 //tree->SetBranchAddress(truthCollName_.c_str(),&truth_tracks_,&btruth_tracks_);
67 }
68
69 // Setup track selections plots
70 for (unsigned int i_reg = 0;
71 i_reg < regionSelections_.size();
72 i_reg++) {
73 std::string regname = AnaHelpers::getFileName(regionSelections_[i_reg],false);
74 std::cout<< "Setting up region "<< regname<<std::endl;
75
76 reg_selectors_[regname] = std::make_shared<BaseSelector>(regname, regionSelections_[i_reg]);
77 reg_selectors_[regname]->setDebug(false);
78 reg_selectors_[regname]->LoadSelection();
79
80 reg_histos_[regname] = std::make_shared<TrackHistos>(regname);
81 reg_histos_[regname]->loadHistoConfig(histCfgFilename_);
82 reg_histos_[regname]->doTrackComparisonPlots(false);
83 reg_histos_[regname]->DefineTrkHitHistos();
84
85 regions_.push_back(regname);
86
87 }
88
89
90
91
92 //Get event header information for trigger
93 tree->SetBranchAddress("EventHeader", &evth_ , &bevth_);
94
95 //Get cluster information for FEEs
96 if (!ecalCollName_.empty())
97 tree->SetBranchAddress(ecalCollName_.c_str(),&ecal_, &becal_);
98
99
100 //Momentum smearing closure test
101 if (!pSmearingFile_.empty()) {
102
103 std::cout<<"Smearing Tool Seed "<<seed_<<std::endl;
104 smearingTool_ = std::make_shared<TrackSmearingTool>(pSmearingFile_,false,seed_);
105 smearingToolRel_ = std::make_shared<TrackSmearingTool>(pSmearingFile_,true, seed_);
106
107 psmear_h_ = new TH1D("psmear_h",
108 "psmear_h",200,0,4);
109
110 psmear_vs_nHits_hh_ = new TH2D("psmear_vs_nHits_hh",
111 "psmear_vs_nHits_hh",
112 5,8,13,
113 200,0,4);
114 psmear_vs_nHits_top_hh_ = new TH2D("psmear_vs_nHits_top_hh",
115 "psmear_vs_nHits_top_hh",
116 5,8,13,
117 200,0,4);
118 psmear_vs_nHits_bot_hh_ = new TH2D("psmear_vs_nHits_bot_hh",
119 "psmear_vs_nHits_bot_hh",
120 5,8,13,
121 200,0,4);
122
123
124 psmear_rel_h_ = new TH1D("psmear_rel_h",
125 "psmear_rel_h",200,0,4);
126
127 psmear_vs_nHits_rel_hh_ = new TH2D("psmear_vs_nHits_rel_hh",
128 "psmear_vs_nHits_rel_hh",
129 5,8,13,
130 200,0,4);
131 psmear_vs_nHits_top_rel_hh_ = new TH2D("psmear_vs_nHits_top_rel_hh",
132 "psmear_vs_nHits_top_rel_hh",
133 5,8,13,
134 200,0,4);
135 psmear_vs_nHits_bot_rel_hh_ = new TH2D("psmear_vs_nHits_bot_rel_hh",
136 "psmear_vs_nHits_bot_rel_hh",
137 5,8,13,
138 200,0,4);
139
140 }
141
142
143}
144
146
147 double weight = 1.;
148 // Loop over all the LCIO Tracks and add them to the HPS event.
149 int n_sel_tracks = 0;
150
151
152 //Trigger requirements - Singles 0 and 1.
153 //TODO use cutFlow
155 return true; //true is correct?
156
157 //Ask for 1 cluster p > 1.2 GeV with time [40,70]
158 //TODO Use Cutflow
159
160 double minTime = 40;
161 double maxTime = 70;
162
163 if (!isData_) {
164 minTime = 30;
165 maxTime = 50;
166 }
167
168 //if (ecal_->size() <= 2)
169 // return true;
170
171 bool foundFeeCluster = false;
172
173 for (unsigned int iclu = 0; iclu < ecal_->size(); iclu++) {
174 if (ecal_->at(iclu)->getEnergy() > 1.5)
175 foundFeeCluster = true;
176 break;
177 }
178
179 if (!foundFeeCluster)
180 return true;
181
182 bool clusterInTime = true;
183
184 for (unsigned int iclu = 0; iclu < ecal_->size(); iclu++) {
185 if (ecal_->at(iclu)->getTime() < 40 || ecal_->at(iclu)->getTime() > 70)
186 clusterInTime = false;
187 }
188
189 if (!clusterInTime)
190 return true;
191
192 for (int itrack = 0; itrack < tracks_->size(); ++itrack) {
193
194 if (trkSelector_) trkSelector_->getCutFlowHisto()->Fill(0.,weight);
195
196 // Get a track
197 Track* track = tracks_->at(itrack);
198 int n2dhits_onTrack = !track->isKalmanTrack() ? track->getTrackerHitCount() * 2 : track->getTrackerHitCount();
199
200 TVector3 trk_mom;
201 trk_mom.SetX(track->getMomentum()[0]);
202 trk_mom.SetY(track->getMomentum()[1]);
203 trk_mom.SetZ(track->getMomentum()[2]);
204
205
206 //Track Selection
207 if (trkSelector_ && !trkSelector_->passCutGt("n_hits_gt",n2dhits_onTrack,weight))
208 continue;
209
210 if (trkSelector_ && !trkSelector_->passCutLt("chi2ndf_lt",track->getChi2Ndf(),weight))
211 continue;
212
213 if (trkSelector_ && !trkSelector_->passCutGt("p_gt",trk_mom.Mag(),weight))
214 continue;
215
216 if (trkSelector_ && !trkSelector_->passCutLt("p_lt",trk_mom.Mag(),weight))
217 continue;
218
219 if (trkSelector_ && !trkSelector_->passCutLt("trk_ecal_lt",track->getPositionAtEcal()[0],weight))
220 continue;
221
222
223 if (trkSelector_ && !trkSelector_->passCutGt("trk_ecal_gt",track->getPositionAtEcal()[0],weight))
224 continue;
225
226 if (trkSelector_ && !trkSelector_->passCutGt("trk_time_gt",track->getTrackTime()-time_offset_,weight))
227 continue;
228
229 if (trkSelector_ && !trkSelector_->passCutLt("trk_time_lt",track->getTrackTime()-time_offset_,weight))
230 continue;
231
232 Track* truth_track = nullptr;
233
234 //Get the truth track
235 if (doTruth_) {
236 truth_track = (Track*) track->getTruthLink().GetObject();
237 if (!truth_track)
238 std::cout<<"Warnings::TrackingAnaProcessor::Requested Truth track but couldn't find it in the ntuple"<<std::endl;
239 }
240
241 if(debug_ > 0)
242 {
243 std::cout<<"========================================="<<std::endl;
244 std::cout<<"========================================="<<std::endl;
245 std::cout<<"Track params: "<<std::endl;
246 track->Print();
247 }
248
250 trkHistos_->Fill2DTrack(track);
251
252 if (truthHistos_) {
253 truthHistos_->Fill1DHistograms(truth_track);
255 truthHistos_->Fill1DTrackTruth(track, truth_track);
256 }
257
258 n_sel_tracks++;
259
260
261
262 //Fill histograms for FEE smearing analysis
263 trkHistos_->Fill2DHisto("xypos_at_ecal_hh",
264 track->getPositionAtEcal()[0],
265 track->getPositionAtEcal()[1]);
266
267 trkHistos_->Fill3DHisto("p_vs_TanLambda_Phi_hhh",
268 track->getPhi(),
269 track->getTanLambda(),
270 track->getP());
271
272 trkHistos_->Fill2DHisto("p_vs_nHits_hh",
273 track->getTrackerHitCount(),
274 track->getP());
275
276 if (track->getTanLambda() > 0 )
277 trkHistos_->Fill2DHisto("p_vs_nHits_top_hh",
278 track->getTrackerHitCount(),
279 track->getP());
280 else
281 trkHistos_->Fill2DHisto("p_vs_nHits_bot_hh",
282 track->getTrackerHitCount(),
283 track->getP());
284
285 trkHistos_->Fill3DHisto("p_vs_TanLambda_nHits_hhh",
286 track->getTanLambda(),
287 track->getTrackerHitCount(),
288 track->getP());
289
290
291
292 //pSmearing closure Test
293 if (!isData_ && !pSmearingFile_.empty()) {
294
295
296 //Check that I get a gaussian as expected
297 double p_base = 1.;
298
299
300 double psmear = smearingTool_->smearTrackP(*track);
301 double psmear_rel = smearingToolRel_->smearTrackP(*track);
302
303 double nhits = track->getTrackerHitCount();
304 double isTop = track->getTanLambda() > 0 ? true : false;
305
306 psmear_h_->Fill(psmear);
307 psmear_vs_nHits_hh_->Fill(nhits,psmear);
308
309 if (isTop) {
310 psmear_vs_nHits_top_hh_->Fill(nhits,psmear);
311 }
312 else {
313 psmear_vs_nHits_bot_hh_->Fill(nhits,psmear);
314 }
315
316
317 psmear_rel_h_->Fill(psmear_rel);
318 psmear_vs_nHits_rel_hh_->Fill(nhits,psmear_rel);
319
320 if (isTop) {
321 psmear_vs_nHits_top_rel_hh_->Fill(nhits,psmear_rel);
322 }
323 else {
324 psmear_vs_nHits_bot_rel_hh_->Fill(nhits,psmear_rel);
325 }
326
327 } // closer test
328
329 }//Loop on tracks
330
331 trkHistos_->Fill1DHisto("n_tracks_h",n_sel_tracks);
332
333 return true;
334}
335
337
339 delete trkHistos_;
340 trkHistos_ = nullptr;
341 if (trkSelector_)
342 trkSelector_->getCutFlowHisto()->Write();
343
344 if (truthHistos_) {
346 delete truthHistos_;
347 truthHistos_ = nullptr;
348 }
349
350 for (reg_it it = reg_histos_.begin(); it!=reg_histos_.end(); ++it) {
351 std::string dirName = it->first;
352 (it->second)->saveHistos(outF_,dirName);
353 outF_->cd(dirName.c_str());
354 reg_selectors_[it->first]->getCutFlowHisto()->Write();
355 }
356
357 if (!pSmearingFile_.empty()) {
358 outF_->cd(trkCollName_.c_str());
359 psmear_h_->Write();
360
361 psmear_vs_nHits_hh_->Write();
364 delete psmear_h_;
365 delete psmear_vs_nHits_hh_;
368
369 psmear_rel_h_->Write();
373 delete psmear_rel_h_;
377
378 }
379
380 //trkHistos_->Clear();
381}
382
Helper class for hipster analysis.
#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
bool isSingle0Trigger() const
bool isSingle1Trigger() const
void Fill2DHisto(const std::string &histoName, float valuex, float valuey, float weight=1.)
description
virtual void DefineHistos()
Definition of histograms from json config.
void Fill3DHisto(const std::string &histoName, float valuex, float valuey, float valuez, float weight=1.)
description
void Fill1DHisto(const std::string &histoName, float value, float weight=1.)
description
virtual void loadHistoConfig(const std::string histoConfigFile)
load histogram config
virtual void saveHistos(TFile *outF=nullptr, std::string folder="")
save histograms
Definition IEvent.h:7
description
Base class for all event processing components.
Definition Processor.h:34
TFile * outF_
Definition Processor.h:125
std::string name_
Definition Processor.h:128
virtual bool process()
Process the histograms and generate analysis output.
Definition Processor.h:95
description
Definition TrackHistos.h:17
void Fill2DTrack(Track *track, float weight=1., const std::string &trkname="")
Fill 2D track.
void Fill1DHistograms(Track *track=nullptr, Vertex *vtx=nullptr, float weight=1.)
Fill 1D histograms.
void doTrackComparisonPlots(bool doplots)
Compare tracks.
void Fill1DTrackTruth(Track *track, Track *truth_track, float weight=1., const std::string &="")
Truth comparison.
Definition Track.h:32
Insert description here. more details.
std::shared_ptr< TrackSmearingTool > smearingTool_
time offset
std::string ecalCollName_
Cluster Collection name.
std::string trkCollName_
Track Collection name.
std::string truthHistCfgFilename_
description
std::shared_ptr< TrackSmearingTool > smearingToolRel_
virtual void configure(const ParameterSet &parameters)
Configure the Ana Processor.
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
std::vector< std::string > regionSelections_
track selections
virtual void initialize(TTree *tree)
Callback for the Processor to take any necessary action when the processing of events starts.
std::map< std::string, std::shared_ptr< TrackHistos > >::iterator reg_it
description
std::vector< CalCluster * > * ecal_
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
TBranch * btracks_
description
TrackHistos * truthHistos_
description
std::vector< Track * > * tracks_
std::vector< std::string > regions_
std::shared_ptr< BaseSelector > trkSelector_
description