13 #include "art/Framework/Core/EDAnalyzer.h"
14 #include "art/Framework/Core/ModuleMacros.h"
15 #include "art/Framework/Principal/Event.h"
16 #include "fhiclcpp/ParameterSet.h"
17 #include "art/Framework/Principal/Run.h"
18 #include "art/Framework/Principal/SubRun.h"
19 #include "art/Framework/Principal/Handle.h"
20 #include "canvas/Persistency/Common/Ptr.h"
21 #include "canvas/Persistency/Common/PtrVector.h"
22 #include "art/Framework/Services/Registry/ServiceHandle.h"
23 #include "art_root_io/TFileService.h"
24 #include "art_root_io/TFileDirectory.h"
25 #include "canvas/Persistency/Common/FindOneP.h"
26 #include "canvas/Persistency/Common/FindManyP.h"
27 #include "canvas/Utilities/InputTag.h"
28 #include "messagefacility/MessageLogger/MessageLogger.h"
54 #include "nusimdata/SimulationBase/MCParticle.h"
55 #include "nusimdata/SimulationBase/MCTruth.h"
56 #include "nusimdata/SimulationBase/MCNeutrino.h"
58 #include "nusimdata/SimulationBase/MCTrajectory.h"
60 #include "nug4/ParticleNavigation/ParticleList.h"
72 #include "TTimeStamp.h"
80 class PMTStartCalibTime;
96 void analyze(art::Event
const &
e)
override;
183 photonLabel(p.
get<art::InputTag>(
"fottoni",
"largeant")),
184 chargeLabel(p.
get<art::InputTag>(
"carconi",
"largeant")),
185 typoLabel (p.
get<art::InputTag>(
"tiponi",
"generator"))
188 std::cout <<
" Let's try to calib in time the PMTs... " << std::endl;
195 art::ServiceHandle<geo::Geometry> geom;
197 std::vector<sim::SimPhotons>
const& optical = *(evt.getValidHandle<std::vector<sim::SimPhotons>>(photonLabel));
198 std::vector<sim::SimChannel>
const& charge = *(evt.getValidHandle<std::vector<sim::SimChannel>>(chargeLabel));
203 event = evt.id().event();
207 auto type = evt.getMany< std::vector<simb::MCTruth> >();
208 art::Handle< std::vector<simb::MCParticle> > particleVecHandle;
209 evt.getByLabel(
"largeant", particleVecHandle);
211 std::vector<const simb::MCParticle*> particleVec;
212 if (particleVecHandle.isValid())
214 for(
size_t idx = 0; idx < particleVecHandle->size(); idx++) particleVec.push_back(&particleVecHandle->at(idx));
216 art::Handle< std::vector<recob::Track> > trackVecHandle;
217 evt.getByLabel(
"pandoraTrackICARUSCryo0", trackVecHandle);
219 std::vector<const recob::Track*> trackVec;
220 if (trackVecHandle.isValid())
222 for(
size_t idx = 0; idx < trackVecHandle->size(); idx++) trackVec.push_back(&trackVecHandle->at(idx));
230 for (
int u=0; u<360; u++)
236 true_barycentre_x =0;
237 true_barycentre_y =0;
238 true_barycentre_z =0;
240 total_quenched_energy =0;
244 for (std::size_t chargechannel = 0; chargechannel<charge.size(); ++chargechannel)
246 auto const& channeltdcide = charge.at(chargechannel).TDCIDEMap();
248 for (std::size_t TDCnu = 0; TDCnu<channeltdcide.size(); ++TDCnu)
251 sim::TDCIDE const& tdcide = channeltdcide.at(TDCnu);
253 for (std::size_t IDEnu = 0; IDEnu<tdcide.second.size(); ++IDEnu)
255 sim::IDE const& ida = tdcide.second.at(IDEnu);
259 true_barycentre_x = true_barycentre_x + ida.
x*ida.
energy;
260 true_barycentre_y = true_barycentre_y + ida.
y*ida.
energy;
261 true_barycentre_z = true_barycentre_z + ida.
z*ida.
energy;
262 total_quenched_energy = total_quenched_energy + ida.
energy;
270 true_barycentre_x = true_barycentre_x/total_quenched_energy;
271 true_barycentre_y = true_barycentre_y/total_quenched_energy;
272 true_barycentre_z = true_barycentre_z/total_quenched_energy;
274 total_quenched_energy = total_quenched_energy/3;
279 total_coll_photons=0;
281 for (std::size_t channel = 0; channel < optical.size(); ++channel) {
285 noPMT[channel] = channel;
287 photons_collected[channel]= photon_vec.size();
293 QE_photons_collected[channel]= 0.06*photons_collected[channel];
295 if (photons_collected[channel]>0){
302 geom->OpDetGeoFromOpChannel(channel).GetCenter(xyz);
304 PMTx[channel] = xyz[0];
305 PMTy[channel] = xyz[1];
306 PMTz[channel] = xyz[2];
308 total_coll_photons= total_coll_photons + photons_collected[channel];
310 firstphoton_time[channel] = 100000000;
312 if (photons_collected[channel]>0)
314 for (
size_t i = 0; i<photon_vec.size() && int(i)<
MaxPhotons; ++i)
316 photon_time[channel][i]= photon_vec.at(i).Time;
318 if (photon_time[channel][i]<firstphoton_time[channel])
320 firstphoton_time[channel]=photon_time[channel][i];
329 if (PMTx[channel]<0){Cryostat[channel]=0;}
330 if (PMTx[channel]>0){Cryostat[channel]=1;}
332 if (PMTx[channel]<-200){
TPC[channel]=0;}
333 if (PMTx[channel]>-200 && PMTx[channel]<0){
TPC[channel]=1;}
334 if (PMTx[channel]<200 && PMTx[channel]>0){
TPC[channel]=2;}
335 if (PMTx[channel]>200){
TPC[channel]=3;}
341 std::cout <<
" fotoni finale = " <<total_coll_photons <<std::endl;
345 for(
int ijk=0;ijk<360;ijk++)
347 firstphoton_time_expected[ijk]=100000000;
348 firstphoton_time_expected_r[ijk]=100000000;
349 firstphoton_tp_expected[ijk]=100000000;
350 firstphoton_tp_expected_r[ijk]=100000000;
351 firstphoton_xp_expected[ijk]=100000000;
352 firstphoton_xp_expected_r[ijk]=100000000;
353 firstphoton_yp_expected[ijk]=100000000;
354 firstphoton_yp_expected_r[ijk]=100000000;
355 firstphoton_zp_expected[ijk]=100000000;
356 firstphoton_zp_expected_r[ijk]=100000000;
358 firstphoton_tp_expected_v2[ijk]=100000000;
359 firstphoton_tp_expected_v3[ijk]=100000000;
360 firstphoton_xp_expected_v2[ijk]=100000000;
361 firstphoton_xp_expected_v3[ijk]=100000000;
362 firstphoton_yp_expected_v2[ijk]=100000000;
363 firstphoton_yp_expected_v3[ijk]=100000000;
364 firstphoton_zp_expected_v2[ijk]=100000000;
365 firstphoton_zp_expected_v3[ijk]=100000000;
367 firstphoton_time_expected_v3[ijk]=100000000;
368 firstphoton_time_expected_v2[ijk]=100000000;
369 firstphoton_time_expected_d2[ijk]=100000000;
370 firstphoton_time_expected_d3[ijk]=100000000;
373 for(
size_t mcl = 0; mcl <
type.size(); ++mcl)
375 art::Handle< std::vector<simb::MCTruth> > mclistHandle =
type[mcl];
377 for(
size_t m = 0;
m < mclistHandle->size(); ++
m)
379 art::Ptr<simb::MCTruth> mct(mclistHandle,
m);
380 for(
int ipart=0;ipart<mct->NParticles();ipart++)
387 event_type=mct->GetParticle(0).PdgCode();
388 vertex_x=mct->GetParticle(0).Vx();
389 vertex_y=mct->GetParticle(0).Vy();
390 vertex_z=mct->GetParticle(0).Vz();
403 for(
const auto& tracknow3 : trackVec)
405 std::cout << tracknow3->NumberTrajectoryPoints() << std::endl;
406 int ntraj = tracknow3->NumberTrajectoryPoints();
407 int last_good_point=ntraj;
408 for (
size_t ijk=0;ijk<tracknow3->NumberTrajectoryPoints();ijk++)
410 auto trajPoint = tracknow3->TrajectoryPoint(ijk);
411 if(trajPoint.position.X()<-600)
421 float y_max_value=-150;
424 for (
size_t ijk=0;ijk<tracknow3->NumberTrajectoryPoints();ijk++)
426 auto trajPoint = tracknow3->TrajectoryPoint(ijk);
427 if(trajPoint.position.Y()>y_max_value)
430 y_max_value=trajPoint.position.Y();
443 auto first_point=tracknow3->TrajectoryPoint(point_y_max);
444 c_f_x=first_point.position.X();
445 c_f_y=first_point.position.Y();
446 c_f_z=first_point.position.Z();
466 std::cout <<
"Start of trajectory at " << first_point.position.X() <<
" " << first_point.position.Y() <<
" " << first_point.position.Z() <<
" cm " << std::endl;
467 for (
int ijk2=0;ijk2<last_good_point;ijk2++)
469 auto trajPoint = tracknow3->TrajectoryPoint(ijk2);
471 float xpr=trajPoint.position.X();
472 float ypr=trajPoint.position.Y();
473 float zpr=trajPoint.position.Z();
474 float distance_from_first_point=sqrt((xpr-c_f_x)*(xpr-c_f_x)+(ypr-c_f_y)*(ypr-c_f_y)+(zpr-c_f_z)*(zpr-c_f_z))/100;
475 float tpr=distance_from_first_point/0.3;
480 for(
int ijk=0;ijk<180;ijk++)
482 float distance_x=xpr-PMTx[ijk+factor];
483 float distance_y=ypr-PMTy[ijk+factor];
484 float distance_z=zpr-PMTz[ijk+factor];
485 float total_distance=sqrt(distance_x*distance_x+distance_y*distance_y+distance_z*distance_z)/100;
486 float time_travel_light=total_distance/(0.1);
488 if(firstphoton_time_expected_r[ijk+factor]>(tpr+time_travel_light))
490 firstphoton_time_expected_r[ijk+factor]=(tpr+time_travel_light);
491 firstphoton_tp_expected_r[ijk+factor]=(tpr);
492 firstphoton_xp_expected_r[ijk+factor]=(xpr);
493 firstphoton_yp_expected_r[ijk+factor]=(ypr);
494 firstphoton_zp_expected_r[ijk+factor]=(zpr);
513 for(
const auto& particlenow3 : particleVec)
516 for ( simb::MCTrajectory::const_iterator trajectory = particlenow3->Trajectory().begin(); trajectory != particlenow3->Trajectory().end(); ++trajectory)
518 float xp=(*trajectory).first.X();
519 float yp=(*trajectory).first.Y();
520 float zp=(*trajectory).first.Z();
521 float tp=(*trajectory).first.T();
524 if (yp>-185 && yp<140 && fabs(zp)<910)
526 if (xp<-343 || xp>-247) {
529 if (xp<-193 || xp>-98) {
534 if(yp>-185 && yp<140 && fabs(zp)<910 && fabs(xp)<370 && fabs(xp)>70){
535 for(
int ijk=0;ijk<180;ijk++)
537 float distance_x=xp-PMTx[ijk+factor];
538 float distance_y=yp-PMTy[ijk+factor];
539 float distance_z=zp-PMTz[ijk+factor];
540 float total_distance=sqrt(distance_x*distance_x+distance_y*distance_y+distance_z*distance_z)/100;
541 float time_travel_light_v2=total_distance/(0.2);
542 float time_travel_light=total_distance/(0.1);
543 float time_travel_light_v3=total_distance/(0.05);
544 if(firstphoton_time_expected[ijk+factor]>(tp+time_travel_light))
546 firstphoton_time_expected[ijk+factor]=(tp+time_travel_light);
547 firstphoton_tp_expected[ijk+factor]=(tp);
548 firstphoton_xp_expected[ijk+factor]=(xp);
549 firstphoton_yp_expected[ijk+factor]=(yp);
550 firstphoton_zp_expected[ijk+factor]=(zp);
552 if(firstphoton_time_expected_v2[ijk+factor]>(tp+time_travel_light_v2))
554 firstphoton_time_expected_v2[ijk+factor]=(tp+time_travel_light_v2);
555 firstphoton_tp_expected_v2[ijk+factor]=(tp);
556 firstphoton_xp_expected_v2[ijk+factor]=(xp);
557 firstphoton_yp_expected_v2[ijk+factor]=(yp);
558 firstphoton_zp_expected_v2[ijk+factor]=(zp);
560 if(firstphoton_time_expected_v3[ijk+factor]>(tp+time_travel_light_v3))
562 firstphoton_time_expected_v3[ijk+factor]=(tp+time_travel_light_v3);
563 firstphoton_tp_expected_v3[ijk+factor]=(tp);
564 firstphoton_xp_expected_v3[ijk+factor]=(xp);
565 firstphoton_yp_expected_v3[ijk+factor]=(yp);
566 firstphoton_zp_expected_v3[ijk+factor]=(zp);
570 for(
int ijk=0;ijk<180;ijk++)
572 float distance_x=(xp-25)-PMTx[ijk+factor];
573 float distance_y=yp-PMTy[ijk+factor];
574 float distance_z=zp-PMTz[ijk+factor];
575 float total_distance=sqrt(distance_x*distance_x+distance_y*distance_y+distance_z*distance_z)/100;
576 float time_travel_light_d2=total_distance/(0.1);
577 if(firstphoton_time_expected_d2[ijk+factor]>(tp+time_travel_light_d2))firstphoton_time_expected_d2[ijk+factor]=(tp+time_travel_light_d2);
579 for(
int ijk=0;ijk<180;ijk++)
581 float distance_x=(xp+25)-PMTx[ijk+factor];
582 float distance_y=yp-PMTy[ijk+factor];
583 float distance_z=zp-PMTz[ijk+factor];
584 float total_distance=sqrt(distance_x*distance_x+distance_y*distance_y+distance_z*distance_z)/100;
585 float time_travel_light_d3=total_distance/(0.1);
586 if(firstphoton_time_expected_d3[ijk+factor]>(tp+time_travel_light_d3))firstphoton_time_expected_d3[ijk+factor]=(tp+time_travel_light_d3);
597 std::cout <<
" after filling " << fTree << std::endl;
602 std::cout <<
" PMTStartCalibTime beginjob " << std::endl;
604 art::ServiceHandle<art::TFileService>
tfs;
605 fTree = tfs->make<TTree>(
"lighttree",
"tree for the light response");
607 fTree->Branch(
"event",&event,
"event/I");
608 fTree->Branch(
"event_type",&event_type,
"event_type/I");
609 fTree->Branch(
"gt_0",>_0,
"gt_0/I");
610 fTree->Branch(
"gt_1",>_1,
"gt_1/I");
611 fTree->Branch(
"total_quenched_energy",&total_quenched_energy,
"total_quenched_energy");
618 fTree->Branch(
"turned_PMT",&turned_PMT,
"turned_PMT/I");
619 fTree->Branch(
"total_coll_photons",&total_coll_photons,
"total_coll_photons/F");
620 fTree->Branch(
"photons_colleted",&photons_collected,(
"photons_collected[" +
std::to_string(
nPMTs) +
"]/F").c_str());
621 fTree->Branch(
"QE_photons_colleted",&QE_photons_collected,(
"QE_photons_collected[" +
std::to_string(
nPMTs) +
"]/F").c_str());
622 fTree->Branch(
"firstphoton_time",&firstphoton_time,(
"firstphoton_time[" +
std::to_string(
nPMTs) +
"]/F").c_str());
623 fTree->Branch(
"firstphoton_time_expected",&firstphoton_time_expected,(
"firstphoton_time_expected[" +
std::to_string(
nPMTs) +
"]/F").c_str());
624 fTree->Branch(
"firstphoton_time_expected_r",&firstphoton_time_expected_r,(
"firstphoton_time_expected_r[" +
std::to_string(
nPMTs) +
"]/F").c_str());
625 fTree->Branch(
"firstphoton_tp_expected",&firstphoton_tp_expected,(
"firstphoton_tp_expected[" +
std::to_string(
nPMTs) +
"]/F").c_str());
626 fTree->Branch(
"firstphoton_tp_expected_r",&firstphoton_tp_expected_r,(
"firstphoton_tp_expected_r[" +
std::to_string(
nPMTs) +
"]/F").c_str());
627 fTree->Branch(
"firstphoton_xp_expected",&firstphoton_xp_expected,(
"firstphoton_xp_expected[" +
std::to_string(
nPMTs) +
"]/F").c_str());
628 fTree->Branch(
"firstphoton_xp_expected_r",&firstphoton_xp_expected_r,(
"firstphoton_xp_expected_r[" +
std::to_string(
nPMTs) +
"]/F").c_str());
629 fTree->Branch(
"firstphoton_yp_expected",&firstphoton_yp_expected,(
"firstphoton_yp_expected[" +
std::to_string(
nPMTs) +
"]/F").c_str());
630 fTree->Branch(
"firstphoton_yp_expected_r",&firstphoton_yp_expected_r,(
"firstphoton_yp_expected_r[" +
std::to_string(
nPMTs) +
"]/F").c_str());
631 fTree->Branch(
"firstphoton_zp_expected",&firstphoton_zp_expected,(
"firstphoton_zp_expected[" +
std::to_string(
nPMTs) +
"]/F").c_str());
632 fTree->Branch(
"firstphoton_zp_expected_r",&firstphoton_zp_expected_r,(
"firstphoton_zp_expected_r[" +
std::to_string(
nPMTs) +
"]/F").c_str());
634 fTree->Branch(
"firstphoton_tp_expected_v2",&firstphoton_tp_expected_v2,(
"firstphoton_tp_expected_v2[" +
std::to_string(
nPMTs) +
"]/F").c_str());
635 fTree->Branch(
"firstphoton_tp_expected_v3",&firstphoton_tp_expected_v3,(
"firstphoton_tp_expected_v3[" +
std::to_string(
nPMTs) +
"]/F").c_str());
636 fTree->Branch(
"firstphoton_xp_expected_v2",&firstphoton_xp_expected_v2,(
"firstphoton_xp_expected_v2[" +
std::to_string(
nPMTs) +
"]/F").c_str());
637 fTree->Branch(
"firstphoton_xp_expected_v3",&firstphoton_xp_expected_v3,(
"firstphoton_xp_expected_v3[" +
std::to_string(
nPMTs) +
"]/F").c_str());
638 fTree->Branch(
"firstphoton_yp_expected_v2",&firstphoton_yp_expected_v2,(
"firstphoton_yp_expected_v3[" +
std::to_string(
nPMTs) +
"]/F").c_str());
639 fTree->Branch(
"firstphoton_yp_expected_v3",&firstphoton_yp_expected_v3,(
"firstphoton_yp_expected_v2[" +
std::to_string(
nPMTs) +
"]/F").c_str());
640 fTree->Branch(
"firstphoton_zp_expected_v2",&firstphoton_zp_expected_v2,(
"firstphoton_zp_expected_v2[" +
std::to_string(
nPMTs) +
"]/F").c_str());
641 fTree->Branch(
"firstphoton_zp_expected_v3",&firstphoton_zp_expected_v3,(
"firstphoton_zp_expected_v3[" +
std::to_string(
nPMTs) +
"]/F").c_str());
644 fTree->Branch(
"firstphoton_time_expected_v2",&firstphoton_time_expected_v2,(
"firstphoton_time_expected_v2[" +
std::to_string(
nPMTs) +
"]/F").c_str());
645 fTree->Branch(
"firstphoton_time_expected_v3",&firstphoton_time_expected_v3,(
"firstphoton_time_expected_v3[" +
std::to_string(
nPMTs) +
"]/F").c_str());
646 fTree->Branch(
"firstphoton_time_expected_d2",&firstphoton_time_expected_d2,(
"firstphoton_time_expected_d2[" +
std::to_string(
nPMTs) +
"]/F").c_str());
647 fTree->Branch(
"firstphoton_time_expected_d3",&firstphoton_time_expected_d3,(
"firstphoton_time_expected_d3[" +
std::to_string(
nPMTs) +
"]/F").c_str());
649 fTree->Branch(
"vertex_x",&vertex_x,
"vertex_x/D");
650 fTree->Branch(
"vertex_y",&vertex_y,
"vertex_y/D");
651 fTree->Branch(
"vertex_z",&vertex_z,
"vertex_z/D");
652 fTree->Branch(
"true_barycentre_x",&true_barycentre_x,
"true_barycentre_x/F");
653 fTree->Branch(
"true_barycentre_y",&true_barycentre_y,
"true_barycentre_y/F");
654 fTree->Branch(
"true_barycentre_z",&true_barycentre_z,
"true_barycentre_z/F");
float firstphoton_zp_expected[nPMTs]
float firstphoton_yp_expected_v3[nPMTs]
float firstphoton_tp_expected[nPMTs]
float z
z position of ionization [cm]
float firstphoton_time_expected_d2[nPMTs]
float firstphoton_xp_expected[nPMTs]
PMTStartCalibTime & operator=(PMTStartCalibTime const &)=delete
std::pair< unsigned short, std::vector< sim::IDE > > TDCIDE
List of energy deposits at the same time (on this channel)
Declaration of signal hit object.
float photons_collected[nPMTs]
float firstphoton_yp_expected_v2[nPMTs]
float firstphoton_zp_expected_v3[nPMTs]
float firstphoton_time_expected_v3[nPMTs]
float firstphoton_zp_expected_r[nPMTs]
void analyze(art::Event const &e) override
float firstphoton_xp_expected_v2[nPMTs]
float x
x position of ionization [cm]
float firstphoton_tp_expected_r[nPMTs]
float firstphoton_yp_expected[nPMTs]
tuple m
now if test mode generate materials, CRT shell, world, gdml header else just generate CRT shell for u...
float firstphoton_xp_expected_r[nPMTs]
float firstphoton_tp_expected_v2[nPMTs]
Simulation objects for optical detectors.
Ionization at a point of the TPC sensitive volume.
float firstphoton_time_expected_d3[nPMTs]
float energy
energy deposited by ionization by this track ID and time [MeV]
float QE_photons_collected[nPMTs]
float firstphoton_yp_expected_r[nPMTs]
Declaration of cluster object.
Definition of data types for geometry description.
Provides recob::Track data product.
float firstphoton_time_expected_r[nPMTs]
float y
y position of ionization [cm]
Collection of photons which recorded on one channel.
float firstphoton_time_expected[nPMTs]
float firstphoton_xp_expected_v3[nPMTs]
float firstphoton_tp_expected_v3[nPMTs]
std::string to_string(WindowPattern const &pattern)
object containing MC truth information necessary for making RawDigits and doing back tracking ...
float firstphoton_zp_expected_v2[nPMTs]
float firstphoton_time[nPMTs]
Declaration of basic channel signal object.
float firstphoton_time_expected_v2[nPMTs]
PMTStartCalibTime(fhicl::ParameterSet const &p)
art::ServiceHandle< art::TFileService > tfs
float photon_time[nPMTs][MaxPhotons]
Utility functions to extract information from recob::Track
Tools and modules for checking out the basics of the Monte Carlo.
art framework interface to geometry description
BEGIN_PROLOG could also be cout
float total_quenched_energy
art::InputTag chargeLabel
art::InputTag photonLabel