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
TridentWABAnaProcessor.cxx
Go to the documentation of this file.
1
11#include <iostream>
12#include <utility>
13TridentWABAnaProcessor::TridentWABAnaProcessor(const std::string& name, Process& process) : Processor(name,process) {
14
15}
16
17//TODO Check this destructor
18
20
22 std::cout << "Configuring TridentWABAnaProcessor" <<std::endl;
23 try
24 {
25 debug_ = parameters.getInteger("debug");
26 anaName_ = parameters.getString("anaName");
27 //cluColl_ = parameters.getString("cluColl");
28 //hitColl_ = parameters.getString("hitColl",hitColl_);
29 // rawhitColl_ = parameters.getString("rawhitColl",rawhitColl_);
30 vtxColl_ = parameters.getString("vtxColl");
31 //trkColl_ = parameters.getString("trkColl");
32 mcColl_ = parameters.getString("mcColl",mcColl_);
33 //fspartColl_ = parameters.getString("fspartColl",fspartColl_);
34 trkSelCfg_ = parameters.getString("trkSelectionjson");
35 selectionCfg_ = parameters.getString("vtxSelectionjson");
36 histoCfg_ = parameters.getString("histoCfg");
37 calTimeOffset_ = parameters.getDouble("CalTimeOffset");
38 trkTimeOffset_ = parameters.getDouble("TrkTimeOffset");
39 beamE_ = parameters.getDouble("beamE");
40 isData = parameters.getInteger("isData");
41
42 //region definitions
43 regionSelections_ = parameters.getVString("regionDefinitions");
44 regionWABSelections_ = parameters.getVString("regionWABDefinitions");
45
46
47 }
48 catch (std::runtime_error& error)
49 {
50 std::cout<<error.what()<<std::endl;
51 }
52}
53
55 tree_ = tree;
56 _ah = std::make_shared<AnaHelpers>();
57 debug_=0;
58 std::cout<<"Track Selection"<<std::endl;
59 trkSelector = std::make_shared<BaseSelector>("trkSelection",trkSelCfg_);
60 trkSelector->setDebug(debug_);
61 trkSelector->LoadSelection();
62
63 std::cout<<"Vertex Selection"<<std::endl;
64 vtxSelector = std::make_shared<BaseSelector>("vtxSelection",selectionCfg_);
65 vtxSelector->setDebug(debug_);
66 vtxSelector->LoadSelection();
67
68 std::cout<<"Making histos"<<std::endl;
69 _vtx_histos = std::make_shared<TridentHistos>("vtxSelection");
70 _vtx_histos->debugMode(debug_);
71 _vtx_histos->setBeamEnergy(beamE_);
72 _vtx_histos->loadHistoConfig(histoCfg_);
73 _vtx_histos->DefineHistos();
74
75
76 // //For each region initialize plots
77 std::cout<<"Starting Regions"<<std::endl;
78 for (unsigned int i_reg = 0; i_reg < regionSelections_.size(); i_reg++) {
79 std::string regname = AnaHelpers::getFileName(regionSelections_[i_reg],false);
80 std::cout<<"Setting up region:: " << regname <<std::endl;
81 _reg_vtx_selectors[regname] = std::make_shared<BaseSelector>(regname, regionSelections_[i_reg]);
82 _reg_vtx_selectors[regname]->setDebug(debug_);
83 _reg_vtx_selectors[regname]->LoadSelection();
84
85 _reg_vtx_histos[regname] = std::make_shared<TridentHistos>(regname);
86 _reg_vtx_histos[regname]->setBeamEnergy(beamE_);
87 _reg_vtx_histos[regname]->loadHistoConfig(histoCfg_);
88 _reg_vtx_histos[regname]->DefineHistos();
89
90 _reg_tuples[regname] = std::make_shared<FlatTupleMaker>(regname+"_tree");
91 _reg_tuples[regname]->addVariable("unc_vtx_mass");
92 _reg_tuples[regname]->addVariable("unc_vtx_z");
93
94 _regions.push_back(regname);
95 }
96
97
98 for (unsigned int i_reg = 0; i_reg < regionWABSelections_.size(); i_reg++) {
99 std::string regname = AnaHelpers::getFileName(regionWABSelections_[i_reg],false);
100 std::cout<<"Setting up region:: " << regname <<std::endl;
101 _reg_WAB_selectors[regname] = std::make_shared<BaseSelector>(regname, regionWABSelections_[i_reg]);
102 _reg_WAB_selectors[regname]->setDebug(debug_);
103 _reg_WAB_selectors[regname]->LoadSelection();
104
105 _reg_WAB_histos[regname] = std::make_shared<TridentHistos>(regname);
106 _reg_WAB_histos[regname]->loadHistoConfig(histoCfg_);
107 _reg_WAB_histos[regname]->DefineHistos();
108
109 _regionsWAB.push_back(regname);
110 }
111
112 //init Reading Tree
113 tree_->SetBranchAddress(vtxColl_.c_str(), &vtxs_ , &bvtxs_);
114 //tree_->SetBranchAddress(fspartColl_.c_str(), &fspart_ , &bfspart_);
115 tree_->SetBranchAddress("EventHeader",&evth_ , &bevth_);
116 //tree_->SetBranchAddress(cluColl_.c_str(), &clus_ , &bclus_);
117 //tree_->SetBranchAddress(hitColl_.c_str(), &hits_ , &bhits_);
118 //tree_->SetBranchAddress(rawhitColl_.c_str(), &rawhits_ , &brawhits_);
119 tree_->SetBranchAddress("TSBank", &tsdata_ , &btsdata_);
120 //If track collection name is empty take the tracks from the particles. TODO:: change this
121 //if (!trkColl_.empty())
122 // tree_->SetBranchAddress(trkColl_.c_str(),&trks_, &btrks_);
123 if(!isData && !mcColl_.empty()) tree_->SetBranchAddress(mcColl_.c_str() , &mcParts_, &bmcParts_);
124 std::cout<<"Done with TridentWABAnaProcessor::initialization"<<std::endl;;
125
126}
127
129
130 HpsEvent* hps_evt = (HpsEvent*) ievent;
131 double weight = 1.;
132 //Get "true" mass
133 double apMass = -0.9;
134 double apZ = -0.9;
135
136 if (mcParts_) {
137 if(debug_)std::cout<<"Number of MCParticles for this events = "<<mcParts_->size()<<std::endl;
138 for(int i = 0; i < mcParts_->size(); i++){
139 if(mcParts_->at(i)->getPDG() == 622) {
140 apMass = mcParts_->at(i)->getMass();
141 apZ = mcParts_->at(i)->getVertexPosition().at(2);
142 }
143 }
144 }
145
146 /*
147 int nElectrons=0;
148 int nPositrons=0;
149 if(trks_->size()>0){
150 for(int i_trk; i_trk<trks_->size();i_trk++){
151 Track* trk=trks_->at(i_trk);
152 int ch=trk->getCharge();
153 if(ch==-1){
154 nElectrons++;
155 }else{
156 nPositrons++;
157 }
158 }
159 }
160
161 int nEleSideClusters=0;
162 int nPosSideClusters=0;
163
164 for(int i_clu=0; i_clu<clus_->size(); i_clu++){
165 CalCluster* clu=clus_->at(i_clu);
166 double clX=clu->getPosition().at(0);
167 if(clX>100.)
168 nPosSideClusters++;
169 if(clX<0)
170 nEleSideClusters++;
171 }
172 */
173 std::vector<Vertex*> selected_tri;
174
175 // std::cout<<"Found "<<vtxs_->size()<<" Unconstrained Vertices"<<std::endl;
176 // std::cout<<"Found "<<matched_tri.size()<<" Matched Vertices"<<std::endl;
177 for ( int i_vtx = 0; i_vtx < vtxs_->size(); i_vtx++ ) {
178
179 vtxSelector->getCutFlowHisto()->Fill(0.,weight);
180
181 Vertex* vtx = vtxs_->at(i_vtx);
182 Particle* ele = nullptr;
183 Particle* pos = nullptr;
184
185 // bool foundParts = _ah->GetParticlesFromVtxAndParticleList(*fspart_,vtx,ele,pos);
186 bool foundParts = _ah->GetParticlesFromVtx(vtx,ele,pos);
187
188 if(debug_) std::cout<<"Checking Particles"<<std::endl;
189 if (!foundParts) {
190 std::cout<<"TridentWABAnaProcessor::WARNING::Found vtx without ele/pos. Skip."<<std::endl;
191 continue;
192 }
193
194 // Trigger requirement - *really hate* having to do it here for each vertex.
195 if(debug_) std::cout<<"Checking Trigger"<<std::endl;
196 if (isData) {
197 if (!vtxSelector->passCutEq("Singles2or3_eq",((int)tsdata_->prescaled.Single_2_Top)||((int)tsdata_->prescaled.Single_2_Bot),weight)){
198 if(debug_)std::cout<<"events didn't pass singles2, check single3"<<std::endl;
199 if (!vtxSelector->passCutEq("Singles2or3_eq",((int)tsdata_->prescaled.Single_3_Top)||((int)tsdata_->prescaled.Single_3_Bot),weight)){
200 if(debug_)std::cout<<"Skipping because event didn't pass singles2 or 3"<<std::endl;
201 continue;
202 }
203 }
204 }
205 /*
206 Track ele_trk = ele->getTrack(); //wish these were still pointers to the track...why did this change?
207 Track pos_trk = pos->getTrack();
208 Track* ele_trk_from_list = _ah->GetTrackFromParticle(*trks_,ele);
209 Track* pos_trk_from_list = _ah->GetTrackFromParticle(*trks_,pos);
210 int n_hits_ele=ele_trk_from_list->getTrackerHitCount();
211 int n_hits_pos=pos_trk_from_list->getTrackerHitCount();
212 */
213 Track* ele_trk=(Track*) ele->getTrack().Clone();
214 Track* pos_trk=(Track*) pos->getTrack().Clone();
215 int n_hits_ele=ele_trk->getTrackerHitCount();
216 int n_hits_pos=pos_trk->getTrackerHitCount();
217
218
219 CalCluster ele_clu=ele->getCluster();
220 CalCluster pos_clu=pos->getCluster();
221
222 TVector3 ele_mom;
223 ele_mom.SetX(ele_trk->getMomentum()[0]);
224 ele_mom.SetY(ele_trk->getMomentum()[1]);
225 ele_mom.SetZ(ele_trk->getMomentum()[2]);
226
227 TVector3 pos_mom;
228 pos_mom.SetX(pos_trk->getMomentum()[0]);
229 pos_mom.SetY(pos_trk->getMomentum()[1]);
230 pos_mom.SetZ(pos_trk->getMomentum()[2]);
231
232
233 if(debug_)std::cout<<" Going through cuts "<<std::endl;
234 if (!vtxSelector->passCutGt("eleNHits_gt",n_hits_ele,weight))
235 continue;
236 if (!vtxSelector->passCutGt("posNHits_gt",n_hits_pos,weight))
237 continue;
238 if(debug_)std::cout<<" Pass nHits for each track cut"<<std::endl;
239 if (!vtxSelector->passCutLt("eleMom_lt",ele_mom.Mag(),weight))
240 continue;
241 if(debug_)std::cout<<" Pass electron momentum cut"<<std::endl;
242
243 //Ele Track Quality
244 if (!vtxSelector->passCutLt("eleTrkChi2_lt",ele_trk->getChi2Ndf(),weight))
245 continue;
246
247 //Pos Track Quality
248 if (!vtxSelector->passCutLt("posTrkChi2_lt",pos_trk->getChi2Ndf(),weight))
249 continue;
250 if(debug_)std::cout<<" Pass chi^2 for each track"<<std::endl;
251
252 //Vertex Quality
253 if (!vtxSelector->passCutLt("chi2unc_lt",vtx->getChi2(),weight))
254 continue;
255
256 if(debug_)std::cout<<" Pass vertex chi2 cut"<<std::endl;
257
258 //Ele min momentum cut
259 if (!vtxSelector->passCutGt("eleMom_gt",ele_mom.Mag(),weight))
260 continue;
261
262 //Pos min momentum cut
263 if (!vtxSelector->passCutGt("posMom_gt",pos_mom.Mag(),weight))
264 continue;
265
266 if(debug_)std::cout<<" Pass min p for each track "<<std::endl;
267
268
269 //Max vtx momentum
270
271 if (!vtxSelector->passCutLt("maxVtxMom_lt",(ele_mom+pos_mom).Mag(),weight))
272 continue;
273
274 if (!vtxSelector->passCutGt("minVtxMom_gt",(ele_mom+pos_mom).Mag(),weight))
275 continue;
276 if(debug_)std::cout<<" Pass vertex momentum cuts"<<std::endl;
277
278
279 double corr_eleClusterTime=666;
280 double corr_posClusterTime=666;
281
282 corr_eleClusterTime = ele_clu.getTime() - calTimeOffset_;
283 corr_posClusterTime = pos_clu.getTime() - calTimeOffset_;
284
285 double corr_eleTrackTime=-666;
286 double corr_posTrackTime=-666;
287
288 corr_eleTrackTime=ele_trk->getTrackTime() - trkTimeOffset_;
289 corr_posTrackTime=pos_trk->getTrackTime() - trkTimeOffset_;
290
291 bool hasEleCluster=corr_eleClusterTime>-300; //this is kludgy but the default time is set at -9999 ns...anything < ~ -100 ns means it was not filled...
292 bool hasPosCluster=corr_posClusterTime>-300;
293
294 //Ele Track Time
295 if (!vtxSelector->passCutLt("eleTrkTime_lt",fabs(corr_eleTrackTime),weight))
296 continue;
297 //Pos Track Time
298 if (!vtxSelector->passCutLt("posTrkTime_lt",fabs(corr_posTrackTime),weight))
299 continue;
300
301 if(debug_)std::cout<<" Pass track time cuts"<<std::endl;
302
303 //Ele Track-Cluster Time Difference
304 if(hasEleCluster)
305 if (!vtxSelector->passCutLt("eleTrkCluTimeDiff_lt",fabs(corr_eleTrackTime - corr_eleClusterTime),weight))
306 continue;
307
308 //Pos Track-Cluster Time Difference
309 if(hasPosCluster)
310 if (!vtxSelector->passCutLt("posTrkCluTimeDiff_lt",fabs(corr_posTrackTime - corr_posClusterTime),weight))
311 continue;
312
313 if(debug_)std::cout<<" Pass cluster match cuts"<<std::endl;
314
315 //Ele Pos Cluster Tme Difference
316 if(hasEleCluster && hasPosCluster)
317 if (!vtxSelector->passCutLt("eleposCluTimeDiff_lt",fabs(corr_eleClusterTime - corr_posClusterTime),weight))
318 continue;
319
320 if(debug_)std::cout<<" Pass ele-pos cluster time difference...and that's it!"<<std::endl;
321
322 _vtx_histos->Fill1DVertex(vtx,
323 ele,
324 pos,
325 ele_trk,
326 pos_trk,
327 // ele_trk_from_list,
328 //pos_trk_from_list,
330 weight);
331 if(debug_)std::cout<<" Filled 1D vertex plots for vtx pre-selection "<<std::endl;
332 _vtx_histos->Fill2DHistograms(vtx,weight);
333 _vtx_histos->Fill2DTrack(ele_trk,weight,"ele_");
334 _vtx_histos->Fill2DTrack(pos_trk,weight,"pos_");
335 if(debug_)std::cout<<" Filled 2D vertex plots for vtx pre-selection "<<std::endl;
336 _vtx_histos->FillTrackClusterHistos(std::pair<CalCluster,Track*>(ele_clu,ele_trk),std::pair<CalCluster,Track*>(pos_clu,pos_trk),calTimeOffset_,trkTimeOffset_,weight);
337 if(debug_)std::cout<<" Filled track-cluster plots pre-selection "<<std::endl;
338 selected_tri.push_back(vtx);
339 vtxSelector->clearSelector();
340 }
341
342 if(debug_) std::cout<<"Found "<<selected_tri.size()<<" Selected Vertices"<<std::endl;
343 _vtx_histos->Fill1DHisto("n_vertices_h",selected_tri.size());
344 /*
345 if (trks_){
346 _vtx_histos->Fill1DHisto("n_tracks_h",trks_->size(),weight);
347 _vtx_histos->Fill1DHisto("n_positrons_h",nPositrons,weight);
348 _vtx_histos->Fill1DHisto("n_electrons_h",nElectrons,weight);
349 }
350
351 _vtx_histos->Fill1DHisto("n_pos_clusters_h",nPosSideClusters,weight);
352 _vtx_histos->Fill1DHisto("n_ele_clusters_h",nEleSideClusters,weight);
353 */
354 //Make Plots for each region: loop on each region. Check if the region has the cut and apply it
355
356 for (auto region : _regions ) {
357 int nvertPass=0;
358 std::vector<Vertex*> final_tri;
359 for ( auto cand : selected_tri) {
360 //No cuts.
361 _reg_vtx_selectors[region]->getCutFlowHisto()->Fill(0.,weight);
362 // get objects we need for this candidate
363 Vertex* vtx = cand;
364 Particle* ele = nullptr;
365 Particle* pos = nullptr;
366 bool foundParts = _ah->GetParticlesFromVtx(vtx,ele,pos);
367 // bool foundParts = _ah->GetParticlesFromVtxAndParticleList(*fspart_,vtx,ele,pos);
368 if(debug_) std::cout<<"Checking Particles"<<std::endl;
369 if (!foundParts) {
370 std::cout<<"TridentWABAnaProcessor::WARNING::Found vtx without ele/pos. Skip."<<std::endl;
371 continue;
372 }
373 Track* ele_trk =(Track*) ele->getTrack().Clone();
374 Track* pos_trk =(Track*) pos->getTrack().Clone();
375
376 CalCluster ele_clu=ele->getCluster();
377 CalCluster pos_clu=pos->getCluster();
378 //Compute analysis variables here.
379
380 double ele_E = ele->getEnergy();
381 double pos_E = pos->getEnergy();
382
383 TVector3 ele_mom;
384 ele_mom.SetX(ele_trk->getMomentum()[0]);
385 ele_mom.SetY(ele_trk->getMomentum()[1]);
386 ele_mom.SetZ(ele_trk->getMomentum()[2]);
387
388 TVector3 pos_mom;
389 pos_mom.SetX(pos_trk->getMomentum()[0]);
390 pos_mom.SetY(pos_trk->getMomentum()[1]);
391 pos_mom.SetZ(pos_trk->getMomentum()[2]);
392
393 if (!_reg_vtx_selectors[region]->passCutGt("radMom_gt",(ele_mom+pos_mom).Mag()/beamE_,weight))
394 continue;
395 /*
396 if (!_reg_vtx_selectors[region]->passCutLt("nPosTracks_lt",nPositrons,weight))
397 continue ;
398 if (!_reg_vtx_selectors[region]->passCutLt("nEleTracks_lt",nElectrons,weight))
399 continue;
400
401 if (!_reg_vtx_selectors[region]->passCutEq("nPosSideClusters_eq",nPosSideClusters,weight))
402 continue;
403 if (!_reg_vtx_selectors[region]->passCutEq("nEleSideClusters_eq",nEleSideClusters,weight))
404 continue;
405 */
406 /* turn off matching for now...
407 if(!isData){
408 std::pair<Track*,MCParticle*> eleMCMatch=matchToMCParticle(ele_trk,*mcParts_);
409 std::pair<Track*,MCParticle*> posMCMatch=matchToMCParticle(pos_trk,*mcParts_);
410 if(!_reg_vtx_selectors[region]->passCutEq("eleMCMatched",eleMCMatch.second!=NULL,weight))
411 continue;
412 if(!_reg_vtx_selectors[region]->passCutEq("posMCMatched",posMCMatch.second!=NULL,weight))
413 continue;
414 //check if MC matched particles are from gamma*
415 bool isRadEle=false;
416 bool isRadPos=false;
417 if(eleMCMatch.second!=NULL){
418 isRadEle=eleMCMatch.second->getMomPDG()==622;
419 if(isRadEle && debug_)
420 std::cout<<"Found radiative electron"<<std::endl;
421 }
422 if(posMCMatch.second!=NULL){
423 isRadPos=posMCMatch.second->getMomPDG()==622;
424 if(isRadEle&&debug_)
425 std::cout<<"Found radiative positron"<<std::endl;
426 }
427 if(!_reg_vtx_selectors[region]->passCutEq("eleMCGammaSt",isRadEle,weight))
428 continue;
429 if(!_reg_vtx_selectors[region]->passCutEq("posMCGammaSt",isRadPos,weight))
430 continue;
431 }
432 */
433 double corr_eleClusterTime=666;
434 double corr_posClusterTime=666;
435
436 corr_eleClusterTime = ele_clu.getTime() - calTimeOffset_;
437 corr_posClusterTime = pos_clu.getTime() - calTimeOffset_;
438
439 double corr_eleTrackTime=-666;
440 double corr_posTrackTime=-666;
441
442 corr_eleTrackTime=ele_trk->getTrackTime() - trkTimeOffset_;
443 corr_posTrackTime=pos_trk->getTrackTime() - trkTimeOffset_;
444
445 bool hasEleCluster=corr_eleClusterTime>-300; //this is kludgy but the default time is set at -9999 ns...anything < ~ -100 ns means it was not filled...
446 bool hasPosCluster=corr_posClusterTime>-300;
447
448 if(!_reg_vtx_selectors[region]->passCutEq("eleClusterMatched",hasEleCluster,weight))
449 continue;
450 if(!_reg_vtx_selectors[region]->passCutEq("posClusterMatched",hasPosCluster,weight))
451 continue;
452
453 bool foundL1ele = false;
454 bool foundL2ele = false;
455 // Track* ele_trk_from_list = _ah->GetTrackFromParticle(*trks_,ele);
456 // Track* pos_trk_from_list = _ah->GetTrackFromParticle(*trks_,pos);
457 _ah->InnermostLayerCheck(ele_trk, foundL1ele, foundL2ele);
458
459 bool foundL1pos = false;
460 bool foundL2pos = false;
461 _ah->InnermostLayerCheck(pos_trk, foundL1pos, foundL2pos);
462
463 int layerCombo=-1;
464 if (foundL1pos&&foundL1ele) //L1L1
465 layerCombo=1;
466 if(!foundL1pos&&foundL2pos&&foundL1ele)//L2L1
467 layerCombo=2;
468 if(foundL1pos&&!foundL1ele&&foundL2ele)//L1L2
469 layerCombo=3;
470 if(!foundL1pos&&foundL2pos&&!foundL1ele&&foundL2ele)//L2L2
471 layerCombo=4;
472
473 if (!_reg_vtx_selectors[region]->passCutEq("LayerRequirement",layerCombo,weight))
474 continue;
475 if(debug_)std::cout<<"passed layer cut layer combo = "<<layerCombo<<std::endl;
476 if(!_reg_vtx_selectors[region]->passCutEq("ele_FoundL2",foundL2ele,weight))
477 continue;
478 if(!_reg_vtx_selectors[region]->passCutEq("pos_FoundL2",foundL2pos,weight))
479 continue;
480 nvertPass++; //this vertex passed all cuts (expect nVtx cut...)
481 //N selected vertices - this is quite a silly cut to make at the end. But okay. that's how we decided atm.
482 // actually, pick random vertex belore
483 final_tri.push_back(vtx);
484
485 }// preselected vertices
486
487 _reg_vtx_histos[region]->Fill1DHisto("n_vertices_h",selected_tri.size(),weight);
488 _reg_vtx_histos[region]->Fill1DHisto("n_vertices_passallcuts_h",nvertPass,weight);
489
490 if(final_tri.size()==0)
491 continue;
492 // pick a random good vertex:
493 Vertex* vtx = *select_randomly(final_tri.begin(), final_tri.end());
494 // get objects we need for this candidate....again...this is lame. I should encapsulate this or something...
495 Particle* ele = nullptr;
496 Particle* pos = nullptr;
497 _ah->GetParticlesFromVtx(vtx,ele,pos);
498 Track* ele_trk = (Track*)ele->getTrack().Clone();
499 Track* pos_trk = (Track*)pos->getTrack().Clone();
500 CalCluster ele_clu=ele->getCluster();
501 CalCluster pos_clu=pos->getCluster();
502
504
505 double corr_eleClusterTime = ele_clu.getTime() - calTimeOffset_;
506 double corr_posClusterTime = pos_clu.getTime() - calTimeOffset_;
507
508 double corr_eleTrackTime=ele_trk->getTrackTime() - trkTimeOffset_;
509 double corr_posTrackTime=pos_trk->getTrackTime() - trkTimeOffset_;
510 if(debug_){
511 std::cout<<"***********************************"<<std::endl;
512 //std::cout<<"nPositrons in event = "<<nPositrons<<std::endl;
513 std::cout<<"positron position at ecal: x = "<<pos_trk->getPositionAtEcal().at(0)
514 <<"; y = "<<pos_trk->getPositionAtEcal().at(1)<<"; p = "<<pos_trk->getMomentum().at(2)<<" trk time = "<<corr_posTrackTime<<std::endl;
515 std::cout<<"positron Cluster: x = "<<pos_clu.getPosition().at(0)
516 <<"; y = "<<pos_clu.getPosition().at(1)<<"; E = "<<pos_clu.getEnergy()<<std::endl;
517 // std::cout<<"clus_->size() = "<<clus_->size()<<std::endl;
518 // for(int k_clu=0; k_clu<clus_->size(); k_clu++){
519 //CalCluster* clu=clus_->at(k_clu);
520 // double corr_ClusterTime = clu->getTime() - calTimeOffset_;
521 //std::cout<<"CalCluster k = "<<k_clu<<" x = "<<clu->getPosition().at(0)<<" y = "<<clu->getPosition().at(1)<<" cluster time = "<< corr_ClusterTime<<"; E = "<<clu->getEnergy()<<std::endl;
522 //}
523 /*
524 std::cout<<"fspart_->size() = "<<fspart_->size()<<std::endl;
525 for(int j_part=0; j_part<fspart_->size();j_part++){
526 Particle* part=fspart_->at(j_part);
527 Track trk=part->getTrack();
528 CalCluster clu=part->getCluster();
529 double corr_ClusterTime = clu.getTime() - calTimeOffset_;
530 double corr_TrackTime=trk.getTrackTime() - trkTimeOffset_;
531 std::cout<<"FSParticle track:: charge = "<<trk.getCharge()<<"; nHits = "<<trk.getTrackerHitCount()<<"; trk time = "<<corr_TrackTime<<std::endl;
532 std::cout<<"FSParticle track:: x = "<<trk.getPositionAtEcal().at(0)
533 <<"; y = "<<trk.getPositionAtEcal().at(1)<<"; p = "<<trk.getMomentum().at(2)<<std::endl;
534 std::cout<<"FSParticle cluster:: x = "<<clu.getPosition().at(0)<<" y = "<<clu.getPosition().at(1)<<"; E = "<<clu.getEnergy()<<"; clu time = "<<corr_ClusterTime<<std::endl;
535 }
536 */
537 std::cout<<"***********************************"<<std::endl;
538 /*
539 for(int j_trk=0; j_trk<trks_->size();j_trk++){
540 Track* trk=trks_->at(j_trk);
541 std::cout<<"KFTrack:: charge = "<<trk->getCharge()<<"; nHits = "<<trk->getTrackerHitCount()<<"; trk time = "<<trk->getTrackTime()<<std::endl;
542 std::cout<<"KFtrack:: x = "<<trk->getPositionAtEcal().at(0)
543 <<"; y = "<<trk->getPositionAtEcal().at(1)<<"; p = "<<trk->getMomentum().at(2)<<std::endl;
544 }
545 */
546 std::cout<<"***********************************"<<std::endl;
547 }
548 // continue;
549 //assign the layer codes for this event
550 // Track* ele_trk_from_list = _ah->GetTrackFromParticle(*trks_,ele);
551 // Track* pos_trk_from_list = _ah->GetTrackFromParticle(*trks_,pos);
552 if(debug_)std::cout<<"fsp->getTrack():: electron time = "<<ele_trk->getTrackTime()<<std::endl;
553 // if(debug_)std::cout<<"from track list:: electron time = "<<ele_trk_from_list->getTrackTime()<<std::endl;
554 _reg_vtx_histos[region]->AssignLayerCode( ele_trk,pos_trk);
555 _reg_vtx_histos[region]->Fill2DHistograms(vtx,weight);
556 _reg_vtx_histos[region]->Fill1DVertex(vtx,
557 ele,
558 pos,
559 ele_trk,
560 pos_trk,
561 //ele_trk_from_list,
562 //pos_trk_from_list,
564 weight);
565
566 _reg_vtx_histos[region]->Fill2DTrack(ele_trk,weight,"ele_");
567 _reg_vtx_histos[region]->Fill2DTrack(pos_trk,weight,"pos_");
568 // _reg_vtx_histos[region]->FillTrackClusterHistos(std::pair<CalCluster,Track*>(ele_clu,ele_trk),std::pair<CalCluster,Track*>(pos_clu,pos_trk),calTimeOffset_,trkTimeOffset_,clus_,weight);
569 _reg_vtx_histos[region]->FillTrackClusterHistos(std::pair<CalCluster,Track*>(ele_clu,ele_trk),std::pair<CalCluster,Track*>(pos_clu,pos_trk),calTimeOffset_,trkTimeOffset_,weight);
570
571 /*
572 if (trks_){
573 _reg_vtx_histos[region]->Fill1DHisto("n_tracks_h",trks_->size(),weight);
574 _reg_vtx_histos[region]->Fill1DHisto("n_positrons_h",nPositrons,weight);
575 _reg_vtx_histos[region]->Fill1DHisto("n_electrons_h",nElectrons,weight);
576 }
577 _reg_vtx_histos[region]->Fill1DHisto("n_pos_clusters_h",nPosSideClusters,weight);
578 _reg_vtx_histos[region]->Fill1DHisto("n_ele_clusters_h",nEleSideClusters,weight);
579 */
580 //Just for the selected vertex
581 _reg_tuples[region]->setVariableValue("unc_vtx_mass", vtx->getInvMass());
582
583 //TODO put this in the Vertex!
584 TVector3 vtxPosSvt;
585 vtxPosSvt.SetX(vtx->getX());
586 vtxPosSvt.SetY(vtx->getY());
587 vtxPosSvt.SetZ(vtx->getZ());
588 vtxPosSvt.RotateY(-0.0305);
589
590 _reg_tuples[region]->setVariableValue("unc_vtx_z" , vtxPosSvt.Z());
591 _reg_tuples[region]->fill();
592 } // regions
593
594
595 /* Ok...now do the WAB analysis */
596
597 // std::vector<WABCand> selected_wab;
598 /*
599 if(debug_) std::cout<<"Number of electrons = "<<goodElectrons.size()<<"; number of photons = "<<goodPhotons.size()<<std::endl;
600
601 for(auto ele: goodElectrons){
602 Track* ele_trk=ele.second;
603 CalCluster* ele_clu=ele.first;
604 for(auto gamma: goodPhotons){
605 std::pair<CalCluster*,Track*> photPair(gamma,NULL); //make this dumb pair for histo filling
606 for(auto region : _regionsWAB){
607 //No cuts.
608 _reg_WAB_selectors[region]->getCutFlowHisto()->Fill(0.,weight);
609 //fill some histos....
610 bool foundL1ele = false;
611 bool foundL2ele = false;
612 //_ah->InnermostLayerCheck(ele_trk, foundL1ele, foundL2ele);
613 int layerCombo=3;//== no L1 or L2 hit
614 if(foundL1ele)
615 layerCombo=1;
616 else if(foundL2ele)
617 layerCombo=2;
618 if (!_reg_WAB_selectors[region]->passCutEq("LayerRequirement",layerCombo,weight))
619 continue;
620
621 if(!_reg_WAB_selectors[region]->passCutEq("eleClusterMatched",ele.first!=NULL,weight))
622 continue;
623 bool isFiducialElectron=_ah->IsECalFiducial(ele.first);
624 bool isFiducialGamma=_ah->IsECalFiducial(gamma);
625
626 if (!_reg_WAB_selectors[region]->passCutEq("cluFiducialElectron",isFiducialElectron,weight))
627 continue;
628 if (!_reg_WAB_selectors[region]->passCutEq("cluFiducialGamma",isFiducialGamma,weight))
629 continue;
630
631 double corr_eleClusterTime=-666;
632 if(ele_clu !=NULL) corr_eleClusterTime = ele_clu->getTime() - timeOffset_;
633 double corr_gamClusterTime = gamma->getTime() - timeOffset_;
634
635 //gamma cluster time
636 if (!_reg_WAB_selectors[region]->passCutLt("gamCluTime_lt",fabs(corr_gamClusterTime),weight))
637 continue;
638 //Ele Pos Cluster Tme Difference
639 if(ele_clu!=NULL)
640 if (!_reg_WAB_selectors[region]->passCutLt("elegamCluTimeDiff_lt",fabs(corr_eleClusterTime - corr_gamClusterTime),weight))
641 continue;
642
643 //Ele Track-Cluster Time Difference
644 if(ele_clu!=NULL)
645 if (!_reg_WAB_selectors[region]->passCutLt("eleTrkCluTimeDiff_lt",fabs(ele_trk->getTrackTime() - corr_eleClusterTime),weight))
646 continue;
647
648 _reg_WAB_histos[region]->Fill1DTrack(ele.second,weight,"ele_");
649 _reg_WAB_histos[region]->FillWABHistos(ele,gamma,weight);
650 _reg_WAB_histos[region]->FillTrackClusterHistos(ele,photPair,timeOffset_,weight);
651 std::cout<<"Filled WAB Histos"<<std::endl;
652 }
653 }
654 }
655 */
656 return true;
657}
658
660
661 //TODO clean this up a little.
662 outF_->cd();
663 _vtx_histos->saveHistos(outF_,_vtx_histos->getName());
664 outF_->cd(_vtx_histos->getName().c_str());
665 vtxSelector->getCutFlowHisto()->Write();
666
667
668 for (reg_it it = _reg_vtx_histos.begin(); it!=_reg_vtx_histos.end(); ++it) {
669 (it->second)->saveHistos(outF_,it->first);
670 outF_->cd((it->first).c_str());
671 _reg_vtx_selectors[it->first]->getCutFlowHisto()->Write();
672 //Save tuples
673 _reg_tuples[it->first]->writeTree();
674 }
675 for (reg_it it = _reg_WAB_histos.begin(); it!=_reg_WAB_histos.end(); ++it) {
676 (it->second)->saveHistos(outF_,it->first);
677 outF_->cd((it->first).c_str());
678 _reg_WAB_selectors[it->first]->getCutFlowHisto()->Write();
679 }
680 outF_->Close();
681
682}
683
684//get the v0 from the tracks after unduplicating and matching to clusters
685Vertex* TridentWABAnaProcessor::matchPairToVertex(Track* eleTrk,Track* posTrk, std::vector<Vertex*>& verts){
686 Vertex* matchedVert=NULL;
687 for (auto vtx: verts){
688 Particle* ele=NULL;
689 Particle* pos=NULL;
690 bool foundParts = _ah->GetParticlesFromVtx(vtx,ele,pos);
691 Track eleVtx=ele->getTrack();
692 Track posVtx=pos->getTrack();
693 // std::cout<<eleVtx.getID()<<" "<<eleTrk->getID()<<" "<<posVtx.getID()<<" "<<posTrk->getID()<<std::endl;
694 if (eleVtx.getID()==eleTrk->getID() && posVtx.getID()==posTrk->getID())
695 matchedVert=vtx;
696 }
697 return matchedVert;
698}
699
700std::pair<Track*,MCParticle*> TridentWABAnaProcessor::matchToMCParticle(Track* trk, std::vector<MCParticle*>& mcParts){
701 int minHitsForMatch=3;
702 MCParticle* matchedMCPart=NULL;
703 TRefArray trk_hits = trk->getSvtHits();
704 std::map<int, std::vector<int> > trueHitIDs;
705
706 for(int i = 0; i < hits_->size(); i++) {
707 TrackerHit* hit = hits_->at(i);
708 trueHitIDs[hit->getID()] = hit->getMCPartIDs();
709 }
710 std::map<int, int> nHits4part;
711 for(int i = 0; i < trk_hits.GetEntries(); i++){
712 TrackerHit* eleHit = (TrackerHit*)trk_hits.At(i);
713 for(int idI = 0; idI < trueHitIDs[eleHit->getID()].size(); idI++ ){
714 int partID = trueHitIDs[eleHit->getID()].at(idI);
715 if ( nHits4part.find(partID) == nHits4part.end() ) {
716 // not found
717 nHits4part[partID] = 1;
718 }
719 else {
720 // found
721 nHits4part[partID]++;
722 }
723 }
724 }
725
726 //Determine the MC part with the most hits on the track
727 int maxNHits = 0;
728 int maxID = 0;
729 for (std::map<int,int>::iterator it=nHits4part.begin(); it!=nHits4part.end(); ++it){
730 if(it->second > maxNHits){
731 maxNHits = it->second;
732 maxID = it->first;
733 }
734 }
735 // std::cout<<"Got maxID and nHits = "<<maxNHits<<std::endl;
736
737 if(maxNHits>=minHitsForMatch){
738 for(int i = 0; i < mcParts.size(); i++){
739 if(mcParts.at(i)->getID() != maxID) continue;
740 // std::cout<<"Found Match"<<std::endl;
741 matchedMCPart=mcParts.at(i);
742 }
743 }
744
745 return std::pair<Track*,MCParticle*>(trk,matchedMCPart);
746}
747
748std::vector<CalCluster*> TridentWABAnaProcessor::getUnmatchedClusters(std::vector<CalCluster*>& allClusters,std::vector<std::pair<CalCluster*,Track*> > electrons, std::vector<std::pair<CalCluster*,Track*> > positrons){
749 std::vector<CalCluster*> unmatchedClusters;
750
751 for(auto clu: allClusters){
752 bool foundMatch=false;
753 for (auto ele: electrons){
754 CalCluster* eleCl=ele.first;
755 if(clu == eleCl)
756 foundMatch=true;
757 }
758 for (auto pos: positrons){
759 CalCluster* posCl=pos.first;
760 if(clu == posCl)
761 foundMatch=true;
762 }
763 if(!foundMatch)
764 unmatchedClusters.push_back(clu);
765 }
766 return unmatchedClusters;
767}
768
#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
double getEnergy() const
Definition CalCluster.h:73
std::vector< double > getPosition() const
Definition CalCluster.h:63
double getTime() const
Definition CalCluster.h:83
Definition IEvent.h:7
description
Track getTrack() const
Definition Particle.h:48
CalCluster getCluster() const
Definition Particle.h:62
double getEnergy() const
Definition Particle.h:143
Base class for all event processing components.
Definition Processor.h:34
TFile * outF_
Definition Processor.h:125
virtual bool process()
Process the histograms and generate analysis output.
Definition Processor.h:95
tsBits prescaled
Definition TSData.h:66
Definition Track.h:32
double getChi2Ndf() const
Definition Track.h:126
int getTrackerHitCount() const
Definition Track.h:345
double getTrackTime() const
Definition Track.h:160
std::vector< double > getPositionAtEcal()
Definition Track.cxx:53
int getID() const
Definition Track.h:262
TRefArray getSvtHits() const
Definition Track.h:64
std::vector< double > getMomentum()
Definition Track.h:285
std::vector< int > getMCPartIDs() const
Definition TrackerHit.h:127
int getID() const
Definition TrackerHit.h:124
std::map< std::string, std::shared_ptr< BaseSelector > > _reg_WAB_selectors
std::vector< std::string > regionWABSelections_
virtual void configure(const ParameterSet &parameters)
Callback for the Processor to configure itself from the given set of parameters.
std::shared_ptr< TridentHistos > _vtx_histos
virtual void finalize()
Callback for the Processor to take any necessary action when the processing of events finishes,...
std::vector< std::string > regionSelections_
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< TridentHistos > > _reg_vtx_histos
std::map< std::string, std::shared_ptr< BaseSelector > > _reg_vtx_selectors
std::map< std::string, std::shared_ptr< TridentHistos > > _reg_WAB_histos
std::shared_ptr< BaseSelector > vtxSelector
std::vector< TrackerHit * > * hits_
std::vector< std::string > _regionsWAB
std::map< std::string, std::shared_ptr< TridentHistos > >::iterator reg_it
std::map< std::string, std::shared_ptr< FlatTupleMaker > > _reg_tuples
Iter select_randomly(Iter start, Iter end, RandomGenerator &g)
std::shared_ptr< AnaHelpers > _ah
Vertex * matchPairToVertex(Track *ele, Track *pos, std::vector< Vertex * > &verts)
std::pair< Track *, MCParticle * > matchToMCParticle(Track *part, std::vector< MCParticle * > &mcParts)
std::shared_ptr< BaseSelector > trkSelector
std::vector< CalCluster * > getUnmatchedClusters(std::vector< CalCluster * > &allClusters, std::vector< std::pair< CalCluster *, Track * > > electrons, std::vector< std::pair< CalCluster *, Track * > > positrons)
std::vector< Vertex * > * vtxs_
std::vector< std::string > _regions
std::vector< MCParticle * > * mcParts_
TridentWABAnaProcessor(const std::string &name, Process &process)
bool Single_2_Bot
Definition TSData.h:49
bool Single_2_Top
Definition TSData.h:45
bool Single_3_Top
Definition TSData.h:46
bool Single_3_Bot
Definition TSData.h:50