11 #include "art/Framework/Core/EDAnalyzer.h"
12 #include "art/Framework/Core/ModuleMacros.h"
13 #include "art/Framework/Principal/Event.h"
14 #include "art/Framework/Principal/Handle.h"
15 #include "art/Framework/Principal/Run.h"
16 #include "art/Framework/Principal/SubRun.h"
17 #include "canvas/Utilities/InputTag.h"
18 #include "fhiclcpp/ParameterSet.h"
19 #include "messagefacility/MessageLogger/MessageLogger.h"
20 #include "art_root_io/TFileService.h"
23 #include "nusimdata/SimulationBase/MCParticle.h"
69 void beginJob()
override;
70 void analyze(art::Event
const&
e)
override;
74 float GetDeltaR(art::Ptr<CRTHit> h1, art::Ptr<CRTHit> h2);
75 int GetDeltaT(art::Ptr<CRTHit> h1, art::Ptr<CRTHit> h2);
76 TVector3 HitToPosVec(art::Ptr<CRTHit>
hit);
114 TH1F *fRres_top, *fXres_top, *fYres_top, *
fZres_top, *fTres_top;
115 TH1F *fRres_rim, *fXres_rim, *fYres_rim, *
fZres_rim, *fTres_rim;
116 TH1F *fRres_lat, *fXres_lat, *fYres_lat, *
fZres_lat, *fTres_lat;
117 TH1F *fRres_nor, *fXres_nor, *fYres_nor, *
fZres_nor, *fTres_nor;
118 TH1F *fRres_sth, *fXres_sth, *fYres_sth, *
fZres_sth, *fTres_sth;
119 TH1F *fRres_bot, *fXres_bot, *fYres_bot, *
fZres_bot, *fTres_bot;
131 fSimulationLabel(
p.get<art::InputTag>(
"SimulationLabel",
"largeant")),
132 fCRTTrueHitLabel(
p.get<art::InputTag>(
"CRTTrueHitLabel",
"crttruehit")),
133 fCRTDataLabel(
p.get<art::InputTag>(
"CRTDataLabel",
"crtdaq")),
134 fCRTSimHitLabel(
p.get<art::InputTag>(
"CRTSimHitLabel",
"crthit")),
135 bt(
p.get<fhicl::ParameterSet>(
"CRTBackTrack")),
137 fPosmax(
p.get<
float>(
"PosMax",1000.)),
138 fPosbinning(
p.get<
float>(
"PosBinning",1.)),
139 fTimemax(
p.get<
float>(
"TimeMax",30.)),
140 fTbinning(
p.get<
float>(
"Tbinning",1.)),
141 fVerbose(
p.get<
bool>(
"Verbose",
false))
148 art::ServiceHandle<art::TFileService>
tfs;
150 fNTrueHitMu = tfs->make<TH1F>(
"hNTrueHitMu",
"No. True Hits per #mu", 10,0,10);
151 fNDataMu = tfs->make<TH1F>(
"hNDataMu",
"No. FEB Triggers per #mu", 10,0,10);
152 fNSimHitMu = tfs->make<TH1F>(
"hNSimHitMu",
"No. Sim Hits per #mu", 10,0,10);
153 fNTrueSimDiffMu = tfs->make<TH1F>(
"hNTrueSimDiffMu",
"No. True-Sim Hits per #mu", 14,-6,8);
155 fNTrueHitMu_top = tfs->make<TH1F>(
"hNTrueHitMu_top",
"No. True Hits per #mu", 10,0,10);
156 fNTrueHitMu_side = tfs->make<TH1F>(
"hNTrueHitMu_side",
"No. True Hits per #mu", 10,0,10);
157 fNTrueHitMu_bot = tfs->make<TH1F>(
"hNTrueHitMu_bot",
"No. True Hits per #mu", 10,0,10);
158 fNSimHitMu_top = tfs->make<TH1F>(
"hNSimHitMu_top",
"No. Sim Hits per #mu", 10,0,10);
159 fNSimHitMu_side = tfs->make<TH1F>(
"hNSimHitMu_side",
"No. Sim Hits per #mu", 10,0,10);
160 fNSimHitMu_bot = tfs->make<TH1F>(
"hNSimHitMu_bot",
"No. Sim Hits per #mu", 10,0,10);
162 fNRegTrue = tfs->make<TH1F>(
"hNRegTrue",
"No. True Hits per Region", 10,0,10);
163 fNRegSim = tfs->make<TH1F>(
"hNRegSim",
"No. Sim Hits per Region", 10,0,10);
165 fFebsTrue = tfs->make<TH1F>(
"hFebsTrue",
"mac5s in true hits", 300,0,300);
166 fFebsSim = tfs->make<TH1F>(
"hFebsSim",
"mac5s in sim hits", 300,0,300);
169 const float absmin = -1*absmax;
176 const float tmin = -1*tmax;
179 art::TFileDirectory resdir = tfs->mkdir(
"resolution");
180 fRres_top = resdir.make<TH1F>(
"hRres_top",
"CRTHit #sigma_{r}: Top", nbinsr,0,rmax);
181 fRres_rim = resdir.make<TH1F>(
"hRres_rim",
"CRTHit #sigma_{r}: Rim", nbinsr,0,rmax);
182 fRres_bot = resdir.make<TH1F>(
"hRres_bot",
"CRTHit #sigma_{r}: Bottom", nbinsr,0,rmax);
183 fRres_lat = resdir.make<TH1F>(
"hRres_lat",
"CRTHit #sigma_{r}: East/West", nbinsr,0,rmax);
184 fRres_nor = resdir.make<TH1F>(
"hRres_nor",
"CRTHit #sigma_{r}: North", nbinsr,0,rmax);
185 fRres_sth = resdir.make<TH1F>(
"hRres_sth",
"CRTHit #sigma_{r}: South", nbinsr,0,rmax);
187 fXres_top = resdir.make<TH1F>(
"hXres_top",
"CRTHit #sigma_{x}: Top", nbinsabs,absmin,absmax);
188 fXres_rim = resdir.make<TH1F>(
"hXres_rim",
"CRTHit #sigma_{x}: Rim", nbinsabs,absmin,absmax);
189 fXres_bot = resdir.make<TH1F>(
"hXres_bot",
"CRTHit #sigma_{x}: Bottom", nbinsabs,absmin,absmax);
190 fXres_lat = resdir.make<TH1F>(
"hXres_lat",
"CRTHit #sigma_{x}: East/West", nbinsabs,absmin,absmax);
191 fXres_nor = resdir.make<TH1F>(
"hXres_nor",
"CRTHit #sigma_{x}: North", nbinsabs,absmin,absmax);
192 fXres_sth = resdir.make<TH1F>(
"hXres_sth",
"CRTHit #sigma_{x}: South", nbinsabs,absmin,absmax);
194 fYres_top = resdir.make<TH1F>(
"hYres_top",
"CRTHit #sigma_{y}: Top", nbinsabs,absmin,absmax);
195 fYres_rim = resdir.make<TH1F>(
"hYres_rim",
"CRTHit #sigma_{y}: Rim", nbinsabs,absmin,absmax);
196 fYres_bot = resdir.make<TH1F>(
"hYres_bot",
"CRTHit #sigma_{y}: Bottom", nbinsabs,absmin,absmax);
197 fYres_lat = resdir.make<TH1F>(
"hYres_lat",
"CRTHit #sigma_{y}: East/West", nbinsabs,absmin,absmax);
198 fYres_nor = resdir.make<TH1F>(
"hYres_nor",
"CRTHit #sigma_{y}: North", nbinsabs,absmin,absmax);
199 fYres_sth = resdir.make<TH1F>(
"hYres_sth",
"CRTHit #sigma_{y}: South", nbinsabs,absmin,absmax);
201 fZres_top = resdir.make<TH1F>(
"hZres_top",
"CRTHit #sigma_{z}: Top", nbinsabs,absmin,absmax);
202 fZres_rim = resdir.make<TH1F>(
"hZres_rim",
"CRTHit #sigma_{z}: Rim", nbinsabs,absmin,absmax);
203 fZres_bot = resdir.make<TH1F>(
"hZres_bot",
"CRTHit #sigma_{z}: Bottom", nbinsabs,absmin,absmax);
204 fZres_lat = resdir.make<TH1F>(
"hZres_lat",
"CRTHit #sigma_{z}: East/West", nbinsabs,absmin,absmax);
205 fZres_nor = resdir.make<TH1F>(
"hZres_nor",
"CRTHit #sigma_{z}: North", nbinsabs,absmin,absmax);
206 fZres_sth = resdir.make<TH1F>(
"hZres_sth",
"CRTHit #sigma_{z}: South", nbinsabs,absmin,absmax);
208 fTres_top = resdir.make<TH1F>(
"hTres_top",
"CRTHit #sigma_{t}: Top", nbinst,tmin,tmax);
209 fTres_rim = resdir.make<TH1F>(
"hTres_rim",
"CRTHit #sigma_{t}: Rim", nbinst,tmin,tmax);
210 fTres_bot = resdir.make<TH1F>(
"hTres_bot",
"CRTHit #sigma_{t}: Bottom", nbinst,tmin,tmax);
211 fTres_lat = resdir.make<TH1F>(
"hTres_lat",
"CRTHit #sigma_{t}: East/West", nbinst,tmin,tmax);
212 fTres_nor = resdir.make<TH1F>(
"hTres_nor",
"CRTHit #sigma_{t}: North", nbinst,tmin,tmax);
213 fTres_sth = resdir.make<TH1F>(
"hTres_sth",
"CRTHit #sigma_{t}: South", nbinst,tmin,tmax);
240 fNTrueHitMu_top->SetLineWidth(2);
241 fNTrueHitMu_side->SetLineWidth(2);
242 fNTrueHitMu_bot->SetLineWidth(2);
243 fNSimHitMu->SetLineWidth(2);
244 fNSimHitMu_top->SetLineWidth(2);
245 fNSimHitMu_side->SetLineWidth(2);
246 fNSimHitMu_bot->SetLineWidth(2);
249 fNTrueHitMu_top->SetLineColor(kBlue);
250 fNTrueHitMu_side->SetLineColor(kRed);
251 fNTrueHitMu_bot->SetLineColor(kGreen);
252 fNSimHitMu->SetLineColor(kBlack);
253 fNSimHitMu_top->SetLineColor(kBlue);
254 fNSimHitMu_side->SetLineColor(kRed);
255 fNSimHitMu_bot->SetLineColor(kGreen);
258 fRres_rim->SetLineWidth(2);
259 fRres_bot->SetLineWidth(2);
260 fRres_lat->SetLineWidth(2);
261 fRres_nor->SetLineWidth(2);
262 fRres_sth->SetLineWidth(2);
264 fXres_top->SetLineWidth(2);
265 fXres_rim->SetLineWidth(2);
266 fXres_bot->SetLineWidth(2);
267 fXres_lat->SetLineWidth(2);
268 fXres_nor->SetLineWidth(2);
269 fXres_sth->SetLineWidth(2);
271 fYres_top->SetLineWidth(2);
272 fYres_rim->SetLineWidth(2);
273 fYres_bot->SetLineWidth(2);
274 fYres_lat->SetLineWidth(2);
275 fYres_nor->SetLineWidth(2);
276 fYres_sth->SetLineWidth(2);
278 fZres_top->SetLineWidth(2);
279 fZres_rim->SetLineWidth(2);
280 fZres_bot->SetLineWidth(2);
281 fZres_lat->SetLineWidth(2);
282 fZres_nor->SetLineWidth(2);
283 fZres_sth->SetLineWidth(2);
285 fTres_top->SetLineWidth(2);
286 fTres_rim->SetLineWidth(2);
287 fTres_bot->SetLineWidth(2);
288 fTres_lat->SetLineWidth(2);
289 fTres_nor->SetLineWidth(2);
290 fTres_sth->SetLineWidth(2);
292 fRres_top->GetXaxis()->SetTitle(
"#||{#vec{r_{true}} - #vec{r_{reco}}} [cm]");
293 fRres_rim->GetXaxis()->SetTitle(
"#||{#vec{r_{true}} - #vec{r_{reco}}} [cm]");
294 fRres_bot->GetXaxis()->SetTitle(
"#||{#vec{r_{true}} - #vec{r_{reco}}} [cm]");
295 fRres_lat->GetXaxis()->SetTitle(
"#||{#vec{r_{true}} - #vec{r_{reco}}} [cm]");
296 fRres_nor->GetXaxis()->SetTitle(
"#||{#vec{r_{true}} - #vec{r_{reco}}} [cm]");
297 fRres_sth->GetXaxis()->SetTitle(
"#||{#vec{r_{true}} - #vec{r_{reco}}} [cm]");
299 fXres_top->GetXaxis()->SetTitle(
"#||{x_{true} - x_{reco}} [cm]");
300 fXres_rim->GetXaxis()->SetTitle(
"#||{x_{true} - x_{reco}} [cm]");
301 fXres_bot->GetXaxis()->SetTitle(
"#||{x_{true} - x_{reco}} [cm]");
302 fXres_lat->GetXaxis()->SetTitle(
"#||{x_{true} - x_{reco}} [cm]");
303 fXres_nor->GetXaxis()->SetTitle(
"#||{x_{true} - x_{reco}} [cm]");
304 fXres_sth->GetXaxis()->SetTitle(
"#||{x_{true} - x_{reco}} [cm]");
306 fYres_top->GetXaxis()->SetTitle(
"#||{y_{true} - y_{reco}} [cm]");
307 fYres_rim->GetXaxis()->SetTitle(
"#||{y_{true} - y_{reco}} [cm]");
308 fYres_bot->GetXaxis()->SetTitle(
"#||{y_{true} - y_{reco}} [cm]");
309 fYres_lat->GetXaxis()->SetTitle(
"#||{y_{true} - y_{reco}} [cm]");
310 fYres_nor->GetXaxis()->SetTitle(
"#||{y_{true} - y_{reco}} [cm]");
311 fYres_sth->GetXaxis()->SetTitle(
"#||{y_{true} - y_{reco}} [cm]");
313 fZres_top->GetXaxis()->SetTitle(
"#||{z_{true} - z_{reco}} [cm]");
314 fZres_rim->GetXaxis()->SetTitle(
"#||{z_{true} - z_{reco}} [cm]");
315 fZres_bot->GetXaxis()->SetTitle(
"#||{z_{true} - z_{reco}} [cm]");
316 fZres_lat->GetXaxis()->SetTitle(
"#||{z_{true} - z_{reco}} [cm]");
317 fZres_nor->GetXaxis()->SetTitle(
"#||{z_{true} - z_{reco}} [cm]");
318 fZres_sth->GetXaxis()->SetTitle(
"#||{z_{true} - z_{reco}} [cm]");
320 fTres_top->GetXaxis()->SetTitle(
"#||{t_{true} - t_{reco}} [ns]");
321 fTres_rim->GetXaxis()->SetTitle(
"#||{t_{true} - t_{reco}} [ns]");
322 fTres_bot->GetXaxis()->SetTitle(
"#||{t_{true} - t_{reco}} [ns]");
323 fTres_lat->GetXaxis()->SetTitle(
"#||{t_{true} - t_{reco}} [ns]");
324 fTres_nor->GetXaxis()->SetTitle(
"#||{t_{true} - t_{reco}} [ns]");
325 fTres_sth->GetXaxis()->SetTitle(
"#||{t_{true} - t_{reco}} [ns]");
334 size_t nmu=0, nmu_dep=0, ntrue=0, ndata=0, nsim=0;
335 size_t nmiss_true = 0, nmiss_data = 0, nmiss_sim = 0;
341 art::Handle< vector<simb::MCParticle> > mcHandle;
342 map< int, const simb::MCParticle*> particleMap;
347 throw cet::exception(
"CRTTruthMatchAnalysis")
348 <<
" No simb::MCParticle objects in this event - "
349 <<
" Line " << __LINE__ <<
" in file " << __FILE__ << std::endl;
353 for(
auto const& particle : (*mcHandle)) {
354 particleMap[particle.TrackId()] = &particle;
360 art::Handle< vector<sim::AuxDetSimChannel> > adscHandle;
361 vector< art::Ptr<sim::AuxDetSimChannel> > adscList;
363 art::fill_ptr_vector(adscList,adscHandle);
365 throw cet::exception(
"CRTTruthMatchAnalysis")
366 <<
" No sim::AuxDetSimChannel objects in this event - "
367 <<
" Line " << __LINE__ <<
" in file " << __FILE__ << std::endl;
370 for(
auto const& adsc : adscList) {
371 for(
auto const& ide : adsc->AuxDetIDEs()) {
372 if(particleMap.find(ide.trackID)==particleMap.end())
374 if(
abs(particleMap[ide.trackID]->PdgCode())!=13)
376 muIds.push_back(ide.trackID);
381 std::sort(muIds.begin(),muIds.end());
382 muIds.erase(std::unique(muIds.begin(),muIds.end()),muIds.end());
390 art::Handle< vector<CRTHit> > trueHitHandle;
391 vector< art::Ptr<CRTHit> > trueHitList;
392 map<int,vector<art::Ptr<CRTHit>>> muToTrueHits;
395 art::fill_ptr_vector(trueHitList,trueHitHandle);
397 for(
auto const&
hit : trueHitList) {
399 if(particleMap.find(
id)==particleMap.end())
401 if(
abs(particleMap[
id]->PdgCode())!=13)
403 muToTrueHits[id].push_back(
hit);
407 ntrue = muToTrueHits.size();
410 mf::LogWarning(
"CRTTruthMatchAnalysis") <<
"no CRTTrueHits found";
413 art::Handle< vector<CRTData> > dataHandle;
414 vector< art::Ptr<CRTData> > dataList;
415 map<int,vector<art::Ptr<CRTData>>> muToData;
417 art::fill_ptr_vector(dataList,dataHandle);
421 for(
auto const& data : dataList) {
423 if(particleMap.find(
id)==particleMap.end())
425 if(
abs(particleMap[
id]->PdgCode())!=13)
427 muToData[id].push_back(data);
432 for(
const int trk : muIds) {
433 if(muToData.find(trk)==muToData.end()){
443 mf::LogWarning(
"CRTTruthMatchAnalysis") <<
"no CRTData found";
446 art::Handle< vector<CRTHit> > simHitHandle;
447 vector< art::Ptr<CRTHit> > simHitList;
448 map<int,vector<art::Ptr<CRTHit>>> muToSimHits;
450 art::fill_ptr_vector(simHitList,simHitHandle);
452 for(
auto const&
hit : simHitList) {
454 if(particleMap.find(
id)==particleMap.end())
456 if(
abs(particleMap[
id]->PdgCode())!=13)
458 muToSimHits[id].push_back(
hit);
464 mf::LogPrint(
"CRTTruthMatchAnalysis")
465 <<
" found " << nsim <<
" muon-associated CRTSimHits ("
466 << 100.0*nsim/simHitList.size() <<
" %)";
469 mf::LogWarning(
"CRTTruthMatchAnalysis") <<
"no CRTSimHits found";
473 size_t nmatch=0, nmiss=0, nmiss_track=0, nmiss_feb=0;
475 for(
const int trk : muIds) {
477 int ntruehit=0, nsimhit=0;
478 int ntrue_top=0, ntrue_side=0, ntrue_bot=0;
479 int nsim_top=0, nsim_side=0, nsim_bot=0;
480 map<string,size_t> nregtrue, nregsim;
482 bool simhasmu =
true;
484 if(muToTrueHits.find(trk)!=muToTrueHits.end()){
485 ntruehit = muToTrueHits[trk].size();
486 for(
auto const&
hit : muToTrueHits[trk]) {
488 for(
auto const&
id :
hit->feb_id)
491 string truereg =
hit->tagger;
492 if(nregtrue.find(truereg)==nregtrue.end())
493 nregtrue[truereg] = 1;
498 if(truetype==
'c') ntrue_top++;
499 if(truetype==
'm') ntrue_side++;
500 if(truetype==
'd') ntrue_bot++;
503 if(muToSimHits.find(trk)!=muToSimHits.end()) {
504 for(
auto const& simhit : muToSimHits[trk]) {
505 std::string simreg = simhit->tagger;
506 if(simreg != truereg)
continue;
507 if(truetype ==
'c' || truetype==
'd'){
508 if(simhit->feb_id[0] ==
hit->feb_id[0]){
543 if(simreg.find(
"Rim")!=string::npos){
551 if(simreg==
"Bottom") {
567 for(
auto const& truefeb :
hit->feb_id){
568 for(
auto const& simfeb : simhit->feb_id){
569 if(truefeb==simfeb) {
577 if(simreg==
"North") {
584 else if(simreg==
"South") {
614 if(muToSimHits.find(trk)!=muToSimHits.end()) {
615 nsimhit = muToSimHits[trk].size();
616 for(
auto const&
hit : muToSimHits[trk]) {
617 for(
auto const&
id :
hit->feb_id)
620 if(nregsim.find(
hit->tagger)==nregsim.end())
621 nregsim[
hit->tagger] = 1;
623 nregsim[
hit->tagger]++;
626 if(
type==
'c') nsim_top++;
627 if(
type==
'm') nsim_side++;
628 if(
type==
'd') nsim_bot++;
646 for(
auto const& nreg : nregtrue)
fNRegTrue->Fill(nreg.second);
647 for(
auto const& nreg : nregsim)
fNRegSim->Fill(nreg.second);
653 <<
" * nmu: " << nmu <<
'\n'
654 <<
" * ntrue hit: " << trueHitList.size() <<
" with " << ntrue <<
" ass'd with muons" <<
'\n'
655 <<
" * nsim hit: " << simHitList.size() <<
" with " << nsim <<
" ass'd with muons" <<
'\n'
658 std::cout <<
"matched true/sim hits:" <<
'\n'
659 <<
" * matched: " << nmatch <<
'\n'
660 <<
" * missed: " << nmiss <<
'\n'
661 <<
" - SimHits missing muon track: " << nmiss_track <<
'\n'
662 <<
" - SimHits, c or d missing FEB match: " << nmiss_feb <<
'\n'
665 std::cout <<
"missed muons (eff.):" <<
'\n'
666 <<
" * trueHit: " << nmiss_true <<
" (" << 1.0*(nmu-nmiss_true)/nmu <<
")" <<
'\n'
667 <<
" * data: " << nmiss_data <<
" (" << 1.0*(nmu-nmiss_data)/nmu <<
")" <<
'\n'
668 <<
" * simHit: " << nmiss_sim <<
" (" << 1.0*(nmu-nmiss_sim)/nmu <<
")" <<
'\n'
676 double dx = h1->x_pos - h2->x_pos;
677 double dy = h1->y_pos - h2->y_pos;
678 double dz = h1->z_pos - h2->z_pos;
680 dr = sqrt(dx*dx + dy*dy + dz*dz);
693 TVector3 vec(hit->x_pos,hit->y_pos,hit->z_pos);
process_name opflashCryo1 flashfilter analyze
float GetDeltaR(art::Ptr< CRTHit > h1, art::Ptr< CRTHit > h2)
CRTTruthMatchAnalysis(fhicl::ParameterSet const &p)
art::InputTag fCRTSimHitLabel
std::size_t size(FixedBins< T, C > const &) noexcept
art::InputTag fSimulationLabel
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
art::InputTag fCRTTrueHitLabel
object containing MC truth information necessary for making RawDigits and doing back tracking ...
TVector3 HitToPosVec(art::Ptr< CRTHit > hit)
char GetRegTypeFromRegName(string name)
CRTCommonUtils * fCrtutils
std::vector< int > AllTrueIds(const art::Event &event, const CRTData &data)
art::InputTag fCRTDataLabel
void analyze(art::Event const &e) override
art::ServiceHandle< art::TFileService > tfs
BEGIN_PROLOG could also be cout
int GetDeltaT(art::Ptr< CRTHit > h1, art::Ptr< CRTHit > h2)